4 chdir(dirname(__FILE__
));
5 require_once 'common.php';
10 * Updates Freshmeat's HTML Purifier with the latest information via XML RPC.
13 class XmlRpc_Freshmeat
16 const URL
= 'http://freshmeat.net/xmlrpc/';
18 public $chatty = false;
20 public $encodeOptions = array(
21 'encoding' => 'utf-8',
25 * This array defines shortcut method signatures for dealing with simple
26 * XML RPC methods. More complex ones (publish_release) should use the named parameter
29 public $signatures = array(
30 'login' => array('username', 'password'),
31 'fetch_branch_list' => array('project_name'),
32 'fetch_release' => array('project_name', 'branch_name', 'version'),
33 'withdraw_release' => array('project_name', 'branch_name', 'version'),
36 protected $sid = null;
39 * @param $username Username to login with
40 * @param $password Password to login with
42 public function __construct($username = null, $password = null) {
43 if ($username && $password) {
44 $this->login($username, $password);
49 * Performs a raw XML RPC call to self::URL
51 protected function call($method, $params) {
52 $request = xmlrpc_encode_request($method, $params, $this->encodeOptions
);
54 curl_setopt($ch, CURLOPT_URL
, self
::URL
);
55 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
56 curl_setopt($ch, CURLOPT_TIMEOUT
, 1);
57 curl_setopt($ch, CURLOPT_HTTPHEADER
, array(
58 'Content-type: text/xml',
59 'Content-length: ' . strlen($request)
61 curl_setopt($ch, CURLOPT_POSTFIELDS
, $request);
62 $data = curl_exec($ch);
63 if ($errno = curl_errno($ch)) {
64 throw new Exception("Curl error [$errno]: " . curl_error($ch));
67 return xmlrpc_decode($data);
72 * Performs an XML RPC call to Freshmeat.
73 * @param $name Name of method to call, can be methodName or method_name
74 * @param $args Arguments of call, in form array('key1', 'val1', 'key2' ...)
76 public function __call($name, $args) {
77 $method = $this->camelToUnderscore($name);
79 if ($this->sid
) $params['SID'] = $this->sid
;
80 if (isset($this->signatures
[$method])) {
81 for ($i = 0, $c = count($this->signatures
[$method]); $i < $c; $i++
) {
82 $params[$this->signatures
[$method][$i]] = $args[$i];
85 for ($i = 0, $c = count($args); $i +
1 < $c; $i +
= 2) {
86 $params[$args[$i]] = $args[$i +
1];
89 $result = $this->call($method, $params);
92 $this->sid
= $result['SID'];
98 if ($this->chatty
) print_r($result);
103 * Munge methodName to method_name
105 private function camelToUnderscore($name) {
107 for ($i = 0, $c = strlen($name); $i < $c; $i++
) {
109 if (ctype_lower($v)) $method .= $v;
110 else $method .= '_' . strtolower($v);
116 * Automatically logout at end of scope
118 public function __destruct() {
119 if ($this->sid
) $this->logout();
124 $rpc = new XmlRpc_Freshmeat($argv[1], $argv[2]);
127 $project = 'htmlpurifier';
129 $version = file_get_contents('../VERSION');
131 $result = $rpc->fetchRelease($project, $branch, $version);
132 if (!isset($result['faultCode'])) {
133 echo "Freshmeat release already exists.\n";
137 $changes = strtr(file_get_contents('../WHATSNEW'), array("\r" => '', "\n" => ' '));
138 $focus = (int) trim(file_get_contents('../FOCUS'));
140 if (strlen($changes) > 600) {
141 echo "WHATSNEW entry is too long.\n";
145 $rpc->publishRelease(
146 'project_name', $project,
147 'branch_name', $branch,
150 'release_focus', $focus,
151 'url_tgz', "http://htmlpurifier.org/releases/htmlpurifier-$version.tar.gz",
152 'url_zip', "http://htmlpurifier.org/releases/htmlpurifier-$version.zip",
153 'url_changelog', "http://htmlpurifier.org/svnroot/htmlpurifier/tags/$version/NEWS"
156 // vim: et sw=4 sts=4