Public Member Functions | |
loadByRequestPath ($path) | |
loadByIdPath ($path) | |
loadByTags ($tags) | |
hasOption ($key) | |
addTag ($tags) | |
removeTag ($tags) | |
rewrite (Zend_Controller_Request_Http $request=null, Zend_Controller_Response_Http $response=null) | |
getStoreId () | |
Public Attributes | |
const | TYPE_CATEGORY = 1 |
const | TYPE_PRODUCT = 2 |
const | TYPE_CUSTOM = 3 |
const | REWRITE_REQUEST_PATH_ALIAS = 'rewrite_request_path' |
Protected Member Functions | |
_construct () | |
_getQueryString () |
Definition at line 36 of file Rewrite.php.
_construct | ( | ) | [protected] |
Enter description here...
Reimplemented from Varien_Object.
Definition at line 43 of file Rewrite.php.
00044 { 00045 $this->_init('core/url_rewrite'); 00046 }
_getQueryString | ( | ) | [protected] |
Definition at line 255 of file Rewrite.php.
00256 { 00257 if (!empty($_SERVER['QUERY_STRING'])) { 00258 $queryParams = array(); 00259 parse_str($_SERVER['QUERY_STRING'], $queryParams); 00260 $hasChanges = false; 00261 foreach ($queryParams as $key=>$value) { 00262 if (substr($key, 0, 3) === '___') { 00263 unset($queryParams[$key]); 00264 $hasChanges = true; 00265 } 00266 } 00267 if ($hasChanges) { 00268 return http_build_query($queryParams); 00269 } 00270 else { 00271 return $_SERVER['QUERY_STRING']; 00272 } 00273 } 00274 return false; 00275 }
addTag | ( | $ | tags | ) |
Definition at line 115 of file Rewrite.php.
00116 { 00117 $curTags = $this->getTags(); 00118 00119 $addTags = is_array($tags) ? $tags : explode(',', $tags); 00120 00121 foreach ($addTags as $k=>$t) { 00122 if (!is_numeric($k)) { 00123 $t = $k.'='.$t; 00124 } 00125 if (!in_array($t, $curTags)) { 00126 $curTags[] = $t; 00127 } 00128 } 00129 00130 $this->setTags($curTags); 00131 00132 return $this; 00133 }
getStoreId | ( | ) |
Definition at line 277 of file Rewrite.php.
00278 { 00279 return $this->_getData('store_id'); 00280 }
hasOption | ( | $ | key | ) |
Definition at line 108 of file Rewrite.php.
00109 { 00110 $optArr = explode(',', $this->getOptions()); 00111 00112 return array_search($key, $optArr) !== false; 00113 }
loadByIdPath | ( | $ | path | ) |
Definition at line 74 of file Rewrite.php.
00075 { 00076 $this->setId(null)->load($path, 'id_path'); 00077 return $this; 00078 }
loadByRequestPath | ( | $ | path | ) |
Load rewrite information for request
if $path is array - that mean what we need try load for each item
mixed | $path |
Definition at line 56 of file Rewrite.php.
00057 { 00058 $this->setId(null); 00059 00060 if (is_array($path)) { 00061 foreach ($path as $pathInfo) { 00062 $this->load($pathInfo, 'request_path'); 00063 if ($this->getId()) { 00064 return $this; 00065 } 00066 } 00067 } 00068 else { 00069 $this->load($path, 'request_path'); 00070 } 00071 return $this; 00072 }
loadByTags | ( | $ | tags | ) |
Definition at line 80 of file Rewrite.php.
00081 { 00082 $this->setId(null); 00083 00084 $loadTags = is_array($tags) ? $tags : explode(',', $tags); 00085 00086 $search = $this->getResourceCollection(); 00087 foreach ($loadTags as $k=>$t) { 00088 if (!is_numeric($k)) { 00089 $t = $k.'='.$t; 00090 } 00091 $search->addTagsFilter($t); 00092 } 00093 if (!is_null($this->getStoreId())) { 00094 $search->addStoreFilter($this->getStoreId()); 00095 } 00096 00097 $search->setPageSize(1)->load(); 00098 00099 if ($search->getSize()>0) { 00100 foreach ($search as $rewrite) { 00101 $this->setData($rewrite->getData()); 00102 } 00103 } 00104 00105 return $this; 00106 }
removeTag | ( | $ | tags | ) |
Definition at line 135 of file Rewrite.php.
00136 { 00137 $curTags = $this->getTags(); 00138 00139 $removeTags = is_array($tags) ? $tags : explode(',', $tags); 00140 00141 foreach ($removeTags as $t) { 00142 if (!is_numeric($k)) { 00143 $t = $k.'='.$t; 00144 } 00145 if ($key = array_search($t, $curTags)) { 00146 unset($curTags[$key]); 00147 } 00148 } 00149 00150 $this->setTags(',', $curTags); 00151 00152 return $this; 00153 }
rewrite | ( | Zend_Controller_Request_Http $ | request = null , |
|
Zend_Controller_Response_Http $ | response = null | |||
) |
Implement logic of custom rewrites
Zend_Controller_Request_Http | $request | |
Zend_Controller_Response_Http | $response |
We need try to find rewrites information for both cases More priority has url with query params
Try to find rewrite by request path at first, if no luck - try to find by id_path
Definition at line 162 of file Rewrite.php.
00163 { 00164 if (!Mage::isInstalled()) { 00165 return false; 00166 } 00167 if (is_null($request)) { 00168 $request = Mage::app()->getFrontController()->getRequest(); 00169 } 00170 if (is_null($response)) { 00171 $response = Mage::app()->getFrontController()->getResponse(); 00172 } 00173 if (is_null($this->getStoreId()) || false===$this->getStoreId()) { 00174 $this->setStoreId(Mage::app()->getStore()->getId()); 00175 } 00176 00177 $requestCases = array(); 00178 $requestPath = trim($request->getPathInfo(), '/'); 00179 00180 /** 00181 * We need try to find rewrites information for both cases 00182 * More priority has url with query params 00183 */ 00184 if ($queryString = $this->_getQueryString()) { 00185 $requestCases[] = $requestPath .'?'.$queryString; 00186 $requestCases[] = $requestPath; 00187 } 00188 else { 00189 $requestCases[] = $requestPath; 00190 } 00191 00192 $this->loadByRequestPath($requestCases); 00193 00194 /** 00195 * Try to find rewrite by request path at first, if no luck - try to find by id_path 00196 */ 00197 if (!$this->getId() && isset($_GET['___from_store'])) { 00198 try { 00199 $fromStoreId = Mage::app()->getStore($_GET['___from_store']); 00200 } 00201 catch (Exception $e) { 00202 return false; 00203 } 00204 00205 $this->setStoreId($fromStoreId)->loadByRequestPath($requestCases); 00206 if (!$this->getId()) { 00207 return false; 00208 } 00209 $this->setStoreId(Mage::app()->getStore()->getId())->loadByIdPath($this->getIdPath()); 00210 } 00211 00212 if (!$this->getId()) { 00213 return false; 00214 } 00215 00216 00217 $request->setAlias(self::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath()); 00218 $external = substr($this->getTargetPath(), 0, 6); 00219 $isPermanentRedirectOption = $this->hasOption('RP'); 00220 if ($external === 'http:/' || $external === 'https:') { 00221 if ($isPermanentRedirectOption) { 00222 header('HTTP/1.1 301 Moved Permanently'); 00223 } 00224 header("Location: ".$this->getTargetPath()); 00225 exit; 00226 } else { 00227 $targetUrl = $request->getBaseUrl(). '/' . $this->getTargetPath(); 00228 } 00229 $isRedirectOption = $this->hasOption('R'); 00230 if ($isRedirectOption || $isPermanentRedirectOption) { 00231 if (Mage::getStoreConfig('web/url/use_store') && $storeCode = Mage::app()->getStore()->getCode()) { 00232 $targetUrl = $request->getBaseUrl(). '/' . $storeCode . '/' .$this->getTargetPath(); 00233 } 00234 if ($isPermanentRedirectOption) { 00235 header('HTTP/1.1 301 Moved Permanently'); 00236 } 00237 header('Location: '.$targetUrl); 00238 exit; 00239 } 00240 00241 if (Mage::getStoreConfig('web/url/use_store') && $storeCode = Mage::app()->getStore()->getCode()) { 00242 $targetUrl = $request->getBaseUrl(). '/' . $storeCode . '/' .$this->getTargetPath(); 00243 } 00244 00245 if ($queryString = $this->_getQueryString()) { 00246 $targetUrl .= '?'.$queryString; 00247 } 00248 00249 $request->setRequestUri($targetUrl); 00250 $request->setPathInfo($this->getTargetPath()); 00251 00252 return true; 00253 }
const REWRITE_REQUEST_PATH_ALIAS = 'rewrite_request_path' |
Definition at line 41 of file Rewrite.php.
const TYPE_CATEGORY = 1 |
Definition at line 38 of file Rewrite.php.
const TYPE_CUSTOM = 3 |
Definition at line 40 of file Rewrite.php.
const TYPE_PRODUCT = 2 |
Definition at line 39 of file Rewrite.php.