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: class Mage_Adminhtml_Model_Url extends Mage_Core_Model_Url
27: {
28: 29: 30:
31: const SECRET_KEY_PARAM_NAME = 'key';
32:
33: 34: 35: 36: 37:
38: public function getSecure()
39: {
40: if ($this->hasData('secure_is_forced')) {
41: return $this->getData('secure');
42: }
43: return Mage::getStoreConfigFlag('web/secure/use_in_adminhtml');
44: }
45:
46: 47: 48: 49: 50:
51: public function setRouteParams(array $data, $unsetOldParams=true)
52: {
53: if (isset($data['_nosecret'])) {
54: $this->setNoSecret(true);
55: unset($data['_nosecret']);
56: } else {
57: $this->setNoSecret(false);
58: }
59:
60: return parent::setRouteParams($data, $unsetOldParams);
61: }
62:
63: 64: 65: 66: 67: 68: 69:
70: public function getUrl($routePath=null, $routeParams=null)
71: {
72: $cacheSecretKey = false;
73: if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) {
74: unset($routeParams['_cache_secret_key']);
75: $cacheSecretKey = true;
76: }
77:
78: $result = parent::getUrl($routePath, $routeParams);
79: if (!$this->useSecretKey()) {
80: return $result;
81: }
82:
83: $_route = $this->getRouteName() ? $this->getRouteName() : '*';
84: $_controller = $this->getControllerName() ? $this->getControllerName() : $this->getDefaultControllerName();
85: $_action = $this->getActionName() ? $this->getActionName() : $this->getDefaultActionName();
86:
87: if ($cacheSecretKey) {
88: $secret = array(self::SECRET_KEY_PARAM_NAME => "\${$_controller}/{$_action}\$");
89: }
90: else {
91: $secret = array(self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($_controller, $_action));
92: }
93: if (is_array($routeParams)) {
94: $routeParams = array_merge($secret, $routeParams);
95: } else {
96: $routeParams = $secret;
97: }
98: if (is_array($this->getRouteParams())) {
99: $routeParams = array_merge($this->getRouteParams(), $routeParams);
100: }
101:
102: return parent::getUrl("{$_route}/{$_controller}/{$_action}", $routeParams);
103: }
104:
105: 106: 107: 108: 109: 110: 111:
112: public function getSecretKey($controller = null, $action = null)
113: {
114: $salt = Mage::getSingleton('core/session')->getFormKey();
115:
116: $p = explode('/', trim($this->getRequest()->getOriginalPathInfo(), '/'));
117: if (!$controller) {
118: $controller = !empty($p[1]) ? $p[1] : $this->getRequest()->getControllerName();
119: }
120: if (!$action) {
121: $action = !empty($p[2]) ? $p[2] : $this->getRequest()->getActionName();
122: }
123:
124: $secret = $controller . $action . $salt;
125: return Mage::helper('core')->getHash($secret);
126: }
127:
128: 129: 130: 131: 132:
133: public function useSecretKey()
134: {
135: return Mage::getStoreConfigFlag('admin/security/use_form_key') && !$this->getNoSecret();
136: }
137:
138: 139: 140: 141: 142:
143: public function turnOnSecretKey()
144: {
145: $this->setNoSecret(false);
146: return $this;
147: }
148:
149: 150: 151: 152: 153:
154: public function turnOffSecretKey()
155: {
156: $this->setNoSecret(true);
157: return $this;
158: }
159:
160: 161: 162: 163: 164:
165: public function renewSecretUrls()
166: {
167: Mage::app()->cleanCache(array(Mage_Adminhtml_Block_Page_Menu::CACHE_TAGS));
168: }
169: }
170: