Project

General

Profile

Paste
Download (12.1 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / print / print.admin.inc @ 76bdcd04

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
 * Form constructor 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 = DRUPAL_ROOT . '/' . strtr($print_css, array(
23
      '%t' => drupal_get_path('theme', variable_get('theme_default', 'garland')),
24
    ));
25
    if (!is_file($css_path) || !is_readable($css_path)) {
26
      drupal_set_message(t("File %file is not readable by the web server.", array('%file' => $css_path)), 'warning', FALSE);
27
    }
28
  }
29

    
30
  $form['settings'] = array(
31
    '#type' => 'fieldset',
32
    '#title' => t('Common settings'),
33
  );
34

    
35
  $form['settings']['print_css'] = array(
36
    '#type' => 'textfield',
37
    '#title' => t('Custom stylesheet'),
38
    '#default_value' => $print_css,
39
    '#size' => 60,
40
    '#maxlength' => 250,
41
    '#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 />' .
42
      t('Macros: %t (path to theme: "%theme")', array(
43
        '%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')),
44
      )) . '<br />' .
45
      t('Requires the <em>Administer site configuration</em> permission.'),
46
    '#disabled' => !user_access('administer site configuration'),
47
  );
48

    
49
  $form['settings']['print_keep_theme_css'] = array(
50
    '#type' => 'checkbox',
51
    '#title' => t('Keep the current theme CSS'),
52
    '#default_value' => variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT),
53
    '#description' => t('If set, the current theme css will still be applied to the printer-friendly versions.'),
54
  );
55

    
56
  $form['settings']['print_urls'] = array(
57
    '#type' => 'checkbox',
58
    '#title' => t('Printer-friendly URLs list'),
59
    '#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
60
    '#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.') . '<br />' .
61
      t('Note that you can enable/disable the URL list for each content type individually from the !url.', array(
62
        '!url' => l(t('Content Types page'), 'admin/structure/types'),
63
      )),
64
  );
65

    
66
  $form['settings']['print_urls_anchors'] = array(
67
    '#type' => 'checkbox',
68
    '#title' => t('Include named anchors in printer-friendly URLs list'),
69
    '#default_value' => variable_get('print_urls_anchors', PRINT_URLS_ANCHORS_DEFAULT),
70
    '#description' => t('If set, the list of the URLs at the bottom of the page will include anchors links on the same page.'),
71
  );
72

    
73
  $form['settings']['print_comments'] = array(
74
    '#type' => 'checkbox',
75
    '#title' => t('Include comments in printer-friendly version'),
76
    '#default_value' => variable_get('print_comments', PRINT_COMMENTS_DEFAULT),
77
    '#description' => t('When this option is active, user comments are also included in the printer-friendly version. Requires the comment module.'),
78
  );
79

    
80
  $form['settings']['print_node_router'] = array(
81
    '#type' => 'checkbox',
82
    '#title' => t('Consult menu router for node display handler'),
83
    '#default_value' => variable_get('print_node_router', PRINT_NODE_ROUTER_DEFAULT),
84
    '#description' => t('When this option is active, print module will check the menu router for the handler to consult for page contents at node/%node.'),
85
  );
86

    
87
  $form['settings']['print_newwindow'] = array(
88
    '#type' => 'radios',
89
    '#title' => t('New window method'),
90
    '#options' => array(t('Use HTML target (does not validate as XHTML Strict)'), t('Use Javascript (requires browser support)')),
91
    '#default_value' => variable_get('print_newwindow', PRINT_NEWWINDOW_DEFAULT),
92
    '#description' => t('Choose the method used to open pages in a new window/tab.'),
93
  );
94

    
95
  $form['settings']['logo'] = array(
96
    '#type' => 'fieldset',
97
    '#title' => t('Logo options'),
98
    '#collapsible' => TRUE,
99
    '#collapsed' => TRUE,
100
  );
101

    
102
  $form['settings']['logo']['print_logo_options'] = array(
103
    '#type' => 'radios',
104
    '#title' => t('Logo type'),
105
    '#options' => array(
106
      t('None (Disabled)'),
107
      t("Current theme's logo"),
108
      t('User-specified'),
109
    ),
110
    '#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
111
    '#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."),
112
  );
113

    
114
  $form['settings']['logo']['print_logo_url'] = array(
115
    '#type' => 'textfield',
116
    '#title' => t('Logo URL'),
117
    '#default_value' => variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT),
118
    '#size' => 60,
119
    '#maxlength' => 250,
120
  );
121

    
122
  $form['settings']['logo']['print_logo_upload'] = array(
123
    '#type' => 'file',
124
    '#title' => t('Upload logo'),
125
    '#size' => 60,
126
    '#maxlength' => 250,
127
    '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
128
  );
129

    
130
  $form['settings']['footer'] = array(
131
    '#type' => 'fieldset',
132
    '#title' => t('Footer options'),
133
    '#collapsible' => TRUE,
134
    '#collapsed' => TRUE,
135
  );
136

    
137
  $form['settings']['footer']['print_footer_options'] = array(
138
    '#type' => 'radios',
139
    '#title' => t('Footer type'),
140
    '#options' => array(
141
      t('None (Disabled)'),
142
      t("Site's footer"),
143
      t('User-specified'),
144
    ),
145
    '#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
146
    '#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
147
  );
148

    
149
  $form['settings']['footer']['print_footer_user'] = array(
150
    '#type' => 'textfield',
151
    '#title' => t('User-specified'),
152
    '#default_value' => variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT),
153
    '#size' => 60,
154
    '#maxlength' => 250,
155
  );
