1: <?php
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: class Mage_Core_Model_Url extends Varien_Object
80: {
81: 82: 83:
84: const DEFAULT_CONTROLLER_NAME = 'index';
85:
86: 87: 88:
89: const DEFAULT_ACTION_NAME = 'index';
90:
91: 92: 93:
94: const XML_PATH_UNSECURE_URL = 'web/unsecure/base_url';
95: const XML_PATH_SECURE_URL = 'web/secure/base_url';
96: const XML_PATH_SECURE_IN_ADMIN = 'default/web/secure/use_in_adminhtml';
97: const XML_PATH_SECURE_IN_FRONT = 'web/secure/use_in_frontend';
98:
99: 100: 101: 102: 103:
104: static protected $_configDataCache;
105:
106: 107: 108: 109: 110:
111: static protected $_encryptedSessionId;
112:
113: 114: 115: 116: 117:
118: protected $_reservedRouteParams = array(
119: '_store', '_type', '_secure', '_forced_secure', '_use_rewrite', '_nosid',
120: '_absolute', '_current', '_direct', '_fragment', '_escape', '_query',
121: '_store_to_url'
122: );
123:
124: 125: 126: 127: 128:
129: protected $_request;
130:
131: 132: 133: 134: 135:
136: protected $_useSession;
137:
138: 139: 140:
141: protected function _construct()
142: {
143: $this->setStore(null);
144: }
145:
146: 147: 148: 149: 150: 151:
152: public function parseUrl($url)
153: {
154: $data = parse_url($url);
155: $parts = array(
156: 'scheme' => 'setScheme',
157: 'host' => 'setHost',
158: 'port' => 'setPort',
159: 'user' => 'setUser',
160: 'pass' => 'setPassword',
161: 'path' => 'setPath',
162: 'query' => 'setQuery',
163: 'fragment' => 'setFragment');
164:
165: foreach ($parts as $component => $method) {
166: if (isset($data[$component])) {
167: $this->$method($data[$component]);
168: }
169: }
170: return $this;
171: }
172:
173: 174: 175: 176: 177:
178: public function getDefaultControllerName()
179: {
180: return self::DEFAULT_CONTROLLER_NAME;
181: }
182:
183: 184: 185: 186: 187: 188:
189: public function setUseUrlCache($flag)
190: {
191: $this->setData('use_url_cache', $flag);
192: return $this;
193: }
194:
195: 196: 197: 198: 199: 200:
201: public function setUseSession($useSession)
202: {
203: $this->_useSession = (bool) $useSession;
204: return $this;
205: }
206:
207: 208: 209: 210: 211: 212:
213: public function setRouteFrontName($name)
214: {
215: $this->setData('route_front_name', $name);
216: return $this;
217: }
218:
219: 220: 221: 222: 223:
224: public function getUseSession()
225: {
226: if (is_null($this->_useSession)) {
227: $this->_useSession = Mage::app()->getUseSessionInUrl();
228: }
229: return $this->_useSession;
230: }
231:
232: 233: 234: 235: 236:
237: public function getDefaultActionName()
238: {
239: return self::DEFAULT_ACTION_NAME;
240: }
241:
242: 243: 244: 245: 246: 247: 248:
249: public function getConfigData($key, $prefix = null)
250: {
251: if (is_null($prefix)) {
252: $prefix = 'web/' . ($this->getSecure() ? 'secure' : 'unsecure').'/';
253: }
254: $path = $prefix . $key;
255:
256: $cacheId = $this->getStore()->getCode() . '/' . $path;
257: if (!isset(self::$_configDataCache[$cacheId])) {
258: $data = $this->getStore()->getConfig($path);
259: self::$_configDataCache[$cacheId] = $data;
260: }
261:
262: return self::$_configDataCache[$cacheId];
263: }
264:
265: 266: 267: 268: 269: 270:
271: public function setRequest(Zend_Controller_Request_Http $request)
272: {
273: $this->_request = $request;
274: return $this;
275: }
276:
277: 278: 279: 280: 281:
282: public function getRequest()
283: {
284: if (!$this->_request) {
285: $this->_request = Mage::app()->getRequest();
286: }
287: return $this->_request;
288: }
289:
290: 291: 292: 293: 294:
295: public function getType()
296: {
297: if (!$this->hasData('type')) {
298: $this->setData('type', Mage_Core_Model_Store::URL_TYPE_LINK);
299: }
300: return $this->_getData('type');
301: }
302:
303: 304: 305: 306: 307:
308: public function getSecure()
309: {
310: if ($this->hasData('secure_is_forced')) {
311: return (bool)$this->getData('secure');
312: }
313:
314: $store = $this->getStore();
315:
316: if ($store->isAdmin() && !$store->isAdminUrlSecure()) {
317: return false;
318: }
319: if (!$store->isAdmin() && !$store->isFrontUrlSecure()) {
320: return false;
321: }
322:
323: if (!$this->hasData('secure')) {
324: if ($this->getType() == Mage_Core_Model_Store::URL_TYPE_LINK && !$store->isAdmin()) {
325: $pathSecure = Mage::getConfig()->shouldUrlBeSecure('/' . $this->getActionPath());
326: $this->setData('secure', $pathSecure);
327: } else {
328: $this->setData('secure', true);
329: }
330: }
331: return $this->getData('secure');
332: }
333:
334: 335: 336: 337: 338: 339:
340: public function setStore($data)
341: {
342: $this->setData('store', Mage::app()->getStore($data));
343: return $this;
344: }
345:
346: 347: 348: 349: 350:
351: public function getStore()
352: {
353: if (!$this->hasData('store')) {
354: $this->setStore(null);
355: }
356: return $this->_getData('store');
357: }
358:
359: 360: 361: 362: 363: 364:
365: public function getBaseUrl($params = array())
366: {
367: if (isset($params['_store'])) {
368: $this->setStore($params['_store']);
369: }
370: if (isset($params['_type'])) {
371: $this->setType($params['_type']);
372: }
373: if (isset($params['_secure'])) {
374: $this->setSecure($params['_secure']);
375: }
376:
377: 378: 379:
380: if ($this->getType() == Mage_Core_Model_Store::URL_TYPE_LINK
381: && Mage::app()->getRequest()->isDirectAccessFrontendName($this->getRouteFrontName())) {
382: $this->setType(Mage_Core_Model_Store::URL_TYPE_DIRECT_LINK);
383: }
384:
385: return $this->getStore()->getBaseUrl($this->getType(), $this->getSecure());
386: }
387:
388: 389: 390: 391: 392: 393:
394: public function setRoutePath($data)
395: {
396: if ($this->_getData('route_path') == $data) {
397: return $this;
398: }
399:
400: $a = explode('/', $data);
401:
402: $route = array_shift($a);
403: if ('*' === $route) {
404: $route = $this->getRequest()->getRequestedRouteName();
405: }
406: $this->setRouteName($route);
407: $routePath = $route . '/';
408:
409: if (!empty($a)) {
410: $controller = array_shift($a);
411: if ('*' === $controller) {
412: $controller = $this->getRequest()->getRequestedControllerName();
413: }
414: $this->setControllerName($controller);
415: $routePath .= $controller . '/';
416: }
417:
418: if (!empty($a)) {
419: $action = array_shift($a);
420: if ('*' === $action) {
421: $action = $this->getRequest()->getRequestedActionName();
422: }
423: $this->setActionName($action);
424: $routePath .= $action . '/';
425: }
426:
427: if (!empty($a)) {
428: $this->unsetData('route_params');
429: while (!empty($a)) {
430: $key = array_shift($a);
431: if (!empty($a)) {
432: $value = array_shift($a);
433: $this->setRouteParam($key, $value);
434: $routePath .= $key . '/' . $value . '/';
435: }
436: }
437: }
438:
439: return $this;
440: }
441:
442: 443: 444: 445: 446:
447: public function getActionPath()
448: {
449: if (!$this->getRouteName()) {
450: return '';
451: }
452:
453: $hasParams = (bool) $this->getRouteParams();
454: $path = $this->getRouteFrontName() . '/';
455:
456: if ($this->getControllerName()) {
457: $path .= $this->getControllerName() . '/';
458: } elseif ($hasParams) {
459: $path .= $this->getDefaultControllerName() . '/';
460: }
461: if ($this->getActionName()) {
462: $path .= $this->getActionName() . '/';
463: } elseif ($hasParams) {
464: $path .= $this->getDefaultActionName() . '/';
465: }
466:
467: return $path;
468: }
469:
470: 471: 472: 473: 474: 475:
476: public function getRoutePath($routeParams = array())
477: {
478: if (!$this->hasData('route_path')) {
479: $routePath = $this->getRequest()->getAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS);
480: if (!empty($routeParams['_use_rewrite']) && ($routePath !== null)) {
481: $this->setData('route_path', $routePath);
482: return $routePath;
483: }
484: $routePath = $this->getActionPath();
485: if ($this->getRouteParams()) {
486: foreach ($this->getRouteParams() as $key=>$value) {
487: if (is_null($value) || false === $value || '' === $value || !is_scalar($value)) {
488: continue;
489: }
490: $routePath .= $key . '/' . $value . '/';
491: }
492: }
493: if ($routePath != '' && substr($routePath, -1, 1) !== '/') {
494: $routePath .= '/';
495: }
496: $this->setData('route_path', $routePath);
497: }
498: return $this->_getData('route_path');
499: }
500:
501: 502: 503: 504: 505: 506:
507: public function setRouteName($data)
508: {
509: if ($this->_getData('route_name') == $data) {
510: return $this;
511: }
512: $this->unsetData('route_front_name')
513: ->unsetData('route_path')
514: ->unsetData('controller_name')
515: ->unsetData('action_name')
516: ->unsetData('secure');
517: return $this->setData('route_name', $data);
518: }
519:
520: 521: 522: 523: 524:
525: public function getRouteFrontName()
526: {
527: if (!$this->hasData('route_front_name')) {
528: $routeName = $this->getRouteName();
529: $route = Mage::app()->getFrontController()->getRouterByRoute($routeName);
530: $frontName = $route->getFrontNameByRoute($routeName);
531:
532: $this->setRouteFrontName($frontName);
533: }
534:
535: return $this->_getData('route_front_name');
536: }
537:
538: 539: 540: 541: 542:
543: public function getRouteName()
544: {
545: return $this->_getData('route_name');
546: }
547:
548: 549: 550: 551: 552: 553: 554: 555:
556: public function setControllerName($data)
557: {
558: if ($this->_getData('controller_name') == $data) {
559: return $this;
560: }
561: $this->unsetData('route_path')->unsetData('action_name')->unsetData('secure');
562: return $this->setData('controller_name', $data);
563: }
564:
565: 566: 567: 568: 569:
570: public function getControllerName()
571: {
572: return $this->_getData('controller_name');
573: }
574:
575: 576: 577: 578: 579: 580: 581:
582: public function setActionName($data)
583: {
584: if ($this->_getData('action_name') == $data) {
585: return $this;
586: }
587: $this->unsetData('route_path');
588: return $this->setData('action_name', $data)->unsetData('secure');
589: }
590:
591: 592: 593: 594: 595:
596: public function getActionName()
597: {
598: return $this->_getData('action_name');
599: }
600:
601: 602: 603: 604: 605: 606: 607:
608: public function setRouteParams(array $data, $unsetOldParams = true)
609: {
610: if (isset($data['_type'])) {
611: $this->setType($data['_type']);
612: unset($data['_type']);
613: }
614:
615: if (isset($data['_store'])) {
616: $this->setStore($data['_store']);
617: unset($data['_store']);
618: }
619:
620: if (isset($data['_forced_secure'])) {
621: $this->setSecure((bool)$data['_forced_secure']);
622: $this->setSecureIsForced(true);
623: unset($data['_forced_secure']);
624: } elseif (isset($data['_secure'])) {
625: $this->setSecure((bool)$data['_secure']);
626: unset($data['_secure']);
627: }
628:
629: if (isset($data['_absolute'])) {
630: unset($data['_absolute']);
631: }
632:
633: if ($unsetOldParams) {
634: $this->unsetData('route_params');
635: }
636:
637: $this->setUseUrlCache(true);
638: if (isset($data['_current'])) {
639: if (is_array($data['_current'])) {
640: foreach ($data['_current'] as $key) {
641: if (array_key_exists($key, $data) || !$this->getRequest()->getUserParam($key)) {
642: continue;
643: }
644: $data[$key] = $this->getRequest()->getUserParam($key);
645: }
646: } elseif ($data['_current']) {
647: foreach ($this->getRequest()->getUserParams() as $key => $value) {
648: if (array_key_exists($key, $data) || $this->getRouteParam($key)) {
649: continue;
650: }
651: $data[$key] = $value;
652: }
653: foreach ($this->getRequest()->getQuery() as $key => $value) {
654: $this->setQueryParam($key, $value);
655: }
656: $this->setUseUrlCache(false);
657: }
658: unset($data['_current']);
659: }
660:
661: if (isset($data['_use_rewrite'])) {
662: unset($data['_use_rewrite']);
663: }
664:
665: if (isset($data['_store_to_url']) && (bool)$data['_store_to_url'] === true) {
666: if (!Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getStore())
667: && !Mage::app()->isSingleStoreMode()
668: ) {
669: $this->setQueryParam('___store', $this->getStore()->getCode());
670: }
671: }
672: unset($data['_store_to_url']);
673:
674: foreach ($data as $k => $v) {
675: $this->setRouteParam($k, $v);
676: }
677:
678: return $this;
679: }
680:
681: 682: 683: 684: 685:
686: public function getRouteParams()
687: {
688: return $this->_getData('route_params');
689: }
690:
691: 692: 693: 694: 695: 696: 697:
698: public function setRouteParam($key, $data)
699: {
700: $params = $this->_getData('route_params');
701: if (isset($params[$key]) && $params[$key] == $data) {
702: return $this;
703: }
704: $params[$key] = $data;
705: $this->unsetData('route_path');
706: return $this->setData('route_params', $params);
707: }
708:
709: 710: 711: 712: 713: 714:
715: public function getRouteParam($key)
716: {
717: return $this->getData('route_params', $key);
718: }
719:
720: 721: 722: 723: 724: 725: 726: 727:
728: public function getRouteUrl($routePath = null, $routeParams = null)
729: {
730: $this->unsetData('route_params');
731:
732: if (isset($routeParams['_direct'])) {
733: if (is_array($routeParams)) {
734: $this->setRouteParams($routeParams, false);
735: }
736: return $this->getBaseUrl() . $routeParams['_direct'];
737: }
738:
739: if (!is_null($routePath)) {
740: $this->setRoutePath($routePath);
741: }
742: if (is_array($routeParams)) {
743: $this->setRouteParams($routeParams, false);
744: }
745:
746: $url = $this->getBaseUrl() . $this->getRoutePath($routeParams);
747: return $url;
748: }
749:
750: 751: 752: 753: 754:
755: public function checkCookieDomains()
756: {
757: $hostArr = explode(':', $this->getRequest()->getServer('HTTP_HOST'));
758: if ($hostArr[0] !== $this->getHost()) {
759: $session = Mage::getSingleton('core/session');
760: if (!$session->isValidForHost($this->getHost())) {
761: if (!self::$_encryptedSessionId) {
762: $helper = Mage::helper('core');
763: if (!$helper) {
764: return $this;
765: }
766: self::$_encryptedSessionId = $session->getEncryptedSessionId();
767: }
768: $this->setQueryParam($session->getSessionIdQueryParam(), self::$_encryptedSessionId);
769: }
770: }
771: return $this;
772: }
773:
774: 775: 776: 777: 778:
779: public function addSessionParam()
780: {
781: $session = Mage::getSingleton('core/session');
782:
783: if (!self::$_encryptedSessionId) {
784: $helper = Mage::helper('core');
785: if (!$helper) {
786: return $this;
787: }
788: self::$_encryptedSessionId = $session->getEncryptedSessionId();
789: }
790: $this->setQueryParam($session->getSessionIdQueryParam(), self::$_encryptedSessionId);
791: return $this;
792: }
793:
794: 795: 796: 797: 798: 799:
800: public function setQuery($data)
801: {
802: if ($this->_getData('query') == $data) {
803: return $this;
804: }
805: $this->unsetData('query_params');
806: return $this->setData('query', $data);
807: }
808:
809: 810: 811: 812: 813: 814:
815: public function getQuery($escape = false)
816: {
817: if (!$this->hasData('query')) {
818: $query = '';
819: $params = $this->getQueryParams();
820: if (is_array($params)) {
821: ksort($params);
822: $query = http_build_query($params, '', $escape ? '&' : '&');
823: }
824: $this->setData('query', $query);
825: }
826: return $this->_getData('query');
827: }
828:
829: 830: 831: 832: 833: 834:
835: public function setQueryParams(array $data)
836: {
837: $this->unsetData('query');
838:
839: if ($this->_getData('query_params') == $data) {
840: return $this;
841: }
842:
843: $params = $this->_getData('query_params');
844: if (!is_array($params)) {
845: $params = array();
846: }
847: foreach ($data as $param => $value) {
848: $params[$param] = $value;
849: }
850: $this->setData('query_params', $params);
851:
852: return $this;
853: }
854:
855: 856: 857: 858: 859:
860: public function purgeQueryParams()
861: {
862: $this->setData('query_params', array());
863: return $this;
864: }
865:
866: 867: 868: 869: 870:
871: public function getQueryParams()
872: {
873: if (!$this->hasData('query_params')) {
874: $params = array();
875: if ($this->_getData('query')) {
876: foreach (explode('&', $this->_getData('query')) as $param) {
877: $paramArr = explode('=', $param);
878: $params[$paramArr[0]] = urldecode($paramArr[1]);
879: }
880: }
881: $this->setData('query_params', $params);
882: }
883: return $this->_getData('query_params');
884: }
885:
886: 887: 888: 889: 890: 891: 892:
893: public function setQueryParam($key, $data)
894: {
895: $params = $this->getQueryParams();
896: if (isset($params[$key]) && $params[$key] == $data) {
897: return $this;
898: }
899: $params[$key] = $data;
900: $this->unsetData('query');
901: return $this->setData('query_params', $params);
902: }
903:
904: 905: 906: 907: 908: 909:
910: public function getQueryParam($key)
911: {
912: if (!$this->hasData('query_params')) {
913: $this->getQueryParams();
914: }
915: return $this->getData('query_params', $key);
916: }
917:
918: 919: 920: 921: 922: 923:
924: public function setFragment($data)
925: {
926: return $this->setData('fragment', $data);
927: }
928:
929: 930: 931: 932: 933:
934: public function getFragment()
935: {
936: return $this->_getData('fragment');
937: }
938:
939: 940: 941: 942: 943: 944: 945:
946: public function getUrl($routePath = null, $routeParams = null)
947: {
948: $escapeQuery = false;
949:
950: 951: 952: 953: 954:
955: if (isset($routeParams['_fragment'])) {
956: $this->setFragment($routeParams['_fragment']);
957: unset($routeParams['_fragment']);
958: }
959:
960: if (isset($routeParams['_escape'])) {
961: $escapeQuery = $routeParams['_escape'];
962: unset($routeParams['_escape']);
963: }
964:
965: $query = null;
966: if (isset($routeParams['_query'])) {
967: $this->purgeQueryParams();
968: $query = $routeParams['_query'];
969: unset($routeParams['_query']);
970: }
971:
972: $noSid = null;
973: if (isset($routeParams['_nosid'])) {
974: $noSid = (bool)$routeParams['_nosid'];
975: unset($routeParams['_nosid']);
976: }
977: $url = $this->getRouteUrl($routePath, $routeParams);
978: 979: 980:
981: if ($query !== null) {
982: if (is_string($query)) {
983: $this->setQuery($query);
984: } elseif (is_array($query)) {
985: $this->setQueryParams($query, !empty($routeParams['_current']));
986: }
987: if ($query === false) {
988: $this->setQueryParams(array());
989: }
990: }
991:
992: if ($noSid !== true) {
993: $this->_prepareSessionUrl($url);
994: }
995:
996: $query = $this->getQuery($escapeQuery);
997: if ($query) {
998: $mark = (strpos($url, '?') === false) ? '?' : ($escapeQuery ? '&' : '&');
999: $url .= $mark . $query;
1000: }
1001:
1002: if ($this->getFragment()) {
1003: $url .= '#' . $this->getFragment();
1004: }
1005:
1006: return $this->escape($url);
1007: }
1008:
1009: 1010: 1011: 1012: 1013: 1014: 1015:
1016: protected function _prepareSessionUrl($url)
1017: {
1018: return $this->_prepareSessionUrlWithParams($url, array());
1019: }
1020:
1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028:
1029: protected function _prepareSessionUrlWithParams($url, array $params)
1030: {
1031: if (!$this->getUseSession()) {
1032: return $this;
1033: }
1034:
1035:
1036: $session = Mage::getSingleton('core/session', $params);
1037:
1038: $sessionId = $session->getSessionIdForHost($url);
1039: if (Mage::app()->getUseSessionVar() && !$sessionId) {
1040: $this->setQueryParam('___SID', $this->getSecure() ? 'S' : 'U');
1041: } else if ($sessionId) {
1042: $this->setQueryParam($session->getSessionIdQueryParam(), $sessionId);
1043: }
1044: return $this;
1045: }
1046:
1047: 1048: 1049: 1050: 1051: 1052:
1053: public function getRebuiltUrl($url)
1054: {
1055: $this->parseUrl($url);
1056: $port = $this->getPort();
1057: if ($port) {
1058: $port = ':' . $port;
1059: } else {
1060: $port = '';
1061: }
1062: $url = $this->getScheme() . '://' . $this->getHost() . $port . $this->getPath();
1063:
1064: $this->_prepareSessionUrl($url);
1065:
1066: $query = $this->getQuery();
1067: if ($query) {
1068: $url .= '?' . $query;
1069: }
1070:
1071: $fragment = $this->getFragment();
1072: if ($fragment) {
1073: $url .= '#' . $fragment;
1074: }
1075:
1076: return $this->escape($url);
1077: }
1078:
1079: 1080: 1081: 1082: 1083: 1084:
1085: public function escape($value)
1086: {
1087: $value = str_replace('"', '%22', $value);
1088: $value = str_replace("'", '%27', $value);
1089: $value = str_replace('>', '%3E', $value);
1090: $value = str_replace('<', '%3C', $value);
1091: return $value;
1092: }
1093:
1094: 1095: 1096: 1097: 1098: 1099: 1100:
1101: public function getDirectUrl($url, $params = array()) {
1102: $params['_direct'] = $url;
1103: return $this->getUrl('', $params);
1104: }
1105:
1106: 1107: 1108: 1109: 1110: 1111:
1112: public function sessionUrlVar($html)
1113: {
1114: return preg_replace_callback('#(\?|&|&)___SID=([SU])(&|&)?#',
1115: array($this, "sessionVarCallback"), $html);
1116: }
1117:
1118: 1119: 1120: 1121: 1122: 1123:
1124: public function useSessionIdForUrl($secure = false)
1125: {
1126: $key = 'use_session_id_for_url_' . (int) $secure;
1127: if (is_null($this->getData($key))) {
1128: $httpHost = Mage::app()->getFrontController()->getRequest()->getHttpHost();
1129: $urlHost = parse_url(Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $secure),
1130: PHP_URL_HOST);
1131:
1132: if ($httpHost != $urlHost) {
1133: $this->setData($key, true);
1134: } else {
1135: $this->setData($key, false);
1136: }
1137: }
1138: return $this->getData($key);
1139: }
1140:
1141: 1142: 1143: 1144: 1145: 1146:
1147: public function sessionVarCallback($match)
1148: {
1149: if ($this->useSessionIdForUrl($match[2] == 'S' ? true : false)) {
1150: $session = Mage::getSingleton('core/session');
1151:
1152: return $match[1]
1153: . $session->getSessionIdQueryParam()
1154: . '=' . $session->getEncryptedSessionId()
1155: . (isset($match[3]) ? $match[3] : '');
1156: } else {
1157: if ($match[1] == '?' && isset($match[3])) {
1158: return '?';
1159: } elseif ($match[1] == '?' && !isset($match[3])) {
1160: return '';
1161: } elseif (($match[1] == '&' || $match[1] == '&') && !isset($match[3])) {
1162: return '';
1163: } elseif (($match[1] == '&' || $match[1] == '&') && isset($match[3])) {
1164: return $match[3];
1165: }
1166: }
1167: return '';
1168: }
1169:
1170: 1171: 1172: 1173: 1174:
1175: public function isOwnOriginUrl()
1176: {
1177: $storeDomains = array();
1178: $referer = parse_url(Mage::app()->getFrontController()->getRequest()->getServer('HTTP_REFERER'), PHP_URL_HOST);
1179: foreach (Mage::app()->getStores() as $store) {
1180: $storeDomains[] = parse_url($store->getBaseUrl(), PHP_URL_HOST);
1181: $storeDomains[] = parse_url($store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true), PHP_URL_HOST);
1182: }
1183: $storeDomains = array_unique($storeDomains);
1184: if (empty($referer) || in_array($referer, $storeDomains)) {
1185: return true;
1186: }
1187: return false;
1188: }
1189:
1190: 1191: 1192: 1193: 1194: 1195: 1196:
1197: public function getRedirectUrl($url)
1198: {
1199: $this->_prepareSessionUrlWithParams($url, array(
1200: 'name' => Mage_Core_Controller_Front_Action::SESSION_NAMESPACE
1201: ));
1202:
1203: $query = $this->getQuery(false);
1204: if ($query) {
1205: $url .= (strpos($url, '?') === false ? '?' : '&') . $query;
1206: }
1207:
1208: return $url;
1209: }
1210: }
1211: