More Google API hacks for Movable Type
8Wow, I was pleasantly surprised with the rush of positive feedback from today’s Google API hack for Movable Type users. A number of people asked for some new features, and given that it was only anoither 7 lines of perl code or so, I coded it up!
The new patch to MT 2.11 adds the following new features to the MTGoogleSearch tag. It adds the following new properties that will change the behavior of the tag:
- title=”1″ : This will cause the google search query to be the title (MTEntryTitle) of your current blog entry
- excerpt=”1″ : This will cause the google serch query to be the entry excerpt (MTEntryExcerpt) of the current blog entry
Those two properties are mutually exclusive (along with the current query=”" and related=”1″ properties).
In addition, if you use strip_html=”1″ inside the MTGoogleSearch tag, it will remove any html that Google replies with, including <b> tags that surround the search query terms.
This is a patch on the default build of Movable Type 2.11. If you’ve already installed my previous patch, it might be easier to just back out the patch and install this one.
By the way, I haven’t done a lot of testing with the MTEntries query code (entries=”1″) so if you do use it, please send me feedback.
Related posts:





I guess I havn’t set up the SOAP module correctly, but I get this error when trying to rebuild my blog:
An error occurred:
Can’t call method “send_receive” on an undefined value at C:/Perl/site/lib/SOAP/Lite.pm line 93.
MT::App::CMS=HASH(0x1a657c8) Use of uninitialized value in sprintf at C:/Perl/site/lib/SOAP/Lite.pm line 1457.
OK…the new excerpt and strip_html didn’t work for me.
Using excerpt=”1″ I get:
500 Internal Server Error at /mt/lib/MT/Template/Context.pm line 1259
And it looks as though strip_html calls remove_html (if I read correctly) and Ben Trott said that command may not work…
Ben: “The only thing I can think of is that may be due to the XML modules installed on your server. If your server is using the XML::Parser::Lite module (part of SOAP::Lite), it doesn’t decode entities, and that could be the issue. The solution is to get your server admin to install XML::Parser. ”
And he’s right…my server uses XML::Parser::Lite
I hope that helps your debugging…
OK…the new excerpt and strip_html didn’t work for me.
Using excerpt=”1″ I get:
500 Internal Server Error at /mt/lib/MT/Template/Context.pm line 1259
And it looks as though strip_html calls remove_html (if I read correctly) and Ben Trott said that command may not work…
Ben: “The only thing I can think of is that may be due to the XML modules installed on your server. If your server is using the XML::Parser::Lite module (part of SOAP::Lite), it doesn’t decode entities, and that could be the issue. The solution is to get your server admin to install XML::Parser. ”
And he’s right…my server uses XML::Parser::Lite
I hope that helps your debugging…
Sorry about that….I didn’t mean to post multiple times, but when I post I didn’t get a result page. Instead I get the following error message:
500 Internal Server Error on context.pm line 1259
Hmmm, I wonder if I overdrew my Google allocation for the day, or if Google had an outage of their SOAP APIs. That server error occurs on the SOAP call to Google.
If you’re using XML::Parser::Lite, then you may be SOL because of the issue you mentioned above. The workaround would be to rewrite remove_html or install the full XML modules in your home directory. strip_html is more selective than remove_html – the remove_html property removes ALL html resulting from the tag, which isn’t what we want – strip_html removes html from the results of the Google search only.
Let’s see if it wasn’t a burp in Google’s service or in my API key, too.
Yup…
perl -MCPAN -e ‘install XML::Parser’
fixed up the line 1259 error for me…
Cool, I just heard back from one of the Movable Type developers that this new feature will be included in their 2.2 release. Dave Winer also links to this, along with a macro for radio to add a “Google It” link to any radio weblog. Actually, that’s not really what this patch does, Dave. For a better Radio Macro, see Jake Savin’s cool hack.
nice article, keep up the good work. lookup zip code