BxTimelineModule.php 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  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. if(!isLogged())
  344. return '';
  345. $iProfileId = $this->getProfileId();
  346. return $this->_getBlockPost($iProfileId);
  347. }
  348. /*
  349. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  350. */
  351. public function serviceGetBlockView($iProfileId = 0)
  352. {
  353. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_TIMELINE);
  354. }
  355. public function serviceGetBlockViewOutline($iProfileId = 0)
  356. {
  357. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_OUTLINE);
  358. }
  359. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  360. {
  361. $sView = BX_TIMELINE_VIEW_TIMELINE;
  362. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  363. }
  364. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  365. {
  366. $sView = BX_TIMELINE_VIEW_OUTLINE;
  367. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  368. }
  369. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  370. {
  371. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_TIMELINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  372. }
  373. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  374. {
  375. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_OUTLINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  376. }
  377. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  378. {
  379. if(!isLogged())
  380. return '';
  381. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_TIMELINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  382. }
  383. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  384. {
  385. if(!isLogged())
  386. return '';
  387. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_OUTLINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  388. }
  389. public function serviceGetBlockItem()
  390. {
  391. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  392. if(!$iItemId)
  393. return array();
  394. return array('content' => $this->_oTemplate->getItemBlock($iItemId));
  395. }
  396. /**
  397. * Data for Notifications module
  398. */
  399. public function serviceGetNotificationsData()
  400. {
  401. $sModule = $this->_aModule['name'];
  402. return array(
  403. 'handlers' => array(
  404. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  405. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  406. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  407. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  408. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  409. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  410. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  411. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  412. ),
  413. 'alerts' => array(
  414. array('unit' => $sModule, 'action' => 'post_common'),
  415. array('unit' => $sModule, 'action' => 'delete'),
  416. array('unit' => $sModule, 'action' => 'repost'),
  417. array('unit' => $sModule, 'action' => 'delete_repost'),
  418. array('unit' => $sModule, 'action' => 'commentPost'),
  419. array('unit' => $sModule, 'action' => 'commentRemoved'),
  420. array('unit' => $sModule, 'action' => 'doVote'),
  421. array('unit' => $sModule, 'action' => 'undoVote'),
  422. )
  423. );
  424. }
  425. public function serviceGetNotificationsRepost($aEvent)
  426. {
  427. $aResult = $this->serviceGetNotificationsPost($aEvent);
  428. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  429. return $aResult;
  430. }
  431. public function serviceGetNotificationsPost($aEvent)
  432. {
  433. $CNF = &$this->_oConfig->CNF;
  434. $iContent = (int)$aEvent['object_id'];
  435. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  436. if(empty($aContent) || !is_array($aContent))
  437. return array();
  438. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  439. return array(
  440. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  441. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  442. 'entry_caption' => $sEntryCaption,
  443. 'entry_author' => $aContent['owner_id'],
  444. '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.
  445. );
  446. }
  447. public function serviceGetNotificationsComment($aEvent)
  448. {
  449. $CNF = &$this->_oConfig->CNF;
  450. $iContent = (int)$aEvent['object_id'];
  451. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  452. if(empty($aContent) || !is_array($aContent))
  453. return array();
  454. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  455. if(!$oComment || !$oComment->isEnabled())
  456. return array();
  457. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  458. return array(
  459. 'entry_sample' => $CNF['T']['txt_sample_single'],
  460. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  461. 'entry_caption' => $sEntryCaption,
  462. 'entry_author' => $aContent['owner_id'],
  463. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  464. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  465. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  466. );
  467. }
  468. public function serviceGetNotificationsVote($aEvent)
  469. {
  470. $CNF = &$this->_oConfig->CNF;
  471. $iContent = (int)$aEvent['object_id'];
  472. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  473. if(empty($aContent) || !is_array($aContent))
  474. return array();
  475. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  476. if(!$oVote || !$oVote->isEnabled())
  477. return array();
  478. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  479. return array(
  480. 'entry_sample' => $CNF['T']['txt_sample_single'],
  481. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  482. 'entry_caption' => $sEntryCaption,
  483. 'entry_author' => $aContent['owner_id'],
  484. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  485. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  486. );
  487. }
  488. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  489. {
  490. if(!$this->isEnabled())
  491. return '';
  492. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  493. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  494. }
  495. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  496. {
  497. if(!$this->isEnabled())
  498. return '';
  499. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  500. return $this->_oTemplate->getRepostCounter($aReposted);
  501. }
  502. public function serviceGetRepostJsScript()
  503. {
  504. if(!$this->isEnabled())
  505. return '';
  506. return $this->_oTemplate->getRepostJsScript();
  507. }
  508. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  509. {
  510. if(!$this->isEnabled())
  511. return '';
  512. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  513. }
  514. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  515. {
  516. if(empty($sSystem) || empty($iObjectId))
  517. return '';
  518. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  519. if($oCmts === false)
  520. return '';
  521. $iCounter = (int)$oCmts->getCommentsCount();
  522. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter > 0 ? $iCounter : '', array(
  523. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  524. 'onclick' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  525. ));
  526. }
  527. public function serviceGetSettingsCheckerHelper()
  528. {
  529. bx_import('FormCheckerHelper', $this->_aModule);
  530. return 'BxTimelineFormCheckerHelper';
  531. }
  532. /*
  533. * COMMON METHODS
  534. */
  535. public function deleteEvent($aEvent)
  536. {
  537. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  538. return false;
  539. $this->onDelete($aEvent);
  540. return true;
  541. }
  542. public function getFormAttachLink()
  543. {
  544. $iUserId = $this->getUserId();
  545. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  546. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  547. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  548. $oForm->initChecker();
  549. if($oForm->isSubmittedAndValid()) {
  550. $sLink = $oForm->getCleanValue('url');
  551. $aMatches = array();
  552. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  553. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  554. $aSiteInfo = bx_get_site_info($sLink, array(
  555. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  556. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  557. ));
  558. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  559. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  560. $sMediaUrl = '';
  561. if(!empty($aSiteInfo['thumbnailUrl']))
  562. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  563. else if(!empty($aSiteInfo['OGImage']))
  564. $sMediaUrl = $aSiteInfo['OGImage'];
  565. $iMediaId = 0;
  566. $oStorage = null;
  567. if(!empty($sMediaUrl)) {
  568. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  569. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  570. }
  571. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  572. if(!empty($iId)) {
  573. if(!empty($oStorage) && !empty($iMediaId))
  574. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  575. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  576. }
  577. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  578. }
  579. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  580. }
  581. public function getFormPost($aParams = array())
  582. {
  583. $iUserId = $this->getUserId();
  584. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  585. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  586. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  587. $oForm->initChecker();
  588. if($oForm->isSubmittedAndValid()) {
  589. list($sUserName) = $this->getUserInfo($iUserId);
  590. $sType = $oForm->getCleanValue('type');
  591. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  592. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  593. $aContent = array();
  594. //--- Process Text ---//
  595. $sText = $oForm->getCleanValue('text');
  596. $sText = $this->_prepareTextForSave($sText);
  597. $bText = !empty($sText);
  598. unset($oForm->aInputs['text']);
  599. if($bText)
  600. $aContent['text'] = $sText;
  601. //--- Process Privacy ---//
  602. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  603. if(empty($iObjectPrivacyView))
  604. $iObjectPrivacyView = $this->_oConfig->getPrivacyViewDefault('object');
  605. //--- Process Link ---//
  606. $aLinkIds = $oForm->getCleanValue('link');
  607. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  608. //--- Process Media ---//
  609. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  610. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  611. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  612. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  613. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  614. return array('msg' => _t('_bx_timeline_txt_err_empty_post'));
  615. $sSample = '<i class="sys-icon picture-o"></i>';
  616. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $sSample;
  617. $sDescription = _t('_bx_timeline_txt_user_added_sample', $sUserName, $sSample);
  618. $iId = $oForm->insert(array(
  619. 'object_id' => $iUserId,
  620. 'object_privacy_view' => $iObjectPrivacyView,
  621. 'content' => serialize($aContent),
  622. 'title' => $sTitle,
  623. 'description' => $sDescription,
  624. 'date' => time()
  625. ));
  626. if(!empty($iId)) {
  627. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  628. if($bText)
  629. $oMetatags->keywordsAdd($iId, $sText);
  630. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  631. //--- Process Link ---//
  632. if($bLinkIds)
  633. foreach($aLinkIds as $iLinkId)
  634. $this->_oDb->saveLink($iId, $iLinkId);
  635. //--- Process Media ---//
  636. if($bPhotoIds)
  637. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  638. if($bVideoIds)
  639. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  640. $this->onPost($iId);
  641. return array('id' => $iId);
  642. }
  643. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  644. }
  645. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  646. }
  647. public function getCmtsObject($sSystem, $iId)
  648. {
  649. if(empty($sSystem) || (int)$iId == 0)
  650. return false;
  651. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  652. if(!$oCmts || !$oCmts->isEnabled())
  653. return false;
  654. return $oCmts;
  655. }
  656. public function getViewObject($sSystem, $iId)
  657. {
  658. if(empty($sSystem) || (int)$iId == 0)
  659. return false;
  660. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  661. if(!$oView || !$oView->isEnabled())
  662. return false;
  663. return $oView;
  664. }
  665. public function getVoteObject($sSystem, $iId)
  666. {
  667. if(empty($sSystem) || (int)$iId == 0)
  668. return false;
  669. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  670. if(!$oVote || !$oVote->isEnabled())
  671. return false;
  672. return $oVote;
  673. }
  674. public function getReportObject($sSystem, $iId)
  675. {
  676. if(empty($sSystem) || (int)$iId == 0)
  677. return false;
  678. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  679. if(!$oReport || !$oReport->isEnabled())
  680. return false;
  681. return $oReport;
  682. }
  683. public function getAttachmentsMenuObject()
  684. {
  685. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  686. $oMenu->addMarkers(array(
  687. 'js_object' => $this->_oConfig->getJsObject('post'),
  688. ));
  689. return $oMenu;
  690. }
  691. public function getManageMenuObject()
  692. {
  693. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  694. }
  695. //--- Check permissions methods ---//
  696. public function isAllowedPost($bPerform = false)
  697. {
  698. if(isAdmin())
  699. return true;
  700. $iUserId = $this->getUserId();
  701. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  702. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  703. if($oProfileOwner !== false) {
  704. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  705. return _t('_sys_txt_access_denied');
  706. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  707. }
  708. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  709. }
  710. public function isAllowedView($aEvent, $bPerform = false)
  711. {
  712. $CNF = $this->_oConfig->CNF;
  713. $mixedResult = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  714. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  715. return false;
  716. return true;
  717. }
  718. public function isAllowedDelete($aEvent, $bPerform = false)
  719. {
  720. if(!isLogged())
  721. return false;
  722. if(isAdmin())
  723. return true;
  724. $iUserId = (int)$this->getUserId();
  725. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  726. return true;
  727. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  728. $oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']);
  729. if($oProfileOwner !== false)
  730. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  731. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  732. }
  733. public function isAllowedComment($aEvent, $bPerform = false)
  734. {
  735. $mixedComments = $this->getCommentsData($aEvent['comments']);
  736. if($mixedComments === false)
  737. return false;
  738. list($sSystem, $iObjectId) = $mixedComments;
  739. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  740. $oCmts->addCssJs();
  741. $bResult = true;
  742. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  743. if($oProfileOwner !== false) {
  744. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  745. return false;
  746. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  747. }
  748. return $bResult;
  749. }
  750. public function isAllowedViewCounter($aEvent, $bPerform = false)
  751. {
  752. $mixedViews = $this->getViewsData($aEvent['views']);
  753. if($mixedViews === false)
  754. return false;
  755. list($sSystem, $iObjectId) = $mixedViews;
  756. $oView = $this->getViewObject($sSystem, $iObjectId);
  757. $bResult = true;
  758. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  759. if($oProfileOwner !== false)
  760. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  761. return $bResult;
  762. }
  763. public function isAllowedVote($aEvent, $bPerform = false)
  764. {
  765. $mixedVotes = $this->getVotesData($aEvent['votes']);
  766. if($mixedVotes === false)
  767. return false;
  768. list($sSystem, $iObjectId) = $mixedVotes;
  769. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  770. $oVote->addCssJs();
  771. $bResult = true;
  772. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  773. if($oProfileOwner !== false)
  774. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  775. return $bResult;
  776. }
  777. public function isAllowedReport($aEvent, $bPerform = false)
  778. {
  779. $mixedReports = $this->getReportsData($aEvent['reports']);
  780. if($mixedReports === false)
  781. return false;
  782. list($sSystem, $iObjectId) = $mixedReports;
  783. $oReport = $this->getReportObject($sSystem, $iObjectId);
  784. $oReport->addCssJs();
  785. $bResult = true;
  786. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  787. if($oProfileOwner !== false)
  788. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  789. return $bResult;
  790. }
  791. public function isAllowedRepost($aEvent, $bPerform = false)
  792. {
  793. if(isAdmin())
  794. return true;
  795. $iUserId = (int)$this->getUserId();
  796. if($iUserId == 0)
  797. return false;
  798. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  799. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  800. if($oProfileOwner !== false)
  801. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  802. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  803. }
  804. public function isAllowedSend($aEvent, $bPerform = false)
  805. {
  806. if(isAdmin())
  807. return true;
  808. $iUserId = (int)$this->getUserId();
  809. if($iUserId == 0)
  810. return false;
  811. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  812. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  813. if($oProfileOwner !== false)
  814. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  815. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  816. }
  817. public function isAllowedPin($aEvent, $bPerform = false)
  818. {
  819. if((int)$aEvent['pinned'] != 0)
  820. return false;
  821. return $this->_isAllowedPin($aEvent, $bPerform);
  822. }
  823. public function isAllowedUnpin($aEvent, $bPerform = false)
  824. {
  825. if((int)$aEvent['pinned'] == 0)
  826. return false;
  827. return $this->_isAllowedPin($aEvent, $bPerform);
  828. }
  829. public function isAllowedMore($aEvent, $bPerform = false)
  830. {
  831. $oMoreMenu = $this->getManageMenuObject();
  832. $oMoreMenu->setEventId($aEvent['id']);
  833. return $oMoreMenu->isVisible();
  834. }
  835. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  836. {
  837. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  838. return _t('_sys_txt_access_denied');
  839. return CHECK_ACTION_RESULT_ALLOWED;
  840. }
  841. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  842. {
  843. $CNF = $this->_oConfig->CNF;
  844. $mixedResult = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  845. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  846. return $mixedResult;
  847. return CHECK_ACTION_RESULT_ALLOWED;
  848. }
  849. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  850. {
  851. $sError = '_sys_txt_access_denied';
  852. $aContentInfo = $this->_oTemplate->getData($aContentInfo);
  853. if($aContentInfo === false)
  854. return _t($sError);
  855. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  856. return _t($sError);
  857. return CHECK_ACTION_RESULT_ALLOWED;
  858. }
  859. public function onPost($iId)
  860. {
  861. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  862. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  863. //--- Request event's data from content module and update it in the Timeline DB.
  864. $this->_oTemplate->getData($aEvent);
  865. $sPostType = 'system';
  866. $iSenderId = $aEvent['owner_id'];
  867. } else {
  868. $sPostType = 'common';
  869. $iSenderId = $aEvent['object_id'];
  870. }
  871. //--- Event -> Post for Alerts Engine ---//
  872. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  873. 'privacy_view' => $aEvent['object_privacy_view'],
  874. 'object_author_id' => $aEvent['owner_id'],
  875. ));
  876. $oAlert->alert();
  877. //--- Event -> Post for Alerts Engine ---//
  878. }
  879. public function onRepost($iId, $aReposted = array())
  880. {
  881. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  882. if(empty($aReposted)) {
  883. $aContent = unserialize($aEvent['content']);
  884. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  885. if(empty($aReposted) || !is_array($aReposted))
  886. return;
  887. }
  888. $iUserId = $this->getUserId();
  889. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  890. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  891. //--- Timeline -> Update for Alerts Engine ---//
  892. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  893. 'privacy_view' => $aEvent['object_privacy_view'],
  894. 'object_author_id' => $aReposted['owner_id'],
  895. 'repost_id' => $iId,
  896. ));
  897. $oAlert->alert();
  898. //--- Timeline -> Update for Alerts Engine ---//
  899. }
  900. public function onDelete($aEvent)
  901. {
  902. $iUserId = $this->getUserId();
  903. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  904. //--- Delete attached photos, videos and links when common event was deleted.
  905. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  906. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  907. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  908. $this->_deleteLinks($aEvent['id']);
  909. }
  910. //--- Update parent event when repost event was deleted.
  911. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  912. if($bRepost) {
  913. $this->_oDb->deleteRepostTrack($aEvent['id']);
  914. $aContent = unserialize($aEvent['content']);
  915. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  916. if(!empty($aReposted) && is_array($aReposted))
  917. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  918. }
  919. //--- Find and delete repost events when parent event was deleted.
  920. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  921. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  922. foreach($aRepostEvents as $aRepostEvent) {
  923. $aContent = unserialize($aRepostEvent['content']);
  924. 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) {
  925. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  926. 'repost_id' => $aRepostEvent['id'],
  927. ));
  928. $oAlert->alert();
  929. }
  930. }
  931. //--- Delete associated meta.
  932. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  933. $oMetatags->onDeleteContent($aEvent['id']);
  934. //--- Event -> Delete for Alerts Engine ---//
  935. if($bRepost)
  936. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  937. 'repost_id' => $aEvent['id'],
  938. ));
  939. else
  940. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  941. $oAlert->alert();
  942. //--- Event -> Delete for Alerts Engine ---//
  943. }
  944. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = '', $aModules = array(), $iTimeline = 0)
  945. {
  946. return $this->_prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  947. }
  948. public function getViewsData(&$aViews)
  949. {
  950. if(empty($aViews) || !is_array($aViews))
  951. return false;
  952. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  953. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  954. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  955. if($sSystem == '' || $iObjectId == 0)
  956. return false;
  957. return array($sSystem, $iObjectId, $iCount);
  958. }
  959. public function getVotesData(&$aVotes)
  960. {
  961. if(empty($aVotes) || !is_array($aVotes))
  962. return false;
  963. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  964. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  965. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  966. if($sSystem == '' || $iObjectId == 0)
  967. return false;
  968. return array($sSystem, $iObjectId, $iCount);
  969. }
  970. public function getReportsData(&$aReports)
  971. {
  972. if(empty($aReports) || !is_array($aReports))
  973. return false;
  974. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  975. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  976. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  977. if($sSystem == '' || $iObjectId == 0)
  978. return false;
  979. return array($sSystem, $iObjectId, $iCount);
  980. }
  981. public function getCommentsData(&$aComments)
  982. {
  983. if(empty($aComments) || !is_array($aComments))
  984. return false;
  985. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  986. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  987. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  988. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  989. return false;
  990. return array($sSystem, $iObjectId, $iCount);
  991. }
  992. /**
  993. * Protected Methods
  994. */
  995. protected function _serviceGetBlockView($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT)
  996. {
  997. if(empty($iProfileId) && bx_get('profile_id') !== false)
  998. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  999. if(empty($iProfileId) && isLogged())
  1000. $iProfileId = bx_get_logged_profile_id();
  1001. $aBlock = $this->_getBlockView($iProfileId, $sView);
  1002. if(!empty($aBlock))
  1003. return $aBlock;
  1004. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  1005. }
  1006. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1007. {
  1008. if(empty($sProfileModule))
  1009. return array();
  1010. if(empty($iProfileContentId) && bx_get('id') !== false)
  1011. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1012. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  1013. if(empty($oProfile))
  1014. return array();
  1015. return $this->_getBlockView($oProfile->id(), $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1016. }
  1017. protected function _serviceGetBlockViewHome($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1018. {
  1019. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_PUBLIC . '/';
  1020. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  1021. return $this->_serviceGetBlockViewByType($iProfileId, $sView, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  1022. }
  1023. 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())
  1024. {
  1025. $aParams = $this->_prepareParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1026. $aParams['view'] = $sView;
  1027. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : ((int)$iPerPageDefault > 0 ? $iPerPageDefault : $this->_oConfig->getPerPage());
  1028. $this->_iOwnerId = $aParams['owner_id'];
  1029. $sContent = $this->_oTemplate->getViewBlock($aParams);
  1030. return array('content' => $sContent);
  1031. }
  1032. protected function _getBlockPost($iProfileId, $aParams = array())
  1033. {
  1034. $this->_iOwnerId = $iProfileId;
  1035. if($this->isAllowedPost() !== true)
  1036. return array();
  1037. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  1038. return array('content' => $sContent);
  1039. }
  1040. protected function _getBlockView($iProfileId, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1041. {
  1042. if(!$iProfileId)
  1043. return array();
  1044. $aParams = $this->_prepareParams($sView, BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1045. $aParams['view'] = $sView;
  1046. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  1047. $this->_iOwnerId = $aParams['owner_id'];
  1048. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  1049. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  1050. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1051. return array('content' => MsgBox($mixedResult));
  1052. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  1053. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $iProfileId . '/';
  1054. $sJsObject = $this->_oConfig->getJsObject('view');
  1055. $aMenu = array(
  1056. 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),
  1057. 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)),
  1058. 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')),
  1059. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  1060. );
  1061. $sContent = '';
  1062. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  1063. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  1064. $oMenu->setSelected('', $sView . '-view-all');
  1065. if (!$sContent)
  1066. $sContent = $this->_oTemplate->getViewBlock($aParams);
  1067. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  1068. return array('content' => $sContent, 'menu' => $oMenu);
  1069. }
  1070. protected function _isAllowedPin($aEvent, $bPerform = false)
  1071. {
  1072. if(isAdmin())
  1073. return true;
  1074. $iUserId = (int)$this->getUserId();
  1075. if($iUserId == 0)
  1076. return false;
  1077. if((int)$aEvent['owner_id'] == $iUserId)
  1078. return true;
  1079. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  1080. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1081. if($oProfileOwner !== false)
  1082. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1083. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1084. }
  1085. protected function _deleteLinks($iId)
  1086. {
  1087. $aLinks = $this->_oDb->getLinks($iId);
  1088. if(empty($aLinks) || !is_array($aLinks))
  1089. return;
  1090. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  1091. foreach($aLinks as $aLink)
  1092. if(!empty($aLink['media_id']))
  1093. $oStorage->deleteFile($aLink['media_id']);
  1094. $this->_oDb->deleteLinks($iId);
  1095. }
  1096. protected function _saveMedia($sType, $iId, $aItemIds)
  1097. {
  1098. if(empty($aItemIds) || !is_array($aItemIds))
  1099. return;
  1100. $iUserId = $this->getUserId();
  1101. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1102. foreach($aItemIds as $iItemId)
  1103. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  1104. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  1105. }
  1106. protected function _deleteMedia($sType, $iId)
  1107. {
  1108. $aItems = $this->_oDb->getMedia($sType, $iId);
  1109. if(empty($aItems) || !is_array($aItems))
  1110. return;
  1111. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1112. foreach($aItems as $iItemId)
  1113. $oStorage->deleteFile($iItemId);
  1114. $this->_oDb->deleteMedia($sType, $iId);
  1115. }
  1116. protected function _prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  1117. {
  1118. return array(
  1119. 'view' => !empty($sView) ? $sView : BX_TIMELINE_VIEW_DEFAULT,
  1120. 'browse' => 'list',
  1121. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  1122. 'owner_id' => (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId(),
  1123. 'filter' => !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL,
  1124. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : array(),
  1125. 'timeline' => (int)$iTimeline > 0 ? $iTimeline : 0,
  1126. 'active' => 1,
  1127. 'hidden' => 0,
  1128. 'start' => (int)$iStart > 0 ? $iStart : 0,
  1129. 'per_page' => (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage(),
  1130. );
  1131. }
  1132. protected function _prepareParamsGet()
  1133. {
  1134. $aParams = array(
  1135. 'browse' => 'list',
  1136. 'dynamic_mode' => true,
  1137. );
  1138. $aParams['view'] = bx_get('view');
  1139. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  1140. $aParams['type'] = bx_get('type');
  1141. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  1142. $aParams['owner_id'] = bx_get('owner_id');
  1143. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  1144. $aParams['start'] = bx_get('start');
  1145. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  1146. $aParams['per_page'] = bx_get('per_page');
  1147. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  1148. $aParams['filter'] = bx_get('filter');
  1149. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  1150. $aParams['modules'] = bx_get('modules');
  1151. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  1152. $aParams['timeline'] = bx_get('timeline');
  1153. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  1154. $aParams['active'] = 1;
  1155. $aParams['hidden'] = 0;
  1156. return $aParams;
  1157. }
  1158. protected function _prepareTextForSave($s)
  1159. {
  1160. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  1161. }
  1162. protected function _getFieldValue($sField, $iContentId)
  1163. {
  1164. $CNF = &$this->_oConfig->CNF;
  1165. if(empty($CNF[$sField]))
  1166. return false;
  1167. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  1168. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  1169. return false;
  1170. return $aEvent[$CNF[$sField]];
  1171. }
  1172. }
  1173. /** @} */