drupal/modules/meta.module

195 lines
6.7 KiB
Plaintext
Raw Normal View History

<?php
function meta_help() {
?>
To be written.
<?php
}
function meta_perm() {
return array("administer meta tags");
}
function meta_link($type) {
if ($type == "admin" && user_access("administer meta tags")) {
$links[] = "<a href=\"admin.php?mod=meta\">meta tags</a>";
}
return $links ? $links : array();
}
function meta_form($type, $edit = array()) {
2001-08-16 20:43:17 +00:00
if (!$edit[attributes]) $edit[attributes] = "";
$c = db_query("SELECT * FROM collection WHERE types LIKE '%". check_input($type) ."%'");
2001-08-16 20:43:17 +00:00
while ($collection = db_fetch_object($c)) {
unset($array);
2001-08-16 20:43:17 +00:00
2001-08-27 14:05:43 +00:00
$t = db_query("SELECT * FROM tag WHERE collections LIKE '%$collection->name%' ORDER BY name");
2001-08-16 20:43:17 +00:00
while ($tag = db_fetch_object($t)) {
if (strstr($edit[attributes], $tag->attributes)) {
$edit[$collection->name] = $tag->attributes;
}
$array[$tag->attributes] = $tag->name;
}
2001-08-16 20:43:17 +00:00
$form .= form_select($collection->name, $collection->name, $edit[$collection->name], $array);
}
2001-08-16 20:43:17 +00:00
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)) {
$array[] = $edit[$collection->name];
}
return $array ? implode(", ", $array) : "";
}
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'.");
Oops, a rather large commit: - Changed meta.module, node.module and index.php to use comma-seperated lists of attributes rather then "foo=a,bar=b" lists. This makes it a a lot easier to use both modules. In addition, error handling can be discarded as it can't be made any simpler, really ... It fits rather nicely in Drupal's design so I'm getting more and more happy with this meta.module (but we are not 100% there yet). - node.module, node.inc: + Improved the node-related admin interface so that navigating back and forth the administrative menus is made both easier and faster. + Removed some redundant database fields from the node table. See 2.00-to-x.xx.sql! + Added 2 news hooks called "node_insert" and "node_update". Just like this is the case with the existing hook "node_delete" these new hooks will automatically get called when a node has been inserted or udpated. Note that this is an optional call-back that only needs to be implemented when required. With the addition of these two hooks, the node mechanism (version 1) is pretty well completed. - watchdog.module: + Fixed bug whit the 'regular messages' query in the watchdog.module. - book.module: + Fixed bug in book.module: the 'parent' was not set properly when updating a book page. + Made it so that older versions of a book page are automatically reactived upon deletion of the most recent version, i.e. when doing a version roll-back. - comment.inc: + Undid Remco's patch to comment.inc; it does not work in some cases. - conf.module: + Fine-tuned some of the options in conf.module a bit. - marvin.theme: + Visual changes to make it look better on Windows browsers. Mind to give some feedback on this? + Fixed 3 HTML typos/bugs. + XHTML-ified the theme at a best effort basis; I didn't carry the XHTML specification with me. + Made use of the theme_slogan variable to display the site's slogan. + As soon we have at least one valid XHTML theme we can wonder on how to integrate other XML namespaces (cfr. MathML story at drop.org). - database.mysql: + Updated database.mysql so that it contains all the latest "database patches".
2001-06-17 18:31:25 +00:00
$form .= form_textfield("Attributes", "attributes", $edit[attributes], 50, 64, "Required. A comma-seperated list of keywords you want to associate this meta-tag with. Example: 'Computers, Software, Webservers'.");
$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: 'Section'.");
$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_preview() {
foreach (module_list() as $name) {
if (module_hook($name, "status") && $name != "node") {
$output .= "<H3>". ucfirst($name) ." type</H3>";
$output .= meta_form($name) ."<HR>";
}
}
return form("", $output);
}
function meta_overview() {
$result = db_query("SELECT * FROM collection ORDER BY name");
$output .= "<H3>Collection overview</H3>";
$output .= "<TABLE BORDER=\"1\" cellpadding=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH>name</TH><TH>node types</TH><TH>operations</TH></TR>\n";
while ($collection = db_fetch_object($result)) {
$output .= " <TR><TD>". check_output($collection->name) ."</TD><TD>". check_output($collection->types) ."</TD><TD><A HREF=\"admin.php?mod=meta&type=collection&op=edit&id=$collection->cid\">edit collection</A></TD></TR>\n";
}
$output .= "</TABLE>\n";
$result = db_query("SELECT * FROM tag ORDER BY name");
$output .= "<H3>Meta-tag overview</H3>";
$output .= "<TABLE BORDER=\"1\" cellpadding=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH>name</TH><TH>collections</TH><TH>meta attributes</TH><TH>operations</TH></TR>\n";
while ($tag = db_fetch_object($result)) {
$output .= " <TR><TD>". check_output($tag->name) ."</TD><TD>". check_output($tag->collections) ."</TD><TD>". check_output($tag->attributes) ."</TD><TD><A HREF=\"admin.php?mod=meta&type=tag&op=edit&id=$tag->tid\">edit tag</A></TD></TR>\n";
}
$output .= "</TABLE>\n";
return $output;
}
function meta_admin() {
global $edit, $type, $op, $id;
if (user_access("administer meta tags")) {
print "<SMALL><A HREF=\"admin.php?mod=meta&type=collection&op=add\">add new collection</A> | <A HREF=\"admin.php?mod=meta&type=tag&op=add\">add new meta-tag</A> | <A HREF=\"admin.php?mod=meta&op=preview\">preview node forms</A> | <A HREF=\"admin.php?mod=meta\">overview</A> | <A HREF=\"admin.php?mod=meta&op=help\">help</A></SMALL><HR>\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 "preview":
print meta_preview();
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();
}
}
else {
print message_access();
}
}
?>