BxTimelineModule.php 32 KB

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