View source
<?php
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]');
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',
);
}
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.'),
),
);
}
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;
}
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;
}
function print_epub_block_info() {
$block['print_epub-top']['info'] = t('Most EPUBed');
$block['print_epub-top']['cache'] = DRUPAL_CACHE_GLOBAL;
return $block;
}
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();
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;
}
function print_epub_node_delete($node) {
db_delete('print_epub_page_counter')
->condition('path', 'node/' . $node->nid)
->execute();
}
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;
}
}
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);
}
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;
}
function print_epub_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'print_epub'),
);
}