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:  * Comments display script
  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 Duck <duck@obala.net>
 12:  */
 13: class Agora_ViewComments {
 14: 
 15:     /**
 16:      * Returns all threads of a forum in a threaded view.
 17:      *
 18:      * @param string  $forum_name     The unique name for the forum.
 19:      * @param boolean $bodies         Whether to include message bodies in the view.
 20:      * @param string  $scope          The application that the specified forum belongs to.
 21:      * @param string  $base_url       An alternate link where edit/delete/reply links
 22:      *                                point to.
 23:      * @param string  $template_file  Template file to use.
 24:      *
 25:      * @return string  The HTML code of the thread view.
 26:      */
 27:     static public function render($forum_name, $scope = 'agora', $base_url = null, $template_file = false)
 28:     {
 29:         $forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope);
 30:         $forum_id = $forums->getForumId($forum_name);
 31:         if ($forum_id === null) {
 32:             return '';
 33:         }
 34: 
 35:         $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $forum_id);
 36:         if ($messages instanceof PEAR_Error) {
 37:             return $messages->getMessage();
 38:         }
 39: 
 40:         if (($view_bodies = Horde_Util::getPost('bodies')) !== null) {
 41:             $GLOBALS['prefs']->setValue('comments_view_bodies', $view_bodies);
 42:         } else {
 43:             $view_bodies = $GLOBALS['prefs']->getValue('comments_view_bodies');
 44:         }
 45: 
 46:         if ($messages->_forum['message_count'] == 0) {
 47:             return '';
 48:         }
 49: 
 50:         $sort_by = Agora::getSortBy('comments');
 51:         $sort_dir = Agora::getSortDir('comments');
 52:         $html = '<div class="header">' . _("Comments") . ' (' . $messages->_forum['message_count'] . ')' . '&nbsp;&nbsp;';
 53:         if (!$GLOBALS['prefs']->isLocked('comments_view_bodies')) {
 54:             $rss = Horde_Util::addParameter(Horde::url('rss/threads.php', true, -1), array('scope' => $scope, 'forum_id' => $forum_id));
 55:             $html .= '<span style="font-size: 0.8em;">';
 56:             $html .= '<form action=' . urldecode($base_url) . ' method="post" name="sorter" style="display: inline;">';
 57:             $html .= _("View") . ' <select name="bodies" onchange="document.sorter.submit()" >';
 58:             $html .= '<option value="2">' . _("Flat") .'</option>';
 59:             $html .= '<option value="1" ' . ($view_bodies == 1 ? 'selected="selected"' : '') . '>' . _("Thread") .'</option>';
 60:             $html .= '</select>';
 61: 
 62:             if ($view_bodies != '1') {
 63:                 $html .= ' ' . _("Sort by") . ' ';
 64:                 $html .= '<select name="comments_sortby" onchange="document.sorter.submit()" >';
 65:                 $html .= '<option value="message_timestamp" ' . ($sort_by == 'message_timestamp' ? 'selected="selected"' : '') . '>' . _("Date") .'</option>';
 66:                 $html .= '<option value="message_author" ' . ($sort_by == 'message_author' ? 'selected="selected"' : '') . '>' . _("Author") .'</option>';
 67:                 $html .= '<option value="message_subject" ' . ($sort_by == 'message_subject' ? 'selected="selected"' : '') . '>' . _("Subject") .'</option>';
 68:                 $html .= '</select>';
 69:                 $html .= ' ' . _("Sort direction") . ' ';
 70:                 $html .= '<select name="comments_sortdir" onchange="document.sorter.submit()" >';
 71:                 $html .= '<option value="0">' . _("Ascending") .'</option>';
 72:                 $html .= '<option value="1" ' . ($sort_dir == 1 ? 'selected="selected"' : '') . '>' . _("Descending") .'</option>';
 73:                 $html .= '</select>';
 74:             }
 75:             $html .= '<link rel="alternate" title="' . _("Threads") . '" href="' . $rss . '" type="application/rss+xml" />';
 76:             $html .= ' <a href="' . $rss . '" />RSS</a> ';
 77:             $html .= '</form></span>';
 78:         }
 79:         $html .= '</div>';
 80: 
 81:         $col_headers = array(
 82:             'message_thread' => _("Subject"),
 83:             'message_thread_class_plain' => 'msgThreadPlain',
 84:             'message_author' => _("Posted by"),
 85:             'message_author_class_plain' => 'msgAuthorPlain',
 86:             'message_timestamp' => _("Date"),
 87:             'message_timestamp_class_plain' => 'msgTimestampPlain'
 88:         );
 89: 
 90:         if ($view_bodies == 1) {
 91:             $threads = $messages->getThreads(0, true, 'message_thread', 0, true, '', $base_url);
 92:             $html .= $messages->getThreadsUi($threads, $col_headers, true, $template_file);
 93:         } else {
 94:             $thread_page = Horde_Util::getFormData('comments_page', 0);
 95:             $thread_per_page = $GLOBALS['prefs']->getValue('comments_per_page');
 96:             $thread_start = $thread_page * $thread_per_page;
 97: 
 98:             if (empty($template_file)) {
 99:                 $template_file = 'messages/flat';
100:             }
101: 
102:             if ($messages->_forum['message_count'] > $thread_per_page && $view_bodies == 2) {
103:                 $vars = new Horde_Variables(array('comments_page' => $thread_page));
104:                 $pager_ob = new Horde_Core_Ui_Pager('comments_page', $vars,
105:                                                 array('num' => $messages->_forum['message_count'],
106:                                                       'url' => $base_url,
107:                                                       'perpage' => $thread_per_page));
108: 
109:                 $pager_html = $pager_ob->render();
110:             } else {
111:                 $pager_html = '';
112:             }
113: 
114:             $threads_list = $messages->getThreads(0, true, $sort_by, $sort_dir, 1, '', $base_url, $thread_start, $thread_per_page);
115:             if ($threads_list instanceof PEAR_Error) {
116:                 $html .= $threads_list->getDebugInfo();
117:             } else {
118:                 $html .= $pager_html
119:                     . $messages->getThreadsUi($threads_list, $col_headers, true, $template_file)
120:                     . $pager_html;
121:             }
122:         }
123: 
124:         return $html;
125:     }
126: 
127: }
128: 
API documentation generated by ApiGen