1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Jonah_Block_Story extends Horde_Core_Block
13: {
14: 15:
16: protected $_story = null;
17:
18: 19:
20: public function __construct($app, $params = array())
21: {
22: parent::__construct($app, $params);
23:
24: $this->_name = _("Story");
25: }
26:
27: 28:
29: protected function _params()
30: {
31: $channels = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannels();
32: $channel_choices = array();
33: foreach ($channels as $channel) {
34: $channel_choices[$channel['channel_id']] = $channel['channel_name'];
35: }
36: natcasesort($channel_choices);
37:
38: return array(
39: 'source' => array(
40: 'name' => _("Feed"),
41: 'type' => 'enum',
42: 'values' => $channel_choices
43: ),
44: 'story' => array(
45: 'name' => _("Story"),
46: 'type' => 'int'
47: ),
48: 'countReads' => array(
49: 'name' => _("Count reads of this story when this block is displayed"),
50: 'type' => 'boolean',
51: 'default' => false
52: )
53: );
54: }
55:
56: 57:
58: protected function _title()
59: {
60: if (empty($this->_params['source']) ||
61: empty($this->_params['story'])) {
62: return $this->getName();
63: }
64:
65: try {
66: $story = $this->_fetch();
67: } catch (Jonah_Exception $e) {
68: return htmlspecialchars($e->getMessage());
69: }
70: return '<span class="storyDate">'
71: . htmlspecialchars($story['updated_date'])
72: . '</span> '
73: . htmlspecialchars($story['title']);
74: }
75:
76: 77:
78: protected function _content()
79: {
80: if (empty($this->_params['source']) || empty($this->_params['story'])) {
81: return _("No story is selected.");
82: }
83:
84: try {
85: $story = $this->_fetch();
86: } catch (Jonah_Exception $e) {
87: return sprintf(_("Error fetching story: %s"), $e->getMessage());
88: }
89:
90: if (empty($story['body_type']) || $story['body_type'] == 'text') {
91: $story['body'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['body'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
92: }
93:
94: $tag_html = array();
95: foreach ($story['tags'] as $id => $tag) {
96: $tag_html[] = Horde::url('results.php')->add(array('tag_id' => $id, 'channel_id' => $this->_prams['source']))->link() . $tag . '</a>';
97: }
98:
99: return '<p class="storyTags">' . _("Tags: ")
100: . implode(', ', $story['tags'])
101: . '</p><p class="storySubtitle">'
102: . htmlspecialchars($story['desc'])
103: . '</p><div class="storyBody">' . $story['body']
104: . '</div>';
105: }
106:
107: 108: 109:
110: private function _fetch()
111: {
112: if (is_null($this->_story)) {
113: $this->_story = $GLOBALS['injector']->getInstance('Jonah_Driver')->getStory(
114: $this->_params['source'],
115: $this->_params['story'],
116: !empty($this->_params['countReads']));
117: }
118:
119: return $this->_story;
120: }
121:
122: }
123: