Index: modules/quotes/quotes.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quotes/quotes.module,v
retrieving revision 1.10
diff -u -r1.10 quotes.module
--- modules/quotes/quotes.module	10 Mar 2004 15:00:59 -0000	1.10
+++ modules/quotes/quotes.module	1 Jul 2004 08:11:50 -0000
@@ -71,22 +71,29 @@
 } // function quotes_perm
 
 /**
- * Drupal hook that returns an array of links valid for the specified
- * type.
+ * Drupal hook that returns an array which registers the quotes
+ * module in the menu system.
  *
- * @param string $in_type The type of links requested.
- * @param integer $in_node The node for which links are requested.
- *
- * @return array An array of links for the specified type and node.
+ * @return array An array of associative arrays defining menu items.
  */
-function quotes_link($in_type, $in_node = 0) {
-  if (($in_type == "system") && user_access("administer quotes") && _quotes_is_installed()) {
-	menu("quotes", t("quotes"), "_quotes_page", 0, MENU_HIDE);
-    menu("admin/quotes", t("quotes"), "_quotes_admin");
-    menu("admin/quotes/quotes", t("overview"), "_quotes_admin", -1);
-    menu("admin/quotes/add", t("add"), "_quotes_admin");
+function quotes_menu() {
+  $items = array();
+
+  if (_quotes_is_installed()) {
+    $items[] = array('path' => 'quotes', 'title' => t('quotes'),
+      'access' => user_access('access content'),
+      'callback' => '_quotes_page',
+      'type' => MENU_CALLBACK);
+    $items[] = array('path' => 'admin/quotes', 'title' => t('quotes'),
+      'access' => user_access('administer quotes'),
+      'callback' => '_quotes_admin');
+    // Tabs:
+    $items[] = array('path' => 'admin/quotes/add', 'title' => t('add quote'),
+      'type' => MENU_LOCAL_TASK);
   }
-} // function quotes_link
+
+  return $items;
+} // function quotes_menu
 
 /**
  * Drupal hook that displays the current installation status of this
@@ -133,13 +140,9 @@
   
   // don't allow settings changes if not installed
   if (!$is_installed) {
-    $the_output .= t("You must install the current version to continue.");
-    $the_output = <<<EOT
-<p>
-  <b>$the_output</b>
-</p>
-
-EOT;
+    if ($_POST['op'] != t("Remove")) {
+      drupal_set_message(t("You must install the current version to continue."), "error");
+    }
   }
   else {
     $the_output .= form_textfield(t("Random quote block name"), "quotes_title", variable_get("quotes_title", ""), 32, 32, t("The name displayed on the random quote block."));
@@ -242,11 +245,11 @@
 EOT;
       break;
 
-    case "admin/system/modules#description":
+    case "admin/modules#description":
       $the_output = "Displays a random quote in a block.";
       break;
 
-    case "admin/system/modules/quotes":
+    case "admin/settings/quotes":
       $the_output = <<<EOT
 <p>
   This page controls the installation and configuration of the quotes
@@ -315,22 +318,13 @@
  * Displays a page with all quotes.
  */
 function _quotes_page() {
-  if (!user_access("access content")) {
-    print theme('page', message_access());
-  }
-  else {
-	print theme('page', _quotes_overview());
-  }
+  print theme('page', _quotes_overview());
 } // function _quotes_page
 
 /**
  * Displays the quotes admin page.
  */
 function _quotes_admin() {
-  if (!user_access("administer quotes")) {
-    print theme('page', message_access());
-  }
-
   $the_op = $_POST['op'];
   
   if (empty($the_op)) {
@@ -343,7 +337,7 @@
       break;
 
     case t("Import"): // import a list of quotes
-      theme('page', _quotes_admin_import(), t('Import quotes'));
+      print theme('page', _quotes_admin_import(), t('Import quotes'));
       break;
 
     case t("Save"): // update a quote
@@ -374,10 +368,6 @@
  * @return string The form to be displayed.
  */
 function _quotes_admin_add() {
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   $the_form1  = form_textarea(t("Quote"), "quote", $_POST['edit']['quote'], 70, 3, t("The actual quote text. Newlines do not need to be escaped."));
   $the_form1 .= form_textfield(t("Author"), "author", $_POST['edit']['author'], 70, 255, t("The author, speaker, character, etc. to whom the quote should be attributed."));
   $the_form1 .= form_submit(t("Add"));
@@ -397,23 +387,19 @@
 function _quotes_admin_insert() {
   global $user, $_quotes_err_num;
 
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   // replace CRLF and CR with LF
   $the_quote = str_replace(array("\r\n", "\r"), "\n", trim($_POST['edit']['quote']));
   $the_author = trim($_POST['edit']['author']);
 
   if (!$the_quote) {
-    $the_output .= t("Please enter a quote.<br />\n");
+    drupal_set_message(t("Please enter a quote."), "error");
   }
 
   if (!$the_author) {
-    $the_output .= t("Please enter an author.<br />\n");
+    drupal_set_message(t("Please enter an author."), "error");
   }
 
-  if (!$the_output) {
+  if ($the_quote && $the_author) {
     $the_query = <<<EOT
 INSERT INTO {quotes_quotes}
   (qid, quote, author, ctime, mtime, uid)
@@ -426,23 +412,14 @@
     restore_error_handler();
 
     if (!$_quotes_err_num) {
-      $the_output = t("Quote added.");
+      drupal_set_message(t("Quote added."));
       unset($_POST['edit']['quote']);
       unset($_POST['edit']['author']);
     }
   }
 
-  $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
-
   // show the add form again
-  $the_output .= _quotes_admin_add();
-
-  return $the_output;
+  return _quotes_admin_add();
 } // function _quotes_admin_insert
 
 /**
@@ -454,10 +431,6 @@
 function _quotes_admin_import() {
   global $user, $_quotes_err_num;
 
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   // replace CRLF and CR with LF
   $the_list = str_replace(array("\r\n", "\r"), "\n", trim($_POST['edit']['quotes']));
 
@@ -473,8 +446,8 @@
     $x = str_replace("\r", "\n", $x);
 
     if (!preg_match("/^([^\t]+)\t([^\t\n]+)$/", $x, $the_fields)) {
-      $the_output .= t("Parse error on line %line.<br />\n", array("%line" => $i + 1));
-      
+      drupal_set_message(t("Parse error on line %line.", array("%line" => $i + 1)), "error");
+      $error = 1;
       continue;
     }
     
@@ -482,7 +455,7 @@
       array("quote" => $the_fields[1], "author" => $the_fields[2]);
   }
 
-  if (!$the_output) {
+  if (!$error) {
     $the_query = <<<EOT
 INSERT INTO {quotes_quotes}
   (qid, quote, author, ctime, mtime, uid)
@@ -498,9 +471,9 @@
       db_query($the_query, db_next_id("quotes_qid"), $x['quote'], $x['author'], $the_time, $the_time, $user->uid);
     
       if ($_quotes_err_num) {
-        $the_output = t("%line quotes added. ", array("%line", $i));
-        $the_output .= t("Error inserting quote on line %line.<br />\n", array("%line", $i));
-        
+        drupal_set_message(t("%line quotes added.", array("%line", $i)));
+        drupal_set_message(t("Error inserting quote on line %line.", array("%line", $i)), "error");
+        $error = 1;
         break;
       }
     }
@@ -508,23 +481,14 @@
     restore_error_handler();
   }
 
-  if (!$the_output) {
-    $the_output = t("%line quotes added. ", array("%line" => count($the_quotes)));
+  if (!$error) {
+    drupal_set_message(t("%line quotes added.", array("%line" => count($the_quotes))));
     
     unset($_POST['edit']['quotes']);
   }
 
-  $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
-
   // show the add form again
-  $the_output .= _quotes_admin_add();
-
-  return $the_output;
+  return _quotes_admin_add();
 } // function _quotes_admin_import
 
 /**
@@ -535,23 +499,13 @@
  * @return string The form to be displayed.
  */
 function _quotes_admin_edit($in_qid) {
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   $the_result = db_query("SELECT q.* FROM {quotes_quotes} q WHERE q.qid = '%d'", $in_qid);
   $the_quote = db_fetch_object($the_result);
 
   if (!$the_quote) {
-    $the_output = t("Quote %qid does not exist.", array("%qid" => $in_qid));
-    $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
-
-    return $the_output;
+    drupal_set_message(t("Quote %qid does not exist.", array("%qid" => $in_qid)), "error");
+    // show the overview list
+    return _quotes_overview("admin");
   }
 
   $the_form  = form_textarea(t("Quote"), "quote", $the_quote->quote, 70, 3, t("The actual quote text. Newlines do not need to be escaped."));
@@ -570,10 +524,6 @@
 function _quotes_admin_save() {
   global $user, $_quotes_err_num;
 
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   $the_qid = $_POST['edit']['qid'];
   
   // replace CRLF and CR with LF
@@ -581,26 +531,20 @@
   $the_author = trim($_POST['edit']['author']);
 
   if (!$the_qid) {
-    $the_output .= t("No quote ID specified.<br />\n");
+    drupal_set_message(t("No quote ID specified."), "error");
+    return;
   }
 
   if (!$the_quote) {
-    $the_output .= t("Please enter a quote.<br />\n");
+    drupal_set_message(t("Please enter a quote."), "error");
+    // show the edit form again
+    return _quotes_admin_edit($the_qid);
   }
   
   if (!$the_author) {
-    $the_output .= t("Please enter an author.<br />\n");
-  }
-
-  if ($the_output) {
-    $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
-
-    return $the_output;
+    drupal_set_message(t("Please enter an author."), "error");
+    // show the edit form again
+    return _quotes_admin_edit($the_qid);
   }
 
   $the_query = <<<EOT
@@ -618,23 +562,15 @@
   restore_error_handler();
 
   if (!$_quotes_err_num) {
-    $the_output = t("Quote saved.");
-    $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
+    drupal_set_message(t("Quote saved."));
 
     // show the overview list
-    $the_output .= _quotes_overview("admin");
+    return _quotes_overview("admin");
   }
   else {
     // show the edit form again
-    $the_output .= _quotes_admin_edit($the_qid);
+    return _quotes_admin_edit($the_qid);
   }
-
-  return $the_output;
 } // function _quotes_admin_save
 
 /**
@@ -647,32 +583,19 @@
 function _quotes_admin_delete($in_qid) {
   global $_quotes_err_num;
 
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   set_error_handler("_quotes_error_handler");
   db_query("DELETE FROM {quotes_quotes} WHERE qid = '%d'", $in_qid);
   restore_error_handler();
 
   if (!$_quotes_err_num && db_affected_rows()) {
-    $the_output .= t("Quote deleted.");
+    drupal_set_message(t("Quote deleted."));
   }
   else {
-    $the_output .= t("Could not delete quote.");
+    drupal_set_message(t("Could not delete quote."), "error");
   }
 
-  $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
-
   // show the overview list
-  $the_output .= _quotes_overview("admin");
-
-  return $the_output;
+  return _quotes_overview("admin");
 } // function _quotes_admin_delete
 
 /**
@@ -719,7 +642,7 @@
 function _quotes_overview($in_type = "user") {
   $the_max = 50;
 
-  if (($in_type == "admin") && user_access("administer quotes")) {
+  if ($in_type == "admin") {
     $is_admin = true;
   }
 
@@ -763,10 +686,6 @@
 function _quotes_install() {
   global $_quotes_err_num;
 
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   // get version information
   $is_installed = _quotes_is_installed();
   $the_current_ver = _quotes_version();
@@ -774,14 +693,15 @@
 
   if ($is_installed) {
     // don't reinstall
-    $the_output = t("Version already installed.");
+    drupal_set_message(t("Version already installed."), "error");
+    $error = 1;
   }
   elseif ($the_installed_ver['build'] > $the_current_ver['build']) {
     // don't install an older version
-    $the_output = t("Cannot install an older version.");
+    drupal_set_message(t("Cannot install an older version."), "error");
   }
   
-  if (!$the_output) {
+  if (!$error) {
     $the_query = <<<EOT
 CREATE TABLE {quotes_quotes} (
   qid INTEGER NOT NULL PRIMARY KEY,
@@ -798,25 +718,17 @@
 
     if ($_quotes_err_num) {
       // couldn't create table
-      $the_output =
-        t("Could not create the quotes table. Please try again.");
+      drupal_set_message(t("Could not create the quotes table. Please try again."), "error");
     }
     else {
       // installed successfully
       variable_set("quotes_version", $the_current_ver);
 
-      $the_output = t("Quotes module version %vers successfully installed. You can now use the \"administer &gt; quotes\" menu to add and manage quotes.", array("%vers" => $the_current_ver['text']));
+      drupal_set_message(t("Quotes module version %vers successfully installed. You can now use the \"administer &gt; quotes\" menu to add and manage quotes.", array("%vers" => $the_current_ver['text'])));
     }
   }
   
-  $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
-
-  return $the_output;
+  return;
 } // function _quotes_install
 
 /**
@@ -828,13 +740,9 @@
 function _quotes_remove() {
   global $_quotes_err_num;
 
-  if (!user_access("administer quotes")) {
-    return message_access();
-  }
-  
   // don't reinstall
   if (!_quotes_is_installed()) {
-    $the_output = t("Current version not installed.");
+    drupal_set_message(t("Current version not installed."), "error");
   }
   else {
     set_error_handler("_quotes_error_handler");    
@@ -843,25 +751,18 @@
 
     if ($_quotes_err_num) {
       // couldn't drop table
-      $the_output = t("Could not remove the quotes table.");
+      drupal_set_message(t("Could not remove the quotes table."), "error");
     }
     else {
       variable_del("quotes_version");
       variable_del("quotes_title");
       variable_del("quotes_leader");
       
-      $the_output = t("Quotes module version %vers successfully removed.", array("%vers" => $the_current_ver['text']));
+      drupal_set_message(t("Quotes module version %vers successfully removed.", array("%vers" => $the_current_ver['text'])));
     }      
   }
 
-  $the_output = <<<EOT
-<p>
-  $the_output
-</p>
-
-EOT;
-
-  return $the_output;
+  return;
 } // function _quotes_remove
 
 /**
