17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
19 if (!defined(
'SQ_COMMENT_HTML_ALLOW')) {
20 define (
'SQ_COMMENT_HTML_ALLOW', 0);
23 if (!defined(
'SQ_COMMENT_HTML_ESCAPE')) {
24 define (
'SQ_COMMENT_HTML_ESCAPE', 1);
27 if (!defined(
'SQ_COMMENT_HTML_STRIP')) {
28 define (
'SQ_COMMENT_HTML_STRIP', 2);
56 protected function _getName($short_name=FALSE, $contextid=NULL)
59 if ($contextid === NULL) {
60 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
64 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
65 if (empty($values) === TRUE) {
66 return strip_tags(parent::_getName($short_name, $contextid));
68 return strip_tags($values[$this->
id]);
83 return $this->
attr(
'name');
97 return $this->
attr(
'comment');
112 $length = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_MAX_LENGTH');
126 $length = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_MAX_RATING');
140 $rating = $this->
attr(
'rating');
141 if ($rating == -1)
return;
156 $rating = $this->
attr(
'rating');
157 if ($rating == -1)
return;
173 $rating_absolute = $this->
attr(
'rating');
175 if (empty($rating_scale))
return 0;
177 $rating = $rating_absolute/100 * $rating_scale;
207 if (empty($integer) || !is_numeric($integer) || $integer < 0) {
213 if (empty($rating_scale))
return 0;
215 if ($integer > $rating_scale)
return 100;
217 $percentage = $integer/$rating_scale * 100;
232 $rating_max = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_MAX_RATING');
247 $rating = $this->
attr(
'rating');
248 if ($rating == -1)
return;
252 $image_location_prefix = sq_web_path(
'data').
'/asset_types/comment/files';
254 $image_rated = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_IMG_RATED');
255 if (empty($image_rated)) {
256 $image_rated = $image_location_prefix.
'/star.png';
259 $image_blank = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_IMG_BLANK');
260 if (empty($image_blank)) {
261 $image_blank = $image_location_prefix.
'/star_grey.png';
266 for ($i = 0; $i < $max_rating; $i++) {
269 $image = $image_rated;
272 $image = $image_blank;
274 $html .=
'<img src="'.htmlspecialchars($image).
'" alt="'.$alt.
'" />';
290 $rating = $this->
attr(
'rating');
291 if ($rating == -1)
return;
293 return round($rating, 2);
306 $keywords = parent::getAvailableKeywords();
308 $keywords[
'comment_max_length'] = translate(
'news_comment_max_length');
309 $keywords[
'comment_max_rating'] =
'Max Rating Value';
310 $keywords[
'comment_rating'] =
'Rating Assigned to the comment (possibly a decimal)';
311 $keywords[
'comment_rating_integer'] =
'Rating Assigned to the comment as integer';
312 $keywords[
'comment_rating_percentage'] =
'Rating Assigned to the comment as percent';
313 $keywords[
'comment_rating_image_html_block'] =
'Rating Assigned to the comment in form of images';
330 if (in_array($name, Array(
'name',
'short_name',
'comment'))) {
332 }
else if (in_array($name, Array(
'name_raw',
'short_name_raw',
'comment_raw'))) {
333 return parent::attr(str_replace(
'_raw',
'', $name));
335 return parent::attr($name);
354 $caller = array_get_index(debug_backtrace(), 1);
355 if (array_get_index($caller,
'class') ==
'page_asset_builder') {
356 if (in_array($name, Array(
'name',
'short_name',
'comment'))) {
363 $length = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_MAX_LENGTH');
364 if (!empty($length) && (strlen($value) > $length)) {
365 $value = substr($value, 0, $length);
367 $value = trim($value);
371 $value = trim($value);
375 return parent::setAttrValue($name, $value);
390 $html_conf = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_HTML_CONF');
392 switch ($html_conf) {
393 case SQ_COMMENT_HTML_STRIP:
394 $value = nl2br(strip_tags($value));
397 case SQ_COMMENT_HTML_ESCAPE:
398 $value = nl2br(htmlspecialchars($value));
401 case SQ_COMMENT_HTML_ALLOW:
406 $disable_keyword_conf = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($this->
type(),
'SQ_COMMENT_DISABLE_KEYWORD_REPLACEMENTS');
408 if ($disable_keyword_conf) {
409 require_once SQ_FUDGE_PATH.
'/general/text.inc';
410 $keywords = extract_keywords($value);
412 foreach ($keywords as $keyword) {
413 $value = str_replace(
'%'.$keyword.
'%', $keyword, $value);