remove tailing spaces from ssviewer

This commit is contained in:
Peter Thaleikis 2015-07-27 22:37:19 +12:00
parent ff4a83f9c8
commit 914b54b0b3

View File

@ -5,16 +5,16 @@
* - Handle entering & leaving sub-scopes in loops and withs * - Handle entering & leaving sub-scopes in loops and withs
* - Track Up and Top * - Track Up and Top
* - (As a side effect) Inject data that needs to be available globally (used to live in ViewableData) * - (As a side effect) Inject data that needs to be available globally (used to live in ViewableData)
* *
* In order to handle up, rather than tracking it using a tree, which would involve constructing new objects * In order to handle up, rather than tracking it using a tree, which would involve constructing new objects
* for each step, we use indexes into the itemStack (which already has to exist). * for each step, we use indexes into the itemStack (which already has to exist).
* *
* Each item has three indexes associated with it * Each item has three indexes associated with it
* *
* - Pop. Which item should become the scope once the current scope is popped out of * - Pop. Which item should become the scope once the current scope is popped out of
* - Up. Which item is up from this item * - Up. Which item is up from this item
* - Current. Which item is the first time this object has appeared in the stack * - Current. Which item is the first time this object has appeared in the stack
* *
* We also keep the index of the current starting point for lookups. A lookup is a sequence of obj calls - * We also keep the index of the current starting point for lookups. A lookup is a sequence of obj calls -
* when in a loop or with tag the end result becomes the new scope, but for injections, we throw away the lookup * when in a loop or with tag the end result becomes the new scope, but for injections, we throw away the lookup
* and revert back to the original scope once we've got the value we're after * and revert back to the original scope once we've got the value we're after
@ -23,20 +23,20 @@
* @subpackage view * @subpackage view
*/ */
class SSViewer_Scope { class SSViewer_Scope {
// The stack of previous "global" items // The stack of previous "global" items
// And array of item, itemIterator, itemIteratorTotal, pop_index, up_index, current_index // And array of item, itemIterator, itemIteratorTotal, pop_index, up_index, current_index
private $itemStack = array(); private $itemStack = array();
// The current "global" item (the one any lookup starts from) // The current "global" item (the one any lookup starts from)
protected $item; protected $item;
// If we're looping over the current "global" item, here's the iterator that tracks with item we're up to // If we're looping over the current "global" item, here's the iterator that tracks with item we're up to
protected $itemIterator; protected $itemIterator;
//Total number of items in the iterator //Total number of items in the iterator
protected $itemIteratorTotal; protected $itemIteratorTotal;
// A pointer into the item stack for which item should be scope on the next pop call // A pointer into the item stack for which item should be scope on the next pop call
private $popIndex; private $popIndex;
@ -45,7 +45,7 @@ class SSViewer_Scope {
// A pointer into the item stack for which item is this one (or null if not in stack yet) // A pointer into the item stack for which item is this one (or null if not in stack yet)
private $currentIndex = null; private $currentIndex = null;
private $localIndex; private $localIndex;
public function __construct($item, $inheritedScope = null) { public function __construct($item, $inheritedScope = null) {
@ -60,7 +60,7 @@ class SSViewer_Scope {
$this->itemStack[] = array($this->item, null, 0, null, null, 0); $this->itemStack[] = array($this->item, null, 0, null, null, 0);
} }
} }
public function getItem(){ public function getItem(){
return $this->itemIterator ? $this->itemIterator->current() : $this->item; return $this->itemIterator ? $this->itemIterator->current() : $this->item;
} }
@ -101,12 +101,12 @@ class SSViewer_Scope {
list($this->item, $this->itemIterator, $this->itemIteratorTotal, $unused2, $this->upIndex, list($this->item, $this->itemIterator, $this->itemIteratorTotal, $unused2, $this->upIndex,
$this->currentIndex) = $this->itemStack[$this->upIndex]; $this->currentIndex) = $this->itemStack[$this->upIndex];
break; break;
case 'Top': case 'Top':
list($this->item, $this->itemIterator, $this->itemIteratorTotal, $unused2, $this->upIndex, list($this->item, $this->itemIterator, $this->itemIteratorTotal, $unused2, $this->upIndex,
$this->currentIndex) = $this->itemStack[0]; $this->currentIndex) = $this->itemStack[0];
break; break;
default: default:
$this->item = $this->getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName); $this->item = $this->getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
$this->itemIterator = null; $this->itemIterator = null;
@ -134,31 +134,31 @@ class SSViewer_Scope {
public function pushScope(){ public function pushScope(){
$newLocalIndex = count($this->itemStack)-1; $newLocalIndex = count($this->itemStack)-1;
$this->popIndex = $this->itemStack[$newLocalIndex][3] = $this->localIndex; $this->popIndex = $this->itemStack[$newLocalIndex][3] = $this->localIndex;
$this->localIndex = $newLocalIndex; $this->localIndex = $newLocalIndex;
// We normally keep any previous itemIterator around, so local $Up calls reference the right element. But // We normally keep any previous itemIterator around, so local $Up calls reference the right element. But
// once we enter a new global scope, we need to make sure we use a new one // once we enter a new global scope, we need to make sure we use a new one
$this->itemIterator = $this->itemStack[$newLocalIndex][1] = null; $this->itemIterator = $this->itemStack[$newLocalIndex][1] = null;
return $this; return $this;
} }
public function popScope(){ public function popScope(){
$this->localIndex = $this->popIndex; $this->localIndex = $this->popIndex;
$this->resetLocalScope(); $this->resetLocalScope();
return $this; return $this;
} }
public function next(){ public function next(){
if (!$this->item) return false; if (!$this->item) return false;
if (!$this->itemIterator) { if (!$this->itemIterator) {
if (is_array($this->item)) $this->itemIterator = new ArrayIterator($this->item); if (is_array($this->item)) $this->itemIterator = new ArrayIterator($this->item);
else $this->itemIterator = $this->item->getIterator(); else $this->itemIterator = $this->item->getIterator();
$this->itemStack[$this->localIndex][1] = $this->itemIterator; $this->itemStack[$this->localIndex][1] = $this->itemIterator;
$this->itemIteratorTotal = iterator_count($this->itemIterator); //count the total number of items $this->itemIteratorTotal = iterator_count($this->itemIterator); //count the total number of items
$this->itemStack[$this->localIndex][2] = $this->itemIteratorTotal; $this->itemStack[$this->localIndex][2] = $this->itemIteratorTotal;
@ -167,17 +167,17 @@ class SSViewer_Scope {
else { else {
$this->itemIterator->next(); $this->itemIterator->next();
} }
$this->resetLocalScope(); $this->resetLocalScope();
if (!$this->itemIterator->valid()) return false; if (!$this->itemIterator->valid()) return false;
return $this->itemIterator->key(); return $this->itemIterator->key();
} }
public function __call($name, $arguments) { public function __call($name, $arguments) {
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item; $on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
$retval = $on ? call_user_func_array(array($on, $name), $arguments) : null; $retval = $on ? call_user_func_array(array($on, $name), $arguments) : null;
$this->resetLocalScope(); $this->resetLocalScope();
return $retval; return $retval;
} }
@ -346,7 +346,7 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider {
/** /**
* Returns true or false depending on if the pos of the iterator is a multiple of a specific number. * Returns true or false depending on if the pos of the iterator is a multiple of a specific number.
* So, <% if MultipleOf(3) %> would return true on indexes: 3,6,9,12,15, etc. * So, <% if MultipleOf(3) %> would return true on indexes: 3,6,9,12,15, etc.
* The count starts from $offset, which defaults to 1. * The count starts from $offset, which defaults to 1.
* @param int $factor The multiple of which to return * @param int $factor The multiple of which to return
* @param int $offset Number to start count from. * @param int $offset Number to start count from.
@ -363,14 +363,14 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider {
* This extends SSViewer_Scope to mix in data on top of what the item provides. This can be "global" * This extends SSViewer_Scope to mix in data on top of what the item provides. This can be "global"
* data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like * data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like
* (like $FirstLast etc). * (like $FirstLast etc).
* *
* It's separate from SSViewer_Scope to keep that fairly complex code as clean as possible. * It's separate from SSViewer_Scope to keep that fairly complex code as clean as possible.
* *
* @package framework * @package framework
* @subpackage view * @subpackage view
*/ */
class SSViewer_DataPresenter extends SSViewer_Scope { class SSViewer_DataPresenter extends SSViewer_Scope {
private static $globalProperties = null; private static $globalProperties = null;
private static $iteratorProperties = null; private static $iteratorProperties = null;
@ -402,7 +402,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
self::$iteratorProperties = array(); self::$iteratorProperties = array();
// Get all the exposed variables from all classes that implement the TemplateIteratorProvider interface // Get all the exposed variables from all classes that implement the TemplateIteratorProvider interface
// //call non-statically // //call non-statically
$this->createCallableArray(self::$iteratorProperties, "TemplateIteratorProvider", $this->createCallableArray(self::$iteratorProperties, "TemplateIteratorProvider",
"get_template_iterator_variables", true); "get_template_iterator_variables", true);
} }
@ -421,7 +421,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
$exposedVariables = call_user_func(array($implementer, $variableMethod)); $exposedVariables = call_user_func(array($implementer, $variableMethod));
foreach($exposedVariables as $varName => $details) { foreach($exposedVariables as $varName => $details) {
if (!is_array($details)) $details = array('method' => $details, if (!is_array($details)) $details = array('method' => $details,
'casting' => Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET)); 'casting' => Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET));
// If just a value (and not a key => value pair), use it for both key and value // If just a value (and not a key => value pair), use it for both key and value
@ -521,7 +521,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
$property = $arguments[0]; //the name of the public function being called $property = $arguments[0]; //the name of the public function being called
//the public function parameters in an array //the public function parameters in an array
if (isset($arguments[1]) && $arguments[1] != null) $params = $arguments[1]; if (isset($arguments[1]) && $arguments[1] != null) $params = $arguments[1];
else $params = array(); else $params = array();
$hasInjected = $res = null; $hasInjected = $res = null;
@ -552,31 +552,31 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
/** /**
* Parses a template file with an *.ss file extension. * Parses a template file with an *.ss file extension.
* *
* In addition to a full template in the templates/ folder, a template in * In addition to a full template in the templates/ folder, a template in
* templates/Content or templates/Layout will be rendered into $Content and * templates/Content or templates/Layout will be rendered into $Content and
* $Layout, respectively. * $Layout, respectively.
* *
* A single template can be parsed by multiple nested {@link SSViewer} instances * A single template can be parsed by multiple nested {@link SSViewer} instances
* through $Layout/$Content placeholders, as well as <% include MyTemplateFile %> template commands. * through $Layout/$Content placeholders, as well as <% include MyTemplateFile %> template commands.
* *
* <b>Themes</b> * <b>Themes</b>
* *
* See http://doc.silverstripe.org/themes and http://doc.silverstripe.org/themes:developing * See http://doc.silverstripe.org/themes and http://doc.silverstripe.org/themes:developing
* *
* <b>Caching</b> * <b>Caching</b>
* *
* Compiled templates are cached via {@link SS_Cache}, usually on the filesystem. * Compiled templates are cached via {@link SS_Cache}, usually on the filesystem.
* If you put ?flush=1 on your URL, it will force the template to be recompiled. * If you put ?flush=1 on your URL, it will force the template to be recompiled.
* *
* @see http://doc.silverstripe.org/themes * @see http://doc.silverstripe.org/themes
* @see http://doc.silverstripe.org/themes:developing * @see http://doc.silverstripe.org/themes:developing
* *
* @package framework * @package framework
* @subpackage view * @subpackage view
*/ */
class SSViewer implements Flushable { class SSViewer implements Flushable {
/** /**
* @config * @config
* @var boolean $source_file_comments * @var boolean $source_file_comments
@ -604,7 +604,7 @@ class SSViewer implements Flushable {
Deprecation::notice('3.2', 'Use the "SSViewer.source_file_comments" config setting instead'); Deprecation::notice('3.2', 'Use the "SSViewer.source_file_comments" config setting instead');
Config::inst()->update('SSViewer', 'source_file_comments', $val); Config::inst()->update('SSViewer', 'source_file_comments', $val);
} }
/** /**
* @deprecated 3.2 Use the "SSViewer.source_file_comments" config setting instead * @deprecated 3.2 Use the "SSViewer.source_file_comments" config setting instead
* @return boolean * @return boolean
@ -613,18 +613,18 @@ class SSViewer implements Flushable {
Deprecation::notice('3.2', 'Use the "SSViewer.source_file_comments" config setting instead'); Deprecation::notice('3.2', 'Use the "SSViewer.source_file_comments" config setting instead');
return Config::inst()->get('SSViewer', 'source_file_comments'); return Config::inst()->get('SSViewer', 'source_file_comments');
} }
/** /**
* @var array $chosenTemplates Associative array for the different * @var array $chosenTemplates Associative array for the different
* template containers: "main" and "Layout". Values are absolute file paths to *.ss files. * template containers: "main" and "Layout". Values are absolute file paths to *.ss files.
*/ */
private $chosenTemplates = array(); private $chosenTemplates = array();
/** /**
* @var boolean * @var boolean
*/ */
protected $rewriteHashlinks = true; protected $rewriteHashlinks = true;
/** /**
* @config * @config
* @var string The used "theme", which usually consists of templates, images and stylesheets. * @var string The used "theme", which usually consists of templates, images and stylesheets.
@ -636,7 +636,7 @@ class SSViewer implements Flushable {
* @config * @config
* @var boolean Use the theme. Set to FALSE in order to disable themes, * @var boolean Use the theme. Set to FALSE in order to disable themes,
* which can be useful for scenarios where theme overrides are temporarily undesired, * which can be useful for scenarios where theme overrides are temporarily undesired,
* such as an administrative interface separate from the website theme. * such as an administrative interface separate from the website theme.
* It retains the theme settings to be re-enabled, for example when a website content * It retains the theme settings to be re-enabled, for example when a website content
* needs to be rendered from within this administrative interface. * needs to be rendered from within this administrative interface.
*/ */
@ -654,7 +654,7 @@ class SSViewer implements Flushable {
/* /*
* Default prepended cache key for partial caching * Default prepended cache key for partial caching
* *
* @var string * @var string
* @config * @config
*/ */
@ -682,25 +682,25 @@ class SSViewer implements Flushable {
} }
return $viewer; return $viewer;
} }
/** /**
* @deprecated 3.2 Use the "SSViewer.theme" config setting instead * @deprecated 3.2 Use the "SSViewer.theme" config setting instead
* @param string $theme The "base theme" name (without underscores). * @param string $theme The "base theme" name (without underscores).
*/ */
public static function set_theme($theme) { public static function set_theme($theme) {
Deprecation::notice('3.2', 'Use the "SSViewer.theme" config setting instead'); Deprecation::notice('3.2', 'Use the "SSViewer.theme" config setting instead');
Config::inst()->update('SSViewer', 'theme', $theme); Config::inst()->update('SSViewer', 'theme', $theme);
} }
/** /**
* @deprecated 3.2 Use the "SSViewer.theme" config setting instead * @deprecated 3.2 Use the "SSViewer.theme" config setting instead
* @return string * @return string
*/ */
public static function current_theme() { public static function current_theme() {
Deprecation::notice('3.2', 'Use the "SSViewer.theme" config setting instead'); Deprecation::notice('3.2', 'Use the "SSViewer.theme" config setting instead');
return Config::inst()->get('SSViewer', 'theme'); return Config::inst()->get('SSViewer', 'theme');
} }
/** /**
* Returns the path to the theme folder * Returns the path to the theme folder
* *
@ -755,7 +755,7 @@ class SSViewer implements Flushable {
public static function get_templates_by_class($className, $suffix = '', $baseClass = null) { public static function get_templates_by_class($className, $suffix = '', $baseClass = null) {
// Figure out the class name from the supplied context. // Figure out the class name from the supplied context.
if(!is_string($className) || !class_exists($className)) { if(!is_string($className) || !class_exists($className)) {
throw new InvalidArgumentException('SSViewer::get_templates_by_class() expects a valid class name as ' . throw new InvalidArgumentException('SSViewer::get_templates_by_class() expects a valid class name as ' .
'its first parameter.'); 'its first parameter.');
return array(); return array();
} }
@ -775,7 +775,7 @@ class SSViewer implements Flushable {
} }
return $templates; return $templates;
} }
/** /**
* @param string|array $templateList If passed as a string with .ss extension, used as the "main" template. * @param string|array $templateList If passed as a string with .ss extension, used as the "main" template.
* If passed as an array, it can be used for template inheritance (first found template "wins"). * If passed as an array, it can be used for template inheritance (first found template "wins").
@ -854,15 +854,15 @@ class SSViewer implements Flushable {
return false; return false;
} }
/** /**
* Set a global rendering option. * Set a global rendering option.
* *
* The following options are available: * The following options are available:
* - rewriteHashlinks: If true (the default), <a href="#..."> will be rewritten to contain the * - rewriteHashlinks: If true (the default), <a href="#..."> will be rewritten to contain the
* current URL. This lets it play nicely with our <base> tag. * current URL. This lets it play nicely with our <base> tag.
* - If rewriteHashlinks = 'php' then, a piece of PHP script will be inserted before the hash * - If rewriteHashlinks = 'php' then, a piece of PHP script will be inserted before the hash
* links: "<?php echo $_SERVER['REQUEST_URI']; ?>". This is useful if you're generating a * links: "<?php echo $_SERVER['REQUEST_URI']; ?>". This is useful if you're generating a
* page that will be saved to a .php file and may be accessed from different URLs. * page that will be saved to a .php file and may be accessed from different URLs.
* *
* @deprecated 3.2 Use the "SSViewer.rewrite_hash_links" config setting instead * @deprecated 3.2 Use the "SSViewer.rewrite_hash_links" config setting instead
@ -878,7 +878,7 @@ class SSViewer implements Flushable {
Config::inst()->update('SSViewer', $optionName, $optionVal); Config::inst()->update('SSViewer', $optionName, $optionVal);
} }
} }
/** /**
* @deprecated 3.2 Use the "SSViewer.rewrite_hash_links" config setting instead * @deprecated 3.2 Use the "SSViewer.rewrite_hash_links" config setting instead
* @param string * @param string
@ -907,7 +907,7 @@ class SSViewer implements Flushable {
return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1]; return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1];
} }
} }
/** /**
* Call this to disable rewriting of <a href="#xxx"> links. This is useful in Ajax applications. * Call this to disable rewriting of <a href="#xxx"> links. This is useful in Ajax applications.
* It returns the SSViewer objects, so that you can call new SSViewer("X")->dontRewriteHashlinks()->process(); * It returns the SSViewer objects, so that you can call new SSViewer("X")->dontRewriteHashlinks()->process();
@ -917,7 +917,7 @@ class SSViewer implements Flushable {
Config::inst()->update('SSViewer', 'rewrite_hash_links', false); Config::inst()->update('SSViewer', 'rewrite_hash_links', false);
return $this; return $this;
} }
public function exists() { public function exists() {
return $this->chosenTemplates; return $this->chosenTemplates;
} }
@ -945,7 +945,7 @@ class SSViewer implements Flushable {
return $founds[0]; return $founds[0];
} }
} }
/** /**
* Clears all parsed template files in the cache folder. * Clears all parsed template files in the cache folder.
* *
@ -976,7 +976,7 @@ class SSViewer implements Flushable {
if (!self::$cacheblock_cache_flushed || $force) { if (!self::$cacheblock_cache_flushed || $force) {
$cache = SS_Cache::factory('cacheblock'); $cache = SS_Cache::factory('cacheblock');
$backend = $cache->getBackend(); $backend = $cache->getBackend();
if( if(
$backend instanceof Zend_Cache_Backend_ExtendedInterface $backend instanceof Zend_Cache_Backend_ExtendedInterface
&& ($capabilities = $backend->getCapabilities()) && ($capabilities = $backend->getCapabilities())
@ -987,7 +987,7 @@ class SSViewer implements Flushable {
$cache->clean(Zend_Cache::CLEANING_MODE_ALL); $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
} }
self::$cacheblock_cache_flushed = true; self::$cacheblock_cache_flushed = true;
} }
} }
@ -1061,14 +1061,14 @@ class SSViewer implements Flushable {
/** /**
* The process() method handles the "meat" of the template processing. * The process() method handles the "meat" of the template processing.
* *
* It takes care of caching the output (via {@link SS_Cache}), as well as * It takes care of caching the output (via {@link SS_Cache}), as well as
* replacing the special "$Content" and "$Layout" placeholders with their * replacing the special "$Content" and "$Layout" placeholders with their
* respective subtemplates. * respective subtemplates.
* *
* The method injects extra HTML in the header via {@link Requirements::includeInHTML()}. * The method injects extra HTML in the header via {@link Requirements::includeInHTML()}.
* *
* Note: You can call this method indirectly by {@link ViewableData->renderWith()}. * Note: You can call this method indirectly by {@link ViewableData->renderWith()}.
* *
* @param ViewableData $item * @param ViewableData $item
* @param array|null $arguments - arguments to an included template * @param array|null $arguments - arguments to an included template
* @param Object $inheritedScope - the current scope of a parent template including a sub-template * @param Object $inheritedScope - the current scope of a parent template including a sub-template
@ -1085,15 +1085,15 @@ class SSViewer implements Flushable {
$key = reset($keys); $key = reset($keys);
$template = $this->chosenTemplates[$key]; $template = $this->chosenTemplates[$key];
} }
$cacheFile = TEMP_FOLDER . "/.cache" $cacheFile = TEMP_FOLDER . "/.cache"
. str_replace(array('\\','/',':'), '.', Director::makeRelative(realpath($template))); . str_replace(array('\\','/',':'), '.', Director::makeRelative(realpath($template)));
$lastEdited = filemtime($template); $lastEdited = filemtime($template);
if(!file_exists($cacheFile) || filemtime($cacheFile) < $lastEdited) { if(!file_exists($cacheFile) || filemtime($cacheFile) < $lastEdited) {
$content = file_get_contents($template); $content = file_get_contents($template);
$content = $this->parseTemplateContent($content, $template); $content = $this->parseTemplateContent($content, $template);
$fh = fopen($cacheFile,'w'); $fh = fopen($cacheFile,'w');
fwrite($fh, $content); fwrite($fh, $content);
fclose($fh); fclose($fh);
@ -1114,21 +1114,21 @@ class SSViewer implements Flushable {
} }
$output = $this->includeGeneratedTemplate($cacheFile, $item, $arguments, $underlay, $inheritedScope); $output = $this->includeGeneratedTemplate($cacheFile, $item, $arguments, $underlay, $inheritedScope);
if($this->includeRequirements) { if($this->includeRequirements) {
$output = Requirements::includeInHTML($template, $output); $output = Requirements::includeInHTML($template, $output);
} }
array_pop(SSViewer::$topLevel); array_pop(SSViewer::$topLevel);
// If we have our crazy base tag, then fix # links referencing the current page. // If we have our crazy base tag, then fix # links referencing the current page.
$rewrite = Config::inst()->get('SSViewer', 'rewrite_hash_links'); $rewrite = Config::inst()->get('SSViewer', 'rewrite_hash_links');
if($this->rewriteHashlinks && $rewrite) { if($this->rewriteHashlinks && $rewrite) {
if(strpos($output, '<base') !== false) { if(strpos($output, '<base') !== false) {
if($rewrite === 'php') { if($rewrite === 'php') {
$thisURLRelativeToBase = "<?php echo Convert::raw2att(\$_SERVER['REQUEST_URI']); ?>"; $thisURLRelativeToBase = "<?php echo Convert::raw2att(\$_SERVER['REQUEST_URI']); ?>";
} else { } else {
$thisURLRelativeToBase = Convert::raw2att($_SERVER['REQUEST_URI']); $thisURLRelativeToBase = Convert::raw2att($_SERVER['REQUEST_URI']);
} }
@ -1142,7 +1142,7 @@ class SSViewer implements Flushable {
/** /**
* Execute the given template, passing it the given data. * Execute the given template, passing it the given data.
* Used by the <% include %> template tag to process templates. * Used by the <% include %> template tag to process templates.
* *
* @param string $template Template name * @param string $template Template name
* @param mixed $data Data context * @param mixed $data Data context
* @param array $arguments Additional arguments * @param array $arguments Additional arguments
@ -1154,12 +1154,12 @@ class SSViewer implements Flushable {
return $v->process($data, $arguments, $scope); return $v->process($data, $arguments, $scope);
} }
/** /**
* Execute the evaluated string, passing it the given data. * Execute the evaluated string, passing it the given data.
* Used by partial caching to evaluate custom cache keys expressed using * Used by partial caching to evaluate custom cache keys expressed using
* template expressions * template expressions
* *
* @param string $content Input string * @param string $content Input string
* @param mixed $data Data context * @param mixed $data Data context
* @param array $arguments Additional arguments * @param array $arguments Additional arguments
@ -1168,7 +1168,7 @@ class SSViewer implements Flushable {
public static function execute_string($content, $data, $arguments = null) { public static function execute_string($content, $data, $arguments = null) {
$v = SSViewer::fromString($content); $v = SSViewer::fromString($content);
$v->includeRequirements(false); $v->includeRequirements(false);
return $v->process($data, $arguments); return $v->process($data, $arguments);
} }
@ -1187,7 +1187,7 @@ class SSViewer implements Flushable {
public function templates() { public function templates() {
return $this->chosenTemplates; return $this->chosenTemplates;
} }
/** /**
* @param string $type "Layout" or "main" * @param string $type "Layout" or "main"
* @param string $file Full system path to the template file * @param string $file Full system path to the template file
@ -1195,17 +1195,17 @@ class SSViewer implements Flushable {
public function setTemplateFile($type, $file) { public function setTemplateFile($type, $file) {
$this->chosenTemplates[$type] = $file; $this->chosenTemplates[$type] = $file;
} }
/** /**
* Return an appropriate base tag for the given template. * Return an appropriate base tag for the given template.
* It will be closed on an XHTML document, and unclosed on an HTML document. * It will be closed on an XHTML document, and unclosed on an HTML document.
* *
* @param $contentGeneratedSoFar The content of the template generated so far; it should contain * @param $contentGeneratedSoFar The content of the template generated so far; it should contain
* the DOCTYPE declaration. * the DOCTYPE declaration.
*/ */
public static function get_base_tag($contentGeneratedSoFar) { public static function get_base_tag($contentGeneratedSoFar) {
$base = Director::absoluteBaseURL(); $base = Director::absoluteBaseURL();
// Is the document XHTML? // Is the document XHTML?
if(preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar)) { if(preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar)) {
return "<base href=\"$base\" />"; return "<base href=\"$base\" />";
@ -1228,19 +1228,19 @@ class SSViewer_FromString extends SSViewer {
* @var bool * @var bool
*/ */
private static $cache_template = true; private static $cache_template = true;
/** /**
* The template to use * The template to use
* @var string * @var string
*/ */
protected $content; protected $content;
/** /**
* Indicates whether templates should be cached * Indicates whether templates should be cached
* @var bool * @var bool
*/ */
protected $cacheTemplate; protected $cacheTemplate;
public function __construct($content, TemplateParser $parser = null) { public function __construct($content, TemplateParser $parser = null) {
$this->setParser($parser ?: Injector::inst()->get('SSTemplateParser')); $this->setParser($parser ?: Injector::inst()->get('SSTemplateParser'));
$this->content = $content; $this->content = $content;
@ -1264,21 +1264,21 @@ class SSViewer_FromString extends SSViewer {
} else { } else {
$cacheTemplate = Config::inst()->get('SSViewer_FromString', 'cache_template'); $cacheTemplate = Config::inst()->get('SSViewer_FromString', 'cache_template');
} }
if (!$cacheTemplate) { if (!$cacheTemplate) {
unlink($cacheFile); unlink($cacheFile);
} }
return $val; return $val;
} }
/** /**
* @param boolean $cacheTemplate * @param boolean $cacheTemplate
*/ */
public function setCacheTemplate($cacheTemplate) { public function setCacheTemplate($cacheTemplate) {
$this->cacheTemplate = (bool) $cacheTemplate; $this->cacheTemplate = (bool) $cacheTemplate;
} }
/** /**
* @return boolean * @return boolean
*/ */