<?php
-
+// Module metainfo
/**
* Implementation of hook_node_info().
*/
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
return TRUE;
- } else if (user_access('edit any metasearch interface', $account)) {
+ }
+ elseif (user_access('edit any metasearch interface', $account)) {
return TRUE;
}
}
}
+
+
+// Node config
/**
* Implementation of hook_form().
*/
'#default_value' => $node->title,
'#weight' => -5
);
-
+ $form['pz2_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pazpar2/Service Proxy path'),
+ '#description' => t('Absolute URL path without leading slash'),
+ '#required' => TRUE,
+ '#default_value' => isset($node->pz2_path) ? $node->pz2_path : 'pazpar2',
+ '#weight' => 0
+ );
return $form;
}
/**
+* Implementation of hook_insert().
+*/
+function mkdru_insert($node) {
+ db_query("INSERT INTO {mkdru} (nid, vid, pz2_path) VALUES (%d, %d, '%s')",
+ $node->nid, $node->vid, $node->pz2_path);
+}
+
+/**
+* Implementation of hook_update().
+*/
+function mkdru_update($node) {
+ if ($node->revision) {
+ // New revision; treat it as a new record.
+ mkdru_insert($node);
+ }
+ else {
+ db_query("UPDATE {mkdru} SET pz2_path = '%s' WHERE vid = '%d'", $node->pz2_path, $node->vid);
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ *
+ * When a node revision is deleted, we need to remove the corresponding record
+ * from our table. The only way to handle revision deletion is by implementing
+ * hook_nodeapi().
+ */
+function node_example_nodeapi(&$node, $op, $teaser, $page) {
+ switch ($op) {
+ case 'delete revision':
+ // Notice that we're matching a single revision based on the node's vid.
+ db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
+ break;
+ }
+}
+
+/**
+ * Implementation of hook_delete().
+ *
+ * When a node is deleted, we need to remove all related records from our table.
+ */
+function node_example_delete($node) {
+ // Deleting by nid covers all revisions.
+ db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
+}
+
+
+
+// Node rendering
+/**
+* Implementation of hook_load()
+*/
+function mkdru_load($node) {
+ return db_fetch_object(db_query('SELECT pz2_path FROM {mkdru} WHERE vid = %d', $node->vid));
+}
+
+/**
* Implementation of hook_theme().
*/
function mkdru_theme() {