BxBaseCmtsView.php 28 KB

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