From: Michael M Slusarz Date: Thu, 9 Jul 2009 20:46:17 +0000 (-0600) Subject: Use Horde_Template:: (for now) X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=16c5fa5780f25e019c0b4fbdda398881bd893b01;p=horde.git Use Horde_Template:: (for now) --- diff --git a/imp/acl.php b/imp/acl.php index 539ba5203..813954261 100644 --- a/imp/acl.php +++ b/imp/acl.php @@ -145,7 +145,7 @@ $chunk = Horde_Util::nonInputVar('chunk'); Prefs_UI::generateHeader(null, $chunk); /* Set up template. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('aclurl', Horde::applicationUrl('acl.php')); $t->set('forminput', Horde_Util::formInput()); diff --git a/imp/ajax.php b/imp/ajax.php index 0acd370e0..12d6a0a32 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -607,7 +607,7 @@ case 'ShowPortal': $result = new stdClass; $result->portal = ''; if (!empty($blocks)) { - $t = new IMP_Template(IMP_TEMPLATES . '/imp/'); + $t = new Horde_Template(IMP_TEMPLATES . '/imp/'); $t->set('block', $blocks); $result->portal = $t->fetch('portal.html'); } diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index 930580f2f..31561338c 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -305,7 +305,7 @@ if ($get_sig && !empty($sig)) { : $msg . "\n" . $sig; } -$t = new IMP_Template(IMP_TEMPLATES . '/imp/'); +$t = new Horde_Template(IMP_TEMPLATES . '/imp/'); $t->setOption('gettext', true); $t->set('title', $title); $t->set('closelink', Horde::img('close.png', 'X', array('id' => 'compose_close'), $registry->getImageDir('horde'))); diff --git a/imp/compose.php b/imp/compose.php index 0bee14879..8a279519c 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -33,7 +33,7 @@ function _popupSuccess() $menu->add(Horde::applicationUrl('compose.php'), _("New Message"), 'compose.png'); $menu->add('', _("Close this window"), 'close.png', $GLOBALS['registry']->getImageDir('horde'), '', 'window.close();'); require IMP_TEMPLATES . '/common-header.inc'; - $success_template = new IMP_Template(); + $success_template = new Horde_Template(); $success_template->set('menu', $menu->render()); echo $success_template->fetch(IMP_TEMPLATES . '/compose/success.html'); IMP::status(); @@ -807,7 +807,7 @@ if (!$redirect) { /* Set up the base template now. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('post_action', Horde_Util::addParameter(Horde::applicationUrl('compose.php'), 'uniq', uniqid(mt_rand()))); $t->set('allow_compose', !$compose_disable); diff --git a/imp/contacts.php b/imp/contacts.php index 1d2db1e06..e0e5f3917 100644 --- a/imp/contacts.php +++ b/imp/contacts.php @@ -62,7 +62,7 @@ foreach (explode('|', Horde_Util::getFormData('sa')) as $addr) { } /* Prepare the contacts template. */ -$template = new IMP_Template(); +$template = new Horde_Template(); $template->setOption('gettext', true); $template->set('action', Horde::url(Horde_Util::addParameter(Horde::applicationUrl('contacts.php'), array('uniq' => uniqid(mt_rand()))))); diff --git a/imp/fetchmailprefs.php b/imp/fetchmailprefs.php index a8e27a00b..e68a46ee7 100644 --- a/imp/fetchmailprefs.php +++ b/imp/fetchmailprefs.php @@ -98,7 +98,7 @@ $app = 'imp'; $chunk = Horde_Util::nonInputVar('chunk'); /* Prepare template. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('navcell', Horde_Util::bufferOutput(array('Prefs_UI', 'generateNavigationCell'), 'fetchmail')); $t->set('fetchurl', $fetch_url); diff --git a/imp/filterprefs.php b/imp/filterprefs.php index 4cafcc443..a04ce52a5 100644 --- a/imp/filterprefs.php +++ b/imp/filterprefs.php @@ -53,7 +53,7 @@ $chunk = Horde_Util::nonInputVar('chunk'); $group = 'filters'; Prefs_UI::generateHeader(null, $chunk); -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('navcell', Horde_Util::bufferOutput(array('Prefs_UI', 'generateNavigationCell'), 'filters')); $t->set('prefsurl', IMP::prefsURL(true)); diff --git a/imp/folders.php b/imp/folders.php index 3d2839b7d..88e886e9d 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -269,7 +269,7 @@ case 'folders_empty_mailbox_confirm': require IMP_TEMPLATES . '/common-header.inc'; IMP::menu(); - $template = new IMP_Template(); + $template = new Horde_Template(); $template->setOption('gettext', true); $template->set('delete', ($actionID == 'delete_folder_confirm')); $template->set('empty', ($actionID == 'folders_empty_mailbox_confirm')); @@ -310,7 +310,7 @@ case 'mbox_size': $loop[] = $data; } - $template = new IMP_Template(); + $template = new Horde_Template(); $template->setOption('gettext', true); $template->set('folders', $loop); $template->set('folders_url', $folders_url); @@ -336,7 +336,7 @@ if ($_SESSION['imp']['file_upload'] && ($actionID == 'import_mbox')) { IMP::quota(); /* Prepare import template. */ - $i_template = new IMP_Template(); + $i_template = new Horde_Template(); $i_template->setOption('gettext', true); $i_template->set('folders_url', $folders_url); $i_template->set('import_folder', $folder_list[0]); @@ -361,7 +361,7 @@ IMP::addInlineScript(array( /* Prepare the header template. */ $refresh_title = _("Reload View"); -$head_template = new IMP_Template(); +$head_template = new Horde_Template(); $head_template->setOption('gettext', true); $head_template->set('title', $refresh_title); $head_template->set('folders_url', $folders_url); @@ -374,7 +374,7 @@ $head_template->set('refresh', Horde::link($folders_url, $refresh_title, '', '', $head_template->set('folders_token', $folders_token); /* Prepare the actions template. */ -$a_template = new IMP_Template(); +$a_template = new Horde_Template(); $a_template->setOption('gettext', true); $a_template->set('id', 0); $a_template->set('javascript', $browser->hasFeature('javascript')); @@ -494,7 +494,7 @@ foreach ($raw_rows as $val) { } /* Render the rows now. */ -$template = new IMP_Template(); +$template = new Horde_Template(); $template->setOption('gettext', true); $template->set('rows', $rows); diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 5d78a9f63..d63d54535 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -625,7 +625,7 @@ class IMP */ static public function menu() { - $t = new IMP_Template(); + $t = new Horde_Template(); $t->set('forminput', Horde_Util::formInput()); $t->set('use_folders', ($_SESSION['imp']['protocol'] != 'pop') && $GLOBALS['conf']['user']['allow_folders'], true); if ($t->get('use_folders')) { @@ -666,7 +666,7 @@ class IMP { $quotadata = self::quotaData(true); if (!empty($quotadata)) { - $t = new IMP_Template(); + $t = new Horde_Template(); $t->set('class', $quotadata['class']); $t->set('message', $quotadata['message']); echo $t->fetch(IMP_TEMPLATES . '/quota/quota.html'); @@ -751,7 +751,7 @@ class IMP */ static public function getNewMessagePopup($var) { - $t = new IMP_Template(); + $t = new Horde_Template(); $t->setOption('gettext', true); if (is_array($var)) { if (empty($var)) { diff --git a/imp/lib/Identity/imp.php b/imp/lib/Identity/imp.php index f77939231..355974cc5 100644 --- a/imp/lib/Identity/imp.php +++ b/imp/lib/Identity/imp.php @@ -49,7 +49,7 @@ class Identity_imp extends Identity */ function __construct() { - parent::Identity(); + parent::__construct(); $this->_properties = array_merge( $this->_properties, array('replyto_addr', 'alias_addr', 'tieto_addr', 'bcc_addr', diff --git a/imp/lib/Template.php b/imp/lib/Template.php deleted file mode 100644 index 109f227b9..000000000 --- a/imp/lib/Template.php +++ /dev/null @@ -1,507 +0,0 @@ -. - * - * Horde_Template provides a basic template engine with tags, loops, - * and if conditions. However, it is also a simple interface with - * several essential functions: set(), fetch(), and - * parse(). Subclasses or decorators can implement (or delegate) these - * three methods, plus the options api, and easily implement other - * template engines (PHP code, XSLT, etc.) without requiring usage - * changes. - * - * Compilation code adapted from code written by Bruno Pedro . - * - * Copyright 2002-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @author Chuck Hagenbuch - * @author Michael Slusarz - * @package Horde_Template - */ - -/** The identifier to use for memory-only templates. */ -define('IMP_TEMPLATE_STRING', '**string'); - -class IMP_Template { - - /** - * The Horde_Cache object to use. - * - * @var Horde_Cache - */ - var $_cache; - - /** - * Option values. - * - * @var array - */ - var $_options = array(); - - /** - * Directory that templates should be read from. - * - * @var string - */ - var $_basepath = ''; - - /** - * Tag (scalar) values. - * - * @var array - */ - var $_scalars = array(); - - /** - * Loop tag values. - * - * @var array - */ - var $_arrays = array(); - - /** - * Path to template source. - * - * @var string - */ - var $_templateFile = null; - - /** - * Template source. - * - * @var string - */ - var $_template = null; - - /** - * Foreach variable mappings. - * - * @var array - */ - var $_foreachMap = array(); - - /** - * Foreach variable incrementor. - * - * @var integer - */ - var $_foreachVar = 0; - - /** - * preg_match() cache. - * - * @var array - */ - var $_pregcache = array(); - - /** - * Constructor. - * - * @param string $basepath The directory where templates are read from. - */ - function IMP_Template($basepath = null) - { - if (!is_null($basepath)) { - $this->_basepath = $basepath; - } - - - $this->_cache = IMP::getCache(); - } - - /** - * Sets an option. - * Currently available options are: - *
-     * 'debug' - Output debugging information to screen
-     * 'forcecompile' - Force a compilation on every page load
-     * 'gettext' - Activate gettext detection
-     * 
-     *
-     * @param string $option  The option name.
-     * @param mixed $val      The option's value.
-     */
-    function setOption($option, $val)
-    {
-        $this->_options[$option] = $val;
-    }
-
-    /**
-     * Set the template contents to a string.
-     *
-     * @param string $template  The template text.
-     */
-    function setTemplate($template)
-    {
-        $this->_template = $template;
-        $this->_parse();
-        $this->_templateFile = IMP_TEMPLATE_STRING;
-    }
-
-    /**
-     * Returns an option's value.
-     *
-     * @param string $option  The option name.
-     *
-     * @return mixed  The option's value.
-     */
-    function getOption($option)
-    {
-        return isset($this->_options[$option]) ? $this->_options[$option] : null;
-    }
-
-    /**
-     * Sets a tag, loop, or if variable.
-     *
-     * @param string|array $tag   Either the tag name or a hash with tag names
-     *                            as keys and tag values as values.
-     * @param mixed        $var   The value to replace the tag with.
-     */
-    function set($tag, $var)
-    {
-        if (is_array($tag)) {
-            foreach ($tag as $tTag => $tVar) {
-                $this->set($tTag, $tVar);
-            }
-        } elseif (is_array($var) || is_object($var)) {
-            $this->_arrays[$tag] = $var;
-        } else {
-            $this->_scalars[$tag] = $var;
-        }
-    }
-
-    /**
-     * Returns the value of a tag or loop.
-     *
-     * @param string $tag  The tag name.
-     *
-     * @return mixed  The tag value or null if the tag hasn't been set yet.
-     */
-    function get($tag)
-    {
-        if (isset($this->_arrays[$tag])) {
-            return $this->_arrays[$tag];
-        }
-        if (isset($this->_scalars[$tag])) {
-            return $this->_scalars[$tag];
-        }
-        return null;
-    }
-
-    /**
-     * Fetches a template from the specified file and return the parsed
-     * contents.
-     *
-     * @param string $filename  The file to fetch the template from.
-     *
-     * @return string  The parsed template.
-     */
-    function fetch($filename = null)
-    {
-        $file = $this->_basepath . $filename;
-        $force = $this->getOption('forcecompile');
-
-        if (!is_null($filename) && ($file != $this->_templateFile)) {
-            $this->_template = $this->_templateFile = null;
-        }
-
-        /* First, check for a cached compiled version. */
-        $cacheid = 'horde_template|' . filemtime($file) . '|' . $file . '|'
-            . $this->getOption('gettext');
-        if (!$force && is_null($this->_template) && $this->_cache) {
-            $this->_template = $this->_cache->get($cacheid, 0);
-            if ($this->_template === false) {
-                $this->_template = null;
-            }
-        }
-
-        /* Parse and compile the template. */
-        if ($force || is_null($this->_template)) {
-            $this->_template = str_replace("\n", " \n", file_get_contents($file));
-            $this->_parse();
-            if (isset($cacheid) &&
-                !$this->_cache->set($cacheid, $this->_template)) {
-                Horde::logMessage(sprintf(_("Could not save the compiled template file '%s'."), $file), __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
-        }
-
-        $this->_templateFile = $file;
-
-        /* Template debugging. */
-        if ($this->getOption('debug')) {
-            echo '
' . htmlspecialchars($this->_template) . '
'; - } - - return $this->parse(); - } - - /** - * Parses all variables/tags in the template. - * - * @param string $contents The unparsed template. - * - * @return string The parsed template. - */ - function parse($contents = null) - { - if (!is_null($contents)) { - $this->setTemplate(str_replace("\n", " \n", $contents)); - } - - /* Evaluate the compiled template and return the output. */ - ob_start(); - eval('?>' . $this->_template); - return is_null($contents) ? ob_get_clean() : str_replace(" \n", "\n", ob_get_clean()); - } - - /** - * Parses all variables/tags in the template. - */ - function _parse() - { - // Escape XML instructions. - $this->_template = preg_replace('/\?>|<\?/', - '', - $this->_template); - - // Parse gettext tags, if the option is enabled. - if ($this->getOption('gettext')) { - $this->_parseGettext(); - } - - // Process ifs. - $this->_parseIf(); - - // Process loops and arrays. - $this->_parseLoop(); - - // Process base scalar tags. Needs to be after _parseLoop() as we - // rely on _foreachMap(). - $this->_parseTags(); - - // Finally, process any associative array scalar tags. - $this->_parseAssociativeTags(); - } - - /** - * Parses gettext tags. - * - * @access private - */ - function _parseGettext() - { - if (preg_match_all("/(.+?)<\/gettext>/s", $this->_template, $matches, PREG_SET_ORDER)) { - $replace = array(); - foreach ($matches as $val) { - $replace[$val[0]] = ''; - } - $this->_doReplace($replace); - } - } - - /** - * Parses 'if' statements. - * - * @access private - * - * @param string $key The key prefix to parse. - */ - function _parseIf($key = null) - { - $replace = array(); - - foreach ($this->_doSearch('if', $key) as $val) { - $replace[$val[0]] = '_generatePHPVar('scalars', $val[1]) . ') || !empty(' . $this->_generatePHPVar('arrays', $val[1]) . ')): ?>'; - $replace[$val[2]] = ''; - - // Check for else statement. - foreach ($this->_doSearch('else', $key) as $val2) { - $replace[$val2[0]] = ''; - $replace[$val2[2]] = ''; - } - } - - $this->_doReplace($replace); - } - - /** - * Parses the given array for any loops or other uses of the array. - * - * @access private - * - * @param string $key The key prefix to parse. - */ - function _parseLoop($key = null) - { - $replace = array(); - - foreach ($this->_doSearch('loop', $key) as $val) { - $divider = null; - - // See if we have a divider. - if (preg_match("/(.*)<\/divider:" . $val[1] . ">/sU", $this->_template, $m)) { - $divider = $m[1]; - $replace[$m[0]] = ''; - } - - if (!isset($this->_foreachMap[$val[1]])) { - $this->_foreachMap[$val[1]] = ++$this->_foreachVar; - } - $varId = $this->_foreachMap[$val[1]]; - $var = $this->_generatePHPVar('arrays', $val[1]); - - $replace[$val[0]] = '_generatePHPVar('arrays', $val[1]) . ' as $k' . $varId . ' => $v' . $varId . '): ?>'; - $replace[$val[2]] = ''; - - // Parse ifs. - $this->_parseIf($val[1]); - - // Parse interior loops. - $this->_parseLoop($val[1]); - - // Replace scalars. - $this->_parseTags($val[1]); - } - - $this->_doReplace($replace); - } - - /** - * Replaces 'tag' tags with their PHP equivalents. - * - * @access private - * - * @param string $key The key prefix to parse. - */ - function _parseTags($key = null) - { - $replace = array(); - - foreach ($this->_doSearch('tag', $key, true) as $val) { - $replace_text = '_foreachMap[$val[1]])) { - $var = $this->_foreachMap[$val[1]]; - $replace_text .= 'if (isset($v' . $var . ')) { echo is_array($v' . $var . ') ? $k' . $var . ' : $v' . $var . '; } else'; - } - $var = $this->_generatePHPVar('scalars', $val[1]); - $replace[$val[0]] = $replace_text . 'if (isset(' . $var . ')) { echo ' . $var . '; } ?>'; - } - - $this->_doReplace($replace); - } - - /** - * Parse associative tags (i.e. ). - * - * @access private - */ - function _parseAssociativeTags() - { - $replace = array(); - - foreach ($this->_pregcache['tag'] as $key => $val) { - $parts = explode('.', $val[1]); - $var = '$this->_arrays[\'' . $parts[0] . '\'][\'' . $parts[1] . '\']'; - $replace[$val[0]] = ''; - unset($this->_pregcache['tag'][$key]); - } - - $this->_doReplace($replace); - } - - /** - * Output the correct PHP variable string for use in template space. - * - * @access private - */ - function _generatePHPVar($tag, $key) - { - $out = ''; - - $a = explode('.', $key); - $a_count = count($a); - - if ($a_count == 1) { - switch ($tag) { - case 'arrays': - $out = '$this->_arrays'; - break; - - case 'scalars': - $out = '$this->_scalars'; - break; - } - } else { - $out = '$v' . $this->_foreachMap[implode('.', array_slice($a, 0, -1))]; - } - - return $out . '[\'' . end($a) . '\']'; - } - - /** - * TODO - * - * @access private - */ - function _doSearch($tag, $key, $noclose = false) - { - $out = array(); - $level = (is_null($key)) ? 0 : substr_count($key, '.') + 1; - - if (!isset($this->_pregcache[$key])) { - $regex = ($noclose) ? - "/<" . $tag . ":(.+?)\s\/>/" : - "/<" . $tag . ":([^>]+)>/"; - preg_match_all($regex, $this->_template, $this->_pregcache[$tag], PREG_SET_ORDER); - } - - foreach ($this->_pregcache[$tag] as $pkey => $val) { - $val_level = substr_count($val[1], '.'); - $add = false; - if (is_null($key)) { - $add = !$val_level; - } else { - $add = (($val_level == $level) && - (strpos($val[1], $key . '.') === 0)); - } - if ($add) { - if (!$noclose) { - $val[2] = ''; - } - $out[] = $val; - unset($this->_pregcache[$tag][$pkey]); - } - } - - return $out; - } - - /** - * TODO - * - * @access private - */ - function _doReplace($replace) - { - if (empty($replace)) { - return; - } - - $search = array(); - - foreach (array_keys($replace) as $val) { - $search[] = '/' . preg_quote($val, '/') . '/'; - } - - $this->_template = preg_replace($search, array_values($replace), $this->_template); - } - -} diff --git a/imp/lib/UI/Mailbox.php b/imp/lib/UI/Mailbox.php index 0a3925925..22f489deb 100644 --- a/imp/lib/UI/Mailbox.php +++ b/imp/lib/UI/Mailbox.php @@ -32,7 +32,7 @@ class IMP_UI_Mailbox * * @param string $mailbox The current mailbox. */ - function __construct($mailbox = null) + public function __construct($mailbox = null) { $this->_mailbox = $mailbox; } diff --git a/imp/login.php b/imp/login.php index 915908a90..e746384c1 100644 --- a/imp/login.php +++ b/imp/login.php @@ -252,7 +252,7 @@ if ($browser->isMobile()) { $display_list = ($show_list && !empty($hordeauth_servers_list)); /* Prepare the login template. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $tabindex = 0; diff --git a/imp/mailbox.php b/imp/mailbox.php index 09c991a43..f6365f521 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -22,7 +22,7 @@ function _outputSummaries($msgs, $mbox) } if (!isset($template)) { - $template = new IMP_Template(); + $template = new Horde_Template(); $template->setOption('gettext', true); // Some browsers have trouble with hidden overflow in table cells @@ -431,7 +431,7 @@ IMP::status(); IMP::quota(); /* Prepare the header template. */ -$hdr_template = new IMP_Template(); +$hdr_template = new Horde_Template(); $hdr_template->set('title', $title); $hdr_template->set('pagetitle', $pagetitle); if ($readonly) { @@ -474,7 +474,7 @@ if (empty($pageOb['end'])) { if ($pageOb['anymsg'] && isset($deleted_prompt)) { /* Show 'Show Deleted' prompt if mailbox has no viewable message but has hidden, deleted messages. */ - $del_template = new IMP_Template(); + $del_template = new Horde_Template(); $del_template->set('hide', Horde::widget(Horde_Util::addParameter($refresh_url, array('actionID' => 'hide_deleted', 'mailbox_token' => $mailbox_token)), $deleted_prompt, 'widget hideAction', '', '', $deleted_prompt)); if (!$readonly) { $del_template->set('purge', Horde::widget(Horde_Util::addParameter($refresh_url, array('actionID' => 'expunge_mailbox', 'mailbox_token' => $mailbox_token)), _("Purge Deleted"), 'widget purgeAction', '', '', _("Pur_ge Deleted"))); @@ -482,7 +482,7 @@ if (empty($pageOb['end'])) { echo $del_template->fetch(IMP_TEMPLATES . '/mailbox/actions_deleted.html'); } - $empty_template = new IMP_Template(); + $empty_template = new Horde_Template(); $empty_template->setOption('gettext', true); echo $empty_template->fetch(IMP_TEMPLATES . '/mailbox/empty_mailbox.html'); require $registry->get('templates', 'horde') . '/common-footer.inc'; @@ -496,7 +496,7 @@ if ($pageOb['msgcount']) { $use_trash = $prefs->getValue('use_trash'); /* Prepare the navbar template. */ - $n_template = new IMP_Template(); + $n_template = new Horde_Template(); $n_template->setOption('gettext', true); $n_template->set('id', 1); $n_template->set('sessiontag', Horde_Util::formInput()); @@ -531,7 +531,7 @@ if ($pageOb['msgcount']) { echo $n_template->fetch(IMP_TEMPLATES . '/mailbox/navbar.html'); /* Prepare the actions template. */ - $a_template = new IMP_Template(); + $a_template = new Horde_Template(); if (!$readonly) { $del_class = ($use_trash && (($imp_mbox['mailbox'] == (IMP::folderPref($prefs->getValue('trash_folder'), true))) || !is_null($vtrash))) ? 'permdeleteAction' @@ -677,7 +677,7 @@ if ($pageOb['msgcount']) { } /* Prepare the message headers template. */ - $mh_template = new IMP_Template(); + $mh_template = new Horde_Template(); $mh_template->setOption('gettext', true); $mh_template->set('check_all', Horde::getAccessKeyAndTitle(_("Check _All/None"))); $mh_template->set('form_tag', true); @@ -711,7 +711,7 @@ while (list(,$ob) = each($mbox_info['overview'])) { $folder_link = Horde::url(Horde_Util::addParameter('mailbox.php', 'mailbox', $ob['mailbox'])); $folder_link = Horde::link($folder_link, sprintf(_("View messages in %s"), IMP::displayFolder($ob['mailbox'])), 'smallheader') . IMP::displayFolder($ob['mailbox']) . ''; if (is_null($search_template)) { - $search_template = new IMP_Template(); + $search_template = new Horde_Template(); } $search_template->set('lastMbox', $lastMbox); $search_template->set('folder_link', $folder_link); @@ -860,7 +860,7 @@ while (list(,$ob) = each($mbox_info['overview'])) { _outputSummaries($msgs, $lastMbox); /* Prepare the message footers template. */ -$mf_template = new IMP_Template(); +$mf_template = new Horde_Template(); $mf_template->set('page', $pageOb['page']); echo $mf_template->fetch(IMP_TEMPLATES . '/mailbox/message_footers.html'); diff --git a/imp/message.php b/imp/message.php index 1f977d967..b76162d50 100644 --- a/imp/message.php +++ b/imp/message.php @@ -422,7 +422,7 @@ if (!IMP::$printMode) { } /* Prepare the navbar top template. */ - $t_template = new IMP_Template(); + $t_template = new Horde_Template(); $t_template->set('message_url', $message_url); $t_template->set('form_input', Horde_Util::formInput()); $t_template->set('mailbox', htmlspecialchars($imp_mbox['mailbox'])); @@ -435,7 +435,7 @@ if (!IMP::$printMode) { $t_template->set('message_token', $message_token); /* Prepare the navbar navigate template. */ - $n_template = new IMP_Template(); + $n_template = new Horde_Template(); $n_template->setOption('gettext', true); $n_template->set('readonly', $readonly); $n_template->set('usepop', $use_pop); @@ -473,7 +473,7 @@ if (!IMP::$printMode) { } /* Prepare the navbar actions template. */ - $a_template = new IMP_Template(); + $a_template = new Horde_Template(); $a_template->setOption('gettext', true); $a_template->set('readonly', $readonly); $compose_params = array('index' => $index, 'identity' => $identity, 'thismailbox' => $mailbox_name); @@ -569,7 +569,7 @@ $hdrs = array(); $i = 1; /* Prepare the main message template. */ -$m_template = new IMP_Template(); +$m_template = new Horde_Template(); foreach ($display_headers as $head => $val) { $hdrs[] = array('name' => $basic_headers[$head], 'val' => $val, 'i' => (++$i % 2)); } diff --git a/imp/pgp.php b/imp/pgp.php index e83023f75..ccec617c7 100644 --- a/imp/pgp.php +++ b/imp/pgp.php @@ -26,7 +26,7 @@ function _importKeyDialog($target) require IMP_TEMPLATES . '/common-header.inc'; IMP::status(); - $t = new IMP_Template(); + $t = new Horde_Template(); $t->setOption('gettext', true); $t->set('selfurl', Horde::applicationUrl('pgp.php')); $t->set('broken_mp_form', $GLOBALS['browser']->hasQuirk('broken_multipart_form')); @@ -314,7 +314,7 @@ $chunk = Horde_Util::nonInputVar('chunk'); Prefs_UI::generateHeader('pgp', $chunk); /* If PGP preference not active, do NOT show PGP Admin screen. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); if ($prefs->getValue('use_pgp')) { Horde::addScriptFile('prototype.js', 'horde', true); diff --git a/imp/rss.php b/imp/rss.php index d619ae7fd..9a9b512e9 100644 --- a/imp/rss.php +++ b/imp/rss.php @@ -81,7 +81,7 @@ $description = ($total_num == 0) ? _("No Messages") : sprintf(_("%u of %u messages in %s unread."), $unseen_num, $total_num, IMP::getLabel($mailbox)); -$t = new IMP_Template(); +$t = new Horde_Template(); $t->set('charset', Horde_Nls::getCharset()); $t->set('xsl', $registry->get('themesuri') . '/feed-rss.xsl'); $t->set('pubDate', htmlspecialchars(date('r'))); diff --git a/imp/saveimage.php b/imp/saveimage.php index 2e4ec53b9..41ca2a73c 100644 --- a/imp/saveimage.php +++ b/imp/saveimage.php @@ -36,7 +36,7 @@ case 'save_image': } /* Build the template. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('action', Horde::applicationUrl('saveimage.php')); $t->set('id', htmlspecialchars($id)); diff --git a/imp/search.php b/imp/search.php index 08ba910ae..b87d674e8 100644 --- a/imp/search.php +++ b/imp/search.php @@ -140,7 +140,7 @@ if (!$conf['user']['allow_folders']) { } /* Prepare the search template. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('action', Horde::applicationUrl('search.php')); diff --git a/imp/smime.php b/imp/smime.php index 8ebe52efc..141624f0c 100644 --- a/imp/smime.php +++ b/imp/smime.php @@ -16,7 +16,7 @@ function _importKeyDialog($target) require IMP_TEMPLATES . '/common-header.inc'; IMP::status(); - $t = new IMP_Template(); + $t = new Horde_Template(); $t->setOption('gettext', true); $t->set('selfurl', Horde::applicationUrl('smime.php')); $t->set('broken_mp_form', $GLOBALS['browser']->hasQuirk('broken_multipart_form')); @@ -242,7 +242,7 @@ try { } /* If S/MIME preference not active, do NOT show S/MIME Admin screen. */ -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('use_smime_help', Horde_Help::link('imp', 'smime-overview')); if ($openssl_check && $prefs->getValue('use_smime')) { diff --git a/imp/stationery.php b/imp/stationery.php index 4b5bddc11..f4ede2056 100644 --- a/imp/stationery.php +++ b/imp/stationery.php @@ -105,7 +105,7 @@ $app = 'imp'; $chunk = Horde_Util::nonInputVar('chunk'); Prefs_UI::generateHeader(null, $chunk); -$t = new IMP_Template(); +$t = new Horde_Template(); $t->setOption('gettext', true); $t->set('action', Horde::selfUrl()); $t->set('forminput', Horde_Util::formInput()); diff --git a/imp/thread.php b/imp/thread.php index d58e8131d..f44203c64 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -141,7 +141,7 @@ foreach ($loop_array as $mbox => $idxlist) { $imp_message = IMP_Message::singleton(); $imp_message->flag(array('\\seen'), $loop_array); -$template = new IMP_Template(); +$template = new Horde_Template(); $template->setOption('gettext', true); $template->set( 'subject', diff --git a/ingo/filters.php b/ingo/filters.php index 284a56b6c..424a1f0d5 100644 --- a/ingo/filters.php +++ b/ingo/filters.php @@ -301,7 +301,7 @@ if (count($filter_list) == 0) { } /* Output the template. */ - $template = new Ingo_Template(); + $template = new Horde_Template(); $template->set('down_img', $down_img); $template->set('up_img', $up_img); $template->set('filter', $display, true); diff --git a/ingo/lib/Template.php b/ingo/lib/Template.php deleted file mode 100644 index 71effba46..000000000 --- a/ingo/lib/Template.php +++ /dev/null @@ -1,511 +0,0 @@ -. - * - * Horde_Template provides a basic template engine with tags, loops, - * and if conditions. However, it is also a simple interface with - * several essential functions: set(), fetch(), and - * parse(). Subclasses or decorators can implement (or delegate) these - * three methods, plus the options api, and easily implement other - * template engines (PHP code, XSLT, etc.) without requiring usage - * changes. - * - * Compilation code adapted from code written by Bruno Pedro . - * - * Copyright 2002-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @author Chuck Hagenbuch - * @author Michael Slusarz - * @package Horde_Template - */ - -/** The identifier to use for memory-only templates. */ -define('INGO_TEMPLATE_STRING', '**string'); - -class Ingo_Template { - - /** - * The Horde_Cache object to use. - * - * @var Horde_Cache - */ - var $_cache; - - /** - * Option values. - * - * @var array - */ - var $_options = array(); - - /** - * Directory that templates should be read from. - * - * @var string - */ - var $_basepath = ''; - - /** - * Tag (scalar) values. - * - * @var array - */ - var $_scalars = array(); - - /** - * Loop tag values. - * - * @var array - */ - var $_arrays = array(); - - /** - * Path to template source. - * - * @var string - */ - var $_templateFile = null; - - /** - * Template source. - * - * @var string - */ - var $_template = null; - - /** - * Foreach variable mappings. - * - * @var array - */ - var $_foreachMap = array(); - - /** - * Foreach variable incrementor. - * - * @var integer - */ - var $_foreachVar = 0; - - /** - * preg_match() cache. - * - * @var array - */ - var $_pregcache = array(); - - /** - * Constructor. - * - * @param string $basepath The directory where templates are read from. - */ - function Ingo_Template($basepath = null) - { - if (!is_null($basepath)) { - $this->_basepath = $basepath; - } - - if (!empty($GLOBALS['conf']['cache']['driver'])) { - require_once 'Horde/Cache.php'; - $this->_cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - } - - // DEBUGGING - $this->setOption('forcecompile', true); - } - - /** - * Sets an option. - * Currently available options are: - *
-     * 'debug' - Output debugging information to screen
-     * 'forcecompile' - Force a compilation on every page load
-     * 'gettext' - Activate gettext detection
-     * 
-     *
-     * @param string $option  The option name.
-     * @param mixed $val      The option's value.
-     */
-    function setOption($option, $val)
-    {
-        $this->_options[$option] = $val;
-    }
-
-    /**
-     * Set the template contents to a string.
-     *
-     * @param string $template  The template text.
-     */
-    function setTemplate($template)
-    {
-        $this->_template = $template;
-        $this->_parse();
-        $this->_templateFile = INGO_TEMPLATE_STRING;
-    }
-
-    /**
-     * Returns an option's value.
-     *
-     * @param string $option  The option name.
-     *
-     * @return mixed  The option's value.
-     */
-    function getOption($option)
-    {
-        return isset($this->_options[$option]) ? $this->_options[$option] : null;
-    }
-
-    /**
-     * Sets a tag, loop, or if variable.
-     *
-     * @param string|array $tag   Either the tag name or a hash with tag names
-     *                            as keys and tag values as values.
-     * @param mixed        $var   The value to replace the tag with.
-     */
-    function set($tag, $var)
-    {
-        if (is_array($tag)) {
-            foreach ($tag as $tTag => $tVar) {
-                $this->set($tTag, $tVar);
-            }
-        } elseif (is_array($var) || is_object($var)) {
-            $this->_arrays[$tag] = $var;
-        } else {
-            $this->_scalars[$tag] = $var;
-        }
-    }
-
-    /**
-     * Returns the value of a tag or loop.
-     *
-     * @param string $tag  The tag name.
-     *
-     * @return mixed  The tag value or null if the tag hasn't been set yet.
-     */
-    function get($tag)
-    {
-        if (isset($this->_arrays[$tag])) {
-            return $this->_arrays[$tag];
-        }
-        if (isset($this->_scalars[$tag])) {
-            return $this->_scalars[$tag];
-        }
-        return null;
-    }
-
-    /**
-     * Fetches a template from the specified file and return the parsed
-     * contents.
-     *
-     * @param string $filename  The file to fetch the template from.
-     *
-     * @return string  The parsed template.
-     */
-    function fetch($filename = null)
-    {
-        $file = $this->_basepath . $filename;
-        $force = $this->getOption('forcecompile');
-
-        if (!is_null($filename) && ($file != $this->_templateFile)) {
-            $this->_template = $this->_templateFile = null;
-        }
-
-        /* First, check for a cached compiled version. */
-        if (!$force && is_null($this->_template) && isset($this->_cache)) {
-            $cacheid = 'horde_template|' . filemtime($file) . '|' . $file;
-            $this->_template = $this->_cache->get($cacheid, 0);
-            if ($this->_template === false) {
-                $this->_template = null;
-            }
-        }
-
-        /* Parse and compile the template. */
-        if ($force || is_null($this->_template)) {
-            $this->_template = str_replace("\n", " \n", file_get_contents($file));
-            $this->_parse();
-            if (isset($cacheid) &&
-                !$this->_cache->set($cacheid, $this->_template)) {
-                Horde::logMessage(sprintf(_("Could not save the compiled template file '%s'."), $file), __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
-        }
-
-        $this->_templateFile = $file;
-
-        /* Template debugging. */
-        if ($this->getOption('debug')) {
-            echo '
' . htmlspecialchars($this->_template) . '
'; - } - - return $this->parse(); - } - - /** - * Parses all variables/tags in the template. - * - * @param string $contents The unparsed template. - * - * @return string The parsed template. - */ - function parse($contents = null) - { - if (!is_null($contents)) { - $this->setTemplate(str_replace("\n", " \n", $contents)); - } - - /* Evaluate the compiled template and return the output. */ - ob_start(); - eval('?>' . $this->_template); - return str_replace(" \n", "\n", ob_get_clean()); - } - - /** - * Parses all variables/tags in the template. - */ - function _parse() - { - // Escape XML instructions. - $this->_template = preg_replace('/\?>|<\?/', - '', - $this->_template); - - // Parse gettext tags, if the option is enabled. - if ($this->getOption('gettext')) { - $this->_parseGettext(); - } - - // Process ifs. - $this->_parseIf(); - - // Process loops and arrays. - $this->_parseLoop(); - - // Process base scalar tags. Needs to be after _parseLoop() as we - // rely on _foreachMap(). - $this->_parseTags(); - - // Finally, process any associative array scalar tags. - $this->_parseAssociativeTags(); - } - - /** - * Parses gettext tags. - * - * @access private - */ - function _parseGettext() - { - if (preg_match_all("/(.+?)<\/gettext>/s", $this->_template, $matches, PREG_SET_ORDER)) { - $replace = array(); - foreach ($matches as $val) { - $replace[$val[0]] = ''; - } - $this->_doReplace($replace); - } - } - - /** - * Parses 'if' statements. - * - * @access private - * - * @param string $key The key prefix to parse. - */ - function _parseIf($key = null) - { - $replace = array(); - - foreach ($this->_doSearch('if', $key) as $val) { - $replace[$val[0]] = '_generatePHPVar('scalars', $val[1]) . ') || !empty(' . $this->_generatePHPVar('arrays', $val[1]) . ')): ?>'; - $replace[$val[2]] = ''; - - // Check for else statement. - foreach ($this->_doSearch('else', $key) as $val2) { - $replace[$val2[0]] = ''; - $replace[$val2[2]] = ''; - } - } - - $this->_doReplace($replace); - } - - /** - * Parses the given array for any loops or other uses of the array. - * - * @access private - * - * @param string $key The key prefix to parse. - */ - function _parseLoop($key = null) - { - $replace = array(); - - foreach ($this->_doSearch('loop', $key) as $val) { - $divider = null; - - // See if we have a divider. - if (preg_match("/(.*)<\/divider:" . $val[1] . ">/sU", $this->_template, $m)) { - $divider = $m[1]; - $replace[$m[0]] = ''; - } - - if (!isset($this->_foreachMap[$val[1]])) { - $this->_foreachMap[$val[1]] = ++$this->_foreachVar; - } - $varId = $this->_foreachMap[$val[1]]; - $var = $this->_generatePHPVar('arrays', $val[1]); - - $replace[$val[0]] = '_generatePHPVar('arrays', $val[1]) . ' as $k' . $varId . ' => $v' . $varId . '): ?>'; - $replace[$val[2]] = ''; - - // Parse ifs. - $this->_parseIf($val[1]); - - // Parse interior loops. - $this->_parseLoop($val[1]); - - // Replace scalars. - $this->_parseTags($val[1]); - } - - $this->_doReplace($replace); - } - - /** - * Replaces 'tag' tags with their PHP equivalents. - * - * @access private - * - * @param string $key The key prefix to parse. - */ - function _parseTags($key = null) - { - $replace = array(); - - foreach ($this->_doSearch('tag', $key, true) as $val) { - $replace_text = '_foreachMap[$val[1]])) { - $var = $this->_foreachMap[$val[1]]; - $replace_text .= 'if (isset($v' . $var . ')) { echo is_array($v' . $var . ') ? $k' . $var . ' : $v' . $var . '; } else'; - } - $var = $this->_generatePHPVar('scalars', $val[1]); - $replace[$val[0]] = $replace_text . 'if (isset(' . $var . ')) { echo ' . $var . '; } ?>'; - } - - $this->_doReplace($replace); - } - - /** - * Parse associative tags (i.e. ). - * - * @access private - */ - function _parseAssociativeTags() - { - $replace = array(); - - foreach ($this->_pregcache['tag'] as $key => $val) { - $parts = explode('.', $val[1]); - $var = '$this->_arrays[\'' . $parts[0] . '\'][\'' . $parts[1] . '\']'; - $replace[$val[0]] = ''; - unset($this->_pregcache['tag'][$key]); - } - - $this->_doReplace($replace); - } - - /** - * Output the correct PHP variable string for use in template space. - * - * @access private - */ - function _generatePHPVar($tag, $key) - { - $out = ''; - - $a = explode('.', $key); - $a_count = count($a); - - if ($a_count == 1) { - switch ($tag) { - case 'arrays': - $out = '$this->_arrays'; - break; - - case 'scalars': - $out = '$this->_scalars'; - break; - } - } else { - $out = '$v' . $this->_foreachMap[implode('.', array_slice($a, 0, -1))]; - } - - return $out . '[\'' . end($a) . '\']'; - } - - /** - * TODO - * - * @access private - */ - function _doSearch($tag, $key, $noclose = false) - { - $out = array(); - $level = (is_null($key)) ? 0 : substr_count($key, '.') + 1; - - if (!isset($this->_pregcache[$key])) { - $regex = ($noclose) ? - "/<" . $tag . ":(.+?)\s\/>/" : - "/<" . $tag . ":([^>]+)>/"; - preg_match_all($regex, $this->_template, $this->_pregcache[$tag], PREG_SET_ORDER); - } - - foreach ($this->_pregcache[$tag] as $pkey => $val) { - $val_level = substr_count($val[1], '.'); - $add = false; - if (is_null($key)) { - $add = !$val_level; - } else { - $add = (($val_level == $level) && - (strpos($val[1], $key . '.') === 0)); - } - if ($add) { - if (!$noclose) { - $val[2] = ''; - } - $out[] = $val; - unset($this->_pregcache[$tag][$pkey]); - } - } - - return $out; - } - - /** - * TODO - * - * @access private - */ - function _doReplace($replace) - { - if (empty($replace)) { - return; - } - - $search = array(); - - foreach (array_keys($replace) as $val) { - $search[] = '/' . preg_quote($val, '/') . '/'; - } - - $this->_template = preg_replace($search, array_values($replace), $this->_template); - } - -}