BxTimelineModule.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup UnaModules
  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_VIEW_TIMELINE', 'timeline');
  16. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  17. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  18. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  19. define('BX_TIMELINE_FILTER_ALL', 'all');
  20. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  21. define('BX_TIMELINE_FILTER_OTHER', 'other');
  22. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  23. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  24. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  25. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  26. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  27. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  28. {
  29. protected $_sJsPostObject;
  30. protected $_sJsViewObject;
  31. protected $_aPostElements;
  32. protected $_sJsOutlineObject;
  33. protected $_sDividerTemplate;
  34. protected $_sBalloonTemplate;
  35. protected $_sCmtPostTemplate;
  36. protected $_sCmtViewTemplate;
  37. protected $_sCmtTemplate;
  38. /**
  39. * Constructor
  40. */
  41. function __construct($aModule)
  42. {
  43. parent::__construct($aModule);
  44. }
  45. /**
  46. * ACTION METHODS
  47. */
  48. public function actionPost()
  49. {
  50. $sType = bx_process_input($_POST['type']);
  51. $sMethod = 'getForm' . ucfirst($sType);
  52. if(!method_exists($this, $sMethod)) {
  53. echoJson(array());
  54. return;
  55. }
  56. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  57. $mixedAllowed = $this->isAllowedPost(true);
  58. if($mixedAllowed !== true) {
  59. echoJson(array('msg' => strip_tags($mixedAllowed)));
  60. return;
  61. }
  62. $aResult = $this->$sMethod();
  63. echoJson($aResult);
  64. }
  65. function actionPin()
  66. {
  67. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  68. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  69. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  70. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  71. if($mixedAllowed !== true)
  72. return echoJson(array('code' => 1, 'msg' => strip_tags($mixedAllowed)));
  73. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  74. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  75. return echoJson(array('code' => 2));
  76. echoJson(array(
  77. 'code' => 0,
  78. 'id' => $iId,
  79. 'eval' => $this->_oConfig->getJsObject('view') . '.onPinPost(oData)'
  80. ));
  81. }
  82. function actionDelete()
  83. {
  84. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  85. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  86. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  87. if($mixedAllowed !== true)
  88. return echoJson(array('code' => 1, 'msg' => strip_tags($mixedAllowed)));
  89. if(!$this->deleteEvent($aEvent))
  90. return echoJson(array('code' => 2));
  91. echoJson(array(
  92. 'code' => 0,
  93. 'id' => $aEvent['id'],
  94. 'eval' => $this->_oConfig->getJsObject('view') . '.onDeletePost(oData)'
  95. ));
  96. }
  97. public function actionRepost()
  98. {
  99. $iAuthorId = $this->getUserId();
  100. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  101. $aContent = array(
  102. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  103. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  104. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  105. );
  106. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  107. if(empty($aReposted) || !is_array($aReposted)) {
  108. echoJson(array('code' => 1, 'msg' => _t('_bx_timeline_txt_err_cannot_repost')));
  109. return;
  110. }
  111. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  112. if($mixedAllowed !== true) {
  113. echoJson(array('code' => 2, 'msg' => strip_tags($mixedAllowed)));
  114. return;
  115. }
  116. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  117. if($bReposted) {
  118. echoJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_already_reposted')));
  119. return;
  120. }
  121. $iId = $this->_oDb->insertEvent(array(
  122. 'owner_id' => $iOwnerId,
  123. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  124. 'action' => '',
  125. 'object_id' => $iAuthorId,
  126. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  127. 'content' => serialize($aContent),
  128. 'title' => '',
  129. 'description' => ''
  130. ));
  131. if(empty($iId)) {
  132. echoJson(array('code' => 4, 'msg' => _t('_bx_timeline_txt_err_cannot_repost')));
  133. return;
  134. }
  135. $this->onRepost($iId, $aReposted);
  136. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  137. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  138. echoJson(array(
  139. 'code' => 0,
  140. 'msg' => _t('_bx_timeline_txt_msg_success_repost'),
  141. 'count' => $aReposted['reposts'],
  142. 'counter' => $sCounter,
  143. 'disabled' => !$bReposted
  144. ));
  145. }
  146. function actionGetPost()
  147. {
  148. $sView = bx_process_input(bx_get('view'));
  149. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  150. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  151. if(empty($aEvent) || !is_array($aEvent))
  152. return echoJson(array());
  153. echoJson(array(
  154. 'id' => $aEvent['id'],
  155. 'view' => $sView,
  156. 'item' => $this->_oTemplate->getPost($aEvent, array(
  157. 'view' => $sView,
  158. 'type' => 'owner',
  159. 'owner_id' => $this->_iOwnerId,
  160. 'dynamic_mode' => true
  161. )),
  162. 'eval' => $this->_oConfig->getJsObject('post') . "._onGetPost(oData)"
  163. ));
  164. }
  165. function actionGetPosts()
  166. {
  167. $aParams = $this->_prepareParamsGet();
  168. list($sItems, $sLoadMore, $sBack, $sEmpty) = $this->_oTemplate->getPosts($aParams);
  169. echoJson(array(
  170. 'view' => $aParams['view'],
  171. 'items' => $sItems,
  172. 'load_more' => $sLoadMore,
  173. 'back' => $sBack,
  174. 'empty' => $sEmpty,
  175. 'eval' => $this->_oConfig->getJsObject('view') . "._onGetPosts(oData)"
  176. ));
  177. }
  178. public function actionGetPostForm($sType)
  179. {
  180. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  181. $sMethod = 'getForm' . ucfirst($sType);
  182. if(!method_exists($this, $sMethod)) {
  183. echoJson(array());
  184. return;
  185. }
  186. $aResult = $this->$sMethod();
  187. echoJson($aResult);
  188. }
  189. public function actionGetComments()
  190. {
  191. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  192. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  193. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  194. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  195. echoJson(array('content' => $sComments));
  196. }
  197. public function actionAddAttachLink()
  198. {
  199. $aResult = $this->getFormAttachLink();
  200. echoJson($aResult);
  201. }
  202. public function actionDeleteAttachLink()
  203. {
  204. $iUserId = $this->getUserId();
  205. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  206. if(empty($iLinkId)) {
  207. echoJson(array());
  208. return;
  209. }
  210. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  211. if(empty($aLink) || !is_array($aLink)) {
  212. echoJson(array());
  213. return;
  214. }
  215. if(!empty($aLink['media_id']))
  216. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  217. $aResult = array();
  218. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  219. $aResult = array('code' => 0);
  220. else
  221. $aResult = array('code' => 1, 'msg' => _t('_bx_timeline_form_post_input_link_err_delete'));
  222. echoJson($aResult);
  223. }
  224. public function actionGetAttachLinkForm()
  225. {
  226. echo $this->_oTemplate->getAttachLinkForm();
  227. }
  228. public function actionGetRepostedBy()
  229. {
  230. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  231. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  232. }
  233. function actionRss()
  234. {
  235. $aArgs = func_get_args();
  236. $sType = array_shift($aArgs);
  237. $iOwnerId = 0;
  238. switch($sType) {
  239. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  240. $iOwnerId = array_shift($aArgs);
  241. list($sUserName) = $this->getUserInfo($iOwnerId);
  242. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  243. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  244. break;
  245. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  246. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  247. $sRssLink = $this->_oConfig->getHomeViewUrl();
  248. break;
  249. }
  250. $aParams = $this->_prepareParams(BX_TIMELINE_VIEW_DEFAULT, $sType, $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  251. $aEvents = $this->_oDb->getEvents($aParams);
  252. $aRssData = array();
  253. foreach($aEvents as $aEvent) {
  254. if(empty($aEvent['title'])) continue;
  255. $aRssData[$aEvent['id']] = array(
  256. 'UnitID' => $aEvent['id'],
  257. 'UnitTitle' => $aEvent['title'],
  258. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  259. 'UnitDesc' => $aEvent['description'],
  260. 'UnitDateTimeUTS' => $aEvent['date'],
  261. );
  262. }
  263. $oRss = new BxDolRssFactory();
  264. header('Content-Type: application/xml; charset=utf-8');
  265. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  266. }
  267. /**
  268. * SERVICE METHODS
  269. */
  270. public function serviceGetAuthor ($iContentId)
  271. {
  272. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  273. if(empty($aEvent) || !is_array($aEvent))
  274. return 0;
  275. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  276. }
  277. public function serviceGetDateChanged ($iContentId)
  278. {
  279. return 0;
  280. }
  281. public function serviceGetLink ($iContentId)
  282. {
  283. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  284. if(empty($aEvent) || !is_array($aEvent))
  285. return '';
  286. return $this->_oConfig->getItemViewUrl($aEvent);
  287. }
  288. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  289. {
  290. return '';
  291. }
  292. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  293. {
  294. $aContentInfo = $this->_oDb->getEvents(array(
  295. 'browse' => 'id',
  296. 'value' => $iContentId)
  297. );
  298. return BxDolContentInfo::formatFields($aContentInfo);
  299. }
  300. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  301. {
  302. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  303. if(empty($aEvent) || !is_array($aEvent))
  304. return '';
  305. if(empty($sUnitTemplate))
  306. $sUnitTemplate = 'unit.html';
  307. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  308. }
  309. /**
  310. * Get Post block for a separate page.
  311. */
  312. public function serviceGetBlockPost($iProfileId = 0)
  313. {
  314. if(empty($iProfileId) && bx_get('profile_id') !== false)
  315. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  316. if(empty($iProfileId) && isLogged())
  317. $iProfileId = bx_get_logged_profile_id();
  318. if(!$iProfileId)
  319. return array();
  320. return $this->_getBlockPost($iProfileId);
  321. }
  322. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  323. {
  324. if(empty($sProfileModule))
  325. return array();
  326. if(empty($iProfileContentId) && bx_get('id') !== false)
  327. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  328. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  329. if(empty($oProfile))
  330. return array();
  331. return $this->_getBlockPost($oProfile->id());
  332. }
  333. public function serviceGetBlockPostHome()
  334. {
  335. $iProfileId = 0;
  336. return $this->_getBlockPost($iProfileId);
  337. }
  338. /*
  339. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  340. */
  341. public function serviceGetBlockView($iProfileId = 0)
  342. {
  343. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_TIMELINE);
  344. }
  345. public function serviceGetBlockViewOutline($iProfileId = 0)
  346. {
  347. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_OUTLINE);
  348. }
  349. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  350. {
  351. $sView = BX_TIMELINE_VIEW_TIMELINE;
  352. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  353. }
  354. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  355. {
  356. $sView = BX_TIMELINE_VIEW_OUTLINE;
  357. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  358. }
  359. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  360. {
  361. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_TIMELINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  362. }
  363. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  364. {
  365. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_OUTLINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  366. }
  367. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  368. {
  369. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_TIMELINE, BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  370. }
  371. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  372. {
  373. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_OUTLINE, BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  374. }
  375. public function serviceGetBlockItem()
  376. {
  377. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  378. if(!$iItemId)
  379. return array();
  380. return array('content' => $this->_oTemplate->getItemBlock($iItemId));
  381. }
  382. /**
  383. * Data for Notifications module
  384. */
  385. public function serviceGetNotificationsData()
  386. {
  387. $sModule = $this->_aModule['name'];
  388. return array(
  389. 'handlers' => array(
  390. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  391. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  392. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  393. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  394. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  395. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  396. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  397. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  398. ),
  399. 'alerts' => array(
  400. array('unit' => $sModule, 'action' => 'post_common'),
  401. array('unit' => $sModule, 'action' => 'delete'),
  402. array('unit' => $sModule, 'action' => 'repost'),
  403. array('unit' => $sModule, 'action' => 'delete_repost'),
  404. array('unit' => $sModule, 'action' => 'commentPost'),
  405. array('unit' => $sModule, 'action' => 'commentRemoved'),
  406. array('unit' => $sModule, 'action' => 'doVote'),
  407. array('unit' => $sModule, 'action' => 'undoVote'),
  408. )
  409. );
  410. }
  411. public function serviceGetNotificationsRepost($aEvent)
  412. {
  413. $aResult = $this->serviceGetNotificationsPost($aEvent);
  414. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  415. return $aResult;
  416. }
  417. public function serviceGetNotificationsPost($aEvent)
  418. {
  419. $CNF = &$this->_oConfig->CNF;
  420. $iContent = (int)$aEvent['object_id'];
  421. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  422. if(empty($aContent) || !is_array($aContent))
  423. return array();
  424. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  425. return array(
  426. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  427. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  428. 'entry_caption' => $sEntryCaption,
  429. 'entry_author' => $aContent['owner_id'],
  430. 'lang_key' => '_bx_timeline_ntfs_txt_object_added', //may be empty or not specified. In this case the default one from Notification module will be used.
  431. );
  432. }
  433. public function serviceGetNotificationsComment($aEvent)
  434. {
  435. $CNF = &$this->_oConfig->CNF;
  436. $iContent = (int)$aEvent['object_id'];
  437. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  438. if(empty($aContent) || !is_array($aContent))
  439. return array();
  440. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  441. if(!$oComment || !$oComment->isEnabled())
  442. return array();
  443. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  444. return array(
  445. 'entry_sample' => $CNF['T']['txt_sample_single'],
  446. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  447. 'entry_caption' => $sEntryCaption,
  448. 'entry_author' => $aContent['owner_id'],
  449. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  450. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  451. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  452. );
  453. }
  454. public function serviceGetNotificationsVote($aEvent)
  455. {
  456. $CNF = &$this->_oConfig->CNF;
  457. $iContent = (int)$aEvent['object_id'];
  458. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  459. if(empty($aContent) || !is_array($aContent))
  460. return array();
  461. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  462. if(!$oVote || !$oVote->isEnabled())
  463. return array();
  464. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  465. return array(
  466. 'entry_sample' => $CNF['T']['txt_sample_single'],
  467. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  468. 'entry_caption' => $sEntryCaption,
  469. 'entry_author' => $aContent['owner_id'],
  470. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  471. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  472. );
  473. }
  474. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  475. {
  476. if(!$this->isEnabled())
  477. return '';
  478. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  479. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  480. }
  481. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  482. {
  483. if(!$this->isEnabled())
  484. return '';
  485. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  486. return $this->_oTemplate->getRepostCounter($aReposted);
  487. }
  488. public function serviceGetRepostJsScript()
  489. {
  490. if(!$this->isEnabled())
  491. return '';
  492. return $this->_oTemplate->getRepostJsScript();
  493. }
  494. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  495. {
  496. if(!$this->isEnabled())
  497. return '';
  498. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  499. }
  500. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  501. {
  502. if(empty($sSystem) || empty($iObjectId))
  503. return '';
  504. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  505. if($oCmts === false)
  506. return '';
  507. $iCounter = (int)$oCmts->getCommentsCount();
  508. return $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  509. 'href' => 'javascript:void(0)',
  510. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  511. 'bx_repeat:attrs' => array(
  512. array('key' => 'onclick', 'value' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")")
  513. ),
  514. 'content' => $iCounter > 0 ? $iCounter : ''
  515. ));
  516. }
  517. public function serviceGetSettingsCheckerHelper()
  518. {
  519. bx_import('FormCheckerHelper', $this->_aModule);
  520. return 'BxTimelineFormCheckerHelper';
  521. }
  522. /*
  523. * COMMON METHODS
  524. */
  525. public function deleteEvent($aEvent)
  526. {
  527. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  528. return false;
  529. $this->onDelete($aEvent);
  530. return true;
  531. }
  532. public function getFormAttachLink()
  533. {
  534. $iUserId = $this->getUserId();
  535. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  536. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  537. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  538. $oForm->initChecker();
  539. if($oForm->isSubmittedAndValid()) {
  540. $sLink = $oForm->getCleanValue('url');
  541. $aMatches = array();
  542. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  543. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  544. $aSiteInfo = bx_get_site_info($sLink, array(
  545. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  546. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  547. ));
  548. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  549. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  550. $sMediaUrl = '';
  551. if(!empty($aSiteInfo['thumbnailUrl']))
  552. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  553. else if(!empty($aSiteInfo['OGImage']))
  554. $sMediaUrl = $aSiteInfo['OGImage'];
  555. $iMediaId = 0;
  556. $oStorage = null;
  557. if(!empty($sMediaUrl)) {
  558. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  559. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  560. }
  561. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  562. if(!empty($iId)) {
  563. if(!empty($oStorage) && !empty($iMediaId))
  564. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  565. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  566. }
  567. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  568. }
  569. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  570. }
  571. public function getFormPost()
  572. {
  573. $iUserId = $this->getUserId();
  574. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_add'), $this->_oTemplate);
  575. $oForm->initChecker();
  576. if($oForm->isSubmittedAndValid()) {
  577. list($sUserName) = $this->getUserInfo($iUserId);
  578. $sType = $oForm->getCleanValue('type');
  579. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  580. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  581. $aContent = array();
  582. //--- Process Text ---//
  583. $sText = $oForm->getCleanValue('text');
  584. $sText = $this->_prepareTextForSave($sText);
  585. $bText = !empty($sText);
  586. unset($oForm->aInputs['text']);
  587. if($bText)
  588. $aContent['text'] = $sText;
  589. //--- Process Link ---//
  590. $aLinkIds = $oForm->getCleanValue('link');
  591. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  592. //--- Process Media ---//
  593. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  594. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  595. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  596. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  597. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  598. return array('msg' => _t('_bx_timeline_txt_err_empty_post'));
  599. $sSample = '<i class="sys-icon picture-o"></i>';
  600. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $sSample;
  601. $sDescription = _t('_bx_timeline_txt_user_added_sample', $sUserName, $sSample);
  602. $iId = $oForm->insert(array(
  603. 'object_id' => $iUserId,
  604. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  605. 'content' => serialize($aContent),
  606. 'title' => $sTitle,
  607. 'description' => $sDescription,
  608. 'date' => time()
  609. ));
  610. if(!empty($iId)) {
  611. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  612. if($bText)
  613. $oMetatags->keywordsAdd($iId, $sText);
  614. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  615. //--- Process Link ---//
  616. if($bLinkIds)
  617. foreach($aLinkIds as $iLinkId)
  618. $this->_oDb->saveLink($iId, $iLinkId);
  619. //--- Process Media ---//
  620. if($bPhotoIds)
  621. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  622. if($bVideoIds)
  623. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  624. $this->onPost($iId);
  625. return array('id' => $iId);
  626. }
  627. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  628. }
  629. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  630. }
  631. public function getCmtsObject($sSystem, $iId)
  632. {
  633. if(empty($sSystem) || (int)$iId == 0)
  634. return false;
  635. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  636. if(!$oCmts || !$oCmts->isEnabled())
  637. return false;
  638. return $oCmts;
  639. }
  640. public function getViewObject($sSystem, $iId)
  641. {
  642. if(empty($sSystem) || (int)$iId == 0)
  643. return false;
  644. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  645. if(!$oView || !$oView->isEnabled())
  646. return false;
  647. return $oView;
  648. }
  649. public function getVoteObject($sSystem, $iId)
  650. {
  651. if(empty($sSystem) || (int)$iId == 0)
  652. return false;
  653. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  654. if(!$oVote || !$oVote->isEnabled())
  655. return false;
  656. return $oVote;
  657. }
  658. public function getReportObject($sSystem, $iId)
  659. {
  660. if(empty($sSystem) || (int)$iId == 0)
  661. return false;
  662. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  663. if(!$oReport || !$oReport->isEnabled())
  664. return false;
  665. return $oReport;
  666. }
  667. public function getAttachmentsMenuObject()
  668. {
  669. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  670. $oMenu->addMarkers(array(
  671. 'js_object' => $this->_oConfig->getJsObject('post'),
  672. ));
  673. return $oMenu;
  674. }
  675. public function getManageMenuObject()
  676. {
  677. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  678. }
  679. //--- Check permissions methods ---//
  680. public function isAllowedPost($bPerform = false)
  681. {
  682. if(isAdmin())
  683. return true;
  684. $iUserId = $this->getUserId();
  685. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  686. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  687. if($oProfileOwner !== false)
  688. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  689. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  690. }
  691. public function isAllowedDelete($aEvent, $bPerform = false)
  692. {
  693. if(!isLogged())
  694. return false;
  695. if(isAdmin())
  696. return true;
  697. $iUserId = (int)$this->getUserId();
  698. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  699. return true;
  700. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  701. $oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']);
  702. if($oProfileOwner !== false)
  703. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  704. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  705. }
  706. public function isAllowedComment($aEvent, $bPerform = false)
  707. {
  708. $mixedComments = $this->getCommentsData($aEvent['comments']);
  709. if($mixedComments === false)
  710. return false;
  711. list($sSystem, $iObjectId) = $mixedComments;
  712. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  713. $oCmts->addCssJs();
  714. $bResult = true;
  715. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  716. if($oProfileOwner !== false)
  717. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  718. return $bResult;
  719. }
  720. public function isAllowedViewCounter($aEvent, $bPerform = false)
  721. {
  722. $mixedViews = $this->getViewsData($aEvent['views']);
  723. if($mixedViews === false)
  724. return false;
  725. list($sSystem, $iObjectId) = $mixedViews;
  726. $oView = $this->getViewObject($sSystem, $iObjectId);
  727. $bResult = true;
  728. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  729. if($oProfileOwner !== false)
  730. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  731. return $bResult;
  732. }
  733. public function isAllowedVote($aEvent, $bPerform = false)
  734. {
  735. $mixedVotes = $this->getVotesData($aEvent['votes']);
  736. if($mixedVotes === false)
  737. return false;
  738. list($sSystem, $iObjectId) = $mixedVotes;
  739. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  740. $oVote->addCssJs();
  741. $bResult = true;
  742. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  743. if($oProfileOwner !== false)
  744. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  745. return $bResult;
  746. }
  747. public function isAllowedReport($aEvent, $bPerform = false)
  748. {
  749. $mixedReports = $this->getReportsData($aEvent['reports']);
  750. if($mixedReports === false)
  751. return false;
  752. list($sSystem, $iObjectId) = $mixedReports;
  753. $oReport = $this->getReportObject($sSystem, $iObjectId);
  754. $oReport->addCssJs();
  755. $bResult = true;
  756. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  757. if($oProfileOwner !== false)
  758. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  759. return $bResult;
  760. }
  761. public function isAllowedRepost($aEvent, $bPerform = false)
  762. {
  763. if(isAdmin())
  764. return true;
  765. $iUserId = (int)$this->getUserId();
  766. if($iUserId == 0)
  767. return false;
  768. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  769. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  770. if($oProfileOwner !== false)
  771. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  772. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  773. }
  774. public function isAllowedSend($aEvent, $bPerform = false)
  775. {
  776. if(isAdmin())
  777. return true;
  778. $iUserId = (int)$this->getUserId();
  779. if($iUserId == 0)
  780. return false;
  781. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  782. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  783. if($oProfileOwner !== false)
  784. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  785. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  786. }
  787. public function isAllowedPin($aEvent, $bPerform = false)
  788. {
  789. if((int)$aEvent['pinned'] != 0)
  790. return false;
  791. return $this->_isAllowedPin($aEvent, $bPerform);
  792. }
  793. public function isAllowedUnpin($aEvent, $bPerform = false)
  794. {
  795. if((int)$aEvent['pinned'] == 0)
  796. return false;
  797. return $this->_isAllowedPin($aEvent, $bPerform);
  798. }
  799. public function isAllowedMore($aEvent, $bPerform = false)
  800. {
  801. $oMoreMenu = $this->getManageMenuObject();
  802. $oMoreMenu->setEventId($aEvent['id']);
  803. return $oMoreMenu->isVisible();
  804. }
  805. public function onPost($iId)
  806. {
  807. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  808. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  809. //--- Request event's data from content module and update it in the Timeline DB.
  810. $this->_oTemplate->getData($aEvent);
  811. $sPostType = 'system';
  812. $iSenderId = $aEvent['owner_id'];
  813. } else {
  814. $sPostType = 'common';
  815. $iSenderId = $aEvent['object_id'];
  816. }
  817. //--- Event -> Post for Alerts Engine ---//
  818. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  819. 'object_author_id' => $aEvent['owner_id']
  820. ));
  821. $oAlert->alert();
  822. //--- Event -> Post for Alerts Engine ---//
  823. }
  824. public function onRepost($iId, $aReposted = array())
  825. {
  826. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  827. if(empty($aReposted)) {
  828. $aContent = unserialize($aEvent['content']);
  829. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  830. if(empty($aReposted) || !is_array($aReposted))
  831. return;
  832. }
  833. $iUserId = $this->getUserId();
  834. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  835. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  836. //--- Timeline -> Update for Alerts Engine ---//
  837. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  838. 'repost_id' => $iId,
  839. 'object_author_id' => $aReposted['owner_id'],
  840. ));
  841. $oAlert->alert();
  842. //--- Timeline -> Update for Alerts Engine ---//
  843. }
  844. public function onDelete($aEvent)
  845. {
  846. $iUserId = $this->getUserId();
  847. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  848. //--- Delete attached photos, videos and links when common event was deleted.
  849. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  850. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  851. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  852. $this->_deleteLinks($aEvent['id']);
  853. }
  854. //--- Update parent event when repost event was deleted.
  855. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  856. if($bRepost) {
  857. $this->_oDb->deleteRepostTrack($aEvent['id']);
  858. $aContent = unserialize($aEvent['content']);
  859. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  860. if(!empty($aReposted) && is_array($aReposted))
  861. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  862. }
  863. //--- Find and delete repost events when parent event was deleted.
  864. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  865. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  866. foreach($aRepostEvents as $aRepostEvent) {
  867. $aContent = unserialize($aRepostEvent['content']);
  868. 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'])) && (int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent['id'])) > 0) {
  869. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  870. 'repost_id' => $aRepostEvent['id'],
  871. ));
  872. $oAlert->alert();
  873. }
  874. }
  875. //--- Delete associated meta.
  876. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  877. $oMetatags->onDeleteContent($aEvent['id']);
  878. //--- Event -> Delete for Alerts Engine ---//
  879. if($bRepost)
  880. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  881. 'repost_id' => $aEvent['id'],
  882. ));
  883. else
  884. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  885. $oAlert->alert();
  886. //--- Event -> Delete for Alerts Engine ---//
  887. }
  888. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = '', $aModules = array(), $iTimeline = 0)
  889. {
  890. return $this->_prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  891. }
  892. public function getViewsData(&$aViews)
  893. {
  894. if(empty($aViews) || !is_array($aViews))
  895. return false;
  896. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  897. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  898. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  899. if($sSystem == '' || $iObjectId == 0)
  900. return false;
  901. return array($sSystem, $iObjectId, $iCount);
  902. }
  903. public function getVotesData(&$aVotes)
  904. {
  905. if(empty($aVotes) || !is_array($aVotes))
  906. return false;
  907. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  908. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  909. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  910. if($sSystem == '' || $iObjectId == 0)
  911. return false;
  912. return array($sSystem, $iObjectId, $iCount);
  913. }
  914. public function getReportsData(&$aReports)
  915. {
  916. if(empty($aReports) || !is_array($aReports))
  917. return false;
  918. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  919. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  920. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  921. if($sSystem == '' || $iObjectId == 0)
  922. return false;
  923. return array($sSystem, $iObjectId, $iCount);
  924. }
  925. public function getCommentsData(&$aComments)
  926. {
  927. if(empty($aComments) || !is_array($aComments))
  928. return false;
  929. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  930. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  931. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  932. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  933. return false;
  934. return array($sSystem, $iObjectId, $iCount);
  935. }
  936. /**
  937. * Protected Methods
  938. */
  939. protected function _serviceGetBlockView($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT)
  940. {
  941. if(empty($iProfileId) && bx_get('profile_id') !== false)
  942. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  943. if(empty($iProfileId) && isLogged())
  944. $iProfileId = bx_get_logged_profile_id();
  945. $aBlock = $this->_getBlockView($iProfileId, $sView);
  946. if(!empty($aBlock))
  947. return $aBlock;
  948. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  949. }
  950. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  951. {
  952. if(empty($sProfileModule))
  953. return array();
  954. if(empty($iProfileContentId) && bx_get('id') !== false)
  955. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  956. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  957. if(empty($oProfile))
  958. return array();
  959. return $this->_getBlockView($oProfile->id(), $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  960. }
  961. protected function _serviceGetBlockViewHome($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  962. {
  963. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_PUBLIC . '/';
  964. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  965. return $this->_serviceGetBlockViewByType($iProfileId, $sView, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  966. }
  967. protected function _serviceGetBlockViewByType($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $sType = BX_TIMELINE_TYPE_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  968. {
  969. $aParams = $this->_prepareParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  970. $aParams['view'] = $sView;
  971. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : ((int)$iPerPageDefault > 0 ? $iPerPageDefault : $this->_oConfig->getPerPage());
  972. $this->_iOwnerId = $aParams['owner_id'];
  973. $sContent = $this->_oTemplate->getViewBlock($aParams);
  974. return array('content' => $sContent);
  975. }
  976. protected function _getBlockPost($iProfileId)
  977. {
  978. $this->_iOwnerId = $iProfileId;
  979. if($this->isAllowedPost() !== true)
  980. return array();
  981. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  982. return array('content' => $sContent);
  983. }
  984. protected function _getBlockView($iProfileId, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  985. {
  986. if(!$iProfileId)
  987. return array();
  988. $aParams = $this->_prepareParams($sView, BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  989. $aParams['view'] = $sView;
  990. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  991. $this->_iOwnerId = $aParams['owner_id'];
  992. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  993. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $iProfileId . '/';
  994. $sJsObject = $this->_oConfig->getJsObject('view');
  995. $aMenu = array(
  996. array('id' => $sView . '-view-all', 'name' => $sView . '-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  997. array('id' => $sView . '-view-owner', 'name' => $sView . '-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  998. array('id' => $sView . '-view-other', 'name' => $sView . '-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  999. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  1000. );
  1001. $sContent = '';
  1002. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  1003. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  1004. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  1005. $oMenu->setSelected('', $sView . '-view-all');
  1006. if (!$sContent)
  1007. $sContent = $this->_oTemplate->getViewBlock($aParams);
  1008. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  1009. return array('content' => $sContent, 'menu' => $oMenu);
  1010. }
  1011. protected function _isAllowedPin($aEvent, $bPerform = false)
  1012. {
  1013. if(isAdmin())
  1014. return true;
  1015. $iUserId = (int)$this->getUserId();
  1016. if($iUserId == 0)
  1017. return false;
  1018. if((int)$aEvent['owner_id'] == $iUserId)
  1019. return true;
  1020. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  1021. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1022. if($oProfileOwner !== false)
  1023. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1024. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1025. }
  1026. protected function _deleteLinks($iId)
  1027. {
  1028. $aLinks = $this->_oDb->getLinks($iId);
  1029. if(empty($aLinks) || !is_array($aLinks))
  1030. return;
  1031. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  1032. foreach($aLinks as $aLink)
  1033. if(!empty($aLink['media_id']))
  1034. $oStorage->deleteFile($aLink['media_id']);
  1035. $this->_oDb->deleteLinks($iId);
  1036. }
  1037. protected function _saveMedia($sType, $iId, $aItemIds)
  1038. {
  1039. if(empty($aItemIds) || !is_array($aItemIds))
  1040. return;
  1041. $iUserId = $this->getUserId();
  1042. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1043. foreach($aItemIds as $iItemId)
  1044. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  1045. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  1046. }
  1047. protected function _deleteMedia($sType, $iId)
  1048. {
  1049. $aItems = $this->_oDb->getMedia($sType, $iId);
  1050. if(empty($aItems) || !is_array($aItems))
  1051. return;
  1052. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1053. foreach($aItems as $iItemId)
  1054. $oStorage->deleteFile($iItemId);
  1055. $this->_oDb->deleteMedia($sType, $iId);
  1056. }
  1057. protected function _prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  1058. {
  1059. return array(
  1060. 'view' => !empty($sView) ? $sView : BX_TIMELINE_VIEW_DEFAULT,
  1061. 'browse' => 'list',
  1062. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  1063. 'owner_id' => (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId(),
  1064. 'filter' => !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL,
  1065. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : array(),
  1066. 'timeline' => (int)$iTimeline > 0 ? $iTimeline : 0,
  1067. 'active' => 1,
  1068. 'hidden' => 0,
  1069. 'start' => (int)$iStart > 0 ? $iStart : 0,
  1070. 'per_page' => (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage(),
  1071. );
  1072. }
  1073. protected function _prepareParamsGet()
  1074. {
  1075. $aParams = array(
  1076. 'browse' => 'list',
  1077. 'dynamic_mode' => true,
  1078. );
  1079. $aParams['view'] = bx_get('view');
  1080. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  1081. $aParams['type'] = bx_get('type');
  1082. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  1083. $aParams['owner_id'] = bx_get('owner_id');
  1084. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  1085. $aParams['start'] = bx_get('start');
  1086. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  1087. $aParams['per_page'] = bx_get('per_page');
  1088. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  1089. $aParams['filter'] = bx_get('filter');
  1090. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  1091. $aParams['modules'] = bx_get('modules');
  1092. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  1093. $aParams['timeline'] = bx_get('timeline');
  1094. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  1095. $aParams['active'] = 1;
  1096. $aParams['hidden'] = 0;
  1097. return $aParams;
  1098. }
  1099. protected function _prepareTextForSave($s)
  1100. {
  1101. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  1102. }
  1103. protected function _getFieldValue($sField, $iContentId)
  1104. {
  1105. $CNF = &$this->_oConfig->CNF;
  1106. if(empty($CNF[$sField]))
  1107. return false;
  1108. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  1109. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  1110. return false;
  1111. return $aEvent[$CNF[$sField]];
  1112. }
  1113. }
  1114. /** @} */