1 | <?php |
---|
2 | // $Id: beautytips.module,v 1.10.2.8 2010/07/07 21:30:09 kleinmp Exp $ |
---|
3 | |
---|
4 | /** |
---|
5 | * @file |
---|
6 | * Provides API for adding beautytips to pages. |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * Implementation of hook_init(). |
---|
11 | */ |
---|
12 | function beautytips_init() { |
---|
13 | if (variable_get('beautytips_always_add', 0)) { |
---|
14 | $selectors = array(); |
---|
15 | $options = array(); |
---|
16 | $selectors = variable_get('beautytips_added_selectors_array', array()); |
---|
17 | if (count($selectors)) { |
---|
18 | foreach ($selectors as $selector) { |
---|
19 | if (!empty($selector)) { |
---|
20 | $options[$selector]['cssSelect'] = $selector; |
---|
21 | } |
---|
22 | } |
---|
23 | } |
---|
24 | $options['.beautytips']['cssSelect'] = '.beautytips'; |
---|
25 | beautytips_add_beautytips($options); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | /** |
---|
30 | * Implementation of hook_menu(). |
---|
31 | */ |
---|
32 | function beautytips_menu() { |
---|
33 | $items['admin/settings/beautytips'] = array( |
---|
34 | 'title' => 'BeautyTips', |
---|
35 | 'page callback' => 'drupal_get_form', |
---|
36 | 'page arguments' => array('beautytips_admin'), |
---|
37 | 'access arguments' => array('administer site configuration'), |
---|
38 | 'file' => 'beautytips.admin.inc', |
---|
39 | ); |
---|
40 | return $items; |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * This is the API. Call this function to add beautytips. |
---|
45 | * |
---|
46 | * @param array $options - See README.txt for details |
---|
47 | */ |
---|
48 | function beautytips_add_beautytips($options = NULL) { |
---|
49 | static $added = FALSE; |
---|
50 | $settings = array('beautytips' => array()); |
---|
51 | $js_added = drupal_add_js($data = NULL, 'setting'); |
---|
52 | |
---|
53 | if (count($options)) { |
---|
54 | foreach ($options as $beautytip => $content) { |
---|
55 | |
---|
56 | // Ensure the js settings are not added more than once |
---|
57 | if (isset($js_added['setting']) && is_array($js_added['setting'])) { |
---|
58 | foreach ($js_added['setting'] as $setting) { |
---|
59 | if (is_array($setting['beautytips'])) { |
---|
60 | if (array_key_exists($beautytip, $setting['beautytips'])) { |
---|
61 | unset($content); |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | // Setup the settings array for adding js |
---|
68 | if (is_array($content)) { |
---|
69 | $style = isset($content['style']) ? $content['style'] : 'default'; |
---|
70 | $settings['beautytips'][$beautytip] = array_merge(beautytips_get_style($style), $content); |
---|
71 | $keys_no_add = array('cssSelect', 'style', 'list', 'text', 'preEval', 'ajaxDisableLink'); |
---|
72 | foreach ($settings['beautytips'][$beautytip] as $key => $value) { |
---|
73 | if (!in_array($key, $keys_no_add)) { |
---|
74 | $settings['beautytips'][$beautytip]['list'][] = $key; |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | if ($added && !empty($settings['beautytips'])) { |
---|
80 | drupal_add_js($settings, 'setting'); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | // Add beautytips jQuery plugin |
---|
85 | if (!$added) { |
---|
86 | $path = drupal_get_path('module', 'beautytips'); |
---|
87 | |
---|
88 | //for IE add this |
---|
89 | $expath = $path . '/other_libs/excanvas_r3'; |
---|
90 | if (count(file_scan_directory($expath, 'excanvas.js', array('.', '..', 'CVS'), 0, FALSE))) { |
---|
91 | drupal_add_js($expath . '/excanvas.compiled.js'); |
---|
92 | } |
---|
93 | drupal_add_js($path . '/js/jquery.bt.min.js'); |
---|
94 | drupal_add_js($path . '/js/beautytips.js'); |
---|
95 | |
---|
96 | drupal_add_js($settings, 'setting'); |
---|
97 | $added = TRUE; |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * Get all the defined beautytips styles |
---|
103 | */ |
---|
104 | function beautytips_get_styles($reload = FALSE) { |
---|
105 | $cache = cache_get('beautytips:beautytips-styles'); |
---|
106 | if (!$cache || $reload) { |
---|
107 | $styles = module_invoke_all('define_beautytips_styles'); |
---|
108 | // Save the beautytips style registry in the cache. |
---|
109 | cache_set('beautytips:beautytips-styles', $styles); |
---|
110 | } |
---|
111 | else { |
---|
112 | $styles = $cache->data; |
---|
113 | } |
---|
114 | return $styles; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * Get an array of options that defines a particular style |
---|
119 | */ |
---|
120 | function beautytips_get_style($style = 'default') { |
---|
121 | $styles = beautytips_get_styles(); |
---|
122 | return isset($styles[$style]) ? $styles[$style] : array(); |
---|
123 | } |
---|
124 | |
---|
125 | /** |
---|
126 | * Implementation of hook_define_beautytips_styles(). |
---|
127 | * |
---|
128 | * @return $styles - an array of different styles |
---|
129 | */ |
---|
130 | function beautytips_define_beautytips_styles() { |
---|
131 | $styles['default'] = variable_get('beautytips_defaults', array()); |
---|
132 | $styles['plain'] = array( |
---|
133 | //'cssStyles' => array(), |
---|
134 | ); |
---|
135 | $styles['netflix'] = array( |
---|
136 | 'positions' => array('right', 'left'), |
---|
137 | 'fill' => '#FFF', |
---|
138 | 'padding' => 5, |
---|
139 | 'shadow' => TRUE, |
---|
140 | 'shadowBlur' => 12, |
---|
141 | 'strokeStyle' => '#B9090B', |
---|
142 | 'spikeLength' => 50, |
---|
143 | 'spikeGirth' => 60, |
---|
144 | 'cornerRadius' => 10, |
---|
145 | 'centerPointY' => .1, |
---|
146 | 'overlap' => -8, |
---|
147 | 'cssStyles' => array( |
---|
148 | 'fontSize' => '12px', |
---|
149 | 'fontFamily' => 'arial,helvetica,sans-serif', |
---|
150 | ), |
---|
151 | ); |
---|
152 | $styles['facebook'] = array( |
---|
153 | 'fill' => '#F7F7F7', |
---|
154 | 'padding' => 8, |
---|
155 | 'strokeStyle' => '#B7B7B7', |
---|
156 | 'cornerRadius' => 0, |
---|
157 | 'cssStyles' => array( |
---|
158 | 'fontFamily' => '"lucida grande",tahoma,verdana,arial,sans-serif', |
---|
159 | 'fontSize' => '11px', |
---|
160 | ), |
---|
161 | ); |
---|
162 | $styles['transparent'] = array( |
---|
163 | 'fill' => 'rgba(0, 0, 0, .8)', |
---|
164 | 'padding' => 20, |
---|
165 | 'strokeStyle' => '#CC0', |
---|
166 | 'strokeWidth' => 3, |
---|
167 | 'spikeLength' => 40, |
---|
168 | 'spikeGirth' => 40, |
---|
169 | 'cornerRadius' => 40, |
---|
170 | 'cssStyles' => array( |
---|
171 | 'color' => '#FFF', |
---|
172 | 'fontWeight' => 'bold', |
---|
173 | ), |
---|
174 | ); |
---|
175 | $styles['big-green'] = array( |
---|
176 | 'fill' => '#00FF4E', |
---|
177 | 'padding' => 20, |
---|
178 | 'strokeWidth' => 0, |
---|
179 | 'spikeLength' => 40, |
---|
180 | 'spikeGirth' => 40, |
---|
181 | 'cornerRadius' => 15, |
---|
182 | 'cssStyles' => array( |
---|
183 | 'fontFamily' => '"lucida grande",tahoma,verdana,arial,sans-serif', |
---|
184 | 'fontSize' => '14px', |
---|
185 | ), |
---|
186 | ); |
---|
187 | $styles['google-maps'] = array( |
---|
188 | 'positions' => array(0 => 'top', 1 => 'bottom'), |
---|
189 | 'fill' => '#FFF', |
---|
190 | 'padding' => 15, |
---|
191 | 'strokeStyle' => '#ABABAB', |
---|
192 | 'strokeWidth' => 1, |
---|
193 | 'spikeLength' => 65, |
---|
194 | 'spikeGirth' => 40, |
---|
195 | 'cornerRadius' => 25, |
---|
196 | 'centerPointX' => .9, |
---|
197 | 'cssStyles' => array(), |
---|
198 | ); |
---|
199 | $styles['hulu'] = array( |
---|
200 | 'fill' => '#F4F4F4', |
---|
201 | 'strokeStyle' => '#666666', |
---|
202 | 'spikeLength' => 20, |
---|
203 | 'spikeGirth' => 10, |
---|
204 | 'width' => 350, |
---|
205 | 'overlap' => 0, |
---|
206 | 'centerPointY' => 1, |
---|
207 | 'cornerRadius' => 0, |
---|
208 | 'cssStyles' => array( |
---|
209 | 'fontFamily' => '"Lucida Grande",Helvetica,Arial,Verdana,sans-serif', |
---|
210 | 'fontSize' => '12px', |
---|
211 | 'padding' => '10px 14px' |
---|
212 | ), |
---|
213 | 'shadow' => TRUE, |
---|
214 | 'shadowColor' => 'rgba(0,0,0,.5)', |
---|
215 | 'shadowBlur' => 8, |
---|
216 | 'shadowOffsetX' => 4, |
---|
217 | 'shadowOffsetY' => 4, |
---|
218 | ); |
---|
219 | return $styles; |
---|
220 | } |
---|