print_ui.admin.inc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * @file
  4. * Contains the administrative functions of the print UI module.
  5. *
  6. * This file is included by the print UI module, and includes the
  7. * settings form.
  8. *
  9. * @ingroup print
  10. */
  11. /**
  12. * Form constructor for the send by email module settings form.
  13. *
  14. * @ingroup forms
  15. */
  16. function print_ui_settings() {
  17. $form['settings'] = array(
  18. '#type' => 'fieldset',
  19. '#title' => t('Link options'),
  20. );
  21. foreach (module_implements('print_link') as $module) {
  22. $function = $module . '_print_link';
  23. if (function_exists($function)) {
  24. $link = call_user_func_array($function, array());
  25. $format = $link['format'];
  26. $form['settings']['checkboxes']['link_pos']['print_' . $format . '_link_pos'] = array(
  27. '#type' => 'checkboxes',
  28. '#title' => t('Link location'),
  29. '#default_value' => variable_get('print_' . $format . '_link_pos', drupal_json_decode(PRINT_UI_LINK_POS_DEFAULT)),
  30. '#options' => array('link' => t('Links area'), 'corner' => t('Content corner'), 'block' => t('Block'), 'help' => t('Help area')),
  31. '#description' => t('Choose the location of the link(s) to the printer-friendly version pages. The Links area is usually below the node content, whereas the Content corner is placed in the upper-right corner of the node content (these apply only in node pages). The Help area is used for system pages. Enabling the block area link will allow links of this format in the provided links module. Unselect all options to disable the link. Even if the link is disabled, you can still go to %path where nid is the numeric id of the node.', array('%path' => $link['path'] . '/nid')),
  32. );
  33. $form['settings']['checkboxes']['link_teaser']['print_' . $format . '_link_teaser'] = array(
  34. '#type' => 'checkbox',
  35. '#title' => t('Display link in teaser'),
  36. '#default_value' => variable_get('print_' . $format . '_link_teaser', PRINT_UI_LINK_TEASER_DEFAULT),
  37. '#description' => t('Enabling this will display the link in teaser mode.'),
  38. );
  39. }
  40. }
  41. $form['settings']['adv_link'] = array(
  42. '#type' => 'fieldset',
  43. '#title' => t('Advanced link options'),
  44. '#collapsible' => TRUE,
  45. '#collapsed' => FALSE,
  46. );
  47. foreach (module_implements('print_link') as $module) {
  48. $function = $module . '_print_link';
  49. if (function_exists($function)) {
  50. $link = call_user_func_array($function, array());
  51. $format = $link['format'];
  52. $form['settings']['adv_link']['show_link']['print_' . $format . '_show_link'] = array(
  53. '#type' => 'radios',
  54. '#title' => t('Link style'),
  55. '#default_value' => variable_get('print_' . $format . '_show_link', PRINT_UI_SHOW_LINK_DEFAULT),
  56. '#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
  57. '#description' => t('Select the visual style of the link.'),
  58. );
  59. $form['settings']['adv_link']['link_use_alias']['print_' . $format . '_link_use_alias'] = array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Use URL alias instead of node ID'),
  62. '#default_value' => variable_get('print_' . $format . '_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT),
  63. '#description' => t('Enabling this will create the link using the URL alias instead of the node ID.'),
  64. );
  65. $form['settings']['adv_link']['link_class']['print_' . $format . '_link_class'] = array(
  66. '#type' => 'textfield',
  67. '#title' => t('Link class'),
  68. '#default_value' => variable_get('print_' . $format . '_link_class', $link['class']),
  69. '#size' => 20,
  70. '#maxlength' => 250,
  71. '#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.'),
  72. );
  73. $form['settings']['adv_link']['sys_link_visibility']['print_' . $format . '_sys_link_visibility'] = array(
  74. '#type' => 'radios',
  75. '#title' => t('Show link in system (non-content) pages'),
  76. '#description' => 'Any page that is not a Drupal node. Usually pages generated by Drupal or a module such as Views or Panels.',
  77. '#default_value' => variable_get('print_' . $format . '_sys_link_visibility', PRINT_UI_SYS_LINK_VISIBILITY_DEFAULT),
  78. '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
  79. );
  80. $form['settings']['adv_link']['sys_link_pages']['print_' . $format . '_sys_link_pages'] = array(
  81. '#type' => 'textarea',
  82. '#default_value' => variable_get('print_' . $format . '_sys_link_pages', PRINT_UI_SYS_LINK_PAGES_DEFAULT),
  83. '#rows' => 3,
  84. '#description' => t('Setting this option will add a link on pages created by Drupal or the enabled modules.') . '<br />' .
  85. 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>')),
  86. );
  87. if (module_exists('php')) {
  88. $access = user_access('use PHP for settings');
  89. if ($form['settings']['adv_link']['sys_link_visibility']['print_' . $format . '_sys_link_visibility']['#default_value'] == 2 && !$access) {
  90. $form['settings']['adv_link']['sys_link_visibility']['print_' . $format . '_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
  91. $form['settings']['adv_link']['sys_link_pages']['print_' . $format . '_sys_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_' . $format . '_sys_link_pages']['#default_value']);
  92. }
  93. elseif ($access) {
  94. $form['settings']['adv_link']['sys_link_visibility']['print_' . $format . '_sys_link_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
  95. $form['settings']['adv_link']['sys_link_pages']['print_' . $format . '_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 ?>'));
  96. }
  97. }
  98. $form['settings']['adv_link']['book_link']['print_' . $format . '_book_link'] = array(
  99. '#type' => 'radios',
  100. '#title' => t('Link in book hierarchy nodes'),
  101. '#default_value' => variable_get('print_' . $format . '_book_link', PRINT_UI_BOOK_LINK_DEFAULT),
  102. '#options' => array(t('No link'), t('Current page and sub-pages'), t('Current page only')),
  103. );
  104. }
  105. }
  106. $form['#theme'] = 'print_ui_settings';
  107. return system_settings_form($form);
  108. }
  109. /**
  110. * Returns HTML for the link settings page.
  111. *
  112. * @param array $variables
  113. * An associative array containing:
  114. * - form: A render element representing the form.
  115. *
  116. * @ingroup themeable
  117. * @ingroup print_themeable
  118. */
  119. function theme_print_ui_settings($variables) {
  120. $form = $variables['form'];
  121. $header = array('');
  122. foreach (module_implements('print_link') as $module) {
  123. $function = $module . '_print_link';
  124. if (function_exists($function)) {
  125. $link = call_user_func_array($function, array());
  126. $header[] = array('data' => $link['format'], 'class' => 'checkbox');
  127. }
  128. }
  129. foreach (element_children($form['settings']) as $group) {
  130. $rows = array();
  131. foreach (element_children($form['settings'][$group]) as $elem) {
  132. $row = array();
  133. foreach (module_implements('print_link') as $module) {
  134. $function = $module . '_print_link';
  135. if (function_exists($function)) {
  136. $link = call_user_func_array($function, array());
  137. $format = $link['format'];
  138. $item = $form['settings'][$group][$elem]['print_' . $format . '_' . $elem];
  139. if (empty($row)) {
  140. // Start row, fill title and description
  141. $row_desc = array(
  142. '#type' => 'item',
  143. '#markup' => isset($item['#title']) ? $item['#title'] : '',
  144. '#description' => isset($item['#description']) ? $item['#description'] : '',
  145. );
  146. $row[] = array('data' => drupal_render($row_desc), 'class' => array(''));
  147. }
  148. $item['#title_display'] = 'invisible';
  149. $item['#description'] = '';
  150. $class = ($item['#type'] == 'checkbox') ? 'checkbox' : '';
  151. $row[] = array('data' => drupal_render($item), 'class' => array($class));
  152. }
  153. }
  154. $rows[] = $row;
  155. }
  156. $form['settings'][$group]['#children'] = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions')));
  157. }
  158. $output = drupal_render_children($form);
  159. return $output;
  160. }