BxTimelineModule.php 56 KB

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