function print_epub_controller in Printer, email and PDF versions 7.2
Generate a EPUB version of the printer-friendly page.
See also
_print_epub_domepub()
_print_epub_tcepub()
1 string reference to 'print_epub_controller'
- print_epub_menu in print_epub/
print_epub.module - Implements hook_menu().
File
- print_epub/
print_epub.pages.inc, line 22
Code
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']);
$node = NULL;
if (!empty($path)) {
if ($alias = drupal_lookup_path('source', $path)) {
// Alias.
$path_arr = explode('/', $alias);
$node = node_load($path_arr[1]);
}
elseif (ctype_digit($args[0])) {
// Normal nid.
$node = node_load($args[0]);
}
$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' => substr($nodepath, 0, 255),
))
->fields(array(
'totalcount' => 1,
'timestamp' => REQUEST_TIME,
))
->expression('totalcount', 'totalcount + 1')
->execute();
drupal_exit();
}