Advertisement
Guest User

Untitled

a guest
Sep 27th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Lets users add private annotations to nodes.
  6. *
  7. * Adds a text field when a node is displayed
  8. * so that authenticated users may make notes.
  9. */
  10.  
  11. /**
  12. * Implementation of hook_menu().
  13. */
  14. function annotate_menu() {
  15.   $items['admin/annotate'] = array(
  16.   'title' => 'Node annotation',
  17.   'description' => 'Adjust node annotation options.',
  18.   'position' => 'right',
  19.   'weight' => -5,
  20.   'page callback' => 'system_admin_menu_block_page',
  21.   'access arguments' => array('administer site configuration'),
  22.   'file' => 'system.admin.inc',
  23.   'file path' => drupal_get_path('module', 'system'),
  24.   );
  25.  
  26.  
  27.   $items['admin/annotate/settings'] = array(
  28.   'title' => 'Annotation settings',
  29.   'description' => 'Change how annotations behave.',
  30.   'page callback' => 'drupal_get_form',
  31.   'page arguments' => array('annotate_admin_settings'),
  32.   'access arguments' => array('administer site configuration'),
  33.   'type' => MENU_NORMAL_ITEM,
  34.   'file' => 'annotate.admin.inc',
  35.   );
  36.  
  37.  
  38.    return $items;
  39.    
  40. }
  41.  
  42.  
  43. function annotate_view($node,$view_mode){
  44.    // nem fut le
  45.     return $node;
  46. }
  47.  
  48.  
  49.  
  50.  
  51. /**
  52. * Implementation of hook_nodeapi().
  53. */
  54. function annotate_nodeapi(&$node, $op, $teaser, $page) {
  55.    
  56.   global $user;
  57.   switch ($op) {
  58.     // The 'view' operation means the node is about to be displayed.
  59.       case 'view':
  60.     // Abort if the user is an anonymous user (not logged in) or
  61.     // if the node is not being displayed on a page by itself
  62.     // (for example, it could be in a node listing or search result).
  63.        if ($user->uid == 0 || !$page) {
  64.          break;
  65.        }
  66.        
  67.        // Find out which node types we should annotate.
  68.        $types_to_annotate = variable_get('annotate_nodetypes', array('page'));
  69.        // Abort if this node is not one of the types we should annotate.
  70.        if (!in_array($node->type, $types_to_annotate)) {
  71.          break;
  72.        }
  73.        // Add our form as a content item.
  74.        $node->content['annotation_form'] = array(
  75.        '#value' => drupal_get_form('annotate_entry_form', $node),
  76.        '#weight' => 10
  77.        );
  78.        break;
  79.   }
  80. }
  81.  
  82.  
  83.  
  84. /**
  85. * Define the form for entering an annotation.
  86. */
  87. function annotate_entry_form($form_state, $node) {
  88. // Define a fieldset.
  89.   $form['annotate'] = array(
  90.     '#type' => 'fieldset',
  91.     '#title' => t('Annotations'),
  92.   );
  93.   // Define a textarea inside the fieldset.
  94.   $form['annotate']['note'] = array(
  95.     '#type' => 'textarea',
  96.     '#title' => t('Notes'),
  97.     '#default_value' => isset($node->annotation) ? $node->annotation : '',
  98.     '#description' => t('Make your personal annotations about this content here.
  99.      Only you (and the site administrator) will be able to see them.')
  100.   );
  101. // For convenience, save the node ID.
  102.   $form['annotate']['nid'] = array(
  103.     '#type' => 'value',
  104.     '#value' => $node->nid,
  105.   );
  106.   // Define a submit function.
  107.   $form['annotate']['submit'] = array(
  108.    '#type' => 'submit',
  109.    '#value' => t('Update'),
  110.   );
  111.   return $form;
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement