BxTimelineModule.php 31 KB

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