BxTimelineModule.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  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. unset($oForm->aInputs['text']);
  530. $aContent['text'] = $this->_prepareTextForSave($sText);
  531. //--- Process Link ---//
  532. $aLinkIds = $oForm->getCleanValue('link');
  533. //--- Process Media ---//
  534. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  535. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  536. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample'));
  537. $sDescription = !empty($aContent['text']) ? $aContent['text'] : '';
  538. $iId = $oForm->insert(array(
  539. 'object_id' => $iUserId,
  540. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  541. 'content' => serialize($aContent),
  542. 'title' => $sTitle,
  543. 'description' => $sDescription,
  544. 'date' => time()
  545. ));
  546. if(!empty($iId)) {
  547. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  548. $oMetatags->keywordsAdd($iId, $aContent['text']);
  549. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  550. //--- Process Link ---//
  551. if(!empty($aLinkIds) && is_array($aLinkIds))
  552. foreach($aLinkIds as $iLinkId)
  553. $this->_oDb->saveLink($iId, $iLinkId);
  554. //--- Process Media ---//
  555. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  556. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  557. $this->onPost($iId);
  558. return array('id' => $iId);
  559. }
  560. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  561. }
  562. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  563. }
  564. public function getCmtsObject($sSystem, $iId)
  565. {
  566. if(empty($sSystem) || (int)$iId == 0)
  567. return false;
  568. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  569. if(!$oCmts->isEnabled())
  570. return false;
  571. return $oCmts;
  572. }
  573. public function getVoteObject($sSystem, $iId)
  574. {
  575. if(empty($sSystem) || (int)$iId == 0)
  576. return false;
  577. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  578. if(!$oVote->isEnabled())
  579. return false;
  580. return $oVote;
  581. }
  582. public function getReportObject($sSystem, $iId)
  583. {
  584. if(empty($sSystem) || (int)$iId == 0)
  585. return false;
  586. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  587. if(!$oReport->isEnabled())
  588. return false;
  589. return $oReport;
  590. }
  591. public function getAttachmentsMenuObject()
  592. {
  593. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  594. $oMenu->addMarkers(array(
  595. 'js_object' => $this->_oConfig->getJsObject('post'),
  596. ));
  597. return $oMenu;
  598. }
  599. public function getManageMenuObject()
  600. {
  601. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  602. }
  603. //--- Check permissions methods ---//
  604. public function isAllowedPost($bPerform = false)
  605. {
  606. if(isAdmin())
  607. return true;
  608. $iUserId = $this->getUserId();
  609. if($this->_iOwnerId == $this->getUserId())
  610. return true;
  611. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  612. if ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId))
  613. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  614. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  615. }
  616. public function isAllowedDelete($aEvent, $bPerform = false)
  617. {
  618. if(isAdmin())
  619. return true;
  620. $iUserId = (int)$this->getUserId();
  621. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  622. return true;
  623. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  624. if ($oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']))
  625. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  626. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  627. }
  628. public function isAllowedComment($aEvent, $bPerform = false)
  629. {
  630. $mixedComments = $this->getCommentsData($aEvent['comments']);
  631. if($mixedComments === false)
  632. return false;
  633. list($sSystem, $iObjectId) = $mixedComments;
  634. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  635. $oCmts->addCssJs();
  636. $bResult = true;
  637. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  638. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  639. return $bResult;
  640. }
  641. public function isAllowedVote($aEvent, $bPerform = false)
  642. {
  643. $mixedVotes = $this->getVotesData($aEvent['votes']);
  644. if($mixedVotes === false)
  645. return false;
  646. list($sSystem, $iObjectId) = $mixedVotes;
  647. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  648. $oVote->addCssJs();
  649. $bResult = true;
  650. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  651. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  652. return $bResult;
  653. }
  654. public function isAllowedReport($aEvent, $bPerform = false)
  655. {
  656. $mixedReports = $this->getReportsData($aEvent['reports']);
  657. if($mixedReports === false)
  658. return false;
  659. list($sSystem, $iObjectId) = $mixedReports;
  660. $oReport = $this->getReportObject($sSystem, $iObjectId);
  661. $oReport->addCssJs();
  662. $bResult = true;
  663. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  664. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  665. return $bResult;
  666. }
  667. public function isAllowedShare($aEvent, $bPerform = false)
  668. {
  669. if(isAdmin())
  670. return true;
  671. $iUserId = (int)$this->getUserId();
  672. if($iUserId == 0)
  673. return false;
  674. $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
  675. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  676. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_share', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  677. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  678. }
  679. public function isAllowedPin($aEvent, $bPerform = false)
  680. {
  681. if((int)$aEvent['pinned'] != 0)
  682. return false;
  683. return $this->_isAllowedPin($aEvent, $bPerform);
  684. }
  685. public function isAllowedUnpin($aEvent, $bPerform = false)
  686. {
  687. if((int)$aEvent['pinned'] == 0)
  688. return false;
  689. return $this->_isAllowedPin($aEvent, $bPerform);
  690. }
  691. public function isAllowedMore($aEvent, $bPerform = false)
  692. {
  693. $oMoreMenu = $this->getManageMenuObject();
  694. $oMoreMenu->setEventId($aEvent['id']);
  695. return $oMoreMenu->isVisible();
  696. }
  697. public function onPost($iId)
  698. {
  699. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  700. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  701. $sPostType = 'system';
  702. $iSenderId = $aEvent['owner_id'];
  703. } else {
  704. $sPostType = 'common';
  705. $iSenderId = $aEvent['object_id'];
  706. }
  707. //--- Event -> Post for Alerts Engine ---//
  708. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  709. 'object_author_id' => $aEvent['owner_id']
  710. ));
  711. $oAlert->alert();
  712. //--- Event -> Post for Alerts Engine ---//
  713. }
  714. public function onShare($iId, $aShared = array())
  715. {
  716. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  717. if(empty($aShared)) {
  718. $aContent = unserialize($aEvent['content']);
  719. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  720. if(empty($aShared) || !is_array($aShared))
  721. return;
  722. }
  723. $iUserId = $this->getUserId();
  724. $this->_oDb->insertShareTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aShared['id']);
  725. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares']);
  726. //--- Timeline -> Update for Alerts Engine ---//
  727. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'share', $aShared['id'], $iUserId);
  728. $oAlert->alert();
  729. //--- Timeline -> Update for Alerts Engine ---//
  730. }
  731. public function onDelete($aEvent)
  732. {
  733. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  734. //--- Delete attached photos, videos and links when common event was deleted.
  735. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  736. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  737. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  738. $this->_deleteLinks($aEvent['id']);
  739. }
  740. //--- Update parent event when share event was deleted.
  741. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_SHARE) {
  742. $this->_oDb->deleteShareTrack($aEvent['id']);
  743. $aContent = unserialize($aEvent['content']);
  744. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  745. if(!empty($aShared) && is_array($aShared))
  746. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares'], -1);
  747. }
  748. //--- Find and delete share events when parent event was deleted.
  749. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  750. $aShareEvents = $this->_oDb->getEvents(array('browse' => 'shared_by_descriptor', 'type' => $aEvent['type']));
  751. foreach($aShareEvents as $aShareEvent) {
  752. $aContent = unserialize($aShareEvent['content']);
  753. 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'])))
  754. $this->_oDb->deleteEvent(array('id' => (int)$aShareEvent['id']));
  755. }
  756. //--- Delete associated meta.
  757. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  758. $oMetatags->onDeleteContent($aEvent['id']);
  759. //--- Event -> Delete for Alerts Engine ---//
  760. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $this->getUserId());
  761. $oAlert->alert();
  762. //--- Event -> Delete for Alerts Engine ---//
  763. }
  764. public function getVotesData(&$aVotes)
  765. {
  766. if(empty($aVotes) || !is_array($aVotes))
  767. return false;
  768. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  769. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  770. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  771. if($sSystem == '' || $iObjectId == 0)
  772. return false;
  773. return array($sSystem, $iObjectId, $iCount);
  774. }
  775. public function getReportsData(&$aReports)
  776. {
  777. if(empty($aReports) || !is_array($aReports))
  778. return false;
  779. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  780. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  781. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  782. if($sSystem == '' || $iObjectId == 0)
  783. return false;
  784. return array($sSystem, $iObjectId, $iCount);
  785. }
  786. public function getCommentsData(&$aComments)
  787. {
  788. if(empty($aComments) || !is_array($aComments))
  789. return false;
  790. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  791. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  792. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  793. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  794. return false;
  795. return array($sSystem, $iObjectId, $iCount);
  796. }
  797. protected function _isAllowedPin($aEvent, $bPerform = false)
  798. {
  799. if(isAdmin())
  800. return true;
  801. $iUserId = (int)$this->getUserId();
  802. if($iUserId == 0)
  803. return false;
  804. if((int)$aEvent['owner_id'] == $iUserId)
  805. return true;
  806. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  807. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  808. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  809. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  810. }
  811. protected function _deleteLinks($iId)
  812. {
  813. $aLinks = $this->_oDb->getLinks($iId);
  814. if(empty($aLinks) || !is_array($aLinks))
  815. return;
  816. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  817. foreach($aLinks as $aLink)
  818. if(!empty($aLink['media_id']))
  819. $oStorage->deleteFile($aLink['media_id']);
  820. $this->_oDb->deleteLinks($iId);
  821. }
  822. protected function _saveMedia($sType, $iId, $aItemIds)
  823. {
  824. if(empty($aItemIds) || !is_array($aItemIds))
  825. return;
  826. $iUserId = $this->getUserId();
  827. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  828. foreach($aItemIds as $iItemId)
  829. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  830. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  831. }
  832. protected function _deleteMedia($sType, $iId)
  833. {
  834. $aItems = $this->_oDb->getMedia($sType, $iId);
  835. if(empty($aItems) || !is_array($aItems))
  836. return;
  837. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  838. foreach($aItems as $iItemId)
  839. $oStorage->deleteFile($iItemId);
  840. $this->_oDb->deleteMedia($sType, $iId);
  841. }
  842. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  843. {
  844. $aParams = array();
  845. $aParams['browse'] = 'list';
  846. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT;
  847. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  848. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  849. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  850. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  851. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  852. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
  853. $aParams['active'] = 1;
  854. $aParams['hidden'] = 0;
  855. return $aParams;
  856. }
  857. protected function _prepareParamsGet()
  858. {
  859. $aParams = array();
  860. $aParams['browse'] = 'list';
  861. $aParams['dynamic_mode'] = true;
  862. $sType = bx_get('type');
  863. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  864. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  865. $iStart = bx_get('start');
  866. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  867. $iPerPage = bx_get('per_page');
  868. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  869. $sFilter = bx_get('filter');
  870. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  871. $aModules = bx_get('modules');
  872. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  873. $iTimeline = bx_get('timeline');
  874. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  875. $aParams['active'] = 1;
  876. $aParams['hidden'] = 0;
  877. return $aParams;
  878. }
  879. protected function _prepareTextForSave($s)
  880. {
  881. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  882. }
  883. }
  884. /** @} */