security updates

have to check views and entityreference for custom patches
This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 20:45:16 +02:00
parent 802ec0c6f3
commit b3221c71e2
516 changed files with 14267 additions and 7349 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

View File

@@ -0,0 +1,32 @@
<?php
/**
* @file
* drush integration for print_epub_phpepub module EPUB libraries download.
*/
/**
* 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');
/**
* Implements hook_drush_command().
*/
function print_epub_phpepub_drush_epub_libs_alter(&$epub_libs) {
$epub_libs['phpepub'] = array(
'callback' => '_print_epub_phpepub_drush_download_url',
);
}
/**
* Discover the correct URL of the package to download.
*
* @return string
* URL of the file to download, FALSE if not known
*/
function _print_epub_phpepub_drush_download_url() {
return PHPEPUB_DOWNLOAD_URI;
}

View File

@@ -0,0 +1,12 @@
name = "PHPePub library handler"
description = "EPUB generation library using PHPePub."
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"
core = "7.x"
project = "print"
datestamp = "1396426766"

View File

@@ -0,0 +1,65 @@
<?php
/**
* @file
* Generate a EPUB for the print_epub module using the PHPePub library.
*
* @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;
}
/**
* Find out the version of the PHPePub library
*
* @param string $epub_tool
* Filename of the tool to be analysed.
*
* @return string
* version number of the library
*/
function _print_epub_phpepub_version($epub_tool) {
require_once(DRUPAL_ROOT . '/' . $epub_tool);
return EPub::VERSION;
}
/**
* Implements hook_print_epub_available_libs_alter().
*/
function print_epub_phpepub_print_epub_available_libs_alter(&$epub_tools) {
module_load_include('inc', 'print', 'includes/print');
$tools = _print_scan_libs('phpepub', '!^EPub.php$!');
foreach ($tools as $tool) {
$epub_tools['print_epub_phpepub|' . $tool] = 'PHPePub (' . dirname($tool) . ')';
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* @file
* 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
*
* @ingroup print
*/
/**
* Implements hook_print_epub_generate().
*/
function print_epub_phpepub_print_epub_generate($html, $meta, $filename = NULL) {
global $language, $base_url;
module_load_include('inc', 'print', 'includes/print');
$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]);
// Try to use local file access for image files
$html = _print_access_images_via_file($html, $images_via_file);
// set document information
$epub = new EPub();
$epub->setTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
$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']));
}
$epub->setPublisher(variable_get('site_name', 'Drupal'), $base_url);
$epub->setSourceURL($meta['url']);
@$epub->addChapter("Chapter", "epub.html", $html, FALSE);
$epub->finalize(); // Finalize the book, and build the archive.
// Close and output EPUB document
$epub->sendBook(empty($filename) ? 'page' : $filename);
return TRUE;
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* @file
* Contains the administrative functions of the EPUB version module.
*
* This file is included by the EPUB version module, and includes the
* settings form.
*
* @ingroup print
*/
/**
* Form constructor for the EPUB version module settings form.
*
* @ingroup forms
*/
function print_epub_settings() {
$epub_tools = array();
drupal_alter('print_epub_available_libs', $epub_tools);
if (!empty($epub_tools)) {
$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;
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('EPUB options'),
);
$form['settings']['print_epub_epub_tool'] = array(
'#type' => 'radios',
'#title' => t('EPUB generation tool'),
'#options' => $epub_tools,
'#default_value' => $epub_tool_default,
'#description' => t('This option selects the EPUB generation tool being used by this module to create the EPUB version.'),
);
$form['settings']['print_epub_images_via_file'] = array(
'#type' => 'checkbox',
'#title' => t('Access images via local file access'),
'#default_value' => variable_get('print_epub_images_via_file', PRINT_EPUB_IMAGES_VIA_FILE_DEFAULT),
'#description' => t("Enabling this option will make the tool use local file access for image files. This option is not recommended to use in conjunction with modules like imagecache which generate the image after it's first accessed. However, it may be necessary in low-end hosting services where the web server is not allowed to open URLs and the user can't modify that configuration setting."),
);
$form['settings']['print_epub_filename'] = array(
'#type' => 'textfield',
'#title' => t('EPUB filename'),
'#default_value' => variable_get('print_epub_filename', PRINT_EPUB_FILENAME_DEFAULT),
'#description' => t("If left empty the generated filename defaults to the node's path. Tokens may be used to build the filename (see following list). The .epub extension will be appended automatically."),
);
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'),
);
}
$form['settings']['print_epub_display_sys_urllist'] = array(
'#type' => 'checkbox',
'#title' => t('Printer-friendly URLs list in system pages'),
'#default_value' => variable_get('print_epub_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
'#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
);
$form['settings']['link_text'] = array(
'#type' => 'fieldset',
'#title' => t('Custom link text'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['link_text']['print_epub_link_text_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable custom link text'),
'#default_value' => variable_get('print_epub_link_text_enabled', PRINT_TYPE_LINK_TEXT_ENABLED_DEFAULT),
);
$form['settings']['link_text']['print_epub_link_text'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('print_epub_link_text', $link['text']),
'#description' => t('Text used in the link to the EPUB version.'),
);
$form['#validate'][] = '_print_epub_settings_validate';
}
else {
variable_set('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
$form['settings'] = array(
'#type' => 'markup',
'#markup' => '<p>' . t("No EPUB generation tool found! Please download a supported PHP EPUB generation tool. Check this module's INSTALL.txt for more details.") . '</p>',
);
}
return system_settings_form($form);
}
/**
* Form validation handler for print_epub_settings().
*
* @see print_epub_settings()
* @ingroup forms
*/
function _print_epub_settings_validate($form, &$form_state) {
if (empty($form_state['values']['print_epub_epub_tool'])) {
form_set_error('print_epub_epub_tool', t("No EPUB tool selected"));
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* @file
* Hooks provided by the EPUB version module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Generate a EPUB version of the provided HTML.
*
* @param string $html
* 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
* @param string $filename
* (optional) Filename of the generated EPUB
*
* @return
* generated EPUB page, or NULL in case of error
*
* @see print_epub_controller_html()
* @ingroup print_hooks
*/
function hook_print_epub_generate($html, $meta, $filename = NULL) {
$epub = new EPUB();
$epub->writeHTML($html);
if ($filename) {
$epub->Output($filename);
return TRUE;
}
else {
return $epub->Output();
}
}
/**
* Alters the list of available EPUB libraries.
*
* During the configuration of the EPUB library to be used, the module needs
* to discover and display the available libraries. This function should use
* the internal _print_scan_libs() function which will scan both the module
* and the libraries directory in search of the unique file pattern that can
* be used to identify the library location.
*
* @param array $epub_tools
* An associative array using as key the format 'module|path', and as value
* a string describing the discovered library, where:
* - module: the machine name of the module that handles this library.
* - path: the path where the library is installed, relative to DRUPAL_ROOT.
* If the recommended path is used, it begins with sites/all/libraries.
* As a recommendation, the value should contain in parantheses the path
* where the library was found, to allow the user to distinguish between
* multiple install paths of the same library version.
*
* @ingroup print_hooks
*/
function hook_print_epub_available_libs_alter(&$epub_tools) {
module_load_include('inc', 'print', 'includes/print');
$tools = _print_scan_libs('foo', '!^foo.php$!');
foreach ($tools as $tool) {
$epub_tools['print_epub_foo|' . $tool] = 'foo (' . dirname($tool) . ')';
}
}
/**
* Alters the EPUB filename.
*
* Changes the value of the EPUB filename variable, just before it is used to
* create the file. When altering the variable, do not suffix it with the
* '.epub' extension, as the module will do that automatically.
*
* @param string $epub_filename
* 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.
*
* @ingroup print_hooks
*/
function hook_print_epub_filename_alter(&$epub_filename, &$path) {
$epub_filename = 'foo';
}
/**
* @} End of "addtogroup hooks".
*/

View File

@@ -0,0 +1,65 @@
<?php
/**
* @file
* drush integration for print_epub module EPUB libraries download.
*/
/**
* Implements hook_drush_command().
*/
function print_epub_drush_command() {
$items = array();
$epub_libs = array();
drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
$items['print-epub-download'] = array(
'description' => 'Download and extract a EPUB library.',
'arguments' => array(
'library' => dt('The EPUB library to download. Available choices: !libs.', array('!libs' => implode(', ', array_keys($epub_libs)))),
),
'options' => array(
'path' => dt('A path to the download folder. If omitted Drush will use the default location (@path).', array('@path' => 'sites/all/libraries')),
),
'aliases' => array('epubdl'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, // No site or config needed.
);
return $items;
}
/**
* Implements of 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)))));
}
}
/**
* Download and extract EPUB archive.
*
* @param string $library
* library to download
*/
function drush_print_epub_download($library) {
$epub_libs = array();
drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
if (isset($library) && isset($epub_libs[drupal_strtolower($library)])) {
$func = $epub_libs[drupal_strtolower($library)]['callback'];
$download_url = $func();
if ($download_url) {
_print_drush_download_lib($library, $download_url);
}
}
else {
drush_log(dt('Please specify a EPUB library. Available choices: !libs.', array('!libs' => implode(', ', array_keys($epub_libs)))), 'error');
}
}

View File

@@ -0,0 +1,13 @@
name = "EPUB version"
description = "Adds the capability to export pages as EPUB. Requires an EPUB library and the respective handler module."
core = 7.x
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"
core = "7.x"
project = "print"
datestamp = "1396426766"

View File

@@ -0,0 +1,159 @@
<?php
/**
* @file
* Install, update and uninstall functions for the print_epub module.
*
* @ingroup print
*/
/**
* Implements hook_enable().
*/
function print_epub_enable() {
$t = get_t();
// Module weight
db_update('system')
->fields(array(
'weight' => 4,
))
->condition('type', 'module')
->condition('name', 'print_epub')
->execute();
}
/**
* Implements hook_uninstall().
*/
function print_epub_uninstall() {
variable_del('print_epub_display_sys_urllist');
variable_del('print_epub_filename');
variable_del('print_epub_images_via_file');
variable_del('print_epub_link_text');
variable_del('print_epub_link_text_enabled');
variable_del('print_epub_epub_tool');
variable_del('print_epub_book_link');
variable_del('print_epub_link_class');
variable_del('print_epub_link_pos');
variable_del('print_epub_link_teaser');
variable_del('print_epub_link_use_alias');
variable_del('print_epub_show_link');
variable_del('print_epub_sys_link_pages');
variable_del('print_epub_sys_link_visibility');
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_epub\_display\_%'");
foreach ($settings as $variable) {
variable_del($variable->name);
}
}
/**
* Implements hook_schema().
*/
function print_epub_schema() {
$schema['print_epub_node_conf'] = array(
'description' => 'EPUB version node-specific configuration settings',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The {node}.nid of the node.',
),
'link' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Show link',
),
'comments' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Show link in individual comments',
),
'url_list' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Show Printer-friendly URLs list',
),
),
'primary key' => array('nid'),
);
$schema['print_epub_page_counter'] = array(
'description' => 'EPUB version access counter',
'fields' => array(
'path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Page path',
),
'totalcount' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'big',
'description' => 'Number of page accesses',
),
'timestamp' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Last access',
),
),
'primary key' => array('path'),
);
return $schema;
}
/**
* Remove hardcoded numeric deltas from all blocks
*/
function print_epub_update_7000(&$sandbox) {
$renamed_deltas = array(
'print_epub' => array(
'0' => 'print_epub-top',
),
);
update_fix_d7_block_deltas($sandbox, $renamed_deltas, array());
if (variable_get('print_epub_filename', '') == '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]') {
variable_set('print_epub_filename', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
}
}
/**
* 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" }'));
$link_pos['block'] = 'block';
$link_pos['help'] = 'help';
variable_set('print_epub_link_pos', $link_pos);
}
/**
* 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('primary key' => array('path')));
}

View File

@@ -0,0 +1,254 @@
<?php
/**
* @file
* Displays Printer-friendly versions of Drupal pages.
*
* @ingroup print
*/
define('PRINT_EPUB_EPUB_TOOL_DEFAULT', 0);
define('PRINT_EPUB_IMAGES_VIA_FILE_DEFAULT', 0);
define('PRINT_EPUB_FILENAME_DEFAULT', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
/**
* Implements hook_print_link().
*/
function print_epub_print_link() {
return array(
'format' => 'epub',
'text' => t('EPUB version'),
'description' => t('Display a EPUB version of this page.'),
'path' => 'printepub',
'class' => 'print-epub',
'icon' => 'epub_icon.png',
'module' => 'print_epub',
);
}
/**
* Implements hook_permission().
*/
function print_epub_permission() {
return array(
'access EPUB version' => array(
'title' => t('Access the EPUB version'),
'description' => t('View the EPUB versions and the links to them in the original pages.'),
),
);
}
/**
* Implements hook_menu().
*/
function print_epub_menu() {
$link = print_epub_print_link();
$items = array();
$items[$link['path']] = array(
'title' => 'Printer-friendly EPUB',
'page callback' => 'print_epub_controller',
'access arguments' => array('access EPUB version'),
'type' => MENU_CALLBACK,
'file' => 'print_epub.pages.inc',
);
$items[$link['path'] . '/' . $link['path']] = array(
'access callback' => FALSE,
);
$items['admin/config/user-interface/print/epub'] = array(
'title' => 'EPUB',
'description' => 'Configure the settings of the EPUB generation functionality.',
'page callback' => 'drupal_get_form',
'page arguments' => array('print_epub_settings'),
'access arguments' => array('administer print'),
'weight' => 3,
'type' => MENU_LOCAL_TASK,
'file' => 'print_epub.admin.inc',
);
$items['admin/config/user-interface/print/epub/options'] = array(
'title' => 'Options',
'weight' => -1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
return $items;
}
/**
* Implements hook_variable_info().
*/
function print_epub_variable_info($options) {
$link = print_epub_print_link();
$variable['print_epub_link_text'] = array(
'title' => t('EPUB version'),
'description' => t('Text used in the link to the EPUB version.'),
'type' => 'string',
'default' => t($link['text']),
);
return $variable;
}
/**
* Implements hook_block_info().
*/
function print_epub_block_info() {
$block['print_epub-top']['info'] = t('Most EPUBed');
$block['print_epub-top']['cache'] = DRUPAL_CACHE_GLOBAL;
return $block;
}
/**
* Implements hook_block_view().
*/
function print_epub_block_view($delta = 0) {
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();
if (count($result)) {
$items = array();
foreach ($result as $obj) {
$items[] = l(_print_get_title($obj->path), $obj->path);
}
$block['content'] = theme('item_list', array('items' => $items, 'type' => 'ul'));
}
break;
}
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().
*/
function print_epub_node_delete($node) {
db_delete('print_epub_page_counter')
->condition('path', 'node/' . $node->nid)
->execute();
}
/**
* Auxiliary function to display a formatted EPUB 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.
* @param object $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',
* 'block', 'help').
*
* @return bool
* string with the HTML link to the printer-friendly page
*
* @ingroup print_api
*/
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));
}
else {
return FALSE;
}
}
/**
* 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
*
* @return bool
* FALSE if not allowed, TRUE otherwise
*/
function print_epub_link_allowed($args) {
$print_epub_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
return (user_access('access EPUB version') && (!empty($print_epub_epub_tool)));
}
/**
* Generate a EPUB version of the provided HTML.
*
* @param string $html
* 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
* @param string $filename
* (optional) Filename of the generated EPUB
*
* @return
* generated EPUB page, or NULL in case of error
*
* @see print_epub_controller()
*
* @ingroup print_api
*/
function print_epub_generate_html($html, $meta, $filename = NULL) {
$epub_tool = explode('|', variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT));
module_load_include('inc', $epub_tool[0], $epub_tool[0] . '.pages');
$function = $epub_tool[0] . '_print_epub_generate';
if (function_exists($function)) {
return $function($html, $meta, $filename);
}
return NULL;
}
/**
* Implements hook_views_api().
*/
function print_epub_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'print_epub'),
);
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* @file
* 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.
*
* @ingroup print
*/
module_load_include('inc', 'print', 'print.pages');
/**
* 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
$GLOBALS['conf']['cache'] = FALSE;
$args = func_get_args();
$path = filter_xss(implode('/', $args));
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
// Handle the query
$query = $_GET;
unset($query['q']);
if (!empty($path)) {
if ($alias = drupal_lookup_path('source', $path)) {
// Alias
$path_arr = explode('/', $alias);
$node = node_load($path_arr[1]);
}
elseif (ctype_digit($args[0])) {
// normal nid
$node = node_load($args[0]);
}
$epub_filename = variable_get('print_epub_filename', PRINT_EPUB_FILENAME_DEFAULT);
if (!empty($epub_filename) && !empty($node)) {
$epub_filename = token_replace($epub_filename, array('node' => $node), array('clear' => TRUE));
}
else {
$epub_filename = token_replace($epub_filename, array('site'), array('clear' => TRUE));
if (empty($epub_filename)) {
// If empty, use a fallback solution
$epub_filename = str_replace('/', '_', $path);
}
}
}
else {
$epub_filename = 'page';
}
if (function_exists('transliteration_clean_filename')) {
$epub_filename = transliteration_clean_filename($epub_filename, language_default('language'));
}
drupal_alter('print_epub_filename', $epub_filename, $path);
$epub = print_epub_generate_path($path, $query, $cid, $epub_filename . '.epub');
if ($epub == NULL) {
drupal_goto($path);
exit;
}
$nodepath = (isset($node->nid)) ? 'node/' . $node->nid : drupal_get_normal_path($path);
db_merge('print_epub_page_counter')
->key(array('path' => $nodepath))
->fields(array(
'totalcount' => 1,
'timestamp' => REQUEST_TIME,
))
->expression('totalcount', 'totalcount + 1')
->execute();
drupal_exit();
}
/**
* Gennerate a EPUB for a given Drupal path.
*
* @param string $path
* 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
* @param int $cid
* (optional) comment ID of the comment to render.
* @param string $epub_filename
* (optional) filename of the generated EPUB
* @param string $view_mode
* (optional) view mode to be used when rendering the content
*
* @return
* 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']));
$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;
return print_epub_generate_html($html, $meta, $epub_filename);
}
else {
return NULL;
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* @file
* EPUB Version Views integration
*
* @ingroup print
*/
/**
* Implements hook_views_data().
*/
function print_epub_views_data() {
// The 'group' index will be used as a prefix in the UI for any of this
// table's fields, sort criteria, etc. so it's easy to tell where they came
// from.
$data['print_epub_node_conf']['table']['group'] = t('Printer-friendly version');
$data['print_epub_page_counter']['table']['group'] = t('Printer-friendly version');
// This table references the {node} table. The declaration below creates an
// 'implicit' relationship to the node table, so that when 'node' is the base
// table, the fields are automatically available.
$data['print_epub_node_conf']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
// 'type' => 'INNER',
);
$data['print_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
$data['print_epub_node_conf']['link'] = array(
'title' => t('EPUB: Show link'),
'help' => t('Whether to show the EPUB version link.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_epub_node_conf']['comments'] = array(
'title' => t('EPUB: Show link in individual comments'),
'help' => t('Whether to show the EPUB version link in individual comments.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_epub_node_conf']['url_list'] = array(
'title' => t('EPUB: Show Printer-friendly URLs list'),
'help' => t('Whether to show the URL list.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// print_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.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
$data['print_epub_page_counter']['timestamp'] = array(
'title' => t('EPUB: Last access'),
'help' => t("The date of the last access to the node's EPUB version."),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}