Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $Id$
- /**
- * @file
- * Lets users add private annotations to nodes.
- *
- * Adds a text field when a node is displayed
- * so that authenticated users may make notes.
- */
- /**
- * Implementation of hook_menu().
- */
- function annotate_menu() {
- $items['admin/annotate'] = array(
- 'title' => 'Node annotation',
- 'description' => 'Adjust node annotation options.',
- 'position' => 'right',
- 'weight' => -5,
- 'page callback' => 'system_admin_menu_block_page',
- 'access arguments' => array('administer site configuration'),
- 'file' => 'system.admin.inc',
- 'file path' => drupal_get_path('module', 'system'),
- );
- $items['admin/annotate/settings'] = array(
- 'title' => 'Annotation settings',
- 'description' => 'Change how annotations behave.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('annotate_admin_settings'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'annotate.admin.inc',
- );
- return $items;
- }
- function annotate_view($node,$view_mode){
- // nem fut le
- return $node;
- }
- /**
- * Implementation of hook_nodeapi().
- */
- function annotate_nodeapi(&$node, $op, $teaser, $page) {
- global $user;
- switch ($op) {
- // The 'view' operation means the node is about to be displayed.
- case 'view':
- // Abort if the user is an anonymous user (not logged in) or
- // if the node is not being displayed on a page by itself
- // (for example, it could be in a node listing or search result).
- if ($user->uid == 0 || !$page) {
- break;
- }
- // Find out which node types we should annotate.
- $types_to_annotate = variable_get('annotate_nodetypes', array('page'));
- // Abort if this node is not one of the types we should annotate.
- if (!in_array($node->type, $types_to_annotate)) {
- break;
- }
- // Add our form as a content item.
- $node->content['annotation_form'] = array(
- '#value' => drupal_get_form('annotate_entry_form', $node),
- '#weight' => 10
- );
- break;
- }
- }
- /**
- * Define the form for entering an annotation.
- */
- function annotate_entry_form($form_state, $node) {
- // Define a fieldset.
- $form['annotate'] = array(
- '#type' => 'fieldset',
- '#title' => t('Annotations'),
- );
- // Define a textarea inside the fieldset.
- $form['annotate']['note'] = array(
- '#type' => 'textarea',
- '#title' => t('Notes'),
- '#default_value' => isset($node->annotation) ? $node->annotation : '',
- '#description' => t('Make your personal annotations about this content here.
- Only you (and the site administrator) will be able to see them.')
- );
- // For convenience, save the node ID.
- $form['annotate']['nid'] = array(
- '#type' => 'value',
- '#value' => $node->nid,
- );
- // Define a submit function.
- $form['annotate']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Update'),
- );
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement