From 96576a6ef748f960b1f8318aa5d425627627d851 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 15 Jun 2001 07:30:44 +0000 Subject: - 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. --- modules/meta.module | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 modules/meta.module (limited to 'modules/meta.module') diff --git a/modules/meta.module b/modules/meta.module new file mode 100644 index 000000000..e8e6fc0dc --- /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 -- cgit v1.2.3