Index: release/project_release.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/release/project_release.module,v
retrieving revision 1.16
diff -u -p -r1.16 project_release.module
--- release/project_release.module	18 Jan 2007 23:30:45 -0000	1.16
+++ release/project_release.module	28 Jan 2007 18:20:49 -0000
@@ -63,6 +63,112 @@ function project_release_menu($may_cache
 }
 
 /**
+ * Implementation of hook_xmlrpc().
+ */
+function project_release_xmlrpc() {
+  $xmlrpc = array();
+  $xmlrpc[] = array(
+    'project.version.data',
+    'project_release_data',
+    array('string', 'string'),
+    t('Provides versioning data for a single project')
+  );
+  $xmlrpc[] = array(
+    'project.version.data.multi',
+    'project_release_data',
+    array('array', 'string'),
+    t('Provides versioning data for an array of projects')
+  );
+  return $xmlrpc;
+}
+
+/**
+ * Callback for hook_xmlrpc().
+ *
+ * Return versioning data a given project or for all available projects.
+ * The version returned is the highest available for a given major and minor
+ * release. These data can be used e.g. by applications on client sites to
+ * determine whether the client sites have the latest available version.
+ *
+ * This call will only be effective for projects that have official versions.
+ *
+ * @param $project
+ *   The 'short name' (stored as 'url') of a project, or the keyword 'all'
+ *   for all projects. May be an array of projects.
+ * @param $version
+ *   The API version to get data for, as defined by the taxonomy.
+ */
+function project_release_data($project = NULL, $version = NULL) {
+  $data = array();
+
+  // Find the $tid for the API version specified.
+  // stop processing when $version = $term; that's our tid. If we don't have
+  // a match, this should assume the most current.
+  $tids = project_release_compatibility_list();
+  foreach ($tids as $tid => $term) {
+    if ($version == $term) {
+      break;
+    }
+  }
+
+  $where[] = array();
+  $parameters = array();
+  $join_parameters = array();
+
+  // Join the release node, project and project node table.
+  $joins[] = "INNER JOIN {project_release_nodes} prn ON n.nid = prn.nid";
+  $joins[] = "INNER JOIN {project_projects} p ON p.nid = prn.pid";
+  $joins[] = "INNER JOIN {node} pn ON pn.nid = p.nid";
+
+  // If more than one project, add them all in.
+  if (is_array($project)) {
+    $placeholders = array_fill(0, count($project), "'%s'");
+    $where[] = 'p.uri IN (' . implode(',', $placeholders) . ')';
+    // As long as this is the first parameters added, this is fine.
+    // If not make this addition.
+    $parameters = $project;
+  }
+  // Or if not 'all' add just the one.
+  else if ($project != 'all') {
+    $where[] = "p.uri = '%s'";
+    $parameters[] = $project;
+  }
+
+  // Restrict to the specified API version.
+  $joins[] = 'INNER JOIN {term_node} tn ON tn.nid = prn.pid';
+  $where[] = 'tn.tid = %d';
+  $parameters[] = $tid;
+
+  // Restrict to only current releases
+  $joins[] = 'INNER JOIN {project_release_default_versions} prdv ON prdv.nid = prn.pid AND prdv.tid = %d AND prdv.major = n.version_major';
+  $join_parameters[] = $tid;
+
+  // Restrict to only official releases
+  $where[] = 'prn.rebuild = 0';
+
+  // Only published release nodes
+  $where[] = 'n.status > 0';
+
+  $query = "SELECT DISTINCT(n.nid), prn.filepath, prn.version, prn.nid, p.uri, pn.title FROM {node} n ";
+  $query .= implode(' ', $joins);
+  $query .= " WHERE " . implode(' AND ', $where);
+  $query .= " ORDER BY prn.version_major DESC, prn.version_minor DESC, prn.version_patch DESC";
+
+  $result = db_query($query, $join_parameters + $parameters));
+  while ($project = db_fetch_object($result)) {
+    if (!isset($data[$project->uri])) {
+    $data[$project->uri] = array(
+      'name' => check_plain($project->title),
+      'version' => $project->version,
+      'link' => url("node/$project->pid", NULL, NULL, TRUE),
+      'download' => url($project->filepath, NULL, NULL, TRUE),
+    );
+  }
+
+  return $data;
+}
+
+/**
  * Callback for the main settings page.
  * @ingroup project_release_core
  */
