print_epub.admin.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @file
  4. * Contains the administrative functions of the EPUB version module.
  5. *
  6. * This file is included by the EPUB version module, and includes the
  7. * settings form.
  8. *
  9. * @ingroup print
  10. */
  11. /**
  12. * Form constructor for the EPUB version module settings form.
  13. *
  14. * @ingroup forms
  15. */
  16. function print_epub_settings() {
  17. $epub_tools = array();
  18. drupal_alter('print_epub_available_libs', $epub_tools);
  19. if (!empty($epub_tools)) {
  20. $link = print_epub_print_link();
  21. $current_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
  22. $epub_tool_default = array_key_exists($current_epub_tool, $epub_tools) ? $current_epub_tool : PRINT_EPUB_EPUB_TOOL_DEFAULT;
  23. $form['settings'] = array(
  24. '#type' => 'fieldset',
  25. '#title' => t('EPUB options'),
  26. );
  27. $form['settings']['print_epub_epub_tool'] = array(
  28. '#type' => 'radios',
  29. '#title' => t('EPUB generation tool'),
  30. '#options' => $epub_tools,
  31. '#default_value' => $epub_tool_default,
  32. '#description' => t('This option selects the EPUB generation tool being used by this module to create the EPUB version.'),
  33. );
  34. $form['settings']['print_epub_images_via_file'] = array(
  35. '#type' => 'checkbox',
  36. '#title' => t('Access images via local file access'),
  37. '#default_value' => variable_get('print_epub_images_via_file', PRINT_EPUB_IMAGES_VIA_FILE_DEFAULT),
  38. '#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."),
  39. );
  40. $form['settings']['print_epub_filename'] = array(
  41. '#type' => 'textfield',
  42. '#title' => t('EPUB filename'),
  43. '#default_value' => variable_get('print_epub_filename', PRINT_EPUB_FILENAME_DEFAULT),
  44. '#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 .epub extension will be appended automatically."),
  45. );
  46. if (module_exists('token')) {
  47. $form['settings']['print_epub_filename_patterns'] = array(
  48. '#theme' => 'token_tree',
  49. '#token_types' => array('node'),
  50. '#dialog' => TRUE,
  51. );
  52. }
  53. $form['settings']['print_epub_display_sys_urllist'] = array(
  54. '#type' => 'checkbox',
  55. '#title' => t('Printer-friendly URLs list in system pages'),
  56. '#default_value' => variable_get('print_epub_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT),
  57. '#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
  58. );
  59. $form['settings']['link_text'] = array(
  60. '#type' => 'fieldset',
  61. '#title' => t('Custom link text'),
  62. '#collapsible' => TRUE,
  63. '#collapsed' => TRUE,
  64. );
  65. $form['settings']['link_text']['print_epub_link_text_enabled'] = array(
  66. '#type' => 'checkbox',
  67. '#title' => t('Enable custom link text'),
  68. '#default_value' => variable_get('print_epub_link_text_enabled', PRINT_TYPE_LINK_TEXT_ENABLED_DEFAULT),
  69. );
  70. $form['settings']['link_text']['print_epub_link_text'] = array(
  71. '#type' => 'textfield',
  72. '#default_value' => variable_get('print_epub_link_text', $link['text']),
  73. '#description' => t('Text used in the link to the EPUB version.'),
  74. );
  75. $form['#validate'][] = '_print_epub_settings_validate';
  76. }
  77. else {
  78. variable_set('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
  79. $form['settings'] = array(
  80. '#type' => 'markup',
  81. '#markup' => '<p>' . t("No EPUB generation tool found! Please download a supported PHP EPUB generation tool. Check this module's INSTALL.txt for more details.") . '</p>',
  82. );
  83. }
  84. return system_settings_form($form);
  85. }
  86. /**
  87. * Form validation handler for print_epub_settings().
  88. *
  89. * @see print_epub_settings()
  90. * @ingroup forms
  91. */
  92. function _print_epub_settings_validate($form, &$form_state) {
  93. if (empty($form_state['values']['print_epub_epub_tool'])) {
  94. form_set_error('print_epub_epub_tool', t("No EPUB tool selected"));
  95. }
  96. }