1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Generates the EPUB version using PHPePub.
|
6
|
*
|
7
|
* This file is included by the print_epub_phpepub module and includes the
|
8
|
* functions that interface with the PHPePub library.
|
9
|
*
|
10
|
* @ingroup print
|
11
|
*/
|
12
|
|
13
|
/**
|
14
|
* Implements hook_print_epub_generate().
|
15
|
*/
|
16
|
function print_epub_phpepub_print_epub_generate($html, $meta, $filename = NULL) {
|
17
|
global $language, $base_url;
|
18
|
|
19
|
module_load_include('inc', 'print', 'includes/print');
|
20
|
|
21
|
$epub_tool = explode('|', variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT));
|
22
|
$images_via_file = variable_get('print_epub_images_via_file', PRINT_EPUB_IMAGES_VIA_FILE_DEFAULT);
|
23
|
|
24
|
$tool_path = DRUPAL_ROOT . '/' . $epub_tool[1];
|
25
|
if (file_exists($tool_path)) {
|
26
|
require_once $tool_path;
|
27
|
}
|
28
|
else {
|
29
|
watchdog('print_epub', 'Configured EPUB tool does not exist at path: %path', array('%path' => $tool_path), WATCHDOG_ERROR);
|
30
|
throw new Exception("Configured EPUB tool does not exist, unable to generate EPUB.");
|
31
|
}
|
32
|
|
33
|
// Try to use local file access for image files.
|
34
|
$html = _print_access_images_via_file($html, $images_via_file);
|
35
|
|
36
|
// Set document information.
|
37
|
$epub = new EPub();
|
38
|
|
39
|
$epub->setTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
|
40
|
$epub->setIdentifier($meta['url'], EPub::IDENTIFIER_URI);
|
41
|
$epub->setLanguage($language->language);
|
42
|
if (isset($meta['name'])) {
|
43
|
$epub->setAuthor(strip_tags($meta['name']), strip_tags($meta['name']));
|
44
|
}
|
45
|
$epub->setPublisher(variable_get('site_name', 'Drupal'), $base_url);
|
46
|
$epub->setSourceURL($meta['url']);
|
47
|
|
48
|
@$epub->addChapter("Chapter", "epub.html", $html, FALSE);
|
49
|
|
50
|
// Finalize the book, and build the archive.
|
51
|
$epub->finalize();
|
52
|
|
53
|
// Close and output EPUB document.
|
54
|
$epub->sendBook(empty($filename) ? 'page' : $filename);
|
55
|
return TRUE;
|
56
|
}
|