/** */ protected function _content() { /* Return empty if we don't have a thread set. */ if (empty($this->_params['thread_id'])) { return ''; } /* Set up the message object. */ list($forum_id, $message_id) = explode('.', $this->_params['thread_id']); $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $forum_id); /* Check if valid thread, otherwise show forum list. */ if ($messages instanceof PEAR_Error || empty($messages)) { throw new Horde_Exception(_("Unable to fetch selected thread.")); } /* Get the sorting. */ $sort_by = Agora::getSortBy('threads'); $sort_dir = Agora::getSortDir('threads'); $view_bodies = $GLOBALS['prefs']->getValue('thread_view_bodies'); /* Get the message array and the sorted thread list. */ $threads_list = $messages->getThreads($messages->getThreadRoot($message_id), true, $sort_by, $sort_dir, $view_bodies, Horde::selfUrl()); /* Set up the column headers. */ $col_headers = array(array('message_thread' => _("Thread"), 'message_subject' => _("Subject")), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date")); $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'threads'); /* Set up the template tags. */ $view = new Agora_View(); $view->col_headers = $col_headers; $view->threads_list = $threads_list; $view->threads_list_header = _("Thread List"); $view->thread_view_bodies = $view_bodies; return $view->render('block/thread'); }
/** */ public function menu($menu) { $scope = Horde_Util::getGet('scope', 'agora'); /* Agora Home. */ $url = Horde::url('forums.php')->add('scope', $scope); $menu->add($url, _("_Forums"), 'forums.png', null, null, null, dirname($_SERVER['PHP_SELF']) == $GLOBALS['registry']->get('webroot') && basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null); /* Thread list, if applicable. */ if (isset($GLOBALS['forum_id'])) { $menu->add(Agora::setAgoraId($GLOBALS['forum_id'], null, Horde::url('threads.php')), _("_Threads"), 'threads.png'); if ($scope == 'agora' && $GLOBALS['registry']->getAuth()) { $menu->add(Agora::setAgoraId($GLOBALS['forum_id'], null, Horde::url('messages/edit.php')), _("New Thread"), 'newmessage.png'); } } if ($scope == 'agora' && Agora_Driver::hasPermission(Horde_Perms::DELETE, 0, $scope)) { $menu->add(Horde::url('editforum.php'), _("_New Forum"), 'newforum.png', null, null, null, Horde_Util::getFormData('agora') ? '__noselection' : null); } if (Agora_Driver::hasPermission(Horde_Perms::DELETE, 0, $scope)) { $url = Horde::url('moderate.php')->add('scope', $scope); $menu->add($url, _("_Moderate"), 'moderate.png'); } if ($GLOBALS['registry']->isAdmin()) { $menu->add(Horde::url('moderators.php'), _("_Moderators"), 'hot.png'); } $url = Horde::url('search.php')->add('scope', $scope); $menu->add($url, _("_Search"), 'search.png'); }
/** * Copyright 2005-2007 Andrew Hosie <*****@*****.**> * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl. */ function handle_avatarselect($updated) { if ($GLOBALS['conf']['avatar']['allow_avatars']) { $avatar_path = Horde_Util::getFormData('avatar_path'); $avatar_path = Agora::validateAvatar($avatar_path) ? $avatar_path : null; if ($avatar_path) { $GLOBALS['prefs']->setValue('avatar_path', $avatar_path); $updated = true; } } return $updated; }
function validate(&$vars, $canAutoFill = false) { global $conf; if (!parent::validate($vars, $canAutoFill)) { if (!$GLOBALS['registry']->getAuth() && !empty($conf['forums']['captcha'])) { $vars->remove('captcha'); $this->removeVariable($varname = 'captcha'); $this->insertVariableBefore('newcomment', _("Spam protection"), 'captcha', 'figlet', true, null, null, array(Agora::getCAPTCHA(true), $conf['forums']['figlet_font'])); } return false; } return true; }
/** */ protected function _content() { global $registry; /* Set up the forums object. */ $forums = array($GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create()); if ($GLOBALS['registry']->isAdmin()) { foreach ($registry->listApps(array('hidden', 'notoolbar', 'active')) as $scope) { if ($registry->hasMethod('hasComments', $scope) && $registry->callByPackage($scope, 'hasComments') === true) { $forums[] = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope); } } } /* Get the sorting. */ $sort_by = Agora::getSortBy('forums'); $sort_dir = Agora::getSortDir('forums'); /* Get the list of forums. */ $forums_list = array(); foreach ($forums as $forum) { try { $scope_forums = $forum->getForums(0, true, $sort_by, $sort_dir, true); $forums_list = array_merge($forums_list, $scope_forums); } catch (Agora_Exception $e) { return $e->getMessage(); /* Catch NotFound exception here so it won't break the cycle. */ } catch (Horde_Exception_NotFound $e) { } } /* Show a message if no available forums. Don't raise an error * as it is not an error to have no forums. */ if (empty($forums_list)) { return _("There are no forums."); } /* Display only the most recent threads if preference set. */ if (!empty($this->_params['forum_display'])) { $forums_list = array_slice($forums_list, 0, $this->_params['forum_display']); } /* Set up the column headers. */ $col_headers = array('forum_name' => _("Forum"), 'message_count' => _("Posts"), 'message_subject' => _("Last Post"), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date")); $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'forums'); /* Set up the template tags. */ $view = new Agora_View(); $view->col_headers = $col_headers; $view->forums_list = $forums_list; return $view->render('block/forums'); }
/** */ function __construct(&$vars, $title) { global $forums, $conf; parent::__construct($vars, $title); try { $forums_list = Agora::formatCategoryTree($forums->getForums(0, false, 'forum_name', 0, true)); } catch (Horde_Exception_NotFound $e) { $this->addHidden('', 'forum_parent_id', 'text', false); $vars->set('forum_parent_id', key($forums_list)); } $this->setButtons($vars->get('forum_id') ? _("Update") : _("Create")); $this->addHidden('', 'forum_id', 'int', false); $this->addVariable(_("Forum name"), 'forum_name', 'text', true); $this->addVariable(_("Parent forum"), 'forum_parent_id', 'enum', false, false, null, array($forums_list, true)); $this->addVariable(_("Enter a brief description of this forum"), 'forum_description', 'longtext', false, false, null, array(4, 40)); $this->addVariable(_("Is this a moderated forum?"), 'forum_moderated', 'boolean', false, false, _("Set this if you want all messages to be checked by a moderator before they are posted.")); $this->addVariable(_("Optional email address to recieve a copy of each posted message"), 'forum_distribution_address', 'text', false, false); if ($conf['forums']['enable_attachments'] == '0') { $this->addVariable(_("Allow attachments in this forum?"), 'forum_attachments', 'boolean', false, false, _("If selected users will be able to attach files to their messages.")); } }
*/ $prefGroups['display_avatar'] = array('column' => _("My Information"), 'label' => _("Avatar"), 'desc' => _("Set the avatar image that is shown with your posts."), 'members' => array('avatar_path', 'avatar_link'), 'suppress' => function () { return !empty($GLOBALS['conf']['avatar']['allow_avatars']); }); $prefGroups['display_forums'] = array('column' => _("Display Preferences"), 'label' => _("Forums View"), 'desc' => _("Set your preferences for the forums view."), 'members' => array('forums_sortby', 'forums_sortdir', 'forums_per_page')); $prefGroups['display_threads'] = array('column' => _("Display Preferences"), 'label' => _("Threads View"), 'desc' => _("Set your preferences for the threads view."), 'members' => array('threads_sortby', 'threads_sortdir', 'threads_hot', 'threads_per_page')); $prefGroups['display_thread'] = array('column' => _("Display Preferences"), 'label' => _("Single Thread View"), 'desc' => _("Set your preferences for the single thread view."), 'members' => array('thread_sortby', 'thread_sortdir', 'thread_view_bodies', 'thread_per_page')); $prefGroups['display_message'] = array('column' => _("Display Preferences"), 'label' => _("Message View"), 'desc' => _("Set your preferences for the message view."), 'members' => array('message_emoticons')); $prefGroups['display_comments'] = array('column' => _("Display Preferences"), 'label' => _("Comments view"), 'desc' => _("Set your preferences for the single thread view."), 'members' => array('comments_sortby', 'comments_sortdir', 'comments_view_bodies', 'comments_per_page')); /* Avatar */ $_prefs['avatar_path'] = array('value' => '', 'type' => 'text', 'desc' => _("The location of your avatar image.")); if ($GLOBALS['conf']['avatar']['allow_avatars'] && $GLOBALS['conf']['avatar']['enable_image_tests']) { $_prefs['avatar_path']['desc'] .= ' ' . sprintf(_("Avatars must be smaller than %s by %s pixels and less than %sKb in size."), $GLOBALS['conf']['avatar']['max_width'], $GLOBALS['conf']['avatar']['max_height'], $GLOBALS['conf']['avatar']['max_size']); } $_prefs['avatar_link'] = array('type' => 'rawhtml', 'suppress' => function () { $vfs = Agora::getVFS(); return $vfs instanceof PEAR_Error || !$GLOBALS['conf']['avatar']['enable_gallery'] || !$vfs->isFolder(Agora::AVATAR_PATH, 'gallery'); }); /* Forums */ $_prefs['forums_sortby'] = array('value' => 'forum_name', 'type' => 'enum', 'enum' => array('forum_name' => _("Forum"), 'message_count' => _("Messages"), 'message_subject' => _("Last Message"), 'message_author' => _("Posted by"), 'message_date' => _("Date")), 'desc' => _("Default forums view sort:")); $_prefs['forums_sortdir'] = array('value' => 0, 'type' => 'enum', 'enum' => array(0 => _("Ascending"), 1 => _("Descending")), 'desc' => _("Default sorting direction:")); $_prefs['forums_per_page'] = array('value' => 20, 'type' => 'enum', 'enum' => array(5 => 5, 10 => 10, 15 => 15, 20 => 20, 25 => 25), 'desc' => _("Number of forums to display on each page")); /* Threads */ $_prefs['threads_sortby'] = array('value' => 'message_modifystamp', 'type' => 'enum', 'enum' => array('message_thread' => _("Thread"), 'message_subject' => _("Subject"), 'message_author' => _("Posted by"), 'message_seq' => _("Posts"), 'message_timestamp' => _("Date"), 'message_modifystamp' => _("Last post")), 'desc' => _("Default threads view sort:")); $_prefs['threads_sortdir'] = array('value' => 1, 'type' => 'enum', 'enum' => array(0 => _("Ascending"), 1 => _("Descending")), 'desc' => _("Default sorting direction:")); $_prefs['threads_hot'] = array('value' => 20, 'type' => 'number', 'desc' => _("Number of views in 24hrs to trigger a 'hot-thread':")); $_prefs['threads_per_page'] = array('value' => 10, 'type' => 'enum', 'enum' => array(5 => 5, 10 => 10, 15 => 15, 20 => 20, 25 => 25), 'desc' => _("Number of messages to display on each page")); /* Thread */ $_prefs['thread_sortby'] = array('value' => 'message_timestamp', 'type' => 'enum', 'enum' => array('message_thread' => _("Thread"), 'message_subject' => _("Subject"), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date")), 'desc' => _("Default thread view sort:")); $_prefs['thread_sortdir'] = array('value' => 0, 'type' => 'enum', 'enum' => array(0 => _("Ascending"), 1 => _("Descending")), 'desc' => _("Default sorting direction:")); $_prefs['thread_view_bodies'] = array('value' => 0, 'type' => 'enum', 'enum' => array(0 => _("No"), 1 => _("Yes"), 2 => _("Yes, and don't thread them")), 'desc' => _("Display full message bodies in the thread list view?"));
/** */ protected function _content() { if (!isset($this->_params['forum_id'])) { throw new Horde_Exception(_("No forum selected")); } if (empty($this->_threads)) { $this->_threads = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $this->_params['forum_id']); if ($this->_threads instanceof PEAR_Error) { throw new Horde_Exception(_("Unable to fetch threads for selected forum.")); } } /* Get the sorting. */ $sort_by = Agora::getSortBy('threads'); $sort_dir = Agora::getSortDir('threads'); /* Get a list of threads and display only the most recent if * preference is set. */ $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); /* Show a message if no available threads. Don't raise an error * as it is not an error to have no threads. */ if (empty($threads_list)) { return _("No available threads."); } /* Set up the column headers. */ $col_headers = array('message_subject' => _("Subject"), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date")); $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'threads'); /* Set up the template tags. */ $view = new Agora_View(); $view->col_headers = $col_headers; $view->threads = $threads_list; return $view->render('block/threads'); }
} foreach ($forum['moderators'] as $id => $moderator) { $delete = $url->add(array('moderator' => $moderator, 'forum_id' => $forum['forum_id'])); $forums_list[$key]['moderators'][$id] = Horde::link($delete, _("Delete")) . $moderator . '</a>'; } } $title = _("Moderators"); $vars = Horde_Variables::getDefaultVariables(); $form = new Horde_Form($vars, $title); $form->addHidden('', 'scope', 'text', false); $form->addHidden('', 'action', 'text', false); $vars->set('action', 'add'); $form->addVariable(_("Moderator"), 'moderator', 'text', true); if ($messages->countForums() > 50) { $form->addVariable(_("Forum"), 'forum_id', 'int', true); } else { $forums_enum = Agora::formatCategoryTree($messages->getForums(0, false, 'forum_name', 0, !$registry->isAdmin())); $form->addVariable(_("Forum"), 'forum_id', 'enum', true, false, false, array($forums_enum)); } /* Set up template data. */ $view = new Agora_View(); Horde::startBuffer(); $form->renderActive(null, null, Horde::url('moderators.php'), 'post'); $view->formbox = Horde::endBuffer(); Horde::startBuffer(); $notification->notify(array('listeners' => 'status')); $view->notify = Horde::endBuffer(); $view->forums = $forums_list; $page_output->header(array('title' => $title)); echo $view->render('moderators'); $page_output->footer();
} /* Get a list of messages still to moderate. Error will occur if you don't have the right permissions */ $messages_list = $messages->getModerateList($sort_by, $sort_dir); if ($messages_list instanceof PEAR_Error) { $notification->push($messages_list->getMessage(), 'horde.error'); Horde::url('forums.php', true)->redirect(); } elseif (empty($messages_list)) { $messages_count = 0; $notification->push(_("No messages are waiting for moderation."), 'horde.message'); } else { $messages_count = count($messages_list); $messages_list = array_slice($messages_list, $messages_start, $messages_per_page); } /* Set up the column headers. */ $col_headers = array('forum_id' => _("Forum"), 'message_subject' => _("Subject"), 'message_author' => _("Posted by"), 'message_body' => _("Body"), 'message_timestamp' => _("Date")); $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'moderate'); /* Set up the template tags. */ $view = new Agora_View(); $view->col_headers = $col_headers; $view->messages = $messages_list; $view->buttons = array(_("Approve"), _("Delete")); $view->session_tag = Horde_Util::formInput(); Horde::startBuffer(); $notification->notify(array('listeners' => 'status')); $view->notify = Horde::endBuffer(); /* Set up pager. */ $vars = Horde_Variables::getDefaultVariables(); $pager_ob = new Horde_Core_Ui_Pager('moderate_page', $vars, array('num' => $messages_count, 'url' => Horde::selfUrl(true), 'perpage' => $messages_per_page)); $pager_ob->preserve('agora', Horde_Util::getFormData('agora')); $view->pager = $pager_ob->render(); if (isset($api_call)) {
if ($threads_list instanceof PEAR_Error) { $notification->push($threads_list->getMessage(), 'horde.error'); Horde::url('forums.php', true)->redirect(); } /* Set up pager. */ if ($thread_count > $thread_per_page && $view_bodies == 2) { $vars = new Horde_Variables(array('thread_page' => $thread_page)); $pager_ob = new Horde_Core_Ui_Pager('thread_page', $vars, array('num' => $thread_count, 'url' => 'messages/index.php', 'perpage' => $thread_per_page)); $pager_ob->preserve('agora', Horde_Util::getFormData('agora')); $view->pager_link = $pager_ob->render(); } /* Set up the column headers. */ $col_headers = array(array('message_thread' => _("Thread"), 'message_subject' => _("Subject")), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date")); $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'thread'); /* Actions. */ $url = Agora::setAgoraId($forum_id, $message_id, Horde::url('messages/index.php')); /* Get the thread table. */ switch ($view_bodies) { case '2': $threads_template = 'messages/flat'; if (!$prefs->isLocked('thread_view_bodies')) { $actions[] = Horde::link($url->add('bodies', 0), _("Hide bodies")) . _("Hide bodies") . '</a>'; $actions[] = Horde::link($url->add('bodies', 1), _("Thread")) . _("Thread") . '</a>'; } $threads = $messages->getThreadsUi($threads_list, $col_headers, $view_bodies, $threads_template); break; case '1': $threads_template = 'messages/flat_thread'; if (!$prefs->isLocked('thread_view_bodies')) { $actions[] = Horde::link($url->add('bodies', 0), _("Hide bodies")) . _("Hide bodies") . '</a>'; $actions[] = Horde::link($url->add('bodies', 2), _("Flat")) . _("Flat") . '</a>';
$form->setButtons(array(_("Move"), _("Cancel"))); $form->addHidden('', 'agora', 'text', false); $form->addHidden('', 'scope', 'text', false); $forums_list = Agora::formatCategoryTree($messages->getForums(0, false)); $v =& $form->addVariable(_("Forum"), 'new_forum_id', 'enum', true, false, null, array($forums_list)); $v->setDefault($forum_id); /* Validate the form. */ if ($form->validate()) { $form->getInfo($vars, $info); if ($vars->get('submitbutton') == _("Move")) { $move = $messages->moveThread($message_id, $info['new_forum_id']); if ($move instanceof PEAR_Error) { $notification->push($move->getMessage(), 'horde.error'); } else { $notification->push(sprintf(_("Thread %s moved to from forum %s to %s."), $message_id, $forum_id, $info['new_forum_id']), 'horde.success'); header('Location: ' . Agora::setAgoraId($info['new_forum_id'], $message_id, Horde::url('messages/index.php', true), $scope)); exit; } } } /* Template object. */ $view = new Agora_View(); Horde::startBuffer(); $form->renderActive(null, $vars, Horde::url('messages/move.php'), 'post'); $view->formbox = Horde::endBuffer(); $view->message_subject = $message['message_subject']; $view->message_author = $message['message_author']; $view->message_body = Agora_Driver::formatBody($message['body']); $page_output->header(); echo $view->render('messages/edit'); $page_output->footer();
$notification->push($forums->message, 'horde.error'); Horde::url('forums.php', true)->redirect(); } /* Check permissions */ if (!$forums->hasPermission(Horde_Perms::DELETE)) { $notification->push(sprintf(_("You don't have permissions to ban users from forum %s."), $forum_id), 'horde.warning'); Horde::url('forums.php', true)->redirect(); } /* Ban action */ if (($action = Horde_Util::getFormData('action')) !== null) { $user = Horde_Util::getFormData('user'); $result = $forums->updateBan($user, $forum_id, $action); if ($result instanceof PEAR_Error) { $notification->push($result->getMessage(), 'horde.error'); } $url = Agora::setAgoraId($forum_id, null, Horde::url('ban.php', true), $scope); header('Location: ' . $url); exit; } /* Get the list of banned users. */ $delete = Horde::url('ban.php')->add(array('action' => 'delete', 'scope' => $scope, 'forum_id' => $forum_id)); $banned = $forums->getBanned(); foreach ($banned as $user => $level) { $banned[$user] = Horde::link($delete->add('user', $user), _("Delete")) . $user . '</a>'; } $title = _("Ban"); $vars = Horde_Variables::getDefaultVariables(); $form = new Horde_Form($vars, $title); $form->addHidden('', 'scope', 'text', false); $form->addHidden('', 'agora', 'text', false); $form->addHidden('', 'action', 'text', false);
<lastBuildDate>' . date('r') . '</lastBuildDate> <description>' . htmlspecialchars($title) . '</description> <link>' . Horde::url('index.php', true, -1) . '</link> <generator>' . htmlspecialchars($registry->get('name')) . '</generator>'; // Use commentCallback to get the return link // show is not enought as we can have many parameters, like turba source etc $url = Horde::url('messages/index.php', true, -1); if ($scope != 'agora' && $registry->hasMethod('commentCallback', $scope)) { $try = $registry->callByPackage($scope, 'commentCallback', array($forum_name, 'link')); if ($try instanceof PEAR_Error) { die($try->getMessage()); } if (substr($url, 0, 4) == 'http') { $url = $try; } } foreach ($threads_list as $thread) { $rss .= ' <item> <title>' . htmlspecialchars($thread['message_subject']) . ' </title> <description>' . htmlspecialchars(trim($thread['body'])) . ' </description> <link>' . Agora::setAgoraId($forum_id, $thread['message_id'], $url, $scope, true) . '</link> </item>'; } $rss .= ' </channel> </rss>'; $cache->set($cache_key, $rss); } header('Content-type: text/xml; charset=UTF-8'); echo $rss;
$sort_by = Agora::getSortBy('forums'); $sort_dir = Agora::getSortDir('forums'); /* Which forums page are we on? Default to page 0. */ $forum_page = Horde_Util::getFormData('forum_page', 0); $forums_per_page = $prefs->getValue('forums_per_page'); $forum_start = $forum_page * $forums_per_page; /* Get the list of forums. */ try { $forums_list = $forums->getForums(0, true, $sort_by, $sort_dir, true, $forum_start, $forums_per_page); $forums_count = $forums->countForums(); } catch (Horde_Exception_NotFound $e) { $forums_count = 0; } /* Set up the column headers. */ $col_headers = array('forum_name' => _("Forum"), 'forum_description' => _("Description"), 'message_count' => _("Posts"), 'thread_count' => _("Threads"), 'message_timestamp' => _("Last Post"), 'message_author' => _("Posted by"), 'message_date' => _("Date")); $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'forums'); /* Set up the template tags. */ $view = new Agora_View(); $view->col_headers = $col_headers; $view->forums_list = $forums_list; Horde::startBuffer(); $notification->notify(array('listeners' => 'status')); $view->notify = Horde::endBuffer(); $view->actions = empty($actions) ? null : $actions; /* Set up pager. */ $vars = Horde_Variables::getDefaultVariables(); $pager_ob = new Horde_Core_Ui_Pager('forum_page', $vars, array('num' => $forums_count, 'url' => 'forums.php', 'perpage' => $forums_per_page)); $pager_ob->preserve('scope', $scope); $view->pager_link = $pager_ob->render(); $page_output->addLinkTag(array('href' => Horde::url('rss/index.php', true, -1)->add('scope', $scope), 'title' => _("Forums"))); $page_output->header(array('title' => _("All Forums")));
/** * Fetches a list of forums. * * @todo This function needs refactoring, as it doesn't return consistent * results. For example when running with $formatted = false it will return * an indexed array, but when running with $formatted = true the result is * associative array. * * @param integer $root_forum The first level forum. * @param boolean $formatted Whether to return the list formatted or raw. * @param string $sort_by The column to sort by. * @param integer $sort_dir Sort direction, 0 = ascending, * 1 = descending. * @param boolean $add_scope Add parent forum if forum for another * scopelication. * @param string $from The forum to start listing at. * @param string $count The number of forums to return. * * @return mixed An array of forums or PEAR_Error on failure. * @throws Agora_Exception */ public function getForums($root_forum = 0, $formatted = true, $sort_by = 'forum_name', $sort_dir = 0, $add_scope = false, $from = 0, $count = 0) { /* Get messages data */ $forums = $this->_getForums($root_forum, $formatted, $sort_by, $sort_dir, $add_scope, $from, $count); if ($forums instanceof PEAR_Error || empty($forums) || !$formatted) { return $forums; } $user = $GLOBALS['registry']->getAuth(); $edit_url = Horde::url('messages/edit.php'); $editforum_url = Horde::url('editforum.php'); $delete_url = Horde::url('deleteforum.php'); foreach ($forums as $key => &$forum) { if (!$this->hasPermission(Horde_Perms::SHOW, $forum['forum_id'], $forum['scope'])) { unset($forums[$key]); continue; } $forum['indentn'] = 0; $forum['indent'] = ''; if (!$this->hasPermission(Horde_Perms::READ, $forum['forum_id'], $forum['scope'])) { continue; } $forum['url'] = Agora::setAgoraId($forum['forum_id'], null, Horde::url('threads.php'), $forum['scope'], true); $forum['message_count'] = number_format($forum['message_count']); $forum['thread_count'] = number_format($forum['thread_count']); if ($forum['last_message_id']) { $forum['last_message_date'] = $this->dateFormat($forum['last_message_timestamp']); $forum['last_message_url'] = Agora::setAgoraId($forum['forum_id'], $forum['last_message_id'], Horde::url('messages/index.php'), $forum['scope'], true); } $forum['actions'] = array(); /* Post message button. */ if ($this->hasPermission(Horde_Perms::EDIT, $forum['forum_id'], $forum['scope'])) { /* New Post forum button. */ $url = Agora::setAgoraId($forum['forum_id'], null, $edit_url, $forum['scope'], true); $forum['actions'][] = Horde::link($url, _("Post message")) . _("New Post") . '</a>'; if ($GLOBALS['registry']->isAdmin(array('permission' => 'agora:admin'))) { /* Edit forum button. */ $url = Agora::setAgoraId($forum['forum_id'], null, $editforum_url, $forum['scope'], true); $forum['actions'][] = Horde::link($url, _("Edit forum")) . _("Edit") . '</a>'; } } if ($GLOBALS['registry']->isAdmin(array('permission' => 'agora:admin'))) { /* Delete forum button. */ $url = Agora::setAgoraId($forum['forum_id'], null, $delete_url, $forum['scope'], true); $forum['actions'][] = Horde::link($url, _("Delete forum")) . _("Delete") . '</a>'; } /* User is a moderator */ if (isset($forum['moderators']) && in_array($user, $forum['moderators'])) { $sql = 'SELECT COUNT(forum_id) FROM ' . $this->_threads_table . ' WHERE forum_id = ? AND approved = ?' . ' GROUP BY forum_id'; try { $unapproved = $this->_db->selectValue($sql, array($forum['forum_id'], 0)); } catch (Horde_Db_Exception $e) { throw new Agora_Exception($e->getMessage()); } $url = Horde::link(Horde::url('moderate.php', true), _("Moderate")) . _("Moderate") . '</a>'; $forum['actions'][] = $url . ' (' . $unapproved . ')'; } } return $forums; }
/** * Allows other Horde apps to post messages. * * In most apps we use the same code to make comments possible. This function * does most of that. Allow comments to be added to any app. The app itself * should check if the agora api is present, determine a key and call this * function before app::menu is called (before any output has started. At the * end of its output it can print the array returned to show the comments. * * @access private * * @param string $scope The application which is posting this message. * @param string $key Unique key from the object (picture etc we're * viewing. It will be used as the forum name. * @param string $callback A callback method of the specified application * that gets called to make sure that posting to * this forum is allowed. * @param boolean $body Show the comment bodies in the thread view or * not. * @param string $base_url Base URL the edit/delete/reply links should * point to. * @param string $url If specified, the form gets submitted to this * URL instead of the current page. * @param array $variables A hash with all variables of a submitted form * generated by this method. * @param string $template_file Template file to use. * * @return mixed array Returns either the rendered Horde_Form for comments * and threads for posting/viewing a message or PEAR * objects on error. */ public function doComments($scope, $key, $callback, $bodies = true, $base_url = null, $url = null, $variables = null, $template_file = false) { if (is_null($base_url)) { $base_url = Horde::selfUrl(true); } list($forum_id, $message_id) = Agora::getAgoraId(); $params = array(); if ($message_id) { $params['message_id'] = $message_id; } if ($parent = Horde_Util::getFormData('message_parent_id')) { $params['message_parent_id'] = $parent; } // See if we're editing. if (isset($params['message_id'])) { $params['title'] = _("Edit a comment"); } else { $params['title'] = _("Add a comment"); $params['message_id'] = null; } if (Horde_Util::getFormData('delete') === null) { $comments = $this->postMessage($scope, $key, $callback, $params, $url, $variables); } else { $comments = $this->removeMessage($scope, $key, $callback, $params, $url, $variables); } if ($comments instanceof PEAR_Error) { return $comments; } include AGORA_BASE . '/lib/Comments.php'; $threads = Agora_ViewComments::render($key, $scope, $base_url, $template_file); if ($threads instanceof PEAR_Error) { $threads = $threads->getMessage(); } if ($comments instanceof PEAR_Error) { $comments = $comments->getMessage(); } return array('threads' => $threads, 'comments' => $comments); }
$vars->set('forum_id', $forum_id); } catch (Horde_Exception $e) { $notification->push($e->getMessage()); unset($forum_id); } } $title = isset($forum_id) ? _("Edit Forum") : _("New Forum"); /* Check permissions */ if (isset($forum_id) && !$registry->isAdmin(array('permission' => 'agora:admin'))) { $notification->push(sprintf(_("You don't have permissions to edit forum %s"), $registry->get('name', $scope)), 'horde.warning'); Horde::url('forums.php', true)->redirect(); } if (!$registry->isAdmin(array('permission' => 'agora:admin'))) { $notification->push(sprintf(_("You don't have permissions to create a new forum in %s"), $registry->get('name', $scope)), 'horde.warning'); Horde::url('forums.php', true)->redirect(); } $form = new Agora_Form_Forum($vars, $title); if ($form->validate()) { $forum_id = $form->execute($vars); if ($forum_id instanceof PEAR_Error) { $notification->push(sprintf(_("Could not create the forum. %s"), $forum_id->message), 'horde.error'); Horde::url('forums.php', true)->redirect(); } $notification->push($vars->get('forum_id') ? _("Forum Modified") : _("Forum created."), 'horde.success'); header('Location: ' . Agora::setAgoraId($forum_id, null, Horde::url('threads.php', true))); exit; } $page_output->header(array('title' => $title)); $notification->notify(array('listeners' => 'status')); $form->renderActive(null, null, Horde::url('editforum.php'), 'post'); $page_output->footer();
/** * Returns all threads of a forum in a threaded view. * * @param string $forum_name The unique name for the forum. * @param boolean $bodies Whether to include message bodies in the view. * @param string $scope The application that the specified forum belongs to. * @param string $base_url An alternate link where edit/delete/reply links * point to. * @param string $template_file Template file to use. * * @return string The HTML code of the thread view. */ public static function render($forum_name, $scope = 'agora', $base_url = null, $template_file = false) { $forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope); $forum_id = $forums->getForumId($forum_name); if ($forum_id === null) { return ''; } $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $forum_id); if ($messages instanceof PEAR_Error) { return $messages->getMessage(); } if (($view_bodies = Horde_Util::getPost('bodies')) !== null) { $GLOBALS['prefs']->setValue('comments_view_bodies', $view_bodies); } else { $view_bodies = $GLOBALS['prefs']->getValue('comments_view_bodies'); } if ($messages->_forum['message_count'] == 0) { return ''; } $sort_by = Agora::getSortBy('comments'); $sort_dir = Agora::getSortDir('comments'); $html = '<div class="header">' . _("Comments") . ' (' . $messages->_forum['message_count'] . ')' . ' '; if (!$GLOBALS['prefs']->isLocked('comments_view_bodies')) { $rss = Horde::url('rss/threads.php', true, -1)->add(array('scope' => $scope, 'forum_id' => $forum_id)); $html .= '<span style="font-size: 0.8em;">'; $html .= '<form action=' . urldecode($base_url) . ' method="post" name="sorter" style="display: inline;">'; $html .= _("View") . ' <select name="bodies" onchange="document.sorter.submit()" >'; $html .= '<option value="2">' . _("Flat") . '</option>'; $html .= '<option value="1" ' . ($view_bodies == 1 ? 'selected="selected"' : '') . '>' . _("Thread") . '</option>'; $html .= '</select>'; if ($view_bodies != '1') { $html .= ' ' . _("Sort by") . ' '; $html .= '<select name="comments_sortby" onchange="document.sorter.submit()" >'; $html .= '<option value="message_timestamp" ' . ($sort_by == 'message_timestamp' ? 'selected="selected"' : '') . '>' . _("Date") . '</option>'; $html .= '<option value="message_author" ' . ($sort_by == 'message_author' ? 'selected="selected"' : '') . '>' . _("Author") . '</option>'; $html .= '<option value="message_subject" ' . ($sort_by == 'message_subject' ? 'selected="selected"' : '') . '>' . _("Subject") . '</option>'; $html .= '</select>'; $html .= ' ' . _("Sort direction") . ' '; $html .= '<select name="comments_sortdir" onchange="document.sorter.submit()" >'; $html .= '<option value="0">' . _("Ascending") . '</option>'; $html .= '<option value="1" ' . ($sort_dir == 1 ? 'selected="selected"' : '') . '>' . _("Descending") . '</option>'; $html .= '</select>'; } $html .= '<link rel="alternate" title="' . _("Threads") . '" href="' . $rss . '" type="application/rss+xml" />'; $html .= ' <a href="' . $rss . '" />RSS</a> '; $html .= '</form></span>'; } $html .= '</div>'; $col_headers = array('message_thread' => _("Subject"), 'message_thread_class_plain' => 'msgThreadPlain', 'message_author' => _("Posted by"), 'message_author_class_plain' => 'msgAuthorPlain', 'message_timestamp' => _("Date"), 'message_timestamp_class_plain' => 'msgTimestampPlain'); if ($view_bodies == 1) { $threads = $messages->getThreads(0, true, 'message_thread', 0, true, '', $base_url); $html .= $messages->getThreadsUi($threads, $col_headers, true, $template_file); } else { $thread_page = Horde_Util::getFormData('comments_page', 0); $thread_per_page = $GLOBALS['prefs']->getValue('comments_per_page'); $thread_start = $thread_page * $thread_per_page; if (empty($template_file)) { $template_file = 'messages/flat'; } if ($messages->_forum['message_count'] > $thread_per_page && $view_bodies == 2) { $vars = new Horde_Variables(array('comments_page' => $thread_page)); $pager_ob = new Horde_Core_Ui_Pager('comments_page', $vars, array('num' => $messages->_forum['message_count'], 'url' => $base_url, 'perpage' => $thread_per_page)); $pager_html = $pager_ob->render(); } else { $pager_html = ''; } $threads_list = $messages->getThreads(0, true, $sort_by, $sort_dir, 1, '', $base_url, $thread_start, $thread_per_page); if ($threads_list instanceof PEAR_Error) { $html .= $threads_list->getDebugInfo(); } else { $html .= $pager_html . $messages->getThreadsUi($threads_list, $col_headers, true, $template_file) . $pager_html; } } return $html; }
} $threads_list = $messages->getThreads($message['message_thread'], true, 'message_timestamp', 1, 1, '', null, 0, 10); if ($threads_list instanceof PEAR_Error) { exit; } $rss = '<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel> <title>' . htmlspecialchars($message['message_subject']) . '</title> <language>' . str_replace('_', '-', strtolower($registry->preferredLang())) . '</language> <lastBuildDate>' . date('r') . '</lastBuildDate> <description>' . htmlspecialchars($message['message_subject']) . '</description> <link>' . Horde::url('index.php', true, -1) . '</link> <generator>' . htmlspecialchars($registry->get('name')) . '</generator>'; foreach ($threads_list as $thread) { $url = Horde::url('messages/index.php', true, -1); $url = Agora::setAgoraId($forum_id, $thread['message_id'], $url, $scope, true); $rss .= ' <item> <title>' . htmlspecialchars($thread['message_subject']) . ' </title> <description>' . htmlspecialchars(trim($thread['body'])) . ' </description> <link>' . $url . '</link> </item>'; } $rss .= ' </channel> </rss>'; $cache->set($cache_key, $rss); } header('Content-type: text/xml; charset=UTF-8'); echo $rss;
$notification->push($forum->message, 'horde.error'); Horde::url('forums.php', true)->redirect(); } /* Prepare forum. */ $vars = Horde_Variables::getDefaultVariables(); $form = new Horde_Form($vars, _("Delete Forum")); // TODO Cancel button doesn't work currently, because it has no condition set $form->setButtons(array(_("Delete"), _("Cancel"))); $form->addHidden('', 'forum_id', 'int', $forum_id); $form->addHidden('', 'scope', 'text', $scope); $form->addVariable(_("This will delete the forum, any subforums and all relative messages."), 'prompt', 'description', false); $form->addVariable(_("Forum name"), 'forum_name', 'text', false, true); $vars->set('forum_name', $forum['forum_name']); $vars->set('forum_id', $forum_id); /* Get a list of available forums. */ $forums_list = Agora::formatCategoryTree($forums->getForums($forum_id, false, null, null)); if (!empty($forums_list)) { $html = implode('<br />', $forums_list); $form->addVariable(_("Subforums"), 'subforums', 'html', false, true); $vars->set('subforums', $html); } /* Process delete. */ if ($form->validate()) { if ($vars->get('submitbutton') == _("Delete")) { try { // TODO also delete child forums as we state in the GUI $forums->deleteForum($vars->get('forum_id')); $notification->push(_("Forum deleted."), 'horde.success'); } catch (Agora_Exception $e) { $notification->push(sprintf(_("Could not delete the forum. %s"), $e->getMessage()), 'horde.error'); }
if ($form->validate($vars)) { $form->getInfo($vars, $info); /* Try and store this message and get back a new message_id */ $message_id = $messages->saveMessage($info); if ($message_id instanceof PEAR_Error) { $notification->push(_("Could not post the message: ") . $message_id->getDebugInfo(), 'horde.error'); } else { if ($messages->_forum['forum_moderated']) { $notification->push(_("Your message has been enqueued and is awaiting moderation. It will become visible after moderator approval."), 'horde.success'); } else { $notification->push(_("Message posted."), 'horde.success'); } if (!empty($info['url'])) { $url = Horde::url($info['url'], true); } else { $url = Agora::setAgoraId($forum_id, $message_id, Horde::url('messages/index.php', true), $scope); } header('Location: ' . $url); exit; } } /* Set up template */ $view = new Agora_View(); /* Check if a parent message exists and set up tags accordingly. */ if ($message_parent_id) { $message = $messages->replyMessage($message_parent_id); if (!$message instanceof PEAR_Error) { $vars->set('message_subject', $message['message_subject']); $vars->set('message_body_old', $message['body']); $view->message_subject = $message['message_subject']; $view->message_author = $message['message_author'];
require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('agora'); /* Set up the forums object. */ $scope = Horde_Util::getGet('scope', 'agora'); $messages = $injector->getInstance('Agora_Factory_Driver')->create($scope); $vars = Horde_Variables::getDefaultVariables(); $form = new Agora_Form_Search($vars, $scope); $thread_page = Horde_Util::getFormData('thread_page'); $view = new Agora_View(); if ($form->isSubmitted() || $thread_page != null) { $form->getInfo($vars, $info); if (!empty($info['keywords'])) { $info['keywords'] = preg_split('/\\s+/', $info['keywords']); } $sort_by = Agora::getSortBy('thread'); $sort_dir = Agora::getSortDir('thread'); $thread_per_page = $prefs->getValue('thread_per_page'); $thread_start = $thread_page * $thread_per_page; $searchResults = $messages->search($info, $sort_by, $sort_dir, $thread_start, $thread_per_page); if ($searchResults instanceof PEAR_Error) { $notification->push($searchResults->getMessage(), 'horde.error'); Horde::url('search.php')->redirect(); } if ($searchResults['total'] > count($searchResults['results'])) { $pager_ob = new Horde_Core_Ui_Pager('thread_page', $vars, array('num' => $searchResults['total'], 'url' => 'search.php', 'perpage' => $thread_per_page)); foreach ($info as $key => $val) { if ($val) { if ($key == 'keywords') { $val = implode(' ', $val); } $pager_ob->preserve($key, $val);