IP/libs/sysplugins/smarty_internal_resource_php.php

108 lines
3.4 KiB
PHP
Raw Permalink Normal View History

2014-04-01 18:38:34 +00:00
<?php
/**
* Smarty Internal Plugin Resource PHP
* Implements the file system as resource for PHP templates
*
2014-10-13 09:24:53 +00:00
* @package Smarty
2014-04-01 18:38:34 +00:00
* @subpackage TemplateResources
2014-10-13 09:24:53 +00:00
* @author Uwe Tews
* @author Rodney Rehm
2014-04-01 18:38:34 +00:00
*/
class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
2014-04-01 18:38:34 +00:00
{
/**
* Flag that it's an uncompiled resource
2014-10-13 09:24:53 +00:00
*
* @var bool
2014-04-01 18:38:34 +00:00
*/
public $uncompiled = true;
2014-04-01 18:38:34 +00:00
/**
* container for short_open_tag directive's value before executing PHP templates
*
* @var string
2014-04-01 18:38:34 +00:00
*/
protected $short_open_tag;
2014-04-01 18:38:34 +00:00
/**
* Resource does implement populateCompiledFilepath() method
2014-04-01 18:38:34 +00:00
*
* @var bool
2014-04-01 18:38:34 +00:00
*/
public $hasCompiledHandler = true;
2014-04-01 18:38:34 +00:00
/**
* Create a new PHP Resource
2014-04-01 18:38:34 +00:00
*/
public function __construct()
2014-04-01 18:38:34 +00:00
{
$this->short_open_tag = ini_get('short_open_tag');
2014-04-01 18:38:34 +00:00
}
/**
* Load template's source from file into current template object
*
* @param Smarty_Template_Source $source source object
2014-10-13 09:24:53 +00:00
*
2014-04-01 18:38:34 +00:00
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public function getContent(Smarty_Template_Source $source)
{
if ($source->exists) {
2014-04-01 18:38:34 +00:00
return '';
}
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
}
/**
* Render and output the template (without using the compiler)
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
2014-10-13 09:24:53 +00:00
*
2014-04-01 18:38:34 +00:00
* @return void
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
*/
public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
{
if (!$source->smarty->allow_php_templates) {
throw new SmartyException("PHP templates are disabled");
}
if (!$source->exists) {
$parentIsTpl = isset($this->parent) && $this->parent->_objType == 2;
throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" .
($parentIsTpl ? " in '{$this->parent->template_resource}'" : ''));
2014-04-01 18:38:34 +00:00
}
// prepare variables
extract($_template->getTemplateVars());
// include PHP template with short open tags enabled
2014-10-13 09:24:53 +00:00
ini_set('short_open_tag', '1');
/** @var Smarty_Internal_Template $_smarty_template
* used in included file
*/
$_smarty_template = $_template;
2014-04-01 18:38:34 +00:00
include($source->filepath);
2014-10-13 09:24:53 +00:00
ini_set('short_open_tag', $this->short_open_tag);
2014-04-01 18:38:34 +00:00
}
/**
* populate compiled object with compiled filepath
*
* @param Smarty_Template_Compiled $compiled compiled object
* @param Smarty_Internal_Template $_template template object (is ignored)
*/
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
{
$compiled->filepath = $_template->source->filepath;
$compiled->timestamp = $_template->source->timestamp;
$compiled->exists = $_template->source->exists;
$compiled->file_dependency[ $_template->source->uid ] =
array($compiled->filepath, $compiled->timestamp,
$_template->source->type,);
}
2014-04-01 18:38:34 +00:00
}