You are here

function print_nodeapi in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 5.4 print.module \print_nodeapi()
  2. 5.3 print.module \print_nodeapi()
  3. 5.x print.module \print_nodeapi()

Implementation of hook_nodeapi().

File

./print.module, line 438
Displays Printer-friendly versions of Drupal pages.

Code

function print_nodeapi(&$node, $op = 'view', $teaser, $page) {
  switch ($op) {
    case 'view':

      // Insert content corner links
      if (!$teaser && isset($node->build_mode) && $node->build_mode === NODE_BUILD_NORMAL) {
        $node->content['print_links'] = array(
          '#prefix' => '<span class="print-link">',
          '#value' => '',
          '#suffix' => '</span>',
          '#weight' => -101,
        );
        $print_html_link_pos = variable_get('print_html_link_pos', unserialize(PRINT_HTML_LINK_POS_DEFAULT));
        if (!empty($print_html_link_pos['corner'])) {
          $node->content['print_links']['#value'] .= print_insert_link(NULL, $node);
        }
      }
      break;
    case 'load':
      $res = db_fetch_object(db_query("SELECT link, comments, url_list FROM {print_node_conf} WHERE nid = %d", $node->nid));
      $node->print_display = $res ? intval($res->link) : variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
      $node->print_display_comment = $res ? intval($res->comments) : variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
      $node->print_display_urllist = $res ? intval($res->url_list) : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
      break;
    case 'insert':
    case 'update':
      if (user_access('administer print') || user_access('node-specific print configuration')) {
        if (!isset($node->print_display)) {
          $node->print_display = variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
        }
        if (!isset($node->print_display_comment)) {
          $node->print_display_comment = variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
        }
        if (!isset($node->print_display_urllist)) {
          $node->print_display_urllist = variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
        }
        _print_node_conf_modify($node->nid, $node->print_display, $node->print_display_comment, $node->print_display_urllist);
      }
      break;
    case 'delete':
      db_query("DELETE FROM {print_node_conf} WHERE nid = %d", $node->nid);
      db_query("DELETE FROM {print_page_counter} WHERE path = 'node/%d'", $node->nid);
      break;
  }
}