Commit c4e84581 authored by jcnventura's avatar jcnventura

Issue #1358770: Handle URL arguments.

parent acb2fc2c
......@@ -85,7 +85,7 @@ function print_permission() {
function print_theme() {
return array(
'print' => array(
'variables' => array('node' => NULL, 'format' => '', 'expand_css' => FALSE, 'message' => ''),
'variables' => array('node' => NULL, 'query' => NULL, 'format' => '', 'expand_css' => FALSE, 'message' => ''),
'template' => 'print',
'file' => 'print.pages.inc',
),
......
......@@ -26,7 +26,11 @@ function print_controller_html() {
$node = print_controller($path, $link['format'], $cid);
if ($node) {
$html = theme('print', array('node' => $node, 'format' => $link['format']));
// Handle the query
$query = $_GET;
unset($query['q']);
$html = theme('print', array('node' => $node, 'query' => $query, 'format' => $link['format']));
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
drupal_send_headers();
print $html;
......@@ -161,8 +165,8 @@ function print_preprocess_print(&$variables) {
$variables['scripts'] = drupal_get_js();
$variables['footer_scripts'] = drupal_get_js('footer');
$variables['sourceurl_enabled'] = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT);
$variables['url'] = url($path, array('absolute' => TRUE));
$variables['source_url'] = url(variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT) ? drupal_get_normal_path($path) : $path, array('alias' => TRUE, 'absolute' => TRUE));
$variables['url'] = url($path, array('absolute' => TRUE, 'query' => $variables['query']));
$variables['source_url'] = url(variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT) ? drupal_get_normal_path($path) : $path, array('alias' => TRUE, 'absolute' => TRUE, 'query' => $variables['query']));
$variables['cid'] = isset($node->cid) ? $node->cid : NULL;
$variables['print_title'] = check_plain($node->title);
$variables['head'] = drupal_get_html_head();
......
......@@ -27,6 +27,10 @@ function print_epub_controller() {
$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
......@@ -60,7 +64,7 @@ function print_epub_controller() {
drupal_alter('print_epub_filename', $epub_filename, $path);
$epub = print_epub_generate_path($path, $cid, $epub_filename . '.epub');
$epub = print_epub_generate_path($path, $query, $cid, $epub_filename . '.epub');
if ($epub == NULL) {
drupal_goto($path);
exit;
......@@ -84,6 +88,8 @@ function print_epub_controller() {
*
* @param string $path
* path of the page to convert to EPUB
* @param array $query
* (optional) array of key/value pairs as used in the url() function for the query
* @param int $cid
* (optional) comment ID of the comment to render.
* @param string $epub_filename
......@@ -96,13 +102,13 @@ function print_epub_controller() {
*
* @see print_epub_controller()
*/
function print_epub_generate_path($path, $cid = NULL, $epub_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
function print_epub_generate_path($path, $query = NULL, $cid = NULL, $epub_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
global $base_url;
$link = print_epub_print_link();
$node = print_controller($path, $link['format'], $cid, $view_mode);
if ($node) {
$html = theme('print', array('node' => $node, 'expand_css' => TRUE, 'format' => $link['format']));
$html = theme('print', array('node' => $node, 'query' => $query, 'expand_css' => TRUE, 'format' => $link['format']));
$meta = array(
'node' => $node,
......
......@@ -49,7 +49,11 @@ function print_mail_form($form, &$form_state) {
$path = drupal_get_normal_path($path);
}
return print_mail_form_for_path($form, $form_state, $path);
// Handle the query
$query = $_GET;
unset($query['q']);
return print_mail_form_for_path($form, $form_state, $path, $query);
}
/**
......@@ -57,7 +61,7 @@ function print_mail_form($form, &$form_state) {
*
* @ingroup forms
*/
function print_mail_form_for_path($form, &$form_state, $path, $user = NULL) {
function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $user = NULL) {
if($user === NULL) {
global $user;
}
......@@ -92,6 +96,7 @@ function print_mail_form_for_path($form, &$form_state, $path, $user = NULL) {
}
$form['path'] = array('#type' => 'value', '#value' => $path);
$form['query'] = array('#type' => 'value', '#value' => $query);
$form['cid'] = array('#type' => 'value', '#value' => $cid);
$form['title'] = array('#type' => 'value', '#value' => $title);
......@@ -121,6 +126,7 @@ function print_mail_form_for_path($form, &$form_state, $path, $user = NULL) {
'#required' => TRUE,
);
if (!empty($title)) {
// To prevent useless translation strings, try to translate only node titles
if (drupal_substr($path, 0, 5) == 'node/') {
$title = t($title);
}
......@@ -128,7 +134,7 @@ function print_mail_form_for_path($form, &$form_state, $path, $user = NULL) {
$form['fld_title'] = array(
'#type' => 'item',
'#title' => t('Page to be sent'),
'#markup' => l($title, $path, array('attributes' => array('title' => t('View page')))),
'#markup' => l($title, $path, array('attributes' => array('title' => t('View page')), 'query' => $query)),
);
}
$form['txt_message'] = array(
......@@ -227,7 +233,7 @@ function print_mail_form_validate($form, &$form_state) {
form_set_error(NULL, '', TRUE);
drupal_get_messages('error');
drupal_goto(preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']));
drupal_goto(preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']), array('query' => $form_state['values']['query']));
return;
}
$from_addr = trim($form_state['values']['fld_from_addr']);
......@@ -299,7 +305,7 @@ function print_mail_form_submit($form, &$form_state) {
$params = array();
$params['subject'] = $form_state['values']['fld_subject'];
$params['message'] = t('Message from sender') . ':<br /><br /><em>' . nl2br(check_plain($form_state['values']['txt_message'])) . '</em>';
$params['link'] = url($form_state['values']['path'], array('absolute' => TRUE));
$params['link'] = url($form_state['values']['path'], array('absolute' => TRUE, 'query' => $form_state['values']['query']));
$params['title'] = $form_state['values']['title'];
// If a name is provided, make From: in the format Common Name <address>
......@@ -320,7 +326,7 @@ function print_mail_form_submit($form, &$form_state) {
$pattern = '!<(img\s[^>]*?)>!is';
$node->content = preg_replace_callback($pattern, '_print_replace_spaces', $node->content);
$params['body'] = theme('print', array('node' => $node, 'format' => $link['format'], 'expand_css' => TRUE, 'message' => $params['message']));
$params['body'] = theme('print', array('node' => $node, 'query' => $form_state['values']['query'], 'format' => $link['format'], 'expand_css' => TRUE, 'message' => $params['message']));
// Img elements must be set to absolute
$pattern = '!<(img\s[^>]*?)>!is';
......@@ -352,7 +358,8 @@ function print_mail_form_submit($form, &$form_state) {
}
}
if ($ok) {
watchdog('print_mail', '%name [%from] sent %page to [%to]', array('%name' => $form_state['values']['fld_from_name'], '%from' => $form_state['values']['fld_from_addr'], '%page' => $form_state['values']['path'], '%to' => $form_state['values']['txt_to_addrs']));
$query = empty($form_state['values']['query']) ? '' : '?' . rawurldecode(drupal_http_build_query($form_state['values']['query']));
watchdog('print_mail', '%name [%from] sent %page to [%to]', array('%name' => $form_state['values']['fld_from_name'], '%from' => $form_state['values']['fld_from_addr'], '%page' => $form_state['values']['path'] . $query, '%to' => $form_state['values']['txt_to_addrs']));
$site_name = variable_get('site_name', t('us'));
drupal_set_message(check_plain(t('Thank you for spreading the word about !site.', array('!site' => $site_name))));
......@@ -369,5 +376,5 @@ function print_mail_form_submit($form, &$form_state) {
}
}
$form_state['redirect'] = preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']);
$form_state['redirect'] = array(preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']), array('query' => $form_state['values']['query']));
}
......@@ -27,6 +27,10 @@ function print_pdf_controller() {
$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
......@@ -60,7 +64,7 @@ function print_pdf_controller() {
drupal_alter('print_pdf_filename', $pdf_filename, $path);
$pdf = print_pdf_generate_path($path, $cid, $pdf_filename . '.pdf');
$pdf = print_pdf_generate_path($path, $query, $cid, $pdf_filename . '.pdf');
if ($pdf == NULL) {
drupal_goto($path);
exit;
......@@ -84,6 +88,8 @@ function print_pdf_controller() {
*
* @param string $path
* path of the page to convert to PDF
* @param array $query
* (optional) array of key/value pairs as used in the url() function for the query
* @param int $cid
* (optional) comment ID of the comment to render.
* @param string $pdf_filename
......@@ -96,7 +102,7 @@ function print_pdf_controller() {
*
* @see print_pdf_controller()
*/
function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
global $base_url;
$link = print_pdf_print_link();
......@@ -112,7 +118,7 @@ function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL, $view
}
$expand = isset($info['expand_css']) ? $info['expand_css'] : FALSE;
$html = theme('print', array('node' => $node, $expand, 'format' => $link['format']));
$html = theme('print', array('node' => $node, 'query' => $query, $expand, 'format' => $link['format']));
// Img elements must be set to absolute
$pattern = '!<(img\s[^>]*?)>!is';
......
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