print.admin.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. * Form constructor 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 = DRUPAL_ROOT . '/' . strtr($print_css, array(
  21. '%t' => drupal_get_path('theme', variable_get('theme_default', 'garland')),
  22. ));
  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. $form['settings'] = array(
  28. '#type' => 'fieldset',
  29. '#title' => t('Common settings'),
  30. );
  31. $form['settings']['print_css'] = array(
  32. '#type' => 'textfield',
  33. '#title' => t('Custom stylesheet'),
  34. '#default_value' => $print_css,
  35. '#size' => 60,
  36. '#maxlength' => 250,
  37. '#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 />' .
  38. t('Macros: %t (path to theme: "%theme")', array(
  39. '%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')),
  40. )) . '<br />' .
  41. t('Requires the <em>Administer site configuration</em> permission.'),
  42. '#disabled' => !user_access('administer site configuration'),
  43. );
  44. $form['settings']['print_keep_theme_css'] = array(
  45. '#type' => 'checkbox',
  46. '#title' => t('Keep the current theme CSS'),
  47. '#default_value' => variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT),
  48. '#description' => t('If set, the current theme css will still be applied to the printer-friendly versions.'),
  49. );
  50. $form['settings']['print_urls'] = array(
  51. '#type' => 'checkbox',
  52. '#title' => t('Printer-friendly URLs list'),
  53. '#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
  54. '#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.') . '<br />' .
  55. t('Note that you can enable/disable the URL list for each content type individually from the !url.', array(
  56. '!url' => l(t('Content Types page'), 'admin/structure/types'),
  57. )),
  58. );
  59. $form['settings']['print_urls_anchors'] = array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Include named anchors in printer-friendly URLs list'),
  62. '#default_value' => variable_get('print_urls_anchors', PRINT_URLS_ANCHORS_DEFAULT),
  63. '#description' => t('If set, the list of the URLs at the bottom of the page will include anchors links on the same page.'),
  64. );
  65. $form['settings']['print_comments'] = array(
  66. '#type' => 'checkbox',
  67. '#title' => t('Include comments in printer-friendly version'),
  68. '#default_value' => variable_get('print_comments', PRINT_COMMENTS_DEFAULT),
  69. '#description' => t('When this option is active, user comments are also included in the printer-friendly version. Requires the comment module.'),
  70. );
  71. $form['settings']['print_node_router'] = array(
  72. '#type' => 'checkbox',
  73. '#title' => t('Consult menu router for node display handler'),
  74. '#default_value' => variable_get('print_node_router', PRINT_NODE_ROUTER_DEFAULT),
  75. '#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.'),
  76. );
  77. $form['settings']['print_newwindow'] = array(
  78. '#type' => 'radios',
  79. '#title' => t('New window method'),
  80. '#options' => array(t('Use HTML target (does not validate as XHTML Strict)'), t('Use Javascript (requires browser support)')),
  81. '#default_value' => variable_get('print_newwindow', PRINT_NEWWINDOW_DEFAULT),
  82. '#description' => t('Choose the method used to open pages in a new window/tab.'),
  83. );
  84. $form['settings']['logo'] = array(
  85. '#type' => 'fieldset',
  86. '#title' => t('Logo options'),
  87. '#collapsible' => TRUE,
  88. '#collapsed' => TRUE,
  89. );
  90. $form['settings']['logo']['print_logo_options'] = array(
  91. '#type' => 'radios',
  92. '#title' => t('Logo type'),
  93. '#options' => array(
  94. t('None (Disabled)'),
  95. t("Current theme's logo"),
  96. t('User-specified'),
  97. ),
  98. '#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
  99. '#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."),
  100. );
  101. $form['settings']['logo']['print_logo_url'] = array(
  102. '#type' => 'textfield',
  103. '#title' => t('Logo URL'),
  104. '#default_value' => variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT),
  105. '#size' => 60,
  106. '#maxlength' => 250,
  107. );
  108. $form['settings']['logo']['print_logo_upload'] = array(
  109. '#type' => 'file',
  110. '#title' => t('Upload logo'),
  111. '#size' => 60,
  112. '#maxlength' => 250,
  113. '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
  114. );
  115. $form['settings']['footer'] = array(
  116. '#type' => 'fieldset',
  117. '#title' => t('Footer options'),
  118. '#collapsible' => TRUE,
  119. '#collapsed' => TRUE,
  120. );
  121. $form['settings']['footer']['print_footer_options'] = array(
  122. '#type' => 'radios',
  123. '#title' => t('Footer type'),
  124. '#options' => array(
  125. t('None (Disabled)'),
  126. t("Site's footer"),
  127. t('User-specified'),
  128. ),
  129. '#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
  130. '#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
  131. );
  132. $form['settings']['footer']['print_footer_user'] = array(
  133. '#type' => 'textfield',
  134. '#title' => t('User-specified'),
  135. '#default_value' => variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT),
  136. '#size' => 60,
  137. '#maxlength' => 250,
  138. );
  139. $form['settings']['print_sourceurl_settings'] = array(
  140. '#type' => 'fieldset',
  141. '#title' => t('Source URL'),
  142. '#collapsible' => TRUE,
  143. '#collapsed' => TRUE,
  144. );
  145. $form['settings']['print_sourceurl_settings']['print_sourceurl_enabled'] = array(
  146. '#type' => 'checkbox',
  147. '#title' => t('Display source URL'),
  148. '#default_value' => variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT),
  149. '#description' => t('When this option is selected, the URL for the original page will be displayed at the bottom of the printer-friendly version.'),
  150. );
  151. $form['settings']['print_sourceurl_settings']['print_sourceurl_date'] = array(
  152. '#type' => 'checkbox',
  153. '#title' => t('Add current time/date to the source URL'),
  154. '#default_value' => variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT),
  155. '#description' => t('Display the current date and time in the Source URL line.'),
  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. $form['#attributes'] = array('enctype' => 'multipart/form-data');
  164. $form['#validate'][] = '_print_main_settings_validate';
  165. return system_settings_form($form);
  166. }
  167. /**
  168. * Form validation handler for print_main_settings().
  169. */
  170. function _print_main_settings_validate($form, &$form_state) {
  171. global $base_root;
  172. // Check for a new uploaded logo, and use that instead.
  173. if ($file = file_save_upload('print_logo_upload', array('file_validate_is_image' => array()))) {
  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 ($filename = file_unmanaged_copy($file->uri)) {
  178. /** @var DrupalStreamWrapperInterface $wrapper */
  179. $wrapper = file_stream_wrapper_get_instance_by_uri($filename);
  180. $form_state['values']['print_logo_options'] = 2;
  181. $form_state['values']['print_logo_url'] = str_replace($base_root, '', $wrapper->getExternalUrl());
  182. }
  183. }
  184. }
  185. /**
  186. * Form constructor for the Printer-friendly pages HTML settings form.
  187. *
  188. * @ingroup forms
  189. */
  190. function print_html_settings() {
  191. $link = print_print_link();
  192. $form['settings'] = array(
  193. '#type' => 'fieldset',
  194. '#title' => t('Web page options'),
  195. );
  196. $form['settings']['print_html_new_window'] = array(
  197. '#type' => 'checkbox',
  198. '#title' => t('Open the printer-friendly version in a new window'),
  199. '#default_value' => variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT),
  200. '#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
  201. );
  202. $form['settings']['print_html_sendtoprinter'] = array(
  203. '#type' => 'checkbox',
  204. '#title' => t('Send to printer'),
  205. '#default_value' => variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT),
  206. '#description' => t("Automatically calls the browser's print function when the printer-friendly version is displayed."),
  207. );
  208. $form['settings']['print_html_windowclose'] = array(
  209. '#type' => 'checkbox',
  210. '#title' => t('Close window after sending to printer'),
  211. '#default_value' => variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT),
  212. '#description' => t("When the above options are enabled, this option will close the window after its contents are printed."),
  213. );
  214. $form['settings']['print_html_display_sys_urllist'] = array(
  215. '#type' => 'checkbox',
  216. '#title' => t('Printer-friendly URLs list in system pages'),
  217. '#default_value' => variable_get('print_html_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
  218. '#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
  219. );
  220. $form['settings']['print_robots_settings'] = array(
  221. '#type' => 'fieldset',
  222. '#title' => t('Robots META tags'),
  223. '#collapsible' => TRUE,
  224. '#collapsed' => FALSE,
  225. );
  226. $form['settings']['print_robots_settings']['print_robots_noindex'] = array(
  227. '#type' => 'checkbox',
  228. '#title' => t('Add noindex'),
  229. '#default_value' => variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT),
  230. '#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.'),
  231. );
  232. $form['settings']['print_robots_settings']['print_robots_nofollow'] = array(
  233. '#type' => 'checkbox',
  234. '#title' => t('Add nofollow'),
  235. '#default_value' => variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT),
  236. '#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.'),
  237. );
  238. $form['settings']['print_robots_settings']['print_robots_noarchive'] = array(
  239. '#type' => 'checkbox',
  240. '#title' => t('Add noarchive'),
  241. '#default_value' => variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT),
  242. '#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.'),
  243. );
  244. $form['settings']['link_text'] = array(
  245. '#type' => 'fieldset',
  246. '#title' => t('Custom link text'),
  247. '#collapsible' => TRUE,
  248. '#collapsed' => TRUE,
  249. );
  250. $form['settings']['link_text']['print_html_link_text_enabled'] = array(
  251. '#type' => 'checkbox',
  252. '#title' => t('Enable custom link text'),
  253. '#default_value' => variable_get('print_html_link_text_enabled', PRINT_TYPE_LINK_TEXT_ENABLED_DEFAULT),
  254. );
  255. $form['settings']['link_text']['print_html_link_text'] = array(
  256. '#type' => 'textfield',
  257. '#default_value' => variable_get('print_html_link_text', $link['text']),
  258. '#description' => t('Text used in the link to the printer-friendly version.'),
  259. );
  260. return system_settings_form($form);
  261. }