2021-03-05 03:08:47 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package Joomla.Component.Builder
|
|
|
|
*
|
|
|
|
* @created 30th April, 2015
|
2024-03-09 19:47:28 +00:00
|
|
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
|
|
|
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
2021-03-05 03:08:47 +00:00
|
|
|
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
?>
|
|
|
|
###BOM###
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
2024-03-09 19:47:28 +00:00
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
use Joomla\CMS\Component\ComponentHelper;
|
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
/**
|
|
|
|
* Routing class from com_###component###
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
class ###Component###Router extends JComponentRouterBase
|
2024-03-09 19:47:28 +00:00
|
|
|
{
|
2021-03-05 03:08:47 +00:00
|
|
|
/**
|
|
|
|
* Build the route for the com_###component### component
|
|
|
|
*
|
|
|
|
* @param array &$query An array of URL arguments
|
|
|
|
*
|
|
|
|
* @return array The URL arguments to use to assemble the subsequent URL.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
public function build(&$query)
|
|
|
|
{
|
2024-03-09 19:47:28 +00:00
|
|
|
$segments = [];
|
2021-03-05 03:08:47 +00:00
|
|
|
|
|
|
|
// Get a menu item based on Itemid or currently active
|
2024-03-09 19:47:28 +00:00
|
|
|
$params = ComponentHelper::getParams('com_###component###');
|
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
if (empty($query['Itemid']))
|
|
|
|
{
|
|
|
|
$menuItem = $this->menu->getActive();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$menuItem = $this->menu->getItem($query['Itemid']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view'];
|
|
|
|
$mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id'];
|
|
|
|
|
|
|
|
if (isset($query['view']))
|
|
|
|
{
|
|
|
|
$view = $query['view'];
|
|
|
|
|
2021-06-14 11:02:12 +00:00
|
|
|
if (empty($query['Itemid']) && !(isset($view) && isset($query['id']) && ###ROUTER_BUILD_VIEWS###))
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
|
|
|
$segments[] = $query['view'];
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($query['view']);
|
|
|
|
}
|
2024-03-09 19:47:28 +00:00
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
// Are we dealing with a item that is attached to a menu item?
|
|
|
|
if (isset($view) && ($mView == $view) and (isset($query['id'])) and ($mId == (int) $query['id']))
|
|
|
|
{
|
|
|
|
unset($query['view']);
|
|
|
|
unset($query['catid']);
|
|
|
|
unset($query['id']);
|
|
|
|
return $segments;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($view) && isset($query['id']) && ###ROUTER_BUILD_VIEWS###)
|
|
|
|
{
|
|
|
|
if ($mId != (int) $query['id'] || $mView != $view)
|
|
|
|
{
|
|
|
|
if (###ROUTER_BUILD_VIEWS###)
|
|
|
|
{
|
|
|
|
$segments[] = $view;
|
|
|
|
$id = explode(':', $query['id']);
|
|
|
|
if (count($id) == 2)
|
|
|
|
{
|
|
|
|
$segments[] = $id[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$segments[] = $id[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($query['id']);
|
|
|
|
}
|
2024-03-09 19:47:28 +00:00
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
$total = count($segments);
|
|
|
|
|
|
|
|
for ($i = 0; $i < $total; $i++)
|
|
|
|
{
|
|
|
|
$segments[$i] = str_replace(':', '-', $segments[$i]);
|
|
|
|
}
|
|
|
|
|
2024-03-09 19:47:28 +00:00
|
|
|
return $segments;
|
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the segments of a URL.
|
|
|
|
*
|
|
|
|
* @param array &$segments The segments of the URL to parse.
|
|
|
|
*
|
|
|
|
* @return array The URL attributes to be used by the application.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
public function parse(&$segments)
|
2024-03-09 19:47:28 +00:00
|
|
|
{
|
2021-03-05 03:08:47 +00:00
|
|
|
$count = count($segments);
|
2024-03-09 19:47:28 +00:00
|
|
|
$vars = [];
|
|
|
|
|
2021-12-21 14:44:50 +00:00
|
|
|
// Handle View and Identifier
|
2021-03-05 03:08:47 +00:00
|
|
|
switch($segments[0])
|
|
|
|
{###ROUTER_PARSE_SWITCH###
|
|
|
|
}
|
|
|
|
|
|
|
|
return $vars;
|
2024-03-09 19:47:28 +00:00
|
|
|
}
|
2021-03-05 03:08:47 +00:00
|
|
|
|
|
|
|
protected function getVar($table, $where = null, $whereString = null, $what = null, $category = false, $operator = '=', $main = '###component###')
|
|
|
|
{
|
|
|
|
if(!$where || !$what || !$whereString)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Get a db connection.
|
2024-03-09 19:47:28 +00:00
|
|
|
$db = Factory::getDbo();
|
2021-03-05 03:08:47 +00:00
|
|
|
// Create a new query object.
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
|
|
|
$query->select($db->quoteName(array($what)));
|
|
|
|
if ('categories' == $table || 'category' == $table || $category)
|
|
|
|
{
|
|
|
|
$getTable = '#__categories';
|
|
|
|
$query->from($db->quoteName($getTable));
|
|
|
|
// we need this to target the components categories (TODO will keep an eye on this)
|
|
|
|
$query->where($db->quoteName('extension') . ' LIKE '. $db->quote((string)'com_' . $main . '%'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we must check if the table exist (TODO not ideal)
|
|
|
|
$tables = $db->getTableList();
|
2024-03-09 19:47:28 +00:00
|
|
|
$app = Factory::getApplication();
|
2021-03-05 03:08:47 +00:00
|
|
|
$prefix = $app->get('dbprefix');
|
|
|
|
$check = $prefix.$main.'_'.$table;
|
|
|
|
if (in_array($check, $tables))
|
|
|
|
{
|
|
|
|
$getTable = '#__'.$main.'_'.$table;
|
|
|
|
$query->from($db->quoteName($getTable));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_numeric($where))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
elseif ($this->checkString($where))
|
|
|
|
{
|
|
|
|
// we must first check if this table has the column
|
|
|
|
$columns = $db->getTableColumns($getTable);
|
|
|
|
if (isset($columns[$whereString]))
|
|
|
|
{
|
|
|
|
$query->where($db->quoteName($whereString) . ' '.$operator.' '. $db->quote((string)$where));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
if ($db->getNumRows())
|
|
|
|
{
|
|
|
|
return $db->loadResult();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2024-03-09 19:47:28 +00:00
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
protected function checkString($string)
|
|
|
|
{
|
|
|
|
if (isset($string) && is_string($string) && strlen($string) > 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ###Component###BuildRoute(&$query)
|
|
|
|
{
|
|
|
|
$router = new ###Component###Router;
|
2024-03-09 19:47:28 +00:00
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
return $router->build($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ###Component###ParseRoute($segments)
|
|
|
|
{
|
|
|
|
$router = new ###Component###Router;
|
|
|
|
|
|
|
|
return $router->parse($segments);
|
2016-01-30 20:28:43 +00:00
|
|
|
}
|