forked from citruscart/citruscart
/
route.php
executable file
·120 lines (102 loc) · 3.45 KB
/
route.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/*------------------------------------------------------------------------
# com_citruscart
# ------------------------------------------------------------------------
# author Citruscart Team - Citruscart http://www.citruscart.com
# copyright Copyright (C) 2014 Citruscart.com All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://citruscart.com
# Technical Support: Forum - http://citruscart.com/forum/index.html
# Fork of Tienda
# @license GNU/GPL Based on Tienda by Dioscouri Design http://www.dioscouri.com.
-------------------------------------------------------------------------*/
/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');
class DSCRoute
{
/**
* Translates an internal Joomla URL to a humanly readible URL.
*
* @param string $url Absolute or Relative URI to Joomla resource.
* @param boolean $xhtml Replace & by & for XML compilance.
* @param integer $ssl Secure state for the resolved URI.
* 1: Make URI secure using global secure site URI.
* 0: Leave URI in the same secure state as it was passed to the function.
* -1: Make URI unsecure using the global unsecure site URI.
*
* @return The translated humanly readible URL.
*
* @since 11.1
*/
public static function _($url, $xhtml = true, $ssl = null, $findItemid = true)
{
// Get the router.
$app = JFactory::getApplication();
$router = $app->getRouter();
// Make sure that we have our router
if (!$router)
{
return null;
}
if ((strpos($url, '&') !== 0) && (strpos($url, 'index.php') !== 0))
{
return $url;
}
//TODO do better Itemid check so we can check if actually has a value
if(!strpos($url, 'Itemid=') && $findItemid) {
$itemid = DSCRoute::findItemid($url);
if($itemid)
$url = $url . '&Itemid='.$itemid ;
}
// Build route.
$uri = $router->build($url);
$url = $uri->__toString(array('path', 'query', 'fragment'));
// Replace spaces.
$url = preg_replace('/\s/u', '%20', $url);
/*
* Get the secure/unsecure URLs.
*
* If the first 5 characters of the BASE are 'https', then we are on an ssl connection over
* https and need to set our secure URL to the current request URL, if not, and the scheme is
* 'http', then we need to do a quick string manipulation to switch schemes.
*/
if ((int) $ssl)
{
$uri = JURI::getInstance();
// Get additional parts.
static $prefix;
if (!$prefix)
{
$prefix = $uri->__toString(array('host', 'port'));
}
// Determine which scheme we want.
$scheme = ((int) $ssl === 1) ? 'https' : 'http';
// Make sure our URL path begins with a slash.
if (!preg_match('#^/#', $url))
{
$url = '/' . $url;
}
// Build the URL.
$url = $scheme . '://' . $prefix . $url;
}
if ($xhtml)
{
$url = htmlspecialchars($url);
}
return $url;
}
public static function findItemid ($url) {
//TODO add CACHING
$db = JFactory::getDBO();
$query = NEW DSCQuery();
$query->select('*');
$query->from(' #__menu as m');
$query->where(' m.link = '. $db->q( $url ) );
$query->where(' m.client_id = '. $db->q(0)); //means frontend only
$query->where(' m.published = '. $db->q( 1 )); //means turned on
$db->setQuery($query, 0 , 1);
$item = $db->loadObject();
if ( $item)
return $item->id;
}
}