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-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Chuck Hagenbuch (chuck@horde.org)
Author: Michael Slusarz (slusarz@horde.org)
Example #1
0
 public function testScalar()
 {
     $template = new Horde_Template();
     $template->set('one', 'one');
     $template->set('two', 2);
     $this->assertEquals("one\n2", $template->parse("<tag:one />\n<tag:two />"));
 }
Example #2
0
function populateStatementItemsTemplateIf($p_account_id, $p_accountName)
{
    if (!Book::Singleton()->isThereStatementForAccount($p_account_id)) {
        return NULL;
    }
    $v_statementItems = Book::Singleton()->getUnmatchedStatementItems($p_account_id, $p_accountName);
    CloudBank::AddLinks($v_statementItems, 'event.php', array('date' => 'date', 'description' => 'description_short', 'amount' => 'amount', 'statement_item_id' => 'id', 'account_id' => 'account_id', 'account_type' => 'account_type', 'account_name' => 'account_name'), 'description', 'description_link');
    Book::SortResultSet($v_statementItems, 'date', TRUE);
    $v_clearedOrMatchedBalance = Book::Singleton()->getClearedOrMatchedBalance($p_account_id);
    $v_closingStatementItem = Book::Singleton()->getClosingBalance($p_account_id);
    $v_template = new Horde_Template();
    $v_template->set('match_link', Horde::link(Horde::url('statement_item_match.php')->add(array('account_id' => $p_account_id)), 'Update matching Events with Statement Item ID reference') . 'Match</a>');
    $v_template->set('clear_all_matched_link', Horde::link(Horde::url('clear_all_matched_events.php')->add(array('account_id' => $p_account_id)), 'Clear all matched Events and PURGE corresponding STATEMENT ITEMS') . 'Clear all matched</a>');
    $v_template->set('statement_items', $v_statementItems);
    $v_template->set('cleared_or_matched_balance', Book::FormatAmount($v_clearedOrMatchedBalance));
    $v_template->set('statement_closing', $v_closingStatementItem);
    $v_template->set('amount_left', Book::FormatAmount($v_clearedOrMatchedBalance - $v_closingStatementItem['amount']));
    //var_dump($v_template);
    return $v_template;
}
Example #3
0
 /**
  * Returns the stories of a channel rendered with the specified template.
  *
  * @param integer $channel_id  The news channel to get stories from.
  * @param string  $tpl         The name of the template to use.
  * @param integer $max         The maximum number of stories to get. If
  *                             null, all stories will be returned.
  * @param integer $from        The number of the story to start with.
  * @param integer $order       How to sort the results for internal channels
  *                             Possible values are the Jonah::ORDER_*
  *                             constants.
  *
  * @TODO: This doesn't belong in a storage driver class. Move it to a
  * view or possible a static method in Jonah::?
  *
  * @return string  The rendered story listing.
  */
 public function renderChannel($channel_id, $tpl, $max = 10, $from = 0, $order = Jonah::ORDER_PUBLISHED)
 {
     $channel = $this->getChannel($channel_id);
     $templates = Horde::loadConfiguration('templates.php', 'templates', 'jonah');
     $escape = !isset($templates[$tpl]['escape']) || !empty($templates[$tpl]['escape']);
     $template = new Horde_Template();
     if ($escape) {
         $channel['channel_name'] = htmlspecialchars($channel['channel_name']);
         $channel['channel_desc'] = htmlspecialchars($channel['channel_desc']);
     }
     $template->set('channel', $channel, true);
     /* Get one story more than requested to see if there are more stories. */
     if ($max !== null) {
         $stories = $this->getStories(array('channel_id' => $channel_id, 'published' => true, 'startnumber' => $from, 'limit' => $max), $order);
     } else {
         $stories = $this->getStories(array('channel_id' => $channel_id, 'published' => true), $order);
         $max = count($stories);
     }
     if (!$stories) {
         $template->set('error', _("No stories are currently available."), true);
         $template->set('stories', false, true);
         $template->set('image', false, true);
         $template->set('form', false, true);
     } else {
         /* Escape. */
         if ($escape) {
             array_walk($stories, array($this, '_escapeStories'));
         }
         /* Process story summaries. */
         array_walk($stories, array($this, '_escapeStoryDescriptions'));
         $template->set('error', false, true);
         $template->set('story_marker', Horde::img('story_marker.png'));
         $template->set('image', false, true);
         $template->set('form', false, true);
         if ($from) {
             $template->set('previous', max(0, $from - $max), true);
         } else {
             $template->set('previous', false, true);
         }
         if ($from && !empty($channel['channel_page_link'])) {
             $template->set('previous_link', str_replace(array('%25c', '%25n', '%c', '%n'), array('%c', '%n', $channel['channel_id'], max(0, $from - $max)), $channel['channel_page_link']), true);
         } else {
             $template->set('previous_link', false, true);
         }
         $more = count($stories) > $max;
         if ($more) {
             $template->set('next', $from + $max, true);
             array_pop($stories);
         } else {
             $template->set('next', false, true);
         }
         if ($more && !empty($channel['channel_page_link'])) {
             $template->set('next_link', str_replace(array('%25c', '%25n', '%c', '%n'), array('%c', '%n', $channel['channel_id'], $from + $max), $channel['channel_page_link']), true);
         } else {
             $template->set('next_link', false, true);
         }
         $template->set('stories', $stories, true);
     }
     return $template->parse($templates[$tpl]['template']);
 }
