Now all modules are in core modules folder
This commit is contained in:
parent
5ba1cdfa0b
commit
05b6a91b0c
1907 changed files with 0 additions and 0 deletions
336
modules/print/print_pdf/print_pdf.admin.inc
Normal file
336
modules/print/print_pdf/print_pdf.admin.inc
Normal file
|
@ -0,0 +1,336 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the administrative functions of the PDF version module.
|
||||
*
|
||||
* This file is included by the PDF version module, and includes the
|
||||
* settings form.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback for the PDF version module settings form.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see _print_pdf_tools()
|
||||
*/
|
||||
function print_pdf_settings() {
|
||||
$pdf_tools = _print_pdf_tools();
|
||||
|
||||
if ($pdf_tools != -1) {
|
||||
$form['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('PDF options'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_pdf_tool'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('PDF generation tool'),
|
||||
'#options' => $pdf_tools,
|
||||
'#default_value' => variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT),
|
||||
'#description' => t('This option selects the PDF generation tool being used by this module to create the PDF version.'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_link_pos'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('PDF version link'),
|
||||
'#default_value' => variable_get('print_pdf_link_pos', unserialize(PRINT_PDF_LINK_POS_DEFAULT)),
|
||||
'#options' => array('link' => t('Links area'), 'corner' => t('Content corner'), 'block' => t('Block'), 'help' => t('Help area')),
|
||||
'#description' => t('Choose the location of the link(s) to the PDF version. The Links area is usually below the node content, whereas the Content corner is placed in the upper-right corner of the node content. Unselect all options to disable the link. Even if the link is disabled, you can still view the PDF version of a node by going to !path/nid where nid is the numeric id of the node.', array('!path' => PRINTPDF_PATH)),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_link_teaser'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display link to the PDF version in teaser'),
|
||||
'#default_value' => variable_get('print_pdf_link_teaser', PRINT_PDF_LINK_TEASER_DEFAULT),
|
||||
'#description' => t('Enabling this will display the link in teaser mode.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Advanced link options'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_show_link'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Link style'),
|
||||
'#default_value' => variable_get('print_pdf_show_link', PRINT_PDF_SHOW_LINK_DEFAULT),
|
||||
'#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
|
||||
'#description' => t('Select the visual style of the link.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_link_use_alias'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use URL alias instead of node ID'),
|
||||
'#default_value' => variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT),
|
||||
'#description' => t('Enabling this will create the link using the URL alias instead of the node ID.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_link_class'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link class'),
|
||||
'#default_value' => variable_get('print_pdf_link_class', PRINT_PDF_LINK_CLASS_DEFAULT),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 250,
|
||||
'#description' => t('This can be used by themers to change the link style or by jQuery modules to open in a new window (e.g. greybox or thickbox). Multiple classes can be specified, separated by spaces.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_node_link_visibility'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Link visibility'),
|
||||
'#default_value' => variable_get('print_pdf_node_link_visibility', PRINT_PDF_NODE_LINK_VISIBILITY_DEFAULT),
|
||||
'#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_node_link_pages'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => variable_get('print_pdf_node_link_pages', PRINT_PDF_NODE_LINK_PAGES_DEFAULT),
|
||||
'#rows' => 3,
|
||||
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
|
||||
'#wysiwyg' => FALSE,
|
||||
);
|
||||
|
||||
$access = user_access('use PHP for link visibility');
|
||||
|
||||
if ($form['settings']['adv_link']['print_pdf_node_link_visibility']['#default_value'] == 2 && !$access) {
|
||||
$form['settings']['adv_link']['print_pdf_node_link_visibility'] = array('#type' => 'value', '#value' => 2);
|
||||
$form['settings']['adv_link']['print_pdf_node_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_pdf_node_link_pages']['#default_value']);
|
||||
}
|
||||
elseif ($access) {
|
||||
$form['settings']['adv_link']['print_pdf_node_link_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
|
||||
$form['settings']['adv_link']['print_pdf_node_link_pages']['#description'] .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
|
||||
}
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_visibility'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Show link in system (non-content) pages'),
|
||||
'#description' => 'Any page that is not a Drupal node. Usually pages generated by Drupal or a module such as Views or Panels.',
|
||||
'#default_value' => variable_get('print_pdf_sys_link_visibility', PRINT_PDF_SYS_LINK_VISIBILITY_DEFAULT),
|
||||
'#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_pages'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => variable_get('print_pdf_sys_link_pages', PRINT_PDF_SYS_LINK_PAGES_DEFAULT),
|
||||
'#rows' => 3,
|
||||
'#description' => t('Setting this option will add a PDF version page link on pages created by Drupal or the enabled modules.') .'<br />'.
|
||||
t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
|
||||
'#wysiwyg' => FALSE,
|
||||
);
|
||||
|
||||
if ($form['settings']['adv_link']['print_pdf_sys_link_visibility']['#default_value'] == 2 && !$access) {
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_pdf_sys_link_pages']['#default_value']);
|
||||
}
|
||||
elseif ($access) {
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_pages']['#description'] .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
|
||||
}
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_book_link'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Link in book hierarchy nodes'),
|
||||
'#default_value' => variable_get('print_pdf_book_link', PRINT_PDF_BOOK_LINK_DEFAULT),
|
||||
'#options' => array(t('No link'), t('Current page and sub-pages'), t('Current page only')),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_content_disposition'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Open PDF in'),
|
||||
'#options' => array(t('Same browser window'), t('New browser window'), t('Save dialog')),
|
||||
'#default_value' => variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT),
|
||||
'#description' => t("Select the desired method for opening the PDF in the user's browser."),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_paper_size'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Paper size'),
|
||||
'#options' => array('4A0' => '4A0', '2A0' => '2A0', 'A0' => 'A0',
|
||||
'A1' => 'A1', 'A2' => 'A2', 'A3' => 'A3', 'A4' => 'A4',
|
||||
'A5' => 'A5', 'A6' => 'A6', 'A7' => 'A7', 'A8' => 'A8',
|
||||
'A9' => 'A9', 'A10' => 'A10', 'B0' => 'B0', 'B1' => 'B1',
|
||||
'B2' => 'B2', 'B3' => 'B3', 'B4' => 'B4', 'B5' => 'B5',
|
||||
'B6' => 'B6', 'B7' => 'B7', 'B8' => 'B8', 'B9' => 'B9',
|
||||
'B10' => 'B10', 'C0' => 'C0', 'C1' => 'C1', 'C2' => 'C2',
|
||||
'C3' => 'C3', 'C4' => 'C4', 'C5' => 'C5', 'C6' => 'C6',
|
||||
'C7' => 'C7', 'C8' => 'C8', 'C9' => 'C9', 'C10' => 'C10',
|
||||
'RA0' => 'RA0', 'RA1' => 'RA1', 'RA2' => 'RA2',
|
||||
'RA3' => 'RA3', 'RA4' => 'RA4', 'SRA0' => 'SRA0',
|
||||
'SRA1' => 'SRA1', 'SRA2' => 'SRA2', 'SRA3' => 'SRA3',
|
||||
'SRA4' => 'SRA4', 'LETTER' => 'Letter', 'LEGAL' => 'Legal',
|
||||
'EXECUTIVE' => 'Executive', 'FOLIO' => 'Folio',
|
||||
),
|
||||
'#default_value' => variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT),
|
||||
'#description' => t('Choose the paper size of the generated PDF.'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_page_orientation'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Page orientation'),
|
||||
'#options' => array('portrait' => t('Portrait'), 'landscape' => t('Landscape')),
|
||||
'#default_value' => variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT),
|
||||
'#description' => t('Choose the page orientation of the generated PDF.'),
|
||||
);
|
||||
$form['settings']['print_pdf_images_via_file'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Access images via local file access'),
|
||||
'#default_value' => variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT),
|
||||
'#description' => t("Enabling this option will make the tool use local file access for image files. This option is not recommended to use in conjunction with modules like imagecache which generate the image after it's first accessed. However, it may be necessary in low-end hosting services where the web server is not allowed to open URLs and the user can't modify that configuration setting."),
|
||||
);
|
||||
$form['settings']['print_pdf_autoconfig'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Auto-configure the PDF tool settings'),
|
||||
'#default_value' => variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT),
|
||||
'#description' => t('If you disable this option, the pdf tool settings must be configured manually. For TCDPF, edit the tcpdf/config/tcpdf_config.php file. For dompdf, edit the dompdf/dompdf_config.inc.php file.'),
|
||||
);
|
||||
$form['settings']['print_pdf_font_family'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Font family'),
|
||||
'#default_value' => variable_get('print_pdf_font_family', PRINT_PDF_FONT_FAMILY_DEFAULT),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 250,
|
||||
'#description' => t('(TCPDF only) Set the font family to be used. Examples: %examples.', array('%examples' => 'helvetica, times, courier, dejavusans, dejavuserif, freesans, freeserif, freemono')) .'<br />'.
|
||||
t("CAUTION: TCPDF embeds the complete font in the generated PDF. If you're not using Unicode, then helvetica or times are safe choices that will keep the PDF small. Unicode fonts can increase the size of the PDF to the 1MB region."),
|
||||
);
|
||||
$form['settings']['print_pdf_font_size'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Font size'),
|
||||
'#default_value' => variable_get('print_pdf_font_size', PRINT_PDF_FONT_SIZE_DEFAULT),
|
||||
'#size' => 2,
|
||||
'#maxlength' => 3,
|
||||
'#description' => t('(TCPDF only) Set the font size to be used for normal text. This is the base value for the scaling applied to other text styles.'),
|
||||
);
|
||||
$form['settings']['print_pdf_font_subsetting'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable font subsetting'),
|
||||
'#default_value' => variable_get('print_pdf_font_subsetting', PRINT_PDF_FONT_SUBSETTING_DEFAULT),
|
||||
'#description' => t('(TCPDF only) Only embed those font characters that are actually used. This can generates smaller PDF files but may significantly slow down processing.'),
|
||||
);
|
||||
$form['settings']['print_pdf_dompdf_unicode'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t("Use dompdf's Unicode Mode"),
|
||||
'#default_value' => variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT),
|
||||
'#description' => t("If enabled, dompdf's Unicode mode is used. If not, the module will attempt to convert some non-ASCII chars to ISO-8859-1."),
|
||||
);
|
||||
$form['settings']['print_pdf_wkhtmltopdf_options'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('wkhtmltopdf options'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 500,
|
||||
'#default_value' => variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS),
|
||||
'#description' => t('(wkhtmltopdf only) Set any additional options to be passed to the wkhtmltopdf executable. Tokens may be used in these options (see list below).'),
|
||||
);
|
||||
|
||||
if (module_exists('token')) {
|
||||
$form['settings']['print_pdf_filename'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('PDF filename'),
|
||||
'#default_value' => variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT),
|
||||
'#description' => t("If left empty the generated filename defaults to the node's path. Tokens may be used to build the filename (see following list). The .pdf extension will be appended automatically."),
|
||||
);
|
||||
$form['settings']['print_pdf_filename_patterns'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Replacement patterns'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['settings']['print_pdf_filename_patterns']['descriptions'] = array(
|
||||
'#type' => 'markup',
|
||||
'#value' => theme('token_help', array('node', 'global')),
|
||||
);
|
||||
}
|
||||
|
||||
$form['settings']['print_pdf_display_sys_urllist'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Printer-friendly URLs list in system pages'),
|
||||
'#default_value' => variable_get('print_pdf_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
|
||||
'#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
|
||||
);
|
||||
|
||||
$form['#validate'][] = '_print_pdf_settings_validate';
|
||||
}
|
||||
else {
|
||||
$form['settings'] = array(
|
||||
'#type' => 'markup',
|
||||
'#value' => '<p>'. t("No PDF generation tool found! Please download a supported PHP PDF generation tool. Check this module's INSTALL.txt for more details.") .'</p>',
|
||||
);
|
||||
}
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate print_pdf_settings form.
|
||||
*/
|
||||
function _print_pdf_settings_validate($form, &$form_state) {
|
||||
if (empty($form_state['values']['print_pdf_pdf_tool'])) {
|
||||
form_set_error('print_pdf_pdf_tool', t("No PDF tool selected"));
|
||||
}
|
||||
if ($form_state['values']['print_pdf_font_size'] < 1) {
|
||||
form_set_error('print_pdf_font_size', t("Font size must be at least 1."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to locate suitable PDF generation tools
|
||||
*
|
||||
* @return
|
||||
* array of filenames with the include-able PHP file of the located tools
|
||||
*/
|
||||
function _print_pdf_tools() {
|
||||
$tools = array_keys(file_scan_directory(drupal_get_path('module', 'print'), '^dompdf_config.inc.php$'));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(drupal_get_path('module', 'print'), '^tcpdf.php$')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(drupal_get_path('module', 'print'), '^wkhtmltopdf')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(PRINT_PDF_LIB_PATH, '^dompdf_config.inc.php$')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(PRINT_PDF_LIB_PATH, '^tcpdf.php$')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(PRINT_PDF_LIB_PATH, '^wkhtmltopdf')));
|
||||
if (module_exists('libraries')) {
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(libraries_get_path('dompdf'), '^dompdf_config.inc.php$')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(libraries_get_path('tcpdf'), '^tcpdf.php$')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(libraries_get_path('wkhtmltopdf'), '^wkhtmltopdf')));
|
||||
}
|
||||
|
||||
|
||||
$num_tools = count($tools);
|
||||
|
||||
if ($num_tools == 0) {
|
||||
variable_set('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
// Instead of array_combine(), use this to maintain PHP4 compatibility
|
||||
$tools2 = array();
|
||||
foreach ($tools as $key => $val) {
|
||||
$tools2[$val] = $val;
|
||||
}
|
||||
|
||||
return $tools2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback for the PDF version module text strings settings form.
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function print_pdf_strings_settings() {
|
||||
drupal_set_message(t("Saving these strings will disable their translation via Drupal's language system. Use the reset button to return them to the original state."), 'warning');
|
||||
|
||||
$form['print_pdf_text'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Text strings'),
|
||||
);
|
||||
|
||||
$form['print_pdf_text']['print_pdf_link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link text'),
|
||||
'#default_value' => variable_get('print_pdf_link_text', t('PDF version')),
|
||||
'#description' => t('Text used in the link to the PDF version.'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
29
modules/print/print_pdf/print_pdf.class.inc
Normal file
29
modules/print/print_pdf/print_pdf.class.inc
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Extend the TCPDF class to be able to customize the Footer
|
||||
*
|
||||
* This file is included by the _print_pdf_tcpdf function
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
class PrintTCPDF extends TCPDF {
|
||||
public $footer;
|
||||
|
||||
// Display invisible link at the bottom of all pages.
|
||||
public function setTcpdfLink($tcpdflink) {
|
||||
$this->tcpdflink = $tcpdflink;
|
||||
}
|
||||
|
||||
// Page footer data
|
||||
public function setFooterContent($arg = '') {
|
||||
$this->footer = $arg;
|
||||
}
|
||||
|
||||
// Page footer
|
||||
public function Footer() {
|
||||
theme('print_pdf_tcpdf_footer2', $this);
|
||||
}
|
||||
}
|
25
modules/print/print_pdf/print_pdf.class_php4.inc
Normal file
25
modules/print/print_pdf/print_pdf.class_php4.inc
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Extend the TCPDF class to be able to customize the Footer (PHP4 version)
|
||||
*
|
||||
* This file is included by the _print_pdf_tcpdf function when the current
|
||||
* PHP_VERSION is less than 5.0.0
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
class PrintTCPDF extends TCPDF {
|
||||
var $footer;
|
||||
|
||||
// Page footer data
|
||||
function SetFooterData($arg = '') {
|
||||
$this->footer = $arg;
|
||||
}
|
||||
|
||||
// Page footer
|
||||
function Footer() {
|
||||
$this = theme('print_pdf_tcpdf_footer2', $this);
|
||||
}
|
||||
}
|
223
modules/print/print_pdf/print_pdf.drush.inc
Normal file
223
modules/print/print_pdf/print_pdf.drush.inc
Normal file
|
@ -0,0 +1,223 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* drush integration for print_pdf module PDF libraries download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The PDF project download URL
|
||||
*/
|
||||
|
||||
// TCPDF is in sourceforge, and nicely provides a link to the latest version
|
||||
define('TCPDF_DOWNLOAD_URI', 'http://sourceforge.net/projects/tcpdf/files/latest');
|
||||
|
||||
// URI to the the latest dompdf version.. Hardcoded version unfortunately
|
||||
define('DOMPDF_DOWNLOAD_URI', 'https://github.com/dompdf/dompdf/releases/download/v0.6.1/dompdf-0.6.1.zip');
|
||||
|
||||
// wkhtmltopdf is a binary, requiring a different download for each platform
|
||||
define('WKHTMLTOPDF_AMD64_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz');
|
||||
define('WKHTMLTOPDF_I386_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-i386_0.12.0-03c001d.tar.xz');
|
||||
define('WKHTMLTOPDF_WIN64_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-win64_0.12.0-03c001d.exe');
|
||||
define('WKHTMLTOPDF_WIN_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-win32_0.12.0-03c001d.exe');
|
||||
define('WKHTMLTOPDF_OSX_DOWNLOAD_URI', 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-OSX-0.10.0_rc2-static.tar.bz2');
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function print_pdf_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$items['print-pdf-download'] = array(
|
||||
'description' => 'Download a PDF library.',
|
||||
'arguments' => array(
|
||||
'library' => dt('The PDF library to download. Either tcpdf, dompdf or wkhtmltopdf.'),
|
||||
),
|
||||
'options' => array(
|
||||
'path' => dt('A path to the download folder. If omitted Drush will use the default location (@path).', array('@path' => 'sites/all/libraries')),
|
||||
),
|
||||
'aliases' => array('pdfdl'),
|
||||
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, // No site or config needed.
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download and extract PDF archive.
|
||||
*/
|
||||
function drush_print_pdf_download($library) {
|
||||
if (isset($library)) {
|
||||
$download_url = _drush_print_pdf_download_url($library);
|
||||
if ($download_url) {
|
||||
$path = drush_get_option('path');
|
||||
if (empty($path)) {
|
||||
$path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries';
|
||||
}
|
||||
|
||||
// Create the path if it does not exist.
|
||||
if (!is_dir($path)) {
|
||||
drush_op('mkdir', $path);
|
||||
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
|
||||
}
|
||||
|
||||
// Chdir to the download location.
|
||||
$olddir = getcwd();
|
||||
drush_op('chdir', $path);
|
||||
|
||||
// Warn about an existing dir
|
||||
if (is_dir($library)) {
|
||||
// drush_op('rmdir', $library); // Directory must be empty for the php rmdir to work..
|
||||
drush_log(dt('An existing @library was overwritten at @path', array('@library' => $library, '@path' => $path . '/' . $library)), 'notice');
|
||||
}
|
||||
|
||||
// Download the archive
|
||||
$filename = _drush_print_pdf_download_file($download_url);
|
||||
if ($filename) {
|
||||
$extract_ret = _drush_print_pdf_download_extract($filename);
|
||||
if ($extract_ret) {
|
||||
// Remove the archive
|
||||
drush_op('unlink', $filename);
|
||||
drush_log(dt('@file has been downloaded and extracted in @path', array('@file' => $filename, '@path' => $path)), 'success');
|
||||
}
|
||||
else {
|
||||
drush_log(dt('@file has been downloaded to @path, but extract failed. Check that you have the necessary program installed, and if necessary extract it manually.',
|
||||
array('@file' => $filename, '@path' => $path)), 'warning');
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('Drush was unable to download @library to @path', array('@library' => $library, '@path' => $path)), 'error');
|
||||
}
|
||||
|
||||
// Set working directory back to the previous working directory.
|
||||
drush_op('chdir', $olddir);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('Please specify a PDF library. Currently supported libraries are dompdf, tcpdf and wkhtmltopdf.'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover the correct URL of the package to download
|
||||
*/
|
||||
function _drush_print_pdf_download_url($library) {
|
||||
$ret = FALSE;
|
||||
|
||||
switch (drupal_strtolower($library)) {
|
||||
case 'dompdf':
|
||||
$ret = DOMPDF_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'tcpdf':
|
||||
$ret = TCPDF_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'wkhtmltopdf':
|
||||
switch (drupal_substr(php_uname('s'), 0, 3)) {
|
||||
case 'Lin':
|
||||
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_AMD64_DOWNLOAD_URI : WKHTMLTOPDF_I386_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'Win':
|
||||
$ret = WKHTMLTOPDF_WIN_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'Dar':
|
||||
$ret = WKHTMLTOPDF_OSX_DOWNLOAD_URI;
|
||||
break;
|
||||
default:
|
||||
drush_log(dt('wkhtmltopdf is not supported in this system, please choose another library.'), 'error');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
drush_log(dt('Unknown PDF library specified, please use one of the supported PDF libraries.'), 'error');
|
||||
break;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to download and extract the zip/tar archive.
|
||||
*/
|
||||
function _drush_print_pdf_download_extract($filename) {
|
||||
$arch_ret = FALSE;
|
||||
|
||||
if (drush_op('is_file', $filename)) {
|
||||
switch (drush_op('mime_content_type', $filename)) {
|
||||
case 1:
|
||||
$arch_ret = TRUE;
|
||||
break;
|
||||
case 'application/zip':
|
||||
// Decompress the zip archive
|
||||
$arch_ret = drush_shell_exec('unzip -qq -o ' . $filename);
|
||||
// ZIP archives usually get the access rights wrong
|
||||
drush_log(dt('@filename is a Zip file. Check the access permissions of the extracted files.', array('@filename' => $filename)), 'warning');
|
||||
break;
|
||||
case 'application/x-gzip':
|
||||
// Decompress the tar gz archive
|
||||
$arch_ret = drush_shell_exec('tar xzf ' . $filename);
|
||||
break;
|
||||
case 'application/x-bzip2':
|
||||
// Decompress the tar bz2 archive
|
||||
$arch_ret = drush_shell_exec('tar xjf ' . $filename);
|
||||
break;
|
||||
case 'application/x-xz':
|
||||
// Decompress the tar xz archive
|
||||
$arch_ret = drush_shell_exec('tar xJf %s', $filename);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('@filename not found.', array('@filename' => $filename)), 'error');
|
||||
}
|
||||
|
||||
return $arch_ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file using wget or curl
|
||||
*
|
||||
* Adapted from a function in drush/includes/drush.inc to support 302 redirects.
|
||||
*
|
||||
* @param string $download_url
|
||||
* The path to the file to download
|
||||
*
|
||||
* @return string
|
||||
* The filename that was downloaded, or NULL if the file could not be
|
||||
* downloaded.
|
||||
*/
|
||||
function _drush_print_pdf_download_file($download_url) {
|
||||
$wget_ret = drush_shell_exec("wget -nv --trust-server-names %s", $download_url);
|
||||
|
||||
if (!drush_get_context('DRUSH_SIMULATE')) {
|
||||
if ($wget_ret) {
|
||||
// Get the filename of the saved file from the output
|
||||
$wget_out = explode('"', array_shift(drush_shell_exec_output()));
|
||||
$filename = $wget_out[1];
|
||||
}
|
||||
else {
|
||||
$tempnam = uniqid('drush_print_pdf_');
|
||||
|
||||
$curl_ret = drush_shell_exec("curl -s -L -o %s %s -w '%%{url_effective}'", $tempnam, $download_url);
|
||||
if ($curl_ret) {
|
||||
// File was donwloaded with the tempname
|
||||
|
||||
// Find the effective name
|
||||
$filename = explode('/', array_shift(drush_shell_exec_output()));
|
||||
$filename = array_pop($filename);
|
||||
|
||||
// Rename file from tempname to effective name
|
||||
if (!drush_op('rename', $tempnam, './' . $filename)) {
|
||||
$filename = $tempnam;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filename = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filename = basename($download_url);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
12
modules/print/print_pdf/print_pdf.info
Normal file
12
modules/print/print_pdf/print_pdf.info
Normal file
|
@ -0,0 +1,12 @@
|
|||
name = "PDF version"
|
||||
description = "Adds the capability to export pages as PDF."
|
||||
dependencies[] = print
|
||||
core=6.x
|
||||
package = "Printer, email and PDF versions"
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-04-02
|
||||
version = "6.x-1.19"
|
||||
core = "6.x"
|
||||
project = "print"
|
||||
datestamp = "1396426748"
|
||||
|
301
modules/print/print_pdf/print_pdf.install
Normal file
301
modules/print/print_pdf/print_pdf.install
Normal file
|
@ -0,0 +1,301 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install file of the print_pdf module
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function print_pdf_install() {
|
||||
drupal_install_schema('print_pdf');
|
||||
|
||||
// Module weight
|
||||
update_sql("UPDATE {system} SET weight = 2 WHERE name = 'print_pdf'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function print_pdf_uninstall() {
|
||||
drupal_uninstall_schema('print_pdf');
|
||||
|
||||
variable_del('print_pdf_settings');
|
||||
variable_del('print_pdf_show_link');
|
||||
variable_del('print_pdf_link_pos');
|
||||
variable_del('print_pdf_link_teaser');
|
||||
variable_del('print_pdf_node_link_visibility');
|
||||
variable_del('print_pdf_node_link_pages');
|
||||
variable_del('print_pdf_link_class');
|
||||
variable_del('print_pdf_sys_link_visibility');
|
||||
variable_del('print_pdf_sys_link_pages');
|
||||
variable_del('print_pdf_book_link');
|
||||
variable_del('print_pdf_pdf_tool');
|
||||
variable_del('print_pdf_content_disposition');
|
||||
variable_del('print_pdf_paper_size');
|
||||
variable_del('print_pdf_page_orientation');
|
||||
variable_del('print_pdf_images_via_file');
|
||||
variable_del('print_pdf_font_family');
|
||||
variable_del('print_pdf_font_size');
|
||||
variable_del('print_pdf_link_text');
|
||||
variable_del('print_pdf_link_use_alias');
|
||||
variable_del('print_pdf_filename');
|
||||
variable_del('print_pdf_autoconfig');
|
||||
variable_del('print_pdf_dompdf_unicode');
|
||||
variable_del('print_pdf_wkhtmltopdf_options');
|
||||
variable_del('print_pdf_display_sys_urllist');
|
||||
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_pdf\_display\_%'");
|
||||
while ($variable = db_fetch_object($settings)) {
|
||||
variable_del($variable->name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
*/
|
||||
function print_pdf_schema() {
|
||||
$schema['print_pdf_node_conf'] = array(
|
||||
'fields' => array(
|
||||
'nid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'link' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 1,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'comments' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 1,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'url_list' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 1,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
),
|
||||
'primary key' => array('nid'),
|
||||
);
|
||||
|
||||
$schema['print_pdf_page_counter'] = array(
|
||||
'fields' => array(
|
||||
'path' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'totalcount' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'big',
|
||||
),
|
||||
'timestamp' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'primary key' => array('path'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 6.x-1.0
|
||||
*/
|
||||
function print_pdf_update_6000() {
|
||||
global $conf;
|
||||
|
||||
$ret = array();
|
||||
if (isset($conf['print_pdf_settings'])) {
|
||||
$print_pdf_settings = variable_get('print_pdf_settings', '');
|
||||
variable_set('print_pdf_link_pos', array('link' => ($print_pdf_settings['show_link'] ? 'link' : 0) ));
|
||||
variable_set('print_pdf_show_link', max(1, $print_pdf_settings['show_link']));
|
||||
variable_set('print_pdf_node_link_visibility', $print_pdf_settings['node_link_visibility']);
|
||||
variable_set('print_pdf_node_link_pages', $print_pdf_settings['node_link_pages']);
|
||||
variable_set('print_pdf_link_class', $print_pdf_settings['link_class']);
|
||||
variable_set('print_pdf_sys_link_visibility', $print_pdf_settings['sys_link_visibility']);
|
||||
variable_set('print_pdf_sys_link_pages', $print_pdf_settings['sys_link_pages']);
|
||||
variable_set('print_pdf_book_link', $print_pdf_settings['book_link']);
|
||||
variable_set('print_pdf_pdf_tool', $print_pdf_settings['pdf_tool']);
|
||||
variable_set('print_pdf_content_disposition', $print_pdf_settings['content_disposition']);
|
||||
variable_set('print_pdf_paper_size', $print_pdf_settings['paper_size']);
|
||||
variable_set('print_pdf_page_orientation', $print_pdf_settings['page_orientation']);
|
||||
variable_del('print_pdf_settings');
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 6.x-1.1
|
||||
*/
|
||||
function print_pdf_update_6001() {
|
||||
$schema['print_pdf_node_conf'] = array(
|
||||
'fields' => array(
|
||||
'nid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'link' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => '1',
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'comments' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => '1',
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'url_list' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => '1',
|
||||
'size' => 'tiny',
|
||||
),
|
||||
),
|
||||
'primary key' => array('nid'),
|
||||
);
|
||||
|
||||
$schema['print_pdf_page_counter'] = array(
|
||||
'fields' => array(
|
||||
'path' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'totalcount' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'big',
|
||||
),
|
||||
'timestamp' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'primary key' => array('path'),
|
||||
);
|
||||
|
||||
$ret = array();
|
||||
db_create_table($ret, 'print_pdf_node_conf', $schema['print_pdf_node_conf']);
|
||||
db_create_table($ret, 'print_pdf_page_counter', $schema['print_pdf_page_counter']);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 6.x-1.2
|
||||
*/
|
||||
function print_pdf_update_6003() {
|
||||
// Delete custom text strings set to the default
|
||||
$ret = array();
|
||||
$vars = array(
|
||||
'print_pdf_link_text' => 'PDF version',
|
||||
);
|
||||
|
||||
$t = get_t();
|
||||
|
||||
foreach ($vars as $name => $default) {
|
||||
if (variable_get($name, '') == $t($default)) {
|
||||
variable_del($name);
|
||||
}
|
||||
}
|
||||
|
||||
menu_rebuild();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 6.x-1.8
|
||||
*/
|
||||
function print_pdf_update_6004() {
|
||||
// add new 'access PDF version' permission to any role which has 'access print'
|
||||
$ret = array();
|
||||
$dbret = db_query('SELECT * FROM {permission}');
|
||||
while ($role = db_fetch_object($dbret)) {
|
||||
if ((strpos($role->perm, 'access print') !== FALSE)) {
|
||||
$role->perm = db_escape_string('access PDF version, '. $role->perm);
|
||||
$ret[] = update_sql("UPDATE {permission} SET perm = '$role->perm' WHERE rid = $role->rid");
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 6.x-1.11
|
||||
*/
|
||||
function print_pdf_update_6005() {
|
||||
$ret = array();
|
||||
|
||||
variable_del('print_pdf_wkhtmltopdf_xdisplay');
|
||||
variable_del('print_pdf_xvfb_options');
|
||||
|
||||
// BLOCK_CACHE_GLOBAL -> 8
|
||||
$ret[] = update_sql("UPDATE {blocks} SET cache = 8 WHERE module = 'print_pdf' AND delta = '0'");
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 6.x-1.11
|
||||
*/
|
||||
function print_pdf_update_6006() {
|
||||
$ret = array();
|
||||
// Module weight
|
||||
$ret[] = update_sql("UPDATE {system} SET weight = 2 WHERE name = 'print_pdf'");
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 6.x-1.11
|
||||
*/
|
||||
function print_pdf_update_6007() {
|
||||
$ret = array();
|
||||
|
||||
foreach (node_get_types() as $key => $value) {
|
||||
$print_pdf_display = variable_get('print_pdf_display_'. $value->type, 1);
|
||||
$print_pdf_display_comment = variable_get('print_pdf_display_comment_'. $value->type, 0);
|
||||
$print_pdf_display_urllist = variable_get('print_pdf_display_urllist_'. $value->type, 1);
|
||||
|
||||
$ret[] = update_sql("UPDATE {print_pdf_node_conf} SET link = (link AND $print_pdf_display), comments = (comments OR $print_pdf_display_comment), url_list = (url_list AND $print_pdf_display_urllist) WHERE nid IN (SELECT nid FROM {node} WHERE type = '$value->type');");
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable block and help area links
|
||||
*/
|
||||
function print_pdf_update_6118() {
|
||||
$ret = array();
|
||||
|
||||
$link_pos = variable_get('print_pdf_link_pos', array('link' => 'link', 'block' => 'block', 'help' => 'help'));
|
||||
$link_pos['block'] = 'block';
|
||||
$link_pos['help'] = 'help';
|
||||
variable_set('print_pdf_link_pos', $link_pos);
|
||||
|
||||
return $ret;
|
||||
}
|
699
modules/print/print_pdf/print_pdf.module
Normal file
699
modules/print/print_pdf/print_pdf.module
Normal file
|
@ -0,0 +1,699 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Displays Printer-friendly versions of Drupal pages.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
define('PRINTPDF_PATH', 'printpdf');
|
||||
|
||||
define('PRINT_PDF_FORMAT', 'pdf');
|
||||
|
||||
define('PRINT_PDF_LIB_PATH', 'sites/all/libraries');
|
||||
|
||||
define('PRINT_PDF_LINK_POS_DEFAULT', serialize(array('link' => 'link', 'block' => 'block', 'help' => 'help')));
|
||||
define('PRINT_PDF_LINK_TEASER_DEFAULT', 0);
|
||||
define('PRINT_PDF_SHOW_LINK_DEFAULT', 1);
|
||||
define('PRINT_PDF_NODE_LINK_VISIBILITY_DEFAULT', 0);
|
||||
define('PRINT_PDF_NODE_LINK_PAGES_DEFAULT', '');
|
||||
define('PRINT_PDF_LINK_CLASS_DEFAULT', 'print-pdf');
|
||||
define('PRINT_PDF_SYS_LINK_VISIBILITY_DEFAULT', 1);
|
||||
define('PRINT_PDF_SYS_LINK_PAGES_DEFAULT', '');
|
||||
define('PRINT_PDF_LINK_USE_ALIAS_DEFAULT', 0);
|
||||
define('PRINT_PDF_BOOK_LINK_DEFAULT', 1);
|
||||
define('PRINT_PDF_PDF_TOOL_DEFAULT', 0);
|
||||
define('PRINT_PDF_CONTENT_DISPOSITION_DEFAULT', 2);
|
||||
define('PRINT_PDF_PAPER_SIZE_DEFAULT', 'A4');
|
||||
define('PRINT_PDF_PAGE_ORIENTATION_DEFAULT', 'portrait');
|
||||
define('PRINT_PDF_IMAGES_VIA_FILE_DEFAULT', 0);
|
||||
define('PRINT_PDF_AUTOCONFIG_DEFAULT', 1);
|
||||
define('PRINT_PDF_FONT_FAMILY_DEFAULT', 'dejavusans');
|
||||
define('PRINT_PDF_FONT_SIZE_DEFAULT', 10);
|
||||
define('PRINT_PDF_FONT_SUBSETTING_DEFAULT', FALSE);
|
||||
define('PRINT_PDF_FILENAME_DEFAULT', '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]');
|
||||
define('PRINT_PDF_DOMPDF_UNICODE_DEFAULT', 0);
|
||||
define('PRINT_PDF_WKHTMLTOPDF_OPTIONS', "--footer-font-size 7 --footer-right '[page]'");
|
||||
define('PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT', 'print_pdf/dompdf');
|
||||
define('PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT', 'print_pdf/tcpdf');
|
||||
|
||||
/**
|
||||
* Implementation of hook_perm().
|
||||
*/
|
||||
function print_pdf_perm() {
|
||||
return array('access PDF version');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme().
|
||||
*/
|
||||
function print_pdf_theme() {
|
||||
return array(
|
||||
'print_pdf_format_link' => array(
|
||||
'arguments' => array(),
|
||||
),
|
||||
'print_pdf_dompdf_footer' => array(
|
||||
'arguments' => array('html' => ''),
|
||||
'file' => 'print_pdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_header' => array(
|
||||
'arguments' => array('pdf' => NULL, 'html' => '', 'font' => array()),
|
||||
'file' => 'print_pdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_page' => array(
|
||||
'arguments' => array('pdf' => NULL),
|
||||
'file' => 'print_pdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_content' => array(
|
||||
'arguments' => array('pdf' => NULL, 'html' => '', 'font' => array()),
|
||||
'file' => 'print_pdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_footer' => array(
|
||||
'arguments' => array('pdf' => NULL, 'html' => '', 'font' => array()),
|
||||
'file' => 'print_pdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_footer2' => array(
|
||||
'arguments' => array('pdf' => NULL),
|
||||
'file' => 'print_pdf.pages.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_init().
|
||||
*/
|
||||
function print_pdf_init() {
|
||||
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
|
||||
$pdf_dirs = array();
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
|
||||
if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
|
||||
$pdf_dirs[] = PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT . '/fonts';
|
||||
}
|
||||
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
|
||||
foreach (array('cache', 'images') as $dir) {
|
||||
$pdf_dirs[] = PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT . '/' . $dir;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($pdf_dirs)) {
|
||||
foreach ($pdf_dirs as $pdf_dir) {
|
||||
$directory = file_directory_path() . '/' . $pdf_dir;
|
||||
if (!is_dir($directory)) {
|
||||
$dir_tmp = '';
|
||||
foreach (explode('/', $pdf_dir) as $dir) {
|
||||
$dir_tmp .= $dir . '/';
|
||||
$directory = file_directory_path() . '/' . $dir_tmp;
|
||||
file_check_directory($directory, FILE_CREATE_DIRECTORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu().
|
||||
*/
|
||||
function print_pdf_menu() {
|
||||
$items = array();
|
||||
|
||||
$items[PRINTPDF_PATH] = array(
|
||||
'title' => 'Printer-friendly PDF',
|
||||
'page callback' => 'print_pdf_controller',
|
||||
'access arguments' => array('access PDF version'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'print_pdf.pages.inc',
|
||||
);
|
||||
$items[PRINTPDF_PATH .'/'. PRINTPDF_PATH] = array(
|
||||
'access callback' => FALSE,
|
||||
);
|
||||
$items['admin/settings/print/pdf'] = array(
|
||||
'title' => 'PDF',
|
||||
'description' => 'Configure the settings of the PDF generation functionality.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('print_pdf_settings'),
|
||||
'access arguments' => array('administer print'),
|
||||
'weight' => 3,
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'print_pdf.admin.inc',
|
||||
);
|
||||
$items['admin/settings/print/pdf/options'] = array(
|
||||
'title' => 'Options',
|
||||
'weight' => 1,
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
);
|
||||
$items['admin/settings/print/pdf/strings'] = array(
|
||||
'title' => 'Text strings',
|
||||
'description' => 'Override the user-facing strings used in the PDF version.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('print_pdf_strings_settings'),
|
||||
'access arguments' => array('administer print'),
|
||||
'weight' => 2,
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'print_pdf.admin.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_block().
|
||||
*/
|
||||
function print_pdf_block($op = 'list', $delta = 0, $edit = array()) {
|
||||
switch ($op) {
|
||||
case 'list':
|
||||
$block[0]['info'] = t('Most PDFd');
|
||||
$block[0]['cache'] = BLOCK_CACHE_GLOBAL;
|
||||
return $block;
|
||||
break;
|
||||
case 'configure':
|
||||
return '';
|
||||
case 'save':
|
||||
return;
|
||||
case 'view':
|
||||
switch ($delta) {
|
||||
case 0:
|
||||
$block['subject'] = t('Most PDFd');
|
||||
$result = db_query_range("SELECT path FROM {print_pdf_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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_requirements().
|
||||
*/
|
||||
function print_pdf_requirements($phase) {
|
||||
$requirements = array();
|
||||
$t = get_t();
|
||||
switch ($phase) {
|
||||
// At runtime, make sure that a PDF generation tool is selected
|
||||
case 'runtime':
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
if (empty($print_pdf_pdf_tool)) {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('Printer, email and PDF versions - PDF generation library'),
|
||||
'value' => $t('No PDF tool selected'),
|
||||
'description' => $t('Please configure it in the !url.', array('!url' => l($t('PDF settings page'), 'admin/settings/print/pdf'))),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
else {
|
||||
if (!is_file($print_pdf_pdf_tool) || !is_readable($print_pdf_pdf_tool)) {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('Printer, email and PDF versions - PDF generation library'),
|
||||
'value' => $t('File not found'),
|
||||
'description' => $t('The currently selected PDF generation library (%file) is no longer accessible.', array('%file' => $print_pdf_pdf_tool)),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
elseif (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
|
||||
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
|
||||
$directory = file_directory_path() . '/' . PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT . '/fonts';
|
||||
if (!is_dir($directory) || !is_writable($directory)) {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('DOMPDF font cache directory'),
|
||||
'value' => $t('Non-writable permissions'),
|
||||
'description' => $t('You must change the %fontdir permissions to be writable, as dompdf requires write-access to that directory.', array('%fontdir' => $directory)),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
|
||||
$version = _print_pdf_tcpdf_version();
|
||||
|
||||
if (version_compare($version, '5.9.001', '<')) {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('Printer, email and PDF versions - PDF generation library'),
|
||||
'value' => $t('Unsupported TCPDF version'),
|
||||
'description' => $t('The currently selected version of TCPDF (@version) is not supported. Please update to a !url.', array('@version' => $version, '!url' => l($t('newer version'), 'http://sourceforge.net/projects/tcpdf/files/latest'))),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('Printer, email and PDF versions - PDF generation library'),
|
||||
'value' => $t('TCPDF') . ' ' . $version,
|
||||
);
|
||||
}
|
||||
|
||||
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
|
||||
foreach (array('cache', 'images') as $dir) {
|
||||
$directory = file_directory_path() . '/' . PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT . '/' . $dir;
|
||||
if (!is_dir($directory) || !is_writable($directory)) {
|
||||
$requirements['print_pdf_tool_'. $dir] = array(
|
||||
'title' => $t('TCPDF directory'),
|
||||
'value' => $t('Non-writable permissions'),
|
||||
'description' => $t('You must change the %fontdir permissions to be writable, as TCPDF requires write-access to that directory.', array('%fontdir' => $directory)),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (drupal_substr(basename($print_pdf_pdf_tool, '.exe'), 0, 11) == 'wkhtmltopdf') {
|
||||
if (function_exists('is_executable') && !is_executable($print_pdf_pdf_tool)) {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('wkhtmltopdf library'),
|
||||
'value' => $t('Non-executable permissions'),
|
||||
'description' => $t('You must modify the permissions of the wkhtmltopdf file (%file) to make it executable.', array('%file' => $print_pdf_pdf_tool)),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$version = _print_pdf_wkhtmltopdf_version();
|
||||
if (version_compare($version, '0.9.6', '<')) {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('Printer, email and PDF versions - PDF generation library'),
|
||||
'value' => $t('Unsupported wkhtmltopdf version'),
|
||||
'description' => $t('The currently selected version of wkhtmltopdf (@version) is not supported. Please update to a !url.', array('@version' => $version, '!url' => l($t('newer version'), 'http://code.google.com/p/wkhtmltopdf/'))),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$requirements['print_pdf_tool'] = array(
|
||||
'title' => $t('Printer, email and PDF versions - PDF generation library'),
|
||||
'value' => $t('wkhtmltopdf') . ' ' . $version,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_link().
|
||||
*/
|
||||
function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
|
||||
$print_pdf_link_pos = variable_get('print_pdf_link_pos', unserialize(PRINT_PDF_LINK_POS_DEFAULT));
|
||||
$print_pdf_link_use_alias = variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT);
|
||||
$allowed_type = print_pdf_link_allowed(array('type' => $type, 'node' => $node, 'teaser' => $teaser));
|
||||
if (($allowed_type) && !empty($print_pdf_link_pos['link'])) {
|
||||
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
|
||||
$links = array();
|
||||
$format = theme('print_pdf_format_link');
|
||||
|
||||
// Show book link
|
||||
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
|
||||
$links['book_pdf'] = array('href' => PRINTPDF_PATH .'/book/export/html/'. $node->nid,
|
||||
'title' => $format['text'],
|
||||
'attributes' => $format['attributes'],
|
||||
'html' => $format['html'],
|
||||
);
|
||||
|
||||
return $links;
|
||||
}
|
||||
elseif ($allowed_type === PRINT_ALLOW_NORMAL_LINK) {
|
||||
$query_arr = $_GET;
|
||||
if ($type == 'comment') {
|
||||
$query_arr['comment'] = $node->cid;
|
||||
}
|
||||
$query = print_query_string_encode($query_arr, array('q'));
|
||||
if (empty($query)) $query = NULL;
|
||||
|
||||
if (($print_pdf_link_use_alias) && ($alias = drupal_lookup_path('alias', 'node/'. $node->nid))) {
|
||||
$path = $alias;
|
||||
}
|
||||
else {
|
||||
$path = $node->nid;
|
||||
}
|
||||
|
||||
$links['print_pdf'] = array('href' => PRINTPDF_PATH .'/'. $path,
|
||||
'title' => $format['text'],
|
||||
'attributes' => $format['attributes'],
|
||||
'html' => $format['html'],
|
||||
'query' => $query,
|
||||
);
|
||||
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_help().
|
||||
*/
|
||||
function print_pdf_help($path, $arg) {
|
||||
$print_pdf_link_pos = variable_get('print_pdf_link_pos', unserialize(PRINT_PDF_LINK_POS_DEFAULT));
|
||||
if (($path !== 'node/%') && !(empty($print_pdf_link_pos['help']))) {
|
||||
static $output = FALSE;
|
||||
|
||||
if ($output === FALSE) {
|
||||
$output = TRUE;
|
||||
|
||||
$link = print_pdf_insert_link();
|
||||
if ($link) {
|
||||
return "<span class='print-syslink'>$link</span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_nodeapi().
|
||||
*/
|
||||
function print_pdf_nodeapi(&$node, $op = 'view', $teaser, $page) {
|
||||
switch ($op) {
|
||||
case 'view':
|
||||
// Insert content corner links
|
||||
$print_pdf_link_pos = variable_get('print_pdf_link_pos', unserialize(PRINT_PDF_LINK_POS_DEFAULT));
|
||||
if (($teaser === FALSE) && !empty($print_pdf_link_pos['corner']) &&
|
||||
isset($node->build_mode) && ($node->build_mode === NODE_BUILD_NORMAL)) {
|
||||
$node->content['print_links']['#value'] .= print_pdf_insert_link(NULL, $node);
|
||||
}
|
||||
break;
|
||||
case 'load':
|
||||
$res = db_fetch_object(db_query("SELECT link, comments, url_list FROM {print_pdf_node_conf} WHERE nid = %d", $node->nid));
|
||||
|
||||
$node->print_pdf_display = $res ? intval($res->link) : variable_get('print_pdf_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
||||
$node->print_pdf_display_comment = $res ? intval($res->comments) : variable_get('print_pdf_display_comment_'. $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
||||
$node->print_pdf_display_urllist = $res ? intval($res->url_list) : variable_get('print_pdf_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_pdf_display)) $node->print_pdf_display = variable_get('print_pdf_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
||||
if (!isset($node->print_pdf_display_comment)) $node->print_pdf_display_comment = variable_get('print_pdf_display_comment_'. $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
||||
if (!isset($node->print_pdf_display_urllist)) $node->print_pdf_display_urllist = variable_get('print_pdf_display_urllist_'. $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
||||
|
||||
_print_pdf_node_conf_modify($node->nid, $node->print_pdf_display, $node->print_pdf_display_comment, $node->print_pdf_display_urllist);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
db_query("DELETE FROM {print_pdf_node_conf} WHERE nid = %d", $node->nid);
|
||||
db_query("DELETE FROM {print_pdf_page_counter} WHERE path = 'node/%d'", $node->nid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter().
|
||||
*/
|
||||
function print_pdf_form_alter(&$form, $form_state, $form_id) {
|
||||
// Add the node-type settings option to activate the PDF version link
|
||||
if ((user_access('administer print') || user_access('node-specific print configuration')) && (($form_id == 'node_type_form') ||
|
||||
(isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id))) {
|
||||
$form['print']['pdf_label'] = array(
|
||||
'#type' => 'markup',
|
||||
'#value' => '<p><strong>'. t('PDF version') .'</strong></p>',
|
||||
);
|
||||
|
||||
$form['print']['print_pdf_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show link'),
|
||||
);
|
||||
$form['print']['print_pdf_display_comment'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show link in individual comments'),
|
||||
);
|
||||
$form['print']['print_pdf_display_urllist'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show Printer-friendly URLs list'),
|
||||
);
|
||||
|
||||
if ($form_id == 'node_type_form') {
|
||||
$form['print']['print_pdf_display']['#default_value'] = variable_get('print_pdf_display_'. $form['#node_type']->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
||||
$form['print']['print_pdf_display_comment']['#default_value'] = variable_get('print_pdf_display_comment_'. $form['#node_type']->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
||||
$form['print']['print_pdf_display_urllist']['#default_value'] = variable_get('print_pdf_display_urllist_'. $form['#node_type']->type, PRINT_TYPE_URLLIST_DEFAULT);
|
||||
}
|
||||
else {
|
||||
$node = $form['#node'];
|
||||
$form['print']['print_pdf_display']['#default_value'] = isset($node->print_pdf_display) ? $node->print_pdf_display : variable_get('print_pdf_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
||||
$form['print']['print_pdf_display_comment']['#default_value'] = isset($node->print_pdf_display_comment) ? $node->print_pdf_display_comment : variable_get('print_pdf_display_comment_'. $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
||||
$form['print']['print_pdf_display_urllist']['#default_value'] = isset($node->print_pdf_display_urllist) ? $node->print_pdf_display_urllist : variable_get('print_pdf_display_urllist_'. $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the print_pdf_node_conf table to reflect the given attributes
|
||||
*
|
||||
* If updating to the default values, delete the record.
|
||||
*
|
||||
* @param $nid
|
||||
* value of the nid field (primary key)
|
||||
* @param $link
|
||||
* value of the link field (0 or 1)
|
||||
* @param $comments
|
||||
* value of the comments field (0 or 1)
|
||||
* @param $url_list
|
||||
* value of the url_list field (0 or 1)
|
||||
*/
|
||||
function _print_pdf_node_conf_modify($nid, $link, $comments, $url_list) {
|
||||
db_query("UPDATE {print_pdf_node_conf} SET link = %d, comments = %d, url_list = %d WHERE nid = %d", $link, $comments, $url_list, $nid);
|
||||
if (!db_affected_rows()) {
|
||||
@db_query("INSERT INTO {print_pdf_node_conf} (nid, link, comments, url_list) VALUES (%d, %d, %d, %d)", $nid, $link, $comments, $url_list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the PDF version link
|
||||
*
|
||||
* @return
|
||||
* array of formatted attributes
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_print_pdf_format_link() {
|
||||
$print_pdf_link_class = variable_get('print_pdf_link_class', PRINT_PDF_LINK_CLASS_DEFAULT);
|
||||
$print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
|
||||
$print_pdf_show_link = variable_get('print_pdf_show_link', PRINT_PDF_SHOW_LINK_DEFAULT);
|
||||
$print_pdf_link_text = filter_xss(variable_get('print_pdf_link_text', t('PDF version')));
|
||||
|
||||
$img = drupal_get_path('module', 'print') .'/icons/pdf_icon.gif';
|
||||
$title = t('Display a PDF version of this page.');
|
||||
$class = strip_tags($print_pdf_link_class);
|
||||
$new_window = ($print_pdf_content_disposition == 1);
|
||||
$format = _print_format_link_aux($print_pdf_show_link, $print_pdf_link_text, $img);
|
||||
|
||||
return array('text' => $format['text'],
|
||||
'html' => $format['html'],
|
||||
'attributes' => print_fill_attributes($title, $class, $new_window),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to display a formatted PDF version link
|
||||
*
|
||||
* Function made available so that developers may call this function from
|
||||
* their defined pages/blocks.
|
||||
*
|
||||
* @param $path
|
||||
* path of the original page (optional). If not specified, the current URL
|
||||
* is used
|
||||
* @param $node
|
||||
* an optional node object, to be used in defining the path, if used, the
|
||||
* path argument is irrelevant
|
||||
* @return
|
||||
* string with the HTML link to the printer-friendly page
|
||||
*/
|
||||
function print_pdf_insert_link($path = NULL, $node = NULL) {
|
||||
if ($node !== NULL) {
|
||||
$nid = $node->nid;
|
||||
$path = 'node/'. $nid;
|
||||
$allowed_type = print_pdf_link_allowed(array('node' => $node));
|
||||
}
|
||||
else {
|
||||
if ($path === NULL) {
|
||||
$nid = preg_replace('!^node/([\d]+)!', '$1', $_GET['q']);
|
||||
$path = $_GET['q'];
|
||||
}
|
||||
else {
|
||||
$nid = NULL;
|
||||
}
|
||||
$allowed_type = print_pdf_link_allowed(array('path' => $path));
|
||||
}
|
||||
|
||||
if ($allowed_type) {
|
||||
if ($nid !== NULL) {
|
||||
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
|
||||
$path = 'book/export/html/'. $nid;
|
||||
}
|
||||
else {
|
||||
if (variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT) && ($alias = drupal_lookup_path('alias', $path))) {
|
||||
$path = $alias;
|
||||
}
|
||||
else {
|
||||
$path = $nid;
|
||||
}
|
||||
}
|
||||
$path = PRINTPDF_PATH .'/'. $path;
|
||||
$query = print_query_string_encode($_GET, array('q'));
|
||||
if (empty($query)) {
|
||||
$query = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$query = NULL;
|
||||
}
|
||||
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
|
||||
$format = theme('print_pdf_format_link');
|
||||
return '<span class="print_pdf">'. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'</span>';
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the link to the PDF version is allowed depending on the settings
|
||||
*
|
||||
* @param $args
|
||||
* array containing the possible parameters:
|
||||
* teaser, node, type, path
|
||||
* @return
|
||||
* FALSE if not allowed
|
||||
* PRINT_ALLOW_NORMAL_LINK if a normal link is allowed
|
||||
* PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
|
||||
*/
|
||||
function print_pdf_link_allowed($args) {
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
if ((!empty($args['teaser']) && !variable_get('print_pdf_link_teaser', PRINT_PDF_LINK_TEASER_DEFAULT))
|
||||
|| !user_access('access PDF version') || (empty($print_pdf_pdf_tool))) {
|
||||
// If the teaser link is disabled or the user is not allowed
|
||||
return FALSE;
|
||||
}
|
||||
if (!empty($args['path'])) {
|
||||
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
|
||||
if (ctype_digit($nid)) {
|
||||
$args['node'] = node_load($nid);
|
||||
}
|
||||
}
|
||||
if (!empty($args['node'])) {
|
||||
static $node_type = FALSE;
|
||||
|
||||
$node = $args['node'];
|
||||
if (isset($node->type)) {
|
||||
$node_type = $node->type;
|
||||
}
|
||||
// Node
|
||||
$print_pdf_node_link_visibility = variable_get('print_pdf_node_link_visibility', PRINT_PDF_NODE_LINK_VISIBILITY_DEFAULT);
|
||||
$print_pdf_node_link_pages = variable_get('print_pdf_node_link_pages', PRINT_PDF_NODE_LINK_PAGES_DEFAULT);
|
||||
|
||||
if (!_print_page_match($print_pdf_node_link_visibility, "node/". $node->nid, $print_pdf_node_link_pages)) {
|
||||
// Page not in visibility list
|
||||
return FALSE;
|
||||
}
|
||||
elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
|
||||
// Link is for a comment, return the configured setting
|
||||
// Cache this statically to avoid duplicate queries for every comment.
|
||||
static $res = array();
|
||||
if (!isset($res[$node->nid])) {
|
||||
$res[$node->nid] = db_fetch_object(db_query("SELECT comments FROM {print_pdf_node_conf} WHERE nid = %d", $node->nid));
|
||||
}
|
||||
$print_display_comment = ($res && ($res[$node->nid] !== FALSE)) ? intval($res[$node->nid]->comments) : variable_get('print_pdf_display_comment_'. $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
||||
if ($print_display_comment) {
|
||||
return PRINT_ALLOW_NORMAL_LINK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Node link
|
||||
if (isset($node->print_pdf_display) && !$node->print_pdf_display) {
|
||||
// Link for this node is disabled
|
||||
return FALSE;
|
||||
}
|
||||
elseif (isset($node->book)) {
|
||||
// Node is a book;
|
||||
$print_pdf_book_link = variable_get('print_pdf_book_link', PRINT_PDF_BOOK_LINK_DEFAULT);
|
||||
switch ($print_pdf_book_link) {
|
||||
case 1:
|
||||
if (user_access('access printer-friendly version')) {
|
||||
return PRINT_ALLOW_BOOK_LINK;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
return PRINT_ALLOW_NORMAL_LINK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return PRINT_ALLOW_NORMAL_LINK;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 'System' page
|
||||
$print_pdf_sys_link_visibility = variable_get('print_pdf_sys_link_visibility', PRINT_PDF_SYS_LINK_VISIBILITY_DEFAULT);
|
||||
$print_pdf_sys_link_pages = variable_get('print_pdf_sys_link_pages', PRINT_PDF_SYS_LINK_PAGES_DEFAULT);
|
||||
|
||||
return _print_page_match($print_pdf_sys_link_visibility, $_GET['q'], $print_pdf_sys_link_pages);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out the version of the TCPDF library
|
||||
*/
|
||||
function _print_pdf_tcpdf_version() {
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
|
||||
// prevent TCPDF default configs
|
||||
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
|
||||
}
|
||||
require_once($print_pdf_pdf_tool);
|
||||
|
||||
// Hide warnings, as some TCPDF constants may still be undefined
|
||||
if (class_exists('TCPDF')) {
|
||||
@$pdf = new TCPDF();
|
||||
|
||||
if (class_exists('TCPDF_STATIC')) {
|
||||
return TCPDF_STATIC::getTCPDFVersion();
|
||||
}
|
||||
elseif (method_exists($pdf, 'getTCPDFVersion')) {
|
||||
return $pdf->getTCPDFVersion();
|
||||
}
|
||||
elseif (defined('PDF_PRODUCER')) {
|
||||
sscanf(PDF_PRODUCER, "TCPDF %s", $version);
|
||||
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out the version of the wkhtmltopdf library
|
||||
*/
|
||||
function _print_pdf_wkhtmltopdf_version() {
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
$descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
|
||||
|
||||
$cmd = '"'. realpath($print_pdf_pdf_tool) .'" --version';
|
||||
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
|
||||
if (is_resource($process)) {
|
||||
$content = stream_get_contents($pipes[1]);
|
||||
$out = preg_match('!.*?(\d+\.\d+\.\d+).*$!m', $content, $matches);
|
||||
fclose($pipes[0]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
$retval = proc_close($process);
|
||||
}
|
||||
|
||||
return ($matches[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function print_pdf_views_api() {
|
||||
return array(
|
||||
'api' => 2.0,
|
||||
'path' => drupal_get_path('module', 'print_pdf'),
|
||||
);
|
||||
}
|
653
modules/print/print_pdf/print_pdf.pages.inc
Normal file
653
modules/print/print_pdf/print_pdf.pages.inc
Normal file
|
@ -0,0 +1,653 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Generates the PDF versions of the pages
|
||||
*
|
||||
* This file is included by the print_pdf module and includes the
|
||||
* functions that interface with the PDF generation packages.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
module_load_include('inc', 'print', 'print.pages');
|
||||
|
||||
/**
|
||||
* Generate a PDF version of the printer-friendly page
|
||||
*
|
||||
* @see print_controller()
|
||||
* @see _print_pdf_dompdf()
|
||||
* @see _print_pdf_tcpdf()
|
||||
*/
|
||||
function print_pdf_controller() {
|
||||
// Disable caching for generated PDFs, as Drupal doesn't ouput the proper headers from the cache
|
||||
$GLOBALS['conf']['cache'] = FALSE;
|
||||
|
||||
$args = func_get_args();
|
||||
$path = filter_xss(implode('/', $args));
|
||||
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
|
||||
|
||||
if (!empty($path)) {
|
||||
if ($alias = drupal_lookup_path('source', $path)) {
|
||||
// Alias
|
||||
$path_arr = explode('/', $alias);
|
||||
$node = node_load($path_arr[1]);
|
||||
}
|
||||
elseif (ctype_digit($args[0])) {
|
||||
// normal nid
|
||||
$node = node_load($args[0]);
|
||||
}
|
||||
|
||||
$pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT);
|
||||
if (module_exists('token')) {
|
||||
if (!empty($pdf_filename) && !empty($node)) {
|
||||
$pdf_filename = token_replace($pdf_filename, 'node', $node, TOKEN_PREFIX, TOKEN_SUFFIX, array('clear' => TRUE));
|
||||
}
|
||||
else {
|
||||
$pdf_filename = token_replace($pdf_filename, 'global', NULL, TOKEN_PREFIX, TOKEN_SUFFIX, array('clear' => TRUE));
|
||||
if (empty($pdf_filename)) {
|
||||
// If empty, use a fallback solution
|
||||
$pdf_filename = str_replace('/', '_', $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$pdf_filename = 'page';
|
||||
}
|
||||
|
||||
if (function_exists('transliteration_clean_filename')) {
|
||||
$pdf_filename = transliteration_clean_filename($pdf_filename, language_default('language'));
|
||||
}
|
||||
|
||||
drupal_alter('print_pdf_filename', $pdf_filename, $path);
|
||||
|
||||
$pdf = print_pdf_generate_path($path, $cid, $pdf_filename . '.pdf');
|
||||
if ($pdf == NULL) {
|
||||
drupal_goto($path);
|
||||
exit;
|
||||
}
|
||||
|
||||
$nodepath = (isset($node->path) && is_string($node->path)) ? drupal_get_normal_path($node->path) : 'node/'. $path;
|
||||
db_query("UPDATE {print_pdf_page_counter} SET totalcount = totalcount + 1, timestamp = %d WHERE path = '%s'", time(), $nodepath);
|
||||
// If we affected 0 rows, this is the first time viewing the node.
|
||||
if (!db_affected_rows()) {
|
||||
// We must create a new row to store counters for the new node.
|
||||
db_query("INSERT INTO {print_pdf_page_counter} (path, totalcount, timestamp) VALUES ('%s', 1, %d)", $nodepath, time());
|
||||
}
|
||||
}
|
||||
|
||||
function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL) {
|
||||
global $base_url;
|
||||
|
||||
$print = print_controller($path, $cid, PRINT_PDF_FORMAT);
|
||||
if ($print === FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Img elements must be set to absolute
|
||||
$pattern = '!<(img\s[^>]*?)>!is';
|
||||
$print['content'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['content']);
|
||||
$print['logo'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['logo']);
|
||||
$print['footer_message'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['footer_message']);
|
||||
|
||||
// Send to printer option causes problems with PDF
|
||||
$print['sendtoprinter'] = '';
|
||||
|
||||
$node = $print['node'];
|
||||
$html = theme('print_page', $print, PRINT_PDF_FORMAT, $node);
|
||||
$html = drupal_final_markup($html);
|
||||
|
||||
// Convert the a href elements, to make sure no relative links remain
|
||||
$pattern = '!<(a\s[^>]*?)>!is';
|
||||
$html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
|
||||
// And make anchor links relative again, to permit in-PDF navigation
|
||||
$html = preg_replace("!${base_url}/". PRINTPDF_PATH .'/.*?#!', '#', $html);
|
||||
|
||||
return print_pdf_generate_html($print, $html, $pdf_filename);
|
||||
}
|
||||
|
||||
function print_pdf_generate_html($print, $html, $filename = NULL) {
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
|
||||
if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
|
||||
return _print_pdf_dompdf($print, $html, $filename);
|
||||
}
|
||||
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
|
||||
return _print_pdf_tcpdf($print, $html, $filename);
|
||||
}
|
||||
elseif (drupal_substr(basename($print_pdf_pdf_tool, '.exe'), 0, 11) == 'wkhtmltopdf') {
|
||||
return _print_pdf_wkhtmltopdf($print, $html, $filename);
|
||||
}
|
||||
elseif ($filename) {
|
||||
return drupal_not_found();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert image paths to the file:// protocol
|
||||
*
|
||||
* In some Drupal setups, the use of the 'private' filesystem or Apache's
|
||||
* configuration prevent access to the images of the page. This function
|
||||
* tries to circumnvent those problems by accessing files in the local
|
||||
* filesystem.
|
||||
*
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
function _print_pdf_file_access_images($html) {
|
||||
global $base_url, $language;
|
||||
$print_pdf_images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
|
||||
|
||||
switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) {
|
||||
case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
|
||||
case LANGUAGE_NEGOTIATION_PATH:
|
||||
$lang = $language->language;
|
||||
break;
|
||||
default:
|
||||
$lang = '';
|
||||
break;
|
||||
}
|
||||
// Always convert private to local paths
|
||||
$file_downloads = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC);
|
||||
if ($file_downloads == FILE_DOWNLOADS_PRIVATE) {
|
||||
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
|
||||
$replacement = '$1file://'. realpath(file_directory_path()) .'/$2';
|
||||
$html = preg_replace($pattern, $replacement, $html);
|
||||
}
|
||||
elseif ($print_pdf_images_via_file) {
|
||||
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is";
|
||||
$replacement = '$1file://'. dirname($_SERVER['SCRIPT_FILENAME']) .'/$2';
|
||||
$html = preg_replace($pattern, $replacement, $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the PDF file using the dompdf library
|
||||
*
|
||||
* @param $print
|
||||
* array containing the configured data
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @param $filename
|
||||
* name of the PDF file to be generated
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
function _print_pdf_dompdf($print, $html, $filename = NULL) {
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
$print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
|
||||
$print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
|
||||
$print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
|
||||
|
||||
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
|
||||
if (!defined('DOMPDF_ENABLE_PHP')) define("DOMPDF_ENABLE_PHP", FALSE);
|
||||
if (!defined('DOMPDF_ENABLE_REMOTE')) define("DOMPDF_ENABLE_REMOTE", TRUE);
|
||||
if (!defined('DOMPDF_TEMP_DIR')) define("DOMPDF_TEMP_DIR", file_directory_temp());
|
||||
if (!defined('DOMPDF_UNICODE_ENABLED')) define("DOMPDF_UNICODE_ENABLED", variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT));
|
||||
if (!defined('DOMPDF_FONT_CACHE')) define("DOMPDF_FONT_CACHE", file_directory_path() . '/' . PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT . '/fonts/');
|
||||
}
|
||||
|
||||
require_once($print_pdf_pdf_tool);
|
||||
if (function_exists('spl_autoload_register')) {
|
||||
spl_autoload_register('DOMPDF_autoload');
|
||||
}
|
||||
|
||||
// Try to use local file access for image files
|
||||
$html = _print_pdf_file_access_images($html);
|
||||
|
||||
// Spaces in img URLs must be replaced with %20
|
||||
$pattern = '!<(img\s[^>]*?)>!is';
|
||||
$html = preg_replace_callback($pattern, '_print_replace_spaces', $html);
|
||||
|
||||
// dompdf seems to have problems with something in system.css so let's not use it
|
||||
$html = preg_replace('!<link.*?modules/system/system.css.*?/>!', '', $html);
|
||||
|
||||
$url_array = parse_url($print['url']);
|
||||
|
||||
$protocol = $url_array['scheme'] .'://';
|
||||
$host = $url_array['host'];
|
||||
$path = dirname($url_array['path']) .'/';
|
||||
|
||||
$dompdf = new DOMPDF();
|
||||
$dompdf->set_base_path($path);
|
||||
$dompdf->set_host($host);
|
||||
$dompdf->set_paper(drupal_strtolower($print_pdf_paper_size), $print_pdf_page_orientation);
|
||||
$dompdf->set_protocol($protocol);
|
||||
|
||||
// dompdf can't handle footers cleanly, so disable the following
|
||||
// $html = theme('print_pdf_dompdf_footer', $html);
|
||||
|
||||
// If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and then to HTML entities
|
||||
if (!variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT)) {
|
||||
// Convert the euro sign to an HTML entity
|
||||
$html = str_replace('€', '€', $html);
|
||||
|
||||
// Convert from UTF-8 to ISO 8859-1 and then to HTML entities
|
||||
if (function_exists('utf8_decode')) {
|
||||
$html = utf8_decode($html);
|
||||
}
|
||||
// iconv fails silently when it encounters something that it doesn't know, so don't use it
|
||||
// else if (function_exists('iconv')) {
|
||||
// $html = iconv('UTF-8', 'ISO-8859-1', $html);
|
||||
// }
|
||||
elseif (function_exists('mb_convert_encoding')) {
|
||||
$html = mb_convert_encoding($html, 'ISO-8859-1', 'UTF-8');
|
||||
}
|
||||
elseif (function_exists('recode_string')) {
|
||||
$html = recode_string('UTF-8..ISO_8859-1', $html);
|
||||
}
|
||||
$html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'ISO-8859-1'), ENT_NOQUOTES);
|
||||
}
|
||||
else {
|
||||
// Otherwise, ensure the content is properly formatted Unicode.
|
||||
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
|
||||
}
|
||||
|
||||
// Must get rid of tbody (dompdf goes into recursion)
|
||||
$html = preg_replace('!<tbody[^>]*?>|</tbody>!i', '', $html);
|
||||
|
||||
$dompdf->load_html($html);
|
||||
|
||||
$dompdf->render();
|
||||
if ($filename) {
|
||||
$dompdf->stream($filename, array('Attachment' => ($print_pdf_content_disposition == 2)));
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return $dompdf->output();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the PDF file using the TCPDF library
|
||||
*
|
||||
* @param $print
|
||||
* array containing the configured data
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @param $filename
|
||||
* name of the PDF file to be generated
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
function _print_pdf_tcpdf($print, $html, $filename = NULL) {
|
||||
global $base_url, $language;
|
||||
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
$print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
|
||||
$print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
|
||||
$print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
|
||||
|
||||
$pdf_tool_path = realpath(dirname($print_pdf_pdf_tool));
|
||||
|
||||
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
|
||||
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
|
||||
if (!defined('K_PATH_MAIN')) define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
|
||||
if (!defined('K_PATH_URL')) define('K_PATH_URL', $base_url);
|
||||
if (!defined('K_PATH_FONTS')) define('K_PATH_FONTS', $pdf_tool_path .'/fonts/');
|
||||
if (!defined('K_PATH_CACHE')) define('K_PATH_CACHE', file_directory_path() . '/' . PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT . '/cache/');
|
||||
if (!defined('K_PATH_IMAGES')) define('K_PATH_IMAGES', '');
|
||||
if (!defined('K_BLANK_IMAGE')) define('K_BLANK_IMAGE', $pdf_tool_path .'/images/_blank.png');
|
||||
if (!defined('K_CELL_HEIGHT_RATIO')) define('K_CELL_HEIGHT_RATIO', 1.25);
|
||||
if (!defined('K_SMALL_RATIO')) define('K_SMALL_RATIO', 2/3);
|
||||
}
|
||||
|
||||
// Try to use local file access for image files
|
||||
$html = _print_pdf_file_access_images($html);
|
||||
|
||||
// Decode HTML entities in image filenames
|
||||
$pattern = "!<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?>!is";
|
||||
$html = preg_replace_callback($pattern, create_function('$matches', 'return html_entity_decode($matches[0], ENT_QUOTES);'), $html);
|
||||
// Remove queries from the image URL
|
||||
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?)(?:%3F|\?)[^\s'\"]+([^>]*?>)!is";
|
||||
$html = preg_replace($pattern, '$1$2', $html);
|
||||
|
||||
require_once($print_pdf_pdf_tool);
|
||||
if (defined('PDF_PRODUCER') && (strpos(PDF_PRODUCER, 'PHP4') !== FALSE)) {
|
||||
module_load_include('inc', 'print_pdf', 'print_pdf.class_php4');
|
||||
}
|
||||
else {
|
||||
module_load_include('inc', 'print_pdf', 'print_pdf.class');
|
||||
}
|
||||
|
||||
$font = Array(
|
||||
check_plain(variable_get('print_pdf_font_family', PRINT_PDF_FONT_FAMILY_DEFAULT)),
|
||||
'',
|
||||
check_plain(variable_get('print_pdf_font_size', PRINT_PDF_FONT_SIZE_DEFAULT)),
|
||||
);
|
||||
$orientation = drupal_strtoupper($print_pdf_page_orientation[0]);
|
||||
|
||||
// create new PDF document
|
||||
$pdf = new PrintTCPDF($orientation , 'mm', $print_pdf_paper_size, TRUE);
|
||||
|
||||
// set document information
|
||||
if (isset($print['submitted'])) {
|
||||
$pdf->SetAuthor(strip_tags($print['submitted']));
|
||||
}
|
||||
$pdf->SetCreator(variable_get('site_name', 'Drupal'));
|
||||
$pdf->SetTitle(html_entity_decode($print['title'], ENT_QUOTES, 'UTF-8'));
|
||||
if (isset($print['taxonomy'])) {
|
||||
$keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
|
||||
$pdf->SetKeywords($keys);
|
||||
}
|
||||
$pdf->setPDFVersion('1.6');
|
||||
$pdf->setFontSubsetting(variable_get('print_pdf_font_subsetting', PRINT_PDF_FONT_SUBSETTING_DEFAULT));
|
||||
$pdf->setTcpdfLink(false);
|
||||
|
||||
if ($language->direction == LANGUAGE_RTL) {
|
||||
$pdf->setRTL(TRUE);
|
||||
}
|
||||
|
||||
$pdf = theme('print_pdf_tcpdf_header', $pdf, $html, $font);
|
||||
$pdf = theme('print_pdf_tcpdf_footer', $pdf, $html, $font);
|
||||
$pdf = theme('print_pdf_tcpdf_page', $pdf);
|
||||
|
||||
// add a page
|
||||
$pdf->AddPage();
|
||||
|
||||
$pdf = theme('print_pdf_tcpdf_content', $pdf, $html, $font);
|
||||
|
||||
// reset pointer to the last page
|
||||
$pdf->lastPage();
|
||||
|
||||
// try to recover from any warning/error
|
||||
ob_clean();
|
||||
|
||||
if ($filename) {
|
||||
// Close and output PDF document
|
||||
$output_dest = ($print_pdf_content_disposition == 2) ? 'D' : 'I';
|
||||
$pdf->Output($filename, $output_dest);
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return $pdf = $pdf->Output('', 'S');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the PDF file using wkhtmltopdf
|
||||
*
|
||||
* @param $print
|
||||
* array containing the configured data
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @param $filename
|
||||
* name of the PDF file to be generated
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
function _print_pdf_wkhtmltopdf($print, $html, $filename = NULL) {
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
$print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
|
||||
$print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
|
||||
$print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
|
||||
$print_pdf_wkhtmltopdf_options = variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS);
|
||||
|
||||
$dpi = 96;
|
||||
|
||||
if (function_exists('token_eplace') && !empty($print_pdf_wkhtmltopdf_options)) {
|
||||
$print_pdf_wkhtmltopdf_options = token_replace($print_pdf_wkhtmltopdf_options, 'node', $print['node'], TOKEN_PREFIX, TOKEN_SUFFIX, array('clear' => FALSE));
|
||||
}
|
||||
|
||||
$version = _print_pdf_wkhtmltopdf_version();
|
||||
|
||||
// 0.10.0 beta2 identifies itself as 0.9.9
|
||||
if (version_compare($version, '0.9.9', '>=')) {
|
||||
$print_pdf_wkhtmltopdf_options = '--disable-local-file-access '. $print_pdf_wkhtmltopdf_options;
|
||||
}
|
||||
elseif (version_compare($version, '0.9.6', '>=')) {
|
||||
$print_pdf_wkhtmltopdf_options = '--disallow-local-file-access '. $print_pdf_wkhtmltopdf_options;
|
||||
}
|
||||
else {
|
||||
drupal_goto($print['url']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'a'));
|
||||
$cmd = '"'. realpath($print_pdf_pdf_tool) ."\" --page-size $print_pdf_paper_size --orientation $print_pdf_page_orientation --dpi $dpi $print_pdf_wkhtmltopdf_options - -";
|
||||
|
||||
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
|
||||
|
||||
if (is_resource($process)) {
|
||||
fwrite($pipes[0], $html);
|
||||
fclose($pipes[0]);
|
||||
|
||||
$pdf = stream_get_contents($pipes[1]);
|
||||
fclose($pipes[1]);
|
||||
|
||||
stream_set_blocking($pipes[2], 0);
|
||||
$error = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[2]);
|
||||
|
||||
$retval = proc_close($process);
|
||||
if (!empty($error) || ($retval != 0)) {
|
||||
if (empty($error)) {
|
||||
$error = 'No stderr output available.';
|
||||
}
|
||||
watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error', array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($pdf)) {
|
||||
if ($filename) {
|
||||
if (headers_sent()) {
|
||||
exit("Unable to stream pdf: headers already sent");
|
||||
}
|
||||
header("Cache-Control: private");
|
||||
header("Content-Type: application/pdf");
|
||||
|
||||
$attachment = ($print_pdf_content_disposition == 2) ? "attachment" : "inline";
|
||||
|
||||
header("Content-Disposition: $attachment; filename=\"$filename\"");
|
||||
|
||||
echo $pdf;
|
||||
flush();
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return $pdf;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message('Unable to generate PDF file.', 'error');
|
||||
drupal_goto($meta['url']);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the dompdf footer contents
|
||||
*
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @see theme_print_pdf_tcpdf_footer()
|
||||
*/
|
||||
function theme_print_pdf_dompdf_footer($html) {
|
||||
preg_match('!<div class="print-footer">(.*?)</div>!si', $html, $tpl_footer);
|
||||
|
||||
if (isset($tpl_footer[1])) {
|
||||
$html = str_replace($tpl_footer[0], '', $html);
|
||||
|
||||
$text = '<script type="text/php">
|
||||
if (isset($pdf)) {
|
||||
$font = Font_Metrics::get_font("verdana");;
|
||||
$size = 10;
|
||||
$color = array(0,0,0);
|
||||
$text_height = Font_Metrics::get_font_height($font, $size);
|
||||
|
||||
$w = $pdf->get_width();
|
||||
$h = $pdf->get_height();
|
||||
|
||||
$footer = $pdf->open_object();
|
||||
|
||||
// Draw a line along the bottom
|
||||
$y = $h - 25;
|
||||
$pdf->line(15, $y, $w - 15, $y, $color, 1);
|
||||
|
||||
$y += $text_height / 2;
|
||||
$pdf->page_text(15, $y, \''. addslashes(strip_tags($tpl_footer[1])) .'\', $font, $size, $color);
|
||||
|
||||
$pdf->close_object();
|
||||
$pdf->add_object($footer, "all");
|
||||
|
||||
// Center the text
|
||||
$width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
|
||||
$pagenumtxt = t("Page !n of !total", array("!n" => "{PAGE_NUM}", "!total" => "{PAGE_COUNT}"));
|
||||
$pdf->page_text($w - 15 - $width, $y, $pagenumtxt, $font, $size, $color);
|
||||
}
|
||||
</script>';
|
||||
|
||||
return str_replace("<body>", "<body>" . $text, $html);
|
||||
} else {
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF header
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @param $font
|
||||
* array with the font definition (font name, styles and size)
|
||||
* @see theme_print_pdf_tcpdf_header()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_header($pdf, $html, $font) {
|
||||
preg_match('!<div class="print-logo">(.*?)</div>!si', $html, $tpl_logo);
|
||||
preg_match('!<h1 class="print-title">(.*?)</h1>!si', $html, $tpl_title);
|
||||
preg_match('!<div class="print-site_name">(.*?)</div>!si', $html, $tpl_site_name);
|
||||
|
||||
$ratio = 0;
|
||||
$logo = '';
|
||||
if (isset($tpl_logo[1]) && preg_match('!src\s*=\s*(?:"(.*?)"|\'(.*?)\'|([^\s]*))!i', $tpl_logo[1], $logo_url)) {
|
||||
$logo = $logo_url[1];
|
||||
if (!empty($logo)) {
|
||||
$size = getimagesize($logo);
|
||||
$ratio = $size ? ($size[0] / $size[1]) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// set header font
|
||||
$pdf->setHeaderFont($font);
|
||||
// set header margin
|
||||
$pdf->setHeaderMargin(5);
|
||||
// set header data
|
||||
$pdf->setHeaderData($logo, 10 * $ratio, html_entity_decode($tpl_title[1], ENT_QUOTES, 'UTF-8'), html_entity_decode(strip_tags($tpl_site_name[1]), ENT_QUOTES, 'UTF-8'));
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF page settings (margins, etc)
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @see theme_print_pdf_tcpdf_page()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_page($pdf) {
|
||||
// set margins
|
||||
$pdf->SetMargins(15, 20, 15);
|
||||
// set auto page breaks
|
||||
$pdf->SetAutoPageBreak(TRUE, 15);
|
||||
// set image scale factor
|
||||
$pdf->setImageScale(1);
|
||||
// set image compression quality
|
||||
$pdf->setJPEGQuality(100);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF page content
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @param $font
|
||||
* array with the font definition (font name, styles and size)
|
||||
* @see theme_print_pdf_tcpdf_content()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_content($pdf, $html, $font) {
|
||||
// set content font
|
||||
$pdf->setFont($font[0], $font[1], $font[2]);
|
||||
|
||||
preg_match('!<body.*?>(.*)</body>!sim', $html, $matches);
|
||||
$pattern = '!(?:<div class="print-(?:logo|site_name|breadcrumb|footer)">.*?</div>|<hr class="print-hr" />)!si';
|
||||
$matches[1] = preg_replace($pattern, '', $matches[1]);
|
||||
|
||||
// Make CCK fields look better
|
||||
$matches[1] = preg_replace('!(<div class="field.*?>)\s*!sm', '$1', $matches[1]);
|
||||
$matches[1] = preg_replace('!(<div class="field.*?>.*?</div>)\s*!sm', '$1', $matches[1]);
|
||||
$matches[1] = preg_replace('!<div( class="field-label.*?>.*?)</div>!sm', '<strong$1</strong>', $matches[1]);
|
||||
|
||||
// Since TCPDF's writeHTML is so bad with <p>, do everything possible to make it look nice
|
||||
$matches[1] = preg_replace('!<(?:p(|\s+.*?)/?|/p)>!i', '<br$1 />', $matches[1]);
|
||||
$matches[1] = str_replace(array('<div', 'div>'), array('<span', 'span><br />'), $matches[1]);
|
||||
do {
|
||||
$prev = $matches[1];
|
||||
$matches[1] = preg_replace('!(</span>)<br />(\s*?</span><br />)!s', '$1$2', $matches[1]);
|
||||
} while ($prev != $matches[1]);
|
||||
|
||||
@$pdf->writeHTML($matches[1]);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF footer contents
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @param $font
|
||||
* array with the font definition (font name, styles and size)
|
||||
* @see theme_print_pdf_tcpdf_footer()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_footer($pdf, $html, $font) {
|
||||
preg_match('!<div class="print-footer">(.*?)</div>!si', $html, $tpl_footer);
|
||||
if (isset($tpl_footer[1])) {
|
||||
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1]));
|
||||
|
||||
// set footer font
|
||||
$font[2] *= 0.8;
|
||||
$pdf->setFooterFont($font);
|
||||
// set footer margin
|
||||
$pdf->SetFooterMargin(10);
|
||||
// set footer data
|
||||
$pdf->setFooterContent($footer);
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF footer layout
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @see theme_print_pdf_tcpdf_footer2()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_footer2($pdf) {
|
||||
// Position at 1.5 cm from bottom
|
||||
$pdf->writeHTMLCell(0, 15, 15, $pdf->getPageHeight()-15, $pdf->footer);
|
||||
|
||||
$ormargins = $pdf->getOriginalMargins();
|
||||
$pagenumtxt = t('Page !n of !total', array('!n' => $pdf->PageNo(), '!total' => $pdf->getAliasNbPages()));
|
||||
// Print page number
|
||||
if ($pdf->getRTL()) {
|
||||
$pdf->SetX($ormargins['right']);
|
||||
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'L');
|
||||
}
|
||||
else {
|
||||
$pdf->SetX($ormargins['left']);
|
||||
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'R');
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
}
|
125
modules/print/print_pdf/print_pdf.views.inc
Normal file
125
modules/print/print_pdf/print_pdf.views.inc
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* PDF Version Views integration
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
// Views join handlers aren't truly handlers according to [#540128]
|
||||
// so they need to be specifically included here.
|
||||
module_load_include('inc', 'print', 'print_join_page_counter');
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function print_pdf_views_data() {
|
||||
// The 'group' index will be used as a prefix in the UI for any of this
|
||||
// table's fields, sort criteria, etc. so it's easy to tell where they came
|
||||
// from.
|
||||
$data['print_pdf_node_conf']['table']['group'] = t('Printer-friendly version');
|
||||
$data['print_pdf_page_counter']['table']['group'] = t('Printer-friendly version');
|
||||
|
||||
// This table references the {node} table. The declaration below creates an
|
||||
// 'implicit' relationship to the node table, so that when 'node' is the base
|
||||
// table, the fields are automatically available.
|
||||
$data['print_pdf_node_conf']['table']['join']['node'] = array(
|
||||
// 'left_field' is the primary key in the referenced table.
|
||||
// 'field' is the foreign key in this table.
|
||||
'left_field' => 'nid',
|
||||
'field' => 'nid',
|
||||
// 'type' => 'INNER',
|
||||
);
|
||||
$data['print_pdf_page_counter']['table']['join']['node'] = array(
|
||||
// 'left_field' is the primary key in the referenced table.
|
||||
// 'field' is the foreign key in this table.
|
||||
'left_field' => 'nid',
|
||||
'field' => 'path',
|
||||
// 'type' => 'INNER',
|
||||
'handler' => 'print_join_page_counter',
|
||||
);
|
||||
|
||||
// print_pdf_node_conf fields
|
||||
$data['print_pdf_node_conf']['link'] = array(
|
||||
'title' => t('PDF: Show link'),
|
||||
'help' => t('Whether to show the PDF version link.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_boolean',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_boolean_operator',
|
||||
'label' => t('Active'),
|
||||
'type' => 'yes-no',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['print_pdf_node_conf']['comments'] = array(
|
||||
'title' => t('PDF: Show link in individual comments'),
|
||||
'help' => t('Whether to show the PDF version link in individual comments.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_boolean',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_boolean_operator',
|
||||
'label' => t('Active'),
|
||||
'type' => 'yes-no',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['print_pdf_node_conf']['url_list'] = array(
|
||||
'title' => t('PDF: Show Printer-friendly URLs list'),
|
||||
'help' => t('Whether to show the URL list.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_boolean',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_boolean_operator',
|
||||
'label' => t('Active'),
|
||||
'type' => 'yes-no',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// print_pdf_page_counter fields
|
||||
$data['print_pdf_page_counter']['totalcount'] = array(
|
||||
'title' => t('PDF: Number of page accesses'),
|
||||
'help' => t('Counter of accesses to the PDF version for this node.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
);
|
||||
$data['print_pdf_page_counter']['timestamp'] = array(
|
||||
'title' => t('PDF: Last access'),
|
||||
'help' => t("The date of the last access to the node's PDF version."),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_date',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort_date',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_date',
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
Reference in a new issue