/** * Prepare category display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); require_once KPATH_SITE . '/models/category.php'; $this->model = new KunenaModelCategory(); $this->me = KunenaUserHelper::getMyself(); $catid = $this->input->getInt('catid'); $limitstart = $this->input->getInt('limitstart', 0); $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = $this->config->threads_per_page; } // TODO: $direction = 'DESC'; $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); $this->headerText = JText::_('COM_KUNENA_THREADS_IN_FORUM') . ': ' . $this->category->name; $topic_ordering = $this->category->topic_ordering; $access = KunenaAccess::getInstance(); $hold = $access->getAllowedHold($this->me, $catid); $moved = 1; $params = array('hold' => $hold, 'moved' => $moved); switch ($topic_ordering) { case 'alpha': $params['orderby'] = 'tt.ordering DESC, tt.subject ASC '; break; case 'creation': $params['orderby'] = 'tt.ordering DESC, tt.first_post_time ' . $direction; break; case 'lastpost': default: $params['orderby'] = 'tt.ordering DESC, tt.last_post_time ' . $direction; } list($this->total, $this->topics) = KunenaForumTopicHelper::getLatestTopics($catid, $limitstart, $limit, $params); if ($this->total > 0) { // Collect user ids for avatar prefetch when integrated. $userlist = array(); $lastpostlist = array(); foreach ($this->topics as $topic) { $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid); $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid); $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id); } // Prefetch all users/avatars to avoid user by user queries during template iterations. if (!empty($userlist)) { KunenaUserHelper::loadUsers($userlist); } KunenaForumTopicHelper::getUserTopics(array_keys($this->topics)); KunenaForumTopicHelper::getKeywords(array_keys($this->topics)); $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch last / new post positions when user can see unapproved or deleted posts. if ($lastreadlist || $this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus()) { KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist); } } $this->topicActions = $this->model->getTopicActions(); $this->actionMove = $this->model->getActionMove(); $this->pagination = new KunenaPagination($this->total, $limitstart, $limit); $this->pagination->setDisplayedPages(5); }
/** * Prepare category display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); require_once KPATH_SITE . '/models/category.php'; $catid = $this->input->getInt('catid'); $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); }
/** * Test getCategories() */ public function testGetAllCategories() { $categories = KunenaForumCategoryHelper::getCategories(); $this->assertInternalType('array', $categories); foreach ($categories as $id=>$category) { $this->assertEquals($id, $category->id); $this->assertTrue($category->exists()); $this->assertSame($category, KunenaForumCategoryHelper::get($id)); } }
function check() { $user = KunenaUserHelper::get($this->user_id); if (!$user->exists()) { $this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_USERCATEGORIES_ERROR_USER_INVALID', (int) $user->userid ) ); } if ($this->category_id && !KunenaForumCategoryHelper::get($this->category_id)->exists()) { $this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_USERCATEGORIES_ERROR_CATEGORY_INVALID', (int) $category->id ) ); } return ($this->getError () == ''); }
/** * Send list of topic icons in JSON for the category set selected * * @return string */ public function displayTopicIcons() { jimport('joomla.filesystem.folder'); $catid = $this->app->input->getInt('catid', 0); $category = KunenaForumCategoryHelper::get($catid); $category_iconset = $category->iconset; if (empty($category_iconset)) { $response = array(); // Set the MIME type and header for JSON output. $this->document->setMimeEncoding('application/json'); JResponse::setHeader('Content-Disposition', 'attachment; filename="' . $this->getName() . '.' . $this->getLayout() . '.json"'); echo json_encode($response); } $topicIcons = array(); $template = KunenaFactory::getTemplate(); $xmlfile = JPATH_ROOT . '/media/kunena/topic_icons/' . $category_iconset . '/topicicons.xml'; if (is_file($xmlfile)) { $xml = simplexml_load_file($xmlfile); foreach ($xml->icons as $icons) { $type = (string) $icons->attributes()->type; $width = (int) $icons->attributes()->width; $height = (int) $icons->attributes()->height; foreach ($icons->icon as $icon) { $attributes = $icon->attributes(); $icon = new stdClass(); $icon->id = (int) $attributes->id; $icon->type = (string) $attributes->type ? (string) $attributes->type : $type; $icon->name = (string) $attributes->name; if ($icon->type != 'user') { $icon->id = $icon->type . '_' . $icon->name; } $icon->iconset = $category_iconset; $icon->published = (int) $attributes->published; $icon->title = (string) $attributes->title; $icon->b2 = (string) $attributes->b2; $icon->b3 = (string) $attributes->b3; $icon->fa = (string) $attributes->fa; $icon->filename = (string) $attributes->src; $icon->width = (int) $attributes->width ? (int) $attributes->width : $width; $icon->height = (int) $attributes->height ? (int) $attributes->height : $height; $icon->path = JURI::root() . 'media/kunena/topic_icons/' . $category_iconset . '/' . $icon->filename; $icon->relpath = $template->getTopicIconPath("{$icon->filename}", false, $category_iconset); $topicIcons[] = $icon; } } } // Set the MIME type and header for JSON output. $this->document->setMimeEncoding('application/json'); JResponse::setHeader('Content-Disposition', 'attachment; filename="' . $this->getName() . '.' . $this->getLayout() . '.json"'); echo json_encode($topicIcons); }
public function check() { $category = KunenaForumCategoryHelper::get($this->category_id); if (!$category->exists()) { $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_TOPICS_ERROR_CATEGORY_INVALID', $category->id)); } else { $this->category_id = $category->id; } $this->subject = trim($this->subject); if (!$this->subject) { $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_TOPICS_ERROR_NO_SUBJECT')); } return $this->getError() == ''; }
/** * Redirect unread layout to the page that contains the first unread message. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { $catid = $this->input->getInt('catid', 0); $id = $this->input->getInt('id', 0); $category = KunenaForumCategoryHelper::get($catid); $category->tryAuthorise(); $topic = KunenaForumTopicHelper::get($id); $topic->tryAuthorise(); KunenaForumTopicHelper::fetchNewStatus(array($topic->id => $topic)); $message = KunenaForumMessageHelper::get($topic->lastread ? $topic->lastread : $topic->last_post_id); $message->tryAuthorise(); while (@ob_end_clean()) { } $this->app->redirect($topic->getUrl($category, false, $message)); }
function subscribe() { if (!JSession::checkToken('get')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->redirectBack(); } $category = KunenaForumCategoryHelper::get(JRequest::getInt('catid', 0)); if (!$category->authorise('read')) { $this->app->enqueueMessage($category->getError(), 'error'); $this->redirectBack(); } if ($this->me->exists()) { $success = $category->subscribe(1); if ($success) { $this->app->enqueueMessage(JText::_('COM_KUNENA_GEN_CATEGORY_SUBCRIBED')); } } $this->redirectBack(); }
function doprune() { $app = JFactory::getApplication (); if (!JRequest::checkToken()) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' ); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $category = KunenaForumCategoryHelper::get(JRequest::getInt ( 'prune_forum', 0 )); if (!$category->authorise('admin')) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_CHOOSEFORUMTOPRUNE' ), 'error' ); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } // Convert days to seconds for timestamp functions... $prune_days = JRequest::getInt ( 'prune_days', 36500 ); $prune_date = JFactory::getDate()->toUnix() - ($prune_days * 86400); $trashdelete = JRequest::getInt( 'trashdelete', 0); // Get up to 100 oldest topics to be deleted $params = array( 'orderby'=>'tt.last_post_time ASC', 'where'=>"AND tt.last_post_time<{$prune_date} AND ordering=0", ); list($count, $topics) = KunenaForumTopicHelper::getLatestTopics($category->id, 0, 100, $params); $deleted = 0; foreach ( $topics as $topic ) { $deleted++; if ( $trashdelete ) $topic->delete(false); else $topic->trash(); } KunenaUserHelper::recount(); KunenaForumCategoryHelper::recount(); KunenaForumMessageAttachmentHelper::cleanup(); if ( $trashdelete ) $app->enqueueMessage ( "" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNEDELETED') . " {$deleted}/{$count} " . JText::_('COM_KUNENA_PRUNETHREADS') ); else $app->enqueueMessage ( "" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNETRASHED') . " {$deleted}/{$count} " . JText::_('COM_KUNENA_PRUNETHREADS') ); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); }
protected function DisplayCreate($tpl = null) { $this->setLayout('edit'); // Get captcha $captcha = KunenaSpamRecaptcha::getInstance(); if ($captcha->enabled()) { $this->captchaHtml = $captcha->getHtml(); if (!$this->captchaHtml) { $this->app->enqueueMessage($captcha->getError(), 'error'); $this->redirectBack(); return; } } // Get saved message $saved = $this->app->getUserState('com_kunena.postfields'); // Get topic icons if allowed if ($this->config->topicicons) { $this->topicIcons = $this->ktemplate->getTopicIcons(false, $saved ? $saved['icon_id'] : 0); } $categories = KunenaForumCategoryHelper::getCategories(); $arrayanynomousbox = array(); $arraypollcatid = array(); foreach ($categories as $category) { if (!$category->isSection() && $category->allow_anonymous) { $arrayanynomousbox[] = '"' . $category->id . '":' . $category->post_anonymous; } if (!$category->isSection() && $category->allow_polls) { $arraypollcatid[] = '"' . $category->id . '":1'; } } $arrayanynomousbox = implode(',', $arrayanynomousbox); $arraypollcatid = implode(',', $arraypollcatid); $this->document->addScriptDeclaration('var arrayanynomousbox={' . $arrayanynomousbox . '}'); $this->document->addScriptDeclaration('var pollcategoriesid = {' . $arraypollcatid . '};'); $cat_params = array('ordering' => 'ordering', 'toplevel' => 0, 'sections' => 0, 'direction' => 1, 'hide_lonely' => 1, 'action' => 'topic.create'); $this->catid = $this->state->get('item.catid'); $this->category = KunenaForumCategoryHelper::get($this->catid); list($this->topic, $this->message) = $this->category->newTopic($saved); if (!$this->topic->category_id) { $msg = JText::sprintf('COM_KUNENA_POST_NEW_TOPIC_NO_PERMISSIONS', $this->topic->getError()); $this->app->enqueueMessage($msg, 'notice'); return false; } $options = array(); $selected = $this->topic->category_id; if ($this->config->pickup_category) { $options[] = JHtml::_('select.option', '', JText::_('COM_KUNENA_SELECT_CATEGORY'), 'value', 'text'); $selected = 0; } if ($saved) { $selected = $saved['catid']; } $this->selectcatlist = JHtml::_('kunenaforum.categorylist', 'catid', $this->catid, $options, $cat_params, 'class="inputbox required"', 'value', 'text', $selected, 'postcatid'); $this->_prepareDocument('create'); $this->action = 'post'; $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category); if ($arraypollcatid) { $this->poll = $this->topic->getPoll(); } $this->post_anonymous = $saved ? $saved['anonymous'] : !empty($this->category->post_anonymous); $this->subscriptionschecked = $saved ? $saved['subscribe'] : $this->config->subscriptionschecked == 1; $this->app->setUserState('com_kunena.postfields', null); $this->render('Topic/Edit', $tpl); }
/** * @param mixed $category * @param string $action * * @return JUri|null */ public function getUri($category = null, $action = null) { $category = $category ? KunenaForumCategoryHelper::get($category) : $this->getCategory(); $Itemid = KunenaRoute::getCategoryItemid($category); if (!$this->exists() || !$category->exists()) { return null; } if ($action instanceof KunenaForumMessage) { $message = $action; $action = 'post' . $message->id; } $uri = JUri::getInstance("index.php?option=com_kunena&view=topic&catid={$category->id}&id={$this->id}&action={$action}&Itemid={$Itemid}"); if ($uri->getVar('action') !== null) { $uri->delVar('action'); $mesid = 0; $limit = max(1, intval(KunenaFactory::getConfig()->messages_per_page)); if (isset($message)) { $mesid = $message->id; } elseif ((string) $action === (string) (int) $action) { if ($action > 0) { $uri->setVar('limitstart', $action * $limit); } } else { switch ($action) { case 'first': $mesid = $this->first_post_id; break; case 'last': $mesid = $this->last_post_id; break; case 'unread': // Special case, improves caching $uri->setVar('layout', 'unread'); // $mesid = $this->lastread ? $this->lastread : $this->last_post_id; break; } } if ($mesid) { if (KunenaUserHelper::getMyself()->getTopicLayout() != 'threaded' && $mesid > 0) { $uri->setFragment($mesid); $limitstart = intval($this->getPostLocation($mesid) / $limit) * $limit; if ($limitstart) { $uri->setVar('limitstart', $limitstart); } } else { $uri->setVar('mesid', $mesid); } } } return $uri; }
function KunenaParseRoute($segments) { $profiler = JProfiler::getInstance('Application'); KUNENA_PROFILER ? $profiler->mark('kunenaRoute') : null; $starttime = $profiler->getmicrotime(); // Get current menu item and get query variables from it $active = JFactory::getApplication()->getMenu ()->getActive (); $vars = isset ( $active->query ) ? $active->query : array ('view'=>'home'); if (empty($vars['view']) || $vars['view']=='home' || $vars['view']=='entrypage') { $vars['view'] = ''; } // Fix bug in Joomla 1.5 when using /components/kunena instead /component/kunena if (!$active && $segments[0] == 'kunena') array_shift ( $segments ); // Enable SEF category feature $sefcats = KunenaRoute::$config->sefcats && isset(KunenaRouter::$sefviews[$vars['view']]) && empty($vars ['id']); // Handle all segments while ( ($segment = array_shift ( $segments )) !== null ) { $seg = explode ( ':', $segment ); $var = array_shift ( $seg ); $value = array_shift ( $seg ); if (is_numeric ( $var )) { $value = (int) $var; if ($vars['view'] == 'user') { $var = 'userid'; } else { // Numeric variable is always catid or id if (empty($vars ['catid']) || (empty($vars ['id']) && KunenaForumCategoryHelper::get($value)->exists() && KunenaForumTopicHelper::get($value)->category_id != $vars ['catid'])) { // First numbers are always categories // FIXME: what if $topic->catid == catid $var = 'catid'; $vars ['view'] = 'category'; } elseif (empty($vars ['id'])) { // Next number is always topic $var = 'id'; $vars ['view'] = 'topic'; $sefcats = false; } elseif (empty($vars ['mesid'])) { // Next number is always message $var = 'mesid'; $vars ['view'] = 'topic'; } else { // Invalid parameter, skip it continue; } } } elseif (empty ( $var ) && empty ( $value )) { // Empty parameter, skip it continue; } elseif ($sefcats && (($value !== null && ! isset ( KunenaRouter::$parsevars[$var] )) || ($value === null && ! isset ( KunenaRouter::$views[$var] ) && ! isset ( KunenaRouter::$layouts[$var] ) && ! isset ( KunenaRouter::$functions[$var] )))) { // We have SEF category: translate category name into catid=123 // TODO: cache filtered values to gain some speed -- I would like to start using category names instead of catids if it gets fast enough $var = 'catid'; $value = -1; $catname = strtr ( $segment, ':', '-' ); $categories = empty($vars ['catid']) ? KunenaForumCategoryHelper::getCategories() : KunenaForumCategoryHelper::getChildren($vars ['catid']); foreach ( $categories as $category ) { if ($catname == KunenaRouter::filterOutput ( $category->name ) || $catname == JFilterOutput::stringURLSafe ( $category->name )) { $value = (int) $category->id; break; } } $vars ['view'] = 'category'; } elseif ($value === null) { // Variable must be either view or layout $sefcats = false; $value = $var; if (empty($vars ['view']) || ($value=='topic' && $vars ['view'] == 'category')) { $var = 'view'; } elseif (empty($vars ['layout'])) { $var = 'layout'; } else { // Unknown parameter: continue if (!empty($vars ['view'])) continue; // Oops: unknown view or non-existing category $var = 'view'; } } $vars [$var] = $value; } if (empty($vars ['layout'])) $vars ['layout'] = 'default'; KunenaRouter::$time = $profiler->getmicrotime() - $starttime; return $vars; }
protected function orderUpDown($id, $direction) { KunenaFactory::loadLanguage('com_kunena', 'admin'); if (!$id) { return; } if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); return; } $category = KunenaForumCategoryHelper::get($id); if (!$category->getParent()->authorise('admin')) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CATEGORY_NO_ADMIN', $this->escape($category->getParent()->name)), 'notice'); return; } if ($category->isCheckedOut($this->me->userid)) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CATEGORY_X_CHECKED_OUT', $this->escape($category->name)), 'notice'); return; } $db = JFactory::getDBO(); $row = new TableKunenaCategories ($db); $row->load($id); // Ensure that we have the right ordering $where = 'parent_id=' . $db->quote($row->parent_id); $row->reorder(); $row->move($direction, $where); }
function check() { $category = KunenaForumCategoryHelper::get($this->catid); if (!$category->exists()) { // TODO: maybe we should have own error message? or not? $this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_TOPICS_ERROR_CATEGORY_INVALID', $this->catid ) ); } else { $this->catid = $category->id; } $this->subject = trim($this->subject); if (!$this->subject) { $this->setError ( JText::_ ( 'COM_KUNENA_LIB_TABLE_MESSAGES_ERROR_NO_SUBJECT' ) ); } $this->message = trim($this->message); if (!$this->message) { $this->setError ( JText::_ ( 'COM_KUNENA_LIB_TABLE_MESSAGES_ERROR_NO_MESSAGE' ) ); } if (!$this->time) { $this->time = JFactory::getDate()->toUnix(); } $this->modified_reason = trim($this->modified_reason); return ($this->getError () == ''); }
public static function categorylist($name, $parent, $options = array(), $params = array(), $attribs = null, $key = 'value', $text = 'text', $selected = array(), $idtag = false, $translate = false) { $unpublished = isset($params['unpublished']) ? (bool) $params['unpublished'] : 0; $sections = isset($params['sections']) ? (bool) $params['sections'] : 0; $ordering = isset($params['ordering']) ? (string) $params['ordering'] : 'ordering'; $direction = isset($params['direction']) && $params['direction'] == 'desc' ? -1 : 1; $action = isset($params['action']) ? (string) $params['action'] : 'read'; $levels = isset($params['levels']) ? (int) $params['levels'] : 10; $topleveltxt = isset($params['toplevel']) ? $params['toplevel'] : false; $catid = isset($params['catid']) ? (int) $params['catid'] : 0; $hide_lonely = isset($params['hide_lonely']) ? (bool) $params['hide_lonely'] : 0; $params = array(); $params['ordering'] = $ordering; $params['direction'] = $direction; $params['unpublished'] = $unpublished; $params['action'] = $action; $params['selected'] = $catid; if ($catid) { $category = KunenaForumCategoryHelper::get($catid); if (!$category->getParent()->authorise($action) && !KunenaUserHelper::getMyself()->isAdmin()) { $categories = KunenaForumCategoryHelper::getParents($catid, $levels, $params); } } $channels = array(); if (!isset($categories)) { $category = KunenaForumCategoryHelper::get($parent); $children = KunenaForumCategoryHelper::getChildren($parent, $levels, $params); if ($params['action'] == 'topic.create') { $channels = $category->getChannels(); if (empty($children) && !isset($channels[$category->id])) { $category = KunenaForumCategoryHelper::get(); } foreach ($channels as $id => $channel) { if (!$id || $category->id == $id || isset($children[$id]) || !$channel->authorise($action)) { unset($channels[$id]); } } } $categories = $category->id > 0 ? array($category->id => $category) + $children : $children; if ($hide_lonely && count($categories) + count($channels) <= 1) { return; } } if (!is_array($options)) { $options = array(); } if ($selected === false || $selected === null) { $selected = array(); } elseif (!is_array($selected)) { $selected = array((string) $selected); } if ($topleveltxt) { $me = KunenaUserHelper::getMyself(); $disabled = $action == 'admin' && !$me->isAdmin(); $options[] = JHtml::_('select.option', '0', JText::_($topleveltxt), 'value', 'text', $disabled); if (empty($selected) && !$disabled) { $selected[] = 0; } $toplevel = 1; } else { $toplevel = -KunenaForumCategoryHelper::get($parent)->level; } foreach ($categories as $category) { $disabled = !$category->authorise($action) || !$sections && $category->isSection(); if (empty($selected) && !$disabled) { $selected[] = $category->id; } $options[] = JHtml::_('select.option', $category->id, str_repeat('- ', $category->level + $toplevel) . ' ' . $category->name, 'value', 'text', $disabled); } $disabled = false; foreach ($channels as $category) { if (empty($selected)) { $selected[] = $category->id; } $options[] = JHtml::_('select.option', $category->id, '+ ' . $category->getParent()->name . ' / ' . $category->name, 'value', 'text', $disabled); } reset($options); if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $id = $name; if ($idtag) { $id = $idtag; } $id = str_replace('[', '', $id); $id = str_replace(']', '', $id); $html = ''; if (!empty($options)) { $html .= '<select name="' . $name . '" id="' . $id . '" ' . $attribs . '>'; $html .= JHtml::_('select.options', $options, $key, $text, $selected, $translate); $html .= '</select>'; } return $html; }
public function getCategory() { return KunenaForumCategoryHelper::get($this->getState('item.catid')); }
/** * @param mixed $category * @param mixed $user * * @return array|bool */ public static function getFileExtensions($category = null, $user = null) { $category = KunenaForumCategoryHelper::get($category); $user = KunenaUserHelper::get($user); $config = KunenaFactory::getConfig(); $types = explode(',', $config->filetypes); foreach ($types as &$type) { $type = trim($type); if (empty($type)) { unset($type); } } // Check if attachments are allowed at all if (!$config->file_upload) { return false; } if ($config->file_upload == 'everybody') { return $types; } // For now on we only allow registered users if (!$user->exists()) { return false; } if ($config->file_upload == 'registered') { return $types; } // For now on we only allow moderators if (!$user->isModerator($category)) { return false; } if ($config->file_upload == 'moderator') { return $types; } // For now on we only allow administrators if (!$user->isAdmin($category)) { return false; } if ($config->file_upload == 'admin') { return $types; } return false; }
/** * Prepare topic display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $catid = $this->input->getInt('catid', 0); $id = $this->input->getInt('id', 0); $mesid = $this->input->getInt('mesid', 0); $start = $this->input->getInt('limitstart', 0); $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = $this->config->messages_per_page; } $this->me = KunenaUserHelper::getMyself(); // Load topic and message. if ($mesid) { // If message was set, use it to find the current topic. $this->message = KunenaForumMessageHelper::get($mesid); $this->topic = $this->message->getTopic(); } else { // Note that redirect loops throw RuntimeException because of we added KunenaForumTopic::getTopic() call! $this->topic = KunenaForumTopicHelper::get($id)->getTopic(); $this->message = KunenaForumMessageHelper::get($this->topic->first_post_id); } // Load also category (prefer the URI variable if available). if ($catid && $catid != $this->topic->category_id) { $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); } else { $this->category = $this->topic->getCategory(); } // Access check. $this->message->tryAuthorise(); // Check if we need to redirect (category or topic mismatch, or resolve permanent URL). if ($this->primary) { $channels = $this->category->getChannels(); if ($this->message->thread != $this->topic->id || $this->topic->category_id != $this->category->id && !isset($channels[$this->topic->category_id]) || $mesid && $this->layout != 'threaded') { while (@ob_end_clean()) { } $this->app->redirect($this->message->getUrl(null, false)); } } // Load messages from the current page and set the pagination. $hold = KunenaAccess::getInstance()->getAllowedHold($this->me, $this->category->id, false); $finder = new KunenaForumMessageFinder(); $finder->where('thread', '=', $this->topic->id)->filterByHold($hold); $start = $mesid ? $this->topic->getPostLocation($mesid) : $start; $this->pagination = new KunenaPagination($finder->count(), $start, $limit); $this->messages = $finder->order('time', $this->me->getMessageOrdering() == 'asc' ? 1 : -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find(); $this->prepareMessages($mesid); // Run events. $params = new JRegistry(); $params->set('ksource', 'kunena'); $params->set('kunena_view', 'topic'); $params->set('kunena_layout', 'default'); $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0)); $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->messages, &$params, 0)); // Get user data, captcha & quick reply. $this->userTopic = $this->topic->getUserTopic(); $this->quickReply = $this->topic->isAuthorised('reply') && $this->me->exists(); $this->headerText = JText::_('COM_KUNENA_TOPIC') . ' ' . html_entity_decode($this->topic->displayField('subject')); }
function move() { if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->setRedirectBack(); return; } $ids = array_keys(JRequest::getVar('topics', array(), 'post', 'array')); // Array of integer keys JArrayHelper::toInteger($ids); $topics = KunenaForumTopicHelper::getTopics($ids); if (!$topics) { $message = JText::_('COM_KUNENA_NO_TOPICS_SELECTED'); } else { $target = KunenaForumCategoryHelper::get(JRequest::getInt('target', 0)); if (!$target->authorise('read')) { $this->app->enqueueMessage($target->getError(), 'error'); } else { foreach ($topics as $topic) { if ($topic->authorise('move') && $topic->move($target)) { $message = JText::_('COM_KUNENA_POST_SUCCESS_MOVE'); } else { $this->app->enqueueMessage($topic->getError(), 'notice'); } } } } if (!empty($message)) { $this->app->enqueueMessage($message); } $this->setRedirectBack(); }
<?php /** * Kunena Component * * @package Kunena.Template.Crypsis * @subpackage Layout.Widget * * @copyright (C) 2008 - 2016 Kunena Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @link https://www.kunena.org **/ defined('_JEXEC') or die; $markAllReadUrl = KunenaForumCategoryHelper::get()->getMarkReadUrl(); // FIXME: move announcements logic and pm logic into the template file... ?> <ul class="nav pull-right"> <li class="dropdown mobile-user"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <?php if ($this->me->status == 0) : ?> <i class="icon-large icon-user green"></i> <?php elseif ($this->me->status == 1) : ?> <i class="icon-large icon-user yellow"></i> <?php elseif ($this->me->status == 2) : ?> <i class="icon-large icon-user red "></i> <?php elseif ($this->me->status == 3) : ?> <i class="icon-large icon-user grey"></i> <?php endif; ?> <b class="caret"></b> </a>
/** * Build SEF URL * * All SEF URLs are formatted like this: * * http://site.com/menuitem/1-category-name/10-subject/[view]/[layout]/[param1]-value1/[param2]-value2?param3=value3¶m4=value4 * * - If catid exists, category will always be in the first segment * - If there is no catid, second segment for message will not be used (param-value: id-10) * - [view] and [layout] are the only parameters without value * - all other segments (task, id, userid, page, sel) are using param-value format * * NOTE! Only major variables are using SEF segments * * @param $query * @return array Segments */ function KunenaBuildRoute(&$query) { $segments = array(); // If Kunena Forum isn't installed or SEF is not enabled, do nothing if (!class_exists('KunenaForum') || !KunenaForum::isCompatible('3.0') || !KunenaForum::installed() || !KunenaRoute::$config->sef) { return $segments; } KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __FUNCTION__ . '()') : null; // Get menu item $menuitem = null; if (isset($query['Itemid'])) { static $menuitems = array(); $Itemid = $query['Itemid'] = (int) $query['Itemid']; if (!isset($menuitems[$Itemid])) { $menuitems[$Itemid] = JFactory::getApplication()->getMenu()->getItem($Itemid); if (!$menuitems[$Itemid]) { // Itemid doesn't exist or is invalid unset($query['Itemid']); } } $menuitem = $menuitems[$Itemid]; } // Safety check: we need view in order to create SEF URLs if (!isset($menuitem->query['view']) && empty($query['view'])) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __FUNCTION__ . '()') : null; return $segments; } // Get view for later use (query wins menu item) $view = isset($query['view']) ? (string) preg_replace('/[^a-z]/', '', $query['view']) : $menuitem->query['view']; // Get default values for URI variables if (isset(KunenaRoute::$views[$view])) { $defaults = KunenaRoute::$views[$view]; } // Check all URI variables and remove those which aren't needed foreach ($query as $var => $value) { if (isset($defaults[$var]) && !isset($menuitem->query[$var]) && $value == $defaults[$var]) { // Remove URI variable which has default value unset($query[$var]); } elseif (isset($menuitem->query[$var]) && $value == $menuitem->query[$var] && $var != 'Itemid' && $var != 'option') { // Remove URI variable which has the same value as menu item unset($query[$var]); } } // We may have catid also in the menu item (it will not be in URI) $numeric = !empty($menuitem->query['catid']); // Support URIs like: /forum/12-my_category if (!empty($query['catid']) && ($view == 'category' || $view == 'topic' || $view == 'home')) { // TODO: ensure that we have view=category/topic $catid = (int) $query['catid']; if ($catid) { $numeric = true; $alias = KunenaForumCategoryHelper::get($catid)->alias; // If category alias is empty, use category id; otherwise use alias $segments[] = empty($alias) ? $catid : $alias; // This segment fully defines category view so the variable is no longer needed if ($view == 'category') { unset($query['view']); } } unset($query['catid']); } // Support URIs like: /forum/12-category/123-topic if (!empty($query['id']) && $numeric) { $id = (int) $query['id']; if ($id) { $subject = KunenaRoute::stringURLSafe(KunenaForumTopicHelper::get($id)->subject); if (empty($subject)) { $segments[] = $id; } else { $segments[] = "{$id}-{$subject}"; } // This segment fully defines topic view so the variable is no longer needed if ($view == 'topic') { unset($query['view']); } } unset($query['id']); } else { // No id available, do not use numeric variable for mesid $numeric = false; } // View gets added only when we do not use short URI for category/topic if (!empty($query['view'])) { // Use filtered value $segments[] = $view; } // Support URIs like: /forum/12-category/123-topic/reply if (!empty($query['layout'])) { // Use filtered value $segments[] = (string) preg_replace('/[^a-z]/', '', $query['layout']); } // Support URIs like: /forum/12-category/123-topic/reply/124 if (isset($query['mesid']) && $numeric) { $segments[] = (int) $query['mesid']; unset($query['mesid']); } // Support URIs like: /forum/user/128-matias if (isset($query['userid']) && $view == 'user') { $segments[] = (int) $query['userid'] . '-' . KunenaRoute::stringURLSafe(KunenaUserHelper::get((int) $query['userid'])->getName()); unset($query['userid']); } unset($query['view'], $query['layout']); // Rest of the known parameters are in var-value form foreach (KunenaRoute::$parsevars as $var => $dummy) { if (isset($query[$var])) { $segments[] = "{$var}-{$query[$var]}"; unset($query[$var]); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __FUNCTION__ . '()') : null; return $segments; }
public function getAdminCategory() { $category = KunenaForumCategoryHelper::get($this->getState('item.id')); if (!$this->me->isAdmin($category)) { return false; } if ($this->_admincategory === false) { if ($category->exists()) { if (!$category->isCheckedOut($this->me->userid)) { $category->checkout($this->me->userid); } } else { // New category is by default child of the first section -- this will help new users to do it right $db = JFactory::getDBO(); $db->setQuery("SELECT a.id, a.name FROM #__kunena_categories AS a WHERE parent_id='0' AND id!='{$category->id}' ORDER BY ordering"); $sections = $db->loadObjectList(); KunenaError::checkDatabaseError(); $category->parent_id = $this->getState('item.parent_id'); $category->published = 0; $category->ordering = 9999; $category->pub_recurse = 1; $category->admin_recurse = 1; $category->accesstype = 'joomla.level'; $category->access = 1; $category->pub_access = 1; $category->admin_access = 8; } $this->_admincategory = $category; } return $this->_admincategory; }
/** * @param int $catid * @param bool $type * * @return stdClass|string */ public function getRank($catid = 0, $type = false) { // Default rank $rank = new stdClass(); $rank->rank_id = false; $rank->rank_title = null; $rank->rank_min = 0; $rank->rank_special = 0; $rank->rank_image = null; $config = KunenaFactory::getConfig(); $category = KunenaForumCategoryHelper::get($catid); if (!$config->showranking) { return; } if (self::$_ranks === null) { $this->_db->setQuery("SELECT * FROM #__kunena_ranks"); self::$_ranks = $this->_db->loadObjectList('rank_id'); KunenaError::checkDatabaseError(); } $rank->rank_title = JText::_('COM_KUNENA_RANK_USER'); $rank->rank_image = 'rank0.gif'; if ($this->userid == 0) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_VISITOR'); $rank->rank_special = 1; } else { if ($this->isBanned()) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_BANNED'); $rank->rank_special = 1; $rank->rank_image = 'rankbanned.gif'; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankbanned') { $rank = $cur; break; } } } else { if ($this->rank != 0 && isset(self::$_ranks[$this->rank])) { $rank = self::$_ranks[$this->rank]; } else { if ($this->rank == 0 && $this->isAdmin($category)) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_ADMINISTRATOR'); $rank->rank_special = 1; $rank->rank_image = 'rankadmin.gif'; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankadmin') { $rank = $cur; break; } } } else { if ($this->rank == 0 && $this->isModerator($category)) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_MODERATOR'); $rank->rank_special = 1; $rank->rank_image = 'rankmod.gif'; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankmod') { $rank = $cur; break; } } } } } } } if ($rank->rank_id === false) { //post count rank $rank->rank_id = 0; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 0 && $cur->rank_min <= $this->posts && $cur->rank_min >= $rank->rank_min) { $rank = $cur; } } } if ($type == 'title') { return $rank->rank_title; } if ($type == 'image') { $template = KunenaTemplate::getInstance(); if (!$config->rankimages) { return; } $iconurl = $template->getRankPath($rank->rank_image, true); return '<img src="' . $iconurl . '" alt="" />'; } if (!$config->rankimages) { $rank->rank_image = null; } return $rank; }
/** * @return KunenaForumCategory */ public function getParent() { $parent = KunenaForumCategoryHelper::get(intval($this->parent_id)); if (!$parent->exists()) { $parent->name = JText::_('COM_KUNENA_TOPLEVEL'); $parent->_exists = true; } return $parent; }
/** * @return KunenaForumCategory */ public function getCategory() { return KunenaForumCategoryHelper::get($this->category_id); }
protected static function checkCategory($item, JUri $uri) { static $cache = array(); $catid = (int) $uri->getVar('catid'); $check = self::check($item, $uri); if (!$check || !$catid) { return $check; } if (!isset($cache[$item->id])) { $cache[$item->id] = array(); if (!empty($item->query['catid'])) { $cache[$item->id] = KunenaForumCategoryHelper::getChildren($item->query['catid']); $cache[$item->id][$item->query['catid']] = KunenaForumCategoryHelper::get($item->query['catid']); } } return intval(isset($cache[$item->id][$catid])) * 8; }
protected function buildInfo() { if ($this->_topics !== false) return; $this->_topics = 0; $this->_posts = 0; $this->_lastid = 0; $categories = $this->getChannels(); $categories += KunenaForumCategoryHelper::getChildren($this->id); foreach ($categories as $category) { $category->buildInfo(); $this->_topics += $category->numTopics; $this->_posts += $category->numPosts; if (KunenaForumCategoryHelper::get($this->_lastid)->last_post_time < $category->last_post_time) $this->_lastid = $category->id; } }
function move() { $app = JFactory::getApplication (); if (! JRequest::checkToken ()) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' ); $this->redirectBack (); } $topics = KunenaForumTopicHelper::getTopics(array_keys(JRequest::getVar('topics', array ( 0 ), 'post', 'array'))); if (!$topics) { $message = JText::_ ( 'COM_KUNENA_NO_TOPICS_SELECTED' ); } else { $target = KunenaForumCategoryHelper::get(JRequest::getInt('target', 0)); if (!$target->authorise('read')) { $app->enqueueMessage ( $target->getError(), 'error' ); } else { foreach ( $topics as $topic ) { if ($topic->authorise('move') && $topic->move($target)) { $message = JText::_ ( 'COM_KUNENA_POST_SUCCESS_MOVE' ); } else { $app->enqueueMessage ( $topic->getError (), 'notice' ); } } } } if (!empty($message)) $app->enqueueMessage ( $message ); $this->redirectBack (); }
function displayFooter($tpl = null) { require_once KPATH_SITE . '/lib/kunena.link.class.php'; $catid = 0; if (KunenaFactory::getConfig ()->enablerss) { if ($catid > 0) { kimport ( 'kunena.forum.category.helper' ); $category = KunenaForumCategoryHelper::get ( $catid ); if ($category->pub_access == 0 && $category->parent) $rss_params = '&catid=' . ( int ) $catid; } else { $rss_params = ''; } if (isset ( $rss_params )) { $document = JFactory::getDocument (); $document->addCustomTag ( '<link rel="alternate" type="application/rss+xml" title="' . JText::_ ( 'COM_KUNENA_LISTCAT_RSS' ) . '" href="' . CKunenaLink::GetRSSURL ( $rss_params ) . '" />' ); $this->assign ( 'rss', CKunenaLink::GetRSSLink ( $this->getIcon ( 'krss', JText::_('COM_KUNENA_LISTCAT_RSS') ), 'follow', $rss_params )); } } $template = KunenaFactory::getTemplate (); $credits = CKunenaLink::GetTeamCreditsLink ( $catid, JText::_('COM_KUNENA_POWEREDBY') ) . ' ' . CKunenaLink::GetCreditsLink (); if ($template->params->get('templatebyText') !='') { $credits .= ' :: <a href ="'. $template->params->get('templatebyLink').'" rel="follow">' . $template->params->get('templatebyText') .' '. $template->params->get('templatebyName') .'</a>'; } $this->assign ( 'credits', $credits ); $result = $this->loadTemplate($tpl); if (JError::isError($result)) { return $result; } echo $result; }
function fillCategoryInfo($matches) { switch ($matches[1]) { case 'ROW': return $this->rowno & 1 ? 'odd' : 'even'; case 'CATEGORY_ICON': return $this->getCategoryIcon($this->category); case 'CATEGORY_NEW_SUFFIX': $new = empty($matches[2]) ? $this->category->getNewCount() : KunenaForumCategoryHelper::get($matches[2])->getNewCount(); return $new ? '-new' : ''; case 'CATEGORY_NEW_COUNT': $new = empty($matches[2]) ? $this->category->getNewCount() : KunenaForumCategoryHelper::get($matches[2])->getNewCount(); return $new ? '<sup class="knewchar">(' . $new . ' ' . JText::_('COM_KUNENA_A_GEN_NEWCHAR') . ")</sup>" : ''; case 'DATE': $date = new KunenaDate($matches[2]); return $date->toSpan('config_post_dateformat', 'config_post_dateformat_hover'); } }