Changeset 23384 for trunk/include/smarty/libs
- Timestamp:
- Jun 20, 2013, 5:38:47 AM (11 years ago)
- Location:
- trunk/include/smarty/libs
- Files:
-
- 95 added
- 24 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/smarty/libs/Smarty.class.php
r3703 r23384 1 1 <?php 2 3 2 /** 4 3 * Project: Smarty: the PHP compiling template engine 5 4 * File: Smarty.class.php 5 * SVN: $Id: Smarty.class.php 4694 2013-01-13 21:13:14Z uwe.tews@googlemail.com $ 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 24 24 * 25 25 * @link http://www.smarty.net/ 26 * @copyright 200 1-2005New Digital Group, Inc.26 * @copyright 2008 New Digital Group, Inc. 27 27 * @author Monte Ohrt <monte at ohrt dot com> 28 * @author Andrei Zmievski <andrei@php.net> 28 * @author Uwe Tews 29 * @author Rodney Rehm 29 30 * @package Smarty 30 * @version 2.6.2631 * @version 3.1.13 31 32 */ 32 33 33 /* $Id: Smarty.class.php 3163 2009-06-17 14:39:24Z monte.ohrt $ */34 35 34 /** 36 * DIR_SEP isn't used anymore, but third party apps might35 * define shorthand directory separator constant 37 36 */ 38 if (!defined('DIR_SEP')) {39 define('D IR_SEP', DIRECTORY_SEPARATOR);37 if (!defined('DS')) { 38 define('DS', DIRECTORY_SEPARATOR); 40 39 } 41 40 42 41 /** 43 42 * set SMARTY_DIR to absolute path to Smarty library files. 44 * if not defined, include_path will be used. Sets SMARTY_DIR only if user 45 * application has not already defined it. 43 * Sets SMARTY_DIR only if user application has not already defined it. 46 44 */ 47 48 45 if (!defined('SMARTY_DIR')) { 49 define('SMARTY_DIR', dirname(__FILE__) . D IRECTORY_SEPARATOR);46 define('SMARTY_DIR', dirname(__FILE__) . DS); 50 47 } 51 48 52 if (!defined('SMARTY_CORE_DIR')) { 53 define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR); 49 /** 50 * set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins. 51 * Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it. 52 */ 53 if (!defined('SMARTY_SYSPLUGINS_DIR')) { 54 define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS); 54 55 } 55 56 define('SMARTY_PHP_PASSTHRU', 0); 57 define('SMARTY_PHP_QUOTE', 1); 58 define('SMARTY_PHP_REMOVE', 2); 59 define('SMARTY_PHP_ALLOW', 3); 56 if (!defined('SMARTY_PLUGINS_DIR')) { 57 define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS); 58 } 59 if (!defined('SMARTY_MBSTRING')) { 60 define('SMARTY_MBSTRING', function_exists('mb_split')); 61 } 62 if (!defined('SMARTY_RESOURCE_CHAR_SET')) { 63 // UTF-8 can only be done properly when mbstring is available! 64 /** 65 * @deprecated in favor of Smarty::$_CHARSET 66 */ 67 define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1'); 68 } 69 if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { 70 /** 71 * @deprecated in favor of Smarty::$_DATE_FORMAT 72 */ 73 define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); 74 } 60 75 61 76 /** 77 * register the class autoloader 78 */ 79 if (!defined('SMARTY_SPL_AUTOLOAD')) { 80 define('SMARTY_SPL_AUTOLOAD', 0); 81 } 82 83 if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) { 84 $registeredAutoLoadFunctions = spl_autoload_functions(); 85 if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { 86 spl_autoload_register(); 87 } 88 } else { 89 spl_autoload_register('smartyAutoload'); 90 } 91 92 /** 93 * Load always needed external class files 94 */ 95 include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_data.php'; 96 include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_templatebase.php'; 97 include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_template.php'; 98 include_once SMARTY_SYSPLUGINS_DIR.'smarty_resource.php'; 99 include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_resource_file.php'; 100 include_once SMARTY_SYSPLUGINS_DIR.'smarty_cacheresource.php'; 101 include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_cacheresource_file.php'; 102 103 /** 104 * This is the main Smarty class 62 105 * @package Smarty 63 106 */ 64 class Smarty 65 { 107 class Smarty extends Smarty_Internal_TemplateBase { 108 66 109 /**#@+ 67 * Smarty Configuration Section 68 */ 69 70 /** 71 * The name of the directory where templates are located. 72 * 110 * constant definitions 111 */ 112 113 /** 114 * smarty version 115 */ 116 const SMARTY_VERSION = 'Smarty-3.1.13'; 117 118 /** 119 * define variable scopes 120 */ 121 const SCOPE_LOCAL = 0; 122 const SCOPE_PARENT = 1; 123 const SCOPE_ROOT = 2; 124 const SCOPE_GLOBAL = 3; 125 /** 126 * define caching modes 127 */ 128 const CACHING_OFF = 0; 129 const CACHING_LIFETIME_CURRENT = 1; 130 const CACHING_LIFETIME_SAVED = 2; 131 /** 132 * define compile check modes 133 */ 134 const COMPILECHECK_OFF = 0; 135 const COMPILECHECK_ON = 1; 136 const COMPILECHECK_CACHEMISS = 2; 137 /** 138 * modes for handling of "<?php ... ?>" tags in templates. 139 */ 140 const PHP_PASSTHRU = 0; //-> print tags as plain text 141 const PHP_QUOTE = 1; //-> escape tags as entities 142 const PHP_REMOVE = 2; //-> escape tags as entities 143 const PHP_ALLOW = 3; //-> escape tags as entities 144 /** 145 * filter types 146 */ 147 const FILTER_POST = 'post'; 148 const FILTER_PRE = 'pre'; 149 const FILTER_OUTPUT = 'output'; 150 const FILTER_VARIABLE = 'variable'; 151 /** 152 * plugin types 153 */ 154 const PLUGIN_FUNCTION = 'function'; 155 const PLUGIN_BLOCK = 'block'; 156 const PLUGIN_COMPILER = 'compiler'; 157 const PLUGIN_MODIFIER = 'modifier'; 158 const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; 159 160 /**#@-*/ 161 162 /** 163 * assigned global tpl vars 164 */ 165 public static $global_tpl_vars = array(); 166 167 /** 168 * error handler returned by set_error_hanlder() in Smarty::muteExpectedErrors() 169 */ 170 public static $_previous_error_handler = null; 171 /** 172 * contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors() 173 */ 174 public static $_muted_directories = array(); 175 /** 176 * Flag denoting if Multibyte String functions are available 177 */ 178 public static $_MBSTRING = SMARTY_MBSTRING; 179 /** 180 * The character set to adhere to (e.g. "UTF-8") 181 */ 182 public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET; 183 /** 184 * The date format to be used internally 185 * (accepts date() and strftime()) 186 */ 187 public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT; 188 /** 189 * Flag denoting if PCRE should run in UTF-8 mode 190 */ 191 public static $_UTF8_MODIFIER = 'u'; 192 193 /** 194 * Flag denoting if operating system is windows 195 */ 196 public static $_IS_WINDOWS = false; 197 198 /**#@+ 199 * variables 200 */ 201 202 /** 203 * auto literal on delimiters with whitspace 204 * @var boolean 205 */ 206 public $auto_literal = true; 207 /** 208 * display error on not assigned variables 209 * @var boolean 210 */ 211 public $error_unassigned = false; 212 /** 213 * look up relative filepaths in include_path 214 * @var boolean 215 */ 216 public $use_include_path = false; 217 /** 218 * template directory 219 * @var array 220 */ 221 private $template_dir = array(); 222 /** 223 * joined template directory string used in cache keys 73 224 * @var string 74 225 */ 75 var $template_dir = 'templates'; 76 77 /** 78 * The directory where compiled templates are located. 79 * 226 public $joined_template_dir = null; 227 /** 228 * joined config directory string used in cache keys 80 229 * @var string 81 230 */ 82 var $compile_dir = 'templates_c'; 83 84 /** 85 * The directory where config files are located. 86 * 231 public $joined_config_dir = null; 232 /** 233 * default template handler 234 * @var callable 235 */ 236 public $default_template_handler_func = null; 237 /** 238 * default config handler 239 * @var callable 240 */ 241 public $default_config_handler_func = null; 242 /** 243 * default plugin handler 244 * @var callable 245 */ 246 public $default_plugin_handler_func = null; 247 /** 248 * compile directory 87 249 * @var string 88 250 */ 89 var $config_dir = 'configs'; 90 91 /** 92 * An array of directories searched for plugins. 93 * 94 * @var array 95 */ 96 var $plugins_dir = array('plugins'); 97 98 /** 99 * If debugging is enabled, a debug console window will display 100 * when the page loads (make sure your browser allows unrequested 101 * popup windows) 102 * 103 * @var boolean 104 */ 105 var $debugging = false; 106 107 /** 108 * When set, smarty does uses this value as error_reporting-level. 109 * 251 private $compile_dir = null; 252 /** 253 * plugins directory 254 * @var array 255 */ 256 private $plugins_dir = array(); 257 /** 258 * cache directory 259 * @var string 260 */ 261 private $cache_dir = null; 262 /** 263 * config directory 264 * @var array 265 */ 266 private $config_dir = array(); 267 /** 268 * force template compiling? 269 * @var boolean 270 */ 271 public $force_compile = false; 272 /** 273 * check template for modifications? 274 * @var boolean 275 */ 276 public $compile_check = true; 277 /** 278 * use sub dirs for compiled/cached files? 279 * @var boolean 280 */ 281 public $use_sub_dirs = false; 282 /** 283 * allow ambiguous resources (that are made unique by the resource handler) 284 * @var boolean 285 */ 286 public $allow_ambiguous_resources = false; 287 /** 288 * caching enabled 289 * @var boolean 290 */ 291 public $caching = false; 292 /** 293 * merge compiled includes 294 * @var boolean 295 */ 296 public $merge_compiled_includes = false; 297 /** 298 * cache lifetime in seconds 110 299 * @var integer 111 300 */ 112 var $error_reporting = null; 113 114 /** 115 * This is the path to the debug console template. If not set, 116 * the default one will be used. 301 public $cache_lifetime = 3600; 302 /** 303 * force cache file creation 304 * @var boolean 305 */ 306 public $force_cache = false; 307 /** 308 * Set this if you want different sets of cache files for the same 309 * templates. 117 310 * 118 311 * @var string 119 312 */ 120 var $debug_tpl = ''; 121 313 public $cache_id = null; 314 /** 315 * Set this if you want different sets of compiled files for the same 316 * templates. 317 * 318 * @var string 319 */ 320 public $compile_id = null; 321 /** 322 * template left-delimiter 323 * @var string 324 */ 325 public $left_delimiter = "{"; 326 /** 327 * template right-delimiter 328 * @var string 329 */ 330 public $right_delimiter = "}"; 331 /**#@+ 332 * security 333 */ 334 /** 335 * class name 336 * 337 * This should be instance of Smarty_Security. 338 * 339 * @var string 340 * @see Smarty_Security 341 */ 342 public $security_class = 'Smarty_Security'; 343 /** 344 * implementation of security class 345 * 346 * @var Smarty_Security 347 */ 348 public $security_policy = null; 349 /** 350 * controls handling of PHP-blocks 351 * 352 * @var integer 353 */ 354 public $php_handling = self::PHP_PASSTHRU; 355 /** 356 * controls if the php template file resource is allowed 357 * 358 * @var bool 359 */ 360 public $allow_php_templates = false; 361 /** 362 * Should compiled-templates be prevented from being called directly? 363 * 364 * {@internal 365 * Currently used by Smarty_Internal_Template only. 366 * }} 367 * 368 * @var boolean 369 */ 370 public $direct_access_security = true; 371 /**#@-*/ 372 /** 373 * debug mode 374 * 375 * Setting this to true enables the debug-console. 376 * 377 * @var boolean 378 */ 379 public $debugging = false; 122 380 /** 123 381 * This determines if debugging is enable-able from the browser. … … 126 384 * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li> 127 385 * </ul> 128 * @link http://www.foo.dom/index.php?SMARTY_DEBUG129 386 * @var string 130 387 */ 131 var $debugging_ctrl = 'NONE'; 132 133 /** 134 * This tells Smarty whether to check for recompiling or not. Recompiling 135 * does not need to happen unless a template or config file is changed. 136 * Typically you enable this during development, and disable for 137 * production. 138 * 139 * @var boolean 140 */ 141 var $compile_check = true; 142 143 /** 144 * This forces templates to compile every time. Useful for development 145 * or debugging. 146 * 147 * @var boolean 148 */ 149 var $force_compile = false; 150 151 /** 152 * This enables template caching. 153 * <ul> 154 * <li>0 = no caching</li> 155 * <li>1 = use class cache_lifetime value</li> 156 * <li>2 = use cache_lifetime in cache file</li> 157 * </ul> 158 * @var integer 159 */ 160 var $caching = 0; 161 162 /** 163 * The name of the directory for cache files. 164 * 388 public $debugging_ctrl = 'NONE'; 389 /** 390 * Name of debugging URL-param. 391 * 392 * Only used when $debugging_ctrl is set to 'URL'. 393 * The name of the URL-parameter that activates debugging. 394 * 395 * @var type 396 */ 397 public $smarty_debug_id = 'SMARTY_DEBUG'; 398 /** 399 * Path of debug template. 165 400 * @var string 166 401 */ 167 var $cache_dir = 'cache'; 168 169 /** 170 * This is the number of seconds cached content will persist. 171 * <ul> 172 * <li>0 = always regenerate cache</li> 173 * <li>-1 = never expires</li> 174 * </ul> 175 * 176 * @var integer 177 */ 178 var $cache_lifetime = 3600; 179 180 /** 181 * Only used when $caching is enabled. If true, then If-Modified-Since headers 182 * are respected with cached content, and appropriate HTTP headers are sent. 183 * This way repeated hits to a cached page do not send the entire page to the 184 * client every time. 185 * 186 * @var boolean 187 */ 188 var $cache_modified_check = false; 189 190 /** 191 * This determines how Smarty handles "<?php ... ?>" tags in templates. 192 * possible values: 193 * <ul> 194 * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li> 195 * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li> 196 * <li>SMARTY_PHP_REMOVE -> remove php tags</li> 197 * <li>SMARTY_PHP_ALLOW -> execute php tags</li> 198 * </ul> 199 * 200 * @var integer 201 */ 202 var $php_handling = SMARTY_PHP_PASSTHRU; 203 204 /** 205 * This enables template security. When enabled, many things are restricted 206 * in the templates that normally would go unchecked. This is useful when 207 * untrusted parties are editing templates and you want a reasonable level 208 * of security. (no direct execution of PHP in templates for example) 209 * 210 * @var boolean 211 */ 212 var $security = false; 213 214 /** 215 * This is the list of template directories that are considered secure. This 216 * is used only if {@link $security} is enabled. One directory per array 217 * element. {@link $template_dir} is in this list implicitly. 218 * 219 * @var array 220 */ 221 var $secure_dir = array(); 222 223 /** 224 * These are the security settings for Smarty. They are used only when 225 * {@link $security} is enabled. 226 * 227 * @var array 228 */ 229 var $security_settings = array( 230 'PHP_HANDLING' => false, 231 'IF_FUNCS' => array('array', 'list', 232 'isset', 'empty', 233 'count', 'sizeof', 234 'in_array', 'is_array', 235 'true', 'false', 'null'), 236 'INCLUDE_ANY' => false, 237 'PHP_TAGS' => false, 238 'MODIFIER_FUNCS' => array('count'), 239 'ALLOW_CONSTANTS' => false, 240 'ALLOW_SUPER_GLOBALS' => true 241 ); 242 243 /** 244 * This is an array of directories where trusted php scripts reside. 245 * {@link $security} is disabled during their inclusion/execution. 246 * 247 * @var array 248 */ 249 var $trusted_dir = array(); 250 251 /** 252 * The left delimiter used for the template tags. 253 * 402 public $debug_tpl = null; 403 /** 404 * When set, smarty uses this value as error_reporting-level. 405 * @var int 406 */ 407 public $error_reporting = null; 408 /** 409 * Internal flag for getTags() 410 * @var boolean 411 */ 412 public $get_used_tags = false; 413 414 /**#@+ 415 * config var settings 416 */ 417 418 /** 419 * Controls whether variables with the same name overwrite each other. 420 * @var boolean 421 */ 422 public $config_overwrite = true; 423 /** 424 * Controls whether config values of on/true/yes and off/false/no get converted to boolean. 425 * @var boolean 426 */ 427 public $config_booleanize = true; 428 /** 429 * Controls whether hidden config sections/vars are read from the file. 430 * @var boolean 431 */ 432 public $config_read_hidden = false; 433 434 /**#@-*/ 435 436 /**#@+ 437 * resource locking 438 */ 439 440 /** 441 * locking concurrent compiles 442 * @var boolean 443 */ 444 public $compile_locking = true; 445 /** 446 * Controls whether cache resources should emply locking mechanism 447 * @var boolean 448 */ 449 public $cache_locking = false; 450 /** 451 * seconds to wait for acquiring a lock before ignoring the write lock 452 * @var float 453 */ 454 public $locking_timeout = 10; 455 456 /**#@-*/ 457 458 /** 459 * global template functions 460 * @var array 461 */ 462 public $template_functions = array(); 463 /** 464 * resource type used if none given 465 * 466 * Must be an valid key of $registered_resources. 254 467 * @var string 255 468 */ 256 var $left_delimiter = '{'; 257 258 /** 259 * The right delimiter used for the template tags. 469 public $default_resource_type = 'file'; 470 /** 471 * caching type 472 * 473 * Must be an element of $cache_resource_types. 260 474 * 261 475 * @var string 262 476 */ 263 var $right_delimiter = '}'; 264 265 /** 266 * The order in which request variables are registered, similar to 267 * variables_order in php.ini E = Environment, G = GET, P = POST, 268 * C = Cookies, S = Server 269 * 477 public $caching_type = 'file'; 478 /** 479 * internal config properties 480 * @var array 481 */ 482 public $properties = array(); 483 /** 484 * config type 270 485 * @var string 271 486 */ 272 var $request_vars_order = 'EGPCS'; 273 274 /** 275 * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false) 276 * are uses as request-vars or $_*[]-vars. note: if 277 * request_use_auto_globals is true, then $request_vars_order has 278 * no effect, but the php-ini-value "gpc_order" 279 * 280 * @var boolean 281 */ 282 var $request_use_auto_globals = true; 283 284 /** 285 * Set this if you want different sets of compiled files for the same 286 * templates. This is useful for things like different languages. 287 * Instead of creating separate sets of templates per language, you 288 * set different compile_ids like 'en' and 'de'. 289 * 487 public $default_config_type = 'file'; 488 /** 489 * cached template objects 490 * @var array 491 */ 492 public $template_objects = array(); 493 /** 494 * check If-Modified-Since headers 495 * @var boolean 496 */ 497 public $cache_modified_check = false; 498 /** 499 * registered plugins 500 * @var array 501 */ 502 public $registered_plugins = array(); 503 /** 504 * plugin search order 505 * @var array 506 */ 507 public $plugin_search_order = array('function', 'block', 'compiler', 'class'); 508 /** 509 * registered objects 510 * @var array 511 */ 512 public $registered_objects = array(); 513 /** 514 * registered classes 515 * @var array 516 */ 517 public $registered_classes = array(); 518 /** 519 * registered filters 520 * @var array 521 */ 522 public $registered_filters = array(); 523 /** 524 * registered resources 525 * @var array 526 */ 527 public $registered_resources = array(); 528 /** 529 * resource handler cache 530 * @var array 531 */ 532 public $_resource_handlers = array(); 533 /** 534 * registered cache resources 535 * @var array 536 */ 537 public $registered_cache_resources = array(); 538 /** 539 * cache resource handler cache 540 * @var array 541 */ 542 public $_cacheresource_handlers = array(); 543 /** 544 * autoload filter 545 * @var array 546 */ 547 public $autoload_filters = array(); 548 /** 549 * default modifier 550 * @var array 551 */ 552 public $default_modifiers = array(); 553 /** 554 * autoescape variable output 555 * @var boolean 556 */ 557 public $escape_html = false; 558 /** 559 * global internal smarty vars 560 * @var array 561 */ 562 public static $_smarty_vars = array(); 563 /** 564 * start time for execution time calculation 565 * @var int 566 */ 567 public $start_time = 0; 568 /** 569 * default file permissions 570 * @var int 571 */ 572 public $_file_perms = 0644; 573 /** 574 * default dir permissions 575 * @var int 576 */ 577 public $_dir_perms = 0771; 578 /** 579 * block tag hierarchy 580 * @var array 581 */ 582 public $_tag_stack = array(); 583 /** 584 * self pointer to Smarty object 585 * @var Smarty 586 */ 587 public $smarty; 588 /** 589 * required by the compiler for BC 290 590 * @var string 291 591 */ 292 var $compile_id = null; 293 294 /** 295 * This tells Smarty whether or not to use sub dirs in the cache/ and 296 * templates_c/ directories. sub directories better organized, but 297 * may not work well with PHP safe mode enabled. 298 * 299 * @var boolean 300 * 301 */ 302 var $use_sub_dirs = false; 303 304 /** 305 * This is a list of the modifiers to apply to all template variables. 306 * Put each modifier in a separate array element in the order you want 307 * them applied. example: <code>array('escape:"htmlall"');</code> 308 * 309 * @var array 310 */ 311 var $default_modifiers = array(); 312 313 /** 314 * This is the resource type to be used when not specified 315 * at the beginning of the resource path. examples: 316 * $smarty->display('file:index.tpl'); 317 * $smarty->display('db:index.tpl'); 318 * $smarty->display('index.tpl'); // will use default resource type 319 * {include file="file:index.tpl"} 320 * {include file="db:index.tpl"} 321 * {include file="index.tpl"} {* will use default resource type *} 322 * 323 * @var array 324 */ 325 var $default_resource_type = 'file'; 326 327 /** 328 * The function used for cache file handling. If not set, built-in caching is used. 329 * 330 * @var null|string function name 331 */ 332 var $cache_handler_func = null; 333 334 /** 335 * This indicates which filters are automatically loaded into Smarty. 336 * 337 * @var array array of filter names 338 */ 339 var $autoload_filters = array(); 340 341 /**#@+ 342 * @var boolean 343 */ 344 /** 345 * This tells if config file vars of the same name overwrite each other or not. 346 * if disabled, same name variables are accumulated in an array. 347 */ 348 var $config_overwrite = true; 349 350 /** 351 * This tells whether or not to automatically booleanize config file variables. 352 * If enabled, then the strings "on", "true", and "yes" are treated as boolean 353 * true, and "off", "false" and "no" are treated as boolean false. 354 */ 355 var $config_booleanize = true; 356 357 /** 358 * This tells whether hidden sections [.foobar] are readable from the 359 * tempalates or not. Normally you would never allow this since that is 360 * the point behind hidden sections: the application can access them, but 361 * the templates cannot. 362 */ 363 var $config_read_hidden = false; 364 365 /** 366 * This tells whether or not automatically fix newlines in config files. 367 * It basically converts \r (mac) or \r\n (dos) to \n 368 */ 369 var $config_fix_newlines = true; 592 public $_current_file = null; 593 /** 594 * internal flag to enable parser debugging 595 * @var bool 596 */ 597 public $_parserdebug = false; 598 /** 599 * Saved parameter of merged templates during compilation 600 * 601 * @var array 602 */ 603 public $merged_templates_func = array(); 370 604 /**#@-*/ 371 605 372 606 /** 373 * If a template cannot be found, this PHP function will be executed. 374 * Useful for creating templates on-the-fly or other special action. 375 * 376 * @var string function name 377 */ 378 var $default_template_handler_func = ''; 379 380 /** 381 * The file that contains the compiler class. This can a full 382 * pathname, or relative to the php_include path. 383 * 384 * @var string 385 */ 386 var $compiler_file = 'Smarty_Compiler.class.php'; 387 388 /** 389 * The class used for compiling templates. 390 * 391 * @var string 392 */ 393 var $compiler_class = 'Smarty_Compiler'; 394 395 /** 396 * The class used to load config vars. 397 * 398 * @var string 399 */ 400 var $config_class = 'Config_File'; 401 402 /**#@+ 403 * END Smarty Configuration Section 404 * There should be no need to touch anything below this line. 405 * @access private 406 */ 407 /** 408 * where assigned template vars are kept 409 * 410 * @var array 411 */ 412 var $_tpl_vars = array(); 413 414 /** 415 * stores run-time $smarty.* vars 416 * 417 * @var null|array 418 */ 419 var $_smarty_vars = null; 420 421 /** 422 * keeps track of sections 423 * 424 * @var array 425 */ 426 var $_sections = array(); 427 428 /** 429 * keeps track of foreach blocks 430 * 431 * @var array 432 */ 433 var $_foreach = array(); 434 435 /** 436 * keeps track of tag hierarchy 437 * 438 * @var array 439 */ 440 var $_tag_stack = array(); 441 442 /** 443 * configuration object 444 * 445 * @var Config_file 446 */ 447 var $_conf_obj = null; 448 449 /** 450 * loaded configuration settings 451 * 452 * @var array 453 */ 454 var $_config = array(array('vars' => array(), 'files' => array())); 455 456 /** 457 * md5 checksum of the string 'Smarty' 458 * 459 * @var string 460 */ 461 var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; 462 463 /** 464 * Smarty version number 465 * 466 * @var string 467 */ 468 var $_version = '2.6.26'; 469 470 /** 471 * current template inclusion depth 472 * 473 * @var integer 474 */ 475 var $_inclusion_depth = 0; 476 477 /** 478 * for different compiled templates 479 * 480 * @var string 481 */ 482 var $_compile_id = null; 483 484 /** 485 * text in URL to enable debug mode 486 * 487 * @var string 488 */ 489 var $_smarty_debug_id = 'SMARTY_DEBUG'; 490 491 /** 492 * debugging information for debug console 493 * 494 * @var array 495 */ 496 var $_smarty_debug_info = array(); 497 498 /** 499 * info that makes up a cache file 500 * 501 * @var array 502 */ 503 var $_cache_info = array(); 504 505 /** 506 * default file permissions 507 * 508 * @var integer 509 */ 510 var $_file_perms = 0644; 511 512 /** 513 * default dir permissions 514 * 515 * @var integer 516 */ 517 var $_dir_perms = 0771; 518 519 /** 520 * registered objects 521 * 522 * @var array 523 */ 524 var $_reg_objects = array(); 525 526 /** 527 * table keeping track of plugins 528 * 529 * @var array 530 */ 531 var $_plugins = array( 532 'modifier' => array(), 533 'function' => array(), 534 'block' => array(), 535 'compiler' => array(), 536 'prefilter' => array(), 537 'postfilter' => array(), 538 'outputfilter' => array(), 539 'resource' => array(), 540 'insert' => array()); 541 542 543 /** 544 * cache serials 545 * 546 * @var array 547 */ 548 var $_cache_serials = array(); 549 550 /** 551 * name of optional cache include file 552 * 553 * @var string 554 */ 555 var $_cache_include = null; 556 557 /** 558 * indicate if the current code is used in a compiled 559 * include 560 * 561 * @var string 562 */ 563 var $_cache_including = false; 564 565 /**#@-*/ 566 /** 567 * The class constructor. 568 */ 569 function Smarty() 570 { 571 $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] 572 : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']); 573 } 574 575 /** 576 * assigns values to template variables 577 * 578 * @param array|string $tpl_var the template variable name(s) 579 * @param mixed $value the value to assign 580 */ 581 function assign($tpl_var, $value = null) 582 { 583 if (is_array($tpl_var)){ 584 foreach ($tpl_var as $key => $val) { 585 if ($key != '') { 586 $this->_tpl_vars[$key] = $val; 607 * Initialize new Smarty object 608 * 609 */ 610 public function __construct() 611 { 612 // selfpointer needed by some other class methods 613 $this->smarty = $this; 614 if (is_callable('mb_internal_encoding')) { 615 mb_internal_encoding(Smarty::$_CHARSET); 616 } 617 $this->start_time = microtime(true); 618 // set default dirs 619 $this->setTemplateDir('.' . DS . 'templates' . DS) 620 ->setCompileDir('.' . DS . 'templates_c' . DS) 621 ->setPluginsDir(SMARTY_PLUGINS_DIR) 622 ->setCacheDir('.' . DS . 'cache' . DS) 623 ->setConfigDir('.' . DS . 'configs' . DS); 624 625 $this->debug_tpl = 'file:' . dirname(__FILE__) . '/debug.tpl'; 626 if (isset($_SERVER['SCRIPT_NAME'])) { 627 $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); 628 } 629 } 630 631 632 /** 633 * Class destructor 634 */ 635 public function __destruct() 636 { 637 // intentionally left blank 638 } 639 640 /** 641 * <<magic>> set selfpointer on cloned object 642 */ 643 public function __clone() 644 { 645 $this->smarty = $this; 646 } 647 648 649 /** 650 * <<magic>> Generic getter. 651 * 652 * Calls the appropriate getter function. 653 * Issues an E_USER_NOTICE if no valid getter is found. 654 * 655 * @param string $name property name 656 * @return mixed 657 */ 658 public function __get($name) 659 { 660 $allowed = array( 661 'template_dir' => 'getTemplateDir', 662 'config_dir' => 'getConfigDir', 663 'plugins_dir' => 'getPluginsDir', 664 'compile_dir' => 'getCompileDir', 665 'cache_dir' => 'getCacheDir', 666 ); 667 668 if (isset($allowed[$name])) { 669 return $this->{$allowed[$name]}(); 670 } else { 671 trigger_error('Undefined property: '. get_class($this) .'::$'. $name, E_USER_NOTICE); 672 } 673 } 674 675 /** 676 * <<magic>> Generic setter. 677 * 678 * Calls the appropriate setter function. 679 * Issues an E_USER_NOTICE if no valid setter is found. 680 * 681 * @param string $name property name 682 * @param mixed $value parameter passed to setter 683 */ 684 public function __set($name, $value) 685 { 686 $allowed = array( 687 'template_dir' => 'setTemplateDir', 688 'config_dir' => 'setConfigDir', 689 'plugins_dir' => 'setPluginsDir', 690 'compile_dir' => 'setCompileDir', 691 'cache_dir' => 'setCacheDir', 692 ); 693 694 if (isset($allowed[$name])) { 695 $this->{$allowed[$name]}($value); 696 } else { 697 trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); 698 } 699 } 700 701 /** 702 * Check if a template resource exists 703 * 704 * @param string $resource_name template name 705 * @return boolean status 706 */ 707 public function templateExists($resource_name) 708 { 709 // create template object 710 $save = $this->template_objects; 711 $tpl = new $this->template_class($resource_name, $this); 712 // check if it does exists 713 $result = $tpl->source->exists; 714 $this->template_objects = $save; 715 return $result; 716 } 717 718 /** 719 * Returns a single or all global variables 720 * 721 * @param object $smarty 722 * @param string $varname variable name or null 723 * @return string variable value or or array of variables 724 */ 725 public function getGlobal($varname = null) 726 { 727 if (isset($varname)) { 728 if (isset(self::$global_tpl_vars[$varname])) { 729 return self::$global_tpl_vars[$varname]->value; 730 } else { 731 return ''; 732 } 733 } else { 734 $_result = array(); 735 foreach (self::$global_tpl_vars AS $key => $var) { 736 $_result[$key] = $var->value; 737 } 738 return $_result; 739 } 740 } 741 742 /** 743 * Empty cache folder 744 * 745 * @param integer $exp_time expiration time 746 * @param string $type resource type 747 * @return integer number of cache files deleted 748 */ 749 function clearAllCache($exp_time = null, $type = null) 750 { 751 // load cache resource and call clearAll 752 $_cache_resource = Smarty_CacheResource::load($this, $type); 753 Smarty_CacheResource::invalidLoadedCache($this); 754 return $_cache_resource->clearAll($this, $exp_time); 755 } 756 757 /** 758 * Empty cache for a specific template 759 * 760 * @param string $template_name template name 761 * @param string $cache_id cache id 762 * @param string $compile_id compile id 763 * @param integer $exp_time expiration time 764 * @param string $type resource type 765 * @return integer number of cache files deleted 766 */ 767 public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) 768 { 769 // load cache resource and call clear 770 $_cache_resource = Smarty_CacheResource::load($this, $type); 771 Smarty_CacheResource::invalidLoadedCache($this); 772 return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time); 773 } 774 775 /** 776 * Loads security class and enables security 777 * 778 * @param string|Smarty_Security $security_class if a string is used, it must be class-name 779 * @return Smarty current Smarty instance for chaining 780 * @throws SmartyException when an invalid class name is provided 781 */ 782 public function enableSecurity($security_class = null) 783 { 784 if ($security_class instanceof Smarty_Security) { 785 $this->security_policy = $security_class; 786 return $this; 787 } elseif (is_object($security_class)) { 788 throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security."); 789 } 790 if ($security_class == null) { 791 $security_class = $this->security_class; 792 } 793 if (!class_exists($security_class)) { 794 throw new SmartyException("Security class '$security_class' is not defined"); 795 } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) { 796 throw new SmartyException("Class '$security_class' must extend Smarty_Security."); 797 } else { 798 $this->security_policy = new $security_class($this); 799 } 800 801 return $this; 802 } 803 804 /** 805 * Disable security 806 * @return Smarty current Smarty instance for chaining 807 */ 808 public function disableSecurity() 809 { 810 $this->security_policy = null; 811 812 return $this; 813 } 814 815 /** 816 * Set template directory 817 * 818 * @param string|array $template_dir directory(s) of template sources 819 * @return Smarty current Smarty instance for chaining 820 */ 821 public function setTemplateDir($template_dir) 822 { 823 $this->template_dir = array(); 824 foreach ((array) $template_dir as $k => $v) { 825 $this->template_dir[$k] = rtrim($v, '/\\') . DS; 826 } 827 828 $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); 829 return $this; 830 } 831 832 /** 833 * Add template directory(s) 834 * 835 * @param string|array $template_dir directory(s) of template sources 836 * @param string $key of the array element to assign the template dir to 837 * @return Smarty current Smarty instance for chaining 838 * @throws SmartyException when the given template directory is not valid 839 */ 840 public function addTemplateDir($template_dir, $key=null) 841 { 842 // make sure we're dealing with an array 843 $this->template_dir = (array) $this->template_dir; 844 845 if (is_array($template_dir)) { 846 foreach ($template_dir as $k => $v) { 847 if (is_int($k)) { 848 // indexes are not merged but appended 849 $this->template_dir[] = rtrim($v, '/\\') . DS; 850 } else { 851 // string indexes are overridden 852 $this->template_dir[$k] = rtrim($v, '/\\') . DS; 853 } 854 } 855 } elseif ($key !== null) { 856 // override directory at specified index 857 $this->template_dir[$key] = rtrim($template_dir, '/\\') . DS; 858 } else { 859 // append new directory 860 $this->template_dir[] = rtrim($template_dir, '/\\') . DS; 861 } 862 $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); 863 return $this; 864 } 865 866 /** 867 * Get template directories 868 * 869 * @param mixed index of directory to get, null to get all 870 * @return array|string list of template directories, or directory of $index 871 */ 872 public function getTemplateDir($index=null) 873 { 874 if ($index !== null) { 875 return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null; 876 } 877 878 return (array)$this->template_dir; 879 } 880 881 /** 882 * Set config directory 883 * 884 * @param string|array $template_dir directory(s) of configuration sources 885 * @return Smarty current Smarty instance for chaining 886 */ 887 public function setConfigDir($config_dir) 888 { 889 $this->config_dir = array(); 890 foreach ((array) $config_dir as $k => $v) { 891 $this->config_dir[$k] = rtrim($v, '/\\') . DS; 892 } 893 894 $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir); 895 return $this; 896 } 897 898 /** 899 * Add config directory(s) 900 * 901 * @param string|array $config_dir directory(s) of config sources 902 * @param string key of the array element to assign the config dir to 903 * @return Smarty current Smarty instance for chaining 904 */ 905 public function addConfigDir($config_dir, $key=null) 906 { 907 // make sure we're dealing with an array 908 $this->config_dir = (array) $this->config_dir; 909 910 if (is_array($config_dir)) { 911 foreach ($config_dir as $k => $v) { 912 if (is_int($k)) { 913 // indexes are not merged but appended 914 $this->config_dir[] = rtrim($v, '/\\') . DS; 915 } else { 916 // string indexes are overridden 917 $this->config_dir[$k] = rtrim($v, '/\\') . DS; 918 } 919 } 920 } elseif( $key !== null ) { 921 // override directory at specified index 922 $this->config_dir[$key] = rtrim($config_dir, '/\\') . DS; 923 } else { 924 // append new directory 925 $this->config_dir[] = rtrim($config_dir, '/\\') . DS; 926 } 927 928 $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir); 929 return $this; 930 } 931 932 /** 933 * Get config directory 934 * 935 * @param mixed index of directory to get, null to get all 936 * @return array|string configuration directory 937 */ 938 public function getConfigDir($index=null) 939 { 940 if ($index !== null) { 941 return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null; 942 } 943 944 return (array)$this->config_dir; 945 } 946 947 /** 948 * Set plugins directory 949 * 950 * @param string|array $plugins_dir directory(s) of plugins 951 * @return Smarty current Smarty instance for chaining 952 */ 953 public function setPluginsDir($plugins_dir) 954 { 955 $this->plugins_dir = array(); 956 foreach ((array)$plugins_dir as $k => $v) { 957 $this->plugins_dir[$k] = rtrim($v, '/\\') . DS; 958 } 959 960 return $this; 961 } 962 963 /** 964 * Adds directory of plugin files 965 * 966 * @param object $smarty 967 * @param string $ |array $ plugins folder 968 * @return Smarty current Smarty instance for chaining 969 */ 970 public function addPluginsDir($plugins_dir) 971 { 972 // make sure we're dealing with an array 973 $this->plugins_dir = (array) $this->plugins_dir; 974 975 if (is_array($plugins_dir)) { 976 foreach ($plugins_dir as $k => $v) { 977 if (is_int($k)) { 978 // indexes are not merged but appended 979 $this->plugins_dir[] = rtrim($v, '/\\') . DS; 980 } else { 981 // string indexes are overridden 982 $this->plugins_dir[$k] = rtrim($v, '/\\') . DS; 587 983 } 588 984 } 589 985 } else { 590 if ($tpl_var != '') 591 $this->_tpl_vars[$tpl_var] = $value; 592 } 593 } 594 595 /** 596 * assigns values to template variables by reference 597 * 598 * @param string $tpl_var the template variable name 599 * @param mixed $value the referenced value to assign 600 */ 601 function assign_by_ref($tpl_var, &$value) 602 { 603 if ($tpl_var != '') 604 $this->_tpl_vars[$tpl_var] = &$value; 605 } 606 607 /** 608 * appends values to template variables 609 * 610 * @param array|string $tpl_var the template variable name(s) 611 * @param mixed $value the value to append 612 */ 613 function append($tpl_var, $value=null, $merge=false) 614 { 615 if (is_array($tpl_var)) { 616 // $tpl_var is an array, ignore $value 617 foreach ($tpl_var as $_key => $_val) { 618 if ($_key != '') { 619 if(!@is_array($this->_tpl_vars[$_key])) { 620 settype($this->_tpl_vars[$_key],'array'); 986 // append new directory 987 $this->plugins_dir[] = rtrim($plugins_dir, '/\\') . DS; 988 } 989 990 $this->plugins_dir = array_unique($this->plugins_dir); 991 return $this; 992 } 993 994 /** 995 * Get plugin directories 996 * 997 * @return array list of plugin directories 998 */ 999 public function getPluginsDir() 1000 { 1001 return (array)$this->plugins_dir; 1002 } 1003 1004 /** 1005 * Set compile directory 1006 * 1007 * @param string $compile_dir directory to store compiled templates in 1008 * @return Smarty current Smarty instance for chaining 1009 */ 1010 public function setCompileDir($compile_dir) 1011 { 1012 $this->compile_dir = rtrim($compile_dir, '/\\') . DS; 1013 if (!isset(Smarty::$_muted_directories[$this->compile_dir])) { 1014 Smarty::$_muted_directories[$this->compile_dir] = null; 1015 } 1016 return $this; 1017 } 1018 1019 /** 1020 * Get compiled directory 1021 * 1022 * @return string path to compiled templates 1023 */ 1024 public function getCompileDir() 1025 { 1026 return $this->compile_dir; 1027 } 1028 1029 /** 1030 * Set cache directory 1031 * 1032 * @param string $cache_dir directory to store cached templates in 1033 * @return Smarty current Smarty instance for chaining 1034 */ 1035 public function setCacheDir($cache_dir) 1036 { 1037 $this->cache_dir = rtrim($cache_dir, '/\\') . DS; 1038 if (!isset(Smarty::$_muted_directories[$this->cache_dir])) { 1039 Smarty::$_muted_directories[$this->cache_dir] = null; 1040 } 1041 return $this; 1042 } 1043 1044 /** 1045 * Get cache directory 1046 * 1047 * @return string path of cache directory 1048 */ 1049 public function getCacheDir() 1050 { 1051 return $this->cache_dir; 1052 } 1053 1054 /** 1055 * Set default modifiers 1056 * 1057 * @param array|string $modifiers modifier or list of modifiers to set 1058 * @return Smarty current Smarty instance for chaining 1059 */ 1060 public function setDefaultModifiers($modifiers) 1061 { 1062 $this->default_modifiers = (array) $modifiers; 1063 return $this; 1064 } 1065 1066 /** 1067 * Add default modifiers 1068 * 1069 * @param array|string $modifiers modifier or list of modifiers to add 1070 * @return Smarty current Smarty instance for chaining 1071 */ 1072 public function addDefaultModifiers($modifiers) 1073 { 1074 if (is_array($modifiers)) { 1075 $this->default_modifiers = array_merge($this->default_modifiers, $modifiers); 1076 } else { 1077 $this->default_modifiers[] = $modifiers; 1078 } 1079 1080 return $this; 1081 } 1082 1083 /** 1084 * Get default modifiers 1085 * 1086 * @return array list of default modifiers 1087 */ 1088 public function getDefaultModifiers() 1089 { 1090 return $this->default_modifiers; 1091 } 1092 1093 1094 /** 1095 * Set autoload filters 1096 * 1097 * @param array $filters filters to load automatically 1098 * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types 1099 * @return Smarty current Smarty instance for chaining 1100 */ 1101 public function setAutoloadFilters($filters, $type=null) 1102 { 1103 if ($type !== null) { 1104 $this->autoload_filters[$type] = (array) $filters; 1105 } else { 1106 $this->autoload_filters = (array) $filters; 1107 } 1108 1109 return $this; 1110 } 1111 1112 /** 1113 * Add autoload filters 1114 * 1115 * @param array $filters filters to load automatically 1116 * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types 1117 * @return Smarty current Smarty instance for chaining 1118 */ 1119 public function addAutoloadFilters($filters, $type=null) 1120 { 1121 if ($type !== null) { 1122 if (!empty($this->autoload_filters[$type])) { 1123 $this->autoload_filters[$type] = array_merge($this->autoload_filters[$type], (array) $filters); 1124 } else { 1125 $this->autoload_filters[$type] = (array) $filters; 1126 } 1127 } else { 1128 foreach ((array) $filters as $key => $value) { 1129 if (!empty($this->autoload_filters[$key])) { 1130 $this->autoload_filters[$key] = array_merge($this->autoload_filters[$key], (array) $value); 1131 } else { 1132 $this->autoload_filters[$key] = (array) $value; 1133 } 1134 } 1135 } 1136 1137 return $this; 1138 } 1139 1140 /** 1141 * Get autoload filters 1142 * 1143 * @param string $type type of filter to get autoloads for. Defaults to all autoload filters 1144 * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified 1145 */ 1146 public function getAutoloadFilters($type=null) 1147 { 1148 if ($type !== null) { 1149 return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array(); 1150 } 1151 1152 return $this->autoload_filters; 1153 } 1154 1155 /** 1156 * return name of debugging template 1157 * 1158 * @return string 1159 */ 1160 public function getDebugTemplate() 1161 { 1162 return $this->debug_tpl; 1163 } 1164 1165 /** 1166 * set the debug template 1167 * 1168 * @param string $tpl_name 1169 * @return Smarty current Smarty instance for chaining 1170 * @throws SmartyException if file is not readable 1171 */ 1172 public function setDebugTemplate($tpl_name) 1173 { 1174 if (!is_readable($tpl_name)) { 1175 throw new SmartyException("Unknown file '{$tpl_name}'"); 1176 } 1177 $this->debug_tpl = $tpl_name; 1178 1179 return $this; 1180 } 1181 1182 /** 1183 * creates a template object 1184 * 1185 * @param string $template the resource handle of the template file 1186 * @param mixed $cache_id cache id to be used with this template 1187 * @param mixed $compile_id compile id to be used with this template 1188 * @param object $parent next higher level of Smarty variables 1189 * @param boolean $do_clone flag is Smarty object shall be cloned 1190 * @return object template object 1191 */ 1192 public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) 1193 { 1194 if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) { 1195 $parent = $cache_id; 1196 $cache_id = null; 1197 } 1198 if (!empty($parent) && is_array($parent)) { 1199 $data = $parent; 1200 $parent = null; 1201 } else { 1202 $data = null; 1203 } 1204 // default to cache_id and compile_id of Smarty object 1205 $cache_id = $cache_id === null ? $this->cache_id : $cache_id; 1206 $compile_id = $compile_id === null ? $this->compile_id : $compile_id; 1207 // already in template cache? 1208 if ($this->allow_ambiguous_resources) { 1209 $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id; 1210 } else { 1211 $_templateId = $this->joined_template_dir . '#' . $template . $cache_id . $compile_id; 1212 } 1213 if (isset($_templateId[150])) { 1214 $_templateId = sha1($_templateId); 1215 } 1216 if ($do_clone) { 1217 if (isset($this->template_objects[$_templateId])) { 1218 // return cached template object 1219 $tpl = clone $this->template_objects[$_templateId]; 1220 $tpl->smarty = clone $tpl->smarty; 1221 $tpl->parent = $parent; 1222 $tpl->tpl_vars = array(); 1223 $tpl->config_vars = array(); 1224 } else { 1225 $tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id); 1226 } 1227 } else { 1228 if (isset($this->template_objects[$_templateId])) { 1229 // return cached template object 1230 $tpl = $this->template_objects[$_templateId]; 1231 $tpl->parent = $parent; 1232 $tpl->tpl_vars = array(); 1233 $tpl->config_vars = array(); 1234 } else { 1235 $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id); 1236 } 1237 } 1238 // fill data if present 1239 if (!empty($data) && is_array($data)) { 1240 // set up variable values 1241 foreach ($data as $_key => $_val) { 1242 $tpl->tpl_vars[$_key] = new Smarty_variable($_val); 1243 } 1244 } 1245 return $tpl; 1246 } 1247 1248 1249 /** 1250 * Takes unknown classes and loads plugin files for them 1251 * class name format: Smarty_PluginType_PluginName 1252 * plugin filename format: plugintype.pluginname.php 1253 * 1254 * @param string $plugin_name class plugin name to load 1255 * @param bool $check check if already loaded 1256 * @return string |boolean filepath of loaded file or false 1257 */ 1258 public function loadPlugin($plugin_name, $check = true) 1259 { 1260 // if function or class exists, exit silently (already loaded) 1261 if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) { 1262 return true; 1263 } 1264 // Plugin name is expected to be: Smarty_[Type]_[Name] 1265 $_name_parts = explode('_', $plugin_name, 3); 1266 // class name must have three parts to be valid plugin 1267 // count($_name_parts) < 3 === !isset($_name_parts[2]) 1268 if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !== 'smarty') { 1269 throw new SmartyException("plugin {$plugin_name} is not a valid name format"); 1270 return false; 1271 } 1272 // if type is "internal", get plugin from sysplugins 1273 if (strtolower($_name_parts[1]) == 'internal') { 1274 $file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) . '.php'; 1275 if (file_exists($file)) { 1276 require_once($file); 1277 return $file; 1278 } else { 1279 return false; 1280 } 1281 } 1282 // plugin filename is expected to be: [type].[name].php 1283 $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php"; 1284 1285 $_stream_resolve_include_path = function_exists('stream_resolve_include_path'); 1286 1287 // loop through plugin dirs and find the plugin 1288 foreach($this->getPluginsDir() as $_plugin_dir) { 1289 $names = array( 1290 $_plugin_dir . $_plugin_filename, 1291 $_plugin_dir . strtolower($_plugin_filename), 1292 ); 1293 foreach ($names as $file) { 1294 if (file_exists($file)) { 1295 require_once($file); 1296 return $file; 1297 } 1298 if ($this->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) { 1299 // try PHP include_path 1300 if ($_stream_resolve_include_path) { 1301 $file = stream_resolve_include_path($file); 1302 } else { 1303 $file = Smarty_Internal_Get_Include_Path::getIncludePath($file); 621 1304 } 622 if($merge && is_array($_val)) { 623 foreach($_val as $_mkey => $_mval) { 624 $this->_tpl_vars[$_key][$_mkey] = $_mval; 625 } 626 } else { 627 $this->_tpl_vars[$_key][] = $_val; 1305 1306 if ($file !== false) { 1307 require_once($file); 1308 return $file; 628 1309 } 629 1310 } 630 1311 } 631 } else { 632 if ($tpl_var != '' && isset($value)) { 633 if(!@is_array($this->_tpl_vars[$tpl_var])) { 634 settype($this->_tpl_vars[$tpl_var],'array'); 1312 } 1313 // no plugin loaded 1314 return false; 1315 } 1316 1317 /** 1318 * Compile all template files 1319 * 1320 * @param string $extension file extension 1321 * @param bool $force_compile force all to recompile 1322 * @param int $time_limit 1323 * @param int $max_errors 1324 * @return integer number of template files recompiled 1325 */ 1326 public function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) 1327 { 1328 return Smarty_Internal_Utility::compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, $this); 1329 } 1330 1331 /** 1332 * Compile all config files 1333 * 1334 * @param string $extension file extension 1335 * @param bool $force_compile force all to recompile 1336 * @param int $time_limit 1337 * @param int $max_errors 1338 * @return integer number of template files recompiled 1339 */ 1340 public function compileAllConfig($extention = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null) 1341 { 1342 return Smarty_Internal_Utility::compileAllConfig($extention, $force_compile, $time_limit, $max_errors, $this); 1343 } 1344 1345 /** 1346 * Delete compiled template file 1347 * 1348 * @param string $resource_name template name 1349 * @param string $compile_id compile id 1350 * @param integer $exp_time expiration time 1351 * @return integer number of template files deleted 1352 */ 1353 public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) 1354 { 1355 return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this); 1356 } 1357 1358 1359 /** 1360 * Return array of tag/attributes of all tags used by an template 1361 * 1362 * @param object $templae template object 1363 * @return array of tag/attributes 1364 */ 1365 public function getTags(Smarty_Internal_Template $template) 1366 { 1367 return Smarty_Internal_Utility::getTags($template); 1368 } 1369 1370 /** 1371 * Run installation test 1372 * 1373 * @param array $errors Array to write errors into, rather than outputting them 1374 * @return boolean true if setup is fine, false if something is wrong 1375 */ 1376 public function testInstall(&$errors=null) 1377 { 1378 return Smarty_Internal_Utility::testInstall($this, $errors); 1379 } 1380 1381 /** 1382 * Error Handler to mute expected messages 1383 * 1384 * @link http://php.net/set_error_handler 1385 * @param integer $errno Error level 1386 * @return boolean 1387 */ 1388 public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) 1389 { 1390 $_is_muted_directory = false; 1391 1392 // add the SMARTY_DIR to the list of muted directories 1393 if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) { 1394 $smarty_dir = realpath(SMARTY_DIR); 1395 if ($smarty_dir !== false) { 1396 Smarty::$_muted_directories[SMARTY_DIR] = array( 1397 'file' => $smarty_dir, 1398 'length' => strlen($smarty_dir), 1399 ); 1400 } 1401 } 1402 1403 // walk the muted directories and test against $errfile 1404 foreach (Smarty::$_muted_directories as $key => &$dir) { 1405 if (!$dir) { 1406 // resolve directory and length for speedy comparisons 1407 $file = realpath($key); 1408 if ($file === false) { 1409 // this directory does not exist, remove and skip it 1410 unset(Smarty::$_muted_directories[$key]); 1411 continue; 635 1412 } 636 if($merge && is_array($value)) { 637 foreach($value as $_mkey => $_mval) { 638 $this->_tpl_vars[$tpl_var][$_mkey] = $_mval; 639 } 640 } else { 641 $this->_tpl_vars[$tpl_var][] = $value; 642 } 1413 $dir = array( 1414 'file' => $file, 1415 'length' => strlen($file), 1416 ); 643 1417 } 644 } 645 } 646 647 /** 648 * appends values to template variables by reference 649 * 650 * @param string $tpl_var the template variable name 651 * @param mixed $value the referenced value to append 652 */ 653 function append_by_ref($tpl_var, &$value, $merge=false) 654 { 655 if ($tpl_var != '' && isset($value)) { 656 if(!@is_array($this->_tpl_vars[$tpl_var])) { 657 settype($this->_tpl_vars[$tpl_var],'array'); 1418 if (!strncmp($errfile, $dir['file'], $dir['length'])) { 1419 $_is_muted_directory = true; 1420 break; 658 1421 } 659 if ($merge && is_array($value)) { 660 foreach($value as $_key => $_val) { 661 $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key]; 662 } 1422 } 1423 1424 // pass to next error handler if this error did not occur inside SMARTY_DIR 1425 // or the error was within smarty but masked to be ignored 1426 if (!$_is_muted_directory || ($errno && $errno & error_reporting())) { 1427 if (Smarty::$_previous_error_handler) { 1428 return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline, $errcontext); 663 1429 } else { 664 $this->_tpl_vars[$tpl_var][] = &$value;665 }666 }667 }668 669 670 /**671 * clear the given assigned template variable.672 *673 * @param string $tpl_var the template variable to clear674 */675 function clear_assign($tpl_var)676 {677 if (is_array($tpl_var))678 foreach ($tpl_var as $curr_var)679 unset($this->_tpl_vars[$curr_var]);680 else681 unset($this->_tpl_vars[$tpl_var]);682 }683 684 685 /**686 * Registers custom function to be used in templates687 *688 * @param string $function the name of the template function689 * @param string $function_impl the name of the PHP function to register690 */691 function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)692 {693 $this->_plugins['function'][$function] =694 array($function_impl, null, null, false, $cacheable, $cache_attrs);695 696 }697 698 /**699 * Unregisters custom function700 *701 * @param string $function name of template function702 */703 function unregister_function($function)704 {705 unset($this->_plugins['function'][$function]);706 }707 708 /**709 * Registers object to be used in templates710 *711 * @param string $object name of template object712 * @param object &$object_impl the referenced PHP object to register713 * @param null|array $allowed list of allowed methods (empty = all)714 * @param boolean $smarty_args smarty argument format, else traditional715 * @param null|array $block_functs list of methods that are block format716 */717 function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())718 {719 settype($allowed, 'array');720 settype($smarty_args, 'boolean');721 $this->_reg_objects[$object] =722 array(&$object_impl, $allowed, $smarty_args, $block_methods);723 }724 725 /**726 * Unregisters object727 *728 * @param string $object name of template object729 */730 function unregister_object($object)731 {732 unset($this->_reg_objects[$object]);733 }734 735 736 /**737 * Registers block function to be used in templates738 *739 * @param string $block name of template block740 * @param string $block_impl PHP function to register741 */742 function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)743 {744 $this->_plugins['block'][$block] =745 array($block_impl, null, null, false, $cacheable, $cache_attrs);746 }747 748 /**749 * Unregisters block function750 *751 * @param string $block name of template function752 */753 function unregister_block($block)754 {755 unset($this->_plugins['block'][$block]);756 }757 758 /**759 * Registers compiler function760 *761 * @param string $function name of template function762 * @param string $function_impl name of PHP function to register763 */764 function register_compiler_function($function, $function_impl, $cacheable=true)765 {766 $this->_plugins['compiler'][$function] =767 array($function_impl, null, null, false, $cacheable);768 }769 770 /**771 * Unregisters compiler function772 *773 * @param string $function name of template function774 */775 function unregister_compiler_function($function)776 {777 unset($this->_plugins['compiler'][$function]);778 }779 780 /**781 * Registers modifier to be used in templates782 *783 * @param string $modifier name of template modifier784 * @param string $modifier_impl name of PHP function to register785 */786 function register_modifier($modifier, $modifier_impl)787 {788 $this->_plugins['modifier'][$modifier] =789 array($modifier_impl, null, null, false);790 }791 792 /**793 * Unregisters modifier794 *795 * @param string $modifier name of template modifier796 */797 function unregister_modifier($modifier)798 {799 unset($this->_plugins['modifier'][$modifier]);800 }801 802 /**803 * Registers a resource to fetch a template804 *805 * @param string $type name of resource806 * @param array $functions array of functions to handle resource807 */808 function register_resource($type, $functions)809 {810 if (count($functions)==4) {811 $this->_plugins['resource'][$type] =812 array($functions, false);813 814 } elseif (count($functions)==5) {815 $this->_plugins['resource'][$type] =816 array(array(array(&$functions[0], $functions[1])817 ,array(&$functions[0], $functions[2])818 ,array(&$functions[0], $functions[3])819 ,array(&$functions[0], $functions[4]))820 ,false);821 822 } else {823 $this->trigger_error("malformed function-list for '$type' in register_resource");824 825 }826 }827 828 /**829 * Unregisters a resource830 *831 * @param string $type name of resource832 */833 function unregister_resource($type)834 {835 unset($this->_plugins['resource'][$type]);836 }837 838 /**839 * Registers a prefilter function to apply840 * to a template before compiling841 *842 * @param callback $function843 */844 function register_prefilter($function)845 {846 $this->_plugins['prefilter'][$this->_get_filter_name($function)]847 = array($function, null, null, false);848 }849 850 /**851 * Unregisters a prefilter function852 *853 * @param callback $function854 */855 function unregister_prefilter($function)856 {857 unset($this->_plugins['prefilter'][$this->_get_filter_name($function)]);858 }859 860 /**861 * Registers a postfilter function to apply862 * to a compiled template after compilation863 *864 * @param callback $function865 */866 function register_postfilter($function)867 {868 $this->_plugins['postfilter'][$this->_get_filter_name($function)]869 = array($function, null, null, false);870 }871 872 /**873 * Unregisters a postfilter function874 *875 * @param callback $function876 */877 function unregister_postfilter($function)878 {879 unset($this->_plugins['postfilter'][$this->_get_filter_name($function)]);880 }881 882 /**883 * Registers an output filter function to apply884 * to a template output885 *886 * @param callback $function887 */888 function register_outputfilter($function)889 {890 $this->_plugins['outputfilter'][$this->_get_filter_name($function)]891 = array($function, null, null, false);892 }893 894 /**895 * Unregisters an outputfilter function896 *897 * @param callback $function898 */899 function unregister_outputfilter($function)900 {901 unset($this->_plugins['outputfilter'][$this->_get_filter_name($function)]);902 }903 904 /**905 * load a filter of specified type and name906 *907 * @param string $type filter type908 * @param string $name filter name909 */910 function load_filter($type, $name)911 {912 switch ($type) {913 case 'output':914 $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false)));915 require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');916 smarty_core_load_plugins($_params, $this);917 break;918 919 case 'pre':920 case 'post':921 if (!isset($this->_plugins[$type . 'filter'][$name]))922 $this->_plugins[$type . 'filter'][$name] = false;923 break;924 }925 }926 927 /**928 * clear cached content for the given template and cache id929 *930 * @param string $tpl_file name of template file931 * @param string $cache_id name of cache_id932 * @param string $compile_id name of compile_id933 * @param string $exp_time expiration time934 * @return boolean935 */936 function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)937 {938 939 if (!isset($compile_id))940 $compile_id = $this->compile_id;941 942 if (!isset($tpl_file))943 $compile_id = null;944 945 $_auto_id = $this->_get_auto_id($cache_id, $compile_id);946 947 if (!empty($this->cache_handler_func)) {948 return call_user_func_array($this->cache_handler_func,949 array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time));950 } else {951 $_params = array('auto_base' => $this->cache_dir,952 'auto_source' => $tpl_file,953 'auto_id' => $_auto_id,954 'exp_time' => $exp_time);955 require_once(SMARTY_CORE_DIR . 'core.rm_auto.php');956 return smarty_core_rm_auto($_params, $this);957 }958 959 }960 961 962 /**963 * clear the entire contents of cache (all templates)964 *965 * @param string $exp_time expire time966 * @return boolean results of {@link smarty_core_rm_auto()}967 */968 function clear_all_cache($exp_time = null)969 {970 return $this->clear_cache(null, null, null, $exp_time);971 }972 973 974 /**975 * test to see if valid cache exists for this template976 *977 * @param string $tpl_file name of template file978 * @param string $cache_id979 * @param string $compile_id980 * @return string|false results of {@link _read_cache_file()}981 */982 function is_cached($tpl_file, $cache_id = null, $compile_id = null)983 {984 if (!$this->caching)985 return false;986 987 if (!isset($compile_id))988 $compile_id = $this->compile_id;989 990 $_params = array(991 'tpl_file' => $tpl_file,992 'cache_id' => $cache_id,993 'compile_id' => $compile_id994 );995 require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');996 return smarty_core_read_cache_file($_params, $this);997 }998 999 1000 /**1001 * clear all the assigned template variables.1002 *1003 */1004 function clear_all_assign()1005 {1006 $this->_tpl_vars = array();1007 }1008 1009 /**1010 * clears compiled version of specified template resource,1011 * or all compiled template files if one is not specified.1012 * This function is for advanced use only, not normally needed.1013 *1014 * @param string $tpl_file1015 * @param string $compile_id1016 * @param string $exp_time1017 * @return boolean results of {@link smarty_core_rm_auto()}1018 */1019 function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)1020 {1021 if (!isset($compile_id)) {1022 $compile_id = $this->compile_id;1023 }1024 $_params = array('auto_base' => $this->compile_dir,1025 'auto_source' => $tpl_file,1026 'auto_id' => $compile_id,1027 'exp_time' => $exp_time,1028 'extensions' => array('.inc', '.php'));1029 require_once(SMARTY_CORE_DIR . 'core.rm_auto.php');1030 return smarty_core_rm_auto($_params, $this);1031 }1032 1033 /**1034 * Checks whether requested template exists.1035 *1036 * @param string $tpl_file1037 * @return boolean1038 */1039 function template_exists($tpl_file)1040 {1041 $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false);1042 return $this->_fetch_resource_info($_params);1043 }1044 1045 /**1046 * Returns an array containing template variables1047 *1048 * @param string $name1049 * @param string $type1050 * @return array1051 */1052 function &get_template_vars($name=null)1053 {1054 if(!isset($name)) {1055 return $this->_tpl_vars;1056 } elseif(isset($this->_tpl_vars[$name])) {1057 return $this->_tpl_vars[$name];1058 } else {1059 // var non-existant, return valid reference1060 $_tmp = null;1061 return $_tmp;1062 }1063 }1064 1065 /**1066 * Returns an array containing config variables1067 *1068 * @param string $name1069 * @param string $type1070 * @return array1071 */1072 function &get_config_vars($name=null)1073 {1074 if(!isset($name) && is_array($this->_config[0])) {1075 return $this->_config[0]['vars'];1076 } else if(isset($this->_config[0]['vars'][$name])) {1077 return $this->_config[0]['vars'][$name];1078 } else {1079 // var non-existant, return valid reference1080 $_tmp = null;1081 return $_tmp;1082 }1083 }1084 1085 /**1086 * trigger Smarty error1087 *1088 * @param string $error_msg1089 * @param integer $error_type1090 */1091 function trigger_error($error_msg, $error_type = E_USER_WARNING)1092 {1093 trigger_error("Smarty error: $error_msg", $error_type);1094 }1095 1096 1097 /**1098 * executes & displays the template results1099 *1100 * @param string $resource_name1101 * @param string $cache_id1102 * @param string $compile_id1103 */1104 function display($resource_name, $cache_id = null, $compile_id = null)1105 {1106 $this->fetch($resource_name, $cache_id, $compile_id, true);1107 }1108 1109 /**1110 * executes & returns or displays the template results1111 *1112 * @param string $resource_name1113 * @param string $cache_id1114 * @param string $compile_id1115 * @param boolean $display1116 */1117 function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)1118 {1119 static $_cache_info = array();1120 1121 $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting)1122 ? $this->error_reporting : error_reporting() & ~E_NOTICE);1123 1124 if (!$this->debugging && $this->debugging_ctrl == 'URL') {1125 $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];1126 if (@strstr($_query_string, $this->_smarty_debug_id)) {1127 if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) {1128 // enable debugging for this browser session1129 @setcookie('SMARTY_DEBUG', true);1130 $this->debugging = true;1131 } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) {1132 // disable debugging for this browser session1133 @setcookie('SMARTY_DEBUG', false);1134 $this->debugging = false;1135 } else {1136 // enable debugging for this page1137 $this->debugging = true;1138 }1139 } else {1140 $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']);1141 }1142 }1143 1144 if ($this->debugging) {1145 // capture time for debugging info1146 $_params = array();1147 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');1148 $_debug_start_time = smarty_core_get_microtime($_params, $this);1149 $this->_smarty_debug_info[] = array('type' => 'template',1150 'filename' => $resource_name,1151 'depth' => 0);1152 $_included_tpls_idx = count($this->_smarty_debug_info) - 1;1153 }1154 1155 if (!isset($compile_id)) {1156 $compile_id = $this->compile_id;1157 }1158 1159 $this->_compile_id = $compile_id;1160 $this->_inclusion_depth = 0;1161 1162 if ($this->caching) {1163 // save old cache_info, initialize cache_info1164 array_push($_cache_info, $this->_cache_info);1165 $this->_cache_info = array();1166 $_params = array(1167 'tpl_file' => $resource_name,1168 'cache_id' => $cache_id,1169 'compile_id' => $compile_id,1170 'results' => null1171 );1172 require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');1173 if (smarty_core_read_cache_file($_params, $this)) {1174 $_smarty_results = $_params['results'];1175 if (!empty($this->_cache_info['insert_tags'])) {1176 $_params = array('plugins' => $this->_cache_info['insert_tags']);1177 require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');1178 smarty_core_load_plugins($_params, $this);1179 $_params = array('results' => $_smarty_results);1180 require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');1181 $_smarty_results = smarty_core_process_cached_inserts($_params, $this);1182 }1183 if (!empty($this->_cache_info['cache_serials'])) {1184 $_params = array('results' => $_smarty_results);1185 require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php');1186 $_smarty_results = smarty_core_process_compiled_include($_params, $this);1187 }1188 1189 1190 if ($display) {1191 if ($this->debugging)1192 {1193 // capture time for debugging info1194 $_params = array();1195 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');1196 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;1197 require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');1198 $_smarty_results .= smarty_core_display_debug_console($_params, $this);1199 }1200 if ($this->cache_modified_check) {1201 $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];1202 $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);1203 $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';1204 if (@count($this->_cache_info['insert_tags']) == 01205 && !$this->_cache_serials1206 && $_gmt_mtime == $_last_modified_date) {1207 if (php_sapi_name()=='cgi')1208 header('Status: 304 Not Modified');1209 else1210 header('HTTP/1.1 304 Not Modified');1211 1212 } else {1213 header('Last-Modified: '.$_gmt_mtime);1214 echo $_smarty_results;1215 }1216 } else {1217 echo $_smarty_results;1218 }1219 error_reporting($_smarty_old_error_level);1220 // restore initial cache_info1221 $this->_cache_info = array_pop($_cache_info);1222 return true;1223 } else {1224 error_reporting($_smarty_old_error_level);1225 // restore initial cache_info1226 $this->_cache_info = array_pop($_cache_info);1227 return $_smarty_results;1228 }1229 } else {1230 $this->_cache_info['template'][$resource_name] = true;1231 if ($this->cache_modified_check && $display) {1232 header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');1233 }1234 }1235 }1236 1237 // load filters that are marked as autoload1238 if (count($this->autoload_filters)) {1239 foreach ($this->autoload_filters as $_filter_type => $_filters) {1240 foreach ($_filters as $_filter) {1241 $this->load_filter($_filter_type, $_filter);1242 }1243 }1244 }1245 1246 $_smarty_compile_path = $this->_get_compile_path($resource_name);1247 1248 // if we just need to display the results, don't perform output1249 // buffering - for speed1250 $_cache_including = $this->_cache_including;1251 $this->_cache_including = false;1252 if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {1253 if ($this->_is_compiled($resource_name, $_smarty_compile_path)1254 || $this->_compile_resource($resource_name, $_smarty_compile_path))1255 {1256 include($_smarty_compile_path);1257 }1258 } else {1259 ob_start();1260 if ($this->_is_compiled($resource_name, $_smarty_compile_path)1261 || $this->_compile_resource($resource_name, $_smarty_compile_path))1262 {1263 include($_smarty_compile_path);1264 }1265 $_smarty_results = ob_get_contents();1266 ob_end_clean();1267 1268 foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) {1269 $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));1270 }1271 }1272 1273 if ($this->caching) {1274 $_params = array('tpl_file' => $resource_name,1275 'cache_id' => $cache_id,1276 'compile_id' => $compile_id,1277 'results' => $_smarty_results);1278 require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php');1279 smarty_core_write_cache_file($_params, $this);1280 require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');1281 $_smarty_results = smarty_core_process_cached_inserts($_params, $this);1282 1283 if ($this->_cache_serials) {1284 // strip nocache-tags from output1285 $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'1286 ,''1287 ,$_smarty_results);1288 }1289 // restore initial cache_info1290 $this->_cache_info = array_pop($_cache_info);1291 }1292 $this->_cache_including = $_cache_including;1293 1294 if ($display) {1295 if (isset($_smarty_results)) { echo $_smarty_results; }1296 if ($this->debugging) {1297 // capture time for debugging info1298 $_params = array();1299 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');1300 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);1301 require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');1302 echo smarty_core_display_debug_console($_params, $this);1303 }1304 error_reporting($_smarty_old_error_level);1305 return;1306 } else {1307 if ($this->debugging) {1308 // capture time for debugging info1309 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');1310 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime(array(), $this) - $_debug_start_time);1311 }1312 error_reporting($_smarty_old_error_level);1313 if (isset($_smarty_results)) { return $_smarty_results; }1314 }1315 }1316 1317 /**1318 * load configuration values1319 *1320 * @param string $file1321 * @param string $section1322 * @param string $scope1323 */1324 function config_load($file, $section = null, $scope = 'global')1325 {1326 require_once($this->_get_plugin_filepath('function', 'config_load'));1327 smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this);1328 }1329 1330 /**1331 * return a reference to a registered object1332 *1333 * @param string $name1334 * @return object1335 */1336 function &get_registered_object($name) {1337 if (!isset($this->_reg_objects[$name]))1338 $this->_trigger_fatal_error("'$name' is not a registered object");1339 1340 if (!is_object($this->_reg_objects[$name][0]))1341 $this->_trigger_fatal_error("registered '$name' is not an object");1342 1343 return $this->_reg_objects[$name][0];1344 }1345 1346 /**1347 * clear configuration values1348 *1349 * @param string $var1350 */1351 function clear_config($var = null)1352 {1353 if(!isset($var)) {1354 // clear all values1355 $this->_config = array(array('vars' => array(),1356 'files' => array()));1357 } else {1358 unset($this->_config[0]['vars'][$var]);1359 }1360 }1361 1362 /**1363 * get filepath of requested plugin1364 *1365 * @param string $type1366 * @param string $name1367 * @return string|false1368 */1369 function _get_plugin_filepath($type, $name)1370 {1371 $_params = array('type' => $type, 'name' => $name);1372 require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php');1373 return smarty_core_assemble_plugin_filepath($_params, $this);1374 }1375 1376 /**1377 * test if resource needs compiling1378 *1379 * @param string $resource_name1380 * @param string $compile_path1381 * @return boolean1382 */1383 function _is_compiled($resource_name, $compile_path)1384 {1385 if (!$this->force_compile && file_exists($compile_path)) {1386 if (!$this->compile_check) {1387 // no need to check compiled file1388 return true;1389 } else {1390 // get file source and timestamp1391 $_params = array('resource_name' => $resource_name, 'get_source'=>false);1392 if (!$this->_fetch_resource_info($_params)) {1393 return false;1394 }1395 if ($_params['resource_timestamp'] <= filemtime($compile_path)) {1396 // template not expired, no recompile1397 return true;1398 } else {1399 // compile template1400 return false;1401 }1402 }1403 } else {1404 // compiled template does not exist, or forced compile1405 return false;1406 }1407 }1408 1409 /**1410 * compile the template1411 *1412 * @param string $resource_name1413 * @param string $compile_path1414 * @return boolean1415 */1416 function _compile_resource($resource_name, $compile_path)1417 {1418 1419 $_params = array('resource_name' => $resource_name);1420 if (!$this->_fetch_resource_info($_params)) {1421 return false;1422 }1423 1424 $_source_content = $_params['source_content'];1425 $_cache_include = substr($compile_path, 0, -4).'.inc';1426 1427 if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) {1428 // if a _cache_serial was set, we also have to write an include-file:1429 if ($this->_cache_include_info) {1430 require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php');1431 smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this);1432 }1433 1434 $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content);1435 require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');1436 smarty_core_write_compiled_resource($_params, $this);1437 1438 return true;1439 } else {1440 return false;1441 }1442 1443 }1444 1445 /**1446 * compile the given source1447 *1448 * @param string $resource_name1449 * @param string $source_content1450 * @param string $compiled_content1451 * @return boolean1452 */1453 function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)1454 {1455 if (file_exists(SMARTY_DIR . $this->compiler_file)) {1456 require_once(SMARTY_DIR . $this->compiler_file);1457 } else {1458 // use include_path1459 require_once($this->compiler_file);1460 }1461 1462 1463 $smarty_compiler = new $this->compiler_class;1464 1465 $smarty_compiler->template_dir = $this->template_dir;1466 $smarty_compiler->compile_dir = $this->compile_dir;1467 $smarty_compiler->plugins_dir = $this->plugins_dir;1468 $smarty_compiler->config_dir = $this->config_dir;1469 $smarty_compiler->force_compile = $this->force_compile;1470 $smarty_compiler->caching = $this->caching;1471 $smarty_compiler->php_handling = $this->php_handling;1472 $smarty_compiler->left_delimiter = $this->left_delimiter;1473 $smarty_compiler->right_delimiter = $this->right_delimiter;1474 $smarty_compiler->_version = $this->_version;1475 $smarty_compiler->security = $this->security;1476 $smarty_compiler->secure_dir = $this->secure_dir;1477 $smarty_compiler->security_settings = $this->security_settings;1478 $smarty_compiler->trusted_dir = $this->trusted_dir;1479 $smarty_compiler->use_sub_dirs = $this->use_sub_dirs;1480 $smarty_compiler->_reg_objects = &$this->_reg_objects;1481 $smarty_compiler->_plugins = &$this->_plugins;1482 $smarty_compiler->_tpl_vars = &$this->_tpl_vars;1483 $smarty_compiler->default_modifiers = $this->default_modifiers;1484 $smarty_compiler->compile_id = $this->_compile_id;1485 $smarty_compiler->_config = $this->_config;1486 $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals;1487 1488 if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) {1489 $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path];1490 }1491 $smarty_compiler->_cache_include = $cache_include_path;1492 1493 1494 $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);1495 1496 if ($smarty_compiler->_cache_serial) {1497 $this->_cache_include_info = array(1498 'cache_serial'=>$smarty_compiler->_cache_serial1499 ,'plugins_code'=>$smarty_compiler->_plugins_code1500 ,'include_file_path' => $cache_include_path);1501 1502 } else {1503 $this->_cache_include_info = null;1504 1505 }1506 1507 return $_results;1508 }1509 1510 /**1511 * Get the compile path for this resource1512 *1513 * @param string $resource_name1514 * @return string results of {@link _get_auto_filename()}1515 */1516 function _get_compile_path($resource_name)1517 {1518 return $this->_get_auto_filename($this->compile_dir, $resource_name,1519 $this->_compile_id) . '.php';1520 }1521 1522 /**1523 * fetch the template info. Gets timestamp, and source1524 * if get_source is true1525 *1526 * sets $source_content to the source of the template, and1527 * $resource_timestamp to its time stamp1528 * @param string $resource_name1529 * @param string $source_content1530 * @param integer $resource_timestamp1531 * @param boolean $get_source1532 * @param boolean $quiet1533 * @return boolean1534 */1535 1536 function _fetch_resource_info(&$params)1537 {1538 if(!isset($params['get_source'])) { $params['get_source'] = true; }1539 if(!isset($params['quiet'])) { $params['quiet'] = false; }1540 1541 $_return = false;1542 $_params = array('resource_name' => $params['resource_name']) ;1543 if (isset($params['resource_base_path']))1544 $_params['resource_base_path'] = $params['resource_base_path'];1545 else1546 $_params['resource_base_path'] = $this->template_dir;1547 1548 if ($this->_parse_resource_name($_params)) {1549 $_resource_type = $_params['resource_type'];1550 $_resource_name = $_params['resource_name'];1551 switch ($_resource_type) {1552 case 'file':1553 if ($params['get_source']) {1554 $params['source_content'] = $this->_read_file($_resource_name);1555 }1556 $params['resource_timestamp'] = filemtime($_resource_name);1557 $_return = is_file($_resource_name) && is_readable($_resource_name);1558 break;1559 1560 default:1561 // call resource functions to fetch the template source and timestamp1562 if ($params['get_source']) {1563 $_source_return = isset($this->_plugins['resource'][$_resource_type]) &&1564 call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],1565 array($_resource_name, &$params['source_content'], &$this));1566 } else {1567 $_source_return = true;1568 }1569 1570 $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) &&1571 call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],1572 array($_resource_name, &$params['resource_timestamp'], &$this));1573 1574 $_return = $_source_return && $_timestamp_return;1575 break;1576 }1577 }1578 1579 if (!$_return) {1580 // see if we can get a template with the default template handler1581 if (!empty($this->default_template_handler_func)) {1582 if (!is_callable($this->default_template_handler_func)) {1583 $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");1584 } else {1585 $_return = call_user_func_array(1586 $this->default_template_handler_func,1587 array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));1588 }1589 }1590 }1591 1592 if (!$_return) {1593 if (!$params['quiet']) {1594 $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');1595 }1596 } else if ($_return && $this->security) {1597 require_once(SMARTY_CORE_DIR . 'core.is_secure.php');1598 if (!smarty_core_is_secure($_params, $this)) {1599 if (!$params['quiet'])1600 $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');1601 $params['source_content'] = null;1602 $params['resource_timestamp'] = null;1603 1430 return false; 1604 1431 } 1605 1432 } 1606 return $_return; 1607 } 1608 1609 1610 /** 1611 * parse out the type and name from the resource 1612 * 1613 * @param string $resource_base_path 1614 * @param string $resource_name 1615 * @param string $resource_type 1616 * @param string $resource_name 1617 * @return boolean 1618 */ 1619 1620 function _parse_resource_name(&$params) 1621 { 1622 1623 // split tpl_path by the first colon 1624 $_resource_name_parts = explode(':', $params['resource_name'], 2); 1625 1626 if (count($_resource_name_parts) == 1) { 1627 // no resource type given 1628 $params['resource_type'] = $this->default_resource_type; 1629 $params['resource_name'] = $_resource_name_parts[0]; 1630 } else { 1631 if(strlen($_resource_name_parts[0]) == 1) { 1632 // 1 char is not resource type, but part of filepath 1633 $params['resource_type'] = $this->default_resource_type; 1634 $params['resource_name'] = $params['resource_name']; 1635 } else { 1636 $params['resource_type'] = $_resource_name_parts[0]; 1637 $params['resource_name'] = $_resource_name_parts[1]; 1638 } 1639 } 1640 1641 if ($params['resource_type'] == 'file') { 1642 if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) { 1643 // relative pathname to $params['resource_base_path'] 1644 // use the first directory where the file is found 1645 foreach ((array)$params['resource_base_path'] as $_curr_path) { 1646 $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name']; 1647 if (file_exists($_fullpath) && is_file($_fullpath)) { 1648 $params['resource_name'] = $_fullpath; 1649 return true; 1650 } 1651 // didn't find the file, try include_path 1652 $_params = array('file_path' => $_fullpath); 1653 require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); 1654 if(smarty_core_get_include_path($_params, $this)) { 1655 $params['resource_name'] = $_params['new_file_path']; 1656 return true; 1657 } 1658 } 1659 return false; 1660 } else { 1661 /* absolute path */ 1662 return file_exists($params['resource_name']); 1663 } 1664 } elseif (empty($this->_plugins['resource'][$params['resource_type']])) { 1665 $_params = array('type' => $params['resource_type']); 1666 require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php'); 1667 smarty_core_load_resource_plugin($_params, $this); 1668 } 1669 1670 return true; 1671 } 1672 1673 1674 /** 1675 * Handle modifiers 1676 * 1677 * @param string|null $modifier_name 1678 * @param array|null $map_array 1679 * @return string result of modifiers 1680 */ 1681 function _run_mod_handler() 1682 { 1683 $_args = func_get_args(); 1684 list($_modifier_name, $_map_array) = array_splice($_args, 0, 2); 1685 list($_func_name, $_tpl_file, $_tpl_line) = 1686 $this->_plugins['modifier'][$_modifier_name]; 1687 1688 $_var = $_args[0]; 1689 foreach ($_var as $_key => $_val) { 1690 $_args[0] = $_val; 1691 $_var[$_key] = call_user_func_array($_func_name, $_args); 1692 } 1693 return $_var; 1694 } 1695 1696 /** 1697 * Remove starting and ending quotes from the string 1698 * 1699 * @param string $string 1700 * @return string 1701 */ 1702 function _dequote($string) 1703 { 1704 if ((substr($string, 0, 1) == "'" || substr($string, 0, 1) == '"') && 1705 substr($string, -1) == substr($string, 0, 1)) 1706 return substr($string, 1, -1); 1707 else 1708 return $string; 1709 } 1710 1711 1712 /** 1713 * read in a file 1714 * 1715 * @param string $filename 1716 * @return string 1717 */ 1718 function _read_file($filename) 1719 { 1720 if ( file_exists($filename) && is_readable($filename) && ($fd = @fopen($filename, 'rb')) ) { 1721 $contents = ''; 1722 while (!feof($fd)) { 1723 $contents .= fread($fd, 8192); 1724 } 1725 fclose($fd); 1726 return $contents; 1727 } else { 1728 return false; 1729 } 1730 } 1731 1732 /** 1733 * get a concrete filename for automagically created content 1734 * 1735 * @param string $auto_base 1736 * @param string $auto_source 1737 * @param string $auto_id 1738 * @return string 1739 * @staticvar string|null 1740 * @staticvar string|null 1741 */ 1742 function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) 1743 { 1744 $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; 1745 $_return = $auto_base . DIRECTORY_SEPARATOR; 1746 1747 if(isset($auto_id)) { 1748 // make auto_id safe for directory names 1749 $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id))); 1750 // split into separate directories 1751 $_return .= $auto_id . $_compile_dir_sep; 1752 } 1753 1754 if(isset($auto_source)) { 1755 // make source name safe for filename 1756 $_filename = urlencode(basename($auto_source)); 1757 $_crc32 = sprintf('%08X', crc32($auto_source)); 1758 // prepend %% to avoid name conflicts with 1759 // with $params['auto_id'] names 1760 $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep . 1761 substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32; 1762 $_return .= '%%' . $_crc32 . '%%' . $_filename; 1763 } 1764 1765 return $_return; 1766 } 1767 1768 /** 1769 * unlink a file, possibly using expiration time 1770 * 1771 * @param string $resource 1772 * @param integer $exp_time 1773 */ 1774 function _unlink($resource, $exp_time = null) 1775 { 1776 if(isset($exp_time)) { 1777 if(time() - @filemtime($resource) >= $exp_time) { 1778 return @unlink($resource); 1779 } 1780 } else { 1781 return @unlink($resource); 1782 } 1783 } 1784 1785 /** 1786 * returns an auto_id for auto-file-functions 1787 * 1788 * @param string $cache_id 1789 * @param string $compile_id 1790 * @return string|null 1791 */ 1792 function _get_auto_id($cache_id=null, $compile_id=null) { 1793 if (isset($cache_id)) 1794 return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; 1795 elseif(isset($compile_id)) 1796 return $compile_id; 1797 else 1798 return null; 1799 } 1800 1801 /** 1802 * trigger Smarty plugin error 1803 * 1804 * @param string $error_msg 1805 * @param string $tpl_file 1806 * @param integer $tpl_line 1807 * @param string $file 1808 * @param integer $line 1809 * @param integer $error_type 1810 */ 1811 function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null, 1812 $file = null, $line = null, $error_type = E_USER_ERROR) 1813 { 1814 if(isset($file) && isset($line)) { 1815 $info = ' ('.basename($file).", line $line)"; 1816 } else { 1817 $info = ''; 1818 } 1819 if (isset($tpl_line) && isset($tpl_file)) { 1820 $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type); 1821 } else { 1822 $this->trigger_error($error_msg . $info, $error_type); 1823 } 1824 } 1825 1826 1827 /** 1828 * callback function for preg_replace, to call a non-cacheable block 1829 * @return string 1830 */ 1831 function _process_compiled_include_callback($match) { 1832 $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3]; 1833 ob_start(); 1834 $_func($this); 1835 $_ret = ob_get_contents(); 1836 ob_end_clean(); 1837 return $_ret; 1838 } 1839 1840 1841 /** 1842 * called for included templates 1843 * 1844 * @param string $_smarty_include_tpl_file 1845 * @param string $_smarty_include_vars 1846 */ 1847 1848 // $_smarty_include_tpl_file, $_smarty_include_vars 1849 1850 function _smarty_include($params) 1851 { 1852 if ($this->debugging) { 1853 $_params = array(); 1854 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 1855 $debug_start_time = smarty_core_get_microtime($_params, $this); 1856 $this->_smarty_debug_info[] = array('type' => 'template', 1857 'filename' => $params['smarty_include_tpl_file'], 1858 'depth' => ++$this->_inclusion_depth); 1859 $included_tpls_idx = count($this->_smarty_debug_info) - 1; 1860 } 1861 1862 $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']); 1863 1864 // config vars are treated as local, so push a copy of the 1865 // current ones onto the front of the stack 1866 array_unshift($this->_config, $this->_config[0]); 1867 1868 $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']); 1869 1870 1871 if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) 1872 || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) 1873 { 1874 include($_smarty_compile_path); 1875 } 1876 1877 // pop the local vars off the front of the stack 1878 array_shift($this->_config); 1879 1880 $this->_inclusion_depth--; 1881 1882 if ($this->debugging) { 1883 // capture time for debugging info 1884 $_params = array(); 1885 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 1886 $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; 1887 } 1888 1889 if ($this->caching) { 1890 $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; 1891 } 1892 } 1893 1894 1895 /** 1896 * get or set an array of cached attributes for function that is 1897 * not cacheable 1898 * @return array 1899 */ 1900 function &_smarty_cache_attrs($cache_serial, $count) { 1901 $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count]; 1902 1903 if ($this->_cache_including) { 1904 /* return next set of cache_attrs */ 1905 $_return = current($_cache_attrs); 1906 next($_cache_attrs); 1907 return $_return; 1908 1909 } else { 1910 /* add a reference to a new set of cache_attrs */ 1911 $_cache_attrs[] = array(); 1912 return $_cache_attrs[count($_cache_attrs)-1]; 1913 1914 } 1915 1916 } 1917 1918 1919 /** 1920 * wrapper for include() retaining $this 1921 * @return mixed 1922 */ 1923 function _include($filename, $once=false, $params=null) 1924 { 1925 if ($once) { 1926 return include_once($filename); 1927 } else { 1928 return include($filename); 1929 } 1930 } 1931 1932 1933 /** 1934 * wrapper for eval() retaining $this 1935 * @return mixed 1936 */ 1937 function _eval($code, $params=null) 1938 { 1939 return eval($code); 1940 } 1941 1942 /** 1943 * Extracts the filter name from the given callback 1944 * 1945 * @param callback $function 1946 * @return string 1947 */ 1948 function _get_filter_name($function) 1949 { 1950 if (is_array($function)) { 1951 $_class_name = (is_object($function[0]) ? 1952 get_class($function[0]) : $function[0]); 1953 return $_class_name . '_' . $function[1]; 1954 } 1955 else { 1956 return $function; 1957 } 1958 } 1959 1960 /**#@-*/ 1961 1433 } 1434 1435 /** 1436 * Enable error handler to mute expected messages 1437 * 1438 * @return void 1439 */ 1440 public static function muteExpectedErrors() 1441 { 1442 /* 1443 error muting is done because some people implemented custom error_handlers using 1444 http://php.net/set_error_handler and for some reason did not understand the following paragraph: 1445 1446 It is important to remember that the standard PHP error handler is completely bypassed for the 1447 error types specified by error_types unless the callback function returns FALSE. 1448 error_reporting() settings will have no effect and your error handler will be called regardless - 1449 however you are still able to read the current value of error_reporting and act appropriately. 1450 Of particular note is that this value will be 0 if the statement that caused the error was 1451 prepended by the @ error-control operator. 1452 1453 Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include 1454 - @filemtime() is almost twice as fast as using an additional file_exists() 1455 - between file_exists() and filemtime() a possible race condition is opened, 1456 which does not exist using the simple @filemtime() approach. 1457 */ 1458 $error_handler = array('Smarty', 'mutingErrorHandler'); 1459 $previous = set_error_handler($error_handler); 1460 1461 // avoid dead loops 1462 if ($previous !== $error_handler) { 1463 Smarty::$_previous_error_handler = $previous; 1464 } 1465 } 1466 1467 /** 1468 * Disable error handler muting expected messages 1469 * 1470 * @return void 1471 */ 1472 public static function unmuteExpectedErrors() 1473 { 1474 restore_error_handler(); 1475 } 1962 1476 } 1963 1477 1964 /* vim: set expandtab: */ 1478 // Check if we're running on windows 1479 Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; 1480 1481 // let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8 1482 if (Smarty::$_CHARSET !== 'UTF-8') { 1483 Smarty::$_UTF8_MODIFIER = ''; 1484 } 1485 1486 /** 1487 * Smarty exception class 1488 * @package Smarty 1489 */ 1490 class SmartyException extends Exception { 1491 public static $escape = true; 1492 public function __construct($message) { 1493 $this->message = self::$escape ? htmlentities($message) : $message; 1494 } 1495 } 1496 1497 /** 1498 * Smarty compiler exception class 1499 * @package Smarty 1500 */ 1501 class SmartyCompilerException extends SmartyException { 1502 } 1503 1504 /** 1505 * Autoloader 1506 */ 1507 function smartyAutoload($class) 1508 { 1509 $_class = strtolower($class); 1510 $_classes = array( 1511 'smarty_config_source' => true, 1512 'smarty_config_compiled' => true, 1513 'smarty_security' => true, 1514 'smarty_cacheresource' => true, 1515 'smarty_cacheresource_custom' => true, 1516 'smarty_cacheresource_keyvaluestore' => true, 1517 'smarty_resource' => true, 1518 'smarty_resource_custom' => true, 1519 'smarty_resource_uncompiled' => true, 1520 'smarty_resource_recompiled' => true, 1521 ); 1522 1523 if (!strncmp($_class, 'smarty_internal_', 16) || isset($_classes[$_class])) { 1524 include SMARTY_SYSPLUGINS_DIR . $_class . '.php'; 1525 } 1526 } 1965 1527 1966 1528 ?> -
trunk/include/smarty/libs/debug.tpl
r3282 r23384 1 {* Smarty *} 2 {* debug.tpl, last updated version 2.1.0 *} 3 {assign_debug_info} 4 {capture assign=debug_output} 1 {capture name='_smarty_debug' assign=debug_output} 5 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 6 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 7 4 <head> 8 5 <title>Smarty Debug Console</title> 6 <style type="text/css"> 9 7 {literal} 10 <style type="text/css">11 /* <![CDATA[ */12 8 body, h1, h2, td, th, p { 13 9 font-family: sans-serif; … … 86 82 color: maroon; 87 83 } 88 /* ]]> */ 84 {/literal} 89 85 </style> 90 {/literal}91 86 </head> 92 87 <body> 93 88 94 <h1>Smarty Debug Console </h1>89 <h1>Smarty Debug Console - {if isset($template_name)}{$template_name|debug_print_var nofilter}{else}Total Time {$execution_time|string_format:"%.5f"}{/if}</h1> 95 90 91 {if !empty($template_data)} 96 92 <h2>included templates & config files (load time in seconds)</h2> 97 93 98 94 <div> 99 {section name=templates loop=$_debug_tpls} 100 {section name=indent loop=$_debug_tpls[templates].depth} {/section} 101 <font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}> 102 {$_debug_tpls[templates].filename|escape:html}</font> 103 {if isset($_debug_tpls[templates].exec_time)} 104 <span class="exectime"> 105 ({$_debug_tpls[templates].exec_time|string_format:"%.5f"}) 106 {if %templates.index% eq 0}(total){/if} 107 </span> 108 {/if} 109 <br /> 110 {sectionelse} 111 <p>no templates included</p> 112 {/section} 95 {foreach $template_data as $template} 96 <font color=brown>{$template.name}</font> 97 <span class="exectime"> 98 (compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}) 99 </span> 100 <br> 101 {/foreach} 113 102 </div> 103 {/if} 114 104 115 105 <h2>assigned template variables</h2> 116 106 117 107 <table id="table_assigned_vars"> 118 {section name=vars loop=$_debug_keys} 119 <tr class="{cycle values="odd,even"}"> 120 <th>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}</th> 121 <td>{$_debug_vals[vars]|@debug_print_var}</td></tr> 122 {sectionelse} 123 <tr><td><p>no template variables assigned</p></td></tr> 124 {/section} 108 {foreach $assigned_vars as $vars} 109 <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> 110 <th>${$vars@key|escape:'html'}</th> 111 <td>{$vars|debug_print_var nofilter}</td></tr> 112 {/foreach} 125 113 </table> 126 114 … … 128 116 129 117 <table id="table_config_vars"> 130 {section name=config_vars loop=$_debug_config_keys} 131 <tr class="{cycle values="odd,even"}"> 132 <th>{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}</th> 133 <td>{$_debug_config_vals[config_vars]|@debug_print_var}</td></tr> 134 {sectionelse} 135 <tr><td><p>no config vars assigned</p></td></tr> 136 {/section} 118 {foreach $config_vars as $vars} 119 <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> 120 <th>{$vars@key|escape:'html'}</th> 121 <td>{$vars|debug_print_var nofilter}</td></tr> 122 {/foreach} 123 137 124 </table> 138 125 </body> 139 126 </html> 140 127 {/capture} 141 {if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"}142 {$debug_output}143 {else}144 128 <script type="text/javascript"> 145 // <![CDATA[ 146 if ( self.name == '' ) {ldelim} 147 var title = 'Console'; 148 {rdelim} 149 else {ldelim} 150 var title = 'Console_' + self.name; 151 {rdelim} 152 _smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes"); 153 _smarty_console.document.write('{$debug_output|escape:'javascript'}'); 129 {$id = $template_name|default:''|md5} 130 _smarty_console = window.open("","console{$id}","width=680,height=600,resizable,scrollbars=yes"); 131 _smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}"); 154 132 _smarty_console.document.close(); 155 // ]]>156 133 </script> 157 {/if} -
trunk/include/smarty/libs/plugins/block.textformat.php
r3282 r23384 1 1 <?php 2 2 /** 3 * Smarty plugin 3 * Smarty plugin to format text blocks 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsBlock 6 7 */ 7 8 … … 13 14 * Purpose: format text a certain way with preset styles 14 15 * or custom wrap/indent settings<br> 15 * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat} 16 * Params: 17 * <pre> 18 * - style - string (email) 19 * - indent - integer (0) 20 * - wrap - integer (80) 21 * - wrap_char - string ("\n") 22 * - indent_char - string (" ") 23 * - wrap_boundary - boolean (true) 24 * </pre> 25 * 26 * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} 16 27 * (Smarty online manual) 17 * @param array 18 * <pre> 19 * Params: style: string (email) 20 * indent: integer (0) 21 * wrap: integer (80) 22 * wrap_char string ("\n") 23 * indent_char: string (" ") 24 * wrap_boundary: boolean (true) 25 * </pre> 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 * @return string content re-formatted 26 33 * @author Monte Ohrt <monte at ohrt dot com> 27 * @param string contents of the block28 * @param Smarty clever simulation of a method29 * @return string string $content re-formatted30 34 */ 31 function smarty_block_textformat($params, $content, &$smarty)35 function smarty_block_textformat($params, $content, $template, &$repeat) 32 36 { 33 37 if (is_null($content)) { … … 43 47 $wrap_cut = false; 44 48 $assign = null; 45 49 46 50 foreach ($params as $_key => $_val) { 47 51 switch ($_key) { … … 64 68 65 69 default: 66 $smarty->trigger_error("textformat: unknown attribute '$_key'");70 trigger_error("textformat: unknown attribute '$_key'"); 67 71 } 68 72 } … … 71 75 $wrap = 72; 72 76 } 73 74 77 // split into paragraphs 75 $_paragraphs = preg_split('![\r\n] [\r\n]!',$content);78 $_paragraphs = preg_split('![\r\n]{2}!', $content); 76 79 $_output = ''; 77 80 78 for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) { 79 if ($_paragraphs[$_x] == '') { 81 82 foreach ($_paragraphs as &$_paragraph) { 83 if (!$_paragraph) { 80 84 continue; 81 85 } 82 86 // convert mult. spaces & special chars to single space 83 $_paragraph s[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);87 $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph); 84 88 // indent first line 85 if ($indent_first > 0) {86 $_paragraph s[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];89 if ($indent_first > 0) { 90 $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; 87 91 } 88 92 // wordwrap sentences 89 $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); 93 if (Smarty::$_MBSTRING) { 94 require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); 95 $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); 96 } else { 97 $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); 98 } 90 99 // indent lines 91 if ($indent > 0) {92 $_paragraph s[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);100 if ($indent > 0) { 101 $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph); 93 102 } 94 103 } 95 104 $_output = implode($wrap_char . $wrap_char, $_paragraphs); 96 97 return $assign ? $smarty->assign($assign, $_output) : $_output; 98 105 106 if ($assign) { 107 $template->assign($assign, $_output); 108 } else { 109 return $_output; 110 } 99 111 } 100 112 101 /* vim: set expandtab: */102 103 113 ?> -
trunk/include/smarty/libs/plugins/function.counter.php
r3282 r23384 3 3 * Smarty plugin 4 4 * @package Smarty 5 * @subpackage plugins5 * @subpackage PluginsFunction 6 6 */ 7 8 7 9 8 /** … … 13 12 * Name: counter<br> 14 13 * Purpose: print out a counter value 14 * 15 15 * @author Monte Ohrt <monte at ohrt dot com> 16 * @link http:// smarty.php.net/manual/en/language.function.counter.php {counter}16 * @link http://www.smarty.net/manual/en/language.function.counter.php {counter} 17 17 * (Smarty online manual) 18 * @param array parameters19 * @param Smarty 18 * @param array $params parameters 19 * @param Smarty_Internal_Template $template template object 20 20 * @return string|null 21 21 */ 22 function smarty_function_counter($params, &$smarty)22 function smarty_function_counter($params, $template) 23 23 { 24 24 static $counters = array(); … … 44 44 45 45 if (isset($counter['assign'])) { 46 $ smarty->assign($counter['assign'], $counter['count']);46 $template->assign($counter['assign'], $counter['count']); 47 47 } 48 48 … … 76 76 } 77 77 78 /* vim: set expandtab: */79 80 78 ?> -
trunk/include/smarty/libs/plugins/function.cycle.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 … … 13 14 * Date: May 3, 2002<br> 14 15 * Purpose: cycle through given values<br> 15 * Input: 16 * - name = name of cycle (optional) 17 * - values = comma separated list of values to cycle, 18 * 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 25 * printed. 26 * 16 * Params: 17 * <pre> 18 * - name - name of cycle (optional) 19 * - values - comma separated list of values to cycle, or an array of values to cycle 20 * (this can be left out for subsequent calls) 21 * - reset - boolean - resets given var to true 22 * - print - boolean - print var or not. default is true 23 * - advance - boolean - whether or not to advance the cycle 24 * - delimiter - the value delimiter, default is "," 25 * - assign - boolean, assigns to template var instead of printed. 26 * </pre> 27 27 * Examples:<br> 28 28 * <pre> … … 31 31 * {cycle name=row} 32 32 * </pre> 33 * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle} 33 * 34 * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} 34 35 * (Smarty online manual) 35 36 * @author Monte Ohrt <monte at ohrt dot com> … … 38 39 * @author credit to Jason Sweat <jsweat_php@yahoo.com> 39 40 * @version 1.3 40 * @param array 41 * @param Smarty 41 * @param array $params parameters 42 * @param Smarty_Internal_Template $template template object 42 43 * @return string|null 43 44 */ 44 function smarty_function_cycle($params, &$smarty) 45 46 function smarty_function_cycle($params, $template) 45 47 { 46 48 static $cycle_vars; 47 49 48 50 $name = (empty($params['name'])) ? 'default' : $params['name']; 49 51 $print = (isset($params['print'])) ? (bool)$params['print'] : true; 50 52 $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; 51 53 $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; 52 53 if (!i n_array('values', array_keys($params))) {54 55 if (!isset($params['values'])) { 54 56 if(!isset($cycle_vars[$name]['values'])) { 55 $smarty->trigger_error("cycle: missing 'values' parameter");57 trigger_error("cycle: missing 'values' parameter"); 56 58 return; 57 59 } … … 64 66 } 65 67 66 $cycle_vars[$name]['delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : ','; 67 68 if (isset($params['delimiter'])) { 69 $cycle_vars[$name]['delimiter'] = $params['delimiter']; 70 } elseif (!isset($cycle_vars[$name]['delimiter'])) { 71 $cycle_vars[$name]['delimiter'] = ','; 72 } 73 68 74 if(is_array($cycle_vars[$name]['values'])) { 69 75 $cycle_array = $cycle_vars[$name]['values']; … … 71 77 $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']); 72 78 } 73 79 74 80 if(!isset($cycle_vars[$name]['index']) || $reset ) { 75 81 $cycle_vars[$name]['index'] = 0; 76 82 } 77 83 78 84 if (isset($params['assign'])) { 79 85 $print = false; 80 $ smarty->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);86 $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); 81 87 } 82 88 83 89 if($print) { 84 90 $retval = $cycle_array[$cycle_vars[$name]['index']]; … … 94 100 } 95 101 } 96 102 97 103 return $retval; 98 104 } 99 105 100 /* vim: set expandtab: */101 102 106 ?> -
trunk/include/smarty/libs/plugins/function.fetch.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 8 9 9 /** … … 13 13 * Name: fetch<br> 14 14 * Purpose: fetch file, web or ftp data and display results 15 * @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch} 15 * 16 * @link http://www.smarty.net/manual/en/language.function.fetch.php {fetch} 16 17 * (Smarty online manual) 17 18 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param array 19 * @param Smarty 20 * @return string|null if the assign parameter is passed, Smarty assigns the 21 * result to a template variable 19 * @param array $params parameters 20 * @param Smarty_Internal_Template $template template object 21 * @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable 22 22 */ 23 function smarty_function_fetch($params, &$smarty)23 function smarty_function_fetch($params, $template) 24 24 { 25 25 if (empty($params['file'])) { 26 $smarty->_trigger_fatal_error("[plugin] parameter 'file' cannot be empty");26 trigger_error("[plugin] fetch parameter 'file' cannot be empty",E_USER_NOTICE); 27 27 return; 28 28 } 29 30 // strip file protocol 31 if (stripos($params['file'], 'file://') === 0) { 32 $params['file'] = substr($params['file'], 7); 33 } 34 35 $protocol = strpos($params['file'], '://'); 36 if ($protocol !== false) { 37 $protocol = strtolower(substr($params['file'], 0, $protocol)); 38 } 39 40 if (isset($template->smarty->security_policy)) { 41 if ($protocol) { 42 // remote resource (or php stream, …) 43 if(!$template->smarty->security_policy->isTrustedUri($params['file'])) { 44 return; 45 } 46 } else { 47 // local file 48 if(!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { 49 return; 50 } 51 } 52 } 29 53 30 54 $content = ''; 31 if ($smarty->security && !preg_match('!^(http|ftp)://!i', $params['file'])) { 32 $_params = array('resource_type' => 'file', 'resource_name' => $params['file']); 33 require_once(SMARTY_CORE_DIR . 'core.is_secure.php'); 34 if(!smarty_core_is_secure($_params, $smarty)) { 35 $smarty->_trigger_fatal_error('[plugin] (secure mode) fetch \'' . $params['file'] . '\' is not allowed'); 36 return; 37 } 38 39 // fetch the file 40 if($fp = @fopen($params['file'],'r')) { 41 while(!feof($fp)) { 42 $content .= fgets ($fp,4096); 43 } 44 fclose($fp); 55 if ($protocol == 'http') { 56 // http fetch 57 if($uri_parts = parse_url($params['file'])) { 58 // set defaults 59 $host = $server_name = $uri_parts['host']; 60 $timeout = 30; 61 $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; 62 $agent = "Smarty Template Engine ". Smarty::SMARTY_VERSION; 63 $referer = ""; 64 $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; 65 $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; 66 $_is_proxy = false; 67 if(empty($uri_parts['port'])) { 68 $port = 80; 69 } else { 70 $port = $uri_parts['port']; 71 } 72 if(!empty($uri_parts['user'])) { 73 $user = $uri_parts['user']; 74 } 75 if(!empty($uri_parts['pass'])) { 76 $pass = $uri_parts['pass']; 77 } 78 // loop through parameters, setup headers 79 foreach($params as $param_key => $param_value) { 80 switch($param_key) { 81 case "file": 82 case "assign": 83 case "assign_headers": 84 break; 85 case "user": 86 if(!empty($param_value)) { 87 $user = $param_value; 88 } 89 break; 90 case "pass": 91 if(!empty($param_value)) { 92 $pass = $param_value; 93 } 94 break; 95 case "accept": 96 if(!empty($param_value)) { 97 $accept = $param_value; 98 } 99 break; 100 case "header": 101 if(!empty($param_value)) { 102 if(!preg_match('![\w\d-]+: .+!',$param_value)) { 103 trigger_error("[plugin] invalid header format '".$param_value."'",E_USER_NOTICE); 104 return; 105 } else { 106 $extra_headers[] = $param_value; 107 } 108 } 109 break; 110 case "proxy_host": 111 if(!empty($param_value)) { 112 $proxy_host = $param_value; 113 } 114 break; 115 case "proxy_port": 116 if(!preg_match('!\D!', $param_value)) { 117 $proxy_port = (int) $param_value; 118 } else { 119 trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); 120 return; 121 } 122 break; 123 case "agent": 124 if(!empty($param_value)) { 125 $agent = $param_value; 126 } 127 break; 128 case "referer": 129 if(!empty($param_value)) { 130 $referer = $param_value; 131 } 132 break; 133 case "timeout": 134 if(!preg_match('!\D!', $param_value)) { 135 $timeout = (int) $param_value; 136 } else { 137 trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); 138 return; 139 } 140 break; 141 default: 142 trigger_error("[plugin] unrecognized attribute '".$param_key."'",E_USER_NOTICE); 143 return; 144 } 145 } 146 if(!empty($proxy_host) && !empty($proxy_port)) { 147 $_is_proxy = true; 148 $fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout); 149 } else { 150 $fp = fsockopen($server_name,$port,$errno,$errstr,$timeout); 151 } 152 153 if(!$fp) { 154 trigger_error("[plugin] unable to fetch: $errstr ($errno)",E_USER_NOTICE); 155 return; 156 } else { 157 if($_is_proxy) { 158 fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); 159 } else { 160 fputs($fp, "GET $uri HTTP/1.0\r\n"); 161 } 162 if(!empty($host)) { 163 fputs($fp, "Host: $host\r\n"); 164 } 165 if(!empty($accept)) { 166 fputs($fp, "Accept: $accept\r\n"); 167 } 168 if(!empty($agent)) { 169 fputs($fp, "User-Agent: $agent\r\n"); 170 } 171 if(!empty($referer)) { 172 fputs($fp, "Referer: $referer\r\n"); 173 } 174 if(isset($extra_headers) && is_array($extra_headers)) { 175 foreach($extra_headers as $curr_header) { 176 fputs($fp, $curr_header."\r\n"); 177 } 178 } 179 if(!empty($user) && !empty($pass)) { 180 fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n"); 181 } 182 183 fputs($fp, "\r\n"); 184 while(!feof($fp)) { 185 $content .= fgets($fp,4096); 186 } 187 fclose($fp); 188 $csplit = preg_split("!\r\n\r\n!",$content,2); 189 190 $content = $csplit[1]; 191 192 if(!empty($params['assign_headers'])) { 193 $template->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0])); 194 } 195 } 45 196 } else { 46 $smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'');197 trigger_error("[plugin fetch] unable to parse URL, check syntax",E_USER_NOTICE); 47 198 return; 48 199 } 49 200 } else { 50 // not a local file 51 if(preg_match('!^http://!i',$params['file'])) { 52 // http fetch 53 if($uri_parts = parse_url($params['file'])) { 54 // set defaults 55 $host = $server_name = $uri_parts['host']; 56 $timeout = 30; 57 $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; 58 $agent = "Smarty Template Engine ".$smarty->_version; 59 $referer = ""; 60 $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; 61 $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; 62 $_is_proxy = false; 63 if(empty($uri_parts['port'])) { 64 $port = 80; 65 } else { 66 $port = $uri_parts['port']; 67 } 68 if(!empty($uri_parts['user'])) { 69 $user = $uri_parts['user']; 70 } 71 if(!empty($uri_parts['pass'])) { 72 $pass = $uri_parts['pass']; 73 } 74 // loop through parameters, setup headers 75 foreach($params as $param_key => $param_value) { 76 switch($param_key) { 77 case "file": 78 case "assign": 79 case "assign_headers": 80 break; 81 case "user": 82 if(!empty($param_value)) { 83 $user = $param_value; 84 } 85 break; 86 case "pass": 87 if(!empty($param_value)) { 88 $pass = $param_value; 89 } 90 break; 91 case "accept": 92 if(!empty($param_value)) { 93 $accept = $param_value; 94 } 95 break; 96 case "header": 97 if(!empty($param_value)) { 98 if(!preg_match('![\w\d-]+: .+!',$param_value)) { 99 $smarty->_trigger_fatal_error("[plugin] invalid header format '".$param_value."'"); 100 return; 101 } else { 102 $extra_headers[] = $param_value; 103 } 104 } 105 break; 106 case "proxy_host": 107 if(!empty($param_value)) { 108 $proxy_host = $param_value; 109 } 110 break; 111 case "proxy_port": 112 if(!preg_match('!\D!', $param_value)) { 113 $proxy_port = (int) $param_value; 114 } else { 115 $smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'"); 116 return; 117 } 118 break; 119 case "agent": 120 if(!empty($param_value)) { 121 $agent = $param_value; 122 } 123 break; 124 case "referer": 125 if(!empty($param_value)) { 126 $referer = $param_value; 127 } 128 break; 129 case "timeout": 130 if(!preg_match('!\D!', $param_value)) { 131 $timeout = (int) $param_value; 132 } else { 133 $smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'"); 134 return; 135 } 136 break; 137 default: 138 $smarty->_trigger_fatal_error("[plugin] unrecognized attribute '".$param_key."'"); 139 return; 140 } 141 } 142 if(!empty($proxy_host) && !empty($proxy_port)) { 143 $_is_proxy = true; 144 $fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout); 145 } else { 146 $fp = fsockopen($server_name,$port,$errno,$errstr,$timeout); 147 } 148 149 if(!$fp) { 150 $smarty->_trigger_fatal_error("[plugin] unable to fetch: $errstr ($errno)"); 151 return; 152 } else { 153 if($_is_proxy) { 154 fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); 155 } else { 156 fputs($fp, "GET $uri HTTP/1.0\r\n"); 157 } 158 if(!empty($host)) { 159 fputs($fp, "Host: $host\r\n"); 160 } 161 if(!empty($accept)) { 162 fputs($fp, "Accept: $accept\r\n"); 163 } 164 if(!empty($agent)) { 165 fputs($fp, "User-Agent: $agent\r\n"); 166 } 167 if(!empty($referer)) { 168 fputs($fp, "Referer: $referer\r\n"); 169 } 170 if(isset($extra_headers) && is_array($extra_headers)) { 171 foreach($extra_headers as $curr_header) { 172 fputs($fp, $curr_header."\r\n"); 173 } 174 } 175 if(!empty($user) && !empty($pass)) { 176 fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n"); 177 } 178 179 fputs($fp, "\r\n"); 180 while(!feof($fp)) { 181 $content .= fgets($fp,4096); 182 } 183 fclose($fp); 184 $csplit = split("\r\n\r\n",$content,2); 185 186 $content = $csplit[1]; 187 188 if(!empty($params['assign_headers'])) { 189 $smarty->assign($params['assign_headers'],split("\r\n",$csplit[0])); 190 } 191 } 192 } else { 193 $smarty->_trigger_fatal_error("[plugin] unable to parse URL, check syntax"); 194 return; 195 } 196 } else { 197 // ftp fetch 198 if($fp = @fopen($params['file'],'r')) { 199 while(!feof($fp)) { 200 $content .= fgets ($fp,4096); 201 } 202 fclose($fp); 203 } else { 204 $smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] .'\''); 205 return; 206 } 201 $content = @file_get_contents($params['file']); 202 if ($content === false) { 203 throw new SmartyException("{fetch} cannot read resource '" . $params['file'] ."'"); 207 204 } 208 209 } 210 205 } 211 206 212 207 if (!empty($params['assign'])) { 213 $ smarty->assign($params['assign'],$content);208 $template->assign($params['assign'], $content); 214 209 } else { 215 210 return $content; … … 217 212 } 218 213 219 /* vim: set expandtab: */220 221 214 ?> -
trunk/include/smarty/libs/plugins/function.html_checkboxes.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 8 9 9 /** … … 15 15 * Date: 24.Feb.2003<br> 16 16 * Purpose: Prints out a list of checkbox input types<br> 17 * Input:<br>18 * - name (optional) - string default "checkbox"19 * - values (required) - array20 * - options (optional) - associative array21 * - checked (optional) - array default not set22 * - separator (optional) - ie <br> or 23 * - output (optional) - the output next to each checkbox24 * - assign (optional) - assign the output as an array to this variable25 17 * Examples: 26 18 * <pre> … … 29 21 * {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names} 30 22 * </pre> 31 * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} 23 * Params: 24 * <pre> 25 * - name (optional) - string default "checkbox" 26 * - values (required) - array 27 * - options (optional) - associative array 28 * - checked (optional) - array default not set 29 * - separator (optional) - ie <br> or 30 * - output (optional) - the output next to each checkbox 31 * - assign (optional) - assign the output as an array to this variable 32 * - escape (optional) - escape the content (not value), defaults to true 33 * </pre> 34 * 35 * @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} 32 36 * (Smarty online manual) 33 37 * @author Christopher Kvarme <christopher.kvarme@flashjab.com> 34 38 * @author credits to Monte Ohrt <monte at ohrt dot com> 35 39 * @version 1.0 36 * @param array 37 * @param Smarty40 * @param array $params parameters 41 * @param object $template template object 38 42 * @return string 39 43 * @uses smarty_function_escape_special_chars() 40 44 */ 41 function smarty_function_html_checkboxes($params, &$smarty)45 function smarty_function_html_checkboxes($params, $template) 42 46 { 43 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');47 require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 44 48 45 49 $name = 'checkbox'; 46 50 $values = null; 47 51 $options = null; 48 $selected = null;52 $selected = array(); 49 53 $separator = ''; 54 $escape = true; 50 55 $labels = true; 56 $label_ids = false; 51 57 $output = null; 52 58 … … 57 63 case 'name': 58 64 case 'separator': 59 $$_key = $_val; 60 break; 61 65 $$_key = (string) $_val; 66 break; 67 68 case 'escape': 62 69 case 'labels': 63 $$_key = (bool)$_val; 70 case 'label_ids': 71 $$_key = (bool) $_val; 64 72 break; 65 73 66 74 case 'options': 67 $$_key = (array) $_val;75 $$_key = (array) $_val; 68 76 break; 69 77 70 78 case 'values': 71 79 case 'output': 72 $$_key = array_values((array) $_val);80 $$_key = array_values((array) $_val); 73 81 break; 74 82 75 83 case 'checked': 76 84 case 'selected': 77 $selected = array_map('strval', array_values((array)$_val)); 85 if (is_array($_val)) { 86 $selected = array(); 87 foreach ($_val as $_sel) { 88 if (is_object($_sel)) { 89 if (method_exists($_sel, "__toString")) { 90 $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); 91 } else { 92 trigger_error("html_checkboxes: selected attribute contains an object of class '". get_class($_sel) ."' without __toString() method", E_USER_NOTICE); 93 continue; 94 } 95 } else { 96 $_sel = smarty_function_escape_special_chars((string) $_sel); 97 } 98 $selected[$_sel] = true; 99 } 100 } elseif (is_object($_val)) { 101 if (method_exists($_val, "__toString")) { 102 $selected = smarty_function_escape_special_chars((string) $_val->__toString()); 103 } else { 104 trigger_error("html_checkboxes: selected attribute is an object of class '". get_class($_val) ."' without __toString() method", E_USER_NOTICE); 105 } 106 } else { 107 $selected = smarty_function_escape_special_chars((string) $_val); 108 } 78 109 break; 79 110 80 111 case 'checkboxes': 81 $smarty->trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);82 $options = (array) $_val;112 trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); 113 $options = (array) $_val; 83 114 break; 84 115 85 116 case 'assign': 86 117 break; 118 119 case 'strict': break; 120 121 case 'disabled': 122 case 'readonly': 123 if (!empty($params['strict'])) { 124 if (!is_scalar($_val)) { 125 trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE); 126 } 127 128 if ($_val === true || $_val === $_key) { 129 $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; 130 } 131 132 break; 133 } 134 // omit break; to fall through! 87 135 88 136 default: … … 90 138 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; 91 139 } else { 92 $smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);140 trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 93 141 } 94 142 break; … … 99 147 return ''; /* raise error here? */ 100 148 101 settype($selected, 'array');102 149 $_html_result = array(); 103 150 104 151 if (isset($options)) { 105 106 foreach ($options as $_key=>$_val) 107 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); 108 109 152 foreach ($options as $_key=>$_val) { 153 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); 154 } 110 155 } else { 111 156 foreach ($values as $_i=>$_key) { 112 157 $_val = isset($output[$_i]) ? $output[$_i] : ''; 113 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); 114 } 115 158 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); 159 } 116 160 } 117 161 118 162 if(!empty($params['assign'])) { 119 $ smarty->assign($params['assign'], $_html_result);120 } else { 121 return implode("\n", $_html_result);163 $template->assign($params['assign'], $_html_result); 164 } else { 165 return implode("\n", $_html_result); 122 166 } 123 167 124 168 } 125 169 126 function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels ) {170 function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape=true) { 127 171 $_output = ''; 128 if ($labels) $_output .= '<label>'; 129 $_output .= '<input type="checkbox" name="' 130 . smarty_function_escape_special_chars($name) . '[]" value="' 131 . smarty_function_escape_special_chars($value) . '"'; 132 133 if (in_array((string)$value, $selected)) { 172 173 if (is_object($value)) { 174 if (method_exists($value, "__toString")) { 175 $value = (string) $value->__toString(); 176 } else { 177 trigger_error("html_options: value is an object of class '". get_class($value) ."' without __toString() method", E_USER_NOTICE); 178 return ''; 179 } 180 } else { 181 $value = (string) $value; 182 } 183 184 if (is_object($output)) { 185 if (method_exists($output, "__toString")) { 186 $output = (string) $output->__toString(); 187 } else { 188 trigger_error("html_options: output is an object of class '". get_class($output) ."' without __toString() method", E_USER_NOTICE); 189 return ''; 190 } 191 } else { 192 $output = (string) $output; 193 } 194 195 if ($labels) { 196 if ($label_ids) { 197 $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value)); 198 $_output .= '<label for="' . $_id . '">'; 199 } else { 200 $_output .= '<label>'; 201 } 202 } 203 204 $name = smarty_function_escape_special_chars($name); 205 $value = smarty_function_escape_special_chars($value); 206 if ($escape) { 207 $output = smarty_function_escape_special_chars($output); 208 } 209 210 $_output .= '<input type="checkbox" name="' . $name . '[]" value="' . $value . '"'; 211 212 if ($labels && $label_ids) { 213 $_output .= ' id="' . $_id . '"'; 214 } 215 216 if (is_array($selected)) { 217 if (isset($selected[$value])) { 218 $_output .= ' checked="checked"'; 219 } 220 } elseif ($value === $selected) { 134 221 $_output .= ' checked="checked"'; 135 222 } 136 $_output .= $extra . '>' . $output; 137 if ($labels) $_output .= '</label>'; 223 224 $_output .= $extra . ' />' . $output; 225 if ($labels) { 226 $_output .= '</label>'; 227 } 228 138 229 $_output .= $separator; 139 140 230 return $_output; 141 231 } -
trunk/include/smarty/libs/plugins/function.html_image.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 8 9 9 /** 10 10 * Smarty {html_image} function plugin 11 * 11 * 12 12 * Type: function<br> 13 13 * Name: html_image<br> 14 14 * Date: Feb 24, 2003<br> 15 15 * Purpose: format HTML tags for the image<br> 16 * Input:<br> 17 * - file = file (and path) of image (required) 18 * - height = image height (optional, default actual height) 19 * - width = image width (optional, default actual width) 20 * - basedir = base directory for absolute paths, default 21 * is environment variable DOCUMENT_ROOT 22 * - path_prefix = prefix for path output (optional, default empty) 23 * 24 * Examples: {html_image file="/images/masthead.gif"} 25 * Output: <img src="/images/masthead.gif" width=400 height=23> 26 * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image} 16 * Examples: {html_image file="/images/masthead.gif"}<br> 17 * Output: <img src="/images/masthead.gif" width=400 height=23><br> 18 * Params: 19 * <pre> 20 * - file - (required) - file (and path) of image 21 * - height - (optional) - image height (default actual height) 22 * - width - (optional) - image width (default actual width) 23 * - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT 24 * - path_prefix - prefix for path output (optional, default empty) 25 * </pre> 26 * 27 * @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} 27 28 * (Smarty online manual) 28 * @author Monte Ohrt <monte at ohrt dot com> 29 * @author credits to Duda <duda@big.hu> - wrote first image function 30 * in repository, helped with lots of functionality 31 * @version 1.0 32 * @param array 33 * @param Smarty 34 * @return string 29 * @author Monte Ohrt <monte at ohrt dot com> 30 * @author credits to Duda <duda@big.hu> 31 * @version 1.0 32 * @param array $params parameters 33 * @param Smarty_Internal_Template $template template object 34 * @return string 35 35 * @uses smarty_function_escape_special_chars() 36 36 */ 37 function smarty_function_html_image($params, &$smarty)37 function smarty_function_html_image($params, $template) 38 38 { 39 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');40 39 require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 40 41 41 $alt = ''; 42 42 $file = ''; … … 47 47 $suffix = ''; 48 48 $path_prefix = ''; 49 $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; 50 $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; 49 $basedir = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : ''; 51 50 foreach($params as $_key => $_val) { 52 switch ($_key) {51 switch ($_key) { 53 52 case 'file': 54 53 case 'height': … … 61 60 62 61 case 'alt': 63 if (!is_array($_val)) {62 if (!is_array($_val)) { 64 63 $$_key = smarty_function_escape_special_chars($_val); 65 64 } else { 66 $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);67 } 65 throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 66 } 68 67 break; 69 68 … … 75 74 76 75 default: 77 if (!is_array($_val)) {78 $extra .= ' ' .$_key.'="'.smarty_function_escape_special_chars($_val).'"';76 if (!is_array($_val)) { 77 $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; 79 78 } else { 80 $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);81 } 79 throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 80 } 82 81 break; 83 } 84 } 82 } 83 } 85 84 86 85 if (empty($file)) { 87 $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);86 trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); 88 87 return; 89 } 88 } 90 89 91 if ( substr($file,0,1)== '/') {90 if ($file[0] == '/') { 92 91 $_image_path = $basedir . $file; 93 92 } else { … … 95 94 } 96 95 97 if(!isset($params['width']) || !isset($params['height'])) { 98 if(!$_image_data = @getimagesize($_image_path)) { 99 if(!file_exists($_image_path)) { 100 $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); 96 // strip file protocol 97 if (stripos($params['file'], 'file://') === 0) { 98 $params['file'] = substr($params['file'], 7); 99 } 100 101 $protocol = strpos($params['file'], '://'); 102 if ($protocol !== false) { 103 $protocol = strtolower(substr($params['file'], 0, $protocol)); 104 } 105 106 if (isset($template->smarty->security_policy)) { 107 if ($protocol) { 108 // remote resource (or php stream, …) 109 if(!$template->smarty->security_policy->isTrustedUri($params['file'])) { 101 110 return; 102 } else if(!is_readable($_image_path)) { 103 $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); 104 return; 105 } else { 106 $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); 111 } 112 } else { 113 // local file 114 if(!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { 107 115 return; 108 116 } 109 117 } 110 if ($smarty->security && 111 ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) && 112 (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) && 113 (!smarty_core_is_secure($_params, $smarty)) ) { 114 $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE); 115 } 116 117 if(!isset($params['width'])) { 118 $width = $_image_data[0]; 119 } 120 if(!isset($params['height'])) { 121 $height = $_image_data[1]; 118 } 119 120 if (!isset($params['width']) || !isset($params['height'])) { 121 // FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader! 122 if (!$_image_data = @getimagesize($_image_path)) { 123 if (!file_exists($_image_path)) { 124 trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); 125 return; 126 } else if (!is_readable($_image_path)) { 127 trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); 128 return; 129 } else { 130 trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); 131 return; 132 } 122 133 } 123 134 124 } 135 if (!isset($params['width'])) { 136 $width = $_image_data[0]; 137 } 138 if (!isset($params['height'])) { 139 $height = $_image_data[1]; 140 } 141 } 125 142 126 if(isset($params['dpi'])) { 127 if(strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) { 143 if (isset($params['dpi'])) { 144 if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mac')) { 145 // FIXME: (rodneyrehm) wrong dpi assumption 146 // don't know who thought this up… even if it was true in 1998, it's definitely wrong in 2011. 128 147 $dpi_default = 72; 129 148 } else { 130 149 $dpi_default = 96; 131 } 132 $_resize = $dpi_default /$params['dpi'];150 } 151 $_resize = $dpi_default / $params['dpi']; 133 152 $width = round($width * $_resize); 134 153 $height = round($height * $_resize); 135 } 154 } 136 155 137 return $prefix . '<img src="'.$path_prefix.$file.'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"'.$extra.'>' . $suffix; 138 } 139 140 /* vim: set expandtab: */ 156 return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />' . $suffix; 157 } 141 158 142 159 ?> -
trunk/include/smarty/libs/plugins/function.html_options.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 8 9 9 /** 10 10 * Smarty {html_options} function plugin 11 * 11 * 12 12 * Type: function<br> 13 13 * Name: html_options<br> 14 * Input:<br>15 * - name (optional) - string default "select"16 * - values (required if no options supplied) - array17 * - options (required if no values supplied) - associative array18 * - selected (optional) - string default not set19 * - output (required if not options supplied) - array20 14 * Purpose: Prints the list of <option> tags generated from 21 * the passed parameters 22 * @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image} 15 * the passed parameters<br> 16 * Params: 17 * <pre> 18 * - name (optional) - string default "select" 19 * - values (required) - if no options supplied) - array 20 * - options (required) - if no values supplied) - associative array 21 * - selected (optional) - string default not set 22 * - output (required) - if not options supplied) - array 23 * - id (optional) - string default not set 24 * - class (optional) - string default not set 25 * </pre> 26 * 27 * @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image} 23 28 * (Smarty online manual) 24 * @author Monte Ohrt <monte at ohrt dot com> 25 * @param array 26 * @param Smarty 27 * @return string 29 * @author Monte Ohrt <monte at ohrt dot com> 30 * @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de> 31 * @param array $params parameters 32 * @param Smarty_Internal_Template $template template object 33 * @return string 28 34 * @uses smarty_function_escape_special_chars() 29 35 */ 30 function smarty_function_html_options($params, &$smarty)36 function smarty_function_html_options($params, $template) 31 37 { 32 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');33 38 require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 39 34 40 $name = null; 35 41 $values = null; 36 42 $options = null; 37 $selected = array();43 $selected = null; 38 44 $output = null; 39 45 $id = null; 46 $class = null; 47 40 48 $extra = ''; 41 42 foreach ($params as $_key => $_val) {43 switch ($_key) {49 50 foreach ($params as $_key => $_val) { 51 switch ($_key) { 44 52 case 'name': 45 $$_key = (string)$_val; 53 case 'class': 54 case 'id': 55 $$_key = (string) $_val; 46 56 break; 47 57 48 58 case 'options': 49 $ $_key = (array)$_val;59 $options = (array) $_val; 50 60 break; 51 61 52 62 case 'values': 53 63 case 'output': 54 $$_key = array_values((array) $_val);64 $$_key = array_values((array) $_val); 55 65 break; 56 66 57 67 case 'selected': 58 $$_key = array_map('strval', array_values((array)$_val)); 59 break; 60 61 default: 62 if(!is_array($_val)) { 63 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; 68 if (is_array($_val)) { 69 $selected = array(); 70 foreach ($_val as $_sel) { 71 if (is_object($_sel)) { 72 if (method_exists($_sel, "__toString")) { 73 $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); 74 } else { 75 trigger_error("html_options: selected attribute contains an object of class '". get_class($_sel) ."' without __toString() method", E_USER_NOTICE); 76 continue; 77 } 78 } else { 79 $_sel = smarty_function_escape_special_chars((string) $_sel); 80 } 81 $selected[$_sel] = true; 82 } 83 } elseif (is_object($_val)) { 84 if (method_exists($_val, "__toString")) { 85 $selected = smarty_function_escape_special_chars((string) $_val->__toString()); 86 } else { 87 trigger_error("html_options: selected attribute is an object of class '". get_class($_val) ."' without __toString() method", E_USER_NOTICE); 88 } 64 89 } else { 65 $s marty->trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);90 $selected = smarty_function_escape_special_chars((string) $_val); 66 91 } 67 92 break; 68 } 93 94 case 'strict': break; 95 96 case 'disabled': 97 case 'readonly': 98 if (!empty($params['strict'])) { 99 if (!is_scalar($_val)) { 100 trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE); 101 } 102 103 if ($_val === true || $_val === $_key) { 104 $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; 105 } 106 107 break; 108 } 109 // omit break; to fall through! 110 111 default: 112 if (!is_array($_val)) { 113 $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; 114 } else { 115 trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 116 } 117 break; 118 } 69 119 } 70 120 71 if (!isset($options) && !isset($values)) 72 return ''; /* raise error here? */ 121 if (!isset($options) && !isset($values)) { 122 /* raise error here? */ 123 return ''; 124 } 73 125 74 126 $_html_result = ''; 127 $_idx = 0; 75 128 76 129 if (isset($options)) { 77 78 foreach ($options as $_key=>$_val) 79 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); 80 130 foreach ($options as $_key => $_val) { 131 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); 132 } 81 133 } else { 82 83 foreach ($values as $_i=>$_key) { 134 foreach ($values as $_i => $_key) { 84 135 $_val = isset($output[$_i]) ? $output[$_i] : ''; 85 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); 86 } 87 136 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); 137 } 88 138 } 89 139 90 if(!empty($name)) { 91 $_html_result = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n"; 92 } 140 if (!empty($name)) { 141 $_html_class = !empty($class) ? ' class="'.$class.'"' : ''; 142 $_html_id = !empty($id) ? ' id="'.$id.'"' : ''; 143 $_html_result = '<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . '</select>' . "\n"; 144 } 93 145 94 return $_html_result;95 96 }97 98 function smarty_function_html_options_optoutput($key, $value, $selected) {99 if(!is_array($value)) {100 $_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' .101 smarty_function_escape_special_chars($key) . '"';102 if (in_array((string)$key, $selected))103 $_html_result .= ' selected="selected"';104 $_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n";105 } else {106 $_html_result = smarty_function_html_options_optgroup($key, $value, $selected);107 }108 146 return $_html_result; 109 147 } 110 148 111 function smarty_function_html_options_optgroup($key, $values, $selected) { 149 function smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, &$idx) 150 { 151 if (!is_array($value)) { 152 $_key = smarty_function_escape_special_chars($key); 153 $_html_result = '<option value="' . $_key . '"'; 154 if (is_array($selected)) { 155 if (isset($selected[$_key])) { 156 $_html_result .= ' selected="selected"'; 157 } 158 } elseif ($_key === $selected) { 159 $_html_result .= ' selected="selected"'; 160 } 161 $_html_class = !empty($class) ? ' class="'.$class.' option"' : ''; 162 $_html_id = !empty($id) ? ' id="'.$id.'-'.$idx.'"' : ''; 163 if (is_object($value)) { 164 if (method_exists($value, "__toString")) { 165 $value = smarty_function_escape_special_chars((string) $value->__toString()); 166 } else { 167 trigger_error("html_options: value is an object of class '". get_class($value) ."' without __toString() method", E_USER_NOTICE); 168 return ''; 169 } 170 } else { 171 $value = smarty_function_escape_special_chars((string) $value); 172 } 173 $_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n"; 174 $idx++; 175 } else { 176 $_idx = 0; 177 $_html_result = smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id.'-'.$idx) : null, $class, $_idx); 178 $idx++; 179 } 180 return $_html_result; 181 } 182 183 function smarty_function_html_options_optgroup($key, $values, $selected, $id, $class, &$idx) 184 { 112 185 $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n"; 113 186 foreach ($values as $key => $value) { 114 $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected );115 } 187 $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx); 188 } 116 189 $optgroup_html .= "</optgroup>\n"; 117 190 return $optgroup_html; 118 } 119 120 /* vim: set expandtab: */ 191 } 121 192 122 193 ?> -
trunk/include/smarty/libs/plugins/function.html_radios.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 8 9 9 /** 10 10 * Smarty {html_radios} function plugin 11 * 11 * 12 12 * File: function.html_radios.php<br> 13 13 * Type: function<br> … … 15 15 * Date: 24.Feb.2003<br> 16 16 * Purpose: Prints out a list of radio input types<br> 17 * Input:<br> 18 * - name (optional) - string default "radio" 19 * - values (required) - array 20 * - options (optional) - associative array 21 * - checked (optional) - array default not set 22 * - separator (optional) - ie <br> or 23 * - output (optional) - the output next to each radio button 24 * - assign (optional) - assign the output as an array to this variable 17 * Params: 18 * <pre> 19 * - name (optional) - string default "radio" 20 * - values (required) - array 21 * - options (required) - associative array 22 * - checked (optional) - array default not set 23 * - separator (optional) - ie <br> or 24 * - output (optional) - the output next to each radio button 25 * - assign (optional) - assign the output as an array to this variable 26 * - escape (optional) - escape the content (not value), defaults to true 27 * </pre> 25 28 * Examples: 26 29 * <pre> … … 29 32 * {html_radios values=$ids checked=$checked separator='<br>' output=$names} 30 33 * </pre> 34 * 31 35 * @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios} 32 36 * (Smarty online manual) 33 * @author Christopher Kvarme <christopher.kvarme@flashjab.com>34 * @author credits to Monte Ohrt <monte at ohrt dot com> 35 * @version 36 * @param array 37 * @param Smarty 38 * @return string 37 * @author Christopher Kvarme <christopher.kvarme@flashjab.com> 38 * @author credits to Monte Ohrt <monte at ohrt dot com> 39 * @version 1.0 40 * @param array $params parameters 41 * @param Smarty_Internal_Template $template template object 42 * @return string 39 43 * @uses smarty_function_escape_special_chars() 40 44 */ 41 function smarty_function_html_radios($params, &$smarty)45 function smarty_function_html_radios($params, $template) 42 46 { 43 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');44 47 require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 48 45 49 $name = 'radio'; 46 50 $values = null; … … 48 52 $selected = null; 49 53 $separator = ''; 54 $escape = true; 50 55 $labels = true; 51 56 $label_ids = false; … … 54 59 55 60 foreach($params as $_key => $_val) { 56 switch ($_key) {61 switch ($_key) { 57 62 case 'name': 58 63 case 'separator': 59 $$_key = (string) $_val;64 $$_key = (string) $_val; 60 65 break; 61 66 62 67 case 'checked': 63 68 case 'selected': 64 if(is_array($_val)) { 65 $smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING); 69 if (is_array($_val)) { 70 trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING); 71 } elseif (is_object($_val)) { 72 if (method_exists($_val, "__toString")) { 73 $selected = smarty_function_escape_special_chars((string) $_val->__toString()); 74 } else { 75 trigger_error("html_radios: selected attribute is an object of class '". get_class($_val) ."' without __toString() method", E_USER_NOTICE); 76 } 66 77 } else { 67 $selected = (string)$_val; 68 } 69 break; 70 78 $selected = (string) $_val; 79 } 80 break; 81 82 case 'escape': 71 83 case 'labels': 72 84 case 'label_ids': 73 $$_key = (bool) $_val;85 $$_key = (bool) $_val; 74 86 break; 75 87 76 88 case 'options': 77 $$_key = (array) $_val;89 $$_key = (array) $_val; 78 90 break; 79 91 80 92 case 'values': 81 93 case 'output': 82 $$_key = array_values((array) $_val);94 $$_key = array_values((array) $_val); 83 95 break; 84 96 85 97 case 'radios': 86 $smarty->trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);87 $options = (array) $_val;98 trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING); 99 $options = (array) $_val; 88 100 break; 89 101 … … 91 103 break; 92 104 105 case 'strict': break; 106 107 case 'disabled': 108 case 'readonly': 109 if (!empty($params['strict'])) { 110 if (!is_scalar($_val)) { 111 trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE); 112 } 113 114 if ($_val === true || $_val === $_key) { 115 $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; 116 } 117 118 break; 119 } 120 // omit break; to fall through! 121 93 122 default: 94 if (!is_array($_val)) {95 $extra .= ' ' .$_key.'="'.smarty_function_escape_special_chars($_val).'"';123 if (!is_array($_val)) { 124 $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; 96 125 } else { 97 $smarty->trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 98 } 99 break; 126 trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 127 } 128 break; 129 } 130 } 131 132 if (!isset($options) && !isset($values)) { 133 /* raise error here? */ 134 return ''; 135 } 136 137 $_html_result = array(); 138 139 if (isset($options)) { 140 foreach ($options as $_key => $_val) { 141 $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); 100 142 } 101 } 102 103 if (!isset($options) && !isset($values)) 104 return ''; /* raise error here? */ 105 106 $_html_result = array(); 107 108 if (isset($options)) { 109 110 foreach ($options as $_key=>$_val) 111 $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids); 112 113 } else { 114 115 foreach ($values as $_i=>$_key) { 143 } else { 144 foreach ($values as $_i => $_key) { 116 145 $_val = isset($output[$_i]) ? $output[$_i] : ''; 117 $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids); 146 $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); 147 } 148 } 149 150 if (!empty($params['assign'])) { 151 $template->assign($params['assign'], $_html_result); 152 } else { 153 return implode("\n", $_html_result); 154 } 155 } 156 157 function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape) 158 { 159 $_output = ''; 160 161 if (is_object($value)) { 162 if (method_exists($value, "__toString")) { 163 $value = (string) $value->__toString(); 164 } else { 165 trigger_error("html_options: value is an object of class '". get_class($value) ."' without __toString() method", E_USER_NOTICE); 166 return ''; 118 167 } 119 120 } 121 122 if(!empty($params['assign'])) { 123 $smarty->assign($params['assign'], $_html_result); 124 } else { 125 return implode("\n",$_html_result); 126 } 127 128 } 129 130 function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) { 131 $_output = ''; 168 } else { 169 $value = (string) $value; 170 } 171 172 if (is_object($output)) { 173 if (method_exists($output, "__toString")) { 174 $output = (string) $output->__toString(); 175 } else { 176 trigger_error("html_options: output is an object of class '". get_class($output) ."' without __toString() method", E_USER_NOTICE); 177 return ''; 178 } 179 } else { 180 $output = (string) $output; 181 } 182 132 183 if ($labels) { 133 if($label_ids) { 134 $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!', '_', $name . '_' . $value)); 135 $_output .= '<label for="' . $_id . '">'; 136 } else { 137 $_output .= '<label>'; 138 } 139 } 140 $_output .= '<input type="radio" name="' 141 . smarty_function_escape_special_chars($name) . '" value="' 142 . smarty_function_escape_special_chars($value) . '"'; 143 144 if ($labels && $label_ids) $_output .= ' id="' . $_id . '"'; 145 146 if ((string)$value==$selected) { 184 if ($label_ids) { 185 $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value)); 186 $_output .= '<label for="' . $_id . '">'; 187 } else { 188 $_output .= '<label>'; 189 } 190 } 191 192 $name = smarty_function_escape_special_chars($name); 193 $value = smarty_function_escape_special_chars($value); 194 if ($escape) { 195 $output = smarty_function_escape_special_chars($output); 196 } 197 198 $_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"'; 199 200 if ($labels && $label_ids) { 201 $_output .= ' id="' . $_id . '"'; 202 } 203 204 if ($value === $selected) { 147 205 $_output .= ' checked="checked"'; 148 206 } 149 $_output .= $extra . '>' . $output; 150 if ($labels) $_output .= '</label>'; 151 $_output .= $separator; 152 207 208 $_output .= $extra . ' />' . $output; 209 if ($labels) { 210 $_output .= '</label>'; 211 } 212 213 $_output .= $separator; 153 214 return $_output; 154 } 215 } 155 216 156 217 ?> -
trunk/include/smarty/libs/plugins/function.html_select_date.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 8 9 /** 10 * @ignore 11 */ 12 require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 13 /** 14 * @ignore 15 */ 16 require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); 7 17 8 18 /** 9 19 * Smarty {html_select_date} plugin 10 * 20 * 11 21 * Type: function<br> 12 22 * Name: html_select_date<br> 13 23 * Purpose: Prints the dropdowns for date selection. 14 * 15 * ChangeLog:<br> 16 * - 1.0 initial release 17 * - 1.1 added support for +/- N syntax for begin 18 * and end year values. (Monte) 19 * - 1.2 added support for yyyy-mm-dd syntax for 20 * time value. (Jan Rosier) 21 * - 1.3 added support for choosing format for 22 * month values (Gary Loescher) 23 * - 1.3.1 added support for choosing format for 24 * day values (Marcus Bointon) 25 * - 1.3.2 support negative timestamps, force year 26 * dropdown to include given date unless explicitly set (Monte) 27 * - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that 28 * of 0000-00-00 dates (cybot, boots) 29 * @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date} 24 * 25 * ChangeLog: 26 * <pre> 27 * - 1.0 initial release 28 * - 1.1 added support for +/- N syntax for begin 29 * and end year values. (Monte) 30 * - 1.2 added support for yyyy-mm-dd syntax for 31 * time value. (Jan Rosier) 32 * - 1.3 added support for choosing format for 33 * month values (Gary Loescher) 34 * - 1.3.1 added support for choosing format for 35 * day values (Marcus Bointon) 36 * - 1.3.2 support negative timestamps, force year 37 * dropdown to include given date unless explicitly set (Monte) 38 * - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that 39 * of 0000-00-00 dates (cybot, boots) 40 * - 2.0 complete rewrite for performance, 41 * added attributes month_names, *_id 42 * </pre> 43 * 44 * @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date} 30 45 * (Smarty online manual) 31 * @version 1.3.4 32 * @author Andrei Zmievski 33 * @author Monte Ohrt <monte at ohrt dot com> 34 * @param array 35 * @param Smarty 36 * @return string 46 * @version 2.0 47 * @author Andrei Zmievski 48 * @author Monte Ohrt <monte at ohrt dot com> 49 * @author Rodney Rehm 50 * @param array $params parameters 51 * @param Smarty_Internal_Template $template template object 52 * @return string 37 53 */ 38 function smarty_function_html_select_date($params, &$smarty)54 function smarty_function_html_select_date($params, $template) 39 55 { 40 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); 41 require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); 42 require_once $smarty->_get_plugin_filepath('function','html_options'); 56 // generate timestamps used for month names only 57 static $_month_timestamps = null; 58 static $_current_year = null; 59 if ($_month_timestamps === null) { 60 $_current_year = date('Y'); 61 $_month_timestamps = array(); 62 for ($i = 1; $i <= 12; $i++) { 63 $_month_timestamps[$i] = mktime(0, 0, 0, $i, 1, 2000); 64 } 65 } 66 43 67 /* Default values. */ 44 $prefix 45 $start_year = strftime("%Y");46 $end_year = $start_year;47 $display_days 48 $display_months 49 $display_years 50 $month_format 68 $prefix = "Date_"; 69 $start_year = null; 70 $end_year = null; 71 $display_days = true; 72 $display_months = true; 73 $display_years = true; 74 $month_format = "%B"; 51 75 /* Write months as numbers by default GL */ 52 76 $month_value_format = "%m"; 53 $day_format 77 $day_format = "%02d"; 54 78 /* Write day values using this format MB */ 55 79 $day_value_format = "%d"; 56 $year_as_text 80 $year_as_text = false; 57 81 /* Display years in reverse order? Ie. 2000,1999,.... */ 58 $reverse_years 82 $reverse_years = false; 59 83 /* Should the select boxes be part of an array when returned from PHP? 60 84 e.g. setting it to "birthday", would create "birthday[Day]", 61 85 "birthday[Month]" & "birthday[Year]". Can be combined with prefix */ 62 $field_array 86 $field_array = null; 63 87 /* <select size>'s of the different <select> tags. 64 88 If not set, uses default dropdown. */ 65 $day_size 66 $month_size 67 $year_size 89 $day_size = null; 90 $month_size = null; 91 $year_size = null; 68 92 /* Unparsed attributes common to *ALL* the <select>/<input> tags. 69 93 An example might be in the template: all_extra ='class ="foo"'. */ 70 $all_extra 94 $all_extra = null; 71 95 /* Separate attributes for the tags. */ 72 $day_extra 73 $month_extra 74 $year_extra 96 $day_extra = null; 97 $month_extra = null; 98 $year_extra = null; 75 99 /* Order in which to display the fields. 76 100 "D" -> day, "M" -> month, "Y" -> year. */ 77 $field_order 101 $field_order = 'MDY'; 78 102 /* String printed between the different fields. */ 79 103 $field_separator = "\n"; 80 $time = time(); 81 $all_empty = null; 82 $day_empty = null; 83 $month_empty = null; 84 $year_empty = null; 85 $extra_attrs = ''; 86 87 foreach ($params as $_key=>$_value) { 104 $option_separator = "\n"; 105 $time = null; 106 // $all_empty = null; 107 // $day_empty = null; 108 // $month_empty = null; 109 // $year_empty = null; 110 $extra_attrs = ''; 111 $all_id = null; 112 $day_id = null; 113 $month_id = null; 114 $year_id = null; 115 116 foreach ($params as $_key => $_value) { 88 117 switch ($_key) { 118 case 'time': 119 if (!is_array($_value) && $_value !== null) { 120 $time = smarty_make_timestamp($_value); 121 } 122 break; 123 124 case 'month_names': 125 if (is_array($_value) && count($_value) == 12) { 126 $$_key = $_value; 127 } else { 128 trigger_error("html_select_date: month_names must be an array of 12 strings", E_USER_NOTICE); 129 } 130 break; 131 89 132 case 'prefix': 90 case ' time':133 case 'field_array': 91 134 case 'start_year': 92 135 case 'end_year': 93 case 'month_format':94 136 case 'day_format': 95 137 case 'day_value_format': 96 case 'field_array': 138 case 'month_format': 139 case 'month_value_format': 97 140 case 'day_size': 98 141 case 'month_size': … … 104 147 case 'field_order': 105 148 case 'field_separator': 106 case 'month_value_format': 149 case 'option_separator': 150 case 'all_empty': 107 151 case 'month_empty': 108 152 case 'day_empty': 109 153 case 'year_empty': 154 case 'all_id': 155 case 'month_id': 156 case 'day_id': 157 case 'year_id': 110 158 $$_key = (string)$_value; 111 break;112 113 case 'all_empty':114 $$_key = (string)$_value;115 $day_empty = $month_empty = $year_empty = $all_empty;116 159 break; 117 160 … … 125 168 126 169 default: 127 if (!is_array($_value)) {128 $extra_attrs .= ' ' .$_key.'="'.smarty_function_escape_special_chars($_value).'"';170 if (!is_array($_value)) { 171 $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; 129 172 } else { 130 $smarty->trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 131 } 132 break; 133 } 134 } 135 136 if (preg_match('!^-\d+$!', $time)) { 137 // negative timestamp, use date() 138 $time = date('Y-m-d', $time); 139 } 140 // If $time is not in format yyyy-mm-dd 141 if (preg_match('/^(\d{0,4}-\d{0,2}-\d{0,2})/', $time, $found)) { 142 $time = $found[1]; 173 trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 174 } 175 break; 176 } 177 } 178 179 // Note: date() is faster than strftime() 180 // Note: explode(date()) is faster than date() date() date() 181 if (isset($params['time']) && is_array($params['time'])) { 182 if (isset($params['time'][$prefix . 'Year'])) { 183 // $_REQUEST[$field_array] given 184 foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) { 185 $_variableName = '_' . strtolower($_elementName); 186 $$_variableName = isset($params['time'][$prefix . $_elementName]) 187 ? $params['time'][$prefix . $_elementName] 188 : date($_elementKey); 189 } 190 $time = mktime(0, 0, 0, $_month, $_day, $_year); 191 } elseif (isset($params['time'][$field_array][$prefix . 'Year'])) { 192 // $_REQUEST given 193 foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) { 194 $_variableName = '_' . strtolower($_elementName); 195 $$_variableName = isset($params['time'][$field_array][$prefix . $_elementName]) 196 ? $params['time'][$field_array][$prefix . $_elementName] 197 : date($_elementKey); 198 } 199 $time = mktime(0, 0, 0, $_month, $_day, $_year); 200 } else { 201 // no date found, use NOW 202 list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d')); 203 } 204 } elseif ($time === null) { 205 if (array_key_exists('time', $params)) { 206 $_year = $_month = $_day = $time = null; 207 } else { 208 list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d')); 209 } 143 210 } else { 144 // use smarty_make_timestamp to get an unix timestamp and 145 // strftime to make yyyy-mm-dd 146 $time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); 147 } 148 // Now split this in pieces, which later can be used to set the select 149 $time = explode("-", $time); 150 151 // make syntax "+N" or "-N" work with start_year and end_year 152 if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { 153 if ($match[1] == '+') { 154 $end_year = strftime('%Y') + $match[2]; 211 list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d', $time)); 212 } 213 214 // make syntax "+N" or "-N" work with $start_year and $end_year 215 // Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr 216 foreach (array('start', 'end') as $key) { 217 $key .= '_year'; 218 $t = $$key; 219 if ($t === null) { 220 $$key = (int)$_current_year; 221 } else if ($t[0] == '+') { 222 $$key = (int)($_current_year + trim(substr($t, 1))); 223 } else if ($t[0] == '-') { 224 $$key = (int)($_current_year - trim(substr($t, 1))); 155 225 } else { 156 $end_year = strftime('%Y') - $match[2]; 157 } 158 } 159 if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) { 160 if ($match[1] == '+') { 161 $start_year = strftime('%Y') + $match[2]; 226 $$key = (int)$$key; 227 } 228 } 229 230 // flip for ascending or descending 231 if (($start_year > $end_year && !$reverse_years) || ($start_year < $end_year && $reverse_years)) { 232 $t = $end_year; 233 $end_year = $start_year; 234 $start_year = $t; 235 } 236 237 // generate year <select> or <input> 238 if ($display_years) { 239 $_html_years = ''; 240 $_extra = ''; 241 $_name = $field_array ? ($field_array . '[' . $prefix . 'Year]') : ($prefix . 'Year'); 242 if ($all_extra) { 243 $_extra .= ' ' . $all_extra; 244 } 245 if ($year_extra) { 246 $_extra .= ' ' . $year_extra; 247 } 248 249 if ($year_as_text) { 250 $_html_years = '<input type="text" name="' . $_name . '" value="' . $_year . '" size="4" maxlength="4"' . $_extra . $extra_attrs . ' />'; 162 251 } else { 163 $start_year = strftime('%Y') - $match[2]; 164 } 165 } 166 if (strlen($time[0]) > 0) { 167 if ($start_year > $time[0] && !isset($params['start_year'])) { 168 // force start year to include given date if not explicitly set 169 $start_year = $time[0]; 170 } 171 if($end_year < $time[0] && !isset($params['end_year'])) { 172 // force end year to include given date if not explicitly set 173 $end_year = $time[0]; 174 } 175 } 176 177 $field_order = strtoupper($field_order); 178 179 $html_result = $month_result = $day_result = $year_result = ""; 180 181 $field_separator_count = -1; 252 $_html_years = '<select name="' . $_name . '"'; 253 if ($year_id !== null || $all_id !== null) { 254 $_html_years .= ' id="' . smarty_function_escape_special_chars( 255 $year_id !== null ? ( $year_id ? $year_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name ) 256 ) . '"'; 257 } 258 if ($year_size) { 259 $_html_years .= ' size="' . $year_size . '"'; 260 } 261 $_html_years .= $_extra . $extra_attrs . '>' . $option_separator; 262 263 if (isset($year_empty) || isset($all_empty)) { 264 $_html_years .= '<option value="">' . ( isset($year_empty) ? $year_empty : $all_empty ) . '</option>' . $option_separator; 265 } 266 267 $op = $start_year > $end_year ? -1 : 1; 268 for ($i=$start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) { 269 $_html_years .= '<option value="' . $i . '"' 270 . ($_year == $i ? ' selected="selected"' : '') 271 . '>' . $i . '</option>' . $option_separator; 272 } 273 274 $_html_years .= '</select>'; 275 } 276 } 277 278 // generate month <select> or <input> 182 279 if ($display_months) { 183 $field_separator_count++; 184 $month_names = array(); 185 $month_values = array(); 186 if(isset($month_empty)) { 187 $month_names[''] = $month_empty; 188 $month_values[''] = ''; 189 } 280 $_html_month = ''; 281 $_extra = ''; 282 $_name = $field_array ? ($field_array . '[' . $prefix . 'Month]') : ($prefix . 'Month'); 283 if ($all_extra) { 284 $_extra .= ' ' . $all_extra; 285 } 286 if ($month_extra) { 287 $_extra .= ' ' . $month_extra; 288 } 289 290 $_html_months = '<select name="' . $_name . '"'; 291 if ($month_id !== null || $all_id !== null) { 292 $_html_months .= ' id="' . smarty_function_escape_special_chars( 293 $month_id !== null ? ( $month_id ? $month_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name ) 294 ) . '"'; 295 } 296 if ($month_size) { 297 $_html_months .= ' size="' . $month_size . '"'; 298 } 299 $_html_months .= $_extra . $extra_attrs . '>' . $option_separator; 300 301 if (isset($month_empty) || isset($all_empty)) { 302 $_html_months .= '<option value="">' . ( isset($month_empty) ? $month_empty : $all_empty ) . '</option>' . $option_separator; 303 } 304 190 305 for ($i = 1; $i <= 12; $i++) { 191 $month_names[$i] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); 192 $month_values[$i] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000)); 193 } 194 195 $month_result .= '<select name='; 196 if (null !== $field_array){ 197 $month_result .= '"' . $field_array . '[' . $prefix . 'Month]"'; 198 } else { 199 $month_result .= '"' . $prefix . 'Month"'; 200 } 201 if (null !== $month_size){ 202 $month_result .= ' size="' . $month_size . '"'; 203 } 204 if (null !== $month_extra){ 205 $month_result .= ' ' . $month_extra; 206 } 207 if (null !== $all_extra){ 208 $month_result .= ' ' . $all_extra; 209 } 210 $month_result .= $extra_attrs . '>'."\n"; 211 212 $month_result .= smarty_function_html_options(array('output' => $month_names, 213 'values' => $month_values, 214 'selected' => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '', 215 'print_result' => false), 216 $smarty); 217 $month_result .= '</select>'; 218 } 219 306 $_val = sprintf('%02d', $i); 307 $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[$i]) : ($month_format == "%m" ? $_val : strftime($month_format, $_month_timestamps[$i])); 308 $_value = $month_value_format == "%m" ? $_val : strftime($month_value_format, $_month_timestamps[$i]); 309 $_html_months .= '<option value="' . $_value . '"' 310 . ($_val == $_month ? ' selected="selected"' : '') 311 . '>' . $_text . '</option>' . $option_separator; 312 } 313 314 $_html_months .= '</select>'; 315 } 316 317 // generate day <select> or <input> 220 318 if ($display_days) { 221 $field_separator_count++; 222 $days = array(); 223 if (isset($day_empty)) { 224 $days[''] = $day_empty; 225 $day_values[''] = ''; 226 } 319 $_html_day = ''; 320 $_extra = ''; 321 $_name = $field_array ? ($field_array . '[' . $prefix . 'Day]') : ($prefix . 'Day'); 322 if ($all_extra) { 323 $_extra .= ' ' . $all_extra; 324 } 325 if ($day_extra) { 326 $_extra .= ' ' . $day_extra; 327 } 328 329 $_html_days = '<select name="' . $_name . '"'; 330 if ($day_id !== null || $all_id !== null) { 331 $_html_days .= ' id="' . smarty_function_escape_special_chars( 332 $day_id !== null ? ( $day_id ? $day_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name ) 333 ) . '"'; 334 } 335 if ($day_size) { 336 $_html_days .= ' size="' . $day_size . '"'; 337 } 338 $_html_days .= $_extra . $extra_attrs . '>' . $option_separator; 339 340 if (isset($day_empty) || isset($all_empty)) { 341 $_html_days .= '<option value="">' . ( isset($day_empty) ? $day_empty : $all_empty ) . '</option>' . $option_separator; 342 } 343 227 344 for ($i = 1; $i <= 31; $i++) { 228 $days[] = sprintf($day_format, $i); 229 $day_values[] = sprintf($day_value_format, $i); 230 } 231 232 $day_result .= '<select name='; 233 if (null !== $field_array){ 234 $day_result .= '"' . $field_array . '[' . $prefix . 'Day]"'; 235 } else { 236 $day_result .= '"' . $prefix . 'Day"'; 237 } 238 if (null !== $day_size){ 239 $day_result .= ' size="' . $day_size . '"'; 240 } 241 if (null !== $all_extra){ 242 $day_result .= ' ' . $all_extra; 243 } 244 if (null !== $day_extra){ 245 $day_result .= ' ' . $day_extra; 246 } 247 $day_result .= $extra_attrs . '>'."\n"; 248 $day_result .= smarty_function_html_options(array('output' => $days, 249 'values' => $day_values, 250 'selected' => $time[2], 251 'print_result' => false), 252 $smarty); 253 $day_result .= '</select>'; 254 } 255 256 if ($display_years) { 257 $field_separator_count++; 258 if (null !== $field_array){ 259 $year_name = $field_array . '[' . $prefix . 'Year]'; 260 } else { 261 $year_name = $prefix . 'Year'; 262 } 263 if ($year_as_text) { 264 $year_result .= '<input type="text" name="' . $year_name . '" value="' . $time[0] . '" size="4" maxlength="4"'; 265 if (null !== $all_extra){ 266 $year_result .= ' ' . $all_extra; 267 } 268 if (null !== $year_extra){ 269 $year_result .= ' ' . $year_extra; 270 } 271 $year_result .= '>'; 272 } else { 273 $years = range((int)$start_year, (int)$end_year); 274 if ($reverse_years) { 275 rsort($years, SORT_NUMERIC); 276 } else { 277 sort($years, SORT_NUMERIC); 278 } 279 $yearvals = $years; 280 if(isset($year_empty)) { 281 array_unshift($years, $year_empty); 282 array_unshift($yearvals, ''); 283 } 284 $year_result .= '<select name="' . $year_name . '"'; 285 if (null !== $year_size){ 286 $year_result .= ' size="' . $year_size . '"'; 287 } 288 if (null !== $all_extra){ 289 $year_result .= ' ' . $all_extra; 290 } 291 if (null !== $year_extra){ 292 $year_result .= ' ' . $year_extra; 293 } 294 $year_result .= $extra_attrs . '>'."\n"; 295 $year_result .= smarty_function_html_options(array('output' => $years, 296 'values' => $yearvals, 297 'selected' => $time[0], 298 'print_result' => false), 299 $smarty); 300 $year_result .= '</select>'; 301 } 302 } 303 304 // Loop thru the field_order field 305 for ($i = 0; $i <= 2; $i++){ 306 $c = substr($field_order, $i, 1); 307 switch ($c){ 345 $_val = sprintf('%02d', $i); 346 $_text = $day_format == '%02d' ? $_val : sprintf($day_format, $i); 347 $_value = $day_value_format == '%02d' ? $_val : sprintf($day_value_format, $i); 348 $_html_days .= '<option value="' . $_value . '"' 349 . ($_val == $_day ? ' selected="selected"' : '') 350 . '>' . $_text . '</option>' . $option_separator; 351 } 352 353 $_html_days .= '</select>'; 354 } 355 356 // order the fields for output 357 $_html = ''; 358 for ($i=0; $i <= 2; $i++) { 359 switch ($field_order[$i]) { 360 case 'Y': 361 case 'y': 362 if (isset($_html_years)) { 363 if ($_html) { 364 $_html .= $field_separator; 365 } 366 $_html .= $_html_years; 367 } 368 break; 369 370 case 'm': 371 case 'M': 372 if (isset($_html_months)) { 373 if ($_html) { 374 $_html .= $field_separator; 375 } 376 $_html .= $_html_months; 377 } 378 break; 379 380 case 'd': 308 381 case 'D': 309 $html_result .= $day_result; 310 break; 311 312 case 'M': 313 $html_result .= $month_result; 314 break; 315 316 case 'Y': 317 $html_result .= $year_result; 318 break; 319 } 320 // Add the field seperator 321 if($i < $field_separator_count) { 322 $html_result .= $field_separator; 323 } 324 } 325 326 return $html_result; 382 if (isset($_html_days)) { 383 if ($_html) { 384 $_html .= $field_separator; 385 } 386 $_html .= $_html_days; 387 } 388 break; 389 } 390 } 391 return $_html; 327 392 } 328 393 329 /* vim: set expandtab: */330 331 394 ?> -
trunk/include/smarty/libs/plugins/function.html_select_time.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 9 /** 10 * @ignore 11 */ 12 require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 13 /** 14 * @ignore 15 */ 16 require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); 8 17 9 18 /** … … 13 22 * Name: html_select_time<br> 14 23 * Purpose: Prints the dropdowns for time selection 15 * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time} 24 * 25 * @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time} 16 26 * (Smarty online manual) 17 27 * @author Roberto Berto <roberto@berto.net> 18 * @ creditsMonte Ohrt <monte AT ohrt DOT com>19 * @param array 20 * @param Smarty 28 * @author Monte Ohrt <monte AT ohrt DOT com> 29 * @param array $params parameters 30 * @param Smarty_Internal_Template $template template object 21 31 * @return string 22 32 * @uses smarty_make_timestamp() 23 33 */ 24 function smarty_function_html_select_time($params, &$smarty)34 function smarty_function_html_select_time($params, $template) 25 35 { 26 require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); 27 require_once $smarty->_get_plugin_filepath('function','html_options'); 28 /* Default values. */ 29 $prefix = "Time_"; 30 $time = time(); 31 $display_hours = true; 32 $display_minutes = true; 33 $display_seconds = true; 34 $display_meridian = true; 35 $use_24_hours = true; 36 $minute_interval = 1; 37 $second_interval = 1; 38 /* Should the select boxes be part of an array when returned from PHP? 39 e.g. setting it to "birthday", would create "birthday[Hour]", 40 "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]". 41 Can be combined with prefix. */ 42 $field_array = null; 43 $all_extra = null; 44 $hour_extra = null; 45 $minute_extra = null; 46 $second_extra = null; 47 $meridian_extra = null; 48 49 foreach ($params as $_key=>$_value) { 36 $prefix = "Time_"; 37 $field_array = null; 38 $field_separator = "\n"; 39 $option_separator = "\n"; 40 $time = null; 41 42 $display_hours = true; 43 $display_minutes = true; 44 $display_seconds = true; 45 $display_meridian = true; 46 47 $hour_format = '%02d'; 48 $hour_value_format = '%02d'; 49 $minute_format = '%02d'; 50 $minute_value_format = '%02d'; 51 $second_format = '%02d'; 52 $second_value_format = '%02d'; 53 54 $hour_size = null; 55 $minute_size = null; 56 $second_size = null; 57 $meridian_size = null; 58 59 $all_empty = null; 60 $hour_empty = null; 61 $minute_empty = null; 62 $second_empty = null; 63 $meridian_empty = null; 64 65 $all_id = null; 66 $hour_id = null; 67 $minute_id = null; 68 $second_id = null; 69 $meridian_id = null; 70 71 $use_24_hours = true; 72 $minute_interval = 1; 73 $second_interval = 1; 74 75 $extra_attrs = ''; 76 $all_extra = null; 77 $hour_extra = null; 78 $minute_extra = null; 79 $second_extra = null; 80 $meridian_extra = null; 81 82 foreach ($params as $_key => $_value) { 50 83 switch ($_key) { 84 case 'time': 85 if (!is_array($_value) && $_value !== null) { 86 $time = smarty_make_timestamp($_value); 87 } 88 break; 89 51 90 case 'prefix': 52 case 'time':53 91 case 'field_array': 92 93 case 'field_separator': 94 case 'option_separator': 95 54 96 case 'all_extra': 55 97 case 'hour_extra': … … 57 99 case 'second_extra': 58 100 case 'meridian_extra': 101 102 case 'all_empty': 103 case 'hour_empty': 104 case 'minute_empty': 105 case 'second_empty': 106 case 'meridian_empty': 107 108 case 'all_id': 109 case 'hour_id': 110 case 'minute_id': 111 case 'second_id': 112 case 'meridian_id': 113 114 case 'hour_format': 115 case 'hour_value_format': 116 case 'minute_format': 117 case 'minute_value_format': 118 case 'second_format': 119 case 'second_value_format': 59 120 $$_key = (string)$_value; 60 121 break; … … 70 131 case 'minute_interval': 71 132 case 'second_interval': 133 134 case 'hour_size': 135 case 'minute_size': 136 case 'second_size': 137 case 'meridian_size': 72 138 $$_key = (int)$_value; 73 139 break; 74 140 75 141 default: 76 $smarty->trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING); 77 } 78 } 79 80 $time = smarty_make_timestamp($time); 81 82 $html_result = ''; 83 142 if (!is_array($_value)) { 143 $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; 144 } else { 145 trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 146 } 147 break; 148 } 149 } 150 151 if (isset($params['time']) && is_array($params['time'])) { 152 if (isset($params['time'][$prefix . 'Hour'])) { 153 // $_REQUEST[$field_array] given 154 foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) { 155 $_variableName = '_' . strtolower($_elementName); 156 $$_variableName = isset($params['time'][$prefix . $_elementName]) 157 ? $params['time'][$prefix . $_elementName] 158 : date($_elementKey); 159 } 160 $_meridian = isset($params['time'][$prefix . 'Meridian']) 161 ? (' ' . $params['time'][$prefix . 'Meridian']) 162 : ''; 163 $time = strtotime( $_hour . ':' . $_minute . ':' . $_second . $_meridian ); 164 list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); 165 } elseif (isset($params['time'][$field_array][$prefix . 'Hour'])) { 166 // $_REQUEST given 167 foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) { 168 $_variableName = '_' . strtolower($_elementName); 169 $$_variableName = isset($params['time'][$field_array][$prefix . $_elementName]) 170 ? $params['time'][$field_array][$prefix . $_elementName] 171 : date($_elementKey); 172 } 173 $_meridian = isset($params['time'][$field_array][$prefix . 'Meridian']) 174 ? (' ' . $params['time'][$field_array][$prefix . 'Meridian']) 175 : ''; 176 $time = strtotime( $_hour . ':' . $_minute . ':' . $_second . $_meridian ); 177 list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); 178 } else { 179 // no date found, use NOW 180 list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d')); 181 } 182 } elseif ($time === null) { 183 if (array_key_exists('time', $params)) { 184 $_hour = $_minute = $_second = $time = null; 185 } else { 186 list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s')); 187 } 188 } else { 189 list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); 190 } 191 192 // generate hour <select> 84 193 if ($display_hours) { 85 $hours = $use_24_hours ? range(0, 23) : range(1, 12); 86 $hour_fmt = $use_24_hours ? '%H' : '%I'; 87 for ($i = 0, $for_max = count($hours); $i < $for_max; $i++) 88 $hours[$i] = sprintf('%02d', $hours[$i]); 89 $html_result .= '<select name='; 90 if (null !== $field_array) { 91 $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"'; 92 } else { 93 $html_result .= '"' . $prefix . 'Hour"'; 94 } 95 if (null !== $hour_extra){ 96 $html_result .= ' ' . $hour_extra; 97 } 98 if (null !== $all_extra){ 99 $html_result .= ' ' . $all_extra; 100 } 101 $html_result .= '>'."\n"; 102 $html_result .= smarty_function_html_options(array('output' => $hours, 103 'values' => $hours, 104 'selected' => strftime($hour_fmt, $time), 105 'print_result' => false), 106 $smarty); 107 $html_result .= "</select>\n"; 108 } 109 194 $_html_hours = ''; 195 $_extra = ''; 196 $_name = $field_array ? ($field_array . '[' . $prefix . 'Hour]') : ($prefix . 'Hour'); 197 if ($all_extra) { 198 $_extra .= ' ' . $all_extra; 199 } 200 if ($hour_extra) { 201 $_extra .= ' ' . $hour_extra; 202 } 203 204 $_html_hours = '<select name="' . $_name . '"'; 205 if ($hour_id !== null || $all_id !== null) { 206 $_html_hours .= ' id="' . smarty_function_escape_special_chars( 207 $hour_id !== null ? ( $hour_id ? $hour_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name ) 208 ) . '"'; 209 } 210 if ($hour_size) { 211 $_html_hours .= ' size="' . $hour_size . '"'; 212 } 213 $_html_hours .= $_extra . $extra_attrs . '>' . $option_separator; 214 215 if (isset($hour_empty) || isset($all_empty)) { 216 $_html_hours .= '<option value="">' . ( isset($hour_empty) ? $hour_empty : $all_empty ) . '</option>' . $option_separator; 217 } 218 219 $start = $use_24_hours ? 0 : 1; 220 $end = $use_24_hours ? 23 : 12; 221 for ($i=$start; $i <= $end; $i++) { 222 $_val = sprintf('%02d', $i); 223 $_text = $hour_format == '%02d' ? $_val : sprintf($hour_format, $i); 224 $_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i); 225 226 if (!$use_24_hours) { 227 $_hour12 = $_hour == 0 228 ? 12 229 : ($_hour <= 12 ? $_hour : $_hour -12); 230 } 231 232 $selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null; 233 $_html_hours .= '<option value="' . $_value . '"' 234 . ($selected ? ' selected="selected"' : '') 235 . '>' . $_text . '</option>' . $option_separator; 236 } 237 238 $_html_hours .= '</select>'; 239 } 240 241 // generate minute <select> 110 242 if ($display_minutes) { 111 $all_minutes = range(0, 59); 112 for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval) 113 $minutes[] = sprintf('%02d', $all_minutes[$i]); 114 $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval); 115 $html_result .= '<select name='; 116 if (null !== $field_array) { 117 $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"'; 118 } else { 119 $html_result .= '"' . $prefix . 'Minute"'; 120 } 121 if (null !== $minute_extra){ 122 $html_result .= ' ' . $minute_extra; 123 } 124 if (null !== $all_extra){ 125 $html_result .= ' ' . $all_extra; 126 } 127 $html_result .= '>'."\n"; 128 129 $html_result .= smarty_function_html_options(array('output' => $minutes, 130 'values' => $minutes, 131 'selected' => $selected, 132 'print_result' => false), 133 $smarty); 134 $html_result .= "</select>\n"; 135 } 136 243 $_html_minutes = ''; 244 $_extra = ''; 245 $_name = $field_array ? ($field_array . '[' . $prefix . 'Minute]') : ($prefix . 'Minute'); 246 if ($all_extra) { 247 $_extra .= ' ' . $all_extra; 248 } 249 if ($minute_extra) { 250 $_extra .= ' ' . $minute_extra; 251 } 252 253 $_html_minutes = '<select name="' . $_name . '"'; 254 if ($minute_id !== null || $all_id !== null) { 255 $_html_minutes .= ' id="' . smarty_function_escape_special_chars( 256 $minute_id !== null ? ( $minute_id ? $minute_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name ) 257 ) . '"'; 258 } 259 if ($minute_size) { 260 $_html_minutes .= ' size="' . $minute_size . '"'; 261 } 262 $_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator; 263 264 if (isset($minute_empty) || isset($all_empty)) { 265 $_html_minutes .= '<option value="">' . ( isset($minute_empty) ? $minute_empty : $all_empty ) . '</option>' . $option_separator; 266 } 267 268 $selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null; 269 for ($i=0; $i <= 59; $i += $minute_interval) { 270 $_val = sprintf('%02d', $i); 271 $_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i); 272 $_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i); 273 $_html_minutes .= '<option value="' . $_value . '"' 274 . ($selected === $i ? ' selected="selected"' : '') 275 . '>' . $_text . '</option>' . $option_separator; 276 } 277 278 $_html_minutes .= '</select>'; 279 } 280 281 // generate second <select> 137 282 if ($display_seconds) { 138 $all_seconds = range(0, 59); 139 for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval) 140 $seconds[] = sprintf('%02d', $all_seconds[$i]); 141 $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval); 142 $html_result .= '<select name='; 143 if (null !== $field_array) { 144 $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"'; 145 } else { 146 $html_result .= '"' . $prefix . 'Second"'; 147 } 148 149 if (null !== $second_extra){ 150 $html_result .= ' ' . $second_extra; 151 } 152 if (null !== $all_extra){ 153 $html_result .= ' ' . $all_extra; 154 } 155 $html_result .= '>'."\n"; 156 157 $html_result .= smarty_function_html_options(array('output' => $seconds, 158 'values' => $seconds, 159 'selected' => $selected, 160 'print_result' => false), 161 $smarty); 162 $html_result .= "</select>\n"; 163 } 164 283 $_html_seconds = ''; 284 $_extra = ''; 285 $_name = $field_array ? ($field_array . '[' . $prefix . 'Second]') : ($prefix . 'Second'); 286 if ($all_extra) { 287 $_extra .= ' ' . $all_extra; 288 } 289 if ($second_extra) { 290 $_extra .= ' ' . $second_extra; 291 } 292 293 $_html_seconds = '<select name="' . $_name . '"'; 294 if ($second_id !== null || $all_id !== null) { 295 $_html_seconds .= ' id="' . smarty_function_escape_special_chars( 296 $second_id !== null ? ( $second_id ? $second_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name ) 297 ) . '"'; 298 } 299 if ($second_size) { 300 $_html_seconds .= ' size="' . $second_size . '"'; 301 } 302 $_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator; 303 304 if (isset($second_empty) || isset($all_empty)) { 305 $_html_seconds .= '<option value="">' . ( isset($second_empty) ? $second_empty : $all_empty ) . '</option>' . $option_separator; 306 } 307 308 $selected = $_second !== null ? ($_second - $_second % $second_interval) : null; 309 for ($i=0; $i <= 59; $i += $second_interval) { 310 $_val = sprintf('%02d', $i); 311 $_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i); 312 $_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i); 313 $_html_seconds .= '<option value="' . $_value . '"' 314 . ($selected === $i ? ' selected="selected"' : '') 315 . '>' . $_text . '</option>' . $option_separator; 316 } 317 318 $_html_seconds .= '</select>'; 319 } 320 321 // generate meridian <select> 165 322 if ($display_meridian && !$use_24_hours) { 166 $html_result .= '<select name='; 167 if (null !== $field_array) { 168 $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"'; 169 } else { 170 $html_result .= '"' . $prefix . 'Meridian"'; 171 } 172 173 if (null !== $meridian_extra){ 174 $html_result .= ' ' . $meridian_extra; 175 } 176 if (null !== $all_extra){ 177 $html_result .= ' ' . $all_extra; 178 } 179 $html_result .= '>'."\n"; 180 181 $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'), 182 'values' => array('am', 'pm'), 183 'selected' => strtolower(strftime('%p', $time)), 184 'print_result' => false), 185 $smarty); 186 $html_result .= "</select>\n"; 187 } 188 189 return $html_result; 323 $_html_meridian = ''; 324 $_extra = ''; 325 $_name = $field_array ? ($field_array . '[' . $prefix . 'Meridian]') : ($prefix . 'Meridian'); 326 if ($all_extra) { 327 $_extra .= ' ' . $all_extra; 328 } 329 if ($meridian_extra) { 330 $_extra .= ' ' . $meridian_extra; 331 } 332 333 $_html_meridian = '<select name="' . $_name . '"'; 334 if ($meridian_id !== null || $all_id !== null) { 335 $_html_meridian .= ' id="' . smarty_function_escape_special_chars( 336 $meridian_id !== null ? ( $meridian_id ? $meridian_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name ) 337 ) . '"'; 338 } 339 if ($meridian_size) { 340 $_html_meridian .= ' size="' . $meridian_size . '"'; 341 } 342 $_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator; 343 344 if (isset($meridian_empty) || isset($all_empty)) { 345 $_html_meridian .= '<option value="">' . ( isset($meridian_empty) ? $meridian_empty : $all_empty ) . '</option>' . $option_separator; 346 } 347 348 $_html_meridian .= '<option value="am"'. ($_hour < 12 ? ' selected="selected"' : '') .'>AM</option>' . $option_separator 349 . '<option value="pm"'. ($_hour < 12 ? '' : ' selected="selected"') .'>PM</option>' . $option_separator 350 . '</select>'; 351 } 352 353 $_html = ''; 354 foreach (array('_html_hours', '_html_minutes', '_html_seconds', '_html_meridian') as $k) { 355 if (isset($$k)) { 356 if ($_html) { 357 $_html .= $field_separator; 358 } 359 $_html .= $$k; 360 } 361 } 362 363 return $_html; 190 364 } 191 365 192 /* vim: set expandtab: */193 194 366 ?> -
trunk/include/smarty/libs/plugins/function.html_table.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 8 9 9 /** … … 14 14 * Date: Feb 17, 2003<br> 15 15 * Purpose: make an html table from an array of data<br> 16 * Input:<br>17 * - loop = array to loop through18 * - cols = number of columns, comma separated list of column names19 * or arrayof column names20 * - rows = number of rows21 * - table_attr = table attributes22 * - th_attr = table heading attributes (arrays are cycled)23 * - tr_attr = table rowattributes (arrays are cycled)24 * - td_attr = table cellattributes (arrays are cycled)25 * - trailpad = value to pad trailing cells with26 * - caption = text for caption element27 * - vdir = vertical direction (default: "down", means top-to-bottom)28 * - hdir = horizontal direction (default: "right", means left-to-right)29 * - inner = inner loop (default "cols": print $loop line by line,30 * $loop will be printed column by column otherwise)31 * 32 * 16 * Params: 17 * <pre> 18 * - loop - array to loop through 19 * - cols - number of columns, comma separated list of column names 20 * or array of column names 21 * - rows - number of rows 22 * - table_attr - table attributes 23 * - th_attr - table heading attributes (arrays are cycled) 24 * - tr_attr - table row attributes (arrays are cycled) 25 * - td_attr - table cell attributes (arrays are cycled) 26 * - trailpad - value to pad trailing cells with 27 * - caption - text for caption element 28 * - vdir - vertical direction (default: "down", means top-to-bottom) 29 * - hdir - horizontal direction (default: "right", means left-to-right) 30 * - inner - inner loop (default "cols": print $loop line by line, 31 * $loop will be printed column by column otherwise) 32 * </pre> 33 33 * Examples: 34 34 * <pre> … … 37 37 * {table loop=$data cols="first,second,third" tr_attr=$colors} 38 38 * </pre> 39 * @author Monte Ohrt <monte at ohrt dot com> 39 * 40 * @author Monte Ohrt <monte at ohrt dot com> 40 41 * @author credit to Messju Mohr <messju at lammfellpuschen dot de> 41 42 * @author credit to boots <boots dot smarty at yahoo dot com> 42 * @version 43 * @link http:// smarty.php.net/manual/en/language.function.html.table.php {html_table}43 * @version 1.1 44 * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table} 44 45 * (Smarty online manual) 45 * @param array 46 * @param Smarty 46 * @param array $params parameters 47 * @param Smarty_Internal_Template $template template object 47 48 * @return string 48 49 */ 49 function smarty_function_html_table($params, &$smarty)50 function smarty_function_html_table($params, $template) 50 51 { 51 52 $table_attr = 'border="1"'; … … 60 61 $inner = 'cols'; 61 62 $caption = ''; 63 $loop = null; 62 64 63 65 if (!isset($params['loop'])) { 64 $smarty->trigger_error("html_table: missing 'loop' parameter");66 trigger_error("html_table: missing 'loop' parameter",E_USER_WARNING); 65 67 return; 66 68 } 67 69 68 foreach ($params as $_key =>$_value) {70 foreach ($params as $_key => $_value) { 69 71 switch ($_key) { 70 72 case 'loop': … … 110 112 if (empty($params['rows'])) { 111 113 /* no rows specified */ 112 $rows = ceil($loop_count /$cols_count);114 $rows = ceil($loop_count / $cols_count); 113 115 } elseif (empty($params['cols'])) { 114 116 if (!empty($params['rows'])) { 115 117 /* no cols specified, but rows */ 116 $cols_count = ceil($loop_count /$rows);118 $cols_count = ceil($loop_count / $rows); 117 119 } 118 120 } … … 128 130 $output .= "<thead><tr>\n"; 129 131 130 for ($r =0; $r<$cols_count; $r++) {132 for ($r = 0; $r < $cols_count; $r++) { 131 133 $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>'; 132 134 $output .= $cols[$r]; … … 137 139 138 140 $output .= "<tbody>\n"; 139 for ($r =0; $r<$rows; $r++) {141 for ($r = 0; $r < $rows; $r++) { 140 142 $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n"; 141 $rx = ($vdir == 'down') ? $r*$cols_count : ($rows-1-$r)*$cols_count;143 $rx = ($vdir == 'down') ? $r * $cols_count : ($rows-1 - $r) * $cols_count; 142 144 143 for ($c =0; $c<$cols_count; $c++) {144 $x = ($hdir == 'right') ? $rx+$c : $rx+$cols_count-1-$c;145 if ($inner !='cols') {145 for ($c = 0; $c < $cols_count; $c++) { 146 $x = ($hdir == 'right') ? $rx + $c : $rx + $cols_count-1 - $c; 147 if ($inner != 'cols') { 146 148 /* shuffle x to loop over rows*/ 147 $x = floor($x /$cols_count) + ($x%$cols_count)*$rows;149 $x = floor($x / $cols_count) + ($x % $cols_count) * $rows; 148 150 } 149 151 150 if ($x <$loop_count) {152 if ($x < $loop_count) { 151 153 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n"; 152 154 } else { … … 158 160 $output .= "</tbody>\n"; 159 161 $output .= "</table>\n"; 160 162 161 163 return $output; 162 164 } 163 165 164 function smarty_function_html_table_cycle($name, $var, $no) { 165 if(!is_array($var)) { 166 function smarty_function_html_table_cycle($name, $var, $no) 167 { 168 if (!is_array($var)) { 166 169 $ret = $var; 167 170 } else { 168 171 $ret = $var[$no % count($var)]; 169 172 } 170 171 return ($ret) ? ' ' .$ret : '';173 174 return ($ret) ? ' ' . $ret : ''; 172 175 } 173 176 174 175 /* vim: set expandtab: */176 177 177 ?> -
trunk/include/smarty/libs/plugins/function.mailto.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 8 9 9 /** … … 13 13 * Name: mailto<br> 14 14 * Date: May 21, 2002 15 * Purpose: automate mailto address link creation, and optionally 16 * encode them.<br>17 * Input:<br>18 * - address =e-mail address19 * - text = (optional)text to display, default is address20 * - encode = (optional)can be one of:21 * * none : no encoding (default)22 * * javascript : encode with javascript23 * * javascript_charcode : encode with javascript charcode24 * * hex : encode with hexidecimal (no javascript)25 * - cc = (optional)address(es) to carbon copy26 * - bcc = (optional)address(es) to blind carbon copy27 * - subject = (optional)e-mail subject28 * - newsgroups = (optional)newsgroup(s) to post to29 * - followupto = (optional)address(es) to follow up to30 * - extra = (optional)extra tags for the href link31 * 15 * Purpose: automate mailto address link creation, and optionally encode them.<br> 16 * Params: 17 * <pre> 18 * - address - (required) - e-mail address 19 * - text - (optional) - text to display, default is address 20 * - encode - (optional) - can be one of: 21 * * none : no encoding (default) 22 * * javascript : encode with javascript 23 * * javascript_charcode : encode with javascript charcode 24 * * hex : encode with hexidecimal (no javascript) 25 * - cc - (optional) - address(es) to carbon copy 26 * - bcc - (optional) - address(es) to blind carbon copy 27 * - subject - (optional) - e-mail subject 28 * - newsgroups - (optional) - newsgroup(s) to post to 29 * - followupto - (optional) - address(es) to follow up to 30 * - extra - (optional) - extra tags for the href link 31 * </pre> 32 32 * Examples: 33 33 * <pre> … … 39 39 * {mailto address="me@domain.com" extra='class="mailto"'} 40 40 * </pre> 41 * @link http://smarty.php.net/manual/en/language.function.mailto.php {mailto} 41 * 42 * @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto} 42 43 * (Smarty online manual) 43 * @version 44 * @author 45 * @author 46 * @param array47 * @param Smarty48 * @return 44 * @version 1.2 45 * @author Monte Ohrt <monte at ohrt dot com> 46 * @author credits to Jason Sweat (added cc, bcc and subject functionality) 47 * @param array $params parameters 48 * @param Smarty_Internal_Template $template template object 49 * @return string 49 50 */ 50 function smarty_function_mailto($params, &$smarty)51 function smarty_function_mailto($params, $template) 51 52 { 53 static $_allowed_encoding = array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true); 52 54 $extra = ''; 53 55 54 56 if (empty($params['address'])) { 55 $smarty->trigger_error("mailto: missing 'address' parameter");57 trigger_error("mailto: missing 'address' parameter",E_USER_WARNING); 56 58 return; 57 59 } else { … … 60 62 61 63 $text = $address; 62 63 64 // netscape and mozilla do not decode %40 (@) in BCC field (bug?) 64 65 // so, don't encode it. 65 66 $search = array('%40', '%2C'); 66 $replace 67 $replace = array('@', ','); 67 68 $mail_parms = array(); 68 foreach ($params as $var =>$value) {69 foreach ($params as $var => $value) { 69 70 switch ($var) { 70 71 case 'cc': … … 72 73 case 'followupto': 73 74 if (!empty($value)) 74 $mail_parms[] = $var .'='.str_replace($search,$replace,rawurlencode($value));75 $mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value)); 75 76 break; 76 77 77 78 case 'subject': 78 79 case 'newsgroups': 79 $mail_parms[] = $var .'='.rawurlencode($value);80 $mail_parms[] = $var . '=' . rawurlencode($value); 80 81 break; 81 82 … … 88 89 } 89 90 90 $mail_parm_vals = ''; 91 for ($i=0; $i<count($mail_parms); $i++) { 92 $mail_parm_vals .= (0==$i) ? '?' : '&'; 93 $mail_parm_vals .= $mail_parms[$i]; 91 if ($mail_parms) { 92 $address .= '?' . join('&', $mail_parms); 94 93 } 95 $address .= $mail_parm_vals; 96 94 97 95 $encode = (empty($params['encode'])) ? 'none' : $params['encode']; 98 if (!i n_array($encode,array('javascript','javascript_charcode','hex','none'))) {99 $smarty->trigger_error("mailto: 'encode' parameter must be none, javascript or hex");96 if (!isset($_allowed_encoding[$encode])) { 97 trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", E_USER_WARNING); 100 98 return; 101 99 } 102 103 if ($encode == 'javascript' 104 $string = 'document.write(\'<a href="mailto:' .$address.'" '.$extra.'>'.$text.'</a>\');';100 // FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed! 101 if ($encode == 'javascript') { 102 $string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');'; 105 103 106 104 $js_encode = ''; 107 for ($x =0; $x < strlen($string); $x++) {105 for ($x = 0, $_length = strlen($string); $x < $_length; $x++) { 108 106 $js_encode .= '%' . bin2hex($string[$x]); 109 107 } 110 108 111 return '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>'; 109 return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>'; 110 } elseif ($encode == 'javascript_charcode') { 111 $string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>'; 112 112 113 } elseif ($encode == 'javascript_charcode' ) { 114 $string = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>'; 115 116 for($x = 0, $y = strlen($string); $x < $y; $x++ ) { 117 $ord[] = ord($string[$x]); 113 for($x = 0, $y = strlen($string); $x < $y; $x++) { 114 $ord[] = ord($string[$x]); 118 115 } 119 116 120 $_ret = "<script type=\"text/javascript\" language=\"javascript\">\n"; 121 $_ret .= "<!--\n"; 122 $_ret .= "{document.write(String.fromCharCode("; 123 $_ret .= implode(',',$ord); 124 $_ret .= "))"; 125 $_ret .= "}\n"; 126 $_ret .= "//-->\n"; 127 $_ret .= "</script>\n"; 128 117 $_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" 118 . "{document.write(String.fromCharCode(" 119 . implode(',', $ord) 120 . "))" 121 . "}\n" 122 . "</script>\n"; 123 129 124 return $_ret; 130 131 132 125 } elseif ($encode == 'hex') { 133 134 preg_match('!^(.*)(\?.*)$!',$address,$match); 135 if(!empty($match[2])) { 136 $smarty->trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript."); 126 preg_match('!^(.*)(\?.*)$!', $address, $match); 127 if (!empty($match[2])) { 128 trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.",E_USER_WARNING); 137 129 return; 138 130 } 139 131 $address_encode = ''; 140 for ($x =0; $x < strlen($address); $x++) {141 if (preg_match('!\w!',$address[$x])) {132 for ($x = 0, $_length = strlen($address); $x < $_length; $x++) { 133 if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[$x])) { 142 134 $address_encode .= '%' . bin2hex($address[$x]); 143 135 } else { … … 146 138 } 147 139 $text_encode = ''; 148 for ($x =0; $x < strlen($text); $x++) {149 $text_encode .= '&#x' . bin2hex($text[$x]) .';';140 for ($x = 0, $_length = strlen($text); $x < $_length; $x++) { 141 $text_encode .= '&#x' . bin2hex($text[$x]) . ';'; 150 142 } 151 143 152 144 $mailto = "mailto:"; 153 return '<a href="'.$mailto.$address_encode.'" '.$extra.'>'.$text_encode.'</a>'; 154 145 return '<a href="' . $mailto . $address_encode . '" ' . $extra . '>' . $text_encode . '</a>'; 155 146 } else { 156 147 // no encoding 157 return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>'; 158 148 return '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>'; 159 149 } 160 161 150 } 162 151 163 /* vim: set expandtab: */164 165 152 ?> -
trunk/include/smarty/libs/plugins/function.math.php
r3584 r23384 2 2 /** 3 3 * Smarty plugin 4 * 5 * This plugin is only for Smarty2 BC 4 6 * @package Smarty 5 * @subpackage plugins7 * @subpackage PluginsFunction 6 8 */ 7 8 9 9 10 /** … … 12 13 * Type: function<br> 13 14 * Name: math<br> 14 * Purpose: handle math computations in template<br> 15 * @link http://smarty.php.net/manual/en/language.function.math.php {math} 15 * Purpose: handle math computations in template 16 * 17 * @link http://www.smarty.net/manual/en/language.function.math.php {math} 16 18 * (Smarty online manual) 17 19 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param array 19 * @param Smarty 20 * @return string 20 * @param array $params parameters 21 * @param Smarty_Internal_Template $template template object 22 * @return string|null 21 23 */ 22 function smarty_function_math($params, &$smarty)24 function smarty_function_math($params, $template) 23 25 { 26 static $_allowed_funcs = array( 27 'int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, 28 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 29 'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true ,'tan' => true 30 ); 24 31 // be sure equation parameter is present 25 32 if (empty($params['equation'])) { 26 $smarty->trigger_error("math: missing equation parameter");33 trigger_error("math: missing equation parameter",E_USER_WARNING); 27 34 return; 28 35 } 29 36 30 // strip out backticks, not necessary for math 31 $equation = str_replace('`','',$params['equation']); 37 $equation = $params['equation']; 32 38 33 39 // make sure parenthesis are balanced 34 40 if (substr_count($equation,"(") != substr_count($equation,")")) { 35 $smarty->trigger_error("math: unbalanced parenthesis");41 trigger_error("math: unbalanced parenthesis",E_USER_WARNING); 36 42 return; 37 43 } 38 44 39 45 // match all vars in equation, make sure all are passed 40 preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]+)!",$equation, $match); 41 $allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10', 42 'max','min','pi','pow','rand','round','sin','sqrt','srand','tan'); 43 46 preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!",$equation, $match); 47 44 48 foreach($match[1] as $curr_var) { 45 if ($curr_var && !i n_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {46 $smarty->trigger_error("math: function call $curr_var not allowed");49 if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) { 50 trigger_error("math: function call $curr_var not allowed",E_USER_WARNING); 47 51 return; 48 52 } … … 53 57 // make sure value is not empty 54 58 if (strlen($val)==0) { 55 $smarty->trigger_error("math: parameter $key is empty");59 trigger_error("math: parameter $key is empty",E_USER_WARNING); 56 60 return; 57 61 } 58 62 if (!is_numeric($val)) { 59 $smarty->trigger_error("math: parameter $key: is not numeric");63 trigger_error("math: parameter $key: is not numeric",E_USER_WARNING); 60 64 return; 61 65 } … … 63 67 } 64 68 } 65 69 $smarty_math_result = null; 66 70 eval("\$smarty_math_result = ".$equation.";"); 67 71 … … 70 74 return $smarty_math_result; 71 75 } else { 72 $ smarty->assign($params['assign'],$smarty_math_result);76 $template->assign($params['assign'],$smarty_math_result); 73 77 } 74 78 } else { … … 76 80 printf($params['format'],$smarty_math_result); 77 81 } else { 78 $ smarty->assign($params['assign'],sprintf($params['format'],$smarty_math_result));82 $template->assign($params['assign'],sprintf($params['format'],$smarty_math_result)); 79 83 } 80 84 } 81 85 } 82 86 83 /* vim: set expandtab: */84 85 87 ?> -
trunk/include/smarty/libs/plugins/modifier.capitalize.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsModifier 6 7 */ 7 8 8 9 9 /** 10 10 * Smarty capitalize modifier plugin 11 * 11 * 12 12 * Type: modifier<br> 13 13 * Name: capitalize<br> 14 14 * Purpose: capitalize words in the string 15 * @link http://smarty.php.net/manual/en/language.modifiers.php#LANGUAGE.MODIFIER.CAPITALIZE 16 * capitalize (Smarty online manual) 17 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param string 19 * @return string 15 * 16 * {@internal {$string|capitalize:true:true} is the fastest option for MBString enabled systems }} 17 * 18 * @param string $string string to capitalize 19 * @param boolean $uc_digits also capitalize "x123" to "X123" 20 * @param boolean $lc_rest capitalize first letters, lowercase all following letters "aAa" to "Aaa" 21 * @return string capitalized string 22 * @author Monte Ohrt <monte at ohrt dot com> 23 * @author Rodney Rehm 20 24 */ 21 function smarty_modifier_capitalize($string, $uc_digits = false )25 function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = false) 22 26 { 23 smarty_modifier_capitalize_ucfirst(null, $uc_digits); 24 return preg_replace_callback('!\'?\b\w(\w|\')*\b!', 'smarty_modifier_capitalize_ucfirst', $string); 25 } 26 27 function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null) 28 { 29 static $_uc_digits = false; 30 31 if(isset($uc_digits)) { 32 $_uc_digits = $uc_digits; 33 return; 27 if (Smarty::$_MBSTRING) { 28 if ($lc_rest) { 29 // uppercase (including hyphenated words) 30 $upper_string = mb_convert_case( $string, MB_CASE_TITLE, Smarty::$_CHARSET ); 31 } else { 32 // uppercase word breaks 33 $upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!eS" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').mb_convert_case(stripslashes('\\2'),MB_CASE_UPPER, '" . addslashes(Smarty::$_CHARSET) . "')", $string); 34 } 35 // check uc_digits case 36 if (!$uc_digits) { 37 if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) { 38 foreach($matches[1] as $match) { 39 $upper_string = substr_replace($upper_string, mb_strtolower($match[0], Smarty::$_CHARSET), $match[1], strlen($match[0])); 40 } 41 } 42 } 43 $upper_string = preg_replace("!((^|\s)['\"])(\w)!e" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').mb_convert_case(stripslashes('\\3'),MB_CASE_UPPER, '" . addslashes(Smarty::$_CHARSET) . "')", $upper_string); 44 return $upper_string; 34 45 } 35 46 36 if(substr($string[0],0,1) != "'" && !preg_match("!\d!",$string[0]) || $_uc_digits) 37 return ucfirst($string[0]); 38 else 39 return $string[0]; 40 } 41 47 // lowercase first 48 if ($lc_rest) { 49 $string = strtolower($string); 50 } 51 // uppercase (including hyphenated words) 52 $upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!eS" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').ucfirst(stripslashes('\\2'))", $string); 53 // check uc_digits case 54 if (!$uc_digits) { 55 if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) { 56 foreach($matches[1] as $match) { 57 $upper_string = substr_replace($upper_string, strtolower($match[0]), $match[1], strlen($match[0])); 58 } 59 } 60 } 61 $upper_string = preg_replace("!((^|\s)['\"])(\w)!e" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').strtoupper(stripslashes('\\3'))", $upper_string); 62 return $upper_string; 63 } 42 64 43 65 ?> -
trunk/include/smarty/libs/plugins/modifier.date_format.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsModifier 6 7 */ 7 8 8 9 /** 9 * Include the {@link shared.make_timestamp.php} plugin10 */11 require_once $smarty->_get_plugin_filepath('shared', 'make_timestamp');12 /**13 10 * Smarty date_format modifier plugin 14 * 11 * 15 12 * Type: modifier<br> 16 13 * Name: date_format<br> 17 14 * Purpose: format datestamps via strftime<br> 18 15 * Input:<br> 19 * - string: input date string 20 * - format: strftime format for output 21 * - default_date: default date if $string is empty 22 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php 23 * date_format (Smarty online manual) 24 * @author Monte Ohrt <monte at ohrt dot com> 25 * @param string 26 * @param string 27 * @param string 28 * @return string|void 16 * - string: input date string 17 * - format: strftime format for output 18 * - default_date: default date if $string is empty 19 * 20 * @link http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual) 21 * @author Monte Ohrt <monte at ohrt dot com> 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 * @return string |void 29 27 * @uses smarty_make_timestamp() 30 28 */ 31 function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')29 function smarty_modifier_date_format($string, $format=null, $default_date='', $formatter='auto') 32 30 { 33 if ($string != '') { 31 if ($format === null) { 32 $format = Smarty::$_DATE_FORMAT; 33 } 34 /** 35 * Include the {@link shared.make_timestamp.php} plugin 36 */ 37 require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); 38 if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') { 34 39 $timestamp = smarty_make_timestamp($string); 35 40 } elseif ($default_date != '') { … … 37 42 } else { 38 43 return; 44 } 45 if($formatter=='strftime'||($formatter=='auto'&&strpos($format,'%')!==false)) { 46 if (DS == '\\') { 47 $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); 48 $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); 49 if (strpos($format, '%e') !== false) { 50 $_win_from[] = '%e'; 51 $_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); 52 } 53 if (strpos($format, '%l') !== false) { 54 $_win_from[] = '%l'; 55 $_win_to[] = sprintf('%\' 2d', date('h', $timestamp)); 56 } 57 $format = str_replace($_win_from, $_win_to, $format); 58 } 59 return strftime($format, $timestamp); 60 } else { 61 return date($format, $timestamp); 39 62 } 40 if (DIRECTORY_SEPARATOR == '\\') { 41 $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); 42 $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); 43 if (strpos($format, '%e') !== false) { 44 $_win_from[] = '%e'; 45 $_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); 46 } 47 if (strpos($format, '%l') !== false) { 48 $_win_from[] = '%l'; 49 $_win_to[] = sprintf('%\' 2d', date('h', $timestamp)); 50 } 51 $format = str_replace($_win_from, $_win_to, $format); 52 } 53 return strftime($format, $timestamp); 54 } 55 56 /* vim: set expandtab: */ 63 } 57 64 58 65 ?> -
trunk/include/smarty/libs/plugins/modifier.debug_print_var.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage Debug 6 7 */ 7 8 8 9 9 /** 10 10 * Smarty debug_print_var modifier plugin 11 * 11 * 12 12 * Type: modifier<br> 13 13 * Name: debug_print_var<br> 14 14 * Purpose: formats variable contents for display in the console 15 * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php 16 * debug_print_var (Smarty online manual) 17 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param array|object 19 * @param integer 20 * @param integer 21 * @return string 15 * 16 * @author Monte Ohrt <monte at ohrt dot com> 17 * @param array|object $var variable to be formatted 18 * @param integer $depth maximum recursion depth if $var is an array 19 * @param integer $length maximum string length if $var is a string 20 * @return string 22 21 */ 23 function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40)22 function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40) 24 23 { 25 $_replace = array( 26 "\n" => '<i>\n</i>', 24 $_replace = array("\n" => '<i>\n</i>', 27 25 "\r" => '<i>\r</i>', 28 26 "\t" => '<i>\t</i>' 29 );27 ); 30 28 31 29 switch (gettype($var)) { … … 34 32 foreach ($var as $curr_key => $curr_val) { 35 33 $results .= '<br>' . str_repeat(' ', $depth * 2) 36 37 38 39 } 34 . '<b>' . strtr($curr_key, $_replace) . '</b> => ' 35 . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); 36 $depth--; 37 } 40 38 break; 39 41 40 case 'object' : 42 41 $object_vars = get_object_vars($var); … … 44 43 foreach ($object_vars as $curr_key => $curr_val) { 45 44 $results .= '<br>' . str_repeat(' ', $depth * 2) 46 47 48 49 } 45 . '<b> ->' . strtr($curr_key, $_replace) . '</b> = ' 46 . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); 47 $depth--; 48 } 50 49 break; 50 51 51 case 'boolean' : 52 52 case 'NULL' : … … 60 60 } else { 61 61 $results = htmlspecialchars((string) $var); 62 } 62 } 63 63 $results = '<i>' . $results . '</i>'; 64 64 break; 65 65 66 case 'integer' : 66 67 case 'float' : 67 68 $results = htmlspecialchars((string) $var); 68 69 break; 70 69 71 case 'string' : 70 72 $results = strtr($var, $_replace); 71 if (strlen($var) > $length ) { 72 $results = substr($var, 0, $length - 3) . '...'; 73 if (Smarty::$_MBSTRING) { 74 if (mb_strlen($var, Smarty::$_CHARSET) > $length) { 75 $results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...'; 76 } 77 } else { 78 if (isset($var[$length])) { 79 $results = substr($var, 0, $length - 3) . '...'; 80 } 73 81 } 82 74 83 $results = htmlspecialchars('"' . $results . '"'); 75 84 break; 85 76 86 case 'unknown type' : 77 87 default : 78 88 $results = strtr((string) $var, $_replace); 79 if (strlen($results) > $length ) { 80 $results = substr($results, 0, $length - 3) . '...'; 89 if (Smarty::$_MBSTRING) { 90 if (mb_strlen($results, Smarty::$_CHARSET) > $length) { 91 $results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...'; 92 } 93 } else { 94 if (strlen($results) > $length) { 95 $results = substr($results, 0, $length - 3) . '...'; 96 } 81 97 } 98 82 99 $results = htmlspecialchars($results); 83 } 100 } 84 101 85 102 return $results; 86 } 87 88 /* vim: set expandtab: */ 103 } 89 104 90 105 ?> -
trunk/include/smarty/libs/plugins/modifier.escape.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsModifier 6 7 */ 7 8 8 9 9 /** … … 12 12 * Type: modifier<br> 13 13 * Name: escape<br> 14 * Purpose: Escape the string according to escapement type 15 * @link http://smarty.php.net/manual/en/language.modifier.escape.php 16 * escape (Smarty online manual) 17 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param string 19 * @param html|htmlall|url|quotes|hex|hexentity|javascript 20 * @return string 14 * Purpose: escape string for output 15 * 16 * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) 17 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param string $string input string 19 * @param string $esc_type escape type 20 * @param string $char_set character set, used for htmlspecialchars() or htmlentities() 21 * @param boolean $double_encode encode already encoded entitites again, used for htmlspecialchars() or htmlentities() 22 * @return string escaped input string 21 23 */ 22 function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1')24 function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) 23 25 { 26 static $_double_encode = null; 27 if ($_double_encode === null) { 28 $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); 29 } 30 31 if (!$char_set) { 32 $char_set = Smarty::$_CHARSET; 33 } 34 24 35 switch ($esc_type) { 25 36 case 'html': 26 return htmlspecialchars($string, ENT_QUOTES, $char_set); 37 if ($_double_encode) { 38 // php >=5.3.2 - go native 39 return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); 40 } else { 41 if ($double_encode) { 42 // php <5.2.3 - only handle double encoding 43 return htmlspecialchars($string, ENT_QUOTES, $char_set); 44 } else { 45 // php <5.2.3 - prevent double encoding 46 $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); 47 $string = htmlspecialchars($string, ENT_QUOTES, $char_set); 48 $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); 49 return $string; 50 } 51 } 27 52 28 53 case 'htmlall': 29 return htmlentities($string, ENT_QUOTES, $char_set); 54 if (Smarty::$_MBSTRING) { 55 // mb_convert_encoding ignores htmlspecialchars() 56 if ($_double_encode) { 57 // php >=5.3.2 - go native 58 $string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); 59 } else { 60 if ($double_encode) { 61 // php <5.2.3 - only handle double encoding 62 $string = htmlspecialchars($string, ENT_QUOTES, $char_set); 63 } else { 64 // php <5.2.3 - prevent double encoding 65 $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); 66 $string = htmlspecialchars($string, ENT_QUOTES, $char_set); 67 $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); 68 return $string; 69 } 70 } 71 72 // htmlentities() won't convert everything, so use mb_convert_encoding 73 return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set); 74 } 75 76 // no MBString fallback 77 if ($_double_encode) { 78 return htmlentities($string, ENT_QUOTES, $char_set, $double_encode); 79 } else { 80 if ($double_encode) { 81 return htmlentities($string, ENT_QUOTES, $char_set); 82 } else { 83 $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); 84 $string = htmlentities($string, ENT_QUOTES, $char_set); 85 $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); 86 return $string; 87 } 88 } 30 89 31 90 case 'url': … … 33 92 34 93 case 'urlpathinfo': 35 return str_replace('%2F', '/',rawurlencode($string));36 94 return str_replace('%2F', '/', rawurlencode($string)); 95 37 96 case 'quotes': 38 97 // escape unescaped single quotes … … 40 99 41 100 case 'hex': 42 // escape every character into hex 101 // escape every byte into hex 102 // Note that the UTF-8 encoded character ä will be represented as %c3%a4 43 103 $return = ''; 44 for ($x=0; $x < strlen($string); $x++) { 104 $_length = strlen($string); 105 for ($x = 0; $x < $_length; $x++) { 45 106 $return .= '%' . bin2hex($string[$x]); 46 107 } 47 108 return $return; 48 109 49 110 case 'hexentity': 50 111 $return = ''; 51 for ($x=0; $x < strlen($string); $x++) { 112 if (Smarty::$_MBSTRING) { 113 require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); 114 $return = ''; 115 foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { 116 $return .= '&#x' . strtoupper(dechex($unicode)) . ';'; 117 } 118 return $return; 119 } 120 // no MBString fallback 121 $_length = strlen($string); 122 for ($x = 0; $x < $_length; $x++) { 52 123 $return .= '&#x' . bin2hex($string[$x]) . ';'; 53 124 } … … 56 127 case 'decentity': 57 128 $return = ''; 58 for ($x=0; $x < strlen($string); $x++) { 129 if (Smarty::$_MBSTRING) { 130 require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); 131 $return = ''; 132 foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { 133 $return .= '&#' . $unicode . ';'; 134 } 135 return $return; 136 } 137 // no MBString fallback 138 $_length = strlen($string); 139 for ($x = 0; $x < $_length; $x++) { 59 140 $return .= '&#' . ord($string[$x]) . ';'; 60 141 } … … 63 144 case 'javascript': 64 145 // escape quotes and backslashes, newlines, etc. 65 return strtr($string, array('\\' =>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));66 146 return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\/')); 147 67 148 case 'mail': 68 // safe way to display e-mail address on a web page 69 return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string); 70 149 if (Smarty::$_MBSTRING) { 150 require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); 151 return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); 152 } 153 // no MBString fallback 154 return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); 155 71 156 case 'nonstd': 72 // escape non-standard chars, such as ms document quotes 73 $_res = ''; 74 for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) { 75 $_ord = ord(substr($string, $_i, 1)); 76 // non-standard char, escape it 77 if($_ord >= 126){ 78 $_res .= '&#' . $_ord . ';'; 79 } 80 else { 81 $_res .= substr($string, $_i, 1); 82 } 83 } 84 return $_res; 157 // escape non-standard chars, such as ms document quotes 158 $return = ''; 159 if (Smarty::$_MBSTRING) { 160 require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); 161 foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { 162 if ($unicode >= 126) { 163 $return .= '&#' . $unicode . ';'; 164 } else { 165 $return .= chr($unicode); 166 } 167 } 168 return $return; 169 } 170 171 $_length = strlen($string); 172 for ($_i = 0; $_i < $_length; $_i++) { 173 $_ord = ord(substr($string, $_i, 1)); 174 // non-standard char, escape it 175 if ($_ord >= 126) { 176 $return .= '&#' . $_ord . ';'; 177 } else { 178 $return .= substr($string, $_i, 1); 179 } 180 } 181 return $return; 85 182 86 183 default: … … 89 186 } 90 187 91 /* vim: set expandtab: */92 93 188 ?> -
trunk/include/smarty/libs/plugins/modifier.regex_replace.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsModifier 6 7 */ 7 8 8 9 9 /** … … 13 13 * Name: regex_replace<br> 14 14 * Purpose: regular expression search/replace 15 * 15 16 * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php 16 17 * regex_replace (Smarty online manual) 17 * @author 18 * @param string 19 * @param string|array 20 * @param string|array 18 * @author Monte Ohrt <monte at ohrt dot com> 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 21 22 * @return string 22 23 */ … … 24 25 { 25 26 if(is_array($search)) { 26 foreach($search as $idx => $s) 27 $search[$idx] = _smarty_regex_replace_check($s); 27 foreach($search as $idx => $s) { 28 $search[$idx] = _smarty_regex_replace_check($s); 29 } 28 30 } else { 29 $search = _smarty_regex_replace_check($search); 30 } 31 31 $search = _smarty_regex_replace_check($search); 32 } 32 33 return preg_replace($search, $replace, $string); 33 34 } 34 35 36 /** 37 * @param string $search string(s) that should be replaced 38 * @return string 39 * @ignore 40 */ 35 41 function _smarty_regex_replace_check($search) 36 42 { 37 if (($pos = strpos($search,"\0")) !== false) 38 $search = substr($search,0,$pos); 43 // null-byte injection detection 44 // anything behind the first null-byte is ignored 45 if (($pos = strpos($search,"\0")) !== false) { 46 $search = substr($search,0,$pos); 47 } 48 // remove eval-modifier from $search 39 49 if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { 40 /* remove eval-modifier from $search */41 50 $search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]); 42 51 } … … 44 53 } 45 54 46 /* vim: set expandtab: */47 48 55 ?> -
trunk/include/smarty/libs/plugins/modifier.replace.php
r3282 r23384 3 3 * Smarty plugin 4 4 * @package Smarty 5 * @subpackage plugins5 * @subpackage PluginsModifier 6 6 */ 7 8 7 9 8 /** 10 9 * Smarty replace modifier plugin 11 * 10 * 12 11 * Type: modifier<br> 13 12 * Name: replace<br> 14 13 * Purpose: simple search/replace 15 * @link http://smarty.php.net/manual/en/language.modifier.replace.php 16 * replace (Smarty online manual) 17 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param string 19 * @param string 20 * @param string 21 * @return string 14 * 15 * @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual) 16 * @author Monte Ohrt <monte at ohrt dot com> 17 * @author Uwe Tews 18 * @param string $string input string 19 * @param string $search text to search for 20 * @param string $replace replacement text 21 * @return string 22 22 */ 23 23 function smarty_modifier_replace($string, $search, $replace) 24 24 { 25 if (Smarty::$_MBSTRING) { 26 require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); 27 return smarty_mb_str_replace($search, $replace, $string); 28 } 29 25 30 return str_replace($search, $replace, $string); 26 } 27 28 /* vim: set expandtab: */ 31 } 29 32 30 33 ?> -
trunk/include/smarty/libs/plugins/modifier.spacify.php
r3282 r23384 3 3 * Smarty plugin 4 4 * @package Smarty 5 * @subpackage plugins5 * @subpackage PluginsModifier 6 6 */ 7 8 7 9 8 /** 10 9 * Smarty spacify modifier plugin 11 * 10 * 12 11 * Type: modifier<br> 13 12 * Name: spacify<br> 14 13 * Purpose: add spaces between characters in a string 15 * @link http://smarty.php.net/manual/en/language.modifier.spacify.php16 * 17 * @author Monte Ohrt <monte at ohrt dot com>18 * @param string 19 * @param string 14 * 15 * @link http://smarty.php.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual) 16 * @author Monte Ohrt <monte at ohrt dot com> 17 * @param string $string input string 18 * @param string $spacify_char string to insert between characters. 20 19 * @return string 21 20 */ 22 21 function smarty_modifier_spacify($string, $spacify_char = ' ') 23 22 { 24 return implode($spacify_char, 25 preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY)); 26 } 27 28 /* vim: set expandtab: */ 23 // well… what about charsets besides latin and UTF-8? 24 return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, -1, PREG_SPLIT_NO_EMPTY)); 25 } 29 26 30 27 ?> -
trunk/include/smarty/libs/plugins/modifier.truncate.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsModifier 6 7 */ 7 8 8 9 9 /** 10 10 * Smarty truncate modifier plugin 11 * 11 * 12 12 * Type: modifier<br> 13 13 * Name: truncate<br> 14 14 * Purpose: Truncate a string to a certain length if necessary, 15 * optionally splitting in the middle of a word, and16 * appending the $etc string or inserting $etc into the middle.17 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php18 * 19 * @author Monte Ohrt <monte at ohrt dot com>20 * @param string 21 * @param integer 22 * @param string 23 * @param boolean 24 * @param boolean 25 * @return string 15 * optionally splitting in the middle of a word, and 16 * appending the $etc string or inserting $etc into the middle. 17 * 18 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) 19 * @author Monte Ohrt <monte at ohrt dot com> 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 * @return string truncated string 26 26 */ 27 function smarty_modifier_truncate($string, $length = 80, $etc = '...', 28 $break_words = false, $middle = false) 29 { 27 function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { 30 28 if ($length == 0) 31 29 return ''; 32 30 33 if (strlen($string) > $length) { 31 if (Smarty::$_MBSTRING) { 32 if (mb_strlen($string, Smarty::$_CHARSET) > $length) { 33 $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); 34 if (!$break_words && !$middle) { 35 $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)); 36 } 37 if (!$middle) { 38 return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; 39 } 40 return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET); 41 } 42 return $string; 43 } 44 45 // no MBString fallback 46 if (isset($string[$length])) { 34 47 $length -= min($length, strlen($etc)); 35 48 if (!$break_words && !$middle) { 36 $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1)); 49 $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); 50 } 51 if (!$middle) { 52 return substr($string, 0, $length) . $etc; 37 53 } 38 if(!$middle) { 39 return substr($string, 0, $length) . $etc; 40 } else { 41 return substr($string, 0, $length/2) . $etc . substr($string, -$length/2); 42 } 43 } else { 44 return $string; 54 return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2); 45 55 } 46 } 47 48 /* vim: set expandtab: */ 56 return $string; 57 } 49 58 50 59 ?> -
trunk/include/smarty/libs/plugins/outputfilter.trimwhitespace.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFilter 6 7 */ 7 8 … … 9 10 * Smarty trimwhitespace outputfilter plugin 10 11 * 11 * File: outputfilter.trimwhitespace.php<br> 12 * Type: outputfilter<br> 13 * Name: trimwhitespace<br> 14 * Date: Jan 25, 2003<br> 15 * Purpose: trim leading white space and blank lines from 16 * template source after it gets interpreted, cleaning 17 * up code and saving bandwidth. Does not affect 18 * <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br> 19 * Install: Drop into the plugin directory, call 20 * <code>$smarty->load_filter('output','trimwhitespace');</code> 21 * from application. 22 * @author Monte Ohrt <monte at ohrt dot com> 23 * @author Contributions from Lars Noschinski <lars@usenet.noschinski.de> 24 * @version 1.3 25 * @param string 26 * @param Smarty 12 * Trim unnecessary whitespace from HTML markup. 13 * 14 * @author Rodney Rehm 15 * @param string $source input string 16 * @param Smarty_Internal_Template $smarty Smarty object 17 * @return string filtered output 18 * @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail! 27 19 */ 28 function smarty_outputfilter_trimwhitespace($source, &$smarty)20 function smarty_outputfilter_trimwhitespace($source, Smarty_Internal_Template $smarty) 29 21 { 30 // Pull out the script blocks 31 preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match); 32 $_script_blocks = $match[0]; 33 $source = preg_replace("!<script[^>]*?>.*?</script>!is", 34 '@@@SMARTY:TRIM:SCRIPT@@@', $source); 22 $store = array(); 23 $_store = 0; 24 $_offset = 0; 35 25 36 // Pull out the pre blocks 37 preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match); 38 $_pre_blocks = $match[0]; 39 $source = preg_replace("!<pre[^>]*?>.*?</pre>!is", 40 '@@@SMARTY:TRIM:PRE@@@', $source); 41 42 // Pull out the textarea blocks 43 preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match); 44 $_textarea_blocks = $match[0]; 45 $source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is", 46 '@@@SMARTY:TRIM:TEXTAREA@@@', $source); 26 // Unify Line-Breaks to \n 27 $source = preg_replace("/\015\012|\015|\012/", "\n", $source); 47 28 48 // remove all leading spaces, tabs and carriage returns NOT 49 // preceeded by a php close tag. 50 $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source)); 29 // capture Internet Explorer Conditional Comments 30 if (preg_match_all('#<!--\[[^\]]+\]>.*?<!\[[^\]]+\]-->#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { 31 foreach ($matches as $match) { 32 $store[] = $match[0][0]; 33 $_length = strlen($match[0][0]); 34 $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; 35 $source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length); 51 36 52 // replace textarea blocks 53 smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source); 37 $_offset += $_length - strlen($replace); 38 $_store++; 39 } 40 } 54 41 55 // replace pre blocks 56 smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source); 42 // Strip all HTML-Comments 43 // yes, even the ones in <script> - see http://stackoverflow.com/a/808850/515124 44 $source = preg_replace( '#<!--.*?-->#ms', '', $source ); 57 45 58 // replace script blocks 59 smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source); 46 // capture html elements not to be messed with 47 $_offset = 0; 48 if (preg_match_all('#<(script|pre|textarea)[^>]*>.*?</\\1>#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { 49 foreach ($matches as $match) { 50 $store[] = $match[0][0]; 51 $_length = strlen($match[0][0]); 52 $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; 53 $source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length); 54 55 $_offset += $_length - strlen($replace); 56 $_store++; 57 } 58 } 59 60 $expressions = array( 61 // replace multiple spaces between tags by a single space 62 // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements 63 '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2', 64 // remove spaces between attributes (but not in attribute values!) 65 '#(([a-z0-9]\s*=\s*(["\'])[^\3]*?\3)|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \4', 66 // note: for some very weird reason trim() seems to remove spaces inside attributes. 67 // maybe a \0 byte or something is interfering? 68 '#^\s+<#Ss' => '<', 69 '#>\s+$#Ss' => '>', 70 ); 71 72 $source = preg_replace( array_keys($expressions), array_values($expressions), $source ); 73 // note: for some very weird reason trim() seems to remove spaces inside attributes. 74 // maybe a \0 byte or something is interfering? 75 // $source = trim( $source ); 76 77 // capture html elements not to be messed with 78 $_offset = 0; 79 if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { 80 foreach ($matches as $match) { 81 $store[] = $match[0][0]; 82 $_length = strlen($match[0][0]); 83 $replace = array_shift($store); 84 $source = substr_replace($source, $replace, $match[0][1] + $_offset, $_length); 85 86 $_offset += strlen($replace) - $_length; 87 $_store++; 88 } 89 } 60 90 61 91 return $source; 62 92 } 63 93 64 function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {65 $_len = strlen($search_str);66 $_pos = 0;67 for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)68 if (($_pos=strpos($subject, $search_str, $_pos))!==false)69 $subject = substr_replace($subject, $replace[$_i], $_pos, $_len);70 else71 break;72 73 }74 75 94 ?> -
trunk/include/smarty/libs/plugins/shared.escape_special_chars.php
r3282 r23384 2 2 /** 3 3 * Smarty shared plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsShared 6 7 */ 7 8 8 9 /** 10 * escape_special_chars common function 11 * 12 * Function: smarty_function_escape_special_chars<br> 13 * Purpose: used by other smarty functions to escape 14 * special chars except for already escaped ones 15 * @author Monte Ohrt <monte at ohrt dot com> 16 * @param string 17 * @return string 18 */ 19 function smarty_function_escape_special_chars($string) 20 { 21 if(!is_array($string)) { 22 $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); 23 $string = htmlspecialchars($string); 24 $string = str_replace(array('%%%SMARTY_START%%%','%%%SMARTY_END%%%'), array('&',';'), $string); 25 } 26 return $string; 27 } 28 29 /* vim: set expandtab: */ 9 if (version_compare(PHP_VERSION, '5.2.3', '>=')) { 10 /** 11 * escape_special_chars common function 12 * 13 * Function: smarty_function_escape_special_chars<br> 14 * Purpose: used by other smarty functions to escape 15 * special chars except for already escaped ones 16 * 17 * @author Monte Ohrt <monte at ohrt dot com> 18 * @param string $string text that should by escaped 19 * @return string 20 */ 21 function smarty_function_escape_special_chars($string) 22 { 23 if (!is_array($string)) { 24 $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false); 25 } 26 return $string; 27 } 28 } else { 29 /** 30 * escape_special_chars common function 31 * 32 * Function: smarty_function_escape_special_chars<br> 33 * Purpose: used by other smarty functions to escape 34 * special chars except for already escaped ones 35 * 36 * @author Monte Ohrt <monte at ohrt dot com> 37 * @param string $string text that should by escaped 38 * @return string 39 */ 40 function smarty_function_escape_special_chars($string) 41 { 42 if (!is_array($string)) { 43 $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); 44 $string = htmlspecialchars($string); 45 $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); 46 } 47 return $string; 48 } 49 } 30 50 31 51 ?> -
trunk/include/smarty/libs/plugins/shared.make_timestamp.php
r3282 r23384 2 2 /** 3 3 * Smarty shared plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsShared 6 7 */ 7 8 8 9 9 /** 10 10 * Function: smarty_make_timestamp<br> 11 * Purpose: used by other smarty functions to make a timestamp 12 * from a string.11 * Purpose: used by other smarty functions to make a timestamp from a string. 12 * 13 13 * @author Monte Ohrt <monte at ohrt dot com> 14 * @param string15 * @return string14 * @param DateTime|int|string $string date object, timestamp or string that can be converted using strtotime() 15 * @return int 16 16 */ 17 17 function smarty_make_timestamp($string) 18 18 { 19 if (empty($string)) {19 if (empty($string)) { 20 20 // use "now": 21 $time = time(); 22 23 } elseif (preg_match('/^\d{14}$/', $string)) { 24 // it is mysql timestamp format of YYYYMMDDHHMMSS? 25 $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), 21 return time(); 22 } elseif ($string instanceof DateTime) { 23 return $string->getTimestamp(); 24 } elseif (strlen($string) == 14 && ctype_digit($string)) { 25 // it is mysql timestamp format of YYYYMMDDHHMMSS? 26 return mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), 26 27 substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4)); 27 28 28 } elseif (is_numeric($string)) { 29 29 // it is a numeric string, we handle it as timestamp 30 $time = (int)$string; 31 30 return (int) $string; 32 31 } else { 33 32 // strtotime should handle it … … 35 34 if ($time == -1 || $time === false) { 36 35 // strtotime() was not able to parse $string, use "now": 37 $time =time();36 return time(); 38 37 } 38 return $time; 39 39 } 40 return $time;41 42 40 } 43 41 44 /* vim: set expandtab: */45 46 42 ?>
Note: See TracChangeset
for help on using the changeset viewer.