Changeset 1949

Show
Ignore:
Timestamp:
04/17/08 13:11:31 (4 months ago)
Author:
takayama
Message:

Fixed BugId:75137
* Changed to using cache_key for include cache directory

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-35/lib/MT/Blog.pm

    r1945 r1949  
    379379sub include_path_parts { 
    380380    my $blog = shift; 
    381     my ($name) = @_; 
    382  
    383     my $filestem = MT::Util::dirify($name)
     381    my ($param) = @_; 
     382 
     383    my $filestem = MT::Util::dirify($param->{name}) || 'template_'.$param->{id}
    384384    my $filename = join q{.}, $filestem, $blog->file_extension; 
    385     return (MT->config('IncludesDir'), substr($filestem, 0, 3), $filename); 
     385    my $path = $param->{path} || ''; 
     386    my @path; 
     387    if ($path =~ m!^/!) { 
     388        # absolute 
     389        @path = split /\//, $path; 
     390    } else { 
     391        # relative 
     392        push @path, MT->config('IncludesDir'); 
     393        push @path, split /\//, $path; 
     394    } 
     395    return ($filename, @path); 
    386396} 
    387397 
    388398sub include_path { 
    389399    my $blog = shift; 
    390     my ($name) = @_; 
    391  
    392     my @parts = $blog->include_path_parts($name); 
    393     my $filename = pop @parts; 
    394     my $path = File::Spec->catdir($blog->site_path, @parts); 
    395     my $file_path = File::Spec->catfile($path, $filename); 
    396     return wantarray ? ($path, $file_path) : $file_path; 
     400 
     401    my ($filename, @path) = $blog->include_path_parts(@_); 
     402    my $extra_path = File::Spec->catdir(@path); 
     403    my $full_path = File::Spec->catdir($blog->site_path, $extra_path); 
     404    my $file_path = File::Spec->catfile($full_path, $filename); 
     405    return wantarray ? ($file_path, $full_path, $filename) : $file_path; 
    397406} 
    398407 
    399408sub include_url { 
    400409    my $blog = shift; 
    401     my ($name) = @_; 
    402  
    403     my @parts = $blog->include_path_parts(); 
    404     my $url = join q{/}, $blog->site_url, @parts; 
     410 
     411    my ($filename, @path) = $blog->include_path_parts(@_); 
     412    my $url = join q{/}, $blog->site_url, @path, $filename; 
    405413    return $url; 
    406414} 
     
    408416sub include_statement { 
    409417    my $blog = shift; 
    410     my ($name) = @_; 
    411418 
    412419    my $system = $blog->include_system or return; 
     
    416423        $statement = q{<!--#include virtual="%s" -->}; 
    417424 
     425        my ($filename, @path) = $blog->include_path_parts(@_); 
    418426        my $site_url = $blog->site_url; 
    419427        $site_url =~ s{ \A \w+ :// [^/]+ }{}xms; 
    420428        $site_url =~ s{ / \z }{}xms; 
    421         $include = join q{/}, $site_url, $blog->include_path_parts($name)
     429        $include = join q{/}, $site_url, @path, $filename
    422430    } 
    423431    else { 
    424         $include = $blog->include_path($name); 
     432        $include = $blog->include_path(@_); 
    425433        $statement = $system eq 'php'   ? q{<?php include("%s") ?>} 
    426434                   : $system eq 'jsp'   ? q{<%@ include file="%s" %>} 
  • branches/release-35/lib/MT/CMS/Template.pm

    r1913 r1949  
    474474        if ($blog) { 
    475475            $param->{include_with_ssi}      = 0; 
     476            $param->{cache_path}            = ''; 
    476477            $param->{cache_enabled}         = 0; 
    477478            $param->{cache_expire_type}     = 0; 
     
    483484            $param->{include_with_ssi} = $obj->include_with_ssi 
    484485              if defined $obj->include_with_ssi; 
     486            $param->{cache_path}       = $obj->cache_path 
     487              if defined $obj->cache_path; 
    485488            $param->{cache_enabled} = $obj->use_cache 
    486489              if defined $obj->use_cache; 
     
    12371240    # module caching 
    12381241    $obj->include_with_ssi( $app->param('include_with_ssi') ? 1 : 0 ); 
     1242    $obj->cache_path( $app->param('cache_path')); 
    12391243    $obj->use_cache( $app->param('cache_enabled')           ? 1 : 0 ); 
    12401244    my $cache_expire_type = $app->param('cache_expire_type'); 
  • branches/release-35/lib/MT/Template.pm

    r1937 r1949  
    4444        'cache_expire_interval' => 'integer meta', 
    4545        'cache_expire_event' => 'string meta', 
     46        'cache_path' => 'string meta', 
    4647    }, 
    4748    indexes => { 
  • branches/release-35/lib/MT/Template/ContextHandlers.pm

    r1926 r1949  
    23282328    my $blog = $ctx->stash('blog') || MT->model('blog')->load($blog_id); 
    23292329 
     2330    my %include_recipe; 
    23302331    my $use_ssi = $blog && $blog->include_system 
    23312332        && ($arg->{ssi} || $tmpl->include_with_ssi) ? 1 : 0; 
     
    23342335        # easiest way to determine this is from the variable 
    23352336        # space setting. 
    2336         $use_ssi = 0 if $ctx->var('system_template'); 
     2337        if ($ctx->var('system_template')) { 
     2338            $use_ssi = 0; 
     2339        } else { 
     2340            my $extra_path = $arg->{cache_key} ? $arg->{cache_key} 
     2341                : $tmpl->cache_path ? $tmpl->cache_path 
     2342                    : ''; 
     2343           %include_recipe = ( 
     2344                name => $tmpl_name, 
     2345                id   => $tmpl->id, 
     2346                path => $extra_path, 
     2347            ); 
     2348        } 
    23372349    } 
    23382350 
     
    23422354      && $blog->include_cache 
    23432355      && ( ( $arg->{cache} && $arg->{cache} > 0 ) 
    2344         || $arg->{key} 
     2356        || $arg->{cache_key} 
    23452357        || ( exists $arg->{ttl} ) 
    23462358        || $tmpl->use_cache ) ? 1 : 0; 
    23472359    my $cache_key = 
    2348         $arg->{key} 
    2349       ? $arg->{key} 
     2360        $arg->{cache_key} 
     2361      ? $arg->{cache_key} 
    23502362      : 'blog::' . $blog_id . '::template_' . $type . '::' . $tmpl_name; 
    23512363    my $ttl = 
     
    23622374                if ($use_ssi) { 
    23632375                    # base cache expiration on physical file timestamp 
    2364                     my $include_name = $arg->{key} || $tmpl_name
    2365                     my $mtime = (stat($blog->include_path($include_name)))[9]; 
     2376                    my $include_file = $blog->include_path(\%include_recipe)
     2377                    my $mtime = (stat($include_file))[9]; 
    23662378                    if ($mtime && (MT::Util::ts2epoch(undef, $latest) > $mtime ) ) { 
    23672379                        $ttl = 1; # bound to force an update 
     
    23882400            return $cache_value if !$use_ssi; 
    23892401 
    2390             my $include_name = $arg->{key} || $tmpl_name; 
    23912402            # The template may still be cached from before we were using SSI 
    23922403            # for this template, so check that it's also on disk. 
    2393             my ($path, $file_path) = $blog->include_path($include_name); 
    2394             if ($blog->file_mgr->exists($file_path)) { 
    2395                 return $blog->include_statement($include_name); 
     2404            my $include_file = $blog->include_path(\%include_recipe); 
     2405            if ($blog->file_mgr->exists($include_file)) { 
     2406                return $blog->include_statement(\%include_recipe); 
    23962407            } 
    23972408        } 
     
    24242435 
    24252436    if ($use_ssi) { 
    2426         my $include_name = $arg->{key} || $tmpl_name; 
     2437        my ($include_file, $path, $filename) = 
     2438            $blog->include_path(\%include_recipe); 
    24272439        my $fmgr = $blog->file_mgr; 
    2428         my ($path, $file_path) = $blog->include_path($include_name); 
    24292440        if (!$fmgr->exists($path)) { 
    24302441            if (!$fmgr->mkpath($path)) { 
     
    24332444            } 
    24342445        } 
    2435         defined($fmgr->put_data($ret, $file_path)) 
     2446        defined($fmgr->put_data($ret, $include_file)) 
    24362447            or return $ctx->error(MT->translate("Writing to '[_1]' failed: [_2]", 
    2437                 $file_path, $fmgr->errstr)); 
     2448                $include_file, $fmgr->errstr)); 
    24382449 
    24392450        MT->upload_file_to_sync( 
    2440             url  => $blog->include_url($include_name), 
    2441             file => $file_path
     2451            url  => $blog->include_url(\%include_recipe), 
     2452            file => $include_file
    24422453            blog => $blog, 
    24432454        ); 
    24442455 
    2445         return $blog->include_statement($include_name); 
     2456        my $stat = $blog->include_statement(\%include_recipe); 
     2457        return $stat; 
    24462458    } 
    24472459 
  • branches/release-35/t/65-ssi.t

    r1541 r1949  
    2020 
    2121my $blog = MT->model('blog')->load(1); 
     22$blog->include_cache(1); 
    2223 
    2324my $include = MT->model('template')->new; 
     
    4344$tmpl = MT->model('template')->new; 
    4445$tmpl->blog_id($blog->id); 
    45 $tmpl->text(q(hi <mt:include module="Included Template" key="woot" ttl="1000"> bye)); 
     46$tmpl->text(q(hi <mt:include module="Included Template" cache_key="woot" ttl="1000"> bye)); 
    4647 
    4748$ctx = MT::Template::Context->new; 
     
    5960$tmpl = MT->model('template')->new; 
    6061$tmpl->blog_id($blog->id); 
    61 $tmpl->text(q(hi <mt:include module="Included Template" key="woot" ttl="1000"> bye)); 
     62$tmpl->text(q(hi <mt:include module="Included Template" cache_key="woot" ttl="1000"> bye)); 
    6263 
    6364$ctx = MT::Template::Context->new; 
     
    7576$tmpl = MT->model('template')->new; 
    7677$tmpl->blog_id($blog->id); 
    77 $tmpl->text(q(hi <mt:include module="Included Template" key="woot" ttl="1000" ssi="1"> bye)); 
     78$tmpl->text(q(hi <mt:include module="Included Template" cache_key="woot" ttl="1000" ssi="1"> bye)); 
    7879 
    7980$ctx = MT::Template::Context->new; 
     
    8283 
    8384ok(defined $out, 'test template built'); 
    84 my $sitepath = $blog->site_path; 
    85 like($out, qr(\Ahi <!--#include file="${sitepath}includes_c/woo/woot.html" --> bye\z)ms, 
     85my $site_url = $blog->site_url; 
     86$site_url =~ s{ \A \w+ :// [^/]+ }{}xms; 
     87$site_url =~ s{ / \z }{}xms; 
     88like($out, qr(\Ahi <!--#include virtual="${site_url}/includes_c/woot/included_template.html" --> bye\z)ms, 
    8689    'test template included template by ssi'); 
    8790 
     
    8992$tmpl = MT->model('template')->new; 
    9093$tmpl->blog_id($blog->id); 
    91 $tmpl->text(q(hi <mt:include module="Included Template" key="w" ttl="1000" ssi="1"> bye)); 
     94$tmpl->text(q(hi <mt:include module="Included Template" cache_key="w" ttl="1000" ssi="1"> bye)); 
    9295 
    9396$ctx = MT::Template::Context->new; 
     
    9699 
    97100ok(defined $out, 'test template built'); 
    98 $sitepath = $blog->site_path; 
    99 like($out, qr(\Ahi <!--#include file="${sitepath}includes_c/w/w.html" --> bye\z)ms, 
     101$site_url = $blog->site_url; 
     102$site_url =~ s{ \A \w+ :// [^/]+ }{}xms; 
     103$site_url =~ s{ / \z }{}xms; 
     104like($out, qr(\Ahi <!--#include virtual="${site_url}/includes_c/w/included_template.html" --> bye\z)ms, 
    100105    'test template included template by ssi'); 
    101106 
  • branches/release-35/tmpl/cms/edit_template.tmpl

    r1942 r1949  
    678678            label="<__trans phrase="Server Side Include">" 
    679679            content_class="field-content-text"> 
    680             <input type="checkbox" id="server-side-include" name="include_with_ssi" value="1" onclick=""<mt:if name="include_with_ssi"> checked</mt:if> /> 
     680            <input type="checkbox" id="server-side-include" name="include_with_ssi" value="1" onclick="toggleHidden('include_cache_path-field')"<mt:if name="include_with_ssi"> checked</mt:if> /> 
    681681            <label for="server-side-include"><__trans phrase="Process as <strong>[_1]</strong> include" params="<$mt:var name="ssi_type"$>"></label> 
     682        </mtapp:setting> 
     683        <mtapp:setting 
     684            id="include_cache_path" 
     685            label="<__trans phrase="Include cache path">" 
     686            shown="<mt:if name="include_with_ssi">0<mt:else>1</mt:if>"> 
     687            <div class="textarea-wrapper"> 
     688                <input type="text" id="include-cache-path" name="cache_path" value="<mt:var name="cache_path">" maxlength="255" class="full-width" mt:watch-change="1" /> 
     689            </div> 
    682690        </mtapp:setting> 
    683691    </mt:if>