As a followup to my previous post on how to enable subfolders in WordPress Hive domains I created the script that will go through and update the symlinks in the appropriate folder to keep your installation up to date. You’d run this after performing an update to WordPress to keep it running smoothly. I think this should keep working in the future but I can’t see the future (if only) so this is provided as is and I’m not responsible if you screw something up!

It’s a simple php script you’ll run from your command line with the parameters of the source folder and the destination folder. With the source being the wordpress installation of the hive and the destination is the domain that is run off of the hive but has its own subfolders. It should tell you about any symlinks it creates and warn you about any potential custom files you have which you should manually compare to the upgrade if needed to see if you need to edit them.

Another thing to keep in mind I’ve found you need to put the full path to the source directory that you want to copy or it will make relative symlinks that don’t seem to work.


<?php
// Updating the symlinks in the destination folder for the updated files in the source folder

// Get list of files for each folder
$srcDirName = $argv[1];
$destDirName = $argv[2];

if ($srcDirName == "" || $destDirName == "") {
echo "Usage: php update_symlinks_src_dest.php [source directory] [destination directory]";
echo " Please leave ending slashes off of directories / ";
}
echo "Updating symlink from source: " . $srcDirName . " \n";
echo "To destination:               " . $destDirName . " \n";

$srcDir = opendir($srcDirName);
$destDir = opendir($destDirName);

$array_dest_files = array();

while ($dest_filename = readdir($destDir)) {
array_push($array_dest_files, $dest_filename);
}

while ($src_filename = readdir($srcDir)) {
// check for file in dest
if (in_array($src_filename, $array_dest_files) ){
// Test each file in both hash against the other
// echo "comparing: src- " . $srcDirName . "/" . $src_filename . " and dest- " . $destDirName . "/" . $src_filename . " \n";

$srcmd5 = md5_file( $srcDirName . "/" . $src_filename );
$destmd5 = md5_file( $destDirName . "/" . $src_filename );

// if pass then this is a symlink or copy and is ok

if ($srcmd5 != $destmd5) {
// if fail then probably this is a custom file so leave it alone but warn about it
echo "Warning potential custom file not handled: " . $destDirName . "/" . $src_filename . "\n";
}
}
else {
// if file in src and not dest create a symlink for it
echo "Creating symlink for file: " . $srcDirName . "/" . $src_filename . " \n";

symlink( $srcDirName . "/" . $src_filename , $destDirName . "/" . $src_filename );
}
}

// if file in dest and not src leave it alone

closedir($srcDir);
closedir($destDir);
?>
Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn

{ 1 comment }

I was going to post this over at the WP Hive forums but their forum registration doesn’t seem to work so I’ll just put it here.

WordPress hive is a super useful plugin that lets you install one copy of WordPress and run a bunch of different sites on it. Quite useful for the enterprising web developer. It does however have some limitations one of which is that since all your sites are pointed to the same place if you want subfolders to hold files or images or whatever that subfolder would be accessible from all the sites run off of the hive installation. Not something you want obviously.

So I figured out a way around this and thought I’d share. To do this you’re going to need shell access to your server probably unless you can talk your admins into doing it for you but it could be a bit of a pain.

Anyway typically you’d install the site into the WordPress Hive plugin using their directions and to get it to work you’d “point” that domain to the domain running the hive. Basically this amounts to adding the domain as an addon domain in your cPanel then making the folder that would hold the domain files into a symlink pointing at the folder holding the hive installation.

Now if you want to enable subfolders for this new site, say you want to host a file people could download or something, what you’re going to do is instead of making that folder be a symlink you’ll create that folder. Then you’re going to go in there and make a symlink to each file in the hive installations folder with the same name. Pretty simple but can take a bit of time. You may want to write a script to do it as well, I haven’t yet but probably will as you’ll also have to keep these symlinks up to date when you upgrade WordPress. Another trick is to make a folder that holds all these symlinks (using absolute file names or relative to your home directory)  and just copy it over whenever you want a new site with subfolders enabled. Also keep in mind that if you’re looking at this folder in your FTP client it’s going to look like all those files are there instead of just symlinks so be careful that you know what is what if you go messing around with FTPing things around. Oh and always remember to back up stuff before you go messing around you know how unforgiving Unix is.

Now viola you’ve got subfolders. Now you can put whatever you want in that folder along with the symlinks and serve up other files. For instance you could have a subfolder with another WordPress install in it or another piece of software in that folder.

Sweet huh? Now get back to work! :D

UPDATE: I’ve coded up that script to keep the symlinks up to date and made a new post about how to how to keep your custom WordPress hive installation up to date.

Photo Attribution

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn

{ 1 comment }

Free Zip Code Database Oh My

June 25, 2008

Heads up to all those who do marketing in any niches that can be localized. These guys at zipcodeguy.com are giving away a free database of zip codes that have been localized to cities and states along with all sorts of useful data. Definitely check it out you can make some really nice long tail [...]

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →

Google Fridge, Me Want!

January 9, 2008

So it looks like Google is getting into the fridge market since they don’t dominate the world quite enough eh? Anyway cool guy Dan Perry is giving one away and I want to win it so I can store me beers er sodas whilst coding and monkeying around. Also perhaps it would be useful for [...]

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →

Control Some Guys Christmas Decorations and Help A Charity

December 23, 2007

I just ran across a site by a guy named Alek who has setup controls on the web along with webcams so you can control his crazy amount of christmas decorations. He’s got lights all over as well as inflatable dudes you can turn on and off. So head on over and help annoy his [...]

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →

Watch Jackass 2.5 Online Now

December 22, 2007

The crazy Jackass guys have released the sequel to Jackass 2 and it’s now online only and you can watch it for free at the Jackass 2.5 site for a few more days then I’m not sure. I’d suggest checking it out if you liked the Jackass movies. They mostly crammed together a bunch of [...]

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →

Next Will Smith Movie OMG SUPER HEROES

December 19, 2007

So I ran across this clip for Will Smith’s next movie, yep even after I am Legend (which I’d like to see) and it looks freakin’ cool as hell check it out. Be a Social Geek:

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →

Funny Web 2.0 Video

December 5, 2007

Wow it’s been a while since I posted, lots happened I moved and have been super busy. Hopefully I’ll get back to posting some cool stuff though. To start back out heres a funny video about web 2.0 Be a Social Geek:

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →

Half Life In 60 Seconds

November 4, 2007

This video is great it actually had me laughing out loud for reals! If you haven’t played Half Life I definitely recommend it the game is fantastic and is one of the best games of all time. Orange box also has Team Fortess 2 and Portal which are both amazing so if you like games [...]

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →

Is Greed And Capitalism Good?

October 27, 2007

Perusing YouTube I just ran across this ABC News report on greed and capitalism and how it may just be a good and positive thing that helps grow countries. It’s also what makes America great. Here’s the first part of it you can find the rest at YouTube. Be a Social Geek:

Be a Social Geek:
  • Facebook
  • Twitter
  • Reddit
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Fark
  • Technorati
  • Sphinn
Read the full article →