1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class Jonah_View_StoryList extends Jonah_View_Base
17: {
18: 19: 20: 21: 22: 23: 24: 25:
26: public function run()
27: {
28: extract($this->_params, EXTR_REFS);
29:
30: $channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($channel_id);
31: if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
32: $notification->push(_("You are not authorised for this action."), 'horde.warning');
33: $registry->authenticateFailure();
34: }
35:
36:
37: $url = Horde_Util::getFormData('url');
38: if ($url) {
39: $url = new Horde_Url($url);
40: }
41:
42: try {
43: $stories = $GLOBALS['injector']->getInstance('Jonah_Driver')->getStories(array('channel_id' => $channel_id));
44: } catch (Exception $e) {
45: $notification->push(sprintf(_("Invalid channel requested. %s"), $e->getMessage()), 'horde.error');
46: Horde::url('channels/index.php', true)->redirect();
47: exit;
48: }
49:
50:
51: if (empty($stories)) {
52: $notification->push(_("No available stories."), 'horde.warning');
53: }
54: if (!empty($refresh)) {
55: $notification->push(_("Channel refreshed."), 'horde.success');
56: }
57: if (!empty($url)) {
58: $url->redirect();
59: exit;
60: }
61:
62:
63: $allow_delete = Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id);
64:
65:
66: foreach ($stories as $key => $story) {
67:
68: if (!empty($stories[$key]['published'])) {
69: $stories[$key]['published_date'] = strftime($prefs->getValue('date_format') . ', ' . ($prefs->getValue('twentyFour') ? '%H:%M' : '%I:%M%p'), $stories[$key]['published']);
70: } else {
71: $stories[$key]['published_date'] = '';
72: }
73:
74:
75: $stories[$key]['pdf_link'] = '';
76: $stories[$key]['edit_link'] = '';
77: $stories[$key]['delete_link'] = '';
78: $stories[$key]['view_link'] = Horde::link($GLOBALS['injector']->getInstance('Jonah_Driver')->getStoryLink($channel, $story), $story['description']) . htmlspecialchars($story['title']) . '</a>';
79:
80:
81: $url = Horde::url('stories/pdf.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id));
82: $stories[$key]['pdf_link'] = $url->link(array('title' => _("PDF version"))) . Horde::img('mime/pdf.png') . '</a>';
83:
84:
85: $url = Horde::url('stories/edit.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id));
86: $stories[$key]['edit_link'] = $url->link(array('title' => _("Edit story"))) . Horde::img('edit.png') . '</a>';
87:
88:
89: if ($allow_delete) {
90: $url = Horde::url('stories/delete.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id));
91: $stories[$key]['delete_link'] = $url->link(array('title' => _("Delete story"))) . Horde::img('delete.png') . '</a>';
92: }
93:
94:
95: if ($conf['comments']['allow'] &&
96: $registry->hasMethod('forums/numMessages')) {
97: $comments = $registry->call('forums/numMessages', array($stories[$key]['id'], 'jonah'));
98: if (!is_a($comments, 'PEAR_Error')) {
99: $stories[$key]['comments'] = $comments;
100: }
101: }
102:
103: }
104:
105:
106: $title = $channel['channel_name'];
107: $view = new Horde_View(array('templatePath' => JONAH_TEMPLATES . '/stories'));
108: $view->stories = $stories;
109: $view->read = true;
110: $view->comments = $conf['comments']['allow'] && $registry->hasMethod('forums/numMessages') && $channel['channel_type'] == Jonah::INTERNAL_CHANNEL;
111: require $registry->get('templates', 'horde') . '/common-header.inc';
112: require JONAH_TEMPLATES . '/menu.inc';
113: echo $view->render('index');
114: require $registry->get('templates', 'horde') . '/common-footer.inc';
115: }
116:
117: }