Repair type-specific link settings
[project/print.git] / print.admin.inc
CommitLineData
ddb9ae21 1<?php
623692c4 2// $Id$
ddb9ae21 3
623692c4
JV
4/**
5 * @file
6 * Contains the administrative functions of the PF module.
7 *
8 * This file is included by the core PF module, and includes the
9 * settings form.
10 */
ddb9ae21
JV
11
12/**
623692c4
JV
13 * Menu callback for the Printer-friendly pages module settings form.
14 *
15 * @ingroup forms
ddb9ae21
JV
16 */
17function print_main_settings() {
9383096e
JV
18 $form['settings'] = array(
19 '#type' => 'fieldset',
20 '#title' => t('Common Settings'),
ddb9ae21
JV
21 );
22
9383096e
JV
23 $form['settings']['print_css'] = array(
24 '#type' => 'textfield',
25 '#title' => t('Stylesheet URL'),
26 '#default_value' => variable_get('print_css', PRINT_CSS_DEFAULT),
27 '#size' => 60,
28 '#maxlength' => 64,
29 '#description' => t('The URL to your custom print cascading stylesheet, if any. When none is specified, the default module CSS file is used.') .'<br />'.
30 t('Macros: %b (base path: "%base"), %t (path to theme: "%theme")', array('%base' => base_path(), '%theme' => path_to_theme())),
6ee36e8a
JV
31 );
32
9383096e
JV
33 $form['settings']['print_urls'] = array(
34 '#type' => 'checkbox',
35 '#title' => t('Printer-friendly URLs list'),
36 '#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
37 '#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.'),
6ee36e8a
JV
38 );
39
9383096e
JV
40 $form['settings']['print_comments'] = array(
41 '#type' => 'checkbox',
42 '#title' => t('Include comments in printer-friendly version'),
43 '#default_value' => variable_get('print_comments', PRINT_COMMENTS_DEFAULT),
44 '#description' => t('When this option is active, user comments are also included in the printer-friendly version. Requires the comment module.'),
9f9f3f56
JV
45 );
46
9383096e 47 $form['settings']['print_newwindow'] = array(
6ee36e8a 48 '#type' => 'radios',
9383096e
JV
49 '#title' => t('New window method'),
50 '#options' => array(t('Use HTML target (does not validate as XHTML Strict)'), t('Use Javascript (requires browser support)')),
51 '#default_value' => variable_get('print_newwindow', PRINT_NEWWINDOW_DEFAULT),
52 '#description' => t('Choose the method used to open pages in a new window/tab.'),
6ee36e8a
JV
53 );
54
9383096e
JV
55 $form['settings']['logo'] = array(
56 '#type' => 'fieldset',
57 '#title' => t('Logo options'),
58 '#collapsible' => TRUE,
59 '#collapsed' => TRUE,
ddb9ae21
JV
60 );
61
9383096e
JV
62 $form['settings']['logo']['print_logo_options'] = array(
63 '#type' => 'radios',
64 '#title' => t('Logo type'),
65 '#options' => array(t('None (Disabled)'), t("Current theme's logo"), t('User-specified')),
66 '#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
67 '#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."),
ddb9ae21
JV
68 );
69
9383096e 70 $form['settings']['logo']['print_logo_url'] = array(
ddb9ae21
JV
71 '#type' => 'textfield',
72 '#title' => t('Logo URL'),
9383096e 73 '#default_value' => variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT),
ddb9ae21
JV
74 '#size' => 60,
75 '#maxlength' => 250,
ddb9ae21
JV
76 );
77
9383096e
JV
78 $form['settings']['logo']['print_logo_upload'] = array(
79 '#type' => 'file',
80 '#title' => t('Upload logo'),
ddb9ae21 81 '#size' => 60,
9383096e
JV
82 '#maxlength' => 250,
83 '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
84 );
85
86 $form['settings']['print_sourceurl_settings'] = array(
87 '#type' => 'fieldset',
88 '#title' => t('Source URL'),
89 '#collapsible' => TRUE,
90 '#collapsed' => TRUE,
ddb9ae21
JV
91 );
92
9383096e 93 $form['settings']['print_sourceurl_settings']['print_sourceurl_enabled'] = array(
ddb9ae21 94 '#type' => 'checkbox',
9383096e
JV
95 '#title' => t('Display source URL'),
96 '#default_value' => variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT),
97 '#description' => t('When this option is selected, the URL for the original page will be displayed at the bottom of the printer-friendly version.'),
ddb9ae21
JV
98 );
99
9383096e 100 $form['settings']['print_sourceurl_settings']['print_sourceurl_date'] = array(
ddb9ae21 101 '#type' => 'checkbox',
9383096e
JV
102 '#title' => t('Add current time/date to the source URL'),
103 '#default_value' => variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT),
104 '#description' => t('Display the current date and time in the Source URL line.'),
ddb9ae21
JV
105 );
106
9383096e 107 $form['settings']['print_sourceurl_settings']['print_sourceurl_forcenode'] = array(
9f9f3f56 108 '#type' => 'checkbox',
9383096e
JV
109 '#title' => t('Force use of node ID in source URL'),
110 '#default_value' => variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT),
111 '#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."),
112 );
113
114 $form['#attributes'] = array('enctype' => 'multipart/form-data');
115 $form['#validate']['_print_main_settings_validate'] = array();
116
117 return system_settings_form($form);
118}
119
120/**
121 * Validate print_main_settings form.
122 */
123function _print_main_settings_validate($form_id, $form_values, $form) {
124 // Check for a new uploaded logo, and use that instead.
125 if ($file = file_check_upload('print_logo_upload')) {
126 if ($info = image_get_info($file->filepath)) {
127 $parts = pathinfo($file->filename);
128 $filename = 'print_logo.'. strtolower($parts['extension']);
129
130 if ($file = file_save_upload('print_logo_upload', $filename, 1)) {
131 form_set_value($form['settings']['logo']['print_logo_options'], 2);
132 form_set_value($form['settings']['logo']['print_logo_url'], base_path() . $file->filepath);
133 }
134 }
135 else {
136 form_set_error('print_logo_upload', t('Only JPEG, PNG and GIF images are allowed to be used as logos.'));
137 }
138 }
139}
140
9df2504f
JV
141/**
142 * Menu callback for the Printer-friendly pages HTML settings form.
143 *
144 * @ingroup forms
145 */
9383096e
JV
146function print_html_settings() {
147 $form['settings'] = array(
148 '#type' => 'fieldset',
149 '#title' => t('Web page options'),
150 );
151
152 $form['settings']['print_html_link_pos'] = array(
153 '#type' => 'checkboxes',
154 '#title' => t('Printer-friendly page link'),
155 '#default_value' => variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT => PRINT_HTML_LINK_POS_DEFAULT)),
156 '#options' => array('link' => t('Links area'), 'corner' => t('Content corner')),
157 '#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)),
9f9f3f56
JV
158 );
159
9383096e
JV
160 $form['settings']['adv_link'] = array(
161 '#type' => 'fieldset',
162 '#title' => t('Advanced link options'),
163 '#collapsible' => TRUE,
164 '#collapsed' => TRUE,
165 );
166
167 $form['settings']['adv_link']['print_html_show_link'] = array(
ddb9ae21 168 '#type' => 'radios',
9383096e
JV
169 '#title' => t('Link style'),
170 '#default_value' => variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT),
171 '#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
172 '#description' => t('Select the visual style of the link.'),
ddb9ae21
JV
173 );
174
9383096e
JV
175 $form['settings']['adv_link']['print_html_node_link_visibility'] = array(
176 '#type' => 'radios',
177 '#title' => t('Link visibility'),
178 '#default_value' => variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT),
179 '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
ddb9ae21
JV
180 );
181
9383096e
JV
182 $form['settings']['adv_link']['print_html_node_link_pages'] = array(
183 '#type' => 'textarea',
184 '#default_value' => variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT),
185 '#rows' => 3,
186 '#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>')),
187 );
ddb9ae21 188
9383096e
JV
189 $form['settings']['adv_link']['print_html_link_class'] = array(
190 '#type' => 'textfield',
191 '#title' => t('Link class'),
192 '#default_value' => variable_get('print_html_link_class', PRINT_HTML_LINK_CLASS_DEFAULT),
193 '#size' => 60,
194 '#maxlength' => 250,
195 '#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.'),
ddb9ae21
JV
196 );
197
9383096e
JV
198 $form['settings']['adv_link']['print_html_sys_link_visibility'] = array(
199 '#type' => 'radios',
200 '#title' => t('Show link in system (non-content) pages'),
201 '#default_value' => variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT),
202 '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
203 );
204
205 $form['settings']['adv_link']['print_html_sys_link_pages'] = array(
206 '#type' => 'textarea',
207 '#default_value' => variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT),
208 '#rows' => 3,
209 '#description' => t('Setting this option will add a printer-friendly version page link on pages created by Drupal or the enabled modules.') .'<br />'.
210 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>')),
ddb9ae21
JV
211 );
212
9383096e 213 $form['settings']['print_html_book_link'] = array(
ddb9ae21 214 '#type' => 'checkbox',
9383096e
JV
215 '#title' => t('Take control of the book module printer-friendly link'),
216 '#default_value' => variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT),
217 '#description' => t('Activate this to have the printer-friendly link in book nodes handled by this module. Requires the (core) book module.'),
ddb9ae21
JV
218 );
219
9383096e 220 $form['settings']['print_html_new_window'] = array(
ddb9ae21 221 '#type' => 'checkbox',
9383096e
JV
222 '#title' => t('Open the printer-friendly version in a new window'),
223 '#default_value' => variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT),
224 '#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
ddb9ae21
JV
225 );
226
9383096e
JV
227 $form['settings']['print_html_sendtoprinter'] = array(
228 '#type' => 'checkbox',
229 '#title' => t('Send to printer'),
230 '#default_value' => variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT),
231 '#description' => t("Automatically calls the browser's print function when the printer-friendly version is displayed."),
232 );
ddb9ae21 233
9383096e 234 $form['settings']['print_robots_settings'] = array(
ddb9ae21
JV
235 '#type' => 'fieldset',
236 '#title' => t('Robots META tags'),
237 '#collapsible' => TRUE,
238 '#collapsed' => TRUE,
ddb9ae21
JV
239 );
240
9383096e 241 $form['settings']['print_robots_settings']['print_robots_noindex'] = array(
ddb9ae21
JV
242 '#type' => 'checkbox',
243 '#title' => t('Add noindex'),
9383096e 244 '#default_value' => variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT),
ddb9ae21
JV
245 '#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.'),
246 );
247
9383096e 248 $form['settings']['print_robots_settings']['print_robots_nofollow'] = array(
ddb9ae21
JV
249 '#type' => 'checkbox',
250 '#title' => t('Add nofollow'),
9383096e 251 '#default_value' => variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT),
ddb9ae21
JV
252 '#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.'),
253 );
254
9383096e 255 $form['settings']['print_robots_settings']['print_robots_noarchive'] = array(
ddb9ae21
JV
256 '#type' => 'checkbox',
257 '#title' => t('Add noarchive'),
9383096e 258 '#default_value' => variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT),
ddb9ae21
JV
259 '#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.'),
260 );
261
ddb9ae21
JV
262 return system_settings_form($form);
263}