Example #4
0
File: time.php Project: horde/horde
        $item = $vars->get('item');
        if (is_null($item) || !count($item)) {
            $notification->push(_("No timeslices were selected to submit."), 'horde.error');
        } else {
            foreach (array_keys($item) as $id) {
                $time[] = array('id' => $id);
            }
            try {
                $GLOBALS['injector']->getInstance('Hermes_Driver')->markAs('submitted', $time);
                $notification->push(_("Your time was successfully submitted."), 'horde.success');
                $vars = new Horde_Variables();
            } catch (Horde_Exception $e) {
                $notification->push(sprintf(_("There was an error submitting your time: %s"), $e->getMessage()), 'horde.error');
            }
        }
        break;
}
// We are displaying all time.
$tabs = Hermes::tabs();
$criteria = array('employee' => $GLOBALS['registry']->getAuth(), 'submitted' => false, 'link_page' => 'time.php');
$table = new Hermes_Table('week', $vars, array('title' => _("My Unsubmitted Time"), 'name' => 'hermes/hours', 'params' => $criteria));
$template = new Horde_Template();
$template->setOption('gettext', true);
$template->set('postUrl', Horde::url('time.php', false, -1));
$template->set('sessionId', Horde_Util::formInput());
$template->set('table', $table->render());
$page_output->header(array('title' => _("My Time")));
$notification->notify(array('listeners' => 'status'));
echo $tabs;
echo $template->fetch(HERMES_TEMPLATES . '/time/form.html');
$page_output->footer();
Example #5
0
File: feed.php Project: horde/horde
$options = array();
foreach ($templates as $key => $info) {
    $options[] = '<option value="' . $key . '"' . ($key == $criteria['channel_format'] ? ' selected="selected"' : '') . '>' . $info['name'] . '</option>';
}
if (empty($criteria['channel_id']) && !empty($criteria['feed'])) {
    $criteria['channel_id'] = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannelId($criteria['feed']);
}
if (empty($criteria['channel_id'])) {
    $notification->push(_("No valid feed name or ID requested."), 'horde.error');
} else {
    $stories = $GLOBALS['injector']->getInstance('Jonah_Driver')->getStories($criteria);
}
if (!empty($stories)) {
    die(print_r($stories, true));
}
$template = new Horde_Template();
$template->setOption('gettext', 'true');
$template->set('url', Horde::selfUrl());
$template->set('session', Horde_Util::formInput());
$template->set('channel_id', $criteria['channel_id']);
$template->set('channel_name', $channel['channel_name']);
$template->set('format', $criteria['channel_format']);
$template->set('options', $options);
$template->set('stories', $news->renderChannel($criteria['channel_id'], $criteria['channel_format']));
// Buffer the notifications and send to the template
Horde::startBuffer();
$GLOBALS['notification']->notify(array('listeners' => 'status'));
$template->set('notify', Horde::endBuffer());
$page_output->header();
echo $template->fetch(JONAH_TEMPLATES . '/delivery/html.html');
$page_output->footer();
Example #6
0
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested feed (' . htmlspecialchars($criteria['channel_id']) . ') was not found on this server.</p>
</body></html>';
    exit;
}
// Fetch stories
try {
    $stories = $driver->getStories($criteria);
} catch (Exception $e) {
    Horde::log($e, 'ERR');
    $stories = array();
}
// Build the template (@TODO: Use Horde_View)
$template = new Horde_Template();
$template->set('jonah', 'Jonah ' . $registry->getVersion() . ' (http://www.horde.org/jonah/)');
$template->set('xsl', Horde_Themes::getFeedXsl());
if (!empty($criteria['tag_id'])) {
    $template->set('channel_name', sprintf(_("Stories tagged with %s in %s"), implode(',', $criteria['tags']), htmlspecialchars($channel['channel_name'])));
} else {
    $template->set('channel_name', htmlspecialchars($channel['channel_name']));
}
$template->set('channel_desc', htmlspecialchars($channel['channel_desc']));
$template->set('channel_updated', htmlspecialchars(date('r', $channel['channel_updated'])));
$template->set('channel_official', htmlspecialchars($channel['channel_official']));
$template->set('channel_rss', htmlspecialchars(Horde::url('delivery/rss.php', true, -1)->add(array('type' => 'rss', 'channel_id' => $channel['channel_id']))));
$template->set('channel_rss2', htmlspecialchars(Horde::url('delivery/rss.php', true, -1)->add(array('type' => 'rss2', 'channel_id' => $channel['channel_id']))));
foreach ($stories as &$story) {
    $story['title'] = htmlspecialchars($story['title']);
    $story['description'] = htmlspecialchars($story['description']);
Example #7
0
function prepareView($p_variables, &$p_form)
{
    $v_accounts = NULL;
    try {
        $v_accounts = Book::Singleton()->getAccountsForStatement();
    } catch (Exception $v_exception) {
        Cloudbank::PushError(Book::XtractMessage($v_exception));
    }
    $v_template = NULL;
    $p_form = NULL;
    switch (is_null($v_accounts) || count($v_accounts) == 0 ? 'import' : 'accounts') {
        case 'accounts':
            $v_template = new Horde_Template();
            array_walk($v_accounts, function (&$p_record, $p_key) {
                $p_record['type'] = CloudBankConsts::LedgerAccountType_Account;
            });
            CloudBank::AddLinks($v_accounts, 'events.php', array('ledger_account_id' => 'id', 'ledger_account_type' => 'type'), 'name', 'account_link');
            $v_template->set('accounts', $v_accounts);
            $p_form = preparePurgeForm($p_variables);
            break;
        case 'import':
            $p_form = prepareImportForm($p_variables, $v_dummy);
            break;
    }
    return $v_template;
}
Example #8
0
 /**
  * $registry
  * $notification
  * $conf
  * $criteria
  *
  */
 public function run()
 {
     extract($this->_params, EXTR_REFS);
     $templates = Horde::loadConfiguration('templates.php', 'templates', 'jonah');
     /* Get requested channel. */
     try {
         $channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($criteria['feed']);
     } catch (Exception $e) {
         Horde::log($e, 'ERR');
         $notification->push(_("Invalid channel."), 'horde.error');
         Horde::url('delivery/index.php', true)->redirect();
         exit;
     }
     $title = sprintf(_("HTML Delivery for \"%s\""), $channel['channel_name']);
     $options = array();
     foreach ($templates as $key => $info) {
         $options[] = '<option value="' . $key . '"' . ($key == $criteria['format'] ? ' selected="selected"' : '') . '>' . $info['name'] . '</option>';
     }
     $template = new Horde_Template();
     $template->setOption('gettext', 'true');
     $template->set('url', Horde::selfUrl());
     $template->set('session', Horde_Util::formInput());
     $template->set('channel_id', $criteria['feed']);
     $template->set('channel_name', $channel['channel_name']);
     $template->set('format', $criteria['format']);
     $template->set('options', $options);
     // @TODO: This is ugly. storage driver shouldn't be rendering any display
     // refactor this to use individual views possibly with a choice of different templates
     $template->set('stories', $GLOBALS['injector']->getInstance('Jonah_Driver')->renderChannel($criteria['feed'], $criteria['format']));
     // Buffer the notifications and send to the template
     Horde::startBuffer();
     $GLOBALS['notification']->notify(array('listeners' => 'status'));
     $template->set('notify', Horde::endBuffer());
     $GLOBALS['page_output']->header(array('title' => $title));
     echo $template->fetch(JONAH_TEMPLATES . '/delivery/html.html');
     $GLOBALS['page_output']->footer();
 }
require_once CLOUDBANK_BASE . '/lib/Cloudbank.php';
require_once CLOUDBANK_BASE . '/lib/Book.php';
/* main() */
$g_isError = FALSE;
try {
    $g_accountsOrCategories = Book::Singleton()->getAccountsOrCategoriesWBalance($g_account_type);
    CloudBank::AddLinks($g_accountsOrCategories, 'events.php', array('ledger_account_id' => 'id', 'ledger_account_type' => 'type'), 'name', 'account_link');
    if ($g_account_type == CloudBankConsts::LedgerAccountType_Account) {
        CloudBank::AddLinks($g_accountsOrCategories, 'account_or_category.php', array('account_id' => 'id', 'name' => 'name', 'account_type' => 'type', 'beginning_balance' => 'beginning_balance'), 'edit_icon', 'edit_icon_link', NULL, 'Edit');
    } else {
        CloudBank::AddLinks($g_accountsOrCategories, 'account_or_category.php', array('account_id' => 'id', 'name' => 'name', 'account_type' => 'type'), 'edit_icon', 'edit_icon_link', NULL, 'Edit');
    }
    CloudBank::AddLinks($g_accountsOrCategories, 'delete_account.php', array('account_id' => 'id', 'account_type' => 'type'), 'delete_icon', 'delete_icon_link', NULL, 'Delete');
    Book::SortResultSet($g_accountsOrCategories, 'name');
    $g_total = $g_account_type == CloudBankConsts::LedgerAccountType_Account ? Book::Singleton()->getAccountsTotal() : Book::Singleton()->getCategoriesTotal();
    $g_template = new Horde_Template();
    $g_template->set('new_account_link', Horde::link(Horde::url('account_or_category.php')->add(array('account_type' => $g_account_type))) . 'New</a>');
    $g_template->set('accounts', $g_accountsOrCategories);
    $g_template->set('total', $g_total);
    $title = _($g_account_type == CloudBankConsts::LedgerAccountType_Account ? "Accounts" : "Categories");
} catch (Exception $v_exception) {
    Cloudbank::PushError(Book::XtractMessage($v_exception));
    $g_isError = TRUE;
}
$page_output->header();
$notification->notify(array('listeners' => 'status'));
if (!$g_isError) {
    //$g_template->setOption('debug', true);
    echo $g_template->fetch(CLOUDBANK_TEMPLATES . '/accounts.html');
}
$page_output->footer();