Overview

Packages

  • Jonah
  • None

Classes

  • Jonah
  • Jonah_Api
  • Jonah_Block_Latest
  • Jonah_Driver
  • Jonah_Driver_Sql
  • Jonah_Exception
  • Jonah_Factory_Driver
  • Jonah_Form_Feed
  • Jonah_Form_Story
  • Jonah_Test
  • Jonah_View_ChannelDelete
  • Jonah_View_ChannelEdit
  • Jonah_View_ChannelList
  • Jonah_View_StoryDelete
  • Jonah_View_StoryEdit
  • Jonah_View_StoryList
  • Jonah_View_StoryPdf
  • Jonah_View_StoryView
  • Jonah_View_TagSearchList
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Turba_View_StoryList:: A view to handle displaying a list of stories in a
  4:  * channel.
  5:  *
  6:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file LICENSE for license information (BSD). If you
  9:  * did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.
 10:  *
 11:  * @author Chuck Hagenbuch <chuck@horde.org>
 12:  * @author Marko Djukic <marko@oblo.com>
 13:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
 14:  * @package Jonah
 15:  */
 16: class Jonah_View_StoryList extends Jonah_View_Base
 17: {
 18:     /**
 19:      * expects
 20:      *   $registry
 21:      *   $notification
 22:      *   $prefs
 23:      *   $conf
 24:      *   $channel_id
 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:         /* Check if a URL has been passed. */
 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:         /* Do some state tests. */
 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:         /* Get channel details, for title, etc. */
 63:         $allow_delete = Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id);
 64: 
 65:         /* Build story specific fields. */
 66:         foreach ($stories as $key => $story) {
 67:             /* published is the publication/release date, updated is the last change date. */
 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:             /* Default to no links. */
 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:             /* PDF link. */
 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:             /* Edit story link. */
 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:             /* Delete story link. */
 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:             /* Comment counter. */
 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:         /* Render page */
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: }
API documentation generated by ApiGen