1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 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:
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:
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:
64: $sort_by = Agora::getSortBy('forums');
65: $sort_dir = Agora::getSortDir('forums');
66:
67:
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:
76: } catch (Horde_Exception_NotFound $e) {}
77: }
78:
79: 80:
81: if (empty($forums_list)) {
82: return _("There are no forums.");
83: }
84:
85:
86: if (!empty($this->_params['forum_display'])) {
87: $forums_list = array_slice($forums_list, 0, $this->_params['forum_display']);
88: }
89:
90:
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:
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: