« Showing names instead of NSIDs | Main | more work on MT 3.2 »

September 28, 2005

Fixing Movable Type StyleCatcher

StyleCatcher is a template picker for Movable Type 3.2. It lets authors easily change the look and feel of their blogs by choosing templates from a library.

It sounds great but I had to go through some hoops to get it to work
on our test system. It is not yet available on blogs.usask.ca.

The StyleCatcher 1.01 README.txt file says installation consists of
copying the appropriate files into your "plugins" and "mt-static"
directories and setting permissions. But there's a bit more to it than that.

Once you've installed the plugin, you have to login to MT as an administrator, go to the PLUGINS page, and configure the StyleCatchter plugin (select "Show Settings").

There are two settings:

Theme Root URL:
Theme Root Path:

The latter is the path to the "themes" folder that you need to create. The former is the URL for this folder. For example:

Theme Root URL: /mt/mt-static/themes
Theme Root Path: /var/www/html/mt/mt-static/themes

Make sure you set permissions on this folder so the web server can write to it, as this is where StyleCatcher will store themes that
it downloads.

I had some trouble with this, because StyleCatcher filled in these two fields for me, and it chose the wrong URL which meant it couldn't find any local themes.

To test local themes, download a theme from the Movable Type Styles Library (http://www.sixapart.com/movabletype/styles/library) and
unpack it into your themes folder.

At this point, you should be able to go into StyleCatcher and see the themes you've downloaded, and apply them to your blogs.

You can get into StyleCatcher by selecting it from the list of
PLUGINS on the right side of the MT main screen. There is also a "Select a design using StyleCatcher" link at the bottom of the Templates screen for each blog.

Getting remote themes to work was a challenge.

UPDATE: Thanks to Jay Allen and Brad Choate at
Sixapart, we determined that the problem I encountered was due
to an old version of the libwww-perl (LWP) perl library. I've
upgraded to the latest version of LWP, and StyleCatcher is working
great. There's no reason for anyone to use my StyleCatcher patch
unless you are stuck with an old version of LWP and can't upgrade.

The StyleCatcher 1.01 code just plain doesn't work. It couldn't find any themes in the Movable Type Styles Library. I don't know why it's broken, but it's broken. So I fixed it.

So, if you install StyleCatcher and you can't see any remote themes, try this: make a backup of your StyleCatcher.pm file and then change these lines:

diff -c StyleCatcher.pm.orig StyleCatcher.pm
*** StyleCatcher.pm.orig        Mon Sep 26 16:32:03 2005
--- StyleCatcher.pm     Tue Sep 27 13:09:33 2005
***************
*** 386,408 ****
              $data->{themes} = [ $theme ];
          } elsif ($type =~ m!^text/html!) {
              my @repo_themes;
!             for my $link (ref($response->headers->{'link'}) eq 'ARRAY'
!                               ? @{ $response->headers->{'link'} }
!                               :    $response->headers->{'link'}  ) {
!                 my ($css, @parsed_link) = split(/;/, $link);
!                 $css =~ s/[<>]//g;
!                 my %attr;
!                 foreach (@parsed_link) {
!                     my ($name, $val) = split /=/, $_, 2;
!                     $name =~ s/^ //;
!                     $val =~ s/^['"]|['"]$//g;
!                     next if $name eq '/';
!                     $attr{lc($name)} = $val;
!                 }
!                 next unless lc $attr{rel} eq 'theme';
!                 next unless lc $attr{type} eq 'text/x-theme';
!                 push @repo_themes, $css;
!             }

my $themes = [];
for my $repo_theme (@repo_themes) {
--- 386,399 ----
$data->{themes} = [ $theme ];
} elsif ($type =~ m!^text/html!) {
my @repo_themes;
! my $c = $response->content;
! while ($c =~ m#<link([^>]+)<#g) {
! my $tags = $1;
! next unless $tags =~ m#rel=['"]?theme#i;
! next unless $tags =~ m#type=['"]?text/x-theme#i;
! my $href = $1 if $tags =~ m#\bhref=["']?([^\s"']+)#;
! push @repo_themes, $href;
! }

my $themes = [];
for my $repo_theme (@repo_themes) {

Posted by elf123 at September 28, 2005 03:43 PM     Topic(s): Technical

Comments

Hey --
I just tried to make the above changes in StyleCatcher.pm and now the plugin throws this error when I run it:

"Unmatched ) before HERE mark in regex m/]+) / at lib/StyleCatcher.pm line 396."

For reference, this is the line that I have on 396:

while ($c =~ m#]+)>#g) {

It looks like the ) in the "+)>" part is causing the regex to fail. Did you run into this in your testing?

Thanks so much for looking into this!

Posted by: Jason Lefkowitz at September 30, 2005 02:49 PM

Hi Jason,

It looks like a bit of code in angle brackets
was stripped out when I posted it. Here's
the way the line should look:

while ($c =~ m#<link([^>]+)>#g) {

That is, after the "m#" you should see a less-than sign,
then "link([^" then a greater-than sign.

Posted by: Earl Fogel at October 1, 2005 01:44 PM

Earl wrote: The StyleCatcher 1.01 code just plain doesn't work. It couldn't find any themes in the Movable Type Styles Library. I don't know why it's broken, but it's broken. So I fixed it.

This makes no sense to me. How can you not know why something is broken and still fix it? I (and many many many other people) have had no problem using the plugin, so I suspect that your server must be missing some prerequisite.

Were you getting some sort of error message in your server's error logs? What was the symptom you were experiencing? If there's a bug, we'd like to fix it, but before we do, we need to understand what it is. Since I've not heard of anyone else having problems (other than you and Jason), I can't imagine that it's only the fault of the plugin.

Send me an email. You have my address.

Posted by: Jay Allen at October 2, 2005 12:22 PM

I replied to Jay by email.

Hopefully they can figure out why StyleCatcher as distributed didn't work for Jason and myself, and
come out with a proper fix.

In the meantime, if you can't browse any remote themes with StyleCatcher, feel free to try my patch to see if it helps.

Posted by: Earl Fogel at October 3, 2005 11:01 AM

The HTML::HeadParser included with LWP version 5.01 and later parses out the "link" tags and puts the contents into the headers. Either you have an older version installed or something is wrong with that package.

Posted by: Brad Choate at October 4, 2005 09:51 AM

(LWP 5.01 was released August, 1996.)

Posted by: Brad Choate at October 4, 2005 09:58 AM

Hi Brad,

We have LWP 5.47, so it should be recent enough to handle the "link" tags. I'll try upgrading to a later version anyway, and we'll see what happens.

Earl

Posted by: Earl Fogel at October 4, 2005 10:13 AM

I've upgraded to LWP 5.803 and StyleCatcher works!

Brad and Jay: thanks for all your help.

Earl

Posted by: Earl Fogel at October 4, 2005 11:07 AM

Hi, I have different problem here.
I install folders in mt-static and plugins folders, I can log in and set the themes path, but I can't click "more settings". It shows "Please configure the settings for this plugin before using it."
I have found many articles on Movable Type Forum, but no related problems had been solved.
I wonder if you can help me with this.
Thank you.

Posted by: DDK at October 5, 2005 09:58 PM

Hi,

You have to "Show Settings" once to check your Theme Root URL and Path, and press the "Save Changes" button to store them in the MT database before you
can access "More Settings".

Also, make sure you are logged into MT as a user with System Administrator privileges, or you won't
see the settings options at all.

Posted by: Earl Fogel at October 6, 2005 09:11 AM

After hours of frustration, I finaaly found your solution...knowing that I can't update my LWP I really hoped your code would do it for me, however, I get this error:

Can't use global $1 in "my" at lib/StyleCatcher.pm line 391.

Do you have any solutions for this? You are pretty much the last strand of hope.

Regards,
Marius

Posted by: Marius at October 10, 2005 02:53 AM

Hello Marius,

I'll e-mail you a copy of my modified StyleCatcher.pm file so you can see if it is the same as yours.

Posted by: Earl Fogel at October 11, 2005 10:18 AM

Hi,

maybe you could be so kind to mail me a copy of your modified StyleCatcher.pm, too ?

Regards,
Tim

Posted by: Tim at October 16, 2005 02:57 PM

Sure.

Posted by: Earl Fogel at October 17, 2005 09:47 AM

I am also having problem with my styplecatcher.pm. HTTPD log complained premature end of script head. Would appreciate if you could put the full pm file for public download. Thanks!

Posted by: G at October 17, 2005 02:51 PM

I do not want to make it too easy for people to download my modified StyleCatcher.pm because the preferred solution to this problem is to upgrade your Perl LWP library.

Were you getting that "premature end of script headers" with the original StyleCatcher, or just after applying my patch?

If the patch is causing you grief, I will mail you a copy of my modified StyleCatcher.pm.

Posted by: Earl Fogel at October 17, 2005 03:36 PM

The problem was with the original version of stypecatcher. I don't have SSH access to the linux host so I did not know if it was due to obsolete LWP. The original version however worked fine on my testing machine with windows os and defalt active perl 5.8 installation. The error log on the linux host is as follows

[Tue Oct 18 04:05:06 2005] [error] [client xx.xx.xx.xx] Premature end of script headers: /hsphere/local/home/xxxx/xxxx.net/mt/plugins/StyleCatcher/stylecatcher.cgi

Posted by: G at October 18, 2005 09:22 AM

The "Premature end of script headers" indicates that the script is likely not running at all. Without ssh access to the box, this will be difficult to debug, but here are a few things to check:

Check that the file is executable.

Check that the path-to-perl on the first line is correct.

Check that you did not upload the file in binary mode. Otherwise you'll have Windows characters at the end of each line instead of
the unix that Perl expects.

Earl

Posted by: Earl Fogel at October 19, 2005 01:21 PM

Thanks for the tips. I eventually discovered that by changing the permissions from 777 (+rwxrwxrwx) to 755 (+rwxr-xr-x) of the .cgi/.pl and the StyleCatcher directory fixed it up. This seems to be the biggest puzzle in my life but thankfully it worked (in a strange way)!

Posted by: G at October 19, 2005 03:38 PM

excellent tutorial...everything went smoothly in terms of installing the plugin and configuring the settings, but my original blog is not updated with the new theme I selected...advice?

Posted by: SiNing at October 27, 2005 01:31 AM

OK, this time I associated my blog index.html file to the style, refreshed my browser and it updated, but everything's centered and I don't see the blog text on the first page...I will play around with it...

Posted by: SiNing at October 27, 2005 01:37 AM

Hey, I really appreciate knowing that, although I might be slow to upgrade or adopt plugins, that I'm not the only person with a problem with this plugin.

It's been driving me crazy for about a week now, and your blog is the first one I've found in my searching that lays out what I need to do.

If only I could upgrade the Perl installation...sadly, I do not have this ability.

Posted by: Nathan Dornbrook at December 6, 2005 04:20 PM

hello Earl,

I got the same problem with you, I couldn't remote the theme that I choosed. I used LWP 5.8.6 but still not working. Maybe you could be so kind to mail me a copy of your modified StyleCatcher.pm, too ? thx you so much...

Posted by: Anita at December 31, 2005 05:14 PM

Hi Anita,

I'll send it, but from your description I suspect it won't help.

Earl

Posted by: Earl Fogel at January 1, 2006 10:14 AM

Thanks for the tips. With the modification from your comments it solved my issues.

Posted by: the tenth letter of the alphabet at April 28, 2006 05:16 PM

I got a 500 error. :( I'm not sure what to do. I hope u can shed some light onto how to get stylecatcher to work... all the necessary files are set to 755 . it's on dreamhost hosting.

Posted by: duck at July 14, 2006 04:36 AM

NEED HELP!
I'm using a MediaTemple account with the MT setup.
I have done no upgrades since the install. I have a simple test blog with 2 entries set up. I've sucessfully altered the CSS through the MT CMS and changed the style. I then reverted all templates back to the original instal. I installed the StyleCatcher Version 1.01 plugin by using the readme directions. no go. i then read your path correcitons/add templates folders to my URL. no go. the error im receiving is:

[error] [client 72.47.10.250] Premature end of script headers: stylecatcher.cgi, referer: http://www.thingsthatarepissingmeoff.com/movabletype/mt.cgi?__mode=list&_type=template&blog_id=1
[Sun Aug 27 15:32:46 2006]

[error] [client 72.47.10.250] File does not exist: /home/virtual/site30/fst/var/www/html/favicon.ico

so now, 4 hours later, im pulling my hair out.

can you help in any way?


Posted by: jgrassman at August 27, 2006 05:08 PM

G, above had the solution that worked for me.

I didn't need to alter any codes or do anything else... All I needed to do was change permissions for the following files in my cgi-bin:

plugins/StyleCatcher (entire folder/directory)
plugins/StyleCatcher/stylecatcher.cgi
plugins/StyleCatcher/stylecatcher.pl

to 755

... and it worked. I was able to finally see the templates! Thanks, G.

Posted by: Jaye at October 15, 2006 03:46 PM