Don't make spurious version directories, and fix update-dev script.
[phpv.git] / get-url.php
bloba4ef335688d49c04b08fff05e0ecdb1d7070f467
1 #!/usr/bin/env php
2 <?php
4 function extract_links($url) {
5 $doc = new DOMDocument();
6 @$doc->loadHTMLFile($url);
7 $xpath = new DOMXPath($doc);
8 return $xpath->query('//a');
11 if (!isset($_SERVER['argv'][1])) {
12 echo <<<EOF
13 Usage: php get-url.php version
15 EOF;
16 exit(1);
18 $install_version = $_SERVER['argv'][1];
20 $url_mirror = 'http://us2.php.net';
21 $url_releases = $url_mirror . '/releases/';
22 $url_downloads = $url_mirror . '/downloads.php';
24 $link_sets = array(extract_links($url_releases), extract_links($url_downloads));
25 $index = array();
27 foreach ($link_sets as $links) {
28 foreach ($links as $link) {
29 $url = $link->getAttribute('href');
30 if (!$url) continue;
31 $result = preg_match('#/php-([^-]+?)\.tar\.gz#', $url, $matches);
32 if (!$result) continue;
33 list($full, $version) = $matches;
34 $url = str_replace('/from/a/mirror', '/from/this/mirror', $url); // make download ready
35 if ($url[0] == '/') $url = $url_mirror . $url; // heuristic assumes absolute paths are used
36 $index[$version] = $url;
40 // maybe add qa support
42 if (!isset($index[$install_version])) {
43 fwrite(STDERR, "Could not find $install_version\n");
44 exit(1);
47 echo $index[$install_version];