From: cajus Date: Tue, 26 Jan 2010 16:03:58 +0000 (+0000) Subject: Added smarty 3 rc X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2f3ab4ddfcec3acc9c7a9b9d5da6172819a70c13;p=gosa.git Added smarty 3 rc git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15339 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/smarty/Smarty.class.php b/gosa-core/include/smarty/Smarty.class.php new file mode 100644 index 000000000..6f2885731 --- /dev/null +++ b/gosa-core/include/smarty/Smarty.class.php @@ -0,0 +1,545 @@ + +* @author Uwe Tews +* @package Smarty +* @version 3-SVN$Rev: 3286 $ +*/ + +/** +* define shorthand directory separator constant +*/ +if (!defined('DS')) { + define('DS', DIRECTORY_SEPARATOR); +} + +/** +* set SMARTY_DIR to absolute path to Smarty library files. +* Sets SMARTY_DIR only if user application has not already defined it. +*/ +if (!defined('SMARTY_DIR')) { + define('SMARTY_DIR', dirname(__FILE__) . DS); +} + +/** +* set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins. +* Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it. +*/ +if (!defined('SMARTY_SYSPLUGINS_DIR')) { + define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS); +} +if (!defined('SMARTY_PLUGINS_DIR')) { + define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS); +} +if (!defined('SMARTY_RESOURCE_CHAR_SET')) { + define('SMARTY_RESOURCE_CHAR_SET', 'UTF-8'); +} +if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { + define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); +} + +/** +* define variable scopes +*/ +define('SMARTY_LOCAL_SCOPE', 0); +define('SMARTY_PARENT_SCOPE', 1); +define('SMARTY_ROOT_SCOPE', 2); +define('SMARTY_GLOBAL_SCOPE', 3); + +/** +* define caching modes +*/ +define('SMARTY_CACHING_OFF', 0); +define('SMARTY_CACHING_LIFETIME_CURRENT', 1); +define('SMARTY_CACHING_LIFETIME_SAVED', 2); + +/** +* This determines how Smarty handles "" tags in templates. +* possible values: +*/ +define('SMARTY_PHP_PASSTHRU', 0); //-> print tags as plain text +define('SMARTY_PHP_QUOTE', 1); //-> escape tags as entities +define('SMARTY_PHP_REMOVE', 2); //-> escape tags as entities +define('SMARTY_PHP_ALLOW', 3); //-> escape tags as entities + +/** +* register the class autoloader +*/ +if (!defined('SMARTY_SPL_AUTOLOAD')) { + define('SMARTY_SPL_AUTOLOAD', 0); +} + +if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) { + $registeredAutoLoadFunctions = spl_autoload_functions(); + if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { + spl_autoload_register(); + } +} else { + spl_autoload_register('smartyAutoload'); +} + +/** +* This is the main Smarty class +*/ +class Smarty extends Smarty_Internal_Data { + // smarty version + const SMARTY_VERSION = 'Smarty3-b7'; + // auto literal on delimiters with whitspace + public $auto_literal = true; + // display error on not assigned variables + public $error_unassigned = false; + // template directory + public $template_dir = null; + // default template handler + public $default_template_handler_func = null; + // compile directory + public $compile_dir = null; + // plugins directory + public $plugins_dir = null; + // cache directory + public $cache_dir = null; + // config directory + public $config_dir = null; + // force template compiling? + public $force_compile = false; + // check template for modifications? + public $compile_check = true; + // use sub dirs for compiled/cached files? + public $use_sub_dirs = false; + // compile_error? + public $compile_error = false; + // caching enabled + public $caching = false; + // merge compiled includea + public $merge_compiled_includes = false; + // cache lifetime + public $cache_lifetime = 3600; + // force cache file creation + public $force_cache = false; + // cache_id + public $cache_id = null; + // compile_id + public $compile_id = null; + // template delimiters + public $left_delimiter = "{"; + public $right_delimiter = "}"; + // security + public $security_class = 'Smarty_Security'; + public $php_handling = SMARTY_PHP_PASSTHRU; + public $allow_php_tag = false; + public $allow_php_templates = false; + public $security = false; + public $security_policy = null; + public $security_handler = null; + public $direct_access_security = true; + // debug mode + public $debugging = false; + public $debugging_ctrl = 'URL'; + public $smarty_debug_id = 'SMARTY_DEBUG'; + public $debug_tpl = null; + // When set, smarty does uses this value as error_reporting-level. + public $error_reporting = null; + // config var settings + public $config_overwrite = true; //Controls whether variables with the same name overwrite each other. + public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean + public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file. + // config vars + public $config_vars = array(); + // assigned tpl vars + public $tpl_vars = array(); + // assigned global tpl vars + public $global_tpl_vars = array(); + // dummy parent object + public $parent = null; + // global template functions + public $template_functions = array(); + // resource type used if none given + public $default_resource_type = 'file'; + // caching type + public $caching_type = 'file'; + // internal cache resource types + public $cache_resource_types = array('file'); + // config type + public $default_config_type = 'file'; + // exception handler: array('ExceptionClass','ExceptionMethod'); + public $exception_handler = null; + // cached template objects + public $template_objects = null; + // check If-Modified-Since headers + public $cache_modified_check = false; + // registered plugins + public $registered_plugins = array(); + // plugin search order + public $plugin_search_order = array('function', 'block', 'compiler', 'class'); + // registered objects + public $registered_objects = array(); + // registered filters + public $registered_filters = array(); + // autoload filter + public $autoload_filters = array(); + // status of filter on variable output + public $variable_filter = true; + // global internal smarty vars + public $_smarty_vars = array(); + // start time for execution time calculation + public $start_time = 0; + // default file permissions + public $_file_perms = 0644; + // default dir permissions + public $_dir_perms = 0771; + // smarty object reference + public $smarty = null; + + /** + * Class constructor, initializes basic smarty properties + */ + public function __construct() { + // self reference needed by other classes methods + $this->smarty = $this; + + if (is_callable('mb_internal_encoding')) { + mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET); + } + $this->start_time = $this->_get_time(); + // set exception handler + if (!empty($this->exception_handler)) + set_exception_handler($this->exception_handler); + // set default dirs + $this->template_dir = array('.' . DS . 'templates' . DS); + $this->compile_dir = '.' . DS . 'templates_c' . DS; + $this->plugins_dir = array(SMARTY_PLUGINS_DIR); + $this->cache_dir = '.' . DS . 'cache' . DS; + $this->config_dir = '.' . DS . 'configs' . DS; + $this->debug_tpl = SMARTY_DIR . 'debug.tpl'; + if (!$this->debugging && $this->debugging_ctrl == 'URL') { + if (isset($_SERVER['QUERY_STRING'])) { + $_query_string = $_SERVER['QUERY_STRING']; + } + else { + $_query_string = ''; + } + if (false !== strpos($_query_string, $this->smarty_debug_id)) { + if (false !== strpos($_query_string, $this->smarty_debug_id . '=on')) { + // enable debugging for this browser session + setcookie('SMARTY_DEBUG', true); + $this->debugging = true; + } + elseif (false !== strpos($_query_string, $this->smarty_debug_id . '=off')) { + // disable debugging for this browser session + setcookie('SMARTY_DEBUG', false); + $this->debugging = false; + } + else { + // enable debugging for this page + $this->debugging = true; + } + } + else { + if (isset($_COOKIE['SMARTY_DEBUG'])) { + $this->debugging = true; + } + } + } + $this->assign_global('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); + } + + /** + * Class destructor + */ + public function __destruct() { + // restore to previous exception handler, if any + if (!empty($this->exception_handler)) + restore_exception_handler(); + } + + /** + * fetches a rendered Smarty template + * + * @param string $template the resource handle of the template file or template object + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @param object $ |null $parent next higher level of Smarty variables + * @return string rendered template output + */ + public function fetch($template, $cache_id = null, $compile_id = null, $parent = null) { + if (is_object($cache_id)) { + $parent = $cache_id; + $cache_id = null; + } + if ($parent === null) { + // get default Smarty data object + $parent = $this; + } + // create template object if necessary + ($template instanceof $this->template_class)? $_template = $template : + $_template = $this->createTemplate ($template, $cache_id, $compile_id, $parent); + $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) + ? $this->error_reporting : error_reporting() &~E_NOTICE); + // return redered template + if (isset($this->autoload_filters['output']) || isset($this->registered_filters['output'])) { + $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $this); + } + else { + $_output = $_template->getRenderedTemplate(); + } + $_template->rendered_content = null; + error_reporting($_smarty_old_error_level); + return $_output; + } + + /** + * displays a Smarty template + * + * @param string $ |object $template the resource handle of the template file or template object + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @param object $parent next higher level of Smarty variables + */ + public function display($template, $cache_id = null, $compile_id = null, $parent = null) { + // display template + echo $this->fetch ($template, $cache_id, $compile_id, $parent); + // debug output + if ($this->debugging) { + Smarty_Internal_Debug::display_debug($this); + } + return true; + } + + /** + * test if cache i valid + * + * @param string $ |object $template the resource handle of the template file or template object + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @return boolean cache status + */ + public function is_cached($template, $cache_id = null, $compile_id = null) { + if (!($template instanceof $this->template_class)) { + $template = $this->createTemplate ($template, $cache_id, $compile_id, $this); + } + // return cache status of template + return $template->isCached(); + } + + /** + * Loads security class and enables security + */ + public function enableSecurity() { + if (isset($this->security_class)) { + $this->security_policy = new $this->security_class; + $this->security_handler = new Smarty_Internal_Security_Handler($this); + $this->security = true; + } + else { + throw new Exception('Property security_class is not defined'); + } + } + + /** + * Set template directory + * + * @param string $ |array $template_dir folder(s) of template sorces + */ + public function setTemplateDir($template_dir) { + $this->template_dir = (array)$template_dir; + return; + } + /** + * Adds template directory(s) to existing ones + * + * @param string $ |array $template_dir folder(s) of template sources + */ + public function addTemplateDir($template_dir) { + $this->template_dir = array_merge((array)$this->template_dir, (array)$template_dir); + $this->template_dir = array_unique($this->template_dir); + return; + } + /** + * Set compile directory + * + * @param string $compile_dir folder of compiled template sources + */ + public function setCompileDir($compile_dir) { + $this->compile_dir = $compile_dir; + return; + } + /** + * Set cache directory + * + * @param string $cache_dir folder of cache files + */ + public function setCacheDir($cache_dir) { + $this->cache_dir = $cache_dir; + return; + } + /** + * Enable Caching + */ + public function enableCaching() { + $this->caching = SMARTY_CACHING_LIFETIME_CURRENT; + return; + } + /** + * Set caching life time + * + * @param integer $lifetime lifetime of cached file in seconds + */ + public function setCacheLifetime($lifetime) { + $this->cache_lifetime = $lifetime; + return; + } + /** + * Takes unknown classes and loads plugin files for them + * class name format: Smarty_PluginType_PluginName + * plugin filename format: plugintype.pluginname.php + * + * @param string $plugin_name class plugin name to load + * @return string|boolean filepath of loaded file or false + */ + public function loadPlugin($plugin_name, $check = true) { + // if function or class exists, exit silently (already loaded) + if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) + return true; + // Plugin name is expected to be: Smarty_[Type]_[Name] + $_plugin_name = strtolower($plugin_name); + $_name_parts = explode('_', $_plugin_name, 3); + // class name must have three parts to be valid plugin + if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') { + throw new Exception("plugin {$plugin_name} is not a valid name format"); + return false; + } + // if type is "internal", get plugin from sysplugins + if ($_name_parts[1] == 'internal') { + $file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php'; + if (file_exists($file)) { + require_once($file); + return $file; + } + else { + return false; + } + } + // plugin filename is expected to be: [type].[name].php + $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php"; + // loop through plugin dirs and find the plugin + foreach((array)$this->plugins_dir as $_plugin_dir) { + if (strpos('/\\', substr($_plugin_dir, -1)) === false) { + $_plugin_dir .= DS; + } + $file = $_plugin_dir . $_plugin_filename; + if (file_exists($file)) { + require_once($file); + return $file; + } + } + // no plugin loaded + return false; + } + + /** + * Sets the exception handler for Smarty. + * + * @param mixed $handler function name or array with object/method names + * @return string previous exception handler + */ + public function setExceptionHandler($handler) { + $this->exception_handler = $handler; + return set_exception_handler($handler); + } + + /** + * Loads cache resource. + * + * @return object of cache resource + */ + public function loadCacheResource($type = null) { + if (!isset($type)) { + $type = $this->caching_type; + } + // already loaded? + if (isset($this->cache_resource_objects[$type])) { + return $this->cache_resource_objects[$type]; + } + if (in_array($type, $this->cache_resource_types)) { + $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type); + return $this->cache_resource_objects[$type] = new $cache_resource_class($this); + } + else { + // try plugins dir + $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type); + if ($this->loadPlugin($cache_resource_class)) { + return $this->cache_resource_objects[$type] = new $cache_resource_class($this); + } + else { + throw new Exception("Unable to load cache resource '{$type}'"); + } + } + } + + /** + * trigger Smarty error + * + * @param string $error_msg + * @param integer $error_type + */ + public function trigger_error($error_msg, $error_type = E_USER_WARNING) { + throw new Exception("Smarty error: $error_msg"); + } + + /** + * Takes unknown class methods and lazy loads sysplugin files for them + * class name format: Smarty_Method_MethodName + * plugin filename format: method.methodname.php + * + * @param string $name unknown methode name + * @param array $args aurgument array + */ + public function __call($name, $args) { + $name = strtolower($name); + if ($name == 'smarty') { + throw new Exception('Please use parent::__construct() to call parent constuctor'); + } + $function_name = 'smarty_method_' . $name; + if (!is_callable($function_name)) { + if (!file_exists(SMARTY_SYSPLUGINS_DIR . $function_name . '.php')) { + throw new Exception('Undefined Smarty method "' . $name . '"'); + } + require_once(SMARTY_SYSPLUGINS_DIR . $function_name . '.php'); + } + return call_user_func_array($function_name, array_merge(array($this), $args)); + } +} + +function smartyAutoload($class) { + $_class = strtolower($class); + if (substr($_class, 0, 16) === 'smarty_internal_' || $_class == 'smarty_security') { + include SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + } +} + +?> diff --git a/gosa-core/include/smarty/debug.tpl b/gosa-core/include/smarty/debug.tpl new file mode 100644 index 000000000..9fd46b153 --- /dev/null +++ b/gosa-core/include/smarty/debug.tpl @@ -0,0 +1,136 @@ +{capture assign=debug_output} + + + + Smarty Debug Console + + + + +

Smarty Debug Console - Total Time {$execution_time|string_format:"%.5f"}

+ +

included templates & config files (load time in seconds)

+ +
+{foreach $template_data as $template} + {$template.name} + + (compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}) + +
+{/foreach} +
+ +

assigned template variables

+ + + {foreach $assigned_vars as $vars} + + + + {/foreach} +
${$vars@key|escape:'html'}{$vars|debug_print_var}
+ +

assigned config file variables (outer template scope)

+ + + {foreach $config_vars as $vars} + + + + {/foreach} + +
{$vars@key|escape:'html'}{$vars|debug_print_var}
+ + +{/capture} + diff --git a/gosa-core/include/smarty/plugins/block.php.php b/gosa-core/include/smarty/plugins/block.php.php new file mode 100644 index 000000000..d1de74002 --- /dev/null +++ b/gosa-core/include/smarty/plugins/block.php.php @@ -0,0 +1,27 @@ +allow_php_tag) { + throw new Exception("{php} is deprecated, set allow_php_tag = true to enable"); + } + eval($content); + return ''; +} +?> diff --git a/gosa-core/include/smarty/plugins/block.render.php b/gosa-core/include/smarty/plugins/block.render.php new file mode 100644 index 000000000..83a8fea8e --- /dev/null +++ b/gosa-core/include/smarty/plugins/block.render.php @@ -0,0 +1,126 @@ + */ + if(empty($text)) { + return(""); + } + + /* Get acl parameter */ + $acl = ""; + if (isset($params['acl'])) { + $acl = $params['acl']; + } + + /* Debug output */ + if (session::is_set('DEBUGLEVEL') && session::get('DEBUGLEVEL') & DEBUG_ACL ){ + echo " ".$acl.""; + } + + + + /* Parameter : checkbox, checked + * If the parameter 'checkbox' is given, we create a html checkbox in front + * of the current object. + * The parameter 'checked' specifies whether the box is checked or not. + * The checkbox disables or enables the current object. + */ + if(isset($params['checkbox']) && $params['checkbox']){ + + /* Detect name and id of the current object */ + $use_text = preg_replace("/\n/"," ",$text); + $name = preg_replace('/^.* name[ ]*=[ ]*("|\')([^\"\' ]*).*$/i',"\\2",$use_text); + + /* Detect id */ + if(preg_match("/ id=(\"|')[^\"']*(\"|')/i",$text)){ + $id = preg_replace('/^.* id[ ]*=[ ]*("|\')([^\"\' ]*).*$/i',"\\2",$use_text); + }else{ + $id = ""; + } + + /* Is the box checked? */ + isset($params['checked'])&&$params['checked'] ? $check = " checked " : $check = ""; + + /* If name isset, we have a html input field */ + if(!empty($name)){ + + /* Print checkbox */ + echo ""; + + /* Disable current object, if checkbox isn't checked */ + if($check == ""){ + $text = preg_replace("/name=/i"," disabled name=",$text); + } + + /* Add id to current entry, if it is missing */ + if($id == ""){ + $text = preg_replace("/name=/i"," id=\"".$name."\" name=",$text); + } + } + } + + + /* Read / Write*/ + if(preg_match("/w/i",$acl)){ + return ($text); + } + + $text = preg_replace ("/\n/","GOSA_LINE_BREAK",$text); + + /* Disable objects, but keep those active that have mode=read_active */ + if(!(isset($params['mode']) && ($params['mode']=='read_active') && preg_match("/(r|w)/",$acl))){ + + /* Disable options && greyout divlists */ + $from = array("/class=['\"]list1nohighlight['\"]/i", + "/class=['\"]list0['\"]/i", + "/class=['\"]list1['\"]/i", + "/class=['\"]sortableListItem[^'\"]*['\"]/i"); + $to = array("class='list1nohighlightdisabled'", + "class='list1nohighlightdisabled'", + "class='list1nohighlightdisabled'", + "class='sortableListItemDisabled'"); + + if(!preg_match("/ disabled /",$text)){ + $from [] = "/name=/i" ; + $to [] = "disabled name="; + } + + $text = preg_replace($from,$to,$text); + + /* Replace picture if object is disabled */ + if(isset($params['disable_picture'])){ + $syn = "/src=['\"][^\"']*['\"]/i"; + $new = "src=\"".$params['disable_picture']."\""; + $text = preg_replace($syn,$new,$text); + } + } + + /* Read only */ + if(preg_match("/r/i",$acl)){ + return(preg_replace("/GOSA_LINE_BREAK/","\n",$text)); + } + + /* No acls */ + if(preg_match("/type['\"= ].*submit/",$text)){ + $text = preg_replace("/submit/","button",$text); + }else{ + $text = preg_replace("/value=['\"][^\"']*['\"]/","",$text); + } + + /* Remove select options */ + $from = array("##i", + "/().*(<\/textarea>)/i", + "/^(.*.*)$/i"); + + $to = array(" ", + "\\1\\2", + "\\1 \\2"); + $text = preg_replace($from,$to,$text); + $text = preg_replace("/GOSA_LINE_BREAK/","\n",$text); + + return $text; +} + +?> diff --git a/gosa-core/include/smarty/plugins/block.t.php b/gosa-core/include/smarty/plugins/block.t.php new file mode 100644 index 000000000..ca7382aeb --- /dev/null +++ b/gosa-core/include/smarty/plugins/block.t.php @@ -0,0 +1,126 @@ + + * @copyright 2004-2005 Sagi Bashari + */ + +/** + * Replaces arguments in a string with their values. + * Arguments are represented by % followed by their number. + * + * @param string Source string + * @param mixed Arguments, can be passed in an array or through single variables. + * @returns string Modified string + */ +function smarty_gettext_strarg($str) +{ + $tr = array(); + $p = 0; + + for ($i=1; $i < func_num_args(); $i++) { + $arg = func_get_arg($i); + + if (is_array($arg)) { + foreach ($arg as $aarg) { + $tr['%'.++$p] = $aarg; + } + } else { + $tr['%'.++$p] = $arg; + } + } + + return strtr($str, $tr); +} + +/** + * Smarty block function, provides gettext support for smarty. + * + * The block content is the text that should be translated. + * + * Any parameter that is sent to the function will be represented as %n in the translation text, + * where n is 1 for the first parameter. The following parameters are reserved: + * - escape - sets escape mode: + * - 'html' for HTML escaping, this is the default. + * - 'js' for javascript escaping. + * - 'url' for url escaping. + * - 'no'/'off'/0 - turns off escaping + * - plural - The plural version of the text (2nd parameter of ngettext()) + * - count - The item count for plural mode (3rd parameter of ngettext()) + */ +function smarty_block_t($params, $text, &$smarty) +{ + $text = stripslashes($text); + + // set escape mode + if (isset($params['escape'])) { + $escape = $params['escape']; + unset($params['escape']); + } + + // set plural version + if (isset($params['plural'])) { + $plural = $params['plural']; + unset($params['plural']); + + // set count + if (isset($params['count'])) { + $count = $params['count']; + unset($params['count']); + } + } + + // use plural if required parameters are set + if (isset($count) && isset($plural)) { + $text = ngettext($text, $plural, $count); + } else { // use normal + $text = gettext($text); + } + + // run strarg if there are parameters + if (count($params)) { + $text = smarty_gettext_strarg($text, $params); + } + + if (!isset($escape) || $escape == 'html') { // html escape, default + $text = nl2br(htmlspecialchars($text)); + } elseif (isset($escape)) { + switch ($escape) { + case 'javascript': + case 'js': + // javascript escape + $text = str_replace('\'', '\\\'', stripslashes($text)); + break; + case 'url': + // url escape + $text = urlencode($text); + break; + } + } + + return $text; +} + +?> diff --git a/gosa-core/include/smarty/plugins/block.textformat.php b/gosa-core/include/smarty/plugins/block.textformat.php new file mode 100644 index 000000000..f578bfb9b --- /dev/null +++ b/gosa-core/include/smarty/plugins/block.textformat.php @@ -0,0 +1,103 @@ + +* Name: textformat
+* Purpose: format text a certain way with preset styles +* or custom wrap/indent settings
+* +* @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat} + (Smarty online manual) +* @param array $params parameters +*
+* Params:   style: string (email)
+*            indent: integer (0)
+*            wrap: integer (80)
+*            wrap_char string ("\n")
+*            indent_char: string (" ")
+*            wrap_boundary: boolean (true)
+* 
+* @author Monte Ohrt +* @param string $content contents of the block +* @param object $smarty Smarty object +* @param boolean &$repeat repeat flag +* @param object $template template object +* @return string content re-formatted +*/ +function smarty_block_textformat($params, $content, $smarty, &$repeat, $template) +{ + if (is_null($content)) { + return; + } + + $style = null; + $indent = 0; + $indent_first = 0; + $indent_char = ' '; + $wrap = 80; + $wrap_char = "\n"; + $wrap_cut = false; + $assign = null; + + foreach ($params as $_key => $_val) { + switch ($_key) { + case 'style': + case 'indent_char': + case 'wrap_char': + case 'assign': + $$_key = (string)$_val; + break; + + case 'indent': + case 'indent_first': + case 'wrap': + $$_key = (int)$_val; + break; + + case 'wrap_cut': + $$_key = (bool)$_val; + break; + + default: + $smarty->trigger_error("textformat: unknown attribute '$_key'"); + } + } + + if ($style == 'email') { + $wrap = 72; + } + // split into paragraphs + $_paragraphs = preg_split('![\r\n][\r\n]!', $content); + $_output = ''; + + for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) { + if ($_paragraphs[$_x] == '') { + continue; + } + // convert mult. spaces & special chars to single space + $_paragraphs[$_x] = preg_replace(array('!\s+!', '!(^\s+)|(\s+$)!'), array(' ', ''), $_paragraphs[$_x]); + // indent first line + if ($indent_first > 0) { + $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x]; + } + // wordwrap sentences + $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); + // indent lines + if ($indent > 0) { + $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]); + } + } + $_output = implode($wrap_char . $wrap_char, $_paragraphs); + + return $assign ? $template->assign($assign, $_output) : $_output; +} + +?> diff --git a/gosa-core/include/smarty/plugins/function.counter.php b/gosa-core/include/smarty/plugins/function.counter.php new file mode 100644 index 000000000..88e49d801 --- /dev/null +++ b/gosa-core/include/smarty/plugins/function.counter.php @@ -0,0 +1,78 @@ + + * Name: counter
+ * Purpose: print out a counter value + * @author Monte Ohrt + * @link http://smarty.php.net/manual/en/language.function.counter.php {counter} + * (Smarty online manual) + * @param array $params parameters + * @param object $smarty Smarty object + * @param object $template template object + * @return string|null + */ +function smarty_function_counter($params, $smarty, $template) +{ + + $name = (isset($params['name'])) ? $params['name'] : 'default'; + if (!isset($template->plugin_data['counter'][$name])) { + $template->plugin_data['counter'][$name] = array( + 'start'=>1, + 'skip'=>1, + 'direction'=>'up', + 'count'=>1 + ); + } + $counter = &$template->plugin_data['counter'][$name]; + + if (isset($params['start'])) { + $counter['start'] = $counter['count'] = (int)$params['start']; + } + + if (!empty($params['assign'])) { + $counter['assign'] = $params['assign']; + } + + if (isset($counter['assign'])) { + $template->assign($counter['assign'], $counter['count']); + } + + if (isset($params['print'])) { + $print = (bool)$params['print']; + } else { + $print = empty($counter['assign']); + } + + if ($print) { + $retval = $counter['count']; + } else { + $retval = null; + } + + if (isset($params['skip'])) { + $counter['skip'] = $params['skip']; + } + + if (isset($params['direction'])) { + $counter['direction'] = $params['direction']; + } + + if ($counter['direction'] == "down") + $counter['count'] -= $counter['skip']; + else + $counter['count'] += $counter['skip']; + + return $retval; + +} + +?> diff --git a/gosa-core/include/smarty/plugins/function.cycle.php b/gosa-core/include/smarty/plugins/function.cycle.php new file mode 100644 index 000000000..f1cb46ba6 --- /dev/null +++ b/gosa-core/include/smarty/plugins/function.cycle.php @@ -0,0 +1,101 @@ + + * Name: cycle
+ * Date: May 3, 2002
+ * Purpose: cycle through given values
+ * + * Examples:
+ *
+ * {cycle values="#eeeeee,#d0d0d0d"}
+ * {cycle name=row values="one,two,three" reset=true}
+ * {cycle name=row}
+ * 
+ * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle} + * (Smarty online manual) + * @author Monte Ohrt + * @author credit to Mark Priatel + * @author credit to Gerard + * @author credit to Jason Sweat + * @param array $params parameters + * Input: + * - name = name of cycle (optional) + * - values = comma separated list of values to cycle, + * or an array of values to cycle + * (this can be left out for subsequent calls) + * - reset = boolean - resets given var to true + * - print = boolean - print var or not. default is true + * - advance = boolean - whether or not to advance the cycle + * - delimiter = the value delimiter, default is "," + * - assign = boolean, assigns to template var instead of + * printed. + * @param object $smarty Smarty object + * @param object $template template object + * @return string|null + */ +function smarty_function_cycle($params, $smarty, $template) +{ + $name = (empty($params['name'])) ? 'default' : $params['name']; + $print = (isset($params['print'])) ? (bool)$params['print'] : true; + $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; + $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; + + if (!in_array('values', array_keys($params))) { + if(!isset($template->plugin_data['cycle'][$name]['values'])) { + trigger_error("cycle: missing 'values' parameter",E_USER_WARNING); + return; + } + } else { + if(isset($template->plugin_data['cycle'][$name]['values']) + && $template->plugin_data['cycle'][$name]['values'] != $params['values'] ) { + $template->plugin_data['cycle'][$name]['index'] = 0; + } + $template->plugin_data['cycle'][$name]['values'] = $params['values']; + } + + if (isset($params['delimiter'])) { + $template->plugin_data['cycle'][$name]['delimiter'] = $params['delimiter']; + } elseif (!isset($template->plugin_data['cycle'][$name]['delimiter'])) { + $template->plugin_data['cycle'][$name]['delimiter'] = ','; + } + + if(is_array($template->plugin_data['cycle'][$name]['values'])) { + $cycle_array = $template->plugin_data['cycle'][$name]['values']; + } else { + $cycle_array = explode($template->plugin_data['cycle'][$name]['delimiter'],$template->plugin_data['cycle'][$name]['values']); + } + + if(!isset($template->plugin_data['cycle'][$name]['index']) || $reset ) { + $template->plugin_data['cycle'][$name]['index'] = 0; + } + + if (isset($params['assign'])) { + $print = false; + $template->assign($params['assign'], $cycle_array[$template->plugin_data['cycle'][$name]['index']]); + } + + if($print) { + $retval = $cycle_array[$template->plugin_data['cycle'][$name]['index']]; + } else { + $retval = null; + } + + if($advance) { + if ( $template->plugin_data['cycle'][$name]['index'] >= count($cycle_array) -1 ) { + $template->plugin_data['cycle'][$name]['index'] = 0; + } else { + $template->plugin_data['cycle'][$name]['index']++; + } + } + + return $retval; +} +?> diff --git a/gosa-core/include/smarty/plugins/function.fetch.php b/gosa-core/include/smarty/plugins/function.fetch.php new file mode 100644 index 000000000..391ff1bb9 --- /dev/null +++ b/gosa-core/include/smarty/plugins/function.fetch.php @@ -0,0 +1,217 @@ + + * Name: fetch
+ * Purpose: fetch file, web or ftp data and display results + * @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch} + * (Smarty online manual) + * @author Monte Ohrt + * @param array $params parameters + * @param object $smarty Smarty object + * @param object $template template object + * @return string|null if the assign parameter is passed, Smarty assigns the + * result to a template variable + */ +function smarty_function_fetch($params, $smarty, $template) +{ + if (empty($params['file'])) { + trigger_error("[plugin] fetch parameter 'file' cannot be empty",E_USER_NOTICE); + return; + } + + $content = ''; + if ($template->security && !preg_match('!^(http|ftp)://!i', $params['file'])) { + if(!$smarty->security_handler->isTrustedResourceDir($params['file'])) { + return; + } + + // fetch the file + if($fp = @fopen($params['file'],'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + trigger_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'',E_USER_NOTICE); + return; + } + } else { + // not a local file + if(preg_match('!^http://!i',$params['file'])) { + // http fetch + if($uri_parts = parse_url($params['file'])) { + // set defaults + $host = $server_name = $uri_parts['host']; + $timeout = 30; + $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; + $agent = "Smarty Template Engine ".$smarty->_version; + $referer = ""; + $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; + $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; + $_is_proxy = false; + if(empty($uri_parts['port'])) { + $port = 80; + } else { + $port = $uri_parts['port']; + } + if(!empty($uri_parts['user'])) { + $user = $uri_parts['user']; + } + if(!empty($uri_parts['pass'])) { + $pass = $uri_parts['pass']; + } + // loop through parameters, setup headers + foreach($params as $param_key => $param_value) { + switch($param_key) { + case "file": + case "assign": + case "assign_headers": + break; + case "user": + if(!empty($param_value)) { + $user = $param_value; + } + break; + case "pass": + if(!empty($param_value)) { + $pass = $param_value; + } + break; + case "accept": + if(!empty($param_value)) { + $accept = $param_value; + } + break; + case "header": + if(!empty($param_value)) { + if(!preg_match('![\w\d-]+: .+!',$param_value)) { + trigger_error("[plugin] invalid header format '".$param_value."'",E_USER_NOTICE); + return; + } else { + $extra_headers[] = $param_value; + } + } + break; + case "proxy_host": + if(!empty($param_value)) { + $proxy_host = $param_value; + } + break; + case "proxy_port": + if(!preg_match('!\D!', $param_value)) { + $proxy_port = (int) $param_value; + } else { + trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); + return; + } + break; + case "agent": + if(!empty($param_value)) { + $agent = $param_value; + } + break; + case "referer": + if(!empty($param_value)) { + $referer = $param_value; + } + break; + case "timeout": + if(!preg_match('!\D!', $param_value)) { + $timeout = (int) $param_value; + } else { + trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); + return; + } + break; + default: + trigger_error("[plugin] unrecognized attribute '".$param_key."'",E_USER_NOTICE); + return; + } + } + if(!empty($proxy_host) && !empty($proxy_port)) { + $_is_proxy = true; + $fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout); + } else { + $fp = fsockopen($server_name,$port,$errno,$errstr,$timeout); + } + + if(!$fp) { + trigger_error("[plugin] unable to fetch: $errstr ($errno)",E_USER_NOTICE); + return; + } else { + if($_is_proxy) { + fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); + } else { + fputs($fp, "GET $uri HTTP/1.0\r\n"); + } + if(!empty($host)) { + fputs($fp, "Host: $host\r\n"); + } + if(!empty($accept)) { + fputs($fp, "Accept: $accept\r\n"); + } + if(!empty($agent)) { + fputs($fp, "User-Agent: $agent\r\n"); + } + if(!empty($referer)) { + fputs($fp, "Referer: $referer\r\n"); + } + if(isset($extra_headers) && is_array($extra_headers)) { + foreach($extra_headers as $curr_header) { + fputs($fp, $curr_header."\r\n"); + } + } + if(!empty($user) && !empty($pass)) { + fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n"); + } + + fputs($fp, "\r\n"); + while(!feof($fp)) { + $content .= fgets($fp,4096); + } + fclose($fp); + $csplit = preg_split("!\r\n\r\n!",$content,2); + + $content = $csplit[1]; + + if(!empty($params['assign_headers'])) { + $template->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0])); + } + } + } else { + trigger_error("[plugin fetch] unable to parse URL, check syntax",E_USER_NOTICE); + return; + } + } else { + // ftp fetch + if($fp = @fopen($params['file'],'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + trigger_error('[plugin] fetch cannot read file \'' . $params['file'] .'\'',E_USER_NOTICE); + return; + } + } + + } + + + if (!empty($params['assign'])) { + $template->assign($params['assign'],$content); + } else { + return $content; + } +} + +?> diff --git a/gosa-core/include/smarty/plugins/function.html_checkboxes.php b/gosa-core/include/smarty/plugins/function.html_checkboxes.php new file mode 100644 index 000000000..ac72f3fdf --- /dev/null +++ b/gosa-core/include/smarty/plugins/function.html_checkboxes.php @@ -0,0 +1,145 @@ + + * Type: function
+ * Name: html_checkboxes
+ * Date: 24.Feb.2003
+ * Purpose: Prints out a list of checkbox input types
+ * Examples: + *
+ * {html_checkboxes values=$ids output=$names}
+ * {html_checkboxes values=$ids name='box' separator='
' output=$names} + * {html_checkboxes values=$ids checked=$checked separator='
' output=$names} + *
+ * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} + * (Smarty online manual) + * @author Christopher Kvarme + * @author credits to Monte Ohrt + * @version 1.0 + * @param array $params parameters + * Input:
+ * - name (optional) - string default "checkbox" + * - values (required) - array + * - options (optional) - associative array + * - checked (optional) - array default not set + * - separator (optional) - ie
or   + * - output (optional) - the output next to each checkbox + * - assign (optional) - assign the output as an array to this variable + * @param object $smarty Smarty object + * @param object $template template object + * @return string + * @uses smarty_function_escape_special_chars() + */ +function smarty_function_html_checkboxes($params, $smarty, $template) +{ + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + //$smarty->loadPlugin('Smarty_shared_escape_special_chars'); + + $name = 'checkbox'; + $values = null; + $options = null; + $selected = null; + $separator = ''; + $labels = true; + $output = null; + + $extra = ''; + + foreach($params as $_key => $_val) { + switch($_key) { + case 'name': + case 'separator': + $$_key = $_val; + break; + + case 'labels': + $$_key = (bool)$_val; + break; + + case 'options': + $$_key = (array)$_val; + break; + + case 'values': + case 'output': + $$_key = array_values((array)$_val); + break; + + case 'checked': + case 'selected': + $selected = array_map('strval', array_values((array)$_val)); + break; + + case 'checkboxes': + trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); + $options = (array)$_val; + break; + + case 'assign': + break; + + default: + if(!is_array($_val)) { + $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; + } else { + trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; + } + } + + if (!isset($options) && !isset($values)) + return ''; /* raise error here? */ + + settype($selected, 'array'); + $_html_result = array(); + + if (isset($options)) { + + foreach ($options as $_key=>$_val) + $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); + + + } else { + foreach ($values as $_i=>$_key) { + $_val = isset($output[$_i]) ? $output[$_i] : ''; + $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); + } + + } + + if(!empty($params['assign'])) { + $template->assign($params['assign'], $_html_result); + } else { + return implode("\n",$_html_result); + } + +} + +function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) { + $_output = ''; + if ($labels) $_output .= ''; + $_output .= $separator; + + return $_output; +} + +?> diff --git a/gosa-core/include/smarty/plugins/function.html_image.php b/gosa-core/include/smarty/plugins/function.html_image.php new file mode 100644 index 000000000..3f031dc00 --- /dev/null +++ b/gosa-core/include/smarty/plugins/function.html_image.php @@ -0,0 +1,139 @@ + +* Name: html_image
+* Date: Feb 24, 2003
+* Purpose: format HTML tags for the image
+* Examples: {html_image file="/images/masthead.gif"} +* Output: +* +* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image} + (Smarty online manual) +* @author Monte Ohrt +* @author credits to Duda +* @version 1.0 +* @param array $params parameters +* Input:
+* - file = file (and path) of image (required) +* - height = image height (optional, default actual height) +* - width = image width (optional, default actual width) +* - basedir = base directory for absolute paths, default +* is environment variable DOCUMENT_ROOT +* - path_prefix = prefix for path output (optional, default empty) +* @param object $smarty Smarty object +* @param object $template template object +* @return string +* @uses smarty_function_escape_special_chars() +*/ +function smarty_function_html_image($params, $smarty, $template) +{ + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + //$smarty->loadPlugin('Smarty_shared_escape_special_chars'); + + $alt = ''; + $file = ''; + $height = ''; + $width = ''; + $extra = ''; + $prefix = ''; + $suffix = ''; + $path_prefix = ''; + $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; + $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; + foreach($params as $_key => $_val) { + switch ($_key) { + case 'file': + case 'height': + case 'width': + case 'dpi': + case 'path_prefix': + case 'basedir': + $$_key = $_val; + break; + + case 'alt': + if (!is_array($_val)) { + $$_key = smarty_function_escape_special_chars($_val); + } else { + throw new Exception ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; + + case 'link': + case 'href': + $prefix = ''; + $suffix = ''; + break; + + default: + if (!is_array($_val)) { + $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; + } else { + throw new Exception ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; + } + } + + if (empty($file)) { + trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); + return; + } + + if (substr($file, 0, 1) == '/') { + $_image_path = $basedir . $file; + } else { + $_image_path = $file; + } + + if (!isset($params['width']) || !isset($params['height'])) { + if (!$_image_data = @getimagesize($_image_path)) { + if (!file_exists($_image_path)) { + trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); + return; + } else if (!is_readable($_image_path)) { + trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); + return; + } else { + trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); + return; + } + } + if ($template->security) { + if (!$smarty->security_handler->isTrustedResourceDir($_image_path)) { + return; + } + } + + if (!isset($params['width'])) { + $width = $_image_data[0]; + } + if (!isset($params['height'])) { + $height = $_image_data[1]; + } + } + + if (isset($params['dpi'])) { + if (strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) { + $dpi_default = 72; + } else { + $dpi_default = 96; + } + $_resize = $dpi_default / $params['dpi']; + $width = round($width * $_resize); + $height = round($height * $_resize); + } + + return $prefix . '' . $alt . '' . $suffix; +} + +?> diff --git a/gosa-core/include/smarty/plugins/function.html_options.php b/gosa-core/include/smarty/plugins/function.html_options.php new file mode 100644 index 000000000..69f56e801 --- /dev/null +++ b/gosa-core/include/smarty/plugins/function.html_options.php @@ -0,0 +1,122 @@ + +* Name: html_options
+* Purpose: Prints the list of