function print_pdf_controller in Printer, email and PDF versions 7
Same name and namespace in other branches
- 5.4 print_pdf/print_pdf.pages.inc \print_pdf_controller()
- 5.3 print_pdf/print_pdf.pages.inc \print_pdf_controller()
- 6 print_pdf/print_pdf.pages.inc \print_pdf_controller()
- 7.2 print_pdf/print_pdf.pages.inc \print_pdf_controller()
- 5.x print_pdf/print_pdf.pages.inc \print_pdf_controller()
Generate a PDF version of the printer-friendly page
See also
1 string reference to 'print_pdf_controller'
- print_pdf_menu in print_pdf/
print_pdf.module - Implements hook_menu().
File
- print_pdf/
print_pdf.pages.inc, line 22
Code
function print_pdf_controller() {
// Disable caching for generated PDFs, 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]);
}
$pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT);
if (!empty($pdf_filename) && !empty($node)) {
$pdf_filename = token_replace($pdf_filename, array(
'node' => $node,
), array(
'clear' => TRUE,
));
}
else {
$pdf_filename = token_replace($pdf_filename, array(
'site',
), array(
'clear' => TRUE,
));
if (empty($pdf_filename)) {
// If empty, use a fallback solution
$pdf_filename = str_replace('/', '_', $path);
}
}
}
else {
$pdf_filename = 'page';
}
if (function_exists('transliteration_clean_filename')) {
$pdf_filename = transliteration_clean_filename($pdf_filename, language_default('language'));
}
drupal_alter('print_pdf_filename', $pdf_filename, $path);
$pdf = print_pdf_generate_path($path, $query, $cid, $pdf_filename . '.pdf');
if ($pdf == NULL) {
drupal_goto($path);
exit;
}
$nodepath = isset($node->path) && is_string($node->path) ? drupal_get_normal_path($node->path) : 'node/' . $path;
db_merge('print_pdf_page_counter')
->key(array(
'path' => $nodepath,
))
->fields(array(
'totalcount' => 1,
'timestamp' => REQUEST_TIME,
))
->expression('totalcount', 'totalcount + 1')
->execute();
drupal_exit();
}