print_pdf.admin.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * @file
  4. * Contains the administrative functions of the PDF version module.
  5. *
  6. * This file is included by the PDF version module, and includes the
  7. * settings form.
  8. *
  9. * @ingroup print
  10. */
  11. /**
  12. * Form constructor for the PDF version module settings form.
  13. *
  14. * @ingroup forms
  15. */
  16. function print_pdf_settings() {
  17. $pdf_tools = array();
  18. drupal_alter('print_pdf_available_libs', $pdf_tools);
  19. if (!empty($pdf_tools)) {
  20. $link = print_pdf_print_link();
  21. $current_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
  22. $pdf_tool_default = array_key_exists((string) $current_pdf_tool, $pdf_tools) ? $current_pdf_tool : PRINT_PDF_PDF_TOOL_DEFAULT;
  23. $form['settings'] = array(
  24. '#type' => 'fieldset',
  25. '#title' => t('PDF options'),
  26. );
  27. $form['settings']['print_pdf_pdf_tool'] = array(
  28. '#type' => 'radios',
  29. '#title' => t('PDF generation tool'),
  30. '#options' => $pdf_tools,
  31. '#default_value' => $pdf_tool_default,
  32. '#description' => t('This option selects the PDF generation tool being used by this module to create the PDF version.'),
  33. );
  34. $form['settings']['print_pdf_content_disposition'] = array(
  35. '#type' => 'radios',
  36. '#title' => t('Open PDF in'),
  37. '#options' => array(
  38. t('Same browser window'),
  39. t('New browser window'),
  40. t('Save dialog'),
  41. ),
  42. '#default_value' => variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT),
  43. '#description' => t("Select the desired method for opening the PDF in the user's browser."),
  44. );
  45. $form['settings']['print_pdf_paper_size'] = array(
  46. '#type' => 'select',
  47. '#title' => t('Paper size'),
  48. '#options' => _print_pdf_paper_sizes(),
  49. '#default_value' => variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT),
  50. '#description' => t('Choose the paper size of the generated PDF.'),
  51. );
  52. $form['settings']['print_pdf_page_orientation'] = array(
  53. '#type' => 'select',
  54. '#title' => t('Page orientation'),
  55. '#options' => array('portrait' => t('Portrait'), 'landscape' => t('Landscape')),
  56. '#default_value' => variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT),
  57. '#description' => t('Choose the page orientation of the generated PDF.'),
  58. );
  59. $form['settings']['print_pdf_cache_enabled'] = array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Enable caching of generated PDFs'),
  62. '#default_value' => variable_get('print_pdf_cache_enabled', PRINT_PDF_CACHE_ENABLED_DEFAULT),
  63. );
  64. $form['settings']['print_pdf_cache_lifetime'] = array(
  65. '#type' => 'select',
  66. '#title' => t('Cache Lifetime'),
  67. '#options' => array(
  68. '0' => 'None',
  69. '10800' => '3 hours',
  70. '21600' => '6 hours',
  71. '43200' => '12 hours',
  72. '64800' => '18 hours',
  73. '86400' => '24 hours',
  74. '129600' => '36 hours',
  75. '172800' => '2 days',
  76. '259200' => '3 days',
  77. '345600' => '4 days',
  78. '432000' => '5 days',
  79. '518400' => '6 days',
  80. '604800' => '7 days',
  81. ),
  82. '#default_value' => variable_get('print_pdf_cache_lifetime', PRINT_PDF_CACHE_LIFETIME_DEFAULT),
  83. '#description' => t('The lifetime of cached PDFs. A cached PDF is only removed when a node is updated, deleted, or cron is run and the last access is older than this value.'),
  84. );
  85. $form['settings']['print_pdf_images_via_file'] = array(
  86. '#type' => 'checkbox',
  87. '#title' => t('Access images via local file access'),
  88. '#default_value' => variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT),
  89. '#description' => t("Enabling this option will make the tool use local file access for image files. This option is not recommended to use in conjunction with modules like imagecache which generate the image after it's first accessed. However, it may be necessary in low-end hosting services where the web server is not allowed to open URLs and the user can't modify that configuration setting."),
  90. );
  91. $form['settings']['print_pdf_autoconfig'] = array(
  92. '#type' => 'checkbox',
  93. '#title' => t('Auto-configure the PDF tool settings'),
  94. '#default_value' => variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT),
  95. '#description' => t('If you disable this option, the pdf tool settings must be configured manually. For TCDPF, edit the tcpdf/config/tcpdf_config.php file. For dompdf, edit the dompdf/dompdf_config.inc.php file.'),
  96. );
  97. $form['settings']['print_pdf_filename'] = array(
  98. '#type' => 'textfield',
  99. '#title' => t('PDF filename'),
  100. '#default_value' => variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT),
  101. '#description' => t("If left empty the generated filename defaults to the node's path. Tokens may be used to build the filename (see following list). The .pdf extension will be appended automatically."),
  102. );
  103. if (module_exists('token')) {
  104. $form['settings']['print_pdf_filename_patterns'] = array(
  105. '#theme' => 'token_tree',
  106. '#token_types' => array('node'),
  107. '#dialog' => TRUE,
  108. );
  109. }
  110. $form['settings']['print_pdf_display_sys_urllist'] = array(
  111. '#type' => 'checkbox',
  112. '#title' => t('Printer-friendly URLs list in system pages'),
  113. '#default_value' => variable_get('print_pdf_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
  114. '#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
  115. );
  116. $form['settings']['link_text'] = array(
  117. '#type' => 'fieldset',
  118. '#title' => t('Custom link text'),
  119. '#collapsible' => TRUE,
  120. '#collapsed' => TRUE,
  121. );
  122. $form['settings']['link_text']['print_pdf_link_text_enabled'] = array(
  123. '#type' => 'checkbox',
  124. '#title' => t('Enable custom link text'),
  125. '#default_value' => variable_get('print_pdf_link_text_enabled', PRINT_TYPE_LINK_TEXT_ENABLED_DEFAULT),
  126. );
  127. $form['settings']['link_text']['print_pdf_link_text'] = array(
  128. '#type' => 'textfield',
  129. '#default_value' => variable_get('print_pdf_link_text', $link['text']),
  130. '#description' => t('Text used in the link to the PDF version.'),
  131. );
  132. $form['#validate'][] = '_print_pdf_settings_validate';
  133. }
  134. else {
  135. variable_set('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
  136. $form['settings'] = array(
  137. '#type' => 'markup',
  138. '#markup' => '<p>' . t("No PDF generation tool found! Please download a supported PHP PDF generation tool. Check this module's INSTALL.txt for more details.") . '</p>',
  139. );
  140. }
  141. return system_settings_form($form);
  142. }
  143. /**
  144. * Form validation handler for print_pdf_settings().
  145. *
  146. * @param array $form
  147. * Form.
  148. * @param array $form_state
  149. * Form state.
  150. *
  151. * @see print_pdf_settings()
  152. * @ingroup forms
  153. */
  154. function _print_pdf_settings_validate($form, &$form_state) {
  155. if (empty($form_state['values']['print_pdf_pdf_tool'])) {
  156. form_set_error('print_pdf_pdf_tool', t("No PDF tool selected"));
  157. }
  158. }