2020-04-13 15:30:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
2022-12-21 16:33:26 +01:00
|
|
|
use Smarty\Resource\FilePlugin;
|
2022-12-23 14:03:05 +01:00
|
|
|
use Smarty\Smarty;
|
2022-12-22 21:23:22 +01:00
|
|
|
use Smarty\Template;
|
|
|
|
|
use Smarty\Template\Source;
|
2022-12-21 16:33:26 +01:00
|
|
|
|
2020-04-13 15:30:52 +02:00
|
|
|
/**
|
|
|
|
|
* Ambiguous Filename Custom Resource Example
|
|
|
|
|
*
|
|
|
|
|
* @package Resource-examples
|
|
|
|
|
* @author Rodney Rehm
|
|
|
|
|
*/
|
2022-12-21 16:33:26 +01:00
|
|
|
class Smarty_Resource_AmbiguousPlugin extends FilePlugin
|
2020-04-13 15:30:52 +02:00
|
|
|
{
|
|
|
|
|
protected $directory;
|
|
|
|
|
protected $segment;
|
|
|
|
|
|
|
|
|
|
public function __construct($directory)
|
|
|
|
|
{
|
2022-03-10 02:06:00 +00:00
|
|
|
$this->directory = rtrim($directory ?? '', "/\\") . DIRECTORY_SEPARATOR;
|
2020-04-13 15:30:52 +02:00
|
|
|
// parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setSegment($segment)
|
|
|
|
|
{
|
|
|
|
|
$this->segment = $segment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* modify resource_name according to resource handlers specifications
|
|
|
|
|
*
|
|
|
|
|
* @param Smarty $smarty Smarty instance
|
|
|
|
|
* @param string $resource_name resource_name to make unique
|
|
|
|
|
*
|
|
|
|
|
* @return string unique resource name
|
|
|
|
|
*/
|
|
|
|
|
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
|
|
|
|
{
|
|
|
|
|
return get_class($this) . '#' . $this->segment . '#' . $resource_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* populate Source Object with meta data from Resource
|
|
|
|
|
*
|
2022-12-22 21:23:22 +01:00
|
|
|
* @param Source $source source object
|
|
|
|
|
* @param Template $_template template object
|
2020-04-13 15:30:52 +02:00
|
|
|
*/
|
2022-12-22 21:23:22 +01:00
|
|
|
public function populate(Source $source, Template $_template = null)
|
2020-04-13 15:30:52 +02:00
|
|
|
{
|
|
|
|
|
$segment = '';
|
|
|
|
|
if ($this->segment) {
|
|
|
|
|
$segment = rtrim($this->segment, "/\\") . DIRECTORY_SEPARATOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$source->filepath = $this->directory . $segment . $source->name;
|
|
|
|
|
$source->uid = sha1($source->filepath);
|
|
|
|
|
if ($_template->smarty->getCompileCheck() && !isset($source->timestamp)) {
|
|
|
|
|
$source->timestamp = @filemtime($source->filepath);
|
|
|
|
|
$source->exists = !!$source->timestamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|