| @@ 2950-2980 (lines=31) @@ | ||
| 2947 | $res['php'] .= $sub['php']; |
|
| 2948 | } |
|
| 2949 | ||
| 2950 | function CacheBlock_CacheBlockTemplate(&$res, $sub){ |
|
| 2951 | // Get the block counter |
|
| 2952 | $block = ++$res['subblocks']; |
|
| 2953 | // Build the key for this block from the global key (evaluated in a closure within the template), |
|
| 2954 | // the passed cache key, the block index, and the sha hash of the template. |
|
| 2955 | $res['php'] .= '$keyExpression = function() use ($scope, $cache) {' . PHP_EOL; |
|
| 2956 | $res['php'] .= '$val = \'\';' . PHP_EOL; |
|
| 2957 | if($globalKey = Config::inst()->get('SSViewer', 'global_key')) { |
|
| 2958 | // Embed the code necessary to evaluate the globalKey directly into the template, |
|
| 2959 | // so that SSTemplateParser only needs to be called during template regeneration. |
|
| 2960 | // Warning: If the global key is changed, it's necessary to flush the template cache. |
|
| 2961 | $parser = Injector::inst()->get('SSTemplateParser', false); |
|
| 2962 | $result = $parser->compileString($globalKey, '', false, false); |
|
| 2963 | if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser); |
|
| 2964 | $res['php'] .= $result . PHP_EOL; |
|
| 2965 | } |
|
| 2966 | $res['php'] .= 'return $val;' . PHP_EOL; |
|
| 2967 | $res['php'] .= '};' . PHP_EOL; |
|
| 2968 | $key = 'sha1($keyExpression())' // Global key |
|
| 2969 | . '.\'_' . sha1($sub['php']) // sha of template |
|
| 2970 | . (isset($res['key']) && $res['key'] ? "_'.sha1(".$res['key'].")" : "'") // Passed key |
|
| 2971 | . ".'_$block'"; // block index |
|
| 2972 | // Get any condition |
|
| 2973 | $condition = isset($res['condition']) ? $res['condition'] : ''; |
|
| 2974 | ||
| 2975 | $res['php'] .= 'if ('.$condition.'($partial = $cache->load('.$key.'))) $val .= $partial;' . PHP_EOL; |
|
| 2976 | $res['php'] .= 'else { $oldval = $val; $val = "";' . PHP_EOL; |
|
| 2977 | $res['php'] .= $sub['php'] . PHP_EOL; |
|
| 2978 | $res['php'] .= $condition . ' $cache->save($val); $val = $oldval . $val;' . PHP_EOL; |
|
| 2979 | $res['php'] .= '}'; |
|
| 2980 | } |
|
| 2981 | ||
| 2982 | /* OldTPart: "_t" N "(" N QuotedString (N "," N CallArguments)? N ")" N (";")? */ |
|
| 2983 | protected $match_OldTPart_typestack = array('OldTPart'); |
|
| @@ 674-704 (lines=31) @@ | ||
| 671 | $res['php'] .= $sub['php']; |
|
| 672 | } |
|
| 673 | ||
| 674 | function CacheBlock_CacheBlockTemplate(&$res, $sub){ |
|
| 675 | // Get the block counter |
|
| 676 | $block = ++$res['subblocks']; |
|
| 677 | // Build the key for this block from the global key (evaluated in a closure within the template), |
|
| 678 | // the passed cache key, the block index, and the sha hash of the template. |
|
| 679 | $res['php'] .= '$keyExpression = function() use ($scope, $cache) {' . PHP_EOL; |
|
| 680 | $res['php'] .= '$val = \'\';' . PHP_EOL; |
|
| 681 | if($globalKey = Config::inst()->get('SSViewer', 'global_key')) { |
|
| 682 | // Embed the code necessary to evaluate the globalKey directly into the template, |
|
| 683 | // so that SSTemplateParser only needs to be called during template regeneration. |
|
| 684 | // Warning: If the global key is changed, it's necessary to flush the template cache. |
|
| 685 | $parser = Injector::inst()->get('SSTemplateParser', false); |
|
| 686 | $result = $parser->compileString($globalKey, '', false, false); |
|
| 687 | if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser); |
|
| 688 | $res['php'] .= $result . PHP_EOL; |
|
| 689 | } |
|
| 690 | $res['php'] .= 'return $val;' . PHP_EOL; |
|
| 691 | $res['php'] .= '};' . PHP_EOL; |
|
| 692 | $key = 'sha1($keyExpression())' // Global key |
|
| 693 | . '.\'_' . sha1($sub['php']) // sha of template |
|
| 694 | . (isset($res['key']) && $res['key'] ? "_'.sha1(".$res['key'].")" : "'") // Passed key |
|
| 695 | . ".'_$block'"; // block index |
|
| 696 | // Get any condition |
|
| 697 | $condition = isset($res['condition']) ? $res['condition'] : ''; |
|
| 698 | ||
| 699 | $res['php'] .= 'if ('.$condition.'($partial = $cache->load('.$key.'))) $val .= $partial;' . PHP_EOL; |
|
| 700 | $res['php'] .= 'else { $oldval = $val; $val = "";' . PHP_EOL; |
|
| 701 | $res['php'] .= $sub['php'] . PHP_EOL; |
|
| 702 | $res['php'] .= $condition . ' $cache->save($val); $val = $oldval . $val;' . PHP_EOL; |
|
| 703 | $res['php'] .= '}'; |
|
| 704 | } |
|
| 705 | ||
| 706 | /*!* |
|
| 707 | ||