You are here

function print_mail_nodeapi in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 5.4 print_mail/print_mail.module \print_mail_nodeapi()
  2. 5.3 print_mail/print_mail.module \print_mail_nodeapi()
  3. 5.x print_mail/print_mail.module \print_mail_nodeapi()

Implementation of hook_nodeapi().

File

print_mail/print_mail.module, line 207
Displays Printer-friendly versions of Drupal pages.

Code

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

      // Insert content corner links
      $print_mail_link_pos = variable_get('print_mail_link_pos', unserialize(PRINT_MAIL_LINK_POS_DEFAULT));
      if ($teaser === FALSE && !empty($print_mail_link_pos['corner']) && isset($node->build_mode) && $node->build_mode === NODE_BUILD_NORMAL) {
        $node->content['print_links']['#value'] .= print_mail_insert_link(NULL, $node);
      }
      break;
    case 'load':
      $res = db_fetch_object(db_query("SELECT link, comments, url_list FROM {print_mail_node_conf} WHERE nid = %d", $node->nid));
      $node->print_mail_display = $res ? intval($res->link) : variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
      $node->print_mail_display_comment = $res ? intval($res->comments) : variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
      $node->print_mail_display_urllist = $res ? intval($res->url_list) : variable_get('print_mail_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_mail_display)) {
          $node->print_mail_display = variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
        }
        if (!isset($node->print_mail_display_comment)) {
          $node->print_mail_display_comment = variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
        }
        if (!isset($node->print_mail_display_urllist)) {
          $node->print_mail_display_urllist = variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
        }
        _print_mail_node_conf_modify($node->nid, $node->print_mail_display, $node->print_mail_display_comment, $node->print_mail_display_urllist);
      }
      break;
    case 'delete':
      db_query("DELETE FROM {print_mail_node_conf} WHERE nid = %d", $node->nid);
      db_query("DELETE FROM {print_mail_page_counter} WHERE path = 'node/%d'", $node->nid);
      break;
  }
}