BxBaseCmtsView.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDolCmts');
  9. bx_import('BxDolProfile');
  10. bx_import('BxTemplPaginate');
  11. /**
  12. * @see BxDolCmts
  13. */
  14. class BxBaseCmtsView extends BxDolCmts {
  15. var $_sJsObjName;
  16. var $_sStylePrefix;
  17. function BxBaseCmtsView( $sSystem, $iId, $iInit = 1 ) {
  18. BxDolCmts::BxDolCmts( $sSystem, $iId, $iInit );
  19. if(empty($sSystem))
  20. return;
  21. $this->_sJsObjName = 'oCmts' . str_replace(' ', '', ucwords(str_replace(array('_' , '-'), array(' ', ' '), $sSystem))) . $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('common_anim.js', 'jquery.form.js', 'BxDolCmts.js'));
  33. bx_import('BxDolForm');
  34. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  35. $oForm->addCssJs();
  36. }
  37. /**
  38. * Get initialization section of comments box
  39. *
  40. * @return string
  41. */
  42. function getScript()
  43. {
  44. $this->addCssJs();
  45. return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->_sJsObjName . " = new BxDolCmts({
  46. sObjName: '" . $this->_sJsObjName . "',
  47. sRootUrl: '" . BX_DOL_URL_ROOT . "',
  48. sSystem: '" . $this->getSystemName() . "',
  49. sSystemTable: '" . $this->_aSystem['table_cmts'] . "',
  50. iAuthorId: '" . $this->_getAuthorId() . "',
  51. iObjId: '" . $this->getId () . "',
  52. sPostFormPosition: '" . $this->_aSystem['post_form_position'] . "',
  53. sBrowseType: '" . $this->_sBrowseType . "',
  54. sDisplayType: '" . $this->_sDisplayType . "'
  55. });");
  56. }
  57. /**
  58. * get full comments block with initializations
  59. */
  60. function getCommentsBlock($iParentId = 0, $iVParentId = 0, $bInDesignbox = true) {
  61. $aBp = array('parent_id' => $iParentId, 'vparent_id' => $iVParentId);
  62. $sCmts = $this->getComments($aBp);
  63. $sCaption = _t('_cmt_block_comments_title', $this->getCommentsCount());
  64. $sContent = BxDolTemplate::getInstance()->parseHtmlByName('comments_block.html', array(
  65. 'system' => $this->_sSystem,
  66. 'list_anchor' => $this->getListAnchor(),
  67. 'id' => $this->getId(),
  68. 'bx_if:show_empty' => array(
  69. 'condition' => $sCmts == '',
  70. 'content' => array(
  71. 'style_prefix' => $this->_sStylePrefix
  72. )
  73. ),
  74. 'comments' => $sCmts,
  75. 'post_form_top' => $this->getFormBoxPost($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP)),
  76. 'post_form_bottom' => $this->getFormBoxPost($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM)),
  77. 'script' => $this->getScript()
  78. ));
  79. return $bInDesignbox ? DesignBoxContent($sCaption, $sContent, BX_DB_PADDING_DEF, $this->_getControlsBox()) : array(
  80. 'title' => $sCaption,
  81. 'content' => $sContent,
  82. 'designbox_id' => BX_DB_PADDING_DEF,
  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. return '';
  99. $sCmts = '';
  100. foreach($aCmts as $k => $aCmt)
  101. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  102. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  103. return $sCmts;
  104. }
  105. /**
  106. * get comment view block with initializations
  107. */
  108. function getCommentBlock($iCmtId = 0)
  109. {
  110. return BxDolTemplate::getInstance()->parseHtmlByName('comment_block.html', array(
  111. 'system' => $this->_sSystem,
  112. 'id' => $this->getId(),
  113. 'comment' => $this->getComment($iCmtId, array('type' => $this->_sBrowseType), array('type' => BX_CMT_DISPLAY_THREADED)),
  114. 'script' => $this->getScript()
  115. ));
  116. }
  117. /**
  118. * get one just posted comment
  119. *
  120. * @param int $iCmtId - comment id
  121. * @return string
  122. */
  123. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  124. {
  125. $oTemplate = BxDolTemplate::getInstance();
  126. $iUserId = $this->_getAuthorId();
  127. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  128. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  129. $sClass = $sRet = '';
  130. if($aCmt['cmt_rated'] == -1 || $aCmt['cmt_rate'] < $this->_aSystem['viewing_threshold']) {
  131. $oTemplate->pareseHtmlByName('comment_hidden.html', array(
  132. 'js_object' => $this->_sJsObjName,
  133. 'id' => $aCmt['cmt_id'],
  134. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  135. 'bx_if:show_replies' => array(
  136. 'condition' => $aCmt['cmt_replies'] > 0,
  137. 'content' => array(
  138. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  139. )
  140. )
  141. ));
  142. $sClass = ' cmt-hidden';
  143. }
  144. if($aCmt['cmt_author_id'] == $iUserId)
  145. $sClass .= ' cmt-mine';
  146. $sActions = $this->_getActionsBox($aCmt, $aDp);
  147. $sText = $aCmt['cmt_text'];
  148. $sTextMore = '';
  149. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  150. if(strlen($sText) > $iMaxLength) {
  151. $iLength = strpos($sText, ' ', $iMaxLength);
  152. $sTextMore = trim(substr($sText, $iLength));
  153. $sText = trim(substr($sText, 0, $iLength));
  154. }
  155. $sText = $this->_prepareTextForOutput($sText);
  156. $sTextMore = $this->_prepareTextForOutput($sTextMore);
  157. $aTmplReplyTo = array();
  158. if((int)$aCmt['cmt_parent_id'] != 0) {
  159. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  160. list($sParAuthorName, $sParAuthorLink, $sParAuthorIcon) = $this->_getAuthorInfo($aParent['cmt_author_id']);
  161. $aTmplReplyTo = array(
  162. 'style_prefix' => $this->_sStylePrefix,
  163. 'par_cmt_link' => $this->getBaseUrl() . '#' . $this->_sSystem . $aCmt['cmt_parent_id'],
  164. 'par_cmt_author' => $sParAuthorName
  165. );
  166. }
  167. $aTmplImages = array();
  168. if($this->isAttachImageEnabled()) {
  169. $aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']);
  170. if(!empty($aImages) && is_array($aImages)) {
  171. bx_import('BxDolImageTranscoder');
  172. $oTranscoder = BxDolImageTranscoder::getObjectInstance($this->_sTranscoderPreview);
  173. foreach($aImages as $aImage)
  174. $aTmplImages[] = array(
  175. 'style_prefix' => $this->_sStylePrefix,
  176. 'js_object' => $this->_sJsObjName,
  177. 'id' => $aImage['image_id'],
  178. 'image' => $oTranscoder->getImageUrl($aImage['image_id'])
  179. );
  180. }
  181. }
  182. $sReplies = '';
  183. if((int)$aCmt['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED)
  184. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  185. $bAuthorIcon = !empty($sAuthorIcon);
  186. return $oTemplate->parseHtmlByName('comment.html', array(
  187. 'system' => $this->_sSystem,
  188. 'style_prefix' => $this->_sStylePrefix,
  189. 'js_object' => $this->_sJsObjName,
  190. 'id' => $aCmt['cmt_id'],
  191. 'class' => $sClass,
  192. 'bx_if:show_icon' => array(
  193. 'condition' => $bAuthorIcon,
  194. 'content' => array(
  195. 'author_icon' => $sAuthorIcon
  196. )
  197. ),
  198. 'bx_if:show_icon_empty' => array(
  199. 'condition' => !$bAuthorIcon,
  200. 'content' => array()
  201. ),
  202. 'bx_if:show_author_link' => array(
  203. 'condition' => !empty($sAuthorLink),
  204. 'content' => array(
  205. 'author_link' => $sAuthorLink,
  206. 'author_name' => $sAuthorName
  207. )
  208. ),
  209. 'bx_if:show_author_text' => array(
  210. 'condition' => empty($sAuthorLink),
  211. 'content' => array(
  212. 'author_name' => $sAuthorName
  213. )
  214. ),
  215. 'bx_if:show_reply_to' => array(
  216. 'condition' => !empty($aTmplReplyTo),
  217. 'content' => $aTmplReplyTo
  218. ),
  219. 'view_link' => bx_append_url_params($this->_sViewUrl, array(
  220. 'sys' => $this->_sSystem,
  221. 'id' => $this->_iId,
  222. 'cmt_id' => $aCmt['cmt_id']
  223. )),
  224. 'ago' => bx_time_js($aCmt['cmt_time']),
  225. 'bx_if:hide_rate_count' => array(
  226. 'condition' => (int)$aCmt['cmt_rate'] <= 0,
  227. 'content' => array()
  228. ),
  229. 'points' => _t(in_array($aCmt['cmt_rate'], array(-1, 0, 1)) ? '_N_point' : '_N_points', $aCmt['cmt_rate']),
  230. 'text' => $sText,
  231. 'bx_if:show_more' => array(
  232. 'condition' => !empty($sTextMore),
  233. 'content' => array(
  234. 'style_prefix' => $this->_sStylePrefix,
  235. 'js_object' => $this->_sJsObjName,
  236. 'text_more' => $sTextMore
  237. )
  238. ),
  239. 'bx_if:show_attached' => array(
  240. 'condition' => !empty($aTmplImages),
  241. 'content' => array(
  242. 'style_prefix' => $this->_sStylePrefix,
  243. 'bx_repeat:attached' => $aTmplImages
  244. )
  245. ),
  246. 'actions' => $sActions,
  247. 'replies' => $sReplies
  248. ));
  249. }
  250. function getFormBoxPost($aBp = array(), $aDp = array())
  251. {
  252. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  253. }
  254. function getFormBoxEdit($aBp = array(), $aDp = array())
  255. {
  256. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  257. }
  258. function getFormPost($iCmtParentId = 0)
  259. {
  260. return $this->_getFormPost($iCmtParentId);
  261. }
  262. function getFormEdit($aCmt)
  263. {
  264. return $this->_getFormEdit($aCmt);
  265. }
  266. function getPlusedBy($iCmtId)
  267. {
  268. $oTemplate = BxDolTemplate::getInstance();
  269. $aTmplUsers = array();
  270. $aUserIds = $this->_oQuery->getRatedBy($this->_aSystem['system_id'], $iCmtId);
  271. foreach($aUserIds as $iUserId) {
  272. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($iUserId);
  273. $aTmplUsers[] = array(
  274. 'style_prefix' => $this->_sStylePrefix,
  275. 'user_unit' => $sUserUnit
  276. );
  277. }
  278. bx_import('BxTemplStudioFunctions');
  279. $sContent = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('comment_pb_list.html', array(
  280. 'style_prefix' => $this->_sStylePrefix,
  281. 'bx_repeat:list' => $aTmplUsers
  282. )));
  283. return $oTemplate->parseHtmlByName('comment_plused_by.html', array(
  284. 'style_prefix' => $this->_sStylePrefix,
  285. 'id' => $this->_sSystem . '-plused-by',
  286. 'content' => $sContent
  287. ));
  288. }
  289. function getImage($iImgId)
  290. {
  291. if(!$this->isAttachImageEnabled())
  292. return '';
  293. $oTemplate = BxDolTemplate::getInstance();
  294. bx_import('BxDolStorage');
  295. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  296. bx_import('BxTemplStudioFunctions');
  297. $sContent = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('bx_img.html', array(
  298. 'src' => $oStorage->getFileUrlById($iImgId),
  299. 'bx_repeat:attrs' => array(
  300. array('key' => 'alt', 'value' => bx_html_attribute(_t('_cmt_view_attached_image'))),
  301. array('key' => 'title', 'value' => bx_html_attribute(_t('_cmt_close_attached_image'))),
  302. array('key' => 'onclick', 'value' => $this->_sJsObjName . '.hideImage(this);')
  303. )
  304. )));
  305. return $oTemplate->parseHtmlByName('comment_image.html', array(
  306. 'style_prefix' => $this->_sStylePrefix,
  307. 'id' => $this->_sSystem . '-attached-image',
  308. 'content' => $sContent
  309. ));
  310. }
  311. /**
  312. * private functions
  313. */
  314. protected function _getControlsBox()
  315. {
  316. $oTemplate = BxDolTemplate::getInstance();
  317. $sDisplay = '';
  318. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  319. if($bDisplay) {
  320. $aDisplayLinks = array(
  321. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  322. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  323. );
  324. bx_import('BxTemplMenuInteractive');
  325. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  326. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  327. $sDisplay = $oMenu->getCode();
  328. }
  329. $sBrowseType = '';
  330. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  331. if($bBrowseType) {
  332. $aBrowseLinks = array(
  333. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  334. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  335. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  336. );
  337. bx_import('BxTemplMenuInteractive');
  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. $iUserId = $this->_getAuthorId();
  376. $isEditAllowedPermanently = ($aCmt['cmt_author_id'] == $iUserId && $this->isEditAllowed()) || $this->isEditAllowedAll();
  377. $isRemoveAllowedPermanently = ($aCmt['cmt_author_id'] == $iUserId && $this->isRemoveAllowed()) || $this->isRemoveAllowedAll();
  378. $sManagePopupId = $sManagePopupText = '';
  379. if($isEditAllowedPermanently || $isRemoveAllowedPermanently) {
  380. $aMenu = array(
  381. array('name' => 'cmt-edit', 'icon' => 'pencil', 'onclick' => $this->_sJsObjName . ".cmtEdit(this, " . $aCmt['cmt_id'] . ")", 'title' => _t('_Edit')),
  382. array('name' => 'cmt-delete', 'icon' => 'remove', 'onclick' => $this->_sJsObjName . ".cmtRemove(this, " . $aCmt['cmt_id'] . ")", 'title' => _t('_Delete')),
  383. );
  384. bx_import('BxTemplStudioMenu');
  385. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_vertical.html', 'menu_items' => $aMenu));
  386. bx_import('BxTemplStudioFunctions');
  387. $sManagePopupText = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('comment_manage.html', array(
  388. 'style_prefix' => $this->_sStylePrefix,
  389. 'content' => $oMenu->getCode()
  390. )));
  391. }
  392. $bRated = (int)$aCmt['cmt_rated'] > 0;
  393. return $oTemplate->parseHtmlByName('comment_actions.html', array(
  394. 'id' => $aCmt['cmt_id'],
  395. 'style_prefix' => $this->_sStylePrefix,
  396. 'view_link' => bx_append_url_params($this->_sViewUrl, array(
  397. 'sys' => $this->_sSystem,
  398. 'id' => $this->_iId,
  399. 'cmt_id' => $aCmt['cmt_id']
  400. )),
  401. 'points' => _t($aCmt['cmt_rate'] == 1 || $aCmt['cmt_rate'] == -1 ? '_N_point' : '_N_points', $aCmt['cmt_rate']),
  402. 'bx_if:show_reply' => array(
  403. 'condition' => $this->isPostReplyAllowed(),
  404. 'content' => array(
  405. 'js_object' => $this->_sJsObjName,
  406. 'style_prefix' => $this->_sStylePrefix,
  407. 'id' => $aCmt['cmt_id'],
  408. 'title_reply' => bx_html_attribute(_t(isset($aCmt['cmt_type']) && $aCmt['cmt_type'] == 'comment' ? '_Comment_to_this_comment' : '_Reply_to_this_comment'))
  409. )
  410. ),
  411. 'bx_if:show_rate' => array(
  412. 'condition' => $this->isRatable() && $this->isRateAllowed(),
  413. 'content' => array(
  414. 'js_object' => $this->_sJsObjName,
  415. 'style_prefix' => $this->_sStylePrefix,
  416. 'id' => $aCmt['cmt_id'],
  417. 'bx_if:hide_rate_plus' => array(
  418. 'condition' => $bRated,
  419. 'content' => array()
  420. ),
  421. 'bx_if:hide_rate_minus' => array(
  422. 'condition' => !$bRated,
  423. 'content' => array()
  424. )
  425. )
  426. ),
  427. 'bx_if:show_manage' => array(
  428. 'condition' => $isEditAllowedPermanently || $isRemoveAllowedPermanently,
  429. 'content' => array(
  430. 'js_object' => $this->_sJsObjName,
  431. 'style_prefix' => $this->_sStylePrefix,
  432. 'id' => $aCmt['cmt_id'],
  433. 'popup_id' => $this->_sSystem . '-manage-' . $aCmt['cmt_id'],
  434. 'popup_text' => $sManagePopupText
  435. )
  436. )
  437. ));
  438. }
  439. protected function _getFormBox($sType, $aBp, $aDp)
  440. {
  441. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  442. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  443. if(!$this->isPostReplyAllowed())
  444. return '';
  445. /*
  446. //TODO: Remove if it's not needed.
  447. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo();
  448. $bAuthorIcon = !empty($sAuthorIcon);
  449. */
  450. $sPositionSystem = $this->_aSystem['post_form_position'];
  451. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  452. return '';
  453. $sMethod = '_getForm' . ucfirst($sType);
  454. $aForm = $this->$sMethod($iCmtParentId);
  455. return BxDolTemplate::getInstance()->parseHtmlByName('comment_reply_box.html', array(
  456. 'js_object' => $this->_sJsObjName,
  457. 'style_prefix' => $this->_sStylePrefix,
  458. 'bx_if:show_class' => array(
  459. 'condition' => !empty($sPosition),
  460. 'content' => array(
  461. 'class' => $this->_sStylePrefix . '-reply-' . $sPosition
  462. )
  463. ),
  464. /*
  465. //TODO: Remove if it's not needed.
  466. 'bx_if:show_icon' => array(
  467. 'condition' => $bAuthorIcon,
  468. 'content' => array(
  469. 'author_icon' => $sAuthorIcon
  470. )
  471. ),
  472. 'bx_if:show_icon_empty' => array(
  473. 'condition' => !$bAuthorIcon,
  474. 'content' => array()
  475. ),
  476. 'bx_if:show_author_link' => array(
  477. 'condition' => !empty($sAuthorLink),
  478. 'content' => array(
  479. 'author_link' => $sAuthorLink,
  480. 'author_name' => $sAuthorName
  481. )
  482. ),
  483. 'bx_if:show_author_text' => array(
  484. 'condition' => empty($sAuthorLink),
  485. 'content' => array(
  486. 'author_name' => $sAuthorName
  487. )
  488. ),
  489. */
  490. 'form' => $aForm['form'],
  491. 'form_id' => $aForm['form_id'],
  492. ));
  493. }
  494. protected function _getFormPost($iCmtParentId = 0)
  495. {
  496. $oForm = $this->_getFormObject(BX_CMT_ACTION_POST, $iCmtParentId);
  497. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  498. $oForm->initChecker();
  499. if($oForm->isSubmittedAndValid()) {
  500. $iCmtAuthorId = $this->_getAuthorId();
  501. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  502. $sCmtText = $oForm->getCleanValue('cmt_text');
  503. if($this->_isSpam($sCmtText))
  504. return array('msg' => _t('_sys_spam_detected', BX_DOL_URL_ROOT . 'contact.php'));
  505. $sCmtText = $this->_prepareTextForSave ($sCmtText);
  506. $oForm->setSubmittedValue('cmt_text', $sCmtText, $oForm->aFormAttrs['method']);
  507. $iLevel = 0;
  508. $iCmtVisualParentId = 0;
  509. if((int)$iCmtParentId > 0) {
  510. $aParent = $this->getCommentRow($iCmtParentId);
  511. $iLevel = (int)$aParent['cmt_level'] + 1;
  512. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  513. }
  514. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  515. if($iCmtId != 0) {
  516. if($this->isAttachImageEnabled()) {
  517. $aImages = $oForm->getCleanValue('cmt_image');
  518. if(!empty($aImages) && is_array($aImages)) {
  519. bx_import('BxDolStorage');
  520. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  521. foreach($aImages as $iImageId)
  522. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  523. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  524. }
  525. }
  526. if($iCmtParentId) {
  527. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  528. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  529. }
  530. $this->_triggerComment();
  531. $this->isPostReplyAllowed(true);
  532. bx_import('BxDolAlerts');
  533. $oZ = new BxDolAlerts($this->_sSystem, 'commentPost', $this->getId(), $iCmtAuthorId, array('comment_id' => $iCmtId, 'comment_author_id' => $iCmtAuthorId));
  534. $oZ->alert();
  535. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  536. }
  537. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  538. }
  539. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  540. }
  541. protected function _getFormEdit($iCmtId)
  542. {
  543. $aCmt = $this->_oQuery->getCommentSimple ($this->getId(), $iCmtId);
  544. if(!$aCmt)
  545. return array('msg' => _t('_No such comment'));
  546. $iCmtAuthorId = $this->_getAuthorId();
  547. if(!$this->isEditAllowedAll() && ($aCmt['cmt_author_id'] != $iCmtAuthorId || !$this->isEditAllowed()))
  548. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId && !$this->isEditAllowed() ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  549. $oForm = $this->_getFormObject(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  550. $oForm->initChecker($aCmt);
  551. if($oForm->isSubmittedAndValid()) {
  552. $sCmtText = $oForm->getCleanValue('cmt_text');
  553. if($this->_isSpam($sCmtText))
  554. return array('msg' => _t('_sys_spam_detected', BX_DOL_URL_ROOT . 'contact.php'));
  555. $sCmtText = $this->_prepareTextForSave ($sCmtText);
  556. $oForm->setSubmittedValue('cmt_text', $sCmtText, $oForm->aFormAttrs['method']);
  557. if($oForm->update($iCmtId)) {
  558. if ($aCmt['cmt_author_id'] == $iCmtAuthorId)
  559. $this->isEditAllowed(true);
  560. bx_import('BxDolAlerts');
  561. $oZ = new BxDolAlerts($this->_sSystem, 'commentUpdated', $this->getId(), $iCmtAuthorId, array('comment_id' => $aCmt['cmt_id'], 'comment_author_id' => $aCmt['cmt_author_id']));
  562. $oZ->alert();
  563. return array('id' => $iCmtId, 'text' => $sCmtText);
  564. }
  565. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  566. }
  567. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  568. }
  569. protected function _getFormObject($sAction, $iId)
  570. {
  571. $sActionCap = ucfirst($sAction);
  572. $sDisplayName = '_sFormDisplay' . $sActionCap;
  573. bx_import('BxDolForm');
  574. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->$sDisplayName);
  575. $oForm->setId(sprintf($oForm->aFormAttrs['id'], $sAction, $this->_sSystem, $iId));
  576. $oForm->setName(sprintf($oForm->aFormAttrs['name'], $sAction, $this->_sSystem, $iId));
  577. $oForm->aParams['db']['table'] = $this->_aSystem['table_cmts'];
  578. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  579. $oForm->aInputs['id']['value'] = $this->_iId;
  580. $oForm->aInputs['action']['value'] = 'Submit' . $sActionCap . 'Form';
  581. if(!$this->isAttachImageEnabled())
  582. unset($oForm->aInputs['cmt_image']);
  583. if(isset($oForm->aInputs['cmt_image'])) {
  584. $aFormNested = array(
  585. 'params' =>array(
  586. 'nested_form_template' => 'comments_uploader_nfw.html'
  587. ),
  588. 'inputs' => array(),
  589. );
  590. bx_import('BxDolFormNested');
  591. $oFormNested = new BxDolFormNested('cmt_image', $aFormNested, 'cmt_submit');
  592. $oForm->aInputs['cmt_image']['storage_object'] = $this->_sStorageObject;
  593. $oForm->aInputs['cmt_image']['images_transcoder'] = $this->_sTranscoderPreview;
  594. $oForm->aInputs['cmt_image']['uploaders'] = $this->_aImageUploaders;
  595. $oForm->aInputs['cmt_image']['upload_buttons_titles'] = array('Simple' => 'camera');
  596. $oForm->aInputs['cmt_image']['multiple'] = true;
  597. $oForm->aInputs['cmt_image']['ghost_template'] = $oFormNested;
  598. }
  599. if(isset($oForm->aInputs['cmt_text'])) {
  600. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  601. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  602. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  603. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  604. }
  605. return $oForm;
  606. }
  607. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  608. {
  609. $iStart = $iPerView = 0;
  610. switch($aBp['type']) {
  611. case BX_CMT_BROWSE_HEAD:
  612. case BX_CMT_BROWSE_POPULAR:
  613. case BX_CMT_BROWSE_CONNECTION:
  614. $iPerView = $aBp['per_view'];
  615. $iStart = $aBp['start'] + $iPerView;
  616. if($iStart >= $aBp['count'])
  617. return $sCmts;
  618. break;
  619. case BX_CMT_BROWSE_TAIL:
  620. $iPerView = $aBp['per_view'];
  621. $iStart = $aBp['start'] - $iPerView;
  622. if($iStart < 0) {
  623. $iPerView += $iStart;
  624. $iStart = 0;
  625. }
  626. if($iStart == 0 && $iPerView == 0)
  627. return $sCmts;
  628. break;
  629. }
  630. $bRoot = (int)$aBp['vparent_id'] <= 0;
  631. $sMore = BxDolTemplate::getInstance()->parseHtmlByName('comment_more.html', array(
  632. 'js_object' => $this->_sJsObjName,
  633. 'style_prefix' => $this->_sStylePrefix,
  634. 'bx_if:is_root' => array(
  635. 'condition' => $bRoot,
  636. 'content' => array()
  637. ),
  638. 'bx_if:is_button' => array(
  639. 'condition' => $bRoot,
  640. 'content' => array()
  641. ),
  642. 'parent_id' => $aBp['vparent_id'],
  643. 'start' => $iStart,
  644. 'per_view' => $iPerView,
  645. 'title' => _t('_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  646. ));
  647. switch($aBp['type']) {
  648. case BX_CMT_BROWSE_HEAD:
  649. case BX_CMT_BROWSE_POPULAR:
  650. case BX_CMT_BROWSE_CONNECTION:
  651. $sCmts .= $sMore;
  652. break;
  653. case BX_CMT_BROWSE_TAIL:
  654. $sCmts = $sMore . $sCmts;
  655. break;
  656. }
  657. return $sCmts;
  658. }
  659. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  660. header('Content-type: text/html; charset=utf-8');
  661. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  662. $oParser = new Services_JSON();
  663. $s = $oParser->encode($a);
  664. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  665. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  666. echo $s;
  667. }
  668. }