[ Index ] |
|
Code source de Phorum 5.1.25 |
1 <?php 2 3 //////////////////////////////////////////////////////////////////////////////// 4 // // 5 // Copyright (C) 2006 Phorum Development Team // 6 // http://www.phorum.org // 7 // // 8 // This program is free software. You can redistribute it and/or modify // 9 // it under the terms of either the current Phorum License (viewable at // 10 // phorum.org) or the Phorum License that was distributed with this file // 11 // // 12 // This program is distributed in the hope that it will be useful, // 13 // but WITHOUT ANY WARRANTY, without even the implied warranty of // 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // 15 // // 16 // You should have received a copy of the Phorum License // 17 // along with this program. // 18 //////////////////////////////////////////////////////////////////////////////// 19 20 if(!defined("PHORUM")) return; 21 22 /** 23 * Parses the Phorum version number. 24 * @param version - version number to parse 25 * @return An array containing two elements. The first one holds the release 26 * type, which can be "unknown" (parse failed), "snapshot", "stable" 27 * or "development". The version can either be NULL or an array 28 * containing a splitted up version number (only for "stable" 29 * and "development"). 30 */ 31 function phorum_parse_version($version) 32 { 33 if (preg_match('/^\w+-(svn|cvs)-\d+$/', $version)) { 34 $release = 'snapshot'; 35 $parsed_version = array(0,0,0,0); 36 } elseif (preg_match('/^(\d+)\.(\d+).(\d+)([a-z])?$/', $version, $m)) { 37 $release = 'stable'; 38 $parsed_version = array_slice($m, 1); 39 } elseif (preg_match('/^(\d+)\.(\d+)-(dev)/', $version, $m)) { 40 $release = 'development'; 41 $parsed_version = array($m[1], $m[2], 0, $m[3]); 42 } elseif (preg_match('/^(\d+)\.(\d+).(\d+)(-alpha|-beta|-RC\d+)?$/', $version, $m)) { 43 $release = 'development'; 44 $parsed_version = array_slice($m, 1); 45 } else { 46 $release = 'unknown'; 47 $parsed_version = NULL; 48 } 49 50 return array($release, $parsed_version); 51 } 52 53 /** 54 * Compares two version numbers as returned by phorum_parse_version() 55 * and tells which of those two is larger. 56 * @param version1 - The first version number 57 * @param version2 - The second version number 58 * @return 1 if version1 is higher than version2, 0 if equal, -1 if lower 59 */ 60 function phorum_compare_version($version1, $version2) 61 { 62 // Compare segment by segment which version is higher. 63 // Segments 1, 2 and 3 are always numbers. Segment 4 can be 64 // a post-release version letter (a, b, c, etc.) or a 65 // development release marker (-alpha and -beta). 66 for ($s=0; $s<=3; $s++) { 67 if ($s != 3) { 68 if ($version1[$s] > $version2[$s]) return 1; 69 if ($version1[$s] < $version2[$s]) return -1; 70 } else { 71 // Build a numerical representation for segment 4. 72 // * 0 if no segment 4 is set 73 // * 1 for alpha 74 // * 2 for beta 75 // * ord for single char version additions (a = 97) 76 $v1 = 0; $v2 = 0; 77 if (isset($version1[$s])) { 78 if ($version1[$s] == '-alpha') $v1 = 1; 79 elseif ($version1[$s] == '-beta') $v1 = 2; 80 elseif (strlen($version1[$s]) == 1) $v1 = ord($version1[$s]); 81 } 82 if (isset($version2[$s])) { 83 if ($version2[$s] == '-alpha') $v2 = 1; 84 elseif ($version2[$s] == '-beta') $v2 = 2; 85 elseif (strlen($version2[$s]) == 1) $v2 = ord($version2[$s]); 86 } 87 // Same version number with a development suffix is 88 // considered lower than without any suffix. 89 if ($v1 == 0 && ($v2 == 1 || $v2 == 2)) return 1; 90 if (($v1 == 1 || $v1 == 2) && $v2 == 0) return -1; 91 92 if ($v1 > $v2) return 1; 93 if ($v1 < $v2) return -1; 94 } 95 } 96 97 // No difference was found. 98 return 0; 99 } 100 101 /** 102 * Retrieves the available software versions from the Phorum website. 103 * The format of the data returned from the server is two lines. The first 104 * line is for the stable version and the second for the development version. 105 * Each line contains pipe separated values, with the following fields in it: 106 * <version>|<release date>|<downloadloc 1>|<downloadloc 2>|...|<downloadloc n> 107 * @return releases - An array of releases for release types "stable" and "development". 108 */ 109 function phorum_available_releases() 110 { 111 $releases = array(); 112 $fp = @fopen("http://phorum.org/version.php", "r"); 113 if ($fp) { 114 foreach (array("stable", "development") as $release) { 115 $line = fgets($fp, 1024); 116 if (strstr($line, '|')) { 117 $fields = explode('|', $line); 118 if (count($fields) >= 3) { 119 // See if we can parse the version and if the parsed 120 // release type matches the release type we're expecting. 121 $parsed_version = phorum_parse_version($fields[0]); 122 if ($parsed_version[0] == $release) { 123 $releases[$release] = array( 124 "version" => array_shift($fields), 125 "pversion" => $parsed_version[1], 126 "date" => array_shift($fields), 127 "locations" => $fields 128 ); 129 } 130 } 131 } 132 } 133 fclose($fp); 134 } 135 136 return $releases; 137 } 138 139 /** 140 * Finds out if there are any upgrades available for a version of Phorum. 141 * @param version - the version to check for (default is the running version) 142 * @return releases - An array of available releases with the 143 * "upgrade" field set in case the release would be an 144 * upgrade for the currently running Phorum software. 145 */ 146 function phorum_find_upgrades($version = PHORUM) 147 { 148 // Parse the running version of phorum. 149 list ($running_release, $running_version) = phorum_parse_version($version); 150 151 // Retrieve the available releases. 152 $releases = phorum_available_releases(); 153 154 // Check if an upgrade is available for the running release. 155 // If we're running a stable version, we only compare to the current 156 // stable release. If we're running a development version, we compare both 157 // stable and development. 158 if (isset($releases["stable"])) { 159 $avail_version = $releases["stable"]["pversion"]; 160 if (phorum_compare_version($running_version, $avail_version) == -1) { 161 $releases["stable"]["upgrade"] = true; 162 } else { 163 $releases["stable"]["upgrade"] = false; 164 } 165 } 166 if (($running_release == 'development' || $running_release == 'snapshot') && isset($releases["development"])) { 167 $avail_version = $releases["development"]["pversion"]; 168 if (phorum_compare_version($running_version, $avail_version) == -1) { 169 $releases["development"]["upgrade"] = true; 170 } else { 171 $releases["development"]["upgrade"] = false; 172 } 173 } 174 175 return $releases; 176 } 177 178 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:22:27 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |