Projet

Général

Profil

Paste
Télécharger (20,3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / print / print.admin.inc @ ba09eb79

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', '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_keep_theme_css'] = array(
46
    '#type' => 'checkbox',
47
    '#title' => t('Keep the current theme CSS'),
48
    '#default_value' => variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT),
49
    '#description' => t('If set, the current theme css will still be applied to the printer-friendly versions.'),
50
  );
51

    
52
  $form['settings']['print_urls'] = array(
53
    '#type' => 'checkbox',
54
    '#title' => t('Printer-friendly URLs list'),
55
    '#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
56
    '#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.') . '<br />' .
57
                      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'))),
58
  );
59

    
60
  $form['settings']['print_urls_anchors'] = array(
61
    '#type' => 'checkbox',
62
    '#title' => t('Include named anchors in printer-friendly URLs list'),
63
    '#default_value' => variable_get('print_urls_anchors', PRINT_URLS_ANCHORS_DEFAULT),
64
    '#description' => t('If set, the list of the URLs at the bottom of the page will include anchors links on the same page.'),
65
  );
66

    
67
  $form['settings']['print_comments'] = array(
68
    '#type' => 'checkbox',
69
    '#title' => t('Include comments in printer-friendly version'),
70
    '#default_value' => variable_get('print_comments', PRINT_COMMENTS_DEFAULT),
71
    '#description' => t('When this option is active, user comments are also included in the printer-friendly version. Requires the comment module.'),
72
  );
73

    
74
  $form['settings']['print_newwindow'] = array(
75
    '#type' => 'radios',
76
    '#title' => t('New window method'),
77
    '#options' => array(t('Use HTML target (does not validate as XHTML Strict)'), t('Use Javascript (requires browser support)')),
78
    '#default_value' => variable_get('print_newwindow', PRINT_NEWWINDOW_DEFAULT),
79
    '#description' => t('Choose the method used to open pages in a new window/tab.'),
80
  );
81

    
82
  $form['settings']['logo'] = array(
83
    '#type' => 'fieldset',
84
    '#title' => t('Logo options'),
85
    '#collapsible' => TRUE,
86
    '#collapsed' => TRUE,
87
  );
88

    
89
  $form['settings']['logo']['print_logo_options'] = array(
90
    '#type' => 'radios',
91
    '#title' => t('Logo type'),
92
    '#options' => array(t('None (Disabled)'), t("Current theme's logo"), t('User-specified')),
93
    '#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
94
    '#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."),
95
  );
96

    
97
  $form['settings']['logo']['print_logo_url'] = array(
98
    '#type' => 'textfield',
99
    '#title' => t('Logo URL'),
100
    '#default_value' => variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT),
101
    '#size' => 60,
102
    '#maxlength' => 250,
103
  );
104

    
105
  $form['settings']['logo']['print_logo_upload'] = array(
106
    '#type' => 'file',
107
    '#title' => t('Upload logo'),
108
    '#size' => 60,
109
    '#maxlength' => 250,
110
    '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
111
  );
112

    
113
  $form['settings']['footer'] = array(
114
    '#type' => 'fieldset',
115
    '#title' => t('Footer options'),
116
    '#collapsible' => TRUE,
117
    '#collapsed' => TRUE,
118
  );
119

    
120
  $form['settings']['footer']['print_footer_options'] = array(
121
    '#type' => 'radios',
122
    '#title' => t('Footer type'),
123
    '#options' => array(t('None (Disabled)'), t("Site's footer"), t('User-specified')),
124
    '#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
125
    '#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
126
  );
127

    
128
  $form['settings']['footer']['print_footer_user'] = array(
129
    '#type' => 'textfield',
130
    '#title' => t('User-specified'),
131
    '#default_value' => variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT),
132
    '#size' => 60,
133
    '#maxlength' => 250,
134
  );
135

    
136
  $form['settings']['print_sourceurl_settings'] = array(
137
    '#type' => 'fieldset',
138
    '#title' => t('Source URL'),
139
    '#collapsible' => TRUE,
140
    '#collapsed' => TRUE,
141
  );
