annotate/0000755000175000017500000000000011007640217010761 5ustar racracannotate/annotate.info0000644000175000017500000000015111007637105013446 0ustar racrac; $Id$ name = Annotate description = Allows users to annotate nodes. package = Example version = "$Name$"annotate/annotate.module0000644000175000017500000000602611007640217014005 0ustar racrac 'admin/settings/annotate', 'title' => t('Annotate settings'), 'description' => t('Change how annotations behave.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('annotate_admin_settings'), 'access' => user_access('administer site configuration') ); } return $items; } /** * Define the settings form. */ function annotate_admin_settings() { $form['annotate_nodetypes'] = array( '#type' => 'checkboxes', '#title' => t('Users may annotate these node types'), '#options' => node_get_types('names'), '#default_value' => variable_get('annotate_nodetypes', array('story')), '#description' => t('A text field will be available on these node types to make user-specific notes.'), ); $form['array_filter'] = array('#type' => 'hidden'); return system_settings_form($form); } /** * Implementation of hook_nodeapi(). */ function annotate_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { case 'view': global $user; // If only the node summary is being displayed, or if the // user is an anonymous user (not logged in), abort. if ($teaser || $user->uid == 0) { break; } $types_to_annotate = variable_get('annotate_nodetypes', array('story')); if (!in_array($node->type, $types_to_annotate)) { break; } // Get previously saved note, if any. $result = db_query("SELECT note FROM {annotations} WHERE uid = %d AND nid = %d", $user->uid, $node->nid); $node->annotation = db_result($result); // Add our form as a content item. $node->content['annotation_form'] = array( '#value' => drupal_get_form('annotate_entry_form', $node), '#weight' => 10 ); } } /** * Define the form for entering an annotation. */ function annotate_entry_form($node) { $form['annotate'] = array( '#type' => 'fieldset', '#title' => t('Annotations') ); $form['annotate']['nid'] = array( '#type' => 'value', '#value' => $node->nid ); $form['annotate']['note'] = array( '#type' => 'textarea', '#title' => t('Notes'), '#default_value' => $node->annotation, '#description' => t('Make your personal annotations about this content here. Only you (and the site administrator) will be able to see them.') ); $form['annotate']['submit'] = array( '#type' => 'submit', '#value' => t('Update') ); return $form; } /** * Save the annotation to the database. */ function annotate_entry_form_submit($form_id, $form_values) { global $user; $nid = $form_values['nid']; $note = $form_values['note']; db_query("DELETE FROM {annotations} WHERE uid = %d and nid = %d", $user->uid, $nid); db_query("INSERT INTO {annotations} (uid, nid, note, timestamp) VALUES (%d, %d, '%s', %d)", $user->uid, $nid, $note, time()); drupal_set_message(t('Your annotation was saved.')); }annotate/annotate.install0000644000175000017500000000167211007637075014200 0ustar racrac