BxTimelineModule.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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_TYPE_ITEM', 'view_item');
  17. define('BX_TIMELINE_HANDLER_TYPE_INSERT', 'insert');
  18. define('BX_TIMELINE_HANDLER_TYPE_UPDATE', 'update');
  19. define('BX_TIMELINE_HANDLER_TYPE_DELETE', 'delete');
  20. define('BX_TIMELINE_FILTER_ALL', 'all');
  21. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  22. define('BX_TIMELINE_FILTER_OTHER', 'other');
  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_POST', 'post');
  27. define('BX_TIMELINE_PARSE_TYPE_SHARE', 'share');
  28. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  29. class BxTimelineModule extends BxDolModule
  30. {
  31. var $_iOwnerId;
  32. var $_sJsPostObject;
  33. var $_sJsViewObject;
  34. var $_aPostElements;
  35. var $_sJsOutlineObject;
  36. var $_sDividerTemplate;
  37. var $_sBalloonTemplate;
  38. var $_sCmtPostTemplate;
  39. var $_sCmtViewTemplate;
  40. var $_sCmtTemplate;
  41. /**
  42. * Constructor
  43. */
  44. function __construct($aModule)
  45. {
  46. parent::BxDolModule($aModule);
  47. $this->_oConfig->init($this->_oDb);
  48. $this->_oTemplate->init();
  49. $this->_iOwnerId = 0;
  50. }
  51. /**
  52. * ACTION METHODS
  53. */
  54. public function actionPost()
  55. {
  56. $sType = bx_process_input($_POST['type']);
  57. $sMethod = 'getForm' . ucfirst($sType);
  58. if(!method_exists($this, $sMethod)) {
  59. $this->_echoResultJson(array());
  60. return;
  61. }
  62. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  63. $mixedAllowed = $this->isAllowedPost(true);
  64. if($mixedAllowed !== true) {
  65. $this->_echoResultJson(array('msg' => strip_tags($mixedAllowed)));
  66. return;
  67. }
  68. $aResult = $this->$sMethod();
  69. $this->_echoResultJson($aResult);
  70. }
  71. function actionDelete()
  72. {
  73. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  74. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  75. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  76. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  77. if($mixedAllowed !== true) {
  78. $this->_echoResultJson(array('code' => 1, 'msg' => strip_tags($mixedAllowed)));
  79. return;
  80. }
  81. if(!$this->_oDb->deleteEvent(array('id' => $iId))) {
  82. $this->_echoResultJson(array('code' => 2));
  83. return;
  84. }
  85. $this->onDelete($aEvent);
  86. $this->_echoResultJson(array('code' => 0, 'id' => $iId));
  87. }
  88. public function actionShare()
  89. {
  90. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  91. $aContent = array(
  92. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  93. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  94. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  95. );
  96. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  97. if(empty($aShared) || !is_array($aShared)) {
  98. $this->_echoResultJson(array('code' => 1, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  99. return;
  100. }
  101. $mixedAllowed = $this->isAllowedShare($aShared, true);
  102. if($mixedAllowed !== true) {
  103. $this->_echoResultJson(array('code' => 2, 'msg' => strip_tags($mixedAllowed)));
  104. return;
  105. }
  106. $iId = $this->_oDb->insertEvent(array(
  107. 'owner_id' => $iOwnerId,
  108. 'type' => $this->_oConfig->getPrefix('common_post') . 'share',
  109. 'action' => '',
  110. 'object_id' => $this->getUserId(),
  111. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  112. 'content' => serialize($aContent),
  113. 'title' => '',
  114. 'description' => ''
  115. ));
  116. if(!empty($iId)) {
  117. $this->onShare($iId, $aShared);
  118. $sCounter = $this->_oTemplate->getShareCounter($aContent['type'], $aContent['action'], $aContent['object_id']);
  119. $this->_echoResultJson(array('code' => 0, 'counter' => $sCounter, 'msg' => _t('_bx_timeline_txt_msg_success_share')));
  120. return;
  121. }
  122. $this->_echoResultJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  123. }
  124. function actionGetPost()
  125. {
  126. $this->_oConfig->setJsMode(true);
  127. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  128. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  129. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  130. $this->_echoResultJson(array('item' => $this->_oTemplate->getPost($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId))));
  131. }
  132. function actionGetPosts()
  133. {
  134. $this->_oConfig->setJsMode(true);
  135. $aParams = $this->_prepareParamsGet();
  136. list($sItems, $sLoadMore, $sBack) = $this->_oTemplate->getPosts($aParams);
  137. $this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore, 'back' => $sBack));
  138. }
  139. public function actionGetPostForm($sType)
  140. {
  141. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  142. $sMethod = 'getForm' . ucfirst($sType);
  143. if(!method_exists($this, $sMethod)) {
  144. $this->_echoResultJson(array());
  145. return;
  146. }
  147. $aResult = $this->$sMethod();
  148. $this->_echoResultJson($aResult);
  149. }
  150. public function actionGetComments()
  151. {
  152. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  153. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  154. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  155. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  156. $this->_echoResultJson(array('content' => $sComments));
  157. }
  158. public function actionGetPostPopup()
  159. {
  160. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  161. if(!$iItemId) {
  162. $this->_echoResultJson(array());
  163. return;
  164. }
  165. echo $this->_oTemplate->getViewItemPopup($iItemId);
  166. }
  167. public function actionGetSharedBy() {
  168. $iSharedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  169. echo $this->_oTemplate->getSharedBy($iSharedId);
  170. }
  171. function actionRss($iOwnerId)
  172. {
  173. list($sUserName) = $this->getUserInfo($iOwnerId);
  174. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  175. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  176. $aParams = $this->_prepareParams('owner', $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  177. $aEvents = $this->_oDb->getEvents($aParams);
  178. $aRssData = array();
  179. foreach($aEvents as $aEvent) {
  180. if(empty($aEvent['title'])) continue;
  181. $aRssData[$aEvent['id']] = array(
  182. 'UnitID' => $aEvent['id'],
  183. 'UnitTitle' => $aEvent['title'],
  184. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  185. 'UnitDesc' => $aEvent['description'],
  186. 'UnitDateTimeUTS' => $aEvent['date'],
  187. );
  188. }
  189. bx_import('BxDolRssFactory');
  190. $oRss = new BxDolRssFactory();
  191. header('Content-Type: text/html; charset=utf-8');
  192. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  193. }
  194. /**
  195. * SERVICE METHODS
  196. */
  197. public function serviceAddHandlers($sModuleUri = 'all')
  198. {
  199. $this->_updateHandlers($sModuleUri, true);
  200. }
  201. public function serviceDeleteHandlers($sModuleUri = 'all')
  202. {
  203. $this->_updateHandlers($sModuleUri, false);
  204. }
  205. function serviceGetActionsChecklist()
  206. {
  207. $aHandlers = $this->_oConfig->getHandlers();
  208. $aResults = array();
  209. foreach($aHandlers as $aHandler) {
  210. if($aHandler['type'] != BX_TIMELINE_HANDLER_TYPE_INSERT)
  211. continue;
  212. $aModule = $this->_oDb->getModuleByName($aHandler['module_name']);
  213. if(empty($aModule))
  214. $aModule['title'] = _t('_bx_timeline_alert_module_' . $aHandler['alert_unit']);
  215. $aResults[$aHandler['id']] = $aModule['title'] . ' (' . _t('_bx_timeline_alert_action_' . $aHandler['alert_action']) . ')';
  216. }
  217. asort($aResults);
  218. return $aResults;
  219. }
  220. public function serviceResponse($oAlert)
  221. {
  222. bx_import('Response', $this->_aModule);
  223. $oResponse = new BxTimelineResponse($this);
  224. $oResponse->response($oAlert);
  225. }
  226. public function serviceGetBlockPost($iProfileId = 0)
  227. {
  228. return $this->serviceGetBlockPostProfile($iProfileId);
  229. }
  230. public function serviceGetBlockPostProfile($iProfileId = 0)
  231. {
  232. if(!$iProfileId && bx_get('id') !== false) {
  233. $oProfile = BxDolProfile::getInstanceByContentAndType(bx_process_input(bx_get('id'), BX_DATA_INT), 'bx_persons');
  234. if(!empty($oProfile))
  235. $iProfileId = $oProfile->id();
  236. }
  237. if(!$iProfileId)
  238. return array();
  239. $this->_iOwnerId = $iProfileId;
  240. list($sUserName, $sUserUrl) = $this->getUserInfo($iProfileId);
  241. if($this->isAllowedPost() !== true)
  242. return array();
  243. return array(
  244. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId)
  245. );
  246. }
  247. public function serviceGetBlockView($iProfileId = 0)
  248. {
  249. $aBlock = $this->serviceGetBlockViewProfile($iProfileId);
  250. if(!empty($aBlock))
  251. return $aBlock;
  252. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  253. }
  254. public function serviceGetBlockViewProfile($iProfileId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  255. {
  256. if(!$iProfileId && bx_get('id') !== false) {
  257. $oProfile = BxDolProfile::getInstanceByContentAndType(bx_process_input(bx_get('id'), BX_DATA_INT), 'bx_persons');
  258. if(!empty($oProfile))
  259. $iProfileId = $oProfile->id();
  260. }
  261. if (!$iProfileId)
  262. return array();
  263. $sJsObject = $this->_oConfig->getJsObject('view');
  264. $aParams = $this->_prepareParams(BX_TIMELINE_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  265. $this->_iOwnerId = $aParams['owner_id'];
  266. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  267. $aMenu = array(
  268. 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),
  269. 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)),
  270. 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')),
  271. array('id' => 'timeline-get-rss', 'name' => 'timeline-get-rss', 'class' => '', 'link' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $iProfileId . '/', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  272. );
  273. bx_import('BxTemplMenuInteractive');
  274. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  275. $oMenu->setSelected('', 'timeline-view-all');
  276. $sContent = $this->_oTemplate->getViewBlock($aParams);
  277. return array('content' => $sContent, 'menu' => $oMenu);
  278. }
  279. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  280. {
  281. $aParams = $this->_prepareParams(BX_TIMELINE_TYPE_CONNECTIONS, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  282. $this->_iOwnerId = $aParams['owner_id'];
  283. $sContent = $this->_oTemplate->getViewBlock($aParams);
  284. return array('content' => $sContent);
  285. }
  286. public function serviceGetBlockItem()
  287. {
  288. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  289. if(!$iItemId)
  290. return array();
  291. return array('content' => $this->_oTemplate->getViewItemBlock($iItemId));
  292. }
  293. public function serviceGetShareElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  294. {
  295. $aParams = array_merge($this->_oConfig->getShareDefaults(), $aParams);
  296. return $this->_oTemplate->getShareElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  297. }
  298. public function serviceGetShareCounter($sType, $sAction, $iObjectId)
  299. {
  300. return $this->_oTemplate->getShareCounter($sType, $sAction, $iObjectId);
  301. }
  302. public function serviceGetShareJsScript()
  303. {
  304. return $this->_oTemplate->getShareJsScript();
  305. }
  306. public function serviceGetShareJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  307. {
  308. return $this->_oTemplate->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  309. }
  310. /*
  311. * COMMON METHODS
  312. */
  313. public function getFormPost()
  314. {
  315. bx_import('BxDolForm');
  316. $oForm = BxDolForm::getObjectInstance('mod_tml_post', 'mod_tml_post_add');
  317. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  318. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  319. if(isset($oForm->aInputs['photo'])) {
  320. $aFormNested = array(
  321. 'params' =>array(
  322. 'nested_form_template' => 'uploader_nfw.html'
  323. ),
  324. 'inputs' => array(),
  325. );
  326. bx_import('BxDolFormNested');
  327. $oFormNested = new BxDolFormNested('photo', $aFormNested, 'do_submit', $this->_oTemplate);
  328. $oForm->aInputs['photo']['storage_object'] = $this->_oConfig->getObject('storage');
  329. $oForm->aInputs['photo']['images_transcoder'] = $this->_oConfig->getObject('transcoder_preview');
  330. $oForm->aInputs['photo']['uploaders'] = $this->_oConfig->getUploaders('image');
  331. $oForm->aInputs['photo']['upload_buttons_titles'] = array('Simple' => 'camera');
  332. $oForm->aInputs['photo']['multiple'] = false;
  333. $oForm->aInputs['photo']['ghost_template'] = $oFormNested;
  334. }
  335. $oForm->initChecker();
  336. if($oForm->isSubmittedAndValid()) {
  337. $iUserId = $this->getUserId();
  338. list($sUserName) = $this->getUserInfo($iUserId);
  339. $sType = $oForm->getCleanValue('type');
  340. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  341. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  342. $aContent = array();
  343. //--- Process Text ---//
  344. $sText = $oForm->getCleanValue('text');
  345. unset($oForm->aInputs['text']);
  346. $aContent['text'] = $sText;
  347. //--- Process Link ---//
  348. $sLink = $oForm->getCleanValue('link');
  349. unset($oForm->aInputs['link']);
  350. if(!empty($sLink)) {
  351. $sLinkContent = bx_file_get_contents($sLink);
  352. $aMatch = array();
  353. preg_match("/<title>(.*)<\/title>/", $sLinkContent, $aMatch);
  354. $sLinkTitle = $aMatch ? $aMatch[1] : '';
  355. preg_match("/<meta.*name[='\" ]+description['\"].*content[='\" ]+(.*)['\"].*><\/meta>/", $sLinkContent, $aMatch);
  356. $sLinkDescription = $aMatch ? $aMatch[1] : '';
  357. $aContent['url'] = strpos($sLink, 'http://') === false && strpos($sLink, 'https://') === false ? 'http://' . $sLink : $sLink;
  358. $aContent['title'] = $sLinkTitle;
  359. if(empty($aContent['text']) && !empty($sLinkDescription))
  360. $aContent['text'] = $sLinkDescription;
  361. }
  362. //--- Process Photos ---//
  363. $aPhIds = $oForm->getCleanValue('photo');
  364. unset($oForm->aInputs['photo']);
  365. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample'));
  366. $sDescription = $aContent['text'];
  367. if(empty($sDescription) && !empty($aContent['link_text']))
  368. $sDescription = $aContent['link_text'];
  369. $iId = $oForm->insert(array(
  370. 'object_id' => $iUserId,
  371. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  372. 'content' => serialize($aContent),
  373. 'title' => $sTitle,
  374. 'description' => $sDescription,
  375. 'date' => time()
  376. ));
  377. if(!empty($iId)) {
  378. if(!empty($aPhIds) && is_array($aPhIds)) {
  379. bx_import('BxDolStorage');
  380. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  381. $iPhIds = count($aPhIds);
  382. for($i = 0; $i < $iPhIds; $i++)
  383. if($this->_oDb->savePhoto($iId, $aPhIds[$i]))
  384. $oStorage->afterUploadCleanup($aPhIds[$i], $iUserId);
  385. }
  386. $this->onPost($iId);
  387. return array('id' => $iId);
  388. }
  389. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  390. }
  391. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  392. }
  393. public function getCmtsObject($sSystem, $iId)
  394. {
  395. if(empty($sSystem) || (int)$iId == 0)
  396. return false;
  397. bx_import('BxDolCmts');
  398. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  399. if(!$oCmts->isEnabled())
  400. return false;
  401. return $oCmts;
  402. }
  403. public function getVoteObject($sSystem, $iId)
  404. {
  405. if(empty($sSystem) || (int)$iId == 0)
  406. return false;
  407. bx_import('BxDolVote');
  408. $oVote = BxDolVote::getObjectInstance($sSystem, $iId);
  409. if(!$oVote->isEnabled())
  410. return false;
  411. return $oVote;
  412. }
  413. public function getUserId()
  414. {
  415. return isLogged() ? bx_get_logged_profile_id() : 0;
  416. }
  417. public function getUserIp()
  418. {
  419. return $_SERVER['REMOTE_ADDR'];
  420. }
  421. public function getUserInfo($iUserId = 0)
  422. {
  423. bx_import('BxDolProfile');
  424. $oProfile = BxDolProfile::getInstance($iUserId);
  425. if (!$oProfile) {
  426. bx_import('BxDolProfileUndefined');
  427. $oProfile = BxDolProfileUndefined::getInstance();
  428. }
  429. return array(
  430. $oProfile->getDisplayName(),
  431. $oProfile->getUrl(),
  432. $oProfile->getThumb(),
  433. $oProfile->getUnit()
  434. );
  435. }
  436. //--- Check permissions methods ---//
  437. public function checkActionErrorMsg ($iAction)
  438. {
  439. $iId = $this->_getAuthorId();
  440. $check_res = checkAction($iId, $iAction);
  441. return $check_res[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $check_res[CHECK_ACTION_MESSAGE] : '';
  442. }
  443. public function isAllowedPost($bPerform = false)
  444. {
  445. if(isAdmin())
  446. return true;
  447. $iUserId = $this->getUserId();
  448. if($this->_iOwnerId == $this->getUserId())
  449. return true;
  450. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  451. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  452. }
  453. public function isAllowedDelete($aEvent, $bPerform = false)
  454. {
  455. if(isAdmin())
  456. return true;
  457. $iUserId = (int)$this->getUserId();
  458. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  459. return true;
  460. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  461. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  462. }
  463. public function isAllowedComment($aEvent, $bPerform = false)
  464. {
  465. $mixedComments = $this->getCommentsData($aEvent['comments']);
  466. if($mixedComments === false)
  467. return false;
  468. list($sSystem, $iObjectId) = $mixedComments;
  469. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  470. $oCmts->addCssJs();
  471. $iUserId = (int)$this->getUserId();
  472. if($iUserId == 0)
  473. return false;
  474. if(isAdmin())
  475. return true;
  476. return $oCmts->isPostReplyAllowed($bPerform);
  477. }
  478. public function isAllowedVote($aEvent, $bPerform = false)
  479. {
  480. $mixedVotes = $this->getVotesData($aEvent['votes']);
  481. if($mixedVotes === false)
  482. return false;
  483. list($sSystem, $iObjectId) = $mixedVotes;
  484. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  485. $oVote->addCssJs();
  486. $iUserId = (int)$this->getUserId();
  487. if($iUserId == 0)
  488. return false;
  489. if(isAdmin())
  490. return true;
  491. return $oVote->isAllowedVote($bPerform);
  492. }
  493. public function isAllowedShare($aEvent, $bPerform = false)
  494. {
  495. if(isAdmin())
  496. return true;
  497. $iUserId = (int)$this->getUserId();
  498. if($iUserId == 0)
  499. return false;
  500. $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
  501. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  502. }
  503. public function onPost($iId)
  504. {
  505. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  506. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  507. $sPostType = 'system';
  508. $iSenderId = $aEvent['owner_id'];
  509. }
  510. else {
  511. $sPostType = 'common';
  512. $iSenderId = $aEvent['object_id'];
  513. }
  514. //--- Event -> Post for Alerts Engine ---//
  515. bx_import('BxDolAlerts');
  516. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'post_' . $sPostType, $iId, $iSenderId);
  517. $oAlert->alert();
  518. //--- Event -> Post for Alerts Engine ---//
  519. }
  520. public function onShare($iId, $aShared = array())
  521. {
  522. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  523. if(empty($aShared)) {
  524. $aContent = unserialize($aEvent['content']);
  525. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  526. if(empty($aShared) || !is_array($aShared))
  527. return;
  528. }
  529. $iUserId = $this->getUserId();
  530. $this->_oDb->insertShareTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aShared['id']);
  531. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares']);
  532. //--- Timeline -> Update for Alerts Engine ---//
  533. bx_import('BxDolAlerts');
  534. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'share', $aShared['id'], $iUserId);
  535. $oAlert->alert();
  536. //--- Timeline -> Update for Alerts Engine ---//
  537. }
  538. public function onDelete($aEvent)
  539. {
  540. $aPhotos = $this->_oDb->getPhotos($aEvent['id']);
  541. if(is_array($aPhotos) && !empty($aPhotos)) {
  542. bx_import('BxDolStorage');
  543. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  544. foreach($aPhotos as $aPhoto)
  545. $oStorage->deleteFile($aPhoto['id']);
  546. $this->_oDb->deletePhotos($aEvent['id']);
  547. }
  548. if($aEvent['type'] == $this->_oConfig->getPrefix('common_post') . BX_TIMELINE_PARSE_TYPE_SHARE) {
  549. $this->_oDb->deleteShareTrack($aEvent['id']);
  550. $aContent = unserialize($aEvent['content']);
  551. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  552. if(!empty($aShared) && is_array($aShared))
  553. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares'], -1);
  554. }
  555. //--- Event -> Delete for Alerts Engine ---//
  556. bx_import('BxDolAlerts');
  557. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'delete', $aEvent['id'], $this->getUserId());
  558. $oAlert->alert();
  559. //--- Event -> Delete for Alerts Engine ---//
  560. }
  561. public function getVotesData(&$aVotes)
  562. {
  563. if(empty($aVotes) || !is_array($aVotes))
  564. return false;
  565. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  566. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  567. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  568. if($sSystem == '' || $iObjectId == 0)
  569. return false;
  570. return array($sSystem, $iObjectId, $iCount);
  571. }
  572. public function getCommentsData(&$aComments)
  573. {
  574. if(empty($aComments) || !is_array($aComments))
  575. return false;
  576. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  577. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  578. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  579. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  580. return false;
  581. return array($sSystem, $iObjectId, $iCount);
  582. }
  583. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  584. {
  585. $aParams = array();
  586. $aParams['browse'] = 'list';
  587. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_OWNER;
  588. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  589. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  590. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  591. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  592. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  593. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
  594. return $aParams;
  595. }
  596. protected function _prepareParamsGet()
  597. {
  598. $aParams = array();
  599. $aParams['browse'] = 'list';
  600. $sType = bx_get('type');
  601. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_OWNER;
  602. $iOwnerId = bx_get('owner_id');
  603. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  604. $iStart = bx_get('start');
  605. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  606. $iPerPage = bx_get('per_page');
  607. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  608. $sFilter = bx_get('filter');
  609. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  610. $aModules = bx_get('modules');
  611. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  612. $iTimeline = bx_get('timeline');
  613. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  614. return $aParams;
  615. }
  616. protected function _updateHandlers($sModuleUri = 'all', $bInstall = true)
  617. {
  618. $aModules = $sModuleUri == 'all' ? $this->_oDb->getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
  619. foreach($aModules as $aModule) {
  620. if(!BxDolRequest::serviceExists($aModule, 'get_timeline_data'))
  621. continue;
  622. $aData = BxDolService::call($aModule['name'], 'get_timeline_data');
  623. if(empty($aData) || !is_array($aData))
  624. continue;
  625. if($bInstall)
  626. $this->_oDb->insertData($aData);
  627. else
  628. $this->_oDb->deleteData($aData);
  629. }
  630. BxDolAlerts::cache();
  631. }
  632. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  633. header('Content-type: text/html; charset=utf-8');
  634. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  635. $oParser = new Services_JSON();
  636. $s = $oParser->encode($a);
  637. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  638. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  639. echo $s;
  640. }
  641. }
  642. /** @} */