summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorSimon Wisselink <wisskid@users.noreply.github.com>2023-08-08 00:04:14 +0200
committerGitHub <noreply@github.com>2023-08-08 00:04:14 +0200
commit8fd949ac5d073c640914f8c2ba96a3a7fc8b8474 (patch)
tree7b78ca54d65f63991d78c4874ed255a9f6ae716b /demo
parenta3cbdc46fbee148f2e0a7c2bf8f0840e5ef2dce0 (diff)
downloadsmarty-8fd949ac5d073c640914f8c2ba96a3a7fc8b8474.tar.gz
smarty-8fd949ac5d073c640914f8c2ba96a3a7fc8b8474.tar.bz2
smarty-8fd949ac5d073c640914f8c2ba96a3a7fc8b8474.zip
Smarty5 (#852)
* WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
Diffstat (limited to 'demo')
-rw-r--r--demo/index.php8
-rw-r--r--demo/plugins/cacheresource.apc.php85
-rw-r--r--demo/plugins/cacheresource.memcache.php99
-rw-r--r--demo/plugins/cacheresource.mysql.php183
-rw-r--r--demo/plugins/cacheresource.pdo.php346
-rw-r--r--demo/plugins/cacheresource.pdo_gzip.php42
-rw-r--r--demo/plugins/resource.extendsall.php62
-rw-r--r--demo/plugins/resource.mysql.php101
-rw-r--r--demo/plugins/resource.mysqls.php77
-rw-r--r--demo/templates/index.tpl2
10 files changed, 4 insertions, 1001 deletions
diff --git a/demo/index.php b/demo/index.php
index 3aed3716..705478ff 100644
--- a/demo/index.php
+++ b/demo/index.php
@@ -2,11 +2,11 @@
/**
* Example Application
*
- * @package Example-application
+
*/
-require '../libs/Smarty.class.php';
-$smarty = new Smarty;
-//$smarty->force_compile = true;
+
+$smarty = new \Smarty\Smarty;
+
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
diff --git a/demo/plugins/cacheresource.apc.php b/demo/plugins/cacheresource.apc.php
deleted file mode 100644
index 7867cc59..00000000
--- a/demo/plugins/cacheresource.apc.php
+++ /dev/null
@@ -1,85 +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');
- }
-}
diff --git a/demo/plugins/cacheresource.memcache.php b/demo/plugins/cacheresource.memcache.php
deleted file mode 100644
index 71fe9d3f..00000000
--- a/demo/plugins/cacheresource.memcache.php
+++ /dev/null
@@ -1,99 +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;
-
- /**
- * Smarty_CacheResource_Memcache constructor.
- */
- 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)
- {
- $res = array();
- foreach ($keys as $key) {
- $k = sha1($key);
- $res[$key] = $this->memcache->get($k);
- }
- 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);
- if (class_exists('Memcached')) {
- $this->memcache->set($k, $v, $expire);
- } else {
- $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();
- }
-}
diff --git a/demo/plugins/cacheresource.mysql.php b/demo/plugins/cacheresource.mysql.php
deleted file mode 100644
index c5037eb1..00000000
--- a/demo/plugins/cacheresource.mysql.php
+++ /dev/null
@@ -1,183 +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
-{
- /**
- * @var \PDO
- */
- protected $db;
-
- /**
- * @var \PDOStatement
- */
- protected $fetch;
-
- /**
- * @var \PDOStatement
- */
- protected $fetchTimestamp;
-
- /**
- * @var \PDOStatement
- */
- 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();
- }
-}
diff --git a/demo/plugins/cacheresource.pdo.php b/demo/plugins/cacheresource.pdo.php
deleted file mode 100644
index ae3ebbf7..00000000
--- a/demo/plugins/cacheresource.pdo.php
+++ /dev/null
@@ -1,346 +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
-{
- /**
- * @var string[]
- */
- 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');
-
- /**
- * @var string
- */
- 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';
-
- /**
- * @var string
- */
- protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
-
- /**
- * @var string
- */
- protected $truncateStatement = 'TRUNCATE TABLE %s';
-
- /**
- * @var string
- */
- protected $fetchColumns = 'modified, content';
-
- /**
- * @var string
- */
- protected $fetchTimestampColumns = 'modified';
-
- /**
- * @var \PDO
- */
- protected $pdo;
-
- /**
- * @var
- */
- protected $table;
-
- /**
- * @var null
- */
- protected $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
- *
- * @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 $this 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
- * @return \PDOStatement
- */
- protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null)
- {
- $args = array();
- 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, $compile_id, &$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, $compile_id, $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}`";
- }
-}
diff --git a/demo/plugins/cacheresource.pdo_gzip.php b/demo/plugins/cacheresource.pdo_gzip.php
deleted file mode 100644
index 5560b9e3..00000000
--- a/demo/plugins/cacheresource.pdo_gzip.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-require_once 'cacheresource.pdo.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
- */
-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);
- }
-}
diff --git a/demo/plugins/resource.extendsall.php b/demo/plugins/resource.extendsall.php
deleted file mode 100644
index a547d41d..00000000
--- a/demo/plugins/resource.extendsall.php
+++ /dev/null
@@ -1,62 +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 false
- */
- public function checkTimestamps()
- {
- return false;
- }
-}
diff --git a/demo/plugins/resource.mysql.php b/demo/plugins/resource.mysql.php
deleted file mode 100644
index 95a3c2ba..00000000
--- a/demo/plugins/resource.mysql.php
+++ /dev/null
@@ -1,101 +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
- *
- * @var \PDO
- */
- protected $db;
-
- /**
- * prepared fetch() statement
- *
- * @var \PDOStatement
- */
- protected $fetch;
-
- /**
- * prepared fetchTimestamp() statement
- *
- * @var \PDOStatement
- */
- 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);
- }
-}
diff --git a/demo/plugins/resource.mysqls.php b/demo/plugins/resource.mysqls.php
deleted file mode 100644
index 148a8dd6..00000000
--- a/demo/plugins/resource.mysqls.php
+++ /dev/null
@@ -1,77 +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
- *
- * @var \PDO
- */
- protected $db;
-
- /**
- * prepared fetch() statement
- *
- * @var \PDOStatement
- */
- 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;
- }
- }
-}
diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl
index 1fbb6d37..1a0f431b 100644
--- a/demo/templates/index.tpl
+++ b/demo/templates/index.tpl
@@ -11,8 +11,6 @@
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>