2018-04-24 12:12:24 +00:00
|
|
|
<?php
|
|
|
|
/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
|
|
|
__ __ _ _____ _ _ __ __ _ _ _
|
|
|
|
\ \ / / | | | __ \ | | | | | \/ | | | | | | |
|
|
|
|
\ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
|
|
|
|
\ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
|
|
|
|
\ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
|
|
|
|
\/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
|
|
|
|
| |
|
|
|
|
|_|
|
|
|
|
/-------------------------------------------------------------------------------------------------------------------------------/
|
|
|
|
|
|
|
|
@version 1.0.x
|
2018-05-05 19:52:41 +00:00
|
|
|
@build 5th May, 2018
|
2018-04-24 12:12:24 +00:00
|
|
|
@created 30th January, 2017
|
|
|
|
@package Questions and Answers
|
|
|
|
@subpackage route.php
|
|
|
|
@author Llewellyn van der Merwe <https://www.vdm.io/>
|
|
|
|
@copyright Copyright (C) 2015. All Rights Reserved
|
|
|
|
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
|
|
|
|
Questions & Answers
|
|
|
|
|
|
|
|
/-----------------------------------------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
// Component Helper
|
|
|
|
jimport('joomla.application.component.helper');
|
|
|
|
jimport('joomla.application.categories');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Questionsanswers Route Helper
|
|
|
|
**/
|
|
|
|
abstract class QuestionsanswersHelperRoute
|
|
|
|
{
|
|
|
|
protected static $lookup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int The route of the Questions_and_answers
|
|
|
|
*/
|
|
|
|
public static function getQuestions_and_answersRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array(
|
|
|
|
'questions_and_answers' => array((int) $id)
|
|
|
|
);
|
|
|
|
// Create the link
|
|
|
|
$link = 'index.php?option=com_questionsanswers&view=questions_and_answers&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array();
|
|
|
|
//Create the link but don't add the id.
|
|
|
|
$link = 'index.php?option=com_questionsanswers&view=questions_and_answers';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
|
|
|
$categories = JCategories::getInstance('questionsanswers.questions_and_answers');
|
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int The route of the Category
|
|
|
|
*/
|
|
|
|
public static function getCategoryRoute($id = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array(
|
|
|
|
'category' => array((int) $id)
|
|
|
|
);
|
|
|
|
// Create the link
|
|
|
|
$link = 'index.php?option=com_questionsanswers&view=category&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array();
|
|
|
|
//Create the link but don't add the id.
|
|
|
|
$link = 'index.php?option=com_questionsanswers&view=category';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int The route of the Downloads
|
|
|
|
*/
|
|
|
|
public static function getDownloadsRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array(
|
|
|
|
'downloads' => array((int) $id)
|
|
|
|
);
|
|
|
|
// Create the link
|
|
|
|
$link = 'index.php?option=com_questionsanswers&view=downloads&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array();
|
|
|
|
//Create the link but don't add the id.
|
|
|
|
$link = 'index.php?option=com_questionsanswers&view=downloads';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
|
|
|
$categories = JCategories::getInstance('questionsanswers.downloads');
|
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the URL route for questionsanswers category from a category ID and language
|
|
|
|
*
|
|
|
|
* @param mixed $catid The id of the items's category either an integer id or a instance of JCategoryNode
|
|
|
|
* @param mixed $language The id of the language being used.
|
|
|
|
*
|
|
|
|
* @return string The link to the contact
|
|
|
|
*
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
|
|
|
public static function getCategoryRoute_keep_for_later($catid, $language = 0)
|
|
|
|
{
|
|
|
|
if ($catid instanceof JCategoryNode)
|
|
|
|
{
|
|
|
|
$id = $catid->id;
|
|
|
|
$category = $catid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Exception('First parameter must be JCategoryNode');
|
|
|
|
}
|
|
|
|
|
|
|
|
$views = array(
|
|
|
|
"com_questionsanswers.questions_and_answers" => "question_and_answer");
|
|
|
|
$view = $views[$category->extension];
|
|
|
|
|
|
|
|
if ($id < 1 || !($category instanceof JCategoryNode))
|
|
|
|
{
|
|
|
|
$link = '';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Create the link
|
|
|
|
$link = 'index.php?option=com_questionsanswers&view='.$view.'&category='.$category->slug;
|
|
|
|
|
|
|
|
$needles = array(
|
|
|
|
$view => array($id),
|
|
|
|
'category' => array($id)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($language && $language != "*" && JLanguageMultilang::isEnabled())
|
|
|
|
{
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
->select('a.sef AS sef')
|
|
|
|
->select('a.lang_code AS lang_code')
|
|
|
|
->from('#__languages AS a');
|
|
|
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
$langs = $db->loadObjectList();
|
|
|
|
foreach ($langs as $lang)
|
|
|
|
{
|
|
|
|
if ($language == $lang->lang_code)
|
|
|
|
{
|
|
|
|
$link .= '&lang='.$lang->sef;
|
|
|
|
$needles['language'] = $language;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles,'category'))
|
|
|
|
{
|
|
|
|
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$catids = array_reverse($category->getPath());
|
|
|
|
$needles = array(
|
|
|
|
'category' => $catids
|
|
|
|
);
|
|
|
|
if ($item = self::_findItem($needles,'category'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
elseif ($item = self::_findItem(null, 'category'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static function _findItem($needles = null,$type = null)
|
|
|
|
{
|
|
|
|
$app = JFactory::getApplication();
|
|
|
|
$menus = $app->getMenu('site');
|
|
|
|
$language = isset($needles['language']) ? $needles['language'] : '*';
|
|
|
|
|
|
|
|
// Prepare the reverse lookup array.
|
|
|
|
if (!isset(self::$lookup[$language]))
|
|
|
|
{
|
|
|
|
self::$lookup[$language] = array();
|
|
|
|
|
|
|
|
$component = JComponentHelper::getComponent('com_questionsanswers');
|
|
|
|
|
|
|
|
$attributes = array('component_id');
|
|
|
|
$values = array($component->id);
|
|
|
|
|
|
|
|
if ($language != '*')
|
|
|
|
{
|
|
|
|
$attributes[] = 'language';
|
|
|
|
$values[] = array($needles['language'], '*');
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = $menus->getItems($attributes, $values);
|
|
|
|
|
|
|
|
foreach ($items as $item)
|
|
|
|
{
|
|
|
|
if (isset($item->query) && isset($item->query['view']))
|
|
|
|
{
|
|
|
|
$view = $item->query['view'];
|
|
|
|
|
|
|
|
if (!isset(self::$lookup[$language][$view]))
|
|
|
|
{
|
|
|
|
self::$lookup[$language][$view] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($item->query['id']))
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Here it will become a bit tricky
|
|
|
|
* language != * can override existing entries
|
|
|
|
* language == * cannot override existing entries
|
|
|
|
*/
|
|
|
|
if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*')
|
|
|
|
{
|
|
|
|
self::$lookup[$language][$view][$item->query['id']] = $item->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($needles)
|
|
|
|
{
|
|
|
|
foreach ($needles as $view => $ids)
|
|
|
|
{
|
|
|
|
if (isset(self::$lookup[$language][$view]))
|
|
|
|
{
|
|
|
|
foreach ($ids as $id)
|
|
|
|
{
|
|
|
|
if (isset(self::$lookup[$language][$view][(int) $id]))
|
|
|
|
{
|
|
|
|
return self::$lookup[$language][$view][(int) $id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type)
|
|
|
|
{
|
|
|
|
// Check if the global menu item has been set.
|
|
|
|
$params = JComponentHelper::getParams('com_questionsanswers');
|
|
|
|
if ($item = $params->get($type.'_menu', 0))
|
|
|
|
{
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the active menuitem matches the requested language
|
|
|
|
$active = $menus->getActive();
|
|
|
|
|
|
|
|
if ($active
|
|
|
|
&& $active->component == 'com_questionsanswers'
|
|
|
|
&& ($language == '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled()))
|
|
|
|
{
|
|
|
|
return $active->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not found, return language specific home link
|
|
|
|
$default = $menus->getDefault($language);
|
|
|
|
|
|
|
|
return !empty($default->id) ? $default->id : null;
|
|
|
|
}
|
|
|
|
}
|