updated print
This commit is contained in:
@@ -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().
|
||||
|
@@ -4,9 +4,8 @@ core = 7.x
|
||||
package = "Printer, email and PDF versions"
|
||||
dependencies[] = print_epub
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-04-02
|
||||
version = "7.x-2.0"
|
||||
; Information added by Drupal.org packaging script on 2018-10-05
|
||||
version = "7.x-2.2"
|
||||
core = "7.x"
|
||||
project = "print"
|
||||
datestamp = "1396426766"
|
||||
|
||||
datestamp = "1538760185"
|
||||
|
@@ -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;
|
||||
}
|
@@ -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,9 +17,21 @@ function print_epub_phpepub_requirements($phase) {
|
||||
* version number of the library
|
||||
*/
|
||||
function _print_epub_phpepub_version($epub_tool) {
|
||||
require_once(DRUPAL_ROOT . '/' . $epub_tool);
|
||||
if (file_exists(DRUPAL_ROOT . '/' . $epub_tool)) {
|
||||
include_once DRUPAL_ROOT . '/' . $epub_tool;
|
||||
|
||||
return EPub::VERSION;
|
||||
$phpepub_version_4_plus = strpos($epub_tool, 'autoload.php') !== FALSE;
|
||||
if ($phpepub_version_4_plus) {
|
||||
return \PHPePub\Core\EPub::VERSION;
|
||||
}
|
||||
else {
|
||||
if (class_exists('EPub')) {
|
||||
return EPub::VERSION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,4 +44,12 @@ function print_epub_phpepub_print_epub_available_libs_alter(&$epub_tools) {
|
||||
foreach ($tools as $tool) {
|
||||
$epub_tools['print_epub_phpepub|' . $tool] = 'PHPePub (' . dirname($tool) . ')';
|
||||
}
|
||||
|
||||
// PHPePub >= 4.0 uses a composer autoloader.
|
||||
$tools = _print_scan_libs('phpepub', '!^autoload.php$!');
|
||||
foreach ($tools as $tool) {
|
||||
if (preg_match('!PHPePub.*?/vendor/autoload.php$!i', $tool)) {
|
||||
$epub_tools['print_epub_phpepub|' . $tool] = 'PHPePub (' . dirname(dirname($tool)) . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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,16 +21,29 @@ 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]);
|
||||
$tool_path = DRUPAL_ROOT . '/' . $epub_tool[1];
|
||||
if (file_exists($tool_path)) {
|
||||
require_once $tool_path;
|
||||
}
|
||||
else {
|
||||
watchdog('print_epub', 'Configured EPUB tool does not exist at path: %path', array('%path' => $tool_path), WATCHDOG_ERROR);
|
||||
throw new Exception("Configured EPUB tool does not exist, unable to generate EPUB.");
|
||||
}
|
||||
|
||||
// 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);
|
||||
$version = _print_epub_phpepub_version($epub_tool[1]);
|
||||
|
||||
// set document information
|
||||
$epub = new EPub();
|
||||
// Set document information.
|
||||
if (version_compare($version, '4.0.0', '>=')) {
|
||||
$epub = new \PHPePub\Core\EPub();
|
||||
}
|
||||
else {
|
||||
$epub = new EPub();
|
||||
}
|
||||
|
||||
$epub->setTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
|
||||
$epub->setIdentifier($meta['url'], EPub::IDENTIFIER_URI);
|
||||
$epub->setIdentifier($meta['url'], $epub::IDENTIFIER_URI);
|
||||
$epub->setLanguage($language->language);
|
||||
if (isset($meta['name'])) {
|
||||
$epub->setAuthor(strip_tags($meta['name']), strip_tags($meta['name']));
|
||||
@@ -40,9 +53,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;
|
||||
}
|
||||
|
@@ -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',
|
||||
@@ -53,14 +53,9 @@ function print_epub_settings() {
|
||||
);
|
||||
if (module_exists('token')) {
|
||||
$form['settings']['print_epub_filename_patterns'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Replacement patterns'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['settings']['print_epub_filename_patterns']['descriptions'] = array(
|
||||
'#theme' => 'token_tree',
|
||||
'#token_types' => array('node'),
|
||||
'#dialog' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -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';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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();
|
||||
|
@@ -5,9 +5,8 @@ package = "Printer, email and PDF versions"
|
||||
dependencies[] = print
|
||||
configure = admin/config/user-interface/print/epub
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-04-02
|
||||
version = "7.x-2.0"
|
||||
; Information added by Drupal.org packaging script on 2018-10-05
|
||||
version = "7.x-2.2"
|
||||
core = "7.x"
|
||||
project = "print"
|
||||
datestamp = "1396426766"
|
||||
|
||||
datestamp = "1538760185"
|
||||
|
@@ -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,
|
||||
@@ -49,6 +47,42 @@ function print_epub_uninstall() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function print_epub_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)) {
|
||||
$requirements['print_epub_tool'] = array(
|
||||
'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
|
||||
'value' => $t('No EPUB tool selected'),
|
||||
'description' => $t('Please configure it in the !url.', array('!url' => l($t('EPUB settings page'), 'admin/config/user-interface/print/epub'))),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$tool = explode('|', $print_epub_epub_tool);
|
||||
|
||||
if (!is_file($tool[1]) || !is_readable($tool[1])) {
|
||||
$requirements['print_epub_tool'] = array(
|
||||
'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
|
||||
'value' => $t('File not found'),
|
||||
'description' => $t('The currently selected EPUB generation library (%file) is no longer accessible.', array('%file' => $tool[1])),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
@@ -122,7 +156,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 +173,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 +183,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')));
|
||||
}
|
||||
|
@@ -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) {
|
||||
@@ -120,41 +121,6 @@ function print_epub_block_view($delta = 0) {
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function print_epub_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)) {
|
||||
$requirements['print_epub_tool'] = array(
|
||||
'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
|
||||
'value' => $t('No EPUB tool selected'),
|
||||
'description' => $t('Please configure it in the !url.', array('!url' => l($t('EPUB settings page'), 'admin/config/user-interface/print/epub'))),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$tool = explode('|', $print_epub_epub_tool);
|
||||
|
||||
if (!is_file($tool[1]) || !is_readable($tool[1])) {
|
||||
$requirements['print_epub_tool'] = array(
|
||||
'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
|
||||
'value' => $t('File not found'),
|
||||
'description' => $t('The currently selected EPUB generation library (%file) is no longer accessible.', array('%file' => $tool[1])),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_delete().
|
||||
*/
|
||||
@@ -165,7 +131,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 +142,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 +152,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 +164,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 +183,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()
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -72,10 +74,10 @@ function print_epub_controller() {
|
||||
|
||||
$nodepath = (isset($node->nid)) ? 'node/' . $node->nid : drupal_get_normal_path($path);
|
||||
db_merge('print_epub_page_counter')
|
||||
->key(array('path' => $nodepath))
|
||||
->key(array('path' => substr($nodepath, 0, 255)))
|
||||
->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);
|
||||
}
|
||||
|
@@ -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.'),
|
||||
|
Reference in New Issue
Block a user