Вход Регистрация
Файл: adultscript-2.0.3-pro/files/libraries/framework/uri.php
Строк: 82
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VUri
{
    private static 
$uri        = array();
    private static 
$request    = array();
    private static 
$sef_url = NULL;
    public static function 
get($key, $strip=FALSE)
    {
        if (!isset(
self::$uri[$key])) {
            
self::__cache_uri($strip);
        }
        
        return 
self::$uri[$key];
    }
    
    public static function 
getURI($strip=FALSE)
    {
        if (!
self::$uri) {
            
// we need this for nginx
            
if (isset($_GET['q']) &&
                isset(
$_GET['q']['0']) &&
                
$_GET['q']['0'] == '/') {
                
$_GET['q'] = substr($_GET['q'], 1);
            }
        
            
self::__cache_uri($strip);
        }
        
        return 
self::$uri;
    }

    private static function 
__cache_uri($strip=FALSE)
    {
        
$uri                     = array();
        
$uri['base_url']        = VF::cfg_item('base_url');
        
$uri['relative_url']    = VF::cfg_item('relative');
    
        
$request        = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL;        
        if (isset(
$request)) {
            if (
$uri['relative_url'] != '') {
                
$request = preg_replace('@^'.$uri['relative_url'].'@', '', $request);
            }
        }
        
        
$url    = $uri['base_url'].$request;
        
$url      = urldecode($url);
        
$url      = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
        
$url      = preg_replace('/eval((.*))/', '', $url);
        
$url      = str_replace('javascript:', '', $url);
        
        
$uri['current_url']        = $url;
        
$uri['admin_url']        = $uri['base_url']. '/admin';
                
        if (!
parse_url($url)) {
            die(
'Failed to cache uri! Aborting!');
        }

        
self::$uri = $uri;
    }

    public static function 
query()
    {
        if (!
self::$request) {
            
self::$request = (isset($_GET['q'])) ? array_pop(explode('/', utf8_strtolower(trim($_GET['q'])))) : array();
        }
        
        return 
self::$request;
    }
    
    public static function 
request($index)
    {
        if (!
self::$request) {
            
self::$request = (isset($_GET['q'])) ? explode('/', utf8_strtolower(trim($_GET['q']))) : array();
        }
        
        if (isset(
self::$request[$index])) {
            return 
self::$request[$index];
        }
    }
    
    public static function 
component($default=NULL)
    {
        if (!
self::$request) {
            
self::$request = (isset($_GET['q'])) ? explode('/', trim($_GET['q'])) : array();
        }
        
        
$component = (isset(self::$request['1'])) ? self::$request['1'] : $default;
        
$component = (isset(self::$request['2']) && !is_numeric(self::$request['2'])) ? $component.'_'.self::$request['2'] : $component;
        
        if (
preg_match('/^[a-z0-9-_]+$/', $component)) {
            return 
$component;
        }
        
        return 
FALSE;
    }
    
    public static function 
build($string, $absolute=TRUE, $html=TRUE)
    {
        if (!isset(
self::$sef_url)) {
            
self::$sef_url = VF::cfg_item('sef_urls');
        }
        
        
$base      = ($absolute === TRUE) ? RELATIVE_URL : BASE_URL;
        
$parts     = explode('?', $string);
        
$dest    = trim($parts['0'], '/');
        
$query = '';
        if (isset(
$parts['1'])) {
            
$separator  = ($html === TRUE) ? '&amp;' : '&';
            
$query         = ($html === TRUE) ? htmlspecialchars($parts['1']) : $parts['1'];
        }
        
        if (
$query != '') {
            
$query = (self::$sef_url == '1') ? '?'.$query : $separator.$query;
        }
        
        
$use_slash     = TRUE;
        
$separator    = ($use_slash === TRUE) ? '/' : '';
        
        if (
self::$sef_url == '1') {
            return 
$base.'/'.$dest.$separator.$query;
        } else {
            return 
$base.'/'.'?q='.$dest.$query;
        }
    }
    
    public static function 
canonicalize()
    {
        if (isset(
$_GET['q']) && strlen($_GET['q']) > 1) {
            if (
substr($_GET['q'], -1) != '/') {
                
// we need to do a 301 redirect now to the correct URL
                // we always want whatever-url/
                // http://www.mattcutts.com/blog/seo-advice-url-canonicalization/
                
$route  = utf8_strtolower(trim($_GET['q']));
                
$route     = (utf8_is_ascii($route))
                    ? 
preg_replace('/[^A-Za-z0-9-_/]+/', '', $route)
                    : 
preg_replace('/[^pLpN-_/]+/u', '', $route);
                
$url    = BASE_URL.'/'.$route.'/';
                if (
strpos(CURRENT_URL, '?') !== FALSE) {
                    
$query_data = array();
                    foreach (
$_GET as $key => $value) {
                        if (
$key != 'q') {
                            
$query_data[urlencode($key)] = urlencode($value);
                        }
                    }
                }
                
                if (isset(
$query_data) && $query_data) {
                    
$url .= '?'.http_build_query($query_data);
                }
                
                
VF::redirect($url, '301');
            }
        }
    }
    
    public static function 
mobile()
    {
          
$request     = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
          
$url        = MOBILE_URL.$request;
          
$url        = urldecode($url);
          
$url        = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
          
$url        = preg_replace('/eval((.*))/', '', $url);
          
$url        = str_replace('javascript:', '', $url);
    
          return 
$url;
    }
    
    public static function 
match($query)
    {
        
// we still require this function for comparation and redirection
        
if (isset($_GET['q'])) {
            
$request = utf8_strtolower(trim($_GET['q']));
            if (
$request != $query) {
                return 
FALSE;
            }
        }
    
        
// backwards compatibility with <= 1.0.4, will be removed in 1.2
        // every url is redirected by default, no need to use the match function
        
return TRUE;    
    }
}
?>
Онлайн: 2
Реклама