Changeset 873

Show
Ignore:
Timestamp:
12/10/06 13:00:44 (2 years ago)
Author:
fumiakiy
Message:

Implemented automatic creation of mtview.php. mt-upgrade now removes the Dynamic Boot Strapper, and it is no longer one of the default templates. Also added is the option to 'build all templates dynamically'. BugId: 32010

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/wheeljack/lib/MT/App/CMS.pm

    r872 r873  
    7272        'cfg_archives' => \&cfg_archives, 
    7373        'cfg_archives_do_add' => \&cfg_archives_do_add, 
     74        'js_check_mtview' => \&js_check_mtview, 
    7475        'cfg_prefs' => \&cfg_prefs, 
    7576        'cfg_entries' => \&cfg_entries, 
     
    43884389    if ($screen eq 'cfg_archives') { 
    43894390        if (my $dcty = $app->param('dynamicity')) { 
    4390             $app->update_dynamicity($obj); 
     4391            $app->update_dynamicity($obj,  
     4392                $app->param('dynamic_cache') ? 1 : 0,  
     4393                $app->param('dynamic_conditional') ? 1 : 0); 
    43914394        } 
    43924395        $app->cfg_archives_save($obj); 
     
    81948197        $blog->custom_dynamic_templates eq 'archives'; 
    81958198    $param{dynamic_custom} = $blog->custom_dynamic_templates eq 'custom'; 
     8199    $param{dynamic_all} = $blog->custom_dynamic_templates eq 'all'; 
    81968200    $param{show_build_options} = $app->config('ObjectDriver') =~ m/^DBI::(postgres|sqlite|mysql)/; 
    81978201    $iter = MT::Template->load_iter({ blog_id => $blog->id }); 
     
    1021010214sub update_dynamicity { 
    1021110215    my $app = shift; 
    10212     my ($blog) = @_; 
     10216    my ($blog, $cache, $conditional) = @_; 
    1021310217    my $dcty = $blog->custom_dynamic_templates; 
    1021410218    if ($dcty eq 'none') { 
     
    1022710231        } 
    1022810232    } elsif ($dcty eq 'custom') { 
     10233    } elsif ($dcty eq 'all') { 
     10234        require MT::Template; 
     10235        my @templates = MT::Template->load({ 
     10236            blog_id => $blog->id, 
     10237            type => [ 'index', 'archive', 'individual', 'category' ], 
     10238        }); 
     10239        for my $tmpl (@templates) { 
     10240            $tmpl->build_dynamic(1); 
     10241            $tmpl->save(); 
     10242        } 
    1022910243    } 
    1023010244 
     
    1024210256            my $contents = ""; 
    1024310257            if (open(HT, $htaccess_path)) { 
    10244                 $/ = undef; 
     10258                local $/ = undef; 
    1024510259                $contents = <HT>; 
    1024610260                close HT; 
     
    1030110315        }; if ($@) { print STDERR $@; }  
    1030210316         
     10317        eval { 
     10318            my $mtview_path = File::Spec->catfile($blog->site_path(), "mtview.php"); 
     10319            my $mv_contents = ''; 
     10320            if (-f $mtview_path) { 
     10321                open(my $mv, "<$mtview_path"); 
     10322                while (my $line = <$mv>) { 
     10323                    $mv_contents .= "//$line" if ($line !~ /<\?(?:php)?|\?>/); 
     10324                } 
     10325                close $mv; 
     10326            } 
     10327            my $cgi_path = MT->instance->server_path() || ""; 
     10328            $cgi_path =~ s!/*$!!; 
     10329            my $mtphp_path = File::Spec->canonpath("$cgi_path/php/mt.php"); 
     10330            my $blog_id = $blog->id; 
     10331            my $config = MT->instance->{cfg_file}; 
     10332            my $cache_code = $cache ? "\n    \$mt->caching = true;" : ''; 
     10333            my $conditional_code = $conditional ? "\n    \$mt->conditional = true;" : ''; 
     10334            my $mtview = <<MTVIEW; 
     10335<?php 
     10336$mv_contents 
     10337    include('$mtphp_path'); 
     10338    \$mt = new MT($blog_id, '$config');$cache_code$conditional_code 
     10339    \$mt->view(); 
     10340?> 
     10341MTVIEW 
     10342            $blog->file_mgr->mkpath($blog->site_path); 
     10343 
     10344            open(my $mv, ">$mtview_path") 
     10345                || die "Couldn't open $mtview_path for appending"; 
     10346            print $mv $mtview || die "Couldn't write to $mtview_path"; 
     10347            close $mv; 
     10348        }; if ($@) { print STDERR $@; }  
     10349 
    1030310350        my $compiled_template_path = File::Spec->catfile($blog->site_path(),  
    1030410351                                                         'templates_c'); 
     
    1031610363        } 
    1031710364            # FIXME: use FileMgr 
     10365 
     10366        if ($cache) { 
     10367            my $cache_path = File::Spec->catfile($blog->site_path(), 'cache'); 
     10368            $app->config('DirUmask', '0000'); 
     10369            $fmgr->mkpath($cache_path); 
     10370            $app->config('DirUmask', $saved_umask); 
     10371            if (-d $cache_path) { 
     10372                $app->add_return_arg('no_write_cachepath' => 1) 
     10373                    unless (-w $cache_path); 
     10374            } else { 
     10375                $app->add_return_arg('no_cachepath' => 1) 
     10376                    unless (-d $cache_path); 
     10377            } 
     10378        } 
    1031810379    } 
    1031910380    $app->add_return_arg(dynamic_set => 1); 
     10381} 
     10382 
     10383sub js_check_mtview { 
     10384    my $app = shift; 
     10385    $app->validate_magic or return; 
     10386    my $blog_id = $app->param('blog_id'); 
     10387    my $blog = MT::Blog->load($blog_id, { cached_ok => 1 }); 
     10388    return $app->errtrans('Blog (ID: [_1]) can\'t be found', $blog_id) if !defined($blog); 
     10389 
     10390    my $cache = 0; 
     10391    my $conditional = 0; 
     10392    my $mtview_path = File::Spec->catfile($blog->site_path(), "mtview.php"); 
     10393    if (-f $mtview_path) { 
     10394        open my($fh), $mtview_path; 
     10395        while (my $line = <$fh>) { 
     10396            $cache = 1 if $line =~ m/^\s*\$mt->caching\s*=\s*true;/i; 
     10397            $conditional = 1 if $line =~ /^\s*\$mt->conditional\s*=\s*true;/i; 
     10398        } 
     10399        close $fh; 
     10400    } 
     10401    $app->send_http_header('text/javascript'); 
     10402    $app->{no_print_body} = 1; 
     10403    $app->print("{cache: $cache, conditional: $conditional}"); 
    1032010404} 
    1032110405 
     
    1085010934    $param{targz} = $@ ? 0 : 1; 
    1085110935    eval "require Archive::Zip;"; 
     10936    eval "require IO::String;"; 
    1085210937    $param{zip} = $@ ? 0 : 1; 
     10938 
    1085310939    $app->build_page('backup_restore.tmpl', \%param); 
    1085410940} 
  • branches/wheeljack/lib/MT/DefaultTemplates.pm

    r855 r873  
    1616            'type' => 'index', 
    1717            'rebuild_me' => '1' 
    18           }, 
    19           { 
    20               'outfile' => 'mtview.php', 
    21               'name' => 'Dynamic Site Bootstrapper', 
    22               'type' => 'index', 
    23               'rebuild_me' => 1, 
    2418          }, 
    2519          { 
  • branches/wheeljack/lib/MT/L10N/ja.pm

    r722 r873  
    23872387¥åŠ›ã—ãªã„ã§ãã ã•ã„ã€‚', 
    23882388    'Dynamic Publishing:' => '再構築オプション: ', 
    2389     'Build all templates statically' => 'すべおをスタティックHTMLで出力したす', 
    2390     'Build only Archive Templates dynamically' => 'アヌカむブのみダむナミック・パブリッシングで出力したす', 
    2391     'Set each template\'s Build Options separately' => 'テンプレヌト別に、スタティックHTMLもしくはダむナミック・パブリッシングを遞択したす', 
     2389    'Build all templates statically' => 'すべおスタティックHTMLで出力', 
     2390    'Build only Archive Templates dynamically' => 'アヌカむブのみダむナミック・パブリッシング', 
     2391    'Set each template\'s Build Options separately' => 'テンプレヌトごずに遞択', 
     2392    'Build all templates dynamically' => 'すべおダむナミック・パブリッシング', 
    23922393    'Archive Mapping' => 'アヌカむブ・マッピング', 
    23932394    '_USAGE_ARCHIVE_MAPS' => 'この画面では、各アヌカむブに耇数のテンプレヌトを蚭定するこずができたす。䟋えば、月別のアヌカむブを2぀䜜り、1぀は1か月分の゚ントリヌのリストにしお、もう1぀は、カレンダヌのように゚ントリヌを芋られるようにする、ずいったこずができたす。', 
  • branches/wheeljack/lib/MT/Upgrade.pm

    r863 r873  
    566566            } 
    567567        }, 
     568        'core_remove_dynamic_site_bootstrapper' => { 
     569            code => \&remove_mtviewphp, 
     570            version_limit => 3.303, 
     571            priority => 5.1, 
     572        }, 
    568573    ); 
    569574} 
     
    10311036    } 
    10321037 
     1038    1; 
     1039} 
     1040 
     1041sub remove_mtviewphp { 
     1042    my $self = shift; 
     1043    my (%param) = @_; 
     1044 
     1045    require MT::Template; 
     1046    $self->progress(MT->translate('Removing Dynamic Site Bootstrapper index template...')); 
     1047    MT::Template->remove( { type => 'index', outfile => 'mtview.php' } ); 
    10331048    1; 
    10341049} 
  • branches/wheeljack/tmpl/cms/cfg_archives.tmpl

    r812 r873  
    22 
    33<div id="cfg-archives"> 
     4<script type="text/javascript" src="<TMPL_VAR NAME=STATIC_URI>js/tc/client.js"></script> 
    45 
    56<script type="text/javascript"> 
     
    113114} 
    114115 
     116function toggleDynamicOptions(selection) { 
     117    var fld = getByID('dynamic_options_area'); 
     118    if (fld) { 
     119        if (selection.value == 'none') { 
     120            fld.style.display = 'none'; 
     121        } else { 
     122            fld.style.display = 'block'; 
     123            TC.Client.call({ 
     124                'load': function(c, response) { 
     125                    var result; 
     126                    try { 
     127                        result = eval('('+response+')'); 
     128                        var cache = getByID("dynamic_cache"); 
     129                        if (cache) 
     130                            cache.checked = result.cache; 
     131                        var condition = getByID("dynamic_conditional"); 
     132                        if (condition) 
     133                            condition.checked = result.conditional; 
     134                        var progress = getByID("progress-bar"); 
     135                        if (progress) { 
     136                            progress.style.display = "none"; 
     137                        } else { 
     138                        } 
     139                        var area = getByID('dynamic_options'); 
     140                        if (area) { 
     141                            area.style.display = "block"; 
     142                        } 
     143                    } catch ( e ) { 
     144                        alert(e.message); 
     145                    } 
     146                }, 
     147                'method': 'POST', 
     148                'uri': '<TMPL_VAR NAME=MT_URL>', 
     149                'arguments': { '__mode': 'js_check_mtview', 
     150                    'blog_id': '<TMPL_VAR NAME=BLOG_ID>', 
     151                    'magic_token': '<TMPL_VAR NAME=MAGIC_TOKEN>'} 
     152            }); 
     153        } 
     154    } 
     155    return false; 
     156} 
    115157//--> 
    116158</script> 
     
    158200<TMPL_ELSE> 
    159201 
     202<TMPL_IF NAME=NO_CACHE_PATH> 
     203<div class="error-message"><MT_TRANS phrase="Error: Movable Type was not able to create a directory to cache your dynamic templates. You should create a directory called <code>[_1]</code> underneath your blog directory." params="cache"></div> 
     204 
     205<TMPL_ELSE> 
     206 
     207<TMPL_IF NAME=NO_WRITE_CACHE_PATH> 
     208<div class="error-message"><MT_TRANS phrase="Error: Movable Type cannot write to the template cache directory. Please check the permissions for the directory called <code>[_1]</code> underneath your blog directory." params="cache"></div> 
     209 
     210<TMPL_ELSE> 
     211 
    160212<TMPL_IF NAME=SAVED> 
    161213<div class="message"><MT_TRANS phrase="Your weblog's archive configuration has been saved."> 
     
    164216</TMPL_IF> 
    165217<br /><TMPL_INCLUDE NAME="rebuild-stub.tmpl"></div> 
     218</TMPL_IF> 
     219</TMPL_IF> 
    166220</TMPL_IF> 
    167221</TMPL_IF> 
     
    301355<TMPL_IF NAME=SHOW_BUILD_OPTIONS> 
    302356<div class="setting"> 
    303 <div class="label"><label for="dynamicity"><MT_TRANS phrase="Dynamic Publishing:"></label>  <a href="#" onclick="return openManual('blog_settings_publishing', 'dynamic_publishing')" class="help">?</a></div> 
    304 <div class="field"> 
    305 <ul> 
    306 <li><input type="radio" id="dynamic_none" name="dynamicity" value="none"<TMPL_IF NAME=DYNAMIC_NONE> checked="on"</TMPL_IF> class="rb" /> <label for="dynamic_none"><MT_TRANS phrase="Build all templates statically"></label></li> 
    307 <li><input type="radio" id="dynamic_archives" name="dynamicity" value="archives"<TMPL_IF NAME=DYNAMIC_ARCHIVES> checked="checked"</TMPL_IF> class="rb" /> <label for="dynamic_archives"><MT_TRANS phrase="Build only Archive Templates dynamically"></label></li> 
    308 <li><input type="radio" id="dynamic_custom" name="dynamicity" value="custom"<TMPL_IF NAME=DYNAMIC_CUSTOM> checked="checked"</TMPL_IF> class="rb" /> <label for="dynamic_custom"><MT_TRANS phrase="Set each template's Build Options separately"></label></li> 
    309 </ul> 
     357<div class="label"><label for="dynamicity"><MT_TRANS phrase="Dynamic Publishing:"></label></div> 
     358<div class="field"> 
     359<select name="dynamicity" id="dynamicity" onchange="return toggleDynamicOptions(this)"> 
     360<option value="none"<TMPL_IF NAME=DYNAMIC_NONE> selected="selected"</TMPL_IF>><MT_TRANS phrase="Build all templates statically"></option> 
     361<option value="archives"<TMPL_IF NAME=DYNAMIC_ARCHIVES> selected="selected"</TMPL_IF>><MT_TRANS phrase="Build only Archive Templates dynamically"></option> 
     362<option value="custom"<TMPL_IF NAME=DYNAMIC_CUSTOM> selected="selected"</TMPL_IF>><MT_TRANS phrase="Set each template's Build Options separately"></option> 
     363<option value="all"<TMPL_IF NAME=DYNAMIC_ALL> selected="selected"</TMPL_IF>><MT_TRANS phrase="Build all templates dynamically"></option> 
     364</select> 
     365<div id="dynamic_options_area" style="display:none;"> 
     366<div id="progress-bar"><p><img src="<TMPL_VAR NAME=STATIC_URI>images/indeterminate-progress-bar.gif" alt="" height="24" width="124" /></p></div> 
     367<div id="dynamic_options" style="display:none;"> 
     368<p><MT_TRANS phrase="Optional Settings for Dynamic Publishing:"> <a href="#" onclick="return openManual('blog_settings_publishing', 'dynamic_publishing_options')" class="help">?</a></p> 
     369<div class="field"> 
     370<input type="checkbox" id="dynamic_cache" name="dynamic_cache" /><label for="dynamic_cache"><MT_TRANS phrase="Enable caching"></label> <input type="checkbox" id="dynamic_conditional" name="dynamic_conditional" /><label for="dynamic_conditional"><MT_TRANS phrase="Enable conditional retrieval"></label> 
     371</div> 
     372</div><a href="#" onclick="return openManual('blog_settings_publishing', 'dynamic_publishing')" class="help">?</a> 
    310373</div> 
    311374</div>