You are here

function printfriendly_create_button in PrintFriendly & PDF 7

Same name and namespace in other branches
  1. 8.3 printfriendly.module \printfriendly_create_button()
  2. 8 printfriendly.module \printfriendly_create_button()
  3. 8.2 printfriendly.module \printfriendly_create_button()
  4. 7.5 printfriendly.module \printfriendly_create_button()
  5. 7.2 printfriendly.module \printfriendly_create_button()
  6. 7.3 printfriendly.module \printfriendly_create_button()
  7. 7.4 printfriendly.module \printfriendly_create_button()

Shared function generate code for printfriendly button for nodes and block.

Parameters

string $url: Path to the page to pass to PrintFriendly.

bool $popup: Whether the JavaScript should be added or not (popup).

Return value

string String containing html code for the button

3 calls to printfriendly_create_button()
printfriendly_block_view in ./printfriendly.module
Implements hook_block_view().
printfriendly_node_view in ./printfriendly.module
Implements hook_node_view().
printfriendly_views_handler_field_pfbutton::render in views/printfriendly_views_handler_field_pfbutton.inc
Render function: return html output.

File

./printfriendly.module, line 125
Adds PrintFriendly button to chosen node types and provides a block.

Code

function printfriendly_create_button($url = NULL, $popup = TRUE) {
  if (!$url && !is_numeric($url)) {
    $url = $_GET['q'];
  }
  $query_string = $_GET;
  unset($query_string['q']);
  $url = url($url, array(
    'absolute' => TRUE,
    'query' => $query_string,
  ));
  $js = 'http://cdn.printfriendly.com/printfriendly.js';
  if (!empty($GLOBALS['is_https'])) {
    $js = 'https://pf-cdn.printfriendly.com/ssl/main.js';
  }
  $image = variable_get('printfriendly_image', 'button-print-grnw20.png');
  if ($image == '_text_') {
    $link_content = '<span class="printfriendly-link printfriendly-text-link">';
    $link_content .= check_plain(variable_get('printfriendly_text', t('Print this page')));
    $link_content .= '</span>';
  }
  else {
    $image = drupal_get_path('module', 'printfriendly') . '/images/' . variable_get('printfriendly_image', 'button-print-grnw20.png');
    $link_content = theme('image', array(
      'path' => $image,
      'alt' => variable_get('printfriendly_description', t('Printer Friendly and PDF')),
    ));
  }
  $options = array(
    'attributes' => array(
      'class' => 'printfriendly',
      'onclick' => 'window.print(); return false;',
      'title' => variable_get('printfriendly_description', t('Printer Friendly and PDF')),
    ),
    'html' => TRUE,
    'query' => array(
      'url' => $url,
    ),
    'external' => TRUE,
  );
  if ($popup) {
    return array(
      '#markup' => l($link_content, 'http://www.printfriendly.com/print', $options),
      '#attached' => array(
        'js' => array(
          $js => array(
            'type' => 'external',
            'scope' => 'footer',
          ),
        ),
      ),
    );
  }
  else {
    unset($options['attributes']['onclick']);
    return array(
      '#markup' => l($link_content, 'http://www.printfriendly.com/print', $options),
    );
  }
}