├── Classes └── Database.php ├── Config ├── Config.php └── Smarty │ └── SmartyTemplate.php ├── Controllers ├── BaseController.php └── Home.php ├── Loader.php ├── Models ├── BaseModel.php └── HomeModel.php ├── README.md ├── autoload.php ├── constants.php ├── index.php └── smarty ├── Autoloader.php ├── Smarty.class.php ├── SmartyBC.class.php ├── debug.tpl ├── plugins ├── block.textformat.php ├── function.counter.php ├── function.cycle.php ├── function.fetch.php ├── function.html_checkboxes.php ├── function.html_image.php ├── function.html_options.php ├── function.html_radios.php ├── function.html_select_date.php ├── function.html_select_time.php ├── function.html_table.php ├── function.mailto.php ├── function.math.php ├── modifier.capitalize.php ├── modifier.date_format.php ├── modifier.debug_print_var.php ├── modifier.escape.php ├── modifier.regex_replace.php ├── modifier.replace.php ├── modifier.spacify.php ├── modifier.truncate.php ├── modifiercompiler.cat.php ├── modifiercompiler.count_characters.php ├── modifiercompiler.count_paragraphs.php ├── modifiercompiler.count_sentences.php ├── modifiercompiler.count_words.php ├── modifiercompiler.default.php ├── modifiercompiler.escape.php ├── modifiercompiler.from_charset.php ├── modifiercompiler.indent.php ├── modifiercompiler.lower.php ├── modifiercompiler.noprint.php ├── modifiercompiler.string_format.php ├── modifiercompiler.strip.php ├── modifiercompiler.strip_tags.php ├── modifiercompiler.to_charset.php ├── modifiercompiler.unescape.php ├── modifiercompiler.upper.php ├── modifiercompiler.wordwrap.php ├── outputfilter.trimwhitespace.php ├── shared.escape_special_chars.php ├── shared.literal_compiler_param.php ├── shared.make_timestamp.php ├── shared.mb_str_replace.php ├── shared.mb_unicode.php ├── shared.mb_wordwrap.php └── variablefilter.htmlspecialchars.php ├── sysplugins ├── smarty_cacheresource.php ├── smarty_cacheresource_custom.php ├── smarty_cacheresource_keyvaluestore.php ├── smarty_data.php ├── smarty_internal_cacheresource_file.php ├── smarty_internal_compile_append.php ├── smarty_internal_compile_assign.php ├── smarty_internal_compile_block.php ├── smarty_internal_compile_break.php ├── smarty_internal_compile_call.php ├── smarty_internal_compile_capture.php ├── smarty_internal_compile_config_load.php ├── smarty_internal_compile_continue.php ├── smarty_internal_compile_debug.php ├── smarty_internal_compile_eval.php ├── smarty_internal_compile_extends.php ├── smarty_internal_compile_for.php ├── smarty_internal_compile_foreach.php ├── smarty_internal_compile_function.php ├── smarty_internal_compile_if.php ├── smarty_internal_compile_include.php ├── smarty_internal_compile_include_php.php ├── smarty_internal_compile_insert.php ├── smarty_internal_compile_ldelim.php ├── smarty_internal_compile_nocache.php ├── smarty_internal_compile_private_block_plugin.php ├── smarty_internal_compile_private_foreachsection.php ├── smarty_internal_compile_private_function_plugin.php ├── smarty_internal_compile_private_modifier.php ├── smarty_internal_compile_private_object_block_function.php ├── smarty_internal_compile_private_object_function.php ├── smarty_internal_compile_private_php.php ├── smarty_internal_compile_private_print_expression.php ├── smarty_internal_compile_private_registered_block.php ├── smarty_internal_compile_private_registered_function.php ├── smarty_internal_compile_private_special_variable.php ├── smarty_internal_compile_rdelim.php ├── smarty_internal_compile_section.php ├── smarty_internal_compile_setfilter.php ├── smarty_internal_compile_shared_inheritance.php ├── smarty_internal_compile_while.php ├── smarty_internal_compilebase.php ├── smarty_internal_config_file_compiler.php ├── smarty_internal_configfilelexer.php ├── smarty_internal_configfileparser.php ├── smarty_internal_data.php ├── smarty_internal_debug.php ├── smarty_internal_extension_clear.php ├── smarty_internal_extension_handler.php ├── smarty_internal_method_addautoloadfilters.php ├── smarty_internal_method_adddefaultmodifiers.php ├── smarty_internal_method_append.php ├── smarty_internal_method_appendbyref.php ├── smarty_internal_method_assignbyref.php ├── smarty_internal_method_assignglobal.php ├── smarty_internal_method_clearallassign.php ├── smarty_internal_method_clearallcache.php ├── smarty_internal_method_clearassign.php ├── smarty_internal_method_clearcache.php ├── smarty_internal_method_clearcompiledtemplate.php ├── smarty_internal_method_clearconfig.php ├── smarty_internal_method_compileallconfig.php ├── smarty_internal_method_compilealltemplates.php ├── smarty_internal_method_configload.php ├── smarty_internal_method_createdata.php ├── smarty_internal_method_getautoloadfilters.php ├── smarty_internal_method_getconfigvars.php ├── smarty_internal_method_getdebugtemplate.php ├── smarty_internal_method_getdefaultmodifiers.php ├── smarty_internal_method_getregisteredobject.php ├── smarty_internal_method_getstreamvariable.php ├── smarty_internal_method_gettags.php ├── smarty_internal_method_gettemplatevars.php ├── smarty_internal_method_loadfilter.php ├── smarty_internal_method_loadplugin.php ├── smarty_internal_method_mustcompile.php ├── smarty_internal_method_registercacheresource.php ├── smarty_internal_method_registerclass.php ├── smarty_internal_method_registerdefaultconfighandler.php ├── smarty_internal_method_registerdefaultpluginhandler.php ├── smarty_internal_method_registerdefaulttemplatehandler.php ├── smarty_internal_method_registerfilter.php ├── smarty_internal_method_registerobject.php ├── smarty_internal_method_registerplugin.php ├── smarty_internal_method_registerresource.php ├── smarty_internal_method_setautoloadfilters.php ├── smarty_internal_method_setdebugtemplate.php ├── smarty_internal_method_setdefaultmodifiers.php ├── smarty_internal_method_unloadfilter.php ├── smarty_internal_method_unregistercacheresource.php ├── smarty_internal_method_unregisterfilter.php ├── smarty_internal_method_unregisterobject.php ├── smarty_internal_method_unregisterplugin.php ├── smarty_internal_method_unregisterresource.php ├── smarty_internal_nocache_insert.php ├── smarty_internal_parsetree.php ├── smarty_internal_parsetree_code.php ├── smarty_internal_parsetree_dq.php ├── smarty_internal_parsetree_dqcontent.php ├── smarty_internal_parsetree_tag.php ├── smarty_internal_parsetree_template.php ├── smarty_internal_parsetree_text.php ├── smarty_internal_resource_eval.php ├── smarty_internal_resource_extends.php ├── smarty_internal_resource_file.php ├── smarty_internal_resource_php.php ├── smarty_internal_resource_registered.php ├── smarty_internal_resource_stream.php ├── smarty_internal_resource_string.php ├── smarty_internal_runtime_cachemodify.php ├── smarty_internal_runtime_codeframe.php ├── smarty_internal_runtime_filterhandler.php ├── smarty_internal_runtime_foreach.php ├── smarty_internal_runtime_getincludepath.php ├── smarty_internal_runtime_hhvm.php ├── smarty_internal_runtime_inheritance.php ├── smarty_internal_runtime_subtemplate.php ├── smarty_internal_runtime_tplfunc.php ├── smarty_internal_runtime_tplfunction.php ├── smarty_internal_runtime_updatecache.php ├── smarty_internal_runtime_updatescope.php ├── smarty_internal_runtime_validatecompiled.php ├── smarty_internal_runtime_var.php ├── smarty_internal_runtime_writefile.php ├── smarty_internal_smartytemplatecompiler.php ├── smarty_internal_template.php ├── smarty_internal_templatebase.php ├── smarty_internal_templatecompilerbase.php ├── smarty_internal_templatelexer.php ├── smarty_internal_templateparser.php ├── smarty_internal_testinstall.php ├── smarty_internal_undefined.php ├── smarty_resource.php ├── smarty_resource_custom.php ├── smarty_resource_recompiled.php ├── smarty_resource_uncompiled.php ├── smarty_security.php ├── smarty_template_cached.php ├── smarty_template_compiled.php ├── smarty_template_config.php ├── smarty_template_resource_base.php ├── smarty_template_source.php ├── smarty_undefined_variable.php ├── smarty_variable.php ├── smartycompilerexception.php └── smartyexception.php ├── templaces_c └── 59fc60b721b089160b69f92d5e6907f8c58a02e1_0.file.index.tpl.php └── templates └── home └── index.tpl /Classes/Database.php: -------------------------------------------------------------------------------- 1 | username = Config::get('mysql/username'); 25 | $this->password = Config::get('mysql/password'); 26 | $this->dsn = 'mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/database'); 27 | 28 | array ( \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION ); 29 | 30 | try{ 31 | $this->database = new \PDO($this->dsn, $this->username, $this->password); 32 | }catch( \PDOException $ex ) { 33 | $this->errors = $ex; 34 | } 35 | } 36 | 37 | public static function connect(){ 38 | if(!isset(self::$dbInstance)) { 39 | self::$dbInstance = new self(); 40 | } 41 | 42 | return self::$dbInstance; 43 | } 44 | 45 | private function __clone() {} // prevent cloning 46 | 47 | private function __wakeup(){} // prevent unserialization 48 | } -------------------------------------------------------------------------------- /Config/Config.php: -------------------------------------------------------------------------------- 1 | setTemplateDir( $smarty_path . 'templates' ); 17 | $this->setCompileDir( $smarty_path . 'templaces_c' ); 18 | $this->setCacheDir( $smarty_path . 'cache' ); 19 | $this->setConfigDir( $smarty_path . 'config' ); 20 | } 21 | 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /Controllers/BaseController.php: -------------------------------------------------------------------------------- 1 | url = $url; 20 | $this->action = $action; 21 | $this->tpl = new SmartyTemplate; 22 | } 23 | 24 | function executeAction(){ 25 | if(!empty($this->action)) return $this->{$this->action}(); 26 | } 27 | 28 | function execView( $viewName ) { 29 | 30 | if( !$viewName ) { 31 | $class = explode( '\\', get_class( $this )); 32 | $class = end($class); 33 | } else { 34 | $class = $viewName; 35 | } 36 | $file = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'Views' . DIRECTORY_SEPARATOR . $class . '.tpl.php'; 37 | 38 | if( file_exists( $file )) { 39 | require_once( $file ); 40 | } 41 | return false; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /Controllers/Home.php: -------------------------------------------------------------------------------- 1 | getNames(); 18 | 19 | if($names) { 20 | $this->tpl->assign('names', $names); 21 | } 22 | 23 | $this->tpl->display('home/index.tpl' ); 24 | } 25 | } -------------------------------------------------------------------------------- /Loader.php: -------------------------------------------------------------------------------- 1 | url = $_GET; 20 | } 21 | 22 | if(isset($this->url['controller'])) { 23 | $this->controller = $this->namespace . $this->url['controller']; 24 | }else { 25 | $this->controller = $this->namespace . 'home'; 26 | } 27 | 28 | if(isset($this->url['action'])) { 29 | $this->action = $this->url['action']; 30 | }else { 31 | $this->action = 'index'; 32 | } 33 | } 34 | 35 | function createController() { 36 | if(class_exists($this->controller)) { 37 | $parent = class_parents($this->controller); 38 | if(in_array( $this->namespace . 'BaseController', $parent)) { 39 | if(method_exists($this->controller,$this->action)) { 40 | return new $this->controller( $this->url, $this->action ); 41 | } else { 42 | throw new \Exception ("Method {$this->action} does not exists."); 43 | } 44 | }else { 45 | throw new \Exception("BaseController of {$this->controller} not found."); 46 | } 47 | 48 | } else { 49 | throw new \Exception("Controller {$this->controller} not found."); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Models/BaseModel.php: -------------------------------------------------------------------------------- 1 | db = Database::connect()->database; 19 | } 20 | } -------------------------------------------------------------------------------- /Models/HomeModel.php: -------------------------------------------------------------------------------- 1 | db->prepare("SELECT * FROM TableName WHERE 1"); 16 | $dbh->execute(); 17 | if($dbh->rowCount()){ 18 | return $dbh->fetchAll(); 19 | } 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-Custom-MVC 2 | 3 | Custom MVC lightweight framework example which utilizes Smarty as the frontend templating engine 4 | 5 | 6 | Links to Step by Step / Tutorial explanation of MVC in PHP : 7 | 8 | 9 | MVC PHP Tutorial 1 - Custom Autoloading : 10 | 11 | https://www.youtube.com/watch?v=mqusAS3V2Tg 12 | 13 | 14 | MVC PHP Tutorial 2 - Routing, Controllers, Actions 15 | 16 | https://www.youtube.com/watch?v=vHAr0gCVy6s 17 | 18 | 19 | MVC PHP Tutorial 3 - Views (using Smarty) : 20 | 21 | https://www.youtube.com/watch?v=08YKy2XAJwA 22 | 23 | 24 | MVC PHP Tutorial 4 - Models, Configuration and DB : 25 | 26 | https://www.youtube.com/watch?v=wsSUoiQZuq8 27 | -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | array ( 13 | 'username' => 'youtube', 14 | 'password' => 'youtube', 15 | 'database' => 'youtube', 16 | 'host' => 'localhost' 17 | ) 18 | ); 19 | 20 | 21 | // Autoloading with Composer 22 | 23 | require_once('../vendor/autoload.php'); 24 | require_once('./Loader.php'); 25 | 26 | //Load Smarty 27 | require_once('./smarty/Smarty.class.php'); 28 | 29 | $expected_controllers = array ( 'index', 'home' ); 30 | $_GET['controller'] = 'home'; 31 | if(!empty($_GET)) { 32 | if(in_array($_GET['controller'], $expected_controllers )) { 33 | $controller = new Loader($_GET); 34 | $controller = $controller->createController(); 35 | $controller->executeAction(); 36 | } 37 | } -------------------------------------------------------------------------------- /smarty/plugins/block.textformat.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: textformat
13 | * Purpose: format text a certain way with preset styles 14 | * or custom wrap/indent settings
15 | * Params: 16 | *
 17 |  * - style         - string (email)
 18 |  * - indent        - integer (0)
 19 |  * - wrap          - integer (80)
 20 |  * - wrap_char     - string ("\n")
 21 |  * - indent_char   - string (" ")
 22 |  * - wrap_boundary - boolean (true)
 23 |  * 
