BxTimelineModule.php 53 KB

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