Show
Ignore:
Timestamp:
07/09/08 20:20:27 (17 months ago)
Author:
breese
Message:

bringing the version of StyleCatcher? in the mtplugins repos up to date with what (will) ships with Movable Type 4.2

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/StyleCatcher/plugins/StyleCatcher/stylecatcher.pl

    r100 r817  
    1 # Copyright 2005-2006 Six Apart. This code cannot be redistributed without 
    2 # permission from www.sixapart.com. 
     1# Movable Type (r) Open Source (C) 2005-2008 Six Apart, Ltd. 
     2# This program is distributed under the terms of the 
     3# GNU General Public License, version 2. 
    34# 
    4 # $Id: stylecatcher.pl 32007 2006-06-22 01:11:47Z jallen $ 
     5# $Id: stylecatcher.pl 1568 2008-03-25 00:48:27Z bsmith $ 
    56 
    67package MT::Plugin::StyleCatcher; 
     
    89use strict; 
    910use base 'MT::Plugin'; 
    10 use vars qw($VERSION); 
    11 $VERSION = '1.1-dev'; 
     11our $VERSION = '2.0'; 
    1212 
    1313my $plugin; 
    1414$plugin = MT::Plugin::StyleCatcher->new({ 
     15    id => 'StyleCatcher', 
    1516    name => "StyleCatcher", 
    1617    version => $VERSION, 
    1718    doc_link => "http://www.sixapart.com/movabletype/styles/", 
    18     description => "<MT_TRANS phrase=\"StyleCatcher lets you easily browse through styles and then apply them to your blog in just a few clicks. To find out more about Movable Type styles, or for new sources for styles, visit the <a href='http://www.sixapart.com/movabletype/styles'>Movable Type styles</a> page.\">", 
    19     config_link => "stylecatcher.cgi", 
    20     author_name => "Nick O'Neil, Brad Choate", 
    21     author_link => "http://www.authenticgeek.net/", 
     19    description => q(<MT_TRANS phrase="StyleCatcher lets you easily browse through styles and then apply them to your blog in just a few clicks. To find out more about Movable Type styles, or for new sources for styles, visit the <a href='http://www.sixapart.com/movabletype/styles'>Movable Type styles</a> page.">), 
     20    author_name => "Six Apart, Ltd.", 
     21    author_link => "http://www.sixapart.com/", 
    2222    l10n_class => 'StyleCatcher::L10N', 
    23     config_template => \&configuration_template, 
    24     settings => new MT::PluginSettings([ 
    25         ['webthemeroot'], 
    26         ['themeroot'], 
    27         ['stylelibrary'], 
    28     ]), 
     23    registry => { 
     24        stylecatcher_libraries => { 
     25            'sixapart_mt4' => { 
     26                url => 'http://www.sixapart.com/movabletype/styles/mt4/library', 
     27                label => 'MT 4 Style Library', 
     28                description_label => "A collection of styles compatible with Movable Type 4 default templates.", 
     29                order => 1, 
     30            }, 
     31            # 'sixapart_mt3' => { 
     32            #     url => 'http://www.sixapart.com/movabletype/styles/mt3/library', 
     33            #     label => 'MT 3 Style Library', 
     34            #     description_label => "A collection of styles compatible with Movable Type 3.3+ default templates.", 
     35            #     order => 1000, 
     36            # }, 
     37        }, 
     38        applications => { 
     39            cms => { 
     40                methods => { 
     41                    stylecatcher_theme => '$StyleCatcher::StyleCatcher::CMS::view', 
     42                    stylecatcher_js => '$StyleCatcher::StyleCatcher::CMS::js', 
     43                    stylecatcher_apply => '$StyleCatcher::StyleCatcher::CMS::apply', 
     44                }, 
     45                menus => { 
     46                    'design:theme' => { 
     47                        label => 'Styles', 
     48                        order => 300, 
     49                        mode => 'stylecatcher_theme', 
     50                        view => "blog", 
     51                        permission => 'edit_templates', 
     52                    }, 
     53                }, 
     54            }, 
     55        }, 
     56    }, 
    2957}); 
    3058MT->add_plugin($plugin); 
    31 MT->add_plugin_action('list_template', 'stylecatcher.cgi', 'Select a Design using StyleCatcher'); 
    32 MT->add_plugin_action('blog','stylecatcher.cgi?', "Select a Design using StyleCatcher"); 
    3359 
    3460sub instance { $plugin } 
    3561 
    36 sub configuration_template { 
    37     my $plugin = shift; 
    38     my ($param, $scope) = @_; 
    39  
    40     my $intro; 
    41     if ($scope eq 'system') { 
    42         if (!$param->{webthemeroot}) { 
    43             $param->{webthemeroot} = MT->instance->static_path; 
    44             $param->{webthemeroot} =~ s!/$!!; 
    45             $param->{webthemeroot} .= '/themes/'; 
    46         } 
    47         $param->{themeroot} ||= File::Spec->catdir(MT->instance->mt_dir, 'mt-static', 'themes'); 
    48         $param->{stylelibrary} ||= $StyleCatcher::DEFAULT_STYLE_LIBRARY; 
    49         $intro = q{<MT_TRANS phrase="<p>You must define a global theme repository where themes can be stored locally.  If a particular blog has not been configured for it's own theme paths, it will use these settings directly. If a blog has it's own theme paths, then the theme will be copied to that location when applied to that weblog. The paths defined here must physically exist and be writable by the webserver.</p>">}; 
    50     } else { 
    51  
    52         my $system_plugin_config = $plugin->get_config_hash(); 
    53         unless ($system_plugin_config && $system_plugin_config->{webthemeroot} && $system_plugin_config->{themeroot}) { 
    54             return q{<MT_TRANS phrase="<p style="color: #f00;"><strong>NOTE:</strong> StyleCatcher must first be configured from the system-level plugins listing before it can be used on any blog.</p>">};     
    55           } 
    56              
    57         if (my $blog = MT->instance->blog) { 
    58             if (!$param->{webthemeroot}) { 
    59                 my $url = $blog->site_url; 
    60                 $url =~ s!/$!!; 
    61                 $url .= '/themes/'; 
    62                 $param->{webthemeroot} = $url; 
    63             } 
    64             if (!$param->{themeroot}) { 
    65                 my $path = $blog->site_path; 
    66                 $path = File::Spec->catdir($path, 'themes'); 
    67                 $param->{themeroot} = $path; 
    68             } 
    69         } 
    70         $intro = q{<MT_TRANS phrase="<p>If you wish to store your themes locally for this blog, you can configure your theme URL and path below.  Although downloaded themes will still be stored in the system-level directory, they will be copied to this directory when they are applied. The paths defined here must physically exist and be writable by the webserver.</p>">}; 
    71  
    72     } 
    73  
    74     return qq{ 
    75 $intro 
    76  
    77 <div class="setting"> 
    78 <div class="label"><label for="stycat_webthemeroot"><MT_TRANS phrase="Theme Root URL:"></label></div> 
    79 <div class="field"> 
    80 <input type="text" name="webthemeroot" id="stycat_webthemeroot" value="<TMPL_VAR NAME=WEBTHEMEROOT ESCAPE=HTML>" style="width: 95%" /> 
    81 </div> 
    82 </div> 
    83  
    84 <div class="setting"> 
    85 <div class="label"><label for="stycat_themeroot"><MT_TRANS phrase="Theme Root Path:"></label></div> 
    86 <div class="field"> 
    87 <input type="text" name="themeroot" id="stycat_themeroot" value="<TMPL_VAR NAME=THEMEROOT ESCAPE=HTML>" style="width: 95%" /> 
    88 </div> 
    89 </div> 
    90  
    91 <div class="setting"> 
    92 <div class="label"><label for="stycat_stylelibrary"><MT_TRANS phrase="Style Library URL:"></label></div> 
    93 <div class="field"> 
    94 <input type="text" name="stylelibrary" id="stycat_stylelibrary" value="<TMPL_VAR NAME=STYLELIBRARY ESCAPE=HTML>" style="width: 95%" /> 
    95 </div> 
    96 </div> 
    97     }; 
    98 } 
    99  
    100 sub save_config { 
    101     my $plugin = shift; 
    102     my ($param, $scope) = @_; 
    103     my $themeroot = $param->{themeroot}; 
    104     return 1 unless $themeroot; 
    105  
    106     my $app = MT->instance; 
    107  
    108     require MT::FileMgr; 
    109     my $filemgr = MT::FileMgr->new('Local') 
    110         or return $app->error(MT::FileMgr->errstr); 
    111  
    112     my $base_weblog_path = File::Spec->catfile($plugin->{full_path}, 
    113                                                "base-weblog.css"); 
    114     my $base_weblog = $filemgr->get_data($base_weblog_path); 
    115     $filemgr->mkpath($param->{themeroot}) 
    116         or die $plugin->translate("Unable to create the theme root directory. Error: [_1]", $filemgr->errstr); 
    117  
    118     defined($filemgr->put_data($base_weblog, 
    119         File::Spec->catfile($param->{themeroot}, "base-weblog.css"))) 
    120         or die $plugin->translate("Unable to write base-weblog.css to themeroot. File Manager gave the error: [_1]. Are you sure your theme root directory is web-server writable?", $filemgr->errstr); 
    121  
    122     return $plugin->SUPER::save_config(@_); 
    123 } 
    124  
    125621;