summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoao Ventura2016-11-13 17:36:56 (GMT)
committerJoao Ventura2016-11-13 17:41:14 (GMT)
commit24247060e453aa6d3f261688744c89516336cb69 (patch)
tree2f8e520df198ee06418a158e9bf7805f11f277a4
parent5cc5aeb7ea9249f4593873cc5d91a872cea92c8a (diff)
Coder fixes and update of library URLs
-rw-r--r--includes/print.drush.inc78
-rw-r--r--includes/print.inc20
-rw-r--r--print.admin.inc27
-rw-r--r--print.api.php4
-rw-r--r--print.install19
-rw-r--r--print.module46
-rw-r--r--print.pages.inc255
-rw-r--r--print.views.inc10
-rw-r--r--print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.drush.inc8
-rw-r--r--print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.install38
-rw-r--r--print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.module34
-rw-r--r--print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.pages.inc15
-rw-r--r--print_epub/print_epub.admin.inc2
-rw-r--r--print_epub/print_epub.api.php12
-rw-r--r--print_epub/print_epub.drush.inc14
-rw-r--r--print_epub/print_epub.install17
-rw-r--r--print_epub/print_epub.module29
-rw-r--r--print_epub/print_epub.pages.inc53
-rw-r--r--print_epub/print_epub.views.inc9
-rw-r--r--print_join_page_counter.inc23
-rw-r--r--print_mail/print_mail.admin.inc8
-rw-r--r--print_mail/print_mail.inc141
-rw-r--r--print_mail/print_mail.install48
-rw-r--r--print_mail/print_mail.module78
-rw-r--r--print_mail/print_mail.views.inc9
-rw-r--r--print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.drush.inc9
-rw-r--r--print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.module6
-rw-r--r--print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.pages.inc70
-rw-r--r--print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.drush.inc9
-rw-r--r--print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.module4
-rw-r--r--print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.pages.inc33
-rw-r--r--print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.admin.inc7
-rw-r--r--print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.class.inc23
-rw-r--r--print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.drush.inc7
-rw-r--r--print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.module6
-rw-r--r--print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.pages.inc136
-rw-r--r--print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.drush.inc27
-rw-r--r--print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.install31
-rw-r--r--print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.module47
-rw-r--r--print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc18
-rw-r--r--print_pdf/print_pdf.admin.inc13
-rw-r--r--print_pdf/print_pdf.api.php24
-rw-r--r--print_pdf/print_pdf.drush.inc14
-rw-r--r--print_pdf/print_pdf.install126
-rw-r--r--print_pdf/print_pdf.module237
-rw-r--r--print_pdf/print_pdf.pages.inc76
-rw-r--r--print_pdf/print_pdf.views.inc9
-rw-r--r--print_ui/print_ui.admin.inc36
-rw-r--r--print_ui/print_ui.api.php17
-rw-r--r--print_ui/print_ui.install2
-rw-r--r--print_ui/print_ui.module137
-rw-r--r--tests/print_basic.test30
52 files changed, 1276 insertions, 875 deletions
diff --git a/includes/print.drush.inc b/includes/print.drush.inc
index d152430..34f77ee 100644
--- a/includes/print.drush.inc
+++ b/includes/print.drush.inc
@@ -2,21 +2,21 @@
/**
* @file
- * common drush functions for the print submodules.
+ * Common drush functions for the print submodules.
*/
/**
- * Download and extract the lib
+ * Download and extract the lib.
*
* @param string $library
- * library to download.
+ * Library to download.
* @param string $url
- * URL of the file to download
+ * URL of the file to download.
*/
function _print_drush_download_lib($library, $url) {
$path = drush_get_option('path');
if (empty($path)) {
- $path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries';
+ $path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries/' . $library;
}
// Create the path if it does not exist.
@@ -29,18 +29,21 @@ function _print_drush_download_lib($library, $url) {
$olddir = getcwd();
drush_op('chdir', $path);
- // Warn about an existing dir
+ // 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
+ if (preg_match('!api.github.com/repos/.*/releases/latest!', $url)) {
+ $url = _print_drush_github_latest_url($url);
+ }
+
+ // Download the archive.
$filename = _print_drush_download_file($url);
if ($filename) {
$extract_ret = _print_drush_download_extract($filename);
if ($extract_ret) {
- // Remove the archive
+ // Remove the archive.
drush_op('unlink', $filename);
drush_log(dt('@file has been downloaded and extracted in @path', array('@file' => $filename, '@path' => $path)), 'success');
}
@@ -58,23 +61,41 @@ function _print_drush_download_lib($library, $url) {
}
/**
- * Download a file using wget or curl
+ * Get filename of latest from github.
+ *
+ * @param string $github_url
+ * The github URL to the latest project release.
+ *
+ * @return string
+ * The URL to the latest file release.
+ */
+function _print_drush_github_latest_url($github_url) {
+ $filename = _print_drush_download_file($github_url);
+ $contents = file_get_contents($filename);
+ $json = json_decode($contents);
+ $download_url = $json->assets[0]->browser_download_url;
+ drush_op('unlink', $filename);
+
+ return $download_url;
+}
+
+/**
+ * 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
+ * The path to the file to download.
*
* @return string
* The filename that was downloaded, or NULL if the file could not be
* downloaded.
*/
function _print_drush_download_file($download_url) {
- $wget_ret = drush_shell_exec("wget -nv --trust-server-names %s", $download_url);
-
if (!drush_get_context('DRUSH_SIMULATE')) {
+ $wget_ret = drush_shell_exec("wget -nv --content-disposition %s", $download_url);
if ($wget_ret) {
- // Get the filename of the saved file from the output
+ // Get the filename of the saved file from the output.
$wget_out = explode('"', array_shift(drush_shell_exec_output()));
$filename = $wget_out[1];
}
@@ -83,13 +104,12 @@ function _print_drush_download_file($download_url) {
$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
+ // File was downloaded with the temporary name.
+ // Find the effective name.
$filename = explode('/', array_shift(drush_shell_exec_output()));
$filename = array_pop($filename);
- // Rename file from tempname to effective name
+ // Rename file from tempname to effective name.
if (!drush_op('rename', $tempnam, './' . $filename)) {
$filename = $tempnam;
}
@@ -110,7 +130,7 @@ function _print_drush_download_file($download_url) {
* Helper to extract the downloaded zip/tar archive.
*
* @param string $filename
- * filename of the file to extract
+ * Filename of the file to extract.
*
* @return bool
* TRUE on success, FALSE on failure
@@ -119,28 +139,36 @@ function _print_drush_download_extract($filename) {
$arch_ret = FALSE;
if (drush_op('is_file', $filename)) {
- switch (drush_op('mime_content_type', $filename)) {
+ $mime_type = drush_op('mime_content_type', $filename);
+ switch ($mime_type) {
case 1:
$arch_ret = TRUE;
break;
+
case 'application/zip':
- // Decompress the zip archive
+ // Decompress the zip archive.
$arch_ret = drush_shell_exec('unzip -qq -o %s', $filename);
- // ZIP archives usually get the access rights wrong
+ // 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
+ // Decompress the tar gz archive.
$arch_ret = drush_shell_exec('tar xzf %s', $filename);
break;
+
case 'application/x-bzip2':
- // Decompress the tar bz2 archive
+ // Decompress the tar bz2 archive.
$arch_ret = drush_shell_exec('tar xjf %s', $filename);
break;
+
case 'application/x-xz':
- // Decompress the tar xz archive
+ // Decompress the tar xz archive.
$arch_ret = drush_shell_exec('tar xJf %s', $filename);
break;
+
+ default:
+ drush_log(dt('Unknown MIME type: @type', array('@type' => $mime_type)), 'error');
}
}
else {
diff --git a/includes/print.inc b/includes/print.inc
index bcd0dbd..9963b8f 100644
--- a/includes/print.inc
+++ b/includes/print.inc
@@ -2,7 +2,7 @@
/**
* @file
- * Common functions used by several of the print modules
+ * Common functions used by several of the print modules.
*
* @ingroup print
*/
@@ -29,18 +29,18 @@ function _print_scan_libs($lib, $mask) {
}
/**
- * Callback function for the preg_replace_callback replacing spaces with %20
+ * Callback function for the preg_replace_callback replacing spaces with %20.
*
* Replace spaces in URLs with %20
*
* @param array $matches
- * array with the matched tag patterns, usually <a...>+text+</a>
+ * Array with the matched tag patterns, usually <a...>+text+</a>.
*
* @return string
* tag with re-written URL
*/
function _print_replace_spaces($matches) {
- // first, split the html into the different tag attributes
+ // Split the html into the different tag attributes.
$pattern = '!\s*(\w+\s*=\s*"(?:\\\"|[^"])*")\s*|\s*(\w+\s*=\s*\'(?:\\\\\'|[^\'])*\')\s*|\s*(\w+\s*=\s*\w+)\s*|\s+!';
$attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($attribs as $key => $value) {
@@ -48,8 +48,8 @@ function _print_replace_spaces($matches) {
}
$size = count($attribs);
- for ($i=1; $i < $size; $i++) {
- // If the attribute is href or src, we may need to rewrite the URL in the value
+ for ($i = 1; $i < $size; $i++) {
+ // If the attribute is href or src, we need to rewrite the URL in the value.
if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
$url = trim($urls[1], " \t\n\r\0\x0B\"'");
$new_url = str_replace(' ', '%20', $url);
@@ -66,7 +66,7 @@ function _print_replace_spaces($matches) {
}
/**
- * Convert image paths to the file:// protocol
+ * 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
@@ -74,9 +74,9 @@ function _print_replace_spaces($matches) {
* filesystem.
*
* @param string $html
- * contents of the post-processed template already with the node data
+ * Contents of the post-processed template already with the node data.
* @param bool $images_via_file
- * if TRUE, convert also files in the 'public' filesystem to local paths
+ * If TRUE, convert also files in the 'public' filesystem to local paths.
*
* @return string
* converted file names
@@ -86,7 +86,7 @@ function _print_access_images_via_file($html, $images_via_file) {
$lang = (function_exists('language_negotiation_get_any') && language_negotiation_get_any('locale-url')) ? $language->language : '';
- // Always convert private to local paths
+ // Always convert private to local paths.
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
$replacement = '$1file://' . realpath(variable_get('file_private_path', '')) . '/$2';
$html = preg_replace($pattern, $replacement, $html);
diff --git a/print.admin.inc b/print.admin.inc
index 7aa8274..bc0514a 100644
--- a/print.admin.inc
+++ b/print.admin.inc
@@ -19,7 +19,9 @@ function print_main_settings() {
$print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
// Check that the stylesheet path is indeed valid and relative to base_path()
if (!empty($print_css) && empty($_POST)) {
- $css_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default', 'garland'))));
+ $css_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . strtr($print_css, array(
+ '%t' => drupal_get_path('theme', variable_get('theme_default', 'garland')),
+ ));
if (!is_file($css_path) || !is_readable($css_path)) {
drupal_set_message(t("File %file is not readable by the web server.", array('%file' => $css_path)), 'warning', FALSE);
}
@@ -37,8 +39,10 @@ function print_main_settings() {
'#size' => 60,
'#maxlength' => 250,
'#description' => t('The path to your custom print cascading stylesheet, if any. The path provided must be relative to the base path. When none is specified, the default module CSS file is used.') . '<br />' .
- t('Macros: %t (path to theme: "%theme")', array('%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')))) . '<br />' .
- t('Requires the <em>Administer site configuration</em> permission.'),
+ t('Macros: %t (path to theme: "%theme")', array(
+ '%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')),
+ )) . '<br />' .
+ t('Requires the <em>Administer site configuration</em> permission.'),
'#disabled' => !user_access('administer site configuration'),
);
@@ -54,7 +58,9 @@ function print_main_settings() {
'#title' => t('Printer-friendly URLs list'),
'#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
'#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.') . '<br />' .
- t('Note that you can enable/disable the URL list for each content type individually from the !url.', array('!url' => l(t('Content Types page'), 'admin/structure/types'))),
+ t('Note that you can enable/disable the URL list for each content type individually from the !url.', array(
+ '!url' => l(t('Content Types page'), 'admin/structure/types'),
+ )),
);
$form['settings']['print_urls_anchors'] = array(
@@ -89,7 +95,11 @@ function print_main_settings() {
$form['settings']['logo']['print_logo_options'] = array(
'#type' => 'radios',
'#title' => t('Logo type'),
- '#options' => array(t('None (Disabled)'), t("Current theme's logo"), t('User-specified')),
+ '#options' => array(
+ t('None (Disabled)'),
+ t("Current theme's logo"),
+ t('User-specified'),
+ ),
'#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
'#description' => t("Select the type of logo to display on the printer-friendly version. In case of a user-specified location, insert the path or URL below."),
);
@@ -120,7 +130,11 @@ function print_main_settings() {
$form['settings']['footer']['print_footer_options'] = array(
'#type' => 'radios',
'#title' => t('Footer type'),
- '#options' => array(t('None (Disabled)'), t("Site's footer"), t('User-specified')),
+ '#options' => array(
+ t('None (Disabled)'),
+ t("Site's footer"),
+ t('User-specified'),
+ ),
'#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
'#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
);
@@ -179,6 +193,7 @@ function _print_main_settings_validate($form, &$form_state) {
// files table as a temporary file. We'll make a copy and let the garbage
// collector delete the original upload.
if ($filename = file_unmanaged_copy($file->uri)) {
+ /** @var DrupalStreamWrapperInterface $wrapper */
$wrapper = file_stream_wrapper_get_instance_by_uri($filename);
$form_state['values']['print_logo_options'] = 2;
diff --git a/print.api.php b/print.api.php
index 4cc7038..fff2650 100644
--- a/print.api.php
+++ b/print.api.php
@@ -2,7 +2,7 @@
/**
* @file
- * Main API entry point for the Printer, email and PDF versions
+ * Main API entry point for the Printer, email and PDF versions.
*
* @ingroup print
*/
@@ -109,7 +109,7 @@
* etc.).
*
* @param string $url
- * the url to be modified.
+ * The url to be modified.
*
* @ingroup print_hooks
*/
diff --git a/print.install b/print.install
index 798576a..ea5a558 100644
--- a/print.install
+++ b/print.install
@@ -21,7 +21,7 @@ function print_install() {
* Implements hook_enable().
*/
function print_enable() {
- // Module weight
+ // Module weight.
db_update('system')
->fields(array(
'weight' => 0,
@@ -146,7 +146,7 @@ function print_schema() {
}
/**
- * Remove hardcoded numeric deltas from all blocks
+ * Remove hardcoded numeric deltas from all blocks.
*/
function print_update_7000(&$sandbox) {
$renamed_deltas = array(
@@ -160,14 +160,14 @@ function print_update_7000(&$sandbox) {
}
/**
- * Enable the print UI module
+ * Enable the print UI module.
*/
function print_update_7199(&$sandbox) {
module_enable(array('print_ui'), FALSE);
}
/**
- * Delete old variables
+ * Delete old variables.
*/
function print_update_7200(&$sandbox) {
variable_del('print_settings');
@@ -193,7 +193,7 @@ function print_update_7200(&$sandbox) {
}
/**
- * Enable block and help area links
+ * Enable block and help area links.
*/
function print_update_7202(&$sandbox) {
$link_pos = variable_get('print_html_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
@@ -203,11 +203,16 @@ function print_update_7202(&$sandbox) {
}
/**
- * Increase size of the path field in the print_page_counter table
+ * Increase size of the path field in the print_page_counter table.
*/
function print_update_7203(&$sandbox) {
db_drop_primary_key('print_page_counter');
db_change_field('print_page_counter', 'path', 'path',
- array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
+ array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'description' => 'Page path',
+ ),
array('primary key' => array('path')));
}
diff --git a/print.module b/print.module
index 1a56c9f..1f64414 100644
--- a/print.module
+++ b/print.module
@@ -85,7 +85,13 @@ function print_permission() {
function print_theme() {
return array(
'print' => array(
- 'variables' => array('node' => NULL, 'query' => NULL, 'format' => '', 'expand_css' => FALSE, 'message' => ''),
+ 'variables' => array(
+ 'node' => NULL,
+ 'query' => NULL,
+ 'format' => '',
+ 'expand_css' => FALSE,
+ 'message' => '',
+ ),
'template' => 'print',
'file' => 'print.pages.inc',
),
@@ -207,7 +213,7 @@ function print_block_view($delta = '') {
case 'print-top':
$block['subject'] = t('Most printed');
$result = db_query_range("SELECT path FROM {print_page_counter} LEFT JOIN {node} n ON path = CONCAT('node/', n.nid) WHERE status <> 0 OR status IS NULL ORDER BY totalcount DESC", 0, 3)
- ->fetchAll();
+ ->fetchAll();
if (count($result)) {
$items = array();
foreach ($result as $obj) {
@@ -224,11 +230,13 @@ function print_block_view($delta = '') {
* Implements hook_help().
*/
function print_help($path, $arg) {
+ $ret = '';
switch ($path) {
case 'admin/help#print':
- // Return a line-break version of the module README
- return _filter_autop(file_get_contents(drupal_get_path('module', 'print') . '/README.txt'));
+ // Return a line-break version of the module README.
+ $ret = _filter_autop(file_get_contents(drupal_get_path('module', 'print') . '/README.txt'));
}
+ return $ret;
}
/**
@@ -251,7 +259,7 @@ function print_entity_info_alter(&$info) {
'custom settings' => FALSE,
),
);
- // Add the 'Print' view mode for field_collections
+ // Add the 'Print' view mode for field_collections.
if (module_exists('field_collection')) {
$info['field_collection_item']['view modes'] += array(
PRINT_VIEW_MODE => array(
@@ -263,10 +271,10 @@ function print_entity_info_alter(&$info) {
}
/**
- * Auxiliary function to discover a given page's title
+ * Auxiliary function to discover a given page's title.
*
* @param string $path
- * path of the page being identified
+ * Path of the page being identified.
*
* @return string
* string with the page's title
@@ -276,16 +284,16 @@ function _print_get_title($path) {
$nid = preg_replace('!^node/!', '', $path);
if (ctype_digit($nid)) {
return db_query("SELECT title FROM {node} WHERE nid = :nid", array(':nid' => $nid))
- ->fetchField();
+ ->fetchField();
}
else {
- // Not a node, try to get title from the menu system
+ // Not a node, try to get title from the menu system.
$menu_item = menu_get_item($path);
if (!empty($menu_item['title'])) {
return $menu_item['title'];
}
elseif (drupal_substr($menu_item['page_callback'], 0, 6) == 'views_') {
- // It's a view, load the view to have access to the title
+ // It's a view, load the view to have access to the title.
$view = views_get_view($menu_item['page_arguments']['0']);
return $view->get_title();
}
@@ -296,7 +304,7 @@ function _print_get_title($path) {
}
/**
- * Auxiliary function to display a formatted Printer-friendly link
+ * Auxiliary function to display a formatted Printer-friendly link.
*
* Function made available so that developers may call this function from
* their defined pages/blocks.
@@ -307,7 +315,7 @@ function _print_get_title($path) {
* node object, to be used in checking node access. If the path argument is
* not provided, the path used will be node/nid.
* @param string $location
- * where in the page where the link is being inserted ('link', 'corner',
+ * Where in the page where the link is being inserted ('link', 'corner',
* 'block', 'help').
*
* @return string
@@ -317,7 +325,11 @@ function _print_get_title($path) {
*/
function print_insert_link($path = NULL, $node = NULL, $location = '') {
if (function_exists('print_ui_insert_link')) {
- return print_ui_insert_link(print_print_link(), array('path' => $path, 'node' => $node, 'location' => $location));
+ return print_ui_insert_link(print_print_link(), array(
+ 'path' => $path,
+ 'node' => $node,
+ 'location' => $location,
+ ));
}
else {
return FALSE;
@@ -325,11 +337,11 @@ function print_insert_link($path = NULL, $node = NULL, $location = '') {
}
/**
- * Check if the link to the PF version is allowed depending on the settings
+ * Check if the link to the PF version is allowed depending on the settings.
*
* @param array $args
- * array containing the possible parameters:
- * view_mode, node, type, path
+ * Array containing the possible parameters:
+ * view_mode, node, type, path.
*
* @return bool
* FALSE if not allowed, TRUE otherwise
@@ -342,7 +354,7 @@ function print_link_allowed($args) {
* Implements hook_contextual_links_view_alter().
*/
function print_contextual_links_view_alter(&$element, $items) {
- // Hide all contextual links
+ // Hide all contextual links.
if (preg_match('!^print!', $_GET['q'])) {
unset($element['#links']);
}
diff --git a/print.pages.inc b/print.pages.inc
index 8a67a8a..06e7128 100644
--- a/print.pages.inc
+++ b/print.pages.inc
@@ -14,23 +14,27 @@
$_print_urls = PRINT_URLS_DEFAULT;
/**
- * Generate an HTML version of the printer-friendly page
+ * Generate an HTML version of the printer-friendly page.
*
* @see print_controller()
*/
function print_controller_html() {
$args = func_get_args();
$path = filter_xss(implode('/', $args));
- $cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
+ $cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
$link = print_print_link();
$node = print_controller($path, $link['format'], $cid);
if ($node) {
- // Handle the query
+ // Handle the query.
$query = $_GET;
unset($query['q']);
- $html = theme('print', array('node' => $node, 'query' => $query, 'format' => $link['format']));
+ $html = theme('print', array(
+ 'node' => $node,
+ 'query' => $query,
+ 'format' => $link['format'],
+ ));
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
drupal_send_headers();
print $html;
@@ -48,19 +52,19 @@ function print_controller_html() {
}
/**
- * Select the print generator function based on the page type
+ * Select the print generator function based on the page type.
*
* Depending on the type of node, this functions chooses the appropriate
* generator function.
*
* @param string $path
- * path of the original page
+ * Path of the original page.
* @param string $format
- * format of the page being generated
+ * Format of the page being generated.
* @param int $cid
- * comment ID of the individual comment to be rendered
+ * Comment ID of the individual comment to be rendered.
* @param string $view_mode
- * (optional) view mode to be used when rendering the content
+ * (Optional) view mode to be used when rendering the content.
*
* @return object
* node-like object to be used in the print template
@@ -72,7 +76,7 @@ function print_controller_html() {
*/
function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
if (empty($path)) {
- // If no path was provided, let's try to generate a page for the referer
+ // If no path was provided, let's try to generate a page for the referer.
global $base_url;
$ref = $_SERVER['HTTP_REFERER'];
@@ -83,7 +87,8 @@ function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_M
}
if ($alias = drupal_lookup_path('source', $path)) {
// Indirect call with print/alias
- // If there is a path alias with these arguments, generate a printer-friendly version for it
+ // If there is a path alias with these arguments, generate a
+ // printer-friendly version for it.
$path = $alias;
}
$parts = explode('/', $path);
@@ -99,11 +104,12 @@ function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_M
else {
$ret = preg_match('!^book/export/html/(.*)!i', $path, $matches);
if ($ret == 1) {
- // This is a book PF page link, handle trough the book handling functions
+ // This is a book PF page link, handle trough the book handling functions.
$node = _print_generate_book($matches[1], $format);
}
else {
- // If no content node was found, handle the page printing with the 'printable' engine
+ // If no content node was found, handle the page printing with the
+ // 'printable' engine.
$node = _print_generate_path($path, $format);
}
}
@@ -115,8 +121,6 @@ function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_M
* Implements hook_preprocess_HOOK().
*/
function print_preprocess_print(&$variables) {
- global $language;
-
$node = $variables['node'];
$format = $variables['format'];
$path = drupal_get_path_alias(empty($node->nid) ? $node->path : "node/$node->nid");
@@ -129,7 +133,7 @@ function print_preprocess_print(&$variables) {
$variables['page']['#show_messages'] = FALSE;
- // Stolen from theme() so that ALL preprocess functions are called
+ // Stolen from theme() so that ALL preprocess functions are called.
$hook = 'page';
$info = $hooks[$hook];
if (isset($info['preprocess functions']) || isset($info['process functions'])) {
@@ -149,35 +153,49 @@ function print_preprocess_print(&$variables) {
$logo_url = FALSE;
switch (variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT)) {
- case 1: // theme's
+ // Theme logo.
+ case 1:
$logo_url = theme_get_setting('logo');
break;
- case 2: // user-specifed
+
+ // User-specifed logo.
+ case 2:
$logo_url = strip_tags(variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT));
break;
}
$logo_url = preg_replace('!^' . base_path() . '!', '', $logo_url);
- $variables['print_logo'] = $logo_url ? theme('image', array('path' => $logo_url, 'alt' => variable_get('site_name', 'Drupal'), 'attributes' => array('class' => array('print-logo'), 'id' => 'logo'))) : NULL;
-
- $variables['print_node'] = $node;
- $variables['content'] = $node->content;
- $variables['scripts'] = drupal_get_js();
- $variables['footer_scripts'] = drupal_get_js('footer');
- $variables['sourceurl_enabled'] = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT);
- $variables['url'] = url($path, array('absolute' => TRUE, 'query' => $variables['query']));
- $variables['source_url'] = url(variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT) ? drupal_get_normal_path($path) : $path, array('alias' => TRUE, 'absolute' => TRUE, 'query' => $variables['query']));
- $variables['cid'] = isset($node->cid) ? $node->cid : NULL;
- $variables['print_title'] = check_plain($node->title);
- $variables['head'] = drupal_get_html_head();
- $variables['robots_meta'] = _print_robots_meta_generator();
- $variables['css'] = _print_css_generator($variables['expand_css']);
+ $variables['print_logo'] = $logo_url ? theme('image', array(
+ 'path' => $logo_url,
+ 'alt' => variable_get('site_name', 'Drupal'),
+ 'attributes' => array(
+ 'class' => array('print-logo'),
+ 'id' => 'logo',
+ ),
+ )) : NULL;
+
+ $variables['print_node'] = $node;
+ $variables['content'] = $node->content;
+ $variables['scripts'] = drupal_get_js();
+ $variables['footer_scripts'] = drupal_get_js('footer');
+ $variables['sourceurl_enabled'] = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT);
+ $variables['url'] = url($path, array('absolute' => TRUE, 'query' => $variables['query']));
+ $variables['source_url'] = url(variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT) ? drupal_get_normal_path($path) : $path, array(
+ 'alias' => TRUE,
+ 'absolute' => TRUE,
+ 'query' => $variables['query'],
+ ));
+ $variables['cid'] = isset($node->cid) ? $node->cid : NULL;
+ $variables['print_title'] = check_plain($node->title);
+ $variables['head'] = drupal_get_html_head();
+ $variables['robots_meta'] = _print_robots_meta_generator();
+ $variables['css'] = _print_css_generator($variables['expand_css']);
if (variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT) && ($format == 'html')) {
drupal_add_js('misc/drupal.js', array('weight' => JS_LIBRARY));
$window_close = (variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT) && variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT)) ? 'window.close();' : '';
- $variables['sendtoprinter'] = '<script type="text/javascript">(function ($) { Drupal.behaviors.print = {attach: function(context) {$(window).load(function() {window.print();' . $window_close . '})}}})(jQuery);</script>';
+ $variables['sendtoprinter'] = '<script type="text/javascript">(function ($) { Drupal.behaviors.print = {attach: function() {$(window).load(function() {window.print();' . $window_close . '})}}})(jQuery);</script>';
}
$type = (isset($node->type)) ? $node->type : '';
@@ -195,7 +213,7 @@ function print_preprocess_print(&$variables) {
* Returns HTML for the published line of the print template.
*
* @param array $vars
- * An empty associative array
+ * An empty associative array.
*
* @return string
* HTML text with the published line
@@ -215,7 +233,7 @@ function theme_print_published($vars) {
*
* @param array $vars
* An associative array containing:
- * - $node: the node object
+ * - $node: the node object.
*
* @return string
* HTML text with the breadcrumb
@@ -245,7 +263,7 @@ function theme_print_breadcrumb($vars) {
* Returns HTML for the footer of the print template.
*
* @param array $vars
- * An empty associative array
+ * An empty associative array.
*
* @return string
* HTML text with the footer
@@ -257,15 +275,18 @@ function theme_print_footer($vars) {
$footer = '';
switch (variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT)) {
- case 1: // theme's
+ // Theme footer.
+ case 1:
$footer_blocks = block_get_blocks_by_region('footer');
$footer = variable_get('site_footer', FALSE) . "\n" . drupal_render($footer_blocks);
break;
- case 2: // user-specifed
+
+ // User-specified footer.
+ case 2:
$footer = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT);
break;
}
- // Delete the contextual links
+ // Delete the contextual links.
$footer = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $footer);
return filter_xss_admin($footer);
@@ -308,7 +329,7 @@ function theme_print_sourceurl($vars) {
* Returns HTML for the URL list of the print template.
*
* @param array $vars
- * An empty associative array
+ * An empty associative array.
*
* @return string
* HTML text with the URL list
@@ -319,10 +340,10 @@ function theme_print_sourceurl($vars) {
function theme_print_url_list($vars) {
global $_print_urls;
- // Display the collected links at the bottom of the page. Code once taken from Kjartan Mannes' project.module
+ // Display the collected links at the bottom of the page. Code once taken from
+ // Kjartan Mannes' project.module.
if (!empty($_print_urls)) {
$urls = _print_friendly_urls();
- $max = count($urls);
$url_list = '';
foreach ($urls as $key => $url) {
drupal_alter('print_url_list', $url);
@@ -331,15 +352,12 @@ function theme_print_url_list($vars) {
if (!empty($url_list)) {
return "<p><strong>" . t('Links') . "</strong><br />$url_list</p>";
}
- else {
- return '';
- }
}
-
+ return '';
}
/**
- * Generates a robots meta tag to tell them what they may index
+ * Generates a robots meta tag to tell them what they may index.
*
* @return string
* meta robots tag
@@ -366,7 +384,7 @@ function _print_robots_meta_generator() {
}
/**
- * Generates the CSS directive to include in the printer-friendly version
+ * Generates the CSS directive to include in the printer-friendly version.
*
* @param bool $expand
* If TRUE, the provided CSS will be expanded, instead of given as a list
@@ -388,13 +406,13 @@ function _print_css_generator($expand = FALSE) {
if (!variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT)) {
foreach ($drupal_css as $key => $css_file) {
if ($css_file['group'] == CSS_THEME) {
- // Unset the theme's CSS
+ // Unset the theme's CSS.
unset($drupal_css[$key]);
}
}
}
- // Expand the CSS if requested
+ // Expand the CSS if requested.
if ($expand) {
$style = '';
$css_files = array_keys($drupal_css);
@@ -411,13 +429,13 @@ function _print_css_generator($expand = FALSE) {
}
/**
- * Callback function for the preg_replace_callback for URL-capable patterns
+ * Callback function for the preg_replace_callback for URL-capable patterns.
*
* Manipulate URLs to make them absolute in the URLs list, and add a [n]
* footnote marker.
*
* @param array $matches
- * array with the matched tag patterns, usually <a...>+text+</a>
+ * Array with the matched tag patterns, usually <a...>+text+</a>.
*
* @return string
* tag with re-written URL and, if applicable, the [n] index to the URL list
@@ -427,7 +445,7 @@ function _print_rewrite_urls($matches) {
$include_anchors = variable_get('print_urls_anchors', PRINT_URLS_ANCHORS_DEFAULT);
- // first, split the html into the different tag attributes
+ // First, split the html into the different tag attributes.
$pattern = '!\s*(\w+\s*=\s*"(?:\\\"|[^"])*")\s*|\s*(\w+\s*=\s*\'(?:\\\\\'|[^\'])*\')\s*|\s*(\w+\s*=\s*\w+)\s*|\s+!';
$attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($attribs as $key => $value) {
@@ -435,34 +453,38 @@ function _print_rewrite_urls($matches) {
}
$size = count($attribs);
- for ($i=1; $i < $size; $i++) {
- // If the attribute is href or src, we may need to rewrite the URL in the value
+ for ($i = 1; $i < $size; $i++) {
+ // If the attribute is href or src, rewrite the URL in the value.
if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
$url = trim($urls[1], " \t\n\r\0\x0B\"'");
if (empty($url)) {
- // If URL is empty, use current_url
+ // If URL is empty, use current_url.
$path = explode('/', $_GET['q']);
unset($path[0]);
$path = implode('/', $path);
if (ctype_digit($path)) {
$path = "node/$path";
}
- // Printer-friendly URLs is on, so we need to make it absolute
- $newurl = url($path, array('fragment' => drupal_substr($url, 1), 'absolute' => TRUE));
+ // Printer-friendly URLs is on, so we need to make it absolute.
+ $newurl = url($path, array(
+ 'fragment' => drupal_substr($url, 1),
+ 'absolute' => TRUE,
+ ));
}
elseif (strpos(html_entity_decode($url), '://') || preg_match('!^mailto:.*?@.*?\..*?$!iu', html_entity_decode($url))) {
- // URL is absolute, do nothing
+ // URL is absolute, do nothing.
$newurl = $url;
}
elseif (strpos(html_entity_decode($url), '//') === 0) {
- // URL is 'almost absolute', but it does not contain protocol; replace with base_path protocol
+ // URL is 'almost absolute', but it does not contain protocol; replace
+ // with base_path protocol.
$newurl = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . ":" . $url;
$matches[1] = str_replace($url, $newurl, $matches[1]);
}
else {
if ($url[0] == '#') {
- // URL is an anchor tag
+ // URL is an anchor tag.
if ($include_anchors && (!empty($_print_urls))) {
$path = explode('/', $_GET['q']);
unset($path[0]);
@@ -470,21 +492,24 @@ function _print_rewrite_urls($matches) {
if (ctype_digit($path)) {
$path = "node/$path";
}
- // Printer-friendly URLs is on, so we need to make it absolute
- $newurl = url($path, array('fragment' => drupal_substr($url, 1), 'absolute' => TRUE));
+ // Printer-friendly URLs is on, so we need to make it absolute.
+ $newurl = url($path, array(
+ 'fragment' => drupal_substr($url, 1),
+ 'absolute' => TRUE,
+ ));
}
// Because base href is the original page, change the link to
- // still be usable inside the print page
+ // still be usable inside the print page.
$matches[1] = str_replace($url, check_plain(base_path() . $_GET['q'] . $url), $matches[1]);
}
else {
- // URL is relative, convert it into absolute URL
+ // URL is relative, convert it into absolute URL.
if ($url[0] == '/') {
- // If it starts with '/' just append it to the server name
+ // If it starts with '/' just append it to the server name.
$newurl = $base_root . '/' . trim($url, '/');
}
elseif (preg_match('!^(?:index.php)?\?q=!i', $url)) {
- // If it starts with ?q=, just prepend with the base URL
+ // If it starts with ?q=, just prepend with the base URL.
$newurl = $base_url . '/' . trim($url, '/');
}
else {
@@ -510,10 +535,10 @@ function _print_rewrite_urls($matches) {
/**
* Auxiliary function to store the Printer-friendly URLs list as static.
*
- * @param string $url
- * absolute URL to be inserted in the list
+ * @param string|int $url
+ * Absolute URL to be inserted in the list.
*
- * @return array
+ * @return array|int
* list of URLs previously stored if $url is 0, or the current count
* otherwise.
*/
@@ -529,18 +554,20 @@ function _print_friendly_urls($url = 0) {
return count($urls);
}
}
- $ret = $urls;
- $urls = array();
- return $ret;
+ else {
+ $ret = $urls;
+ $urls = array();
+ return $ret;
+ }
}
/**
- * Check URL list settings for this node
+ * Check URL list settings for this node.
*
- * @param object $node
- * node object
+ * @param Object $node
+ * Node object.
* @param string $format
- * format of the page being generated
+ * Format of the page being generated.
*
* @return bool
* TRUE if URL list should be displayed, FALSE otherwise
@@ -553,25 +580,25 @@ function _print_url_list_enabled($node, $format) {
$node_urllist = isset($node->{'print_' . $format . '_display_urllist'}) ? $node->{'print_' . $format . '_display_urllist'} : variable_get('print_' . $format . '_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
- // Get value of Printer-friendly URLs setting
+ // Get value of Printer-friendly URLs setting.
return (variable_get('print_urls', PRINT_URLS_DEFAULT) && ($node_urllist));
}
/**
- * Prepare a Printer-friendly-ready node body for content nodes
+ * Prepare a Printer-friendly-ready node body for content nodes.
*
* @param int $nid
- * node ID of the node to be rendered into a printer-friendly page
+ * Node ID of the node to be rendered into a printer-friendly page.
* @param string $format
- * format of the page being generated
+ * Format of the page being generated.
* @param int $vid
- * (optional) revision ID of the node to use
+ * (Optional) revision ID of the node to use.
* @param int $cid
- * (optional) comment ID of the individual comment to be rendered
+ * (Optional) comment ID of the individual comment to be rendered.
* @param string $view_mode
- * (optional) view mode to be used when rendering the content
+ * (Optional) view mode to be used when rendering the content.
*
- * @return object
+ * @return object|bool
* filled node-like object to be used in the print template
*/
function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
@@ -581,26 +608,27 @@ function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mod
$langcode = $GLOBALS['language_content']->language;
}
- // We can take a node id
+ // We can take a node id.
$node = node_load($nid, $vid);
if (!$node) {
- // Node not found
+ // Node not found.
drupal_not_found();
return FALSE;
}
elseif (!node_access('view', $node)) {
- // Access is denied
+ // Access is denied.
drupal_access_denied();
return FALSE;
}
drupal_set_title($node->title);
+ $build = array();
if ($cid === NULL) {
// Adapted (simplified) version of node_view
- // Render the node content
+ // Render the node content.
node_build_content($node, $view_mode);
- // Disable the links area
+ // Disable the links area.
unset($node->content['links']);
$build = $node->content;
@@ -609,8 +637,7 @@ function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mod
if (function_exists('comment_node_page_additions') &&
(($cid != NULL) || (variable_get('print_comments', PRINT_COMMENTS_DEFAULT)))) {
- // Print only the requested comment (or if $cid is NULL, all of them)
-
+ // Print only the requested comment (or if $cid is NULL, all of them).
$comments = comment_node_page_additions($node);
if (!empty($comments)) {
unset($comments['comment_form']);
@@ -642,7 +669,7 @@ function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mod
$content = render($build);
- // Get rid of any links before the content
+ // Get rid of any links before the content.
$parts = explode('<div class="content', $content, 2);
if (count($parts) == 2) {
$pattern = '!(.*?)<a [^>]*?>(.*?)</a>(.*?)!mis';
@@ -650,10 +677,10 @@ function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mod
$content = implode('<div class="content', $parts);
}
- // Check URL list settings
+ // Check URL list settings.
$_print_urls = _print_url_list_enabled($node, $format);
- // Convert the a href elements
+ // Convert the a href elements.
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
$content = preg_replace_callback($pattern, '_print_rewrite_urls', $content);
@@ -663,20 +690,20 @@ function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mod
}
/**
- * Prepare a Printer-friendly-ready node body for non-content pages
+ * Prepare a Printer-friendly-ready node body for non-content pages.
*
* @param string $path
- * path of the node to be rendered into a printer-friendly page
+ * Path of the node to be rendered into a printer-friendly page.
* @param string $format
- * format of the page being generated
+ * Format of the page being generated.
*
- * @return object
+ * @return object|bool
* filled node-like object to be used in the print template
*/
function _print_generate_path($path, $format) {
global $_print_urls;
- // Handle node tabs
+ // Handle node tabs.
$parts = explode('/', $path);
if (ctype_digit($parts[0]) && (count($parts) > 1)) {
$path = 'node/' . $path;
@@ -697,11 +724,10 @@ function _print_generate_path($path, $format) {
case MENU_NOT_FOUND:
drupal_not_found();
return FALSE;
- break;
+
case MENU_ACCESS_DENIED:
drupal_access_denied();
return FALSE;
- break;
}
}
@@ -709,32 +735,31 @@ function _print_generate_path($path, $format) {
$node->path = $path;
$node->changed = REQUEST_TIME;
- // Delete any links area
+ // Delete any links area.
$node->content = preg_replace('!\s*<div class="links">.*?</div>!sim', '', $node->content);
- // Delete the contextual links also
+ // Delete the contextual links also.
$node->content = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $node->content);
- // Check URL list settings
+ // Check URL list settings.
$_print_urls = _print_url_list_enabled($node, $format);
- // Convert the a href elements
+ // Convert the a href elements.
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
$node->content = preg_replace_callback($pattern, '_print_rewrite_urls', $node->content);
return $node;
}
-
/**
- * Prepare a Printer-friendly-ready node body for book pages
+ * Prepare a Printer-friendly-ready node body for book pages.
*
* @param int $nid
- * node ID of the node to be rendered into a printer-friendly page
+ * Node ID of the node to be rendered into a printer-friendly page.
* @param string $format
- * format of the page being generated
+ * Format of the page being generated.
*
- * @return object
+ * @return object|bool
* filled node-like object to be used in the print template
*/
function _print_generate_book($nid, $format) {
@@ -742,12 +767,12 @@ function _print_generate_book($nid, $format) {
$node = node_load($nid);
if (!$node) {
- // Node not found
+ // Node not found.
drupal_not_found();
return FALSE;
}
elseif (!node_access('view', $node) || (!user_access('access printer-friendly version'))) {
- // Access is denied
+ // Access is denied.
drupal_access_denied();
return FALSE;
}
@@ -755,10 +780,10 @@ function _print_generate_book($nid, $format) {
$tree = book_menu_subtree_data($node->book);
$node->content = book_export_traverse($tree, 'book_node_export');
- // Check URL list settings
+ // Check URL list settings.
$_print_urls = _print_url_list_enabled($node, $format);
- // Convert the a href elements
+ // Convert the a href elements.
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
$node->content = preg_replace_callback($pattern, '_print_rewrite_urls', $node->content);
diff --git a/print.views.inc b/print.views.inc
index c50e183..a76c4e0 100644
--- a/print.views.inc
+++ b/print.views.inc
@@ -2,12 +2,11 @@
/**
* @file
- * Printer-friendly version Views integration
+ * Printer-friendly version Views integration.
*
* @ingroup print
*/
-
/**
* Implements hook_views_data().
*/
@@ -26,18 +25,16 @@ function print_views_data() {
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
-// 'type' => 'INNER',
);
$data['print_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_node_conf fields
+ // print_node_conf fields.
$data['print_node_conf']['link'] = array(
'title' => t('Web: Show link'),
'help' => t('Whether to show the printer-friendly version link.'),
@@ -87,8 +84,7 @@ function print_views_data() {
),
);
-
- // print_page_counter fields
+ // print_page_counter fields.
$data['print_page_counter']['totalcount'] = array(
'title' => t('Web: Number of page accesses'),
'help' => t('Counter of accesses to the printer-friendly version for this node.'),
diff --git a/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.drush.inc b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.drush.inc
index 4aba243..630b6fb 100644
--- a/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.drush.inc
+++ b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.drush.inc
@@ -2,15 +2,15 @@
/**
* @file
- * drush integration for print_epub_phpepub module EPUB libraries download.
+ * Provides drush integration for print_epub_phpepub module.
*/
/**
- * The EPUB project download URL
+ * The EPUB project download URL.
*/
-// URI to the the latest PHPePub version.. Hardcoded version unfortunately
-define('PHPEPUB_DOWNLOAD_URI', 'https://github.com/Grandt/PHPePub/tarball/2.04');
+// URI to the the latest PHPePub version.
+define('PHPEPUB_DOWNLOAD_URI', 'https://api.github.com/repos/Grandt/PHPePub/releases/latest');
/**
* Implements hook_drush_command().
diff --git a/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.install b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.install
new file mode 100644
index 0000000..b953d0f
--- /dev/null
+++ b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.install
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the print_epub_phpepub module.
+ *
+ * @ingroup print
+ */
+
+/**
+ * Implements hook_requirements().
+ */
+function print_epub_phpepub_requirements($phase) {
+ $requirements = array();
+ $t = get_t();
+ switch ($phase) {
+ // At runtime, make sure that a EPUB generation tool is selected.
+ case 'runtime':
+ $print_epub_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
+
+ if (!empty($print_epub_epub_tool)) {
+ $tool = explode('|', $print_epub_epub_tool);
+
+ if (is_file($tool[1]) && is_readable($tool[1])) {
+ if (basename($tool[1]) == 'EPub.php') {
+ $version = _print_epub_phpepub_version($tool[1]);
+
+ $requirements['print_epub_tool_version'] = array(
+ 'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
+ 'value' => $t('PHPePub') . ' ' . $version,
+ );
+ }
+ }
+ }
+ break;
+ }
+ return $requirements;
+}
diff --git a/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.module b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.module
index 191ba12..2d20a2b 100644
--- a/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.module
+++ b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.module
@@ -8,37 +8,7 @@
*/
/**
- * Implements hook_requirements().
- */
-function print_epub_phpepub_requirements($phase) {
- $requirements = array();
- $t = get_t();
- switch ($phase) {
- // At runtime, make sure that a EPUB generation tool is selected
- case 'runtime':
- $print_epub_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
-
- if (!empty($print_epub_epub_tool)) {
- $tool = explode('|', $print_epub_epub_tool);
-
- if (is_file($tool[1]) && is_readable($tool[1])) {
- if (basename($tool[1]) == 'EPub.php') {
- $version = _print_epub_phpepub_version($tool[1]);
-
- $requirements['print_epub_tool_version'] = array(
- 'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
- 'value' => $t('PHPePub') . ' ' . $version,
- );
- }
- }
- }
- break;
- }
- return $requirements;
-}
-
-/**
- * Find out the version of the PHPePub library
+ * Find out the version of the PHPePub library.
*
* @param string $epub_tool
* Filename of the tool to be analysed.
@@ -47,7 +17,7 @@ function print_epub_phpepub_requirements($phase) {
* version number of the library
*/
function _print_epub_phpepub_version($epub_tool) {
- require_once(DRUPAL_ROOT . '/' . $epub_tool);
+ require_once DRUPAL_ROOT . '/' . $epub_tool;
return EPub::VERSION;
}
diff --git a/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.pages.inc b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.pages.inc
index 23d7d86..6353068 100644
--- a/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.pages.inc
+++ b/print_epub/lib_handlers/print_epub_phpepub/print_epub_phpepub.pages.inc
@@ -2,10 +2,10 @@
/**
* @file
- * Generates the EPUB version using PHPePub
+ * Generates the EPUB version using PHPePub.
*
* This file is included by the print_epub_phpepub module and includes the
- * functions that interface with the PHPePub library
+ * functions that interface with the PHPePub library.
*
* @ingroup print
*/
@@ -21,12 +21,12 @@ function print_epub_phpepub_print_epub_generate($html, $meta, $filename = NULL)
$epub_tool = explode('|', variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT));
$images_via_file = variable_get('print_epub_images_via_file', PRINT_EPUB_IMAGES_VIA_FILE_DEFAULT);
- require_once(DRUPAL_ROOT . '/' . $epub_tool[1]);
+ require_once DRUPAL_ROOT . '/' . $epub_tool[1];
- // Try to use local file access for image files
+ // Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
- // set document information
+ // Set document information.
$epub = new EPub();
$epub->setTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
@@ -40,9 +40,10 @@ function print_epub_phpepub_print_epub_generate($html, $meta, $filename = NULL)
@$epub->addChapter("Chapter", "epub.html", $html, FALSE);
- $epub->finalize(); // Finalize the book, and build the archive.
+ // Finalize the book, and build the archive.
+ $epub->finalize();
- // Close and output EPUB document
+ // Close and output EPUB document.
$epub->sendBook(empty($filename) ? 'page' : $filename);
return TRUE;
}
diff --git a/print_epub/print_epub.admin.inc b/print_epub/print_epub.admin.inc
index 08ef006..3d41aed 100644
--- a/print_epub/print_epub.admin.inc
+++ b/print_epub/print_epub.admin.inc
@@ -23,7 +23,7 @@ function print_epub_settings() {
$link = print_epub_print_link();
$current_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
- $epub_tool_default = array_key_exists($current_epub_tool, $epub_tools) ? $current_epub_tool : PRINT_EPUB_EPUB_TOOL_DEFAULT;
+ $epub_tool_default = array_key_exists($current_epub_tool, $epub_tools) ? $current_epub_tool : PRINT_EPUB_EPUB_TOOL_DEFAULT;
$form['settings'] = array(
'#type' => 'fieldset',
diff --git a/print_epub/print_epub.api.php b/print_epub/print_epub.api.php
index 437e68b..65d98fa 100644
--- a/print_epub/print_epub.api.php
+++ b/print_epub/print_epub.api.php
@@ -14,17 +14,17 @@
* Generate a EPUB version of the provided HTML.
*
* @param string $html
- * HTML content of the EPUB
+ * HTML content of the EPUB.
* @param array $meta
* Meta information to be used in the EPUB
* - url: original URL
* - name: author's name
* - title: Page title
- * - node: node object
+ * - node: node object.
* @param string $filename
- * (optional) Filename of the generated EPUB
+ * (optional) Filename of the generated EPUB.
*
- * @return
+ * @return string|null
* generated EPUB page, or NULL in case of error
*
* @see print_epub_controller_html()
@@ -80,7 +80,7 @@ function hook_print_epub_available_libs_alter(&$epub_tools) {
* '.epub' extension, as the module will do that automatically.
*
* @param string $epub_filename
- * current value of the epub_filename variable, after processing tokens and
+ * Current value of the epub_filename variable, after processing tokens and
* any transliteration steps.
* @param string $path
* original alias/system path of the page being converted to EPUB.
@@ -88,7 +88,7 @@ function hook_print_epub_available_libs_alter(&$epub_tools) {
* @ingroup print_hooks
*/
function hook_print_epub_filename_alter(&$epub_filename, &$path) {
- $epub_filename = 'foo';
+ $epub_filename = $path . '/foo';
}
/**
diff --git a/print_epub/print_epub.drush.inc b/print_epub/print_epub.drush.inc
index 583783d..33a28ec 100644
--- a/print_epub/print_epub.drush.inc
+++ b/print_epub/print_epub.drush.inc
@@ -2,7 +2,7 @@
/**
* @file
- * drush integration for print_epub module EPUB libraries download.
+ * Provides drush integration for print_epub module EPUB libraries download.
*/
/**
@@ -23,21 +23,25 @@ function print_epub_drush_command() {
'path' => dt('A path to the download folder. If omitted Drush will use the default location (@path).', array('@path' => 'sites/all/libraries')),
),
'aliases' => array('epubdl'),
- 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, // No site or config needed.
+ // No site or config needed.
+ 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
);
return $items;
}
/**
- * Implements of drush_hook_COMMAND_validate().
+ * Implements drush_hook_COMMAND_validate().
*/
function drush_print_epub_download_validate($library = NULL) {
if (is_null($library)) {
$epub_libs = array();
drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
- drush_set_error('DRUSH_EPUBDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array('!cmd' => 'print-epub-download', '!libs' => implode(', ', array_keys($epub_libs)))));
+ drush_set_error('DRUSH_EPUBDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array(
+ '!cmd' => 'print-epub-download',
+ '!libs' => implode(', ', array_keys($epub_libs)),
+ )));
}
}
@@ -45,7 +49,7 @@ function drush_print_epub_download_validate($library = NULL) {
* Download and extract EPUB archive.
*
* @param string $library
- * library to download
+ * Library to download.
*/
function drush_print_epub_download($library) {
$epub_libs = array();
diff --git a/print_epub/print_epub.install b/print_epub/print_epub.install
index d97aedf..514699e 100644
--- a/print_epub/print_epub.install
+++ b/print_epub/print_epub.install
@@ -11,9 +11,7 @@
* Implements hook_enable().
*/
function print_epub_enable() {
- $t = get_t();
-
- // Module weight
+ // Module weight.
db_update('system')
->fields(array(
'weight' => 4,
@@ -122,7 +120,7 @@ function print_epub_schema() {
}
/**
- * Remove hardcoded numeric deltas from all blocks
+ * Remove hardcoded numeric deltas from all blocks.
*/
function print_epub_update_7000(&$sandbox) {
$renamed_deltas = array(
@@ -139,7 +137,7 @@ function print_epub_update_7000(&$sandbox) {
}
/**
- * Enable block and help area links
+ * Enable block and help area links.
*/
function print_epub_update_7202(&$sandbox) {
$link_pos = variable_get('print_epub_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
@@ -149,11 +147,16 @@ function print_epub_update_7202(&$sandbox) {
}
/**
- * Increase size of the path field in the print_epub_page_counter table
+ * Increase size of the path field in the print_epub_page_counter table.
*/
function print_epub_update_7203(&$sandbox) {
db_drop_primary_key('print_epub_page_counter');
db_change_field('print_epub_page_counter', 'path', 'path',
- array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
+ array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'description' => 'Page path',
+ ),
array('primary key' => array('path')));
}
diff --git a/print_epub/print_epub.module b/print_epub/print_epub.module
index 8fc04c8..7802d39 100644
--- a/print_epub/print_epub.module
+++ b/print_epub/print_epub.module
@@ -103,11 +103,12 @@ function print_epub_block_info() {
* Implements hook_block_view().
*/
function print_epub_block_view($delta = 0) {
+ $block = array();
switch ($delta) {
case 'print_epub-top':
$block['subject'] = t('Most EPUBd');
$result = db_query_range("SELECT path FROM {print_epub_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)
- ->fetchAll();
+ ->fetchAll();
if (count($result)) {
$items = array();
foreach ($result as $obj) {
@@ -127,7 +128,7 @@ function print_epub_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
- // At runtime, make sure that a EPUB generation tool is selected
+ // At runtime, make sure that a EPUB generation tool is selected.
case 'runtime':
$print_epub_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
if (empty($print_epub_epub_tool)) {
@@ -165,7 +166,7 @@ function print_epub_node_delete($node) {
}
/**
- * Auxiliary function to display a formatted EPUB version link
+ * Auxiliary function to display a formatted EPUB version link.
*
* Function made available so that developers may call this function from
* their defined pages/blocks.
@@ -176,7 +177,7 @@ function print_epub_node_delete($node) {
* node object, to be used in checking node access. If the path argument is
* not provided, the path used will be node/nid.
* @param string $location
- * where in the page where the link is being inserted ('link', 'corner',
+ * Where in the page where the link is being inserted ('link', 'corner',
* 'block', 'help').
*
* @return bool
@@ -186,7 +187,11 @@ function print_epub_node_delete($node) {
*/
function print_epub_insert_link($path = NULL, $node = NULL, $location = '') {
if (function_exists('print_ui_insert_link')) {
- return print_ui_insert_link(print_epub_print_link(), array('path' => $path, 'node' => $node, 'location' => $location));
+ return print_ui_insert_link(print_epub_print_link(), array(
+ 'path' => $path,
+ 'node' => $node,
+ 'location' => $location,
+ ));
}
else {
return FALSE;
@@ -194,11 +199,11 @@ function print_epub_insert_link($path = NULL, $node = NULL, $location = '') {
}
/**
- * Check if the link to the EPUB version is allowed depending on the settings
+ * Check if the link to the EPUB version is allowed depending on the settings.
*
* @param array $args
- * array containing the possible parameters:
- * view_mode, node, type, path
+ * Array containing the possible parameters:
+ * view_mode, node, type, path.
*
* @return bool
* FALSE if not allowed, TRUE otherwise
@@ -213,17 +218,17 @@ function print_epub_link_allowed($args) {
* Generate a EPUB version of the provided HTML.
*
* @param string $html
- * HTML content of the EPUB
+ * HTML content of the EPUB.
* @param array $meta
* Meta information to be used in the EPUB
* - url: original URL
* - name: author's name
* - title: Page title
- * - node: node object
+ * - node: node object.
* @param string $filename
- * (optional) Filename of the generated EPUB
+ * (optional) Filename of the generated EPUB.
*
- * @return
+ * @return string|null
* generated EPUB page, or NULL in case of error
*
* @see print_epub_controller()
diff --git a/print_epub/print_epub.pages.inc b/print_epub/print_epub.pages.inc
index fa46a9d..1e9e837 100644
--- a/print_epub/print_epub.pages.inc
+++ b/print_epub/print_epub.pages.inc
@@ -2,7 +2,7 @@
/**
* @file
- * Generates the EPUB versions of the pages
+ * Generates the EPUB versions of the pages.
*
* This file is included by the print_epub module and includes the
* functions that interface with the EPUB generation packages.
@@ -13,32 +13,34 @@
module_load_include('inc', 'print', 'print.pages');
/**
- * Generate a EPUB version of the printer-friendly page
+ * Generate a EPUB version of the printer-friendly page.
*
* @see print_controller()
* @see _print_epub_domepub()
* @see _print_epub_tcepub()
*/
function print_epub_controller() {
- // Disable caching for generated EPUBs, as Drupal doesn't ouput the proper headers from the cache
+ // Disable caching for generated EPUBs, 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;
+ $cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
- // Handle the query
+ // Handle the query.
$query = $_GET;
unset($query['q']);
+ $node = NULL;
if (!empty($path)) {
if ($alias = drupal_lookup_path('source', $path)) {
- // Alias
+ // Alias.
$path_arr = explode('/', $alias);
$node = node_load($path_arr[1]);
}
elseif (ctype_digit($args[0])) {
- // normal nid
+ // Normal nid.
$node = node_load($args[0]);
}
@@ -49,7 +51,7 @@ function print_epub_controller() {
else {
$epub_filename = token_replace($epub_filename, array('site'), array('clear' => TRUE));
if (empty($epub_filename)) {
- // If empty, use a fallback solution
+ // If empty, use a fallback solution.
$epub_filename = str_replace('/', '_', $path);
}
}
@@ -74,8 +76,8 @@ function print_epub_controller() {
db_merge('print_epub_page_counter')
->key(array('path' => $nodepath))
->fields(array(
- 'totalcount' => 1,
- 'timestamp' => REQUEST_TIME,
+ 'totalcount' => 1,
+ 'timestamp' => REQUEST_TIME,
))
->expression('totalcount', 'totalcount + 1')
->execute();
@@ -87,36 +89,43 @@ function print_epub_controller() {
* Gennerate a EPUB for a given Drupal path.
*
* @param string $path
- * path of the page to convert to EPUB
+ * path of the page to convert to EPUB.
* @param array $query
- * (optional) array of key/value pairs as used in the url() function for the
- * query
+ * (Optional) array of key/value pairs as used in the url() function for the
+ * query.
* @param int $cid
- * (optional) comment ID of the comment to render.
+ * (Optional) comment ID of the comment to render.
* @param string $epub_filename
- * (optional) filename of the generated EPUB
+ * (Optional) filename of the generated EPUB.
* @param string $view_mode
- * (optional) view mode to be used when rendering the content
+ * (Optional) view mode to be used when rendering the content.
*
- * @return
+ * @return string|null
* generated EPUB page, or NULL in case of error
*
* @see print_epub_controller()
*/
function print_epub_generate_path($path, $query = NULL, $cid = NULL, $epub_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
- global $base_url;
-
$link = print_epub_print_link();
$node = print_controller($path, $link['format'], $cid, $view_mode);
if ($node) {
- $html = theme('print', array('node' => $node, 'query' => $query, 'expand_css' => TRUE, 'format' => $link['format']));
+ $html = theme('print', array(
+ 'node' => $node,
+ 'query' => $query,
+ 'expand_css' => TRUE,
+ 'format' => $link['format'],
+ ));
$meta = array(
'node' => $node,
'url' => url(drupal_get_path_alias(empty($node->nid) ? $node->path : "node/$node->nid"), array('absolute' => TRUE)),
);
- if (isset($node->name)) $meta['name'] = $node->name;
- if (isset($node->title)) $meta['title'] = $node->title;
+ if (isset($node->name)) {
+ $meta['name'] = $node->name;
+ }
+ if (isset($node->title)) {
+ $meta['title'] = $node->title;
+ }
return print_epub_generate_html($html, $meta, $epub_filename);
}
diff --git a/print_epub/print_epub.views.inc b/print_epub/print_epub.views.inc
index 30b9cd7..0a9d75a 100644
--- a/print_epub/print_epub.views.inc
+++ b/print_epub/print_epub.views.inc
@@ -2,7 +2,7 @@
/**
* @file
- * EPUB Version Views integration
+ * EPUB Version Views integration.
*
* @ingroup print
*/
@@ -25,18 +25,16 @@ function print_epub_views_data() {
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
-// 'type' => 'INNER',
);
$data['print_epub_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_epub_node_conf fields
+ // print_epub_node_conf fields.
$data['print_epub_node_conf']['link'] = array(
'title' => t('EPUB: Show link'),
'help' => t('Whether to show the EPUB version link.'),
@@ -86,8 +84,7 @@ function print_epub_views_data() {
),
);
-
- // print_epub_page_counter fields
+ // print_epub_page_counter fields.
$data['print_epub_page_counter']['totalcount'] = array(
'title' => t('EPUB: Number of page accesses'),
'help' => t('Counter of accesses to the EPUB version for this node.'),
diff --git a/print_join_page_counter.inc b/print_join_page_counter.inc
index fe73f00..c97e385 100644
--- a/print_join_page_counter.inc
+++ b/print_join_page_counter.inc
@@ -2,24 +2,35 @@
/**
* @file
- * Custom Views integration join for the page counters
+ * Custom Views integration join for the page counters.
*
* @ingroup print
*/
+/**
+ * Class print_join_page_counter.
+ */
class print_join_page_counter extends views_join {
- // PHP 4 doesn't call constructors of the base class automatically from a
- // constructor of a derived class. It is your responsibility to propagate
- // the call to constructors upstream where appropriate.
- function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
+
+ /**
+ * @inheritdoc
+ */
+ public function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
+ // PHP 4 doesn't call constructors of the base class automatically from a
+ // constructor of a derived class. It is your responsibility to propagate
+ // the call to constructors upstream where appropriate.
parent::construct($table, $left_table, $left_field, $field, $extra, $type);
}
- function build_join($select_query, $table, $view_query) {
+ /**
+ * @inheritdoc
+ */
+ public function build_join($select_query, $table, $view_query) {
if ($this->left_table) {
$this->left_field = "CONCAT('node/', $this->left_table.$this->left_field)";
$this->left_table = NULL;
}
parent::build_join($select_query, $table, $view_query);
}
+
}
diff --git a/print_mail/print_mail.admin.inc b/print_mail/print_mail.admin.inc
index 5dc3c13..283f1fc 100644
--- a/print_mail/print_mail.admin.inc
+++ b/print_mail/print_mail.admin.inc
@@ -10,8 +10,8 @@
* @ingroup print
*/
-// Include MIME library
-@include_once('Mail/mime.php');
+// Include MIME library, if available.
+@include_once 'Mail/mime.php';
/**
* Form constructor for the send by email module settings form.
@@ -30,7 +30,9 @@ function print_mail_settings() {
'#type' => 'select',
'#title' => t('Hourly threshold'),
'#default_value' => variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD),
- '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)),
+ '#options' => drupal_map_assoc(
+ array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)
+ ),
'#description' => t('The maximum number of emails a user can send per hour.'),
);
diff --git a/print_mail/print_mail.inc b/print_mail/print_mail.inc
index b673346..98caad4 100644
--- a/print_mail/print_mail.inc
+++ b/print_mail/print_mail.inc
@@ -10,8 +10,8 @@
* @ingroup print
*/
-// Include MIME library
-@include_once('Mail/mime.php');
+// Include MIME library, if available.
+@include_once 'Mail/mime.php';
/**
* Form constructor for the send by email form.
@@ -19,12 +19,12 @@
* @ingroup forms
*/
function print_mail_form($form, &$form_state) {
- // Remove the printmail/ prefix
+ // Remove the printmail/ prefix.
$path_arr = explode('/', $_GET['q']);
unset($path_arr[0]);
$path = filter_xss(implode('/', $path_arr));
if (empty($path)) {
- // If no path was provided, let's try to generate a page for the referer
+ // If no path was provided, let's try to generate a page for the referer.
global $base_url;
$link = print_mail_print_link();
@@ -37,11 +37,11 @@ function print_mail_form($form, &$form_state) {
}
elseif (ctype_digit($path_arr[1])) {
if (drupal_lookup_path('source', $path)) {
- // This is a numeric alias
+ // This is a numeric alias.
$path = drupal_get_normal_path($path);
}
else {
- // normal nid
+ // Normal nid.
$path = 'node/' . $path;
}
}
@@ -49,7 +49,7 @@ function print_mail_form($form, &$form_state) {
$path = drupal_get_normal_path($path);
}
- // Handle the query
+ // Handle the query.
$query = $_GET;
unset($query['q']);
@@ -59,6 +59,20 @@ function print_mail_form($form, &$form_state) {
/**
* Build email form for the page provided in the path argument.
*
+ * @param array $form
+ * Form.
+ * @param array $form_state
+ * Form state.
+ * @param string $path
+ * Path.
+ * @param array $query
+ * Query.
+ * @param Object $user
+ * Current user.
+ *
+ * @return array
+ * Modified form.
+ *
* @ingroup forms
*/
function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $user = NULL) {
@@ -81,11 +95,11 @@ function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $us
$print_mail_user_recipients_default = variable_get('print_mail_user_recipients', PRINT_MAIL_USER_RECIPIENTS_DEFAULT);
$form = array();
- $cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
+ $cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
$title = _print_get_title($path);
+ $options = array();
if ($print_mail_user_recipients_default) {
- $options = array();
if (module_exists('realname')) {
$sql = "SELECT u.mail, r.realname AS name from {users} u LEFT JOIN {realname} r ON u.uid = r.uid WHERE u.uid <> :uid ORDER BY name ASC";
}
@@ -103,8 +117,8 @@ function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $us
db_merge('print_mail_page_counter')
->key(array('path' => $nodepath))
->fields(array(
- 'totalcount' => 1,
- 'timestamp' => REQUEST_TIME,
+ 'totalcount' => 1,
+ 'timestamp' => REQUEST_TIME,
))
->expression('totalcount', 'totalcount + 1')
->execute();
@@ -112,7 +126,7 @@ function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $us
$form['path'] = array('#type' => 'value', '#value' => $path);
$form['query'] = array('#type' => 'value', '#value' => $query);
- $form['cid'] = array('#type' => 'value', '#value' => $cid);
+ $form['cid'] = array('#type' => 'value', '#value' => $cid);
$form['title'] = array('#type' => 'value', '#value' => $title);
$form['fld_from_addr'] = array(
@@ -153,7 +167,7 @@ function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $us
'#required' => TRUE,
);
if (!empty($title)) {
- // To prevent useless translation strings, try to translate only non-node titles
+ // To prevent useless translation strings, translate only non-node titles.
if (drupal_substr($path, 0, 5) != 'node/') {
$title = t($title);
}
@@ -204,8 +218,12 @@ function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $us
$user_name = t('Someone');
}
$site_name = variable_get('site_name', t('an interesting site'));
- $form['fld_subject']['#default_value'] = t('!user has sent you a message from !site', array('!user' => $user_name, '!site' => $site_name, '!title' => $title));
- $form['txt_message']['#default_value'] = t('');
+ $form['fld_subject']['#default_value'] = t('!user has sent you a message from !site', array(
+ '!user' => $user_name,
+ '!site' => $site_name,
+ '!title' => $title,
+ ));
+ $form['txt_message']['#default_value'] = '';
return $form;
}
@@ -216,8 +234,11 @@ function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $us
* Adds a class to the form labels. This class is used to place the label on
* the left of the input fields.
*
- * @param array $form
- * Form array
+ * @param array $variables
+ * Theme variables including the form.
+ *
+ * @return string
+ * Send by-email form HTML.
*
* @see print_mail_form()
* @ingroup forms
@@ -250,8 +271,11 @@ function theme_print_mail_form($variables) {
*
* Allows themes and modules to override the default sendlink plain text format.
*
- * @param $params
- * $params as passed to print_mail_mail().
+ * @param array $params
+ * Value of $params as passed to print_mail_mail().
+ *
+ * @return string
+ * Plain text containing the message and a simple link to the content.
*
* @ingroup themeable
* @ingroup print_themeable
@@ -265,8 +289,11 @@ function theme_print_mail_sendlink_plain($params) {
*
* Allows themes and modules to override the default sendlink HTML format.
*
- * @param $params
- * $params as passed to print_mail_mail().
+ * @param array $params
+ * Value of $params as passed to print_mail_mail().
+ *
+ * @return string
+ * HTML text containing the message and a simple link to the content.
*
* @ingroup themeable
* @ingroup print_themeable
@@ -303,9 +330,9 @@ function print_mail_form_validate($form, &$form_state) {
}
if (!empty($form_state['values']['txt_to']['addrs'])) {
- // All new-lines are replaced by commas
+ // All new-lines are replaced by commas.
$to_addrs = preg_replace('![\r|\n|,]+!', ',', trim($form_state['values']['txt_to']['addrs']));
- // Create an array from the string
+ // Create an array from the string.
$to_array = array_merge($to_array, explode(',', $to_addrs));
}
@@ -313,16 +340,16 @@ function print_mail_form_validate($form, &$form_state) {
form_set_error('txt_to', t('You must specify at least one email address or user as a recipient.'));
}
- // Verify each element of the array
+ // Verify each element of the array.
foreach ($to_array as $key => $address) {
$address = trim($address);
if (preg_match('/(.*?) <(.*)>/s', $address, $matches)) {
- // Address is of the type User Name <user@domain.tld>
+ // Address is of the type User Name <user@domain.tld>.
$test = user_validate_mail($matches[2]);
$to_array[$key] = trim($matches[1]) . ' <' . $matches[2] . '>';
}
else {
- // Address must be user@domain.tld
+ // Address must be user@domain.tld.
$test = user_validate_mail($address);
}
if ($test) {
@@ -333,19 +360,19 @@ function print_mail_form_validate($form, &$form_state) {
$print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD);
if ((!user_access('send unlimited emails')) && (!flood_is_allowed('print_mail', $print_mail_hourly_threshold - count($to_array) + 1))) {
- form_set_error('txt_to', t('You cannot send more than %number messages per hour. Please reduce the number of recipients.', array('%number' => $print_mail_hourly_threshold)));
+ form_set_error('txt_to', t('You cannot send more than %number messages per hour. Please reduce the number of recipients.', array('%number' => $print_mail_hourly_threshold)));
}
- // In all fields, prevent insertion of custom headers
+ // In all fields, prevent insertion of custom headers.
foreach ($form_state['values'] as $key => $string) {
- if ( (drupal_substr($key, 0, 4) == 'fld_') && ((strpos($string, "\n") !== FALSE) || (strpos($string, "\r") !== FALSE)) ) {
+ if ((drupal_substr($key, 0, 4) == 'fld_') && ((strpos($string, "\n") !== FALSE) || (strpos($string, "\r") !== FALSE))) {
form_set_error($key, 'Found invalid character');
}
}
$form_state['values']['fld_from_addr'] = $from_addr;
$form_state['values']['fld_from_name'] = trim($form_state['values']['fld_from_name']);
- // Re-create the string from the re-organized array
+ // Re-create the string from the re-organized array.
$form_state['values']['txt_to']['addrs'] = implode(', ', $to_array);
}
@@ -375,7 +402,7 @@ function print_mail_form_submit($form, &$form_state) {
$params['link'] = url($form_state['values']['path'], array('absolute' => TRUE, 'query' => $form_state['values']['query']));
$params['title'] = $form_state['values']['title'];
- // If a name is provided, make From: in the format Common Name <address>
+ // If a name is provided, make From: in the format Common Name <address>.
if (!empty($form_state['values']['fld_from_name'])) {
$from = '"' . mime_header_encode($form_state['values']['fld_from_name']) . '" <' . $form_state['values']['fld_from_addr'] . '>';
}
@@ -383,43 +410,60 @@ function print_mail_form_submit($form, &$form_state) {
$from = $form_state['values']['fld_from_addr'];
}
- // If using reply-to, move the From: info to the params array, so that it is passed to hook_mail later
+ // If using reply-to, move the From: info to the params array, so that it
+ // is passed to hook_mail later.
if (variable_get('print_mail_use_reply_to', PRINT_MAIL_USE_REPLY_TO)) {
$params['from'] = $from;
$from = NULL;
}
- // Spaces in img URLs must be replaced with %20
+ // Spaces in img URLs must be replaced with %20.
$pattern = '!<(img\s[^>]*?)>!is';
$node->content = preg_replace_callback($pattern, '_print_replace_spaces', $node->content);
- $params['body'] = theme('print', array('node' => $node, 'query' => $form_state['values']['query'], 'format' => $link['format'], 'expand_css' => TRUE, 'message' => $params['message']));
+ $params['body'] = theme('print', array(
+ 'node' => $node,
+ 'query' => $form_state['values']['query'],
+ 'format' => $link['format'],
+ 'expand_css' => TRUE,
+ 'message' => $params['message'],
+ ));
- // Img elements must be set to absolute
+ // Img elements must be set to absolute.
$pattern = '!<(img\s[^>]*?)>!is';
$params['body'] = preg_replace_callback($pattern, '_print_rewrite_urls', $params['body']);
- // Convert the a href elements, to make sure no relative links remain
+ // Convert the a href elements, to make sure no relative links remain.
$pattern = '!<(a\s[^>]*?)>!is';
$params['body'] = preg_replace_callback($pattern, '_print_rewrite_urls', $params['body']);
- // Enable support for third-party modules to alter the e-mail before it's sent
+ // Enable support for third-party modules to alter the e-mail before
+ // being sent.
drupal_alter('print_mail', $params, $to);
$ok = FALSE;
$use_job_queue = variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT);
+ $queue = NULL;
if ($use_job_queue) {
$queue = DrupalQueue::get('print_mail_send');
}
$addresses = explode(', ', $form_state['values']['txt_to']['addrs']);
foreach ($addresses as $to) {
+ $ret = array();
if ($use_job_queue) {
- // Use job queue to send mails during cron runs
- $queue->createItem(array('module' => 'print_mail', 'key' => $print_mail_send_option_default, 'to' => $to, 'language' => language_default(), 'params' => $params, 'from' => $from));
+ // Use job queue to send mails during cron runs.
+ $queue->createItem(array(
+ 'module' => 'print_mail',
+ 'key' => $print_mail_send_option_default,
+ 'to' => $to,
+ 'language' => language_default(),
+ 'params' => $params,
+ 'from' => $from,
+ ));
}
else {
- // Send mail immediately using Drupal's mail handler
+ // Send mail immediately using Drupal's mail handler.
$ret = drupal_mail('print_mail', $print_mail_send_option_default, $to, language_default(), $params, $from);
}
if ($use_job_queue || $ret['result']) {
@@ -429,15 +473,20 @@ function print_mail_form_submit($form, &$form_state) {
}
if ($ok) {
$query = empty($form_state['values']['query']) ? '' : '?' . rawurldecode(drupal_http_build_query($form_state['values']['query']));
- watchdog('print_mail', '%name [%from] sent %page to [%to]', array('%name' => $form_state['values']['fld_from_name'], '%from' => $form_state['values']['fld_from_addr'], '%page' => $form_state['values']['path'] . $query, '%to' => $form_state['values']['txt_to']['addrs']));
+ watchdog('print_mail', '%name [%from] sent %page to [%to]', array(
+ '%name' => $form_state['values']['fld_from_name'],
+ '%from' => $form_state['values']['fld_from_addr'],
+ '%page' => $form_state['values']['path'] . $query,
+ '%to' => $form_state['values']['txt_to']['addrs'],
+ ));
$site_name = variable_get('site_name', t('us'));
drupal_set_message(check_plain(t('Thank you for spreading the word about !site.', array('!site' => $site_name))));
$nodepath = drupal_get_normal_path($form_state['values']['path']);
db_update('print_mail_page_counter')
->fields(array(
- 'sentcount' => 1,
- 'sent_timestamp' => REQUEST_TIME,
+ 'sentcount' => 1,
+ 'sent_timestamp' => REQUEST_TIME,
))
->condition('path', $nodepath, '=')
->expression('sentcount', 'sentcount + :inc', array(':inc' => count($addresses)))
@@ -446,5 +495,9 @@ function print_mail_form_submit($form, &$form_state) {
}
}
- $form_state['redirect'] = array(preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']), array('query' => $form_state['values']['query']));
+ $form_state['redirect'] = array(
+ preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']), array(
+ 'query' => $form_state['values']['query'],
+ ),
+ );
}
diff --git a/print_mail/print_mail.install b/print_mail/print_mail.install
index fd44e02..f9e7cf4 100644
--- a/print_mail/print_mail.install
+++ b/print_mail/print_mail.install
@@ -11,9 +11,7 @@
* Implements hook_enable().
*/
function print_mail_enable() {
- $t = get_t();
-
- // Module weight
+ // Module weight.
db_update('system')
->fields(array(
'weight' => 1,
@@ -28,6 +26,31 @@ function print_mail_enable() {
}
/**
+ * Implements hook_requirements().
+ */
+function print_mail_requirements($phase) {
+ $requirements = array();
+ $t = get_t();
+ switch ($phase) {
+ // At runtime, make sure that a PDF generation tool is selected.
+ case 'runtime':
+ if (module_exists('mailsystem')) {
+ $mail_system = mailsystem_get();
+ if (($mail_system['default-system'] != 'DefaultMailSystem') && (!isset($mail_system['print_mail']) || ($mail_system['print_mail'] != 'DefaultMailSystem'))) {
+ $requirements['print_mail_mailsystem'] = array(
+ 'title' => $t('Printer, email and PDF versions - Send by email'),
+ 'value' => $t('Incompatible Mail System setting detected'),
+ 'description' => $t('The send by email module requires the use of the DefaultMailSystem, please configure it in the !url.', array('!url' => l($t('Mail System Settings page'), 'admin/config/system/mailsystem'))),
+ 'severity' => REQUIREMENT_WARNING,
+ );
+ }
+ }
+ }
+
+ return $requirements;
+}
+
+/**
* Implements hook_disable().
*/
function print_mail_disable() {
@@ -154,7 +177,7 @@ function print_mail_schema() {
}
/**
- * Remove hardcoded numeric deltas from all blocks
+ * Remove hardcoded numeric deltas from all blocks.
*/
function print_mail_update_7000(&$sandbox) {
$renamed_deltas = array(
@@ -167,7 +190,7 @@ function print_mail_update_7000(&$sandbox) {
}
/**
- * Disable MimeMailSystem for now
+ * Disable MimeMailSystem for now.
*/
function print_mail_update_7100(&$sandbox) {
if (module_exists('mailsystem')) {
@@ -176,7 +199,7 @@ function print_mail_update_7100(&$sandbox) {
}
/**
- * Update permissions to new spellings
+ * Update permissions to new spellings.
*/
function print_mail_update_7101(&$sandbox) {
db_update('role_permission')
@@ -190,7 +213,7 @@ function print_mail_update_7101(&$sandbox) {
}
/**
- * Delete old variables
+ * Delete old variables.
*/
function print_mail_update_7200(&$sandbox) {
variable_del('print_mail_settings');
@@ -206,7 +229,7 @@ function print_mail_update_7200(&$sandbox) {
}
/**
- * Enable block and help area links
+ * Enable block and help area links.
*/
function print_mail_update_7202(&$sandbox) {
$link_pos = variable_get('print_mail_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
@@ -216,11 +239,16 @@ function print_mail_update_7202(&$sandbox) {
}
/**
- * Increase size of the path field in the print_mail_page_counter table
+ * Increase size of the path field in the print_mail_page_counter table.
*/
function print_mail_update_7203(&$sandbox) {
db_drop_primary_key('print_mail_page_counter');
db_change_field('print_mail_page_counter', 'path', 'path',
- array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
+ array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'description' => 'Page path',
+ ),
array('primary key' => array('path')));
}
diff --git a/print_mail/print_mail.module b/print_mail/print_mail.module
index 4520f24..6041d5d 100644
--- a/print_mail/print_mail.module
+++ b/print_mail/print_mail.module
@@ -116,31 +116,6 @@ function print_mail_variable_info($options) {
}
/**
- * Implements hook_requirements().
- */
-function print_mail_requirements($phase) {
- $requirements = array();
- $t = get_t();
- switch ($phase) {
- // At runtime, make sure that a PDF generation tool is selected
- case 'runtime':
- if (module_exists('mailsystem')) {
- $mail_system = mailsystem_get();
- if (($mail_system['default-system'] != 'DefaultMailSystem') && (!isset($mail_system['print_mail']) || ($mail_system['print_mail'] != 'DefaultMailSystem'))) {
- $requirements['print_mail_mailsystem'] = array(
- 'title' => $t('Printer, email and PDF versions - Send by email'),
- 'value' => $t('Incompatible Mail System setting detected'),
- 'description' => $t('The send by email module requires the use of the DefaultMailSystem, please configure it in the !url.', array('!url' => l($t('Mail System Settings page'), 'admin/config/system/mailsystem'))),
- 'severity' => REQUIREMENT_WARNING,
- );
- }
- }
- }
-
- return $requirements;
-}
-
-/**
* Implements hook_block_info().
*/
function print_mail_block_info() {
@@ -153,11 +128,12 @@ function print_mail_block_info() {
* Implements hook_block_view().
*/
function print_mail_block_view($delta = 0) {
+ $block = array();
switch ($delta) {
case 'print_mail-top':
$block['subject'] = t('Most emailed');
$result = db_query_range("SELECT path FROM {print_mail_page_counter} LEFT JOIN {node} n ON path = CONCAT('node/', n.nid) WHERE status <> 0 OR status IS NULL ORDER BY sentcount DESC", 0, 3)
- ->fetchAll();
+ ->fetchAll();
if (count($result)) {
$items = array();
foreach ($result as $obj) {
@@ -217,62 +193,66 @@ function print_mail_mail($key, &$message, $params) {
$message['headers']['Reply-To'] = $params['from'];
}
+ $sendlink_plain = '';
+ $sendlink_html = '';
switch ($key) {
case 'sendpage':
$message['body'][] = check_plain($params['body']);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
+
case 'sendlink':
- // Generate plain-text and html versions of message with link
+ // Generate plain-text and html versions of message with link.
$sendlink_plain = theme('print_mail_sendlink_plain', $params);
$sendlink_html = theme('print_mail_sendlink_html', $params);
- // Send HTML-only version if MIME library not present
+ // Send HTML-only version if MIME library not present.
if (!class_exists('Mail_mime')) {
$message['body'][] = check_plain($sendlink_html);
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
break;
}
- // no break on purpose
+ // No break on purpose.
case 'plain-attachment':
case 'inline-attachment':
- // Configure new MIME object
+ // Configure new MIME object.
$mime = new Mail_mime("\n");
$mime_params['html_encoding'] = '7bit';
$mime_params['html_charset'] = 'utf-8';
$mime_params['text_charset'] = 'utf-8';
- // Pass message contents into MIME object
+ // Pass message contents into MIME object.
switch ($key) {
case 'sendlink':
$mime->setTxtBody($sendlink_plain);
$mime->setHTMLBody($sendlink_html);
break;
+
case 'inline-attachment':
$mime->setHTMLBody($params['body']);
- // no break on purpose
+ // No break on purpose.
case 'plain-attachment':
$mime->setTxtBody($params['message']);
$mime->addAttachment($params['body'], 'text/html', 'Attachment.html', FALSE);
break;
}
- // Store MIME message output in message array
+ // Store MIME message output in message array.
$message['body'][] = check_plain($mime->get($mime_params));
$message['headers'] = $mime->headers($message['headers']);
- // Strip special characters from Content-Type header
- // Required to prevent mime_header_encode() from disrupting Content-Type header
+ // Strip special characters from Content-Type header. Required to prevent
+ // mime_header_encode() from disrupting Content-Type header.
$message['headers']['Content-Type'] = preg_replace('/[^\x20-\x7E]/', '', $message['headers']['Content-Type']);
break;
}
}
/**
- * Access callback to check a combination of user_acess() and page access
+ * Access callback to check a combination of user_acess() and page access.
*
* @param string $permission
- * permission required to view the page
+ * Permission required to view the page.
*
* @return bool
* TRUE if the user has permission to view the page, FALSE otherwise
@@ -287,18 +267,18 @@ function _print_mail_access($permission) {
$path = implode('/', $parts);
if (ctype_digit($parts[1])) {
if (drupal_lookup_path('source', $path)) {
- // This is a numeric alias
+ // This is a numeric alias.
$path = drupal_get_normal_path($path);
}
else {
- // normal nid
+ // Normal nid.
$path = 'node/' . $path;
}
}
else {
$path = drupal_get_normal_path($path);
}
- // If the destination page is not accessible, don't show the form
+ // If the destination page is not accessible, don't show the form.
if (!($router_item = menu_get_item($path)) || (!$router_item['access'])) {
$page_access = FALSE;
}
@@ -309,7 +289,7 @@ function _print_mail_access($permission) {
}
/**
- * Auxiliary function to display a formatted send by email link
+ * Auxiliary function to display a formatted send by email link.
*
* Function made available so that developers may call this function from
* their defined pages/blocks.
@@ -320,7 +300,7 @@ function _print_mail_access($permission) {
* node object, to be used in checking node access. If the path argument is
* not provided, the path used will be node/nid.
* @param string $location
- * where in the page where the link is being inserted ('link', 'corner',
+ * Where in the page where the link is being inserted ('link', 'corner',
* 'block', 'help').
*
* @return string
@@ -330,7 +310,8 @@ function _print_mail_access($permission) {
*/
function print_mail_insert_link($path = NULL, $node = NULL, $location = '') {
if (function_exists('print_ui_insert_link')) {
- return print_ui_insert_link(print_mail_print_link(), array('path' => $path, 'node' => $node, 'location' => $location));
+ return print_ui_insert_link(print_mail_print_link(),
+ array('path' => $path, 'node' => $node, 'location' => $location));
}
else {
return FALSE;
@@ -338,14 +319,14 @@ function print_mail_insert_link($path = NULL, $node = NULL, $location = '') {
}
/**
- * Check if the link to send by email is allowed depending on the settings
+ * Check if the link to send by email is allowed depending on the settings.
*
* @param array $args
- * array containing the possible parameters:
- * view_mode, node, type, path
+ * Array containing the possible parameters:
+ * view_mode, node, type, path.
*
* @return bool
- * FALSE if not allowed, TRUE otherwise
+ * FALSE if not allowed, TRUE otherwise.
*/
function print_mail_link_allowed($args) {
return (user_access('access send by email'));
@@ -366,6 +347,7 @@ function print_mail_mollom_form_list() {
* Implemenents hook_mollom_form_info().
*/
function print_mail_mollom_form_info($form_id) {
+ $form_info = array();
switch ($form_id) {
case 'print_mail_form':
$form_info = array(
@@ -426,7 +408,7 @@ function print_mail_rules_action_info() {
}
/**
- * Action handler for the print_mail_action_submit
+ * Action handler for the print_mail_action_submit.
*
* @ingroup rules
*/
diff --git a/print_mail/print_mail.views.inc b/print_mail/print_mail.views.inc
index cca366a..dcb08da 100644
--- a/print_mail/print_mail.views.inc
+++ b/print_mail/print_mail.views.inc
@@ -2,7 +2,7 @@
/**
* @file
- * Send by email Views integration
+ * Send by email Views integration.
*
* @ingroup print
*/
@@ -25,18 +25,16 @@ function print_mail_views_data() {
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
-// 'type' => 'INNER',
);
$data['print_mail_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_mail_node_conf fields
+ // print_mail_node_conf fields.
$data['print_mail_node_conf']['link'] = array(
'title' => t('Email: Show link'),
'help' => t('Whether to show the send by email link.'),
@@ -86,8 +84,7 @@ function print_mail_views_data() {
),
);
-
- // print_mail_page_counter fields
+ // print_mail_page_counter fields.
$data['print_mail_page_counter']['totalcount'] = array(
'title' => t('Email: Number of page accesses'),
'help' => t('Counter of accesses to the send by email form for this node.'),
diff --git a/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.drush.inc b/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.drush.inc
index 56678ad..9c6e091 100644
--- a/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.drush.inc
+++ b/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.drush.inc
@@ -2,15 +2,14 @@
/**
* @file
- * drush integration for print_pdf_dompdf module PDF libraries download.
+ * Provide drush integration for print_pdf_dompdf module PDF libraries download.
*/
/**
- * The PDF project download URL
+ * The PDF project download URL.
*/
-
-// 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');
+// URI to the the latest dompdf version.
+define('DOMPDF_DOWNLOAD_URI', 'https://api.github.com/repos/dompdf/dompdf/releases/latest');
/**
* Implements hook_drush_command().
diff --git a/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.module b/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.module
index 1196412..e4c0db5 100644
--- a/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.module
+++ b/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.module
@@ -16,7 +16,7 @@ define('PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT', FALSE);
function print_pdf_dompdf_pdf_tool_info() {
return array(
'name' => 'dompdf',
- 'url' => 'http://code.google.com/p/dompdf/downloads/list',
+ 'url' => 'https://github.com/dompdf/dompdf/releases/latest',
'expand_css' => FALSE,
'public_dirs' => array(
'fonts',
@@ -59,9 +59,9 @@ function print_pdf_dompdf_menu() {
* Implements hook_pdf_tool_version().
*/
function print_pdf_dompdf_pdf_tool_version($pdf_tool) {
- require_once(DRUPAL_ROOT . '/' . $pdf_tool);
+ require_once DRUPAL_ROOT . '/' . $pdf_tool;
- // Poor man's way to find dompdf version
+ // Poor man's way to find dompdf version.
if (!defined('DOMPDF_DIR')) {
return 'unknown';
}
diff --git a/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.pages.inc b/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.pages.inc
index 0061a0e..098e3d1 100644
--- a/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.pages.inc
+++ b/print_pdf/lib_handlers/print_pdf_dompdf/print_pdf_dompdf.pages.inc
@@ -2,10 +2,10 @@
/**
* @file
- * Generates the PDF version using dompdf
+ * Generates the PDF version using dompdf.
*
* This file is included by the print_pdf_dompdf module and includes the
- * functions that interface with the dompdf library
+ * functions that interface with the dompdf library.
*
* @ingroup print
*/
@@ -23,7 +23,6 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
- $content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
$unicode = TRUE;
@@ -31,27 +30,39 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
$unicode = variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT);
$font_subsetting = variable_get('print_pdf_dompdf_font_subsetting', PRINT_PDF_DOMPDF_FONT_SUBSETTING_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', $unicode);
- if (!defined('DOMPDF_ENABLE_FONTSUBSETTING')) define('DOMPDF_ENABLE_FONTSUBSETTING', $font_subsetting);
- if (!defined('DOMPDF_FONT_CACHE')) define('DOMPDF_FONT_CACHE', drupal_realpath('public://print_pdf/print_pdf_dompdf/fonts/'));
+ 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', $unicode);
+ }
+ if (!defined('DOMPDF_ENABLE_FONTSUBSETTING')) {
+ define('DOMPDF_ENABLE_FONTSUBSETTING', $font_subsetting);
+ }
+ if (!defined('DOMPDF_FONT_CACHE')) {
+ define('DOMPDF_FONT_CACHE', drupal_realpath('public://print_pdf/print_pdf_dompdf/fonts/'));
+ }
}
- require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
+ require_once DRUPAL_ROOT . '/' . $pdf_tool[1];
spl_autoload_register('DOMPDF_autoload');
- // Try to use local file access for image files
+ // Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
- // Spaces in img URLs must be replaced with %20, when using external access
+ // Spaces in img URLs must be replaced with %20, when using external access.
if (!$images_via_file) {
$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
+ // It seems dompdf has problems with something in system.css, don't use it.
$html = preg_replace('!<link.*?modules/system/system.css.*?/>!', '', $html);
$url_array = parse_url($meta['url']);
@@ -66,22 +77,26 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
$dompdf->set_paper(drupal_strtolower($paper_size), $page_orientation);
$dompdf->set_protocol($protocol);
-// dompdf can't handle footers cleanly, so disable the following
-// $html = theme('print_pdf_dompdf_footer', array('html' => $html));
+ // It seems dompdf can't handle footers cleanly, so disable the following.
+ /* $html = theme('print_pdf_dompdf_footer', array('html' => $html)); */
- // If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and then to HTML entities
+ // If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and
+ // then to HTML entities.
if (!$unicode) {
- // Convert the euro sign to an HTML entity
+ // Convert the euro sign to an HTML entity.
$html = str_replace('€', '&#0128;', $html);
- // Convert from UTF-8 to ISO 8859-1 and then to HTML entities
+ // Convert from UTF-8 to ISO 8859-1 and then to HTML entities.
if (function_exists('utf8_decode')) {
- $html = utf8_decode($html);
+ $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);
}
- // 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');
}
@@ -95,7 +110,7 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
}
- // Must get rid of tbody (dompdf goes into recursion)
+ // Must get rid of tbody (dompdf goes into recursion).
$html = preg_replace('!<tbody[^>]*?>|</tbody>!i', '', $html);
$dompdf->load_html($html);
@@ -105,11 +120,11 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
}
/**
- * Format the dompdf footer contents
+ * Format the dompdf footer contents.
*
* @param array $vars
* An associative array containing:
- * - $html: contents of the body of the HTML from the original node
+ * - $html: contents of the body of the HTML from the original node.
*
* @return string
* customized HTML text
@@ -152,7 +167,8 @@ function theme_print_pdf_dompdf_footer($vars) {
</script>';
return str_replace("<body>", "<body>" . $text, $html);
- } else {
+ }
+ else {
return $vars['html'];
}
}
diff --git a/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.drush.inc b/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.drush.inc
index d89d61b..3f01542 100644
--- a/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.drush.inc
+++ b/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.drush.inc
@@ -2,15 +2,14 @@
/**
* @file
- * drush integration for print_pdf_mpdf module PDF libraries download.
+ * Provides drush integration for print_pdf_mpdf module PDF libraries download.
*/
/**
- * The PDF project download URL
+ * The PDF project download URL.
*/
-
-// URI to the the latest mpdf version.. Hardcoded version unfortunately
-define('MPDF_DOWNLOAD_URI', 'http://mpdf1.com/repos/MPDF57.zip');
+// URI to the the latest mpdf version.
+define('MPDF_DOWNLOAD_URI', 'https://api.github.com/repos/mpdf/mpdf/releases/latest');
/**
* Implements hook_drush_command().
diff --git a/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.module b/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.module
index b160587..fab3765 100644
--- a/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.module
+++ b/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.module
@@ -13,7 +13,7 @@
function print_pdf_mpdf_pdf_tool_info() {
return array(
'name' => 'mPDF',
- 'url' => 'http://www.mpdf1.com/mpdf/download',
+ 'url' => 'https://github.com/mpdf/mpdf/releases/latest',
'expand_css' => FALSE,
'public_dirs' => array(
'ttfontdata',
@@ -29,7 +29,7 @@ function print_pdf_mpdf_pdf_tool_info() {
* Implements hook_pdf_tool_version().
*/
function print_pdf_mpdf_pdf_tool_version($pdf_tool) {
- require_once(DRUPAL_ROOT . '/' . $pdf_tool);
+ require_once DRUPAL_ROOT . '/' . $pdf_tool;
if (defined('mPDF_VERSION')) {
return mPDF_VERSION;
diff --git a/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.pages.inc b/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.pages.inc
index 52c9e1c..64e5a32 100644
--- a/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.pages.inc
+++ b/print_pdf/lib_handlers/print_pdf_mpdf/print_pdf_mpdf.pages.inc
@@ -2,10 +2,10 @@
/**
* @file
- * Generates the PDF version using mPDF
+ * Generates the PDF version using mPDF.
*
* This file is included by the print_pdf_mpdf module and includes the
- * functions that interface with the mPDF library
+ * functions that interface with the mPDF library.
*
* @ingroup print
*/
@@ -23,42 +23,47 @@ function print_pdf_mpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $pa
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
- $content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
- if (!defined('_MPDF_TTFONTDATAPATH')) define('_MPDF_TTFONTDATAPATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/ttfontdata/'));
- if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/tmp/'));
+ if (!defined('_MPDF_TTFONTDATAPATH')) {
+ define('_MPDF_TTFONTDATAPATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/ttfontdata/'));
+ }
+ if (!defined('_MPDF_TEMP_PATH')) {
+ define('_MPDF_TEMP_PATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/tmp/'));
+ }
}
- require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
+ require_once DRUPAL_ROOT . '/' . $pdf_tool[1];
$format = ($page_orientation == "landscape") ? $paper_size . "-L" : $paper_size;
- // Try to use local file access for image files
+ // Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
- // set document information
+ // Set document information.
$mpdf = new mPDF('UTF-8', $format);
$mpdf->SetAuthor(strip_tags($meta['name']));
$mpdf->SetCreator(variable_get('site_name', 'Drupal'));
+ /*
// Pulled from the HTML meta data
- // $mpdf->SetTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
+ $mpdf->SetTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
-// $keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
-// $mpdf->SetKeywords($keys);
+ $keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
+ $mpdf->SetKeywords($keys);
// Encrypt the file and grant permissions to the user to copy and print
// No password is required to open the document
// Owner has full rights using the password "MyPassword"
- // $mpdf->SetProtection(array('copy', 'print'), '', 'MyPassword');
- // $mpdf->SetProtection(array('copy', 'print', 'print-highres'), '', '');
+ $mpdf->SetProtection(array('copy', 'print'), '', 'MyPassword');
+ $mpdf->SetProtection(array('copy', 'print', 'print-highres'), '', '');
+ */
drupal_alter('print_pdf_mpdf', $mpdf, $html, $meta);
$mpdf->WriteHTML($html);
- // try to recover from any warning/error
+ // Try to recover from any warning/error.
ob_clean();
return $mpdf->Output('', 'S');
diff --git a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.admin.inc b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.admin.inc
index 9c3270b..751885c 100644
--- a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.admin.inc
+++ b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.admin.inc
@@ -28,7 +28,7 @@ function print_pdf_tcpdf_settings() {
'#size' => 60,
'#maxlength' => 250,
'#description' => t('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."),
+ 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',
@@ -53,6 +53,11 @@ function print_pdf_tcpdf_settings() {
/**
* Form validation handler for print_pdf_tcpdf_settings().
*
+ * @param array $form
+ * Form.
+ * @param array $form_state
+ * Form state.
+ *
* @see print_pdf_tcpdf_settings()
* @ingroup forms
*/
diff --git a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.class.inc b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.class.inc
index b6a4c53..d31655e 100644
--- a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.class.inc
+++ b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.class.inc
@@ -2,9 +2,9 @@
/**
* @file
- * Extend the TCPDF class to be able to customize the Footer
+ * Extend the TCPDF class to be able to customize the Footer.
*
- * This file is included by the _print_pdf_tcpdf function
+ * This file is included by the _print_pdf_tcpdf function.
*
* @ingroup print
*/
@@ -12,18 +12,31 @@
class PrintTCPDF extends TCPDF {
public $footer;
- // Display invisible link at the bottom of all pages.
+ /**
+ * Display invisible link at the bottom of all pages.
+ *
+ * @param string $tcpdflink
+ * TCPDF link.
+ */
public function setTcpdfLink($tcpdflink) {
$this->tcpdflink = $tcpdflink;
}
- // Page footer data
+ /**
+ * Page footer data.
+ *
+ * @param string $arg
+ * Footer contents.
+ */
public function setFooterContent($arg = '') {
$this->footer = $arg;
}
- // Page footer
+ /**
+ * Page footer.
+ */
public function Footer() {
theme('print_pdf_tcpdf_footer2', array('pdf' => $this));
}
+
}
diff --git a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.drush.inc b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.drush.inc
index de1d60e..52863a2 100644
--- a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.drush.inc
+++ b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.drush.inc
@@ -2,14 +2,13 @@
/**
* @file
- * drush integration for print_pdf_tcpdf module PDF libraries download.
+ * Provides drush integration for print_pdf_tcpdf module PDF libraries download.
*/
/**
- * The PDF project download URL
+ * The PDF project download URL.
*/
-
-// TCPDF is in sourceforge, and nicely provides a link to the latest version
+// TCPDF is in sourceforge, and nicely provides a link to the latest version.
define('TCPDF_DOWNLOAD_URI', 'http://sourceforge.net/projects/tcpdf/files/latest');
/**
diff --git a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.module b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.module
index 3d839a2..76edb67 100644
--- a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.module
+++ b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.module
@@ -81,12 +81,12 @@ function print_pdf_tcpdf_menu() {
*/
function print_pdf_tcpdf_pdf_tool_version($pdf_tool) {
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
- // prevent TCPDF default configs
+ // Prevent TCPDF default configs.
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
}
- require_once(DRUPAL_ROOT . '/' . $pdf_tool);
+ require_once DRUPAL_ROOT . '/' . $pdf_tool;
- // Hide warnings, as some TCPDF constants may still be undefined
+ // Hide warnings, as some TCPDF constants may still be undefined.
if (class_exists('TCPDF')) {
@$pdf = new TCPDF();
diff --git a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.pages.inc b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.pages.inc
index 029cd29..459a711 100644
--- a/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.pages.inc
+++ b/print_pdf/lib_handlers/print_pdf_tcpdf/print_pdf_tcpdf.pages.inc
@@ -2,10 +2,10 @@
/**
* @file
- * Generates the PDF version using TCPDF
+ * Generates the PDF version using TCPDF.
*
* This file is included by the print_pdf_tcpdf module and includes the
- * functions that interface with the TCPDF library
+ * functions that interface with the TCPDF library.
*
* @ingroup print
*/
@@ -25,47 +25,64 @@ function print_pdf_tcpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $p
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
- $content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$pdf_tool_path = realpath(dirname($pdf_tool[1]));
- 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', drupal_realpath('public://print_pdf/print_pdf_tcpdf/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);
+ 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', drupal_realpath('public://print_pdf/print_pdf_tcpdf/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
+ // Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
- // Decode HTML entities in image filenames
+ // 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
+ // 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(DRUPAL_ROOT . '/' . $pdf_tool[1]);
+ require_once DRUPAL_ROOT . '/' . $pdf_tool[1];
module_load_include('inc', 'print_pdf_tcpdf', 'print_pdf_tcpdf.class');
- $font = Array(
+ $font = array(
check_plain(variable_get('print_pdf_font_family', PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT)),
'',
check_plain(variable_get('print_pdf_font_size', PRINT_PDF_TCPDF_FONT_SIZE_DEFAULT)),
);
$orientation = drupal_strtoupper($page_orientation[0]);
- // create new PDF document
- $pdf = new PrintTCPDF($orientation , 'mm', $paper_size, TRUE);
+ // Create new PDF document.
+ $pdf = new PrintTCPDF($orientation, 'mm', $paper_size, TRUE);
- // set document information
+ // Set document information.
if (isset($meta['name'])) {
$pdf->SetAuthor(strip_tags($meta['name']));
}
@@ -73,35 +90,48 @@ function print_pdf_tcpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $p
$pdf->SetTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
$pdf->setPDFVersion('1.6');
$pdf->setFontSubsetting(variable_get('print_pdf_font_subsetting', PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT));
- $pdf->setTcpdfLink(false);
+ $pdf->setTcpdfLink(FALSE);
if ($language->direction == LANGUAGE_RTL) {
$pdf->setRTL(TRUE);
}
- $pdf = theme('print_pdf_tcpdf_header', array('pdf' => $pdf, 'html' => $html, 'font' => $font));
- $pdf = theme('print_pdf_tcpdf_footer', array('pdf' => $pdf, 'html' => $html, 'font' => $font));
+ $pdf = theme('print_pdf_tcpdf_header', array(
+ 'pdf' => $pdf,
+ 'html' => $html,
+ 'font' => $font,
+ ));
+ $pdf = theme('print_pdf_tcpdf_footer', array(
+ 'pdf' => $pdf,
+ 'html' => $html,
+ 'font' => $font,
+ ));
$pdf = theme('print_pdf_tcpdf_page', array('pdf' => $pdf));
- // Enable third-party module to alter the pdf object, via hook_print_pdf_tcpdf_alter()
+ // Enable third-party module to alter the pdf object, via
+ // hook_print_pdf_tcpdf_alter().
drupal_alter('print_pdf_tcpdf', $pdf, $html, $meta);
- // add a page
+ // Add a page.
$pdf->AddPage();
- $pdf = theme('print_pdf_tcpdf_content', array('pdf' => $pdf, 'html' => $html, 'font' => $font));
+ $pdf = theme('print_pdf_tcpdf_content', array(
+ 'pdf' => $pdf,
+ 'html' => $html,
+ 'font' => $font,
+ ));
- // reset pointer to the last page
+ // Reset pointer to the last page.
$pdf->lastPage();
- // try to recover from any warning/error
+ // Try to recover from any warning/error.
ob_clean();
return $pdf = $pdf->Output('', 'S');
}
/**
- * Format the TCPDF header
+ * Format the TCPDF header.
*
* @param array $vars
* An associative array containing:
@@ -128,7 +158,7 @@ function theme_print_pdf_tcpdf_header($vars) {
if (isset($tpl_logo[1]) && preg_match('!src\s*=\s*(?:"(.*?)"|\'(.*?)\'|([^\s]*))!i', $tpl_logo[1], $logo_url)) {
$logo = $logo_url[1];
- // Make logo relative again
+ // Make logo relative again.
$logo = preg_replace("!^$base_url(.*)!sm", dirname($_SERVER['SCRIPT_FILENAME']) . '$1', $logo);
if (!empty($logo)) {
@@ -137,22 +167,22 @@ function theme_print_pdf_tcpdf_header($vars) {
}
}
- // set header font
+ // Set header font.
$pdf->setHeaderFont($vars['font']);
- // set header margin
+ // Set header margin.
$pdf->setHeaderMargin(5);
- // set header data
+ // 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)
+ * Format the TCPDF page settings (margins, etc).
*
* @param array $vars
* An associative array containing:
- * - $pdf: current TCPDF object
+ * - $pdf: current TCPDF object.
*
* @return object
* modified PDF object
@@ -162,20 +192,20 @@ function theme_print_pdf_tcpdf_header($vars) {
*/
function theme_print_pdf_tcpdf_page($vars) {
$pdf = $vars['pdf'];
- // set margins
+ // Set margins.
$pdf->SetMargins(15, 20, 15);
- // set auto page breaks
+ // Set auto page breaks.
$pdf->SetAutoPageBreak(TRUE, 15);
- // set image scale factor
+ // Set image scale factor.
$pdf->setImageScale(1);
- // set image compression quality
+ // Set image compression quality.
$pdf->setJPEGQuality(100);
return $pdf;
}
/**
- * Format the TCPDF page content
+ * Format the TCPDF page content.
*
* @param array $vars
* An associative array containing:
@@ -191,20 +221,20 @@ function theme_print_pdf_tcpdf_page($vars) {
*/
function theme_print_pdf_tcpdf_content($vars) {
$pdf = $vars['pdf'];
- // set content font
+ // Set content font.
$pdf->setFont($vars['font'][0], $vars['font'][1], $vars['font'][2]);
- // Remove the logo, published, breadcrumb and footer from the main content
+ // Remove the logo, published, breadcrumb and footer from the main content.
preg_match('!<body.*?>(.*)</body>!sim', $vars['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
+ // 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
+ // Since TCPDF's writeHTML is so bad with <p>, try 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 {
@@ -218,7 +248,7 @@ function theme_print_pdf_tcpdf_content($vars) {
}
/**
- * Format the TCPDF footer contents
+ * Format the TCPDF footer contents.
*
* @param array $vars
* An associative array containing:
@@ -239,12 +269,12 @@ function theme_print_pdf_tcpdf_footer($vars) {
if (isset($tpl_footer[1])) {
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1]));
- // set footer font
+ // Set footer font.
$vars['font'][2] *= 0.8;
$pdf->setFooterFont($vars['font']);
- // set footer margin
+ // Set footer margin.
$pdf->SetFooterMargin(10);
- // set footer data
+ // Set footer data.
$pdf->setFooterContent($footer);
}
@@ -252,11 +282,11 @@ function theme_print_pdf_tcpdf_footer($vars) {
}
/**
- * Format the TCPDF footer layout
+ * Format the TCPDF footer layout.
*
* @param array $vars
* An associative array containing:
- * - $pdf: current TCPDF object
+ * - $pdf: current TCPDF object.
*
* @return object
* modified PDF object
@@ -266,12 +296,12 @@ function theme_print_pdf_tcpdf_footer($vars) {
*/
function theme_print_pdf_tcpdf_footer2($vars) {
$pdf = $vars['pdf'];
- // Position at 1.5 cm from bottom
- $pdf->writeHTMLCell(0, 15, 15, $pdf->getPageHeight()-15, $pdf->footer);
+ // 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
+ // Print page number.
if ($pdf->getRTL()) {
$pdf->SetX($ormargins['right']);
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'L');
diff --git a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.drush.inc b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.drush.inc
index dca3d29..e30dc17 100644
--- a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.drush.inc
+++ b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.drush.inc
@@ -2,19 +2,19 @@
/**
* @file
- * drush integration for print_pdf_wkhtmltopdf module PDF libraries download.
+ * Provides drush integration for print_pdf_wkhtmltopdf module.
*/
/**
- * The PDF project download URL
+ * The PDF project download URL.
*/
-
-// 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');
+// Since wkhtmltopdf is a binary, a different URL is required for each platform.
+define('WKHTMLTOPDF_LNX64_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz');
+define('WKHTMLTOPDF_LNX32_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-i386.tar.xz');
+define('WKHTMLTOPDF_WIN64_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3.2/wkhtmltox-0.12.3.2_msvc2013-win64.exe');
+define('WKHTMLTOPDF_WIN32_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3.2/wkhtmltox-0.12.3.2_msvc2013-win32.exe');
+define('WKHTMLTOPDF_OSX64_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_osx-cocoa-x86-64.pkg');
+define('WKHTMLTOPDF_OSX32_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_osx-carbon-i386.pkg');
/**
* Implements hook_drush_command().
@@ -36,14 +36,17 @@ function _print_pdf_wkhtmltopdf_drush_download_url() {
switch (drupal_substr(php_uname('s'), 0, 3)) {
case 'Lin':
- $ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_AMD64_DOWNLOAD_URI : WKHTMLTOPDF_I386_DOWNLOAD_URI;
+ $ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_LNX64_DOWNLOAD_URI : WKHTMLTOPDF_LNX32_DOWNLOAD_URI;
break;
+
case 'Win':
- $ret = WKHTMLTOPDF_WIN_DOWNLOAD_URI;
+ $ret = WKHTMLTOPDF_WIN32_DOWNLOAD_URI;
break;
+
case 'Dar':
- $ret = WKHTMLTOPDF_OSX_DOWNLOAD_URI;
+ $ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_OSX64_DOWNLOAD_URI : WKHTMLTOPDF_OSX32_DOWNLOAD_URI;
break;
+
default:
drush_log(dt('wkhtmltopdf is not supported in this system, please choose another library.'), 'error');
break;
diff --git a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.install b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.install
index 6a4b787..fba3c35 100644
--- a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.install
+++ b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.install
@@ -13,3 +13,34 @@
function print_pdf_wkhtmltopdf_uninstall() {
variable_del('print_pdf_wkhtmltopdf_options');
}
+
+/**
+ * Implements hook_requirements().
+ */
+function print_pdf_wkhtmltopdf_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)) {
+ $tool = explode('|', $print_pdf_pdf_tool);
+
+ if (is_file($tool[1]) && is_readable($tool[1])) {
+ if (drupal_substr(basename($tool[1], '.exe'), 0, 11) == 'wkhtmltopdf') {
+ if (function_exists('is_executable') && !is_executable($tool[1])) {
+ $requirements['print_pdf_wkhtmltopdf'] = 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' => $tool[1])),
+ 'severity' => REQUIREMENT_ERROR,
+ );
+ }
+ }
+ }
+ }
+ break;
+ }
+ return $requirements;
+}
diff --git a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.module b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.module
index 5646214..0138843 100644
--- a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.module
+++ b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.module
@@ -16,7 +16,7 @@ function print_pdf_wkhtmltopdf_pdf_tool_info() {
return array(
'name' => 'wkhtmltopdf',
'min_version' => '0.9.6',
- 'url' => 'http://code.google.com/p/wkhtmltopdf/downloads/list',
+ 'url' => 'http://wkhtmltopdf.org/downloads.html',
'expand_css' => FALSE,
);
}
@@ -41,54 +41,29 @@ function print_pdf_wkhtmltopdf_menu() {
}
/**
- * Implements hook_requirements().
- */
-function print_pdf_wkhtmltopdf_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)) {
- $tool = explode('|', $print_pdf_pdf_tool);
-
- if (is_file($tool[1]) && is_readable($tool[1])) {
- if (drupal_substr(basename($tool[1], '.exe'), 0, 11) == 'wkhtmltopdf') {
- if (function_exists('is_executable') && !is_executable($tool[1])) {
- $requirements['print_pdf_wkhtmltopdf'] = 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' => $tool[1])),
- 'severity' => REQUIREMENT_ERROR,
- );
- }
- }
- }
- }
- break;
- }
- return $requirements;
-}
-
-/**
* Implements hook_pdf_tool_version().
*/
function print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool) {
- $descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
+ $descriptor = array(
+ 0 => array('pipe', 'r'),
+ 1 => array('pipe', 'w'),
+ 2 => array('pipe', 'w'),
+ );
$cmd = '"' . realpath($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);
+ preg_match('!.*?(\d+\.\d+\.\d+).*$!m', $content, $matches);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
- $retval = proc_close($process);
+ proc_close($process);
+
+ return ($matches[1]);
}
- return ($matches[1]);
+ return 'unknown';
}
/**
diff --git a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc
index 3e86f97..c91325f 100644
--- a/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc
+++ b/print_pdf/lib_handlers/print_pdf_wkhtmltopdf/print_pdf_wkhtmltopdf.pages.inc
@@ -2,10 +2,10 @@
/**
* @file
- * Generates the PDF version using wkhtmltopdf
+ * Generates the PDF version using wkhtmltopdf.
*
* This file is included by the print_pdf_wkhtmltopdf module and includes the
- * functions that interface with the wkhtmltopdf library
+ * functions that interface with the wkhtmltopdf library.
*
* @ingroup print
*/
@@ -21,7 +21,6 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
- $content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$wkhtmltopdf_options = variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS);
$dpi = 96;
@@ -32,7 +31,7 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
$version = print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool[1]);
- // 0.10.0 beta2 identifies itself as 0.9.9
+ // 0.10.0 beta2 identifies itself as 0.9.9.
if (version_compare($version, '0.9.9', '>=')) {
$wkhtmltopdf_options = '--disable-local-file-access ' . $wkhtmltopdf_options;
}
@@ -44,12 +43,16 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
exit;
}
- // use basic http authentication to fetch included CSS, etc
+ // Use basic http authentication to fetch included CSS, etc.
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$wkhtmltopdf_options .= ' --username ' . check_plain($_SERVER['PHP_AUTH_USER']) . ' --password ' . check_plain($_SERVER['PHP_AUTH_PW']);
}
- $descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'a'));
+ $descriptor = array(
+ 0 => array('pipe', 'r'),
+ 1 => array('pipe', 'w'),
+ 2 => array('pipe', 'a'),
+ );
$cmd = '"' . realpath($pdf_tool[1]) . "\" --page-size $paper_size --orientation $page_orientation --dpi $dpi $wkhtmltopdf_options - -";
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
@@ -70,7 +73,8 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
if (empty($error)) {
$error = 'No stderr output available.';
}
- watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error', array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
+ watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error',
+ array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
}
}
diff --git a/print_pdf/print_pdf.admin.inc b/print_pdf/print_pdf.admin.inc
index ef8e2c2..5cb70af 100644
--- a/print_pdf/print_pdf.admin.inc
+++ b/print_pdf/print_pdf.admin.inc
@@ -23,7 +23,7 @@ function print_pdf_settings() {
$link = print_pdf_print_link();
$current_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
- $pdf_tool_default = array_key_exists($current_pdf_tool, $pdf_tools) ? $current_pdf_tool : PRINT_PDF_PDF_TOOL_DEFAULT;
+ $pdf_tool_default = array_key_exists($current_pdf_tool, $pdf_tools) ? $current_pdf_tool : PRINT_PDF_PDF_TOOL_DEFAULT;
$form['settings'] = array(
'#type' => 'fieldset',
@@ -41,7 +41,11 @@ function print_pdf_settings() {
$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')),
+ '#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."),
);
@@ -163,6 +167,11 @@ function print_pdf_settings() {
/**
* Form validation handler for print_pdf_settings().
*
+ * @param array $form
+ * Form.
+ * @param array $form_state
+ * Form state.
+ *
* @see print_pdf_settings()
* @ingroup forms
*/
diff --git a/print_pdf/print_pdf.api.php b/print_pdf/print_pdf.api.php
index f6c34bd..6d14a26 100644
--- a/print_pdf/print_pdf.api.php
+++ b/print_pdf/print_pdf.api.php
@@ -13,7 +13,7 @@
/**
* Provide some information on the needs of the PDF library.
*
- * @return
+ * @return array
* Associative array with the following data:
* - name: name of the PDF library.
* - min_version: minimum version of the PDF library supported by the
@@ -47,7 +47,7 @@ function hook_pdf_tool_info() {
}
/**
- * Find out the version of the PDF library
+ * Find out the version of the PDF library.
*
* @param string $pdf_tool
* Filename of the tool to be analysed.
@@ -55,8 +55,8 @@ function hook_pdf_tool_info() {
* @return string
* version number of the library
*/
-function hook_pdf_tool_version() {
- require_once(DRUPAL_ROOT . '/' . $pdf_tool);
+function hook_pdf_tool_version($pdf_tool) {
+ require_once DRUPAL_ROOT . '/' . $pdf_tool;
return '1.0';
}
@@ -65,26 +65,26 @@ function hook_pdf_tool_version() {
* Generate a PDF version of the provided HTML.
*
* @param string $html
- * HTML content of the PDF
+ * HTML content of the PDF.
* @param array $meta
* Meta information to be used in the PDF
* - url: original URL
* - name: author's name
* - title: Page title
- * - node: node object
+ * - node: node object.
* @param string $paper_size
- * (optional) Paper size of the generated PDF
+ * (optional) Paper size of the generated PDF.
* @param string $page_orientation
- * (optional) Page orientation of the generated PDF
+ * (optional) Page orientation of the generated PDF.
*
- * @return
+ * @return Object|null
* generated PDF page, or NULL in case of error
*
* @see print_pdf_controller_html()
* @ingroup print_hooks
*/
function hook_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
- $pdf = new PDF();
+ $pdf = new PDF($meta, $paper_size, $page_orientation);
$pdf->writeHTML($html);
return $pdf->Output();
@@ -128,7 +128,7 @@ function hook_print_pdf_available_libs_alter(&$pdf_tools) {
* '.pdf' extension, as the module will do that automatically.
*
* @param string $pdf_filename
- * current value of the pdf_filename variable, after processing tokens and
+ * Current value of the pdf_filename variable, after processing tokens and
* any transliteration steps.
* @param string $path
* original alias/system path of the page being converted to PDF.
@@ -136,7 +136,7 @@ function hook_print_pdf_available_libs_alter(&$pdf_tools) {
* @ingroup print_hooks
*/
function hook_print_pdf_filename_alter(&$pdf_filename, &$path) {
- $pdf_filename = 'foo';
+ $pdf_filename = $path . 'foo';
}
/**
diff --git a/print_pdf/print_pdf.drush.inc b/print_pdf/print_pdf.drush.inc
index c46ea22..1d6814a 100644
--- a/print_pdf/print_pdf.drush.inc
+++ b/print_pdf/print_pdf.drush.inc
@@ -2,7 +2,7 @@
/**
* @file
- * drush integration for print_pdf module PDF libraries download.
+ * Provide drush integration for print_pdf module PDF libraries download.
*/
/**
@@ -23,21 +23,25 @@ function print_pdf_drush_command() {
'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.
+ // No site or config needed.
+ 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
);
return $items;
}
/**
- * Implements of drush_hook_COMMAND_validate().
+ * Implements drush_hook_COMMAND_validate().
*/
function drush_print_pdf_download_validate($library = NULL) {
if (is_null($library)) {
$pdf_libs = array();
drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
- drush_set_error('DRUSH_PDFDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array('!cmd' => 'print-pdf-download', '!libs' => implode(', ', array_keys($pdf_libs)))));
+ drush_set_error('DRUSH_PDFDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array(
+ '!cmd' => 'print-pdf-download',
+ '!libs' => implode(', ', array_keys($pdf_libs)),
+ )));
}
}
@@ -45,7 +49,7 @@ function drush_print_pdf_download_validate($library = NULL) {
* Download and extract PDF archive.
*
* @param string $library
- * library to download
+ * Library to download.
*/
function drush_print_pdf_download($library) {
$pdf_libs = array();
diff --git a/print_pdf/print_pdf.install b/print_pdf/print_pdf.install
index 3b138b5..4ca164a 100644
--- a/print_pdf/print_pdf.install
+++ b/print_pdf/print_pdf.install
@@ -11,9 +11,7 @@
* Implements hook_enable().
*/
function print_pdf_enable() {
- $t = get_t();
-
- // Module weight
+ // Module weight.
db_update('system')
->fields(array(
'weight' => 2,
@@ -139,7 +137,100 @@ function print_pdf_schema() {
}
/**
- * Remove hardcoded numeric deltas from all blocks
+ * Implements 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/config/user-interface/print/pdf'))),
+ 'severity' => REQUIREMENT_ERROR,
+ );
+ }
+ else {
+ // Tool is defined, get some data from it's handler module.
+ $tool = explode('|', $print_pdf_pdf_tool);
+ $function = $tool[0] . '_pdf_tool_info';
+ if (function_exists($function)) {
+ $info = $function();
+ }
+
+ // Is the file there?
+ if (!is_file($tool[1]) || !is_readable($tool[1])) {
+ $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' => $tool[1])),
+ 'severity' => REQUIREMENT_ERROR,
+ );
+ }
+ else {
+ // Get the version number.
+ $function = $tool[0] . '_pdf_tool_version';
+ if (function_exists($function)) {
+ $version = $function($tool[1]);
+
+ if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
+ $requirements['print_pdf_tool_version'] = array(
+ 'title' => $t('Printer, email and PDF versions - PDF generation library'),
+ 'value' => $t('Unsupported %lib version', array('%lib' => $info['name'])),
+ 'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to a !url.', array(
+ '%lib' => $info['name'],
+ '@version' => $version,
+ '!url' => l($t('newer version'), $info['url']),
+ )),
+ 'severity' => REQUIREMENT_ERROR,
+ );
+ }
+ else {
+ $requirements['print_pdf_tool_version'] = array(
+ 'title' => $t('Printer, email and PDF versions - PDF generation library'),
+ 'value' => $info['name'] . ' ' . $version,
+ );
+ }
+ }
+ }
+
+ // If auto-config is on, check for write access to the appropriate dirs.
+ if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
+ $directories = array();
+ if (isset($info['public_dirs'])) {
+ foreach ($info['public_dirs'] as $dir) {
+ $directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
+ }
+ }
+ if (isset($info['tool_dirs'])) {
+ foreach ($info['tool_dirs'] as $dir) {
+ $directories[] = dirname($tool[1]) . '/' . $dir;
+ }
+ }
+
+ foreach ($directories as $dir) {
+ if (!is_dir($dir) || !is_writable($dir)) {
+ $requirements['print_pdf_tool_' . $dir] = array(
+ 'title' => $t('%lib directory', array('%lib' => $info['name'])),
+ 'value' => $t('Non-writable permissions'),
+ 'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => $info['name'], '%libdir' => $dir)),
+ 'severity' => REQUIREMENT_ERROR,
+ );
+ }
+ }
+ }
+ }
+ break;
+ }
+ return $requirements;
+}
+
+/**
+ * Remove hardcoded numeric deltas from all blocks.
*/
function print_pdf_update_7000(&$sandbox) {
$renamed_deltas = array(
@@ -156,7 +247,7 @@ function print_pdf_update_7000(&$sandbox) {
}
/**
- * Delete old variables
+ * Delete old variables.
*/
function print_pdf_update_7200(&$sandbox) {
variable_del('print_pdf_settings');
@@ -166,13 +257,13 @@ function print_pdf_update_7200(&$sandbox) {
}
/**
- * Update pdf_tool variable to new module|path format
+ * Update pdf_tool variable to new module|path format.
*/
function print_pdf_update_7201(&$sandbox) {
- $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
+ $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
if (count($tool) == 1) {
- // Not an array yet, update variable to new format
+ // Not an array yet, update variable to new format.
if (preg_match('!dompdf_config.inc.php$!', $tool[0])) {
$tool[0] = 'print_pdf_dompdf|' . $tool[0];
}
@@ -191,7 +282,7 @@ function print_pdf_update_7201(&$sandbox) {
}
/**
- * Enable block and help area links
+ * Enable block and help area links.
*/
function print_pdf_update_7202(&$sandbox) {
$link_pos = variable_get('print_pdf_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
@@ -201,7 +292,7 @@ function print_pdf_update_7202(&$sandbox) {
}
/**
- * Add Size and Orientation fields for per content type Size and Orientation
+ * Add Size and Orientation fields for per content type Size and Orientation.
*/
function print_pdf_update_7203(&$sandbox) {
$spec = array(
@@ -219,11 +310,11 @@ function print_pdf_update_7203(&$sandbox) {
}
/**
- * Enable the PDF generation sub-module being used
+ * Enable the PDF generation sub-module being used.
*/
function print_pdf_update_7204(&$sandbox) {
- // Since update_7201 already has stored the correct module in the array, use that
- $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
+ // Since update_7201 already stored the correct module in the array, use that.
+ $tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
if (count($tool) == 2) {
module_enable(array($tool[0]), FALSE);
@@ -231,11 +322,16 @@ function print_pdf_update_7204(&$sandbox) {
}
/**
- * Increase size of the path field in the print_pdf_page_counter table
+ * Increase size of the path field in the print_pdf_page_counter table.
*/
function print_pdf_update_7205(&$sandbox) {
db_drop_primary_key('print_pdf_page_counter');
db_change_field('print_pdf_page_counter', 'path', 'path',
- array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
+ array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'description' => 'Page path',
+ ),
array('primary key' => array('path')));
}
diff --git a/print_pdf/print_pdf.module b/print_pdf/print_pdf.module
index 0cdff67..c3de80a 100644
--- a/print_pdf/print_pdf.module
+++ b/print_pdf/print_pdf.module
@@ -15,7 +15,8 @@ define('PRINT_PDF_IMAGES_VIA_FILE_DEFAULT', 0);
define('PRINT_PDF_AUTOCONFIG_DEFAULT', 1);
define('PRINT_PDF_FILENAME_DEFAULT', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
define('PRINT_PDF_CACHE_ENABLED_DEFAULT', 0);
-define('PRINT_PDF_CACHE_LIFETIME_DEFAULT', 86400); // 1 day
+// 1 day.
+define('PRINT_PDF_CACHE_LIFETIME_DEFAULT', 86400);
/**
* Implements hook_print_link().
@@ -66,6 +67,7 @@ function print_pdf_init() {
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directory = 'public://print_pdf/' . $tool[0] . '/' . $dir;
+ /** @var DrupalLocalStreamWrapper $wrapper */
$wrapper = file_stream_wrapper_get_instance_by_uri($directory);
$real_directory_path = $wrapper->getDirectoryPath() . "/" . file_uri_target($directory);
$result = file_prepare_directory($real_directory_path, FILE_CREATE_DIRECTORY);
@@ -160,11 +162,12 @@ function print_pdf_block_info() {
* Implements hook_block_view().
*/
function print_pdf_block_view($delta = 0) {
+ $block = array();
switch ($delta) {
case 'print_pdf-top':
$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)
- ->fetchAll();
+ ->fetchAll();
if (count($result)) {
$items = array();
foreach ($result as $obj) {
@@ -178,96 +181,6 @@ function print_pdf_block_view($delta = 0) {
}
/**
- * Implements 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/config/user-interface/print/pdf'))),
- 'severity' => REQUIREMENT_ERROR,
- );
- }
- else {
- // Tool is defined, get some data from it's handler module
- $tool = explode('|', $print_pdf_pdf_tool);
- $function = $tool[0] . '_pdf_tool_info';
- if (function_exists($function)) {
- $info = $function();
- }
-
- // Is the file there?
- if (!is_file($tool[1]) || !is_readable($tool[1])) {
- $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' => $tool[1])),
- 'severity' => REQUIREMENT_ERROR,
- );
- }
- else {
- // Get the version number
- $function = $tool[0] . '_pdf_tool_version';
- if (function_exists($function)) {
- $version = $function($tool[1]);
-
- if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
- $requirements['print_pdf_tool_version'] = array(
- 'title' => $t('Printer, email and PDF versions - PDF generation library'),
- 'value' => $t('Unsupported %lib version', array('%lib' => $info['name'])),
- 'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to a !url.',
- array('%lib' => $info['name'], '@version' => $version, '!url' => l($t('newer version'), $info['url']))),
- 'severity' => REQUIREMENT_ERROR,
- );
- }
- else {
- $requirements['print_pdf_tool_version'] = array(
- 'title' => $t('Printer, email and PDF versions - PDF generation library'),
- 'value' => $info['name'] . ' ' . $version,
- );
- }
- }
- }
-
- // If auto-config is on, check for write access to the appropriate dirs
- if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
- $directories = array();
- if (isset($info['public_dirs'])) {
- foreach ($info['public_dirs'] as $dir) {
- $directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
- }
- }
- if (isset($info['tool_dirs'])) {
- foreach ($info['tool_dirs'] as $dir) {
- $directories[] = dirname($tool[1]) . '/' . $dir;
- }
- }
-
- foreach ($directories as $dir) {
- if (!is_dir($dir) || !is_writable($dir)) {
- $requirements['print_pdf_tool_' . $dir] = array(
- 'title' => $t('%lib directory', array('%lib' => $info['name'])),
- 'value' => $t('Non-writable permissions'),
- 'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => $info['name'], '%libdir' => $dir)),
- 'severity' => REQUIREMENT_ERROR,
- );
- }
- }
- }
- }
- break;
- }
- return $requirements;
-}
-
-/**
* Implements hook_node_load().
*/
function print_pdf_node_load($nodes, $types) {
@@ -293,7 +206,7 @@ function print_pdf_node_load($nodes, $types) {
* Implements hook_node_insert().
*/
function print_pdf_node_insert($node) {
- return print_pdf_node_update($node);
+ print_pdf_node_update($node);
}
/**
@@ -306,8 +219,12 @@ function print_pdf_node_update($node) {
$size = 'print_' . $link['format'] . '_size';
$orientation = 'print_' . $link['format'] . '_orientation';
- if (!isset($node->{$size})) $node->{$size} = variable_get($size . '_' . $node->type);
- if (!isset($node->{$orientation})) $node->{$orientation} = variable_get($orientation . '_' . $node->type);
+ if (!isset($node->{$size})) {
+ $node->{$size} = variable_get($size . '_' . $node->type);
+ }
+ if (!isset($node->{$orientation})) {
+ $node->{$orientation} = variable_get($orientation . '_' . $node->type);
+ }
db_merge('print_pdf_node_conf')
->key(array('nid' => $node->nid))
@@ -336,7 +253,7 @@ function print_pdf_node_delete($node) {
* Implements hook_form_alter().
*/
function print_pdf_form_alter(&$form, &$form_state, $form_id) {
- // Add the node-type settings option to activate the printer-friendly version link
+ // Add the node-type settings to activate the printer-friendly version link.
if ((user_access('administer print') || user_access('node-specific print configuration')) &&
(($form_id == 'node_type_form') || !empty($form['#node_edit_form']))) {
$link = print_pdf_print_link();
@@ -354,7 +271,11 @@ function print_pdf_form_alter(&$form, &$form_state, $form_id) {
$form['print']['print_' . $link['format']][$orientation] = array(
'#type' => 'select',
'#title' => t('Page orientation'),
- '#options' => array('' => 'Unchanged', 'portrait' => t('Portrait'), 'landscape' => t('Landscape')),
+ '#options' => array(
+ '' => 'Unchanged',
+ 'portrait' => t('Portrait'),
+ 'landscape' => t('Landscape'),
+ ),
'#description' => t('Choose the page orientation of the generated PDF.'),
);
@@ -371,18 +292,18 @@ function print_pdf_form_alter(&$form, &$form_state, $form_id) {
}
/**
- * Auxiliary function to display a formatted PDF version link
+ * 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 string $path
- * path to be used in the link. If not specified, the current URL is used.
+ * Path to be used in the link. If not specified, the current URL is used.
* @param object $node
- * node object, to be used in checking node access. If the path argument is
+ * Node object, to be used in checking node access. If the path argument is
* not provided, the path used will be node/nid.
* @param string $location
- * where in the page where the link is being inserted ('link', 'corner',
+ * Where in the page where the link is being inserted ('link', 'corner',
* 'block', 'help').
*
* @return bool
@@ -392,7 +313,11 @@ function print_pdf_form_alter(&$form, &$form_state, $form_id) {
*/
function print_pdf_insert_link($path = NULL, $node = NULL, $location = '') {
if (function_exists('print_ui_insert_link')) {
- return print_ui_insert_link(print_pdf_print_link(), array('path' => $path, 'node' => $node, 'location' => $location));
+ return print_ui_insert_link(print_pdf_print_link(), array(
+ 'path' => $path,
+ 'node' => $node,
+ 'location' => $location,
+ ));
}
else {
return FALSE;
@@ -400,11 +325,11 @@ function print_pdf_insert_link($path = NULL, $node = NULL, $location = '') {
}
/**
- * Check if the link to the PDF version is allowed depending on the settings
+ * Check if the link to the PDF version is allowed depending on the settings.
*
* @param array $args
- * array containing the possible parameters:
- * view_mode, node, type, path
+ * Array containing the possible parameters:
+ * view_mode, node, type, path.
*
* @return bool
* FALSE if not allowed, TRUE otherwise
@@ -431,11 +356,11 @@ function print_pdf_cache_clean() {
if ($lifetime > 0) {
$files = file_scan_directory(print_pdf_cache_dir(), '!\d+\.pdf$!');
foreach ($files as $file) {
- // For all files in the cache directory, see when they were last accessed
+ // For all files in the cache directory, see when they were last accessed.
$result = db_query("SELECT timestamp FROM {print_pdf_page_counter} WHERE path = :path", array(':path' => 'node/' . $file->name))
- ->fetchField();
+ ->fetchField();
- // Keep the file only if the last access was within the cache max life value
+ // Keep the file only if last access was within the cache max life value.
if (($result === FALSE) || ($result + $lifetime < REQUEST_TIME)) {
print_pdf_cache_delete($file->name);
}
@@ -460,7 +385,7 @@ function print_pdf_cache_dir() {
/**
* Deletes one or more files from the PDF cache directory.
*
- * @param int nid
+ * @param int $nid
* The node ID of the page for which the cached PDF should be deleted.
* If not provided, the entire cache directory will be deleted.
*/
@@ -485,9 +410,9 @@ function print_pdf_cache_delete($nid = NULL) {
* Displays the PDF as inline or a downloadable file.
*
* @param string $pdf
- * PDF content string
+ * PDF content string.
* @param string $filename
- * Filename of the generated PDF
+ * Filename of the generated PDF.
*
* @return string
* The disposed PDF file
@@ -500,7 +425,7 @@ function print_pdf_dispose_content($pdf, $filename) {
header('Content-Type: application/pdf');
$content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
- $attachment = ($content_disposition == 2) ? 'attachment' : 'inline';
+ $attachment = ($content_disposition == 2) ? 'attachment' : 'inline';
header("Content-Disposition: $attachment; filename=\"$filename\"");
@@ -514,21 +439,21 @@ function print_pdf_dispose_content($pdf, $filename) {
* Generate a PDF version of the provided HTML.
*
* @param string $html
- * HTML content of the PDF
+ * HTML content of the PDF.
* @param array $meta
* Meta information to be used in the PDF
* - url: original URL
* - name: author's name
* - title: Page title
- * - node: node object
+ * - node: node object.
* @param string $filename
- * (optional) Filename of the generated PDF
+ * (optional) Filename of the generated PDF.
* @param string $paper_size
- * (optional) Paper size of the generated PDF
+ * (optional) Paper size of the generated PDF.
* @param string $page_orientation
- * (optional) Page orientation of the generated PDF
+ * (optional) Page orientation of the generated PDF.
*
- * @return
+ * @return string|null
* generated PDF page, or NULL in case of error
*
* @see print_pdf_controller()
@@ -541,9 +466,7 @@ function print_pdf_generate_html($html, $meta, $filename = NULL, $paper_size = N
module_load_include('inc', $pdf_tool[0], $pdf_tool[0] . '.pages');
$function = $pdf_tool[0] . '_print_pdf_generate';
- if (function_exists($function)) {
- $pdf = $function($html, $meta, $paper_size, $page_orientation);
- }
+ $pdf = function_exists($function) ? $function($html, $meta, $paper_size, $page_orientation) : NULL;
if ($filename) {
return print_pdf_dispose_content($pdf, $filename);
}
@@ -562,31 +485,67 @@ function print_pdf_views_api() {
}
/**
- * Lists all possible paper sizes
+ * Lists all possible paper sizes.
*
- * @return
+ * @param bool $include_default
+ * Flag indicating whether to include the tool's default value.
+ *
+ * @return array
* array of strings with the available paper sizes
*/
function _print_pdf_paper_sizes($include_default = FALSE) {
- $ret = array();
-
$ret = ($include_default) ? array('' => 'Unchanged') : array();
$ret += 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',
+ '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',
);
return $ret;
diff --git a/print_pdf/print_pdf.pages.inc b/print_pdf/print_pdf.pages.inc
index be867d0..625575b 100644
--- a/print_pdf/print_pdf.pages.inc
+++ b/print_pdf/print_pdf.pages.inc
@@ -2,7 +2,7 @@
/**
* @file
- * Generates the PDF versions of the pages
+ * 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.
@@ -13,32 +13,34 @@
module_load_include('inc', 'print', 'print.pages');
/**
- * Generate a PDF version of the printer-friendly page
+ * 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
+ // Disable caching for generated PDFs, as Drupal doesn't output 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;
+ $cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
- // Handle the query
+ // Handle the query.
$query = $_GET;
unset($query['q']);
+ $node = NULL;
if (!empty($path)) {
if ($alias = drupal_lookup_path('source', $path)) {
- // Alias
+ // Alias.
$path_arr = explode('/', $alias);
$node = node_load($path_arr[1]);
}
elseif (ctype_digit($args[0])) {
- // normal nid
+ // Normal nid.
$node = node_load($args[0]);
}
@@ -49,7 +51,7 @@ function print_pdf_controller() {
else {
$pdf_filename = token_replace($pdf_filename, array('site'), array('clear' => TRUE));
if (empty($pdf_filename)) {
- // If empty, use a fallback solution
+ // If empty, use a fallback solution.
$pdf_filename = str_replace('/', '_', $path);
}
}
@@ -74,8 +76,8 @@ function print_pdf_controller() {
db_merge('print_pdf_page_counter')
->key(array('path' => $nodepath))
->fields(array(
- 'totalcount' => 1,
- 'timestamp' => REQUEST_TIME,
+ 'totalcount' => 1,
+ 'timestamp' => REQUEST_TIME,
))
->expression('totalcount', 'totalcount + 1')
->execute();
@@ -87,18 +89,18 @@ function print_pdf_controller() {
* Gennerate a PDF for a given Drupal path.
*
* @param string $path
- * path of the page to convert to PDF
+ * path of the page to convert to PDF.
* @param array $query
- * (optional) array of key/value pairs as used in the url() function for the
- * query
+ * (Optional) array of key/value pairs as used in the url() function for the
+ * query.
* @param int $cid
- * (optional) comment ID of the comment to render.
+ * (Optional) comment ID of the comment to render.
* @param string $pdf_filename
- * (optional) filename of the generated PDF
+ * (Optional) filename of the generated PDF.
* @param string $view_mode
- * (optional) view mode to be used when rendering the content
+ * (Optional) view mode to be used when rendering the content.
*
- * @return
+ * @return string|null
* generated PDF page, or NULL in case of error
*
* @see print_pdf_controller()
@@ -109,7 +111,7 @@ function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filenam
$link = print_pdf_print_link();
$node = print_controller($path, $link['format'], $cid, $view_mode);
if ($node) {
- // Call the current tool's hook_pdf_tool_info(), to see if we need to expand CSS
+ // Call the tool's hook_pdf_tool_info(), to see if CSS must be expanded.
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
$cache_enabled = variable_get('print_pdf_cache_enabled', PRINT_PDF_CACHE_ENABLED_DEFAULT);
@@ -119,38 +121,48 @@ function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filenam
}
$expand = isset($info['expand_css']) ? $info['expand_css'] : FALSE;
- $html = theme('print', array('node' => $node, 'query' => $query, $expand, 'format' => $link['format']));
+ $html = theme('print', array(
+ 'node' => $node,
+ 'query' => $query,
+ 'expand_css' => $expand,
+ 'format' => $link['format'],
+ ));
- // Img elements must be set to absolute
+ // Img elements must be set to absolute.
$pattern = '!<(img\s[^>]*?)>!is';
$html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
- // Convert the a href elements, to make sure no relative links remain
+ // 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
+ // And make anchor links relative again, to permit in-PDF navigation.
$html = preg_replace("!${base_url}/" . $link['path'] . '/.*?#!', '#', $html);
$meta = array(
'node' => $node,
'url' => url(drupal_get_path_alias(empty($node->nid) ? $node->path : "node/$node->nid"), array('absolute' => TRUE)),
);
- if (isset($node->name)) $meta['name'] = $node->name;
- if (isset($node->title)) $meta['title'] = $node->title;
+ if (isset($node->name)) {
+ $meta['name'] = $node->name;
+ }
+ if (isset($node->title)) {
+ $meta['title'] = $node->title;
+ }
$paper_size = isset($node->print_pdf_size) ? $node->print_pdf_size : NULL;
$page_orientation = isset($node->print_pdf_orientation) ? $node->print_pdf_orientation : NULL;
$pdf = '';
$cachemiss = FALSE;
+ $cachefile = '';
if ($cache_enabled && isset($node->nid)) {
- // See if the file exists in the cache
+ // See if the file exists in the cache.
$cachefile = drupal_realpath(print_pdf_cache_dir()) . '/' . $node->nid . '.pdf';
if (is_readable($cachefile)) {
- // Get the PDF content from the cached file
+ // Get the PDF content from the cached file.
$pdf = file_get_contents($cachefile);
if ($pdf === FALSE) {
- watchdog('print_pdf', 'Failed to read from cached file %file', array('%file' => $cached), WATCHDOG_ERROR);
+ watchdog('print_pdf', 'Failed to read from cached file %file', array('%file' => $cachefile), WATCHDOG_ERROR);
}
}
else {
@@ -158,23 +170,21 @@ function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filenam
}
}
- // If cache is off or file is not cached, generate one from scratch
+ // If cache is off or file is not cached, generate one from scratch.
if (empty($pdf)) {
$pdf = print_pdf_generate_html($html, $meta, NULL, $paper_size, $page_orientation);
}
if (!empty($pdf)) {
- // A PDF was created, save it to cache if configured
+ // A PDF was created, save it to cache if configured.
if ($cachemiss) {
if (file_unmanaged_save_data($pdf, $cachefile, FILE_EXISTS_REPLACE) == FALSE) {
- watchdog('print_pdf', 'Failed to write to "%f".', array('%f' => $filename), WATCHDOG_ERROR);
+ watchdog('print_pdf', 'Failed to write to "%f".', array('%f' => $cachefile), WATCHDOG_ERROR);
}
}
return $pdf_filename ? print_pdf_dispose_content($pdf, $pdf_filename) : $pdf;
}
}
- else {
- return NULL;
- }
+ return NULL;
}
diff --git a/print_pdf/print_pdf.views.inc b/print_pdf/print_pdf.views.inc
index 847c389..4bef272 100644
--- a/print_pdf/print_pdf.views.inc
+++ b/print_pdf/print_pdf.views.inc
@@ -2,7 +2,7 @@
/**
* @file
- * PDF Version Views integration
+ * PDF Version Views integration.
*
* @ingroup print
*/
@@ -25,18 +25,16 @@ function print_pdf_views_data() {
// '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
+ // 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.'),
@@ -114,8 +112,7 @@ function print_pdf_views_data() {
),
);
-
- // print_pdf_page_counter fields
+ // 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.'),
diff --git a/print_ui/print_ui.admin.inc b/print_ui/print_ui.admin.inc
index 60c6133..0e80e1b 100644
--- a/print_ui/print_ui.admin.inc
+++ b/print_ui/print_ui.admin.inc
@@ -31,7 +31,12 @@ function print_ui_settings() {
'#type' => 'checkboxes',
'#title' => t('Link location'),
'#default_value' => variable_get('print_' . $format . '_link_pos', drupal_json_decode(PRINT_UI_LINK_POS_DEFAULT)),
- '#options' => array('link' => t('Links area'), 'corner' => t('Content corner'), 'block' => t('Block'), 'help' => t('Help area')),
+ '#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 printer-friendly version pages. The Links area is usually below the node content, whereas the Content corner is placed in the upper-right corner of the node content (these apply only in node pages). The Help area is used for system pages. Enabling the block area link will allow links of this format in the provided links module. Unselect all options to disable the link. Even if the link is disabled, you can still go to %path where nid is the numeric id of the node.', array('%path' => $link['path'] . '/nid')),
);
@@ -61,7 +66,11 @@ function print_ui_settings() {
'#type' => 'radios',
'#title' => t('Link style'),
'#default_value' => variable_get('print_' . $format . '_show_link', PRINT_UI_SHOW_LINK_DEFAULT),
- '#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
+ '#options' => array(
+ 1 => t('Text only'),
+ 2 => t('Icon only'),
+ 3 => t('Icon and Text'),
+ ),
'#description' => t('Select the visual style of the link.'),
);
@@ -94,7 +103,11 @@ function print_ui_settings() {
'#default_value' => variable_get('print_' . $format . '_sys_link_pages', PRINT_UI_SYS_LINK_PAGES_DEFAULT),
'#rows' => 3,
'#description' => t('Setting this option will add a 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>')),
+ 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>',
+ )),
);
if (module_exists('php')) {
@@ -114,7 +127,11 @@ function print_ui_settings() {
'#type' => 'radios',
'#title' => t('Link in book hierarchy nodes'),
'#default_value' => variable_get('print_' . $format . '_book_link', PRINT_UI_BOOK_LINK_DEFAULT),
- '#options' => array(t('No link'), t('Current page and sub-pages'), t('Current page only')),
+ '#options' => array(
+ t('No link'),
+ t('Current page and sub-pages'),
+ t('Current page only'),
+ ),
);
}
}
@@ -131,6 +148,9 @@ function print_ui_settings() {
* An associative array containing:
* - form: A render element representing the form.
*
+ * @return string
+ * HTML for the link settings page.
+ *
* @ingroup themeable
* @ingroup print_themeable
*/
@@ -161,7 +181,7 @@ function theme_print_ui_settings($variables) {
$item = $form['settings'][$group][$elem]['print_' . $format . '_' . $elem];
if (empty($row)) {
- // Start row, fill title and description
+ // Start row, fill title and description.
$row_desc = array(
'#type' => 'item',
'#markup' => isset($item['#title']) ? $item['#title'] : '',
@@ -182,7 +202,11 @@ function theme_print_ui_settings($variables) {
$rows[] = $row;
}
- $form['settings'][$group]['#children'] = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions')));
+ $form['settings'][$group]['#children'] = theme('table', array(
+ 'header' => $header,
+ 'rows' => $rows,
+ 'attributes' => array('id' => 'permissions'),
+ ));
}
$output = drupal_render_children($form);
diff --git a/print_ui/print_ui.api.php b/print_ui/print_ui.api.php
index 75a6d75..9f37003 100644
--- a/print_ui/print_ui.api.php
+++ b/print_ui/print_ui.api.php
@@ -76,23 +76,18 @@ function hook_link_allowed($args) {
}
/**
- * Checks if the link is allowed according to the appropriate sub-module.
+ * Allows the user to change the new window behaviour.
*
- * Normally checks if the user holds the required access permission, but can
- * be used for extra checks, such as the proper module configuration, etc.
- *
- * @param array $args
- * An associative array containing:
- * - path: path to the non-node page being displayed.
- * - node: path to the node beign displayed.
- * - view_mode: current view mode of the node being displayed.
- * - type: 'node' or 'comment'.
+ * @param string $new_window
+ * New window status.
+ * @param string $format
+ * Format being processed.
*
* @ingroup print_hooks
*/
function hook_print_new_window_alter(&$new_window, $format) {
if ($format == 'foo') {
- $new_window = variable_get('print_foo_new_windo', FALSE);
+ $new_window = variable_get('print_foo_new_window', FALSE);
}
}
diff --git a/print_ui/print_ui.install b/print_ui/print_ui.install
index 54c1aec..8e096cf 100644
--- a/print_ui/print_ui.install
+++ b/print_ui/print_ui.install
@@ -11,7 +11,7 @@
* Implements hook_enable().
*/
function print_ui_enable() {
- // Module weight
+ // Module weight.
db_update('system')
->fields(array(
'weight' => 1,
diff --git a/print_ui/print_ui.module b/print_ui/print_ui.module
index 3affdb3..f1b4bc4 100644
--- a/print_ui/print_ui.module
+++ b/print_ui/print_ui.module
@@ -91,9 +91,9 @@ function print_ui_block_view($delta = '') {
if (ctype_digit($nid)) {
$node = node_load($nid);
if (!node_access('view', $node)) {
- // If the user doesn't have access to the node, don't show any links
+ // If the user doesn't have access to the node, don't show any links.
$block['content'] = '';
- return;
+ return array();
}
}
else {
@@ -150,6 +150,7 @@ function print_ui_help($path, $arg) {
}
}
}
+ return '';
}
/**
@@ -166,10 +167,12 @@ function print_ui_node_view_alter(&$build) {
if (!empty($link_pos['link'])) {
$format = theme('print_ui_format_link', array('format' => 'html', 'location' => 'link'));
+ $path = '';
switch ($book_link) {
case 1:
$path = $build['links']['book']['#links']['book_printer']['href'];
break;
+
case 2:
$link_use_alias = variable_get('print_html_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT);
$path = ($link_use_alias && ($alias = drupal_lookup_path('alias', 'node/' . $build['#node']->nid))) ? $alias : $build['#node']->nid;
@@ -205,23 +208,27 @@ function print_ui_node_view($node, $view_mode) {
$link_use_alias = variable_get('print_' . $link['format'] . '_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT);
if (!preg_match('!^node/[\d]*/revisions/[\d]*/view$!', $_GET['q'])) {
- // Not a revision, use node->nid to build the path
+ // Not a revision, use node->nid to build the path.
$path = (($link_use_alias) && ($alias = drupal_lookup_path('alias', 'node/' . $node->nid))) ? $alias : $node->nid;
}
else {
- // This is a node revision, replace only the node component
+ // This is a node revision, replace only the node component.
$path = preg_replace('!^node/!', '', $_GET['q']);
}
$path = $link['path'] . '/' . $path;
foreach (array('node', 'comment') as $type) {
- $allowed_type = print_ui_link_allowed($link, array('type' => $type, 'node' => $node, 'view_mode' => $view_mode));
+ $allowed_type = print_ui_link_allowed($link, array(
+ 'type' => $type,
+ 'node' => $node,
+ 'view_mode' => $view_mode,
+ ));
if ($allowed_type) {
drupal_add_css(drupal_get_path('module', 'print_ui') . '/css/print_ui.theme.css');
$links = array();
$format = theme('print_ui_format_link', array('format' => $link['format'], 'location' => 'link'));
- // Show book link
+ // Show book link.
if ($allowed_type === PRINT_UI_ALLOW_BOOK_LINK) {
$path = $link['path'] . '/book/export/html/' . $node->nid;
@@ -238,7 +245,7 @@ function print_ui_node_view($node, $view_mode) {
'title' => $format['text'],
'attributes' => $format['attributes'],
'html' => $format['html'],
- 'query' => _print_ui_query_string_encode($_GET, array('q')),
+ 'query' => _print_ui_query_string_encode($_GET, array('q')),
);
}
@@ -248,7 +255,8 @@ function print_ui_node_view($node, $view_mode) {
'#attributes' => array('class' => array('links', 'inline')),
);
- // If it's a node, and configured to show the link, but it's not the html version of a book then show it
+ // If it's a node, and configured to show the link, but it's not the
+ // html version of a book then show it.
if (($type == 'node') && !empty($link_pos['link']) && !(isset($node->book) && ($link['format'] == 'html'))) {
$node->content['links']['print_' . $link['format']] = $link_content;
}
@@ -264,13 +272,17 @@ function print_ui_node_view($node, $view_mode) {
}
if (!empty($link_pos['corner'])) {
- $corner_markup .= print_ui_insert_link($link, array('node' => $node, 'path' => $path, 'location' => 'corner'));
+ $corner_markup .= print_ui_insert_link($link, array(
+ 'node' => $node,
+ 'path' => $path,
+ 'location' => 'corner',
+ ));
}
}
}
if (($view_mode == 'full') && (!empty($corner_markup))) {
- // Insert content corner links
+ // Insert content corner links.
$node->content['print_links'] = array(
'#prefix' => '<span class="print-link">',
'#markup' => $corner_markup,
@@ -296,7 +308,7 @@ function print_ui_node_load($nodes, $types) {
$display = 'print_' . $link['format'] . '_display';
$display_comment = 'print_' . $link['format'] . '_display_comment';
- $display_urllist = 'print_' . $link['format'] . '_display_urllist';
+ $display_urllist = 'print_' . $link['format'] . '_display_urllist';
$result = db_query('SELECT nid, link, comments, url_list FROM {' . $module . '_node_conf} WHERE nid IN (:nids)', array(':nids' => $ids))->fetchAllAssoc('nid');
@@ -313,7 +325,7 @@ function print_ui_node_load($nodes, $types) {
* Implements hook_node_insert().
*/
function print_ui_node_insert($node) {
- return print_ui_node_update($node);
+ print_ui_node_update($node);
}
/**
@@ -328,7 +340,7 @@ function print_ui_node_update($node) {
$display = 'print_' . $link['format'] . '_display';
$display_comment = 'print_' . $link['format'] . '_display_comment';
- $display_urllist = 'print_' . $link['format'] . '_display_urllist';
+ $display_urllist = 'print_' . $link['format'] . '_display_urllist';
if (!isset($node->{$display}) || $node->{$display} === NULL) {
$node->{$display} = variable_get($display . '_' . $node->type, PRINT_UI_TYPE_SHOW_LINK_DEFAULT);
@@ -360,7 +372,7 @@ function print_ui_node_delete($node) {
foreach (module_implements('print_link') as $module) {
$function = $module . '_print_link';
if (function_exists($function)) {
- $link = call_user_func_array($function, array());
+ call_user_func_array($function, array());
db_delete($module . '_node_conf')
->condition('nid', $node->nid)
@@ -373,7 +385,8 @@ function print_ui_node_delete($node) {
* Implements hook_form_alter().
*/
function print_ui_form_alter(&$form, &$form_state, $form_id) {
- // Add the node-type settings option to activate the printer-friendly version link
+ // Add the node-type settings option to activate the printer-friendly
+ // version link.
if ((user_access('administer print') || user_access('node-specific print configuration')) &&
(($form_id == 'node_type_form') || !empty($form['#node_edit_form']))) {
$form['print'] = array(
@@ -398,7 +411,7 @@ function print_ui_form_alter(&$form, &$form_state, $form_id) {
$display = 'print_' . $link['format'] . '_display';
$display_comment = 'print_' . $link['format'] . '_display_comment';
- $display_urllist = 'print_' . $link['format'] . '_display_urllist';
+ $display_urllist = 'print_' . $link['format'] . '_display_urllist';
$form['print']['print_' . $link['format']][$display] = array(
'#type' => 'checkbox',
@@ -430,14 +443,14 @@ function print_ui_form_alter(&$form, &$form_state, $form_id) {
}
/**
- * Auxiliary function to fill the Printer-friendly link attributes
+ * Auxiliary function to fill the Printer-friendly link attributes.
*
* @param string $title
- * text to displayed by the link when hovering over it with the mouse
+ * Text to displayed by the link when hovering over it with the mouse.
* @param string $class
- * class attribute to be used in the link
+ * Class attribute to be used in the link.
* @param bool $new_window
- * if TRUE opens the target page in a new window
+ * If TRUE opens the target page in a new window.
*
* @return array
* An associative array containing:
@@ -460,12 +473,13 @@ function _print_ui_fill_attributes($title = '', $class = '', $new_window = FALSE
if ($new_window) {
switch ($print_newwindow) {
- case 0:
- $attributes['target'] = '_blank';
- break;
- case 1:
- $attributes['onclick'] = 'window.open(this.href); return false';
- break;
+ case 0:
+ $attributes['target'] = '_blank';
+ break;
+
+ case 1:
+ $attributes['onclick'] = 'window.open(this.href); return false';
+ break;
}
}
if (!empty($print_robots_noindex)) {
@@ -475,7 +489,7 @@ function _print_ui_fill_attributes($title = '', $class = '', $new_window = FALSE
}
/**
- * Format the Printer-friendly link
+ * Format the Printer-friendly link.
*
* @return array
* An associative array containing:
@@ -508,14 +522,30 @@ function theme_print_ui_format_link($vars) {
$show_link = variable_get('print_' . $link['format'] . '_show_link', PRINT_UI_SHOW_LINK_DEFAULT);
$link_text = filter_xss(variable_get('print_' . $link['format'] . '_link_text', $link['text']));
+ $text = '';
if ($show_link >= 2) {
$img = drupal_get_path('module', $module) . '/icons/' . $link['icon'];
switch ($show_link) {
case 2:
- $text = theme('image', array('path' => $img, 'width' => '16px', 'height' => '16px', 'alt' => $link_text, 'title' => $link_text, 'attributes' => array('class' => array('print-icon'))));
+ $text = theme('image', array(
+ 'path' => $img,
+ 'width' => '16px',
+ 'height' => '16px',
+ 'alt' => $link_text,
+ 'title' => $link_text,
+ 'attributes' => array('class' => array('print-icon')),
+ ));
break;
+
case 3:
- $text = theme('image', array('path' => $img, 'width' => '16px', 'height' => '16px', 'alt' => $link_text, 'title' => $link_text, 'attributes' => array('class' => array('print-icon', 'print-icon-margin')))) . $link_text;
+ $text = theme('image', array(
+ 'path' => $img,
+ 'width' => '16px',
+ 'height' => '16px',
+ 'alt' => $link_text,
+ 'title' => $link_text,
+ 'attributes' => array('class' => array('print-icon', 'print-icon-margin')),
+ )) . $link_text;
break;
}
$html = TRUE;
@@ -533,16 +563,17 @@ function theme_print_ui_format_link($vars) {
}
}
}
+ return array();
}
/**
- * Auxiliary function to display a formatted Printer-friendly link
+ * Auxiliary function to display a formatted Printer-friendly link.
*
* Function made available so that developers may call this function from
* their defined pages/blocks.
*
* @param array $link
- * array returned by the hook_print_link() call.
+ * Array returned by the hook_print_link() call.
* @param array $args
* Array of optional arguments:
* - node: node object, to be used in checking node access. If the path
@@ -599,7 +630,12 @@ function print_ui_insert_link($link, $args = array()) {
}
drupal_add_css(drupal_get_path('module', 'print_ui') . '/css/print_ui.theme.css');
$format = theme('print_ui_format_link', array('format' => $link['format'], 'location' => $location));
- return '<span class="print_' . $link['format'] . '">' . l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) . '</span>';
+ return '<span class="print_' . $link['format'] . '">' . l($format['text'], $path, array(
+ 'attributes' => $format['attributes'],
+ 'query' => $query,
+ 'absolute' => TRUE,
+ 'html' => $format['html'],
+ )) . '</span>';
}
else {
return FALSE;
@@ -607,15 +643,15 @@ function print_ui_insert_link($link, $args = array()) {
}
/**
- * Check if the link to the PF version is allowed depending on the settings
+ * Check if the link to the PF version is allowed depending on the settings.
*
* @param array $link
- * array returned by the hook_print_link() call.
+ * Array returned by the hook_print_link() call.
* @param array $args
- * array containing the possible parameters:
- * view_mode, node, type, path
+ * Array containing the possible parameters:
+ * view_mode, node, type, path.
*
- * @return
+ * @return int
* FALSE if not allowed
* PRINT_UI_ALLOW_NORMAL_LINK if a normal link is allowed
* PRINT_UI_ALLOW_BOOK_LINK if a link is allowed in a book node
@@ -625,14 +661,14 @@ function print_ui_link_allowed($link, $args) {
$view_mode = $args['view_mode'];
if ((($view_mode == 'teaser') && !variable_get('print_' . $link['format'] . '_link_teaser', PRINT_UI_LINK_TEASER_DEFAULT))
|| !in_array($view_mode, array('full', 'teaser'))) {
- // If the teaser link is disabled
+ // If the teaser link is disabled.
return FALSE;
}
}
$link_allowed_func = $link['module'] . '_link_allowed';
if (function_exists($link_allowed_func)) {
if (!$link_allowed_func($args)) {
- // If the format-specific function disallows the link
+ // If the format-specific function disallows the link.
return FALSE;
}
}
@@ -649,7 +685,7 @@ function print_ui_link_allowed($link, $args) {
if (isset($node->type)) {
$node_type = $node->type;
}
- // Node
+ // Node.
if (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.
@@ -663,14 +699,14 @@ function print_ui_link_allowed($link, $args) {
}
}
else {
- // Node link
+ // Node link.
$display = 'print_' . $link['format'] . '_display';
if (isset($node->{$display}) && !$node->{$display}) {
- // Link for this node is disabled
+ // Link for this node is disabled.
return FALSE;
}
elseif (isset($node->book)) {
- // Node is a book;
+ // Node is a book.
$book_link = variable_get('print_' . $link['format'] . '_book_link', PRINT_UI_BOOK_LINK_DEFAULT);
switch ($book_link) {
case 1:
@@ -678,6 +714,7 @@ function print_ui_link_allowed($link, $args) {
return PRINT_UI_ALLOW_BOOK_LINK;
}
break;
+
case 2:
return PRINT_UI_ALLOW_NORMAL_LINK;
}
@@ -688,7 +725,7 @@ function print_ui_link_allowed($link, $args) {
}
}
else {
- // 'System' page
+ // 'System' page.
$sys_link_visibility = variable_get('print_' . $link['format'] . '_sys_link_visibility', PRINT_UI_SYS_LINK_VISIBILITY_DEFAULT);
$sys_link_pages = variable_get('print_' . $link['format'] . '_sys_link_pages', PRINT_UI_SYS_LINK_PAGES_DEFAULT);
@@ -698,16 +735,16 @@ function print_ui_link_allowed($link, $args) {
}
/**
- * Check if the provided page is enabled according to the visibility settings
+ * Check if the provided page is enabled according to the visibility settings.
*
* @param int $visibility
- * current visibility settings:
+ * Current visibility settings:
* 0 for show on every page except the listed pages
- * 1 for show on only the listed pages
+ * 1 for show on only the listed pages.
* @param string $path
- * current path
+ * Current path.
* @param string $pages
- * list of pages
+ * List of pages.
*
* @return bool
* TRUE if it is enabled, FALSE otherwise
@@ -742,7 +779,7 @@ function _print_ui_page_match($visibility, $path, $pages) {
* encoded original. (see #301192)
*
* @param array $query
- * The array to be processed e.g. $_GET
+ * The array to be processed e.g. $_GET.
* @param array $exclude
* The array filled with keys to be excluded.
* @param string $parent
diff --git a/tests/print_basic.test b/tests/print_basic.test
index 0306838..e279894 100644
--- a/tests/print_basic.test
+++ b/tests/print_basic.test
@@ -2,21 +2,24 @@
/**
* @file
- * print module simpletest tests
+ * Print module simpletest tests.
*
* This file includes the defined tests for the print module.
*
* @ingroup print
*/
+/**
+ * Class PrintBasicTest.
+ */
class PrintBasicTest extends DrupalWebTestCase {
- protected $web_user;
+ protected $webUser;
protected $getq;
/**
* Implementation of getInfo().
*/
- function getInfo() {
+ public function getInfo() {
return array(
'name' => t('Printer, email and PDF versions tests'),
'description' => t('Unit tests for the print, print_mail and print_pdf modules.'),
@@ -27,14 +30,16 @@ class PrintBasicTest extends DrupalWebTestCase {
/**
* Implementation of setUp().
*/
- function setUp() {
+ public function setUp() {
parent::setUp();
// User to set up print.
-// $this->web_user = $this->drupalCreateUserRolePerm(array('administer print'));
+ /*
+ $this->webUser = $this->drupalCreateUserRolePerm(array('administer print'));
-// $this->drupalGet('logout');
-// $this->drupalLoginUser($this->web_user);
+ $this->drupalGet('logout');
+ $this->drupalLoginUser($this->webUser);
+ */
$this->getq = $_GET['q'];
$_GET['q'] = 'print/' . $_GET['q'];
@@ -43,16 +48,20 @@ class PrintBasicTest extends DrupalWebTestCase {
/**
* Implementation of tearDown().
*/
- function tearDown() {
+ public function tearDown() {
$_GET['q'] = $this->getq;
parent::tearDown();
}
- function testPrintRewriteUrls() {
+ /**
+ * Test rewrite of URLs.
+ */
+ public function testPrintRewriteUrls() {
global $base_url, $base_root, $_print_urls;
- // Must require it, since this function gets called via Drupal's dynamic loading
+ // Must require it, since this function gets called via Drupal's dynamic
+ // loading.
module_load_include('inc', 'print', 'print.pages');
variable_set('print_urls_anchors', 1);
@@ -110,4 +119,5 @@ class PrintBasicTest extends DrupalWebTestCase {
$this->assertEqual($urls[0], $abs_url[$i], t('Absolute URL (!url)', array('!url' => $abs_url[$i])));
}
}
+
}