function sy_absolute_url($url, $relative = null, $base = null) { if (empty($base)) { $base = Simplify::config()->get('www:url'); } if (empty($relative)) { $relative = $base; } if (strpos($url, '/') === 0) { $url = sy_fix_url($base . $url); } elseif (!sy_url_is_absolute($url)) { $url = sy_fix_url($base . $relative . '/' . $url); } else { $url = sy_fix_url($url); } return $url; }
/** * * @return string */ public function build() { $route = $this->_route(); $url = $route; if (strpos($url, 'javascript:') === 0) { return $url; } if (!sy_url_is_absolute($url) || strpos($route, 'route://') === 0) { if (empty($route)) { $route = Simplify::request()->route(); } elseif (strpos($route, 'route://') === 0) { $route = substr($route, 8); if (($p = strpos($route, '?')) !== false) { $name = substr($route, 0, $p); parse_str(substr($route, $p + 1), $params); } else { $name = $route; $params = null; } $route = Simplify::router()->make($name, $params); } while (strpos($route, '//') !== false) { $route = str_replace('//', '/', $route); } while (strpos($route, '/') === strlen($route) - 1) { $route = substr($route, 0, strlen($route) - 2); } if (strpos($route, '/') !== 0) { $route = '/' . $route; } $url = Simplify::request()->url(); if (!Simplify::request()->pretty()) { $url .= '/' . Simplify::request()->self(); } $url .= $route; $ext = $this->_format(); if (empty($ext) && $ext !== false) { $ext = Simplify::request()->extension(); } if (!empty($ext)) { if (preg_match('#/$#', $url)) { $url = substr($url, 0, strlen($url) - 1); } $url .= '.' . $ext; } } $params = $this->_params(); if ($this->_keepOriginal()) { $keep = Simplify::request()->get()->getAll(); $params = array_merge($keep, $params); } $remove = $this->_remove(); if (!empty($remove)) { $keep = array_diff_key($params, array_flip($remove)); $params = array_intersect_key($params, $keep); } if (!empty($params)) { $url .= '?' . http_build_query($params, null, '&'); } return $url; }