CGI that enable moblog using GMail in MovableType 

Simple View | Forum View

This Perl CGI script helps you do moblogging easily in MovableType. It uses GMail account. I guess this CGI is most easy to install and adapt to your MT blog. Just install some Perl modules and copy this CGI, then you can do moblogging right now.

Description

This Perl CGI use GMail account . Dont have to make extra GMail account for moblogging. You can use current account without confusing with other none-for-moblog email or spams.

You can create a new Weblog for moblog, but it's too overhead I think.(Of course, you can do it by this CGI) Instead of making new blog, just add new catefory for moblog.

With this CGI, you can adapt it with cron (a sceduler ) but in normal hosting condition, we can't use that service. Then just call this cgi by your cell-phone.

I think the most frustrating install process is not in my CGI, but Mail::Webmail::Gmail Perl module. This module requires a some security-related prerequsites modules, and you have to install it too.

Some features of this CGI

  • You can send an email with no image and only text body.
  • It can resize original image sent by phone. If width of image is wider than some preset value, then the image will be resized to that width in ratio of original images' width/height.
  • It can created a new thumbnail image by MT's Image module. This URL of thumbnail is entered in an entry's Keywords. You can use thumbnail by the tag <$MTEntryKeywords$>
  • Original images and thumbnail are stored in folders like year/month with tree structrues.
  • It logs every errors to MT's log, so you can view it in "View Active Logs" menu.
  • Some camera-phone made imperfect JPG header, so all image resizing process failed. If you have same occasions, you can bypass this result by provided plugin.
  • If you've use KeyValue plugin, you can adapt it to this CGI.

Requirements

  • GMail account
  • Perl modules : Time::Local, File::Path, Mail::Webmail::Gmail
  • ImageMagick or NetPBM if you want image resizing.

Installation

  • Download this here and uncompress.
     
  • Move g.cgi to mt/ folder and MT.Image.init__AND__scale.pl to mt/plugins folder.
     
  • Add excute-permission to g.cgi ($ chmod +x g.cgi )
     
  • Make a folder, which is to store original images and thumbnail images, under blog/ folder. I will assume this folder is blog/moImages.
     
  • Open Mail/Webmail/Gmail.pm which may be in some Perl library folder if you installed, and add following subroutine to the last line.
sub get_image {
    my ( $self ) = shift;
    my ( $url, $image_dir ) = @_;
    my ( $req, $res );
 
    unless ( check_login( $self ) ) { return };
 
    $req = HTTP::Request->new( GET => $url );
    $req->header( Cookie => $self->{_cookie}, Accept => 'image/*');
    if ( $self->{_proxy_enable} >= 2 ) {
        $req->proxy_authorization_basic( $self->{_proxy_user}, $self->{_proxy_pass} );
    }
    $res = $self->{_ua}->request( $req );
    if($res->is_success) {
      open IFH, "+>$image_dir";
      print IFH $res->content;
      close IFH;
    }
}


Configuration

Open mt/g.cgi and modify following varibales with your environments and tastes.

my $myGmailID = 'alogblog';
my $myGmailPswd = '12345678';
my $moCheck_tag = 'moblog';
my $moDefaultTitle = 'Picture taken at ';
my $myBlogURL = 'http://alogblog.com';
my $webRootDIR = '/home/hosting_users/myaccount/www';
my $moImageDIR = '/blog/moImages';
my $blog_id = 1;
my $author_id = 1;
my $category_id = 1;
my $moImage_DIV_attribute = 'class="moImg"';
my $moImage_resize = 1;
my $moImage_width = 300;
my $moImage_height;
my $moImage_thumbnail = 1;
my $moImage_thumbnail_width = 100;
my $moImage_thumbnail_height;
my $useKeyValuePlugin = 0;
my $multibyte_characters = 1;

Following, I'll explain these in detail.

  • my $myGmailID = 'your GMail account name';
    my $myGmailPswd = 'your GMail account password';
  • my $moCheck_tag = '1234';
    my $moDefaultTitle = 'Picture taken at ';

How do you assure this mail was sent by YOU with a purpose of moblogging. The email for moblogging should be treated carefully because that is to be saved with an entry and published in your blog directly and publicly. No email header information that was sent automatically by your telephone-company guarantees it. So you should enter $moCheck_tag value into your mail's title.

For example, email title>1234 this is my first
Then, this email is to be assumed to be for moblog and the title of entry will be "this is my first".

