1 <?php
defined('IN_CMS') or die('No direct access allowed.');
5 private static $base_url, $index_page;
7 public static function make($uri = '') {
8 if(empty(static::$base_url)) {
9 static::$base_url = Config
::get('application.base_url');
12 if(empty(static::$index_page)) {
13 static::$index_page = Config
::get('application.index_page') ? Config
::get('application.index_page') . '/' : '';
16 return static::$base_url . static::$index_page . ltrim($uri, '/');
19 public static function build($segments = array()) {
20 // make sure we have all the fragments
21 foreach(array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment') as $fragment) {
22 if(isset($segments[$fragment]) === false) {
23 // set missing default
26 $segments[$fragment] = 'http';
29 $segments[$fragment] = Input
::server('http_host');
32 $segments[$fragment] = '';
37 $url = $segments['scheme'] . '://';
39 if($segments['user']) {
40 $url .= $segments['user'];
42 if($segments['pass']) {
43 $url .= ':' . $segments['pass'];
49 $url .= trim($segments['host'], '/');
51 if($segments['port']) {
52 $url .= ':' . $segments['port'];
55 if($segments['path']) {
56 $url .= '/' . ltrim($segments['path'], '/');
59 if($segments['query']) {
60 if(is_array($segments['query'])) {
61 $segments['query'] = http_build_query($segments['query']);
64 $url .= '?' . htmlentities($segments['query'], ENT_COMPAT
, 'UTF-8', false);
67 if($segments['fragment']) {
68 $url .= '#' . urlencode($segments['fragment']);
74 public static function current() {
75 return parse_url(Input
::server('REQUEST_URI'), PHP_URL_PATH
);
78 public static function title($str) {
86 '[^a-z0-9\-\._]' => '',
87 $replace.'+' => $replace,
93 $str = strip_tags($str);
95 foreach($trans as $key => $val) {
96 $str = preg_replace("#" . $key . "#i", $val, $str);
99 $str = strtolower($str);
101 return trim(stripslashes($str));