ARC2::getScriptURI PHP Method

getScriptURI() static public method

static public getScriptURI ( )
    static function getScriptURI()
    {
        if (isset($_SERVER) && (isset($_SERVER['SERVER_NAME']) || isset($_SERVER['HTTP_HOST']))) {
            $proto = preg_replace('/^([a-z]+)\\/.*$/', '\\1', strtolower($_SERVER['SERVER_PROTOCOL']));
            $port = $_SERVER['SERVER_PORT'];
            $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
            $script = $_SERVER['SCRIPT_NAME'];
            /* https */
            if ($proto == 'http' && $port == 443) {
                $proto = 'https';
                $port = 80;
            }
            return $proto . '://' . $server . ($port != 80 ? ':' . $port : '') . $script;
        } elseif (isset($_SERVER['SCRIPT_FILENAME'])) {
            return 'file://' . realpath($_SERVER['SCRIPT_FILENAME']);
        }
        return 'http://localhost/unknown_path';
    }

Usage Example

Example #1
0
 function parse($q, $src = '')
 {
     $this->setDefaultPrefixes();
     $this->base = $src ? $this->calcBase($src) : ARC2::getScriptURI();
     $this->r = array('base' => '', 'vars' => array(), 'prefixes' => array());
     $this->unparsed_code = $q;
     list($r, $v) = $this->xQuery($q);
     if ($r) {
         $this->r['query'] = $r;
         $this->unparsed_code = trim($v);
     } elseif (!$this->getErrors() && !$this->unparsed_code) {
         $this->addError('Query not properly closed');
     }
     $this->r['prefixes'] = $this->prefixes;
     $this->r['base'] = $this->base;
     /* remove trailing comments */
     while (preg_match('/^\\s*(\\#[^\\xd\\xa]*)(.*)$/si', $this->unparsed_code, $m)) {
         $this->unparsed_code = $m[2];
     }
     if ($this->unparsed_code && !$this->getErrors()) {
         $rest = preg_replace('/[\\x0a|\\x0d]/i', ' ', substr($this->unparsed_code, 0, 30));
         $msg = trim($rest) ? 'Could not properly handle "' . $rest . '"' : 'Syntax error, probably an incomplete pattern';
         $this->addError($msg);
     }
 }
All Usage Examples Of ARC2::getScriptURI