BxTimelineModule.php 30 KB

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