Revision 76bdcd04
Added by Assos Assos almost 6 years ago
drupal7/sites/all/modules/print/print.pages.inc | ||
---|---|---|
14 | 14 |
$_print_urls = PRINT_URLS_DEFAULT; |
15 | 15 |
|
16 | 16 |
/** |
17 |
* Generate an HTML version of the printer-friendly page |
|
17 |
* Generate an HTML version of the printer-friendly page.
|
|
18 | 18 |
* |
19 | 19 |
* @see print_controller() |
20 | 20 |
*/ |
21 | 21 |
function print_controller_html() { |
22 | 22 |
$args = func_get_args(); |
23 | 23 |
$path = filter_xss(implode('/', $args)); |
24 |
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL; |
|
25 |
|
|
26 |
// Handle the query |
|
27 |
$query = $_GET; |
|
28 |
unset($query['q']); |
|
29 |
|
|
30 |
$print = print_controller($path, $query, $cid, PRINT_HTML_FORMAT); |
|
31 |
if ($print !== FALSE) { |
|
32 |
$node = $print['node']; |
|
33 |
$html = theme('print', array('print' => $print, 'type' => PRINT_HTML_FORMAT, 'node' => $node)); |
|
24 |
$cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL; |
|
25 |
$link = print_print_link(); |
|
26 |
|
|
27 |
$node = print_controller($path, $link['format'], $cid); |
|
28 |
if ($node) { |
|
29 |
// Handle the query. |
|
30 |
$query = $_GET; |
|
31 |
unset($query['q']); |
|
32 |
|
|
33 |
$html = theme('print', array( |
|
34 |
'node' => $node, |
|
35 |
'query' => $query, |
|
36 |
'format' => $link['format'], |
|
37 |
)); |
|
34 | 38 |
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8'); |
35 | 39 |
drupal_send_headers(); |
36 | 40 |
print $html; |
37 | 41 |
|
38 |
$nodepath = (isset($node->path) && is_string($node->path)) ? drupal_get_normal_path($node->path) : 'node/' . $path;
|
|
42 |
$nodepath = (isset($node->nid)) ? 'node/' . $node->nid : drupal_get_normal_path($path);
|
|
39 | 43 |
db_merge('print_page_counter') |
40 | 44 |
->key(array('path' => $nodepath)) |
41 | 45 |
->fields(array( |
42 |
'totalcount' => 1,
|
|
43 |
'timestamp' => REQUEST_TIME,
|
|
46 |
'totalcount' => 1, |
|
47 |
'timestamp' => REQUEST_TIME, |
|
44 | 48 |
)) |
45 | 49 |
->expression('totalcount', 'totalcount + 1') |
46 | 50 |
->execute(); |
... | ... | |
48 | 52 |
} |
49 | 53 |
|
50 | 54 |
/** |
51 |
* Select the print generator function based on the page type |
|
55 |
* Select the print generator function based on the page type.
|
|
52 | 56 |
* |
53 | 57 |
* Depending on the type of node, this functions chooses the appropriate |
54 | 58 |
* generator function. |
55 | 59 |
* |
56 |
* @param $path |
|
57 |
* path of the original page |
|
58 |
* @param array $query |
|
59 |
* (optional) array of key/value pairs as used in the url() function for the |
|
60 |
* query |
|
61 |
* @param $cid |
|
62 |
* comment ID of the individual comment to be rendered |
|
63 |
* @param $format |
|
64 |
* format of the page being generated |
|
65 |
* @param $teaser |
|
66 |
* if set to TRUE, outputs only the node's teaser |
|
67 |
* @param $message |
|
68 |
* optional sender's message (used by the send email module) |
|
69 |
* @return |
|
70 |
* array with the fields to be used in the template |
|
60 |
* @param string $path |
|
61 |
* Path of the original page. |
|
62 |
* @param string $format |
|
63 |
* Format of the page being generated. |
|
64 |
* @param int $cid |
|
65 |
* Comment ID of the individual comment to be rendered. |
|
66 |
* @param string $view_mode |
|
67 |
* (Optional) view mode to be used when rendering the content. |
|
68 |
* |
|
69 |
* @return object |
|
70 |
* node-like object to be used in the print template |
|
71 |
* |
|
71 | 72 |
* @see _print_generate_node() |
72 | 73 |
* @see _print_generate_path() |
73 | 74 |
* @see _print_generate_book() |
75 |
* @see print_preprocess_print() |
|
74 | 76 |
*/ |
75 |
function print_controller($path, $query = NULL, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
|
77 |
function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
|
|
76 | 78 |
if (empty($path)) { |
77 |
// If no path was provided, let's try to generate a page for the referer |
|
79 |
// If no path was provided, let's try to generate a page for the referer.
|
|
78 | 80 |
global $base_url; |
79 | 81 |
|
80 | 82 |
$ref = $_SERVER['HTTP_REFERER']; |
... | ... | |
85 | 87 |
} |
86 | 88 |
if ($alias = drupal_lookup_path('source', $path)) { |
87 | 89 |
// Indirect call with print/alias |
88 |
// If there is a path alias with these arguments, generate a printer-friendly version for it |
|
90 |
// If there is a path alias with these arguments, generate a |
|
91 |
// printer-friendly version for it. |
|
89 | 92 |
$path = $alias; |
90 | 93 |
} |
91 | 94 |
$parts = explode('/', $path); |
92 |
if (($parts[0] == 'node') && (count($parts) > 1) && ctype_digit($parts[1])) { |
|
95 |
$node_router = variable_get('print_node_router', FALSE); |
|
96 |
if (($parts[0] == 'node') && (count($parts) > 1) && ctype_digit($parts[1]) && !$node_router) { |
|
93 | 97 |
array_shift($parts); |
94 | 98 |
$path = implode('/', $parts); |
95 | 99 |
} |
96 |
if (ctype_digit($parts[0]) && (count($parts) == 1)) { |
|
97 |
$print = _print_generate_node($path, $query, $cid, $format, $teaser, $message); |
|
100 |
$revision_view = preg_match('!^[\d]*/revisions/[\d]*/view$!', $path); |
|
101 |
if (ctype_digit($parts[0]) && ((count($parts) == 1) || $revision_view) && !$node_router) { |
|
102 |
$vid = $revision_view ? $parts[2] : NULL; |
|
103 |
$node = _print_generate_node($path, $format, $vid, $cid, $view_mode); |
|
98 | 104 |
} |
99 | 105 |
else { |
100 | 106 |
$ret = preg_match('!^book/export/html/(.*)!i', $path, $matches); |
101 | 107 |
if ($ret == 1) { |
102 |
// This is a book PF page link, handle trough the book handling functions |
|
103 |
$print = _print_generate_book($matches[1], $query, $format, $teaser, $message);
|
|
108 |
// This is a book PF page link, handle trough the book handling functions.
|
|
109 |
$node = _print_generate_book($matches[1], $format);
|
|
104 | 110 |
} |
105 | 111 |
else { |
106 |
// If no content node was found, handle the page printing with the 'printable' engine |
|
107 |
$print = _print_generate_path($path, $query, $format, $teaser, $message); |
|
112 |
// If no content node was found, handle the page printing with the |
|
113 |
// 'printable' engine. |
|
114 |
$node = _print_generate_path($path, $format); |
|
108 | 115 |
} |
109 | 116 |
} |
110 | 117 |
|
111 |
return $print; |
|
118 |
return $node; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Implements hook_preprocess_HOOK(). |
|
123 |
*/ |
|
124 |
function print_preprocess_print(&$variables) { |
|
125 |
$node = $variables['node']; |
|
126 |
$format = $variables['format']; |
|
127 |
$path = drupal_get_path_alias(empty($node->nid) ? $node->path : "node/$node->nid"); |
|
128 |
|
|
129 |
static $hooks = NULL; |
|
130 |
if (!isset($hooks)) { |
|
131 |
drupal_theme_initialize(); |
|
132 |
$hooks = theme_get_registry(); |
|
133 |
} |
|
134 |
|
|
135 |
$variables['page']['#show_messages'] = FALSE; |
|
136 |
$variables['theme_hook_suggestions'] = array(); |
|
137 |
|
|
138 |
// Stolen from theme() so that ALL preprocess functions are called. |
|
139 |
$hook = 'page'; |
|
140 |
$info = $hooks[$hook]; |
|
141 |
if (isset($info['preprocess functions']) || isset($info['process functions'])) { |
|
142 |
foreach (array('preprocess functions', 'process functions') as $phase) { |
|
143 |
if (!empty($info[$phase])) { |
|
144 |
foreach ($info[$phase] as $processor_function) { |
|
145 |
if (function_exists($processor_function)) { |
|
146 |
// We don't want a poorly behaved process function changing $hook. |
|
147 |
$hook_clone = $hook; |
|
148 |
$processor_function($variables, $hook_clone); |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
$logo_url = FALSE; |
|
156 |
switch (variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT)) { |
|
157 |
// Theme logo. |
|
158 |
case 1: |
|
159 |
$logo_url = theme_get_setting('logo'); |
|
160 |
break; |
|
161 |
|
|
162 |
// User-specifed logo. |
|
163 |
case 2: |
|
164 |
$logo_url = strip_tags(variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT)); |
|
165 |
break; |
|
166 |
} |
|
167 |
$logo_url = preg_replace('!^' . base_path() . '!', '', $logo_url); |
|
168 |
|
|
169 |
$variables['print_logo'] = $logo_url ? theme('image', array( |
|
170 |
'path' => $logo_url, |
|
171 |
'alt' => variable_get('site_name', 'Drupal'), |
|
172 |
'attributes' => array( |
|
173 |
'class' => array('print-logo'), |
|
174 |
'id' => 'logo', |
|
175 |
), |
|
176 |
)) : NULL; |
|
177 |
|
|
178 |
$variables['print_node'] = $node; |
|
179 |
$variables['content'] = $node->content; |
|
180 |
$variables['scripts'] = drupal_get_js(); |
|
181 |
$variables['footer_scripts'] = drupal_get_js('footer'); |
|
182 |
$variables['sourceurl_enabled'] = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT); |
|
183 |
$variables['url'] = url($path, array('absolute' => TRUE, 'query' => $variables['query'])); |
|
184 |
$variables['source_url'] = url(variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT) ? drupal_get_normal_path($path) : $path, array( |
|
185 |
'alias' => TRUE, |
|
186 |
'absolute' => TRUE, |
|
187 |
'query' => $variables['query'], |
|
188 |
)); |
|
189 |
$variables['cid'] = isset($node->cid) ? $node->cid : NULL; |
|
190 |
$variables['print_title'] = check_plain($node->title); |
|
191 |
$variables['head'] = drupal_get_html_head(); |
|
192 |
$variables['robots_meta'] = _print_robots_meta_generator(); |
|
193 |
$variables['css'] = _print_css_generator($variables['expand_css']); |
|
194 |
|
|
195 |
if (variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT) && ($format == 'html')) { |
|
196 |
drupal_add_js('misc/drupal.js', array('weight' => JS_LIBRARY)); |
|
197 |
|
|
198 |
$window_close = (variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT) && variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT)) ? 'setTimeout(function(){window.close();}, 1);' : ''; |
|
199 |
$variables['sendtoprinter'] = '<script type="text/javascript">(function ($) { Drupal.behaviors.print = {attach: function() {$(window).load(function() {window.print();' . $window_close . '})}}})(jQuery);</script>'; |
|
200 |
} |
|
201 |
|
|
202 |
$type = (isset($node->type)) ? $node->type : ''; |
|
203 |
$nid = (isset($node->nid)) ? $node->nid : ''; |
|
204 |
|
|
205 |
$variables['theme_hook_suggestions'][] = "print__node__{$type}"; |
|
206 |
$variables['theme_hook_suggestions'][] = "print__node__{$type}__{$nid}"; |
|
207 |
$variables['theme_hook_suggestions'][] = "print__{$format}"; |
|
208 |
$variables['theme_hook_suggestions'][] = "print__{$format}__node__{$type}"; |
|
209 |
$variables['theme_hook_suggestions'][] = "print__{$format}__node__{$type}__{$nid}"; |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* Returns HTML for the published line of the print template. |
|
214 |
* |
|
215 |
* @param array $vars |
|
216 |
* An empty associative array. |
|
217 |
* |
|
218 |
* @return string |
|
219 |
* HTML text with the published line |
|
220 |
* |
|
221 |
* @ingroup themeable |
|
222 |
* @ingroup print_themeable |
|
223 |
*/ |
|
224 |
function theme_print_published($vars) { |
|
225 |
global $base_url; |
|
226 |
|
|
227 |
$published_site = variable_get('site_name', 0); |
|
228 |
return $published_site ? t('Published on %site_name', array('%site_name' => $published_site)) . ' (' . l($base_url, $base_url) . ')' : ''; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Returns HTML for the breadcrumb line of the print template. |
|
233 |
* |
|
234 |
* @param array $vars |
|
235 |
* An associative array containing: |
|
236 |
* - $node: the node object. |
|
237 |
* |
|
238 |
* @return string |
|
239 |
* HTML text with the breadcrumb |
|
240 |
* |
|
241 |
* @ingroup themeable |
|
242 |
* @ingroup print_themeable |
|
243 |
*/ |
|
244 |
function theme_print_breadcrumb($vars) { |
|
245 |
$node = $vars['node']; |
|
246 |
$old_path = $_GET['q']; |
|
247 |
|
|
248 |
$path = empty($node->nid) ? $node->path : "node/$node->nid"; |
|
249 |
menu_set_active_item($path); |
|
250 |
$breadcrumb = drupal_get_breadcrumb(); |
|
251 |
if (!empty($breadcrumb)) { |
|
252 |
$breadcrumb[] = menu_get_active_title(); |
|
253 |
menu_set_active_item($old_path); |
|
254 |
return filter_xss(implode(' > ', $breadcrumb)); |
|
255 |
} |
|
256 |
else { |
|
257 |
menu_set_active_item($old_path); |
|
258 |
return ''; |
|
259 |
} |
|
260 |
} |
|
261 |
|
|
262 |
/** |
|
263 |
* Returns HTML for the footer of the print template. |
|
264 |
* |
|
265 |
* @param array $vars |
|
266 |
* An empty associative array. |
|
267 |
* |
|
268 |
* @return string |
|
269 |
* HTML text with the footer |
|
270 |
* |
|
271 |
* @ingroup themeable |
|
272 |
* @ingroup print_themeable |
|
273 |
*/ |
|
274 |
function theme_print_footer($vars) { |
|
275 |
$footer = ''; |
|
276 |
|
|
277 |
switch (variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT)) { |
|
278 |
// Theme footer. |
|
279 |
case 1: |
|
280 |
$footer_blocks = block_get_blocks_by_region('footer'); |
|
281 |
$footer = variable_get('site_footer', FALSE) . "\n" . drupal_render($footer_blocks); |
|
282 |
break; |
|
283 |
|
|
284 |
// User-specified footer. |
|
285 |
case 2: |
|
286 |
$footer = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT); |
|
287 |
break; |
|
288 |
} |
|
289 |
// Delete the contextual links. |
|
290 |
$footer = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $footer); |
|
291 |
|
|
292 |
return filter_xss_admin($footer); |
|
293 |
} |
|
294 |
|
|
295 |
/** |
|
296 |
* Returns HTML for the source URL line of the print template. |
|
297 |
* |
|
298 |
* @param array $vars |
|
299 |
* An associative array containing: |
|
300 |
* - $url: the URL to the full node view. |
|
301 |
* - $node: the node object. |
|
302 |
* - $cid; comment ID of the comment to display. |
|
303 |
* |
|
304 |
* @return string |
|
305 |
* HTML text with the footer |
|
306 |
* |
|
307 |
* @ingroup themeable |
|
308 |
* @ingroup print_themeable |
|
309 |
*/ |
|
310 |
function theme_print_sourceurl($vars) { |
|
311 |
$sourceurl_date = variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT); |
|
312 |
$url = is_int($vars['cid']) ? $vars['url'] . '#comment-' . $vars['cid'] : $vars['url']; |
|
313 |
|
|
314 |
$output = '<strong>' . t('Source URL'); |
|
315 |
if ($sourceurl_date && isset($vars['node'])) { |
|
316 |
$output .= ' ('; |
|
317 |
$date = format_date($vars['node']->changed, 'short'); |
|
318 |
|
|
319 |
$output .= empty($vars['node']->nid) ? t('retrieved on !date', array('!date' => $date)) : t('modified on !date', array('!date' => $date)); |
|
320 |
|
|
321 |
$output .= ')'; |
|
322 |
} |
|
323 |
$output .= ':</strong> ' . $url; |
|
324 |
|
|
325 |
return $output; |
|
326 |
} |
|
327 |
|
|
328 |
/** |
|
329 |
* Returns HTML for the URL list of the print template. |
|
330 |
* |
|
331 |
* @param array $vars |
|
332 |
* An empty associative array. |
|
333 |
* |
|
334 |
* @return string |
|
335 |
* HTML text with the URL list |
|
336 |
* |
|
337 |
* @ingroup themeable |
|
338 |
* @ingroup print_themeable |
|
339 |
*/ |
|
340 |
function theme_print_url_list($vars) { |
|
341 |
global $_print_urls; |
|
342 |
|
|
343 |
// Display the collected links at the bottom of the page. Code once taken from |
|
344 |
// Kjartan Mannes' project.module. |
|
345 |
if (!empty($_print_urls)) { |
|
346 |
$urls = _print_friendly_urls(); |
|
347 |
$url_list = ''; |
|
348 |
foreach ($urls as $key => $url) { |
|
349 |
drupal_alter('print_url_list', $url); |
|
350 |
$url_list .= '[' . ($key + 1) . '] ' . check_plain($url) . "<br />\n"; |
|
351 |
} |
|
352 |
if (!empty($url_list)) { |
|
353 |
return "<p><strong>" . t('Links') . "</strong><br />$url_list</p>"; |
|
354 |
} |
|
355 |
} |
|
356 |
return ''; |
|
112 | 357 |
} |
113 | 358 |
|
114 | 359 |
/** |
115 |
* Generates a robots meta tag to tell them what they may index |
|
360 |
* Generates a robots meta tag to tell them what they may index.
|
|
116 | 361 |
* |
117 |
* @return |
|
118 |
* string with the meta robots tag
|
|
362 |
* @return string
|
|
363 |
* meta robots tag |
|
119 | 364 |
*/ |
120 | 365 |
function _print_robots_meta_generator() { |
121 |
$print_robots_noindex = variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT); |
|
122 |
$print_robots_nofollow = variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT); |
|
123 |
$print_robots_noarchive = variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT); |
|
124 | 366 |
$robots_meta = array(); |
125 | 367 |
|
126 |
if (!empty($print_robots_noindex)) {
|
|
368 |
if (variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT)) {
|
|
127 | 369 |
$robots_meta[] = 'noindex'; |
128 | 370 |
} |
129 |
if (!empty($print_robots_nofollow)) {
|
|
371 |
if (variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT)) {
|
|
130 | 372 |
$robots_meta[] = 'nofollow'; |
131 | 373 |
} |
132 |
if (!empty($print_robots_noarchive)) {
|
|
374 |
if (variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT)) {
|
|
133 | 375 |
$robots_meta[] = 'noarchive'; |
134 | 376 |
} |
135 | 377 |
|
136 | 378 |
if (count($robots_meta) > 0) { |
137 |
$robots_meta = implode(', ', $robots_meta); |
|
138 |
$robots_meta = "<meta name='robots' content='$robots_meta' />\n"; |
|
379 |
return '<meta name="robots" content=' . implode(', ', $robots_meta) . ' />'; |
|
139 | 380 |
} |
140 | 381 |
else { |
141 |
$robots_meta = '';
|
|
382 |
return '';
|
|
142 | 383 |
} |
143 |
|
|
144 |
return $robots_meta; |
|
145 | 384 |
} |
146 | 385 |
|
147 | 386 |
/** |
148 |
* Post-processor that fills the array for the template with common details |
|
149 |
* |
|
150 |
* @param $node |
|
151 |
* generated node with a printer-friendly node body |
|
152 |
* @param array $query |
|
153 |
* (optional) array of key/value pairs as used in the url() function for the |
|
154 |
* query |
|
155 |
* @param $message |
|
156 |
* optional sender's message (used by the send email module) |
|
157 |
* @param $cid |
|
158 |
* id of current comment being generated (NULL when not generating |
|
159 |
* an individual comment) |
|
160 |
* @return |
|
161 |
* array with the fields to be used in the template |
|
387 |
* Generates the CSS directive to include in the printer-friendly version. |
|
388 |
* |
|
389 |
* @param bool $expand |
|
390 |
* If TRUE, the provided CSS will be expanded, instead of given as a list |
|
391 |
* of includes. |
|
392 |
* |
|
393 |
* @return string |
|
394 |
* applicable CSS |
|
162 | 395 |
*/ |
163 |
function _print_var_generator($node, $query = NULL, $message = NULL, $cid = NULL) { |
|
164 |
global $base_url, $language, $_print_urls; |
|
165 |
|
|
166 |
$path = empty($node->nid) ? $node->path : "node/$node->nid"; |
|
167 |
|
|
168 |
// print module settings |
|
396 |
function _print_css_generator($expand = FALSE) { |
|
169 | 397 |
$print_css = variable_get('print_css', PRINT_CSS_DEFAULT); |
170 |
$print_keep_theme_css = variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT); |
|
171 |
$print_logo_options = variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT); |
|
172 |
$print_logo_url = variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT); |
|
173 |
$print_html_new_window = variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT); |
|
174 |
$print_html_sendtoprinter = variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT); |
|
175 |
$print_html_windowclose = variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT); |
|
176 |
$print_sourceurl_enabled = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT); |
|
177 |
$print_sourceurl_forcenode = variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT); |
|
178 |
$print_sourceurl_date = variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT); |
|
179 |
$print_footer_options = variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT); |
|
180 |
$print_footer_user = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT); |
|
181 |
|
|
182 |
$print['language'] = $language->language; |
|
183 |
$print['title'] = check_plain($node->title); |
|
184 |
$print['head'] = drupal_get_html_head(); |
|
185 |
if ($print_html_sendtoprinter) { |
|
186 |
drupal_add_js('misc/drupal.js', array('weight' => JS_LIBRARY)); |
|
187 |
} |
|
188 |
$print['scripts'] = drupal_get_js(); |
|
189 |
$print['footer_scripts'] = drupal_get_js('footer'); |
|
190 |
$print['robots_meta'] = _print_robots_meta_generator(); |
|
191 |
$print['url'] = url($path, array('absolute' => TRUE, 'query' => $query)); |
|
192 |
$print['base_href'] = "<base href='" . $print['url'] . "' />\n"; |
|
193 |
$print['favicon'] = theme_get_setting('toggle_favicon') ? "<link rel='shortcut icon' href='" . theme_get_setting('favicon') . "' type='image/x-icon' />\n" : ''; |
|
194 | 398 |
|
195 | 399 |
if (!empty($print_css)) { |
196 | 400 |
drupal_add_css(strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default'))))); |
... | ... | |
199 | 403 |
drupal_add_css(drupal_get_path('module', 'print') . '/css/print.css'); |
200 | 404 |
} |
201 | 405 |
$drupal_css = drupal_add_css(); |
202 |
if (!$print_keep_theme_css) {
|
|
406 |
if (!variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT)) {
|
|
203 | 407 |
foreach ($drupal_css as $key => $css_file) { |
204 | 408 |
if ($css_file['group'] == CSS_THEME) { |
205 |
// Unset the theme's CSS
|
|
409 |
// Unset the theme's CSS.
|
|
206 | 410 |
unset($drupal_css[$key]); |
207 | 411 |
} |
208 | 412 |
} |
209 | 413 |
} |
210 | 414 |
|
211 |
// If we are sending a message via email, the CSS must be embedded
|
|
212 |
if (!empty($message)) {
|
|
415 |
// Expand the CSS if requested.
|
|
416 |
if ($expand) {
|
|
213 | 417 |
$style = ''; |
214 | 418 |
$css_files = array_keys($drupal_css); |
215 | 419 |
foreach ($css_files as $filename) { |
216 |
$res = file_exists($filename) ? file_get_contents($filename, TRUE) : FALSE; |
|
217 |
if ($res != FALSE) { |
|
218 |
$style .= $res; |
|
420 |
if (file_exists($filename)) { |
|
421 |
$style .= file_get_contents($filename, TRUE); |
|
219 | 422 |
} |
220 | 423 |
} |
221 |
$print['css'] = "<style type='text/css' media='all'>$style</style>\n"; |
|
222 |
} |
|
223 |
else { |
|
224 |
$print['css'] = drupal_get_css($drupal_css); |
|
225 |
} |
|
226 |
|
|
227 |
$window_close = ($print_html_new_window && $print_html_windowclose) ? 'window.close();' : ''; |
|
228 |
$print['sendtoprinter'] = $print_html_sendtoprinter ? '<script type="text/javascript">(function ($) { Drupal.behaviors.print = {attach: function(context) {$(window).load(function() {window.print();' . $window_close . '})}}})(jQuery);</script>' : ''; |
|
229 |
|
|
230 |
switch ($print_logo_options) { |
|
231 |
case 0: // none |
|
232 |
$logo_url = 0; |
|
233 |
break; |
|
234 |
case 1: // theme's |
|
235 |
$logo_url = theme_get_setting('logo'); |
|
236 |
break; |
|
237 |
case 2: // user-specifed |
|
238 |
$logo_url = strip_tags($print_logo_url); |
|
239 |
break; |
|
240 |
} |
|
241 |
$logo_url = preg_replace('!^' . base_path() . '!', '', $logo_url); |
|
242 |
$site_name = variable_get('site_name', 'Drupal'); |
|
243 |
$print['logo'] = $logo_url ? theme('image', array('path' => $logo_url, 'alt' => $site_name, 'attributes' => array('class' => 'print-logo', 'id' => 'logo'))) : ''; |
|
244 |
|
|
245 |
switch ($print_footer_options) { |
|
246 |
case 0: // none |
|
247 |
$footer = ''; |
|
248 |
break; |
|
249 |
case 1: // theme's |
|
250 |
$footer_blocks = block_get_blocks_by_region('footer'); |
|
251 |
$footer = variable_get('site_footer', FALSE) . "\n" . drupal_render($footer_blocks); |
|
252 |
break; |
|
253 |
case 2: // user-specifed |
|
254 |
$footer = $print_footer_user; |
|
255 |
break; |
|
256 |
} |
|
257 |
// Delete the contextual links |
|
258 |
$footer = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $footer); |
|
259 |
|
|
260 |
$print['footer_message'] = filter_xss_admin($footer); |
|
261 |
|
|
262 |
$published_site = variable_get('site_name', 0); |
|
263 |
if ($published_site) { |
|
264 |
$print_text_published = filter_xss(variable_get('print_text_published', t('Published on %site_name'))); |
|
265 |
$published = t($print_text_published, array('%site_name' => $published_site)); |
|
266 |
$print['site_name'] = $published . ' (' . l($base_url, $base_url) . ')'; |
|
267 |
} |
|
268 |
else { |
|
269 |
$print['site_name'] = ''; |
|
270 |
} |
|
271 |
|
|
272 |
if ($print_sourceurl_enabled == 1) { |
|
273 |
/* Grab and format the src URL */ |
|
274 |
if (empty($print_sourceurl_forcenode)) { |
|
275 |
$url = $print['url']; |
|
276 |
} |
|
277 |
else { |
|
278 |
$url = $base_url . '/' . (((bool)variable_get('clean_url', '0')) ? '' : '?q=') . $path; |
|
279 |
} |
|
280 |
if (is_int($cid)) { |
|
281 |
$url .= "#comment-$cid"; |
|
282 |
} |
|
283 |
$retrieved_date = format_date(REQUEST_TIME, 'short'); |
|
284 |
$print_text_retrieved = filter_xss(variable_get('print_text_retrieved', t('retrieved on %date'))); |
|
285 |
$retrieved = t($print_text_retrieved, array('%date' => $retrieved_date)); |
|
286 |
$print['printdate'] = $print_sourceurl_date ? " ($retrieved)" : ''; |
|
287 |
|
|
288 |
$source_url = filter_xss(variable_get('print_text_source_url', t('Source URL'))); |
|
289 |
$print['source_url'] = '<strong>' . $source_url . $print['printdate'] . ':</strong> ' . l($url, $url); |
|
290 |
} |
|
291 |
else { |
|
292 |
$print['source_url'] = ''; |
|
293 |
} |
|
294 |
|
|
295 |
$print['type'] = (isset($node->type)) ? $node->type : ''; |
|
296 |
|
|
297 |
menu_set_active_item($path); |
|
298 |
$breadcrumb = drupal_get_breadcrumb(); |
|
299 |
if (!empty($breadcrumb)) { |
|
300 |
$breadcrumb[] = menu_get_active_title(); |
|
301 |
$print['breadcrumb'] = filter_xss(implode(' > ', $breadcrumb)); |
|
424 |
return "<style type='text/css' media='all'>$style</style>\n"; |
|
302 | 425 |
} |
303 | 426 |
else { |
304 |
$print['breadcrumb'] = ''; |
|
305 |
} |
|
306 |
|
|
307 |
// Display the collected links at the bottom of the page. Code once taken from Kjartan Mannes' project.module |
|
308 |
$print['pfp_links'] = ''; |
|
309 |
if (!empty($_print_urls)) { |
|
310 |
$urls = _print_friendly_urls(); |
|
311 |
$max = count($urls); |
|
312 |
$pfp_links = ''; |
|
313 |
if ($max) { |
|
314 |
for ($i = 0; $i < $max; $i++) { |
|
315 |
$pfp_links .= '[' . ($i + 1) . '] ' . check_plain($urls[$i]) . "<br />\n"; |
|
316 |
} |
|
317 |
$links = filter_xss(variable_get('print_text_links', t('Links'))); |
|
318 |
$print['pfp_links'] = "<p><strong>$links:</strong><br />$pfp_links</p>"; |
|
319 |
} |
|
427 |
return drupal_get_css($drupal_css); |
|
320 | 428 |
} |
321 |
|
|
322 |
$print['node'] = $node; |
|
323 |
$print['message'] = $message; |
|
324 |
|
|
325 |
return $print; |
|
326 | 429 |
} |
327 | 430 |
|
328 | 431 |
/** |
329 |
* Callback function for the preg_replace_callback for URL-capable patterns |
|
432 |
* Callback function for the preg_replace_callback for URL-capable patterns. |
|
433 |
* |
|
434 |
* Manipulate URLs to make them absolute in the URLs list, and add a [n] |
|
435 |
* footnote marker. |
|
330 | 436 |
* |
331 |
* Manipulate URLs to make them absolute in the URLs list, and to add a
|
|
332 |
* [n] footnote marker.
|
|
437 |
* @param array $matches
|
|
438 |
* Array with the matched tag patterns, usually <a...>+text+</a>.
|
|
333 | 439 |
* |
334 |
* @param $matches |
|
335 |
* array with the matched tag patterns, usually <a...>+text+</a> |
|
336 |
* @return |
|
337 |
* tag with re-written URL and when appropriate the [n] index to the |
|
338 |
* URL list |
|
440 |
* @return string |
|
441 |
* tag with re-written URL and, if applicable, the [n] index to the URL list |
|
339 | 442 |
*/ |
340 | 443 |
function _print_rewrite_urls($matches) { |
341 | 444 |
global $base_url, $base_root, $_print_urls; |
342 | 445 |
|
343 | 446 |
$include_anchors = variable_get('print_urls_anchors', PRINT_URLS_ANCHORS_DEFAULT); |
344 | 447 |
|
345 |
// first, split the html into the different tag attributes
|
|
448 |
// First, split the html into the different tag attributes.
|
|
346 | 449 |
$pattern = '!\s*(\w+\s*=\s*"(?:\\\"|[^"])*")\s*|\s*(\w+\s*=\s*\'(?:\\\\\'|[^\'])*\')\s*|\s*(\w+\s*=\s*\w+)\s*|\s+!'; |
347 | 450 |
$attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); |
348 | 451 |
foreach ($attribs as $key => $value) { |
... | ... | |
350 | 453 |
} |
351 | 454 |
|
352 | 455 |
$size = count($attribs); |
353 |
for ($i=1; $i < $size; $i++) {
|
|
354 |
// If the attribute is href or src, we may need to rewrite the URL in the value
|
|
456 |
for ($i = 1; $i < $size; $i++) {
|
|
457 |
// If the attribute is href or src, rewrite the URL in the value.
|
|
355 | 458 |
if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) { |
356 | 459 |
$url = trim($urls[1], " \t\n\r\0\x0B\"'"); |
357 | 460 |
|
358 | 461 |
if (empty($url)) { |
359 |
// If URL is empty, use current_url |
|
462 |
// If URL is empty, use current_url.
|
|
360 | 463 |
$path = explode('/', $_GET['q']); |
361 | 464 |
unset($path[0]); |
362 | 465 |
$path = implode('/', $path); |
363 | 466 |
if (ctype_digit($path)) { |
364 | 467 |
$path = "node/$path"; |
365 | 468 |
} |
366 |
// Printer-friendly URLs is on, so we need to make it absolute |
|
367 |
$newurl = url($path, array('fragment' => drupal_substr($url, 1), 'absolute' => TRUE)); |
|
469 |
// Printer-friendly URLs is on, so we need to make it absolute. |
|
470 |
$newurl = url($path, array( |
|
471 |
'fragment' => drupal_substr($url, 1), |
|
472 |
'absolute' => TRUE, |
|
473 |
)); |
|
368 | 474 |
} |
369 | 475 |
elseif (strpos(html_entity_decode($url), '://') || preg_match('!^mailto:.*?@.*?\..*?$!iu', html_entity_decode($url))) { |
370 |
// URL is absolute, do nothing |
|
476 |
// URL is absolute, do nothing.
|
|
371 | 477 |
$newurl = $url; |
372 | 478 |
} |
373 | 479 |
elseif (strpos(html_entity_decode($url), '//') === 0) { |
374 |
// URL is 'almost absolute', but it does not contain protocol; replace with base_path protocol |
|
480 |
// URL is 'almost absolute', but it does not contain protocol; replace |
|
481 |
// with base_path protocol. |
|
375 | 482 |
$newurl = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . ":" . $url; |
376 | 483 |
$matches[1] = str_replace($url, $newurl, $matches[1]); |
377 | 484 |
} |
378 | 485 |
else { |
379 | 486 |
if ($url[0] == '#') { |
380 |
// URL is an anchor tag |
|
487 |
// URL is an anchor tag.
|
|
381 | 488 |
if ($include_anchors && (!empty($_print_urls))) { |
382 | 489 |
$path = explode('/', $_GET['q']); |
383 | 490 |
unset($path[0]); |
... | ... | |
385 | 492 |
if (ctype_digit($path)) { |
386 | 493 |
$path = "node/$path"; |
387 | 494 |
} |
388 |
// Printer-friendly URLs is on, so we need to make it absolute |
|
389 |
$newurl = url($path, array('fragment' => drupal_substr($url, 1), 'absolute' => TRUE)); |
|
495 |
// Printer-friendly URLs is on, so we need to make it absolute. |
|
496 |
$newurl = url($path, array( |
|
497 |
'fragment' => drupal_substr($url, 1), |
|
498 |
'absolute' => TRUE, |
|
499 |
)); |
|
390 | 500 |
} |
391 | 501 |
// Because base href is the original page, change the link to |
392 |
// still be usable inside the print page |
|
502 |
// still be usable inside the print page.
|
|
393 | 503 |
$matches[1] = str_replace($url, check_plain(base_path() . $_GET['q'] . $url), $matches[1]); |
394 | 504 |
} |
395 | 505 |
else { |
396 |
// URL is relative, convert it into absolute URL |
|
506 |
// URL is relative, convert it into absolute URL.
|
|
397 | 507 |
if ($url[0] == '/') { |
398 |
// If it starts with '/' just append it to the server name |
|
508 |
// If it starts with '/' just append it to the server name.
|
|
399 | 509 |
$newurl = $base_root . '/' . trim($url, '/'); |
400 | 510 |
} |
401 | 511 |
elseif (preg_match('!^(?:index.php)?\?q=!i', $url)) { |
402 |
// If it starts with ?q=, just prepend with the base URL |
|
512 |
// If it starts with ?q=, just prepend with the base URL.
|
|
403 | 513 |
$newurl = $base_url . '/' . trim($url, '/'); |
404 | 514 |
} |
405 | 515 |
else { |
... | ... | |
425 | 535 |
/** |
426 | 536 |
* Auxiliary function to store the Printer-friendly URLs list as static. |
427 | 537 |
* |
428 |
* @param $url |
|
429 |
* absolute URL to be inserted in the list |
|
430 |
* @return |
|
538 |
* @param string|int $url |
|
539 |
* Absolute URL to be inserted in the list. |
|
540 |
* |
|
541 |
* @return array|int |
|
431 | 542 |
* list of URLs previously stored if $url is 0, or the current count |
432 | 543 |
* otherwise. |
433 | 544 |
*/ |
... | ... | |
443 | 554 |
return count($urls); |
444 | 555 |
} |
445 | 556 |
} |
446 |
$ret = $urls; |
|
447 |
$urls = array(); |
|
448 |
return $ret; |
|
557 |
else { |
|
558 |
$ret = $urls; |
|
559 |
$urls = array(); |
|
560 |
return $ret; |
|
561 |
} |
|
449 | 562 |
} |
450 | 563 |
|
451 | 564 |
/** |
452 |
* Check URL list settings for this node |
|
565 |
* Check URL list settings for this node.
|
|
453 | 566 |
* |
454 |
* @param node |
|
455 |
* node object |
|
456 |
* @param $format |
|
457 |
* format of the page being generated |
|
458 |
* @return |
|
567 |
* @param Object $node |
|
568 |
* Node object. |
|
569 |
* @param string $format |
|
570 |
* Format of the page being generated. |
|
571 |
* |
|
572 |
* @return bool |
|
459 | 573 |
* TRUE if URL list should be displayed, FALSE otherwise |
460 | 574 |
*/ |
461 |
function _print_url_list_enabled($node, $format = PRINT_HTML_FORMAT) {
|
|
575 |
function _print_url_list_enabled($node, $format) { |
|
462 | 576 |
if (!isset($node->type)) { |
463 |
switch ($format) { |
|
464 |
case PRINT_HTML_FORMAT: |
|
465 |
$node_urllist = variable_get('print_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT); |
|
466 |
break; |
|
467 |
case PRINT_MAIL_FORMAT: |
|
468 |
$node_urllist = variable_get('print_mail_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT); |
|
469 |
break; |
|
470 |
case PRINT_PDF_FORMAT: |
|
471 |
$node_urllist = variable_get('print_pdf_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT); |
|
472 |
break; |
|
473 |
default: |
|
474 |
$node_urllist = PRINT_TYPE_SYS_URLLIST_DEFAULT; |
|
475 |
} |
|
577 |
$node_urllist = variable_get('print_' . $format . '_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT); |
|
476 | 578 |
} |
477 | 579 |
else { |
478 |
switch ($format) { |
|
479 |
case PRINT_HTML_FORMAT: |
|
480 |
$node_urllist = isset($node->print_display_urllist) ? $node->print_display_urllist : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT); |
|
481 |
break; |
|
482 |
case PRINT_MAIL_FORMAT: |
|
483 |
$node_urllist = isset($node->print_mail_display_urllist) ? $node->print_mail_display_urllist : variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT); |
|
484 |
break; |
|
485 |
case PRINT_PDF_FORMAT: |
|
486 |
$node_urllist = isset($node->print_pdf_display_urllist) ? $node->print_pdf_display_urllist : variable_get('print_pdf_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT); |
|
487 |
break; |
|
488 |
default: |
|
489 |
$node_urllist = PRINT_TYPE_URLLIST_DEFAULT; |
|
490 |
} |
|
580 |
$node_urllist = isset($node->{'print_' . $format . '_display_urllist'}) ? $node->{'print_' . $format . '_display_urllist'} : variable_get('print_' . $format . '_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT); |
|
491 | 581 |
} |
492 | 582 |
|
493 |
// Get value of Printer-friendly URLs setting |
|
583 |
// Get value of Printer-friendly URLs setting.
|
|
494 | 584 |
return (variable_get('print_urls', PRINT_URLS_DEFAULT) && ($node_urllist)); |
495 | 585 |
} |
496 | 586 |
|
497 | 587 |
/** |
498 |
* Prepare a Printer-friendly-ready node body for content nodes |
|
499 |
* |
|
500 |
* @param $nid |
|
501 |
* node ID of the node to be rendered into a printer-friendly page |
|
502 |
* @param array $query |
|
503 |
* (optional) array of key/value pairs as used in the url() function for the |
|
504 |
* query |
|
505 |
* @param $cid |
|
506 |
* comment ID of the individual comment to be rendered |
|
507 |
* @param $format |
|
508 |
* format of the page being generated |
|
509 |
* @param $teaser |
|
510 |
* if set to TRUE, outputs only the node's teaser |
|
511 |
* @param $message |
|
512 |
* optional sender's message (used by the send email module) |
|
513 |
* @return |
|
514 |
* filled array ready to be used in the template |
|
588 |
* Prepare a Printer-friendly-ready node body for content nodes. |
|
589 |
* |
|
590 |
* @param int $nid |
|
591 |
* Node ID of the node to be rendered into a printer-friendly page. |
|
592 |
* @param string $format |
|
593 |
* Format of the page being generated. |
|
594 |
* @param int $vid |
|
595 |
* (Optional) revision ID of the node to use. |
|
596 |
* @param int $cid |
|
597 |
* (Optional) comment ID of the individual comment to be rendered. |
|
598 |
* @param string $view_mode |
|
599 |
* (Optional) view mode to be used when rendering the content. |
|
600 |
* |
|
601 |
* @return object|bool |
|
602 |
* filled node-like object to be used in the print template |
|
515 | 603 |
*/ |
516 |
function _print_generate_node($nid, $query = NULL, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
|
604 |
function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
|
|
517 | 605 |
global $_print_urls; |
518 | 606 |
|
519 | 607 |
if (!isset($langcode)) { |
520 | 608 |
$langcode = $GLOBALS['language_content']->language; |
521 | 609 |
} |
522 | 610 |
|
523 |
// We can take a node id |
|
524 |
$node = node_load($nid); |
|
611 |
// We can take a node id.
|
|
612 |
$node = node_load($nid, $vid);
|
|
525 | 613 |
if (!$node) { |
526 |
// Node not found |
|
614 |
// Node not found.
|
|
527 | 615 |
drupal_not_found(); |
528 |
return FALSE;
|
|
616 |
drupal_exit();
|
|
529 | 617 |
} |
530 | 618 |
elseif (!node_access('view', $node)) { |
531 |
// Access is denied |
|
619 |
// Access is denied.
|
|
532 | 620 |
drupal_access_denied(); |
533 |
return FALSE;
|
|
621 |
drupal_exit();
|
|
534 | 622 |
} |
535 | 623 |
drupal_set_title($node->title); |
536 | 624 |
|
537 |
$view_mode = $teaser ? 'teaser' : 'print'; |
|
538 |
|
|
539 |
// Turn off Pagination by the Paging module |
|
540 |
unset($node->pages); |
|
541 |
unset($node->page_count); |
|
542 |
|
|
543 |
// Make this page a member of the original page's organic group |
|
544 |
if (function_exists('og_set_group_context') && isset($node->og_groups)) { |
|
545 |
og_set_group_context($node->og_groups); |
|
546 |
} |
|
547 |
|
|
625 |
$build = array(); |
|
548 | 626 |
if ($cid === NULL) { |
549 | 627 |
// Adapted (simplified) version of node_view |
550 |
// Render the node content |
|
628 |
// Render the node content.
|
|
551 | 629 |
node_build_content($node, $view_mode); |
552 | 630 |
|
553 |
// Disable the links area |
|
631 |
// Disable the links area.
|
|
554 | 632 |
unset($node->content['links']); |
555 |
// Disable fivestar widget output |
|
556 |
unset($node->content['fivestar_widget']); |
|
557 |
// Disable service links module output |
|
558 |
unset($node->content['service_links']); |
|
559 | 633 |
|
560 | 634 |
$build = $node->content; |
561 | 635 |
unset($node->content); |
562 | 636 |
} |
563 | 637 |
|
564 |
$print_comments = variable_get('print_comments', PRINT_COMMENTS_DEFAULT); |
|
565 |
|
|
566 |
if (function_exists('comment_node_page_additions') && (($cid != NULL) || ($print_comments))) { |
|
567 |
// Print only the requested comment (or if $cid is NULL, all of them) |
|
568 |
|
|
638 |
if (function_exists('comment_node_page_additions') && |
|
639 |
(($cid != NULL) || (variable_get('print_comments', PRINT_COMMENTS_DEFAULT)))) { |
|
640 |
// Print only the requested comment (or if $cid is NULL, all of them). |
|
569 | 641 |
$comments = comment_node_page_additions($node); |
570 | 642 |
if (!empty($comments)) { |
571 | 643 |
unset($comments['comment_form']); |
... | ... | |
597 | 669 |
|
598 | 670 |
$content = render($build); |
599 | 671 |
|
600 |
// Get rid of any links before the content |
|
672 |
// Get rid of any links before the content.
|
|
601 | 673 |
$parts = explode('<div class="content', $content, 2); |
602 | 674 |
if (count($parts) == 2) { |
603 | 675 |
$pattern = '!(.*?)<a [^>]*?>(.*?)</a>(.*?)!mis'; |
... | ... | |
605 | 677 |
$content = implode('<div class="content', $parts); |
606 | 678 |
} |
607 | 679 |
|
608 |
// Check URL list settings |
|
680 |
// Check URL list settings.
|
|
609 | 681 |
$_print_urls = _print_url_list_enabled($node, $format); |
610 | 682 |
|
611 |
// Convert the a href elements |
|
683 |
// Convert the a href elements.
|
|
612 | 684 |
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is'; |
613 | 685 |
$content = preg_replace_callback($pattern, '_print_rewrite_urls', $content); |
614 | 686 |
|
615 |
$print = _print_var_generator($node, $query, $message, $cid); |
|
616 |
$print['content'] = $content; |
|
687 |
$node->content = $content; |
|
617 | 688 |
|
618 |
return $print;
|
|
689 |
return $node;
|
|
619 | 690 |
} |
620 | 691 |
|
621 | 692 |
/** |
622 |
* Prepare a Printer-friendly-ready node body for non-content pages |
|
623 |
* |
|
624 |
* @param $path |
|
625 |
* path of the node to be rendered into a printer-friendly page |
|
626 |
* @param array $query |
|
627 |
* (optional) array of key/value pairs as used in the url() function for the |
|
628 |
* query |
|
629 |
* @param $format |
|
630 |
* format of the page being generated |
|
631 |
* @param $teaser |
|
632 |
* if set to TRUE, outputs only the node's teaser |
|
633 |
* @param $message |
|
634 |
* optional sender's message (used by the send email module) |
|
635 |
* @return |
|
636 |
* filled array ready to be used in the template |
|
693 |
* Prepare a Printer-friendly-ready node body for non-content pages. |
|
694 |
* |
|
695 |
* @param string $path |
|
696 |
* Path of the node to be rendered into a printer-friendly page. |
|
697 |
* @param string $format |
|
698 |
* Format of the page being generated. |
|
699 |
* |
|
700 |
* @return object|bool |
|
701 |
* filled node-like object to be used in the print template |
|
637 | 702 |
*/ |
638 |
function _print_generate_path($path, $query = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
|
703 |
function _print_generate_path($path, $format) {
|
|
639 | 704 |
global $_print_urls; |
640 | 705 |
|
641 |
// Handle node tabs |
|
706 |
// Handle node tabs, or cases where the 'node_router' option is enabled.
|
|
642 | 707 |
$parts = explode('/', $path); |
643 |
if (ctype_digit($parts[0]) && (count($parts) > 1)) {
|
|
708 |
if (ctype_digit($parts[0]) && ((count($parts) > 1) || variable_get('print_node_router', FALSE))) {
|
|
644 | 709 |
$path = 'node/' . $path; |
645 | 710 |
} |
646 | 711 |
|
... | ... | |
649 | 714 |
menu_set_active_item($path); |
650 | 715 |
// Adapted from index.php. |
651 | 716 |
$node = new stdClass(); |
652 |
$node->body = menu_execute_active_handler($path, FALSE);
|
|
653 |
if (is_array($node->body)) {
|
|
654 |
$node->body = drupal_render($node->body);
|
|
717 |
$node->content = menu_execute_active_handler($path, FALSE);
|
|
718 |
if (is_array($node->content)) {
|
|
719 |
$node->content = drupal_render($node->content);
|
|
655 | 720 |
} |
656 | 721 |
|
657 |
if (is_int($node->body)) {
|
|
658 |
switch ($node->body) {
|
|
722 |
if (is_int($node->content)) {
|
|
723 |
switch ($node->content) {
|
|
659 | 724 |
case MENU_NOT_FOUND: |
660 | 725 |
drupal_not_found(); |
661 |
return FALSE;
|
|
726 |
drupal_exit();
|
|
662 | 727 |
break; |
728 |
|
|
663 | 729 |
case MENU_ACCESS_DENIED: |
664 | 730 |
drupal_access_denied(); |
665 |
return FALSE;
|
|
731 |
drupal_exit();
|
|
666 | 732 |
break; |
667 | 733 |
} |
668 | 734 |
} |
669 | 735 |
|
670 | 736 |
$node->title = drupal_get_title(); |
671 | 737 |
$node->path = $path; |
672 |
$node->changed = 0; |
|
738 |
$node->changed = REQUEST_TIME; |
|
739 |
$node->type = ''; |
|
673 | 740 |
|
674 |
// Delete any links area |
|
675 |
$node->body = preg_replace('!\s*<div class="links">.*?</div>!sim', '', $node->body);
|
|
741 |
// Delete any links area.
|
|
742 |
$node->content = preg_replace('!\s*<div class="links">.*?</div>!sim', '', $node->content);
|
|
676 | 743 |
|
677 |
// Delete the contextual links also |
|
744 |
// Delete the contextual links also.
|
|
678 | 745 |
$node->content = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $node->content); |
679 | 746 |
|
680 |
// Check URL list settings |
|
747 |
// Check URL list settings.
|
|
681 | 748 |
$_print_urls = _print_url_list_enabled($node, $format); |
682 | 749 |
|
683 |
// Convert the a href elements |
|
750 |
// Convert the a href elements.
|
|
684 | 751 |
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is'; |
685 |
$node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body); |
|
686 |
|
|
687 |
$print = _print_var_generator($node, $query, $message); |
|
688 |
$print['content'] = $node->body; |
|
752 |
$node->content = preg_replace_callback($pattern, '_print_rewrite_urls', $node->content); |
|
689 | 753 |
|
690 |
return $print;
|
|
754 |
return $node;
|
|
691 | 755 |
} |
692 | 756 |
|
693 |
|
|
694 | 757 |
/** |
695 |
* Prepare a Printer-friendly-ready node body for book pages |
|
696 |
* |
|
697 |
* @param $nid |
|
698 |
* node ID of the node to be rendered into a printer-friendly page |
|
699 |
* @param array $query |
|
700 |
* (optional) array of key/value pairs as used in the url() function for the |
|
701 |
* query |
|
702 |
* @param $format |
|
703 |
* format of the page being generated |
|
704 |
* @param $teaser |
|
705 |
* if set to TRUE, outputs only the node's teaser |
|
706 |
* @param $message |
|
707 |
* optional sender's message (used by the send email module) |
|
708 |
* @return |
|
709 |
* filled array ready to be used in the template |
|
758 |
* Prepare a Printer-friendly-ready node body for book pages. |
|
759 |
* |
|
760 |
* @param int $nid |
|
761 |
* Node ID of the node to be rendered into a printer-friendly page. |
|
762 |
* @param string $format |
|
763 |
* Format of the page being generated. |
|
764 |
* |
|
765 |
* @return object|bool |
|
766 |
* filled node-like object to be used in the print template |
|
710 | 767 |
*/ |
711 |
function _print_generate_book($nid, $query = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
|
768 |
function _print_generate_book($nid, $format) {
|
|
712 | 769 |
global $_print_urls; |
713 | 770 |
|
714 | 771 |
$node = node_load($nid); |
715 | 772 |
if (!$node) { |
716 |
// Node not found |
|
773 |
// Node not found.
|
|
717 | 774 |
drupal_not_found(); |
718 |
return FALSE;
|
|
775 |
drupal_exit();
|
|
719 | 776 |
} |
720 | 777 |
elseif (!node_access('view', $node) || (!user_access('access printer-friendly version'))) { |
721 |
// Access is denied |
|
778 |
// Access is denied.
|
|
722 | 779 |
drupal_access_denied(); |
723 |
return FALSE;
|
|
780 |
drupal_exit();
|
|
724 | 781 |
} |
725 | 782 |
|
726 | 783 |
$tree = book_menu_subtree_data($node->book); |
727 |
$node->body = book_export_traverse($tree, 'book_node_export');
|
|
784 |
$node->content = book_export_traverse($tree, 'book_node_export');
|
|
728 | 785 |
|
729 |
// Check URL list settings |
|
786 |
// Check URL list settings.
|
|
730 | 787 |
$_print_urls = _print_url_list_enabled($node, $format); |
731 | 788 |
|
732 |
// Convert the a href elements |
|
789 |
// Convert the a href elements.
|
|
733 | 790 |
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is'; |
734 |
$node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body); |
|
735 |
|
|
736 |
$print = _print_var_generator($node, $query, $message); |
|
737 |
$print['content'] = $node->body; |
|
738 |
|
|
739 |
// The title is already displayed by the book_recurse, so avoid duplication |
|
740 |
$print['title'] = ''; |
|
791 |
$node->content = preg_replace_callback($pattern, '_print_rewrite_urls', $node->content); |
|
741 | 792 |
|
742 |
return $print;
|
|
793 |
return $node;
|
|
743 | 794 |
} |
Also available in: Unified diff
Weekly update of contrib modules