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 />")); }
/** * 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']); }