Re: pecl4win patches
| From: | Gaetano Giunta | Date: | Tue, 29 May 2007 22:59:13 +0000 |
| Subject: | Re: pecl4win patches | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-29906@lists.php.net to get a copy of this message | ||
One more patch: a php file to generate rss feeds for pecl4win releases. It can list all files or all files for a given php branch.
The base rss code is taken from pecl rss.
It assumes that for every extension and php branch, there is only one file in the db (ie. not many builds corresponding to different php versions).
Bye
Gaetano
ps: sorry for spamming the list. Is there some other place I should post this?
<?php
/**
+----------------------------------------------------------------------+
| PECL4WIN Web site |+----------------------------------------------------------------------+
| Copyright (c) 2007 The PHP Group |+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_01.txt. || If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. |+----------------------------------------------------------------------+ @author Pierre-Alain Joye <pajoye@php.net> @author G. Giunta @version $Id: $ @todo use a better xml-escaping filter than htmlspecialchars @todo shall we return a specific error if user asks for inexisting extension? */ if (!defined("SITE_ROOT")) { define("SITE_ROOT", dirname(__FILE__)); } include SITE_ROOT."/lib/includes/init.php"; function rss_bailout() { header('HTTP/1.0 404 Not Found'); echo "<h1>The requested URL " . (($_SERVER['REQUEST_URI'])) . " was not found on this server.</h1>"; exit(); } /* if file is given, the file will be used to store the rss feed */ function rss_create($items, $channel_title, $channel_description, $dest_file=false) { if (is_array($items) /*&& count($items)>0*/) {
$rss_top = <<<EOT<?xml version="1.0" encoding="iso-8859-1"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel rdf:about="http://pecl4win.php.net/"> <link>http://pecl4win.php.net/</link> <dc:creator>edink@php.net</dc:creator> <dc:publisher>edink@php.net</dc:publisher> <dc:language>en-us</dc:language> EOT;
$items_xml = "<items><rdf:Seq>";
$item_entries = '';
foreach ($items as $item) {
$date = date("Y-m-d\TH:i:s-05:00", strtotime($item['releasedate']));
/* allows to override the default link */
if (!isset($item['link'])) {
$url = 'http://pecl4win.php.net/download.php/ext/' . $item['branch'] . '/' . $item['version'] . '/' . $item['name'];
} else {
$url = $item['link'];
}
if (!empty($item['branch'])) {
$title = $item['name'] . ' (' . $item['branch'] . ' branch)';
} else {
$title = $item['name'];
}
//$node = $this->newItem($title, $url, $item['releasenotes'], $date);
$items_xml .= '<rdf:li rdf:resource="' . $url . '"/>' . "\n";
$item_entries .= "<item rdf:about=" . '"' .$url . '"' . ">
<title>$title</title>
<link>$url</link>
<description>" . $item['releasenotes'] ."
</description>
<dc:date>$date</dc:date>
</item>";
$item_entries .= "";
}
$items_xml .= "</rdf:Seq></items>\n";
$rss_feed = $rss_top . $items_xml ."<title>$channel_title</title> <description>$channel_description</description> </channel> $item_entries </rdf:RDF>";
/* lock free write, thx rasmus for the tip */
if($dest_file && (!file_exists($dest_file) || filemtime($dest_file) < (time()-$timeout))) {
$stream = fopen($url,'r');
$tmpf = tempnam('/tmp','YWS');
// Note the direct write from the stream here
file_put_contents($tmpf, $stream);
fclose($stream);
rename($tmpf, $dest_file);
}
header("Content-Type: text/xml; charset=iso-8859-1");
echo $rss_feed;
} else {
rss_bailout();} } $channel_title = 'PECL4WIN: Latest releases'; $channel_description = 'The latest releases in PECL4WIN.'; $q = "select fname, branch, pversion, filesize, updated from ext"; $args = isset($_SERVER['PATH_INFO']) ? explode("/", $_SERVER['PATH_INFO']) : ''; if (count($args) > 1 && $args[1] != '') { //$branch = $args[1]; $channel_title .= ' for branch '.htmlspecialchars($args[1]); $q .= safe_sql_str(" where branch=!s", $args[1]); } else { //$branch = ''; } $q .= " order by updated desc"; $res = $DB->query($q); $i = 0; $items = array(); while ($row = $DB->fetchRow($res)) { $file = new stdClass; $DB->loadFromDbRow($file, $res, $row); $items[] = array(
'name' => $file->fname,
'branch' => $file->branch,
'releasedate' => $file->updated,
'version' => $file->pversion,
'releasenotes' => 'Size: ' . $file->filesize . " KB - Last build: " . date('Y-m-d H:i:s', $file->updated)
);
/// @todo move select limit from here unto query for bette resource usage
if (++$i > 10) {
break;} } // we do not use yet static files. It will be activated with the new backends. // $file = dirname(__FILE__) . '/' . $type . '_' . $argument . '.rss'; $file = false; rss_create($items, $channel_title, $channel_description, $file);