Component-Builder/admin/compiler/joomla_3/router.php

228 lines
6.1 KiB
PHP
Raw Normal View History

2016-01-30 20:28:43 +00:00
<?php
/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
__ __ _ _____ _ _ __ __ _ _ _
\ \ / / | | | __ \ | | | | | \/ | | | | | | |
\ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
\ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
\ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
\/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
| |
|_|
/-------------------------------------------------------------------------------------------------------------------------------/
@package Component Builder
@subpackage componentbuilder.php
@author Llewellyn van der Merwe <https://www.vdm.io/joomla-component-builder>
@my wife Roline van der Merwe <http://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
Builds Complex Joomla Components
/-----------------------------------------------------------------------------------------------------------------------------*/
// 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');
/**
* Routing class from com_###component###
*
* @since 3.3
*/
class ###Component###Router extends JComponentRouterBase
{
/**
* 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)
{
$segments = array();
// Get a menu item based on Itemid or currently active
$params = JComponentHelper::getParams('com_###component###');
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'];
if (empty($query['Itemid']))
{
$segments[] = $query['view'];
}
unset($query['view']);
}
// 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']);
}
$total = count($segments);
for ($i = 0; $i < $total; $i++)
{
$segments[$i] = str_replace(':', '-', $segments[$i]);
}
return $segments;
}
/**
* 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)
{
2016-01-30 20:28:43 +00:00
$count = count($segments);
$vars = array();
2016-01-30 20:28:43 +00:00
//Handle View and Identifier
switch($segments[0])
{###ROUTER_PARSE_SWITCH###
}
return $vars;
}
protected function getVar($table, $where = null, $whereString = null, $what = null, $category = false, $operator = '=', $main = '###component###')
2016-01-30 20:28:43 +00:00
{
if(!$where || !$what || !$whereString)
2016-01-30 20:28:43 +00:00
{
return false;
2016-01-30 20:28:43 +00:00
}
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query->select($db->quoteName(array($what)));
if ('categories' == $table || 'category' == $table || $category)
2016-01-30 20:28:43 +00:00
{
$getTable = '#__categories';
$query->from($db->quoteName($getTable));
2016-01-30 20:28:43 +00:00
}
else
{
// we must check if the table exist (TODO not ideal)
$tables = $db->getTableList();
$app = JFactory::getApplication();
$prefix = $app->get('dbprefix');
$check = $prefix.$main.'_'.$table;
if (in_array($check, $tables))
{
$getTable = '#__'.$main.'_'.$table;
$query->from($db->quoteName($getTable));
}
else
{
return false;
}
2016-01-30 20:28:43 +00:00
}
if (is_numeric($where))
{
return false;
2016-01-30 20:28:43 +00:00
}
elseif ($this->checkString($where))
2016-01-30 20:28:43 +00:00
{
// 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;
}
2016-01-30 20:28:43 +00:00
}
else
{
return false;
}
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return $db->loadResult();
}
return false;
}
protected function checkString($string)
{
if (isset($string) && is_string($string) && strlen($string) > 0)
{
return true;
}
return false;
}
2016-01-30 20:28:43 +00:00
}
function ###Component###BuildRoute(&$query)
{
$router = new ###Component###Router;
return $router->build($query);
}
function ###Component###ParseRoute($segments)
{
$router = new ContentRouter;
return $router->parse($segments);
}