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:  * Provides a list of Agora forums in a block item.
  4:  *
  5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Marko Djukic <marko@oblo.com>
 11:  * @author  Jan Schneider <jan@horde.org>
 12:  */
 13: class Agora_Block_Forums extends Horde_Core_Block
 14: {
 15:     /**
 16:      */
 17:     public function __construct($app, $params = array())
 18:     {
 19:         parent::__construct($app, $params);
 20: 
 21:         $this->_name = _("Forums");
 22:     }
 23: 
 24:     /**
 25:      */
 26:     protected function _title()
 27:     {
 28:         return Horde::url('forums.php', true)->link() . $this->getName() . '</a>';
 29:     }
 30: 
 31:     /**
 32:      */
 33:     protected function _params()
 34:     {
 35:         return array(
 36:             /* Display the last X number of threads. */
 37:             'forum_display' => array(
 38:                 'name' => _("Only display this many forums (0 to display all forums)"),
 39:                 'type' => 'int',
 40:                 'default' => 0,
 41:                 'values' => $GLOBALS['prefs']->getValue('forums_block_display')
 42:             )
 43:         );
 44:     }
 45: 
 46:     /**
 47:      */
 48:     protected function _content()
 49:     {
 50:         global $registry;
 51: 
 52:         /* Set up the forums object. */
 53:         $forums = array($GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create());
 54:         if ($GLOBALS['registry']->isAdmin()) {
 55:             foreach ($registry->listApps(array('hidden', 'notoolbar', 'active')) as $scope) {
 56:                 if ($registry->hasMethod('hasComments', $scope) &&
 57:                     $registry->callByPackage($scope, 'hasComments') === true) {
 58:                     $forums[] = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope);
 59:                 }
 60:             }
 61:         }
 62: 
 63:         /* Get the sorting. */
 64:         $sort_by = Agora::getSortBy('forums');
 65:         $sort_dir = Agora::getSortDir('forums');
 66: 
 67:         /* Get the list of forums. */
 68:         $forums_list = array();
 69:         foreach ($forums as $forum) {
 70:             try {
 71:                 $scope_forums = $forum->getForums(0, true, $sort_by, $sort_dir, true);
 72:                 $forums_list = array_merge($forums_list, $scope_forums);
 73:             } catch (Agora_Exception $e) {
 74:                 return $e->getMessage();
 75:             /* Catch NotFound exception here so it won't break the cycle. */
 76:             } catch (Horde_Exception_NotFound $e) {}
 77:         }
 78: 
 79:         /* Show a message if no available forums. Don't raise an error
 80:          * as it is not an error to have no forums. */
 81:         if (empty($forums_list)) {
 82:             return _("There are no forums.");
 83:         }
 84: 
 85:         /* Display only the most recent threads if preference set. */
 86:         if (!empty($this->_params['forum_display'])) {
 87:             $forums_list = array_slice($forums_list, 0, $this->_params['forum_display']);
 88:         }
 89: 
 90:         /* Set up the column headers. */
 91:         $col_headers = array('forum_name' => _("Forum"), 'message_count' => _("Posts"), 'message_subject' => _("Last Post"), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date"));
 92:         $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'forums');
 93: 
 94:         /* Set up the template tags. */
 95:         $view = new Agora_View();
 96:         $view->col_headers = $col_headers;
 97:         $view->forums_list = $forums_list;
 98: 
 99:         return $view->render('block/forums');
100:     }
101: 
102: }
103: 
API documentation generated by ApiGen