How to Change the Directory that Movable Type Uploads to When Using the Atom Protocol (Lifeblog, PixelPipe, etc)
I don't know about you, but I have had a little list of blog upkeep items that have been on my to do list for ages, but haven't had the time to research and then execute them. After thinking about a few of them for some time, oh like a couple of years, I decided recently to make a real paper list and make it happen.
Here are the things I wanted to do:
1) Figure out how to get thumbnails of images to appear in the excerpted version of this blog's RSS and Atom feeds.
2) Think about how to keep the evil sploggers (spam bloggers who scrape feeds) at bay AND keep my regular feed readers happy with a good feed. I have had my private full feed for at least two years now & announce it frequently but folks who want a full feed didn't know about it.
3) Even though Perl is not really my friend, I have wanted to figure out how to alter the Atom script for this blog so that when I use Lifeblog or PixelPipe to mobile blog from my camera phone to this blog that the photo will be uploaded into the file directory of my choice and not the default main blog directory.
A few weeks ago, I dedicated a few hours to attempting to bending the Atom and RSS feed templates to my will. Unfortunately, Movable Type 4.x is very dependent on the Asset Manager for knowing where the images are, and due to challenge #3, I was not able to fix #1 with any satisfaction, as all the fixes required the Asset Manager to know where all the images are and by default the Atom script uploads all assets/images to the main blog directory, which causes a messy main directory with my daily mobile blogging. To solve this, I have been manually moving images to a proper image directory and then updating the blog post later, thus the Asset Manager can't keep up with me. Poor thing.
Persistent artist vs. computer program. Who is going to lose? In the long run, the program. Until I solved problem #3, problem #1 was a null point.
I solved #2 by resetting my public facing feeds to be a bit bigger excerpts that would show the images but would excerpt any article over a certain length. I use the .htaccess file to stop any lifting of images. And I still have the private complete feed for anyone who emails me and lets me know that they want the url.
Today, I decided to conquer the moblogging directory issue and attempt to make Perl bend to my will.
Why? Well, if you want to mobile blog from your mobile or cell phone to your blog you have several options depending on your phone and your blogging software. One can, depending on the device, software, and whether it is hosted or self-hosted, either use email, a plugin, or an application on the phone to send the images/video and text to one's blog.
If you are an iPhone owner and use WordPress (be it hosted or self-hosted), you are currently golden and can moblog to your heart's desire. But if you like me want a mobile with a much better camera and use a non-WordPress blog software (sorry, not everyone loves WP, really, it's true), then moblogging can be a bit challenging.
Nokia used to have a GREAT mobile blogging app called Lifeblog that came natively installed on the Nokia NSeries mobiles and Movable Type kindly made their mt-atom.cgi script to be compatible for mobile devices to post to one's blog using their Atom script. And now with encouragement, PixelPipe allows one to add your self-hosted blog's atom url to be a pipe.
As with all things Movalbe Type anything beyond the basic blogging requires more than a bit of DIY spirit and the willingness to get under the hood with a wrench. Today's wrench set was getting into the atom script to set the url upload path and blog posting path to store the mobile blogged images to a directory that was not the main blog directory.
I started by searching on Google and was not able to find anyone else who was tinkering with the mt-atom.cgi script recently and writing about it. Since Movable Type 4.3 was released earlier this year, the mt-atom.cgi script went from a full script that did all the work for the posting to the blog via the Atom Protocol to just being a few lined script that delegated all the work to the AtomServer.pm script that lives in the /lib/ directory of the MT install.
Given my lack of Perl foo, I try to avoid altering in the scripts in the /lib/ directory so that I don't have a blog software meltdown. But I did participate in safe DIY tinkering and I backed up the original script and then started to read it to find where the parts that dealt with image upload where. I found on line 882 of the AtomServer.pm some relevant bits and was able to add the directory that I wanted the images to go to. I then tested the fix with my Nokia by sending a photo up, but it was only half the fix.
For anyone who wants to also change your MT 4.x's AtomServer.pm to not upload to
your main blog directory here is the fix but instead to upload assets/images to the directory of your choosing, here are the lines in the AtomServer.pm to be changed:
line 835 my $local_relative = File::Spec->catfile('%r', $fname); to my $local_relative = File::Spec->catfile('%r', 'name of upload dir', $fname); [in my case the upload dir is 'moblog']
line 836 my $local = File::Spec->catfile($blog->site_path, $fname);
to my $local = File::Spec->catfile($blog->site_path, 'moblog', $fname);
line 882 my $url = '%r/' . $base . $ext;
to my $url = '%r/moblog/' . $base . $ext;
Please back up the original AtomServer.pm file before starting to tinker and then have fun moblogging with nice clean, well ordered directories.