Rev 1435 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1435 | Rev 1436 | ||
---|---|---|---|
Line 1943... | Line 1943... | ||
1943 | } catch (\Exception $e) { |
1943 | } catch (\Exception $e) { |
1944 | } |
1944 | } |
1945 | } |
1945 | } |
1946 | 1946 | ||
1947 | /** |
1947 | /** |
1948 | * @param string $infoFile Path to a changelog.json.php file (It must be in its source code form!) |
1948 | * @param string|array $infoFile Path or content of a changelog.json.php file (It must be in its source code form!) |
1949 | * @param bool $allow_dev_version If set to false, then versions ending with "-dev" will be ignored |
1949 | * @param bool $allow_dev_version If set to false, then versions ending with "-dev" will be ignored |
1950 | * @return false|string |
1950 | * @return false|string |
1951 | */ |
1951 | */ |
1952 | public static function getVersion(string $infoFile = __DIR__.'/../../changelog.json.php', bool $allow_dev_version=true) { |
1952 | public static function getVersion($infoFile = __DIR__.'/../../changelog.json.php', bool $allow_dev_version=true) { |
1953 | static $cachedVersion = []; |
1953 | if (is_array($infoFile)) { |
- | 1954 | $json = $infoFile; |
|
- | 1955 | } else { |
|
1954 | if ($cachedVersion[$infoFile] ?? false) { |
1956 | if (strlen($infoFile) > 255) { |
1955 | return $cachedVersion[$infoFile]; |
1957 | $cont = $infoFile; |
1956 | } |
1958 | } else { |
1957 | - | ||
1958 | if ((stripos($infoFile,'http://')===0) || (stripos($infoFile,'https://')===0)) { |
1959 | if ((stripos($infoFile,'http://')===0) || (stripos($infoFile,'https://')===0)) { |
1959 | $cont = @url_get_contents($infoFile); |
1960 | $cont = @url_get_contents($infoFile); |
1960 | } else { |
1961 | } else { |
1961 | $cont = @file_get_contents($infoFile); |
1962 | $cont = @file_get_contents($infoFile); |
1962 | } |
1963 | } |
- | 1964 | } |
|
1963 | if ($cont === false) return false; |
1965 | if ($cont === false) return false; |
1964 | $json = @json_decode($cont, true); |
1966 | $json = @json_decode($cont, true); |
1965 | if ($json === null) return false; |
1967 | if ($json === null) return false; |
- | 1968 | } |
|
1966 | $latest_version = false; |
1969 | $latest_version = false; |
1967 | foreach ($json as $v) { |
1970 | foreach ($json as $v) { |
1968 | if (isset($v['version'])) { |
1971 | if (isset($v['version'])) { |
1969 | if (!$allow_dev_version && str_ends_with($v['version'],'-dev')) continue; |
1972 | if (!$allow_dev_version && str_ends_with($v['version'],'-dev')) continue; |
1970 | $latest_version = $v['version']; |
1973 | $latest_version = $v['version']; |
1971 | break; // the first item is the latest version |
1974 | break; // the first item is the latest version |
1972 | } |
1975 | } |
1973 | } |
1976 | } |
1974 | return ($cachedVersion[$infoFile] = $latest_version); |
1977 | return $latest_version; |
1975 | 1978 | ||
1976 | /* |
1979 | /* |
1977 | 1980 | ||
1978 | $installType = OIDplus::getInstallType(); |
1981 | $installType = OIDplus::getInstallType(); |
1979 | 1982 | ||
1980 | if ($installType === 'svn-wc') { |
1983 | if ($installType === 'svn-wc') { |
1981 | if (is_dir($svn_dir = OIDplus::findSvnFolder())) { |
1984 | if (is_dir($svn_dir = OIDplus::findSvnFolder())) { |
1982 | $ver = get_svn_revision($svn_dir); |
1985 | $ver = get_svn_revision($svn_dir); |
1983 | if ($ver) |
1986 | if ($ver) |
1984 | return ($cachedVersion[$infoFile] = 'svn-'.$ver); |
1987 | return ($cachedVersion[$infoFile] = '2.0.0.'.$ver); |
1985 | } |
1988 | } |
1986 | } |
1989 | } |
1987 | 1990 | ||
1988 | if ($installType === 'git-wc') { |
1991 | if ($installType === 'git-wc') { |
1989 | $ver = OIDplus::getGitsvnRevision(); |
1992 | $ver = OIDplus::getGitsvnRevision(); |
1990 | if ($ver) |
1993 | if ($ver) |
1991 | return ($cachedVersion[$infoFile] = 'svn-'.$ver); |
1994 | return ($cachedVersion[$infoFile] = '2.0.0.'.$ver); |
1992 | } |
- | |
1993 | - | ||
1994 | if ($installType === 'manual') { |
- | |
1995 | $cont = ''; |
- | |
1996 | if (file_exists($filename = OIDplus::localpath().'oidplus_version.txt')) |
- | |
1997 | $cont = file_get_contents($filename); |
- | |
1998 | if (file_exists($filename = OIDplus::localpath().'.version.php')) |
- | |
1999 | $cont = file_get_contents($filename); |
- | |
2000 | $m = array(); |
- | |
2001 | if (preg_match('@Revision (\d+)@', $cont, $m)) // do not translate |
- | |
2002 | return ($cachedVersion[$infoFile] = 'svn-'.$m[1]); // do not translate |
- | |
2003 | } |
1995 | } |
2004 | 1996 | ||
2005 | return ($cachedVersion[$infoFile] = false); // version ambigous or unknown |
- | |
2006 | - | ||
2007 | */ |
1997 | */ |
2008 | } |
1998 | } |
2009 | 1999 | ||
2010 | const ENFORCE_SSL_NO = 0; |
2000 | const ENFORCE_SSL_NO = 0; |
2011 | const ENFORCE_SSL_YES = 1; |
2001 | const ENFORCE_SSL_YES = 1; |