/[drupal]/contributions/modules/fivestarextra/fivestarextra.admin.inc
ViewVC logotype

Contents of /contributions/modules/fivestarextra/fivestarextra.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Mon Oct 27 12:34:28 2008 UTC (13 months ago) by likeless
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA3, DRUPAL-6--1-1, HEAD
Changes since 1.2: +46 -3 lines
File MIME type: text/x-php
#326507 by Likeless: Added prototype node type filtering for comment rating.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Admin pages and functions for fivestarextra
7 *
8 */
9
10
11 /**
12 * Admin settings form, mainly cannibalised from fivestar_form_alter,
13 * with a few important modifications.
14 */
15 function fivestarextra_comments_admin_form(&$form_state) {
16
17 $form['fivestar'] = array(
18 '#type' => 'fieldset',
19 '#title' => t('Fivestar Comments Rating'),
20 '#description' => t('This is for rating comments, as in whether a particular comment is good or bad. For writing reviews of nodes, including comments, see the module Fivestar Comments.'),
21 '#theme' => 'fivestar_node_type_form',
22 '#attributes' => array('id' => 'fivestar-node-type-form'),
23 );
24
25 $form['fivestar']['fivestar'] = array(
26 '#type' => 'checkbox',
27 '#title' => t('Enable Fivestar rating on comments'),
28 '#default_value' => variable_get('fivestarextra_enable_comment', 0),
29 '#return_value' => 1,
30 '#weight' => -5,
31 );
32
33 $form['fivestar']['fivestar_stars'] = array(
34 '#type' => 'select',
35 '#title' => t('Number of stars'),
36 '#options' => drupal_map_assoc(range(1, 10)),
37 '#default_value' => variable_get('fivestarextra_stars_comment', 5),
38 '#weight' => -4,
39 );
40
41
42 $form['fivestar']['labels'] = array(
43 '#type' => 'fieldset',
44 '#title' => t('Star Labels'),
45 '#collapsible' => TRUE,
46 '#collapsed' => TRUE,
47 '#description' => t('These star labels appear as the link title when javascript is enabled as well as the select list options when javascript is disabled.'),
48 );
49
50 $form['fivestar']['labels']['fivestar_labels_enable'] = array(
51 '#type' => 'checkbox',
52 '#title' => t('Display labels on mouse over'),
53 '#default_value' => variable_get('fivestarextra_labels_enable_comment', 1),
54 '#return_value' => 1,
55 '#weight' => -5,
56 '#description' => t('When enabled, the star labels will dynamically appear underneath the stars as the user hovers over each star to provide a more descriptive qualitative meaning for each star value.'),
57 );
58
59 // Create the Mouseover text forms for each of the rating options
60 // This form depends on the number of stars, and these extra textfields will be hidden with javascript
61 $star_count = variable_get('fivestarextra_stars_comment', 5);
62 $labels = variable_get('fivestarextra_labels_comment', array());
63 for ($n = 0; $n <= 10; $n++) {
64 if ($star_count == 5 && $n <= 5) {
65 // If the default 5 stars are chosen, then use these five default label values.
66 $default_labels = array('Cancel rating', 'Poor', 'Okay', 'Good', 'Great', 'Awesome');
67 }
68 elseif ($n == 0) {
69 $default_labels[$n] = 'Cancel rating';
70 }
71 else {
72 $default_labels[$n] = 'Give it @star/@count';
73 }
74 $form['fivestar']['labels']['fivestar_label_'. $n] = array(
75 '#type' => 'textfield',
76 '#title' => $n > 0 ? t('Star @star label', array('@star' => $n)) : t('Cancel label'),
77 '#default_value' => isset($labels[$n]) ? $labels[$n] : $default_labels[$n],
78 '#prefix' => '<div id="fivestar-label-'. $n .'" class="fivestar-label">',
79 '#suffix' => '</div>',
80 '#size' => 30,
81 );
82 }
83
84 $form['fivestar']['direct'] = array(
85 '#type' => 'fieldset',
86 '#title' => t('Direct rating widget'),
87 '#collapsible' => FALSE,
88 '#description' => t('These settings allow you to display a rating widget to your users while they are viewing content of this type. Rating will immediately register a vote for that piece of content.'),
89 '#weight' => 2,
90 );
91
92 $form['fivestar']['direct']['fivestar_style'] = array(
93 '#type' => 'select',
94 '#title' => t('Star display style'),
95 '#default_value' => variable_get('fivestarextra_style_comment', 'average'),
96 '#options' => array(
97 'average' => t('Display average vote value'),
98 'user' => t('Display user vote value'),
99 'smart' => t('User vote if available, average otherwise'),
100 'dual' => t('Both user and average vote'),
101 ),
102 );
103
104 $form['fivestar']['direct']['fivestar_text'] = array(
105 '#type' => 'select',
106 '#title' => t('Text display style'),
107 '#default_value' => variable_get('fivestarextra_text_comment', 'dual'),
108 '#options' => array(
109 'none' => t('Display no text beneath stars'),
110 'average' => t('Current average in text'),
111 'user' => t('User current vote in text'),
112 'smart' => t('User vote if available, average otherwise'),
113 'dual' => t('Both user and average vote'),
114 ),
115 );
116
117 $form['fivestar']['direct']['fivestar_title'] = array(
118 '#type' => 'checkbox',
119 '#title' => t('Show widget title'),
120 '#default_value' => variable_get('fivestarextra_title_comment', 1),
121 '#return_value' => 1,
122 );
123
124 $form['fivestar']['direct']['fivestar_feedback'] = array(
125 '#type' => 'checkbox',
126 '#title' => t('Enable feedback during vote saving and deletion'),
127 '#default_value' => variable_get('fivestarextra_feedback_comment', 1),
128 '#return_value' => 1
129 );
130
131 $form['fivestar']['direct']['fivestar_unvote'] = array(
132 '#type' => 'checkbox',
133 '#title' => t('Allow users to undo their votes'),
134 '#default_value' => variable_get('fivestarextra_unvote_comment', 0),
135 '#return_value' => 1,
136 );
137
138 $form['fivestar']['direct']['fivestar_position'] = array(
139 '#type' => 'select',
140 '#title' => t('Display mode'),
141 '#default_value' => variable_get('fivestarextra_position_comment', 'below'),
142 '#options' => array(
143 'above' => t('Clickable widget above comment body'),
144 'below' => t('Clickable widget below comment body'),
145 'hidden' => t('<Hidden>'),
146 ),
147 );
148
149 $form['fivestar']['direct']['fivestar_direct_preview'] = array(
150 '#type' => 'item',
151 '#title' => t('Direct rating widget preview'),
152 '#value' => theme(
153 'fivestar_preview',
154 $form['fivestar']['direct']['fivestar_style']['#default_value'],
155 $form['fivestar']['direct']['fivestar_text']['#default_value'],
156 $form['fivestar']['fivestar_stars']['#default_value'],
157 $form['fivestar']['direct']['fivestar_unvote']['#default_value'],
158 $form['fivestar']['direct']['fivestar_title']['#default_value'] ? NULL : FALSE,
159 $form['fivestar']['labels']['fivestar_labels_enable']['#default_value'],
160 variable_get('fivestarextra_labels_comment', array())
161 ),
162 );
163 if (!$form['fivestar']['fivestar']['#default_value']) {
164 $form['fivestar']['direct']['fivestar_direct_preview']['#value'] = theme('fivestar_preview_wrapper', '');
165 }
166 else {
167 $form['fivestar']['direct']['fivestar_direct_preview']['#value'] = theme('fivestar_preview_wrapper', $form['fivestar']['direct']['fivestar_direct_preview']['#value']);
168 }
169
170 $form['fivestar']['nodetypes'] = array(
171 '#type' => 'fieldset',
172 '#title' => t('Restrict By Node Type'),
173 '#collapsible' => TRUE,
174 '#collapsed' => TRUE,
175 '#description' => t('Leave this section alone to allow rating of all comments. Enable it if you want to allow comments to be rated only on particular types of node.'),
176 '#weight' => 5,
177 );
178
179 $form['fivestar']['nodetypes']['fivestar_noderestrict_enable'] = array(
180 '#type' => 'checkbox',
181 '#title' => t('Restrict By Node Type'),
182 '#default_value' => variable_get('fivestarextra_noderestrict_enable_comment', 0),
183 '#return_value' => 1,
184 '#prefix' => theme('fivestarextra_noderestrict_enable_comment',''),
185 '#weight' => -5,
186 );
187
188 $nodetypes = node_get_types('names');
189 $form['fivestar']['nodetypes']['fivestar_noderestrict_nodetypes'] = array(
190 '#type' => 'checkboxes',
191 '#title' => t('Enable Comment Rating on These Node Types'),
192 '#default_value' => variable_get('fivestarextra_noderestrict_nodetypes', array_keys($nodetypes)),
193 '#options' => $nodetypes,
194 '#attributes' => array('class' => 'fivestarextra_noderestrict_nodetypes'),
195 '#weight' => 0,
196 );
197
198 $form['submit'] = array(
199 '#type' => 'submit',
200 '#value' => t('Submit'),
201 '#weight' => 45,
202 );
203
204 $form['#submit'][] = 'fivestarextra_comments_admin_form_submit';
205 return $form;
206 }
207
208
209 /**
210 * Admin settings form submit function. It simply saves the variables.
211 */
212 function fivestarextra_comments_admin_form_submit($form, &$form_state) {
213 variable_set('fivestarextra_enable_comment',$form_state['values']['fivestar']);
214
215 $variables = array('stars','labels_enable','style','text','title','unvote','feedback','position','noderestrict_enable');
216 foreach ($variables as $variable) {
217 variable_set('fivestarextra_'.$variable .'_comment',$form_state['values']['fivestar_'.$variable]);
218 }
219
220 //Merge node types into an array
221 $nodetypes = array();
222 foreach ($form_state['values']['fivestar_noderestrict_nodetypes'] as $type => $value) {
223 if ($value) {
224 $nodetypes[] = $type;
225 }
226 }
227 variable_set('fivestarextra_noderestrict_nodetypes',$nodetypes);
228
229 // Merge labels into a single variable.
230 $labels = array();
231 for ($n = 0; $n <= 10; $n++) {
232 $labels[] = $form_state['values']['fivestar_label_'. $n];
233 variable_del('fivestarextra_label_'. $n .'_comment');
234 }
235 variable_del('fivestar_labels_comment');
236 if ($form_state['values']['fivestar_labels_enable']) {
237 variable_set('fivestarextra_labels_comment', $labels);
238 }
239 };
240
241
242 /**
243 * Theme the checkbox for the node type part of the admin form. This adds a tiny javascript file.
244 */
245 function theme_fivestarextra_noderestrict_enable_comment($element) {
246 drupal_add_js(drupal_get_path('module', 'fivestarextra') .'/fivestarextra-admin.js');
247 return '';
248 }
249
250
251 /**
252 * Admin settings form, mainly cannibalised from fivestar_form_alter,
253 * with a few important modifications.
254 */
255 function fivestarextra_users_admin_form(&$form_state) {
256
257 $form['fivestar'] = array(
258 '#type' => 'fieldset',
259 '#title' => t('Fivestar users Rating'),
260 '#description' => t('This is for rating users, as in whether a particular user is good or bad. For writing reviews of nodes, including users, see the module Fivestar users.'),
261 '#theme' => 'fivestar_node_type_form',
262 '#attributes' => array('id' => 'fivestar-node-type-form'),
263 );
264
265 $form['fivestar']['fivestar'] = array(
266 '#type' => 'checkbox',
267 '#title' => t('Enable Fivestar rating on users'),
268 '#default_value' => variable_get('fivestarextra_enable_user', 0),
269 '#return_value' => 1,
270 '#weight' => -5,
271 );
272
273 $form['fivestar']['fivestar_stars'] = array(
274 '#type' => 'select',
275 '#title' => t('Number of stars'),
276 '#options' => drupal_map_assoc(range(1, 10)),
277 '#default_value' => variable_get('fivestarextra_stars_user', 5),
278 '#weight' => -4,
279 );
280
281
282 $form['fivestar']['labels'] = array(
283 '#type' => 'fieldset',
284 '#title' => t('Star Labels'),
285 '#collapsible' => TRUE,
286 '#collapsed' => TRUE,
287 '#description' => t('These star labels appear as the link title when javascript is enabled as well as the select list options when javascript is disabled.'),
288 );
289
290 $form['fivestar']['labels']['fivestar_labels_enable'] = array(
291 '#type' => 'checkbox',
292 '#title' => t('Display labels on mouse over'),
293 '#default_value' => variable_get('fivestarextra_labels_enable_user', 1),
294 '#return_value' => 1,
295 '#weight' => -5,
296 '#description' => t('When enabled, the star labels will dynamically appear underneath the stars as the user hovers over each star to provide a more descriptive qualitative meaning for each star value.'),
297 );
298
299 // Create the Mouseover text forms for each of the rating options
300 // This form depends on the number of stars, and these extra textfields will be hidden with javascript
301 $star_count = variable_get('fivestarextra_stars_user', 5);
302 $labels = variable_get('fivestarextra_labels_user', array());
303 for ($n = 0; $n <= 10; $n++) {
304 if ($star_count == 5 && $n <= 5) {
305 // If the default 5 stars are chosen, then use these five default label values.
306 $default_labels = array('Cancel rating', 'Poor', 'Okay', 'Good', 'Great', 'Awesome');
307 }
308 elseif ($n == 0) {
309 $default_labels[$n] = 'Cancel rating';
310 }
311 else {
312 $default_labels[$n] = 'Give it @star/@count';
313 }
314 $form['fivestar']['labels']['fivestar_label_'. $n] = array(
315 '#type' => 'textfield',
316 '#title' => $n > 0 ? t('Star @star label', array('@star' => $n)) : t('Cancel label'),
317 '#default_value' => isset($labels[$n]) ? $labels[$n] : $default_labels[$n],
318 '#prefix' => '<div id="fivestar-label-'. $n .'" class="fivestar-label">',
319 '#suffix' => '</div>',
320 '#size' => 30,
321 );
322 }
323
324 $form['fivestar']['direct'] = array(
325 '#type' => 'fieldset',
326 '#title' => t('Direct rating widget'),
327 '#collapsible' => FALSE,
328 '#description' => t('These settings allow you to display a rating widget to your users while they are viewing content of this type. Rating will immediately register a vote for that piece of content.'),
329 '#weight' => 2,
330 );
331
332 $form['fivestar']['direct']['fivestar_style'] = array(
333 '#type' => 'select',
334 '#title' => t('Star display style'),
335 '#default_value' => variable_get('fivestarextra_style_user', 'average'),
336 '#options' => array(
337 'average' => t('Display average vote value'),
338 'user' => t('Display user vote value'),
339 'smart' => t('User vote if available, average otherwise'),
340 'dual' => t('Both user and average vote'),
341 ),
342 );
343
344 $form['fivestar']['direct']['fivestar_text'] = array(
345 '#type' => 'select',
346 '#title' => t('Text display style'),
347 '#default_value' => variable_get('fivestarextra_text_user', 'dual'),
348 '#options' => array(
349 'none' => t('Display no text beneath stars'),
350 'average' => t('Current average in text'),
351 'user' => t('User current vote in text'),
352 'smart' => t('User vote if available, average otherwise'),
353 'dual' => t('Both user and average vote'),
354 ),
355 );
356
357 $form['fivestar']['direct']['fivestar_title'] = array(
358 '#type' => 'checkbox',
359 '#title' => t('Show widget title'),
360 '#default_value' => variable_get('fivestarextra_title_user', 1),
361 '#return_value' => 1,
362 );
363
364 $form['fivestar']['direct']['fivestar_feedback'] = array(
365 '#type' => 'checkbox',
366 '#title' => t('Enable feedback during vote saving and deletion'),
367 '#default_value' => variable_get('fivestarextra_feedback_user', 1),
368 '#return_value' => 1
369 );
370
371 $form['fivestar']['direct']['fivestar_unvote'] = array(
372 '#type' => 'checkbox',
373 '#title' => t('Allow users to undo their votes'),
374 '#default_value' => variable_get('fivestarextra_unvote_user', 0),
375 '#return_value' => 1,
376 );
377
378 $weightoptions = array('hidden' => t('<Hidden>'));
379 foreach (range(-100,100) as $weight) {
380 $weightoptions[$weight] = $weight;
381 }
382
383 $form['fivestar']['direct']['fivestar_position'] = array(
384 '#type' => 'select',
385 '#title' => t('Weight'),
386 '#description' => t('Determines the position of the voting widget on the user page. Higher values are lower down.'),
387 '#default_value' => variable_get('fivestarextra_position_user', '100'),
388 '#options' => $weightoptions,
389 );
390
391 $form['fivestar']['direct']['fivestar_direct_preview'] = array(
392 '#type' => 'item',
393 '#title' => t('Direct rating widget preview'),
394 '#value' => theme(
395 'fivestar_preview',
396 $form['fivestar']['direct']['fivestar_style']['#default_value'],
397 $form['fivestar']['direct']['fivestar_text']['#default_value'],
398 $form['fivestar']['fivestar_stars']['#default_value'],
399 $form['fivestar']['direct']['fivestar_unvote']['#default_value'],
400 $form['fivestar']['direct']['fivestar_title']['#default_value'] ? NULL : FALSE,
401 $form['fivestar']['labels']['fivestar_labels_enable']['#default_value'],
402 variable_get('fivestarextra_labels_user', array())
403 ),
404 );
405 if (!$form['fivestar']['fivestar']['#default_value']) {
406 $form['fivestar']['direct']['fivestar_direct_preview']['#value'] = theme('fivestar_preview_wrapper', '');
407 }
408 else {
409 $form['fivestar']['direct']['fivestar_direct_preview']['#value'] = theme('fivestar_preview_wrapper', $form['fivestar']['direct']['fivestar_direct_preview']['#value']);
410 }
411
412 $form['submit'] = array(
413 '#type' => 'submit',
414 '#value' => t('Submit'),
415 '#weight' => 45,
416 );
417
418 $form['#submit'][] = 'fivestarextra_users_admin_form_submit';
419 return $form;
420 }
421
422
423 /**
424 * Admin settings form submit function. It simply saves the variables.
425 */
426 function fivestarextra_users_admin_form_submit($form, &$form_state) {
427
428 variable_set('fivestarextra_enable_user',$form_state['values']['fivestar']);
429
430 $variables = array('stars','labels_enable','style','text','title','unvote','feedback','position');
431 foreach ($variables as $variable) {
432 variable_set('fivestarextra_'.$variable .'_user',$form_state['values']['fivestar_'.$variable]);
433 }
434
435 // Merge labels into a single variable.
436 $labels = array();
437 for ($n = 0; $n <= 10; $n++) {
438 $labels[] = $form_state['values']['fivestar_label_'. $n];
439 variable_del('fivestarextra_label_'. $n .'_user');
440 }
441 variable_del('fivestar_labels_user');
442 if ($form_state['values']['fivestar_labels_enable']) {
443 variable_set('fivestarextra_labels_user', $labels);
444 }
445 };
446

  ViewVC Help
Powered by ViewVC 1.1.2