Jump to content

Cloning content across sites/servers


Pete
 Share

Recommended Posts

This is a continuation of something that was being discussed in the second part of ryan's post here: http://processwire.com/talk/index.php/topic,414.msg3192.html#msg3192

The reason I was interested in this is because I've had a scenario in my head for a while. I'm intending to build an accomodation directory website (being intentionally vague here) and there will hopefully be the opportunity to build some individual websites for the individual accomodation (for the sake of argument let's assume hotels, but it's not).

The way I therefore see site cloning being useful for that is if the owner is allowed to update content themselves on the directory website and then this information automatically (via cloning, probably not instantly) gets updated on the specific hotel website.

So whilst I'm being vague about a website I'm intending to build, this is one scenario that could be a real selling point to customers. I'll also have the luxury of having websites hosted on the same server, at least to start with, so that would probably make things even easier. I think I'd definitely look into the web service approach as well though as that would make it easier if it took off.

Something unrelated that's been bugging me for a while Ryan - on the villa website you've created, how did you determine which photos would go across the top and which ones down the side? Also some are square in two columns and others are wider covering both columns - surely that's all automatic but I can't get my head around how it's been done. No worries if it's a trade secret ;)

Link to comment
Share on other sites

Pete, I work on several travel-based web sites as well and they keep me in business. Good to hear you are working on these types of sites too–it's nice to have a peer in the industry! Perhaps we should collaborate on one of these projects someday. There seems to be an overabundance of work in this area, it's enjoyable work, and a lot of good people.

Not specific to travel industry, but my experience has been that most sites that have a large inventory of constantly changing stuff in any industry are providing a means to share and mirror their data. Most often, they are using verbose XML feeds (well beyond something like RSS), and letting their vendors or affiliates pull data off of them. The type of data sharing I was describing in the other thread is really no different, and I would say that PW lends itself especially well to both sharing and pulling data. PW also makes it easy to go far beyond just providing a feed and instead providing a true web service that can be queried. It really is fun to do.

Something unrelated that's been bugging me for a while Ryan - on the villa website you've created, how did you determine which photos would go across the top and which ones down the side? Also some are square in two columns and others are wider covering both columns - surely that's all automatic but I can't get my head around how it's been done. No worries if it's a trade secret

I've done this on a few sites, and seen other sites do it too, so it's not a secret or anything. However, it does cross into a territory of getting logic involved in style, so not a best practice for those that like to just swap in new stylesheets to completely change a design.

Lets use a fictional example where you want to display a wide horizontal row of 3 square photos and another vertical row of square thumbnails, 2 per row. For landscape orientation photos that have the resolution, you want to double the width to maximize the space. You'd treat the big horizontal row and the vertical thumbnails as two separate things, though might use the same code (in a function) to handle either.

In either case, you need to know the total width of the row in pixels so you know how much room you have to work with. Then you'll keep a counter on the width of each photo so you'll know when you've filled the space. You'll also look for opportunities to maximize the photo width. Treat the following as pseudocode because it's typed in the browser and not tested:

<?php

$pixelsMax = 900; // max pixels we're allowed to use
$pixels = 0; // counter of current used pixels
$w1 = 300; // target regular size image width
$w2 = 600; // target double size image width
$h1 = 300; // target height
$skipped = array(); // images skipped due to being too small, can be displayed elsewhere
$out = ''; // where we'll store our markup

while(1) {

    // if there's no more room for a small photo, then break
    if($pixels + $w1 > $pixelsMax) break;

    // shift off the first image 
    $image = $page->images->shift(); 

    // no image? then stop
    if(!$image) break;

    // get it's width and height
    $w = $image->width;
    $h = $image->height; 

    // if the image isn't big enough, then save it and skip it
    if($w < $w1 || $h < $h1) {
        $skipped[] = $image; 
        continue;
    }

    // get the current image width/height
    $w = $image->width();
    $h = $image->height();

    // see if there's room for a double-wide
    // and also if the image has a wide-landscape orientation
    if(($pixels + $w2 <= $pixelsMax) && ($w / $h >= 1.5)) {
        $newWidth = $w2; // double-wide
    } else {
        $newWidth = $w1; // square
    }

    // make the image the size we need it 
    $newImage = $image->size($newWidth, $h1); 

    // add to our width counter
    $pixels += $newWidth; 

    // make the markup
    $out .= "<a href='{$image->url}'><img src='{$newImage->url}' alt='{$image->description}' width='$newWidth' height='$newHeight' /></a>";
}

// stuff the unused images back to the page 
// so they can be used for the vertical thumbnails
foreach(array_reverse($skipped) as $image) {
    $page->images->prepend($image);
}

This is all typed in the browser and untested, so there may be errors, but hopefully it at least works as pseudocode. If it were real code, we'd want it in a function too.

Now the vertical thumbnails part would work in a similar manner. You could use the above as a function for each row of thumbnails, but may prefer to make something more efficient custom to the need.

Link to comment
Share on other sites

Cheers Ryan

Hopefully I'll have something to show you in the coming weeks in terms of the website I'm working on - it's a personal project that's travel/accomodation based. It's not intended to make money to start with, but it will be an excellent showcase piece to show other clients and could make money further down the line. I imagine your Tripsite and villa website work makes it much easier to sell an idea (and this CMS) if you've already got an example or two to hand!

There are other projects I've got in mind, but I'd like to get this one done first as for one thing it's something I've been meaning to do for years and, as mentioned, would make a good showcase.

I'm all for collaboration - I do love working on larger websites as the additional challenges are usually fun and always give you a good feeling when you overcome them. That said, I don't mind working on smaller sites however they can often be very time-consuming and the time-to-profit ratio can sometimes get you down if you're charging a lump sum rather than an hourly rate. I like to be able to give clients an overall cost before starting work, but sometimes it doesn't work out so well... I'll leave it at that but I'm sure we've all built enough websites for folks to get what I mean ;) I think overall I like working on larger projects because you don't have to chop and change too much - you can work on one project for a good length of time with the same set of people and give it your full attention.

At the other end of the scale I worked at a company once in a web team and they were juggling 20 websites at once and working on each one for an hour a day and alternating it throughout the week so they could show the clients a bit of progress each week - I don't agree with that personally - it was chaotic at best.

Thanks for the pseudocode - I think it will come in handy on the site I've mentioned here as well as my gaming one with a few modifications :)

Link to comment
Share on other sites

Thanks Pete. Sorry somehow I missed this message before. Large/long projects have their own set of challenges too... like: the client's team changing halfway through, higher risks of scope creep, and so on. It's hard to do more than 1 or 2 a year. The smaller projects end up being more fun and less risky on consistent income. But I think any of us that work independently with a lot of clients always value the opportunity to really focus on something for more than a couple weeks. Big projects leave you satisfied... at least until the client starts designing their own in-house graphics and plastering them on the site. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...