1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Jonah_Block_NewsPopular extends Horde_Core_Block
15: {
16: 17:
18: public function __construct($app, $params = array())
19: {
20: parent::__construct($app, $params);
21:
22: $this->_name = _("Most Popular Stories");
23: }
24:
25: 26:
27: protected function _params()
28: {
29: $templates = Horde::loadConfiguration('templates.php', 'templates', 'jonah');
30: $params['source'] = array('name' => _("Feed"),
31: 'type' => 'enum',
32: 'values' => array());
33:
34: $channels = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannels();
35: foreach ($channels as $channel) {
36: if ($channel['channel_type'] == Jonah::INTERNAL_CHANNEL) {
37: $params['source']['values'][$channel['channel_id']] = $channel['channel_name'];
38: }
39: }
40: natcasesort($params['source']['values']);
41:
42: $params['view'] = array('name' => _("View"),
43: 'type' => 'enum',
44: 'values' => array());
45: foreach ($templates as $key => $template) {
46: $params['view']['values'][$key] = $template['name'];
47: }
48:
49: $params['max'] = array('name' => _("Maximum Stories"),
50: 'type' => 'int',
51: 'default' => 10,
52: 'required' => false);
53:
54: return $params;
55: }
56:
57: 58:
59: protected function _title()
60: {
61: try {
62: $channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($this->_params['source']);
63: } catch (Exception $e) {
64: return htmlspecialchars($e->getMessage());
65: }
66:
67: if (!empty($channel['channel_link'])) {
68: $title = Horde::link(htmlspecialchars($channel['channel_link']), '', '', '_blank')
69: . htmlspecialchars($channel['channel_name'])
70: . _(" - Most read stories") . '</a>';
71: } else {
72: $title = htmlspecialchars($channel['channel_name'])
73: . _(" - Most read stories");
74: }
75:
76: return $title;
77: }
78:
79: 80:
81: protected function _content()
82: {
83: if (empty($this->_params['source'])) {
84: return _("No feed specified.");
85: }
86:
87: $params = $this->_params();
88:
89: $view = isset($this->_params['view']) ? $this->_params['view'] : 'standard';
90: if (!isset($this->_params['max'])) {
91: $this->_params['max'] = $params['max']['default'];
92: }
93:
94:
95: return $GLOBALS['injector']->getInstance('Jonah_Driver')->renderChannel($this->_params['source'], $view, $this->_params['max'], 0, Jonah::ORDER_READ);
96: }
97:
98: }
99: