BxDolCmts.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. bx_import('BxDolAcl');
  10. define('BX_CMT_OLD_VOTES', 365*86400); ///< comment votes older than this number of seconds will be deleted automatically
  11. define('BX_CMT_ACTION_POST', 'post');
  12. define('BX_CMT_ACTION_EDIT', 'edit');
  13. define('BX_CMT_DISPLAY_FLAT', 'flat');
  14. define('BX_CMT_DISPLAY_THREADED', 'threaded');
  15. define('BX_CMT_BROWSE_HEAD', 'head');
  16. define('BX_CMT_BROWSE_TAIL', 'tail');
  17. define('BX_CMT_BROWSE_POPULAR', 'popular');
  18. define('BX_CMT_BROWSE_CONNECTION', 'connection');
  19. define('BX_CMT_ORDER_BY_DATE', 'date');
  20. define('BX_CMT_ORDER_BY_POPULAR', 'popular');
  21. define('BX_CMT_FILTER_ALL', 'all');
  22. define('BX_CMT_FILTER_OTHERS', 'others');
  23. define('BX_CMT_FILTER_FRIENDS', 'friends');
  24. define('BX_CMT_FILTER_SUBSCRIPTIONS', 'subscriptions');
  25. define('BX_CMT_ORDER_WAY_ASC', 'asc');
  26. define('BX_CMT_ORDER_WAY_DESC', 'desc');
  27. define('BX_CMT_PFP_TOP', 'top');
  28. define('BX_CMT_PFP_BOTTOM', 'bottom');
  29. define('BX_CMT_RATE_VALUE_PLUS', 1);
  30. define('BX_CMT_RATE_VALUE_MINUS', -1);
  31. /**
  32. * Comments for any content
  33. *
  34. * Related classes:
  35. * - BxDolCmtsQuery - comments database queries
  36. * - BxBaseCmts - comments base representation
  37. * - BxTemplCmts - custom template representation
  38. *
  39. * AJAX comments for any content.
  40. * Self moderated - users rate all comments, and if comment is
  41. * below viewing treshold it is hidden by default.
  42. *
  43. * To add comments section to your module you need to add a record to 'sys_objects_cmts' table:
  44. *
  45. * - ID - autoincremented id for internal usage
  46. * - ObjectName - your unique module name, with vendor prefix, lowercase and spaces are underscored
  47. * - TableCmts - table name where comments are stored
  48. * - Nl2br - convert new lines to <br /> on saving
  49. * - PerView - number of comments on a page
  50. * - IsRatable - 0 or 1 allow to rate comments or not
  51. * - ViewingThreshold - comment viewing treshost, if comment is below this number it is hidden by default
  52. * - IsOn - is this comment object enabled
  53. * - RootStylePrefix - toot comments style prefix, if you need root comments look different\
  54. * - ObjectVote - Vote object name to process comments' votes. May be empty if Comment Vote is not needed.
  55. * - TriggerTable - table to be updated upon each comment
  56. * - TriggerFieldId - TriggerTable table field with unique record id of
  57. * - TriggerFieldComments - TriggerTable table field with comments count, it will be updated automatically upon eaech comment
  58. * - ClassName - your custom class name if you need to override default class, this class must have the same constructor arguments
  59. * - ClassFile - file where your ClassName is stored.
  60. *
  61. * You can refer to BoonEx modules for sample record in this table.
  62. *
  63. *
  64. *
  65. * @section example Example of usage:
  66. * After filling in the table you can show comments section in any place, using the following code:
  67. *
  68. * @code
  69. * $o = new BxTemplCmts('value of ObjectName field', $iYourEntryId);
  70. * if ($o->isEnabled())
  71. * echo $o->getCommentsFirst ();
  72. * @endcode
  73. *
  74. * Please note that you never need to use BxDolCmts class directly, use BxTemplCmts instead.
  75. * Also if you override comments class with your own then make it child of BxTemplCmts class.
  76. *
  77. *
  78. *
  79. * @section acl Memberships/ACL:
  80. * - comments post
  81. * - comments edit own
  82. * - comments remove own
  83. * - comments edit all
  84. *
  85. *
  86. *
  87. * @section alerts Alerts:
  88. * Alerts type/unit - every module has own type/unit, it equals to ObjectName.
  89. *
  90. * The following alerts are rised
  91. *
  92. * - commentPost - comment was posted
  93. * - $iObjectId - entry id
  94. * - $iSenderId - author of comment
  95. * - $aExtra['comment_id'] - just added comment id
  96. *
  97. * - commentRemoved - comments was removed
  98. * - $iObjectId - entry id
  99. * - $iSenderId - comment deleter id
  100. * - $aExtra['comment_id'] - removed comment id
  101. *
  102. * - commentUpdated - comments was updated
  103. * - $iObjectId - entry id
  104. * - $iSenderId - comment deleter id
  105. * - $aExtra['comment_id'] - updated comment id
  106. *
  107. * - commentRated - comments was rated
  108. * - $iObjectId - entry id
  109. * - $iSenderId - comment rater id
  110. * - $aExtra['comment_id'] - rated comment id
  111. * - $aExtra['rate'] - comment rate 1 or -1
  112. *
  113. */
  114. class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContentInfoService
  115. {
  116. protected $_oQuery = null;
  117. protected $_oTemplate = null;
  118. protected $_sFormObject;
  119. protected $_sFormDisplayPost;
  120. protected $_sFormDisplayEdit;
  121. protected $_sConnObjFriends;
  122. protected $_sConnObjSubscriptions;
  123. protected $_sMenuObjManage;
  124. protected $_sMenuObjActions;
  125. protected $_sViewUrl = '';
  126. protected $_sBaseUrl = '';
  127. protected $_sListAnchor = '';
  128. protected $_sItemAnchor = '';
  129. protected $_sSystem = 'profile'; ///< current comment system name
  130. protected $_aSystem = array (); ///< current comments system array
  131. protected $_iId = 0; ///< obect id to be commented
  132. protected $_bHtml = false; ///< whether HTML formating is used during comment posting or not. Read Only!
  133. protected $_aT = array (); ///< an array of lang keys
  134. protected $_aMarkers = array ();
  135. protected $_sDisplayType = '';
  136. protected $_sDpSessionKey = '';
  137. protected $_iDpMaxLevel = 0;
  138. protected $_sBrowseType = '';
  139. protected $_bBrowseFilter = false;
  140. protected $_sBrowseFilter = '';
  141. protected $_sBpSessionKeyType = '';
  142. protected $_sBpSessionKeyFilter = '';
  143. protected $_aOrder = array();
  144. protected $_sSnippetLenthLiveSearch = 50;
  145. protected $_iRememberTime = 2592000;
  146. /**
  147. * Constructor
  148. * $sSystem - comments system name
  149. * $iId - obect id to be commented
  150. */
  151. protected function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  152. {
  153. parent::__construct();
  154. $this->_aSystems = $this->getSystems();
  155. if(!isset($this->_aSystems[$sSystem]))
  156. return;
  157. $this->_sSystem = $sSystem;
  158. $this->_aSystem = $this->_aSystems[$sSystem];
  159. $this->_aSystem['table_images'] = 'sys_cmts_images';
  160. $this->_aSystem['table_images2entries'] = 'sys_cmts_images2entries';
  161. $this->_aSystem['table_ids'] = 'sys_cmts_ids';
  162. $this->_aSystem['is_browse_filter'] = (int)$this->_bBrowseFilter;
  163. $this->_iDpMaxLevel = (int)$this->_aSystem['number_of_levels'];
  164. $this->_sDisplayType = $this->_iDpMaxLevel == 0 ? BX_CMT_DISPLAY_FLAT : BX_CMT_DISPLAY_THREADED;
  165. $this->_sDpSessionKey = 'bx_' . $this->_sSystem . '_dp_';
  166. $this->_sBrowseType = $this->_aSystem['browse_type'];
  167. $this->_sBrowseFilter = BX_CMT_FILTER_ALL;
  168. $this->_sBpSessionKeyType = 'bx_' . $this->_sSystem . '_bpt_';
  169. $this->_sBpSessionKeyFilter = 'bx_' . $this->_sSystem . '_bpf_';
  170. $this->_aOrder = array(
  171. 'by' => BX_CMT_ORDER_BY_DATE,
  172. 'way' => BX_CMT_ORDER_WAY_ASC
  173. );
  174. list($mixedUserDp, $mixedUserBpType, $mixedUserBpFilter) = $this->_getUserChoice();
  175. if(!empty($mixedUserDp))
  176. $this->_sDisplayType = $mixedUserDp;
  177. if(!empty($mixedUserBpType))
  178. $this->_sBrowseType = $mixedUserBpType;
  179. if(!empty($mixedUserBpFilter))
  180. $this->_sBrowseFilter = $mixedUserBpFilter;
  181. $this->_sViewUrl = BX_DOL_URL_ROOT . 'cmts.php';
  182. $this->_sBaseUrl = BxDolPermalinks::getInstance()->permalink($this->_aSystem['base_url']);
  183. if(get_mb_substr($this->_sBaseUrl, 0, 4) != 'http')
  184. $this->_sBaseUrl = BX_DOL_URL_ROOT . $this->_sBaseUrl;
  185. $this->_sListAnchor = "cmts-anchor-%s-%d";
  186. $this->_sItemAnchor = "cmt-anchor-%s-%d-%d";
  187. $this->_oQuery = new BxDolCmtsQuery($this);
  188. $this->_sFormObject = 'sys_comment';
  189. $this->_sFormDisplayPost = 'sys_comment_post';
  190. $this->_sFormDisplayEdit = 'sys_comment_edit';
  191. $this->_sConnObjFriends = 'sys_profiles_friends';
  192. $this->_sConnObjSubscriptions = 'sys_profiles_subscriptions';
  193. $this->_sMenuObjManage = 'sys_cmts_item_manage';
  194. $this->_sMenuObjActions = 'sys_cmts_item_actions';
  195. $this->_sMetatagsObj = 'sys_cmts';
  196. $this->_aT = array(
  197. 'block_comments_title' => '_cmt_block_comments_title'
  198. );
  199. if ($iInit)
  200. $this->init($iId);
  201. if ($oTemplate)
  202. $this->_oTemplate = $oTemplate;
  203. else
  204. $this->_oTemplate = BxDolTemplate::getInstance();
  205. }
  206. /**
  207. * get comments object instanse
  208. * @param $sSys comments object name
  209. * @param $iId associated content id, where comments are postred in
  210. * @param $iInit perform initialization
  211. * @return null on error, or ready to use class instance
  212. */
  213. public static function getObjectInstance($sSys, $iId, $iInit = true, $oTemplate = false)
  214. {
  215. if(isset($GLOBALS['bxDolClasses']['BxDolCmts!' . $sSys . $iId]))
  216. return $GLOBALS['bxDolClasses']['BxDolCmts!' . $sSys . $iId];
  217. $aSystems = self::getSystems();
  218. if (!isset($aSystems[$sSys]))
  219. return null;
  220. $sClassName = 'BxTemplCmts';
  221. if(!empty($aSystems[$sSys]['class_name'])) {
  222. $sClassName = $aSystems[$sSys]['class_name'];
  223. if(!empty($aSystems[$sSys]['class_file']))
  224. require_once(BX_DIRECTORY_PATH_ROOT . $aSystems[$sSys]['class_file']);
  225. }
  226. $o = new $sClassName($sSys, $iId, $iInit, $oTemplate);
  227. return ($GLOBALS['bxDolClasses']['BxDolCmts!' . $sSys . $iId] = $o);
  228. }
  229. public static function &getSystems ()
  230. {
  231. $sKey = 'bx_dol_cache_memory_cmts_systems';
  232. if (!isset($GLOBALS[$sKey])) {
  233. $GLOBALS[$sKey] = BxDolDb::getInstance()->fromCache('sys_objects_cmts', 'getAllWithKey', '
  234. SELECT
  235. `ID` as `system_id`,
  236. `Name` AS `name`,
  237. `Module` AS `module`,
  238. `Table` AS `table`,
  239. `CharsPostMin` AS `chars_post_min`,
  240. `CharsPostMax` AS `chars_post_max`,
  241. `CharsDisplayMax` AS `chars_display_max`,
  242. `Nl2br` AS `nl2br`,
  243. `PerView` AS `per_view`,
  244. `PerViewReplies` AS `per_view_replies`,
  245. `BrowseType` AS `browse_type`,
  246. `IsBrowseSwitch` AS `is_browse_switch`,
  247. `PostFormPosition` AS `post_form_position`,
  248. `NumberOfLevels` AS `number_of_levels`,
  249. `IsDisplaySwitch` AS `is_display_switch`,
  250. `IsRatable` AS `is_ratable`,
  251. `ViewingThreshold` AS `viewing_threshold`,
  252. `IsOn` AS `is_on`,
  253. `RootStylePrefix` AS `root_style_prefix`,
  254. `BaseUrl` AS `base_url`,
  255. `ObjectVote` AS `object_vote`,
  256. `TriggerTable` AS `trigger_table`,
  257. `TriggerFieldId` AS `trigger_field_id`,
  258. `TriggerFieldAuthor` AS `trigger_field_author`,
  259. `TriggerFieldTitle` AS `trigger_field_title`,
  260. `TriggerFieldComments` AS `trigger_field_comments`,
  261. `ClassName` AS `class_name`,
  262. `ClassFile` AS `class_file`
  263. FROM `sys_objects_cmts`', 'name');
  264. }
  265. return $GLOBALS[$sKey];
  266. }
  267. public function init ($iId)
  268. {
  269. if (empty($this->iId) && $iId)
  270. $this->setId($iId);
  271. $this->addMarkers(array(
  272. 'object_id' => $this->getId(),
  273. 'user_id' => $this->_getAuthorId()
  274. ));
  275. }
  276. public function getId ()
  277. {
  278. return $this->_iId;
  279. }
  280. public function isEnabled ()
  281. {
  282. return isset($this->_aSystem['is_on']) && $this->_aSystem['is_on'];
  283. }
  284. public function getSystemId()
  285. {
  286. return $this->_aSystem['system_id'];
  287. }
  288. public function getSystemName()
  289. {
  290. return $this->_sSystem;
  291. }
  292. public function getStorageObjectName()
  293. {
  294. return $this->_getFormObject()->getStorageObjectName();
  295. }
  296. public function getTranscoderPreviewName()
  297. {
  298. return $this->_getFormObject()->getTranscoderPreviewName();
  299. }
  300. public function getSystemInfo()
  301. {
  302. return $this->_aSystem;
  303. }
  304. public function getMaxLevel()
  305. {
  306. return $this->_iDpMaxLevel;
  307. }
  308. public function getOrder ()
  309. {
  310. return $this->_sOrder;
  311. }
  312. public function getPerView ($iCmtParentId = 0)
  313. {
  314. return $iCmtParentId == 0 ? $this->_aSystem['per_view'] : $this->_aSystem['per_view_replies'];
  315. }
  316. public function getViewUrl($iCmtId)
  317. {
  318. if(empty($this->_aSystem['trigger_field_title']))
  319. return '';
  320. return bx_append_url_params($this->_sViewUrl, array(
  321. 'sys' => $this->_sSystem,
  322. 'id' => $this->_iId,
  323. 'cmt_id' => $iCmtId
  324. ));
  325. }
  326. public function getBaseUrl()
  327. {
  328. return $this->_replaceMarkers($this->_sBaseUrl);
  329. }
  330. public function getListUrl()
  331. {
  332. $sBaseUrl = $this->getBaseUrl();
  333. if(empty($sBaseUrl))
  334. return '';
  335. return $sBaseUrl . $this->getListAnchor(true);
  336. }
  337. public function getItemUrl($iItemId)
  338. {
  339. $sBaseUrl = $this->getBaseUrl();
  340. if(empty($sBaseUrl))
  341. return '';
  342. return $sBaseUrl . $this->getItemAnchor($iItemId, true);
  343. }
  344. public function getListAnchor($bWithHash = false)
  345. {
  346. return ($bWithHash ? '#' : '') . sprintf($this->_sListAnchor, str_replace('_', '-', $this->getSystemName()), $this->getId());
  347. }
  348. public function getItemAnchor($iItemId, $bWithHash = false)
  349. {
  350. return ($bWithHash ? '#' : '') . sprintf($this->_sItemAnchor, str_replace('_', '-', $this->getSystemName()), $this->getId(), $iItemId);
  351. }
  352. public function getConnectionObject($sType)
  353. {
  354. $sResult = '';
  355. switch($sType) {
  356. case BX_CMT_FILTER_FRIENDS:
  357. $sResult = $this->_sConnObjFriends;
  358. break;
  359. case BX_CMT_FILTER_SUBSCRIPTIONS:
  360. $sResult = $this->_sConnObjSubscriptions;
  361. break;
  362. }
  363. return $sResult;
  364. }
  365. public function getVoteObject($iId)
  366. {
  367. if(empty($this->_aSystem['object_vote']))
  368. $this->_aSystem['object_vote'] = 'sys_cmts';
  369. $oVote = BxDolVote::getObjectInstance($this->_aSystem['object_vote'], $iId, true, $this->_oTemplate);
  370. if(!$oVote || !$oVote->isEnabled())
  371. return false;
  372. return $oVote;
  373. }
  374. public function getNotificationId()
  375. {
  376. return 'cmts-notification-' . $this->_sSystem . '-' . $this->_iId;
  377. }
  378. public function setTableNameFiles($sTable)
  379. {
  380. $this->_aSystem['table_images'] = $sTable;
  381. $this->_oQuery->setTableNameFiles($sTable);
  382. }
  383. public function setTableNameFiles2Entries($sTable)
  384. {
  385. $this->_aSystem['table_images2entries'] = $sTable;
  386. $this->_oQuery->setTableNameFiles2Entries($sTable);
  387. }
  388. public function isNl2br ()
  389. {
  390. return $this->_aSystem['nl2br'];
  391. }
  392. public function isRatable ()
  393. {
  394. return $this->_aSystem['is_ratable'];
  395. }
  396. public function isAttachImageEnabled()
  397. {
  398. return true;
  399. }
  400. /**
  401. * set id to operate with votes
  402. */
  403. public function setId ($iId)
  404. {
  405. if ($iId == $this->getId()) return;
  406. $this->_iId = $iId;
  407. }
  408. /**
  409. * Add replace markers.
  410. * @param $a array of markers as key => value
  411. * @return true on success or false on error
  412. */
  413. public function addMarkers ($a)
  414. {
  415. if (empty($a) || !is_array($a))
  416. return false;
  417. $this->_aMarkers = array_merge ($this->_aMarkers, $a);
  418. return true;
  419. }
  420. /**
  421. * Database functions
  422. */
  423. public function getQueryObject ()
  424. {
  425. return $this->_oQuery;
  426. }
  427. public function getCommentsTableName ()
  428. {
  429. return $this->_oQuery->getTableName ();
  430. }
  431. public function getObjectAuthorId ($iObjectId = 0)
  432. {
  433. if(empty($this->_aSystem['trigger_field_author']))
  434. return 0;
  435. return $this->_oQuery->getObjectAuthorId ($iObjectId ? $iObjectId : $this->getId());
  436. }
  437. public function getObjectTitle ($iObjectId = 0)
  438. {
  439. if(empty($this->_aSystem['trigger_field_title']))
  440. return '';
  441. return $this->_oQuery->getObjectTitle ($iObjectId ? $iObjectId : $this->getId());
  442. }
  443. public function getCommentsCountAll ($iObjectId = 0)
  444. {
  445. return $this->_oQuery->getCommentsCountAll ($iObjectId ? $iObjectId : $this->getId());
  446. }
  447. public function getCommentsCount ($iObjectId = 0, $iCmtVParentId = -1, $sFilter = '')
  448. {
  449. return $this->_oQuery->getCommentsCount ($iObjectId ? $iObjectId : $this->getId(), $iCmtVParentId, $this->_getAuthorId(), $sFilter);
  450. }
  451. public function getCommentsArray ($iVParentId, $sFilter, $aOrder, $iStart = 0, $iCount = -1)
  452. {
  453. return $this->_oQuery->getComments ($this->getId(), $iVParentId, $this->_getAuthorId(), $sFilter, $aOrder, $iStart, $iCount);
  454. }
  455. public function getCommentRow ($iCmtId)
  456. {
  457. return $this->_oQuery->getComment ($this->getId(), $iCmtId);
  458. }
  459. public function onObjectDelete ($iObjectId = 0)
  460. {
  461. // delete comments
  462. $aFiles = $aCmtIds = array();
  463. $this->_oQuery->deleteObjectComments ($iObjectId ? $iObjectId : $this->getId(), $aFiles, $aCmtIds);
  464. // delete meta info
  465. $this->deleteMetaInfo($aCmtIds);
  466. // delete files
  467. if ($aFiles) {
  468. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  469. if ($oStorage)
  470. $oStorage->queueFilesForDeletion($aFiles);
  471. }
  472. }
  473. public static function onAuthorDelete ($iAuthorId)
  474. {
  475. $aSystems = self::getSystems();
  476. foreach($aSystems as $sSystem => $aSystem) {
  477. $o = self::getObjectInstance($sSystem, 0);
  478. $oQuery = $o->getQueryObject();
  479. // delete comments
  480. $aFiles = $aCmtIds = array ();
  481. $oQuery->deleteAuthorComments($iAuthorId, $aFiles, $aCmtIds);
  482. // delete meta info
  483. $o->deleteMetaInfo($aCmtIds);
  484. // delete files
  485. $oStorage = BxDolStorage::getObjectInstance($o->getStorageObjectName());
  486. if ($oStorage)
  487. $oStorage->queueFilesForDeletion($aFiles);
  488. }
  489. return true;
  490. }
  491. public static function onModuleEnable ($sModuleName)
  492. {
  493. $aSystems = self::getSystems();
  494. foreach($aSystems as $sSystem => $aSystem) {
  495. if ($sModuleName !== $aSystem['module'])
  496. continue;
  497. $o = self::getObjectInstance($sSystem, 0);
  498. $o->registerTranscoders();
  499. }
  500. return true;
  501. }
  502. public static function onModuleDisable ($sModuleName)
  503. {
  504. $aSystems = self::getSystems();
  505. foreach($aSystems as $sSystem => $aSystem) {
  506. if ($sModuleName !== $aSystem['module'])
  507. continue;
  508. $o = self::getObjectInstance($sSystem, 0);
  509. $o->unregisterTranscoders();
  510. }
  511. return true;
  512. }
  513. public static function onModuleUninstall ($sModuleName, &$iFiles = null)
  514. {
  515. $aSystems = self::getSystems();
  516. foreach($aSystems as $sSystem => $aSystem) {
  517. if ($sModuleName !== $aSystem['module'])
  518. continue;
  519. $o = self::getObjectInstance($sSystem, 0);
  520. $oQuery = $o->getQueryObject();
  521. // delete comments
  522. $aFiles = $aCmtIds = array ();
  523. $oQuery->deleteAll($aSystem['system_id'], $aFiles, $aCmtIds);
  524. // delete meta info
  525. $o->deleteMetaInfo($aCmtIds);
  526. // delete files
  527. $oStorage = BxDolStorage::getObjectInstance($o->getStorageObjectName());
  528. if ($oStorage && $aFiles)
  529. $oStorage->queueFilesForDeletion($aFiles);
  530. if (null !== $iFiles)
  531. $iFiles += count($aFiles);
  532. }
  533. return true;
  534. }
  535. public function deleteMetaInfo ($mixedCmtId)
  536. {
  537. if (!$this->_sMetatagsObj)
  538. return;
  539. if (!is_array($mixedCmtId))
  540. $mixedCmtId = array($mixedCmtId);
  541. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  542. foreach ($mixedCmtId as $iCmtId) {
  543. $oMetatags->onDeleteContent($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId));
  544. $this->_oQuery->deleteCmtIds($this->_aSystem['system_id'], $iCmtId);
  545. }
  546. }
  547. /**
  548. * Permissions functions
  549. */
  550. public function checkAction ($sAction, $isPerformAction = false)
  551. {
  552. $iId = $this->_getAuthorId();
  553. $a = checkActionModule($iId, $sAction, 'system', $isPerformAction);
  554. return $a[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  555. }
  556. public function checkActionErrorMsg ($sAction)
  557. {
  558. $iId = $this->_getAuthorId();
  559. $a = checkActionModule($iId, $sAction, 'system');
  560. return $a[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $a[CHECK_ACTION_MESSAGE] : '';
  561. }
  562. public function isViewAllowed ($isPerformAction = false)
  563. {
  564. $mixedResult = BxDolService::call($this->_aSystem['module'], 'check_allowed_comments_view', array($this->getId(), $this->getSystemName()));
  565. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  566. return $mixedResult;
  567. return CHECK_ACTION_RESULT_ALLOWED;
  568. }
  569. public function isVoteAllowed ($aCmt, $isPerformAction = false)
  570. {
  571. if(!$this->isRatable())
  572. return false;
  573. $oVote = $this->getVoteObject($aCmt['cmt_id']);
  574. if($oVote === false)
  575. return false;
  576. $iUserId = (int)$this->_getAuthorId();
  577. if($iUserId == 0)
  578. return false;
  579. if(isAdmin())
  580. return true;
  581. return $oVote->isAllowedVote($isPerformAction);
  582. }
  583. public function isPostReplyAllowed ($isPerformAction = false)
  584. {
  585. $mixedResult = BxDolService::call($this->_aSystem['module'], 'check_allowed_comments_post', array($this->getId(), $this->getSystemName()));
  586. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  587. return false;
  588. return $this->checkAction ('comments post', $isPerformAction);
  589. }
  590. public function msgErrPostReplyAllowed ()
  591. {
  592. return $this->checkActionErrorMsg('comments post');
  593. }
  594. public function isEditAllowed ($aCmt, $isPerformAction = false)
  595. {
  596. if(isAdmin())
  597. return true;
  598. if($this->checkAction('comments edit all', $isPerformAction))
  599. return true;
  600. $mixedResult = BxDolService::call($this->_aSystem['module'], 'check_allowed_comments_post', array($this->getId(), $this->getSystemName()));
  601. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  602. return false;
  603. return $aCmt['cmt_author_id'] == $this->_getAuthorId() && $this->checkAction ('comments edit own', $isPerformAction);
  604. }
  605. public function msgErrEditAllowed ()
  606. {
  607. return $this->checkActionErrorMsg ('comments edit own');
  608. }
  609. public function isRemoveAllowed ($aCmt, $isPerformAction = false)
  610. {
  611. if(isAdmin())
  612. return true;
  613. if($aCmt['cmt_author_id'] == $this->_getAuthorId() && $this->checkAction ('comments remove own', $isPerformAction))
  614. return true;
  615. return $this->checkAction ('comments remove all', $isPerformAction);
  616. }
  617. public function msgErrRemoveAllowed ()
  618. {
  619. return $this->checkActionErrorMsg('comments remove own');
  620. }
  621. /**
  622. * Actions functions
  623. */
  624. public function actionGetFormPost ()
  625. {
  626. if (!$this->isEnabled())
  627. return '';
  628. $iCmtParentId= isset($_REQUEST['CmtParent']) ? bx_process_input($_REQUEST['CmtParent'], BX_DATA_INT) : 0;
  629. $sCmtBrowse = isset($_REQUEST['CmtBrowse']) ? bx_process_input($_REQUEST['CmtBrowse'], BX_DATA_TEXT) : '';
  630. $sCmtDisplay = isset($_REQUEST['CmtDisplay']) ? bx_process_input($_REQUEST['CmtDisplay'], BX_DATA_TEXT) : '';
  631. return $this->getFormBoxPost(array('parent_id' => $iCmtParentId, 'type' => $sCmtBrowse), array('type' => $sCmtDisplay, 'dynamic_mode' => true));
  632. }
  633. public function actionGetFormEdit ()
  634. {
  635. if (!$this->isEnabled()){
  636. echoJson(array());
  637. return;
  638. }
  639. $iCmtId = bx_process_input(bx_get('Cmt'), BX_DATA_INT);
  640. echoJson($this->getFormEdit($iCmtId, array('dynamic_mode' => true)));
  641. }
  642. public function actionGetCmt ()
  643. {
  644. if (!$this->isEnabled())
  645. return '';
  646. if($this->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  647. return '';
  648. $iCmtId = bx_process_input($_REQUEST['Cmt'], BX_DATA_INT);
  649. $sCmtBrowse = isset($_REQUEST['CmtBrowse']) ? bx_process_input($_REQUEST['CmtBrowse'], BX_DATA_TEXT) : '';
  650. $sCmtDisplay = isset($_REQUEST['CmtDisplay']) ? bx_process_input($_REQUEST['CmtDisplay'], BX_DATA_TEXT) : '';
  651. $aCmt = $this->getCommentRow($iCmtId);
  652. echoJson(array(
  653. 'parent_id' => $aCmt['cmt_parent_id'],
  654. 'vparent_id' => $aCmt['cmt_vparent_id'],
  655. 'content' => $this->getComment($aCmt, array('type' => $sCmtBrowse), array('type' => $sCmtDisplay, 'dynamic_mode' => true))
  656. ));
  657. }
  658. public function actionGetCmts ()
  659. {
  660. if (!$this->isEnabled())
  661. return '';
  662. if($this->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  663. return '';
  664. $aBp = $aDp = array();
  665. $this->_getParams($aBp, $aDp);
  666. $aDp['dynamic_mode'] = true;
  667. return $this->getComments($aBp, $aDp);
  668. }
  669. public function actionSubmitPostForm()
  670. {
  671. if(!$this->isEnabled() || !$this->isPostReplyAllowed()) {
  672. echoJson(array());
  673. return;
  674. }
  675. $iCmtParentId = 0;
  676. if(bx_get('cmt_parent_id') !== false)
  677. $iCmtParentId = bx_process_input(bx_get('cmt_parent_id'), BX_DATA_INT);
  678. echoJson($this->getFormPost($iCmtParentId, array('dynamic_mode' => true)));
  679. }
  680. public function actionSubmitEditForm()
  681. {
  682. if (!$this->isEnabled()) {
  683. echoJson(array());
  684. return;
  685. };
  686. $iCmtId = 0;
  687. if(bx_get('cmt_id') !== false)
  688. $iCmtId = bx_process_input(bx_get('cmt_id'), BX_DATA_INT);
  689. echoJson($this->getFormEdit($iCmtId, array('dynamic_mode' => true)));
  690. }
  691. public function actionRemove()
  692. {
  693. if (!$this->isEnabled()) {
  694. echoJson(array());
  695. return;
  696. };
  697. $iObjId = $this->getId();
  698. $iObjAthrId = $this->getObjectAuthorId($iObjId);
  699. $iCmtId = 0;
  700. if(bx_get('Cmt') !== false)
  701. $iCmtId = bx_process_input(bx_get('Cmt'), BX_DATA_INT);
  702. $aCmt = $this->_oQuery->getCommentSimple ($iObjId, $iCmtId);
  703. if(!$aCmt) {
  704. echoJson(array('msg' => _t('_No such comment')));
  705. return;
  706. }
  707. if ($aCmt['cmt_replies'] > 0) {
  708. echoJson(array('msg' => _t('_Can not delete comments with replies')));
  709. return;
  710. }
  711. $iPerformerId = $this->_getAuthorId();
  712. if(!$this->isRemoveAllowed($aCmt)) {
  713. echoJson(array('msg' => $aCmt['cmt_author_id'] == $iPerformerId ? strip_tags($this->msgErrRemoveAllowed()) : _t('_Access denied')));
  714. return;
  715. }
  716. if($this->_oQuery->removeComment($iObjId, $iCmtId, $aCmt['cmt_parent_id'])) {
  717. $this->_triggerComment();
  718. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  719. $aImages = $this->_oQuery->getFiles($this->_aSystem['system_id'], $iCmtId);
  720. foreach($aImages as $aImage)
  721. $oStorage->deleteFile($aImage['image_id']);
  722. $this->_oQuery->deleteImages($this->_aSystem['system_id'], $iCmtId);
  723. $this->isRemoveAllowed(true);
  724. $this->deleteMetaInfo ($iCmtId);
  725. bx_alert($this->_sSystem, 'commentRemoved', $iObjId, $iPerformerId, array(
  726. 'object_author_id' => $iObjAthrId,
  727. 'comment_id' => $iCmtId,
  728. 'comment_author_id' => $aCmt['cmt_author_id']
  729. ));
  730. bx_alert('comment', 'deleted', $iCmtId, $iPerformerId, array(
  731. 'object_system' => $this->_sSystem,
  732. 'object_id' => $iObjId,
  733. 'object_author_id' => $iObjAthrId,
  734. 'comment_author_id' => $aCmt['cmt_author_id']
  735. ));
  736. if(!empty($aCmt['cmt_parent_id'])) {
  737. $iCmtPrntId = (int)$aCmt['cmt_parent_id'];
  738. $aCmtPrnt = $this->_oQuery->getCommentSimple($iObjId, $iCmtPrntId);
  739. if(!empty($aCmtPrnt) && is_array($aCmtPrnt)) {
  740. bx_alert($this->_sSystem, 'replyRemoved', $iCmtPrntId, $iPerformerId, array(
  741. 'object_id' => $iObjId,
  742. 'object_author_id' => $iObjAthrId,
  743. 'parent_author_id' => $aCmtPrnt['cmt_author_id'],
  744. 'comment_id' => $iCmtId,
  745. 'comment_author_id' => $aCmt['cmt_author_id'],
  746. ));
  747. bx_alert('reply', 'deleted', $iCmtId, $iPerformerId, array(
  748. 'object_system' => $this->_sSystem,
  749. 'object_id' => $iObjId,
  750. 'object_author_id' => $iObjAthrId,
  751. 'parent_id' => $iCmtPrntId,
  752. 'parent_author_id' => $aCmtPrnt['cmt_author_id'],
  753. 'comment_author_id' => $aCmt['cmt_author_id'],
  754. ));
  755. }
  756. }
  757. echoJson(array('id' => $iCmtId));
  758. return;
  759. }
  760. echoJson(array('msg' => _t('_cmt_err_cannot_perform_action')));
  761. }
  762. public function actionResumeLiveUpdate()
  763. {
  764. $sKey = $this->getNotificationId();
  765. bx_import('BxDolSession');
  766. BxDolSession::getInstance()->unsetValue($sKey);
  767. }
  768. public function actionPauseLiveUpdate()
  769. {
  770. $sKey = $this->getNotificationId();
  771. bx_import('BxDolSession');
  772. BxDolSession::getInstance()->setValue($sKey, 1);
  773. }
  774. public function onPostAfter($iCmtId)
  775. {
  776. $iObjId = (int)$this->getId();
  777. $iObjAthrId = $this->getObjectAuthorId($iObjId);
  778. $aCmt = $this->_oQuery->getCommentSimple($iObjId, $iCmtId);
  779. if(empty($aCmt) || !is_array($aCmt))
  780. return false;
  781. $iPerformerId = (int)$aCmt['cmt_author_id'];
  782. bx_alert($this->_sSystem, 'commentPost', $iObjId, $iPerformerId, array(
  783. 'object_author_id' => $iObjAthrId,
  784. 'comment_id' => $iCmtId,
  785. 'comment_author_id' => $aCmt['cmt_author_id'],
  786. 'comment_text' => $aCmt['cmt_text']
  787. ));
  788. bx_alert('comment', 'added', $iCmtId, $iPerformerId, array(
  789. 'object_system' => $this->_sSystem,
  790. 'object_id' => $iObjId,
  791. 'object_author_id' => $iObjAthrId,
  792. 'comment_author_id' => $aCmt['cmt_author_id'],
  793. 'comment_text' => $aCmt['cmt_text']
  794. ));
  795. if(!empty($aCmt['cmt_parent_id'])) {
  796. $iCmtPrntId = (int)$aCmt['cmt_parent_id'];
  797. $aCmtPrnt = $this->_oQuery->getCommentSimple($iObjId, $iCmtPrntId);
  798. if(!empty($aCmtPrnt) && is_array($aCmtPrnt)) {
  799. bx_alert($this->_sSystem, 'replyPost', $iCmtPrntId, $iPerformerId, array(
  800. 'object_id' => $iObjId,
  801. 'object_author_id' => $iObjAthrId,
  802. 'parent_author_id' => $aCmtPrnt['cmt_author_id'],
  803. 'comment_id' => $iCmtId,
  804. 'comment_author_id' => $aCmt['cmt_author_id'],
  805. 'comment_text' => $aCmt['cmt_text']
  806. ));
  807. bx_alert('comment', 'replied', $iCmtId, $iPerformerId, array(
  808. 'object_system' => $this->_sSystem,
  809. 'object_id' => $iObjId,
  810. 'object_author_id' => $iObjAthrId,
  811. 'parent_id' => $iCmtPrntId,
  812. 'parent_author_id' => $aCmtPrnt['cmt_author_id'],
  813. 'comment_author_id' => $aCmt['cmt_author_id'],
  814. 'comment_text' => $aCmt['cmt_text']
  815. ));
  816. }
  817. }
  818. return true;
  819. }
  820. public function onEditAfter($iCmtId)
  821. {
  822. $iObjId = (int)$this->getId();
  823. $iObjAthrId = $this->getObjectAuthorId($iObjId);
  824. $aCmt = $this->_oQuery->getCommentSimple($iObjId, $iCmtId);
  825. if(empty($aCmt) || !is_array($aCmt))
  826. return false;
  827. $iPerformerId = $this->_getAuthorId();
  828. bx_alert($this->_sSystem, 'commentUpdated', $iObjId, $iPerformerId, array(
  829. 'object_author_id' => $iObjAthrId,
  830. 'comment_id' => $iCmtId,
  831. 'comment_author_id' => $aCmt['cmt_author_id'],
  832. 'comment_text' => $aCmt['cmt_text']
  833. ));
  834. bx_alert('comment', 'edited', $iCmtId, $iPerformerId, array(
  835. 'object_system' => $this->_sSystem,
  836. 'object_id' => $iObjId,
  837. 'object_author_id' => $iObjAthrId,
  838. 'comment_author_id' => $aCmt['cmt_author_id'],
  839. 'comment_text' => $aCmt['cmt_text']
  840. ));
  841. return true;
  842. }
  843. public function serviceGetAuthor ($iContentId)
  844. {
  845. $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
  846. $this->setId($aComment['cmt_object_id']);
  847. return $aComment['cmt_author_id'];
  848. }
  849. public function serviceGetDateAdded ($iContentId)
  850. {
  851. $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
  852. $this->setId($aComment['cmt_object_id']);
  853. return $aComment['cmt_time'];
  854. }
  855. public function serviceGetDateChanged ($iContentId)
  856. {
  857. return 0;
  858. }
  859. public function serviceGetLink ($iContentId)
  860. {
  861. $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
  862. $this->setId($aComment['cmt_object_id']);
  863. return $this->getViewUrl($iContentId);
  864. }
  865. public function serviceGetTitle ($iContentId)
  866. {
  867. return '';
  868. }
  869. public function serviceGetText ($iContentId)
  870. {
  871. $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
  872. $this->setId($aComment['cmt_object_id']);
  873. return $aComment['cmt_text'];
  874. }
  875. public function serviceGetThumb ($iContentId)
  876. {
  877. return '';
  878. }
  879. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  880. {
  881. $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
  882. $this->setId($aComment['cmt_object_id']);
  883. return BxDolContentInfo::formatFields($aComment);
  884. }
  885. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  886. {
  887. $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
  888. if(empty($aComment) || !is_array($aComment))
  889. return '';
  890. $this->setId($aComment['cmt_object_id']);
  891. return $this->getComment($aComment, array(), array('type' => BX_CMT_DISPLAY_FLAT, 'view_only' => true));
  892. }
  893. public function serviceGetAll ($aParams = array())
  894. {
  895. if(empty($aParams) || !is_array($aParams))
  896. $aParams = array('type' => 'all');
  897. return $this->_oQuery->getCommentsBy($aParams);
  898. }
  899. public function serviceGetSearchableFieldsExtended()
  900. {
  901. $oForm = BxDolForm::getObjectInstance('sys_comment', 'sys_comment_post', $this->_oTemplate);
  902. if(!$oForm)
  903. return array();
  904. $aSrchNamesExcept = array();
  905. $aSrchCaptions = array(
  906. 'cmt_author_id' => '_sys_form_comment_input_caption_cmt_author_id',
  907. 'cmt_text' => '_sys_form_comment_input_caption_cmt_text'
  908. );
  909. $aResult = array(
  910. 'cmt_author_id' => array(
  911. 'type' => 'text_auto',
  912. 'caption' => $aSrchCaptions['cmt_author_id'],
  913. 'values' => '',
  914. 'pass' => ''
  915. )
  916. );
  917. foreach ($oForm->aInputs as $aInput)
  918. if (in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $aSrchNamesExcept))
  919. $aResult[$aInput['name']] = array(
  920. 'type' => $aInput['type'],
  921. 'caption' => !empty($aInput['caption_src']) ? $aInput['caption_src'] : (!empty($aSrchCaptions[$aInput['name']]) ? $aSrchCaptions[$aInput['name']] : ''),
  922. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  923. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : ''
  924. );
  925. return $aResult;
  926. }
  927. /**
  928. * Overwrite this method and register transcoder(s) if comments object uses custom transcoder(s),
  929. * which differs from default one 'sys_cmts_images_preview'
  930. */
  931. public function registerTranscoders()
  932. {}
  933. /**
  934. * Overwrite this method and unregister transcoder(s) if comments object uses custom transcoder(s),
  935. * which differs from default one 'sys_cmts_images_preview'
  936. */
  937. public function unregisterTranscoders()
  938. {}
  939. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
  940. {
  941. if(empty($aParams) || !is_array($aParams))
  942. return array();
  943. return $this->_oQuery->getCommentsBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  944. }
  945. /**
  946. * Internal functions
  947. */
  948. protected function _getAuthorId ()
  949. {
  950. return isMember() ? bx_get_logged_profile_id() : 0;
  951. }
  952. protected function _getAuthorPassword ()
  953. {
  954. return isMember() ? $_COOKIE['memberPassword'] : "";
  955. }
  956. protected function _getAuthorIp ()
  957. {
  958. return getVisitorIP();
  959. }
  960. protected function _getAuthorInfo($iAuthorId = 0)
  961. {
  962. $oProfile = $this->_getAuthorObject($iAuthorId);
  963. return array(
  964. $oProfile->getDisplayName(),
  965. $oProfile->getUrl(),
  966. $oProfile->getThumb(),
  967. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  968. );
  969. }
  970. protected function _getAuthorObject($iAuthorId = 0)
  971. {
  972. if(empty($iAuthorId))
  973. return BxDolProfileUndefined::getInstance();
  974. $oProfile = BxDolProfile::getInstance($iAuthorId);
  975. if (!$oProfile)
  976. $oProfile = BxDolProfileUndefined::getInstance();
  977. return $oProfile;
  978. }
  979. protected function _getFormObject($sAction = BX_CMT_ACTION_POST)
  980. {
  981. $sDisplayName = '_sFormDisplay' . ucfirst($sAction);
  982. return BxDolForm::getObjectInstance($this->_sFormObject, $this->$sDisplayName, false, $this->_sSystem);
  983. }
  984. protected function _getParams(&$aBp, &$aDp)
  985. {
  986. //--- Process 'Browse' params.
  987. $aBp['parent_id'] = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  988. $aBp['vparent_id'] = isset($aBp['vparent_id']) ? (int)$aBp['vparent_id'] : 0;
  989. if(bx_get('CmtParent') !== false)
  990. $aBp['vparent_id'] = bx_process_input(bx_get('CmtParent'), BX_DATA_INT);
  991. $aBp['type'] = isset($aBp['type']) ? $aBp['type'] : '';
  992. if(bx_get('CmtBrowse') !== false)
  993. $aBp['type'] = bx_process_input(bx_get('CmtBrowse'), BX_DATA_TEXT);
  994. $aBp['filter'] = isset($aBp['filter']) ? $aBp['filter'] : '';
  995. if(bx_get('CmtFilter') !== false)
  996. $aBp['filter'] = bx_process_input(bx_get('CmtFilter'), BX_DATA_TEXT);
  997. $aBp['start'] = isset($aBp['start']) ? (int)$aBp['start'] : -1;
  998. if(bx_get('CmtStart') !== false)
  999. $aBp['start'] = bx_process_input($_REQUEST['CmtStart'], BX_DATA_INT);
  1000. $aBp['per_view'] = isset($aBp['per_view']) ? (int)$aBp['per_view'] : -1;
  1001. if(bx_get('CmtPerView') !== false)
  1002. $aBp['per_view'] = bx_process_input($_REQUEST['CmtPerView'], BX_DATA_INT);
  1003. //--- Process 'Display' params.
  1004. $aDp['type'] = isset($aDp['type']) ? $aDp['type'] : '';
  1005. if(bx_get('CmtDisplay') !== false)
  1006. $aDp['type'] = bx_process_input($_REQUEST['CmtDisplay'], BX_DATA_TEXT);
  1007. $aDp['blink'] = isset($aDp['blink']) ? $aDp['blink'] : '';
  1008. if(bx_get('CmtBlink') !== false)
  1009. $aDp['blink'] = bx_process_input($_REQUEST['CmtBlink'], BX_DATA_TEXT);
  1010. $aDp['in_designbox'] = isset($aDp['in_designbox']) ? (bool)$aDp['in_designbox'] : true;
  1011. $aDp['dynamic_mode'] = isset($aDp['dynamic_mode']) ? (bool)$aDp['dynamic_mode'] : false;
  1012. $aDp['show_empty'] = isset($aDp['show_empty']) ? (bool)$aDp['show_empty'] : false;
  1013. }
  1014. protected function _prepareTextForEdit ($s)
  1015. {
  1016. if ($this->isNl2br())
  1017. return htmlspecialchars_decode(str_replace('<br />', "", $s));
  1018. return $s;
  1019. }
  1020. protected function _prepareTextForSave ($s)
  1021. {
  1022. $iDataAction = $this->isNl2br() ? BX_DATA_TEXT_MULTILINE : BX_DATA_HTML;
  1023. return bx_process_input($s, $iDataAction);
  1024. }
  1025. protected function _prepareTextForOutput ($s, $iCmtId = 0)
  1026. {
  1027. $iDataAction = $this->isNl2br() ? BX_DATA_TEXT_MULTILINE : BX_DATA_HTML;
  1028. $s = bx_process_output($s, $iDataAction);
  1029. $s = bx_linkify_html($s, 'class="' . BX_DOL_LINK_CLASS . '"');
  1030. if ($this->_sMetatagsObj && $iCmtId) {
  1031. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  1032. $s = $oMetatags->metaParse($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $s);
  1033. }
  1034. return $s;
  1035. }
  1036. protected function _prepareParams(&$aBp, &$aDp)
  1037. {
  1038. $aBp['type'] = isset($aBp['type']) && !empty($aBp['type']) ? $aBp['type'] : $this->_sBrowseType;
  1039. $aBp['filter'] = isset($aBp['filter']) && !empty($aBp['filter']) ? $aBp['filter'] : $this->_sBrowseFilter;
  1040. $aBp['parent_id'] = isset($aBp['parent_id']) ? $aBp['parent_id'] : 0;
  1041. $aBp['start'] = isset($aBp['start']) ? $aBp['start'] : -1;
  1042. $aBp['per_view'] = isset($aBp['per_view']) ? $aBp['per_view'] : -1;
  1043. $aBp['order']['by'] = isset($aBp['order_by']) ? $aBp['order_by'] : $this->_aOrder['by'];
  1044. $aBp['order']['way'] = isset($aBp['order_way']) ? $aBp['order_way'] : $this->_aOrder['way'];
  1045. $aDp['type'] = isset($aDp['type']) && !empty($aDp['type']) ? $aDp['type'] : $this->_sDisplayType;
  1046. $aDp['blink'] = isset($aDp['blink']) && !empty($aDp['blink']) ? $aDp['blink'] : array();
  1047. if(!is_array($aDp['blink']))
  1048. $aDp['blink'] = explode(',', $aDp['blink']);
  1049. switch($aDp['type']) {
  1050. case BX_CMT_DISPLAY_FLAT:
  1051. $aBp['vparent_id'] = -1;
  1052. $aBp['per_view'] = $aBp['per_view'] != -1 ? $aBp['per_view'] : $this->getPerView(0);
  1053. break;
  1054. case BX_CMT_DISPLAY_THREADED:
  1055. $aBp['per_view'] = $aBp['per_view'] != -1 ? $aBp['per_view'] : $this->getPerView($aBp['vparent_id']);
  1056. break;
  1057. }
  1058. switch ($aBp['type']) {
  1059. case BX_CMT_BROWSE_POPULAR:
  1060. $aBp['order'] = array(
  1061. 'by' => BX_CMT_ORDER_BY_POPULAR,
  1062. 'way' => BX_CMT_ORDER_WAY_DESC
  1063. );
  1064. break;
  1065. }
  1066. $aBp['count'] = $this->getCommentsCount($this->_iId, $aBp['vparent_id'], $aBp['filter']);
  1067. if($aBp['start'] != -1)
  1068. return;
  1069. $aBp['start'] = 0;
  1070. if($aBp['type'] == BX_CMT_BROWSE_TAIL) {
  1071. $aBp['start'] = $aBp['count'] - $aBp['per_view'];
  1072. if($aBp['start'] < 0) {
  1073. $aBp['per_view'] += $aBp['start'];
  1074. $aBp['start'] = 0;
  1075. }
  1076. }
  1077. $this->_setUserChoice($aDp['type'], $aBp['type'], $aBp['filter']);
  1078. }
  1079. protected function _triggerComment()
  1080. {
  1081. if(!$this->_aSystem['trigger_table'])
  1082. return false;
  1083. $iId = $this->getId();
  1084. if(!$iId)
  1085. return false;
  1086. $iCount = $this->getCommentsCount($iId);
  1087. return $this->_oQuery->updateTriggerTable($iId, $iCount);
  1088. }
  1089. /**
  1090. * Replace provided markers in a string
  1091. * @param $mixed string or array to replace markers in
  1092. * @return string where all occured markers are replaced
  1093. */
  1094. protected function _replaceMarkers ($mixed)
  1095. {
  1096. return bx_replace_markers($mixed, $this->_aMarkers);
  1097. }
  1098. protected function _getUserChoice()
  1099. {
  1100. $mixedDp = $mixedBpType = $mixedBpFilter = false;
  1101. if(!isLogged())
  1102. return array($mixedDp, $mixedBpType, $mixedBpFilter);
  1103. $iUserId = $this->_getAuthorId();
  1104. $oSession = BxDolSession::getInstance();
  1105. $mixedDp = $oSession->getValue($this->_sDpSessionKey . $iUserId);
  1106. $mixedBpType = $oSession->getValue($this->_sBpSessionKeyType . $iUserId);
  1107. $mixedBpFilter = $oSession->getValue($this->_sBpSessionKeyFilter . $iUserId);
  1108. return array($mixedDp, $mixedBpType, $mixedBpFilter);
  1109. }
  1110. protected function _setUserChoice($sDp, $sBpType, $sBpFilter)
  1111. {
  1112. if(!isLogged())
  1113. return;
  1114. $iUserId = $this->_getAuthorId();
  1115. $oSession = BxDolSession::getInstance();
  1116. if(!empty($sDp))
  1117. $oSession->setValue($this->_sDpSessionKey . $iUserId, $sDp);
  1118. if(!empty($sBpType))
  1119. $oSession->setValue($this->_sBpSessionKeyType . $iUserId, $sBpType);
  1120. if(!empty($sBpFilter))
  1121. $oSession->setValue($this->_sBpSessionKeyFilter . $iUserId, $sBpFilter);
  1122. }
  1123. protected function _sendNotificationEmail($iCmtId, $iCmtParentId)
  1124. {
  1125. $aCmt = $this->getCommentRow($iCmtId);
  1126. $aCmtParent = $this->getCommentRow($iCmtParentId);
  1127. if(empty($aCmt) || !is_array($aCmt) || empty($aCmtParent) || !is_array($aCmtParent) || (int)$aCmt['cmt_author_id'] == (int)$aCmtParent['cmt_author_id'])
  1128. return;
  1129. $oProfile = $this->_getAuthorObject($aCmtParent['cmt_author_id']);
  1130. if($oProfile instanceof BxDolProfileUndefined)
  1131. return;
  1132. $iAccount = $oProfile->getAccountId();
  1133. $aAccount = BxDolAccount::getInstance($iAccount)->getInfo();
  1134. $aPlus = array();
  1135. $aPlus['sender_display_name'] = $oProfile->getDisplayName();
  1136. $aPlus['reply_text'] = $this->_prepareTextForOutput($aCmt['cmt_text'], $iCmtId);
  1137. $sPageUrl = $this->getBaseUrl();
  1138. if(empty($sPageUrl))
  1139. $sPageUrl = $this->getViewUrl($iCmtParentId);
  1140. else
  1141. $sPageUrl .= $this->getItemAnchor($iCmtParentId, true);
  1142. $aPlus['page_url'] = $sPageUrl;
  1143. $sPageTitle = $this->getObjectTitle();
  1144. if(empty($sPageTitle))
  1145. $sPageTitle = _t('_Content');
  1146. $aPlus['page_title'] = $sPageTitle;
  1147. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_CommentReplied', $aPlus);
  1148. return $aTemplate && sendMail($aAccount['email'], $aTemplate['Subject'], $aTemplate['Body']);
  1149. }
  1150. }
  1151. /** @} */