Index: project-release-history.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/release/project-release-history.php,v
retrieving revision 1.2
diff -u -p -r1.2 project-release-history.php
--- project-release-history.php	16 Jun 2007 18:38:32 -0000	1.2
+++ project-release-history.php	7 Jul 2007 11:57:38 -0000
@@ -80,7 +80,7 @@ if (!is_dir(BASE_DIRECTORY)) {
 
 /// @todo Add command-line args to only generate a given project/version.
 project_release_history_generate_all();
-
+project_list_generate();
 
 // ------------------------------------------------------------
 // Functions: main work
@@ -207,7 +207,7 @@ function project_release_history_generat
     $xml .= " </release>\n";
   }
   $xml .= "</releases>\n</project>\n";
-  project_release_history_write_xml($project, $api_version, $xml);
+  project_release_history_write_xml($xml, $project, $api_version);
 }
 
 
@@ -221,29 +221,47 @@ function project_release_history_generat
  * @param $xml
  *  String containing the XML representation of the history.
  */
-function project_release_history_write_xml($project, $api_version, $xml) {
+function project_release_history_write_xml($xml, $project = NULL, $api_version = NULL) {
 
-  // Setup the filenames we'll be using.  Normally, we'd have to be
-  // extra careful with $project->uri to avoid malice here, however,
-  // that's validated on the project edit form to prevent any funny
-  // characters, so that much is safe.  The rest of these paths are
-  // just from the global variables at the top of this script, so we
-  // can trust those.  The only one we should be careful of is the
-  // taxonomy term for the API compatibility.
-  $safe_api_vers = strtr($api_version, '/', '_');
-  $project_dir = BASE_DIRECTORY .'/'. $project->uri;
-  $project_id = $project->uri .'-'. $safe_api_vers .'.xml';
-  $filename = $project_dir .'/'. $project_id;
-  $tmp_filename = $filename .'.new';
+  if (!isset($project)) {
+    // We are outputting a global project list.
+    $project_dir = BASE_DIRECTORY .'/project-list';
+    $filename = $project_dir .'/project-list-all.xml';
+    $tmp_filename = $filename .'.new';
+    $errors = array(
+      'mkdir'  => t("ERROR: mkdir(@dir) failed, can't write project list.", array('@dir' => $project_dir)),
+      'unlink' => t("ERROR: unlink(@file) failed, can't write project list.", array('@file' => $tmp_filename)),
+      'rename' => t("ERROR: rename(@old, @new) failed, can't write project list.", array('@old' => $tmp_filename, '@new' => $filename))
+    );
+  }
+  else {
+    // Setup the filenames we'll be using.  Normally, we'd have to be
+    // extra careful with $project->uri to avoid malice here, however,
+    // that's validated on the project edit form to prevent any funny
+    // characters, so that much is safe.  The rest of these paths are
+    // just from the global variables at the top of this script, so we
+    // can trust those.  The only one we should be careful of is the
+    // taxonomy term for the API compatibility.
+    $safe_api_vers = strtr($api_version, '/', '_');
+    $project_dir = BASE_DIRECTORY .'/'. $project->uri;
+    $project_id = $project->uri .'-'. $safe_api_vers .'.xml';
+    $filename = $project_dir .'/'. $project_id;
+    $tmp_filename = $filename .'.new';
+    $errors = array(
+      'mkdir'  => t("ERROR: mkdir(@dir) failed, can't write history for %project.", array('@dir' => $project_dir, '%project' => $project->title)),
+      'unlink' => t("ERROR: unlink(@file) failed, can't write history for %project.", array('@file' => $tmp_filename, '%project' => $project->title)),
+      'rename' => t("ERROR: rename(@old, @new) failed, can't write history for %project.", array('@old' => $tmp_filename, '@new' => $filename, '%project' => $project->title))
+    );
+  }
 
   // Make sure we've got the right project-specific subdirectory.
   if (!is_dir($project_dir) && !mkdir($project_dir)) {
-    wd_err(t("ERROR: mkdir(@dir) failed, can't write history for %project.", array('@dir' => $project_dir, '%project' => $project->title)));
+    wd_err($errors['mkdir']);
     return FALSE;
   }
   // Make sure the "[project]-[version].xml.new" file doesn't exist.
   if (is_file($tmp_filename) && !unlink($tmp_filename)) {
-    wd_err(t("ERROR: unlink(@file) failed, can't write history for %project.", array('@file' => $tmp_filename, '%project' => $project->title)));
+    wd_err($errors['unlink']);
     return FALSE;
   }
   // Write the XML history to "[project]-[version].xml.new".
@@ -260,12 +278,33 @@ function project_release_history_write_x
 
   // Now we can atomically rename the .new into place in the "live" spot.
   if (!rename($tmp_filename, $filename)) {
-    wd_err(t("ERROR: rename(@old, $new) failed, can't write history for %project.", array('@old' => $tmp_filename, '@new' => $filename, '%project' => $project->title)));
+    wd_err($errors['rename']);
     return FALSE;
   }
   return TRUE;
 }
 
+/**
+ * Generate a list of all projects available on this server.
+ */
+function project_list_generate() {
+  $query = db_query("SELECT n.title, n.nid, p.uri FROM {node} n INNER JOIN {project_projects} p ON n.nid = p.nid");
+  if (!db_num_rows($query)) {
+    wd_err(t('No projects found on this server.'));
+    return FALSE;
+  }
+  $xml = "<projects>\n";
+  while ($project = db_fetch_object($query)) {
+    $xml .= " <project>\n";
+    $xml .= '  <title>'. check_plain($project->title) ."</title>\n";
+    $xml .= '  <short_name>'. check_plain($project->uri) ."</short_name>\n";
+    $xml .= '  <link>'. url("node/$project->nid", NULL, NULL, TRUE) ."</link>\n";
+    $xml .= " </project>\n";
+  }
+  $xml .= "</projects>\n";
+  project_release_history_write_xml($xml);
+}
+
 
 // ------------------------------------------------------------
 // Functions: utility methods
