forked from indupros/magebridge-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Url.php
165 lines (143 loc) · 5.16 KB
/
Url.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* MageBridge
*
* @author Yireo
* @package MageBridge
* @copyright Copyright 2012
* @license Yireo EULA (www.yireo.com)
* @link http://www.yireo.com
*/
class Yireo_MageBridge_Model_Rewrite_Url extends Mage_Core_Model_Url
{
/*
* Rewrite of original method
*
* @param null
* @return boolean
*/
public function getSecure()
{
if(Mage::helper('magebridge')->isBridge() == false) {
return parent::getSecure();
}
$request = Mage::getSingleton('magebridge/core')->getRequestUrl();
return $this->isSecurePage($request);
}
/*
* Rewrite of original method
*
* @param string $routePath
* @param array $routeParams
* @return string
*/
public function getUrl($routePath = null, $routeParams = null)
{
if(Mage::helper('magebridge')->isBridge() == false) {
return parent::getUrl($routePath, $routeParams);
}
// Set the original URL when dealing with direct download-links
$bridge_downloads = Mage::app()->getStore()->getConfig('magebridge/settings/bridge_downloads');
if($bridge_downloads == 0 && preg_match('/(downloadable|\*)\/download\/link/', $routePath)) {
return $this->setOriginalUrl($routePath, $routeParams);
}
// Initialize the parameters if needed
if(!is_array($routeParams)) {
$routeParams = array();
}
// Make sure the SID is always removed
$routeParams['_nosid'] = true;
// Call the original URL
$url = parent::getUrl($routePath, $routeParams);
// Correct HTTP/HTTPS
if($this->isSecurePage($routePath)) {
$url = str_replace('http://', 'https://', $url);
} else {
$url = str_replace('https://', 'http://', $url);
}
// Determine whether to add the Joomla! URL Suffix or not
static $append_suffix = null;
if($append_suffix == null) {
$joomla_sef_suffix = Mage::getSingleton('magebridge/core')->getMetaData('joomla_sef_suffix');
if($joomla_sef_suffix == 1) {
$append_suffix = true;
} else {
$append_suffix = false;
}
}
// Add the Joomla! URL Suffix if needed
if($append_suffix) {
if(!preg_match('/\/$/', $url) && !preg_match('/\.html$/', $url) && !preg_match('/\.html\?/', $url)) {
if(preg_match('/\?/', $url)) {
$url = preg_replace('/([^\/]+)\?/', '$1.html?', $url);
} else {
$url .= '.html';
}
}
}
return $url;
}
/*
* Helper method
*
* @param string $routePath
* @return boolean
*/
protected function isSecurePage($routePath = null)
{
$routePath = preg_replace('/\*\//', Mage::app()->getRequest()->getRequestedRouteName().'/', $routePath);
$routePath = preg_replace('/\/\*\//', Mage::app()->getRequest()->getRequestedControllerName().'/', $routePath);
$redirect_ssl = Mage::getSingleton('magebridge/core')->getMetaData('enforce_ssl');
$payment_urls = Mage::getSingleton('magebridge/core')->getMetaData('payment_urls');
$payment_urls = explode(',', $payment_urls);
$pages = array(
'checkout/',
'customer/',
'wishlist/',
);
if(!empty($payment_urls)) {
foreach($payment_urls as $payment_url) {
$payment_url = trim($payment_url);
if(!empty($payment_url)) {
$pages[] = $payment_url;
}
}
}
if($redirect_ssl == 1 || $redirect_ssl == 2) {
return true;
} elseif($redirect_ssl == 3) {
foreach($pages as $page) {
if(preg_match('/^'.str_replace('/', '\/', $page).'/', $routePath) == true) {
return true;
}
}
}
return false;
}
/*
* Helper method
*
* @param string $routePath
* @param array $routeParams
* @return string
*/
protected function setOriginalUrl($routePath = null, $routeParams = null)
{
// Get the original URLs from the registry
$original_urls = Mage::registry('original_urls');
// If this value is empty, it is not yet initialized
if(empty($original_urls)) {
return parent::getUrl($routePath, $routeParams);
}
// Fetch the result from this method
$rt = parent::getUrl($routePath, $routeParams);
// Replace the current URL with the original URL
$store = Mage::app()->getStore();
if($store->getConfig('web/secure/use_in_frontend') == 1 && isset($original_urls['web/secure/base_url'])) {
$rt = str_replace( $store->getConfig('web/secure/base_url'), $original_urls['web/secure/base_url'], $rt);
} elseif(isset($original_urls['web/unsecure/base_url'])) {
$rt = str_replace( $store->getConfig('web/unsecure/base_url'), $original_urls['web/unsecure/base_url'], $rt);
}
return $rt;
}
}