'admin/annotate', 'title' => t('Node annotation'), 'description' => t('Adjust node annotation options.'), 'position' => 'right', 'weight' => -5, 'callback' => 'system_admin_menu_block_page', 'access' => user_access('administer site configuration') ); $items[] = array( 'path' => 'admin/annotate/settings', 'title' => t('Annotation 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() { /* original code: */ /* $form['annotate_nodetypes'] = array( '#type' => 'checkboxes', '#title' => t('Users may annotate these node types'), '#options' => node_get_types('names'), '#default_value' => variable_get('annotate_nodetype_', array('story')), '#description' => t('A text field will be available on these node types to make user-specific notes.'), ); */ /** ************ Changed to: ****************** */ /* we don't store these nodetypes in an array but in single variables as nodeprofile does. */ $form['annotate_nodetypes'] = array( '#type' => 'fieldset', '#title' => t('Users may annotate these node types'), '#description' => t('A text field will be available on these node types to make user-specific notes.'), ); foreach(node_get_types() as $type => $name) { $form['annotate_nodetypes']['annotate_nodetype_' . $type] = array( '#type' => 'checkbox', '#title' => $type, '#return_value' => 1, '#default_value' => variable_get('annotate_nodetype_' . $type, 0), ); } /** ************ End of change. ****************** */ $form['annotate_deletion'] = array( '#type' => 'radios', '#title' => t('Annotations will be deleted'), '#description' => t('Select a method for deleting annotations.'), '#options' => array( t('Never'), t('Randomly'), t('After 30 days') ), '#default_value' => variable_get('annotate_deletion', 0) // default to Never ); $form['annotate_limit_per_node'] = array( '#type' => 'textfield', '#title' => t('Annotations per node'), '#description' => t('Enter the maximum number of annotations allowed per node (0 for no limit).'), '#default_value' => variable_get('annotate_limit_per_node', 1), '#size' => 3 ); // Retrieve stored variables in the settings form. $max = variable_get('annotate_limit_per_node', 1); $max = variable_get('annotate_deletion', 0); // Define a validation function. $form['#validate'] = array( 'annotate_admin_settings_validate' => array() ); return system_settings_form($form); } // Validate the settings form. function annotate_admin_settings_validate($form_id, $form_values) { if (!is_numeric($form_values['annotate_limit_per_node'])) { form_set_error('annotate_limit_per_node', t('Please enter a number.')); } } /** * 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; } /* original code */ /* 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['annotate_form'] = array( '#value' => drupal_get_form('annotate_entry_form', $node), '#weight' => 10 ); */ /** ************ Changed ****************** */ $type_to_annotate = variable_get('annotate_nodetype_' . $type, array('story')); if(!is_annotatetype($node)) { break; } else { // 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['annotate_form'] = array( '#value' => drupal_get_form('annotate_entry_form', $node), '#weight' => 10 ); } /** ************ End of change ****************** */ } } /** ************ Addition (this function is copied over from the nodeprofile module.) ****************** */ /* Check if nodetype is enabled for annotations. */ function is_annotatetype($type) { if (is_object($type)) { $type = $type->type; } return variable_get('annotate_nodetype_' . $type, 0); } /** ************ End of addition ****************** */ /** * 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.')); }