diff options
| author | Uwe.Tews@googlemail.com <Uwe.Tews@googlemail.com> | 2014-06-06 02:40:04 +0000 |
|---|---|---|
| committer | Uwe.Tews@googlemail.com <Uwe.Tews@googlemail.com> | 2014-06-06 02:40:04 +0000 |
| commit | 425091a19f674cb3e869493c8beb85ac96ed7d42 (patch) | |
| tree | e4394a276e62eee3efb222d51cb5339f4db3793b /demo | |
| parent | ca6a908c833d68908c79f48b4514ffd43be4b88d (diff) | |
| download | smarty-425091a19f674cb3e869493c8beb85ac96ed7d42.tar.gz smarty-425091a19f674cb3e869493c8beb85ac96ed7d42.tar.bz2 smarty-425091a19f674cb3e869493c8beb85ac96ed7d42.zip | |
- fixed spelling, PHPDoc , minor errors, code cleanup
Diffstat (limited to 'demo')
| -rw-r--r-- | demo/index.php | 20 | ||||
| -rw-r--r-- | demo/plugins/cacheresource.apc.php | 17 | ||||
| -rw-r--r-- | demo/plugins/cacheresource.memcache.php | 22 | ||||
| -rw-r--r-- | demo/plugins/cacheresource.mysql.php | 38 | ||||
| -rw-r--r-- | demo/plugins/resource.extendsall.php | 12 | ||||
| -rw-r--r-- | demo/plugins/resource.mysql.php | 13 | ||||
| -rw-r--r-- | demo/plugins/resource.mysqls.php | 10 | ||||
| -rw-r--r-- | demo/templates/header.tpl | 2 | ||||
| -rw-r--r-- | demo/templates/index.tpl | 85 |
9 files changed, 117 insertions, 102 deletions
diff --git a/demo/index.php b/demo/index.php index b7d988f5..33f3035c 100644 --- a/demo/index.php +++ b/demo/index.php @@ -1,7 +1,7 @@ <?php - /** +/** * Example Application - + * * @package Example-application */ @@ -14,17 +14,17 @@ $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("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"))); + 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_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'); diff --git a/demo/plugins/cacheresource.apc.php b/demo/plugins/cacheresource.apc.php index 9854f638..d7336f2b 100644 --- a/demo/plugins/cacheresource.apc.php +++ b/demo/plugins/cacheresource.apc.php @@ -2,12 +2,12 @@ /** * 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 + * @author Uwe Tews */ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore { @@ -22,7 +22,8 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore /** * Read values for a set of keys from cache * - * @param array $keys list of keys to fetch + * @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 */ @@ -40,11 +41,12 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore /** * Save values for a set of keys to cache * - * @param array $keys list of values to save - * @param int $expire expiration time + * @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) + protected function write(array $keys, $expire = null) { foreach ($keys as $k => $v) { apc_store($k, $v, $expire); @@ -56,7 +58,8 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore /** * Remove values from cache * - * @param array $keys list of keys to delete + * @param array $keys list of keys to delete + * * @return boolean true on success, false on failure */ protected function delete(array $keys) diff --git a/demo/plugins/cacheresource.memcache.php b/demo/plugins/cacheresource.memcache.php index f38b00ac..e265365f 100644 --- a/demo/plugins/cacheresource.memcache.php +++ b/demo/plugins/cacheresource.memcache.php @@ -2,20 +2,19 @@ /** * 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 + * @author Rodney Rehm */ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore { /** * memcache instance + * * @var Memcache */ protected $memcache = null; @@ -23,13 +22,14 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore public function __construct() { $this->memcache = new Memcache(); - $this->memcache->addServer( '127.0.0.1', 11211 ); + $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 + * @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 */ @@ -53,11 +53,12 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore /** * Save values for a set of keys to cache * - * @param array $keys list of values to save - * @param int $expire expiration time + * @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) + protected function write(array $keys, $expire = null) { foreach ($keys as $k => $v) { $k = sha1($k); @@ -70,7 +71,8 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore /** * Remove values from cache * - * @param array $keys list of keys to delete + * @param array $keys list of keys to delete + * * @return boolean true on success, false on failure */ protected function delete(array $keys) @@ -90,6 +92,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore */ protected function purge() { - return $this->memcache->flush(); + $this->memcache->flush(); } } diff --git a/demo/plugins/cacheresource.mysql.php b/demo/plugins/cacheresource.mysql.php index 73771e7b..d8d00ab2 100644 --- a/demo/plugins/cacheresource.mysql.php +++ b/demo/plugins/cacheresource.mysql.php @@ -2,10 +2,8 @@ /** * 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', @@ -22,7 +20,7 @@ * ) ENGINE = InnoDB;</pre> * * @package CacheResource-examples - * @author Rodney Rehm + * @author Rodney Rehm */ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { @@ -36,7 +34,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); - } catch (PDOException $e) { + } + 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'); @@ -54,6 +53,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom * @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) @@ -74,10 +74,12 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom * 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 + * + * @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) @@ -98,17 +100,18 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom * @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, - )); + 'id' => $id, + 'name' => $name, + 'cache_id' => $cache_id, + 'compile_id' => $compile_id, + 'content' => $content, + )); return !!$this->save->rowCount(); } @@ -120,6 +123,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom * @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) @@ -129,7 +133,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom // returning the number of deleted caches would require a second query to count them $query = $this->db->query('TRUNCATE TABLE output_cache'); - return -1; + return - 1; } // build the filter $where = array(); @@ -147,8 +151,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom } // 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 .'|%') .')'; + $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)); diff --git a/demo/plugins/resource.extendsall.php b/demo/plugins/resource.extendsall.php index 586e6c8c..500b3c86 100644 --- a/demo/plugins/resource.extendsall.php +++ b/demo/plugins/resource.extendsall.php @@ -2,12 +2,11 @@ /** * 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 + * @author Rodney Rehm */ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends { @@ -16,22 +15,25 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends * * @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) + public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { $uid = ''; $sources = array(); $exists = true; foreach ($_template->smarty->getTemplateDir() as $key => $directory) { try { - $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name ); + $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name); if (!$s->exists) { continue; } $sources[$s->uid] = $s; $uid .= $s->filepath; - } catch (SmartyException $e) {} + } + catch (SmartyException $e) { + } } if (!$sources) { diff --git a/demo/plugins/resource.mysql.php b/demo/plugins/resource.mysql.php index af78394c..dfc9606b 100644 --- a/demo/plugins/resource.mysql.php +++ b/demo/plugins/resource.mysql.php @@ -2,10 +2,8 @@ /** * 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, @@ -13,12 +11,11 @@ * `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 + * @author Rodney Rehm */ class Smarty_Resource_Mysql extends Smarty_Resource_Custom { @@ -33,7 +30,8 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); - } catch (PDOException $e) { + } + catch (PDOException $e) { throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); @@ -46,6 +44,7 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom * @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) @@ -66,7 +65,9 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom * 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 + * + * @param string $name template name + * * @return integer timestamp (epoch) the template was modified */ protected function fetchTimestamp($name) diff --git a/demo/plugins/resource.mysqls.php b/demo/plugins/resource.mysqls.php index d16ad4b5..f694ddf1 100644 --- a/demo/plugins/resource.mysqls.php +++ b/demo/plugins/resource.mysqls.php @@ -2,13 +2,10 @@ /** * 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, @@ -16,12 +13,11 @@ * `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 + * @author Rodney Rehm */ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom { @@ -34,7 +30,8 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); - } catch (PDOException $e) { + } + catch (PDOException $e) { throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); @@ -46,6 +43,7 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom * @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) diff --git a/demo/templates/header.tpl b/demo/templates/header.tpl index 783210a1..13fa6cb5 100644 --- a/demo/templates/header.tpl +++ b/demo/templates/header.tpl @@ -1,5 +1,5 @@ <HTML> <HEAD> -<TITLE>{$title} - {$Name}</TITLE> + <TITLE>{$title} - {$Name}</TITLE> </HEAD> <BODY bgcolor="#ffffff"> diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl index 38d23341..1fbb6d37 100644 --- a/demo/templates/index.tpl +++ b/demo/templates/index.tpl @@ -4,18 +4,18 @@ <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} + {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 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} + The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME} -Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME} + Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME} -The value of {ldelim}$Name{rdelim} is <b>{$Name}</b> + The value of {ldelim}$Name{rdelim} is <b>{$Name}</b> variable modifier example of {ldelim}$Name|upper{rdelim} @@ -24,59 +24,64 @@ variable modifier example of {ldelim}$Name|upper{rdelim} 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} + {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: + 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> + {section name=sec1 loop=$contacts} + phone: {$contacts[sec1].phone} + <br> -testing strip tags -{strip} + 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> + <tr> + <td> + <A HREF="{$SCRIPT_NAME}"> + <font color="red">This is a test </font> + </A> + </td> + </tr> </table> -{/strip} + {/strip} </PRE> This is an example of the html_select_date function: <form> -{html_select_date start_year=1998 end_year=2010} + {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} + {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> + <select name=states> + {html_options values=$option_values selected=$option_selected output=$option_output} + </select> </form> {include file="footer.tpl"} |
