BxBaseCmts.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. /**
  10. * @see BxDolCmts
  11. */
  12. class BxBaseCmts extends BxDolCmts
  13. {
  14. protected $_sJsObjName;
  15. protected $_sStylePrefix;
  16. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  17. {
  18. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  19. if (empty($sSystem))
  20. return;
  21. $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
  22. $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
  23. BxDolTemplate::getInstance()->addJsTranslation('_sys_txt_cmt_loading');
  24. }
  25. /**
  26. * Add comments CSS/JS
  27. */
  28. public function addCssJs ()
  29. {
  30. $this->_oTemplate->addCss(array('cmts.css'));
  31. $this->_oTemplate->addJs(array('jquery.anim.js', 'jquery.form.min.js', 'BxDolCmts.js'));
  32. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  33. $oForm->addCssJs();
  34. }
  35. public function getJsObjectName()
  36. {
  37. return $this->_sJsObjName;
  38. }
  39. /**
  40. * Get initialization section of comments box
  41. *
  42. * @return string
  43. */
  44. public function getJsScript()
  45. {
  46. $aParams = array(
  47. 'sObjName' => $this->_sJsObjName,
  48. 'sRootUrl' => BX_DOL_URL_ROOT,
  49. 'sSystem' => $this->getSystemName(),
  50. 'iAuthorId' => $this->_getAuthorId(),
  51. 'iObjId' => $this->getId(),
  52. 'sBaseUrl' => $this->getBaseUrl(),
  53. 'sPostFormPosition' => $this->_aSystem['post_form_position'],
  54. 'sBrowseType' => $this->_sBrowseType,
  55. 'sDisplayType' => $this->_sDisplayType
  56. );
  57. $this->addCssJs();
  58. return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->_sJsObjName . " = new BxDolCmts(" . json_encode($aParams) . ");");
  59. }
  60. /**
  61. * get full comments block with initializations
  62. */
  63. function getCommentsBlock($iParentId = 0, $iVParentId = 0, $bInDesignbox = true)
  64. {
  65. $aBp = $aDp = array();
  66. $this->_getParams($aBp, $aDp);
  67. $aBp['parent_id'] = $iParentId;
  68. $aBp['vparent_id'] = $iVParentId;
  69. $aDp['show_empty'] = false;
  70. //add live update
  71. $this->actionResumeLiveUpdate();
  72. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_updates_comments', array($this->_sSystem, $this->_iId, $this->_getAuthorId(), '{count}'), 'TemplCmtsServices');
  73. BxDolLiveUpdates::getInstance()->add($this->_sSystem . '_live_updates_cmts_' . $this->_iId, 1, $sServiceCall);
  74. //add live update
  75. $sCaption = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll());
  76. $sContent = BxDolTemplate::getInstance()->parseHtmlByName('comments_block.html', array(
  77. 'system' => $this->_sSystem,
  78. 'list_anchor' => $this->getListAnchor(),
  79. 'id' => $this->getId(),
  80. 'comments' => $this->getComments($aBp, $aDp),
  81. 'post_form_top' => $this->getFormBoxPost($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP)),
  82. 'post_form_bottom' => $this->getFormBoxPost($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM)),
  83. 'view_image_popup' => $this->_getViewImagePopup(),
  84. 'script' => $this->getJsScript()
  85. ));
  86. return $bInDesignbox ? DesignBoxContent($sCaption, $sContent, BX_DB_DEF, $this->_getControlsBox()) : array(
  87. 'title' => $sCaption,
  88. 'content' => $sContent,
  89. 'menu' => $this->_getControlsBox(),
  90. );
  91. }
  92. /**
  93. * get comments list for specified parent comment
  94. *
  95. * @param array $aBp - browse params array
  96. * @param array $aDp - display params array
  97. *
  98. */
  99. function getComments($aBp = array(), $aDp = array())
  100. {
  101. $this->_prepareParams($aBp, $aDp);
  102. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp['per_view']);
  103. if(empty($aCmts) || !is_array($aCmts)) {
  104. if((int)$aBp['parent_id'] == 0 && !isLogged()) {
  105. $oPermalink = BxDolPermalinks::getInstance();
  106. return MsgBox(_t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account')));
  107. }
  108. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty() : '';
  109. }
  110. $sCmts = '';
  111. foreach($aCmts as $k => $aCmt)
  112. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  113. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  114. return $sCmts;
  115. }
  116. /**
  117. * get comment view block with initializations
  118. */
  119. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  120. {
  121. $sComment = $this->getComment(
  122. $iCmtId,
  123. array_merge(array('type' => $this->_sBrowseType), $aBp),
  124. array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp)
  125. );
  126. if (!$sComment)
  127. return '';
  128. return BxDolTemplate::getInstance()->parseHtmlByName('comment_block.html', array(
  129. 'system' => $this->_sSystem,
  130. 'id' => $this->getId(),
  131. 'comment' => $sComment,
  132. 'view_image_popup' => $this->_getViewImagePopup(),
  133. 'script' => $this->getJsScript()
  134. ));
  135. }
  136. /**
  137. * get one just posted comment
  138. *
  139. * @param int $iCmtId - comment id
  140. * @return string
  141. */
  142. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  143. {
  144. $iUserId = $this->_getAuthorId();
  145. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  146. if (!$aCmt)
  147. return '';
  148. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  149. $sClass = $sClassCnt = '';
  150. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  151. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  152. 'js_object' => $this->_sJsObjName,
  153. 'id' => $aCmt['cmt_id'],
  154. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  155. 'bx_if:show_replies' => array(
  156. 'condition' => $aCmt['cmt_replies'] > 0,
  157. 'content' => array(
  158. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  159. )
  160. )
  161. ));
  162. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  163. }
  164. if($aCmt['cmt_author_id'] == $iUserId)
  165. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  166. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  167. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  168. if(!empty($aDp['class_comment']))
  169. $sClass .= ' ' . $aDp['class_comment'];
  170. if(!empty($aDp['class_comment_content']))
  171. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  172. $sActions = $this->_getActionsBox($aCmt, $aDp);
  173. $aTmplReplyTo = array();
  174. if((int)$aCmt['cmt_parent_id'] != 0) {
  175. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  176. list($sParAuthorName, $sParAuthorLink, $sParAuthorIcon) = $this->_getAuthorInfo($aParent['cmt_author_id']);
  177. $aTmplReplyTo = array(
  178. 'style_prefix' => $this->_sStylePrefix,
  179. 'par_cmt_link' => $this->getBaseUrl() . '#' . $this->_sSystem . $aCmt['cmt_parent_id'],
  180. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to', $sParAuthorName)),
  181. 'par_cmt_author' => $sParAuthorName
  182. );
  183. }
  184. $aTmplImages = array();
  185. if($this->isAttachImageEnabled()) {
  186. $aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']);
  187. if(!empty($aImages) && is_array($aImages)) {
  188. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  189. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  190. foreach($aImages as $aImage)
  191. $aTmplImages[] = array(
  192. 'style_prefix' => $this->_sStylePrefix,
  193. 'js_object' => $this->_sJsObjName,
  194. 'image' => $oTranscoder->getFileUrl($aImage['image_id']),
  195. 'image_orig' => $oStorage->getFileUrlById($aImage['image_id'])
  196. );
  197. }
  198. }
  199. $sReplies = '';
  200. if((int)$aCmt['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED) {
  201. $aDp['show_empty'] = false;
  202. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  203. }
  204. $sAgo = bx_time_js($aCmt['cmt_time']);
  205. $bObjectTitle = !empty($this->_aSystem['trigger_field_title']);
  206. return $this->_oTemplate->parseHtmlByName('comment.html', array_merge(array(
  207. 'system' => $this->_sSystem,
  208. 'style_prefix' => $this->_sStylePrefix,
  209. 'js_object' => $this->_sJsObjName,
  210. 'id' => $aCmt['cmt_id'],
  211. 'class' => $sClass,
  212. 'class_cnt' => $sClassCnt,
  213. 'bx_if:show_reply_to' => array(
  214. 'condition' => !empty($aTmplReplyTo),
  215. 'content' => $aTmplReplyTo
  216. ),
  217. 'bx_if:show_ago_link' => array(
  218. 'condition' => $bObjectTitle,
  219. 'content' => array(
  220. 'style_prefix' => $this->_sStylePrefix,
  221. 'view_link' => $this->getViewUrl($aCmt['cmt_id']),
  222. 'ago' => $sAgo
  223. )
  224. ),
  225. 'bx_if:show_ago_text' => array(
  226. 'condition' => !$bObjectTitle,
  227. 'content' => array(
  228. 'ago' => $sAgo
  229. )
  230. ),
  231. 'bx_if:show_attached' => array(
  232. 'condition' => !empty($aTmplImages),
  233. 'content' => array(
  234. 'style_prefix' => $this->_sStylePrefix,
  235. 'bx_repeat:attached' => $aTmplImages
  236. )
  237. ),
  238. 'actions' => $sActions,
  239. 'replies' => $sReplies
  240. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsText($aCmt)));
  241. }
  242. /**
  243. * get one comment for "Live Search"
  244. *
  245. * @param int $iCmtId - comment id
  246. * @return string
  247. */
  248. function getCommentLiveSearch($mixedCmt, $aParams = array())
  249. {
  250. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  251. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  252. $bAuthorIcon = !empty($sAuthorIcon);
  253. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  254. return BxDolTemplate::getInstance()->parseHtmlByName('comment_live_search.html', array(
  255. 'bx_if:show_icon' => array(
  256. 'condition' => $bAuthorIcon,
  257. 'content' => array(
  258. 'author_icon' => $sAuthorIcon,
  259. 'view_link' => $sViewLink
  260. )
  261. ),
  262. 'bx_if:show_icon_empty' => array(
  263. 'condition' => !$bAuthorIcon,
  264. 'content' => array()
  265. ),
  266. 'view_link' => $sViewLink,
  267. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  268. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  269. ));
  270. }
  271. function getFormBoxPost($aBp = array(), $aDp = array())
  272. {
  273. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  274. }
  275. function getFormBoxEdit($aBp = array(), $aDp = array())
  276. {
  277. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  278. }
  279. function getFormPost($iCmtParentId = 0)
  280. {
  281. return $this->_getFormPost($iCmtParentId);
  282. }
  283. function getFormEdit($aCmt)
  284. {
  285. return $this->_getFormEdit($aCmt);
  286. }
  287. function getNotification($iCountOld = 0, $iCountNew = 0)
  288. {
  289. $iCount = (int)$iCountNew - (int)$iCountOld;
  290. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  291. if(empty($aComments) || !is_array($aComments))
  292. return '';
  293. $sJsObject = $this->getJsObjectName();
  294. $aComments = array_reverse($aComments);
  295. $iComments = count($aComments);
  296. $aTmplVarsNotifs = array();
  297. foreach($aComments as $iIndex => $aComment) {
  298. $iCommentId = $aComment['cmt_id'];
  299. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->_sSystem . $iCommentId . "', '" . $iCommentId . "');";
  300. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->_sSystem . $iCommentId . "', '" . $iCommentId . "');";
  301. $aTmplVarsNotifs[] = array_merge(array(
  302. 'style_prefix' => $this->_sStylePrefix,
  303. 'js_object' => $sJsObject,
  304. 'bx_if:show_as_hidden' => array(
  305. 'condition' => $iIndex < ($iComments - 1),
  306. 'content' => array(),
  307. ),
  308. 'show_onclick' => $sShowOnClick,
  309. 'reply_onclick' => $sReplyOnClick,
  310. 'bx_if:show_previous' => array(
  311. 'condition' => $iIndex > 0,
  312. 'content' => array(
  313. 'style_prefix' => $this->_sStylePrefix,
  314. 'js_object' => $sJsObject
  315. )
  316. )
  317. ), $this->_getTmplVarsAuthor($aComment), $this->_getTmplVarsText($aComment));
  318. }
  319. return BxDolTemplate::getInstance()->parseHtmlByName('comments_notification.html', array(
  320. 'html_id' => $this->getNotificationId(),
  321. 'style_prefix' => $this->_sStylePrefix,
  322. 'bx_repeat:notifs' => $aTmplVarsNotifs
  323. ));
  324. }
  325. /**
  326. * private functions
  327. */
  328. protected function _getControlsBox()
  329. {
  330. $sDisplay = '';
  331. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  332. if($bDisplay) {
  333. $aDisplayLinks = array(
  334. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  335. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  336. );
  337. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  338. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  339. $sDisplay = $oMenu->getCode();
  340. }
  341. $sBrowseType = '';
  342. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  343. if($bBrowseType) {
  344. $aBrowseLinks = array(
  345. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  346. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  347. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  348. );
  349. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  350. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  351. $sBrowseType = $oMenu->getCode();
  352. }
  353. $sBrowseFilter = '';
  354. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  355. if($bBrowseFilter) {
  356. $aFilterLinks = array(
  357. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  358. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  359. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  360. );
  361. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  362. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  363. $sBrowseFilter = $oMenu->getCode();
  364. }
  365. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  366. 'display_switcher' => $bDisplay ? $sDisplay : '',
  367. 'bx_if:is_divider_1' => array(
  368. 'condition' => $bDisplay && $bBrowseType,
  369. 'content' => array(
  370. 'style_prefix' => $this->_sStylePrefix,
  371. )
  372. ),
  373. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  374. 'bx_if:is_divider_2' => array(
  375. 'condition' => $bBrowseType && $bBrowseFilter,
  376. 'content' => array(
  377. 'style_prefix' => $this->_sStylePrefix,
  378. )
  379. ),
  380. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  381. ));
  382. }
  383. protected function _getActionsBox(&$aCmt, $aDp = array())
  384. {
  385. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  386. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  387. $bMenuManage = false;
  388. $sMenuActions = $sMenuManage = '';
  389. if(!$bViewOnly) {
  390. //--- Actions Menu
  391. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  392. $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
  393. $oMenuActions->setDynamicMode($bDynamicMode);
  394. $sMenuActions = $oMenuActions->getCode();
  395. /*
  396. TODO: Remove before commit.
  397. $oVote = $this->getVoteObject($aCmt['cmt_id']);
  398. if($oVote !== false)
  399. $sMenuActions .= $oVote->getJsScript();
  400. */
  401. //--- Manage Menu
  402. $oMenuManage = BxDolMenu::getObjectInstance($this->_sMenuObjManage);
  403. $oMenuManage->setCmtsData($this, $aCmt['cmt_id']);
  404. $sMenuManage = $oMenuManage->getCode();
  405. $bMenuManage = !empty($sMenuManage);
  406. if($bMenuManage) {
  407. $sMenuManage = $this->_oTemplate->parseHtmlByName('comment_manage.html', array(
  408. 'style_prefix' => $this->_sStylePrefix,
  409. 'content' => $sMenuManage
  410. ));
  411. $sMenuManage = BxTemplFunctions::getInstance()->transBox($this->_sSystem . '-manage-' . $aCmt['cmt_id'], $sMenuManage, true);
  412. }
  413. }
  414. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  415. 'id' => $aCmt['cmt_id'],
  416. 'js_object' => $this->_sJsObjName,
  417. 'style_prefix' => $this->_sStylePrefix,
  418. 'menu_actions' => $sMenuActions,
  419. /*
  420. 'bx_if:hide_rate_count' => array(
  421. 'condition' => (int)$aCmt['cmt_rate'] <= 0,
  422. 'content' => array()
  423. ),
  424. 'points' => _t(in_array($aCmt['cmt_rate'], array(-1, 0, 1)) ? '_N_point' : '_N_points', $aCmt['cmt_rate']),
  425. */
  426. 'bx_if:show_menu_manage' => array(
  427. 'condition' => $bMenuManage,
  428. 'content' => array(
  429. 'js_object' => $this->_sJsObjName,
  430. 'style_prefix' => $this->_sStylePrefix,
  431. 'id' => $aCmt['cmt_id'],
  432. 'popup_text' => $sMenuManage
  433. )
  434. )
  435. ));
  436. }
  437. protected function _getFormBox($sType, $aBp, $aDp)
  438. {
  439. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  440. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  441. if(!$this->isPostReplyAllowed())
  442. return '';
  443. $sPositionSystem = $this->_aSystem['post_form_position'];
  444. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  445. return '';
  446. $sMethod = '_getForm' . ucfirst($sType);
  447. $aForm = $this->$sMethod($iCmtParentId);
  448. return BxDolTemplate::getInstance()->parseHtmlByName('comment_reply_box.html', array(
  449. 'js_object' => $this->_sJsObjName,
  450. 'style_prefix' => $this->_sStylePrefix,
  451. 'bx_if:show_class' => array(
  452. 'condition' => !empty($sPosition),
  453. 'content' => array(
  454. 'class' => $this->_sStylePrefix . '-reply-' . $sPosition
  455. )
  456. ),
  457. 'form' => $aForm['form'],
  458. 'form_id' => $aForm['form_id'],
  459. ));
  460. }
  461. protected function _getFormPost($iCmtParentId = 0)
  462. {
  463. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  464. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  465. $oForm->initChecker();
  466. if($oForm->isSubmittedAndValid()) {
  467. $iCmtObjectId = (int)$this->getId();
  468. $iCmtObjectAuthorId = $this->getObjectAuthorId($iCmtObjectId);
  469. $iCmtAuthorId = $this->_getAuthorId();
  470. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  471. $sCmtText = $oForm->getCleanValue('cmt_text');
  472. $sCmtText = $this->_prepareTextForSave ($sCmtText);
  473. $oForm->setSubmittedValue('cmt_text', $sCmtText, $oForm->aFormAttrs['method']);
  474. $iLevel = 0;
  475. $iCmtVisualParentId = 0;
  476. if((int)$iCmtParentId > 0) {
  477. $aParent = $this->getCommentRow($iCmtParentId);
  478. $iLevel = (int)$aParent['cmt_level'] + 1;
  479. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  480. }
  481. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  482. if($iCmtId != 0) {
  483. if($this->isAttachImageEnabled()) {
  484. $aImages = $oForm->getCleanValue('cmt_image');
  485. if(!empty($aImages) && is_array($aImages)) {
  486. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  487. foreach($aImages as $iImageId)
  488. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  489. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  490. }
  491. }
  492. if($iCmtParentId) {
  493. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  494. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  495. }
  496. $this->_triggerComment();
  497. $this->isPostReplyAllowed(true);
  498. if ($this->_sMetatagsObj) {
  499. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  500. $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  501. }
  502. $oZ = new BxDolAlerts($this->_sSystem, 'commentPost', $iCmtObjectId, $iCmtAuthorId, array('comment_id' => $iCmtId, 'comment_text' => $sCmtText, 'comment_author_id' => $iCmtAuthorId, 'object_author_id' => $iCmtObjectAuthorId));
  503. $oZ->alert();
  504. $oZ = new BxDolAlerts('comment', 'added', $iCmtId, $iCmtAuthorId, array('object_system' => $this->_sSystem, 'object_id' => $iCmtObjectId, 'object_author_id' => $iCmtObjectAuthorId, 'comment_text' => $sCmtText));
  505. $oZ->alert();
  506. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  507. }
  508. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  509. }
  510. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  511. }
  512. protected function _getFormEdit($iCmtId)
  513. {
  514. $iCmtObjectId = (int)$this->getId();
  515. $iCmtObjectAuthorId = $this->getObjectAuthorId($iCmtObjectId);
  516. $aCmt = $this->_oQuery->getCommentSimple ($iCmtObjectId, $iCmtId);
  517. if(!$aCmt)
  518. return array('msg' => _t('_No such comment'));
  519. $iCmtAuthorId = $this->_getAuthorId();
  520. if(!$this->isEditAllowed($aCmt))
  521. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  522. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  523. $aCmt['cmt_text'] = $this->_prepareTextForEdit($aCmt['cmt_text']);
  524. $oForm->initChecker($aCmt);
  525. if($oForm->isSubmittedAndValid()) {
  526. $sCmtText = $oForm->getCleanValue('cmt_text');
  527. $sCmtText = $this->_prepareTextForSave ($sCmtText);
  528. $oForm->setSubmittedValue('cmt_text', $sCmtText, $oForm->aFormAttrs['method']);
  529. if($oForm->update($iCmtId)) {
  530. $this->isEditAllowed(true);
  531. if ($this->_sMetatagsObj) {
  532. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  533. $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  534. }
  535. $oZ = new BxDolAlerts($this->_sSystem, 'commentUpdated', $iCmtObjectId, $iCmtAuthorId, array('comment_id' => $aCmt['cmt_id'], 'comment_author_id' => $aCmt['cmt_author_id'], 'object_author_id' => $iCmtObjectAuthorId));
  536. $oZ->alert();
  537. $oZ = new BxDolAlerts('comment', 'edited', $iCmtId, $iCmtAuthorId, array('object_system' => $this->_sSystem, 'object_id' => $iCmtObjectId, 'object_author_id' => $iCmtObjectAuthorId));
  538. $oZ->alert();
  539. return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($sCmtText, $iCmtId));
  540. }
  541. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  542. }
  543. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  544. }
  545. protected function _getForm($sAction, $iId)
  546. {
  547. $oForm = $this->_getFormObject($sAction);
  548. $oForm->setId(sprintf($oForm->aFormAttrs['id'], $sAction, $this->_sSystem, $iId));
  549. $oForm->setName(sprintf($oForm->aFormAttrs['name'], $sAction, $this->_sSystem, $iId));
  550. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  551. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  552. $oForm->aInputs['id']['value'] = $this->_iId;
  553. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  554. if(!$this->isAttachImageEnabled())
  555. unset($oForm->aInputs['cmt_image']);
  556. if(isset($oForm->aInputs['cmt_text'])) {
  557. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  558. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  559. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  560. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  561. }
  562. return $oForm;
  563. }
  564. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  565. {
  566. $iStart = $iPerView = 0;
  567. switch($aBp['type']) {
  568. case BX_CMT_BROWSE_HEAD:
  569. case BX_CMT_BROWSE_POPULAR:
  570. case BX_CMT_BROWSE_CONNECTION:
  571. $iPerView = $aBp['per_view'];
  572. $iStart = $aBp['start'] + $iPerView;
  573. if($iStart >= $aBp['count'])
  574. return $sCmts;
  575. break;
  576. case BX_CMT_BROWSE_TAIL:
  577. $iPerView = $aBp['per_view'];
  578. $iStart = $aBp['start'] - $iPerView;
  579. if($iStart < 0) {
  580. $iPerView += $iStart;
  581. $iStart = 0;
  582. }
  583. if($iStart == 0 && $iPerView == 0)
  584. return $sCmts;
  585. break;
  586. }
  587. $bRoot = (int)$aBp['vparent_id'] <= 0;
  588. $sMore = BxDolTemplate::getInstance()->parseHtmlByName('comment_more.html', array(
  589. 'js_object' => $this->_sJsObjName,
  590. 'style_prefix' => $this->_sStylePrefix,
  591. 'bx_if:is_root' => array(
  592. 'condition' => $bRoot,
  593. 'content' => array()
  594. ),
  595. 'parent_id' => $aBp['vparent_id'],
  596. 'start' => $iStart,
  597. 'per_view' => $iPerView,
  598. 'title' => _t('_cmt_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  599. ));
  600. switch($aBp['type']) {
  601. case BX_CMT_BROWSE_HEAD:
  602. case BX_CMT_BROWSE_POPULAR:
  603. case BX_CMT_BROWSE_CONNECTION:
  604. $sCmts .= $sMore;
  605. break;
  606. case BX_CMT_BROWSE_TAIL:
  607. $sCmts = $sMore . $sCmts;
  608. break;
  609. }
  610. return $sCmts;
  611. }
  612. protected function _getEmpty()
  613. {
  614. return BxDolTemplate::getInstance()->parseHtmlByName('comment_empty.html', array(
  615. 'style_prefix' => $this->_sStylePrefix
  616. ));
  617. }
  618. protected function _getViewImagePopup()
  619. {
  620. $sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
  621. $sViewImagePopupContent = BxDolTemplate::getInstance()->parseHtmlByName('popup_image.html', array(
  622. 'image_url' => ''
  623. ));
  624. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  625. }
  626. protected function _getTmplVarsAuthor($aCmt)
  627. {
  628. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  629. $bAuthorIcon = !empty($sAuthorIcon);
  630. return array(
  631. 'bx_if:show_icon' => array(
  632. 'condition' => $bAuthorIcon,
  633. 'content' => array(
  634. 'author_icon' => $sAuthorIcon
  635. )
  636. ),
  637. 'bx_if:show_icon_empty' => array(
  638. 'condition' => !$bAuthorIcon,
  639. 'content' => array()
  640. ),
  641. 'bx_if:show_author_link' => array(
  642. 'condition' => !empty($sAuthorLink),
  643. 'content' => array(
  644. 'author_link' => $sAuthorLink,
  645. 'author_title' => bx_html_attribute($sAuthorName),
  646. 'author_name' => $sAuthorName
  647. )
  648. ),
  649. 'bx_if:show_author_text' => array(
  650. 'condition' => empty($sAuthorLink),
  651. 'content' => array(
  652. 'author_name' => $sAuthorName
  653. )
  654. ),
  655. );
  656. }
  657. protected function _getTmplVarsText($aCmt)
  658. {
  659. $sText = $aCmt['cmt_text'];
  660. $sTextMore = '';
  661. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  662. if(strlen($sText) > $iMaxLength) {
  663. $iLength = strpos($sText, ' ', $iMaxLength);
  664. $sTextMore = trim(substr($sText, $iLength));
  665. $sText = trim(substr($sText, 0, $iLength));
  666. }
  667. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  668. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  669. return array(
  670. 'text' => $sText,
  671. 'bx_if:show_more' => array(
  672. 'condition' => !empty($sTextMore),
  673. 'content' => array(
  674. 'style_prefix' => $this->_sStylePrefix,
  675. 'js_object' => $this->_sJsObjName,
  676. 'text_more' => $sTextMore
  677. )
  678. ),
  679. );
  680. }
  681. }
  682. /** @} */