Projet

Général

Profil

Paste
Télécharger (8,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / print / print_ui / print_ui.admin.inc @ 76bdcd04

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the administrative functions of the print UI module.
6
 *
7
 * This file is included by the print UI module, and includes the
8
 * settings form.
9
 *
10
 * @ingroup print
11
 */
12

    
13
/**
14
 * Form constructor for the send by email module settings form.
15
 *
16
 * @ingroup forms
17
 */
18
function print_ui_settings() {
19
  $form['settings'] = array(
20
    '#type' => 'fieldset',
21
    '#title' => t('Link options'),
22
  );
23

    
24
  foreach (module_implements('print_link') as $module) {
25
    $function = $module . '_print_link';
26
    if (function_exists($function)) {
27
      $link = call_user_func_array($function, array());
28
      $format = $link['format'];
29

    
30
      $form['settings']['checkboxes']['link_pos']['print_' . $format . '_link_pos'] = array(
31
        '#type' => 'checkboxes',
32
        '#title' => t('Link location'),
33
        '#default_value' => variable_get('print_' . $format . '_link_pos', drupal_json_decode(PRINT_UI_LINK_POS_DEFAULT)),
34
        '#options' => array(
35
          'link' => t('Links area'),
36
          'corner' => t('Content corner'),
37
          'block' => t('Block'),
38
          'help' => t('Help area'),
39
        ),
40
        '#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')),
41
      );
42

    
43
      $form['settings']['checkboxes']['link_teaser']['print_' . $format . '_link_teaser'] = array(
44
        '#type' => 'checkbox',
45
        '#title' => t('Display link in teaser'),
46
        '#default_value' => variable_get('print_' . $format . '_link_teaser', PRINT_UI_LINK_TEASER_DEFAULT),
47
        '#description' => t('Enabling this will display the link in teaser mode.'),
48
      );
49
    }
50
  }
51

    
52
  $form['settings']['adv_link'] = array(
53
    '#type' => 'fieldset',
54
    '#title' => t('Advanced link options'),
55
    '#collapsible' => TRUE,
56
    '#collapsed' => FALSE,
57
  );
58

    
59
  foreach (module_implements('print_link') as $module) {
60
    $function = $module . '_print_link';
61
    if (function_exists($function)) {
62
      $link = call_user_func_array($function, array());
63
      $format = $link['format'];
64

    
65
      $form['settings']['adv_link']['show_link']['print_' . $format . '_show_link'] = array(
66
        '#type' => 'radios',
67
        '#title' => t('Link style'),
68
        '#default_value' => variable_get('print_' . $format . '_show_link', PRINT_UI_SHOW_LINK_DEFAULT),
69
        '#options' => array(
70
          1 => t('Text only'),
71
          2 => t('Icon only'),
72
          3 => t('Icon and Text'),
73
        ),
74
        '#description' => t('Select the visual style of the link.'),
75
      );
76

    
77
      $form['settings']['adv_link']['link_use_alias']['print_' . $format . '_link_use_alias'] = array(
78
        '#type' => 'checkbox',
79
        '#title' => t('Use URL alias instead of node ID'),
80
        '#default_value' => variable_get('print_' . $format . '_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT),
81
        '#description' => t('Enabling this will create the link using the URL alias instead of the node ID.'),
82
      );
83

    
84
      $form['settings']['adv_link']['link_class']['print_' . $format . '_link_class'] = array(
85
        '#type' => 'textfield',
86
        '#title' => t('Link class'),
87
        '#default_value' => variable_get('print_' . $format . '_link_class', $link['class']),
88
        '#size' => 20,
89
        '#maxlength' => 250,
90
        '#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.'),
91
      );
92

    
93
      $form['settings']['adv_link']['sys_link_visibility']['print_' . $format . '_sys_link_visibility'] = array(
94
        '#type' => 'radios',
95
        '#title' => t('Show link in system (non-content) pages'),
96
        '#description' => 'Any page that is not a Drupal node. Usually pages generated by Drupal or a module such as Views or Panels.',
97
        '#default_value' => variable_get('print_' . $format . '_sys_link_visibility', PRINT_UI_SYS_LINK_VISIBILITY_DEFAULT),
98
        '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
99
      );
100

    
101
      $form['settings']['adv_link']['sys_link_pages']['print_' . $format . '_sys_link_pages'] = array(
102
        '#type' => 'textarea',
103
        '#default_value' => variable_get('print_' . $format . '_sys_link_pages', PRINT_UI_SYS_LINK_PAGES_DEFAULT),
104
        '#rows' => 3,
105
        '#description' => t('Setting this option will add a link on pages created by Drupal or the enabled modules.') . '<br />' .
106
          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(
107
            '%blog' => 'blog',
108
            '%blog-wildcard' => 'blog/*',
109
            '%front' => '<front>',
110
          )),
111
      );
112

    
113
      if (module_exists('php')) {
114
        $access = user_access('use PHP for settings');
115

    
116
        if ($form['settings']['adv_link']['sys_link_visibility']['print_' . $format . '_sys_link_visibility']['#default_value'] == 2 && !$access) {
117
          $form['settings']['adv_link']['sys_link_visibility']['print_' . $format . '_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
118
          $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']);
119
        }
120
        elseif ($access) {
121
          $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).');
122
          $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 ?>'));
123
        }
124
      }
125

    
126
      $form['settings']['adv_link']['book_link']['print_' . $format . '_book_link'] = array(
127
        '#type' => 'radios',
128
        '#title' => t('Link in book hierarchy nodes'),
129
        '#default_value' => variable_get('print_' . $format . '_book_link', PRINT_UI_BOOK_LINK_DEFAULT),
130
        '#options' => array(
131
          t('No link'),
132
          t('Current page and sub-pages'),
133
          t('Current page only'),
134
        ),
135
      );
136
    }
