Rev 1367 | Rev 1435 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1367 | Rev 1426 | ||
---|---|---|---|
Line 1899... | Line 1899... | ||
1899 | * @return string|void |
1899 | * @return string|void |
1900 | */ |
1900 | */ |
1901 | public static function getInstallType() { |
1901 | public static function getInstallType() { |
1902 | $counter = 0; |
1902 | $counter = 0; |
1903 | 1903 | ||
1904 | if ($new_version_file_exists = file_exists(OIDplus::localpath().'.version.php')) { |
- | |
1905 | $counter++; |
- | |
1906 | } |
- | |
1907 | if ($old_version_file_exists = file_exists(OIDplus::localpath().'oidplus_version.txt')) { |
- | |
1908 | $counter++; |
- | |
1909 | } |
- | |
1910 | $version_file_exists = $old_version_file_exists | $new_version_file_exists; |
- | |
1911 | - | ||
1912 | if ($svn_dir_exists = (OIDplus::findSvnFolder() !== false)) { |
1904 | if ($svn_dir_exists = (OIDplus::findSvnFolder() !== false)) { |
1913 | $counter++; |
1905 | $counter++; |
1914 | } |
1906 | } |
1915 | if ($git_dir_exists = (OIDplus::findGitFolder() !== false)) { |
1907 | if ($git_dir_exists = (OIDplus::findGitFolder() !== false)) { |
1916 | $counter++; |
1908 | $counter++; |
1917 | } |
1909 | } |
1918 | 1910 | ||
1919 | if ($counter === 0) { |
1911 | if ($counter > 1) { |
1920 | return 'unknown'; // do not translate |
- | |
1921 | } |
- | |
1922 | else if ($counter > 1) { |
- | |
1923 | return 'ambigous'; // do not translate |
1912 | return 'ambigous'; // do not translate |
1924 | } |
1913 | } |
1925 | else if ($svn_dir_exists) { |
1914 | else if ($svn_dir_exists) { |
1926 | return 'svn-wc'; // do not translate |
1915 | return 'svn-wc'; // do not translate |
1927 | } |
1916 | } |
1928 | else if ($git_dir_exists) { |
1917 | else if ($git_dir_exists) { |
1929 | return 'git-wc'; // do not translate |
1918 | return 'git-wc'; // do not translate |
1930 | } |
1919 | } |
1931 | else if ($version_file_exists) { |
1920 | else { |
1932 | return 'svn-snapshot'; // do not translate |
1921 | return 'manual'; // do not translate |
1933 | } |
1922 | } |
1934 | } |
1923 | } |
1935 | 1924 | ||
1936 | /** |
1925 | /** |
1937 | * @return void |
1926 | * @return void |
Line 1953... | Line 1942... | ||
1953 | } catch (\Exception $e) { |
1942 | } catch (\Exception $e) { |
1954 | } |
1943 | } |
1955 | } |
1944 | } |
1956 | 1945 | ||
1957 | /** |
1946 | /** |
- | 1947 | * @param string $infoFile Path to a changelog.json.php file (It must be in its source code form!) |
|
- | 1948 | * @param bool $allow_dev_version If set to false, then versions ending with "-dev" will be ignored |
|
1958 | * @return false|string |
1949 | * @return false|string |
1959 | */ |
1950 | */ |
- | 1951 | public static function getVersion(string $infoFile = __DIR__.'/../../changelog.json.php', bool $allow_dev_version=true) { |
|
1960 | public static function getVersion() { |
1952 | static $cachedVersion = []; |
- | 1953 | if ($cachedVersion[$infoFile] ?? false) { |
|
1961 | static $cachedVersion = null; |
1954 | return $cachedVersion[$infoFile]; |
- | 1955 | } |
|
- | 1956 | ||
- | 1957 | if ((stripos($infoFile,'http://')===0) || (stripos($infoFile,'https://')===0)) { |
|
- | 1958 | $cont = @url_get_contents($infoFile); |
|
- | 1959 | } else { |
|
- | 1960 | $cont = @file_get_contents($infoFile); |
|
- | 1961 | } |
|
- | 1962 | if ($cont === false) return false; |
|
- | 1963 | $json = @json_decode($cont, true); |
|
- | 1964 | if ($json === null) return false; |
|
- | 1965 | $latest_version = false; |
|
- | 1966 | foreach ($json as $v) { |
|
1962 | if (!is_null($cachedVersion)) { |
1967 | if (isset($v['version'])) { |
- | 1968 | if (!$allow_dev_version && str_ends_with($v['version'],'-dev')) continue; |
|
1963 | return $cachedVersion; |
1969 | $latest_version = $v['version']; |
- | 1970 | break; // the first item is the latest version |
|
- | 1971 | } |
|
1964 | } |
1972 | } |
- | 1973 | return ($cachedVersion[$infoFile] = $latest_version); |
|
- | 1974 | ||
- | 1975 | /* |
|
1965 | 1976 | ||
1966 | $installType = OIDplus::getInstallType(); |
1977 | $installType = OIDplus::getInstallType(); |
1967 | 1978 | ||
1968 | if ($installType === 'svn-wc') { |
1979 | if ($installType === 'svn-wc') { |
1969 | if (is_dir($svn_dir = OIDplus::findSvnFolder())) { |
1980 | if (is_dir($svn_dir = OIDplus::findSvnFolder())) { |
1970 | $ver = get_svn_revision($svn_dir); |
1981 | $ver = get_svn_revision($svn_dir); |
1971 | if ($ver) |
1982 | if ($ver) |
1972 | return ($cachedVersion = 'svn-'.$ver); |
1983 | return ($cachedVersion[$infoFile] = 'svn-'.$ver); |
1973 | } |
1984 | } |
1974 | } |
1985 | } |
1975 | 1986 | ||
1976 | if ($installType === 'git-wc') { |
1987 | if ($installType === 'git-wc') { |
1977 | $ver = OIDplus::getGitsvnRevision(); |
1988 | $ver = OIDplus::getGitsvnRevision(); |
1978 | if ($ver) |
1989 | if ($ver) |
1979 | return ($cachedVersion = 'svn-'.$ver); |
1990 | return ($cachedVersion[$infoFile] = 'svn-'.$ver); |
1980 | } |
1991 | } |
1981 | 1992 | ||
1982 | if ($installType === 'svn-snapshot') { |
1993 | if ($installType === 'manual') { |
1983 | $cont = ''; |
1994 | $cont = ''; |
1984 | if (file_exists($filename = OIDplus::localpath().'oidplus_version.txt')) |
1995 | if (file_exists($filename = OIDplus::localpath().'oidplus_version.txt')) |
1985 | $cont = file_get_contents($filename); |
1996 | $cont = file_get_contents($filename); |
1986 | if (file_exists($filename = OIDplus::localpath().'.version.php')) |
1997 | if (file_exists($filename = OIDplus::localpath().'.version.php')) |
1987 | $cont = file_get_contents($filename); |
1998 | $cont = file_get_contents($filename); |
1988 | $m = array(); |
1999 | $m = array(); |
1989 | if (preg_match('@Revision (\d+)@', $cont, $m)) // do not translate |
2000 | if (preg_match('@Revision (\d+)@', $cont, $m)) // do not translate |
1990 | return ($cachedVersion = 'svn-'.$m[1]); // do not translate |
2001 | return ($cachedVersion[$infoFile] = 'svn-'.$m[1]); // do not translate |
1991 | } |
2002 | } |
1992 | 2003 | ||
1993 | return ($cachedVersion = false); // version ambigous or unknown |
2004 | return ($cachedVersion[$infoFile] = false); // version ambigous or unknown |
- | 2005 | ||
- | 2006 | */ |
|
1994 | } |
2007 | } |
1995 | 2008 | ||
1996 | const ENFORCE_SSL_NO = 0; |
2009 | const ENFORCE_SSL_NO = 0; |
1997 | const ENFORCE_SSL_YES = 1; |
2010 | const ENFORCE_SSL_YES = 1; |
1998 | const ENFORCE_SSL_AUTO = 2; |
2011 | const ENFORCE_SSL_AUTO = 2; |