Commit e281ff0b authored by jcnventura's avatar jcnventura

Fix #358838 by EugenMayer: Use theme preprocess functions for the template suggestions

parent 65cf1df9
......@@ -109,9 +109,49 @@ function print_theme() {
'print_format_link' => array(
'arguments' => array(),
),
'print_node' => array(
'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE, 'type' => PRINT_HTML_FORMAT),
'template' => 'print_node',
),
'print_page' => array(
'arguments' => array('print' => NULL, 'type' => PRINT_HTML_FORMAT, 'node' => NULL),
'template' => 'print',
),
);
}
/**
* Clones the node theme registry for print_node so that it works with existing node templates
*/
function print_theme_registry_alter(&$theme_registry) {
$theme_registry['print_node']['theme paths'] += $theme_registry['node']['theme paths'];
}
/**
* Renders the content of the node using the theme api
*/
function print_preprocess_print_node(&$vars) {
$format = $vars['type'];
$type = $vars['node']->type;
$vars['template_files'][] = "node";
$vars['template_files'][] = "node-$type";
$vars['template_files'][] = "print_node";
$vars['template_files'][] = "print_node_$format";
$vars['template_files'][] = "print_node_$format.node-$type";
}
/**
* Renders the print page, where the node content gets embedded
*/
function print_preprocess_print_page(&$vars) {
$format = $vars['type'];
$type = $vars['node']->type;
$vars['template_files'][] = "print";
$vars['template_files'][] = "print.node-$type";
$vars['template_files'][] = "print_$format";
$vars['template_files'][] = "print_$format.node-$type";
}
/**
* Implements hook_menu().
*/
......
......@@ -18,7 +18,6 @@ $_print_urls = PRINT_URLS_DEFAULT;
* Generate an HTML version of the printer-friendly page
*
* @see print_controller()
* @see _print_get_template()
*/
function print_controller_html() {
$args = func_get_args();
......@@ -28,7 +27,8 @@ function print_controller_html() {
$print = print_controller($path, $cid, PRINT_HTML_FORMAT);
if ($print !== FALSE) {
$node = $print['node'];
include_once(DRUPAL_ROOT . '/' . _print_get_template(PRINT_HTML_FORMAT, $print['type']));
$html = theme('print_page', $print, PRINT_HTML_FORMAT, $node);
print $html;
$nodepath = (isset($node->path)) ? drupal_get_normal_path($node->path) : 'node/' . $path;
db_merge('print_page_counter')
......@@ -455,51 +455,6 @@ function _print_friendly_urls($url = 0) {
return $ret;
}
/**
* Choose most appropriate template
*
* Auxiliary function to resolve the most appropriate template trying to find
* a content specific template in the theme or module dir before falling back
* on a generic template also in those dirs.
*
* @param format
* format of the PF page being rendered (html, pdf, etc.)
* @param $type
* name of the node type being rendered in a PF page
* @return
* filename of the most suitable template
*/
function _print_get_template($format = NULL, $type = NULL) {
$filenames = array();
// First try to find a template defined both for the format and then the type
if (!empty($format) && !empty($type)) {
$filenames[] = "print_$format.node-$type.tpl.php";
}
// Then only for the format
if (!empty($format)) {
$filenames[] = "print_$format.tpl.php";
}
// If the node type is known, then try to find that type's template file
if (!empty($type)) {
$filenames[] = "print.node-$type.tpl.php";
}
// Finally search for a generic template file
$filenames[] = 'print.tpl.php';
foreach ($filenames as $value) {
// First in the theme directory
$file = drupal_get_path('theme', $GLOBALS['theme_key']) . '/' . $value;
if (file_exists($file)) {
return $file;
}
// Then in the module directory
$file = drupal_get_path('module', 'print') . '/' . $value;
if (file_exists($file)) {
return $file;
}
}
}
/**
* Check URL list settings for this node
*
......@@ -634,6 +589,8 @@ function _print_generate_node($nid, $cid = NULL, $format = PRINT_HTML_FORMAT, $t
module_invoke_all('node_alter', $node, $teaser, TRUE);
$content = theme('print_node', $node, $teaser, TRUE, $format);
if ($teaser) {
$node->body = $node->teaser;
unset($node->teaser);
......
......@@ -277,10 +277,7 @@ function print_mail_form_submit($form, &$form_state) {
$params['title'] = $form_state['values']['title'];
$node = $print['node'];
ob_start();
include_once(DRUPAL_ROOT . '/' . _print_get_template(PRINT_MAIL_FORMAT, $print['type']));
$params['body'] = ob_get_contents();
ob_end_clean();
$params['body'] = theme('print_page', $print, PRINT_MAIL_FORMAT, $node);
$ok = FALSE;
if (function_exists('job_queue_add') && variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT)) {
......
......@@ -17,7 +17,6 @@ require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'print') . '/print.pa
* Generate a PDF version of the printer-friendly page
*
* @see print_controller()
* @see _print_get_template()
* @see _print_pdf_dompdf()
* @see _print_pdf_tcpdf()
*/
......@@ -65,10 +64,7 @@ function print_pdf_controller() {
$print['sendtoprinter'] = '';
$node = $print['node'];
ob_start();
include_once(DRUPAL_ROOT . '/' . _print_get_template(PRINT_PDF_FORMAT, $print['type']));
$html = ob_get_contents();
ob_end_clean();
$html = theme('print_page', $print, PRINT_PDF_FORMAT, $node);
// Convert the a href elements, to make sure no relative links remain
$pattern = '!<(a\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