137
  }
138

    
139
  $form['#theme'] = 'print_ui_settings';
140

    
141
  return system_settings_form($form);
142
}
143

    
144
/**
145
 * Returns HTML for the link settings page.
146
 *
147
 * @param array $variables
148
 *   An associative array containing:
149
 *   - form: A render element representing the form.
150
 *
151
 * @return string
152
 *   HTML for the link settings page.
153
 *
154
 * @ingroup themeable
155
 * @ingroup print_themeable
156
 */
157
function theme_print_ui_settings($variables) {
158
  $form = $variables['form'];
159
  $header = array('');
160

    
161
  foreach (module_implements('print_link') as $module) {
162
    $function = $module . '_print_link';
163
    if (function_exists($function)) {
164
      $link = call_user_func_array($function, array());
165

    
166
      $header[] = array('data' => $link['format'], 'class' => 'checkbox');
167
    }
168
  }
169

    
170
  foreach (element_children($form['settings']) as $group) {
171
    $rows = array();
172
    foreach (element_children($form['settings'][$group]) as $elem) {
173
      $row = array();
174

    
175
      foreach (module_implements('print_link') as $module) {
176
        $function = $module . '_print_link';
177
        if (function_exists($function)) {
178
          $link = call_user_func_array($function, array());
179
          $format = $link['format'];
180

    
181
          $item = $form['settings'][$group][$elem]['print_' . $format . '_' . $elem];
182

    
183
          if (empty($row)) {
184
            // Start row, fill title and description.
185
            $row_desc = array(
186
              '#type' => 'item',
187
              '#markup' => isset($item['#title']) ? $item['#title'] : '',
188
              '#description' => isset($item['#description']) ? $item['#description'] : '',
189
            );
190

    
191
            $row[] = array('data' => drupal_render($row_desc), 'class' => array(''));
192
          }
193

    
194
          $item['#title_display'] = 'invisible';
195
          $item['#description'] = '';
196

    
197
          $class = ($item['#type'] == 'checkbox') ? 'checkbox' : '';
198

    
199
          $row[] = array('data' => drupal_render($item), 'class' => array($class));
200
        }
201
      }
202
      $rows[] = $row;
203
    }
204

    
205
    $form['settings'][$group]['#children'] = theme('table', array(
206
      'header' => $header,
207
      'rows' => $rows,
208
      'attributes' => array('id' => 'permissions'),
209
    ));
210
  }
211

    
212
  $output = drupal_render_children($form);
213

    
214
  return $output;
215
}