142

    
143
  $form['settings']['print_sourceurl_settings']['print_sourceurl_enabled'] = array(
144
    '#type' => 'checkbox',
145
    '#title' => t('Display source URL'),
146
    '#default_value' => variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT),
147
    '#description' => t('When this option is selected, the URL for the original page will be displayed at the bottom of the printer-friendly version.'),
148
  );
149

    
150
  $form['settings']['print_sourceurl_settings']['print_sourceurl_date'] = array(
151
    '#type' => 'checkbox',
152
    '#title' => t('Add current time/date to the source URL'),
153
    '#default_value' => variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT),
154
    '#description' => t('Display the current date and time in the Source URL line.'),
155
  );
156

    
157
  $form['settings']['print_sourceurl_settings']['print_sourceurl_forcenode'] = array(
158
    '#type' => 'checkbox',
159
    '#title' => t('Force use of node ID in source URL'),
160
    '#default_value' => variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT),
161
    '#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."),
162
  );
163

    
164
  $form['#attributes'] = array('enctype' => 'multipart/form-data');
165
  $form['#validate'][] = '_print_main_settings_validate';
166

    
167
  return system_settings_form($form);
168
}
169

    
170
/**
171
 * Validate print_main_settings form.
172
 */
173
function _print_main_settings_validate($form, &$form_state) {
174
  global $base_root;
175

    
176
  // Check for a new uploaded logo, and use that instead.
177
  if ($file = file_save_upload('print_logo_upload', array('file_validate_is_image' => array()))) {
178
    // The image was saved using file_save_upload() and was added to the
179
    // files table as a temporary file. We'll make a copy and let the garbage
180
    // collector delete the original upload.
181
    if ($filename = file_unmanaged_copy($file->uri)) {
182
      $wrapper = file_stream_wrapper_get_instance_by_uri($filename);
183

    
184
      $form_state['values']['print_logo_options'] = 2;
185
      $form_state['values']['print_logo_url'] = str_replace($base_root, '', $wrapper->getExternalUrl());
186
    }
187
  }
188
}
189

    
190
/**
191
 * Menu callback for the Printer-friendly pages HTML settings form.
192
 *
193
 * @ingroup forms
194
 */
195
function print_html_settings() {
196
  $form['settings'] = array(
197
    '#type' => 'fieldset',
198
    '#title' => t('Web page options'),
199
  );
200

    
201
  $form['settings']['print_html_link_pos'] = array(
202
    '#type' => 'checkboxes',
203
    '#title' => t('Printer-friendly page link'),
204
    '#default_value' => variable_get('print_html_link_pos', drupal_json_decode(PRINT_HTML_LINK_POS_DEFAULT)),
205
    '#options' => array('link' => t('Links area'), 'corner' => t('Content corner'), 'block' => t('Block'), 'help' => t('Help area')),
206
    '#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)),
207
  );
208

    
209
  $form['settings']['print_html_link_teaser'] = array(
210
    '#type' => 'checkbox',
211
    '#title' => t('Display printer-friendly link in teaser'),
212
    '#default_value' => variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT),
213
    '#description' => t('Enabling this will display the link in teaser mode.'),
214
  );
215

    
216
  $form['settings']['adv_link'] = array(
217
    '#type' => 'fieldset',
218
    '#title' => t('Advanced link options'),
219
    '#collapsible' => TRUE,
220
    '#collapsed' => FALSE,
221
  );
222

    
223
  $form['settings']['adv_link']['print_html_show_link'] = array(
224
    '#type' => 'radios',
225
    '#title' => t('Link style'),
226
    '#default_value' => variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT),
227
    '#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
228
    '#description' => t('Select the visual style of the link.'),
229
  );
230

    
231
  $form['settings']['adv_link']['print_html_link_use_alias'] = array(
232
    '#type' => 'checkbox',
233
    '#title' => t('Use URL alias instead of node ID'),
234
    '#default_value' => variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT),
235
    '#description' => t('Enabling this will create the link using the URL alias instead of the node ID.'),
236
  );
