BxBaseCmts.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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 static $_sTmplContentElementBlock;
  15. protected static $_sTmplContentElementInline;
  16. protected static $_sTmplContentDoCommentLabel;
  17. protected static $_sTmplContentCounter;
  18. protected $_sTmplNameItem;
  19. protected $_sTmplNameItemContent;
  20. protected $_sJsObjClass;
  21. protected $_sJsObjName;
  22. protected $_sStylePrefix;
  23. protected $_aHtmlIds;
  24. protected $_aElementDefaults;
  25. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  26. {
  27. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  28. if (empty($sSystem))
  29. return;
  30. $this->_sTmplNameItem = 'comment.html';
  31. $this->_sTmplNameItemContent = 'comment_content.html';
  32. $this->_sJsObjClass = 'BxDolCmts';
  33. $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
  34. $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
  35. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  36. $this->_aHtmlIds = array(
  37. 'main' => 'bx-cmt-' . $sHtmlId,
  38. 'counter' => 'bx-cmt-counter-' . $sHtmlId
  39. );
  40. $this->_aElementDefaults = array(
  41. 'show_do_comment_as_button' => false,
  42. 'show_do_comment_as_button_small' => false,
  43. 'show_do_comment_image' => false,
  44. 'show_do_comment_icon' => true,
  45. 'show_do_comment_label' => false,
  46. 'show_counter' => true,
  47. 'show_counter_empty' => false
  48. );
  49. if(empty(self::$_sTmplContentElementBlock))
  50. self::$_sTmplContentElementBlock = $this->_oTemplate->getHtml('comment_element_block.html');
  51. if(empty(self::$_sTmplContentElementInline))
  52. self::$_sTmplContentElementInline = $this->_oTemplate->getHtml('comment_element_inline.html');
  53. if(empty(self::$_sTmplContentDoCommentLabel))
  54. self::$_sTmplContentDoCommentLabel = $this->_oTemplate->getHtml('comment_do_comment_label.html');
  55. if(empty(self::$_sTmplContentCounter))
  56. self::$_sTmplContentCounter = $this->_oTemplate->getHtml('comment_counter.html');
  57. $this->_oTemplate->addJsTranslation('_sys_txt_cmt_loading');
  58. }
  59. /**
  60. * Add comments CSS/JS
  61. */
  62. public function addCssJs ()
  63. {
  64. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  65. $oForm->addCssJs();
  66. }
  67. public function getJsObjectName()
  68. {
  69. return $this->_sJsObjName;
  70. }
  71. /**
  72. * Get initialization section of comments box
  73. *
  74. * @return string
  75. */
  76. public function getJsScript($aBp = array(), $aDp = array())
  77. {
  78. $bMinPostForm = isset($aDp['min_post_form']) ? $aDp['min_post_form'] : $this->_bMinPostForm;
  79. $aParams = array(
  80. 'sObjName' => $this->_sJsObjName,
  81. 'sRootUrl' => BX_DOL_URL_ROOT,
  82. 'sSystem' => $this->getSystemName(),
  83. 'iAuthorId' => $this->_getAuthorId(),
  84. 'iObjId' => $this->getId(),
  85. 'sBaseUrl' => $this->getBaseUrl(),
  86. 'sPostFormPosition' => $this->_aSystem['post_form_position'],
  87. 'sBrowseType' => $this->_sBrowseType,
  88. 'sDisplayType' => $this->_sDisplayType,
  89. 'iDisplayStructure' => isset($aDp['structure']) && !empty($aDp['structure']) ? 1 : 0,
  90. 'iMinPostForm' => $bMinPostForm ? 1 : 0,
  91. 'sStylePrefix' => $this->_sStylePrefix,
  92. );
  93. $this->addCssJs();
  94. return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
  95. }
  96. /**
  97. * get full comments block with initializations
  98. */
  99. function getCommentsBlock($aBp = array(), $aDp = array())
  100. {
  101. $mixedResult = $this->isViewAllowed();
  102. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  103. return $mixedResult;
  104. $this->_getParams($aBp, $aDp);
  105. //add live update
  106. $this->actionResumeLiveUpdate();
  107. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_update', array($this->_sSystem, $this->_iId, $this->_getAuthorId(), '{count}'), 'TemplCmtsServices');
  108. BxDolLiveUpdates::getInstance()->add($this->_sSystem . '_live_updates_cmts_' . $this->_iId, 1, $sServiceCall);
  109. //add live update
  110. $sCaption = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll());
  111. $sContent = $this->_oTemplate->parseHtmlByName('comments_block.html', array(
  112. 'system' => $this->_sSystem,
  113. 'list_anchor' => $this->getListAnchor(),
  114. 'id' => $this->getId(),
  115. 'comments' => $this->getComments($aBp, $aDp),
  116. 'post_form_top' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP))),
  117. 'post_form_bottom' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM))),
  118. 'view_image_popup' => $this->_getViewImagePopup(),
  119. 'script' => $this->getJsScript($aBp, $aDp)
  120. ));
  121. return $aDp['in_designbox'] ? DesignBoxContent($sCaption, $sContent, BX_DB_DEF, $this->_getControlsBox()) : array(
  122. 'title' => $sCaption,
  123. 'content' => $sContent,
  124. 'menu' => $this->_getControlsBox(),
  125. );
  126. }
  127. /**
  128. * get comments list for specified parent comment
  129. *
  130. * @param array $aBp - browse params array
  131. * @param array $aDp - display params array
  132. *
  133. */
  134. function getComments($aBp = array(), $aDp = array())
  135. {
  136. $this->_prepareParams($aBp, $aDp);
  137. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp['per_view']);
  138. if(empty($aCmts) || !is_array($aCmts)) {
  139. if((int)$aBp['parent_id'] == 0 && !isLogged()) {
  140. $oPermalink = BxDolPermalinks::getInstance();
  141. return MsgBox(_t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account')));
  142. }
  143. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  144. }
  145. $sCmts = '';
  146. foreach($aCmts as $k => $aCmt)
  147. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  148. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  149. return $sCmts;
  150. }
  151. public function getCommentsByStructure($aBp = array(), $aDp = array())
  152. {
  153. if(empty($aDp['structure']))
  154. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  155. $aBp['count'] = count($aDp['structure']);
  156. $this->_prepareParams($aBp, $aDp);
  157. $aDp['structure'] = array_slice($aDp['structure'], $aBp['start'], $aBp['per_view'], true);
  158. $sCmts = '';
  159. foreach($aDp['structure'] as $iCmtId => $aCmt)
  160. $sCmts .= $this->getComment($iCmtId, $aBp, $aDp);
  161. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  162. return $sCmts;
  163. }
  164. /**
  165. * get comment view block with initializations
  166. */
  167. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  168. {
  169. $mixedResult = $this->isViewAllowed();
  170. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  171. return $mixedResult;
  172. $aBp = array_merge(array('type' => $this->_sBrowseType), $aBp);
  173. $aDp = array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp);
  174. //--- Beg: Using pregenerated structure
  175. $mixedStructure = $this->getCommentStructure((int)$iCmtId, $aBp, $aDp);
  176. if($mixedStructure !== false)
  177. $aDp['structure'] = $mixedStructure;
  178. //--- End: Using pregenerated structure
  179. $sComment = $this->getComment($iCmtId, $aBp, $aDp);
  180. if (!$sComment)
  181. return '';
  182. return $this->_oTemplate->parseHtmlByName('comment_block.html', array(
  183. 'system' => $this->_sSystem,
  184. 'id' => $this->getId(),
  185. 'comment' => $sComment,
  186. 'view_image_popup' => $this->_getViewImagePopup(),
  187. 'script' => $this->getJsScript($aBp, $aDp)
  188. ));
  189. }
  190. /**
  191. * get one just posted comment
  192. *
  193. * @param int $iCmtId - comment id
  194. * @return string
  195. */
  196. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  197. {
  198. $iUserId = $this->_getAuthorId();
  199. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  200. if (!$aCmt)
  201. return '';
  202. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  203. $sClass = $sClassCnt = '';
  204. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  205. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  206. 'js_object' => $this->_sJsObjName,
  207. 'id' => $aCmt['cmt_id'],
  208. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  209. 'bx_if:show_replies' => array(
  210. 'condition' => $aCmt['cmt_replies'] > 0,
  211. 'content' => array(
  212. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  213. )
  214. )
  215. ));
  216. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  217. }
  218. if($aCmt['cmt_author_id'] == $iUserId)
  219. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  220. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  221. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  222. if(!empty($aDp['class_comment']))
  223. $sClass .= ' ' . $aDp['class_comment'];
  224. if(!empty($aDp['class_comment_content']))
  225. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  226. $sActions = $this->_getActionsBox($aCmt, $aDp);
  227. $aTmplReplyTo = array();
  228. if((int)$aCmt['cmt_parent_id'] != 0) {
  229. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  230. $oProfile = $this->_getAuthorObject($aParent['cmt_author_id']);
  231. $sParAuthorName = $oProfile->getDisplayName();
  232. $sParAuthorUnit = $oProfile->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')));
  233. $aTmplReplyTo = array(
  234. 'style_prefix' => $this->_sStylePrefix,
  235. 'par_cmt_link' => $this->getItemUrl($aCmt['cmt_parent_id']),
  236. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to_x', $sParAuthorName)),
  237. 'par_cmt_author' => $sParAuthorName,
  238. 'par_cmt_author_unit' => $sParAuthorUnit
  239. );
  240. }
  241. $sReplies = '';
  242. if(!empty($aDp)) {
  243. $aDp['show_empty'] = false;
  244. if(!empty($aDp['structure'][$aCmt['cmt_id']]) && is_array($aDp['structure'][$aCmt['cmt_id']])) {
  245. if(!empty($aDp['structure'][$aCmt['cmt_id']]['items'])) {
  246. $aDp['structure'] = $aDp['structure'][$aCmt['cmt_id']]['items'];
  247. $sReplies = $this->getCommentsByStructure(array('parent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  248. }
  249. }
  250. else if((int)$aCmt['cmt_replies'] > 0 && $aDp['type'] == BX_CMT_DISPLAY_THREADED)
  251. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  252. }
  253. $aTmplVarsMeta = array();
  254. if(!empty($this->_sMenuObjMeta)) {
  255. $oMenuMeta = BxDolMenu::getObjectInstance($this->_sMenuObjMeta, $this->_oTemplate);
  256. if($oMenuMeta) {
  257. $oMenuMeta->setCmtsData($this, $aCmt['cmt_id']);
  258. $aTmplVarsMeta = array(
  259. 'style_prefix' => $this->_sStylePrefix,
  260. 'meta' => $oMenuMeta->getCode()
  261. );
  262. }
  263. }
  264. $sContent = $this->_getContent($aCmt);
  265. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameItem, array_merge(array(
  266. 'system' => $this->_sSystem,
  267. 'style_prefix' => $this->_sStylePrefix,
  268. 'js_object' => $this->_sJsObjName,
  269. 'id' => $aCmt['cmt_id'],
  270. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  271. 'class' => $sClass,
  272. 'class_cnt' => $sClassCnt,
  273. 'bx_if:show_reply_to' => array(
  274. 'condition' => !empty($aTmplReplyTo),
  275. 'content' => $aTmplReplyTo
  276. ),
  277. 'bx_if:meta' => array(
  278. 'condition' => !empty($aTmplVarsMeta),
  279. 'content' => $aTmplVarsMeta
  280. ),
  281. 'content' => $sContent,
  282. 'actions' => $sActions,
  283. 'replies' => $sReplies,
  284. ), $this->_getTmplVarsAuthor($aCmt)));
  285. }
  286. public function getCommentStructure($iCmtId, $aBp = array(), $aDp = array())
  287. {
  288. $aRoot = $this->getCommentRow((int)$iCmtId);
  289. $aBps = $aBp;
  290. if(!empty($aRoot))
  291. $aBps['parent_id'] = $aRoot['cmt_id'];
  292. $this->_prepareStructureBp($aDp['type'], $aBps);
  293. $iLevel = 0;
  294. $aStructure = array();
  295. $this->_getStructure($aRoot, $aBps, $iLevel, $aStructure);
  296. return !empty($aStructure) && is_array($aStructure) ? $aStructure : false;
  297. }
  298. function getCommentSearch($iCmtId, &$sAddon)
  299. {
  300. $aBp = array();
  301. $aDp = array(
  302. 'type' => BX_CMT_DISPLAY_FLAT,
  303. 'view_only' => true
  304. );
  305. if(empty($sAddon))
  306. $sAddon = $this->getJsScript($aBp, $aDp);
  307. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  308. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  309. 'view_image_popup' => $this->_getViewImagePopup(),
  310. ));
  311. }
  312. /**
  313. * get one comment for "Live Search"
  314. *
  315. * @param int $iCmtId - comment id
  316. * @return string
  317. */
  318. function getCommentLiveSearch($mixedCmt, $aParams = array())
  319. {
  320. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  321. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  322. $bAuthorIcon = !empty($sAuthorIcon);
  323. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  324. if(empty($sViewLink))
  325. $sViewLink = '#';
  326. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  327. 'bx_if:show_icon' => array(
  328. 'condition' => $bAuthorIcon,
  329. 'content' => array(
  330. 'author_icon' => $sAuthorIcon,
  331. 'view_link' => $sViewLink
  332. )
  333. ),
  334. 'bx_if:show_icon_empty' => array(
  335. 'condition' => !$bAuthorIcon,
  336. 'content' => array()
  337. ),
  338. 'view_link' => $sViewLink,
  339. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  340. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  341. ));
  342. }
  343. function getFormBoxPost($aBp = array(), $aDp = array())
  344. {
  345. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  346. }
  347. function getFormBoxEdit($aBp = array(), $aDp = array())
  348. {
  349. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  350. }
  351. function getFormPost($iCmtParentId = 0, $aDp = array())
  352. {
  353. return $this->_getFormPost($iCmtParentId, $aDp);
  354. }
  355. function getFormEdit($iCmtId, $aDp = array())
  356. {
  357. return $this->_getFormEdit($iCmtId, $aDp);
  358. }
  359. function getLiveUpdate($iCountOld = 0, $iCountNew = 0)
  360. {
  361. $iCount = (int)$iCountNew - (int)$iCountOld;
  362. if($iCount < 0)
  363. return '';
  364. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  365. if(empty($aComments) || !is_array($aComments))
  366. return '';
  367. $aComment = array_shift($aComments);
  368. if(empty($aComment) || !is_array($aComment))
  369. return '';
  370. $sJsObject = $this->getJsObjectName();
  371. return $this->_oTemplate->parseHtmlByName('comments_lu_button.html', array(
  372. 'style_prefix' => $this->_sStylePrefix,
  373. 'html_id' => $this->getNotificationId(),
  374. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, '" . $this->getItemAnchor($aComment['cmt_id']) . "', '" . $aComment['cmt_id'] . "');",
  375. ));
  376. }
  377. function getLiveUpdates($iCountOld = 0, $iCountNew = 0)
  378. {
  379. $bShowAll = true;
  380. $bShowActions = false;
  381. $iCount = (int)$iCountNew - (int)$iCountOld;
  382. if($iCount < 0)
  383. return '';
  384. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  385. if(empty($aComments) || !is_array($aComments))
  386. return '';
  387. $sJsObject = $this->getJsObjectName();
  388. $iUserId = $this->_getAuthorId();
  389. $bModerator = $this->isModerator();
  390. $aComments = array_reverse($aComments);
  391. $iComments = count($aComments);
  392. $aTmplVarsNotifs = array();
  393. foreach($aComments as $iIndex => $aComment) {
  394. $iCommentId = $aComment['cmt_id'];
  395. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  396. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  397. $iAuthorId = (int)$aComment['cmt_author_id'];
  398. if($iAuthorId < 0) {
  399. if(abs($iAuthorId) == $iUserId)
  400. continue;
  401. else if($bModerator)
  402. $iAuthorId *= -1;
  403. }
  404. $oAuthor = $this->_getAuthorObject($iAuthorId);
  405. $sAuthorName = $oAuthor->getDisplayName();
  406. $aTmplVarsNotifs[] = array(
  407. 'bx_if:show_as_hidden' => array(
  408. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  409. 'content' => array(),
  410. ),
  411. 'item' => $this->_oTemplate->parseHtmlByName('comments_lu_notifications.html', array(
  412. 'style_prefix' => $this->_sStylePrefix,
  413. 'onclick_show' => $sShowOnClick,
  414. 'onclick_reply' => $sReplyOnClick,
  415. 'author_link' => $oAuthor->getUrl(),
  416. 'author_title' => bx_html_attribute($sAuthorName),
  417. 'author_name' => $sAuthorName,
  418. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  419. 'text' => _t('_cmt_txt_added_sample')
  420. )),
  421. 'bx_if:show_previous' => array(
  422. 'condition' => $bShowActions && $iIndex > 0,
  423. 'content' => array(
  424. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  425. )
  426. ),
  427. 'bx_if:show_close' => array(
  428. 'condition' => $bShowActions,
  429. 'content' => array(
  430. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  431. )
  432. )
  433. );
  434. }
  435. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  436. 'html_id' => $this->getNotificationId(),
  437. 'bx_repeat:items' => $aTmplVarsNotifs
  438. ));
  439. }
  440. public function getElementBlock($aParams = array())
  441. {
  442. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  443. return $this->getElement($aParams);
  444. }
  445. public function getElementInline($aParams = array())
  446. {
  447. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  448. return $this->getElement($aParams);
  449. }
  450. public function getElement($aParams = array())
  451. {
  452. $aParams = array_merge($this->_aElementDefaults, $aParams);
  453. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  454. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  455. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  456. $iObjectId = $this->getId();
  457. $iAuthorId = $this->_getAuthorId();
  458. $iAuthorIp = $this->_getAuthorIp();
  459. $iCount = $this->getCommentsCountAll();
  460. $bCount = (int)$iCount != 0;
  461. $isAllowedComment = $this->isPostAllowed();
  462. //--- Do Comment
  463. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  464. $aTmplVarsDoComment = array();
  465. if($bTmplVarsDoComment) {
  466. $sClass = '';
  467. if($bShowDoCommentAsButton)
  468. $sClass = 'bx-btn';
  469. else if ($bShowDoCommentAsButtonSmall)
  470. $sClass = 'bx-btn bx-btn-small';
  471. if(!$isAllowedComment)
  472. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  473. $aTmplVarsDoComment = array(
  474. 'style_prefix' => $this->_sStylePrefix,
  475. 'do_comment' => $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), array(
  476. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  477. 'title' => _t($this->_getTitleDo())
  478. )),
  479. );
  480. }
  481. //--- Counter
  482. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  483. $aTmplVarsCounter = array();
  484. if($bTmplVarsCounter)
  485. $aTmplVarsCounter = array(
  486. 'style_prefix' => $this->_sStylePrefix,
  487. 'bx_if:show_hidden' => array(
  488. 'condition' => !$bShowCounterEmpty && !$bCount,
  489. 'content' => array()
  490. ),
  491. 'counter' => $this->getCounter($aParams)
  492. );
  493. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  494. return '';
  495. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_DOL_SCORE_USAGE_DEFAULT)}();
  496. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  497. 'style_prefix' => $this->_sStylePrefix,
  498. 'html_id' => $this->_aHtmlIds['main'],
  499. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  500. 'count' => $iCount,
  501. 'bx_if:show_do_comment' => array(
  502. 'condition' => $bTmplVarsDoComment,
  503. 'content' => $aTmplVarsDoComment
  504. ),
  505. 'bx_if:show_counter' => array(
  506. 'condition' => $bTmplVarsCounter,
  507. 'content' => $aTmplVarsCounter
  508. ),
  509. 'script' => ''
  510. ));
  511. }
  512. public function getCounter($aParams = array())
  513. {
  514. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  515. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  516. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  517. $iCount = (int)$this->getCommentsCountAll();
  518. $sClass = $this->_sStylePrefix . '-counter';
  519. if($bShowDoCommentAsButtonSmall)
  520. $sClass .= ' bx-btn-small-height';
  521. if($bShowDoCommentAsButton)
  522. $sClass .= ' bx-btn-height';
  523. $iCmtsLimit = 5;
  524. $aCmts = $this->_oQuery->getCommentsBy(array('type' => 'object_id', 'object_id' => $this->getId(), 'order_way' => 'desc', 'start' => 0, 'per_page' => $iCmtsLimit * 4));
  525. $aCmts = array_reverse($aCmts);
  526. $aTmplVarsProfiles = array();
  527. foreach($aCmts as $aCmt) {
  528. $iAuthor = (int)$aCmt['cmt_author_id'];
  529. if(array_key_exists($iAuthor, $aTmplVarsProfiles))
  530. continue;
  531. $oAuthor = BxDolProfile::getInstanceMagic($iAuthor);
  532. if(!$oAuthor)
  533. continue;
  534. $aTmplVarsProfiles[$iAuthor] = array(
  535. 'icon' => $oAuthor->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')))
  536. );
  537. if(count($aTmplVarsProfiles) >= $iCmtsLimit)
  538. break;
  539. }
  540. $aTmplVarsProfiles = array_values($aTmplVarsProfiles);
  541. $sHref = !empty($aParams['overwrite_counter_link_href']) ? $aParams['overwrite_counter_link_href'] : $this->getListUrl();
  542. $sOnclick = '';
  543. if(!empty($aParams['overwrite_counter_link_onclick']))
  544. $sOnclick = $aParams['overwrite_counter_link_onclick'];
  545. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), array(
  546. 'id' => $this->_aHtmlIds['counter'],
  547. 'class' => $sClass,
  548. 'href' => $sHref,
  549. 'bx_if:show_onclick' => array(
  550. 'condition' => !empty($sOnclick),
  551. 'content' => array(
  552. 'onclick' => $sOnclick
  553. )
  554. ),
  555. 'content' => $iCount != 0 || $bShowEmpty ? $this->_getCounterLabel($iCount) : '',
  556. 'bx_repeat:profiles' => $aTmplVarsProfiles,
  557. 'bx_if:show_icon' => array(
  558. 'condition' => $bShowEmpty || !empty($aTmplVarsProfiles),
  559. 'content' => array(
  560. 'sp' => $this->_sStylePrefix
  561. )
  562. )
  563. ));
  564. }
  565. protected function _getLabelDo($aParams = array())
  566. {
  567. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), array(
  568. 'style_prefix' => $this->_sStylePrefix,
  569. 'bx_if:show_image' => array(
  570. 'condition' => isset($aParams['show_do_comment_image']) && $aParams['show_do_comment_image'] == true,
  571. 'content' => array(
  572. 'style_prefix' => $this->_sStylePrefix,
  573. 'src' => $this->_getImageDo()
  574. )
  575. ),
  576. 'bx_if:show_icon' => array(
  577. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  578. 'content' => array(
  579. 'style_prefix' => $this->_sStylePrefix,
  580. 'name' => $this->_getIconDo()
  581. )
  582. ),
  583. 'bx_if:show_text' => array(
  584. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  585. 'content' => array(
  586. 'style_prefix' => $this->_sStylePrefix,
  587. 'text' => _t($this->_getTitleDo())
  588. )
  589. )
  590. ));
  591. }
  592. protected function _getCounterLabel($iCount)
  593. {
  594. return (int)$iCount != 0 ? _t('_cmt_txt_counter', $iCount) : _t('_cmt_txt_counter_empty');
  595. }
  596. protected function _getTmplElementBlock()
  597. {
  598. return self::$_sTmplContentElementBlock;
  599. }
  600. protected function _getTmplElementInline()
  601. {
  602. return self::$_sTmplContentElementInline;
  603. }
  604. protected function _getTmplLabelDo()
  605. {
  606. return self::$_sTmplContentDoCommentLabel;
  607. }
  608. protected function _getTmplCounter()
  609. {
  610. return self::$_sTmplContentCounter;
  611. }
  612. /**
  613. * private functions
  614. */
  615. protected function _getControlsBox()
  616. {
  617. $sDisplay = '';
  618. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  619. if($bDisplay) {
  620. $aDisplayLinks = array(
  621. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  622. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  623. );
  624. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  625. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  626. $sDisplay = $oMenu->getCode();
  627. }
  628. $sBrowseType = '';
  629. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  630. if($bBrowseType) {
  631. $aBrowseLinks = array(
  632. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  633. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  634. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  635. );
  636. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  637. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  638. $sBrowseType = $oMenu->getCode();
  639. }
  640. $sBrowseFilter = '';
  641. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  642. if($bBrowseFilter) {
  643. $aFilterLinks = array(
  644. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  645. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  646. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  647. );
  648. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  649. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  650. $sBrowseFilter = $oMenu->getCode();
  651. }
  652. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  653. 'display_switcher' => $bDisplay ? $sDisplay : '',
  654. 'bx_if:is_divider_1' => array(
  655. 'condition' => $bDisplay && $bBrowseType,
  656. 'content' => array(
  657. 'style_prefix' => $this->_sStylePrefix,
  658. )
  659. ),
  660. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  661. 'bx_if:is_divider_2' => array(
  662. 'condition' => $bBrowseType && $bBrowseFilter,
  663. 'content' => array(
  664. 'style_prefix' => $this->_sStylePrefix,
  665. )
  666. ),
  667. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  668. ));
  669. }
  670. protected function _getActionsBox(&$aCmt, $aDp = array())
  671. {
  672. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  673. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  674. $sMenuActions = '';
  675. if(!$bViewOnly) {
  676. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  677. $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
  678. $oMenuActions->setDynamicMode($bDynamicMode);
  679. $sMenuActions = $oMenuActions->getCode();
  680. }
  681. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  682. 'id' => $aCmt['cmt_id'],
  683. 'js_object' => $this->_sJsObjName,
  684. 'style_prefix' => $this->_sStylePrefix,
  685. 'menu_actions' => $sMenuActions,
  686. ));
  687. }
  688. protected function _getFormBox($sType, $aBp, $aDp)
  689. {
  690. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  691. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  692. $bQuote = isset($aDp['quote']) && (bool)$aDp['quote'];
  693. $bFormMin = $iCmtParentId == 0 && isset($aDp['min_post_form']) && (bool)$aDp['min_post_form'];
  694. $sPositionSystem = $this->_aSystem['post_form_position'];
  695. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  696. return '';
  697. $sClass = '';
  698. if(!empty($sPosition))
  699. $sClass .= ' ' . $this->_sStylePrefix . '-reply-' . $sPosition;
  700. if($bQuote)
  701. $sClass .= ' ' . $this->_sStylePrefix . '-reply-quote';
  702. if($bFormMin)
  703. $sClass .= ' ' . $this->_sStylePrefix . '-reply-min';
  704. if(!empty($aDp['class']))
  705. $sClass .= ' ' . $aDp['class'];
  706. $sClassBody = '';
  707. if(!empty($aDp['class_body']))
  708. $sClassBody .= ' ' . $aDp['class_body'];
  709. $aTmplVarsFormMin = array();
  710. if($bFormMin) {
  711. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($this->_getAuthorId());
  712. $oForm = new BxTemplFormView(array());
  713. $aInputPlaceholder = array(
  714. 'type' => 'text',
  715. 'name' => 'comment',
  716. 'caption' => '',
  717. 'attrs' => array(
  718. 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtShowForm(this)',
  719. 'placeholder' => _t($this->_aT['txt_min_form_placeholder'], $sAuthorName)
  720. ),
  721. 'value' => '',
  722. );
  723. $sClassBodyMin = '';
  724. if(!empty($aDp['class_body_min']))
  725. $sClassBodyMin .= ' ' . $aDp['class_body_min'];
  726. $aTmplVarsFormMin = array(
  727. 'js_object' => $this->_sJsObjName,
  728. 'class_body_min' => $sClassBodyMin,
  729. 'style_prefix' => $this->_sStylePrefix,
  730. 'author_unit' => $sAuthorUnit,
  731. 'placeholder' => $oForm->genRow($aInputPlaceholder)
  732. );
  733. }
  734. $aForm = $this->{'_getForm' . ucfirst($sType)}($iCmtParentId, $aDp);
  735. if(empty($aForm['form']))
  736. return !empty($aForm['msg']) && (isLogged() || $iCmtParentId != 0 || $this->getCommentsCount() > 0) ? MsgBox($aForm['msg']) : '';
  737. return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
  738. 'js_object' => $this->_sJsObjName,
  739. 'style_prefix' => $this->_sStylePrefix,
  740. 'class' => $sClass,
  741. 'class_body' => $sClassBody,
  742. 'bx_if:show_form_min' => array(
  743. 'condition' => $bFormMin,
  744. 'content' => $aTmplVarsFormMin
  745. ),
  746. 'form' => $aForm['form'],
  747. 'form_id' => $aForm['form_id'],
  748. ));
  749. }
  750. protected function _getFormPost($iCmtParentId = 0, $aDp = array())
  751. {
  752. $bCmtParentId = !empty($iCmtParentId);
  753. if(!$bCmtParentId && !$this->isPostAllowed())
  754. return array('msg' => $this->msgErrPostAllowed());
  755. if($bCmtParentId && !$this->isReplyAllowed($iCmtParentId))
  756. return array('msg' => $this->msgErrReplyAllowed());
  757. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  758. $bQuote = isset($aDp['quote']) && (bool)$aDp['quote'];
  759. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  760. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  761. if($bQuote) {
  762. $aCmtParent = $this->getCommentRow((int)$iCmtParentId);
  763. if(!empty($aCmtParent['cmt_text']))
  764. $oForm->aInputs['cmt_text']['value'] = $this->_oTemplate->parseHtmlByName('comment_quote.html', array(
  765. 'content' => $aCmtParent['cmt_text']
  766. ));
  767. }
  768. $oForm->initChecker();
  769. if($oForm->isSubmittedAndValid()) {
  770. $iCmtAuthorId = $this->_getAuthorId();
  771. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  772. $sCmtText = $oForm->getCleanValue('cmt_text');
  773. $iLevel = 0;
  774. $iCmtVisualParentId = 0;
  775. if((int)$iCmtParentId > 0) {
  776. $aParent = $this->getCommentRow($iCmtParentId);
  777. $iLevel = (int)$aParent['cmt_level'] + 1;
  778. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  779. }
  780. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  781. if($iCmtId != 0) {
  782. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, $iCmtAuthorId);
  783. if($this->isAttachImageEnabled())
  784. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, true);
  785. if($iCmtParentId) {
  786. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  787. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  788. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  789. }
  790. $this->_triggerComment();
  791. if($bCmtParentId)
  792. $this->isReplyAllowed($iCmtParentId, true);
  793. else
  794. $this->isPostAllowed(true);
  795. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  796. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  797. if(($mixedResult = $this->onPostAfter($iCmtId)) !== false)
  798. return $mixedResult;
  799. }
  800. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  801. }
  802. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  803. }
  804. protected function _getFormEdit($iCmtId, $aDp = array())
  805. {
  806. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  807. $aCmt = $this->getCommentSimple($iCmtId);
  808. if(!$aCmt)
  809. return array('msg' => _t('_No such comment'));
  810. $iCmtAuthorId = $this->_getAuthorId();
  811. if(!$this->isEditAllowed($aCmt))
  812. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  813. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  814. $oForm->initChecker($aCmt);
  815. if($oForm->isSubmittedAndValid()) {
  816. $sCmtText = $oForm->getCleanValue('cmt_text');
  817. if($oForm->update($iCmtId) !== false) {
  818. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, (int)$aCmt['cmt_author_id']);
  819. if($this->isAttachImageEnabled())
  820. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, false);
  821. $this->isEditAllowed($aCmt, true);
  822. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  823. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  824. if(($mixedResult = $this->onEditAfter($iCmtId)) !== false)
  825. return $mixedResult;
  826. }
  827. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  828. }
  829. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  830. }
  831. protected function _getForm($sAction, $iId)
  832. {
  833. $oForm = $this->_getFormObject($sAction);
  834. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $iId));
  835. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $iId));
  836. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  837. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  838. $oForm->aInputs['id']['value'] = $this->_iId;
  839. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  840. if(!$this->isAttachImageEnabled())
  841. unset($oForm->aInputs['cmt_image']);
  842. if(isset($oForm->aInputs['cmt_text'])) {
  843. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  844. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  845. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  846. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  847. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  848. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  849. }
  850. return $oForm;
  851. }
  852. protected function _getContent($aCmt)
  853. {
  854. $sAttachments = $this->_getAttachments($aCmt);
  855. $sReactions = '';
  856. if(($oReaction = $this->getReactionObject($aCmt['cmt_unique_id'])) !== false)
  857. $sReactions = $oReaction->getCounter(array(
  858. 'show_counter' => true
  859. ));
  860. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameItemContent, array_merge(array(
  861. 'style_prefix' => $this->_sStylePrefix,
  862. 'js_object' => $this->_sJsObjName,
  863. 'bx_if:show_attached' => array(
  864. 'condition' => !empty($sAttachments),
  865. 'content' => array(
  866. 'style_prefix' => $this->_sStylePrefix,
  867. 'attached' => $sAttachments
  868. )
  869. ),
  870. 'reactions' => $sReactions,
  871. ), $this->_getTmplVarsText($aCmt)));
  872. }
  873. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  874. {
  875. $iStart = $iPerView = 0;
  876. switch($aBp['type']) {
  877. case BX_CMT_BROWSE_HEAD:
  878. case BX_CMT_BROWSE_POPULAR:
  879. case BX_CMT_BROWSE_CONNECTION:
  880. $iPerView = $aBp['per_view'];
  881. $iStart = $aBp['start'] + $iPerView;
  882. if($iStart >= $aBp['count'])
  883. return $sCmts;
  884. break;
  885. case BX_CMT_BROWSE_TAIL:
  886. $iPerView = $aBp['per_view'];
  887. $iStart = $aBp['start'] - $iPerView;
  888. if($iStart < 0) {
  889. $iPerView += $iStart;
  890. $iStart = 0;
  891. }
  892. if($iStart == 0 && $iPerView == 0)
  893. return $sCmts;
  894. break;
  895. }
  896. $sParentKey = isset($aBp['vparent_id']) ? 'vparent_id' : 'parent_id';
  897. $bRoot = (int)$aBp[$sParentKey] <= 0;
  898. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  899. 'js_object' => $this->_sJsObjName,
  900. 'style_prefix' => $this->_sStylePrefix,
  901. 'bx_if:is_root' => array(
  902. 'condition' => $bRoot,
  903. 'content' => array()
  904. ),
  905. 'parent_id' => $aBp[$sParentKey],
  906. 'start' => $iStart,
  907. 'per_view' => $iPerView,
  908. 'title' => _t('_cmt_load_more_' . ($aBp[$sParentKey] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  909. ));
  910. switch($aBp['type']) {
  911. case BX_CMT_BROWSE_HEAD:
  912. case BX_CMT_BROWSE_POPULAR:
  913. case BX_CMT_BROWSE_CONNECTION:
  914. $sCmts .= $sMore;
  915. break;
  916. case BX_CMT_BROWSE_TAIL:
  917. $sCmts = $sMore . $sCmts;
  918. break;
  919. }
  920. return $sCmts;
  921. }
  922. protected function _getEmpty($aDp = array())
  923. {
  924. $sClass = '';
  925. if(!empty($aDp['class']))
  926. $sClass .= ' ' . $aDp['class'];
  927. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  928. 'style_prefix' => $this->_sStylePrefix,
  929. 'class' => $sClass,
  930. 'content' => MsgBox(_t('_Empty'))
  931. ));
  932. }
  933. protected function _getViewImagePopup()
  934. {
  935. $sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
  936. $sViewImagePopupContent = $this->_oTemplate->parseHtmlByName('popup_image.html', array(
  937. 'image_url' => ''
  938. ));
  939. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  940. }
  941. protected function _getAttachments($aCmt)
  942. {
  943. $aTmplImages = array();
  944. if(!$this->isAttachImageEnabled())
  945. return '';
  946. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  947. if(!empty($aFiles) && is_array($aFiles)) {
  948. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  949. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  950. foreach($aFiles as $aFile) {
  951. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  952. $sPreview = '';
  953. if($oTranscoder && $bImage)
  954. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  955. if(!$sPreview)
  956. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  957. $aTmplVarsFile = array(
  958. 'js_object' => $this->_sJsObjName,
  959. 'preview' => $sPreview,
  960. 'file' => $oStorage->getFileUrlById($aFile['image_id']),
  961. 'file_name' => $aFile['file_name'],
  962. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  963. 'file_size' => _t_format_size($aFile['size']),
  964. );
  965. $aTmplImages[] = array(
  966. 'style_prefix' => $this->_sStylePrefix,
  967. 'bx_if:show_image' => array(
  968. 'condition' => $bImage,
  969. 'content' => $aTmplVarsFile
  970. ),
  971. 'bx_if:show_file' => array(
  972. 'condition' => !$bImage,
  973. 'content' => $aTmplVarsFile
  974. ),
  975. );
  976. }
  977. }
  978. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  979. 'bx_repeat:attached' => $aTmplImages
  980. ));
  981. }
  982. protected function _getTmplVarsAuthor($aCmt)
  983. {
  984. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  985. $bAuthorIcon = !empty($sAuthorIcon);
  986. return array(
  987. 'author_unit' => $sAuthorUnit,
  988. 'bx_if:show_icon' => array(
  989. 'condition' => $bAuthorIcon,
  990. 'content' => array(
  991. 'author_icon' => $sAuthorIcon
  992. )
  993. ),
  994. 'bx_if:show_icon_empty' => array(
  995. 'condition' => !$bAuthorIcon,
  996. 'content' => array()
  997. ),
  998. 'bx_if:show_author_link' => array(
  999. 'condition' => !empty($sAuthorLink),
  1000. 'content' => array(
  1001. 'author_link' => $sAuthorLink,
  1002. 'author_title' => bx_html_attribute($sAuthorName),
  1003. 'author_name' => $sAuthorName
  1004. )
  1005. ),
  1006. 'bx_if:show_author_text' => array(
  1007. 'condition' => empty($sAuthorLink),
  1008. 'content' => array(
  1009. 'author_name' => $sAuthorName
  1010. )
  1011. ),
  1012. );
  1013. }
  1014. protected function _getTmplVarsText($aCmt)
  1015. {
  1016. $sText = $aCmt['cmt_text'];
  1017. $sTextMore = '';
  1018. if(!$this->isHtml()) {
  1019. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  1020. if(strlen($sText) > $iMaxLength) {
  1021. $iLength = strpos($sText, ' ', $iMaxLength);
  1022. $sTextMore = trim(substr($sText, $iLength));
  1023. $sText = trim(substr($sText, 0, $iLength));
  1024. }
  1025. }
  1026. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  1027. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  1028. return array(
  1029. 'text' => $sText,
  1030. 'bx_if:show_more' => array(
  1031. 'condition' => !empty($sTextMore),
  1032. 'content' => array(
  1033. 'style_prefix' => $this->_sStylePrefix,
  1034. 'js_object' => $this->_sJsObjName,
  1035. 'text_more' => $sTextMore
  1036. )
  1037. ),
  1038. );
  1039. }
  1040. }
  1041. /** @} */