/** * url method * * @param mixed $url * @param array $merge * @return void * @access protected */ function _url($url, $merge = array('admin' => null, 'prefix' => null, 'plugin' => null)) { if (class_exists('SeoComponent')) { return SeoComponent::url(am($merge, $url)); } App::import('Core', 'Router'); return Router::url(am($merge, $url)); }
/** * url method * * @param mixed $url * @param bool $full false * @return void * @access public */ function url($url, $full = false) { if (is_a($this, 'SeoComponent')) { $_this =& $this; } else { $_this =& SeoComponent::getInstance(); } $domain = null; if (is_array($url)) { $url = $_this->sortUrl($url); if (array_key_exists('domain', $url)) { if (!strpos($url['domain'], '.')) { $site = Configure::read('Site.id'); if ($url['domain'] == $site) { unset($url['domain']); } else { $url['domain'] = MiCache::data('Site', 'field', 'domain', array('id' => $url['domain'])); } } elseif ($url['domain'] == Configure::read('Seo.maindomain')) { unset($url['domain']); } if (!empty($url['domain'])) { $domain = $url['domain']; } unset($url['domain']); } } $_url = Router::url($url); if (!$domain) { return $_url; } static $s = false; if ($s === false) { if (env('HTTPS')) { $s = 's'; } else { $s = null; } } return 'http' . $s . '://' . $domain . $_url; }
/** * url method * * Bail early if it's a string url and doesn't start with a / unless it's an asset * This means a relative url (shouldn't ever be any) an # or http:... * * Otherwise, check the cache and return the previously calculated url or calculate the url, * cache it and return it. * * For assets, if they exist in the webroot the url is automatically timestamped * * @param mixed $url * @param mixed $full * @return void * @access public */ function url($url, $full) { $isAsset = false; if (is_string($url)) { if (strpos($url, '://')) { return $url; } if (!$url || ($url[0] !== '/' || !preg_match('@(^|/)(aud|doc|gen|ico|img|txt|vid|js|css|files)/@', $url))) { return $this->webroot . ltrim($url, '/'); } $isAsset = true; $hash = $url; } else { $url += $this->_extraParams; $hash = md5(serialize($url)); } if (isset($this->_cache[$hash])) { return $this->_cache[$hash]; } elseif (isset($this->_cacheGlobal[$hash])) { return $this->_cacheGlobal[$hash]; } if (class_exists('SeoComponent')) { $url = SeoComponent::url($url, $full); } else { $url = Router::url($url, $full); } if ($isAsset) { if (preg_match('@(^|/)(aud|doc|gen|ico|img|txt|vid|js|css|files)/@', $url) && !file_exists(WWW_ROOT . ltrim($url, '/'))) { $url = $url . '?token=' . Security::hash($url, null, true); } $this->_cacheGlobal[$hash] = $url; $this->_changeGlobal = true; } else { $this->_cache[$hash] = $url; $this->_change = true; } return $url; }
/** * normalizeUrl method * * @param mixed $url null * @return void * @access protected */ protected function _normalizeUrl($url = null, $key = false) { if (is_string($url) && $this->webroot !== '/') { $url = preg_replace('@^' . $this->webroot . '@', '/', $url); } if (is_string($url) && $url && $url[0] === '/' && $this->settings['usingSubdomains']) { $url = 'http://' . env('HTTP_HOST') . $url; } if ($key && is_string($url)) { return preg_replace('@(?<!:)/+@', '/', $url); } if (class_exists('SeoComponent')) { $url = SeoComponent::url($url); if (!$key) { if ($this->webroot !== '/') { return preg_replace('@^' . $this->webroot . '@', '/', $url); } return preg_replace('@(?<!:)/+@', '/', $url); } } if ($key) { $url = Router::normalize($url); } elseif (is_array($url)) { $url = Router::url($url); } if ($this->webroot !== '/') { $url = preg_replace('@^' . $this->webroot . '@', '/', $url); } return preg_replace('@(?<!:)/+@', '/', $url); }