237

    
238
  $form['settings']['adv_link']['print_html_link_class'] = array(
239
    '#type' => 'textfield',
240
    '#title' => t('Link class'),
241
    '#default_value' => variable_get('print_html_link_class', PRINT_HTML_LINK_CLASS_DEFAULT),
242
    '#size' => 60,
243
    '#maxlength' => 250,
244
    '#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.'),
245
  );
246

    
247
  $form['settings']['adv_link']['print_html_node_link_visibility'] = array(
248
    '#type' => 'radios',
249
    '#title' => t('Link visibility'),
250
    '#default_value' => variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT),
251
    '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
252
  );
253

    
254
  $form['settings']['adv_link']['print_html_node_link_pages'] = array(
255
    '#type' => 'textarea',
256
    '#default_value' => variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT),
257
    '#rows' => 3,
258
    '#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>')),
259
  );
260

    
261
  if (module_exists('php')) {
262
    $access = user_access('use PHP for settings');
263

    
264
    if ($form['settings']['adv_link']['print_html_node_link_visibility']['#default_value'] == 2 && !$access) {
265
      $form['settings']['adv_link']['print_html_node_link_visibility'] = array('#type' => 'value', '#value' => 2);
266
      $form['settings']['adv_link']['print_html_node_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_html_node_link_pages']['#default_value']);
267
    }
268
    elseif ($access) {
269
      $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).');
270
      $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 ?>'));
271
    }
272
  }
273

    
274
  $form['settings']['adv_link']['print_html_sys_link_visibility'] = array(
275
    '#type' => 'radios',
276
    '#title' => t('Show link in system (non-content) pages'),
277
    '#description' => 'Any page that is not a Drupal node. Usually pages generated by Drupal or a module such as Views or Panels.',
278
    '#default_value' => variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT),
279
    '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
280
  );
281

    
282
  $form['settings']['adv_link']['print_html_sys_link_pages'] = array(
283
    '#type' => 'textarea',
284
    '#default_value' => variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT),
285
    '#rows' => 3,
286
    '#description' => t('Setting this option will add a printer-friendly version page link on pages created by Drupal or the enabled modules.') . '<br />' .
287
                      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>')),
288
  );
289

    
290
  if (module_exists('php')) {
291
    if ($form['settings']['adv_link']['print_html_sys_link_visibility']['#default_value'] == 2 && !$access) {
292
      $form['settings']['adv_link']['print_html_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
293
      $form['settings']['adv_link']['print_html_sys_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_html_sys_link_pages']['#default_value']);
294
    }
295
    elseif ($access) {
296
      $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).');
297
      $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 ?>'));
298
    }
299
  }
300

    
301
  $form['settings']['adv_link']['print_html_book_link'] = array(
302
    '#type' => 'radios',
303
    '#title' => t('Link in book hierarchy nodes'),
304
    '#default_value' => variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT),
305
    '#options' => array(t('Book module link not modified'), t('Current page and sub-pages'), t('Current page only')),
306
  );
307

    
308
  $form['settings']['print_html_new_window'] = array(
309
    '#type' => 'checkbox',
310
    '#title' => t('Open the printer-friendly version in a new window'),
311
    '#default_value' => variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT),
312
    '#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
313
  );
314

    
315
  $form['settings']['print_html_sendtoprinter'] = array(
316
    '#type' => 'checkbox',
317
    '#title' => t('Send to printer'),
318
    '#default_value' => variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT),
319
    '#description' => t("Automatically calls the browser's print function when the printer-friendly version is displayed."),
320
  );
321

    
322
  $form['settings']['print_html_windowclose'] = array(
323
    '#type' => 'checkbox',
324
    '#title' => t('Close window after sending to printer'),
325
    '#default_value' => variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT),
326
    '#description' => t("When the above options are enabled, this option will close the window after its contents are printed."),
327
  );
