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