00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class Mage_Adminhtml_Model_Url extends Mage_Core_Model_Url
00027 {
00028
00029
00030
00031 const SECRET_KEY_PARAM_NAME = 'key';
00032
00033
00034
00035
00036
00037
00038 public function getSecure()
00039 {
00040 if ($this->hasData('secure_is_forced')) {
00041 return $this->getData('secure');
00042 }
00043 return Mage::getStoreConfigFlag('web/secure/use_in_adminhtml');
00044 }
00045
00046
00047
00048
00049
00050
00051 public function setRouteParams(array $data, $unsetOldParams=true)
00052 {
00053 if (isset($data['_nosecret'])) {
00054 $this->setNoSecret(true);
00055 unset($data['_nosecret']);
00056 } else {
00057 $this->setNoSecret(false);
00058 }
00059
00060 return parent::setRouteParams($data, $unsetOldParams);
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070 public function getUrl($routePath=null, $routeParams=null)
00071 {
00072 $result = parent::getUrl($routePath, $routeParams);
00073
00074 if (!$this->useSecretKey()) {
00075 return $result;
00076 }
00077
00078 $_route = $this->getRouteName() ? $this->getRouteName() : '*';
00079 $_controller = $this->getControllerName() ? $this->getControllerName() : $this->getDefaultControllerName();
00080 $_action = $this->getActionName() ? $this->getActionName() : $this->getDefaultActionName();
00081 $secret = array(self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($_controller, $_action));
00082 if (is_array($routeParams)) {
00083 $routeParams = array_merge($secret, $routeParams);
00084 } else {
00085 $routeParams = $secret;
00086 }
00087 if (is_array($this->getRouteParams())) {
00088 $routeParams = array_merge($this->getRouteParams(), $routeParams);
00089 }
00090 return parent::getUrl("{$_route}/{$_controller}/{$_action}", $routeParams);
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100 public function getSecretKey($controller = null, $action = null)
00101 {
00102 $salt = Mage::getSingleton('core/session')->getFormKey();
00103
00104 $p = explode('/', trim($this->getRequest()->getOriginalPathInfo(), '/'));
00105 if (!$controller) {
00106 $controller = !empty($p[1]) ? $p[1] : $this->getRequest()->getControllerName();
00107 }
00108 if (!$action) {
00109 $action = !empty($p[2]) ? $p[2] : $this->getRequest()->getActionName();
00110 }
00111
00112 $secret = $controller . $action . $salt;
00113 return Mage::helper('core')->getHash($secret);
00114 }
00115
00116
00117
00118
00119
00120
00121 public function useSecretKey()
00122 {
00123 return Mage::getStoreConfigFlag('admin/security/use_form_key') && !$this->getNoSecret();
00124 }
00125
00126
00127
00128
00129
00130
00131 public function turnOnSecretKey()
00132 {
00133 $this->setNoSecret(false);
00134 return $this;
00135 }
00136
00137
00138
00139
00140
00141
00142 public function turnOffSecretKey()
00143 {
00144 $this->setNoSecret(true);
00145 return $this;
00146 }
00147
00148
00149
00150
00151
00152
00153 public function renewSecretUrls()
00154 {
00155 Mage::app()->cleanCache(array(Mage_Adminhtml_Block_Page_Menu::CACHE_TAGS));
00156 }
00157 }