BxBaseCmts.php 30 KB

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