24 | * 25 | * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} 26 | * (Smarty online manual) 27 | * 28 | * @param array $params parameters 29 | * @param string $content contents of the block 30 | * @param Smarty_Internal_Template $template template object 31 | * @param boolean &$repeat repeat flag 32 | * 33 | * @return string content re-formatted 34 | * @author Monte Ohrt 35 | */ 36 | function smarty_block_textformat($params, $content, $template, &$repeat) 37 | { 38 | if (is_null($content)) { 39 | return; 40 | } 41 | 42 | $style = null; 43 | $indent = 0; 44 | $indent_first = 0; 45 | $indent_char = ' '; 46 | $wrap = 80; 47 | $wrap_char = "\n"; 48 | $wrap_cut = false; 49 | $assign = null; 50 | 51 | foreach ($params as $_key => $_val) { 52 | switch ($_key) { 53 | case 'style': 54 | case 'indent_char': 55 | case 'wrap_char': 56 | case 'assign': 57 | $$_key = (string) $_val; 58 | break; 59 | 60 | case 'indent': 61 | case 'indent_first': 62 | case 'wrap': 63 | $$_key = (int) $_val; 64 | break; 65 | 66 | case 'wrap_cut': 67 | $$_key = (bool) $_val; 68 | break; 69 | 70 | default: 71 | trigger_error("textformat: unknown attribute '$_key'"); 72 | } 73 | } 74 | 75 | if ($style == 'email') { 76 | $wrap = 72; 77 | } 78 | // split into paragraphs 79 | $_paragraphs = preg_split('![\r\n]{2}!', $content); 80 | 81 | foreach ($_paragraphs as &$_paragraph) { 82 | if (!$_paragraph) { 83 | continue; 84 | } 85 | // convert mult. spaces & special chars to single space 86 | $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph); 87 | // indent first line 88 | if ($indent_first > 0) { 89 | $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; 90 | } 91 | // wordwrap sentences 92 | if (Smarty::$_MBSTRING) { 93 | require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); 94 | $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); 95 | } else { 96 | $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); 97 | } 98 | // indent lines 99 | if ($indent > 0) { 100 | $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph); 101 | } 102 | } 103 | $_output = implode($wrap_char . $wrap_char, $_paragraphs); 104 | 105 | if ($assign) { 106 | $template->assign($assign, $_output); 107 | } else { 108 | return $_output; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /smarty/plugins/function.counter.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: counter
13 | * Purpose: print out a counter value 14 | * 15 | * @author Monte Ohrt 16 | * @link http://www.smarty.net/manual/en/language.function.counter.php {counter} 17 | * (Smarty online manual) 18 | * 19 | * @param array $params parameters 20 | * @param Smarty_Internal_Template $template template object 21 | * 22 | * @return string|null 23 | */ 24 | function smarty_function_counter($params, $template) 25 | { 26 | static $counters = array(); 27 | 28 | $name = (isset($params['name'])) ? $params['name'] : 'default'; 29 | if (!isset($counters[$name])) { 30 | $counters[$name] = array( 31 | 'start' => 1, 32 | 'skip' => 1, 33 | 'direction' => 'up', 34 | 'count' => 1 35 | ); 36 | } 37 | $counter =& $counters[$name]; 38 | 39 | if (isset($params['start'])) { 40 | $counter['start'] = $counter['count'] = (int) $params['start']; 41 | } 42 | 43 | if (!empty($params['assign'])) { 44 | $counter['assign'] = $params['assign']; 45 | } 46 | 47 | if (isset($counter['assign'])) { 48 | $template->assign($counter['assign'], $counter['count']); 49 | } 50 | 51 | if (isset($params['print'])) { 52 | $print = (bool) $params['print']; 53 | } else { 54 | $print = empty($counter['assign']); 55 | } 56 | 57 | if ($print) { 58 | $retval = $counter['count']; 59 | } else { 60 | $retval = null; 61 | } 62 | 63 | if (isset($params['skip'])) { 64 | $counter['skip'] = $params['skip']; 65 | } 66 | 67 | if (isset($params['direction'])) { 68 | $counter['direction'] = $params['direction']; 69 | } 70 | 71 | if ($counter['direction'] == "down") { 72 | $counter['count'] -= $counter['skip']; 73 | } else { 74 | $counter['count'] += $counter['skip']; 75 | } 76 | 77 | return $retval; 78 | } 79 | -------------------------------------------------------------------------------- /smarty/plugins/function.cycle.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: cycle
13 | * Date: May 3, 2002
14 | * Purpose: cycle through given values
15 | * Params: 16 | *
 17 |  * - name      - name of cycle (optional)
 18 |  * - values    - comma separated list of values to cycle, or an array of values to cycle
 19 |  *               (this can be left out for subsequent calls)
 20 |  * - reset     - boolean - resets given var to true
 21 |  * - print     - boolean - print var or not. default is true
 22 |  * - advance   - boolean - whether or not to advance the cycle
 23 |  * - delimiter - the value delimiter, default is ","
 24 |  * - assign    - boolean, assigns to template var instead of printed.
 25 |  * 
26 | * Examples:
27 | *
 28 |  * {cycle values="#eeeeee,#d0d0d0d"}
 29 |  * {cycle name=row values="one,two,three" reset=true}
 30 |  * {cycle name=row}
 31 |  * 
32 | * 33 | * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} 34 | * (Smarty online manual) 35 | * @author Monte Ohrt 36 | * @author credit to Mark Priatel 37 | * @author credit to Gerard 38 | * @author credit to Jason Sweat 39 | * @version 1.3 40 | * 41 | * @param array $params parameters 42 | * @param Smarty_Internal_Template $template template object 43 | * 44 | * @return string|null 45 | */ 46 | 47 | function smarty_function_cycle($params, $template) 48 | { 49 | static $cycle_vars; 50 | 51 | $name = (empty($params['name'])) ? 'default' : $params['name']; 52 | $print = (isset($params['print'])) ? (bool) $params['print'] : true; 53 | $advance = (isset($params['advance'])) ? (bool) $params['advance'] : true; 54 | $reset = (isset($params['reset'])) ? (bool) $params['reset'] : false; 55 | 56 | if (!isset($params['values'])) { 57 | if (!isset($cycle_vars[$name]['values'])) { 58 | trigger_error("cycle: missing 'values' parameter"); 59 | 60 | return; 61 | } 62 | } else { 63 | if (isset($cycle_vars[$name]['values']) 64 | && $cycle_vars[$name]['values'] != $params['values'] 65 | ) { 66 | $cycle_vars[$name]['index'] = 0; 67 | } 68 | $cycle_vars[$name]['values'] = $params['values']; 69 | } 70 | 71 | if (isset($params['delimiter'])) { 72 | $cycle_vars[$name]['delimiter'] = $params['delimiter']; 73 | } elseif (!isset($cycle_vars[$name]['delimiter'])) { 74 | $cycle_vars[$name]['delimiter'] = ','; 75 | } 76 | 77 | if (is_array($cycle_vars[$name]['values'])) { 78 | $cycle_array = $cycle_vars[$name]['values']; 79 | } else { 80 | $cycle_array = explode($cycle_vars[$name]['delimiter'], $cycle_vars[$name]['values']); 81 | } 82 | 83 | if (!isset($cycle_vars[$name]['index']) || $reset) { 84 | $cycle_vars[$name]['index'] = 0; 85 | } 86 | 87 | if (isset($params['assign'])) { 88 | $print = false; 89 | $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); 90 | } 91 | 92 | if ($print) { 93 | $retval = $cycle_array[$cycle_vars[$name]['index']]; 94 | } else { 95 | $retval = null; 96 | } 97 | 98 | if ($advance) { 99 | if ($cycle_vars[$name]['index'] >= count($cycle_array) - 1) { 100 | $cycle_vars[$name]['index'] = 0; 101 | } else { 102 | $cycle_vars[$name]['index'] ++; 103 | } 104 | } 105 | 106 | return $retval; 107 | } 108 | -------------------------------------------------------------------------------- /smarty/plugins/function.math.php: -------------------------------------------------------------------------------- 1 | 13 | * Name: math
14 | * Purpose: handle math computations in template 15 | * 16 | * @link http://www.smarty.net/manual/en/language.function.math.php {math} 17 | * (Smarty online manual) 18 | * @author Monte Ohrt 19 | * 20 | * @param array $params parameters 21 | * @param Smarty_Internal_Template $template template object 22 | * 23 | * @return string|null 24 | */ 25 | function smarty_function_math($params, $template) 26 | { 27 | static $_allowed_funcs = array( 28 | 'int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, 29 | 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 30 | 'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true 31 | ); 32 | // be sure equation parameter is present 33 | if (empty($params['equation'])) { 34 | trigger_error("math: missing equation parameter", E_USER_WARNING); 35 | 36 | return; 37 | } 38 | 39 | $equation = $params['equation']; 40 | 41 | // make sure parenthesis are balanced 42 | if (substr_count($equation, "(") != substr_count($equation, ")")) { 43 | trigger_error("math: unbalanced parenthesis", E_USER_WARNING); 44 | 45 | return; 46 | } 47 | 48 | // match all vars in equation, make sure all are passed 49 | preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match); 50 | 51 | foreach ($match[1] as $curr_var) { 52 | if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) { 53 | trigger_error("math: function call $curr_var not allowed", E_USER_WARNING); 54 | 55 | return; 56 | } 57 | } 58 | 59 | foreach ($params as $key => $val) { 60 | if ($key != "equation" && $key != "format" && $key != "assign") { 61 | // make sure value is not empty 62 | if (strlen($val) == 0) { 63 | trigger_error("math: parameter $key is empty", E_USER_WARNING); 64 | 65 | return; 66 | } 67 | if (!is_numeric($val)) { 68 | trigger_error("math: parameter $key: is not numeric", E_USER_WARNING); 69 | 70 | return; 71 | } 72 | $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); 73 | } 74 | } 75 | $smarty_math_result = null; 76 | eval("\$smarty_math_result = " . $equation . ";"); 77 | 78 | if (empty($params['format'])) { 79 | if (empty($params['assign'])) { 80 | return $smarty_math_result; 81 | } else { 82 | $template->assign($params['assign'], $smarty_math_result); 83 | } 84 | } else { 85 | if (empty($params['assign'])) { 86 | printf($params['format'], $smarty_math_result); 87 | } else { 88 | $template->assign($params['assign'], sprintf($params['format'], $smarty_math_result)); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /smarty/plugins/modifier.capitalize.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: capitalize
13 | * Purpose: capitalize words in the string 14 | * {@internal {$string|capitalize:true:true} is the fastest option for MBString enabled systems }} 15 | * 16 | * @param string $string string to capitalize 17 | * @param boolean $uc_digits also capitalize "x123" to "X123" 18 | * @param boolean $lc_rest capitalize first letters, lowercase all following letters "aAa" to "Aaa" 19 | * 20 | * @return string capitalized string 21 | * @author Monte Ohrt 22 | * @author Rodney Rehm 23 | */ 24 | function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = false) 25 | { 26 | if (Smarty::$_MBSTRING) { 27 | if ($lc_rest) { 28 | // uppercase (including hyphenated words) 29 | $upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET); 30 | } else { 31 | // uppercase word breaks 32 | $upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert_cb', $string); 33 | } 34 | // check uc_digits case 35 | if (!$uc_digits) { 36 | if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) { 37 | foreach ($matches[1] as $match) { 38 | $upper_string = substr_replace($upper_string, mb_strtolower($match[0], Smarty::$_CHARSET), $match[1], strlen($match[0])); 39 | } 40 | } 41 | } 42 | $upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb', $upper_string); 43 | return $upper_string; 44 | } 45 | 46 | // lowercase first 47 | if ($lc_rest) { 48 | $string = strtolower($string); 49 | } 50 | // uppercase (including hyphenated words) 51 | $upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb', $string); 52 | // check uc_digits case 53 | if (!$uc_digits) { 54 | if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) { 55 | foreach ($matches[1] as $match) { 56 | $upper_string = substr_replace($upper_string, strtolower($match[0]), $match[1], strlen($match[0])); 57 | } 58 | } 59 | } 60 | $upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb', $upper_string); 61 | return $upper_string; 62 | } 63 | 64 | /* 65 | * 66 | * Bug: create_function() use exhausts memory when used in long loops 67 | * Fix: use declared functions for callbacks instead of using create_function() 68 | * Note: This can be fixed using anonymous functions instead, but that requires PHP >= 5.3 69 | * 70 | * @author Kyle Renfrow 71 | */ 72 | function smarty_mod_cap_mbconvert_cb($matches) 73 | { 74 | return stripslashes($matches[1]) . mb_convert_case(stripslashes($matches[2]), MB_CASE_UPPER, Smarty::$_CHARSET); 75 | } 76 | 77 | function smarty_mod_cap_mbconvert2_cb($matches) 78 | { 79 | return stripslashes($matches[1]) . mb_convert_case(stripslashes($matches[3]), MB_CASE_UPPER, Smarty::$_CHARSET); 80 | } 81 | 82 | function smarty_mod_cap_ucfirst_cb($matches) 83 | { 84 | return stripslashes($matches[1]) . ucfirst(stripslashes($matches[2])); 85 | } 86 | 87 | function smarty_mod_cap_ucfirst2_cb($matches) 88 | { 89 | return stripslashes($matches[1]) . ucfirst(stripslashes($matches[3])); 90 | } 91 | -------------------------------------------------------------------------------- /smarty/plugins/modifier.date_format.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: date_format
13 | * Purpose: format datestamps via strftime
14 | * Input:
15 | * - string: input date string 16 | * - format: strftime format for output 17 | * - default_date: default date if $string is empty 18 | * 19 | * @link http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual) 20 | * @author Monte Ohrt 21 | * 22 | * @param string $string input date string 23 | * @param string $format strftime format for output 24 | * @param string $default_date default date if $string is empty 25 | * @param string $formatter either 'strftime' or 'auto' 26 | * 27 | * @return string |void 28 | * @uses smarty_make_timestamp() 29 | */ 30 | function smarty_modifier_date_format($string, $format = null, $default_date = '', $formatter = 'auto') 31 | { 32 | if ($format === null) { 33 | $format = Smarty::$_DATE_FORMAT; 34 | } 35 | /** 36 | * require_once the {@link shared.make_timestamp.php} plugin 37 | */ 38 | require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); 39 | if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') { 40 | $timestamp = smarty_make_timestamp($string); 41 | } elseif ($default_date != '') { 42 | $timestamp = smarty_make_timestamp($default_date); 43 | } else { 44 | return; 45 | } 46 | if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) { 47 | if (DS == '\\') { 48 | $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); 49 | $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); 50 | if (strpos($format, '%e') !== false) { 51 | $_win_from[] = '%e'; 52 | $_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); 53 | } 54 | if (strpos($format, '%l') !== false) { 55 | $_win_from[] = '%l'; 56 | $_win_to[] = sprintf('%\' 2d', date('h', $timestamp)); 57 | } 58 | $format = str_replace($_win_from, $_win_to, $format); 59 | } 60 | 61 | return strftime($format, $timestamp); 62 | } else { 63 | return date($format, $timestamp); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /smarty/plugins/modifier.regex_replace.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: regex_replace
13 | * Purpose: regular expression search/replace 14 | * 15 | * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php 16 | * regex_replace (Smarty online manual) 17 | * @author Monte Ohrt 18 | * 19 | * @param string $string input string 20 | * @param string|array $search regular expression(s) to search for 21 | * @param string|array $replace string(s) that should be replaced 22 | * @param int $limit the maximum number of replacements 23 | * 24 | * @return string 25 | */ 26 | function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1) 27 | { 28 | if (is_array($search)) { 29 | foreach ($search as $idx => $s) { 30 | $search[$idx] = _smarty_regex_replace_check($s); 31 | } 32 | } else { 33 | $search = _smarty_regex_replace_check($search); 34 | } 35 | 36 | return preg_replace($search, $replace, $string, $limit); 37 | } 38 | 39 | /** 40 | * @param string $search string(s) that should be replaced 41 | * 42 | * @return string 43 | * @ignore 44 | */ 45 | function _smarty_regex_replace_check($search) 46 | { 47 | // null-byte injection detection 48 | // anything behind the first null-byte is ignored 49 | if (($pos = strpos($search, "\0")) !== false) { 50 | $search = substr($search, 0, $pos); 51 | } 52 | // remove eval-modifier from $search 53 | if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { 54 | $search = substr($search, 0, - strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]); 55 | } 56 | 57 | return $search; 58 | } 59 | -------------------------------------------------------------------------------- /smarty/plugins/modifier.replace.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: replace
13 | * Purpose: simple search/replace 14 | * 15 | * @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual) 16 | * @author Monte Ohrt 17 | * @author Uwe Tews 18 | * 19 | * @param string $string input string 20 | * @param string $search text to search for 21 | * @param string $replace replacement text 22 | * 23 | * @return string 24 | */ 25 | function smarty_modifier_replace($string, $search, $replace) 26 | { 27 | if (Smarty::$_MBSTRING) { 28 | require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); 29 | 30 | return smarty_mb_str_replace($search, $replace, $string); 31 | } 32 | 33 | return str_replace($search, $replace, $string); 34 | } 35 | -------------------------------------------------------------------------------- /smarty/plugins/modifier.spacify.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: spacify
13 | * Purpose: add spaces between characters in a string 14 | * 15 | * @link http://smarty.php.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual) 16 | * @author Monte Ohrt 17 | * 18 | * @param string $string input string 19 | * @param string $spacify_char string to insert between characters. 20 | * 21 | * @return string 22 | */ 23 | function smarty_modifier_spacify($string, $spacify_char = ' ') 24 | { 25 | // well… what about charsets besides latin and UTF-8? 26 | return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, - 1, PREG_SPLIT_NO_EMPTY)); 27 | } 28 | -------------------------------------------------------------------------------- /smarty/plugins/modifier.truncate.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: truncate
13 | * Purpose: Truncate a string to a certain length if necessary, 14 | * optionally splitting in the middle of a word, and 15 | * appending the $etc string or inserting $etc into the middle. 16 | * 17 | * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) 18 | * @author Monte Ohrt 19 | * 20 | * @param string $string input string 21 | * @param integer $length length of truncated text 22 | * @param string $etc end string 23 | * @param boolean $break_words truncate at word boundary 24 | * @param boolean $middle truncate in the middle of text 25 | * 26 | * @return string truncated string 27 | */ 28 | function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) 29 | { 30 | if ($length == 0) { 31 | return ''; 32 | } 33 | 34 | if (Smarty::$_MBSTRING) { 35 | if (mb_strlen($string, Smarty::$_CHARSET) > $length) { 36 | $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); 37 | if (!$break_words && !$middle) { 38 | $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)); 39 | } 40 | if (!$middle) { 41 | return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; 42 | } 43 | 44 | return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET); 45 | } 46 | 47 | return $string; 48 | } 49 | 50 | // no MBString fallback 51 | if (isset($string[$length])) { 52 | $length -= min($length, strlen($etc)); 53 | if (!$break_words && !$middle) { 54 | $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); 55 | } 56 | if (!$middle) { 57 | return substr($string, 0, $length) . $etc; 58 | } 59 | 60 | return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2); 61 | } 62 | 63 | return $string; 64 | } 65 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.cat.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: cat
13 | * Date: Feb 24, 2003
14 | * Purpose: catenate a value to a variable
15 | * Input: string to catenate
16 | * Example: {$var|cat:"foo"} 17 | * 18 | * @link http://smarty.php.net/manual/en/language.modifier.cat.php cat 19 | * (Smarty online manual) 20 | * @author Uwe Tews 21 | * 22 | * @param array $params parameters 23 | * 24 | * @return string with compiled code 25 | */ 26 | function smarty_modifiercompiler_cat($params) 27 | { 28 | return '(' . implode(').(', $params) . ')'; 29 | } 30 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.count_characters.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: count_characteres
13 | * Purpose: count the number of characters in a text 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * 20 | * @return string with compiled code 21 | */ 22 | function smarty_modifiercompiler_count_characters($params) 23 | { 24 | if (!isset($params[1]) || $params[1] != 'true') { 25 | return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[0] . ', $tmp)'; 26 | } 27 | if (Smarty::$_MBSTRING) { 28 | return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; 29 | } 30 | // no MBString fallback 31 | return 'strlen(' . $params[0] . ')'; 32 | } 33 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.count_paragraphs.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: count_paragraphs
13 | * Purpose: count the number of paragraphs in a text 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php 16 | * count_paragraphs (Smarty online manual) 17 | * @author Uwe Tews 18 | * 19 | * @param array $params parameters 20 | * 21 | * @return string with compiled code 22 | */ 23 | function smarty_modifiercompiler_count_paragraphs($params) 24 | { 25 | // count \r or \n characters 26 | return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)'; 27 | } 28 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.count_sentences.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: count_sentences 13 | * Purpose: count the number of sentences in a text 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php 16 | * count_sentences (Smarty online manual) 17 | * @author Uwe Tews 18 | * 19 | * @param array $params parameters 20 | * 21 | * @return string with compiled code 22 | */ 23 | function smarty_modifiercompiler_count_sentences($params) 24 | { 25 | // find periods, question marks, exclamation marks with a word before but not after. 26 | return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[0] . ', $tmp)'; 27 | } 28 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.count_words.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: count_words
13 | * Purpose: count the number of words in a text 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * 20 | * @return string with compiled code 21 | */ 22 | function smarty_modifiercompiler_count_words($params) 23 | { 24 | if (Smarty::$_MBSTRING) { 25 | // return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; 26 | // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592 27 | return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; 28 | } 29 | // no MBString fallback 30 | return 'str_word_count(' . $params[0] . ')'; 31 | } 32 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.default.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: default
13 | * Purpose: designate default value for empty variables 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * 20 | * @return string with compiled code 21 | */ 22 | function smarty_modifiercompiler_default($params) 23 | { 24 | $output = $params[0]; 25 | if (!isset($params[1])) { 26 | $params[1] = "''"; 27 | } 28 | 29 | array_shift($params); 30 | foreach ($params as $param) { 31 | $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; 32 | } 33 | 34 | return $output; 35 | } 36 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.from_charset.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: from_charset
13 | * Purpose: convert character encoding from $charset to internal encoding 14 | * 15 | * @author Rodney Rehm 16 | * 17 | * @param array $params parameters 18 | * 19 | * @return string with compiled code 20 | */ 21 | function smarty_modifiercompiler_from_charset($params) 22 | { 23 | if (!Smarty::$_MBSTRING) { 24 | // FIXME: (rodneyrehm) shouldn't this throw an error? 25 | return $params[0]; 26 | } 27 | 28 | if (!isset($params[1])) { 29 | $params[1] = '"ISO-8859-1"'; 30 | } 31 | 32 | return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')'; 33 | } 34 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.indent.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: indent
13 | * Purpose: indent lines of text 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * 20 | * @return string with compiled code 21 | */ 22 | 23 | function smarty_modifiercompiler_indent($params) 24 | { 25 | if (!isset($params[1])) { 26 | $params[1] = 4; 27 | } 28 | if (!isset($params[2])) { 29 | $params[2] = "' '"; 30 | } 31 | 32 | return 'preg_replace(\'!^!m\',str_repeat(' . $params[2] . ',' . $params[1] . '),' . $params[0] . ')'; 33 | } 34 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.lower.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: lower
13 | * Purpose: convert string to lowercase 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual) 16 | * @author Monte Ohrt 17 | * @author Uwe Tews 18 | * 19 | * @param array $params parameters 20 | * 21 | * @return string with compiled code 22 | */ 23 | 24 | function smarty_modifiercompiler_lower($params) 25 | { 26 | if (Smarty::$_MBSTRING) { 27 | return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; 28 | } 29 | // no MBString fallback 30 | return 'strtolower(' . $params[0] . ')'; 31 | } 32 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.noprint.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: noprint
13 | * Purpose: return an empty string 14 | * 15 | * @author Uwe Tews 16 | * @return string with compiled code 17 | */ 18 | function smarty_modifiercompiler_noprint() 19 | { 20 | return "''"; 21 | } 22 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.string_format.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: string_format
13 | * Purpose: format strings via sprintf 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * 20 | * @return string with compiled code 21 | */ 22 | function smarty_modifiercompiler_string_format($params) 23 | { 24 | return 'sprintf(' . $params[1] . ',' . $params[0] . ')'; 25 | } 26 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.strip.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: strip
13 | * Purpose: Replace all repeated spaces, newlines, tabs 14 | * with a single space or supplied replacement string.
15 | * Example: {$var|strip} {$var|strip:" "}
16 | * Date: September 25th, 2002 17 | * 18 | * @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual) 19 | * @author Uwe Tews 20 | * 21 | * @param array $params parameters 22 | * 23 | * @return string with compiled code 24 | */ 25 | 26 | function smarty_modifiercompiler_strip($params) 27 | { 28 | if (!isset($params[1])) { 29 | $params[1] = "' '"; 30 | } 31 | 32 | return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; 33 | } 34 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.strip_tags.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: strip_tags
13 | * Purpose: strip html tags from text 14 | * 15 | * @link http://www.smarty.net/manual/en/language.modifier.strip.tags.php strip_tags (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * 20 | * @return string with compiled code 21 | */ 22 | function smarty_modifiercompiler_strip_tags($params) 23 | { 24 | if (!isset($params[1]) || $params[1] === true || trim($params[1], '"') == 'true') { 25 | return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})"; 26 | } else { 27 | return 'strip_tags(' . $params[0] . ')'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.to_charset.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: to_charset
13 | * Purpose: convert character encoding from internal encoding to $charset 14 | * 15 | * @author Rodney Rehm 16 | * 17 | * @param array $params parameters 18 | * 19 | * @return string with compiled code 20 | */ 21 | function smarty_modifiercompiler_to_charset($params) 22 | { 23 | if (!Smarty::$_MBSTRING) { 24 | // FIXME: (rodneyrehm) shouldn't this throw an error? 25 | return $params[0]; 26 | } 27 | 28 | if (!isset($params[1])) { 29 | $params[1] = '"ISO-8859-1"'; 30 | } 31 | 32 | return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; 33 | } 34 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.unescape.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: unescape
13 | * Purpose: unescape html entities 14 | * 15 | * @author Rodney Rehm 16 | * 17 | * @param array $params parameters 18 | * 19 | * @return string with compiled code 20 | */ 21 | function smarty_modifiercompiler_unescape($params) 22 | { 23 | if (!isset($params[1])) { 24 | $params[1] = 'html'; 25 | } 26 | if (!isset($params[2])) { 27 | $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\''; 28 | } else { 29 | $params[2] = "'" . $params[2] . "'"; 30 | } 31 | 32 | switch (trim($params[1], '"\'')) { 33 | case 'entity': 34 | case 'htmlall': 35 | if (Smarty::$_MBSTRING) { 36 | return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')'; 37 | } 38 | 39 | return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')'; 40 | 41 | case 'html': 42 | return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)'; 43 | 44 | case 'url': 45 | return 'rawurldecode(' . $params[0] . ')'; 46 | 47 | default: 48 | return $params[0]; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.upper.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: lower
13 | * Purpose: convert string to uppercase 14 | * 15 | * @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * 20 | * @return string with compiled code 21 | */ 22 | function smarty_modifiercompiler_upper($params) 23 | { 24 | if (Smarty::$_MBSTRING) { 25 | return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; 26 | } 27 | // no MBString fallback 28 | return 'strtoupper(' . $params[0] . ')'; 29 | } 30 | -------------------------------------------------------------------------------- /smarty/plugins/modifiercompiler.wordwrap.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: wordwrap
13 | * Purpose: wrap a string of text at a given length 14 | * 15 | * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual) 16 | * @author Uwe Tews 17 | * 18 | * @param array $params parameters 19 | * @param $compiler 20 | * 21 | * @return string with compiled code 22 | */ 23 | function smarty_modifiercompiler_wordwrap($params, $compiler) 24 | { 25 | if (!isset($params[1])) { 26 | $params[1] = 80; 27 | } 28 | if (!isset($params[2])) { 29 | $params[2] = '"\n"'; 30 | } 31 | if (!isset($params[3])) { 32 | $params[3] = 'false'; 33 | } 34 | $function = 'wordwrap'; 35 | if (Smarty::$_MBSTRING) { 36 | if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { 37 | $compiler->parent_compiler->template->compiled->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'; 38 | $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; 39 | } else { 40 | $compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'; 41 | $compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; 42 | } 43 | $function = 'smarty_mb_wordwrap'; 44 | } 45 | 46 | return $function . '(' . $params[0] . ',' . $params[1] . ',' . $params[2] . ',' . $params[3] . ')'; 47 | } 48 | -------------------------------------------------------------------------------- /smarty/plugins/shared.escape_special_chars.php: -------------------------------------------------------------------------------- 1 | =')) { 10 | /** 11 | * escape_special_chars common function 12 | * Function: smarty_function_escape_special_chars
13 | * Purpose: used by other smarty functions to escape 14 | * special chars except for already escaped ones 15 | * 16 | * @author Monte Ohrt 17 | * 18 | * @param string $string text that should by escaped 19 | * 20 | * @return string 21 | */ 22 | function smarty_function_escape_special_chars($string) 23 | { 24 | if (!is_array($string)) { 25 | $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false); 26 | } 27 | 28 | return $string; 29 | } 30 | } else { 31 | /** 32 | * escape_special_chars common function 33 | * Function: smarty_function_escape_special_chars
34 | * Purpose: used by other smarty functions to escape 35 | * special chars except for already escaped ones 36 | * 37 | * @author Monte Ohrt 38 | * 39 | * @param string $string text that should by escaped 40 | * 41 | * @return string 42 | */ 43 | function smarty_function_escape_special_chars($string) 44 | { 45 | if (!is_array($string)) { 46 | $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); 47 | $string = htmlspecialchars($string); 48 | $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); 49 | } 50 | 51 | return $string; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /smarty/plugins/shared.literal_compiler_param.php: -------------------------------------------------------------------------------- 1 | 11 | * Purpose: used by other smarty functions to make a timestamp from a string. 12 | * 13 | * @author Monte Ohrt 14 | * 15 | * @param DateTime|int|string $string date object, timestamp or string that can be converted using strtotime() 16 | * 17 | * @return int 18 | */ 19 | function smarty_make_timestamp($string) 20 | { 21 | if (empty($string)) { 22 | // use "now": 23 | return time(); 24 | } elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) { 25 | return (int) $string->format('U'); // PHP 5.2 BC 26 | } elseif (strlen($string) == 14 && ctype_digit($string)) { 27 | // it is mysql timestamp format of YYYYMMDDHHMMSS? 28 | return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), 29 | substr($string, 4, 2), substr($string, 6, 2), substr($string, 0, 4)); 30 | } elseif (is_numeric($string)) { 31 | // it is a numeric string, we handle it as timestamp 32 | return (int) $string; 33 | } else { 34 | // strtotime should handle it 35 | $time = strtotime($string); 36 | if ($time == - 1 || $time === false) { 37 | // strtotime() was not able to parse $string, use "now": 38 | return time(); 39 | } 40 | 41 | return $time; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /smarty/plugins/shared.mb_str_replace.php: -------------------------------------------------------------------------------- 1 | $width) { 37 | if ($cut) { 38 | $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); 39 | } 40 | } 41 | 42 | foreach ($_tokens as $token) { 43 | $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token); 44 | $token_length = mb_strlen($token, Smarty::$_CHARSET); 45 | $length += $token_length; 46 | 47 | if ($length > $width) { 48 | // remove space before inserted break 49 | if ($_previous) { 50 | $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET); 51 | } 52 | 53 | if (!$_space) { 54 | // add the break before the token 55 | if (!empty($t)) { 56 | $t .= $break; 57 | } 58 | $length = $token_length; 59 | } 60 | } elseif ($token == "\n") { 61 | // hard break must reset counters 62 | $_previous = 0; 63 | $length = 0; 64 | } 65 | $_previous = $_space; 66 | // add the token 67 | $t .= $token; 68 | } 69 | } 70 | 71 | return $t; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /smarty/plugins/variablefilter.htmlspecialchars.php: -------------------------------------------------------------------------------- 1 | dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); 55 | $this->smarty = $smarty; 56 | if (is_object($_parent)) { 57 | // when object set up back pointer 58 | $this->parent = $_parent; 59 | } elseif (is_array($_parent)) { 60 | // set up variable values 61 | foreach ($_parent as $_key => $_val) { 62 | $this->tpl_vars[$_key] = new Smarty_Variable($_val); 63 | } 64 | } elseif ($_parent != null) { 65 | throw new SmartyException("Wrong type for template variables"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_append.php: -------------------------------------------------------------------------------- 1 | required_attributes = array('var', 'value'); 32 | $this->shorttag_order = array('var', 'value'); 33 | $this->optional_attributes = array('scope', 'index'); 34 | // check and get attributes 35 | $_attr = $this->getAttributes($compiler, $args); 36 | // map to compile assign attributes 37 | if (isset($_attr['index'])) { 38 | $_params['smarty_internal_index'] = '[' . $_attr['index'] . ']'; 39 | unset($_attr['index']); 40 | } else { 41 | $_params['smarty_internal_index'] = '[]'; 42 | } 43 | $_new_attr = array(); 44 | foreach ($_attr as $key => $value) { 45 | $_new_attr[] = array($key => $value); 46 | } 47 | // call compile assign 48 | return parent::compile($_new_attr, $compiler, $_params); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_break.php: -------------------------------------------------------------------------------- 1 | true, 'foreach' => true, 'while' => true, 'section' => true); 48 | // check and get attributes 49 | $_attr = $this->getAttributes($compiler, $args); 50 | 51 | if ($_attr['nocache'] === true) { 52 | $compiler->trigger_template_error('nocache option not allowed', null, true); 53 | } 54 | 55 | if (isset($_attr['levels'])) { 56 | if (!is_numeric($_attr['levels'])) { 57 | $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); 58 | } 59 | $_levels = $_attr['levels']; 60 | } else { 61 | $_levels = 1; 62 | } 63 | $level_count = $_levels; 64 | $stack_count = count($compiler->_tag_stack) - 1; 65 | while ($level_count > 0 && $stack_count >= 0) { 66 | if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { 67 | $level_count --; 68 | } 69 | $stack_count --; 70 | } 71 | if ($level_count != 0) { 72 | $compiler->trigger_template_error("cannot break {$_levels} level(s)", null, true); 73 | } 74 | 75 | return ""; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_call.php: -------------------------------------------------------------------------------- 1 | getAttributes($compiler, $args); 55 | // save possible attributes 56 | if (isset($_attr['assign'])) { 57 | // output will be stored in a smarty variable instead of being displayed 58 | $_assign = $_attr['assign']; 59 | } 60 | //$_name = trim($_attr['name'], "'\""); 61 | $_name = $_attr['name']; 62 | unset($_attr['name'], $_attr['assign'], $_attr['nocache']); 63 | // set flag (compiled code of {function} must be included in cache file 64 | if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) { 65 | $_nocache = 'true'; 66 | } else { 67 | $_nocache = 'false'; 68 | } 69 | $_paramsArray = array(); 70 | foreach ($_attr as $_key => $_value) { 71 | if (is_int($_key)) { 72 | $_paramsArray[] = "$_key=>$_value"; 73 | } else { 74 | $_paramsArray[] = "'$_key'=>$_value"; 75 | } 76 | } 77 | $_params = 'array(' . implode(",", $_paramsArray) . ')'; 78 | //$compiler->suppressNocacheProcessing = true; 79 | // was there an assign attribute 80 | if (isset($_assign)) { 81 | $_output = 82 | "smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; 83 | } else { 84 | $_output = 85 | "smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n"; 86 | } 87 | return $_output; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_continue.php: -------------------------------------------------------------------------------- 1 | true, 'foreach' => true, 'while' => true, 'section' => true); 48 | // check and get attributes 49 | $_attr = $this->getAttributes($compiler, $args); 50 | 51 | if ($_attr['nocache'] === true) { 52 | $compiler->trigger_template_error('nocache option not allowed', null, true); 53 | } 54 | 55 | if (isset($_attr['levels'])) { 56 | if (!is_numeric($_attr['levels'])) { 57 | $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); 58 | } 59 | $_levels = $_attr['levels']; 60 | } else { 61 | $_levels = 1; 62 | } 63 | $level_count = $_levels; 64 | $stack_count = count($compiler->_tag_stack) - 1; 65 | while ($level_count > 0 && $stack_count >= 0) { 66 | if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { 67 | $level_count --; 68 | } 69 | $stack_count --; 70 | } 71 | if ($level_count != 0) { 72 | $compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true); 73 | } 74 | 75 | return ""; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_debug.php: -------------------------------------------------------------------------------- 1 | getAttributes($compiler, $args); 32 | 33 | // compile always as nocache 34 | $compiler->tag_nocache = true; 35 | 36 | // display debug template 37 | $_output = "display_debug(\$_smarty_tpl);\n"; 38 | $_output .= "unset(\$_smarty_debug);\n?>"; 39 | return $_output; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_eval.php: -------------------------------------------------------------------------------- 1 | required_attributes = array('var'); 52 | $this->optional_attributes = array('assign'); 53 | // check and get attributes 54 | $_attr = $this->getAttributes($compiler, $args); 55 | if (isset($_attr['assign'])) { 56 | // output will be stored in a smarty variable instead of being displayed 57 | $_assign = $_attr['assign']; 58 | } 59 | 60 | // create template object 61 | $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr['var'] . ", \$_smarty_tpl->smarty, \$_smarty_tpl);"; 62 | //was there an assign attribute? 63 | if (isset($_assign)) { 64 | $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());"; 65 | } else { 66 | $_output .= "echo \$_template->fetch();"; 67 | } 68 | 69 | return ""; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_ldelim.php: -------------------------------------------------------------------------------- 1 | getAttributes($compiler, $args); 32 | if ($_attr['nocache'] === true) { 33 | $compiler->trigger_template_error('nocache option not allowed', null, true); 34 | } 35 | // this tag does not return compiled code 36 | $compiler->has_code = true; 37 | 38 | return $compiler->smarty->left_delimiter; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_nocache.php: -------------------------------------------------------------------------------- 1 | getAttributes($compiler, $args); 38 | $this->openTag($compiler, 'nocache', array($compiler->nocache)); 39 | // enter nocache mode 40 | $compiler->nocache = true; 41 | // this tag does not return compiled code 42 | $compiler->has_code = false; 43 | 44 | return true; 45 | } 46 | } 47 | 48 | /** 49 | * Smarty Internal Plugin Compile Nocacheclose Class 50 | * 51 | * @package Smarty 52 | * @subpackage Compiler 53 | */ 54 | class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase 55 | { 56 | /** 57 | * Compiles code for the {/nocache} tag 58 | * This tag does not generate compiled output. It only sets a compiler flag. 59 | * 60 | * @param array $args array with attributes from parser 61 | * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object 62 | * 63 | * @return bool 64 | */ 65 | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) 66 | { 67 | $_attr = $this->getAttributes($compiler, $args); 68 | // leave nocache mode 69 | list($compiler->nocache) = $this->closeTag($compiler, array('nocache')); 70 | // this tag does not return compiled code 71 | $compiler->has_code = false; 72 | 73 | return true; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_private_function_plugin.php: -------------------------------------------------------------------------------- 1 | has_output = true; 50 | 51 | // check and get attributes 52 | $_attr = $this->getAttributes($compiler, $args); 53 | if ($_attr['nocache'] === true) { 54 | $compiler->tag_nocache = true; 55 | } 56 | unset($_attr['nocache']); 57 | // convert attributes into parameter array string 58 | $_paramsArray = array(); 59 | foreach ($_attr as $_key => $_value) { 60 | if (is_int($_key)) { 61 | $_paramsArray[] = "$_key=>$_value"; 62 | } else { 63 | $_paramsArray[] = "'$_key'=>$_value"; 64 | } 65 | } 66 | $_params = 'array(' . implode(",", $_paramsArray) . ')'; 67 | // compile code 68 | $output = "\n"; 69 | 70 | return $output; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_private_object_function.php: -------------------------------------------------------------------------------- 1 | getAttributes($compiler, $args); 42 | if ($_attr['nocache'] === true) { 43 | $compiler->tag_nocache = true; 44 | } 45 | unset($_attr['nocache']); 46 | $_assign = null; 47 | if (isset($_attr['assign'])) { 48 | $_assign = $_attr['assign']; 49 | unset($_attr['assign']); 50 | } 51 | // method or property ? 52 | if (method_exists($compiler->smarty->registered_objects[$tag][0], $method)) { 53 | // convert attributes into parameter array string 54 | if ($compiler->smarty->registered_objects[$tag][2]) { 55 | $_paramsArray = array(); 56 | foreach ($_attr as $_key => $_value) { 57 | if (is_int($_key)) { 58 | $_paramsArray[] = "$_key=>$_value"; 59 | } else { 60 | $_paramsArray[] = "'$_key'=>$_value"; 61 | } 62 | } 63 | $_params = 'array(' . implode(",", $_paramsArray) . ')'; 64 | $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)"; 65 | } else { 66 | $_params = implode(",", $_attr); 67 | $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})"; 68 | } 69 | } else { 70 | // object property 71 | $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}"; 72 | } 73 | 74 | if (empty($_assign)) { 75 | // This tag does create output 76 | $compiler->has_output = true; 77 | $output = "\n"; 78 | } else { 79 | $output = "assign({$_assign},{$return});?>\n"; 80 | } 81 | 82 | return $output; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_private_registered_function.php: -------------------------------------------------------------------------------- 1 | has_output = true; 41 | // check and get attributes 42 | $_attr = $this->getAttributes($compiler, $args); 43 | if ($_attr['nocache']) { 44 | $compiler->tag_nocache = true; 45 | } 46 | unset($_attr['nocache']); 47 | if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) { 48 | $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag]; 49 | } else { 50 | $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag]; 51 | } 52 | // not cachable? 53 | $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1]; 54 | // convert attributes into parameter array string 55 | $_paramsArray = array(); 56 | foreach ($_attr as $_key => $_value) { 57 | if (is_int($_key)) { 58 | $_paramsArray[] = "$_key=>$_value"; 59 | } elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) { 60 | $_value = str_replace("'", "^#^", $_value); 61 | $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; 62 | } else { 63 | $_paramsArray[] = "'$_key'=>$_value"; 64 | } 65 | } 66 | $_params = 'array(' . implode(",", $_paramsArray) . ')'; 67 | $function = $tag_info[0]; 68 | // compile code 69 | if (!is_array($function)) { 70 | $output = "\n"; 71 | } elseif (is_object($function[0])) { 72 | $output = "smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n"; 73 | } else { 74 | $output = "\n"; 75 | } 76 | 77 | return $output; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_rdelim.php: -------------------------------------------------------------------------------- 1 | getAttributes($compiler, $args); 31 | if ($_attr['nocache'] === true) { 32 | $compiler->trigger_template_error('nocache option not allowed', null, true); 33 | } 34 | // this tag does not return compiled code 35 | $compiler->has_code = true; 36 | 37 | return $compiler->smarty->right_delimiter; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_setfilter.php: -------------------------------------------------------------------------------- 1 | variable_filter_stack[] = $compiler->variable_filters; 31 | $compiler->variable_filters = $parameter['modifier_list']; 32 | // this tag does not return compiled code 33 | $compiler->has_code = false; 34 | 35 | return true; 36 | } 37 | } 38 | 39 | /** 40 | * Smarty Internal Plugin Compile Setfilterclose Class 41 | * 42 | * @package Smarty 43 | * @subpackage Compiler 44 | */ 45 | class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase 46 | { 47 | /** 48 | * Compiles code for the {/setfilter} tag 49 | * This tag does not generate compiled output. It resets variable filter. 50 | * 51 | * @param array $args array with attributes from parser 52 | * @param object $compiler compiler object 53 | * 54 | * @return string compiled code 55 | */ 56 | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) 57 | { 58 | $_attr = $this->getAttributes($compiler, $args); 59 | // reset variable filter to previous state 60 | if (count($compiler->variable_filter_stack)) { 61 | $compiler->variable_filters = array_pop($compiler->variable_filter_stack); 62 | } else { 63 | $compiler->variable_filters = array(); 64 | } 65 | // this tag does not return compiled code 66 | $compiler->has_code = false; 67 | 68 | return true; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_compile_shared_inheritance.php: -------------------------------------------------------------------------------- 1 | _cache['inheritanceInit'])) { 28 | $compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'), 29 | array($initChildSequence), 'inheritanceInit', $initChildSequence); 30 | 31 | $compiler->_cache['inheritanceInit'] = true; 32 | } 33 | } 34 | 35 | /** 36 | * Compile inheritance initialization code as prefix 37 | * 38 | * @param \Smarty_Internal_TemplateCompilerBase $compiler 39 | * @param bool|false $initChildSequence if true force child template 40 | */ 41 | static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false) 42 | { 43 | $compiler->prefixCompiledCode .= "ext->_inheritance->init(\$_smarty_tpl, " . 44 | var_export($initChildSequence, true) . ");\n?>\n"; 45 | } 46 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_addautoloadfilters.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 32 | if ($type !== null) { 33 | $this->_checkFilterType($type); 34 | if (!empty($smarty->autoload_filters[$type])) { 35 | $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $filters); 36 | } else { 37 | $smarty->autoload_filters[$type] = (array) $filters; 38 | } 39 | } else { 40 | foreach ((array) $filters as $type => $value) { 41 | $this->_checkFilterType($type); 42 | if (!empty($smarty->autoload_filters[$type])) { 43 | $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $value); 44 | } else { 45 | $smarty->autoload_filters[$type] = (array) $value; 46 | } 47 | } 48 | } 49 | return $obj; 50 | } 51 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_adddefaultmodifiers.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | if (is_array($modifiers)) { 36 | $this->default_modifiers = array_merge($smarty->default_modifiers, $modifiers); 37 | } else { 38 | $smarty->default_modifiers[] = $modifiers; 39 | } 40 | return $obj; 41 | } 42 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_append.php: -------------------------------------------------------------------------------- 1 | $_val) { 41 | if ($_key != '') { 42 | $this->append($data, $_key, $_val, $merge, $nocache); 43 | } 44 | } 45 | } else { 46 | if ($tpl_var != '' && isset($value)) { 47 | if (!isset($data->tpl_vars[$tpl_var])) { 48 | $tpl_var_inst = $data->ext->getTemplateVars->_getVariable($data, $tpl_var, null, true, false); 49 | if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { 50 | $data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); 51 | } else { 52 | $data->tpl_vars[$tpl_var] = clone $tpl_var_inst; 53 | } 54 | } 55 | if (!(is_array($data->tpl_vars[$tpl_var]->value) || 56 | $data->tpl_vars[$tpl_var]->value instanceof ArrayAccess) 57 | ) { 58 | settype($data->tpl_vars[$tpl_var]->value, 'array'); 59 | } 60 | if ($merge && is_array($value)) { 61 | foreach ($value as $_mkey => $_mval) { 62 | $data->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; 63 | } 64 | } else { 65 | $data->tpl_vars[$tpl_var]->value[] = $value; 66 | } 67 | } 68 | if ($data->_objType == 2 && $data->scope) { 69 | $data->ext->_updateScope->updateScope($data, $tpl_var); 70 | } 71 | } 72 | return $data; 73 | } 74 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_appendbyref.php: -------------------------------------------------------------------------------- 1 | tpl_vars[$tpl_var])) { 32 | $data->tpl_vars[$tpl_var] = new Smarty_Variable(); 33 | } 34 | if (!is_array($data->tpl_vars[$tpl_var]->value)) { 35 | settype($data->tpl_vars[$tpl_var]->value, 'array'); 36 | } 37 | if ($merge && is_array($value)) { 38 | foreach ($value as $_key => $_val) { 39 | $data->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key]; 40 | } 41 | } else { 42 | $data->tpl_vars[$tpl_var]->value[] = &$value; 43 | } 44 | if ($data->_objType == 2 && $data->scope) { 45 | $data->ext->_updateScope->updateScope($data, $tpl_var); 46 | } 47 | } 48 | return $data; 49 | } 50 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_assignbyref.php: -------------------------------------------------------------------------------- 1 | tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); 29 | $data->tpl_vars[$tpl_var]->value = &$value; 30 | if ($data->_objType == 2 && $data->scope) { 31 | $data->ext->_updateScope->updateScope($data, $tpl_var); 32 | } 33 | } 34 | return $data; 35 | } 36 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_assignglobal.php: -------------------------------------------------------------------------------- 1 | _objType == 2) { 37 | $ptr->tpl_vars[$varName] = clone Smarty::$global_tpl_vars[$varName]; 38 | $ptr = $ptr->parent; 39 | } 40 | } 41 | return $data; 42 | } 43 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_clearallassign.php: -------------------------------------------------------------------------------- 1 | tpl_vars = array(); 34 | 35 | return $data; 36 | } 37 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_clearallcache.php: -------------------------------------------------------------------------------- 1 | caching_type != 'file') { 38 | $_cache_resource->invalidLoadedCache($smarty); 39 | } 40 | 41 | return $_cache_resource->clearAll($smarty, $exp_time); 42 | } 43 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_clearassign.php: -------------------------------------------------------------------------------- 1 | tpl_vars[$curr_var]); 37 | } 38 | } else { 39 | unset($data->tpl_vars[$tpl_var]); 40 | } 41 | 42 | return $data; 43 | } 44 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_clearcache.php: -------------------------------------------------------------------------------- 1 | caching_type != 'file' && !isset($template_name)) { 41 | $_cache_resource->invalidLoadedCache($smarty); 42 | } 43 | 44 | return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time); 45 | } 46 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_clearconfig.php: -------------------------------------------------------------------------------- 1 | config_vars[$name]); 36 | } else { 37 | $data->config_vars = array(); 38 | } 39 | return $data; 40 | } 41 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_compileallconfig.php: -------------------------------------------------------------------------------- 1 | compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors, true); 31 | } 32 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_createdata.php: -------------------------------------------------------------------------------- 1 | smarty) ? $this->smarty : $obj; 38 | $dataObj = new Smarty_Data($parent, $smarty, $name); 39 | if ($smarty->debugging) { 40 | Smarty_Internal_Debug::register_data($dataObj); 41 | } 42 | return $dataObj; 43 | } 44 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_getautoloadfilters.php: -------------------------------------------------------------------------------- 1 | array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type 26 | * was specified 27 | */ 28 | public function getAutoloadFilters(Smarty_Internal_TemplateBase $obj, $type = null) 29 | { 30 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; 31 | if ($type !== null) { 32 | $this->_checkFilterType($type); 33 | return isset($smarty->autoload_filters[$type]) ? $smarty->autoload_filters[$type] : array(); 34 | } 35 | return $smarty->autoload_filters; 36 | } 37 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_getconfigvars.php: -------------------------------------------------------------------------------- 1 | config_vars[$varname])) { 40 | return $_ptr->config_vars[$varname]; 41 | } 42 | } else { 43 | $var_array = array_merge($_ptr->config_vars, $var_array); 44 | } 45 | // not found, try at parent 46 | if ($search_parents) { 47 | $_ptr = $_ptr->parent; 48 | } else { 49 | $_ptr = null; 50 | } 51 | } 52 | if (isset($varname)) { 53 | return ''; 54 | } else { 55 | return $var_array; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_getdebugtemplate.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 33 | return $smarty->debug_tpl; 34 | } 35 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_getdefaultmodifiers.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 33 | return $smarty->default_modifiers; 34 | } 35 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_getregisteredobject.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 36 | if (!isset($smarty->registered_objects[$object_name])) { 37 | throw new SmartyException("'$object_name' is not a registered object"); 38 | } 39 | if (!is_object($smarty->registered_objects[$object_name][0])) { 40 | throw new SmartyException("registered '$object_name' is not an object"); 41 | } 42 | return $smarty->registered_objects[$object_name][0]; 43 | } 44 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_getstreamvariable.php: -------------------------------------------------------------------------------- 1 | smarty) ? $data->smarty : $data; 45 | if ($smarty->error_unassigned) { 46 | throw new SmartyException('Undefined stream variable "' . $variable . '"'); 47 | } else { 48 | return null; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_gettags.php: -------------------------------------------------------------------------------- 1 | smarty) ? $this->smarty : $obj; 37 | if ($obj->_objType == 2 && !isset($template)) { 38 | $tpl = clone $obj; 39 | } elseif (isset($template) && $template->_objType == 2) { 40 | $tpl = clone $template; 41 | } elseif (isset($template) && is_string($template)) { 42 | /* @var Smarty_Internal_Template $tpl */ 43 | $tpl = new $smarty->template_class($template, $smarty); 44 | // checks if template exists 45 | if (!$tpl->source->exists) { 46 | throw new SmartyException("Unable to load template {$tpl->source->type} '{$tpl->source->name}'"); 47 | } 48 | } 49 | if (isset($tpl)) { 50 | $tpl->smarty = clone $tpl->smarty; 51 | $tpl->smarty->_cache['get_used_tags'] = true; 52 | $tpl->_cache['used_tags'] = array(); 53 | $tpl->smarty->merge_compiled_includes = false; 54 | $tpl->smarty->disableSecurity(); 55 | $tpl->caching = false; 56 | $tpl->loadCompiler(); 57 | $tpl->compiler->compileTemplate($tpl); 58 | return $tpl->_cache['used_tags']; 59 | } 60 | throw new SmartyException("Missing template specification"); 61 | } 62 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_loadfilter.php: -------------------------------------------------------------------------------- 1 | true, 'post' => true, 'output' => true, 'variable' => true); 27 | 28 | /** 29 | * load a filter of specified type and name 30 | * 31 | * @api Smarty::loadFilter() 32 | * 33 | * @link http://www.smarty.net/docs/en/api.load.filter.tpl 34 | * 35 | * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj 36 | * @param string $type filter type 37 | * @param string $name filter name 38 | * 39 | * @return bool 40 | * @throws SmartyException if filter could not be loaded 41 | */ 42 | public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) 43 | { 44 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; 45 | $this->_checkFilterType($type); 46 | $_plugin = "smarty_{$type}filter_{$name}"; 47 | $_filter_name = $_plugin; 48 | if (is_callable($_plugin)) { 49 | $smarty->registered_filters[$type][$_filter_name] = $_plugin; 50 | return true; 51 | } 52 | if ($smarty->loadPlugin($_plugin)) { 53 | if (class_exists($_plugin, false)) { 54 | $_plugin = array($_plugin, 'execute'); 55 | } 56 | if (is_callable($_plugin)) { 57 | $smarty->registered_filters[$type][$_filter_name] = $_plugin; 58 | return true; 59 | } 60 | } 61 | throw new SmartyException("{$type}filter \"{$name}\" not found or callable"); 62 | } 63 | 64 | /** 65 | * Check if filter type is valid 66 | * 67 | * @param string $type 68 | * 69 | * @throws \SmartyException 70 | */ 71 | public function _checkFilterType($type) 72 | { 73 | if (!isset($this->filterTypes[$type])) { 74 | throw new SmartyException("Illegal filter type \"{$type}\""); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_mustcompile.php: -------------------------------------------------------------------------------- 1 | source->exists) { 34 | if (isset($_template->parent) && $_template->parent->_objType == 2) { 35 | $parent_resource = " in '$_template->parent->template_resource}'"; 36 | } else { 37 | $parent_resource = ''; 38 | } 39 | throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); 40 | } 41 | if ($_template->mustCompile === null) { 42 | $_template->mustCompile = (!$_template->source->handler->uncompiled && 43 | ($_template->smarty->force_compile || $_template->source->handler->recompiled || !$_template->compiled->exists || 44 | ($_template->smarty->compile_check && $_template->compiled->getTimeStamp() < $_template->source->getTimeStamp()))); 45 | } 46 | 47 | return $_template->mustCompile; 48 | } 49 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registercacheresource.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 36 | $smarty->registered_cache_resources[$name] = $resource_handler; 37 | return $obj; 38 | } 39 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registerclass.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 38 | // test if exists 39 | if (!class_exists($class_impl)) { 40 | throw new SmartyException("Undefined class '$class_impl' in register template class"); 41 | } 42 | // register the class 43 | $smarty->registered_classes[$class_name] = $class_impl; 44 | return $obj; 45 | } 46 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registerdefaultconfighandler.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | if (is_callable($callback)) { 36 | $smarty->default_config_handler_func = $callback; 37 | } else { 38 | throw new SmartyException("Default config handler not callable"); 39 | } 40 | return $obj; 41 | } 42 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 36 | if (is_callable($callback)) { 37 | $smarty->default_plugin_handler_func = $callback; 38 | } else { 39 | throw new SmartyException("Default plugin handler '$callback' not callable"); 40 | } 41 | return $obj; 42 | } 43 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | if (is_callable($callback)) { 36 | $smarty->default_template_handler_func = $callback; 37 | } else { 38 | throw new SmartyException("Default template handler not callable"); 39 | } 40 | return $obj; 41 | } 42 | 43 | /** 44 | * get default content from template or config resource handler 45 | * 46 | * @param Smarty_Template_Source $source 47 | */ 48 | public static function _getDefaultTemplate(Smarty_Template_Source $source) 49 | { 50 | if ($source->isConfig) { 51 | $default_handler = $source->smarty->default_config_handler_func; 52 | } else { 53 | $default_handler = $source->smarty->default_template_handler_func; 54 | } 55 | $_content = $_timestamp = null; 56 | $_return = call_user_func_array($default_handler, array($source->type, $source->name, &$_content, &$_timestamp, 57 | $source->smarty)); 58 | if (is_string($_return)) { 59 | $source->exists = is_file($_return); 60 | if ($source->exists) { 61 | $source->timestamp = filemtime($_return); 62 | } 63 | $source->filepath = $_return; 64 | } elseif ($_return === true) { 65 | $source->content = $_content; 66 | $source->timestamp = $_timestamp; 67 | $source->exists = true; 68 | $source->handler->recompiled = true; 69 | $source->filepath = false; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registerfilter.php: -------------------------------------------------------------------------------- 1 | true, 'post' => true, 'output' => true, 'variable' => true); 27 | 28 | /** 29 | * Registers a filter function 30 | * 31 | * @api Smarty::registerFilter() 32 | * 33 | * @link http://www.smarty.net/docs/en/api.register.filter.tpl 34 | * 35 | * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj 36 | * @param string $type filter type 37 | * @param callback $callback 38 | * @param string|null $name optional filter name 39 | * 40 | * @return \Smarty|\Smarty_Internal_Template 41 | * @throws \SmartyException 42 | */ 43 | public function registerFilter(Smarty_Internal_TemplateBase $obj, $type, $callback, $name = null) 44 | { 45 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; 46 | $this->_checkFilterType($type); 47 | $name = isset($name) ? $name : $this->_getFilterName($callback); 48 | if (!is_callable($callback)) { 49 | throw new SmartyException("{$type}filter \"{$name}\" not callable"); 50 | } 51 | $smarty->registered_filters[$type][$name] = $callback; 52 | return $obj; 53 | } 54 | 55 | /** 56 | * Return internal filter name 57 | * 58 | * @param callback $function_name 59 | * 60 | * @return string internal filter name 61 | */ 62 | public function _getFilterName($function_name) 63 | { 64 | if (is_array($function_name)) { 65 | $_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]); 66 | 67 | return $_class_name . '_' . $function_name[1]; 68 | } elseif (is_string($function_name)) { 69 | return $function_name; 70 | } else { 71 | return 'closure'; 72 | } 73 | } 74 | 75 | /** 76 | * Check if filter type is valid 77 | * 78 | * @param string $type 79 | * 80 | * @throws \SmartyException 81 | */ 82 | public function _checkFilterType($type) 83 | { 84 | if (!isset($this->filterTypes[$type])) { 85 | throw new SmartyException("Illegal filter type \"{$type}\""); 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registerplugin.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 41 | if (isset($smarty->registered_plugins[$type][$name])) { 42 | throw new SmartyException("Plugin tag \"{$name}\" already registered"); 43 | } elseif (!is_callable($callback)) { 44 | throw new SmartyException("Plugin \"{$name}\" not callable"); 45 | } else { 46 | $smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr); 47 | } 48 | return $obj; 49 | } 50 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_registerresource.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 40 | $smarty->registered_resources[$name] = $resource_handler instanceof 41 | Smarty_Resource ? $resource_handler : array($resource_handler, false); 42 | return $obj; 43 | } 44 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_setautoloadfilters.php: -------------------------------------------------------------------------------- 1 | true, 'post' => true, 'output' => true, 'variable' => true); 27 | 28 | /** 29 | * Set autoload filters 30 | * 31 | * @api Smarty::setAutoloadFilters() 32 | * 33 | * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj 34 | * @param array $filters filters to load automatically 35 | * @param string $type "pre", "output", … specify the 36 | * filter type to set. Defaults to 37 | * none treating $filters' keys as 38 | * the appropriate types 39 | * 40 | * @return \Smarty|\Smarty_Internal_Template 41 | */ 42 | public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) 43 | { 44 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; 45 | if ($type !== null) { 46 | $this->_checkFilterType($type); 47 | $smarty->autoload_filters[$type] = (array) $filters; 48 | } else { 49 | foreach ((array) $filters as $type => $value) { 50 | $this->_checkFilterType($type); 51 | } 52 | $smarty->autoload_filters = (array) $filters; 53 | } 54 | return $obj; 55 | } 56 | 57 | /** 58 | * Check if filter type is valid 59 | * 60 | * @param string $type 61 | * 62 | * @throws \SmartyException 63 | */ 64 | public function _checkFilterType($type) 65 | { 66 | if (!isset($this->filterTypes[$type])) { 67 | throw new SmartyException("Illegal filter type \"{$type}\""); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_setdebugtemplate.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | if (!is_readable($tpl_name)) { 36 | throw new SmartyException("Unknown file '{$tpl_name}'"); 37 | } 38 | $smarty->debug_tpl = $tpl_name; 39 | return $obj; 40 | } 41 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_setdefaultmodifiers.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | $smarty->default_modifiers = (array) $modifiers; 36 | return $obj; 37 | } 38 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_unloadfilter.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 30 | $this->_checkFilterType($type); 31 | if (isset($smarty->registered_filters[$type])) { 32 | $_filter_name = "smarty_{$type}filter_{$name}"; 33 | if (isset($smarty->registered_filters[$type][$_filter_name])) { 34 | unset ($smarty->registered_filters[$type][$_filter_name]); 35 | if (empty($smarty->registered_filters[$type])) { 36 | unset($smarty->registered_filters[$type]); 37 | } 38 | } 39 | } 40 | return $obj; 41 | } 42 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_unregistercacheresource.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | if (isset($smarty->registered_cache_resources[$name])) { 36 | unset($smarty->registered_cache_resources[$name]); 37 | } 38 | return $obj; 39 | } 40 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_unregisterfilter.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 30 | $this->_checkFilterType($type); 31 | if (isset($smarty->registered_filters[$type])) { 32 | $name = is_string($callback) ? $callback : $this->_getFilterName($callback); 33 | if (isset($smarty->registered_filters[$type][$name])) { 34 | unset($smarty->registered_filters[$type][$name]); 35 | if (empty($smarty->registered_filters[$type])) { 36 | unset($smarty->registered_filters[$type]); 37 | } 38 | } 39 | } 40 | return $obj; 41 | } 42 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_unregisterobject.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | if (isset($smarty->registered_objects[$object_name])) { 36 | unset($smarty->registered_objects[$object_name]); 37 | } 38 | return $obj; 39 | } 40 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_unregisterplugin.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 36 | if (isset($smarty->registered_plugins[$type][$name])) { 37 | unset($smarty->registered_plugins[$type][$name]); 38 | } 39 | return $obj; 40 | } 41 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_method_unregisterresource.php: -------------------------------------------------------------------------------- 1 | smarty) ? $obj->smarty : $obj; 35 | if (isset($smarty->registered_resources[$type])) { 36 | unset($smarty->registered_resources[$type]); 37 | } 38 | return $obj; 39 | } 40 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_nocache_insert.php: -------------------------------------------------------------------------------- 1 | assign('{$_assign}' , {$_function} (" . var_export($_attr, true) . ",\$_smarty_tpl), true);?>"; 41 | } else { 42 | $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>"; 43 | } 44 | $_tpl = $_template; 45 | while (isset($_tpl->parent) && $_tpl->parent->_objType == 2) { 46 | $_tpl = $_tpl->parent; 47 | } 48 | 49 | return "/*%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_parsetree.php: -------------------------------------------------------------------------------- 1 | data = null; 49 | $this->subtrees = null; 50 | } 51 | 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_parsetree_code.php: -------------------------------------------------------------------------------- 1 | data = $data; 29 | } 30 | 31 | /** 32 | * Return buffer content in parentheses 33 | * 34 | * @param \Smarty_Internal_Templateparser $parser 35 | * 36 | * @return string content 37 | */ 38 | public function to_smarty_php(Smarty_Internal_Templateparser $parser) 39 | { 40 | return sprintf("(%s)", $this->data); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_parsetree_dq.php: -------------------------------------------------------------------------------- 1 | subtrees[] = $subtree; 29 | if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { 30 | $parser->block_nesting_level = count($parser->compiler->_tag_stack); 31 | } 32 | } 33 | 34 | /** 35 | * Append buffer to subtree 36 | * 37 | * @param \Smarty_Internal_Templateparser $parser 38 | * @param Smarty_Internal_ParseTree $subtree parse tree buffer 39 | */ 40 | public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree) 41 | { 42 | $last_subtree = count($this->subtrees) - 1; 43 | if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $parser->block_nesting_level) { 44 | if ($subtree instanceof Smarty_Internal_ParseTree_Code) { 45 | $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, 'data . ';?>'); 46 | } elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) { 47 | $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, 'data . '";?>'); 48 | } else { 49 | $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data); 50 | } 51 | } else { 52 | $this->subtrees[] = $subtree; 53 | } 54 | if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { 55 | $parser->block_nesting_level = count($parser->compiler->_tag_stack); 56 | } 57 | } 58 | 59 | /** 60 | * Merge subtree buffer content together 61 | * 62 | * @param \Smarty_Internal_Templateparser $parser 63 | * 64 | * @return string compiled template code 65 | */ 66 | public function to_smarty_php(Smarty_Internal_Templateparser $parser) 67 | { 68 | $code = ''; 69 | foreach ($this->subtrees as $subtree) { 70 | if ($code !== "") { 71 | $code .= "."; 72 | } 73 | if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { 74 | $more_php = $subtree->assign_to_var($parser); 75 | } else { 76 | $more_php = $subtree->to_smarty_php($parser); 77 | } 78 | 79 | $code .= $more_php; 80 | 81 | if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) { 82 | $parser->compiler->has_variable_string = true; 83 | } 84 | } 85 | 86 | return $code; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_parsetree_dqcontent.php: -------------------------------------------------------------------------------- 1 | data = $data; 29 | } 30 | 31 | /** 32 | * Return content as double quoted string 33 | * 34 | * @param \Smarty_Internal_Templateparser $parser 35 | * 36 | * @return string doubled quoted string 37 | */ 38 | public function to_smarty_php(Smarty_Internal_Templateparser $parser) 39 | { 40 | return '"' . $this->data . '"'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_parsetree_tag.php: -------------------------------------------------------------------------------- 1 | data = $data; 38 | $this->saved_block_nesting = $parser->block_nesting_level; 39 | } 40 | 41 | /** 42 | * Return buffer content 43 | * 44 | * @param \Smarty_Internal_Templateparser $parser 45 | * 46 | * @return string content 47 | */ 48 | public function to_smarty_php(Smarty_Internal_Templateparser $parser) 49 | { 50 | return $this->data; 51 | } 52 | 53 | /** 54 | * Return complied code that loads the evaluated output of buffer content into a temporary variable 55 | * 56 | * @param \Smarty_Internal_Templateparser $parser 57 | * 58 | * @return string template code 59 | */ 60 | public function assign_to_var(Smarty_Internal_Templateparser $parser) 61 | { 62 | $var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number); 63 | $tmp = $parser->compiler->appendCode('', $this->data); 64 | $tmp = $parser->compiler->appendCode($tmp, ""); 65 | $parser->compiler->prefix_code[] = sprintf("%s", $tmp); 66 | 67 | return $var; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_parsetree_text.php: -------------------------------------------------------------------------------- 1 | data = $data; 27 | } 28 | 29 | /** 30 | * Return buffer content 31 | * 32 | * @param \Smarty_Internal_Templateparser $parser 33 | * 34 | * @return string text 35 | */ 36 | public function to_smarty_php(Smarty_Internal_Templateparser $parser) 37 | { 38 | return $this->data; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_resource_eval.php: -------------------------------------------------------------------------------- 1 | uid = $source->filepath = sha1($source->name); 32 | $source->timestamp = false; 33 | $source->exists = true; 34 | } 35 | 36 | /** 37 | * Load template's source from $resource_name into current template object 38 | * 39 | * @uses decode() to decode base64 and urlencoded template_resources 40 | * 41 | * @param Smarty_Template_Source $source source object 42 | * 43 | * @return string template source 44 | */ 45 | public function getContent(Smarty_Template_Source $source) 46 | { 47 | return $this->decode($source->name); 48 | } 49 | 50 | /** 51 | * decode base64 and urlencode 52 | * 53 | * @param string $string template_resource to decode 54 | * 55 | * @return string decoded template_resource 56 | */ 57 | protected function decode($string) 58 | { 59 | // decode if specified 60 | if (($pos = strpos($string, ':')) !== false) { 61 | if (!strncmp($string, 'base64', 6)) { 62 | return base64_decode(substr($string, 7)); 63 | } elseif (!strncmp($string, 'urlencode', 9)) { 64 | return urldecode(substr($string, 10)); 65 | } 66 | } 67 | 68 | return $string; 69 | } 70 | 71 | /** 72 | * modify resource_name according to resource handlers specifications 73 | * 74 | * @param Smarty $smarty Smarty instance 75 | * @param string $resource_name resource_name to make unique 76 | * @param boolean $isConfig flag for config resource 77 | * 78 | * @return string unique resource name 79 | */ 80 | public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) 81 | { 82 | return get_class($this) . '#' . $this->decode($resource_name); 83 | } 84 | 85 | /** 86 | * Determine basename for compiled filename 87 | * 88 | * @param Smarty_Template_Source $source source object 89 | * 90 | * @return string resource's basename 91 | */ 92 | public function getBasename(Smarty_Template_Source $source) 93 | { 94 | return ''; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_resource_registered.php: -------------------------------------------------------------------------------- 1 | filepath = $source->type . ':' . $source->name; 32 | $source->uid = sha1($source->filepath); 33 | if ($source->smarty->compile_check) { 34 | $source->timestamp = $this->getTemplateTimestamp($source); 35 | $source->exists = !!$source->timestamp; 36 | } 37 | } 38 | 39 | /** 40 | * populate Source Object with timestamp and exists from Resource 41 | * 42 | * @param Smarty_Template_Source $source source object 43 | * 44 | * @return void 45 | */ 46 | public function populateTimestamp(Smarty_Template_Source $source) 47 | { 48 | $source->timestamp = $this->getTemplateTimestamp($source); 49 | $source->exists = !!$source->timestamp; 50 | } 51 | 52 | /** 53 | * Get timestamp (epoch) the template source was modified 54 | * 55 | * @param Smarty_Template_Source $source source object 56 | * 57 | * @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp 58 | */ 59 | public function getTemplateTimestamp(Smarty_Template_Source $source) 60 | { 61 | // return timestamp 62 | $time_stamp = false; 63 | call_user_func_array($source->smarty->registered_resources[$source->type][0][1], array($source->name, &$time_stamp, $source->smarty)); 64 | 65 | return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp; 66 | } 67 | 68 | /** 69 | * Load template's source by invoking the registered callback into current template object 70 | * 71 | * @param Smarty_Template_Source $source source object 72 | * 73 | * @return string template source 74 | * @throws SmartyException if source cannot be loaded 75 | */ 76 | public function getContent(Smarty_Template_Source $source) 77 | { 78 | // return template string 79 | $content = null; 80 | $t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$content, $source->smarty)); 81 | if (is_bool($t) && !$t) { 82 | throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); 83 | } 84 | 85 | return $content; 86 | } 87 | 88 | /** 89 | * Determine basename for compiled filename 90 | * 91 | * @param Smarty_Template_Source $source source object 92 | * 93 | * @return string resource's basename 94 | */ 95 | public function getBasename(Smarty_Template_Source $source) 96 | { 97 | return basename($source->name); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_resource_stream.php: -------------------------------------------------------------------------------- 1 | resource, '://') !== false) { 33 | $source->filepath = $source->resource; 34 | } else { 35 | $source->filepath = str_replace(':', '://', $source->resource); 36 | } 37 | $source->uid = false; 38 | $source->content = $this->getContent($source); 39 | $source->timestamp = false; 40 | $source->exists = !!$source->content; 41 | } 42 | 43 | /** 44 | * Load template's source from stream into current template object 45 | * 46 | * @param Smarty_Template_Source $source source object 47 | * 48 | * @return string template source 49 | * @throws SmartyException if source cannot be loaded 50 | */ 51 | public function getContent(Smarty_Template_Source $source) 52 | { 53 | $t = ''; 54 | // the availability of the stream has already been checked in Smarty_Resource::fetch() 55 | $fp = fopen($source->filepath, 'r+'); 56 | if ($fp) { 57 | while (!feof($fp) && ($current_line = fgets($fp)) !== false) { 58 | $t .= $current_line; 59 | } 60 | fclose($fp); 61 | 62 | return $t; 63 | } else { 64 | return false; 65 | } 66 | } 67 | 68 | /** 69 | * modify resource_name according to resource handlers specifications 70 | * 71 | * @param Smarty $smarty Smarty instance 72 | * @param string $resource_name resource_name to make unique 73 | * @param boolean $isConfig flag for config resource 74 | * 75 | * @return string unique resource name 76 | */ 77 | public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) 78 | { 79 | return get_class($this) . '#' . $resource_name; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_resource_string.php: -------------------------------------------------------------------------------- 1 | uid = $source->filepath = sha1($source->name); 32 | $source->timestamp = 0; 33 | $source->exists = true; 34 | } 35 | 36 | /** 37 | * Load template's source from $resource_name into current template object 38 | * 39 | * @uses decode() to decode base64 and urlencoded template_resources 40 | * 41 | * @param Smarty_Template_Source $source source object 42 | * 43 | * @return string template source 44 | */ 45 | public function getContent(Smarty_Template_Source $source) 46 | { 47 | return $this->decode($source->name); 48 | } 49 | 50 | /** 51 | * decode base64 and urlencode 52 | * 53 | * @param string $string template_resource to decode 54 | * 55 | * @return string decoded template_resource 56 | */ 57 | protected function decode($string) 58 | { 59 | // decode if specified 60 | if (($pos = strpos($string, ':')) !== false) { 61 | if (!strncmp($string, 'base64', 6)) { 62 | return base64_decode(substr($string, 7)); 63 | } elseif (!strncmp($string, 'urlencode', 9)) { 64 | return urldecode(substr($string, 10)); 65 | } 66 | } 67 | 68 | return $string; 69 | } 70 | 71 | /** 72 | * modify resource_name according to resource handlers specifications 73 | * 74 | * @param Smarty $smarty Smarty instance 75 | * @param string $resource_name resource_name to make unique 76 | * @param boolean $isConfig flag for config resource 77 | * 78 | * @return string unique resource name 79 | */ 80 | public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) 81 | { 82 | return get_class($this) . '#' . $this->decode($resource_name); 83 | } 84 | 85 | /** 86 | * Determine basename for compiled filename 87 | * Always returns an empty string. 88 | * 89 | * @param Smarty_Template_Source $source source object 90 | * 91 | * @return string resource's basename 92 | */ 93 | public function getBasename(Smarty_Template_Source $source) 94 | { 95 | return ''; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_runtime_cachemodify.php: -------------------------------------------------------------------------------- 1 | isCached() && !$_template->compiled->has_nocache_code; 22 | $_last_modified_date = 23 | @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); 24 | if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) { 25 | switch (PHP_SAPI) { 26 | case 'cgi': // php-cgi < 5.3 27 | case 'cgi-fcgi': // php-cgi >= 5.3 28 | case 'fpm-fcgi': // php-fpm >= 5.3.3 29 | header('Status: 304 Not Modified'); 30 | break; 31 | 32 | case 'cli': 33 | if ( /* ^phpunit */ 34 | !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */ 35 | ) { 36 | $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified'; 37 | } 38 | break; 39 | 40 | default: 41 | if ( /* ^phpunit */ 42 | !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */ 43 | ) { 44 | $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified'; 45 | } else { 46 | header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified'); 47 | } 48 | break; 49 | } 50 | } else { 51 | switch (PHP_SAPI) { 52 | case 'cli': 53 | if ( /* ^phpunit */ 54 | !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */ 55 | ) { 56 | $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 57 | 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT'; 58 | } 59 | break; 60 | default: 61 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT'); 62 | break; 63 | } 64 | echo $content; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_runtime_filterhandler.php: -------------------------------------------------------------------------------- 1 | smarty->autoload_filters[$type])) { 37 | foreach ((array) $template->smarty->autoload_filters[$type] as $name) { 38 | $plugin_name = "Smarty_{$type}filter_{$name}"; 39 | if (function_exists($plugin_name)) { 40 | $callback = $plugin_name; 41 | } elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) { 42 | $callback = array($plugin_name, 'execute'); 43 | } elseif ($template->smarty->loadPlugin($plugin_name, false)) { 44 | if (function_exists($plugin_name)) { 45 | // use loaded Smarty2 style plugin 46 | $callback = $plugin_name; 47 | } elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) { 48 | // loaded class of filter plugin 49 | $callback = array($plugin_name, 'execute'); 50 | } else { 51 | throw new SmartyException("Auto load {$type}-filter plugin method \"{$plugin_name}::execute\" not callable"); 52 | } 53 | } else { 54 | // nothing found, throw exception 55 | throw new SmartyException("Unable to auto load {$type}-filter plugin \"{$plugin_name}\""); 56 | } 57 | $content = call_user_func($callback, $content, $template); 58 | } 59 | } 60 | // loop over registered filters of specified type 61 | if (!empty($template->smarty->registered_filters[$type])) { 62 | foreach ($template->smarty->registered_filters[$type] as $key => $name) { 63 | $content = call_user_func($template->smarty->registered_filters[$type][$key], $content, $template); 64 | } 65 | } 66 | // return filtered output 67 | return $content; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_runtime_foreach.php: -------------------------------------------------------------------------------- 1 | getIterator()); 29 | } elseif ($value instanceof Iterator) { 30 | return iterator_count($value); 31 | } elseif ($value instanceof PDOStatement) { 32 | return $value->rowCount(); 33 | } elseif ($value instanceof Traversable) { 34 | return iterator_count($value); 35 | } elseif ($value instanceof ArrayAccess) { 36 | if ($value->offsetExists(0)) { 37 | return 1; 38 | } 39 | } elseif (is_object($value)) { 40 | return count($value); 41 | } 42 | return 0; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_runtime_hhvm.php: -------------------------------------------------------------------------------- 1 | scope) { 23 | return; 24 | } 25 | foreach (array($scope, $tpl->scope) as $s) { 26 | $s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s; 27 | if ($bubble_up && $s) { 28 | $ptr = $tpl->parent; 29 | if (isset($ptr)) { 30 | $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; 31 | $ptr = $ptr->parent; 32 | } 33 | if ($s == Smarty::SCOPE_PARENT) { 34 | continue; 35 | } 36 | while (isset($ptr) && $ptr->_objType == 2) { 37 | $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; 38 | $ptr = $ptr->parent; 39 | } 40 | if ($s == Smarty::SCOPE_TPL_ROOT) { 41 | continue; 42 | } elseif ($s == Smarty::SCOPE_SMARTY) { 43 | $tpl->smarty->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; 44 | } elseif ($s == Smarty::SCOPE_GLOBAL) { 45 | Smarty::$global_tpl_vars[$varName] = $tpl->tpl_vars[$varName]; 46 | } elseif ($s == Smarty::SCOPE_ROOT) { 47 | while (isset($ptr->parent)) { 48 | $ptr = $ptr->parent; 49 | } 50 | $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName]; 51 | } 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_runtime_var.php: -------------------------------------------------------------------------------- 1 | tpl_vars[$varName])) { 23 | $tpl->tpl_vars[$varName] = new Smarty_Variable(array(), $nocache); 24 | } else { 25 | $tpl->tpl_vars[$varName] = clone $tpl->tpl_vars[$varName]; 26 | if (!(is_array($tpl->tpl_vars[$varName]->value) || 27 | $tpl->tpl_vars[$varName]->value instanceof ArrayAccess) 28 | ) { 29 | settype($tpl->tpl_vars[$varName]->value, 'array'); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_runtime_writefile.php: -------------------------------------------------------------------------------- 1 | _file_perms : 0644; 33 | $_dir_perms = property_exists($smarty, '_dir_perms') ? (isset($smarty->_dir_perms) ? $smarty->_dir_perms : 0777) : 0771; 34 | if ($_file_perms !== null) { 35 | $old_umask = umask(0); 36 | } 37 | 38 | $_dirpath = dirname($_filepath); 39 | // if subdirs, create dir structure 40 | if ($_dirpath !== '.' && !file_exists($_dirpath)) { 41 | mkdir($_dirpath, $_dir_perms, true); 42 | } 43 | 44 | // write to tmp file, then move to overt file lock race condition 45 | $_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true)); 46 | if (!file_put_contents($_tmp_file, $_contents)) { 47 | error_reporting($_error_reporting); 48 | throw new SmartyException("unable to write file {$_tmp_file}"); 49 | } 50 | 51 | /* 52 | * Windows' rename() fails if the destination exists, 53 | * Linux' rename() properly handles the overwrite. 54 | * Simply unlink()ing a file might cause other processes 55 | * currently reading that file to fail, but linux' rename() 56 | * seems to be smart enough to handle that for us. 57 | */ 58 | if (Smarty::$_IS_WINDOWS) { 59 | // remove original file 60 | if (is_file($_filepath)) { 61 | @unlink($_filepath); 62 | } 63 | // rename tmp file 64 | $success = @rename($_tmp_file, $_filepath); 65 | } else { 66 | // rename tmp file 67 | $success = @rename($_tmp_file, $_filepath); 68 | if (!$success) { 69 | // remove original file 70 | if (is_file($_filepath)) { 71 | @unlink($_filepath); 72 | } 73 | // rename tmp file 74 | $success = @rename($_tmp_file, $_filepath); 75 | } 76 | } 77 | if (!$success) { 78 | error_reporting($_error_reporting); 79 | throw new SmartyException("unable to write file {$_filepath}"); 80 | } 81 | if ($_file_perms !== null) { 82 | // set file permissions 83 | chmod($_filepath, $_file_perms); 84 | umask($old_umask); 85 | } 86 | error_reporting($_error_reporting); 87 | 88 | return true; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_internal_undefined.php: -------------------------------------------------------------------------------- 1 | cached->valid = false; 29 | } else { 30 | $tpl->mustCompile = true; 31 | } 32 | return false; 33 | } 34 | 35 | /** 36 | * Call error handler for undefined method 37 | * 38 | * @param string $name unknown method-name 39 | * @param array $args argument array 40 | * 41 | * @return mixed 42 | * @throws SmartyException 43 | */ 44 | public function __call($name, $args) 45 | { 46 | throw new SmartyException(get_class($args[0]) . "->{$name}() undefined method"); 47 | } 48 | } -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_resource_custom.php: -------------------------------------------------------------------------------- 1 | filepath = $source->type . ':' . $source->name; 51 | $source->uid = sha1($source->type . ':' . $source->name); 52 | 53 | $mtime = $this->fetchTimestamp($source->name); 54 | if ($mtime !== null) { 55 | $source->timestamp = $mtime; 56 | } else { 57 | $this->fetch($source->name, $content, $timestamp); 58 | $source->timestamp = isset($timestamp) ? $timestamp : false; 59 | if (isset($content)) { 60 | $source->content = $content; 61 | } 62 | } 63 | $source->exists = !!$source->timestamp; 64 | } 65 | 66 | /** 67 | * Load template's source into current template object 68 | * 69 | * @param Smarty_Template_Source $source source object 70 | * 71 | * @return string template source 72 | * @throws SmartyException if source cannot be loaded 73 | */ 74 | public function getContent(Smarty_Template_Source $source) 75 | { 76 | $this->fetch($source->name, $content, $timestamp); 77 | if (isset($content)) { 78 | return $content; 79 | } 80 | 81 | throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); 82 | } 83 | 84 | /** 85 | * Determine basename for compiled filename 86 | * 87 | * @param Smarty_Template_Source $source source object 88 | * 89 | * @return string resource's basename 90 | */ 91 | public function getBasename(Smarty_Template_Source $source) 92 | { 93 | return basename($source->name); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_resource_recompiled.php: -------------------------------------------------------------------------------- 1 | filepath = false; 44 | $compiled->timestamp = false; 45 | $compiled->exists = false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_resource_uncompiled.php: -------------------------------------------------------------------------------- 1 | filepath = false; 52 | $compiled->timestamp = false; 53 | $compiled->exists = false; 54 | } 55 | 56 | /** 57 | * render compiled template code 58 | * 59 | * @param Smarty_Internal_Template $_template 60 | * 61 | * @return string 62 | * @throws Exception 63 | */ 64 | public function render($_template) 65 | { 66 | $level = ob_get_level(); 67 | ob_start(); 68 | try { 69 | $this->renderUncompiled($_template->source, $_template); 70 | return ob_get_clean(); 71 | } 72 | catch (Exception $e) { 73 | while (ob_get_level() > $level) { 74 | ob_end_clean(); 75 | } 76 | throw $e; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /smarty/sysplugins/smarty_undefined_variable.php: -------------------------------------------------------------------------------- 1 | value = $value; 34 | $this->nocache = $nocache; 35 | } 36 | 37 | /** 38 | * <> String conversion 39 | * 40 | * @return string 41 | */ 42 | public function __toString() 43 | { 44 | return (string) $this->value; 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /smarty/sysplugins/smartycompilerexception.php: -------------------------------------------------------------------------------- 1 | Smarty Compiler: ' . $this->message . ' <-- '; 13 | } 14 | 15 | /** 16 | * The line number of the template error 17 | * 18 | * @type int|null 19 | */ 20 | public $line = null; 21 | /** 22 | * The template source snippet relating to the error 23 | * 24 | * @type string|null 25 | */ 26 | public $source = null; 27 | /** 28 | * The raw text of the error message 29 | * 30 | * @type string|null 31 | */ 32 | public $desc = null; 33 | /** 34 | * The resource identifier or template name 35 | * 36 | * @type string|null 37 | */ 38 | public $template = null; 39 | } 40 | -------------------------------------------------------------------------------- /smarty/sysplugins/smartyexception.php: -------------------------------------------------------------------------------- 1 | Smarty: ' . (self::$escape ? htmlentities($this->message) : $this->message) . ' <-- '; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /smarty/templaces_c/59fc60b721b089160b69f92d5e6907f8c58a02e1_0.file.index.tpl.php: -------------------------------------------------------------------------------- 1 | smarty->ext->_validateCompiled->decodeProperties($_smarty_tpl, array ( 6 | 'has_nocache_code' => false, 7 | 'version' => '3.1.28-dev/77', 8 | 'unifunc' => 'content_565fe20c668793_17860579', 9 | 'file_dependency' => 10 | array ( 11 | '59fc60b721b089160b69f92d5e6907f8c58a02e1' => 12 | array ( 13 | 0 => '/Applications/MAMP/htdocs/YouTube/app/smarty/templates/home/index.tpl', 14 | 1 => 1449124361, 15 | 2 => 'file', 16 | ), 17 | ), 18 | 'includes' => 19 | array ( 20 | ), 21 | ),false)) { 22 | function content_565fe20c668793_17860579 ($_smarty_tpl) { 23 | ?> 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 | tpl_vars['names']->value; 35 | if (!is_array($_from) && !is_object($_from)) { 36 | settype($_from, 'array'); 37 | } 38 | $__foreach_i_0_saved_item = isset($_smarty_tpl->tpl_vars['i']) ? $_smarty_tpl->tpl_vars['i'] : false; 39 | $__foreach_i_0_saved_key = isset($_smarty_tpl->tpl_vars['k']) ? $_smarty_tpl->tpl_vars['k'] : false; 40 | $_smarty_tpl->tpl_vars['i'] = new Smarty_Variable(); 41 | $__foreach_i_0_total = $_smarty_tpl->smarty->ext->_foreach->count($_from); 42 | if ($__foreach_i_0_total) { 43 | $_smarty_tpl->tpl_vars['k'] = new Smarty_Variable(); 44 | foreach ($_from as $_smarty_tpl->tpl_vars['k']->value => $_smarty_tpl->tpl_vars['i']->value) { 45 | $__foreach_i_0_saved_local_item = $_smarty_tpl->tpl_vars['i']; 46 | ?> 47 | Name: tpl_vars['i']->value['name'];?> 48 |
49 | tpl_vars['i'] = $__foreach_i_0_saved_local_item; 51 | } 52 | } 53 | if ($__foreach_i_0_saved_item) { 54 | $_smarty_tpl->tpl_vars['i'] = $__foreach_i_0_saved_item; 55 | } 56 | if ($__foreach_i_0_saved_key) { 57 | $_smarty_tpl->tpl_vars['k'] = $__foreach_i_0_saved_key; 58 | } 59 | ?> 60 |
61 | 62 | 63 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | {foreach from=$names key=k item=i} 11 | Name: {$i.name}
12 | {/foreach} 13 |
14 | 15 | 16 | --------------------------------------------------------------------------------