BxBaseCmtsView.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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', '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 . "'});
  64. " . $this->_sJsObjName . ".oCmtElements = {";
  65. for (reset($this->_aPostElements); list($k,$r) = each ($this->_aPostElements); ) {
  66. $ret .= "\n'$k' : { 'reg' : '{$r['reg']}', 'msg' : \"". bx_js_string(trim($r['msg'])) . "\" },";
  67. }
  68. $ret = substr($ret, 0, -1);
  69. $ret .= "\n};\n";
  70. $ret .= "</script>";
  71. $this->getExtraJs();
  72. $this->getExtraCss();
  73. BxDolTemplate::getInstance()->addJsTranslation(array(
  74. '_Error occured',
  75. '_Are you sure?'
  76. ));
  77. return $ret;
  78. }
  79. /**
  80. * get full comments block with initializations
  81. */
  82. function getCommentsBlock($iParentId = 0, $iVParentId = 0) {
  83. $aBp = array('parent_id' => $iParentId, 'vparent_id' => $iVParentId);
  84. $sCmts = $this->getComments($aBp);
  85. return BxDolTemplate::getInstance()->parseHtmlByName('comments_block.html', array(
  86. 'system' => $this->_sSystem,
  87. 'id' => $this->getId(),
  88. 'bx_if:show_empty' => array(
  89. 'condition' => $sCmts == '',
  90. 'content' => array(
  91. 'style_prefix' => $this->_sStylePrefix
  92. )
  93. ),
  94. 'controls' => $this->_getControlsBox(),
  95. 'comments' => $sCmts,
  96. 'post_form_top' => $this->_getPostReplyBox($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP)),
  97. 'post_form_bottom' => $this->_getPostReplyBox($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM)),
  98. 'script' => $this->getScript()
  99. ));
  100. }
  101. /**
  102. * get comments list for specified parent comment
  103. *
  104. * @param array $aBp - browse params array
  105. * @param array $aDp - display params array
  106. *
  107. */
  108. function getComments($aBp = array(), $aDp = array())
  109. {
  110. $this->_prepareParams($aBp, $aDp);
  111. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['order'], $aBp['start'], $aBp['per_view']);
  112. if(empty($aCmts) || !is_array($aCmts))
  113. return '';
  114. $sCmts = '';
  115. foreach($aCmts as $k => $r)
  116. $sCmts .= $this->getComment($r, $aBp, $aDp);
  117. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  118. return $sCmts;
  119. }
  120. /**
  121. * get comment view block with initializations
  122. */
  123. function getCommentBlock($iCmtId = 0)
  124. {
  125. return BxDolTemplate::getInstance()->parseHtmlByName('comment_block.html', array(
  126. 'system' => $this->_sSystem,
  127. 'id' => $this->getId(),
  128. 'comment' => $this->getComment($iCmtId, array('type' => $this->_sBrowseType), array('type' => BX_CMT_DISPLAY_THREADED)),
  129. 'script' => $this->getScript()
  130. ));
  131. }
  132. /**
  133. * get one just posted comment
  134. *
  135. * @param int $iCmtId - comment id
  136. * @return string
  137. */
  138. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  139. {
  140. $oTemplate = BxDolTemplate::getInstance();
  141. $iUserId = $this->_getAuthorId();
  142. $r = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  143. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($r['cmt_author_id']);
  144. $sClass = $sRet = '';
  145. if($r['cmt_rated'] == -1 || $r['cmt_rate'] < $this->_aSystem['viewing_threshold']) {
  146. $oTemplate->pareseHtmlByName('comment_hidden.html', array(
  147. 'js_object' => $this->_sJsObjName,
  148. 'id' => $r['cmt_id'],
  149. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  150. 'bx_if:show_replies' => array(
  151. 'condition' => $r['cmt_replies'] > 0,
  152. 'content' => array(
  153. 'replies' => _t('_Show N replies', $r['cmt_replies'])
  154. )
  155. )
  156. ));
  157. $sClass = ' cmt-hidden';
  158. }
  159. if($r['cmt_author_id'] == $iUserId)
  160. $sClass .= ' cmt-mine';
  161. $sActions = $this->_getActionsBox($r, $aDp);
  162. $sText = $r['cmt_text'];
  163. $sTextMore = '';
  164. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  165. if(strlen($sText) > $iMaxLength) {
  166. $iLength = strpos($sText, ' ', $iMaxLength);
  167. $sTextMore = trim(substr($sText, $iLength));
  168. $sText = trim(substr($sText, 0, $iLength));
  169. }
  170. $sText = $this->_prepareTextForOutput($sText);
  171. $sTextMore = $this->_prepareTextForOutput($sTextMore);
  172. $aTmplReplyTo = array();
  173. if((int)$r['cmt_parent_id'] != 0) {
  174. $aParent = $this->getCommentRow($r['cmt_parent_id']);
  175. list($sParAuthorName, $sParAuthorLink, $sParAuthorIcon) = $this->_getAuthorInfo($aParent['cmt_author_id']);
  176. $aTmplReplyTo = array(
  177. 'style_prefix' => $this->_sStylePrefix,
  178. 'par_cmt_link' => $this->getBaseUrl() . '#' . $this->_sSystem . $r['cmt_parent_id'],
  179. 'par_cmt_author' => $sParAuthorName
  180. );
  181. }
  182. $sReplies = '';
  183. if((int)$r['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED)
  184. $sReplies = $this->getComments(array('parent_id' => $r['cmt_id'], 'vparent_id' => $r['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' => $r['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' => $r['cmt_id']
  223. )),
  224. 'ago' => $r['cmt_ago'],
  225. 'bx_if:hide_rate_count' => array(
  226. 'condition' => (int)$r['cmt_rate'] <= 0,
  227. 'content' => array()
  228. ),
  229. 'points' => _t(in_array($r['cmt_rate'], array(-1, 0, 1)) ? '_N_point' : '_N_points', $r['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. 'actions' => $sActions,
  240. 'replies' => $sReplies
  241. ));
  242. }
  243. function getFormBox($aBp = array(), $aDp = array())
  244. {
  245. return $this->_getPostReplyBox($aBp, $aDp);
  246. }
  247. function getForm($iCmtParentId, $sText, $sFunction)
  248. {
  249. return $this->_getPostReplyForm($iCmtParentId, $sText, $sFunction);
  250. }
  251. function getPlusedBy($iCmtId)
  252. {
  253. $oTemplate = BxDolTemplate::getInstance();
  254. $aTmplUsers = array();
  255. $aUserIds = $this->_oQuery->getRatedBy($this->_aSystem['system_id'], $iCmtId);
  256. foreach($aUserIds as $iUserId) {
  257. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($iUserId);
  258. $aTmplUsers[] = array(
  259. 'style_prefix' => $this->_sStylePrefix,
  260. 'user_unit' => $sUserUnit
  261. );
  262. }
  263. $sContent = $oTemplate->parseHtmlByName('comment_pb_list.html', array(
  264. 'style_prefix' => $this->_sStylePrefix,
  265. 'bx_repeat:list' => $aTmplUsers
  266. ));
  267. bx_import('BxTemplStudioFunctions');
  268. $sContent = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('comment_manage.html', array(
  269. 'content' => $sContent
  270. )));
  271. return $oTemplate->parseHtmlByName('comment_plused_by.html', array(
  272. 'style_prefix' => $this->_sStylePrefix,
  273. 'id' => $this->_sSystem . '-plused-by' . $iCmtId,
  274. 'content' => $sContent
  275. ));
  276. }
  277. /**
  278. * private functions
  279. */
  280. function _getControlsBox()
  281. {
  282. $oTemplate = BxDolTemplate::getInstance();
  283. $sDisplay = '';
  284. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  285. if($bDisplay) {
  286. $aDisplayLinks = array(
  287. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  288. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  289. );
  290. bx_import('BxTemplMenuInteractive');
  291. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  292. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  293. $sDisplay = $oMenu->getCode();
  294. }
  295. $sBrowse = '';
  296. $bBrowse = (int)$this->_aSystem['is_browse_switch'] == 1;
  297. if($bBrowse) {
  298. $aBrowseLinks = array(
  299. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  300. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  301. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  302. array('id' => $this->_sSystem . '-connection', 'name' => $this->_sSystem . '-connection', 'class' => '', 'title' => '_cmt_browse_connection', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'connection\');')
  303. );
  304. bx_import('BxTemplMenuInteractive');
  305. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  306. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  307. $sBrowse = $oMenu->getCode();
  308. }
  309. return $oTemplate->parseHtmlByName('comments_controls.html', array(
  310. 'js_object' => $this->_sJsObjName,
  311. 'style_prefix' => $this->_sStylePrefix,
  312. 'comments_count' => _t('_N_comments', $this->_oQuery->getCommentsCount($this->_iId)),
  313. 'display_switcher' => $bDisplay ? $sDisplay : '',
  314. 'bx_if:is_divider' => array(
  315. 'condition' => $bDisplay && $bBrowse,
  316. 'content' => array(
  317. 'style_prefix' => $this->_sStylePrefix,
  318. )
  319. ),
  320. 'browse_switcher' => $bBrowse ? $sBrowse : '',
  321. ));
  322. }
  323. function _getActionsBox(&$a, $aDp = array())
  324. {
  325. $oTemplate = BxDolTemplate::getInstance();
  326. $iUserId = $this->_getAuthorId();
  327. $isEditAllowedPermanently = ($a['cmt_author_id'] == $iUserId && $this->isEditAllowed()) || $this->isEditAllowedAll();
  328. $isRemoveAllowedPermanently = ($a['cmt_author_id'] == $iUserId && $this->isRemoveAllowed()) || $this->isRemoveAllowedAll();
  329. $sManagePopupId = $sManagePopupText = '';
  330. if($isEditAllowedPermanently || $isRemoveAllowedPermanently) {
  331. $aMenu = array(
  332. array('name' => 'cmt-edit', 'icon' => '', 'onclick' => $this->_sJsObjName . ".cmtEdit(this, " . $a['cmt_id'] . ")", 'title' => _t('_Edit')),
  333. array('name' => 'cmt-delete', 'icon' => '', 'onclick' => $this->_sJsObjName . ".cmtRemove(this, " . $a['cmt_id'] . ")", 'title' => _t('_Delete')),
  334. );
  335. bx_import('BxTemplStudioMenu');
  336. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_vertical_lite.html', 'menu_items' => $aMenu));
  337. bx_import('BxTemplStudioFunctions');
  338. $sManagePopupText = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('comment_manage.html', array(
  339. 'content' => $oMenu->getCode()
  340. )));
  341. }
  342. $bRated = (int)$a['cmt_rated'] > 0;
  343. return $oTemplate->parseHtmlByName('comment_actions.html', array(
  344. 'id' => $a['cmt_id'],
  345. 'style_prefix' => $this->_sStylePrefix,
  346. 'view_link' => bx_append_url_params($this->_sViewUrl, array(
  347. 'sys' => $this->_sSystem,
  348. 'id' => $this->_iId,
  349. 'cmt_id' => $a['cmt_id']
  350. )),
  351. 'ago' => $a['cmt_ago'],
  352. 'points' => _t($a['cmt_rate'] == 1 || $a['cmt_rate'] == -1 ? '_N_point' : '_N_points', $a['cmt_rate']),
  353. 'bx_if:show_reply' => array(
  354. 'condition' => $this->isPostReplyAllowed(),
  355. 'content' => array(
  356. 'js_object' => $this->_sJsObjName,
  357. 'style_prefix' => $this->_sStylePrefix,
  358. 'id' => $a['cmt_id'],
  359. 'text' => _t(isset($a['cmt_type']) && $a['cmt_type'] == 'comment' ? '_Comment_to_this_comment' : '_Reply_to_this_comment')
  360. )
  361. ),
  362. 'bx_if:show_rate' => array(
  363. 'condition' => $this->isRatable() && $this->isRateAllowed(),
  364. 'content' => array(
  365. 'js_object' => $this->_sJsObjName,
  366. 'style_prefix' => $this->_sStylePrefix,
  367. 'id' => $a['cmt_id'],
  368. 'bx_if:hide_rate_plus' => array(
  369. 'condition' => $bRated,
  370. 'content' => array()
  371. ),
  372. 'bx_if:hide_rate_minus' => array(
  373. 'condition' => !$bRated,
  374. 'content' => array()
  375. )
  376. )
  377. ),
  378. 'bx_if:show_manage' => array(
  379. 'condition' => $isEditAllowedPermanently || $isRemoveAllowedPermanently,
  380. 'content' => array(
  381. 'js_object' => $this->_sJsObjName,
  382. 'style_prefix' => $this->_sStylePrefix,
  383. 'id' => $a['cmt_id'],
  384. 'popup_id' => $this->_sSystem . '-manage' . $a['cmt_id'],
  385. 'popup_text' => $sManagePopupText
  386. )
  387. )
  388. ));
  389. }
  390. function _getPostReplyBox($aBp, $aDp)
  391. {
  392. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  393. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  394. if(!$this->isPostReplyAllowed())
  395. return '';
  396. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo();
  397. $sPositionSystem = $this->_aSystem['post_form_position'];
  398. if(!empty($sPosition) && $sPositionSystem != BX_CMT_PFP_BOTH && $sPositionSystem != $sPosition)
  399. return '';
  400. $bAuthorIcon = !empty($sAuthorIcon);
  401. return BxDolTemplate::getInstance()->parseHtmlByName('comment_reply_box.html', array(
  402. 'style_prefix' => $this->_sStylePrefix,
  403. 'bx_if:show_class' => array(
  404. 'condition' => !empty($sPosition),
  405. 'content' => array(
  406. 'class' => $this->_sStylePrefix . '-reply-' . $sPosition
  407. )
  408. ),
  409. 'bx_if:show_icon' => array(
  410. 'condition' => $bAuthorIcon,
  411. 'content' => array(
  412. 'author_icon' => $sAuthorIcon
  413. )
  414. ),
  415. 'bx_if:show_icon_empty' => array(
  416. 'condition' => !$bAuthorIcon,
  417. 'content' => array()
  418. ),
  419. 'bx_if:show_author_link' => array(
  420. 'condition' => !empty($sAuthorLink),
  421. 'content' => array(
  422. 'author_link' => $sAuthorLink,
  423. 'author_name' => $sAuthorName
  424. )
  425. ),
  426. 'bx_if:show_author_text' => array(
  427. 'condition' => empty($sAuthorLink),
  428. 'content' => array(
  429. 'author_name' => $sAuthorName
  430. )
  431. ),
  432. 'form' => $this->_getPostReplyForm($iCmtParentId)
  433. ));
  434. }
  435. function _getPostReplyForm($iCmtParentId = 0, $sText = "", $sFunction = "cmtSubmit(this)")
  436. {
  437. $aForm = array(
  438. 'form_attrs' => array(
  439. 'name' => 'cmt-post-reply-' . $this->_sSystem,
  440. 'method' => 'post',
  441. 'onsubmit' => $this->_sJsObjName . '.' . $sFunction . '; return false;',
  442. 'class' => 'cmt-post-reply'
  443. ),
  444. 'params' => array (
  445. 'csrf' => array(
  446. 'disable' => true,
  447. )
  448. ),
  449. 'inputs' => array(
  450. 'CmtParent' => array(
  451. 'type' => 'hidden',
  452. 'name' => 'CmtParent',
  453. 'value' => $iCmtParentId
  454. ),
  455. 'CmtType' => array(
  456. 'type' => 'hidden',
  457. 'name' => 'CmtType',
  458. 'value' => 'text'
  459. ),
  460. 'CmtText' => array(
  461. 'type' => 'textarea',
  462. 'name' => 'CmtText',
  463. 'caption' => '',
  464. 'value' => $sText,
  465. 'required' => false,
  466. ),
  467. 'CmtSubmit' => array(
  468. 'type' => 'submit',
  469. 'name' => 'CmtSubmit',
  470. 'value' => _t('_Submit_Comment')
  471. )
  472. )
  473. );
  474. bx_import('BxTemplFormView');
  475. $oForm = new BxTemplFormView ($aForm);
  476. return $oForm->getCode();
  477. }
  478. function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  479. {
  480. $iStart = $iPerView = 0;
  481. switch($aBp['type']) {
  482. case BX_CMT_BROWSE_HEAD:
  483. case BX_CMT_BROWSE_POPULAR:
  484. case BX_CMT_BROWSE_CONNECTION:
  485. $iPerView = $aBp['per_view'];
  486. $iStart = $aBp['start'] + $iPerView;
  487. if($iStart >= $aBp['count'])
  488. return $sCmts;
  489. break;
  490. case BX_CMT_BROWSE_TAIL:
  491. $iPerView = $aBp['per_view'];
  492. $iStart = $aBp['start'] - $iPerView;
  493. if($iStart < 0) {
  494. $iPerView += $iStart;
  495. $iStart = 0;
  496. }
  497. if($iStart == 0 && $iPerView == 0)
  498. return $sCmts;
  499. break;
  500. }
  501. $bRoot = (int)$aBp['vparent_id'] <= 0;
  502. $sMore = BxDolTemplate::getInstance()->parseHtmlByName('comment_more.html', array(
  503. 'js_object' => $this->_sJsObjName,
  504. 'style_prefix' => $this->_sStylePrefix,
  505. 'bx_if:is_root' => array(
  506. 'condition' => $bRoot,
  507. 'content' => array()
  508. ),
  509. 'bx_if:is_button' => array(
  510. 'condition' => $bRoot,
  511. 'content' => array()
  512. ),
  513. 'parent_id' => $aBp['vparent_id'],
  514. 'start' => $iStart,
  515. 'per_view' => $iPerView,
  516. 'title' => _t('_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  517. ));
  518. switch($aBp['type']) {
  519. case BX_CMT_BROWSE_HEAD:
  520. case BX_CMT_BROWSE_POPULAR:
  521. case BX_CMT_BROWSE_CONNECTION:
  522. $sCmts .= $sMore;
  523. break;
  524. case BX_CMT_BROWSE_TAIL:
  525. $sCmts = $sMore . $sCmts;
  526. break;
  527. }
  528. return $sCmts;
  529. }
  530. function _getLevelGap($a, $aDp = array())
  531. {
  532. if($aDp['type'] != BX_CMT_DISPLAY_THREADED || !is_array($a) || !isset($a['cmt_level']))
  533. return 0;
  534. return 84 * ((int)$a['cmt_level'] <= $this->_iDpMaxLevel ? (int)$a['cmt_level'] : $this->_iDpMaxLevel);
  535. }
  536. function _getLevelGapByParent($iParentId, $aDp = array()) {
  537. if($aDp['type'] != BX_CMT_DISPLAY_THREADED || (int)$iParentId == 0)
  538. return 0;
  539. $a = $this->getCommentRow($iParentId);
  540. if(isset($a['cmt_level']))
  541. $a['cmt_level'] += 1;
  542. return $this->_getLevelGap($a, $aDp);
  543. }
  544. }