BxBaseCmts.php 31 KB

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