Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
comment_prefs.inc
1 <?php
17 require_once SQ_LIB_PATH.'/config/prefs.inc';
18 require_once SQ_ATTRIBUTES_PATH.'/css_dimension/css_dimension.inc';
19 require_once SQ_ATTRIBUTES_PATH.'/int/int.inc';
20 require_once SQ_ATTRIBUTES_PATH.'/boolean/boolean.inc';
21 require_once SQ_ATTRIBUTES_PATH.'/url/url.inc';
22 
23 
24 if (!defined('SQ_COMMENT_HTML_ALLOW')) {
25  define ('SQ_COMMENT_HTML_ALLOW', 0);
26 }
27 
28 if (!defined('SQ_COMMENT_HTML_ESCAPE')) {
29  define ('SQ_COMMENT_HTML_ESCAPE', 1);
30 }
31 
32 if (!defined('SQ_COMMENT_HTML_STRIP')) {
33  define ('SQ_COMMENT_HTML_STRIP', 2);
34 }
35 
36 
48 class Comment_Prefs extends Prefs
49 {
50 
51 
58  var $pref_vars = Array(
59  'SQ_COMMENT_INPUT_SIZE' => Array(
60  'name' => 'comment_pref_input_size',
61  'description' => 'This preference allows you to change the size of the Comment Input Box',
62  'default' => Array(
63  'width' => '300px',
64  'height' => '100px',
65  ),
66  'protected' => FALSE,
67  ),
68  'SQ_COMMENT_MAX_LENGTH' => Array(
69  'name' => 'comment_pref_max_length',
70  'description' => 'This preferences allows you to set the maximum number of characters that can be entered in the Comment Input Box',
71  'default' => 0,
72  'protected' => FALSE,
73  ),
74  'SQ_COMMENT_HTML_CONF' => Array(
75  'name' => 'comment_pref_html_conf_label',
76  'description' => 'Determines whether HTML is allowed, escaped or removed',
77  'default' => SQ_COMMENT_HTML_ESCAPE,
78  'protected' => FALSE,
79  ),
80  'SQ_COMMENT_MAX_RATING' => Array(
81  'name' => 'maximum_rating',
82  'description' => 'This preference sets the upper bound for ratings',
83  'default' => 5,
84  'protected' => FALSE,
85  ),
86  'SQ_COMMENT_IMG_RATED' => Array(
87  'name' => 'rated_image',
88  'description' => 'Rated Image to be used instead of the default',
89  'default' => NULL,
90  'protected' => FALSE,
91  ),
92  'SQ_COMMENT_IMG_BLANK' => Array(
93  'name' => 'blank_image',
94  'description' => 'Blank Image to be used instead of the default',
95  'default' => NULL,
96  'protected' => FALSE,
97  ),
98  'SQ_COMMENT_DISABLE_KEYWORD_REPLACEMENTS' => Array(
99  'name' => 'comment_disable_keyword_replacements',
100  'description' => 'Whether to replace the keywords in the comment',
101  'default' => 1,
102  'protected' => FALSE,
103  ),
104  );
105 
112  var $css_dimension_width;
113 
114 
121  var $css_dimension_height;
122 
123 
130  var $int_max_length;
131 
132 
139  var $int_max_rating;
140 
141 
148  var $url_processor;
149 
150 
151  var $html_conf_options = Array();
152 
153 
158  function Comment_Prefs($pref_file='')
159  {
160  $this->Prefs($pref_file);
161 
162  // we'll use these attributes to print the inputs for SQ_COMMENT_INPUT_SIZE
163  $this->css_dimension_width = new Asset_Attribute_CSS_Dimension();
164  $this->css_dimension_height = new Asset_Attribute_CSS_Dimension();
165 
166  // attribute for input of SQ_COMMENT_MAX_LENGTH
167  $this->int_max_length = new Asset_Attribute_Int();
168  $this->int_max_length->setParam('allow_negative', FALSE);
169 
170  // attribute for input of SQ_COMMENT_MAX_RATING
171  $this->int_max_rating = new Asset_Attribute_Int();
172  $this->int_max_rating->setParam('allow_negative', FALSE);
173  $this->int_max_rating->setParam('allow_empty', FALSE);
174 
175  $this->url_processor = new Asset_Attribute_Url();
176  $this->url_processor->_edit_params['protocols'] = Array('http','https');
177  $this->url_processor->_edit_params['width'] = '60';
178 
179  $this->disable_keyword_replacements = Array(
180  0 => "No",
181  1 => "Yes",
182  );
183 
184  $this->html_conf_options = Array(
185  SQ_COMMENT_HTML_ALLOW => translate('allow'),
186  SQ_COMMENT_HTML_ESCAPE => translate('escape'),
187  SQ_COMMENT_HTML_STRIP => translate('strip'),
188  );
189 
190  }//end constructor
191 
192 
203  function paintBackend(&$o, $have_lock, $pref=NULL)
204  {
205  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
206  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
207  $print_sub_title = TRUE;
208  if (!is_null($pref)) $print_sub_title = FALSE;
209 
210  $prefs = array_keys($this->pref_vars);
211  if (!is_null($pref) && in_array($pref, array_keys($this->pref_vars))) {
212  $prefs = Array($pref);
213  }
214 
215  foreach ($prefs as $pref_value) {
216  $fn = 'paint'.str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($pref_value)))).'Backend';
217  if (!method_exists($this, $fn)) continue;
218 
219  // call individual paint function for each pref
220  if (is_null($pref) || $pref == $pref_value) {
221  $this->$fn($o, $have_lock, $pref_value, $print_sub_title, $is_root, $is_admin);
222  }
223  }
224 
225  }//end paintBackend()
226 
227 
241  function paintSqCommentInputSizeBackend(&$o, $have_lock, $pref_name, $print_sub_title, $is_root, $is_admin)
242  {
243  if ($print_sub_title) {
244  $o->openField(translate($this->pref_vars['SQ_COMMENT_INPUT_SIZE']['name']));
245  } else {
246  $o->openField('&nbsp;');
247  }
248 
249  $comment_size = $this->pref_vars['SQ_COMMENT_INPUT_SIZE']['default'];
250 
251  ?><table class="sq-backend-table" style="width: 350px;">
252  <tr>
253  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('width') ?></td>
254  <td class="sq-backend-table-cell" style="width: 100%;">
255  <?php
256  if ($have_lock && $is_admin) {
257  $this->css_dimension_width->paint($pref_name.'_width', $have_lock, $comment_size['width']);
258  } else {
259  echo $comment_size['width'];
260  }
261  ?>
262  </td>
263  </tr>
264  <tr>
265  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('height') ?></td>
266  <td class="sq-backend-table-cell" style="width: 100%;">
267  <?php
268  if ($have_lock && $is_admin) {
269  $this->css_dimension_height->paint($pref_name.'_height', $have_lock, $comment_size['height']);
270  } else {
271  echo $comment_size['height'];
272  }
273  ?>
274  </td>
275  </tr>
276  </table><?php
277 
278  $o->closeField();
279 
280  }//end paintSqCommentInputSizeBackend()
281 
282 
296  function paintSqCommentMaxLengthBackend(&$o, $have_lock, $pref_name, $print_sub_title, $is_root, $is_admin)
297  {
298  if ($print_sub_title) {
299  $o->openField(translate($this->pref_vars['SQ_COMMENT_MAX_LENGTH']['name']));
300  } else {
301  $o->openField('&nbsp;');
302  }
303 
304  $comment_length = $this->pref_vars['SQ_COMMENT_MAX_LENGTH']['default'];
305 
306  if ($have_lock && $is_admin) {
307  $this->int_max_length->value = $comment_length;
308  $this->int_max_length->paint($pref_name.'_max_length', !$have_lock);
309  } else {
310  echo $comment_length;
311  }
312  $o->note(translate('comment_pref_max_length_note'));
313 
314  $o->closeField();
315 
316  }//end paintSqCommentMaxLengthBackend()
317 
318 
332  function paintSqCommentHtmlConfBackend(&$o, $have_lock, $pref_name, $print_sub_title, $is_root, $is_admin)
333  {
334  if ($print_sub_title) {
335  $o->openField(translate($this->pref_vars[$pref_name]['name']));
336  } else {
337  $o->openField('&nbsp;');
338  }
339 
340  $current_conf = $this->pref_vars[$pref_name]['default'];
341 
342  $readonly = !($have_lock && $is_admin);
343 
344  if ($readonly) {
345  echo array_get_index($this->html_conf_options, $current_conf);
346  } else {
347  combo_box($pref_name, $this->html_conf_options, FALSE, $current_conf);
348  }
349 
350  $o->closeField();
351 
352  }//end paintSqCommentHtmlConfBackend()
353 
354 
368  function paintSqCommentDisableKeywordReplacementsBackend(&$o, $have_lock, $pref_name, $print_sub_title, $is_root, $is_admin)
369  {
370  if ($print_sub_title) {
371  $o->openField(translate($this->pref_vars[$pref_name]['name']));
372  } else {
373  $o->openField('&nbsp;');
374  }
375 
376  $current_conf = $this->pref_vars[$pref_name]['default'];
377 
378  $readonly = !($have_lock && $is_admin);
379 
380  if ($readonly) {
381  echo array_get_index($this->disable_keyword_replacements, $current_conf);
382  } else {
383  combo_box($pref_name, $this->disable_keyword_replacements, FALSE, $current_conf);
384  }
385 
386  $o->closeField();
387 
388  }//end paintSqCommentDisableKeywordReplacementBackend()
389 
390 
404  function paintSqCommentMaxRatingBackend(&$o, $have_lock, $pref_name, $print_sub_title, $is_root, $is_admin)
405  {
406  if ($print_sub_title) {
407  $o->openField(translate($this->pref_vars[$pref_name]['name']));
408  } else {
409  $o->openField('&nbsp;');
410  }
411 
412  $max_rating = $this->pref_vars[$pref_name]['default'];
413 
414  $readonly = !($have_lock && $is_admin);
415 
416  $this->int_max_rating->value = $max_rating;
417  $this->int_max_rating->paint($pref_name, $readonly);
418 
419  $o->closeField();
420 
421  }//end paintSqCommentMaxRatingBackend()
422 
423 
434  function processBackend(&$o, $have_lock, $pref=NULL)
435  {
436  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
437  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
438  if (!$is_admin || !$have_lock) {
439  return FALSE;
440  }
441 
442  $prefs = array_keys($this->pref_vars);
443  if (!is_null($pref) && in_array($pref, array_keys($this->pref_vars))) {
444  $prefs = Array($pref);
445  }
446 
447  $res = TRUE;
448 
449  foreach ($prefs as $pref) {
450  $fn = 'process'.str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($pref)))).'Backend';
451  if (!method_exists($this, $fn)) continue;
452 
453  // call individual process function for each pref
454  if (!$this->$fn($o, $have_lock, $pref, $is_root, $is_admin)) {
455  $res = FALSE;
456  }
457  }
458  return $res;
459 
460  }//end processBackend()
461 
462 
475  function processSqCommentInputSizeBackend(&$o, $have_lock, $pref, $is_root, $is_admin)
476  {
477 
478  if (isset($_POST[$pref.'_width']) && isset($_POST[$pref.'_height'])) {
479  // process css attributes
480  $this->css_dimension_width->process($pref.'_width');
481  $this->css_dimension_height->process($pref.'_height');
482 
483  $this->pref_vars['SQ_COMMENT_INPUT_SIZE']['default']['width'] = $this->css_dimension_width->getContent();
484  $this->pref_vars['SQ_COMMENT_INPUT_SIZE']['default']['height'] = $this->css_dimension_height->getContent();
485 
486  return TRUE;
487  }
488  return FALSE;
489 
490  }//end processSqCommentInputSizeBackend()
491 
492 
505  function processSqCommentMaxLengthBackend(&$o, $have_lock, $pref, $is_root, $is_admin)
506  {
507  if (isset($_POST[$pref.'_max_length'])) {
508 
509  $this->int_max_length->process($pref.'_max_length');
510  $this->pref_vars['SQ_COMMENT_MAX_LENGTH']['default'] = $this->int_max_length->value;
511 
512  return TRUE;
513  }
514  return FALSE;
515 
516  }//end processSqCommentMaxLengthBackend()
517 
518 
531  function processSqCommentHtmlConfBackend(&$o, $have_lock, $pref, $is_root, $is_admin)
532  {
533  $new_setting = array_get_index($_POST, $pref);
534 
535  if (!is_null($new_setting)) {
536  $this->pref_vars[$pref]['default'] = $new_setting;
537 
538  return TRUE;
539  }
540  return FALSE;
541 
542  }//end processSqCommentHtmlConfBackend()
543 
544 
557  function processSqCommentDisableKeywordReplacementsBackend(&$o, $have_lock, $pref, $is_root, $is_admin)
558  {
559  $new_setting = array_get_index($_POST, $pref);
560 
561  if (!is_null($new_setting)) {
562  $this->pref_vars[$pref]['default'] = $new_setting;
563 
564  return TRUE;
565  }
566  return FALSE;
567 
568  }//end processSqCommentDisableKeywordReplacementBackend()
569 
570 
583  function processSqCommentMaxRatingBackend(&$o, $have_lock, $pref, $is_root, $is_admin)
584  {
585  $this->int_max_rating->process($pref);
586  if (!$this->int_max_rating->processed) return FALSE;
587 
588  $this->pref_vars[$pref]['default'] = $this->int_max_rating->value;
589 
590  return TRUE;
591 
592  }//end processSqCommentMaxRatingBackend()
593 
594 
608  function paintSqCommentImgRatedBackend(&$o, $have_lock, $pref_name, $print_sub_title, $is_root, $is_admin)
609  {
610  if ($print_sub_title) {
611  $o->openField(translate($this->pref_vars[$pref_name]['name']));
612  } else {
613  $o->openField('&nbsp;');
614  }
615 
616  $current_setting = $this->pref_vars[$pref_name]['default'];
617 
618  $read_only = !($have_lock && $is_admin);
619 
620  $image_location_prefix = sq_web_path('data').'/asset_types/comment/files';
621 
622  if (empty($current_setting)) {
623  $current_image = sq_web_path('data').'/asset_types/comment/files/star.png';
624  } else {
625  $current_image = $current_setting;
626  }
627 
628  echo 'Current Image: <img src="'.htmlspecialchars($current_image).'" />';
629  echo '<br />';
630 
631  $url = $this->url_processor;
632  $url->value = $current_setting;
633  $url->paint($pref_name, $read_only);
634 
635 
636  if (!$read_only) {
637  $o->note($this->pref_vars[$pref_name]['description']);
638  $o->note('Empty means default');
639  }
640 
641  $o->closeField();
642 
643  }//end paintSqCommentImgRatedBackend()
644 
645 
658  function processSqCommentImgRatedBackend(&$o, $have_lock, $pref, $is_root, $is_admin)
659  {
660  $url = $this->url_processor;
661 
662  $url->process($pref);
663  $new_setting = $url->value;
664 
665  $this->pref_vars[$pref]['default'] = $new_setting;
666 
667  return TRUE;
668 
669  }//end processSqCommentImgRatedBackend()
670 
671 
685  function paintSqCommentImgBlankBackend(&$o, $have_lock, $pref_name, $print_sub_title, $is_root, $is_admin)
686  {
687  if ($print_sub_title) {
688  $o->openField(translate($this->pref_vars[$pref_name]['name']));
689  } else {
690  $o->openField('&nbsp;');
691  }
692 
693  $current_setting = $this->pref_vars[$pref_name]['default'];
694 
695  $read_only = !($have_lock && $is_admin);
696 
697  $image_location_prefix = sq_web_path('data').'/asset_types/comment/files';
698 
699  if (empty($current_setting)) {
700  $current_image = sq_web_path('data').'/asset_types/comment/files/star_grey.png';
701  } else {
702  $current_image = $current_setting;
703  }
704 
705  echo 'Current Image: <img src="'.htmlspecialchars($current_image).'" />';
706  echo '<br />';
707 
708  $url = $this->url_processor;
709  $url->value = $current_setting;
710  $url->paint($pref_name, $read_only);
711 
712  if (!$read_only) {
713  $o->note($this->pref_vars[$pref_name]['description']);
714  $o->note('Empty means default');
715  }
716 
717  $o->closeField();
718 
719  }//end paintSqCommentImgBlankBackend()
720 
721 
734  function processSqCommentImgBlankBackend(&$o, $have_lock, $pref, $is_root, $is_admin)
735  {
736  $url = $this->url_processor;
737 
738  $url->process($pref);
739  $new_setting = $url->value;
740 
741  $this->pref_vars[$pref]['default'] = $new_setting;
742 
743  return TRUE;
744 
745  }//end processSqCommentImgBlankBackend()
746 
747 
748 }//end class
749 
750 ?>