BxTimelineModule.php 32 KB

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