From 96576a6ef748f960b1f8318aa5d425627627d851 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 15 Jun 2001 07:30:44 +0000 Subject: [PATCH] - Added meta.module, an improved index.module that allows you to associate different collections - think "combobox" here - with different content types, all hardcoded references to "section" have been removed and the admin-friendliness of the meta admin section has been slightly improved. I'll keep working on it during the weekend - if time allows me to. Moreover, I'll focus on the usability/user-friendlines of the meta admin section as well as graceful input-checking, and error-handling. Requires an SQL update, see updates/2.00-to-x.xx.sql! Index.module will be removed, or meta.module will be renamed as soon we can ditch one of them. For now, having both coexist is not going to harm your setup and is useful to make a comparison and / or to migrate from index.module to meta.module. Index.module is de-coupled form the rest of the system so you will have to use meta.module after having upgraded. You have been warned. - Updated CHANGELOG. --- CHANGELOG | 3 +- includes/node.inc | 15 ++-- modules/meta.module | 165 +++++++++++++++++++++++++++++++++++++ modules/poll.module | 6 +- modules/poll/poll.module | 6 +- modules/story.module | 6 +- modules/story/story.module | 6 +- updates/2.00-to-x.xx.sql | 32 ++++++- 8 files changed, 215 insertions(+), 24 deletions(-) create mode 100644 modules/meta.module diff --git a/CHANGELOG b/CHANGELOG index 07bbe8257fe..3270495d25c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,7 +12,8 @@ drupal x.xx, xx/xx/xxxx (CVS, unstable) - rewrote section code and renamed it to structure.module: * supports both "categories" and "topics" (cfr. Scoop, SlashCode). Topics can be nested to create a multi-level hierarchy. * added "auto-post new submissions" feature versus "moderate new submissions". -- renamed hostname.conf to conf.php for security's sake. +- rewrote configuration file resolving: + * Drupal tries to locate a configuration file that matches your domainname or uses conf.php if the former failed. Note also that the configuration files got renamed from .conf to .php for security's sake on mal-configured Drupal sites. - added poll.module. - added conf.module: * moved most of the configuration options from hostname.conf to the new administration section. diff --git a/includes/node.inc b/includes/node.inc index 94972461f53..ec88c662c31 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -213,23 +213,18 @@ function node_preview($node) { } -function node_attributes_edit($edit) { - return index_collection_form("section", ($edit[section] ? $edit[section] : "section:". field_get($edit[attributes], "section") .";")); +function node_attributes_edit($type, $edit) { + return meta_form($type, $edit); } -function node_attributes_save($edit) { - if ($edit[nid] && $node = node_get_array(array("nid" => $edit[nid]))) { - return field_merge($node[attributes], $edit[section]); - } - else { - return $edit[section]; - } +function node_attributes_save($type, $edit) { + return meta_save($type, $edit); } function node_attributes_view($string) { foreach (explode(",", $string) as $data) { $entry = explode("=", $data); - if (in_array($entry[0], array("section"))) { + if ($entry[0] && $entry[1]) { $array[] = "$entry[1]"; } } diff --git a/modules/meta.module b/modules/meta.module new file mode 100644 index 00000000000..e8e6fc0dc72 --- /dev/null +++ b/modules/meta.module @@ -0,0 +1,165 @@ + + To be written. + name%'"); + while ($tag = db_fetch_object($t)) { + $array[$tag->attributes] = $tag->name; + } + $form .= form_select($collection->name, $collection->name, $edit[$collection->name], $array); + } + return $form; +} + +function meta_save($type, $edit = array()) { + $result = db_query("SELECT * FROM collection WHERE types LIKE '%". check_input($type) ."%'"); + while ($collection = db_fetch_object($result)) { + $output = field_merge($output, $edit[$collection->name]); + } + return $output; +} + +function meta_get_collection($cid) { + return db_fetch_array(db_query("SELECT * FROM collection WHERE cid = '". check_input($cid) ."'")); +} + +function meta_get_tag($tid) { + return db_fetch_array(db_query("SELECT * FROM tag WHERE tid = '". check_input($tid) ."'")); +} + +function meta_form_collection($edit = array()) { + global $REQUEST_URI; + + $form .= form_textfield("Collection name", "name", $edit[name], 50, 64, "Required. The name for this group or collection of meta-tags. Example: 'Software'."); + $form .= form_textfield("Types", "types", $edit[types], 50, 64, "Required. A comma-seperated list of node types you want to associate this collection with. Example: 'story, book'."); + $form .= form_submit("Submit"); + + if ($edit[cid]) { + $form .= form_submit(t("Delete")); + $form .= form_hidden("cid", $edit[cid]); + } + + return form($REQUEST_URI, $form); +} + +function meta_form_tag($edit = array()) { + global $REQUEST_URI; + + $form .= form_textfield("Meta-tag name", "name", $edit[name], 50, 64, "Required. The name for this meta-tag. Example: 'Apache'."); + $form .= form_textfield("Attributes", "attributes", $edit[attributes], 50, 64, htmlentities("Required. Format: :;:;. Example: 'software=apache,type=webserver,os=linux,'.")); + $form .= form_textfield("Collections", "collections", $edit[collections], 50, 64, "Required. A comma-seperated list of collections you want to associate this meta-tag with. Example: 'Software, Internet'"); + $form .= form_submit("Submit"); + + if ($edit[tid]) { + $form .= form_submit(t("Delete")); + $form .= form_hidden("tid", $edit[tid]); + } + + return form($REQUEST_URI, $form); +} + +function meta_save_collection($edit) { + if ($edit[cid] && $edit[name]) { + db_query("UPDATE collection SET name = '". check_input($edit[name]) ."', types = '". check_input($edit[types]) ."' WHERE cid = '$edit[cid]'"); + } + else if ($edit[cid]) { + db_query("DELETE FROM collection WHERE cid = '". check_input($edit[cid]) ."'"); + } + else { + db_query("INSERT INTO collection (name, types) VALUES ('". check_input($edit[name]) ."', '". check_input($edit[types]) ."')"); + } +} + +function meta_save_tag($edit) { + if ($edit[tid] && $edit[name]) { + db_query("UPDATE tag SET name = '". check_input($edit[name]) ."', attributes = '". check_input($edit[attributes]) ."', collections = '". check_input($edit[collections]) ."' WHERE tid = '$edit[tid]'"); + } + else if ($edit[tid]) { + db_query("DELETE FROM tag WHERE tid = '". check_input($edit[tid]) ."'"); + } + else { + db_query("INSERT INTO tag (name, attributes, collections) VALUES ('". check_input($edit[name]) ."', '". check_input($edit[attributes]) ."', '". check_input($edit[collections]) ."')"); + } +} + +function meta_verify() { + foreach (module_list() as $name) { + if (module_hook($name, "status") && $name != "node") { + $output .= "

". ucfirst($name) ." type

"; + $output .= meta_form($name) ."
"; + } + } + return form("", $output); +} + +function meta_overview() { + $result = db_query("SELECT * FROM collection ORDER BY name"); + + $output .= "

Collection overview

"; + $output .= "\n"; + $output .= " \n"; + while ($collection = db_fetch_object($result)) { + $output .= " \n"; + } + $output .= "
namenode typesoperations
". check_output($collection->name) ."". check_output($collection->types) ."cid\">edit collection
\n"; + + $result = db_query("SELECT * FROM tag ORDER BY name"); + + $output .= "

Meta-tag overview

"; + $output .= "\n"; + $output .= " \n"; + while ($tag = db_fetch_object($result)) { + $output .= " \n"; + } + $output .= "
namecollectionsmeta attributesoperations
". check_output($tag->name) ."". check_output($tag->collections) ."". check_output($tag->attributes) ."tid\">edit tag
\n"; + + return $output; +} + +function meta_admin() { + global $edit, $type, $op, $id; + + print "add new collection | add new meta-tag | verify node forms | overview | help
\n"; + + switch ($op) { + case "add": + if ($type == "collection") + print meta_form_collection(); + else + print meta_form_tag(); + break; + case "edit": + if ($type == "collection") + print meta_form_collection(meta_get_collection($id)); + else + print meta_form_tag(meta_get_tag($id)); + break; + case "help": + print meta_help(); + break; + case "verify": + print meta_verify(); + break; + case "Delete": + $edit[name] = 0; + // fall through: + case "Submit": + if ($type == "collection") + print status(meta_save_collection($edit)); + else + print status(meta_save_tag($edit)); + // fall through: + default: + print meta_overview(); + } +} + +?> \ No newline at end of file diff --git a/modules/poll.module b/modules/poll.module index df4c64b5740..880529c686b 100644 --- a/modules/poll.module +++ b/modules/poll.module @@ -202,7 +202,7 @@ function poll_form($edit = array(), $nocheck = 0) { $form .= form_select(t("Poll duration"), "runtime", $edit[runtime] ? $edit[runtime] : t("1 week"), $duration, t("After this period, the poll will automatically be closed.")); if ($admin) $form .= form_select(t("Poll status"), "active", $edit[active], $active); - $form .= node_attributes_edit($edit); + $form .= node_attributes_edit("poll", $edit); // hidden fields: if ($edit[nid] > 0) { @@ -232,10 +232,10 @@ function poll_save($edit) { global $status, $user; if (!$edit[nid]) { - $nid = node_save($edit, array(active => 1, attributes => node_attributes_save($edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => "")); + $nid = node_save($edit, array(active => 1, attributes => node_attributes_save("poll", $edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => "")); } else if (user_access($user)) { - $nid = node_save($edit, array(active, attributes => node_attributes_save($edit), cid, tid, runtime, title, type => "poll")); + $nid = node_save($edit, array(active, attributes => node_attributes_save("poll", $edit), cid, tid, runtime, title, type => "poll")); db_query("DELETE FROM poll_choices WHERE nid='" . $nid . "'"); } if ($nid) { diff --git a/modules/poll/poll.module b/modules/poll/poll.module index df4c64b5740..880529c686b 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -202,7 +202,7 @@ function poll_form($edit = array(), $nocheck = 0) { $form .= form_select(t("Poll duration"), "runtime", $edit[runtime] ? $edit[runtime] : t("1 week"), $duration, t("After this period, the poll will automatically be closed.")); if ($admin) $form .= form_select(t("Poll status"), "active", $edit[active], $active); - $form .= node_attributes_edit($edit); + $form .= node_attributes_edit("poll", $edit); // hidden fields: if ($edit[nid] > 0) { @@ -232,10 +232,10 @@ function poll_save($edit) { global $status, $user; if (!$edit[nid]) { - $nid = node_save($edit, array(active => 1, attributes => node_attributes_save($edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => "")); + $nid = node_save($edit, array(active => 1, attributes => node_attributes_save("poll", $edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => "")); } else if (user_access($user)) { - $nid = node_save($edit, array(active, attributes => node_attributes_save($edit), cid, tid, runtime, title, type => "poll")); + $nid = node_save($edit, array(active, attributes => node_attributes_save("poll", $edit), cid, tid, runtime, title, type => "poll")); db_query("DELETE FROM poll_choices WHERE nid='" . $nid . "'"); } if ($nid) { diff --git a/modules/story.module b/modules/story.module index 1325c0d3f30..527523985d6 100644 --- a/modules/story.module +++ b/modules/story.module @@ -45,7 +45,7 @@ function story_form($edit = array()) { $form .= form_item(t("Your name"), format_username(($edit[userid] ? $edit[userid] : $user->userid))); $form .= form_hidden("userid", $edit[userid]); $form .= form_textfield(t("Subject"), "title", $edit[title], 50, 64); - $form .= node_attributes_edit($edit); + $form .= node_attributes_edit("story", $edit); $form .= form_textarea(t("Abstract"), "abstract", $edit[abstract], 70, 10, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))); $form .= form_textarea(t("Body"), "body", $edit[body], 70, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))); @@ -73,10 +73,10 @@ function story_save($edit) { global $status, $user; if (!$edit[nid]) { - node_save($edit, array(abstract, attributes => node_attributes_save($edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0)); + node_save($edit, array(abstract, attributes => node_attributes_save("story", $edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0)); } else if (user_access($user)) { - node_save($edit, array(abstract, attributes => node_attributes_save($edit), body, title, type => "story")); + node_save($edit, array(abstract, attributes => node_attributes_save("story", $edit), body, title, type => "story")); } } diff --git a/modules/story/story.module b/modules/story/story.module index 1325c0d3f30..527523985d6 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -45,7 +45,7 @@ function story_form($edit = array()) { $form .= form_item(t("Your name"), format_username(($edit[userid] ? $edit[userid] : $user->userid))); $form .= form_hidden("userid", $edit[userid]); $form .= form_textfield(t("Subject"), "title", $edit[title], 50, 64); - $form .= node_attributes_edit($edit); + $form .= node_attributes_edit("story", $edit); $form .= form_textarea(t("Abstract"), "abstract", $edit[abstract], 70, 10, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))); $form .= form_textarea(t("Body"), "body", $edit[body], 70, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))); @@ -73,10 +73,10 @@ function story_save($edit) { global $status, $user; if (!$edit[nid]) { - node_save($edit, array(abstract, attributes => node_attributes_save($edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0)); + node_save($edit, array(abstract, attributes => node_attributes_save("story", $edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0)); } else if (user_access($user)) { - node_save($edit, array(abstract, attributes => node_attributes_save($edit), body, title, type => "story")); + node_save($edit, array(abstract, attributes => node_attributes_save("story", $edit), body, title, type => "story")); } } diff --git a/updates/2.00-to-x.xx.sql b/updates/2.00-to-x.xx.sql index 374a14819c7..d1b2ac98012 100644 --- a/updates/2.00-to-x.xx.sql +++ b/updates/2.00-to-x.xx.sql @@ -239,4 +239,34 @@ ALTER TABLE feed CHANGE attribute attributes varchar(255) DEFAULT '' NOT NULL; ALTER TABLE item CHANGE attribute attributes varchar(255) DEFAULT '' NOT NULL; # 12/06/01 -ALTER TABLE watchdog DROP link; \ No newline at end of file +ALTER TABLE watchdog DROP link; + +# 15/06/01 +CREATE TABLE tag ( + tid int(10) unsigned DEFAULT '0' NOT NULL auto_increment, + name varchar(32) DEFAULT '' NOT NULL, + attributes varchar(255) DEFAULT '' NOT NULL, + collections varchar(32) DEFAULT '' NOT NULL, + UNIQUE name (name, collections), + PRIMARY KEY (tid) +); + +CREATE TABLE collection ( + cid int(10) unsigned DEFAULT '0' NOT NULL auto_increment, + name varchar(32) DEFAULT '' NOT NULL, + types varchar(128) DEFAULT '' NOT NULL, + UNIQUE name (name), + PRIMARY KEY (cid) +); + +// test data: + +INSERT INTO collection (name, types) VALUES ('Software', 'story, book, poll'); +INSERT INTO collection (name, types) VALUES ('Hardware', 'story'); + +INSERT INTO tag (collections, name) VALUES ('Software', 'ThatWare'); +INSERT INTO tag (collections, name) VALUES ('Software', 'phpWeblog'); +INSERT INTO tag (collections, name) VALUES ('Software', 'PHP-Nuke'); +INSERT INTO tag (collections, name) VALUES ('Software', 'Drupal'); +INSERT INTO tag (collections, name) VALUES ('Hardware', 'ARM CPU'); +INSERT INTO tag (collections, name) VALUES ('Hardware', 'x86 CPU');