Issue #1299150 by pluess: rules action to send an e-nail of a configured node.
[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) && empty($_POST)) {
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' => $print_css,
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', 'garland')))) .'<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/content/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_copy($file, $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 '#wysiwyg' => FALSE,
254 );
255
256 $access = user_access('use PHP for link visibility');
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 $form['settings']['adv_link']['print_html_sys_link_visibility'] = array(
268 '#type' => 'radios',
269 '#title' => t('Show link in system (non-content) pages'),
270 '#default_value' => variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT),
271 '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
272 );
273
274 $form['settings']['adv_link']['print_html_sys_link_pages'] = array(
275 '#type' => 'textarea',
276 '#default_value' => variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT),
277 '#rows' => 3,
278 '#description' => t('Setting this option will add a printer-friendly version page link on pages created by Drupal or the enabled modules.') .'<br />'.
279 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>')),
280 '#wysiwyg' => FALSE,
281 );
282
283 if ($form['settings']['adv_link']['print_html_sys_link_visibility']['#default_value'] == 2 && !$access) {
284 $form['settings']['adv_link']['print_html_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
285 $form['settings']['adv_link']['print_html_sys_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_html_sys_link_pages']['#default_value']);
286 }
287 elseif ($access) {
288 $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).');
289 $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 ?>'));
290 }
291
292 $form['settings']['adv_link']['print_html_book_link'] = array(
293 '#type' => 'radios',
294 '#title' => t('Link in book hierarchy nodes'),
295 '#default_value' => variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT),
296 '#options' => array(t('Book module link not modified'), t('Current page and sub-pages'), t('Current page only')),
297 );
298
299 $form['settings']['print_html_new_window'] = array(
300 '#type' => 'checkbox',
301 '#title' => t('Open the printer-friendly version in a new window'),
302 '#default_value' => variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT),
303 '#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
304 );
305
306 $form['settings']['print_html_sendtoprinter'] = array(
307 '#type' => 'checkbox',
308 '#title' => t('Send to printer'),
309 '#default_value' => variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT),
310 '#description' => t("Automatically calls the browser's print function when the printer-friendly version is displayed."),
311 );
312
313 $form['settings']['print_html_windowclose'] = array(
314 '#type' => 'checkbox',
315 '#title' => t('Close window after sending to printer'),
316 '#default_value' => variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT),
317 '#description' => t("When the above options are enabled, this option will close the window after its contents are printed."),
318 );
319
320 $form['settings']['print_display_sys_urllist'] = array(
321 '#type' => 'checkbox',
322 '#title' => t('Printer-friendly URLs list in system pages'),
323 '#default_value' => variable_get('print_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
324 '#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
325 );
326
327 $form['settings']['print_robots_settings'] = array(
328 '#type' => 'fieldset',
329 '#title' => t('Robots META tags'),
330 '#collapsible' => TRUE,
331 '#collapsed' => TRUE,
332 );
333
334 $form['settings']['print_robots_settings']['print_robots_noindex'] = array(
335 '#type' => 'checkbox',
336 '#title' => t('Add noindex'),
337 '#default_value' => variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT),
338 '#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.'),
339 );
340
341 $form['settings']['print_robots_settings']['print_robots_nofollow'] = array(
342 '#type' => 'checkbox',
343 '#title' => t('Add nofollow'),
344 '#default_value' => variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT),
345 '#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.'),
346 );
347
348 $form['settings']['print_robots_settings']['print_robots_noarchive'] = array(
349 '#type' => 'checkbox',
350 '#title' => t('Add noarchive'),
351 '#default_value' => variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT),
352 '#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.'),
353 );
354
355 return system_settings_form($form);
356 }
357
358 /**
359 * Menu callback for the Printer-friendly pages module text strings settings form.
360 *
361 * @ingroup forms
362 */
363 function print_main_strings_settings() {
364 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');
365
366 $form['print_main_text'] = array(
367 '#type' => 'fieldset',
368 '#title' => t('Text strings'),
369 );
370
371 $form['print_main_text']['print_text_published'] = array(
372 '#type' => 'textfield',
373 '#default_value' => variable_get('print_text_published', t('Published on %site_name')),
374 );
375 $form['print_main_text']['print_text_source_url'] = array(
376 '#type' => 'textfield',
377 '#default_value' => variable_get('print_text_source_url', t('Source URL')),
378 );
379 $form['print_main_text']['print_text_retrieved'] = array(
380 '#type' => 'textfield',
381 '#default_value' => variable_get('print_text_retrieved', t('retrieved on %date')),
382 );
383 $form['print_main_text']['print_text_links'] = array(
384 '#type' => 'textfield',
385 '#default_value' => variable_get('print_text_links', t('Links')),
386 );
387
388 return system_settings_form($form);
389 }
390
391 /**
392 * Menu callback for the Printer-friendly pages module text strings settings form.
393 *
394 * @ingroup forms
395 */
396 function print_html_strings_settings() {
397 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');
398
399 $form['print_html_text'] = array(
400 '#type' => 'fieldset',
401 '#title' => t('Text strings'),
402 );
403
404 $form['print_html_text']['print_html_link_text'] = array(
405 '#type' => 'textfield',
406 '#title' => t('Link text'),
407 '#default_value' => variable_get('print_html_link_text', t('Printer-friendly version')),
408 '#description' => t('Text used in the link to the printer-friendly version.'),
409 );
410
411 return system_settings_form($form);
412 }