Issue #1228472: fix display of footer blocks when using the theme's footer option.
[project/print.git] / print.admin.inc
1 <?php
2
3 /**
4 * @file
5 * Contains the administrative functions of the PF module.
6 *
7 * This file is included by the core PF module, and includes the
8 * settings form.
9 *
10 * @ingroup print
11 */
12
13 /**
14 * Menu callback for the Printer-friendly pages module settings form.
15 *
16 * @ingroup forms
17 */
18 function print_main_settings() {
19 $print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
20 // Check that the stylesheet path is indeed valid and relative to base_path()
21 if (!empty($print_css)) {
22 $css_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default', 'garland'))));
23 if (!is_file($css_path) || !is_readable($css_path)) {
24 drupal_set_message(t("File %file is not readable by the web server.", array('%file' => $css_path)), 'warning', FALSE);
25 }
26 }
27
28 $form['settings'] = array(
29 '#type' => 'fieldset',
30 '#title' => t('Common Settings'),
31 );
32
33 $form['settings']['print_css'] = array(
34 '#type' => 'textfield',
35 '#title' => t('Custom Stylesheet'),
36 '#default_value' => variable_get('print_css', PRINT_CSS_DEFAULT),
37 '#size' => 60,
38 '#maxlength' => 250,
39 '#description' => t('The path to your custom print cascading stylesheet, if any. The path provided must be relative to the base path. When none is specified, the default module CSS file is used.') . '<br />' .
40 t('Macros: %t (path to theme: "%theme")', array('%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')))) . '<br />' .
41 t('Requires the <em>administer site configuration</em> permission.'),
42 '#disabled' => !user_access('administer site configuration'),
43 );
44
45 $form['settings']['print_urls'] = array(
46 '#type' => 'checkbox',
47 '#title' => t('Printer-friendly URLs list'),
48 '#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
49 '#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.') . '<br />' .
50 t('Note that you can enable/disable the URL list for each content type individually from the !url.', array('!url' => l(t('Content Types page'), 'admin/structure/types'))),
51 );
52
53 $form['settings']['print_urls_anchors'] = array(
54 '#type' => 'checkbox',
55 '#title' => t('Include named anchors in printer-friendly URLs list'),
56 '#default_value' => variable_get('print_urls_anchors', PRINT_URLS_ANCHORS_DEFAULT),
57 '#description' => t('If set, the list of the URLs at the bottom of the page will include anchors links on the same page.'),
58 );
59
60 $form['settings']['print_comments'] = array(
61 '#type' => 'checkbox',
62 '#title' => t('Include comments in printer-friendly version'),
63 '#default_value' => variable_get('print_comments', PRINT_COMMENTS_DEFAULT),
64 '#description' => t('When this option is active, user comments are also included in the printer-friendly version. Requires the comment module.'),
65 );
66
67 $form['settings']['print_newwindow'] = array(
68 '#type' => 'radios',
69 '#title' => t('New window method'),
70 '#options' => array(t('Use HTML target (does not validate as XHTML Strict)'), t('Use Javascript (requires browser support)')),
71 '#default_value' => variable_get('print_newwindow', PRINT_NEWWINDOW_DEFAULT),
72 '#description' => t('Choose the method used to open pages in a new window/tab.'),
73 );
74
75 $form['settings']['logo'] = array(
76 '#type' => 'fieldset',
77 '#title' => t('Logo options'),
78 '#collapsible' => TRUE,
79 '#collapsed' => TRUE,
80 );
81
82 $form['settings']['logo']['print_logo_options'] = array(
83 '#type' => 'radios',
84 '#title' => t('Logo type'),
85 '#options' => array(t('None (Disabled)'), t("Current theme's logo"), t('User-specified')),
86 '#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
87 '#description' => t("Select the type of logo to display on the printer-friendly version. In case of a user-specified location, insert the path or URL below."),
88 );
89
90 $form['settings']['logo']['print_logo_url'] = array(
91 '#type' => 'textfield',
92 '#title' => t('Logo URL'),
93 '#default_value' => variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT),
94 '#size' => 60,
95 '#maxlength' => 250,
96 );
97
98 $form['settings']['logo']['print_logo_upload'] = array(
99 '#type' => 'file',
100 '#title' => t('Upload logo'),
101 '#size' => 60,
102 '#maxlength' => 250,
103 '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
104 );
105
106 $form['settings']['footer'] = array(
107 '#type' => 'fieldset',
108 '#title' => t('Footer options'),
109 '#collapsible' => TRUE,
110 '#collapsed' => TRUE,
111 );
112
113 $form['settings']['footer']['print_footer_options'] = array(
114 '#type' => 'radios',
115 '#title' => t('Footer type'),
116 '#options' => array(t('None (Disabled)'), t("Site's footer"), t('User-specified')),
117 '#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
118 '#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
119 );
120
121 $form['settings']['footer']['print_footer_user'] = array(
122 '#type' => 'textfield',
123 '#title' => t('User-specified'),
124 '#default_value' => variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT),
125 '#size' => 60,
126 '#maxlength' => 250,
127 );
128
129 $form['settings']['print_sourceurl_settings'] = array(
130 '#type' => 'fieldset',
131 '#title' => t('Source URL'),
132 '#collapsible' => TRUE,
133 '#collapsed' => TRUE,
134 );
135
136 $form['settings']['print_sourceurl_settings']['print_sourceurl_enabled'] = array(
137 '#type' => 'checkbox',
138 '#title' => t('Display source URL'),
139 '#default_value' => variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT),
140 '#description' => t('When this option is selected, the URL for the original page will be displayed at the bottom of the printer-friendly version.'),
141 );
142
143 $form['settings']['print_sourceurl_settings']['print_sourceurl_date'] = array(
144 '#type' => 'checkbox',
145 '#title' => t('Add current time/date to the source URL'),
146 '#default_value' => variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT),
147 '#description' => t('Display the current date and time in the Source URL line.'),
148 );
149
150 $form['settings']['print_sourceurl_settings']['print_sourceurl_forcenode'] = array(
151 '#type' => 'checkbox',
152 '#title' => t('Force use of node ID in source URL'),
153 '#default_value' => variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT),
154 '#description' => t("Drupal will attempt to use the page's defined alias in case there is one. To force the use of the fixed URL, activate this option."),
155 );
156
157 $form['#attributes'] = array('enctype' => 'multipart/form-data');
158 $form['#validate'][] = '_print_main_settings_validate';
159
160 return system_settings_form($form);
161 }
162
163 /**
164 * Validate print_main_settings form.
165 */
166 function _print_main_settings_validate($form, &$form_state) {
167 global $base_url;
168
169 // Check for a new uploaded logo, and use that instead.
170 if ($file = file_save_upload('print_logo_upload', array('file_validate_is_image' => array()))) {
171 $parts = pathinfo($file->filename);
172 $filename = 'print_logo.' . drupal_strtolower($parts['extension']);
173
174 // The image was saved using file_save_upload() and was added to the
175 // files table as a temporary file. We'll make a copy and let the garbage
176 // collector delete the original upload.
177 if (file_unmanaged_copy($file->filename, $filename, FILE_EXISTS_REPLACE)) {
178 $form_state['values']['print_logo_options'] = 2;
179 $form_state['values']['print_logo_url'] = base_path() . $file->filepath;
180 }
181 }
182 }
183
184 /**
185 * Menu callback for the Printer-friendly pages HTML settings form.
186 *
187 * @ingroup forms
188 */
189 function print_html_settings() {
190 $form['settings'] = array(
191 '#type' => 'fieldset',
192 '#title' => t('Web page options'),
193 );
194
195 $form['settings']['print_html_link_pos'] = array(
196 '#type' => 'checkboxes',
197 '#title' => t('Printer-friendly page link'),
198 '#default_value' => variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT => PRINT_HTML_LINK_POS_DEFAULT)),
199 '#options' => array('link' => t('Links area'), 'corner' => t('Content corner')),
200 '#description' => t('Choose the location of the link(s) to the printer-friendly page. The Links area is usually below the node content, whereas the Content corner is placed in the upper-right corner of the node content. Unselect all options to disable the link. Even if the link is disabled, you can still view the print version of a node by going to !path/nid where nid is the numeric id of the node.', array('!path' => PRINT_PATH)),
201 );
202
203 $form['settings']['print_html_link_teaser'] = array(
204 '#type' => 'checkbox',
205 '#title' => t('Display printer-friendly link in teaser'),
206 '#default_value' => variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT),
207 '#description' => t('Enabling this will display the link in teaser mode.'),
208 );
209
210 $form['settings']['adv_link'] = array(
211 '#type' => 'fieldset',
212 '#title' => t('Advanced link options'),
213 '#collapsible' => TRUE,
214 '#collapsed' => FALSE,
215 );
216
217 $form['settings']['adv_link']['print_html_show_link'] = array(
218 '#type' => 'radios',
219 '#title' => t('Link style'),
220 '#default_value' => variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT),
221 '#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
222 '#description' => t('Select the visual style of the link.'),
223 );
224
225 $form['settings']['adv_link']['print_html_link_use_alias'] = array(
226 '#type' => 'checkbox',
227 '#title' => t('Use URL alias instead of node ID'),
228 '#default_value' => variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT),
229 '#description' => t('Enabling this will create the link using the URL alias instead of the node ID.'),
230 );
231
232 $form['settings']['adv_link']['print_html_link_class'] = array(
233 '#type' => 'textfield',
234 '#title' => t('Link class'),
235 '#default_value' => variable_get('print_html_link_class', PRINT_HTML_LINK_CLASS_DEFAULT),
236 '#size' => 60,
237 '#maxlength' => 250,
238 '#description' => t('This can be used by themers to change the link style or by jQuery modules to open in a new window (e.g. greybox or thickbox). Multiple classes can be specified, separated by spaces.'),
239 );
240
241 $form['settings']['adv_link']['print_html_node_link_visibility'] = array(
242 '#type' => 'radios',
243 '#title' => t('Link visibility'),
244 '#default_value' => variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT),
245 '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
246 );
247
248 $form['settings']['adv_link']['print_html_node_link_pages'] = array(
249 '#type' => 'textarea',
250 '#default_value' => variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT),
251 '#rows' => 3,
252 '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
253 );
254
255 if (module_exists('php')) {
256 $access = user_access('use PHP for settings');
257
258 if ($form['settings']['adv_link']['print_html_node_link_visibility']['#default_value'] == 2 && !$access) {
259 $form['settings']['adv_link']['print_html_node_link_visibility'] = array('#type' => 'value', '#value' => 2);
260 $form['settings']['adv_link']['print_html_node_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_html_node_link_pages']['#default_value']);
261 }
262 elseif ($access) {
263 $form['settings']['adv_link']['print_html_node_link_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
264 $form['settings']['adv_link']['print_html_node_link_pages']['#description'] .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
265 }
266 }
267
268 $form['settings']['adv_link']['print_html_sys_link_visibility'] = array(
269 '#type' => 'radios',
270 '#title' => t('Show link in system (non-content) pages'),
271 '#default_value' => variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT),
272 '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
273 );
274
275 $form['settings']['adv_link']['print_html_sys_link_pages'] = array(
276 '#type' => 'textarea',
277 '#default_value' => variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT),
278 '#rows' => 3,
279 '#description' => t('Setting this option will add a printer-friendly version page link on pages created by Drupal or the enabled modules.') . '<br />' .
280 t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
281 );
282
283 if (module_exists('php')) {
284 if ($form['settings']['adv_link']['print_html_sys_link_visibility']['#default_value'] == 2 && !$access) {
285 $form['settings']['adv_link']['print_html_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
286 $form['settings']['adv_link']['print_html_sys_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_html_sys_link_pages']['#default_value']);
287 }
288 elseif ($access) {
289 $form['settings']['adv_link']['print_html_sys_link_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
290 $form['settings']['adv_link']['print_html_sys_link_pages']['#description'] .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
291 }
292 }
293
294 $form['settings']['adv_link']['print_html_book_link'] = array(
295 '#type' => 'radios',
296 '#title' => t('Link in book hierarchy nodes'),
297 '#default_value' => variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT),
298 '#options' => array(t('Book module link not modified'), t('Current page and sub-pages'), t('Current page only')),
299 );
300
301 $form['settings']['print_html_new_window'] = array(
302 '#type' => 'checkbox',
303 '#title' => t('Open the printer-friendly version in a new window'),
304 '#default_value' => variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT),
305 '#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
306 );
307
308 $form['settings']['print_html_sendtoprinter'] = array(
309 '#type' => 'checkbox',
310 '#title' => t('Send to printer'),
311 '#default_value' => variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT),
312 '#description' => t("Automatically calls the browser's print function when the printer-friendly version is displayed."),
313 );
314
315 $form['settings']['print_html_windowclose'] = array(
316 '#type' => 'checkbox',
317 '#title' => t('Close window after sending to printer'),
318 '#default_value' => variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT),
319 '#description' => t("When the above options are enabled, this option will close the window after its contents are printed."),
320 );
321
322 $form['settings']['print_robots_settings'] = array(
323 '#type' => 'fieldset',
324 '#title' => t('Robots META tags'),
325 '#collapsible' => TRUE,
326 '#collapsed' => TRUE,
327 );
328
329 $form['settings']['print_robots_settings']['print_robots_noindex'] = array(
330 '#type' => 'checkbox',
331 '#title' => t('Add noindex'),
332 '#default_value' => variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT),
333 '#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.'),
334 );
335
336 $form['settings']['print_robots_settings']['print_robots_nofollow'] = array(
337 '#type' => 'checkbox',
338 '#title' => t('Add nofollow'),
339 '#default_value' => variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT),
340 '#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.'),
341 );
342
343 $form['settings']['print_robots_settings']['print_robots_noarchive'] = array(
344 '#type' => 'checkbox',
345 '#title' => t('Add noarchive'),
346 '#default_value' => variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT),
347 '#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.'),
348 );
349
350 return system_settings_form($form);
351 }
352
353 /**
354 * Menu callback for the Printer-friendly pages module text strings settings form.
355 *
356 * @ingroup forms
357 */
358 function print_main_strings_settings() {
359 drupal_set_message(t("Saving these strings will disable their translation via Drupal's language system. Use the reset button to return them to the original state."), 'warning');
360
361 $form['print_main_text'] = array(
362 '#type' => 'fieldset',
363 '#title' => t('Text strings'),
364 );
365
366 $form['print_main_text']['print_text_published'] = array(
367 '#type' => 'textfield',
368 '#default_value' => variable_get('print_text_published', t('Published on %site_name')),
369 );
370 $form['print_main_text']['print_text_source_url'] = array(
371 '#type' => 'textfield',
372 '#default_value' => variable_get('print_text_source_url', t('Source URL')),
373 );
374 $form['print_main_text']['print_text_retrieved'] = array(
375 '#type' => 'textfield',
376 '#default_value' => variable_get('print_text_retrieved', t('retrieved on %date')),
377 );
378 $form['print_main_text']['print_text_links'] = array(
379 '#type' => 'textfield',
380 '#default_value' => variable_get('print_text_links', t('Links')),
381 );
382 $form['print_main_text']['reset'] = array(
383 '#type' => 'submit',
384 '#value' => t('Reset to defaults'),
385 '#submit' => array('print_main_strings_settings_delete'),
386 );
387
388 return system_settings_form($form);
389 }
390
391 /**
392 * Reset button callback for text strings settings form
393 *
394 * @ingroup forms
395 */
396 function print_main_strings_settings_delete() {
397 variable_del('print_text_published');
398 variable_del('print_text_source_url');
399 variable_del('print_text_retrieved');
400 variable_del('print_text_links');
401 }
402
403 /**
404 * Menu callback for the Printer-friendly pages module text strings settings form.
405 *
406 * @ingroup forms
407 */
408 function print_html_strings_settings() {
409 drupal_set_message(t("Saving these strings will disable their translation via Drupal's language system. Use the reset button to return them to the original state."), 'warning');
410
411 $form['print_html_text'] = array(
412 '#type' => 'fieldset',
413 '#title' => t('Text strings'),
414 );
415
416 $form['print_html_text']['print_html_link_text'] = array(
417 '#type' => 'textfield',
418 '#title' => t('Link text'),
419 '#default_value' => variable_get('print_html_link_text', t('Printer-friendly version')),
420 '#description' => t('Text used in the link to the printer-friendly version.'),
421 );
422 $form['print_html_text']['reset'] = array(
423 '#type' => 'submit',
424 '#value' => t('Reset to defaults'),
425 '#submit' => array('print_html_strings_settings_delete'),
426 );
427
428 return system_settings_form($form);
429 }
430
431 /**
432 * Reset button callback for text strings settings form
433 *
434 * @ingroup forms
435 */
436 function print_html_strings_settings_delete() {
437 variable_del('print_html_link_text');
438 }