/** * @param string The context of the content being passed to the plugin. * @param object The article object. Note $article->text is also available * @param object The article params * @param int The 'page' number * * @return void * @since 1.6 */ public function onContentPrepare($context, &$row, &$params, $page = 0) { $canProceed = $context == 'com_content.article'; if (!$canProceed) { return; } $style = $this->params->get('style', 'pages'); // Expression to search for. $regex = '#<hr(.*)class="system-pagebreak"(.*)\\/>#iU'; $print = Request::getBool('print'); $showall = Request::getBool('showall'); if (!$this->params->get('enabled', 1)) { $print = true; } if ($print) { $row->text = preg_replace($regex, '<br />', $row->text); return true; } // Simple performance check to determine whether bot should process further. if (JString::strpos($row->text, 'class="system-pagebreak') === false) { return true; } $db = App::get('db'); $view = Request::getString('view'); $full = Request::getBool('fullview'); if (!$page) { $page = 0; } if ($params->get('intro_only') || $params->get('popup') || $full || $view != 'article') { $row->text = preg_replace($regex, '', $row->text); return; } // Find all instances of plugin and put in $matches. $matches = array(); preg_match_all($regex, $row->text, $matches, PREG_SET_ORDER); if ($showall && $this->params->get('showall', 1)) { $hasToc = $this->params->get('multipage_toc', 1); if ($hasToc) { // Display TOC. $page = 1; $this->_createToc($row, $matches, $page); } else { $row->toc = ''; } $row->text = preg_replace($regex, '<br />', $row->text); return true; } // Split the text around the plugin. $text = preg_split($regex, $row->text); // Count the number of pages. $n = count($text); // We have found at least one plugin, therefore at least 2 pages. if ($n > 1) { $title = $this->params->get('title', 1); $hasToc = $this->params->get('multipage_toc', 1); // Adds heading or title to <site> Title. if ($title) { if ($page) { $page_text = $page + 1; if ($page && @$matches[$page - 1][2]) { $attrs = JUtility::parseAttributes($matches[$page - 1][1]); if (@$attrs['title']) { $row->page_title = $attrs['title']; } } } } // Reset the text, we already hold it in the $text array. $row->text = ''; if ($style == 'pages') { // Display TOC. if ($hasToc) { $this->_createToc($row, $matches, $page); } else { $row->toc = ''; } // traditional mos page navigation $pageNav = new \Hubzero\Pagination\Paginator($n, $page, 1); // Page counter. $row->text .= '<div class="pagenavcounter">'; $row->text .= $pageNav->getPagesCounter(); $row->text .= '</div>'; // Page text. $text[$page] = str_replace('<hr id="system-readmore" />', '', $text[$page]); $row->text .= $text[$page]; // $row->text .= '<br />'; $row->text .= '<div class="pagination">'; // Adds navigation between pages to bottom of text. if ($hasToc) { $this->_createNavigation($row, $page, $n); } // Page links shown at bottom of page if TOC disabled. if (!$hasToc) { $row->text .= $pageNav->getPagesLinks(); } $row->text .= '</div>'; } else { $t[] = $text[0]; $t[] = (string) Html::$style('start'); foreach ($text as $key => $subtext) { if ($key >= 1) { $match = $matches[$key - 1]; $match = (array) JUtility::parseAttributes($match[0]); if (isset($match['alt'])) { $title = stripslashes($match["alt"]); } elseif (isset($match['title'])) { $title = stripslashes($match['title']); } else { $title = Lang::txt('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $key + 1); } $t[] = (string) Html::$style('panel', $title, 'basic-details'); } $t[] = (string) $subtext; } $t[] = (string) Html::$style('end'); $row->text = implode(' ', $t); } } return true; }
<form action="<?php echo Route::url('index.php?option=' . $this->option); ?> " id="component-form" method="post" name="adminForm" autocomplete="off" class="form-validate"> <fieldset> <div class="fltrt"> <button type="button" onclick="Joomla.submitform('component.apply', this.form);"><?php echo Lang::txt('JAPPLY'); ?> </button> <button type="button" onclick="Joomla.submitform('component.save', this.form);"><?php echo Lang::txt('JSAVE'); ?> </button> <button type="button" onclick="<?php echo Request::getBool('refresh', 0) ? 'window.parent.location.href=window.parent.location.href;' : ''; ?> window.parent.$.fancybox.close();"><?php echo Lang::txt('JCANCEL'); ?> </button> </div> <div class="configuration"> <?php echo Lang::txt($this->component->option . '_configuration'); ?> </div> </fieldset> <?php echo Html::tabs('start', 'config-tabs-' . $this->component->option . '_configuration', array('useCookie' => 1));
/** * @since 1.6 */ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0) { $view = Request::getCmd('view'); $print = Request::getBool('print'); if ($print) { return false; } if ($params->get('show_item_navigation') && $context == 'com_content.article' && $view == 'article') { $html = ''; $db = App::get('db'); $nullDate = $db->getNullDate(); $date = Date::of('now'); $now = $date->toSql(); $uid = $row->id; $option = 'com_content'; $canPublish = User::authorise('core.edit.state', $option . '.article.' . $row->id); // The following is needed as different menu items types utilise a different param to control ordering. // For Blogs the `orderby_sec` param is the order controlling param. // For Table and List views it is the `orderby` param. $params_list = $params->toArray(); if (array_key_exists('orderby_sec', $params_list)) { $order_method = $params->get('orderby_sec', ''); } else { $order_method = $params->get('orderby', ''); } // Additional check for invalid sort ordering. if ($order_method == 'front') { $order_method = ''; } // Determine sort order. switch ($order_method) { case 'date': $orderby = 'a.created'; break; case 'rdate': $orderby = 'a.created DESC'; break; case 'alpha': $orderby = 'a.title'; break; case 'ralpha': $orderby = 'a.title DESC'; break; case 'hits': $orderby = 'a.hits'; break; case 'rhits': $orderby = 'a.hits DESC'; break; case 'order': $orderby = 'a.ordering'; break; case 'author': $orderby = 'a.created_by_alias, u.name'; break; case 'rauthor': $orderby = 'a.created_by_alias DESC, u.name DESC'; break; case 'front': $orderby = 'f.ordering'; break; default: $orderby = 'a.ordering'; break; } $xwhere = ' AND (a.state = 1 OR a.state = -1)' . ' AND (publish_up = ' . $db->Quote($nullDate) . ' OR publish_up <= ' . $db->Quote($now) . ')' . ' AND (publish_down = ' . $db->Quote($nullDate) . ' OR publish_down >= ' . $db->Quote($now) . ')'; // Array of articles in same category correctly ordered. $query = $db->getQuery(true); //sqlsrv changes $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id . ' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('cc.alias'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('cc.id'); $case_when1 .= $query->concatenate(array($c_id, 'cc.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id . ' END as catslug'; $query->select('a.id, a.language,' . $case_when . ',' . $case_when1); $query->from('#__content AS a'); $query->leftJoin('#__categories AS cc ON cc.id = a.catid'); $query->where('a.catid = ' . (int) $row->catid . ' AND a.state = ' . (int) $row->state . ($canPublish ? '' : ' AND a.access = ' . (int) $row->access) . $xwhere); $query->order($orderby); if (\App::isSite() && \App::get('language.filter')) { $query->where('a.language in (' . $db->quote(Lang::getTag()) . ',' . $db->quote('*') . ')'); } $db->setQuery($query); $list = $db->loadObjectList('id'); // This check needed if incorrect Itemid is given resulting in an incorrect result. if (!is_array($list)) { $list = array(); } reset($list); // Location of current content item in array list. $location = array_search($uid, array_keys($list)); $rows = array_values($list); $row->prev = null; $row->next = null; if ($location - 1 >= 0) { // The previous content item cannot be in the array position -1. $row->prev = $rows[$location - 1]; } if ($location + 1 < count($rows)) { // The next content item cannot be in an array position greater than the number of array postions. $row->next = $rows[$location + 1]; } $pnSpace = ""; if (Lang::txt('JGLOBAL_LT') || Lang::txt('JGLOBAL_GT')) { $pnSpace = " "; } if ($row->prev) { $row->prev = Route::url(ContentHelperRoute::getArticleRoute($row->prev->slug, $row->prev->catslug, $row->prev->language)); } else { $row->prev = ''; } if ($row->next) { $row->next = Route::url(ContentHelperRoute::getArticleRoute($row->next->slug, $row->next->catslug, $row->next->language)); } else { $row->next = ''; } // Output. if ($row->prev || $row->next) { $html = ' <ul class="pagenav">'; if ($row->prev) { $html .= ' <li class="pagenav-prev"> <a href="' . $row->prev . '" rel="prev">' . Lang::txt('JGLOBAL_LT') . $pnSpace . Lang::txt('JPREV') . '</a> </li>'; } if ($row->next) { $html .= ' <li class="pagenav-next"> <a href="' . $row->next . '" rel="next">' . Lang::txt('JNEXT') . $pnSpace . Lang::txt('JGLOBAL_GT') . '</a> </li>'; } $html .= ' </ul>'; $row->pagination = $html; $row->paginationposition = $this->params->get('position', 1); // This will default to the 1.5 and 1.6-1.7 behavior. $row->paginationrelative = $this->params->get('relative', 0); } } return; }
<jdoc:include type="modules" name="notices" /> <header id="header" role="banner"> <h1><a href="<?php echo Request::root(); ?> "><?php echo Config::get('sitename'); ?> </a></h1> <ul class="user-options"> <?php //Display an harcoded logout $task = Request::getCmd('task'); $hideLinks = Request::getBool('hidemainmenu'); $logoutLink = Route::url('index.php?option=com_login&task=logout&' . Session::getFormToken() . '=1'); if ($task == 'edit' || $task == 'editA' || $hideLinks) { $logoutLink = ''; } $output = array(); $output[] = ($hideLinks ? '<li class="disabled" data-title="' . Lang::txt('TPL_KAMELEON_LOG_OUT') . '"><span class="logout">' : '<li data-title="' . Lang::txt('TPL_KAMELEON_LOG_OUT') . '"><a class="logout" href="' . $logoutLink . '">') . Lang::txt('TPL_KAMELEON_LOG_OUT') . ($hideLinks ? '</span></li>' : '</a></li>'); // Reverse rendering order for rtl display. if ($this->direction == "rtl") { $output = array_reverse($output); } // Output the items. foreach ($output as $item) { echo $item; } ?>
/** * Method to log in a user. * * @since 1.6 */ public function login() { // Populate the data array: $data = array(); $options = array(); $data['return'] = base64_decode(Request::getVar('return', '', 'POST', 'BASE64')); $data['username'] = Request::getVar('username', '', 'method', 'username'); $data['password'] = Request::getString('passwd', '', 'post', JREQUEST_ALLOWRAW); $authenticator = Request::getVar('authenticator', '', 'method'); // If a specific authenticator is specified try to call the login method for that plugin if (!empty($authenticator)) { Plugin::import('authentication'); $plugins = Plugin::byType('authentication'); foreach ($plugins as $plugin) { $className = 'plg' . $plugin->type . $plugin->name; if ($plugin->name != $authenticator) { continue; } if (class_exists($className)) { if (method_exists($className, 'login')) { $myplugin = new $className($this, (array) $plugin); $myplugin->login($credentials, $options); if (isset($options['return'])) { $data['return'] = $options['return']; } } $options['authenticator'] = $authenticator; $options['action'] = 'core.login.site'; break; } } } // If no authenticator is specified, or the login method for that plugin did not exist then use joomla default if (!isset($myplugin)) { // Check for request forgeries Session::checkToken('request'); if ($return = Request::getVar('return', '', 'method', 'base64')) { $return = base64_decode($return); if (!JURI::isInternal($return)) { $return = ''; } } if ($freturn = Request::getVar('freturn', '', 'method', 'base64')) { $freturn = base64_decode($freturn); if (!JURI::isInternal($freturn)) { $freturn = ''; } } // Get the log in options. $options = array(); $options['remember'] = Request::getBool('remember', false); $options['return'] = $data['return']; $options['action'] = 'core.login.site'; if (!empty($authenticator)) { $options['authenticator'] = $authenticator; } // Get the log in credentials. $credentials = array(); $credentials['username'] = $data['username']; $credentials['password'] = $data['password']; } // Set the return URL if empty. if (empty($data['return'])) { $data['return'] = 'index.php?option=com_members&task=myaccount'; } // Set the return URL in the user state to allow modification by plugins User::setState('users.login.form.return', $data['return']); try { $result = App::get('auth')->login($credentials, $options); } catch (Exception $e) { $result = $e; } // Perform the log in. if (true === $result) { // Success User::setState('users.login.form.data', array()); // If no_html is set, return json response if (Request::getInt('no_html', 0)) { echo json_encode(array("success" => true, "redirect" => Route::url(User::getState('users.login.form.return'), false))); exit; } else { App::redirect(Route::url(User::getState('users.login.form.return'), false)); } } else { // Login failed ! $data['remember'] = isset($options['remember']) ? (int) $options['remember'] : 0; User::setState('users.login.form.data', $data); // Facilitate third party login forms if (!isset($return) || !$return) { $return = Route::url('index.php?option=com_users&view=login'); } if (isset($freturn)) { $return = $freturn; } $error = $result ? $result->getMessage() : 'An unknown error has occurred'; // If no_html is set, return json response if (Request::getInt('no_html', 0)) { echo json_encode(array("error" => $error, "freturn" => Route::url($return, false))); exit; } else { // Redirect to a login form App::redirect(Route::url($return, false), $error, 'error'); } } }
function display($tpl = null) { // Initialise variables. $app = JFactory::getApplication(); $userId = User::get('id'); $this->item = $this->get('Item'); $this->print = Request::getBool('print'); $this->state = $this->get('State'); $this->user = User::getRoot(); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors), 500); return false; } // Create a shortcut for $item. $item =& $this->item; // Add router helpers. $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id; $item->catslug = $item->category_alias ? $item->catid . ':' . $item->category_alias : $item->catid; $item->parent_slug = $item->category_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id; // TODO: Change based on shownoauth $item->readmore_link = Route::url(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug, $item->language)); // Merge article params. If this is single-article view, menu params override article params // Otherwise, article params override menu item params $this->params = $this->state->get('params'); $active = \App::get('menu')->getActive(); $temp = clone $this->params; // Check to see which parameters should take priority if ($active) { $currentLink = $active->link; // If the current view is the active item and an article view for this article, then the menu item params take priority if (strpos($currentLink, 'view=article') && strpos($currentLink, '&id=' . (string) $item->id)) { // $item->params are the article params, $temp are the menu item params // Merge so that the menu item params take priority $item->params->merge($temp); // Load layout from active query (in case it is an alternative menu item) if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } } else { // Current view is not a single article, so the article params take priority here // Merge the menu item params with the article params so that the article params take priority $temp->merge($item->params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-article menu item) // Single-article menu item layout takes priority over alt layout for an article if ($layout = $item->params->get('article_layout')) { $this->setLayout($layout); } } } else { // Merge so that article params take priority $temp->merge($item->params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-article menu item) // Single-article menu item layout takes priority over alt layout for an article if ($layout = $item->params->get('article_layout')) { $this->setLayout($layout); } } $offset = $this->state->get('list.offset'); // Check the view access to the article (the model has already computed the values). if ($item->params->get('access-view') == false && $item->params->get('show_noauth', '0') == '0') { throw new Exception(Lang::txt('JERROR_ALERTNOAUTHOR'), 403); return; } if ($item->params->get('show_intro', '1') == '1') { $item->text = $item->introtext . ' ' . $item->fulltext; } elseif ($item->fulltext) { $item->text = $item->fulltext; } else { $item->text = $item->introtext; } // // Process the content plugins. // $results = Event::trigger('content.onContentPrepare', array('com_content.article', &$item, &$this->params, $offset)); $item->event = new stdClass(); $results = Event::trigger('content.onContentAfterTitle', array('com_content.article', &$item, &$this->params, $offset)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = Event::trigger('content.onContentBeforeDisplay', array('com_content.article', &$item, &$this->params, $offset)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = Event::trigger('content.onContentAfterDisplay', array('com_content.article', &$item, &$this->params, $offset)); $item->event->afterDisplayContent = trim(implode("\n", $results)); // Increment the hit counter of the article. if (!$this->params->get('intro_only') && $offset == 0) { // [!] HUBZERO - (zooley) Removing hit counter as it can contribute to performance issues. Need a better way of doing this. //$model = $this->getModel(); //$model->hit(); } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($this->item->params->get('pageclass_sfx')); $this->_prepareDocument(); parent::display($tpl); }
/** * @covers Xmf\Request::getBool * @todo Implement testGetBool(). */ public function testGetBool() { $varname = 'RequestTest'; $_REQUEST[$varname] = '9'; $this->assertTrue(Request::getBool($varname)); $_REQUEST[$varname] = 'a string'; $this->assertTrue(Request::getBool($varname)); $_REQUEST[$varname] = true; $this->assertTrue(Request::getBool($varname)); $_REQUEST[$varname] = ''; $this->assertFalse(Request::getBool($varname)); $_REQUEST[$varname] = false; $this->assertFalse(Request::getBool($varname)); $this->assertFalse(Request::getBool($varname . 'no-such-key')); }
/** * @since 1.6 */ function display($tpl = null) { // Get view related request variables. $print = Request::getBool('print'); // Get model data. $state = $this->get('State'); $item = $this->get('Item'); if ($item) { // Get Category Model data $categoryModel = JModelLegacy::getInstance('Category', 'NewsfeedsModel', array('ignore_request' => true)); $categoryModel->setState('category.id', $item->catid); $categoryModel->setState('list.ordering', 'a.name'); $categoryModel->setState('list.direction', 'asc'); $items = $categoryModel->getItems(); } // Check for errors. // @TODO Maybe this could go into Component::raiseErrors($this->get('Errors')) if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors), 500); return false; } // Add router helpers. $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id; $item->catslug = $item->category_alias ? $item->catid . ':' . $item->category_alias : $item->catid; $item->parent_slug = $item->category_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id; // check if cache directory is writeable $cacheDir = PATH_APP . '/cache/site'; if (!is_writable($cacheDir)) { throw new Exception(Lang::txt('COM_NEWSFEEDS_CACHE_DIRECTORY_UNWRITABLE')); return; } // Merge newsfeed params. If this is single-newsfeed view, menu params override newsfeed params // Otherwise, newsfeed params override menu item params $params = $state->get('params'); $newsfeed_params = clone $item->params; $active = \App::get('menu')->getActive(); $temp = clone $params; // Check to see which parameters should take priority if ($active) { $currentLink = $active->link; // If the current view is the active item and an newsfeed view for this feed, then the menu item params take priority if (strpos($currentLink, 'view=newsfeed') && strpos($currentLink, '&id=' . (string) $item->id)) { // $item->params are the newsfeed params, $temp are the menu item params // Merge so that the menu item params take priority $newsfeed_params->merge($temp); $item->params = $newsfeed_params; // Load layout from active query (in case it is an alternative menu item) if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } } else { // Current view is not a single newsfeed, so the newsfeed params take priority here // Merge the menu item params with the newsfeed params so that the newsfeed params take priority $temp->merge($newsfeed_params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-newsfeed menu item) if ($layout = $item->params->get('newsfeed_layout')) { $this->setLayout($layout); } } } else { // Merge so that newsfeed params take priority $temp->merge($newsfeed_params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-newsfeed menu item) if ($layout = $item->params->get('newsfeed_layout')) { $this->setLayout($layout); } } $offset = $state->get('list.offset'); // Check the access to the newsfeed $levels = User::getAuthorisedViewLevels(); if (!in_array($item->access, $levels) or in_array($item->access, $levels) and !in_array($item->category_access, $levels)) { throw new Exception(Lang::txt('JERROR_ALERTNOAUTHOR'), 403); return; } // Get the current menu item $menus = App::get('menu'); $menu = $menus->getActive(); $params = JFactory::getApplication()->getParams(); // Get the newsfeed $newsfeed = $item; $temp = new \Hubzero\Config\Registry($item->params); $params->merge($temp); // get RSS parsed object $rssDoc = App::get('feed.parser'); $rssDoc->set_feed_url($newsfeed->link); $rssDoc->set_cache_duration($newsfeed->cache_time); $rssDoc->init(); $rssDoc = App::get('feed.parser'); if ($rssDoc == false) { $msg = Lang::txt('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED'); App::redirect(NewsFeedsHelperRoute::getCategoryRoute($newsfeed->catslug), $msg); return; } $lists = array(); // channel header and link $newsfeed->channel['title'] = $rssDoc->get_title(); $newsfeed->channel['link'] = $rssDoc->get_link(); $newsfeed->channel['description'] = $rssDoc->get_description(); $newsfeed->channel['language'] = $rssDoc->get_language(); // channel image if exists $newsfeed->image['url'] = $rssDoc->get_image_url(); $newsfeed->image['title'] = $rssDoc->get_image_title(); $newsfeed->image['link'] = $rssDoc->get_image_link(); $newsfeed->image['height'] = $rssDoc->get_image_height(); $newsfeed->image['width'] = $rssDoc->get_image_width(); // items $newsfeed->items = $rssDoc->get_items(); // feed elements $newsfeed->items = array_slice($newsfeed->items, 0, $newsfeed->numarticles); // feed display order $feed_display_order = $params->get('feed_display_order', 'des'); if ($feed_display_order == 'asc') { $newsfeed->items = array_reverse($newsfeed->items); } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->assignRef('params', $params); $this->assignRef('newsfeed', $newsfeed); $this->assignRef('state', $state); $this->assignRef('item', $item); $this->assignRef('user', User::getRoot()); $this->print = $print; $this->_prepareDocument(); parent::display($tpl); }