BxTimelineModule.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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 TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxBaseModNotificationsModule');
  13. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  14. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  15. define('BX_TIMELINE_FILTER_ALL', 'all');
  16. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  17. define('BX_TIMELINE_FILTER_OTHER', 'other');
  18. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  19. define('BX_TIMELINE_PARSE_TYPE_SHARE', 'share');
  20. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  21. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  22. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  23. class BxTimelineModule extends BxBaseModNotificationsModule
  24. {
  25. protected $_sJsPostObject;
  26. protected $_sJsViewObject;
  27. protected $_aPostElements;
  28. protected $_sJsOutlineObject;
  29. protected $_sDividerTemplate;
  30. protected $_sBalloonTemplate;
  31. protected $_sCmtPostTemplate;
  32. protected $_sCmtViewTemplate;
  33. protected $_sCmtTemplate;
  34. /**
  35. * Constructor
  36. */
  37. function __construct($aModule)
  38. {
  39. parent::__construct($aModule);
  40. }
  41. /**
  42. * ACTION METHODS
  43. */
  44. public function actionPost()
  45. {
  46. $sType = bx_process_input($_POST['type']);
  47. $sMethod = 'getForm' . ucfirst($sType);
  48. if(!method_exists($this, $sMethod)) {
  49. $this->_echoResultJson(array());
  50. return;
  51. }
  52. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  53. $mixedAllowed = $this->isAllowedPost(true);
  54. if($mixedAllowed !== true) {
  55. $this->_echoResultJson(array('msg' => strip_tags($mixedAllowed)));
  56. return;
  57. }
  58. $aResult = $this->$sMethod();
  59. $this->_echoResultJson($aResult);
  60. }
  61. function actionDelete()
  62. {
  63. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  64. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  65. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  66. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  67. if($mixedAllowed !== true) {
  68. $this->_echoResultJson(array('code' => 1, 'msg' => strip_tags($mixedAllowed)));
  69. return;
  70. }
  71. if(!$this->deleteEvent($aEvent))
  72. $this->_echoResultJson(array('code' => 2));
  73. else
  74. $this->_echoResultJson(array('code' => 0, 'id' => $iId));
  75. }
  76. public function actionShare()
  77. {
  78. $iAuthorId = $this->getUserId();
  79. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  80. $aContent = array(
  81. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  82. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  83. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  84. );
  85. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  86. if(empty($aShared) || !is_array($aShared)) {
  87. $this->_echoResultJson(array('code' => 1, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  88. return;
  89. }
  90. $mixedAllowed = $this->isAllowedShare($aShared, true);
  91. if($mixedAllowed !== true) {
  92. $this->_echoResultJson(array('code' => 2, 'msg' => strip_tags($mixedAllowed)));
  93. return;
  94. }
  95. $bShared = $this->_oDb->isShared($aShared['id'], $iOwnerId, $iAuthorId);
  96. if($bShared) {
  97. $this->_echoResultJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_already_shared')));
  98. return;
  99. }
  100. $iId = $this->_oDb->insertEvent(array(
  101. 'owner_id' => $iOwnerId,
  102. 'type' => $this->_oConfig->getPrefix('common_post') . 'share',
  103. 'action' => '',
  104. 'object_id' => $iAuthorId,
  105. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  106. 'content' => serialize($aContent),
  107. 'title' => '',
  108. 'description' => ''
  109. ));
  110. if(empty($iId)) {
  111. $this->_echoResultJson(array('code' => 4, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  112. return;
  113. }
  114. $this->onShare($iId, $aShared);
  115. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  116. $sCounter = $this->_oTemplate->getShareCounter($aShared);
  117. $this->_echoResultJson(array(
  118. 'code' => 0,
  119. 'msg' => _t('_bx_timeline_txt_msg_success_share'),
  120. 'count' => $aShared['shares'],
  121. 'counter' => $sCounter,
  122. 'disabled' => !$bShared
  123. ));
  124. }
  125. function actionGetPost()
  126. {
  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, 'dynamic_mode' => true))));
  131. }
  132. function actionGetPosts()
  133. {
  134. $aParams = $this->_prepareParamsGet();
  135. list($sItems, $sLoadMore, $sBack) = $this->_oTemplate->getPosts($aParams);
  136. $this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore, 'back' => $sBack));
  137. }
  138. public function actionGetPostForm($sType)
  139. {
  140. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  141. $sMethod = 'getForm' . ucfirst($sType);
  142. if(!method_exists($this, $sMethod)) {
  143. $this->_echoResultJson(array());
  144. return;
  145. }
  146. $aResult = $this->$sMethod();
  147. $this->_echoResultJson($aResult);
  148. }
  149. public function actionGetComments()
  150. {
  151. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  152. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  153. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  154. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  155. $this->_echoResultJson(array('content' => $sComments));
  156. }
  157. public function actionAddAttachLink()
  158. {
  159. $aResult = $this->getFormAttachLink();
  160. $this->_echoResultJson($aResult);
  161. }
  162. public function actionDeleteAttachLink()
  163. {
  164. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  165. if(empty($iLinkId)) {
  166. $this->_echoResultJson(array());
  167. return;
  168. }
  169. $aResult = array();
  170. if($this->_oDb->deleteUnusedLinks($this->getUserId(), $iLinkId))
  171. $aResult = array('code' => 0);
  172. else
  173. $aResult = array('code' => 1, 'msg' => _t('_bx_timeline_form_post_input_link_err_delete'));
  174. $this->_echoResultJson($aResult);
  175. }
  176. public function actionGetAttachLinkForm()
  177. {
  178. echo $this->_oTemplate->getAttachLinkForm();
  179. }
  180. public function actionGetSharedBy()
  181. {
  182. $iSharedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  183. echo $this->_oTemplate->getSharedBy($iSharedId);
  184. }
  185. function actionRss($iOwnerId)
  186. {
  187. list($sUserName) = $this->getUserInfo($iOwnerId);
  188. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  189. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  190. $aParams = $this->_prepareParams('owner', $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  191. $aEvents = $this->_oDb->getEvents($aParams);
  192. $aRssData = array();
  193. foreach($aEvents as $aEvent) {
  194. if(empty($aEvent['title'])) continue;
  195. $aRssData[$aEvent['id']] = array(
  196. 'UnitID' => $aEvent['id'],
  197. 'UnitTitle' => $aEvent['title'],
  198. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  199. 'UnitDesc' => $aEvent['description'],
  200. 'UnitDateTimeUTS' => $aEvent['date'],
  201. );
  202. }
  203. $oRss = new BxDolRssFactory();
  204. header('Content-Type: application/xml; charset=utf-8');
  205. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  206. }
  207. /**
  208. * SERVICE METHODS
  209. *
  210. * Get Post block for a separate page.
  211. */
  212. public function serviceGetBlockPost($sProfileModule = 'bx_persons', $iProfileId = 0)
  213. {
  214. return $this->serviceGetBlockPostProfile($sProfileModule, $iProfileId);
  215. }
  216. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileId = 0)
  217. {
  218. if(empty($iProfileId) && !empty($sProfileModule) && bx_get('id') !== false) {
  219. $oProfile = BxDolProfile::getInstanceByContentAndType(bx_process_input(bx_get('id'), BX_DATA_INT), $sProfileModule);
  220. if(!empty($oProfile))
  221. $iProfileId = $oProfile->id();
  222. }
  223. if(!$iProfileId)
  224. return array();
  225. $this->_iOwnerId = $iProfileId;
  226. if($this->isAllowedPost() !== true)
  227. return array();
  228. return array(
  229. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId)
  230. );
  231. }
  232. /*
  233. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  234. */
  235. public function serviceGetBlockView($sProfileModule = 'bx_persons', $iProfileId = 0)
  236. {
  237. $aBlock = $this->serviceGetBlockViewProfile($sProfileModule, $iProfileId);
  238. if(!empty($aBlock))
  239. return $aBlock;
  240. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  241. }
  242. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  243. {
  244. if(empty($iProfileId) && !empty($sProfileModule) && bx_get('id') !== false) {
  245. $oProfile = BxDolProfile::getInstanceByContentAndType(bx_process_input(bx_get('id'), BX_DATA_INT), $sProfileModule);
  246. if(!empty($oProfile))
  247. $iProfileId = $oProfile->id();
  248. }
  249. if (!$iProfileId)
  250. return array();
  251. $sJsObject = $this->_oConfig->getJsObject('view');
  252. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  253. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  254. $this->_iOwnerId = $aParams['owner_id'];
  255. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  256. $aMenu = array(
  257. 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),
  258. 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)),
  259. 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')),
  260. 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')),
  261. );
  262. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  263. $oMenu->setSelected('', 'timeline-view-all');
  264. $sContent = $this->_oTemplate->getViewBlock($aParams);
  265. return array('content' => $sContent, 'menu' => $oMenu);
  266. }
  267. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  268. {
  269. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  270. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('account');
  271. $this->_iOwnerId = $aParams['owner_id'];
  272. $sContent = $this->_oTemplate->getViewBlock($aParams);
  273. return array('content' => $sContent);
  274. }
  275. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  276. {
  277. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  278. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('home');
  279. $this->_iOwnerId = $aParams['owner_id'];
  280. $sContent = $this->_oTemplate->getViewBlock($aParams);
  281. return array('content' => $sContent);
  282. }
  283. public function serviceGetBlockItem()
  284. {
  285. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  286. if(!$iItemId)
  287. return array();
  288. return array('content' => $this->_oTemplate->getItemBlock($iItemId));
  289. }
  290. public function serviceGetShareElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  291. {
  292. if(!$this->isEnabled())
  293. return '';
  294. $aParams = array_merge($this->_oConfig->getShareDefaults(), $aParams);
  295. return $this->_oTemplate->getShareElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  296. }
  297. public function serviceGetShareCounter($sType, $sAction, $iObjectId)
  298. {
  299. if(!$this->isEnabled())
  300. return '';
  301. $aShared = $this->_oDb->getShared($sType, $sAction, $iObjectId);
  302. return $this->_oTemplate->getShareCounter($aShared);
  303. }
  304. public function serviceGetShareJsScript()
  305. {
  306. if(!$this->isEnabled())
  307. return '';
  308. return $this->_oTemplate->getShareJsScript();
  309. }
  310. public function serviceGetShareJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  311. {
  312. if(!$this->isEnabled())
  313. return '';
  314. return $this->_oTemplate->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  315. }
  316. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  317. {
  318. if(empty($sSystem) || empty($iObjectId))
  319. return '';
  320. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  321. if($oCmts === false)
  322. return '';
  323. $iCounter = (int)$oCmts->getCommentsCount();
  324. return $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  325. 'href' => 'javascript:void(0)',
  326. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  327. 'bx_repeat:attrs' => array(
  328. array('key' => 'onclick', 'value' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")")
  329. ),
  330. 'content' => $iCounter > 0 ? $iCounter : ''
  331. ));
  332. }
  333. public function serviceGetSettingsCheckerHelper()
  334. {
  335. bx_import('FormCheckerHelper', $this->_aModule);
  336. return 'BxTimelineFormCheckerHelper';
  337. }
  338. /*
  339. * COMMON METHODS
  340. */
  341. public function deleteEvent($aEvent)
  342. {
  343. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  344. return false;
  345. $this->onDelete($aEvent);
  346. return true;
  347. }
  348. public function getFormAttachLink()
  349. {
  350. $iUserId = $this->getUserId();
  351. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  352. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  353. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  354. $oForm->initChecker();
  355. if($oForm->isSubmittedAndValid()) {
  356. $sLink = $oForm->getCleanValue('url');
  357. $aMatches = array();
  358. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  359. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  360. $aSiteInfo = bx_get_site_info($sLink, array(
  361. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  362. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  363. ));
  364. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'url' => $sLink, 'title' => $aSiteInfo['title'], 'text' => $aSiteInfo['description'], 'added' => time()));
  365. if(!empty($iId))
  366. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  367. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  368. }
  369. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  370. }
  371. public function getFormPost()
  372. {
  373. $iUserId = $this->getUserId();
  374. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_add'), $this->_oTemplate);
  375. $oForm->initChecker();
  376. if($oForm->isSubmittedAndValid()) {
  377. list($sUserName) = $this->getUserInfo($iUserId);
  378. $sType = $oForm->getCleanValue('type');
  379. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  380. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  381. $aContent = array();
  382. //--- Process Text ---//
  383. $sText = $oForm->getCleanValue('text');
  384. unset($oForm->aInputs['text']);
  385. $aContent['text'] = $this->_prepareTextForSave($sText);
  386. //--- Process Link ---//
  387. $aLinkIds = $oForm->getCleanValue('link');
  388. //--- Process Media ---//
  389. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  390. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  391. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample'));
  392. $sDescription = !empty($aContent['text']) ? $aContent['text'] : '';
  393. $iId = $oForm->insert(array(
  394. 'object_id' => $iUserId,
  395. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  396. 'content' => serialize($aContent),
  397. 'title' => $sTitle,
  398. 'description' => $sDescription,
  399. 'date' => time()
  400. ));
  401. if(!empty($iId)) {
  402. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  403. $oMetatags->keywordsAdd($iId, $aContent['text']);
  404. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  405. //--- Process Link ---//
  406. if(!empty($aLinkIds) && is_array($aLinkIds))
  407. foreach($aLinkIds as $iLinkId)
  408. $this->_oDb->saveLink($iId, $iLinkId);
  409. //--- Process Media ---//
  410. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  411. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  412. $this->onPost($iId);
  413. return array('id' => $iId);
  414. }
  415. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  416. }
  417. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  418. }
  419. public function getCmtsObject($sSystem, $iId)
  420. {
  421. if(empty($sSystem) || (int)$iId == 0)
  422. return false;
  423. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  424. if(!$oCmts->isEnabled())
  425. return false;
  426. return $oCmts;
  427. }
  428. public function getVoteObject($sSystem, $iId)
  429. {
  430. if(empty($sSystem) || (int)$iId == 0)
  431. return false;
  432. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  433. if(!$oVote->isEnabled())
  434. return false;
  435. return $oVote;
  436. }
  437. public function getAttachmentsMenuObject()
  438. {
  439. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  440. $oMenu->addMarkers(array(
  441. 'js_object' => $this->_oConfig->getJsObject('post'),
  442. ));
  443. return $oMenu;
  444. }
  445. public function getManageMenuObject()
  446. {
  447. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  448. }
  449. //--- Check permissions methods ---//
  450. public function isAllowedPost($bPerform = false)
  451. {
  452. if(isAdmin())
  453. return true;
  454. $iUserId = $this->getUserId();
  455. if($this->_iOwnerId == $this->getUserId())
  456. return true;
  457. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  458. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  459. }
  460. public function isAllowedDelete($aEvent, $bPerform = false)
  461. {
  462. if(isAdmin())
  463. return true;
  464. $iUserId = (int)$this->getUserId();
  465. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  466. return true;
  467. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  468. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  469. }
  470. public function isAllowedComment($aEvent, $bPerform = false)
  471. {
  472. $mixedComments = $this->getCommentsData($aEvent['comments']);
  473. if($mixedComments === false)
  474. return false;
  475. list($sSystem, $iObjectId) = $mixedComments;
  476. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  477. $oCmts->addCssJs();
  478. if(isAdmin())
  479. return true;
  480. return true;
  481. }
  482. public function isAllowedVote($aEvent, $bPerform = false)
  483. {
  484. $mixedVotes = $this->getVotesData($aEvent['votes']);
  485. if($mixedVotes === false)
  486. return false;
  487. list($sSystem, $iObjectId) = $mixedVotes;
  488. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  489. $oVote->addCssJs();
  490. if(isAdmin())
  491. return true;
  492. return true;
  493. }
  494. public function isAllowedShare($aEvent, $bPerform = false)
  495. {
  496. if(isAdmin())
  497. return true;
  498. $iUserId = (int)$this->getUserId();
  499. if($iUserId == 0)
  500. return false;
  501. $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
  502. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  503. }
  504. public function isAllowedMore($aEvent, $bPerform = false)
  505. {
  506. $oMoreMenu = $this->getManageMenuObject();
  507. $oMoreMenu->setEventId($aEvent['id']);
  508. return $oMoreMenu->isVisible();
  509. }
  510. public function onPost($iId)
  511. {
  512. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  513. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  514. $sPostType = 'system';
  515. $iSenderId = $aEvent['owner_id'];
  516. } else {
  517. $sPostType = 'common';
  518. $iSenderId = $aEvent['object_id'];
  519. }
  520. //--- Event -> Post for Alerts Engine ---//
  521. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId);
  522. $oAlert->alert();
  523. //--- Event -> Post for Alerts Engine ---//
  524. }
  525. public function onShare($iId, $aShared = array())
  526. {
  527. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  528. if(empty($aShared)) {
  529. $aContent = unserialize($aEvent['content']);
  530. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  531. if(empty($aShared) || !is_array($aShared))
  532. return;
  533. }
  534. $iUserId = $this->getUserId();
  535. $this->_oDb->insertShareTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aShared['id']);
  536. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares']);
  537. //--- Timeline -> Update for Alerts Engine ---//
  538. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'share', $aShared['id'], $iUserId);
  539. $oAlert->alert();
  540. //--- Timeline -> Update for Alerts Engine ---//
  541. }
  542. public function onDelete($aEvent)
  543. {
  544. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  545. //--- Delete attached photos, videos and links when common event was deleted.
  546. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  547. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  548. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  549. $this->_oDb->deleteLinks($aEvent['id']);
  550. }
  551. //--- Update parent event when share event was deleted.
  552. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_SHARE) {
  553. $this->_oDb->deleteShareTrack($aEvent['id']);
  554. $aContent = unserialize($aEvent['content']);
  555. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  556. if(!empty($aShared) && is_array($aShared))
  557. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares'], -1);
  558. }
  559. //--- Find and delete share events when parent event was deleted.
  560. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  561. $aShareEvents = $this->_oDb->getEvents(array('browse' => 'shared_by_descriptor', 'type' => $aEvent['type']));
  562. foreach($aShareEvents as $aShareEvent) {
  563. $aContent = unserialize($aShareEvent['content']);
  564. if(isset($aContent['type']) && $aContent['type'] == $aEvent['type'] && isset($aContent['object_id']) && (($bSystem && (int)$aContent['object_id'] == (int)$aEvent['object_id']) || (!$bSystem && (int)$aContent['object_id'] == (int)$aEvent['id'])))
  565. $this->_oDb->deleteEvent(array('id' => (int)$aShareEvent['id']));
  566. }
  567. //--- Delete associated meta.
  568. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  569. $oMetatags->onDeleteContent($aEvent['id']);
  570. //--- Event -> Delete for Alerts Engine ---//
  571. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $this->getUserId());
  572. $oAlert->alert();
  573. //--- Event -> Delete for Alerts Engine ---//
  574. }
  575. public function getVotesData(&$aVotes)
  576. {
  577. if(empty($aVotes) || !is_array($aVotes))
  578. return false;
  579. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  580. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  581. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  582. if($sSystem == '' || $iObjectId == 0)
  583. return false;
  584. return array($sSystem, $iObjectId, $iCount);
  585. }
  586. public function getCommentsData(&$aComments)
  587. {
  588. if(empty($aComments) || !is_array($aComments))
  589. return false;
  590. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  591. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  592. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  593. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  594. return false;
  595. return array($sSystem, $iObjectId, $iCount);
  596. }
  597. protected function _saveMedia($sType, $iId, $aItemIds)
  598. {
  599. if(empty($aItemIds) || !is_array($aItemIds))
  600. return;
  601. $iUserId = $this->getUserId();
  602. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  603. foreach($aItemIds as $iItemId)
  604. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  605. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  606. }
  607. protected function _deleteMedia($sType, $iId)
  608. {
  609. $aItems = $this->_oDb->getMedia($sType, $iId);
  610. if(empty($aItems) || !is_array($aItems))
  611. return;
  612. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  613. foreach($aItems as $iItemId)
  614. $oStorage->deleteFile($iItemId);
  615. $this->_oDb->deleteMedia($sType, $iId);
  616. }
  617. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  618. {
  619. $aParams = array();
  620. $aParams['browse'] = 'list';
  621. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT;
  622. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  623. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  624. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  625. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  626. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  627. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
  628. $aParams['active'] = 1;
  629. $aParams['hidden'] = 0;
  630. return $aParams;
  631. }
  632. protected function _prepareParamsGet()
  633. {
  634. $aParams = array();
  635. $aParams['browse'] = 'list';
  636. $aParams['dynamic_mode'] = true;
  637. $sType = bx_get('type');
  638. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  639. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  640. $iStart = bx_get('start');
  641. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  642. $iPerPage = bx_get('per_page');
  643. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  644. $sFilter = bx_get('filter');
  645. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  646. $aModules = bx_get('modules');
  647. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  648. $iTimeline = bx_get('timeline');
  649. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  650. $aParams['active'] = 1;
  651. $aParams['hidden'] = 0;
  652. return $aParams;
  653. }
  654. protected function _prepareTextForSave($s)
  655. {
  656. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  657. }
  658. }
  659. /** @} */