2015-08-24 20:22:07 +00:00
|
|
|
<?php
|
|
|
|
/*----------------------------------------------------------------------------------| www.vdm.io |----/
|
|
|
|
Vast Development Method
|
|
|
|
/-------------------------------------------------------------------------------------------------------/
|
|
|
|
|
2017-04-08 18:35:55 +00:00
|
|
|
@version 2.0.0
|
2018-05-05 01:16:22 +00:00
|
|
|
@build 24th April, 2018
|
2017-04-08 18:35:55 +00:00
|
|
|
@created 18th October, 2016
|
2015-08-24 20:22:07 +00:00
|
|
|
@package Demo
|
2015-12-03 02:17:44 +00:00
|
|
|
@subpackage route.php
|
2015-08-24 20:22:07 +00:00
|
|
|
@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
|
|
|
|
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
|
|
|
|
(_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _)
|
|
|
|
.-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )(
|
|
|
|
\____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__)
|
|
|
|
|
|
|
|
/------------------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
// Component Helper
|
|
|
|
jimport('joomla.application.component.helper');
|
|
|
|
jimport('joomla.application.categories');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Demo Route Helper
|
|
|
|
**/
|
|
|
|
abstract class DemoHelperRoute
|
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
protected static $lookup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int The route of the Looks
|
|
|
|
*/
|
|
|
|
public static function getLooksRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array(
|
|
|
|
'looks' => array((int) $id)
|
|
|
|
);
|
|
|
|
// Create the link
|
|
|
|
$link = 'index.php?option=com_demo&view=looks&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array();
|
|
|
|
//Create the link but don't add the id.
|
|
|
|
$link = 'index.php?option=com_demo&view=looks';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
|
|
|
$categories = JCategories::getInstance('demo.looks');
|
|
|
|
$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 Looking
|
|
|
|
*/
|
|
|
|
public static function getLookingRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array(
|
|
|
|
'looking' => array((int) $id)
|
|
|
|
);
|
|
|
|
// Create the link
|
|
|
|
$link = 'index.php?option=com_demo&view=looking&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array();
|
|
|
|
//Create the link but don't add the id.
|
|
|
|
$link = 'index.php?option=com_demo&view=looking';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
|
|
|
$categories = JCategories::getInstance('demo.looking');
|
|
|
|
$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;
|
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the URL route for demo 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
|
|
|
|
*/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function getCategoryRoute_keep_for_later($catid, $language = 0)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
if ($catid instanceof JCategoryNode)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
|
|
|
$id = $catid->id;
|
|
|
|
$category = $catid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Exception('First parameter must be JCategoryNode');
|
|
|
|
}
|
|
|
|
|
|
|
|
$views = array();
|
|
|
|
$view = $views[$category->extension];
|
|
|
|
|
|
|
|
if ($id < 1 || !($category instanceof JCategoryNode))
|
|
|
|
{
|
|
|
|
$link = '';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Create the link
|
|
|
|
$link = 'index.php?option=com_demo&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)
|
2015-12-03 02:17:44 +00:00
|
|
|
->select('a.sef AS sef')
|
|
|
|
->select('a.lang_code AS lang_code')
|
|
|
|
->from('#__languages AS a');
|
2015-08-24 20:22:07 +00:00
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
protected static function _findItem($needles = null,$type = null)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
$app = JFactory::getApplication();
|
|
|
|
$menus = $app->getMenu('site');
|
|
|
|
$language = isset($needles['language']) ? $needles['language'] : '*';
|
2015-08-24 20:22:07 +00:00
|
|
|
|
|
|
|
// Prepare the reverse lookup array.
|
|
|
|
if (!isset(self::$lookup[$language]))
|
|
|
|
{
|
|
|
|
self::$lookup[$language] = array();
|
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
$component = JComponentHelper::getComponent('com_demo');
|
2015-08-24 20:22:07 +00:00
|
|
|
|
|
|
|
$attributes = array('component_id');
|
2015-12-03 02:17:44 +00:00
|
|
|
$values = array($component->id);
|
2015-08-24 20:22:07 +00:00
|
|
|
|
|
|
|
if ($language != '*')
|
|
|
|
{
|
|
|
|
$attributes[] = 'language';
|
2015-12-03 02:17:44 +00:00
|
|
|
$values[] = array($needles['language'], '*');
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$items = $menus->getItems($attributes, $values);
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2015-08-24 20:22:07 +00:00
|
|
|
foreach ($items as $item)
|
|
|
|
{
|
|
|
|
if (isset($item->query) && isset($item->query['view']))
|
|
|
|
{
|
|
|
|
$view = $item->query['view'];
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2015-08-24 20:22:07 +00:00
|
|
|
if (!isset(self::$lookup[$language][$view]))
|
|
|
|
{
|
|
|
|
self::$lookup[$language][$view] = array();
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
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 != '*')
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
self::$lookup[$language][$view][$item->query['id']] = $item->id;
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2015-08-24 20:22:07 +00:00
|
|
|
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]))
|
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
return self::$lookup[$language][$view][(int) $id];
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
|
|
|
if ($type)
|
|
|
|
{
|
|
|
|
// Check if the global menu item has been set.
|
|
|
|
$params = JComponentHelper::getParams('com_demo');
|
|
|
|
if ($item = $params->get($type.'_menu', 0))
|
|
|
|
{
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
// Check if the active menuitem matches the requested language
|
2015-08-24 20:22:07 +00:00
|
|
|
$active = $menus->getActive();
|
2015-12-03 02:17:44 +00:00
|
|
|
|
|
|
|
if ($active
|
|
|
|
&& $active->component == 'com_demo'
|
|
|
|
&& ($language == '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled()))
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
|
|
|
return $active->id;
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
// If not found, return language specific home link
|
2015-08-24 20:22:07 +00:00
|
|
|
$default = $menus->getDefault($language);
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2015-08-24 20:22:07 +00:00
|
|
|
return !empty($default->id) ? $default->id : null;
|
|
|
|
}
|
|
|
|
}
|