8 require_once( CH_DIRECTORY_PATH_CLASSES .
'ChWsbCmtsQuery.php' );
10 define(
'CH_OLD_CMT_VOTES', 365*86400);
111 '-1' =>
'_sys_txt_cmt_mood_negative',
112 '0' =>
'_sys_txt_cmt_mood_neutral',
113 '1' =>
'_sys_txt_cmt_mood_positive',
123 $this->_aCmtElements = array (
124 'CmtParent' => array (
'reg' =>
'^[0-9]+$',
'msg' => str_replace(
'"',
'\\"', trim(
_t(
'_bad comment parent id'))) ),
125 'CmtText' => array (
'reg' =>
'^.{3,2048}$',
'msg' => str_replace(
'"',
'\\"', trim(
_t(
'_Please enter 3-2048 characters'))) ),
126 'CmtMood' => array (
'reg' =>
'^-?[0-9]?$',
'msg' => str_replace(
'"',
'\\"', trim(
_t(
'_You need to select the mood'))) ),
131 $this->_sSystem = $sSystem;
132 if (isset($this->_aSystems[$sSystem]))
133 $this->_aSystem = $this->_aSystems[$sSystem];
142 $this->iGlobAllowHtml = (
getParam(
"enable_tiny_in_comments") ==
"on") ? 1 : 0;
144 $this->bDynamic = isset($_SERVER[
'HTTP_X_REQUESTED_WITH']) && $_SERVER[
'HTTP_X_REQUESTED_WITH'] ==
'XMLHttpRequest';
161 $sClassName =
'ChTemplCmtsView';
163 require_once (CH_DIRECTORY_PATH_ROOT .
$aSystems[
$sSys][
'class_file']);
167 $oCmts =
new $sClassName(
$sSys,
$iId, $iInit);
173 if (!isset(
$GLOBALS[
'ch_dol_cmts_systems'])) {
174 $GLOBALS[
'ch_dol_cmts_systems'] =
$GLOBALS[
'MySQL']->fromCache(
'sys_objects_cmts',
'getAllWithKey',
'
177 `ObjectName` AS `name`,
178 `TableCmts` AS `table_cmts`,
179 `TableTrack` AS `table_track`,
180 `AllowTags` AS `allow_tags`,
182 `SecToEdit` AS `sec_to_edit`,
183 `PerView` AS `per_view`,
184 `IsRatable` AS `is_ratable`,
185 `ViewingThreshold` AS `viewing_threshold`,
186 `AnimationEffect` AS `animation_effect`,
187 `AnimationSpeed` AS `animation_speed`,
189 `IsMood` AS `is_mood`,
190 `RootStylePrefix` AS `root_style_prefix`,
191 `TriggerTable` AS `trigger_table`,
192 `TriggerFieldId` AS `trigger_field_id`,
193 `TriggerFieldComments` AS `trigger_field_comments`,
194 `ClassName` AS `class_name`,
195 `ClassFile` AS `class_file`
196 FROM `sys_objects_cmts`',
'name');
199 return $GLOBALS[
'ch_dol_cmts_systems'];
235 return isset($this->_aSystem[
'is_on']) && $this->_aSystem[
'is_on'];
264 return isset($this->_aSystems[$sSystem]);
269 return $this->_aSystem[
'allow_tags'];
274 return $this->_aSystem[
'nl2br'];
279 return $this->_aSystem[
'is_ratable'];
284 return $this->_aSystem[
'sec_to_edit'];
289 return $this->_aSystem[
'per_view'];
294 return $this->_aSystem[
'system_id'];
302 $iDeletedRecords = 0;
303 foreach ($this->_aSystems
as $aSystem) {
304 if (!$aSystem[
'is_on'])
307 $iDeletedRecords += $oQuery->maintenance();
310 return $iDeletedRecords;
318 return $this->_oQuery->getComments ($this->
getId(), $iCmtParentId, $this->
_getAuthorId(), $sCmtOrder, $iStart, $iCount);
323 return $this->_oQuery->getComment ($this->
getId(), $iCmtId, $this->
_getAuthorId());
328 return $this->_oQuery->deleteObjectComments ($iObjectId ? $iObjectId : $this->
getId());
335 foreach ($this->_aSystems
as $sSystem => $aSystem) {
337 $oQuery->deleteAuthorComments ($iAuthorId);
344 return $this->_oQuery->getTableName ();
349 return $this->_oQuery->getObjectCommentsCount ($iObjectId ? $iObjectId : $this->
getId());
423 return $this->getPaginate($iCmtStart, $iCmtPerPage);
434 return $this->getForm($sCmtType, $iCmtParentId);
442 $iCmtParentId = (int)
$_REQUEST[
'CmtParent'];
447 return $this->getComments($iCmtParentId, $sCmtOrder, $iCmtStart, $iCmtPerPage);
456 return $this->getComment ($iCmtId, (isset(
$_REQUEST[
'Type']) ?
$_REQUEST[
'Type'] :
'new'));
467 $iCmtObjectId = (int)$this->
getId();
468 $iCmtParentId = (int)
$_REQUEST[
'CmtParent'];
472 return sprintf(
_t(
"_sys_spam_detected"), CH_WSB_URL_ROOT .
'contact.php');
478 $iCmtNewId = $this->_oQuery->addComment ($iCmtObjectId, $iCmtParentId, $iCmtAuthorId, $sText, $iMood);
480 if(
false === $iCmtNewId)
488 $oZ =
new ChWsbAlerts($this->_sSystem,
'commentPost', $iCmtObjectId, $iCmtAuthorId, array(
'comment_id' => $iCmtNewId,
'comment_author_id' => $iCmtAuthorId));
491 $oZ =
new ChWsbAlerts(
'comment',
'add', $iCmtNewId, $iCmtAuthorId, array(
'object_system' => $this->_sSystem,
'object_id' => $iCmtObjectId));
505 $iObjectId = (int)$this->
getId();
508 $aCmt = $this->_oQuery->getCommentSimple ($iObjectId, $iCmtId);
510 return _t(
'_No such comment');
512 if($aCmt[
'cmt_replies'] > 0)
513 return _t(
'_Can not delete comments with replies');
519 if (!$this->_oQuery->removeComment ($iObjectId, $aCmt[
'cmt_id'], $aCmt[
'cmt_parent_id']))
520 return _t(
'_Database Error');
524 if ($aCmt[
'cmt_author_id'] == $iAuthorId)
528 $oZ =
new ChWsbAlerts($this->_sSystem,
'commentRemoved', $iObjectId, $iAuthorId, array(
'comment_id' => $aCmt[
'cmt_id'],
'comment_author_id' => $aCmt[
'cmt_author_id']));
531 $oZ =
new ChWsbAlerts(
'comment',
'delete', $aCmt[
'cmt_id'], $iAuthorId, array(
'object_system' => $this->_sSystem,
'object_id' => $iObjectId));
544 $aCmt = $this->_oQuery->getCommentSimple ($this->
getId(), $iCmtId);
547 return 'err'._t(
'_No such comment');
553 return $this->_getFormBox (
'edit', array(
'id' => $iCmtId,
'parent_id' => $aCmt[
'cmt_parent_id'],
'text' => $aCmt[
'cmt_text']));
563 return json_encode(array(
'err' => sprintf(
_t(
"_sys_spam_detected"), CH_WSB_URL_ROOT .
'contact.php')));
565 $iObjectId = $this->
getId();
569 $sTextRet = stripslashes($sText);
573 $aCmt = $this->_oQuery->getCommentSimple ($iObjectId, $iCmtId);
582 if (($sTextRet != $aCmt[
'cmt_text'] || $iCmtMood != $aCmt[
'cmt_mood']) && $this->_oQuery->updateComment ($iObjectId, $aCmt[
'cmt_id'], $sText, $iCmtMood)) {
583 if ($aCmt[
'cmt_author_id'] == $iAuthorId)
587 $oZ =
new ChWsbAlerts($this->_sSystem,
'commentUpdated', $iObjectId, $iAuthorId, array(
'comment_id' => $aCmt[
'cmt_id'],
'comment_author_id' => $aCmt[
'cmt_author_id']));
590 $oZ =
new ChWsbAlerts(
'comment',
'change', $aCmt[
'cmt_id'], $iAuthorId, array(
'object_system' => $this->_sSystem,
'object_id' => $iObjectId));
594 $aCmt = $this->_oQuery->getCommentSimple($iObjectId, $iCmtId);
596 return json_encode(array(
'text' => $aCmt[
'cmt_text'],
'mood' => $aCmt[
'cmt_mood'],
'mood_text' =>
_t($this->_aMoodText[$aCmt[
'cmt_mood']])));
601 if (!$this->
isEnabled())
return _t(
'_Error occured');
602 if (!$this->
isRatable())
return _t(
'_Error occured');
613 return _t(
'_Error occured');
615 if(!$this->_oQuery->rateComment($this->getSystemId(), $iCmtId, $iRate, $this->_getAuthorId(), $this->_getAuthorIp()))
616 return _t(
'_Duplicate vote');
618 $aCmt = $this->_oQuery->getCommentSimple ($this->
getId(), $iCmtId);
623 $oZ =
new ChWsbAlerts($this->_sSystem,
'commentRated', $this->
getId(), $this->
_getAuthorId(), array(
'comment_id' => $iCmtId,
'comment_author_id' => $aCmt[
'cmt_author_id'],
'rate' => $iRate));
634 return isMember() ? (int)$_COOKIE[
'memberID'] : 0;
639 return isMember() ? $_COOKIE[
'memberPassword'] :
"";
650 return str_replace(array(
'<br />',
'­'),
'',
$s);
659 elseif (!$this->iGlobAllowHtml && $this->
isNl2br()) {
677 if (!$this->_aSystem[
'trigger_table'])
682 $iCount = $this->_oQuery->getObjectCommentsCount (
$iId);
683 return $this->_oQuery->updateTriggerTable(
$iId, $iCount);
693 $aReplacement = array(
698 return str_replace(array_keys($aReplacement), array_values($aReplacement), $this->_sSystem .
'-' . $this->
getId() .
'-' .
$iId);