Overview

Packages

  • Agora
  • None

Classes

  • Agora_Application
  • Agora_Block_Forums
  • Agora_Block_Thread
  • Agora_Block_Threads
  • Agora_Tree_Flat
  • Agora_ViewComments

Functions

  • handle_avatarselect
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Provide an API to include an Agora forum's thread into any other Horde
  4:  * app through a block.
  5:  *
  6:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @author  Marko Djukic <marko@oblo.com>
 12:  * @author  Jan Schneider <jan@horde.org>
 13:  */
 14: class Agora_Block_Threads extends Horde_Core_Block
 15: {
 16:     /**
 17:      * TODO
 18:      *
 19:      * @var array
 20:      */
 21:     private $_threads = array();
 22: 
 23:     /**
 24:      */
 25:     public function __construct($app, $params = array())
 26:     {
 27:         parent::__construct($app, $params);
 28: 
 29:         $this->_name = _("Threads");
 30:     }
 31: 
 32:     /**
 33:      */
 34:     protected function _params()
 35:     {
 36:         $params = array();
 37: 
 38:         $forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create();
 39: 
 40:         /* Get the list of forums to display. */
 41:         /* TODO: we really need something like getBareForums only with permissions,
 42:          * to return associative array. It would really simplify things. */
 43:         $forums_list = array();
 44:         foreach ($forums->getForums(0, false, 'forum_name', 0, !$GLOBALS['registry']->isAdmin()) as $forum) {
 45:             $forums_list[$forum['forum_id']] = $forum['forum_name'];
 46:         }
 47:         $params['forum_id'] = array(
 48:             'name' => _("Forum"),
 49:             'type' => 'enum',
 50:             'values' => $forums_list,
 51:         );
 52: 
 53:         /* Display the last X number of threads. */
 54:         $params['thread_display'] = array(
 55:             'name' => _("Only display this many threads (0 to display all threads)"),
 56:             'type' => 'int',
 57:             'default' => 0,
 58:             'values' => $GLOBALS['prefs']->getValue('threads_block_display'),
 59:         );
 60: 
 61:         return $params;
 62:     }
 63: 
 64:     /**
 65:      */
 66:     protected function _title()
 67:     {
 68:         if (!isset($this->_params['forum_id'])) {
 69:             return $this->getName();
 70:         }
 71: 
 72:         if (empty($this->_threads)) {
 73:             $this->_threads = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $this->_params['forum_id']);
 74:             if ($this->_threads instanceof PEAR_Error) {
 75:                 return $this->getName();
 76:             }
 77:         }
 78: 
 79:         $title = sprintf(_("Threads in \"%s\""), $this->_threads->_forum['forum_name']);
 80:         $url = Horde::url('threads.php', true);
 81:         if (!empty($scope)) {
 82:             $url = Horde_Util::addParameter($url, 'scope', $scope);
 83:         }
 84: 
 85:         return Horde::link(Agora::setAgoraId($this->_params['forum_id'], null, $url))
 86:             . $title . '</a>';
 87:     }
 88: 
 89:     /**
 90:      */
 91:     protected function _content()
 92:     {
 93:         if (!isset($this->_params['forum_id'])) {
 94:             throw new Horde_Exception(_("No forum selected"));
 95:         }
 96: 
 97:         if (empty($this->_threads)) {
 98:             $this->_threads = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $this->_params['forum_id']);
 99:             if ($this->_threads instanceof PEAR_Error) {
100:                 throw new Horde_Exception(_("Unable to fetch threads for selected forum."));
101:             }
102:         }
103: 
104:         /* Get the sorting. */
105:         $sort_by = Agora::getSortBy('threads');
106:         $sort_dir = Agora::getSortDir('threads');
107: 
108:         /* Get a list of threads and display only the most recent if
109:          * preference is set. */
110:         $threads_list = $this->_threads->getThreads(0, false, $sort_by, $sort_dir, false, Horde::selfUrl(), null, 0, !empty($this->_params['thread_display']) ? $this->_params['thread_display'] : null);
111: 
112:         /* Show a message if no available threads. Don't raise an error
113:          * as it is not an error to have no threads. */
114:         if (empty($threads_list)) {
115:             return _("No available threads.");
116:         }
117: 
118:         /* Set up the column headers. */
119:         $col_headers = array('message_subject' => _("Subject"), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date"));
120:         $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'threads');
121: 
122:         /* Set up the template tags. */
123:         $view = new Agora_View();
124:         $view->col_headers = $col_headers;
125:         $view->threads = $threads_list;
126: 
127:         return $view->render('block/threads');
128:     }
129: 
130: }
131: 
API documentation generated by ApiGen