BxTimelineModule.php 55 KB

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