-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathathenapdf.callbacks.inc
43 lines (39 loc) · 1.01 KB
/
athenapdf.callbacks.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Callback for menu: node/%node/pdf
* Redirects to a PDF file for the given node, generating the file if required.
*
* @param $node
* The currently processed node object.
*/
function athenapdf_view_node_page($node) {
// Display the pdf file if already exists.
$fid = athenapdf_get_cached_file($node->nid);
if (empty($fid)) {
// Try to generate the PDF file for the given node.
$file = athenapdf_create_for_node($node);
}
else {
$file = file_load($fid);
}
// Report an error if we could not generate the PDF files.
if (!$file) {
watchdog(
'athenapdf',
'Could not generate pdf for node: @nid',
['@nid' => $node->nid],
WATCHDOG_ERROR
);
drupal_set_message(
t(
"We're sorry but the PDF for the current page is not available, please try again later"
),
'error',
FALSE
);
drupal_goto('node/' . $node->nid);
}
$url = file_create_url($file->uri);
header('Location: ' . $url . '', TRUE, 302);
drupal_exit($url);
}