print.admin.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <?php
  2. /**
  3. * @file
  4. * Contains the administrative functions of the PF module.
  5. *
  6. * This file is included by the core PF module, and includes the
  7. * settings form.
  8. *
  9. * @ingroup print
  10. */
  11. /**
  12. * Menu callback for the Printer-friendly pages module settings form.
  13. *
  14. * @ingroup forms
  15. */
  16. function print_main_settings() {
  17. $print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
  18. // Check that the stylesheet path is indeed valid and relative to base_path()
  19. if (!empty($print_css) && empty($_POST)) {
  20. $css_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default', 'garland'))));
  21. if (!is_file($css_path) || !is_readable($css_path)) {
  22. drupal_set_message(t("File %file is not readable by the web server.", array('%file' => $css_path)), 'warning', FALSE);
  23. }
  24. }
  25. $form['settings'] = array(
  26. '#type' => 'fieldset',
  27. '#title' => t('Common settings'),
  28. );
  29. $form['settings']['print_css'] = array(
  30. '#type' => 'textfield',
  31. '#title' => t('Custom stylesheet'),
  32. '#default_value' => $print_css,
  33. '#size' => 60,
  34. '#maxlength' => 250,
  35. '#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 />' .
  36. t('Macros: %t (path to theme: "%theme")', array('%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')))) . '<br />' .
  37. t('Requires the <em>Administer site configuration</em> permission.'),
  38. '#disabled' => !user_access('administer site configuration'),
  39. );
  40. $form['settings']['print_keep_theme_css'] = array(
  41. '#type' => 'checkbox',
  42. '#title' => t('Keep the current theme CSS'),
  43. '#default_value' => variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT),
  44. '#description' => t('If set, the current theme css will still be applied to the printer-friendly versions.'),
  45. );
  46. $form['settings']['print_urls'] = array(
  47. '#type' => 'checkbox',
  48. '#title' => t('Printer-friendly URLs list'),
  49. '#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
  50. '#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.') . '<br />' .
  51. 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'))),
  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. $form['settings']['print_comments'] = array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Include comments in printer-friendly version'),
  62. '#default_value' => variable_get('print_comments', PRINT_COMMENTS_DEFAULT),
  63. '#description' => t('When this option is active, user comments are also included in the printer-friendly version. Requires the comment module.'),
  64. );
  65. $form['settings']['print_newwindow'] = array(
  66. '#type' => 'radios',
  67. '#title' => t('New window method'),
  68. '#options' => array(t('Use HTML target (does not validate as XHTML Strict)'), t('Use Javascript (requires browser support)')),
  69. '#default_value' => variable_get('print_newwindow', PRINT_NEWWINDOW_DEFAULT),
  70. '#description' => t('Choose the method used to open pages in a new window/tab.'),
  71. );
  72. $form['settings']['logo'] = array(
  73. '#type' => 'fieldset',
  74. '#title' => t('Logo options'),
  75. '#collapsible' => TRUE,
  76. '#collapsed' => TRUE,
  77. );
  78. $form['settings']['logo']['print_logo_options'] = array(
  79. '#type' => 'radios',
  80. '#title' => t('Logo type'),
  81. '#options' => array(t('None (Disabled)'), t("Current theme's logo"), t('User-specified')),
  82. '#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
  83. '#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."),
  84. );
  85. $form['settings']['logo']['print_logo_url'] = array(
  86. '#type' => 'textfield',
  87. '#title' => t('Logo URL'),
  88. '#default_value' => variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT),
  89. '#size' => 60,
  90. '#maxlength' => 250,
  91. );
  92. $form['settings']['logo']['print_logo_upload'] = array(
  93. '#type' => 'file',
  94. '#title' => t('Upload logo'),
  95. '#size' => 60,
  96. '#maxlength' => 250,
  97. '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
  98. );
  99. $form['settings']['footer'] = array(
  100. '#type' => 'fieldset',
  101. '#title' => t('Footer options'),
  102. '#collapsible' => TRUE,
  103. '#collapsed' => TRUE,
  104. );
  105. $form['settings']['footer']['print_footer_options'] = array(
  106. '#type' => 'radios',
  107. '#title' => t('Footer type'),
  108. '#options' => array(t('None (Disabled)'), t("Site's footer"), t('User-specified')),
  109. '#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
  110. '#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
  111. );
  112. $form['settings']['footer']['print_footer_user'] = array(
  113. '#type' => 'textfield',
  114. '#title' => t('User-specified'),
  115. '#default_value' => variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT),
  116. '#size' => 60,
  117. '#maxlength' => 250,
  118. );
  119. $form['settings']['print_sourceurl_settings'] = array(
  120. '#type' => 'fieldset',
  121. '#title' => t('Source URL'),
  122. '#collapsible' => TRUE,
  123. '#collapsed' => TRUE,
  124. );
  125. $form['settings']['print_sourceurl_settings']['print_sourceurl_enabled'] = array(
  126. '#type' => 'checkbox',
  127. '#title' => t('Display source URL'),
  128. '#default_value' => variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT),
  129. '#description' => t('When this option is selected, the URL for the original page will be displayed at the bottom of the printer-friendly version.'),
  130. );
  131. $form['settings']['print_sourceurl_settings']['print_sourceurl_date'] = array(
  132. '#type' => 'checkbox',
  133. '#title' => t('Add current time/date to the source URL'),
  134. '#default_value' => variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT),
  135. '#description' => t('Display the current date and time in the Source URL line.'),
  136. );
  137. $form['settings']['print_sourceurl_settings']['print_sourceurl_forcenode'] = array(
  138. '#type' => 'checkbox',
  139. '#title' => t('Force use of node ID in source URL'),
  140. '#default_value' => variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT),
  141. '#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."),
  142. );
  143. $form['#attributes'] = array('enctype' => 'multipart/form-data');
  144. $form['#validate'][] = '_print_main_settings_validate';
  145. return system_settings_form($form);
  146. }
  147. /**
  148. * Validate print_main_settings form.
  149. */
  150. function _print_main_settings_validate($form, &$form_state) {
  151. global $base_root;
  152. // Check for a new uploaded logo, and use that instead.
  153. if ($file = file_save_upload('print_logo_upload', array('file_validate_is_image' => array()))) {
  154. // The image was saved using file_save_upload() and was added to the
  155. // files table as a temporary file. We'll make a copy and let the garbage
  156. // collector delete the original upload.
  157. if ($filename = file_unmanaged_copy($file->uri)) {
  158. $wrapper = file_stream_wrapper_get_instance_by_uri($filename);
  159. $form_state['values']['print_logo_options'] = 2;
  160. $form_state['values']['print_logo_url'] = str_replace($base_root, '', $wrapper->getExternalUrl());
  161. }
  162. }
  163. }
  164. /**
  165. * Menu callback for the Printer-friendly pages HTML settings form.
  166. *
  167. * @ingroup forms
  168. */
  169. function print_html_settings() {
  170. $form['settings'] = array(
  171. '#type' => 'fieldset',
  172. '#title' => t('Web page options'),
  173. );
  174. $form['settings']['print_html_link_pos'] = array(
  175. '#type' => 'checkboxes',
  176. '#title' => t('Printer-friendly page link'),
  177. '#default_value' => variable_get('print_html_link_pos', drupal_json_decode(PRINT_HTML_LINK_POS_DEFAULT)),
  178. '#options' => array('link' => t('Links area'), 'corner' => t('Content corner'), 'block' => t('Block'), 'help' => t('Help area')),
  179. '#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)),
  180. );
  181. $form['settings']['print_html_link_teaser'] = array(
  182. '#type' => 'checkbox',
  183. '#title' => t('Display printer-friendly link in teaser'),
  184. '#default_value' => variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT),
  185. '#description' => t('Enabling this will display the link in teaser mode.'),
  186. );
  187. $form['settings']['adv_link'] = array(
  188. '#type' => 'fieldset',
  189. '#title' => t('Advanced link options'),
  190. '#collapsible' => TRUE,
  191. '#collapsed' => FALSE,
  192. );
  193. $form['settings']['adv_link']['print_html_show_link'] = array(
  194. '#type' => 'radios',
  195. '#title' => t('Link style'),
  196. '#default_value' => variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT),
  197. '#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
  198. '#description' => t('Select the visual style of the link.'),
  199. );
  200. $form['settings']['adv_link']['print_html_link_use_alias'] = array(
  201. '#type' => 'checkbox',
  202. '#title' => t('Use URL alias instead of node ID'),
  203. '#default_value' => variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT),
  204. '#description' => t('Enabling this will create the link using the URL alias instead of the node ID.'),
  205. );
  206. $form['settings']['adv_link']['print_html_link_class'] = array(
  207. '#type' => 'textfield',
  208. '#title' => t('Link class'),
  209. '#default_value' => variable_get('print_html_link_class', PRINT_HTML_LINK_CLASS_DEFAULT),
  210. '#size' => 60,
  211. '#maxlength' => 250,
  212. '#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.'),
  213. );
  214. $form['settings']['adv_link']['print_html_node_link_visibility'] = array(
  215. '#type' => 'radios',
  216. '#title' => t('Link visibility'),
  217. '#default_value' => variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT),
  218. '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
  219. );
  220. $form['settings']['adv_link']['print_html_node_link_pages'] = array(
  221. '#type' => 'textarea',
  222. '#default_value' => variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT),
  223. '#rows' => 3,
  224. '#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>')),
  225. );
  226. if (module_exists('php')) {
  227. $access = user_access('use PHP for settings');
  228. if ($form['settings']['adv_link']['print_html_node_link_visibility']['#default_value'] == 2 && !$access) {
  229. $form['settings']['adv_link']['print_html_node_link_visibility'] = array('#type' => 'value', '#value' => 2);
  230. $form['settings']['adv_link']['print_html_node_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_html_node_link_pages']['#default_value']);
  231. }
  232. elseif ($access) {
  233. $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).');
  234. $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 ?>'));
  235. }
  236. }
  237. $form['settings']['adv_link']['print_html_sys_link_visibility'] = array(
  238. '#type' => 'radios',
  239. '#title' => t('Show link in system (non-content) pages'),
  240. '#description' => 'Any page that is not a Drupal node. Usually pages generated by Drupal or a module such as Views or Panels.',
  241. '#default_value' => variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT),
  242. '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
  243. );
  244. $form['settings']['adv_link']['print_html_sys_link_pages'] = array(
  245. '#type' => 'textarea',
  246. '#default_value' => variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT),
  247. '#rows' => 3,
  248. '#description' => t('Setting this option will add a printer-friendly version page link on pages created by Drupal or the enabled modules.') . '<br />' .
  249. 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>')),
  250. );
  251. if (module_exists('php')) {
  252. if ($form['settings']['adv_link']['print_html_sys_link_visibility']['#default_value'] == 2 && !$access) {
  253. $form['settings']['adv_link']['print_html_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
  254. $form['settings']['adv_link']['print_html_sys_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_html_sys_link_pages']['#default_value']);
  255. }
  256. elseif ($access) {
  257. $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).');
  258. $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 ?>'));
  259. }
  260. }
  261. $form['settings']['adv_link']['print_html_book_link'] = array(
  262. '#type' => 'radios',
  263. '#title' => t('Link in book hierarchy nodes'),
  264. '#default_value' => variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT),
  265. '#options' => array(t('Book module link not modified'), t('Current page and sub-pages'), t('Current page only')),
  266. );
  267. $form['settings']['print_html_new_window'] = array(
  268. '#type' => 'checkbox',
  269. '#title' => t('Open the printer-friendly version in a new window'),
  270. '#default_value' => variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT),
  271. '#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
  272. );
  273. $form['settings']['print_html_sendtoprinter'] = array(
  274. '#type' => 'checkbox',
  275. '#title' => t('Send to printer'),
  276. '#default_value' => variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT),
  277. '#description' => t("Automatically calls the browser's print function when the printer-friendly version is displayed."),
  278. );
  279. $form['settings']['print_html_windowclose'] = array(
  280. '#type' => 'checkbox',
  281. '#title' => t('Close window after sending to printer'),
  282. '#default_value' => variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT),
  283. '#description' => t("When the above options are enabled, this option will close the window after its contents are printed."),
  284. );
  285. $form['settings']['print_display_sys_urllist'] = array(
  286. '#type' => 'checkbox',
  287. '#title' => t('Printer-friendly URLs list in system pages'),
  288. '#default_value' => variable_get('print_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
  289. '#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
  290. );
  291. $form['settings']['print_robots_settings'] = array(
  292. '#type' => 'fieldset',
  293. '#title' => t('Robots META tags'),
  294. '#collapsible' => TRUE,
  295. '#collapsed' => TRUE,
  296. );
  297. $form['settings']['print_robots_settings']['print_robots_noindex'] = array(
  298. '#type' => 'checkbox',
  299. '#title' => t('Add noindex'),
  300. '#default_value' => variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT),
  301. '#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.'),
  302. );
  303. $form['settings']['print_robots_settings']['print_robots_nofollow'] = array(
  304. '#type' => 'checkbox',
  305. '#title' => t('Add nofollow'),
  306. '#default_value' => variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT),
  307. '#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.'),
  308. );
  309. $form['settings']['print_robots_settings']['print_robots_noarchive'] = array(
  310. '#type' => 'checkbox',
  311. '#title' => t('Add noarchive'),
  312. '#default_value' => variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT),
  313. '#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.'),
  314. );
  315. return system_settings_form($form);
  316. }
  317. /**
  318. * Menu callback for the common print module text strings settings form
  319. *
  320. * @ingroup forms
  321. */
  322. function print_main_strings_settings() {
  323. 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');
  324. $form['print_main_text'] = array(
  325. '#type' => 'fieldset',
  326. '#title' => t('Text strings'),
  327. );
  328. $form['print_main_text']['print_text_published'] = array(
  329. '#type' => 'textfield',
  330. '#default_value' => variable_get('print_text_published', t('Published on %site_name')),
  331. );
  332. $form['print_main_text']['print_text_source_url'] = array(
  333. '#type' => 'textfield',
  334. '#default_value' => variable_get('print_text_source_url', t('Source URL')),
  335. );
  336. $form['print_main_text']['print_text_retrieved'] = array(
  337. '#type' => 'textfield',
  338. '#default_value' => variable_get('print_text_retrieved', t('retrieved on %date')),
  339. );
  340. $form['print_main_text']['print_text_links'] = array(
  341. '#type' => 'textfield',
  342. '#default_value' => variable_get('print_text_links', t('Links')),
  343. );
  344. $form['print_main_text']['reset'] = array(
  345. '#type' => 'submit',
  346. '#value' => t('Reset to defaults'),
  347. '#submit' => array('print_main_strings_settings_delete'),
  348. );
  349. return system_settings_form($form);
  350. }
  351. /**
  352. * Reset button callback for text strings settings form
  353. *
  354. * @ingroup forms
  355. */
  356. function print_main_strings_settings_delete() {
  357. variable_del('print_text_published');
  358. variable_del('print_text_source_url');
  359. variable_del('print_text_retrieved');
  360. variable_del('print_text_links');
  361. }
  362. /**
  363. * Menu callback for the printer-friendly version text strings settings form
  364. *
  365. * @ingroup forms
  366. */
  367. function print_html_strings_settings() {
  368. 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');
  369. $form['print_html_text'] = array(
  370. '#type' => 'fieldset',
  371. '#title' => t('Text strings'),
  372. );
  373. $form['print_html_text']['print_html_link_text'] = array(
  374. '#type' => 'textfield',
  375. '#title' => t('Link text'),
  376. '#default_value' => variable_get('print_html_link_text', t('Printer-friendly version')),
  377. '#description' => t('Text used in the link to the printer-friendly version.'),
  378. );
  379. $form['print_html_text']['reset'] = array(
  380. '#type' => 'submit',
  381. '#value' => t('Reset to defaults'),
  382. '#submit' => array('print_html_strings_settings_delete'),
  383. );
  384. return system_settings_form($form);
  385. }
  386. /**
  387. * Reset button callback for text strings settings form
  388. *
  389. * @ingroup forms
  390. */
  391. function print_html_strings_settings_delete() {
  392. variable_del('print_html_link_text');
  393. }