What if you don't enter extra title of email, just only $moCheck_tag value?
For example, email title>1234
Then the title of an entry wil be $moDefaultTitle+date_information, like 'Picture taken at 2005.01.01 12:10".

  • my $myBlogURL = 'http://alogblog.com';
    my $webRootDIR = '/home/hosting_users/myaccount/www';
    my $moImageDIR = '/blog/moImages';

Above three values must end with no trailing '/'.
$myBlogURL is your blog domain name.
$webRootDIR is absolute path of web root.
$moImageDIR is relative path (but starting '/') from web root.

  • my $blog_id = 1;
    my $author_id = 1;
    my $category_id = 1;

You dont have to make a new weblog for moblogging. Just add a new category for mobloggin.

  • my $moImage_DIV_attribute = 'class="moImg"';

When saving an entry for moblg, the Entry Body  is like below.
<div class="moImg"><img src="http: / /myblog...com / blog / moImages / 2005 / 01 / 123456.jpg" /></div>This is my first moblogging...
So you can design moblog entry using CSS.

  • my $moImage_resize = 1;
    my $moImage_width = 450;
    my $moImage_height;

What happens if the width of image is wider than that of entry's fixed width ? These values are for the case that images sent by phone is too big for your entry design. if you set like above, then in images that have smaller then 450px, no resizing occurs. If wider than 450px, the image will be resized in proportion with original width/height ratio and fixed 450 width. If you dont any resizing, set it 0.

  • my $moImage_thumbnail = 1;
    my $moImage_thumbnail_width = 100;
    my $moImage_thumbnail_height;

If you want extra thumbnail image, set it 1. If you set like above, the width of thumbnail is 100px, and original width/height ratio is kept.

  • my $multibyte_characters = 0;

In multibyte characters like Korean, Chinese and Japanses, set it 1. GMail use UTF-8 encoding, but encoding of blog may be different with that. In that case, multibyte characters are broken. So internally by using Perl' Encode module, this CGI solve this problem.

  • my $useKeyValuePlugin = 0;

If you use default value 0, as explained above, the Entry Body of an entry will be
<div $moImage_DIV_attribute ><img src="http: / /myblog...com / blog / moImages / 2005 / 01 / 123456.jpg" /></div>This is the my first mobloggin...

And if you set $moImage_thumbnail = 1, the URL of thumbnail image is saved in entry's Keywords. So if you want to display a thumbnail list in archives list page, you can use <MTEntryKeywords> tag like this, <img src="<$MTEntryKeywords$>" title="Thumbnail of ..." />I

If you've used KeyValue plugin and want to adapt it, you can set it 1. Then the Entry Body of an entry will have no <img> tag. Instead, the entry will hava Keywords like below format.

moImage=http://myblog....com/blog/moImages/2005/03/123456.jpg
moThumb=http://myblog....com/blog/moImages/2005/03/123456_thumb.jpg

If you dont know KeyValue plugin, then just use default 0.


How to Use

  • Send email to your GMail account by camera-phone
  • In email's title, you MUST enter $moCheck_tag value before real title(subject), title is optional
  • Browse(ie. run) http: / /your_blog...com/mt/g.cgi by your phone. Then the message 'I got your command' is displayed and about 1 second later, it redirect real CGI. Ater seeing that message, you can hang up. The amount time of total processing is about 10 secs or more, but you don't have to wait to see 'Processed...' message.

Some notes

  • This CGI logs all erros into MT's Active Log. So you can view logs later.
  • If you want, you can send email by local PC's email clients like Outlook, Thunderbird ,etc.
  • If CGI processed incoming email for mobloggin, it would archive the new emails to All Mail in GMail automatically.
  • If it's possible for you to use a scheduler like cron, you can configure it to run g.cgi. Then you dont have to run g.cgi by cell-phone.

Post a comment

  • PGP/GPG 서명된 코멘트를 지원합니다. ?
  • 이메일 주소는 정중히 사절합니다.
  • 이름(닉네임)/블로그 주소는 필수 입력사항입니다.
  • 이미지는 자기 블로그상의 대문이미지 등을 사용하셔도 좋습니다.
  • 코멘트에 달린 이미지를 클릭하면 자신의 블로그로 연결됩니다.
  • 깨진 블로그/이미지 주소를 가진 코멘트는 수정/삭제 대상입니다.


  •   Forget me

    ?