BxBaseCmts.php 33 KB

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