Rev 494 | Rev 496 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 494 | Rev 495 | ||
---|---|---|---|
Line 800... | Line 800... | ||
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,'/').'/'; |
803 | return rtrim($res,'/').'/'; |
804 | } |
804 | } |
805 | if (php_sapi_name() == 'cli') { |
805 | if (PHP_SAPI == 'cli') { |
806 | try { |
806 | try { |
807 | return OIDplus::config()->getValue('last_known_system_url', false); |
807 | return OIDplus::config()->getValue('last_known_system_url', false); |
808 | } catch (Exception $e) { |
808 | } catch (Exception $e) { |
809 | return false; |
809 | return false; |
810 | } |
810 | } |
811 | } |
811 | } |
812 | } |
812 | } |
813 | 813 | ||
814 | if (!isset($_SERVER["SCRIPT_NAME"]) && !isset($_SERVER["SCRIPT_FILENAME"])) return false; |
- | |
815 | - | ||
816 | // First, try to find out how many levels we need to go up |
814 | // First, try to find out how many levels we need to go up |
- | 815 | if (PHP_SAPI == 'cli') { |
|
- | 816 | global $argv; |
|
- | 817 | $test_dir = dirname(realpath($argv[0])); |
|
- | 818 | } else { |
|
- | 819 | if (!isset($_SERVER["SCRIPT_FILENAME"])) return false; |
|
817 | $test_dir = dirname($_SERVER['SCRIPT_FILENAME']); |
820 | $test_dir = dirname($_SERVER['SCRIPT_FILENAME']); |
- | 821 | } |
|
818 | $test_dir = str_replace('\\', '/', $test_dir); |
822 | $test_dir = str_replace('\\', '/', $test_dir); |
819 | $c = 0; |
823 | $steps_up = 0; |
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! |
824 | 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! |
821 | $test_dir = dirname($test_dir); |
825 | $test_dir = dirname($test_dir); |
822 | $c++; |
826 | $steps_up++; |
823 | if ($c == 1000) return false; // to make sure there will never be an infinite loop |
827 | if ($steps_up == 1000) return false; // to make sure there will never be an infinite loop |
824 | } |
828 | } |
825 | 829 | ||
826 | // Now go up these amount of levels, based on SCRIPT_NAME |
830 | // Now go up these amount of levels, based on SCRIPT_NAME |
- | 831 | if (PHP_SAPI == 'cli') { |
|
- | 832 | if ($relative) { |
|
- | 833 | return str_repeat('../',$steps_up); |
|
- | 834 | } else { |
|
- | 835 | return false; |
|
- | 836 | } |
|
- | 837 | } else { |
|
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 |
838 | $res = dirname($_SERVER['SCRIPT_NAME'].'index.php'); // This fake 'index.php' ensures that SCRIPT_NAME does not end with '/', which would make dirname() fail |
828 | for ($i=1; $i<=$c; $i++) { |
839 | for ($i=0; $i<$steps_up; $i++) { |
829 | $res = dirname($res); |
840 | $res = dirname($res); |
830 | } |
841 | } |
831 | $res = str_replace('\\', '/', $res); |
842 | $res = str_replace('\\', '/', $res); |
832 | if ($res == '/') $res = ''; |
843 | if ($res == '/') $res = ''; |
833 | $res .= '/'; |
844 | $res .= '/'; |
Line 840... | Line 851... | ||
840 | $res = $protocol.'://'.$host.$res; |
851 | $res = $protocol.'://'.$host.$res; |
841 | } |
852 | } |
842 | 853 | ||
843 | return $res; |
854 | return $res; |
844 | } |
855 | } |
- | 856 | } |
|
845 | 857 | ||
846 | private static $system_id_cache = null; |
858 | private static $system_id_cache = null; |
847 | public static function getSystemId($oid=false) { |
859 | public static function getSystemId($oid=false) { |
848 | if (!is_null(self::$system_id_cache)) { |
860 | if (!is_null(self::$system_id_cache)) { |
849 | $out = self::$system_id_cache; |
861 | $out = self::$system_id_cache; |
Line 977... | Line 989... | ||
977 | 989 | ||
978 | private static $sslAvailableCache = null; |
990 | private static $sslAvailableCache = null; |
979 | public static function isSslAvailable() { |
991 | public static function isSslAvailable() { |
980 | if (!is_null(self::$sslAvailableCache)) return self::$sslAvailableCache; |
992 | if (!is_null(self::$sslAvailableCache)) return self::$sslAvailableCache; |
981 | 993 | ||
982 | if (php_sapi_name() == 'cli') { |
994 | if (PHP_SAPI == 'cli') { |
983 | self::$sslAvailableCache = false; |
995 | self::$sslAvailableCache = false; |
984 | return false; |
996 | return false; |
985 | } |
997 | } |
986 | 998 | ||
987 | $timeout = 2; |
999 | $timeout = 2; |