BxTimelineModule.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxDolModule');
  13. require_once( BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php' );
  14. define('BX_TIMELINE_TYPE_OWNER', 'owner');
  15. define('BX_TIMELINE_TYPE_CONNECTIONS', 'connections');
  16. define('BX_TIMELINE_HANDLER_TYPE_INSERT', 'insert');
  17. define('BX_TIMELINE_HANDLER_TYPE_UPDATE', 'update');
  18. define('BX_TIMELINE_HANDLER_TYPE_DELETE', 'delete');
  19. define('BX_TIMELINE_FILTER_ALL', 'all');
  20. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  21. define('BX_TIMELINE_FILTER_OTHER', 'other');
  22. define('BX_TIMELINE_DIVIDER_ID', ',');
  23. define('BX_TIMELINE_PARSE_TYPE_TEXT', 'text');
  24. define('BX_TIMELINE_PARSE_TYPE_LINK', 'link');
  25. define('BX_TIMELINE_PARSE_TYPE_PHOTO', 'photo');
  26. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_TEXT);
  27. class BxTimelineModule extends BxDolModule
  28. {
  29. var $_iOwnerId;
  30. var $_sJsPostObject;
  31. var $_sJsViewObject;
  32. var $_aPostElements;
  33. var $_sJsOutlineObject;
  34. var $_sDividerTemplate;
  35. var $_sBalloonTemplate;
  36. var $_sCmtPostTemplate;
  37. var $_sCmtViewTemplate;
  38. var $_sCmtTemplate;
  39. /**
  40. * Constructor
  41. */
  42. function __construct($aModule)
  43. {
  44. parent::BxDolModule($aModule);
  45. $this->_oConfig->init($this->_oDb);
  46. $this->_oTemplate->init();
  47. $this->_iOwnerId = 0;
  48. }
  49. /**
  50. * ACTION METHODS
  51. */
  52. public function actionPost()
  53. {
  54. $sType = bx_process_input($_POST['type']);
  55. $sMethod = 'getForm' . ucfirst($sType);
  56. if(!method_exists($this, $sMethod)) {
  57. $this->_echoResultJson(array());
  58. return;
  59. }
  60. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  61. if (!$this->isAllowedPost(true)) {
  62. $this->_echoResultJson(array('msg' => bx_js_string(_t('_bx_timeline_txt_msg_not_allowed_post'))));
  63. return;
  64. }
  65. $aResult = $this->$sMethod();
  66. $this->_echoResultJson($aResult);
  67. }
  68. function actionDelete()
  69. {
  70. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  71. if(!$this->isAllowedDelete(true)) {
  72. $this->_echoResultJson(array('code' => 1));
  73. return;
  74. }
  75. $iPostId = bx_process_input(bx_get('post_id'), BX_DATA_INT);
  76. if(!$this->_oDb->deleteEvent(array('id' => $iPostId))) {
  77. $this->_echoResultJson(array('code' => 2));
  78. return;
  79. }
  80. $aPhotos = $this->_oDb->getPhotos($iPostId);
  81. if(is_array($aPhotos) && !empty($aPhotos)) {
  82. bx_import('BxDolStorage');
  83. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  84. foreach($aPhotos as $aPhoto)
  85. $oStorage->deleteFile($aPhoto['id']);
  86. $this->_oDb->deletePhotos($iPostId);
  87. }
  88. //--- Event -> Delete for Alerts Engine ---//
  89. bx_import('BxDolAlerts');
  90. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'delete', $iPostId, $this->getUserId());
  91. $oAlert->alert();
  92. //--- Event -> Delete for Alerts Engine ---//
  93. $this->_echoResultJson(array('code' => 0, 'id' => $iPostId));
  94. }
  95. function actionGetPost()
  96. {
  97. $this->_oConfig->setJsMode(true);
  98. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  99. $iEvent = bx_process_input(bx_get('post_id'), BX_DATA_INT);
  100. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  101. $this->_echoResultJson(array('item' => $this->_oTemplate->getCommon($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId))));
  102. }
  103. function actionGetPosts()
  104. {
  105. $this->_oConfig->setJsMode(true);
  106. $aParams = $this->_prepareParamsGet();
  107. list($sItems, $sLoadMore) = $this->_oTemplate->getPosts($aParams);
  108. $this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore));
  109. }
  110. public function actionGetPostForm($sType)
  111. {
  112. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  113. $sMethod = 'getForm' . ucfirst($sType);
  114. if(!method_exists($this, $sMethod)) {
  115. $this->_echoResultJson(array());
  116. return;
  117. }
  118. $aResult = $this->$sMethod();
  119. $this->_echoResultJson($aResult);
  120. }
  121. public function actionGetTimeline()
  122. {
  123. $aParams = $this->_prepareParamsGet();
  124. $sTimeline = $this->_oTemplate->getTimeline($aParams);
  125. $this->_echoResultJson(array('timeline' => $sTimeline));
  126. }
  127. public function actionGetComments()
  128. {
  129. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  130. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  131. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  132. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  133. $this->_echoResultJson(array('content' => $sComments));
  134. }
  135. public function actionGetPostPopup()
  136. {
  137. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  138. if(!$iItemId) {
  139. $this->_echoResultJson(array());
  140. return;
  141. }
  142. $sContent = $this->_oTemplate->getViewItemPopup($iItemId);
  143. $this->_echoResultJson(array('popup' => $sContent));
  144. }
  145. /**
  146. * SERVICE METHODS
  147. */
  148. public function serviceAddHandlers($sModuleUri = 'all')
  149. {
  150. $this->_updateHandlers($sModuleUri, true);
  151. }
  152. public function serviceDeleteHandlers($sModuleUri = 'all')
  153. {
  154. $this->_updateHandlers($sModuleUri, false);
  155. }
  156. function serviceGetActionsChecklist()
  157. {
  158. $aHandlers = $this->_oConfig->getHandlers();
  159. $aResults = array();
  160. foreach($aHandlers as $aHandler) {
  161. if($aHandler['type'] != BX_TIMELINE_HANDLER_TYPE_INSERT)
  162. continue;
  163. $aModule = $this->_oDb->getModuleByName($aHandler['module_name']);
  164. if(empty($aModule))
  165. $aModule['title'] = _t('_bx_timeline_alert_module_' . $aHandler['alert_unit']);
  166. $aResults[$aHandler['id']] = $aModule['title'] . ' (' . _t('_bx_timeline_alert_action_' . $aHandler['alert_action']) . ')';
  167. }
  168. asort($aResults);
  169. return $aResults;
  170. }
  171. public function serviceResponse($oAlert)
  172. {
  173. bx_import('Response', $this->_aModule);
  174. $oResponse = new BxTimelineResponse($this);
  175. $oResponse->response($oAlert);
  176. }
  177. public function serviceGetBlockPostProfile($iProfileId = 0)
  178. {
  179. if (!$iProfileId && bx_get('id') !== false) {
  180. $iProfileId = bx_process_input(bx_get('id'), BX_DATA_INT);
  181. $iProfileId = BxDolProfile::getInstanceByContentAndType($iProfileId, 'bx_persons')->id();
  182. }
  183. if (!$iProfileId)
  184. return array();
  185. $this->_iOwnerId = $iProfileId;
  186. list($sUserName, $sUserUrl) = $this->getUserInfo($iProfileId);
  187. if($this->_iOwnerId != $this->getUserId() && !$this->isAllowedPost())
  188. return array();
  189. bx_import('BxDolMenu');
  190. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post'));
  191. $oMenu->setMenuId('timeline-post-menu');
  192. $oMenu->setSelected($this->getName(), 'post-text');
  193. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  194. return array('content' => $sContent, 'menu' => $oMenu);
  195. }
  196. public function serviceGetBlockViewProfile($iProfileId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  197. {
  198. if (!$iProfileId) {
  199. $iProfileId = bx_process_input(bx_get('id'), BX_DATA_INT);
  200. $iProfileId = BxDolProfile::getInstanceByContentAndType($iProfileId, 'bx_persons')->id();
  201. }
  202. if (!$iProfileId)
  203. return array();
  204. $sJsObject = $this->_oConfig->getJsObject('view');
  205. $aParams = $this->_prepareParams('owner', $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  206. $this->_iOwnerId = $aParams['owner_id'];
  207. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  208. $aMenu = array(
  209. array('id' => 'timeline-view-all', 'name' => 'timeline-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  210. array('id' => 'timeline-view-owner', 'name' => 'timeline-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  211. array('id' => 'timeline-view-other', 'name' => 'timeline-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  212. //array('id' => 'timeline-get-rss', 'name' => 'timeline-get-rss', 'class' => '', 'link' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $iProfileId . '/', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  213. );
  214. bx_import('BxTemplMenuInteractive');
  215. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  216. $oMenu->setSelected('', 'timeline-view-all');
  217. $sContent = $this->_oTemplate->getViewBlock($aParams);
  218. return array('content' => $sContent, 'menu' => $oMenu);
  219. }
  220. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  221. {
  222. $aParams = $this->_prepareParams('connections', $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  223. $this->_iOwnerId = $aParams['owner_id'];
  224. $sContent = $this->_oTemplate->getViewBlock($aParams);
  225. return array('content' => $sContent);
  226. }
  227. public function serviceGetBlockItem()
  228. {
  229. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  230. if(!$iItemId)
  231. return array();
  232. return array('content' => $this->_oTemplate->getViewItemBlock($iItemId));
  233. }
  234. /*
  235. * COMMON METHODS
  236. */
  237. public function getFormText()
  238. {
  239. bx_import('BxDolForm');
  240. $oForm = BxDolForm::getObjectInstance('mod_tml_text', 'mod_tml_text_add');
  241. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  242. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  243. $oForm->initChecker();
  244. if($oForm->isSubmittedAndValid()) {
  245. $iUserId = $this->getUserId();
  246. list($sUserName) = $this->getUserInfo($iUserId);
  247. $sType = $oForm->getCleanValue('type');
  248. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  249. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  250. $sContent = $sDescription = $oForm->getCleanValue('content');
  251. $sContent = serialize(array('text' => $sContent));
  252. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  253. bx_import('BxDolPrivacy');
  254. $iId = $oForm->insert(array(
  255. 'object_id' => $iUserId,
  256. 'object_privacy_view' => BX_DOL_PG_ALL,
  257. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_wrote')),
  258. 'description' => $sDescription,
  259. 'date' => time()
  260. ));
  261. if($iId != 0) {
  262. $this->onPost($iId, $iUserId);
  263. return array('id' => $iId);
  264. }
  265. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  266. }
  267. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  268. }
  269. public function getFormLink()
  270. {
  271. bx_import('BxDolForm');
  272. $oForm = BxDolForm::getObjectInstance('mod_tml_link', 'mod_tml_link_add');
  273. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  274. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  275. $oForm->initChecker();
  276. if($oForm->isSubmittedAndValid()) {
  277. $iUserId = $this->getUserId();
  278. list($sUserName) = $this->getUserInfo($iUserId);
  279. $sType = $oForm->getCleanValue('type');
  280. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  281. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  282. $sUrl = $oForm->getCleanValue('content');
  283. $sContent = bx_file_get_contents($sUrl);
  284. preg_match("/<title>(.*)<\/title>/", $sContent, $aMatch);
  285. $sTitle = $aMatch ? $aMatch[1] : '';
  286. preg_match("/<meta.*name[='\" ]+description['\"].*content[='\" ]+(.*)['\"].*><\/meta>/", $sContent, $aMatch);
  287. $sDescription = $aMatch ? $aMatch[1] : '';
  288. $sContent = serialize(array(
  289. 'url' => strpos($sUrl, 'http://') === false && strpos($sUrl, 'https://') === false ? 'http://' . $sUrl : $sUrl,
  290. 'title' => $sTitle,
  291. 'text' => $sDescription
  292. ));
  293. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  294. bx_import('BxDolPrivacy');
  295. $iId = $oForm->insert(array(
  296. 'object_id' => $iUserId,
  297. 'object_privacy_view' => BX_DOL_PG_ALL,
  298. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_shared_link')),
  299. 'description' => bx_process_input($sUrl . ' - ' . $sTitle),
  300. 'date' => time()
  301. ));
  302. if($iId != 0) {
  303. $this->onPost($iId, $iUserId);
  304. return array('id' => $iId);
  305. }
  306. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  307. }
  308. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  309. }
  310. public function getFormPhoto()
  311. {
  312. $aFormNested = array(
  313. 'inputs' => array(
  314. 'file_title' => array(
  315. 'type' => 'text',
  316. 'name' => 'file_title[]',
  317. 'value' => '{file_title}',
  318. 'caption' => _t('_bx_timeline_form_photo_input_title'),
  319. 'required' => true,
  320. 'checker' => array(
  321. 'func' => 'length',
  322. 'params' => array(1, 150),
  323. 'error' => _t('_bx_timeline_form_photo_input_err_title')
  324. ),
  325. 'db' => array (
  326. 'pass' => 'Xss',
  327. ),
  328. ),
  329. 'file_text' => array(
  330. 'type' => 'textarea',
  331. 'name' => 'file_text[]',
  332. 'caption' => _t('_bx_timeline_form_photo_input_description'),
  333. 'required' => true,
  334. 'checker' => array(
  335. 'func' => 'length',
  336. 'params' => array(10, 5000),
  337. 'error' => _t('_bx_timeline_form_photo_input_err_description')
  338. ),
  339. 'db' => array (
  340. 'pass' => 'Xss',
  341. ),
  342. ),
  343. ),
  344. );
  345. bx_import('BxDolForm');
  346. $oForm = BxDolForm::getObjectInstance('mod_tml_photo', 'mod_tml_photo_add');
  347. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  348. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  349. bx_import('BxDolFormNested');
  350. $oFormNested = new BxDolFormNested('content', $aFormNested, 'do_submit');
  351. $oForm->aInputs['content']['storage_object'] = $this->_oConfig->getObject('storage');
  352. $oForm->aInputs['content']['images_transcoder'] = $this->_oConfig->getObject('transcoder_preview');
  353. $oForm->aInputs['content']['uploaders'] = $this->_oConfig->getUploaders('image');
  354. $oForm->aInputs['content']['multiple'] = false;
  355. $oForm->aInputs['content']['ghost_template'] = $oFormNested;
  356. $oForm->initChecker();
  357. if($oForm->isSubmittedAndValid()) {
  358. $iUserId = $this->getUserId();
  359. list($sUserName) = $this->getUserInfo($iUserId);
  360. $sType = $oForm->getCleanValue('type');
  361. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  362. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  363. $aPhIds = $oForm->getCleanValue('content');
  364. BxDolForm::setSubmittedValue('content', serialize(array()), $oForm->aFormAttrs['method']);
  365. bx_import('BxDolPrivacy');
  366. $iId = $oForm->insert(array(
  367. 'object_id' => $iUserId,
  368. 'object_privacy_view' => BX_DOL_PG_ALL,
  369. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_added_photo')),
  370. 'description' => '',
  371. 'date' => time()
  372. ));
  373. if($iId != 0) {
  374. $iPhIds = count($aPhIds);
  375. if($iPhIds > 0) {
  376. $aPhTitles = $oForm->getCleanValue('file_title');
  377. $aPhTexts = $oForm->getCleanValue('file_text');
  378. bx_import('BxDolStorage');
  379. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  380. for($i = 0; $i < $iPhIds; $i++)
  381. if($this->_oDb->savePhoto($iId, $aPhIds[$i], $aPhTitles[$i], $aPhTexts[$i]))
  382. $oStorage->afterUploadCleanup($aPhIds[$i], $iUserId);
  383. }
  384. $this->onPost($iId, $iUserId);
  385. return array('id' => $iId);
  386. }
  387. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  388. }
  389. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  390. }
  391. public function getCmtsObject($sSystem, $iId)
  392. {
  393. if(empty($sSystem) || (int)$iId == 0)
  394. return false;
  395. bx_import('BxDolCmts');
  396. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  397. if(!$oCmts->isEnabled())
  398. return false;
  399. return $oCmts;
  400. }
  401. public function getUserId()
  402. {
  403. return isLogged() ? bx_get_logged_profile_id() : 0;
  404. }
  405. public function getUserInfo($iUserId = 0)
  406. {
  407. bx_import('BxDolProfile');
  408. $oProfile = BxDolProfile::getInstance($iUserId);
  409. if (!$oProfile) {
  410. bx_import('BxDolProfileUndefined');
  411. $oProfile = BxDolProfileUndefined::getInstance();
  412. }
  413. return array(
  414. $oProfile->getDisplayName(),
  415. $oProfile->getUrl(),
  416. $oProfile->getIcon(),
  417. $oProfile->getUnit()
  418. );
  419. }
  420. public function isAllowedPost($bPerform = false)
  421. {
  422. if(isAdmin())
  423. return true;
  424. $iUserId = $this->getUserId();
  425. if($iUserId == 0 && $this->_oConfig->isAllowGuestComments())
  426. return true;
  427. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  428. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  429. }
  430. public function isAllowedDelete($aEvent, $bPerform = false)
  431. {
  432. if(isAdmin())
  433. return true;
  434. $iUserId = (int)$this->getUserId();
  435. if((int)$aEvent['owner_id'] == $iUserId)
  436. return true;
  437. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  438. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  439. }
  440. public function isAllowedComment($aEvent, $bPerform = false)
  441. {
  442. $mixedComments = $this->getCommentsData($aEvent);
  443. if($mixedComments === false)
  444. return false;
  445. list($sSystem, $iObjectId) = $mixedComments;
  446. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  447. $oCmts->addCssJs();
  448. if(isAdmin())
  449. return true;
  450. return $oCmts->isPostReplyAllowed($bPerform);
  451. }
  452. public function onPost($iId, $iUserId)
  453. {
  454. //--- Event -> Post for Alerts Engine ---//
  455. bx_import('BxDolAlerts');
  456. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'post', $iId, $iUserId);
  457. $oAlert->alert();
  458. //--- Event -> Post for Alerts Engine ---//
  459. }
  460. public function onUpdate($iOwnerId)
  461. {
  462. //--- Timeline -> Update for Alerts Engine ---//
  463. bx_import('BxDolAlerts');
  464. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'update', $iOwnerId);
  465. $oAlert->alert();
  466. //--- Timeline -> Update for Alerts Engine ---//
  467. }
  468. public function getCommentsData(&$aEvent)
  469. {
  470. if(empty($aEvent['comments']) || !is_array($aEvent['comments']))
  471. return false;
  472. $aComments = $aEvent['comments'];
  473. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  474. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  475. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  476. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  477. return false;
  478. return array($sSystem, $iObjectId, $iCount);
  479. }
  480. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  481. {
  482. $aParams = array();
  483. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_OWNER;
  484. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  485. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  486. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  487. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  488. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  489. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : $this->_oDb->getMaxDuration($aParams);
  490. return $aParams;
  491. }
  492. protected function _prepareParamsGet()
  493. {
  494. $aParams = array();
  495. $sType = bx_get('type');
  496. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_OWNER;
  497. $iOwnerId = bx_get('owner_id');
  498. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  499. $iStart = bx_get('start');
  500. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  501. $iPerPage = bx_get('per_page');
  502. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  503. $sFilter = bx_get('filter');
  504. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  505. $aModules = bx_get('modules');
  506. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  507. $iTimeline = bx_get('timeline');
  508. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : $this->_oDb->getMaxDuration($aParams);
  509. return $aParams;
  510. }
  511. protected function _updateHandlers($sModuleUri = 'all', $bInstall = true)
  512. {
  513. $aModules = $sModuleUri == 'all' ? $this->_oDb->getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
  514. foreach($aModules as $aModule) {
  515. if(!BxDolRequest::serviceExists($aModule, 'get_timeline_data'))
  516. continue;
  517. $aData = BxDolService::call($aModule['name'], 'get_timeline_data');
  518. if(empty($aData) || !is_array($aData))
  519. continue;
  520. if($bInstall)
  521. $this->_oDb->insertData($aData);
  522. else
  523. $this->_oDb->deleteData($aData);
  524. }
  525. BxDolAlerts::cache();
  526. }
  527. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  528. header('Content-type: text/html; charset=utf-8');
  529. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  530. $oParser = new Services_JSON();
  531. $s = $oParser->encode($a);
  532. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  533. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  534. echo $s;
  535. }
  536. /**
  537. * Get RSS for specified owner.
  538. *
  539. * @param string $sUsername wall owner username
  540. * @return string with RSS.
  541. */
  542. function actionRss($sUsername)
  543. {
  544. $aOwner = $this->_oDb->getUser($sUsername, 'username');
  545. $aEvents = $this->_oDb->getEvents(array(
  546. 'type' => 'owner',
  547. 'owner_id' => $aOwner['id'],
  548. 'order' => 'desc',
  549. 'start' => 0,
  550. 'count' => $this->_oConfig->getRssLength(),
  551. 'filter' => ''
  552. ));
  553. $sRssBaseUrl = $this->_oConfig->getBaseUri() . 'index/' . $aOwner['username'] . '/';
  554. $aRssData = array();
  555. foreach($aEvents as $aEvent) {
  556. if(empty($aEvent['title'])) continue;
  557. $aRssData[$aEvent['id']] = array(
  558. 'UnitID' => $aEvent['id'],
  559. 'OwnerID' => $aOwner['id'],
  560. 'UnitTitle' => $aEvent['title'],
  561. 'UnitLink' => BX_DOL_URL_ROOT . $sRssBaseUrl . '#wall-event-' . $aEvent['id'],
  562. 'UnitDesc' => $aEvent['description'],
  563. 'UnitDateTimeUTS' => $aEvent['date'],
  564. 'UnitIcon' => ''
  565. );
  566. }
  567. $oRss = new BxDolRssFactory();
  568. header('Content-Type: text/html; charset=utf-8');
  569. return $oRss->GenRssByData($aRssData, $aOwner['username'] . ' ' . _t('_wall_rss_caption'), $sRssBaseUrl);
  570. }
  571. }
  572. /** @} */