You are here

function _printfriendly_get_button_script in PrintFriendly & PDF 7.2

1 call to _printfriendly_get_button_script()
printfriendly_create_button in ./printfriendly.module
Shared function generate code for printfriendly button for nodes and block.

File

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

Code

function _printfriendly_get_button_script() {
  $added =& drupal_static(__FUNCTION__, FALSE);
  if ($added) {
    return NULL;
  }
  $added = TRUE;
  $print_settings = variable_get('printfriendly_options', array(
    'pfdisableClickToDel' => 0,
    'pfHideImages' => 0,
    'pfImageDisplayStyle' => 'right',
    'pfDisableEmail' => 0,
    'pfDisablePDF' => 0,
    'pfDisablePrint' => 0,
  ));
  $script = '';
  foreach ($print_settings as $setting => $value) {
    $script .= 'var ' . $setting . ' = ';
    if (is_numeric($value)) {
      $script .= (int) $value;
    }
    else {
      $script .= "'" . (string) addslashes($value) . "'";
    }
    $script .= ';';
  }
  $script .= <<<SNIPPET
(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';
if ('https:' === document.location.protocol){
  js='https://pf-cdn.printfriendly.com/ssl/main.js'
}else{
  js='http://cdn.printfriendly.com/printfriendly.js'
}
pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();
SNIPPET;
  return $script;
}