Home > Projects > Xanga mirror script

Xanga blog mirror script

What is this? Why is it useful?

Xanga is sort of like the Microsoft Windows of the blogging world. It's the most popular blogging site out there used by millions, and it's got a nice, easy to use interface. If you're a novice and just want a simple to use blog, Xanga does the trick.

Also analogously to Windows, Xanga seems to be looked down upon amongst the "hard-core" bloggers, because of its closed, proprietary hosted system, and lack of many features standard in other blog-management software as well as total ability to tinker with the source code and customize settings to one's heart's content.

Yet, despite their shortcomings, both Windows and Xanga are hard to ignore because of their user communities. In particular, I found that many of my friends only bothered to read other Xanga sites through its built-in aggregator, and rarely if ever read non-Xanga sites like mine hosted using Movable Type. So, for a while, I was manually mirroring my MT entries onto Xanga via cutting and pasting. However, being the lazy nerd I am, I decided to come up with something better.

Presenting the Xanga mirror script, written in Perl. It automates logging in and posting to Xanga, and is designed to be called from content-management software such as Movable Type. In all fairness, the idea isn't totally mine, although this implementation is. I first saw this technique on a friend of a friend's site, and was intrigued. However, he was apparently using some other CMS, and not MT, so I decided to implement my own solution.

The requirements are simple: MT or some other blog/content management software written in Perl, a host that you have access to, and some basic knowledge of editing text files on UNIX. Oh, and of course, a Xanga account, which you can freely sign up for if you don't have one already. The basic one will do -- no need for Premium.

Enjoy! =)

Usage

Xanga.pm -- the Xanga posting script. Download this, edit the user setting variables in the file itself, and save it to somewhere in your Perl @INC path, probably PATH_TO_YOUR_BLOG_SOFTWARE/lib/. For Moveable Type using the default installation paths, it's the same directory that MT.pm is in.

SECURITY WARNING: If this file resides in a web-server accessible directory, make sure you take steps to protect this file from being accessed through the web server itself and exposing your Xanga username/password. Please consult your web server's documentation. For Apache, the easiest way is to create a file called .htaccess located in the same directory as this file with the contents:

Order Deny,Allow
Deny from all

Now, you will need to modify your blog software somehow. Here's what I did for MT 2.661 which will automatically call the Xanga posting routine whenever the file is saved, and log Xanga posts to the activity log:

  1. In file MT_PATH/lib/MT/App/CMS.pm, add the line 'use Xanga;' without the quotes between the below lines near the beginning of the file as shown:

    @MT::App::CMS::ISA = qw( MT::App );

    use Xanga;

    sub init {

  2. In the same file, search for sub save_entry {. In this subroutine, insert the following code in bold between the appropriate lines which you can find by scrolling down (you may wish to tweak the setting of $xanga_post to suit your preferences):

    if ($id) {
    ## Delete the author_id param (if present), because we don't want to
    ## change the existing author.
    $app->delete_param('author_id');
    }
    my %values = map { $_ => scalar $q->param($_) } @$names;

    my $xanga_post = "<b><font size=+1>".$values{'title'}."</font></b>\r\n\r\n" .$values{'text'};
    if($values{'text_more'}) {
    $xanga_post .= "\r\n\r\n".$values{'text_more'};
    }
    my $xanga_post_results = &Xanga::post_to_xanga($xanga_post);
    $app->log($xanga_post_results);

    ## Strip linefeed characters.
    for my $col (qw( text excerpt text_more keywords )) {
    $values{$col} =~ tr/\r//d if $values{$col};
    }

Now, when you post to your MT blog, the entry should be automatically mirrored in Xanga. If you go to your Xanga site, you should see the entry. If you don't, check the activity log in your MT blog for any errors.

For non-MT users

I have endeavored to make this routine as CMS-agnostic as possible. If you use any sort of blog/CMS software written in Perl, it should be easy to incorporate it, but you'll need some rudimentary knowledge of Perl to do so. I have only tested with MT 2.661 though. If you use something else, and it works or doesn't work for you, please let me know.

Limitations

This is basically alpha quality software. It only has the most rudimentary of error handling. Also, it only supports posting new posts to Xanga and not editing or deleting existing posts. So, if you go back and edit an entry in your "real" blog, you'll probably need to go to Xanga and make the old entry "private". Also, I am no Perl or MT guru, so if you can write this in a better way, please do let me know!

License

If you use this script, I would appreciate it if you drop me a email letting me know... just so I can notify you of any changes or improvements I make in the future.

You are free to use this as you like. I only ask that you do not take credit for it, and if you make improvements to the script, to please notify me. This is not a very important life project for me, so bug fixes/support is not guaranteed, especially for compatibility with software other than MT. Also, if you somehow use this as part of your nuclear reactor or air traffic control software and Bad Things happen, don't sue me... =P

Comments

Please feel free to email me or publically comment in my blog.


Mark Wang <mwang@cs.stanford.edu>
Last modified: 2004.2.28