156

    
157
  $form['settings']['print_sourceurl_settings'] = array(
158
    '#type' => 'fieldset',
159
    '#title' => t('Source URL'),
160
    '#collapsible' => TRUE,
161
    '#collapsed' => TRUE,
162
  );
163

    
164
  $form['settings']['print_sourceurl_settings']['print_sourceurl_enabled'] = array(
165
    '#type' => 'checkbox',
166
    '#title' => t('Display source URL'),
167
    '#default_value' => variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT),
168
    '#description' => t('When this option is selected, the URL for the original page will be displayed at the bottom of the printer-friendly version.'),
169
  );
170

    
171
  $form['settings']['print_sourceurl_settings']['print_sourceurl_date'] = array(
172
    '#type' => 'checkbox',
173
    '#title' => t('Add current time/date to the source URL'),
174
    '#default_value' => variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT),
175
    '#description' => t('Display the current date and time in the Source URL line.'),
176
  );
177

    
178
  $form['settings']['print_sourceurl_settings']['print_sourceurl_forcenode'] = array(
179
    '#type' => 'checkbox',
180
    '#title' => t('Force use of node ID in source URL'),
181
    '#default_value' => variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT),
182
    '#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."),
183
  );
184

    
185
  $form['#attributes'] = array('enctype' => 'multipart/form-data');
186
  $form['#validate'][] = '_print_main_settings_validate';
187

    
188
  return system_settings_form($form);
189
}
190

    
191
/**
192
 * Form validation handler for print_main_settings().
193
 */
194
function _print_main_settings_validate($form, &$form_state) {
195
  global $base_root;
196

    
197
  // Check for a new uploaded logo, and use that instead.
198
  if ($file = file_save_upload('print_logo_upload', array('file_validate_is_image' => array()))) {
199
    // The image was saved using file_save_upload() and was added to the
200
    // files table as a temporary file. We'll make a copy and let the garbage
201
    // collector delete the original upload.
202
    if ($filename = file_unmanaged_copy($file->uri)) {
203
      /** @var DrupalStreamWrapperInterface $wrapper */
204
      $wrapper = file_stream_wrapper_get_instance_by_uri($filename);
205

    
206
      $form_state['values']['print_logo_options'] = 2;
207
      $form_state['values']['print_logo_url'] = str_replace($base_root, '', $wrapper->getExternalUrl());
208
    }
209
  }
210
}
211

    
212
/**
213
 * Form constructor for the Printer-friendly pages HTML settings form.
214
 *
215
 * @ingroup forms
216
 */
217
function print_html_settings() {
218
  $link = print_print_link();
219

    
220
  $form['settings'] = array(
221
    '#type' => 'fieldset',
222
    '#title' => t('Web page options'),
223
  );
224

    
225
  $form['settings']['print_html_new_window'] = array(
226
    '#type' => 'checkbox',
227
    '#title' => t('Open the printer-friendly version in a new window'),
228
    '#default_value' => variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT),
229
    '#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
230
  );
231

    
232
  $form['settings']['print_html_sendtoprinter'] = array(
233
    '#type' => 'checkbox',
234
    '#title' => t('Send to printer'),
235
    '#default_value' => variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT),
236
    '#description' => t("Automatically calls the browser's print function when the printer-friendly version is displayed."),
237
  );
238

    
239
  $form['settings']['print_html_windowclose'] = array(
240
    '#type' => 'checkbox',
241
    '#title' => t('Close window after sending to printer'),
242
    '#default_value' => variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT),
243
    '#description' => t("When the above options are enabled, this option will close the window after its contents are printed."),
244
  );
245

    
246
  $form['settings']['print_html_display_sys_urllist'] = array(
247
    '#type' => 'checkbox',
248
    '#title' => t('Printer-friendly URLs list in system pages'),
249
    '#default_value' => variable_get('print_html_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
250
    '#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
251
  );
252

    
253
  $form['settings']['print_robots_settings'] = array(
254
    '#type' => 'fieldset',
255
    '#title' => t('Robots META tags'),
256
    '#collapsible' => TRUE,
257
    '#collapsed' => FALSE,
258
  );
259

    
260
  $form['settings']['print_robots_settings']['print_robots_noindex'] = array(
261
    '#type' => 'checkbox',
262
    '#title' => t('Add noindex'),
263
    '#default_value' => variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT),
264
    '#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.'),
265
  );
266

    
267
  $form['settings']['print_robots_settings']['print_robots_nofollow'] = array(
268
    '#type' => 'checkbox',
269
    '#title' => t('Add nofollow'),
270
    '#default_value' => variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT),
271
    '#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.'),
272
  );
273

    
274
  $form['settings']['print_robots_settings']['print_robots_noarchive'] = array(
275
    '#type' => 'checkbox',
276
    '#title' => t('Add noarchive'),
277
    '#default_value' => variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT),
278
    '#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.'),
279
  );
280

    
281
  $form['settings']['link_text'] = array(
282
    '#type' => 'fieldset',
283
    '#title' => t('Custom link text'),
284
    '#collapsible' => TRUE,
285
    '#collapsed' => TRUE,
286
  );
287
  $form['settings']['link_text']['print_html_link_text_enabled'] = array(
288
    '#type' => 'checkbox',
289
    '#title' => t('Enable custom link text'),
290
    '#default_value' => variable_get('print_html_link_text_enabled', PRINT_TYPE_LINK_TEXT_ENABLED_DEFAULT),
291
  );
292
  $form['settings']['link_text']['print_html_link_text'] = array(
293
    '#type' => 'textfield',
294
    '#default_value' => variable_get('print_html_link_text', $link['text']),
295
    '#description' => t('Text used in the link to the printer-friendly version.'),
296
  );
297

    
298
  return system_settings_form($form);
299
}