BxTimelineModule.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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_PARSE_TYPE_TEXT', 'text');
  23. define('BX_TIMELINE_PARSE_TYPE_LINK', 'link');
  24. define('BX_TIMELINE_PARSE_TYPE_PHOTO', 'photo');
  25. define('BX_TIMELINE_PARSE_TYPE_SHARE', 'share');
  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. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  76. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  77. if(!$this->_oDb->deleteEvent(array('id' => $iId))) {
  78. $this->_echoResultJson(array('code' => 2));
  79. return;
  80. }
  81. $this->onDelete($aEvent);
  82. $this->_echoResultJson(array('code' => 0, 'id' => $iId));
  83. }
  84. public function actionShare()
  85. {
  86. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  87. $aContent = array(
  88. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  89. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  90. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  91. );
  92. $iId = $this->_oDb->insertEvent(array(
  93. 'owner_id' => $iOwnerId,
  94. 'type' => $this->_oConfig->getPrefix('common_post') . 'share',
  95. 'action' => '',
  96. 'object_id' => $this->getUserId(),
  97. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  98. 'content' => serialize($aContent),
  99. 'title' => '',
  100. 'description' => ''
  101. ));
  102. if(!empty($iId)) {
  103. $this->onShare($iId);
  104. $this->_echoResultJson(array('msg' => _t('_bx_timeline_txt_msg_success_share')));
  105. return;
  106. }
  107. $this->_echoResultJson(array('msg' => _t('_bx_timeline_txt_err_cannot_share')));
  108. }
  109. function actionGetPost()
  110. {
  111. $this->_oConfig->setJsMode(true);
  112. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  113. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  114. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  115. $this->_echoResultJson(array('item' => $this->_oTemplate->getPost($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId))));
  116. }
  117. function actionGetPosts()
  118. {
  119. $this->_oConfig->setJsMode(true);
  120. $aParams = $this->_prepareParamsGet();
  121. list($sItems, $sLoadMore, $sBack) = $this->_oTemplate->getPosts($aParams);
  122. $this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore, 'back' => $sBack));
  123. }
  124. public function actionGetPostForm($sType)
  125. {
  126. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  127. $sMethod = 'getForm' . ucfirst($sType);
  128. if(!method_exists($this, $sMethod)) {
  129. $this->_echoResultJson(array());
  130. return;
  131. }
  132. $aResult = $this->$sMethod();
  133. $this->_echoResultJson($aResult);
  134. }
  135. public function actionGetComments()
  136. {
  137. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  138. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  139. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  140. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  141. $this->_echoResultJson(array('content' => $sComments));
  142. }
  143. public function actionGetPostPopup()
  144. {
  145. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  146. if(!$iItemId) {
  147. $this->_echoResultJson(array());
  148. return;
  149. }
  150. $sContent = $this->_oTemplate->getViewItemPopup($iItemId);
  151. $this->_echoResultJson(array('popup' => $sContent));
  152. }
  153. /**
  154. * SERVICE METHODS
  155. */
  156. public function serviceAddHandlers($sModuleUri = 'all')
  157. {
  158. $this->_updateHandlers($sModuleUri, true);
  159. }
  160. public function serviceDeleteHandlers($sModuleUri = 'all')
  161. {
  162. $this->_updateHandlers($sModuleUri, false);
  163. }
  164. function serviceGetActionsChecklist()
  165. {
  166. $aHandlers = $this->_oConfig->getHandlers();
  167. $aResults = array();
  168. foreach($aHandlers as $aHandler) {
  169. if($aHandler['type'] != BX_TIMELINE_HANDLER_TYPE_INSERT)
  170. continue;
  171. $aModule = $this->_oDb->getModuleByName($aHandler['module_name']);
  172. if(empty($aModule))
  173. $aModule['title'] = _t('_bx_timeline_alert_module_' . $aHandler['alert_unit']);
  174. $aResults[$aHandler['id']] = $aModule['title'] . ' (' . _t('_bx_timeline_alert_action_' . $aHandler['alert_action']) . ')';
  175. }
  176. asort($aResults);
  177. return $aResults;
  178. }
  179. public function serviceResponse($oAlert)
  180. {
  181. bx_import('Response', $this->_aModule);
  182. $oResponse = new BxTimelineResponse($this);
  183. $oResponse->response($oAlert);
  184. }
  185. public function serviceGetBlockPostProfile($iProfileId = 0)
  186. {
  187. if (!$iProfileId && bx_get('id') !== false) {
  188. $iProfileId = bx_process_input(bx_get('id'), BX_DATA_INT);
  189. $iProfileId = BxDolProfile::getInstanceByContentAndType($iProfileId, 'bx_persons')->id();
  190. }
  191. if (!$iProfileId)
  192. return array();
  193. $this->_iOwnerId = $iProfileId;
  194. list($sUserName, $sUserUrl) = $this->getUserInfo($iProfileId);
  195. if($this->_iOwnerId != $this->getUserId() && !$this->isAllowedPost())
  196. return array();
  197. bx_import('BxDolMenu');
  198. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post'));
  199. $oMenu->setMenuId('timeline-post-menu');
  200. $oMenu->setSelected($this->getName(), 'post-text');
  201. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  202. return array('content' => $sContent, 'menu' => $oMenu);
  203. }
  204. public function serviceGetBlockViewProfile($iProfileId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  205. {
  206. if (!$iProfileId) {
  207. $iProfileId = bx_process_input(bx_get('id'), BX_DATA_INT);
  208. $iProfileId = BxDolProfile::getInstanceByContentAndType($iProfileId, 'bx_persons')->id();
  209. }
  210. if (!$iProfileId)
  211. return array();
  212. $sJsObject = $this->_oConfig->getJsObject('view');
  213. $aParams = $this->_prepareParams('owner', $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  214. $this->_iOwnerId = $aParams['owner_id'];
  215. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  216. $aMenu = array(
  217. 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),
  218. 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)),
  219. 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')),
  220. //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')),
  221. );
  222. bx_import('BxTemplMenuInteractive');
  223. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  224. $oMenu->setSelected('', 'timeline-view-all');
  225. $sContent = $this->_oTemplate->getViewBlock($aParams);
  226. return array('content' => $sContent, 'menu' => $oMenu);
  227. }
  228. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  229. {
  230. $aParams = $this->_prepareParams('connections', $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  231. $this->_iOwnerId = $aParams['owner_id'];
  232. $sContent = $this->_oTemplate->getViewBlock($aParams);
  233. return array('content' => $sContent);
  234. }
  235. public function serviceGetBlockItem()
  236. {
  237. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  238. if(!$iItemId)
  239. return array();
  240. return array('content' => $this->_oTemplate->getViewItemBlock($iItemId));
  241. }
  242. public function serviceGetShareOnclick($iOwnerId, $sType, $sAction, $iObjectId)
  243. {
  244. $sJsObject = $this->_oConfig->getJsObject('view');
  245. $sFormat = "%s.shareItem(this, %d, '%s', '%s', %d);";
  246. $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getUserId(); //--- in whose timeline the content will be shared
  247. return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
  248. }
  249. /*
  250. * COMMON METHODS
  251. */
  252. public function getFormText()
  253. {
  254. bx_import('BxDolForm');
  255. $oForm = BxDolForm::getObjectInstance('mod_tml_text', 'mod_tml_text_add');
  256. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  257. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  258. $oForm->initChecker();
  259. if($oForm->isSubmittedAndValid()) {
  260. $iUserId = $this->getUserId();
  261. list($sUserName) = $this->getUserInfo($iUserId);
  262. $sType = $oForm->getCleanValue('type');
  263. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  264. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  265. $sContent = $sDescription = $oForm->getCleanValue('content');
  266. $sContent = serialize(array('text' => $sContent));
  267. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  268. $iId = $oForm->insert(array(
  269. 'object_id' => $iUserId,
  270. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  271. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_wrote')),
  272. 'description' => $sDescription,
  273. 'date' => time()
  274. ));
  275. if(!empty($iId)) {
  276. $this->onPost($iId);
  277. return array('id' => $iId);
  278. }
  279. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  280. }
  281. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  282. }
  283. public function getFormLink()
  284. {
  285. bx_import('BxDolForm');
  286. $oForm = BxDolForm::getObjectInstance('mod_tml_link', 'mod_tml_link_add');
  287. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  288. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  289. $oForm->initChecker();
  290. if($oForm->isSubmittedAndValid()) {
  291. $iUserId = $this->getUserId();
  292. list($sUserName) = $this->getUserInfo($iUserId);
  293. $sType = $oForm->getCleanValue('type');
  294. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  295. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  296. $sUrl = $oForm->getCleanValue('content');
  297. $sContent = bx_file_get_contents($sUrl);
  298. preg_match("/<title>(.*)<\/title>/", $sContent, $aMatch);
  299. $sTitle = $aMatch ? $aMatch[1] : '';
  300. preg_match("/<meta.*name[='\" ]+description['\"].*content[='\" ]+(.*)['\"].*><\/meta>/", $sContent, $aMatch);
  301. $sDescription = $aMatch ? $aMatch[1] : '';
  302. $sContent = serialize(array(
  303. 'url' => strpos($sUrl, 'http://') === false && strpos($sUrl, 'https://') === false ? 'http://' . $sUrl : $sUrl,
  304. 'title' => $sTitle,
  305. 'text' => $sDescription
  306. ));
  307. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  308. $iId = $oForm->insert(array(
  309. 'object_id' => $iUserId,
  310. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  311. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_shared_link')),
  312. 'description' => bx_process_input($sUrl . ' - ' . $sTitle),
  313. 'date' => time()
  314. ));
  315. if(!empty($iId)) {
  316. $this->onPost($iId);
  317. return array('id' => $iId);
  318. }
  319. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  320. }
  321. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  322. }
  323. public function getFormPhoto()
  324. {
  325. $aFormNested = array(
  326. 'inputs' => array(
  327. 'file_title' => array(
  328. 'type' => 'text',
  329. 'name' => 'file_title[]',
  330. 'value' => '{file_title}',
  331. 'caption' => _t('_bx_timeline_form_photo_input_title'),
  332. 'required' => true,
  333. 'checker' => array(
  334. 'func' => 'length',
  335. 'params' => array(1, 150),
  336. 'error' => _t('_bx_timeline_form_photo_input_err_title')
  337. ),
  338. 'db' => array (
  339. 'pass' => 'Xss',
  340. ),
  341. ),
  342. 'file_text' => array(
  343. 'type' => 'textarea',
  344. 'name' => 'file_text[]',
  345. 'caption' => _t('_bx_timeline_form_photo_input_description'),
  346. 'required' => true,
  347. 'checker' => array(
  348. 'func' => 'length',
  349. 'params' => array(10, 5000),
  350. 'error' => _t('_bx_timeline_form_photo_input_err_description')
  351. ),
  352. 'db' => array (
  353. 'pass' => 'Xss',
  354. ),
  355. ),
  356. ),
  357. );
  358. bx_import('BxDolForm');
  359. $oForm = BxDolForm::getObjectInstance('mod_tml_photo', 'mod_tml_photo_add');
  360. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  361. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  362. bx_import('BxDolFormNested');
  363. $oFormNested = new BxDolFormNested('content', $aFormNested, 'do_submit');
  364. $oForm->aInputs['content']['storage_object'] = $this->_oConfig->getObject('storage');
  365. $oForm->aInputs['content']['images_transcoder'] = $this->_oConfig->getObject('transcoder_preview');
  366. $oForm->aInputs['content']['uploaders'] = $this->_oConfig->getUploaders('image');
  367. $oForm->aInputs['content']['multiple'] = false;
  368. $oForm->aInputs['content']['ghost_template'] = $oFormNested;
  369. $oForm->initChecker();
  370. if($oForm->isSubmittedAndValid()) {
  371. $iUserId = $this->getUserId();
  372. list($sUserName) = $this->getUserInfo($iUserId);
  373. $sType = $oForm->getCleanValue('type');
  374. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  375. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  376. $aPhIds = $oForm->getCleanValue('content');
  377. BxDolForm::setSubmittedValue('content', serialize(array()), $oForm->aFormAttrs['method']);
  378. $iId = $oForm->insert(array(
  379. 'object_id' => $iUserId,
  380. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  381. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_added_photo')),
  382. 'description' => '',
  383. 'date' => time()
  384. ));
  385. if(!empty($iId)) {
  386. $iPhIds = count($aPhIds);
  387. if($iPhIds > 0) {
  388. $aPhTitles = $oForm->getCleanValue('file_title');
  389. $aPhTexts = $oForm->getCleanValue('file_text');
  390. bx_import('BxDolStorage');
  391. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  392. for($i = 0; $i < $iPhIds; $i++)
  393. if($this->_oDb->savePhoto($iId, $aPhIds[$i], $aPhTitles[$i], $aPhTexts[$i]))
  394. $oStorage->afterUploadCleanup($aPhIds[$i], $iUserId);
  395. }
  396. $this->onPost($iId);
  397. return array('id' => $iId);
  398. }
  399. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  400. }
  401. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  402. }
  403. public function getCmtsObject($sSystem, $iId)
  404. {
  405. if(empty($sSystem) || (int)$iId == 0)
  406. return false;
  407. bx_import('BxDolCmts');
  408. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  409. if(!$oCmts->isEnabled())
  410. return false;
  411. return $oCmts;
  412. }
  413. public function getUserId()
  414. {
  415. return isLogged() ? bx_get_logged_profile_id() : 0;
  416. }
  417. public function getUserInfo($iUserId = 0)
  418. {
  419. bx_import('BxDolProfile');
  420. $oProfile = BxDolProfile::getInstance($iUserId);
  421. if (!$oProfile) {
  422. bx_import('BxDolProfileUndefined');
  423. $oProfile = BxDolProfileUndefined::getInstance();
  424. }
  425. return array(
  426. $oProfile->getDisplayName(),
  427. $oProfile->getUrl(),
  428. $oProfile->getIcon(),
  429. $oProfile->getUnit()
  430. );
  431. }
  432. public function isAllowedPost($bPerform = false)
  433. {
  434. if(isAdmin())
  435. return true;
  436. $iUserId = $this->getUserId();
  437. if($iUserId == 0 && $this->_oConfig->isAllowGuestComments())
  438. return true;
  439. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  440. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  441. }
  442. public function isAllowedDelete($aEvent, $bPerform = false)
  443. {
  444. if(isAdmin())
  445. return true;
  446. $iUserId = (int)$this->getUserId();
  447. if((int)$aEvent['owner_id'] == $iUserId)
  448. return true;
  449. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  450. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  451. }
  452. public function isAllowedComment($aEvent, $bPerform = false)
  453. {
  454. $mixedComments = $this->getCommentsData($aEvent['comments']);
  455. if($mixedComments === false)
  456. return false;
  457. list($sSystem, $iObjectId) = $mixedComments;
  458. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  459. $oCmts->addCssJs();
  460. if(isAdmin())
  461. return true;
  462. return $oCmts->isPostReplyAllowed($bPerform);
  463. }
  464. public function onPost($iId)
  465. {
  466. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  467. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  468. $sPostType = 'system';
  469. $iSenderId = $aEvent['owner_id'];
  470. }
  471. else {
  472. $sPostType = 'common';
  473. $iSenderId = $aEvent['object_id'];
  474. }
  475. //--- Event -> Post for Alerts Engine ---//
  476. bx_import('BxDolAlerts');
  477. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'post_' . $sPostType, $iId, $iSenderId);
  478. $oAlert->alert();
  479. //--- Event -> Post for Alerts Engine ---//
  480. }
  481. public function onShare($iId)
  482. {
  483. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  484. $aContent = unserialize($aEvent['content']);
  485. $iSharedId = $this->_oDb->updateSharesCounter($aContent['type'], $aContent['action'], $aContent['object_id']);
  486. //--- Timeline -> Update for Alerts Engine ---//
  487. bx_import('BxDolAlerts');
  488. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'share', $iSharedId, $aEvent['object_id']);
  489. $oAlert->alert();
  490. //--- Timeline -> Update for Alerts Engine ---//
  491. }
  492. public function onDelete($aEvent)
  493. {
  494. $aPhotos = $this->_oDb->getPhotos($aEvent['id']);
  495. if(is_array($aPhotos) && !empty($aPhotos)) {
  496. bx_import('BxDolStorage');
  497. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  498. foreach($aPhotos as $aPhoto)
  499. $oStorage->deleteFile($aPhoto['id']);
  500. $this->_oDb->deletePhotos($aEvent['id']);
  501. }
  502. if($aEvent['type'] == $this->_oConfig->getPrefix('common_post') . BX_TIMELINE_PARSE_TYPE_SHARE) {
  503. $aContent = unserialize($aEvent['content']);
  504. $this->_oDb->updateSharesCounter($aContent['type'], $aContent['action'], $aContent['object_id'], -1);
  505. }
  506. //--- Event -> Delete for Alerts Engine ---//
  507. bx_import('BxDolAlerts');
  508. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'delete', $aEvent['id'], $this->getUserId());
  509. $oAlert->alert();
  510. //--- Event -> Delete for Alerts Engine ---//
  511. }
  512. public function getCommentsData(&$aComments)
  513. {
  514. if(empty($aComments) || !is_array($aComments))
  515. return false;
  516. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  517. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  518. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  519. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  520. return false;
  521. return array($sSystem, $iObjectId, $iCount);
  522. }
  523. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  524. {
  525. $aParams = array();
  526. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_OWNER;
  527. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  528. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  529. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  530. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  531. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  532. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
  533. return $aParams;
  534. }
  535. protected function _prepareParamsGet()
  536. {
  537. $aParams = array();
  538. $sType = bx_get('type');
  539. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_OWNER;
  540. $iOwnerId = bx_get('owner_id');
  541. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  542. $iStart = bx_get('start');
  543. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  544. $iPerPage = bx_get('per_page');
  545. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  546. $sFilter = bx_get('filter');
  547. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  548. $aModules = bx_get('modules');
  549. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  550. $iTimeline = bx_get('timeline');
  551. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  552. return $aParams;
  553. }
  554. protected function _updateHandlers($sModuleUri = 'all', $bInstall = true)
  555. {
  556. $aModules = $sModuleUri == 'all' ? $this->_oDb->getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
  557. foreach($aModules as $aModule) {
  558. if(!BxDolRequest::serviceExists($aModule, 'get_timeline_data'))
  559. continue;
  560. $aData = BxDolService::call($aModule['name'], 'get_timeline_data');
  561. if(empty($aData) || !is_array($aData))
  562. continue;
  563. if($bInstall)
  564. $this->_oDb->insertData($aData);
  565. else
  566. $this->_oDb->deleteData($aData);
  567. }
  568. BxDolAlerts::cache();
  569. }
  570. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  571. header('Content-type: text/html; charset=utf-8');
  572. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  573. $oParser = new Services_JSON();
  574. $s = $oParser->encode($a);
  575. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  576. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  577. echo $s;
  578. }
  579. /**
  580. * Get RSS for specified owner.
  581. *
  582. * @param string $sUsername wall owner username
  583. * @return string with RSS.
  584. */
  585. function actionRss($sUsername)
  586. {
  587. $aOwner = $this->_oDb->getUser($sUsername, 'username');
  588. $aEvents = $this->_oDb->getEvents(array(
  589. 'type' => 'owner',
  590. 'owner_id' => $aOwner['id'],
  591. 'order' => 'desc',
  592. 'start' => 0,
  593. 'count' => $this->_oConfig->getRssLength(),
  594. 'filter' => ''
  595. ));
  596. $sRssBaseUrl = $this->_oConfig->getBaseUri() . 'index/' . $aOwner['username'] . '/';
  597. $aRssData = array();
  598. foreach($aEvents as $aEvent) {
  599. if(empty($aEvent['title'])) continue;
  600. $aRssData[$aEvent['id']] = array(
  601. 'UnitID' => $aEvent['id'],
  602. 'OwnerID' => $aOwner['id'],
  603. 'UnitTitle' => $aEvent['title'],
  604. 'UnitLink' => BX_DOL_URL_ROOT . $sRssBaseUrl . '#wall-event-' . $aEvent['id'],
  605. 'UnitDesc' => $aEvent['description'],
  606. 'UnitDateTimeUTS' => $aEvent['date'],
  607. 'UnitIcon' => ''
  608. );
  609. }
  610. $oRss = new BxDolRssFactory();
  611. header('Content-Type: text/html; charset=utf-8');
  612. return $oRss->GenRssByData($aRssData, $aOwner['username'] . ' ' . _t('_wall_rss_caption'), $sRssBaseUrl);
  613. }
  614. }
  615. /** @} */