BxBaseCmts.php 31 KB

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