/** * @see KunenaControllerBase::execute() */ public function execute() { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . get_class($this) . '::' . __FUNCTION__ . '()') : null; try { // Run before executing action. $result = $this->before(); if ($result === false) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . get_class($this) . '::' . __FUNCTION__ . '()') : null; return KunenaLayout::factory('Empty')->setOptions($this->getOptions()); } // Display layout with given parameters. $this->output = $this->display(); // Run after executing action. $this->after(); } catch (KunenaExceptionAuthorise $e) { if ($this->primary) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . get_class($this) . '::' . __FUNCTION__ . '()') : null; throw $e; } else { $this->output = KunenaLayout::factory('Empty')->setOptions($this->getOptions()); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . get_class($this) . '::' . __FUNCTION__ . '()') : null; return $this->output; }
public function toTimeAgo() { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $chunks = array('y' => array(JText::_('COM_KUNENA_DATE_YEAR'), JText::_('COM_KUNENA_DATE_YEARS')), 'm' => array(JText::_('COM_KUNENA_DATE_MONTH'), JText::_('COM_KUNENA_DATE_MONTHS')), 'w' => array(JText::_('COM_KUNENA_DATE_WEEK'), JText::_('COM_KUNENA_DATE_WEEKS')), 'd' => array(JText::_('COM_KUNENA_DATE_DAY'), JText::_('COM_KUNENA_DATE_DAYS')), 'h' => array(JText::_('COM_KUNENA_DATE_HOUR'), JText::_('COM_KUNENA_DATE_HOURS')), 'i' => array(JText::_('COM_KUNENA_DATE_MINUTE'), JText::_('COM_KUNENA_DATE_MINUTES'))); // we only want to output two chunks of time here, eg: "x years, xx months" or "x days, xx hours" $tick = 0; $output = ''; $diff = $this->diff(new JDate()); foreach ($diff as $name => $count) { if ($name == 'd') { // Days are special case as we want to break it into weeks and days. $weeks = (int) ($count / 7); if ($weeks) { $count %= 7; $output .= $weeks == 1 ? " 1 {$chunks['w'][0]}" : " {$weeks} {$chunks['w'][1]}"; if (2 == ++$tick) { break; } } } if (!$count || !isset($chunks[$name])) { continue; } $output .= $count == 1 ? " 1 {$chunks[$name][0]}" : " {$count} {$chunks[$name][1]}"; if (2 == ++$tick) { break; } } if (!$output) { $output .= '0 ' . JText::_('COM_KUNENA_DATE_MINUTES'); } $output = JText::sprintf('COM_KUNENA_LIB_TIME_AGO', trim($output)); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $output; }
/** * Returns the global KunenaUserHelper object, only creating it if it doesn't already exist. * * @access public * @param int $id The user to load - Can be an integer or string - If string, it is converted to ID automatically. * @return JUser The User object. * @since 1.6 */ public static function get($identifier = null, $reload = false) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if ($identifier === null || $identifier === false) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return self::$_me; } if ($identifier instanceof KunenaUser) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $identifier; } // Find the user id if ($identifier instanceof JUser) { $id = intval($identifier->id); } else { if (is_numeric($identifier)) { $id = intval($identifier); } else { jimport('joomla.user.helper'); $id = intval(JUserHelper::getUserId((string) $identifier)); } } // Always return fresh user if id is anonymous/not found if ($id === 0) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return new KunenaUser($id); } else { if ($reload || empty(self::$_instances[$id])) { self::$_instances[$id] = new KunenaUser($id); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return self::$_instances[$id]; }
static public function initialize($name, $integration) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__."($name,$integration)") : null; $object = self::_initialize($name, $integration); if (!$object) $object = self::_initialize($name, 'auto'); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__."($name,$integration)") : null; return $object; }
public function __construct($config = array()) { $name = isset($config['name']) ? $config['name'] : $this->getName(); $this->document = JFactory::getDocument(); $this->document->setBase(''); $this->profiler = KunenaProfiler::instance('Kunena'); $this->app = JFactory::getApplication(); $this->me = KunenaUserHelper::getMyself(); $this->config = KunenaFactory::getConfig(); $this->ktemplate = KunenaFactory::getTemplate(); // Set the default template search path if ($this->app->isSite() && !isset($config['template_path'])) { $config['template_path'] = $this->ktemplate->getTemplatePaths("html/{$name}", true); } if ($this->app->isAdmin()) { $templateAdmin = KunenaFactory::getAdminTemplate(); $templateAdmin->initialize(); $config['template_path'] = $templateAdmin->getTemplatePaths($name); } parent::__construct($config); if ($this->app->isSite()) { // Add another template file lookup path specific to the current template $fallback = JPATH_THEMES . "/{$this->app->getTemplate()}/html/com_kunena/{$this->ktemplate->name}/{$this->getName()}"; $this->addTemplatePath($fallback); } // Use our own browser side cache settings. JResponse::allowCache(false); JResponse::setHeader('Expires', 'Mon, 1 Jan 2001 00:00:00 GMT', true); JResponse::setHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT', true); JResponse::setHeader('Cache-Control', 'no-store, must-revalidate, post-check=0, pre-check=0', true); }
function __construct($config = array()){ parent::__construct($config); $this->profiler = KunenaProfiler::instance('Kunena'); $this->me = KunenaUserHelper::getMyself(); $this->config = KunenaFactory::getConfig(); $this->template = KunenaFactory::getTemplate(); }
public function getURL($user, $sizex=90, $sizey=90) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; $size = $this->getSize($sizex, $sizey); if (!$size->x || !$size->y) return; $result = $this->_getURL($user, $size->x, $size->y); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $result; }
public function load($userlist) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if (class_exists('CFactory') && method_exists('CFactory', 'loadUsers')) { CFactory::loadUsers($userlist); } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; }
/** * Method to get the time of page generation * * @return string */ protected function getTime() { $config = KunenaFactory::getConfig(); if (!$config->time_to_create_page) { return null; } $profiler = KunenaProfiler::instance('Kunena'); $time = $profiler->getTime('Total Time'); return sprintf('%0.3f', $time); }
public static function parseBBCode($txt, $parent = null, $len = 0) { if (!$txt) { return; } KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $bbcode = KunenaBbcode::getInstance(self::$relative); $bbcode->parent = $parent; $bbcode->SetLimit($len); $bbcode->SetPlainMode(false); $txt = $bbcode->Parse($txt); $txt = self::prepareContent($txt); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $txt; }
public function __construct($config = array()) { $name = isset($config['name']) ? $config['name'] : $this->getName(); $this->document = JFactory::getDocument(); $this->profiler = KunenaProfiler::instance('Kunena'); $this->app = JFactory::getApplication(); $this->me = KunenaUserHelper::getMyself(); $this->config = KunenaFactory::getConfig(); $this->ktemplate = KunenaFactory::getTemplate(); // Set the default template search path if ($this->app->isSite() && !isset($config['template_path'])) { $config['template_path'] = $this->ktemplate->getTemplatePaths("html/{$name}", true); } parent::__construct($config); if ($this->app->isSite()) { // Add another template file lookup path specific to the current template $fallback = JPATH_THEMES . "/{$this->app->getTemplate()}/html/com_kunena/{$this->ktemplate->name}/{$this->getName()}"; $this->addTemplatePath($fallback); } }
// Display offline message if Kunena hasn't been fully installed. if (!class_exists('KunenaForum') || !KunenaForum::isCompatible('4.0') || !KunenaForum::installed()) { $lang = JFactory::getLanguage(); $lang->load('com_kunena.install', JPATH_ADMINISTRATOR . '/components/com_kunena', 'en-GB'); $lang->load('com_kunena.install', JPATH_ADMINISTRATOR . '/components/com_kunena'); JResponse::setHeader('Status', '503 Service Temporarily Unavailable', true); ?> <h2><?php echo JText::_('COM_KUNENA_INSTALL_OFFLINE_TOPIC') ?></h2> <div><?php echo JText::_('COM_KUNENA_INSTALL_OFFLINE_DESC') ?></div> <?php return; } // Display time it took to create the entire page in the footer. $kunena_profiler = KunenaProfiler::instance('Kunena'); $kunena_profiler->start('Total Time'); KUNENA_PROFILER ? $kunena_profiler->mark('afterLoad') : null; // Prevent direct access to the component if the option has been disabled. if (!KunenaConfig::getInstance()->get('access_component', 1)) { $active = JFactory::getApplication()->getMenu()->getActive(); if (!$active) { // Prevent access without using a menu item. JLog::add("Kunena: Direct access denied: " . JUri::getInstance()->toString(array('path', 'query')), JLog::WARNING, 'kunena'); JError::raiseError(404, JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND')); } elseif ($active->type != 'component' || $active->component != 'com_kunena')
/** * @param mixed $categories * @param int $limitstart * @param int $limit * @param array $params * * @return array|KunenaForumTopic[] */ public static function getLatestTopics($categories = false, $limitstart = 0, $limit = 0, $params = array()) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $db = JFactory::getDBO(); $config = KunenaFactory::getConfig(); if ($limit < 1 && empty($params['nolimit'])) { $limit = $config->threads_per_page; } $reverse = isset($params['reverse']) ? (int) $params['reverse'] : 0; $orderby = isset($params['orderby']) ? (string) $params['orderby'] : 'tt.last_post_time DESC'; $starttime = isset($params['starttime']) ? (int) $params['starttime'] : 0; $user = isset($params['user']) ? KunenaUserHelper::get($params['user']) : KunenaUserHelper::getMyself(); $hold = isset($params['hold']) ? (string) $params['hold'] : 0; $moved = isset($params['moved']) ? (string) $params['moved'] : 0; $where = isset($params['where']) ? (string) $params['where'] : ''; if (strstr('ut.last_', $orderby)) { $post_time_field = 'ut.last_post_time'; } elseif (strstr('tt.first_', $orderby)) { $post_time_field = 'tt.first_post_time'; } else { $post_time_field = 'tt.last_post_time'; } $categories = KunenaForumCategoryHelper::getCategories($categories, $reverse); $catlist = array(); foreach ($categories as $category) { $catlist += $category->getChannels(); } if (empty($catlist)) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array(0, array()); } $catlist = implode(',', array_keys($catlist)); $whereuser = array(); if (!empty($params['started'])) { $whereuser[] = 'ut.owner=1'; } if (!empty($params['replied'])) { $whereuser[] = '(ut.owner=0 AND ut.posts>0)'; } if (!empty($params['posted'])) { $whereuser[] = 'ut.posts>0'; } if (!empty($params['favorited'])) { $whereuser[] = 'ut.favorite=1'; } if (!empty($params['subscribed'])) { $whereuser[] = 'ut.subscribed=1'; } if ($config->keywords || $config->userkeywords) { $kwids = array(); if (!empty($params['keywords'])) { $keywords = KunenaKeywordHelper::getByKeywords($params['keywords']); foreach ($keywords as $keyword) { $kwids[] = $keyword->id; } $kwids = implode(',', $kwids); } //TODO: add support for keywords (example:) /* SELECT tt.*, COUNT(*) AS score FROM #__kunena_keywords_map AS km INNER JOIN #__kunena_topics` AS tt ON km.topic_id=tt.id WHERE km.keyword_id IN (1,2) AND km.user_id IN (0,62) GROUP BY topic_id ORDER BY score DESC, tt.last_post_time DESC */ } $wheretime = $starttime ? " AND {$post_time_field}>{$db->Quote($starttime)}" : ''; $whereuser = $whereuser ? " AND ut.user_id={$db->Quote($user->userid)} AND (" . implode(' OR ', $whereuser) . ')' : ''; $where = "tt.hold IN ({$hold}) AND tt.category_id IN ({$catlist}) {$whereuser} {$wheretime} {$where}"; if (!$moved) { $where .= " AND tt.moved_id='0'"; } // Get total count if ($whereuser) { $query = "SELECT COUNT(*) FROM #__kunena_user_topics AS ut INNER JOIN #__kunena_topics AS tt ON tt.id=ut.topic_id WHERE {$where}"; } else { $query = "SELECT COUNT(*) FROM #__kunena_topics AS tt WHERE {$where}"; } $db->setQuery($query); $total = (int) $db->loadResult(); if (KunenaError::checkDatabaseError() || !$total) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array(0, array()); } // If out of range, use last page if ($limit && $total < $limitstart) { $limitstart = intval($total / $limit) * $limit; } // Get items if ($whereuser) { $query = "SELECT tt.*, ut.posts AS myposts, ut.last_post_id AS my_last_post_id, ut.favorite, tt.last_post_id AS lastread, 0 AS unread\r\n\t\t\t\tFROM #__kunena_user_topics AS ut\r\n\t\t\t\tINNER JOIN #__kunena_topics AS tt ON tt.id=ut.topic_id\r\n\t\t\t\tWHERE {$where} ORDER BY {$orderby}"; } else { $query = "SELECT tt.*, ut.posts AS myposts, ut.last_post_id AS my_last_post_id, ut.favorite, tt.last_post_id AS lastread, 0 AS unread\r\n\t\t\t\tFROM #__kunena_topics AS tt\r\n\t\t\t\tLEFT JOIN #__kunena_user_topics AS ut ON tt.id=ut.topic_id AND ut.user_id={$db->Quote($user->userid)}\r\n\t\t\t\tWHERE {$where} ORDER BY {$orderby}"; } $db->setQuery($query, $limitstart, $limit); $results = (array) $db->loadAssocList('id'); if (KunenaError::checkDatabaseError()) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array(0, array()); } $topics = array(); foreach ($results as $id => $result) { $instance = new KunenaForumTopic($result); $instance->exists(true); self::$_instances[$id] = $instance; $topics[$id] = $instance; } unset($results); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array($total, $topics); }
protected static function setItemID($uri) { static $candidates = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; $view = $uri->getVar('view'); $catid = (int) $uri->getVar('catid'); $key = $view.$catid; if (!isset($candidates[$key])) { if (self::$search === false) self::build(); $search = array(); if (self::$home) { // Search from the current home menu $search[self::$home->id] = 1; // Then search from all linked home menus $search += self::$search['home'][self::$home->id]; } // Finally search from other home menus $search += self::$search['home']; // Find all potential candidates $candidates[$key] = array(); foreach ($search as $id=>$dummy) { $follow = !empty(self::$menu[$id]) ? self::$menu[$id] : null; if ($follow && self::checkHome($follow, $catid)) { $candidates[$key] += !empty(self::$search[$view][$follow->id]) ? self::$search[$view][$follow->id] : array(); if ($view == 'topic') $candidates[$key] += !empty(self::$search['category'][$follow->id]) ? self::$search['category'][$follow->id] : array(); $candidates[$key][$follow->id] = $follow->id; } } // Don't forget lonely candidates $candidates[$key] += !empty(self::$search[$view][0]) ? self::$search[$view][0] : array(); if ($view == 'topic') $candidates[$key] += !empty(self::$search['category'][0]) ? self::$search['category'][0] : array(); } $bestid = $bestcount = 0; //echo "$key "; print_r($candidates[$key]); foreach ($candidates[$key] as $id) { $item = self::$menu[$id]; switch ($item->query['view']) { case 'home': $matchcount = 1; break; case 'category': case 'topic': $matchcount = self::checkCategory($item, $uri); break; default: $matchcount = self::check($item, $uri); } if ($matchcount > $bestcount) { // This is our best candidate this far $bestid = $item->id; $bestcount = $matchcount; } } $uri->setVar('Itemid', $bestid); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $bestid; }
/** * 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 getAllowedCategories($user = null, $rule = 'read') { static $read = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; $user = KunenaFactory::getUser($user); $id = $user->userid; $allowed = array(); switch ($rule) { case 'read': case 'post': case 'reply': case 'edit': if (!isset($read[$id])) { $app = JFactory::getApplication(); // TODO: handle guests/bots with no userstate $read[$id] = $app->getUserState("com_kunena.user{$id}_read"); if ($read[$id] === null) { $read[$id] = array(); $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); foreach ( $categories as $category ) { if (!$category->published) { unset($categories[$category->id]); } if ($id && self::isModerator($id, $category->id)) { $read[$id][$category->id] = $category->id; unset($categories[$category->id]); } } $read[$id] += self::$instance->loadAllowedCategories($id, $categories); $app->setUserState("com_kunena.user{$id}_read", $read[$id]); } } $allowed = $read[$id]; break; case 'moderate': if (isset(self::$moderatorsByUserid[$id])) $allowed += self::$moderatorsByUserid[$id]; // Continue: Administrators have also moderation permissions case 'admin': if (isset(self::$adminsByUserid[$id])) $allowed += self::$adminsByUserid[$id]; } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $allowed; }
/** * @param string $action * @param mixed $user * @param bool $silent * * @return bool * @deprecated K4.0 */ public function authorise($action = 'read', $user = null, $silent = false) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if ($user === null) { $user = KunenaUserHelper::getMyself(); } elseif (!$user instanceof KunenaUser) { $user = KunenaUserHelper::get($user); } $exception = $this->tryAuthorise($action, $user, false); if ($silent === false && $exception) { $this->setError($exception->getMessage()); } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if ($silent !== null) { return !$exception; } return $exception ? $exception->getMessage() : null; }
function stringURLSafe($str) { static $filtered = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; if (!isset($filtered[$str])) { if (self::$config->sefutf8) { $str = self::filterOutput ( $str ); $filtered[$str] = urlencode ( $str ); } else { $filtered[$str] = JFilterOutput::stringURLSafe ( $str ); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $filtered[$str]; }
/** * @param mixed $user * * @return mixed */ public function getAllowedCategories($user = null) { static $read = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if (!$user instanceof KunenaUser) { $user = KunenaFactory::getUser($user); } if (!isset($read[$user->userid])) { $id = $user->userid; $app = JFactory::getApplication(); // TODO: handle guests/bots with no userstate $read[$id] = $app->getUserState("com_kunena.user{$id}_read"); if ($read[$id] === null) { $list = array(); $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); foreach ($categories as $category) { // Remove unpublished categories if ($category->published != 1) { unset($categories[$category->id]); } // Moderators have always access if (self::isModerator($user, $category->id)) { $list[$category->id] = $category->id; unset($categories[$category->id]); } } // Get external authorization if (!empty($categories)) { // @var KunenaAccess $access foreach ($this->accesstypes['all'] as $access) { if (method_exists($access, 'authoriseCategories')) { $list += $access->authoriseCategories($id, $categories); } } } // Clean up and filter the resulting list by using only array keys. $list = array_keys($list); Joomla\Utilities\ArrayHelper::toInteger($list); $read[$id] = array_combine($list, $list); unset($read[$id][0]); $app->setUserState("com_kunena.user{$id}_read", $read[$id]); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $read[$user->userid]; }
public static function convert($uri, $showstart = 1) { // Make sure that input is JUri to legacy Kunena func=xxx if (!$uri instanceof JUri) { return; } if ($uri->getVar('option') != 'com_kunena') { return; } KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if ($uri->getVar('func')) { $uri->setVar('view', $uri->getVar('func')); $uri->delVar('func'); } if (!isset(self::$functions[$uri->getVar('view')])) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return; } $legacy = clone $uri; // Turn &do=xxx into &layout=xxx if ($uri->getVar('do')) { $uri->setVar('layout', $uri->getVar('do')); $uri->delVar('do'); } $app = JFactory::getApplication(); $config = KunenaFactory::getConfig(); $changed = false; switch ($uri->getVar('view')) { case 'entrypage': $changed = true; $uri->setVar('view', 'home'); break; case 'listcat': $changed = true; $uri->setVar('view', 'category'); $uri->setVar('layout', 'list'); break; case 'showcat': $changed = true; $uri->setVar('view', 'category'); $page = (int) $uri->getVar('page', $showstart); if ($page > 0) { $uri->setVar('limitstart', (int) $config->messages_per_page * ($page - 1)); $uri->setVar('limit', (int) $config->messages_per_page); } $uri->delVar('page'); break; case 'latest': case 'mylatest': case 'noreplies': case 'subscriptions': case 'favorites': case 'userposts': case 'unapproved': case 'deleted': $changed = true; $uri->setVar('view', 'topics'); // Handle both &func=noreplies and &func=latest&do=noreplies $mode = $uri->getVar('layout') ? $uri->getVar('layout') : $uri->getVar('view'); switch ($mode) { case 'latest': $uri->setVar('layout', 'default'); $uri->setVar('mode', 'replies'); break; case 'unapproved': $uri->setVar('layout', 'default'); $uri->setVar('mode', 'unapproved'); break; case 'deleted': $uri->setVar('layout', 'default'); $uri->setVar('mode', 'deleted'); break; case 'noreplies': $uri->setVar('layout', 'default'); $uri->setVar('mode', 'noreplies'); break; case 'latesttopics': $uri->setVar('layout', 'default'); $uri->setVar('mode', 'topics'); break; case 'mylatest': $uri->setVar('layout', 'user'); $uri->setVar('mode', 'default'); break; case 'subscriptions': $uri->setVar('layout', 'user'); $uri->setVar('mode', 'subscriptions'); break; case 'favorites': $uri->setVar('layout', 'user'); $uri->setVar('mode', 'favorites'); break; case 'owntopics': $uri->setVar('layout', 'user'); $uri->setVar('mode', 'started'); break; case 'userposts': $uri->setVar('userid', '0'); // Continue in latestposts // Continue in latestposts case 'latestposts': $uri->setVar('layout', 'posts'); $uri->setVar('mode', 'recent'); break; case 'saidthankyouposts': $uri->setVar('layout', 'posts'); $uri->setVar('mode', 'mythanks'); break; case 'gotthankyouposts': $uri->setVar('layout', 'posts'); $uri->setVar('mode', 'thankyou'); break; case 'catsubscriptions': $uri->setVar('view', 'category'); $uri->setVar('layout', 'user'); break; default: $uri->setVar('layout', 'default'); $uri->setVar('mode', 'replies'); } $page = (int) $uri->getVar('page', $showstart); if ($page > 0) { $uri->setVar('limitstart', (int) $config->threads_per_page * ($page - 1)); $uri->setVar('limit', (int) $config->threads_per_page); } $uri->delVar('page'); break; case 'view': $changed = true; $uri->setVar('view', 'topic'); // Convert URI to have both id and mesid $id = $uri->getVar('id'); $message = KunenaForumMessageHelper::get($id); $mesid = $uri->getVar('mesid'); if ($message->exists()) { $id = $message->thread; if ($id != $message->id) { $mesid = $message->id; } } if ($id) { $uri->setVar('id', $id); } if ($mesid) { $uri->setVar('mesid', $mesid); } break; case 'moderateuser': if ($uri->getVar('view') == 'moderateuser') { $uri->setVar('layout', 'moderate'); } // Continue to user profile // Continue to user profile case 'myprofile': case 'userprofile': case 'fbprofile': case 'profile': $changed = true; $uri->setVar('view', 'user'); if ($uri->getVar('task')) { $app->enqueueMessage(JText::_('COM_KUNENA_DEPRECATED_ACTION'), 'error'); $uri->delVar('task'); } // Handle &do=xxx switch ($uri->getVar('layout')) { case 'edit': $uri->setVar('layout', 'edit'); break; case 'moderate': $uri->setVar('layout', 'moderate'); break; default: $uri->delVar('layout'); break; } break; case 'report': $changed = true; $uri->setVar('view', 'topic'); $uri->setVar('layout', 'report'); // Convert URI to have both id and mesid $id = $uri->getVar('id'); $message = KunenaForumMessageHelper::get($id); $mesid = null; if ($message->exists()) { $id = $message->thread; if ($id != $message->id) { $mesid = $message->id; } } if ($id) { $uri->setVar('id', $id); } if ($mesid) { $uri->setVar('mesid', $mesid); } break; case 'userlist': $changed = true; $uri->setVar('view', 'user'); $uri->setVar('layout', 'list'); break; case 'rss': $changed = true; $uri->setVar('view', 'topics'); $mode = $config->rss_type; switch ($mode) { case 'topic': $uri->setVar('layout', 'default'); $uri->setVar('mode', 'topics'); break; case 'recent': $uri->setVar('layout', 'default'); $uri->setVar('mode', 'replies'); break; case 'post': default: $uri->setVar('layout', 'posts'); $uri->setVar('mode', 'latest'); break; } switch ($config->rss_timelimit) { case 'week': $uri->setVar('sel', 168); break; case 'year': $uri->setVar('sel', 8760); break; case 'month': default: $uri->setVar('sel', 720); break; } $uri->setVar('type', 'rss'); $uri->setVar('format', 'feed'); break; case 'post': $changed = true; $uri->setVar('view', 'topic'); // Support old &parentid=123 and &replyto=123 variables $id = $uri->getVar('id'); if (!$id) { $id = $uri->getVar('parentid'); $uri->delVar('parentid'); } if (!$id) { $id = $uri->getVar('replyto'); $uri->delVar('replyto'); } // Convert URI to have both id and mesid $message = KunenaForumMessageHelper::get($id); $mesid = null; if ($message->exists()) { $id = $message->thread; if ($id != $message->id) { $mesid = $message->id; } } if ($id) { $uri->setVar('id', $id); } if ($mesid) { $uri->setVar('mesid', $mesid); } if ($uri->getVar('action')) { $app->enqueueMessage(JText::_('COM_KUNENA_DEPRECATED_ACTION'), 'error'); $uri->delVar('action'); } else { // Handle &do=xxx $layout = $uri->getVar('layout'); $uri->delVar('layout'); switch ($layout) { // Create, reply, quote and edit: case 'new': $uri->setVar('layout', 'create'); $uri->delVar('id'); $uri->delVar('mesid'); break; case 'quote': $uri->setVar('layout', 'reply'); $uri->setVar('quote', 1); break; case 'reply': $uri->setVar('layout', 'reply'); break; case 'edit': $uri->setVar('layout', 'edit'); // Always add &mesid=x if (!$mesid) { $uri->setVar('mesid', $id); } break; // Topic moderation: // Topic moderation: case 'moderatethread': $uri->setVar('layout', 'moderate'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'deletethread': $uri->setVar('task', 'delete'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'sticky': $uri->setVar('task', 'sticky'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'unsticky': $uri->setVar('task', 'unsticky'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'lock': $uri->setVar('task', 'lock'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'unlock': $uri->setVar('task', 'unlock'); // Always remove &mesid=x $uri->delVar('mesid'); break; // Message moderator actions: // Message moderator actions: case 'moderate': $uri->setVar('layout', 'moderate'); // Always add &mesid=x if (!$mesid) { $uri->setVar('mesid', $id); } break; case 'approve': $uri->setVar('task', 'approve'); // Always add &mesid=x if (!$mesid) { $uri->setVar('mesid', $id); } break; case 'delete': $uri->setVar('task', 'delete'); // Always add &mesid=x if (!$mesid) { $uri->setVar('mesid', $id); } break; case 'undelete': $uri->setVar('task', 'undelete'); // Always add &mesid=x if (!$mesid) { $uri->setVar('mesid', $id); } break; case 'permdelete': $uri->setVar('task', 'permdelete'); // Always add &mesid=x if (!$mesid) { $uri->setVar('mesid', $id); } break; // Topic user actions: // Topic user actions: case 'subscribe': $uri->setVar('task', 'subscribe'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'unsubscribe': $uri->setVar('task', 'unsubscribe'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'favorite': $uri->setVar('task', 'favorite'); // Always remove &mesid=x $uri->delVar('mesid'); break; case 'unfavorite': $uri->setVar('task', 'unfavorite'); // Always remove &mesid=x $uri->delVar('mesid'); break; default: $app->enqueueMessage(JText::_('COM_KUNENA_DEPRECATED_ACTION'), 'error'); } } break; case 'stats': $changed = true; $uri->setVar('view', 'statistics'); break; case 'search': case 'advsearch': $changed = true; $uri->setVar('view', 'search'); break; case 'poll': $changed = true; $uri->setVar('view', 'topic'); // Handle &do=xxx switch ($uri->getVar('layout')) { case 'changevote': $uri->setVar('layout', 'vote'); break; } break; case 'review': $changed = true; $uri->setVar('view', 'topics'); $uri->setVar('layout', 'posts'); $uri->setVar('mode', 'unapproved'); $uri->setVar('userid', 0); $uri->delVar('action'); break; case 'announcement': switch ($uri->getVar('layout')) { case 'read': $changed = true; $uri->delVar('layout'); break; case 'show': $changed = true; $uri->setVar('layout', 'list'); break; case 'add': $changed = true; $uri->setVar('layout', 'create'); break; case 'edit': $changed = false; break; case 'doedit': $changed = true; $uri->delVar('layout'); $uri->setVar('task', 'edit'); break; case 'delete': $changed = true; $uri->delVar('layout'); $uri->setVar('task', 'delete'); break; } break; case 'thankyou': // Convert URI to have both id and mesid $id = $uri->getVar('pid'); if ($id) { $changed = true; $uri->setVar('view', 'topic'); $uri->setVar('task', 'thankyou'); $uri->delVar('pid'); $message = KunenaForumMessageHelper::get($id); if ($message->exists()) { $id = $message->thread; $uri->setVar('mesid', $message->id); } $uri->setVar('id', $id); } break; case 'karma': $changed = true; $uri->setVar('view', 'user'); switch ($uri->getVar('layout')) { case 'increase': $uri->setVar('task', 'karmaup'); break; case 'decrease': $uri->setVar('task', 'karmadown'); break; } $uri->delVar('layout'); $uri->delVar('pid'); break; case 'template': $changed = true; $uri->setVar('view', 'misc'); $uri->setVar('task', 'template'); break; case 'rules': case 'help': $changed = true; $uri->setVar('view', 'misc'); $uri->delVar('layout'); break; } if ($changed) { JLog::add("Legacy URI {$legacy->toString(array('path', 'query'))} was converted to {$uri->toString(array('path', 'query'))}", JLog::DEBUG, 'kunena'); } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $changed; }
/** * @param array $instances */ protected static function buildTree(array &$instances) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; self::$_tree = array(); foreach ($instances as $instance) { if (!isset(self::$_tree[(int) $instance->id])) { self::$_tree[$instance->id] = array(); } self::$_tree[$instance->parent_id][$instance->id] =& self::$_tree[(int) $instance->id]; } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; }
/** * @param array $userids * * @return array */ public static function loadUsers(array $userids = array()) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; // Make sure that userids are unique and that indexes are correct $e_userids = array(); foreach ($userids as $userid) { // Ignore guests and imported users, which haven't been mapped to Joomla (id<0). if ($userid > 0 && empty(self::$_instances[$userid])) { $e_userids[(int) $userid] = (int) $userid; } } if (!empty($e_userids)) { $userlist = implode(',', $e_userids); $db = JFactory::getDBO(); $query = "SELECT u.name, u.username, u.email, u.block as blocked, u.registerDate, u.lastvisitDate, ku.*, u.id AS userid\n\t\t\t\tFROM #__users AS u\n\t\t\t\tLEFT JOIN #__kunena_users AS ku ON u.id = ku.userid\n\t\t\t\tWHERE u.id IN ({$userlist})"; $db->setQuery($query); $results = $db->loadAssocList(); KunenaError::checkDatabaseError(); foreach ($results as $user) { $instance = new KunenaUser(false); $instance->setProperties($user); $instance->exists(isset($user['posts'])); self::$_instances[$instance->userid] = $instance; } // Preload avatars if configured $avatars = KunenaFactory::getAvatarIntegration(); $avatars->load($e_userids); } $list = array(); foreach ($userids as $userid) { if (isset(self::$_instances[$userid])) { $list[$userid] = self::$_instances[$userid]; } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $list; }
/** * Method to display a view. * * @param boolean $cachable If true, the view output will be cached * @param array|bool $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JControllerLegacy A JControllerLegacy object to support chaining. */ public function display($cachable = false, $urlparams = false) { KUNENA_PROFILER ? $this->profiler->mark('beforeDisplay') : null; KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; // Get the document object. $document = JFactory::getDocument(); // Set the default view name and format from the Request. $vName = JRequest::getWord('view', $this->app->isAdmin() ? 'cpanel' : 'home'); $lName = JRequest::getWord('layout', 'default'); $vFormat = $document->getType(); if ($this->app->isAdmin()) { // Load admin language files KunenaFactory::loadLanguage('com_kunena.install', 'admin'); KunenaFactory::loadLanguage('com_kunena.views', 'admin'); // Load last to get deprecated language files to work KunenaFactory::loadLanguage('com_kunena', 'admin'); // Version warning require_once KPATH_ADMIN . '/install/version.php'; $version = new KunenaVersion(); $version_warning = $version->getVersionWarning(); if (!empty($version_warning)) { $this->app->enqueueMessage($version_warning, 'notice'); } } else { // Load site language files KunenaFactory::loadLanguage('com_kunena.views'); KunenaFactory::loadLanguage('com_kunena.templates'); // Load last to get deprecated language files to work KunenaFactory::loadLanguage('com_kunena'); $menu = $this->app->getMenu(); $active = $menu->getActive(); // Check if menu item was correctly routed $routed = $menu->getItem(KunenaRoute::getItemID()); if ($vFormat == 'html' && !empty($routed->id) && (empty($active->id) || $active->id != $routed->id)) { // Routing has been changed, redirect // FIXME: check possible redirect loops! $route = KunenaRoute::_(null, false); $activeId = !empty($active->id) ? $active->id : 0; JLog::add("Redirect from " . JUri::getInstance()->toString(array('path', 'query')) . " ({$activeId}) to {$route} ({$routed->id})", JLog::DEBUG, 'kunena'); $this->app->redirect($route); } // Joomla 2.5+ multi-language support /* // FIXME: if (isset($active->language) && $active->language != '*') { $language = JFactory::getDocument()->getLanguage(); if (strtolower($active->language) != strtolower($language)) { $route = KunenaRoute::_(null, false); JLog::add("Language redirect from ".JUri::getInstance()->toString(array('path', 'query'))." to {$route}", JLog::DEBUG, 'kunena'); $this->redirect ($route); } } */ } $view = $this->getView($vName, $vFormat); if ($view) { if ($this->app->isSite() && $vFormat == 'html') { $common = $this->getView('common', $vFormat); $model = $this->getModel('common'); $common->setModel($model, true); $view->ktemplate = $common->ktemplate = KunenaFactory::getTemplate(); $view->common = $common; } // Set the view layout. $view->setLayout($lName); // Get the appropriate model for the view. $model = $this->getModel($vName); // Push the model into the view (as default). $view->setModel($model, true); // Push document object into the view. $view->document = $document; // Render the view. if ($vFormat == 'html') { JPluginHelper::importPlugin('kunena'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onKunenaDisplay', array('start', $view)); $view->displayAll(); $dispatcher->trigger('onKunenaDisplay', array('end', $view)); } else { $view->displayLayout(); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $this; }
protected static function loadCategories() { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $db = JFactory::getDBO(); $query = "SELECT * FROM #__kunena_categories ORDER BY ordering, name"; $db->setQuery($query); $results = (array) $db->loadAssocList(); KunenaError::checkDatabaseError(); self::$_instances = array(); self::$_tree = array(); if (empty($results)) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return; } foreach ($results as $category) { $instance = new KunenaForumCategory($category); $instance->exists(true); self::$_instances[$instance->id] = $instance; if (!isset(self::$_tree[(int) $instance->id])) { self::$_tree[$instance->id] = array(); } self::$_tree[$instance->parent_id][$instance->id] =& self::$_tree[(int) $instance->id]; } unset($results); // TODO: remove this by adding level into table $heap = array(0); while (($parent = array_shift($heap)) !== null) { foreach (self::$_tree[$parent] as $id => $children) { if (!empty($children)) { array_push($heap, $id); } self::$_instances[$id]->level = $parent ? self::$_instances[$parent]->level + 1 : 0; } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; }
public function authorise($action='read', $user=null, $silent=false) { if ($action == 'none') return true; KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; if ($user === null) { $user = $this->_me; } elseif (!($user instanceof KunenaUser)) { $user = KunenaUserHelper::get($user); } if (empty($this->_authcache[$user->userid][$action])) { if (!isset(self::$actions[$action])) { JError::raiseError(500, JText::sprintf ( 'COM_KUNENA_LIB_AUTHORISE_INVALID_ACTION', $action ) ); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return false; } $this->_authcache[$user->userid][$action] = null; foreach (self::$actions[$action] as $function) { if (!isset($this->_authfcache[$user->userid][$function])) { $authFunction = 'authorise'.$function; $this->_authfcache[$user->userid][$function] = $this->$authFunction($user); } $error = $this->_authfcache[$user->userid][$function]; if ($error) { $this->_authcache[$user->userid][$action] = $error; break; } } } $error = $this->_authcache[$user->userid][$action]; if ($silent === false && $error) $this->setError ( $error ); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; if ($silent !== null) $error = !$error; return $error; }
/** * @param mixed $user * * @return mixed */ public function getAllowedCategories($user = null) { static $read = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $user = KunenaFactory::getUser($user); $id = $user->userid; if (!isset($read[$id])) { $app = JFactory::getApplication(); // TODO: handle guests/bots with no userstate $read[$id] = $app->getUserState("com_kunena.user{$id}_read"); if ($read[$id] === null) { $read[$id] = array(); $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); foreach ($categories as $category) { // Remove unpublished categories if (!$category->published) { unset($categories[$category->id]); } // Moderators have always access if (self::isModerator($id, $category->id)) { $read[$id][$category->id] = $category->id; unset($categories[$category->id]); } } // Get external authorization if (!empty($categories)) { /** @var KunenaAccess $access */ foreach ($this->accesstypes['all'] as $access) { if (method_exists($access, 'authoriseCategories')) { $read[$id] += $access->authoriseCategories($id, $categories); } } } $app->setUserState("com_kunena.user{$id}_read", $read[$id]); } } $allowed = $read[$id]; KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $allowed; }
/** * @param KunenaForumTopic $topic * @param null $action * @param null $content * @param null $title * @param null $class * @param KunenaForumCategory $category * * @return mixed */ public function getTopicLink(KunenaForumTopic $topic, $action = null, $content = null, $title = null, $class = null, KunenaForumCategory $category = null) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $url = $topic->getUrl($category ? $category : (isset($this->category) ? $this->category : $topic->getCategory()), true, $action); if (!$content) { $content = KunenaHtmlParser::parseText($topic->subject); } if ($title === null) { if ($action instanceof KunenaForumMessage) { $title = JText::sprintf('COM_KUNENA_TOPIC_MESSAGE_LINK_TITLE', $this->escape($topic->subject)); } else { switch ($action) { case 'first': $title = JText::sprintf('COM_KUNENA_TOPIC_FIRST_LINK_TITLE', $this->escape($topic->subject)); break; case 'last': $title = JText::sprintf('COM_KUNENA_TOPIC_LAST_LINK_TITLE', $this->escape($topic->subject)); break; case 'unread': $title = JText::sprintf('COM_KUNENA_TOPIC_UNREAD_LINK_TITLE', $this->escape($topic->subject)); break; default: $title = JText::sprintf('COM_KUNENA_TOPIC_LINK_TITLE', $this->escape($topic->subject)); } } } $link = JHtml::_('kunenaforum.link', $url, $content, $title, $class, 'nofollow'); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $link; }
/** * Method to display a view. * * @return void * @since 1.6 */ public function display($cachable = false, $urlparams = false) { KUNENA_PROFILER ? $this->profiler->mark('beforeDisplay') : null; KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $app = JFactory::getApplication(); if ($app->isAdmin()) { // Version warning require_once KPATH_ADMIN . '/install/version.php'; $version = new KunenaVersion(); $version_warning = $version->getVersionWarning(); if (!empty($version_warning)) { $app->enqueueMessage($version_warning, 'notice'); } } else { $menu = $app->getMenu(); $active = $menu->getActive(); // Check if menu item was correctly routed $routed = $menu->getItem(KunenaRoute::getItemID()); /* if (!$active) { // FIXME: we may want to resctrict access only to menu items JError::raiseError ( 500, JText::_ ( 'COM_KUNENA_NO_ACCESS' ) ); } */ if ($active->id != $routed->id) { // Routing has been changed, redirect // FIXME: check possible redirect loops! $app->redirect(KunenaRoute::_(null, false)); } // Joomla 1.6+ multi-language support /* // FIXME: if (isset($active->language) && $active->language != '*') { $language = JFactory::getDocument()->getLanguage(); if (strtolower($active->language) != strtolower($language)) { $this->redirect (KunenaRoute::_(null, false)); } } */ } // Get the document object. $document = JFactory::getDocument(); // Set the default view name and format from the Request. $vName = JRequest::getWord('view', 'none'); $lName = JRequest::getWord('layout', 'default'); $vFormat = $document->getType(); $view = $this->getView($vName, $vFormat); if ($view) { if ($app->isSite() && $vFormat == 'html') { $common = $this->getView('common', $vFormat); $model = $this->getModel('common'); $common->setModel($model, true); $view->ktemplate = $common->ktemplate = KunenaFactory::getTemplate(); $view->common = $common; } // Get the appropriate model for the view. $model = $this->getModel($vName); // Push the model into the view (as default). $view->setModel($model, true); // Set the view layout. $view->setLayout($lName); // Push document object into the view. $view->document = $document; // Render the view. if ($vFormat == 'html') { JPluginHelper::importPlugin('kunena'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onKunenaDisplay', array('start', $view)); $view->displayAll(); $dispatcher->trigger('onKunenaDisplay', array('end', $view)); } else { $view->displayLayout(); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; }
/** * Load Kunena language file * * Helper function for external modules and plugins to load the main Kunena language file(s) * */ public static function loadLanguage( $file = 'com_kunena', $client = 'site' ) { static $loaded = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; if ($client == 'site') { $lookup1 = JPATH_SITE; $lookup2 = KPATH_SITE; } else { $client = 'admin'; $lookup1 = JPATH_ADMINISTRATOR; $lookup2 = KPATH_ADMIN; } if (empty($loaded["{$client}/{$file}"])) { $lang = JFactory::getLanguage(); $english = false; if ($lang->getTag() != 'en-GB' && !JDEBUG && !$lang->getDebug() && !KunenaFactory::getConfig()->get('debug') && KunenaFactory::getConfig()->get('fallback_english')) { $lang->load($file, $lookup2, 'en-GB', true, false); $english = true; } $loaded[$file] = $lang->load($file, $lookup1, null, $english, false) || $lang->load($file, $lookup2, null, $english, false); } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $loaded[$file]; }
protected static function setItemID(JUri $uri) { static $candidates = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; $view = $uri->getVar('view'); $catid = (int) $uri->getVar('catid'); $Itemid = (int) $uri->getVar('Itemid'); $key = $view.$catid; if (!isset($candidates[$key])) { if (self::$search === false) { self::build(); } $search = array(); if (self::$home) { // Search from the current home menu $search[self::$home->id] = 1; // Then search from all linked home menus if (isset(self::$search['home'][self::$home->id])) { $search += self::$search['home'][self::$home->id]; } } // Finally search from other home menus $search += self::$search['home']; // Find all potential candidates $candidates[$key] = array(); foreach ($search as $id=>$dummy) { $follow = !empty(self::$menu[$id]) ? self::$menu[$id] : null; if ($follow && self::checkHome($follow, $catid)) { $candidates[$key] += !empty(self::$search[$view][$follow->id]) ? self::$search[$view][$follow->id] : array(); if ($view == 'topic') { $candidates[$key] += !empty(self::$search['category'][$follow->id]) ? self::$search['category'][$follow->id] : array(); } $candidates[$key][$follow->id] = $follow->id; } } // Don't forget lonely candidates $candidates[$key] += !empty(self::$search[$view][0]) ? self::$search[$view][0] : array(); if ($view == 'topic') { $candidates[$key] += !empty(self::$search['category'][0]) ? self::$search['category'][0] : array(); } } // Check current menu item first $bestcount = ($Itemid && isset(self::$menu[$Itemid])) ? self::checkItem(self::$menu[$Itemid], $uri) : 0; $bestid = $bestcount ? $Itemid : 0; // Then go through all candidates foreach ($candidates[$key] as $id) { $item = self::$menu[$id]; $matchcount = self::checkItem($item, $uri); if ($matchcount > $bestcount) { // This is our best candidate this far $bestid = $item->id; $bestcount = $matchcount; } } $uri->setVar('Itemid', $bestid); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $bestid; }