You are here

function print_block in Printer, email and PDF versions 6

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

Implementation of hook_block().

File

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

Code

function print_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('Printer, email and PDF versions');
      $block[0]['cache'] = BLOCK_CACHE_PER_PAGE;
      $block[1]['info'] = t('Most printed');
      $block[1]['cache'] = BLOCK_CACHE_GLOBAL;
      return $block;
      break;
    case 'configure':
      return '';
    case 'save':
      return;
    case 'view':
      switch ($delta) {
        case 0:
          $nid = preg_replace('!^node/!', '', $_GET['q']);
          if (ctype_digit($nid)) {
            $node = node_load($nid);
            if (!node_access('view', $node)) {

              // If the user doesn't have access to the node, don't show any links
              $block['content'] = '';
              return;
            }
          }
          else {
            $node = NULL;
          }
          $block['content'] = '';
          foreach (array(
            'html' => 'print',
            'mail' => 'print_mail',
            'pdf' => 'print_pdf',
          ) as $format => $module) {
            $link_pos = variable_get('print_' . $format . '_link_pos', unserialize(PRINT_HTML_LINK_POS_DEFAULT));
            if (!empty($link_pos['block'])) {
              $func = $module . '_insert_link';
              if (function_exists($func)) {
                $links = $func(NULL, $node);
                if (!empty($links)) {
                  $block['content'] .= $links;
                }
              }
            }
          }
          break;
        case 1:
          $block['subject'] = t('Most printed');
          $result = db_query_range("SELECT path FROM {print_page_counter} LEFT JOIN {node} n ON path = CONCAT('node/', n.nid) WHERE status <> 0 OR status IS NULL ORDER BY totalcount DESC", 0, 3);
          if (db_affected_rows()) {
            $block['content'] = '<div class="item-list"><ul>';
            while ($obj = db_fetch_object($result)) {
              $block['content'] .= '<li>' . l(_print_get_title($obj->path), $obj->path) . '</li>';
            }
            $block['content'] .= '</ul></div>';
          }
          break;
      }
      return $block;
      break;
  }
}