Changeset 1949
- Timestamp:
- 04/17/08 13:11:31 (4 months ago)
- Files:
-
- branches/release-35/lib/MT/Blog.pm (modified) (3 diffs)
- branches/release-35/lib/MT/CMS/Template.pm (modified) (3 diffs)
- branches/release-35/lib/MT/Template.pm (modified) (1 diff)
- branches/release-35/lib/MT/Template/ContextHandlers.pm (modified) (7 diffs)
- branches/release-35/t/65-ssi.t (modified) (7 diffs)
- branches/release-35/tmpl/cms/edit_template.tmpl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-35/lib/MT/Blog.pm
r1945 r1949 379 379 sub include_path_parts { 380 380 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}; 384 384 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); 386 396 } 387 397 388 398 sub include_path { 389 399 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; 397 406 } 398 407 399 408 sub include_url { 400 409 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; 405 413 return $url; 406 414 } … … 408 416 sub include_statement { 409 417 my $blog = shift; 410 my ($name) = @_;411 418 412 419 my $system = $blog->include_system or return; … … 416 423 $statement = q{<!--#include virtual="%s" -->}; 417 424 425 my ($filename, @path) = $blog->include_path_parts(@_); 418 426 my $site_url = $blog->site_url; 419 427 $site_url =~ s{ \A \w+ :// [^/]+ }{}xms; 420 428 $site_url =~ s{ / \z }{}xms; 421 $include = join q{/}, $site_url, $blog->include_path_parts($name);429 $include = join q{/}, $site_url, @path, $filename; 422 430 } 423 431 else { 424 $include = $blog->include_path( $name);432 $include = $blog->include_path(@_); 425 433 $statement = $system eq 'php' ? q{<?php include("%s") ?>} 426 434 : $system eq 'jsp' ? q{<%@ include file="%s" %>} branches/release-35/lib/MT/CMS/Template.pm
r1913 r1949 474 474 if ($blog) { 475 475 $param->{include_with_ssi} = 0; 476 $param->{cache_path} = ''; 476 477 $param->{cache_enabled} = 0; 477 478 $param->{cache_expire_type} = 0; … … 483 484 $param->{include_with_ssi} = $obj->include_with_ssi 484 485 if defined $obj->include_with_ssi; 486 $param->{cache_path} = $obj->cache_path 487 if defined $obj->cache_path; 485 488 $param->{cache_enabled} = $obj->use_cache 486 489 if defined $obj->use_cache; … … 1237 1240 # module caching 1238 1241 $obj->include_with_ssi( $app->param('include_with_ssi') ? 1 : 0 ); 1242 $obj->cache_path( $app->param('cache_path')); 1239 1243 $obj->use_cache( $app->param('cache_enabled') ? 1 : 0 ); 1240 1244 my $cache_expire_type = $app->param('cache_expire_type'); branches/release-35/lib/MT/Template.pm
r1937 r1949 44 44 'cache_expire_interval' => 'integer meta', 45 45 'cache_expire_event' => 'string meta', 46 'cache_path' => 'string meta', 46 47 }, 47 48 indexes => { branches/release-35/lib/MT/Template/ContextHandlers.pm
r1926 r1949 2328 2328 my $blog = $ctx->stash('blog') || MT->model('blog')->load($blog_id); 2329 2329 2330 my %include_recipe; 2330 2331 my $use_ssi = $blog && $blog->include_system 2331 2332 && ($arg->{ssi} || $tmpl->include_with_ssi) ? 1 : 0; … … 2334 2335 # easiest way to determine this is from the variable 2335 2336 # 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 } 2337 2349 } 2338 2350 … … 2342 2354 && $blog->include_cache 2343 2355 && ( ( $arg->{cache} && $arg->{cache} > 0 ) 2344 || $arg->{ key}2356 || $arg->{cache_key} 2345 2357 || ( exists $arg->{ttl} ) 2346 2358 || $tmpl->use_cache ) ? 1 : 0; 2347 2359 my $cache_key = 2348 $arg->{ key}2349 ? $arg->{ key}2360 $arg->{cache_key} 2361 ? $arg->{cache_key} 2350 2362 : 'blog::' . $blog_id . '::template_' . $type . '::' . $tmpl_name; 2351 2363 my $ttl = … … 2362 2374 if ($use_ssi) { 2363 2375 # 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]; 2366 2378 if ($mtime && (MT::Util::ts2epoch(undef, $latest) > $mtime ) ) { 2367 2379 $ttl = 1; # bound to force an update … … 2388 2400 return $cache_value if !$use_ssi; 2389 2401 2390 my $include_name = $arg->{key} || $tmpl_name;2391 2402 # The template may still be cached from before we were using SSI 2392 2403 # 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); 2396 2407 } 2397 2408 } … … 2424 2435 2425 2436 if ($use_ssi) { 2426 my $include_name = $arg->{key} || $tmpl_name; 2437 my ($include_file, $path, $filename) = 2438 $blog->include_path(\%include_recipe); 2427 2439 my $fmgr = $blog->file_mgr; 2428 my ($path, $file_path) = $blog->include_path($include_name);2429 2440 if (!$fmgr->exists($path)) { 2430 2441 if (!$fmgr->mkpath($path)) { … … 2433 2444 } 2434 2445 } 2435 defined($fmgr->put_data($ret, $ file_path))2446 defined($fmgr->put_data($ret, $include_file)) 2436 2447 or return $ctx->error(MT->translate("Writing to '[_1]' failed: [_2]", 2437 $ file_path, $fmgr->errstr));2448 $include_file, $fmgr->errstr)); 2438 2449 2439 2450 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, 2442 2453 blog => $blog, 2443 2454 ); 2444 2455 2445 return $blog->include_statement($include_name); 2456 my $stat = $blog->include_statement(\%include_recipe); 2457 return $stat; 2446 2458 } 2447 2459 branches/release-35/t/65-ssi.t
r1541 r1949 20 20 21 21 my $blog = MT->model('blog')->load(1); 22 $blog->include_cache(1); 22 23 23 24 my $include = MT->model('template')->new; … … 43 44 $tmpl = MT->model('template')->new; 44 45 $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)); 46 47 47 48 $ctx = MT::Template::Context->new; … … 59 60 $tmpl = MT->model('template')->new; 60 61 $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)); 62 63 63 64 $ctx = MT::Template::Context->new; … … 75 76 $tmpl = MT->model('template')->new; 76 77 $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)); 78 79 79 80 $ctx = MT::Template::Context->new; … … 82 83 83 84 ok(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, 85 my $site_url = $blog->site_url; 86 $site_url =~ s{ \A \w+ :// [^/]+ }{}xms; 87 $site_url =~ s{ / \z }{}xms; 88 like($out, qr(\Ahi <!--#include virtual="${site_url}/includes_c/woot/included_template.html" --> bye\z)ms, 86 89 'test template included template by ssi'); 87 90 … … 89 92 $tmpl = MT->model('template')->new; 90 93 $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)); 92 95 93 96 $ctx = MT::Template::Context->new; … … 96 99 97 100 ok(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; 104 like($out, qr(\Ahi <!--#include virtual="${site_url}/includes_c/w/included_template.html" --> bye\z)ms, 100 105 'test template included template by ssi'); 101 106 branches/release-35/tmpl/cms/edit_template.tmpl
r1942 r1949 678 678 label="<__trans phrase="Server Side Include">" 679 679 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> /> 681 681 <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> 682 690 </mtapp:setting> 683 691 </mt:if>
