Commit 42a86d52 authored by jcnventura's avatar jcnventura

Issue #1280728: use the referring page when accessing printmail with no arguments.

parent b80ad20f
......@@ -71,8 +71,8 @@ function print_controller($path, $cid = NULL, $format = PRINT_HTML_FORMAT, $teas
$ref = $_SERVER['HTTP_REFERER'];
$path = preg_replace("!^$base_url/!", '', $ref);
if ($path === $ref) {
$path = '';
if (($path === $ref) || empty($path)) {
$path = variable_get('site_frontpage', 'node');
}
}
if ($alias = drupal_lookup_path('source', $path)) {
......
......@@ -23,6 +23,32 @@ require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'print') . '/print.pa
function print_mail_form($form, &$form_state) {
global $user;
// Remove the printmail/ prefix
$path_arr = explode('/', $_GET['q']);
unset($path_arr[0]);
$path = implode('/', $path_arr);
if (empty($path)) {
// If no path was provided, let's try to generate a page for the referer
global $base_url;
$ref = $_SERVER['HTTP_REFERER'];
$path = preg_replace("!^$base_url/!", '', $ref);
if (($path === $ref) || empty($path)) {
$path = variable_get('site_frontpage', 'node');
}
drupal_goto(PRINTMAIL_PATH . '/' . $path);
}
else if (ctype_digit($path_arr[1])) {
if (drupal_lookup_path('source', $path)) {
// This is a numeric alias
$path = drupal_get_normal_path($path);
}
else {
// normal nid
$path = 'node/' . $path;
}
}
$print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD);
if ((!user_access('administer print')) && (!flood_is_allowed('print_mail', $print_mail_hourly_threshold))) {
......@@ -37,20 +63,6 @@ function print_mail_form($form, &$form_state) {
$print_mail_teaser_choice = variable_get('print_mail_teaser_choice', PRINT_MAIL_TEASER_CHOICE_DEFAULT);
$form = array();
// Remove the printmail/ prefix
$path_arr = explode('/', $_GET['q']);
unset($path_arr[0]);
$path = implode('/', $path_arr);
if (ctype_digit($path_arr[1])) {
if (drupal_lookup_path('source', $path)) {
// This is a numeric alias
$path = drupal_get_normal_path($path);
}
else {
// normal nid
$path = 'node/' . $path;
}
}
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
$title = _print_get_title($path);
......
......@@ -27,22 +27,27 @@ function print_pdf_controller() {
$path = implode('/', $args);
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
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]);
}
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)) . '.pdf';
$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)) . '.pdf';
}
else {
$pdf_filename = str_replace('/', '_', $path) . '.pdf';
}
}
else {
$pdf_filename = str_replace('/', '_', $path) . '.pdf';
$pdf_filename = 'page.pdf';
}
if (function_exists('transliteration_clean_filename')) {
$pdf_filename = transliteration_clean_filename($pdf_filename, language_default('language'));
......@@ -296,7 +301,9 @@ function _print_pdf_tcpdf($print, $html, $filename = NULL) {
$pdf = new PrintTCPDF($orientation , 'mm', $print_pdf_paper_size, TRUE);
// set document information
$pdf->SetAuthor(strip_tags($print['node']->name));
if (property_exists($print['node'], 'name')) {
$pdf->SetAuthor(strip_tags($print['node']->name));
}
$pdf->SetCreator(variable_get('site_name', 'Drupal'));
$pdf->SetTitle(html_entity_decode($print['title'], ENT_QUOTES, 'UTF-8'));
$pdf->setPDFVersion('1.6');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment