1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class {
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 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'] . ')' . ' ';
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: