BxTimelineModule.php 51 KB

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