_sJsObjName = 'oCmts' . ucfirst($sSystem) . $iId;
$this->_oPaginate = new BxTemplPaginate(array(
'page_url' => 'javascript:void(0);',
'start' => 0,
//'count' => $this->_oQuery->getObjectCommentsCount($this->getId(), 0),
'per_page' => $this->getPerView(),
'sorting' => $this->_sOrder,
'per_page_step' => 2,
'per_page_interval' => 3,
'on_change_page' => $this->_sJsObjName . '.changePage({start}, {per_page})',
'on_change_per_page' => $this->_sJsObjName . '.changePerPage(this)',
'on_change_sorting' => $this->_sJsObjName . '.changeOrder(this)'
));
$this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
BxDolTemplate::getInstance()->addJsTranslation('_sys_txt_cmt_loading');
}
/**
* get full comments block with initializations
*/
function getCommentsFirst () {
$sRet = '
';
$sRet .= '
' . $this->_getBrowse() . '
';
$sRet .= '
' . $this->getComments (0, $this->_sOrder) . '
';
if(($sPaginate = $this->getPaginate()) !== "")
$sRet .= '
' . $sPaginate . '
';
if($this->isPostReplyAllowed ())
$sRet .= '
' . $this->_getPostReplyBox() . "
";
$sRet .= '
';
$sRet .= $this->getCmtsInit ();
return $sRet;
}
/**
* get comments list for specified parent comment
*
* @param int $iCmtsParentId - parent comment to get child comments from
*/
function getComments ($iCmtsParentId = 0, $sCmtOrder = 'asc', $iStart = 0, $iPerPage = -1) {
if ($iCmtsParentId == 0 && $iPerPage == -1)
$iPerPage = $this->getPerView();
$sRet = '';
$aCmts = $this->getCommentsArray ($iCmtsParentId, $sCmtOrder, $iStart, $iPerPage);
if (!$aCmts) {
$sRet .= '- ' . _t('_There are no comments yet') . '
';
} else {
$i = 0;
for ( reset($aCmts) ; list ($k, $r) = each ($aCmts) ; ++$i) {
$sClass = '';
if ($r['cmt_rated'] == -1 || $r['cmt_rate'] < $this->_aSystem['viewing_threshold']) {
$sRet .= '- ';
$sRet .= bx_process_output(_t('_hidden_comment', $r['cmt_author_name'])) . ' ' . ($r['cmt_replies'] > 0 ? _t('_Show N replies', $r['cmt_replies']) . '. ' : '') . '' . _t('_show_replacement') . '.';
if ($this->isRatable())
$sRet .= $this->_getRateBox($r);
$sRet .= '
';
$sClass = ' cmt-hidden';
}
$isOwnComment = $r['cmt_author_id'] == $this->_getAuthorId();
if ($isOwnComment)
$sClass .= ' cmt-mine';
$sRet .= '- ';
$sRet .= '
';
$sRet .= $this->_getAuthorIcon($r);
$sRet .= '
';
$sRet .= $this->_getCommentHeadBox($r);
$sRet .= '';
$sRet .= $this->_getCommentBodyBox ($r);
$sRet .= '
';
$sRet .= $this->_getActionsBox ($r, false);
$sRet .= '';
$sRet .= '
';
$sRet .= '
' . ($r['cmt_replies'] ? $this->_getRepliesBox($r) : ' ') . '
';
if ($this->isPostReplyAllowed())
$sRet .= $this->_getPostReplyBoxTo($r);
$sRet .= '
';
if ($this->isRatable())
$sRet .= $this->_getRateBox($r);
$sRet .= '
';
}
}
$sRet .= '
';
return $sRet;
}
/**
* get one just posted comment
*
* @param int $iCmtId - comment id
* @return string
*/
function getComment($iCmtId, $sType = 'new')
{
$r = $this->getCommentRow ($iCmtId);
$sRet = '';
if($r['cmt_rated'] == -1 || $r['cmt_rate'] < $this->_aSystem['viewing_threshold']) {
$sRet .= '';
$sRet .= bx_process_output(_t('_hidden_comment', $r['cmt_author_name'])) . ' ' . ($r['cmt_replies'] > 0 ? _t('_Show N replies', $r['cmt_replies']) . '. ' : '') . '' . _t('_show_replacement') . '.';
if($this->isRatable())
$sRet .= $this->_getRateBox($r);
$sRet .= '';
$sClass = ' cmt-hidden';
}
$sRet .= '';
$sRet .= '';
if ($this->isRatable())
$sRet .= $this->_getRateBox($r);
$sRet .= $this->_getAuthorIcon($r);
$sRet .= '
';
$sRet .= $this->_getCommentHeadBox($r);
$sRet .= '';
$sRet .= $this->_getCommentBodyBox ($r);
$sRet .= '
';
if ($sType == 'new' && ($r['cmt_author_id'] == $this->_getAuthorId() || $this->isEditAllowedAll() || $this->isRemoveAllowedAll()))
$sRet .= $this->_getActionsBox ($r, true);
$sRet .= '';
$sRet .= '
';
$sRet .= '
' . ($r['cmt_replies'] ? $this->_getRepliesBox($r) : '') . '
';
if($sType != 'new' && $this->isPostReplyAllowed())
$sRet .= $this->_getPostReplyBoxTo($r);
$sRet .= '
';
return $sRet;
}
function getPaginate($iStart = -1, $iPerPage = -1) {
return $this->_oPaginate->getPaginate($iStart, $iPerPage);
}
function getForm($sType, $iParentId) {
return $this->_getPostReplyBox($sType, $iParentId);
}
function getActions($iCmtId, $sType = 'reply') {
$aParams = array(
'cmt_id' => $iCmtId,
'cmt_replies' => $this->_oQuery->getObjectCommentsCount($this->getId(), 0),
'cmt_type' => $sType
);
$sRet = "";
$sRet .= '' . ($aParams['cmt_replies'] ? $this->_getRepliesBox($aParams) : ' ') . '
';
if($this->isPostReplyAllowed())
$sRet .= $this->_getPostReplyBoxTo($aParams);
$sRet .= '
';
return $sRet;
}
/**
* Get comments css file string
*
* @return string
*/
function getExtraCss ()
{
BxDolTemplate::getInstance()->addCss('cmts.css');
}
/**
* Get comments js file string
*
* @return string
*/
function getExtraJs () {
BxDolTemplate::getInstance()->addJs('BxDolCmts.js');
}
/**
* Get initialization section of comments box
*
* @return string
*/
function getCmtsInit() {
$sToggleAdd = '';
$sUseHtmlAdd = '';
$ret = '';
if($this->iGlobAllowHtml == 1 && $this->iGlobUseTinyMCE == 1 && ($this->isEditAllowed() || $this->isEditAllowedAll())) {
bx_import('BxTemplConfig');
$ret .= BxTemplConfig::getInstance()->sTinyMceEditorMicroJS;
}
$ret .= $sToggleAdd . "
";
$this->getExtraJs();
$this->getExtraCss();
return $ret;
}
/**
* private functions
*/
function _getCommentHeadBox (&$a) {
if ($a['cmt_author_id'] && $a['cmt_author_name'])
$sAuthor = '' . bx_process_output($a['cmt_author_name']) . '';
else
$sAuthor = _t('_Anonymous');
$sRet = '| | ' . bx_process_output($sAuthor) . ' ' . _t('_wrote') . ' ' . $a['cmt_ago'] . ' (' . _t($this->_aMoodText[$a['cmt_mood']]) . ') | |
';
return $sRet;
}
function _getCommentBodyBox(&$a) {
return '
|
' . bx_process_output($a['cmt_mood']) . '
' . bx_process_output($a['cmt_text'], BX_DATA_TEXT_MULTILINE) . '
|
| ';
}
function _getRateBox(&$a)
{
$sClass = '';
if ($a['cmt_rated'] || $a['cmt_rate'] < $this->_aSystem['viewing_threshold'])
$sClass = ' cmt-rate-disabled';
return '
'._t( (1 == $a['cmt_rate'] || -1 == $a['cmt_rate']) ? '_N point' : '_N points', $a['cmt_rate']).'
';
}
function _getActionsBox (&$a, $isJustPosted) {
$n = $this->getAllowedEditTime();
$isEditAllowedPermanently = ($a['cmt_author_id'] == $this->_getAuthorId() && $this->isEditAllowed()) || $this->isEditAllowedAll();
$isRemoveAllowedPermanently = ($a['cmt_author_id'] == $this->_getAuthorId() && $this->isRemoveAllowed()) || $this->isRemoveAllowedAll();
if (!($n && $isJustPosted) && !$isEditAllowedPermanently && !$isRemoveAllowedPermanently)
return '';
$sRet = '| | ';
if (($isEditAllowedPermanently || ($isJustPosted && $n)) && strpos($a['cmt_text'], 'video_comments') === false)
$sRet .= ' ';
if ($isRemoveAllowedPermanently || ($isJustPosted && $n))
$sRet .= '';
if ($isJustPosted && $n && !$isEditAllowedPermanently)
$sRet .= _t('_available_for_n_seconds', $n);
$sRet .= ' | |
';
return $sRet;
}
function _getRepliesBox (&$a) {
$sContentShow = _t((isset($a['cmt_type']) && $a['cmt_type'] == 'comment' ? '_Show N comments' : '_Show N replies'), $a['cmt_replies']);
$sContentHide = _t((isset($a['cmt_type']) && $a['cmt_type'] == 'comment' ? '_Hide N comments' : '_Hide N replies'), $a['cmt_replies']);
return '' . $sContentShow . '' . $sContentHide . '';
}
function _getPostReplyBoxTo (&$a) {
$sContent = _t(isset($a['cmt_type']) && $a['cmt_type'] == 'comment' ? '_Comment to this comment' : '_Reply to this comment');
return '';
}
function _getPostReplyBox($sType = 'comment', $iCmtParentId = 0) {
if ($sType == 'comment')
$sSwitcher = '' . _t('_Add Your Comment') . '' . _t('_Record Your Comment') . '';
else if ($sType == 'reply')
$sSwitcher = '' . _t('_Reply as text') . '' . _t('_Reply as video') . '';
return '
' . $this->_getAuthorIcon(array('cmt_author_id' => $this->_getAuthorId())) . '
| |
' . $sSwitcher . ' |
|
| |
' . $this->_getFormBox($iCmtParentId) . ' |
|
';
}
function _getFormBox($iCmtParentId = 0, $sText = "", $sFunction = "submitComment(this)") {
$sTinyStyle = ($this->iGlobAllowHtml == 1 && $this->iGlobUseTinyMCE == 1) ? ' tinypossible="true" ' : '';
if ($this->_aSystem['is_mood'])
$sMood = '
';
return '
';
}
function _getAuthorIcon ($a) {
global $oFunctions;
if (!$a['cmt_author_id'] || !getProfileInfo($a['cmt_author_id'])) {
if (!@include_once (BX_DIRECTORY_PATH_MODULES . 'boonex/avatar/include.php'))
return '';
return '';
} else {
return $oFunctions->getMemberIcon($a['cmt_author_id']);
}
}
function _getBrowse() {
return "TODO: cmts browse";
/*
$sRet = '
' . $this->_oPaginate->getSorting(array('asc' => '_oldest first', 'desc' => '_newest first')) . '
' . $this->_oPaginate->getPages() . '
';
return $sRet;
*/
}
}