source: sipes/modules_contrib/beautytips/beautytips.admin.inc @ 6e81fb4

stableversion-3.0
Last change on this file since 6e81fb4 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100755
File size: 10.7 KB
Línea 
1<?php
2// $Id: beautytips.admin.inc,v 1.1.2.6 2010/06/25 21:33:10 kleinmp Exp $
3
4/**
5 * @file
6 * Beautytips settings form and submit action
7 */
8
9/**
10 * Menu callback - beautytips admin settings form
11 */
12function beautytips_admin() {
13
14  $form['beautytips_always_add'] = array(
15    '#title' => t('Add beautytips js to every page'),
16    '#description' => t('This allows you to give the class \'beautytips\' to any element on a page and the title attribute will popup as a beautytip.<br /> i.e. <i> &lt;p class="beautytips" title="type the text you want beautytips to display here"&gt .....&lt/p&gt</i>'),
17    '#type' => 'checkbox',
18    '#default_value' => variable_get('beautytips_always_add', 0),
19    '#weight' => -1,
20  );
21  $selectors = variable_get('beautytips_added_selectors_array', '');
22  $form['beautytips_added_selectors_string'] = array(
23    '#title' => t('Add beautytips to the following selectors'),
24    '#description' => t("Separate selectors with a comma.  Beautytips will be added to each of these on every page.  The element's title attribute will be the text used. (OPTIONAL)"),
25    '#type' => 'textfield',
26    '#default_value' => is_array($selectors) ? implode(", ", $selectors) : '',
27    '#weight' => -1,
28  );
29  $form['beautytips_default_styles'] = array(
30    '#type' => 'fieldset',
31    '#title' => 'Styling Options',
32    '#collapsible' => TRUE,
33    '#collapsible' => FALSE,
34  );
35  $styles = beautytips_get_styles(TRUE);
36  if (count($styles)) {
37    unset($styles['default']);
38    foreach ($styles as $name => $style) {
39      $bt_style_options[$name]['cssSelect'] = '#edit-beautytips-default-style-' . $name;
40      $bt_style_options[$name]['text'] = 'Aenean risus purus, pharetra in, blandit quis, gravida a, turpis.  Aenean risus purus, pharetra in, blandit quis, gravida a, turpis.  Aenean risus purus, pharetra in, blandit quis, gravida a, turpis.';
41      $bt_style_options[$name]['width'] = isset($style['width']) ? $style['width'] : '300px';
42      $bt_style_options[$name]['style'] = $name;
43      $style_options[$name] = $name;
44    }
45  }
46  $bt_style_options['default_hover'] = array(
47    'cssSelect' => '#beautytips-site-wide-popup',
48    'text' => 'Sed justo nibh, ultrices ut gravida et, laoreet et elit. Nullam consequat lacus et dui dignissim venenatis. Curabitur quis urna eget mi interdum viverra quis eu enim. Ut sit amet nunc augue. Morbi fermentum ultricies velit sed aliquam. Etiam dui tortor, auctor sed tempus ac, auctor sed sapien.',
49    'positions' => array('right'),
50  );
51  $form['beautytips_default_styles']['beautytips_default_style'] = array(
52    '#type' => 'radios',
53    '#title' => t('Choose a default style'),
54    '#description' => t('Mouse over the radio buttons to see a preview.'),
55    '#prefix' => '<div id="beauty-default-styles">',
56    '#suffix' => '</div>',
57    '#options' => $style_options,
58    '#default_value' => variable_get('beautytips_default_style', 'plain'),
59  ); 
60  $style_options = array(
61    'fill' => t('background color (string - html color)'),
62    'strokeWidth' => t('width of border (integer)'),
63    'strokeStyle' => t('color of border (string - html color)'),
64    'width' => t('width of popup (number in px)'),
65    'padding' => t('space between content and border (number in px)'),
66    'cornerRadius' => t('Controls roundness of corners (integer)'),
67    'spikeGirth' => t('thickness of spike (integer)'),
68    'spikeLength' => t('length of spike (integer)'),
69    'shadowBlur' => t('Size of popup shadow (integer)'),
70    'shadowColor' => t('Color of popup shadow (string - html color)'),
71  );
72  $form['beautytips_default_styles']['custom_styles'] = array(
73    '#type' => 'fieldset',
74    '#title' => t('Custom Style Options'),
75    '#description' => t('<b>Set a custom style.</b><br /> Note: These will use the default style that is selected as a base <br /> but will overide elements such as background color, border color etc.   <br /><i>Leave these empty unless you know what you are doing.</i><div id="beautytips-popup-changes"><div id="beauty-click-text"><p>Double Click here to view popup with custom changes</p></div></div>'),
76    '#collapsible' => TRUE,
77    '#collapsed' => TRUE,
78    '#attributes' => array('class' => 'bt-custom-styles'),
79    '#prefix' => '<div id="beautytips-site-wide-popup"><div id="beauty-text"><p>Hover here to see the current site-wide beautytips</p></div></div>',
80  );
81  $custom_style = variable_get('beautytips_custom_style', NULL);
82  foreach ($style_options as $option => $description) {
83    $form['beautytips_default_styles']['custom_styles']['bt-options-box-' . $option] = array(
84      '#title' => $option,
85      '#description' => $description,
86      '#type' => 'textfield',
87      '#default_value' => isset($custom_style[$option]) ? $custom_style[$option] : '',
88    );
89  }
90  // TODO: make this a radio (default, shadow, no-shadow)
91  $form['beautytips_default_styles']['custom_styles']['bt-options-box-shadow'] = array(
92    '#title' => 'shadow',
93    '#description' => t('Whether or not the popup has a shadow'),
94    '#type' => 'radios',
95    '#options' => array('default' => t('Default'), 'shadow' => t('Shadow On'), 'no_shadow' => t('Shadow Off')),
96    '#attributes' => array('class' => 'beautytips-options-shadow'),
97    '#default_value' => isset($custom_style['shadow']) ? $custom_style['shadow'] : 'default',
98  );
99  $form['beautytips_default_styles']['custom_styles']['bt-options-cssClass'] = array(
100    '#title' => 'cssClass',
101    '#description' => t('The class that will be applied to the box wrapper div (of the TIP)'),
102    '#type' => 'textfield',
103    '#default_value' => isset($custom_style['cssClass']) ? $custom_style['cssClass'] : '',
104  );
105  $css_style_options = array('color', 'fontFamily', 'fontWeight', 'fontSize');
106  $form['beautytips_default_styles']['custom_styles']['css-styles'] = array(
107    '#type' => 'fieldset',
108    '#title' => t('Font Styling'),
109    '#description' => t('Enter css options for changing the font style'),
110    '#attributes' => array('class' => 'beautytips-css-styling'),
111    '#collapsible' => FALSE,
112  );
113  foreach ($css_style_options as $option) {
114    $form['beautytips_default_styles']['custom_styles']['css-styles']['bt-options-css-' . $option] = array(
115      '#title' => $option,
116      '#type' => 'textfield',
117      '#default_value' => isset($custom_style['cssStyles'][$option]) ? $custom_style['cssStyles'][$option] : '',
118    );
119  }
120
121  $form['#submit'][] = 'beautytips_admin_submit';
122 
123  $path = drupal_get_path('module', 'beautytips');
124  drupal_add_js($path . '/other_libs/colorpicker/js/colorpicker.js');
125  drupal_add_css($path . '/other_libs/colorpicker/css/colorpicker.css');
126  drupal_add_css($path .'/css/beautytips.css');
127  drupal_add_css($path .'/css/beautytips_admin.css');
128  beautytips_add_beautytips($bt_style_options);
129  drupal_add_js($path . '/js/bt_admin_page.js');
130
131  if (module_exists('beautytips_ui')) {
132    beautytips_ui_admin_settings($form);
133  }
134
135  return system_settings_form($form);
136}
137
138/**
139 * Validation for beautytips settings form
140 */
141function beautytips_admin_validate($form, &$form_state) {
142  $values = $form_state['values'];
143  $integer_fields = array('bt-options-box-strokeWidth', 'bt-options-box-cornerRadius', 'bt-options-box-spikeGirth', 'bt-options-box-spikeLength', 'bt-options-box-shadowBlur');
144  $pixel_fields = array('bt-options-box-width', 'bt-options-box-padding', 'bt-options-css-fontSize');
145  $color_fields = array('bt-options-box-fill', 'bt-options-css-color', 'bt-options-box-shadowColor');
146  $sanitize_strings = array('bt-options-cssClass', 'bt-options-css-fontFamily', 'bt-options-css-fontWeight');
147
148  foreach ($integer_fields as $name) {
149    if ($values[$name]) {
150      if (!is_numeric($values[$name])) {
151        form_set_error($name, t('You need to enter a numeric value for <em>@name</em>', array('@name' => str_replace(array('bt-options-box-', 'bt-options-css-'), '', $name))));
152      }
153      else {
154        $form_state['values'][$name] = round($values[$name]); 
155      }
156    }
157  }
158
159  foreach ($pixel_fields as $name) {
160    if ($values[$name]) {
161      $value = str_replace(array('px', ' '), '', $values[$name]);
162      if (!is_numeric($value) || (!$value && $value != 0)) {
163        form_set_error($name, t('You need to enter a numeric value for <em>@name</em>, followed by <em>px</em>', array('@name' => str_replace(array('bt-options-box-', 'bt-options-css-'), '', $name))));
164      }
165      else {
166        $form_state['values'][$name] = round($values[$name]) . 'px';
167      }
168    }
169  }
170
171  foreach ($color_fields as $name) {
172    if ($values[$name]) {
173      $form_state['values'][$name] = check_plain($values[$name]);
174    }
175  }
176
177  foreach ($sanitize_strings as $name) {
178    if ($values[$name]) {
179      $form_state['values'][$name] = check_plain($values[$name]);
180    }
181  }
182}
183
184/**
185 * Submit function for beautytips settings form
186 */
187function beautytips_admin_submit($form, &$form_state) {
188  $values = $form_state['values'];
189  if (count($values)) {
190    $custom_style = array();
191    $css_style = array();
192    foreach ($values as $option => $value) {
193      if (strpos($option, 'bt-options-box-') === 0) {
194        $option = str_replace('bt-options-box-', '', $option);
195        $custom_style[$option] = $value;
196      }
197      if (strpos($option, 'bt-options-css-') === 0) {
198        $option = str_replace('bt-options-css-', '', $option);
199        if ($value) {
200          $css_style[$option] = $value;
201        }
202      }
203    }
204
205    // Store the defaults - they will be passed to javascript
206    $style = beautytips_get_style($values['beautytips_default_style']);
207    if (count($custom_style)) {
208      foreach ($custom_style as $option => $value) {
209        if ($option == 'shadow') {
210          if ($value != 'default') {
211            $style['shadow'] = $value == 'shadow' ? TRUE : FALSE;
212          }
213        }
214        else if (!empty($value) || $value == '0') {
215          $style[$option] = is_numeric($value) ? (int) $value : (string) $value;
216        }
217      }
218    }
219    if (count($css_style)) {
220      foreach ($css_style as $option => $value) {
221        if (!empty($value)) {
222          $style['cssStyles'][$option] = (string) $value;
223        }
224      }
225      if (!empty($css_style)) {
226        $custom_style['cssStyles'] = $css_style;
227      }
228    }
229    variable_set('beautytips_defaults', $style);
230    variable_set('beautytips_custom_style', $custom_style);
231    variable_set('beautytips_default_style', $values['beautytips_default_style']);
232    cache_clear_all('beautytips:beautytips-styles', 'cache');
233
234    // Store array of selectors that bt will be added to on every page
235    $selectors = explode(",", check_plain($values['beautytips_added_selectors_string']));
236    $test = serialize($selectors);
237    if (count($selectors)) {
238      foreach ($selectors as $key => $selector) {
239        $selectors[$key] = trim($selector);
240      }
241    }
242    variable_set('beautytips_added_selectors_array', $selectors);
243  }
244  if (module_exists('beautytips_ui')) {
245    beautytips_ui_admin_submit($form, $form_state);
246  }
247}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.