mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 02:14:26 +02:00
Fixed #476, Wrong demo directory location
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
title = Welcome to Smarty!
|
|
||||||
cutoff_size = 40
|
|
||||||
|
|
||||||
[setup]
|
|
||||||
bold = true
|
|
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Example Application
|
|
||||||
*
|
|
||||||
* @package Example-application
|
|
||||||
*/
|
|
||||||
|
|
||||||
require '../libs/Smarty.class.php';
|
|
||||||
|
|
||||||
$smarty = new Smarty;
|
|
||||||
|
|
||||||
//$smarty->force_compile = true;
|
|
||||||
$smarty->debugging = true;
|
|
||||||
$smarty->caching = true;
|
|
||||||
$smarty->cache_lifetime = 120;
|
|
||||||
|
|
||||||
$smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
|
|
||||||
$smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
|
|
||||||
$smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
|
|
||||||
$smarty->assign(
|
|
||||||
"Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"),
|
|
||||||
array("M", "N", "O", "P"))
|
|
||||||
);
|
|
||||||
|
|
||||||
$smarty->assign(
|
|
||||||
"contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
|
||||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))
|
|
||||||
);
|
|
||||||
|
|
||||||
$smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX"));
|
|
||||||
$smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));
|
|
||||||
$smarty->assign("option_selected", "NE");
|
|
||||||
|
|
||||||
$smarty->display('index.tpl');
|
|
@@ -1,88 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APC CacheResource
|
|
||||||
* CacheResource Implementation based on the KeyValueStore API to use
|
|
||||||
* memcache as the storage resource for Smarty's output caching.
|
|
||||||
* *
|
|
||||||
*
|
|
||||||
* @package CacheResource-examples
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Smarty_CacheResource_Apc constructor.
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
// test if APC is present
|
|
||||||
if (!function_exists('apc_cache_info')) {
|
|
||||||
throw new Exception('APC Template Caching Error: APC is not installed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read values for a set of keys from cache
|
|
||||||
*
|
|
||||||
* @param array $keys list of keys to fetch
|
|
||||||
*
|
|
||||||
* @return array list of values with the given keys used as indexes
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function read(array $keys)
|
|
||||||
{
|
|
||||||
$_res = array();
|
|
||||||
$res = apc_fetch($keys);
|
|
||||||
foreach ($res as $k => $v) {
|
|
||||||
$_res[ $k ] = $v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $_res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save values for a set of keys to cache
|
|
||||||
*
|
|
||||||
* @param array $keys list of values to save
|
|
||||||
* @param int $expire expiration time
|
|
||||||
*
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function write(array $keys, $expire = null)
|
|
||||||
{
|
|
||||||
foreach ($keys as $k => $v) {
|
|
||||||
apc_store($k, $v, $expire);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove values from cache
|
|
||||||
*
|
|
||||||
* @param array $keys list of keys to delete
|
|
||||||
*
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function delete(array $keys)
|
|
||||||
{
|
|
||||||
foreach ($keys as $k) {
|
|
||||||
apc_delete($k);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove *all* values from cache
|
|
||||||
*
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function purge()
|
|
||||||
{
|
|
||||||
return apc_clear_cache('user');
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,101 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Memcache CacheResource
|
|
||||||
* CacheResource Implementation based on the KeyValueStore API to use
|
|
||||||
* memcache as the storage resource for Smarty's output caching.
|
|
||||||
* Note that memcache has a limitation of 256 characters per cache-key.
|
|
||||||
* To avoid complications all cache-keys are translated to a sha1 hash.
|
|
||||||
*
|
|
||||||
* @package CacheResource-examples
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* memcache instance
|
|
||||||
*
|
|
||||||
* @var Memcache
|
|
||||||
*/
|
|
||||||
protected $memcache = null;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
if (class_exists('Memcached')) {
|
|
||||||
$this->memcache = new Memcached();
|
|
||||||
} else {
|
|
||||||
$this->memcache = new Memcache();
|
|
||||||
}
|
|
||||||
$this->memcache->addServer('127.0.0.1', 11211);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read values for a set of keys from cache
|
|
||||||
*
|
|
||||||
* @param array $keys list of keys to fetch
|
|
||||||
*
|
|
||||||
* @return array list of values with the given keys used as indexes
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function read(array $keys)
|
|
||||||
{
|
|
||||||
$_keys = $lookup = array();
|
|
||||||
foreach ($keys as $k) {
|
|
||||||
$_k = sha1($k);
|
|
||||||
$_keys[] = $_k;
|
|
||||||
$lookup[ $_k ] = $k;
|
|
||||||
}
|
|
||||||
$_res = array();
|
|
||||||
$res = $this->memcache->get($_keys);
|
|
||||||
foreach ($res as $k => $v) {
|
|
||||||
$_res[ $lookup[ $k ] ] = $v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $_res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save values for a set of keys to cache
|
|
||||||
*
|
|
||||||
* @param array $keys list of values to save
|
|
||||||
* @param int $expire expiration time
|
|
||||||
*
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function write(array $keys, $expire = null)
|
|
||||||
{
|
|
||||||
foreach ($keys as $k => $v) {
|
|
||||||
$k = sha1($k);
|
|
||||||
$this->memcache->set($k, $v, 0, $expire);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove values from cache
|
|
||||||
*
|
|
||||||
* @param array $keys list of keys to delete
|
|
||||||
*
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function delete(array $keys)
|
|
||||||
{
|
|
||||||
foreach ($keys as $k) {
|
|
||||||
$k = sha1($k);
|
|
||||||
$this->memcache->delete($k);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove *all* values from cache
|
|
||||||
*
|
|
||||||
* @return boolean true on success, false on failure
|
|
||||||
*/
|
|
||||||
protected function purge()
|
|
||||||
{
|
|
||||||
return $this->memcache->flush();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,169 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MySQL CacheResource
|
|
||||||
* CacheResource Implementation based on the Custom API to use
|
|
||||||
* MySQL as the storage resource for Smarty's output caching.
|
|
||||||
* Table definition:
|
|
||||||
* <pre>CREATE TABLE IF NOT EXISTS `output_cache` (
|
|
||||||
* `id` CHAR(40) NOT NULL COMMENT 'sha1 hash',
|
|
||||||
* `name` VARCHAR(250) NOT NULL,
|
|
||||||
* `cache_id` VARCHAR(250) NULL DEFAULT NULL,
|
|
||||||
* `compile_id` VARCHAR(250) NULL DEFAULT NULL,
|
|
||||||
* `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
* `content` LONGTEXT NOT NULL,
|
|
||||||
* PRIMARY KEY (`id`),
|
|
||||||
* INDEX(`name`),
|
|
||||||
* INDEX(`cache_id`),
|
|
||||||
* INDEX(`compile_id`),
|
|
||||||
* INDEX(`modified`)
|
|
||||||
* ) ENGINE = InnoDB;</pre>
|
|
||||||
*
|
|
||||||
* @package CacheResource-examples
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
|
||||||
{
|
|
||||||
// PDO instance
|
|
||||||
protected $db;
|
|
||||||
|
|
||||||
protected $fetch;
|
|
||||||
|
|
||||||
protected $fetchTimestamp;
|
|
||||||
|
|
||||||
protected $save;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty_CacheResource_Mysql constructor.
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
|
||||||
}
|
|
||||||
catch (PDOException $e) {
|
|
||||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
|
|
||||||
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');
|
|
||||||
$this->save = $this->db->prepare(
|
|
||||||
'REPLACE INTO output_cache (id, name, cache_id, compile_id, content)
|
|
||||||
VALUES (:id, :name, :cache_id, :compile_id, :content)'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fetch cached content and its modification time from data source
|
|
||||||
*
|
|
||||||
* @param string $id unique cache content identifier
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string $cache_id cache id
|
|
||||||
* @param string $compile_id compile id
|
|
||||||
* @param string $content cached content
|
|
||||||
* @param integer $mtime cache modification timestamp (epoch)
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime)
|
|
||||||
{
|
|
||||||
$this->fetch->execute(array('id' => $id));
|
|
||||||
$row = $this->fetch->fetch();
|
|
||||||
$this->fetch->closeCursor();
|
|
||||||
if ($row) {
|
|
||||||
$content = $row[ 'content' ];
|
|
||||||
$mtime = strtotime($row[ 'modified' ]);
|
|
||||||
} else {
|
|
||||||
$content = null;
|
|
||||||
$mtime = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch cached content's modification timestamp from data source
|
|
||||||
*
|
|
||||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content.
|
|
||||||
*
|
|
||||||
* @param string $id unique cache content identifier
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string $cache_id cache id
|
|
||||||
* @param string $compile_id compile id
|
|
||||||
*
|
|
||||||
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
|
|
||||||
*/
|
|
||||||
protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
|
|
||||||
{
|
|
||||||
$this->fetchTimestamp->execute(array('id' => $id));
|
|
||||||
$mtime = strtotime($this->fetchTimestamp->fetchColumn());
|
|
||||||
$this->fetchTimestamp->closeCursor();
|
|
||||||
|
|
||||||
return $mtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save content to cache
|
|
||||||
*
|
|
||||||
* @param string $id unique cache content identifier
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string $cache_id cache id
|
|
||||||
* @param string $compile_id compile id
|
|
||||||
* @param integer|null $exp_time seconds till expiration time in seconds or null
|
|
||||||
* @param string $content content to cache
|
|
||||||
*
|
|
||||||
* @return boolean success
|
|
||||||
*/
|
|
||||||
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
|
|
||||||
{
|
|
||||||
$this->save->execute(
|
|
||||||
array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
|
|
||||||
'content' => $content,)
|
|
||||||
);
|
|
||||||
|
|
||||||
return !!$this->save->rowCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete content from cache
|
|
||||||
*
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string $cache_id cache id
|
|
||||||
* @param string $compile_id compile id
|
|
||||||
* @param integer|null $exp_time seconds till expiration or null
|
|
||||||
*
|
|
||||||
* @return integer number of deleted caches
|
|
||||||
*/
|
|
||||||
protected function delete($name, $cache_id, $compile_id, $exp_time)
|
|
||||||
{
|
|
||||||
// delete the whole cache
|
|
||||||
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
|
|
||||||
// returning the number of deleted caches would require a second query to count them
|
|
||||||
$query = $this->db->query('TRUNCATE TABLE output_cache');
|
|
||||||
|
|
||||||
return - 1;
|
|
||||||
}
|
|
||||||
// build the filter
|
|
||||||
$where = array();
|
|
||||||
// equal test name
|
|
||||||
if ($name !== null) {
|
|
||||||
$where[] = 'name = ' . $this->db->quote($name);
|
|
||||||
}
|
|
||||||
// equal test compile_id
|
|
||||||
if ($compile_id !== null) {
|
|
||||||
$where[] = 'compile_id = ' . $this->db->quote($compile_id);
|
|
||||||
}
|
|
||||||
// range test expiration time
|
|
||||||
if ($exp_time !== null) {
|
|
||||||
$where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)';
|
|
||||||
}
|
|
||||||
// equal test cache_id and match sub-groups
|
|
||||||
if ($cache_id !== null) {
|
|
||||||
$where[] = '(cache_id = ' . $this->db->quote($cache_id) . ' OR cache_id LIKE ' .
|
|
||||||
$this->db->quote($cache_id . '|%') . ')';
|
|
||||||
}
|
|
||||||
// run delete query
|
|
||||||
$query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where));
|
|
||||||
|
|
||||||
return $query->rowCount();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,308 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PDO Cache Handler
|
|
||||||
* Allows you to store Smarty Cache files into your db.
|
|
||||||
* Example table :
|
|
||||||
* CREATE TABLE `smarty_cache` (
|
|
||||||
* `id` char(40) NOT NULL COMMENT 'sha1 hash',
|
|
||||||
* `name` varchar(250) NOT NULL,
|
|
||||||
* `cache_id` varchar(250) DEFAULT NULL,
|
|
||||||
* `compile_id` varchar(250) DEFAULT NULL,
|
|
||||||
* `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
* `expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
|
|
||||||
* `content` mediumblob NOT NULL,
|
|
||||||
* PRIMARY KEY (`id`),
|
|
||||||
* KEY `name` (`name`),
|
|
||||||
* KEY `cache_id` (`cache_id`),
|
|
||||||
* KEY `compile_id` (`compile_id`),
|
|
||||||
* KEY `modified` (`modified`),
|
|
||||||
* KEY `expire` (`expire`)
|
|
||||||
* ) ENGINE=InnoDB
|
|
||||||
* Example usage :
|
|
||||||
* $cnx = new PDO("mysql:host=localhost;dbname=mydb", "username", "password");
|
|
||||||
* $smarty->setCachingType('pdo');
|
|
||||||
* $smarty->loadPlugin('Smarty_CacheResource_Pdo');
|
|
||||||
* $smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo($cnx, 'smarty_cache'));
|
|
||||||
*
|
|
||||||
* @author Beno!t POLASZEK - 2014
|
|
||||||
*/
|
|
||||||
class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|
||||||
{
|
|
||||||
protected $fetchStatements = Array('default' => 'SELECT %2$s
|
|
||||||
FROM %1$s
|
|
||||||
WHERE 1
|
|
||||||
AND id = :id
|
|
||||||
AND cache_id IS NULL
|
|
||||||
AND compile_id IS NULL',
|
|
||||||
'withCacheId' => 'SELECT %2$s
|
|
||||||
FROM %1$s
|
|
||||||
WHERE 1
|
|
||||||
AND id = :id
|
|
||||||
AND cache_id = :cache_id
|
|
||||||
AND compile_id IS NULL',
|
|
||||||
'withCompileId' => 'SELECT %2$s
|
|
||||||
FROM %1$s
|
|
||||||
WHERE 1
|
|
||||||
AND id = :id
|
|
||||||
AND compile_id = :compile_id
|
|
||||||
AND cache_id IS NULL',
|
|
||||||
'withCacheIdAndCompileId' => 'SELECT %2$s
|
|
||||||
FROM %1$s
|
|
||||||
WHERE 1
|
|
||||||
AND id = :id
|
|
||||||
AND cache_id = :cache_id
|
|
||||||
AND compile_id = :compile_id');
|
|
||||||
protected $insertStatement = 'INSERT INTO %s
|
|
||||||
|
|
||||||
SET id = :id,
|
|
||||||
name = :name,
|
|
||||||
cache_id = :cache_id,
|
|
||||||
compile_id = :compile_id,
|
|
||||||
modified = CURRENT_TIMESTAMP,
|
|
||||||
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
|
|
||||||
content = :content
|
|
||||||
|
|
||||||
ON DUPLICATE KEY UPDATE
|
|
||||||
name = :name,
|
|
||||||
cache_id = :cache_id,
|
|
||||||
compile_id = :compile_id,
|
|
||||||
modified = CURRENT_TIMESTAMP,
|
|
||||||
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
|
|
||||||
content = :content';
|
|
||||||
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
|
|
||||||
protected $truncateStatement = 'TRUNCATE TABLE %s';
|
|
||||||
protected $fetchColumns = 'modified, content';
|
|
||||||
protected $fetchTimestampColumns = 'modified';
|
|
||||||
protected $pdo, $table, $database;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param PDO $pdo PDO : active connection
|
|
||||||
* @param string $table : table (or view) name
|
|
||||||
* @param string $database : optional - if table is located in another db
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Smarty_CacheResource_Pdo constructor.
|
|
||||||
*
|
|
||||||
* @param \PDO $pdo
|
|
||||||
* @param $table
|
|
||||||
* @param null $database
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function __construct(PDO $pdo, $table, $database = null)
|
|
||||||
{
|
|
||||||
if (is_null($table)) {
|
|
||||||
throw new SmartyException("Table name for caching can't be null");
|
|
||||||
}
|
|
||||||
$this->pdo = $pdo;
|
|
||||||
$this->table = $table;
|
|
||||||
$this->database = $database;
|
|
||||||
$this->fillStatementsWithTableName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Fills the table name into the statements.
|
|
||||||
*
|
|
||||||
* @return Current Instance
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function fillStatementsWithTableName()
|
|
||||||
{
|
|
||||||
foreach ($this->fetchStatements AS &$statement) {
|
|
||||||
$statement = sprintf($statement, $this->getTableName(), '%s');
|
|
||||||
}
|
|
||||||
$this->insertStatement = sprintf($this->insertStatement, $this->getTableName());
|
|
||||||
$this->deleteStatement = sprintf($this->deleteStatement, $this->getTableName(), '%s');
|
|
||||||
$this->truncateStatement = sprintf($this->truncateStatement, $this->getTableName());
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Gets the fetch statement, depending on what you specify
|
|
||||||
*
|
|
||||||
* @param string $columns : the column(s) name(s) you want to retrieve from the database
|
|
||||||
* @param string $id unique cache content identifier
|
|
||||||
* @param string|null $cache_id cache id
|
|
||||||
* @param string|null $compile_id compile id
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null)
|
|
||||||
{
|
|
||||||
if (!is_null($cache_id) && !is_null($compile_id)) {
|
|
||||||
$query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND
|
|
||||||
$args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id);
|
|
||||||
} elseif (is_null($cache_id) && !is_null($compile_id)) {
|
|
||||||
$query = $this->fetchStatements[ 'withCompileId' ] AND
|
|
||||||
$args = Array('id' => $id, 'compile_id' => $compile_id);
|
|
||||||
} elseif (!is_null($cache_id) && is_null($compile_id)) {
|
|
||||||
$query = $this->fetchStatements[ 'withCacheId' ] AND $args = Array('id' => $id, 'cache_id' => $cache_id);
|
|
||||||
} else {
|
|
||||||
$query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id);
|
|
||||||
}
|
|
||||||
$query = sprintf($query, $columns);
|
|
||||||
$stmt = $this->pdo->prepare($query);
|
|
||||||
foreach ($args AS $key => $value) {
|
|
||||||
$stmt->bindValue($key, $value);
|
|
||||||
}
|
|
||||||
return $stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fetch cached content and its modification time from data source
|
|
||||||
*
|
|
||||||
* @param string $id unique cache content identifier
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string|null $cache_id cache id
|
|
||||||
* @param string|null $compile_id compile id
|
|
||||||
* @param string $content cached content
|
|
||||||
* @param integer $mtime cache modification timestamp (epoch)
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function fetch($id, $name, $cache_id = null, $compile_id = null, &$content, &$mtime)
|
|
||||||
{
|
|
||||||
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
|
|
||||||
$stmt->execute();
|
|
||||||
$row = $stmt->fetch();
|
|
||||||
$stmt->closeCursor();
|
|
||||||
if ($row) {
|
|
||||||
$content = $this->outputContent($row[ 'content' ]);
|
|
||||||
$mtime = strtotime($row[ 'modified' ]);
|
|
||||||
} else {
|
|
||||||
$content = null;
|
|
||||||
$mtime = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch cached content's modification timestamp from data source
|
|
||||||
* {@internal implementing this method is optional.
|
|
||||||
* Only implement it if modification times can be accessed faster than loading the complete cached content.}}
|
|
||||||
*
|
|
||||||
* @param string $id unique cache content identifier
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string|null $cache_id cache id
|
|
||||||
* @param string|null $compile_id compile id
|
|
||||||
*
|
|
||||||
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
// protected function fetchTimestamp($id, $name, $cache_id = null, $compile_id = null) {
|
|
||||||
// $stmt = $this->getFetchStatement($this->fetchTimestampColumns, $id, $cache_id, $compile_id);
|
|
||||||
// $stmt -> execute();
|
|
||||||
// $mtime = strtotime($stmt->fetchColumn());
|
|
||||||
// $stmt -> closeCursor();
|
|
||||||
// return $mtime;
|
|
||||||
// }
|
|
||||||
/**
|
|
||||||
* Save content to cache
|
|
||||||
*
|
|
||||||
* @param string $id unique cache content identifier
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string|null $cache_id cache id
|
|
||||||
* @param string|null $compile_id compile id
|
|
||||||
* @param integer|null $exp_time seconds till expiration time in seconds or null
|
|
||||||
* @param string $content content to cache
|
|
||||||
*
|
|
||||||
* @return boolean success
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function save($id, $name, $cache_id = null, $compile_id = null, $exp_time, $content)
|
|
||||||
{
|
|
||||||
$stmt = $this->pdo->prepare($this->insertStatement);
|
|
||||||
$stmt->bindValue('id', $id);
|
|
||||||
$stmt->bindValue('name', $name);
|
|
||||||
$stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
|
||||||
$stmt->bindValue('expire', (int)$exp_time, PDO::PARAM_INT);
|
|
||||||
$stmt->bindValue('content', $this->inputContent($content));
|
|
||||||
$stmt->execute();
|
|
||||||
return !!$stmt->rowCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Encodes the content before saving to database
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
* @return string $content
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function inputContent($content)
|
|
||||||
{
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Decodes the content before saving to database
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
* @return string $content
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function outputContent($content)
|
|
||||||
{
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete content from cache
|
|
||||||
*
|
|
||||||
* @param string|null $name template name
|
|
||||||
* @param string|null $cache_id cache id
|
|
||||||
* @param string|null $compile_id compile id
|
|
||||||
* @param integer|null|-1 $exp_time seconds till expiration or null
|
|
||||||
*
|
|
||||||
* @return integer number of deleted caches
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function delete($name = null, $cache_id = null, $compile_id = null, $exp_time = null)
|
|
||||||
{
|
|
||||||
// delete the whole cache
|
|
||||||
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
|
|
||||||
// returning the number of deleted caches would require a second query to count them
|
|
||||||
$this->pdo->query($this->truncateStatement);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// build the filter
|
|
||||||
$where = array();
|
|
||||||
// equal test name
|
|
||||||
if ($name !== null) {
|
|
||||||
$where[] = 'name = ' . $this->pdo->quote($name);
|
|
||||||
}
|
|
||||||
// equal test cache_id and match sub-groups
|
|
||||||
if ($cache_id !== null) {
|
|
||||||
$where[] = '(cache_id = ' . $this->pdo->quote($cache_id) . ' OR cache_id LIKE ' .
|
|
||||||
$this->pdo->quote($cache_id . '|%') . ')';
|
|
||||||
}
|
|
||||||
// equal test compile_id
|
|
||||||
if ($compile_id !== null) {
|
|
||||||
$where[] = 'compile_id = ' . $this->pdo->quote($compile_id);
|
|
||||||
}
|
|
||||||
// for clearing expired caches
|
|
||||||
if ($exp_time === Smarty::CLEAR_EXPIRED) {
|
|
||||||
$where[] = 'expire < CURRENT_TIMESTAMP';
|
|
||||||
} // range test expiration time
|
|
||||||
elseif ($exp_time !== null) {
|
|
||||||
$where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)';
|
|
||||||
}
|
|
||||||
// run delete query
|
|
||||||
$query = $this->pdo->query(sprintf($this->deleteStatement, join(' AND ', $where)));
|
|
||||||
return $query->rowCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the formatted table name
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function getTableName()
|
|
||||||
{
|
|
||||||
return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PDO Cache Handler with GZIP support
|
|
||||||
* Example usage :
|
|
||||||
* $cnx = new PDO("mysql:host=localhost;dbname=mydb", "username", "password");
|
|
||||||
* $smarty->setCachingType('pdo_gzip');
|
|
||||||
* $smarty->loadPlugin('Smarty_CacheResource_Pdo_Gzip');
|
|
||||||
* $smarty->registerCacheResource('pdo_gzip', new Smarty_CacheResource_Pdo_Gzip($cnx, 'smarty_cache'));
|
|
||||||
*
|
|
||||||
* @require Smarty_CacheResource_Pdo class
|
|
||||||
* @author Beno!t POLASZEK - 2014
|
|
||||||
*/
|
|
||||||
require_once 'cacheresource.pdo.php';
|
|
||||||
|
|
||||||
class Smarty_CacheResource_Pdo_Gzip extends Smarty_CacheResource_Pdo
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Encodes the content before saving to database
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
* @return string $content
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function inputContent($content)
|
|
||||||
{
|
|
||||||
return gzdeflate($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Decodes the content before saving to database
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
* @return string $content
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function outputContent($content)
|
|
||||||
{
|
|
||||||
return gzinflate($content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extends All Resource
|
|
||||||
* Resource Implementation modifying the extends-Resource to walk
|
|
||||||
* through the template_dirs and inherit all templates of the same name
|
|
||||||
*
|
|
||||||
* @package Resource-examples
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* populate Source Object with meta data from Resource
|
|
||||||
*
|
|
||||||
* @param Smarty_Template_Source $source source object
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
|
||||||
{
|
|
||||||
$uid = '';
|
|
||||||
$sources = array();
|
|
||||||
$timestamp = 0;
|
|
||||||
foreach ($source->smarty->getTemplateDir() as $key => $directory) {
|
|
||||||
try {
|
|
||||||
$s = Smarty_Resource::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name);
|
|
||||||
if (!$s->exists) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$sources[ $s->uid ] = $s;
|
|
||||||
$uid .= $s->filepath;
|
|
||||||
$timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp;
|
|
||||||
}
|
|
||||||
catch (SmartyException $e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$sources) {
|
|
||||||
$source->exists = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sources = array_reverse($sources, true);
|
|
||||||
reset($sources);
|
|
||||||
$s = current($sources);
|
|
||||||
$source->components = $sources;
|
|
||||||
$source->filepath = $s->filepath;
|
|
||||||
$source->uid = sha1($uid . $source->smarty->_joined_template_dir);
|
|
||||||
$source->exists = true;
|
|
||||||
$source->timestamp = $timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Disable timestamp checks for extendsall resource.
|
|
||||||
* The individual source components will be checked.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function checkTimestamps()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,88 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MySQL Resource
|
|
||||||
* Resource Implementation based on the Custom API to use
|
|
||||||
* MySQL as the storage resource for Smarty's templates and configs.
|
|
||||||
* Table definition:
|
|
||||||
* <pre>CREATE TABLE IF NOT EXISTS `templates` (
|
|
||||||
* `name` varchar(100) NOT NULL,
|
|
||||||
* `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
* `source` text,
|
|
||||||
* PRIMARY KEY (`name`)
|
|
||||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre>
|
|
||||||
* Demo data:
|
|
||||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
|
|
||||||
*
|
|
||||||
* @package Resource-examples
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
|
||||||
{
|
|
||||||
// PDO instance
|
|
||||||
protected $db;
|
|
||||||
|
|
||||||
// prepared fetch() statement
|
|
||||||
protected $fetch;
|
|
||||||
|
|
||||||
// prepared fetchTimestamp() statement
|
|
||||||
protected $mtime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty_Resource_Mysql constructor.
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
|
||||||
}
|
|
||||||
catch (PDOException $e) {
|
|
||||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
|
|
||||||
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a template and its modification time from database
|
|
||||||
*
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string $source template source
|
|
||||||
* @param integer $mtime template modification timestamp (epoch)
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function fetch($name, &$source, &$mtime)
|
|
||||||
{
|
|
||||||
$this->fetch->execute(array('name' => $name));
|
|
||||||
$row = $this->fetch->fetch();
|
|
||||||
$this->fetch->closeCursor();
|
|
||||||
if ($row) {
|
|
||||||
$source = $row[ 'source' ];
|
|
||||||
$mtime = strtotime($row[ 'modified' ]);
|
|
||||||
} else {
|
|
||||||
$source = null;
|
|
||||||
$mtime = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a template's modification time from database
|
|
||||||
*
|
|
||||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source.
|
|
||||||
*
|
|
||||||
* @param string $name template name
|
|
||||||
*
|
|
||||||
* @return integer timestamp (epoch) the template was modified
|
|
||||||
*/
|
|
||||||
protected function fetchTimestamp($name)
|
|
||||||
{
|
|
||||||
$this->mtime->execute(array('name' => $name));
|
|
||||||
$mtime = $this->mtime->fetchColumn();
|
|
||||||
$this->mtime->closeCursor();
|
|
||||||
|
|
||||||
return strtotime($mtime);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,68 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MySQL Resource
|
|
||||||
* Resource Implementation based on the Custom API to use
|
|
||||||
* MySQL as the storage resource for Smarty's templates and configs.
|
|
||||||
* Note that this MySQL implementation fetches the source and timestamps in
|
|
||||||
* a single database query, instead of two separate like resource.mysql.php does.
|
|
||||||
* Table definition:
|
|
||||||
* <pre>CREATE TABLE IF NOT EXISTS `templates` (
|
|
||||||
* `name` varchar(100) NOT NULL,
|
|
||||||
* `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
* `source` text,
|
|
||||||
* PRIMARY KEY (`name`)
|
|
||||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre>
|
|
||||||
* Demo data:
|
|
||||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
|
|
||||||
*
|
|
||||||
* @package Resource-examples
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
|
||||||
{
|
|
||||||
// PDO instance
|
|
||||||
protected $db;
|
|
||||||
|
|
||||||
// prepared fetch() statement
|
|
||||||
protected $fetch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty_Resource_Mysqls constructor.
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
|
||||||
}
|
|
||||||
catch (PDOException $e) {
|
|
||||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a template and its modification time from database
|
|
||||||
*
|
|
||||||
* @param string $name template name
|
|
||||||
* @param string $source template source
|
|
||||||
* @param integer $mtime template modification timestamp (epoch)
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function fetch($name, &$source, &$mtime)
|
|
||||||
{
|
|
||||||
$this->fetch->execute(array('name' => $name));
|
|
||||||
$row = $this->fetch->fetch();
|
|
||||||
$this->fetch->closeCursor();
|
|
||||||
if ($row) {
|
|
||||||
$source = $row[ 'source' ];
|
|
||||||
$mtime = strtotime($row[ 'modified' ]);
|
|
||||||
} else {
|
|
||||||
$source = null;
|
|
||||||
$mtime = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,2 +0,0 @@
|
|||||||
</BODY>
|
|
||||||
</HTML>
|
|
@@ -1,5 +0,0 @@
|
|||||||
<HTML>
|
|
||||||
<HEAD>
|
|
||||||
<TITLE>{$title} - {$Name}</TITLE>
|
|
||||||
</HEAD>
|
|
||||||
<BODY bgcolor="#ffffff">
|
|
@@ -1,87 +0,0 @@
|
|||||||
{config_load file="test.conf" section="setup"}
|
|
||||||
{include file="header.tpl" title=foo}
|
|
||||||
|
|
||||||
<PRE>
|
|
||||||
|
|
||||||
{* bold and title are read from the config file *}
|
|
||||||
{if #bold#}<b>{/if}
|
|
||||||
{* capitalize the first letters of each word of the title *}
|
|
||||||
Title: {#title#|capitalize}
|
|
||||||
{if #bold#}</b>{/if}
|
|
||||||
|
|
||||||
The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
|
|
||||||
|
|
||||||
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
|
|
||||||
|
|
||||||
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
|
|
||||||
|
|
||||||
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
|
|
||||||
|
|
||||||
variable modifier example of {ldelim}$Name|upper{rdelim}
|
|
||||||
|
|
||||||
<b>{$Name|upper}</b>
|
|
||||||
|
|
||||||
|
|
||||||
An example of a section loop:
|
|
||||||
|
|
||||||
{section name=outer
|
|
||||||
loop=$FirstName}
|
|
||||||
{if $smarty.section.outer.index is odd by 2}
|
|
||||||
{$smarty.section.outer.rownum} . {$FirstName[outer]} {$LastName[outer]}
|
|
||||||
{else}
|
|
||||||
{$smarty.section.outer.rownum} * {$FirstName[outer]} {$LastName[outer]}
|
|
||||||
{/if}
|
|
||||||
{sectionelse}
|
|
||||||
none
|
|
||||||
{/section}
|
|
||||||
|
|
||||||
An example of section looped key values:
|
|
||||||
|
|
||||||
{section name=sec1 loop=$contacts}
|
|
||||||
phone: {$contacts[sec1].phone}
|
|
||||||
<br>
|
|
||||||
|
|
||||||
fax: {$contacts[sec1].fax}
|
|
||||||
<br>
|
|
||||||
|
|
||||||
cell: {$contacts[sec1].cell}
|
|
||||||
<br>
|
|
||||||
{/section}
|
|
||||||
<p>
|
|
||||||
|
|
||||||
testing strip tags
|
|
||||||
{strip}
|
|
||||||
<table border=0>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<A HREF="{$SCRIPT_NAME}">
|
|
||||||
<font color="red">This is a test </font>
|
|
||||||
</A>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
{/strip}
|
|
||||||
|
|
||||||
</PRE>
|
|
||||||
|
|
||||||
This is an example of the html_select_date function:
|
|
||||||
|
|
||||||
<form>
|
|
||||||
{html_select_date start_year=1998 end_year=2010}
|
|
||||||
</form>
|
|
||||||
|
|
||||||
This is an example of the html_select_time function:
|
|
||||||
|
|
||||||
<form>
|
|
||||||
{html_select_time use_24_hours=false}
|
|
||||||
</form>
|
|
||||||
|
|
||||||
This is an example of the html_options function:
|
|
||||||
|
|
||||||
<form>
|
|
||||||
<select name=states>
|
|
||||||
{html_options values=$option_values selected=$option_selected output=$option_output}
|
|
||||||
</select>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{include file="footer.tpl"}
|
|
@@ -11,6 +11,11 @@
|
|||||||
*/
|
*/
|
||||||
class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Smarty_CacheResource_Apc constructor.
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// test if APC is present
|
// test if APC is present
|
||||||
|
@@ -96,6 +96,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
|||||||
*/
|
*/
|
||||||
protected function purge()
|
protected function purge()
|
||||||
{
|
{
|
||||||
$this->memcache->flush();
|
return $this->memcache->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,11 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
|||||||
|
|
||||||
protected $save;
|
protected $save;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty_CacheResource_Mysql constructor.
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@@ -29,35 +29,30 @@
|
|||||||
*/
|
*/
|
||||||
class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $fetchStatements = Array('default' => 'SELECT %2$s
|
protected $fetchStatements = Array('default' => 'SELECT %2$s
|
||||||
FROM %1$s
|
FROM %1$s
|
||||||
WHERE 1
|
WHERE 1
|
||||||
AND id = :id
|
AND id = :id
|
||||||
AND cache_id IS NULL
|
AND cache_id IS NULL
|
||||||
AND compile_id IS NULL',
|
AND compile_id IS NULL',
|
||||||
|
|
||||||
'withCacheId' => 'SELECT %2$s
|
'withCacheId' => 'SELECT %2$s
|
||||||
FROM %1$s
|
FROM %1$s
|
||||||
WHERE 1
|
WHERE 1
|
||||||
AND id = :id
|
AND id = :id
|
||||||
AND cache_id = :cache_id
|
AND cache_id = :cache_id
|
||||||
AND compile_id IS NULL',
|
AND compile_id IS NULL',
|
||||||
|
|
||||||
'withCompileId' => 'SELECT %2$s
|
'withCompileId' => 'SELECT %2$s
|
||||||
FROM %1$s
|
FROM %1$s
|
||||||
WHERE 1
|
WHERE 1
|
||||||
AND id = :id
|
AND id = :id
|
||||||
AND compile_id = :compile_id
|
AND compile_id = :compile_id
|
||||||
AND cache_id IS NULL',
|
AND cache_id IS NULL',
|
||||||
|
|
||||||
'withCacheIdAndCompileId' => 'SELECT %2$s
|
'withCacheIdAndCompileId' => 'SELECT %2$s
|
||||||
FROM %1$s
|
FROM %1$s
|
||||||
WHERE 1
|
WHERE 1
|
||||||
AND id = :id
|
AND id = :id
|
||||||
AND cache_id = :cache_id
|
AND cache_id = :cache_id
|
||||||
AND compile_id = :compile_id');
|
AND compile_id = :compile_id');
|
||||||
|
|
||||||
protected $insertStatement = 'INSERT INTO %s
|
protected $insertStatement = 'INSERT INTO %s
|
||||||
|
|
||||||
SET id = :id,
|
SET id = :id,
|
||||||
@@ -75,15 +70,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
modified = CURRENT_TIMESTAMP,
|
modified = CURRENT_TIMESTAMP,
|
||||||
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
|
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
|
||||||
content = :content';
|
content = :content';
|
||||||
|
|
||||||
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
|
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
|
||||||
|
|
||||||
protected $truncateStatement = 'TRUNCATE TABLE %s';
|
protected $truncateStatement = 'TRUNCATE TABLE %s';
|
||||||
|
|
||||||
protected $fetchColumns = 'modified, content';
|
protected $fetchColumns = 'modified, content';
|
||||||
|
|
||||||
protected $fetchTimestampColumns = 'modified';
|
protected $fetchTimestampColumns = 'modified';
|
||||||
|
|
||||||
protected $pdo, $table, $database;
|
protected $pdo, $table, $database;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -93,17 +83,23 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
* @param string $table : table (or view) name
|
* @param string $table : table (or view) name
|
||||||
* @param string $database : optional - if table is located in another db
|
* @param string $database : optional - if table is located in another db
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Smarty_CacheResource_Pdo constructor.
|
||||||
|
*
|
||||||
|
* @param \PDO $pdo
|
||||||
|
* @param $table
|
||||||
|
* @param null $database
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
public function __construct(PDO $pdo, $table, $database = null)
|
public function __construct(PDO $pdo, $table, $database = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (is_null($table)) {
|
if (is_null($table)) {
|
||||||
throw new SmartyException("Table name for caching can't be null");
|
throw new SmartyException("Table name for caching can't be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdo = $pdo;
|
$this->pdo = $pdo;
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
|
|
||||||
$this->fillStatementsWithTableName();
|
$this->fillStatementsWithTableName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,15 +111,12 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
*/
|
*/
|
||||||
protected function fillStatementsWithTableName()
|
protected function fillStatementsWithTableName()
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach ($this->fetchStatements AS &$statement) {
|
foreach ($this->fetchStatements AS &$statement) {
|
||||||
$statement = sprintf($statement, $this->getTableName(), '%s');
|
$statement = sprintf($statement, $this->getTableName(), '%s');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->insertStatement = sprintf($this->insertStatement, $this->getTableName());
|
$this->insertStatement = sprintf($this->insertStatement, $this->getTableName());
|
||||||
$this->deleteStatement = sprintf($this->deleteStatement, $this->getTableName(), '%s');
|
$this->deleteStatement = sprintf($this->deleteStatement, $this->getTableName(), '%s');
|
||||||
$this->truncateStatement = sprintf($this->truncateStatement, $this->getTableName());
|
$this->truncateStatement = sprintf($this->truncateStatement, $this->getTableName());
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +131,6 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
*/
|
*/
|
||||||
protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null)
|
protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!is_null($cache_id) && !is_null($compile_id)) {
|
if (!is_null($cache_id) && !is_null($compile_id)) {
|
||||||
$query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND
|
$query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND
|
||||||
$args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id);
|
$args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id);
|
||||||
@@ -150,15 +142,11 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
} else {
|
} else {
|
||||||
$query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id);
|
$query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = sprintf($query, $columns);
|
$query = sprintf($query, $columns);
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare($query);
|
$stmt = $this->pdo->prepare($query);
|
||||||
|
|
||||||
foreach ($args AS $key => $value) {
|
foreach ($args AS $key => $value) {
|
||||||
$stmt->bindValue($key, $value);
|
$stmt->bindValue($key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,12 +165,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
*/
|
*/
|
||||||
protected function fetch($id, $name, $cache_id = null, $compile_id = null, &$content, &$mtime)
|
protected function fetch($id, $name, $cache_id = null, $compile_id = null, &$content, &$mtime)
|
||||||
{
|
{
|
||||||
|
|
||||||
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
|
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$row = $stmt->fetch();
|
$row = $stmt->fetch();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$content = $this->outputContent($row[ 'content' ]);
|
$content = $this->outputContent($row[ 'content' ]);
|
||||||
$mtime = strtotime($row[ 'modified' ]);
|
$mtime = strtotime($row[ 'modified' ]);
|
||||||
@@ -212,7 +198,6 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
// $stmt -> closeCursor();
|
// $stmt -> closeCursor();
|
||||||
// return $mtime;
|
// return $mtime;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save content to cache
|
* Save content to cache
|
||||||
*
|
*
|
||||||
@@ -228,17 +213,14 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
*/
|
*/
|
||||||
protected function save($id, $name, $cache_id = null, $compile_id = null, $exp_time, $content)
|
protected function save($id, $name, $cache_id = null, $compile_id = null, $exp_time, $content)
|
||||||
{
|
{
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare($this->insertStatement);
|
$stmt = $this->pdo->prepare($this->insertStatement);
|
||||||
|
|
||||||
$stmt->bindValue('id', $id);
|
$stmt->bindValue('id', $id);
|
||||||
$stmt->bindValue('name', $name);
|
$stmt->bindValue('name', $name);
|
||||||
$stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
$stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
||||||
$stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
$stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
||||||
$stmt->bindValue('expire', (int) $exp_time, PDO::PARAM_INT);
|
$stmt->bindValue('expire', (int)$exp_time, PDO::PARAM_INT);
|
||||||
$stmt->bindValue('content', $this->inputContent($content));
|
$stmt->bindValue('content', $this->inputContent($content));
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
return !!$stmt->rowCount();
|
return !!$stmt->rowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,22 +251,21 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
/**
|
/**
|
||||||
* Delete content from cache
|
* Delete content from cache
|
||||||
*
|
*
|
||||||
* @param string|null $name template name
|
* @param string|null $name template name
|
||||||
* @param string|null $cache_id cache id
|
* @param string|null $cache_id cache id
|
||||||
* @param string|null $compile_id compile id
|
* @param string|null $compile_id compile id
|
||||||
* @param integer|null|-1 $exp_time seconds till expiration or null
|
* @param integer|null|-1 $exp_time seconds till expiration or null
|
||||||
*
|
*
|
||||||
* @return integer number of deleted caches
|
* @return integer number of deleted caches
|
||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
protected function delete($name = null, $cache_id = null, $compile_id = null, $exp_time = null)
|
protected function delete($name = null, $cache_id = null, $compile_id = null, $exp_time = null)
|
||||||
{
|
{
|
||||||
|
// delete the whole cache
|
||||||
// delete the whole cache
|
|
||||||
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
|
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
|
||||||
// returning the number of deleted caches would require a second query to count them
|
// returning the number of deleted caches would require a second query to count them
|
||||||
$this->pdo->query($this->truncateStatement);
|
$this->pdo->query($this->truncateStatement);
|
||||||
return - 1;
|
return -1;
|
||||||
}
|
}
|
||||||
// build the filter
|
// build the filter
|
||||||
$where = array();
|
$where = array();
|
||||||
|
@@ -28,6 +28,11 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
|||||||
// prepared fetchTimestamp() statement
|
// prepared fetchTimestamp() statement
|
||||||
protected $mtime;
|
protected $mtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty_Resource_Mysql constructor.
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@@ -27,6 +27,11 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
|||||||
// prepared fetch() statement
|
// prepared fetch() statement
|
||||||
protected $fetch;
|
protected $fetch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty_Resource_Mysqls constructor.
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user