Wow, if you wanna see some uber cool geekiness, you have to check this out from the guys at thinkgeek.com. Wow...just wow...
Kudos guys! Probably one of the most entertaining covers of The Who too!
Slashdot Entertainment Story | Timmy O'Riley By L. Hadron and the Colliders
Wednesday, February 24, 2010
Wednesday, December 16, 2009
WordPress CLI Import
So a few weeks back I wrote some code to export a WordPress blog via the command line. Now, to come full circle I finished dissecting the code to import a WordPress blog via CLI.
Now before proceding, I highly recommend going through the import/export process via the admin GUI if you have not done so already. Doing so will let you understand fully what the entire process is like and can see why some parts of code were written.
At this point I assume that an xml export has already been made; if not, go make one!
Here's the entire code:
The code is short and simple. The only part that was hard to understand was how the author_in and user_select POST arrays were used so, I'm going to take a minute to give a brief explanation.
Right now, I only have a need to import a 1-to-1 user mapping; meaning: import one user's posts and map them to an existing user. Though of course, with a little more work, this code can support a multiple user import.
The author_in array is a
Now, the user_select array is made up of the existing blog's user's IDs where the key is the same key for whatever was used for the author_in array. (Yes, this is what confused me!)
If you wanted to import multiple users' blogs you'll understand these two arrays better.
Example
Users to be imported: jim, mary
To be mapped to these users: frank, sue (respectively)
Now the arrays would look something like this:
Now hopefully you'll see what's going on now if you look at the array keys!
Enjoy! Cheers!
Now before proceding, I highly recommend going through the import/export process via the admin GUI if you have not done so already. Doing so will let you understand fully what the entire process is like and can see why some parts of code were written.
At this point I assume that an xml export has already been made; if not, go make one!
Here's the entire code:
if ($argc < 4) {
print "Usage: $argv[0] from_topic to_topic xml_file\n";
exit;
}
$user_login = $argv[2];
include 'wp-config.php';
include 'wp-admin/includes/import.php';
include 'wp-includes/registration.php';
include 'wp-admin/includes/post.php';
include 'wp-admin/includes/taxonomy.php';
include 'wp-admin/import/wordpress.php';
// the WP_Import class looks for POST values for author_in and user_select
// author_in is an array of users to import
$_POST['author_in'][1] = $argv[1];
// user_select is an array of the selected user's ID for posts to be mapped to
// if empty, the user in author_in will be created
$userdata = get_userdatabylogin( $user_login );
$_POST['user_select'][1] = $userdata->ID;
$wp_import = new WP_Import();
$wp_import->import_file($argv[3]);
The code is short and simple. The only part that was hard to understand was how the author_in and user_select POST arrays were used so, I'm going to take a minute to give a brief explanation.
$_POST['author_in'][1] = $argv[1];Right now, I only have a need to import a 1-to-1 user mapping; meaning: import one user's posts and map them to an existing user. Though of course, with a little more work, this code can support a multiple user import.
The author_in array is a
0...n key array where the values are the users to-be-imported. Remember though, you'll need to remember what key you use since it'll be the same key for the user_select array.
$userdata = get_userdatabylogin( $user_login );
$_POST['user_select'][1] = $userdata->ID;
Now, the user_select array is made up of the existing blog's user's IDs where the key is the same key for whatever was used for the author_in array. (Yes, this is what confused me!)
If you wanted to import multiple users' blogs you'll understand these two arrays better.
Example
Users to be imported: jim, mary
To be mapped to these users: frank, sue (respectively)
Now the arrays would look something like this:
$_POST['author_in'][0] = 'jim';
$_POST['author_in'][1] = 'mary';
$userdata = get_userdatabylogin( 'frank' );
$_POST['user_select'][0] = $userdata->ID;
$userdata = get_userdatabylogin( 'sue' );
$_POST['user_select'][1] = $userdata->ID;
Now hopefully you'll see what's going on now if you look at the array keys!
Enjoy! Cheers!
Monday, December 14, 2009
Help Save MySQL!
We are using MySQL, help save it!
Creator of MySQL, Michael "Monty" Widenius, blogged this passed Saturday urging all MySQL users to show their support. As we all know already, Oracle has acquired Sun and this puts MySQL's future in their hands. Monty outlines the dangers that are near if Oracle gets their way. The main form of showing support is to email the European Commission.
Monty was even kind enough to set up email templates so now all you need to do is copy/paste! I've reposted below:
Creator of MySQL, Michael "Monty" Widenius, blogged this passed Saturday urging all MySQL users to show their support. As we all know already, Oracle has acquired Sun and this puts MySQL's future in their hands. Monty outlines the dangers that are near if Oracle gets their way. The main form of showing support is to email the European Commission.
Monty was even kind enough to set up email templates so now all you need to do is copy/paste! I've reposted below:
Send this to: comp-merger-registry@ec.europa.eu
If you want to keep us updated, send a copy to ec@askmonty.org
If you have extra time to help, fill in the following, if not, just skip to the main text.
Name:
Title:
Company:
Size of company:
How many MySQL installations:
Total data stored in MySQL (megabyte):
For what type of applications is MySQL used:
Should this email be kept confidential by EC: Yes/No
Copy or use one of the below texts as a base for your answer:
a)
I don't trust that Oracle will take good care of MySQL and MySQL should be divested to another company or foundation that have everything to gain by developing and promoting MySQL. One should also in the future be able to combine MySQL with closed source application (either by exceptions, a more permissive license or be able to dual license MySQL under favourable terms)
b)
I think that Oracle could be a good steward of MySQL, but I would need EC to have legally binding guarantees from Oracle that:
- All of MySQL will continue to be fully Open Source/free software in the future (no closed source modules).
- Open Source version and dual-licensed version of MySQL should have same source (like today).
- That development will be done in community friendly way.
- The manual should be released under a permissive license (so that one can fork it, the same way one can fork the server)
- That MySQL should be released under a more permissive license to ensure that forks can truly compete with Oracle if Oracle is not a good steward after all.
Alternatively:
- One should be able to always buy low priced commercial licenses for MySQL.
- All of the above should be perpetual and irrevocable.
There should also be mechanism so that if Oracle is not doing what is expected of it, forks should be able to compete with Oracle
c)
I trust Oracle and I suggest that EC will approve the deal unconditionally.
--------------------
Wednesday, November 25, 2009
WordPress CLI Export
Why would you want to use the command line to export your WordPress blog? Well, if you are like me and manage 300+ blogs, you'll want an easy way to export a blog without logging into each and every WordPress admin page to click around and export that xml file.
Anyhow, if you poke around in the wp-admin/export.php page, you'll notice that it calls a function
It'll spit out the xml to stdout so you'll want to grab that buffer! See the code below to generally see how I did things.
Simple. Very useful! Cheers!
Anyhow, if you poke around in the wp-admin/export.php page, you'll notice that it calls a function
export_wp (which is defined at wp-admin/includes/export.php). And voila! Amazingly that's all you need!It'll spit out the xml to stdout so you'll want to grab that buffer! See the code below to generally see how I did things.
Simple. Very useful! Cheers!
include 'wp-config.php';
include 'wp-admin/includes/export.php';
ob_start();
export_wp();
$file = ob_get_contents();
ob_end_clean();
$fh = fopen("wordpress-" . date('Y-m-d') . ".xml", 'w');
fwrite($fh, $file);
fclose($fh);
Thursday, August 27, 2009
Quick Bash One-Liner
Well, I'm here trying to wrap up things for the day and just found a very useful technique to get a directory without the filename from the listing if using find.
So, I'm sure you were all thinking, "well why don't you just use `find` with `-type d`?" Well, for this specific task I will be using `find` to get a list of all files and then I need whatever that directory is for another script. So booyah, in your face! (hehe jk)
So, apparently if I have a directory structure string with a file at the end of it I can drop the end part like so:
Sweet as!
And if you were curious how I was using it as a one-liner, here ya go:
Obviously, I'm doing a lot more here than just echoing, but this is just an example mmmkay? ;)
Cheers!
Post Script: It's been a while for posts, but I've just been working on proprietary stuff lately and nothing would be too useful for ya'll. Sorry!
So, I'm sure you were all thinking, "well why don't you just use `find` with `-type d`?" Well, for this specific task I will be using `find` to get a list of all files and then I need whatever that directory is for another script. So booyah, in your face! (hehe jk)
So, apparently if I have a directory structure string with a file at the end of it I can drop the end part like so:
f1=/mnt/www/tmpdrin/dir1/dir2/fileindir.txt
f2=${f1%/*};
## $f2 will now be /mnt/www/tmpdrin/dir1/dir2
Sweet as!
And if you were curious how I was using it as a one-liner, here ya go:
for f in `find /mnt/www/tmpdrin/ -type f`; do f2=`echo "$f" | sed -e 's!/mnt/!!g'`; f3=${f2%/*}; echo "$f3"; done
Obviously, I'm doing a lot more here than just echoing, but this is just an example mmmkay? ;)
Cheers!
Post Script: It's been a while for posts, but I've just been working on proprietary stuff lately and nothing would be too useful for ya'll. Sorry!
Tuesday, June 23, 2009
Rant: Stupid Debugging Day!
This is not going to be a tech recipe or anything productive. In fact, it's more of a kick myself in the arse type-of-deal. --and I guess also a reminder to myself if/when I have to make this change again.
Anyhow, here's the story in a nutshell: my project manager tasks me to roll out my code for our next version release to our test group. All goes well EXCEPT for one (yes, that's right 1) site. Odd. So, now I suppose it must be some rare issue with corrupt data in the database. I make a dump of the production db for that site and bring it down to beta to test. I run it through the upgrade; success! Interesting.
So now, I'm back again to try this upgrade again in production. Yup, fails again. Crap! So some fresh eyes need to take a look things over so I ask my manager to take a look. The issue puzzles him for a little bit, but then he IMs, "hold. I think I know why." :seconds pass: "working now?" And yes it is!
An error in the apache log sheds some light to the situation. Apache is complaining that an .htm file is missing in the root directory of my app. Apparently, this one site I needed to upgrade happened to be the first site in the apache conf and it didn't have this one file that the Netscaler needed. Awesome. Had nothing to do with my code. Spent pretty much the entire day debugging code to see what was going on. Lame...
At least now I know for future reference.
Cheers!
Anyhow, here's the story in a nutshell: my project manager tasks me to roll out my code for our next version release to our test group. All goes well EXCEPT for one (yes, that's right 1) site. Odd. So, now I suppose it must be some rare issue with corrupt data in the database. I make a dump of the production db for that site and bring it down to beta to test. I run it through the upgrade; success! Interesting.
So now, I'm back again to try this upgrade again in production. Yup, fails again. Crap! So some fresh eyes need to take a look things over so I ask my manager to take a look. The issue puzzles him for a little bit, but then he IMs, "hold. I think I know why." :seconds pass: "working now?" And yes it is!
An error in the apache log sheds some light to the situation. Apache is complaining that an .htm file is missing in the root directory of my app. Apparently, this one site I needed to upgrade happened to be the first site in the apache conf and it didn't have this one file that the Netscaler needed. Awesome. Had nothing to do with my code. Spent pretty much the entire day debugging code to see what was going on. Lame...
At least now I know for future reference.
Cheers!
Friday, June 5, 2009
Update: WordPress - Modifying Post Content
Earlier in May I wrote up this post about modifying WordPress post content and prefixing URIs to go through a tracker. Well, one of the web designers here found this ridiculously rare bug. Apparently if you have content that has a URI that breaks at the end of a line because of word wrap, the trackURL function will not process. Weird!
So, I tested and confirmed and basically rewrote the entire function to one line. Who knew?
Anyhow here it is in all of its glory:
Blogger is giving me gripe about the regex, so here's a screenshot:

Cheers!
So, I tested and confirmed and basically rewrote the entire function to one line. Who knew?
Anyhow here it is in all of its glory:
function trackURL($content) {
$content = preg_replace('/\< a(\s|\n|[^href])href=\"([^"]+)\"\>([^<]+)\<\/a\>/','$3',$content);
return $content;
}
Blogger is giving me gripe about the regex, so here's a screenshot:
Cheers!
Subscribe to:
Posts (Atom)