328

    
329
  $form['settings']['print_display_sys_urllist'] = array(
330
    '#type' => 'checkbox',
331
    '#title' => t('Printer-friendly URLs list in system pages'),
332
    '#default_value' => variable_get('print_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
333
    '#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
334
  );
335

    
336
  $form['settings']['print_robots_settings'] = array(
337
      '#type' => 'fieldset',
338
      '#title' => t('Robots META tags'),
339
      '#collapsible' => TRUE,
340
      '#collapsed' => TRUE,
341
  );
342

    
343
  $form['settings']['print_robots_settings']['print_robots_noindex'] = array(
344
    '#type' => 'checkbox',
345
    '#title' => t('Add noindex'),
346
    '#default_value' => variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT),
347
    '#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.'),
348
  );
349

    
350
  $form['settings']['print_robots_settings']['print_robots_nofollow'] = array(
351
    '#type' => 'checkbox',
352
    '#title' => t('Add nofollow'),
353
    '#default_value' => variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT),
354
    '#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.'),
355
  );
356

    
357
  $form['settings']['print_robots_settings']['print_robots_noarchive'] = array(
358
    '#type' => 'checkbox',
359
    '#title' => t('Add noarchive'),
360
    '#default_value' => variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT),
361
    '#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.'),
362
  );
363

    
364
  return system_settings_form($form);
365
}
366

    
367
/**
368
 * Menu callback for the common print module text strings settings form
369
 *
370
 * @ingroup forms
371
 */
372
function print_main_strings_settings() {
373
  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');
374

    
375
  $form['print_main_text'] = array(
376
    '#type' => 'fieldset',
377
    '#title' => t('Text strings'),
378
  );
379

    
380
  $form['print_main_text']['print_text_published'] = array(
381
    '#type' => 'textfield',
382
    '#default_value' => variable_get('print_text_published', t('Published on %site_name')),
383
  );
384
  $form['print_main_text']['print_text_source_url'] = array(
385
    '#type' => 'textfield',
386
    '#default_value' => variable_get('print_text_source_url', t('Source URL')),
387
  );
388
  $form['print_main_text']['print_text_retrieved'] = array(
389
    '#type' => 'textfield',
390
    '#default_value' => variable_get('print_text_retrieved', t('retrieved on %date')),
391
  );
392
  $form['print_main_text']['print_text_links'] = array(
393
    '#type' => 'textfield',
394
    '#default_value' => variable_get('print_text_links', t('Links')),
395
  );
396
  $form['print_main_text']['reset'] = array(
397
    '#type' => 'submit',
398
    '#value' => t('Reset to defaults'),
399
    '#submit' => array('print_main_strings_settings_delete'),
400
  );
401

    
402
  return system_settings_form($form);
403
}
404

    
405
/**
406
 * Reset button callback for text strings settings form
407
 *
408
 * @ingroup forms
409
 */
410
function print_main_strings_settings_delete() {
411
  variable_del('print_text_published');
412
  variable_del('print_text_source_url');
413
  variable_del('print_text_retrieved');
414
  variable_del('print_text_links');
415
}
416

    
417
/**
418
 * Menu callback for the printer-friendly version text strings settings form
419
 *
420
 * @ingroup forms
421
 */
422
function print_html_strings_settings() {
423
  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');
424

    
425
  $form['print_html_text'] = array(
426
    '#type' => 'fieldset',
427
    '#title' => t('Text strings'),
428
  );
429

    
430
  $form['print_html_text']['print_html_link_text'] = array(
431
    '#type' => 'textfield',
432
    '#title' => t('Link text'),
433
    '#default_value' => variable_get('print_html_link_text', t('Printer-friendly version')),
434
    '#description' => t('Text used in the link to the printer-friendly version.'),
435
  );
436
  $form['print_html_text']['reset'] = array(
437
    '#type' => 'submit',
438
    '#value' => t('Reset to defaults'),
439
    '#submit' => array('print_html_strings_settings_delete'),
440
  );
441

    
442
  return system_settings_form($form);
443
}
444

    
445
/**
446
 * Reset button callback for text strings settings form
447
 *
448
 * @ingroup forms
449
 */
450
function print_html_strings_settings_delete() {
451
  variable_del('print_html_link_text');
452
}