BxTimelineModule.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxBaseModNotificationsModule');
  13. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  14. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  15. define('BX_TIMELINE_FILTER_ALL', 'all');
  16. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  17. define('BX_TIMELINE_FILTER_OTHER', 'other');
  18. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  19. define('BX_TIMELINE_PARSE_TYPE_SHARE', 'share');
  20. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  21. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  22. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  23. class BxTimelineModule extends BxBaseModNotificationsModule
  24. {
  25. protected $_sJsPostObject;
  26. protected $_sJsViewObject;
  27. protected $_aPostElements;
  28. protected $_sJsOutlineObject;
  29. protected $_sDividerTemplate;
  30. protected $_sBalloonTemplate;
  31. protected $_sCmtPostTemplate;
  32. protected $_sCmtViewTemplate;
  33. protected $_sCmtTemplate;
  34. /**
  35. * Constructor
  36. */
  37. function __construct($aModule)
  38. {
  39. parent::__construct($aModule);
  40. }
  41. /**
  42. * ACTION METHODS
  43. */
  44. public function actionPost()
  45. {
  46. $sType = bx_process_input($_POST['type']);
  47. $sMethod = 'getForm' . ucfirst($sType);
  48. if(!method_exists($this, $sMethod)) {
  49. echoJson(array());
  50. return;
  51. }
  52. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  53. $mixedAllowed = $this->isAllowedPost(true);
  54. if($mixedAllowed !== true) {
  55. echoJson(array('msg' => strip_tags($mixedAllowed)));
  56. return;
  57. }
  58. $aResult = $this->$sMethod();
  59. echoJson($aResult);
  60. }
  61. function actionPin()
  62. {
  63. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  64. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  65. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  66. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  67. if($mixedAllowed !== true)
  68. return echoJson(array('code' => 1, 'msg' => strip_tags($mixedAllowed)));
  69. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  70. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  71. return echoJson(array('code' => 2));
  72. $aResult = array('code' => 0, 'id' => $iId);
  73. if($aEvent['pinned'] != 0)
  74. $aResult['content'] = $this->_oTemplate->getPost($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId, 'dynamic_mode' => true));
  75. echoJson($aResult);
  76. }
  77. function actionDelete()
  78. {
  79. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  80. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  81. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  82. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  83. if($mixedAllowed !== true) {
  84. echoJson(array('code' => 1, 'msg' => strip_tags($mixedAllowed)));
  85. return;
  86. }
  87. if(!$this->deleteEvent($aEvent))
  88. echoJson(array('code' => 2));
  89. else
  90. echoJson(array('code' => 0, 'id' => $iId));
  91. }
  92. public function actionShare()
  93. {
  94. $iAuthorId = $this->getUserId();
  95. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  96. $aContent = array(
  97. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  98. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  99. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  100. );
  101. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  102. if(empty($aShared) || !is_array($aShared)) {
  103. echoJson(array('code' => 1, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  104. return;
  105. }
  106. $mixedAllowed = $this->isAllowedShare($aShared, true);
  107. if($mixedAllowed !== true) {
  108. echoJson(array('code' => 2, 'msg' => strip_tags($mixedAllowed)));
  109. return;
  110. }
  111. $bShared = $this->_oDb->isShared($aShared['id'], $iOwnerId, $iAuthorId);
  112. if($bShared) {
  113. echoJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_already_shared')));
  114. return;
  115. }
  116. $iId = $this->_oDb->insertEvent(array(
  117. 'owner_id' => $iOwnerId,
  118. 'type' => $this->_oConfig->getPrefix('common_post') . 'share',
  119. 'action' => '',
  120. 'object_id' => $iAuthorId,
  121. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  122. 'content' => serialize($aContent),
  123. 'title' => '',
  124. 'description' => ''
  125. ));
  126. if(empty($iId)) {
  127. echoJson(array('code' => 4, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  128. return;
  129. }
  130. $this->onShare($iId, $aShared);
  131. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  132. $sCounter = $this->_oTemplate->getShareCounter($aShared);
  133. echoJson(array(
  134. 'code' => 0,
  135. 'msg' => _t('_bx_timeline_txt_msg_success_share'),
  136. 'count' => $aShared['shares'],
  137. 'counter' => $sCounter,
  138. 'disabled' => !$bShared
  139. ));
  140. }
  141. function actionGetPost()
  142. {
  143. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  144. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  145. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  146. echoJson(array('item' => $this->_oTemplate->getPost($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId, 'dynamic_mode' => true))));
  147. }
  148. function actionGetPosts()
  149. {
  150. $aParams = $this->_prepareParamsGet();
  151. list($sItems, $sLoadMore, $sBack) = $this->_oTemplate->getPosts($aParams);
  152. echoJson(array('items' => $sItems, 'load_more' => $sLoadMore, 'back' => $sBack));
  153. }
  154. public function actionGetPostForm($sType)
  155. {
  156. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  157. $sMethod = 'getForm' . ucfirst($sType);
  158. if(!method_exists($this, $sMethod)) {
  159. echoJson(array());
  160. return;
  161. }
  162. $aResult = $this->$sMethod();
  163. echoJson($aResult);
  164. }
  165. public function actionGetComments()
  166. {
  167. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  168. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  169. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  170. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  171. echoJson(array('content' => $sComments));
  172. }
  173. public function actionAddAttachLink()
  174. {
  175. $aResult = $this->getFormAttachLink();
  176. echoJson($aResult);
  177. }
  178. public function actionDeleteAttachLink()
  179. {
  180. $iUserId = $this->getUserId();
  181. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  182. if(empty($iLinkId)) {
  183. echoJson(array());
  184. return;
  185. }
  186. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  187. if(empty($aLink) || !is_array($aLink)) {
  188. echoJson(array());
  189. return;
  190. }
  191. if(!empty($aLink['media_id']))
  192. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  193. $aResult = array();
  194. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  195. $aResult = array('code' => 0);
  196. else
  197. $aResult = array('code' => 1, 'msg' => _t('_bx_timeline_form_post_input_link_err_delete'));
  198. echoJson($aResult);
  199. }
  200. public function actionGetAttachLinkForm()
  201. {
  202. echo $this->_oTemplate->getAttachLinkForm();
  203. }
  204. public function actionGetSharedBy()
  205. {
  206. $iSharedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  207. echo $this->_oTemplate->getSharedBy($iSharedId);
  208. }
  209. function actionRss($iOwnerId)
  210. {
  211. list($sUserName) = $this->getUserInfo($iOwnerId);
  212. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  213. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  214. $aParams = $this->_prepareParams('owner', $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  215. $aEvents = $this->_oDb->getEvents($aParams);
  216. $aRssData = array();
  217. foreach($aEvents as $aEvent) {
  218. if(empty($aEvent['title'])) continue;
  219. $aRssData[$aEvent['id']] = array(
  220. 'UnitID' => $aEvent['id'],
  221. 'UnitTitle' => $aEvent['title'],
  222. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  223. 'UnitDesc' => $aEvent['description'],
  224. 'UnitDateTimeUTS' => $aEvent['date'],
  225. );
  226. }
  227. $oRss = new BxDolRssFactory();
  228. header('Content-Type: application/xml; charset=utf-8');
  229. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  230. }
  231. /**
  232. * SERVICE METHODS
  233. *
  234. * Get Post block for a separate page.
  235. */
  236. public function serviceGetBlockPost($iProfileId = 0)
  237. {
  238. if(empty($iProfileId) && bx_get('profile_id') !== false)
  239. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  240. if(empty($iProfileId) && isLogged())
  241. $iProfileId = bx_get_logged_profile_id();
  242. return $this->getBlockPost($iProfileId);
  243. }
  244. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  245. {
  246. if(empty($sProfileModule))
  247. return array();
  248. if(empty($iProfileContentId) && bx_get('id') !== false)
  249. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  250. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  251. if(empty($oProfile))
  252. return array();
  253. return $this->getBlockPost($oProfile->id());
  254. }
  255. /*
  256. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  257. */
  258. public function serviceGetBlockView($iProfileId = 0)
  259. {
  260. if(empty($iProfileId) && bx_get('profile_id') !== false)
  261. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  262. if(empty($iProfileId) && isLogged())
  263. $iProfileId = bx_get_logged_profile_id();
  264. $aBlock = $this->getBlockView($iProfileId);
  265. if(!empty($aBlock))
  266. return $aBlock;
  267. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  268. }
  269. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  270. {
  271. if(empty($sProfileModule))
  272. return array();
  273. if(empty($iProfileContentId) && bx_get('id') !== false)
  274. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  275. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  276. if(empty($oProfile))
  277. return array();
  278. return $this->getBlockView($oProfile->id(), $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  279. }
  280. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  281. {
  282. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  283. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('account');
  284. $this->_iOwnerId = $aParams['owner_id'];
  285. $sContent = $this->_oTemplate->getViewBlock($aParams);
  286. return array('content' => $sContent);
  287. }
  288. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  289. {
  290. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  291. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('home');
  292. $this->_iOwnerId = $aParams['owner_id'];
  293. $sContent = $this->_oTemplate->getViewBlock($aParams);
  294. return array('content' => $sContent);
  295. }
  296. public function serviceGetBlockItem()
  297. {
  298. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  299. if(!$iItemId)
  300. return array();
  301. return array('content' => $this->_oTemplate->getItemBlock($iItemId));
  302. }
  303. /**
  304. * Data for Notifications module
  305. */
  306. public function serviceGetNotificationsData()
  307. {
  308. $sModule = $this->_aModule['name'];
  309. return array(
  310. 'handlers' => array(
  311. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  312. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  313. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  314. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  315. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  316. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  317. ),
  318. 'alerts' => array(
  319. array('unit' => $sModule, 'action' => 'post_common'),
  320. array('unit' => $sModule, 'action' => 'delete'),
  321. array('unit' => $sModule, 'action' => 'commentPost'),
  322. array('unit' => $sModule, 'action' => 'commentRemoved'),
  323. array('unit' => $sModule, 'action' => 'doVote'),
  324. array('unit' => $sModule, 'action' => 'undoVote'),
  325. )
  326. );
  327. }
  328. public function serviceGetNotificationsPost($aEvent)
  329. {
  330. $CNF = &$this->_oConfig->CNF;
  331. $iContent = (int)$aEvent['object_id'];
  332. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  333. if(empty($aContent) || !is_array($aContent))
  334. return array();
  335. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  336. return array(
  337. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  338. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  339. 'entry_caption' => $sEntryCaption,
  340. 'entry_author' => $aContent['owner_id'],
  341. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  342. );
  343. }
  344. public function serviceGetNotificationsComment($aEvent)
  345. {
  346. $CNF = &$this->_oConfig->CNF;
  347. $iContent = (int)$aEvent['object_id'];
  348. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  349. if(empty($aContent) || !is_array($aContent))
  350. return array();
  351. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  352. if(!$oComment || !$oComment->isEnabled())
  353. return array();
  354. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  355. return array(
  356. 'entry_sample' => $CNF['T']['txt_sample_single'],
  357. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  358. 'entry_caption' => $sEntryCaption,
  359. 'entry_author' => $aContent['owner_id'],
  360. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  361. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  362. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  363. );
  364. }
  365. public function serviceGetNotificationsVote($aEvent)
  366. {
  367. $CNF = &$this->_oConfig->CNF;
  368. $iContent = (int)$aEvent['object_id'];
  369. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  370. if(empty($aContent) || !is_array($aContent))
  371. return array();
  372. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  373. if(!$oVote || !$oVote->isEnabled())
  374. return array();
  375. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  376. return array(
  377. 'entry_sample' => $CNF['T']['txt_sample_single'],
  378. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  379. 'entry_caption' => $sEntryCaption,
  380. 'entry_author' => $aContent['owner_id'],
  381. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  382. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  383. );
  384. }
  385. public function serviceGetShareElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  386. {
  387. if(!$this->isEnabled())
  388. return '';
  389. $aParams = array_merge($this->_oConfig->getShareDefaults(), $aParams);
  390. return $this->_oTemplate->getShareElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  391. }
  392. public function serviceGetShareCounter($sType, $sAction, $iObjectId)
  393. {
  394. if(!$this->isEnabled())
  395. return '';
  396. $aShared = $this->_oDb->getShared($sType, $sAction, $iObjectId);
  397. return $this->_oTemplate->getShareCounter($aShared);
  398. }
  399. public function serviceGetShareJsScript()
  400. {
  401. if(!$this->isEnabled())
  402. return '';
  403. return $this->_oTemplate->getShareJsScript();
  404. }
  405. public function serviceGetShareJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  406. {
  407. if(!$this->isEnabled())
  408. return '';
  409. return $this->_oTemplate->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  410. }
  411. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  412. {
  413. if(empty($sSystem) || empty($iObjectId))
  414. return '';
  415. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  416. if($oCmts === false)
  417. return '';
  418. $iCounter = (int)$oCmts->getCommentsCount();
  419. return $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  420. 'href' => 'javascript:void(0)',
  421. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  422. 'bx_repeat:attrs' => array(
  423. array('key' => 'onclick', 'value' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")")
  424. ),
  425. 'content' => $iCounter > 0 ? $iCounter : ''
  426. ));
  427. }
  428. public function serviceGetSettingsCheckerHelper()
  429. {
  430. bx_import('FormCheckerHelper', $this->_aModule);
  431. return 'BxTimelineFormCheckerHelper';
  432. }
  433. /*
  434. * COMMON METHODS
  435. */
  436. public function getBlockPost($iProfileId)
  437. {
  438. if(!$iProfileId)
  439. return array();
  440. $this->_iOwnerId = $iProfileId;
  441. if($this->isAllowedPost() !== true)
  442. return array();
  443. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  444. return array('content' => $sContent);
  445. }
  446. public function getBlockView($iProfileId, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  447. {
  448. if(!$iProfileId)
  449. return array();
  450. $sJsObject = $this->_oConfig->getJsObject('view');
  451. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  452. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  453. $this->_iOwnerId = $aParams['owner_id'];
  454. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  455. $aMenu = array(
  456. 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),
  457. 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)),
  458. 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')),
  459. 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')),
  460. );
  461. $sContent = '';
  462. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  463. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  464. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  465. $oMenu->setSelected('', 'timeline-view-all');
  466. if (!$sContent)
  467. $sContent = $this->_oTemplate->getViewBlock($aParams);
  468. return array('content' => $sContent, 'menu' => $oMenu);
  469. }
  470. public function deleteEvent($aEvent)
  471. {
  472. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  473. return false;
  474. $this->onDelete($aEvent);
  475. return true;
  476. }
  477. public function getFormAttachLink()
  478. {
  479. $iUserId = $this->getUserId();
  480. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  481. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  482. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  483. $oForm->initChecker();
  484. if($oForm->isSubmittedAndValid()) {
  485. $sLink = $oForm->getCleanValue('url');
  486. $aMatches = array();
  487. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  488. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  489. $aSiteInfo = bx_get_site_info($sLink, array(
  490. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  491. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  492. ));
  493. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  494. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  495. $sMediaUrl = '';
  496. if(!empty($aSiteInfo['thumbnailUrl']))
  497. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  498. else if(!empty($aSiteInfo['OGImage']))
  499. $sMediaUrl = $aSiteInfo['OGImage'];
  500. $iMediaId = 0;
  501. $oStorage = null;
  502. if(!empty($sMediaUrl)) {
  503. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  504. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  505. }
  506. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  507. if(!empty($iId)) {
  508. if(!empty($oStorage) && !empty($iMediaId))
  509. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  510. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  511. }
  512. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  513. }
  514. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  515. }
  516. public function getFormPost()
  517. {
  518. $iUserId = $this->getUserId();
  519. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_add'), $this->_oTemplate);
  520. $oForm->initChecker();
  521. if($oForm->isSubmittedAndValid()) {
  522. list($sUserName) = $this->getUserInfo($iUserId);
  523. $sType = $oForm->getCleanValue('type');
  524. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  525. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  526. $aContent = array();
  527. //--- Process Text ---//
  528. $sText = $oForm->getCleanValue('text');
  529. $sText = $this->_prepareTextForSave($sText);
  530. $bText = !empty($sText);
  531. unset($oForm->aInputs['text']);
  532. if($bText)
  533. $aContent['text'] = $sText;
  534. //--- Process Link ---//
  535. $aLinkIds = $oForm->getCleanValue('link');
  536. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  537. //--- Process Media ---//
  538. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  539. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  540. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  541. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  542. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  543. return array('msg' => _t('_bx_timeline_txt_err_empty_post'));
  544. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample'));
  545. $sDescription = $bText ? $sText : '';
  546. $iId = $oForm->insert(array(
  547. 'object_id' => $iUserId,
  548. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  549. 'content' => serialize($aContent),
  550. 'title' => $sTitle,
  551. 'description' => $sDescription,
  552. 'date' => time()
  553. ));
  554. if(!empty($iId)) {
  555. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  556. if($bText)
  557. $oMetatags->keywordsAdd($iId, $sText);
  558. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  559. //--- Process Link ---//
  560. if($bLinkIds)
  561. foreach($aLinkIds as $iLinkId)
  562. $this->_oDb->saveLink($iId, $iLinkId);
  563. //--- Process Media ---//
  564. if($bPhotoIds)
  565. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  566. if($bVideoIds)
  567. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  568. $this->onPost($iId);
  569. return array('id' => $iId);
  570. }
  571. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  572. }
  573. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  574. }
  575. public function getCmtsObject($sSystem, $iId)
  576. {
  577. if(empty($sSystem) || (int)$iId == 0)
  578. return false;
  579. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  580. if(!$oCmts->isEnabled())
  581. return false;
  582. return $oCmts;
  583. }
  584. public function getVoteObject($sSystem, $iId)
  585. {
  586. if(empty($sSystem) || (int)$iId == 0)
  587. return false;
  588. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  589. if(!$oVote->isEnabled())
  590. return false;
  591. return $oVote;
  592. }
  593. public function getReportObject($sSystem, $iId)
  594. {
  595. if(empty($sSystem) || (int)$iId == 0)
  596. return false;
  597. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  598. if(!$oReport->isEnabled())
  599. return false;
  600. return $oReport;
  601. }
  602. public function getAttachmentsMenuObject()
  603. {
  604. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  605. $oMenu->addMarkers(array(
  606. 'js_object' => $this->_oConfig->getJsObject('post'),
  607. ));
  608. return $oMenu;
  609. }
  610. public function getManageMenuObject()
  611. {
  612. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  613. }
  614. //--- Check permissions methods ---//
  615. public function isAllowedPost($bPerform = false)
  616. {
  617. if(isAdmin())
  618. return true;
  619. $iUserId = $this->getUserId();
  620. if($this->_iOwnerId == $this->getUserId())
  621. return true;
  622. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  623. if ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId))
  624. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  625. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  626. }
  627. public function isAllowedDelete($aEvent, $bPerform = false)
  628. {
  629. if(isAdmin())
  630. return true;
  631. $iUserId = (int)$this->getUserId();
  632. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  633. return true;
  634. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  635. if ($oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']))
  636. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  637. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  638. }
  639. public function isAllowedComment($aEvent, $bPerform = false)
  640. {
  641. $mixedComments = $this->getCommentsData($aEvent['comments']);
  642. if($mixedComments === false)
  643. return false;
  644. list($sSystem, $iObjectId) = $mixedComments;
  645. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  646. $oCmts->addCssJs();
  647. $bResult = true;
  648. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  649. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  650. return $bResult;
  651. }
  652. public function isAllowedVote($aEvent, $bPerform = false)
  653. {
  654. $mixedVotes = $this->getVotesData($aEvent['votes']);
  655. if($mixedVotes === false)
  656. return false;
  657. list($sSystem, $iObjectId) = $mixedVotes;
  658. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  659. $oVote->addCssJs();
  660. $bResult = true;
  661. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  662. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  663. return $bResult;
  664. }
  665. public function isAllowedReport($aEvent, $bPerform = false)
  666. {
  667. $mixedReports = $this->getReportsData($aEvent['reports']);
  668. if($mixedReports === false)
  669. return false;
  670. list($sSystem, $iObjectId) = $mixedReports;
  671. $oReport = $this->getReportObject($sSystem, $iObjectId);
  672. $oReport->addCssJs();
  673. $bResult = true;
  674. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  675. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  676. return $bResult;
  677. }
  678. public function isAllowedShare($aEvent, $bPerform = false)
  679. {
  680. if(isAdmin())
  681. return true;
  682. $iUserId = (int)$this->getUserId();
  683. if($iUserId == 0)
  684. return false;
  685. $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
  686. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  687. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_share', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  688. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  689. }
  690. public function isAllowedPin($aEvent, $bPerform = false)
  691. {
  692. if((int)$aEvent['pinned'] != 0)
  693. return false;
  694. return $this->_isAllowedPin($aEvent, $bPerform);
  695. }
  696. public function isAllowedUnpin($aEvent, $bPerform = false)
  697. {
  698. if((int)$aEvent['pinned'] == 0)
  699. return false;
  700. return $this->_isAllowedPin($aEvent, $bPerform);
  701. }
  702. public function isAllowedMore($aEvent, $bPerform = false)
  703. {
  704. $oMoreMenu = $this->getManageMenuObject();
  705. $oMoreMenu->setEventId($aEvent['id']);
  706. return $oMoreMenu->isVisible();
  707. }
  708. public function onPost($iId)
  709. {
  710. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  711. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  712. $sPostType = 'system';
  713. $iSenderId = $aEvent['owner_id'];
  714. } else {
  715. $sPostType = 'common';
  716. $iSenderId = $aEvent['object_id'];
  717. }
  718. //--- Event -> Post for Alerts Engine ---//
  719. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  720. 'object_author_id' => $aEvent['owner_id']
  721. ));
  722. $oAlert->alert();
  723. //--- Event -> Post for Alerts Engine ---//
  724. }
  725. public function onShare($iId, $aShared = array())
  726. {
  727. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  728. if(empty($aShared)) {
  729. $aContent = unserialize($aEvent['content']);
  730. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  731. if(empty($aShared) || !is_array($aShared))
  732. return;
  733. }
  734. $iUserId = $this->getUserId();
  735. $this->_oDb->insertShareTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aShared['id']);
  736. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares']);
  737. //--- Timeline -> Update for Alerts Engine ---//
  738. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'share', $aShared['id'], $iUserId);
  739. $oAlert->alert();
  740. //--- Timeline -> Update for Alerts Engine ---//
  741. }
  742. public function onDelete($aEvent)
  743. {
  744. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  745. //--- Delete attached photos, videos and links when common event was deleted.
  746. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  747. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  748. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  749. $this->_deleteLinks($aEvent['id']);
  750. }
  751. //--- Update parent event when share event was deleted.
  752. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_SHARE) {
  753. $this->_oDb->deleteShareTrack($aEvent['id']);
  754. $aContent = unserialize($aEvent['content']);
  755. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  756. if(!empty($aShared) && is_array($aShared))
  757. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares'], -1);
  758. }
  759. //--- Find and delete share events when parent event was deleted.
  760. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  761. $aShareEvents = $this->_oDb->getEvents(array('browse' => 'shared_by_descriptor', 'type' => $aEvent['type']));
  762. foreach($aShareEvents as $aShareEvent) {
  763. $aContent = unserialize($aShareEvent['content']);
  764. 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'])))
  765. $this->_oDb->deleteEvent(array('id' => (int)$aShareEvent['id']));
  766. }
  767. //--- Delete associated meta.
  768. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  769. $oMetatags->onDeleteContent($aEvent['id']);
  770. //--- Event -> Delete for Alerts Engine ---//
  771. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $this->getUserId());
  772. $oAlert->alert();
  773. //--- Event -> Delete for Alerts Engine ---//
  774. }
  775. public function getVotesData(&$aVotes)
  776. {
  777. if(empty($aVotes) || !is_array($aVotes))
  778. return false;
  779. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  780. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  781. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  782. if($sSystem == '' || $iObjectId == 0)
  783. return false;
  784. return array($sSystem, $iObjectId, $iCount);
  785. }
  786. public function getReportsData(&$aReports)
  787. {
  788. if(empty($aReports) || !is_array($aReports))
  789. return false;
  790. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  791. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  792. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  793. if($sSystem == '' || $iObjectId == 0)
  794. return false;
  795. return array($sSystem, $iObjectId, $iCount);
  796. }
  797. public function getCommentsData(&$aComments)
  798. {
  799. if(empty($aComments) || !is_array($aComments))
  800. return false;
  801. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  802. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  803. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  804. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  805. return false;
  806. return array($sSystem, $iObjectId, $iCount);
  807. }
  808. protected function _isAllowedPin($aEvent, $bPerform = false)
  809. {
  810. if(isAdmin())
  811. return true;
  812. $iUserId = (int)$this->getUserId();
  813. if($iUserId == 0)
  814. return false;
  815. if((int)$aEvent['owner_id'] == $iUserId)
  816. return true;
  817. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  818. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  819. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  820. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  821. }
  822. protected function _deleteLinks($iId)
  823. {
  824. $aLinks = $this->_oDb->getLinks($iId);
  825. if(empty($aLinks) || !is_array($aLinks))
  826. return;
  827. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  828. foreach($aLinks as $aLink)
  829. if(!empty($aLink['media_id']))
  830. $oStorage->deleteFile($aLink['media_id']);
  831. $this->_oDb->deleteLinks($iId);
  832. }
  833. protected function _saveMedia($sType, $iId, $aItemIds)
  834. {
  835. if(empty($aItemIds) || !is_array($aItemIds))
  836. return;
  837. $iUserId = $this->getUserId();
  838. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  839. foreach($aItemIds as $iItemId)
  840. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  841. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  842. }
  843. protected function _deleteMedia($sType, $iId)
  844. {
  845. $aItems = $this->_oDb->getMedia($sType, $iId);
  846. if(empty($aItems) || !is_array($aItems))
  847. return;
  848. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  849. foreach($aItems as $iItemId)
  850. $oStorage->deleteFile($iItemId);
  851. $this->_oDb->deleteMedia($sType, $iId);
  852. }
  853. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  854. {
  855. $aParams = array();
  856. $aParams['browse'] = 'list';
  857. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT;
  858. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  859. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  860. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  861. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  862. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  863. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
  864. $aParams['active'] = 1;
  865. $aParams['hidden'] = 0;
  866. return $aParams;
  867. }
  868. protected function _prepareParamsGet()
  869. {
  870. $aParams = array();
  871. $aParams['browse'] = 'list';
  872. $aParams['dynamic_mode'] = true;
  873. $sType = bx_get('type');
  874. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  875. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  876. $iStart = bx_get('start');
  877. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  878. $iPerPage = bx_get('per_page');
  879. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  880. $sFilter = bx_get('filter');
  881. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  882. $aModules = bx_get('modules');
  883. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  884. $iTimeline = bx_get('timeline');
  885. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  886. $aParams['active'] = 1;
  887. $aParams['hidden'] = 0;
  888. return $aParams;
  889. }
  890. protected function _prepareTextForSave($s)
  891. {
  892. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  893. }
  894. }
  895. /** @} */