Subversion Repositories oidplus

Rev

Rev 486 | Rev 495 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 486 Rev 494
Line 798... Line 798...
798
 
798
 
799
        public static function getSystemUrl($relative=false) {
799
        public static function getSystemUrl($relative=false) {
800
                if (!$relative) {
800
                if (!$relative) {
801
                        $res = OIDplus::baseConfig()->getValue('EXPLICIT_ABSOLUTE_SYSTEM_URL', '');
801
                        $res = OIDplus::baseConfig()->getValue('EXPLICIT_ABSOLUTE_SYSTEM_URL', '');
802
                        if ($res !== '') {
802
                        if ($res !== '') {
-
 
803
                                return rtrim($res,'/').'/';
-
 
804
                        }
-
 
805
                        if (php_sapi_name() == 'cli') {
-
 
806
                                try {
-
 
807
                                        return OIDplus::config()->getValue('last_known_system_url', false);
-
 
808
                                } catch (Exception $e) {
803
                                return $res;
809
                                        return false;
-
 
810
                                }
804
                        }
811
                        }
805
                }
812
                }
806
 
813
 
807
                if (!isset($_SERVER["SCRIPT_NAME"])) return false;
814
                if (!isset($_SERVER["SCRIPT_NAME"]) && !isset($_SERVER["SCRIPT_FILENAME"])) return false;
808
 
815
 
-
 
816
                // First, try to find out how many levels we need to go up
809
                $test_dir = dirname($_SERVER['SCRIPT_FILENAME']);
817
                $test_dir = dirname($_SERVER['SCRIPT_FILENAME']);
810
                $test_dir = str_replace('\\', '/', $test_dir);
818
                $test_dir = str_replace('\\', '/', $test_dir);
811
                $c = 0;
819
                $c = 0;
812
                // We just assume that only the OIDplus base directory contains "oidplus.min.css.php" and not any subsequent directory!
820
                while (!file_exists($test_dir.'/oidplus.min.css.php')) { // We just assume that only the OIDplus base directory contains "oidplus.min.css.php" and not any subsequent directory!
813
                while (!file_exists($test_dir.'/oidplus.min.css.php')) {
-
 
814
                        $test_dir = dirname($test_dir);
821
                        $test_dir = dirname($test_dir);
815
                        $c++;
822
                        $c++;
816
                        if ($c == 1000) return false;
823
                        if ($c == 1000) return false; // to make sure there will never be an infinite loop
817
                }
824
                }
818
 
825
 
819
                $res = dirname($_SERVER['SCRIPT_NAME'].'xxx');
826
                // Now go up these amount of levels, based on SCRIPT_NAME
820
 
-
 
-
 
827
                $res = dirname($_SERVER['SCRIPT_NAME'].'index.php'); // This fake 'index.php' ensures that SCRIPT_NAME does not end with '/', which would make dirname() fail
821
                for ($i=1; $i<=$c; $i++) {
828
                for ($i=1; $i<=$c; $i++) {
822
                        $res = dirname($res);
829
                        $res = dirname($res);
823
                }
830
                }
824
 
-
 
825
                $res = str_replace('\\', '/', $res);
831
                $res = str_replace('\\', '/', $res);
826
                if ($res == '/') $res = '';
832
                if ($res == '/') $res = '';
827
                $res .= '/';
833
                $res .= '/';
828
 
834
 
-
 
835
                // Do we want to have an absolute URI?
829
                if (!$relative) {
836
                if (!$relative) {
830
                        if (php_sapi_name() == 'cli') {
-
 
831
                                try {
-
 
832
                                        return OIDplus::config()->getValue('last_known_system_url', false);
-
 
833
                                } catch (Exception $e) {
-
 
834
                                        return false;
-
 
835
                                }
-
 
836
                        }
-
 
837
 
-
 
838
                        $is_ssl = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on');
837
                        $is_ssl = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on');
839
                        $protocol = $is_ssl ? 'https' : 'http'; // do not translate
838
                        $protocol = $is_ssl ? 'https' : 'http'; // do not translate
840
                        $host = $_SERVER['HTTP_HOST']; // includes port if it is not 80/443
839
                        $host = $_SERVER['HTTP_HOST']; // includes port if it is not 80/443
841
                        $res = $protocol.'://'.$host.$res;
840
                        $res = $protocol.'://'.$host.$res;
842
                }
841
                }