BxTimelineModule.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  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_SHARE', 'share');
  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 actionShare()
  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. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  106. if(empty($aShared) || !is_array($aShared)) {
  107. echoJson(array('code' => 1, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  108. return;
  109. }
  110. $mixedAllowed = $this->isAllowedShare($aShared, true);
  111. if($mixedAllowed !== true) {
  112. echoJson(array('code' => 2, 'msg' => strip_tags($mixedAllowed)));
  113. return;
  114. }
  115. $bShared = $this->_oDb->isShared($aShared['id'], $iOwnerId, $iAuthorId);
  116. if($bShared) {
  117. echoJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_already_shared')));
  118. return;
  119. }
  120. $iId = $this->_oDb->insertEvent(array(
  121. 'owner_id' => $iOwnerId,
  122. 'type' => $this->_oConfig->getPrefix('common_post') . 'share',
  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_share')));
  132. return;
  133. }
  134. $this->onShare($iId, $aShared);
  135. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  136. $sCounter = $this->_oTemplate->getShareCounter($aShared);
  137. echoJson(array(
  138. 'code' => 0,
  139. 'msg' => _t('_bx_timeline_txt_msg_success_share'),
  140. 'count' => $aShared['shares'],
  141. 'counter' => $sCounter,
  142. 'disabled' => !$bShared
  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) = $this->_oTemplate->getPosts($aParams);
  168. echoJson(array(
  169. 'view' => $aParams['view'],
  170. 'items' => $sItems,
  171. 'load_more' => $sLoadMore,
  172. 'back' => $sBack,
  173. 'eval' => $this->_oConfig->getJsObject('view') . "._onGetPosts(oData)"
  174. ));
  175. }
  176. public function actionGetPostForm($sType)
  177. {
  178. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  179. $sMethod = 'getForm' . ucfirst($sType);
  180. if(!method_exists($this, $sMethod)) {
  181. echoJson(array());
  182. return;
  183. }
  184. $aResult = $this->$sMethod();
  185. echoJson($aResult);
  186. }
  187. public function actionGetComments()
  188. {
  189. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  190. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  191. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  192. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  193. echoJson(array('content' => $sComments));
  194. }
  195. public function actionAddAttachLink()
  196. {
  197. $aResult = $this->getFormAttachLink();
  198. echoJson($aResult);
  199. }
  200. public function actionDeleteAttachLink()
  201. {
  202. $iUserId = $this->getUserId();
  203. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  204. if(empty($iLinkId)) {
  205. echoJson(array());
  206. return;
  207. }
  208. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  209. if(empty($aLink) || !is_array($aLink)) {
  210. echoJson(array());
  211. return;
  212. }
  213. if(!empty($aLink['media_id']))
  214. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  215. $aResult = array();
  216. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  217. $aResult = array('code' => 0);
  218. else
  219. $aResult = array('code' => 1, 'msg' => _t('_bx_timeline_form_post_input_link_err_delete'));
  220. echoJson($aResult);
  221. }
  222. public function actionGetAttachLinkForm()
  223. {
  224. echo $this->_oTemplate->getAttachLinkForm();
  225. }
  226. public function actionGetSharedBy()
  227. {
  228. $iSharedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  229. echo $this->_oTemplate->getSharedBy($iSharedId);
  230. }
  231. function actionRss()
  232. {
  233. $aArgs = func_get_args();
  234. $iOwnerId = array_shift($aArgs);
  235. list($sUserName) = $this->getUserInfo($iOwnerId);
  236. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  237. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  238. $aParams = $this->_prepareParams('owner', $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  239. $aEvents = $this->_oDb->getEvents($aParams);
  240. $aRssData = array();
  241. foreach($aEvents as $aEvent) {
  242. if(empty($aEvent['title'])) continue;
  243. $aRssData[$aEvent['id']] = array(
  244. 'UnitID' => $aEvent['id'],
  245. 'UnitTitle' => $aEvent['title'],
  246. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  247. 'UnitDesc' => $aEvent['description'],
  248. 'UnitDateTimeUTS' => $aEvent['date'],
  249. );
  250. }
  251. $oRss = new BxDolRssFactory();
  252. header('Content-Type: application/xml; charset=utf-8');
  253. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  254. }
  255. /**
  256. * SERVICE METHODS
  257. *
  258. * Get Post block for a separate page.
  259. */
  260. public function serviceGetBlockPost($iProfileId = 0)
  261. {
  262. if(empty($iProfileId) && bx_get('profile_id') !== false)
  263. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  264. if(empty($iProfileId) && isLogged())
  265. $iProfileId = bx_get_logged_profile_id();
  266. if(!$iProfileId)
  267. return array();
  268. return $this->_getBlockPost($iProfileId);
  269. }
  270. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  271. {
  272. if(empty($sProfileModule))
  273. return array();
  274. if(empty($iProfileContentId) && bx_get('id') !== false)
  275. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  276. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  277. if(empty($oProfile))
  278. return array();
  279. return $this->_getBlockPost($oProfile->id());
  280. }
  281. public function serviceGetBlockPostHome()
  282. {
  283. $iProfileId = 0;
  284. return $this->_getBlockPost($iProfileId);
  285. }
  286. /*
  287. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  288. */
  289. public function serviceGetBlockView($iProfileId = 0)
  290. {
  291. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_TIMELINE);
  292. }
  293. public function serviceGetBlockViewOutline($iProfileId = 0)
  294. {
  295. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_OUTLINE);
  296. }
  297. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  298. {
  299. $sView = BX_TIMELINE_VIEW_TIMELINE;
  300. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  301. }
  302. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  303. {
  304. $sView = BX_TIMELINE_VIEW_OUTLINE;
  305. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  306. }
  307. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  308. {
  309. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_TIMELINE, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  310. }
  311. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  312. {
  313. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_OUTLINE, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  314. }
  315. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  316. {
  317. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_TIMELINE, BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  318. }
  319. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  320. {
  321. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_OUTLINE, BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  322. }
  323. public function serviceGetBlockItem()
  324. {
  325. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  326. if(!$iItemId)
  327. return array();
  328. return array('content' => $this->_oTemplate->getItemBlock($iItemId));
  329. }
  330. /**
  331. * Data for Notifications module
  332. */
  333. public function serviceGetNotificationsData()
  334. {
  335. $sModule = $this->_aModule['name'];
  336. return array(
  337. 'handlers' => array(
  338. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  339. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  340. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  341. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  342. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  343. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  344. ),
  345. 'alerts' => array(
  346. array('unit' => $sModule, 'action' => 'post_common'),
  347. array('unit' => $sModule, 'action' => 'delete'),
  348. array('unit' => $sModule, 'action' => 'commentPost'),
  349. array('unit' => $sModule, 'action' => 'commentRemoved'),
  350. array('unit' => $sModule, 'action' => 'doVote'),
  351. array('unit' => $sModule, 'action' => 'undoVote'),
  352. )
  353. );
  354. }
  355. public function serviceGetNotificationsPost($aEvent)
  356. {
  357. $CNF = &$this->_oConfig->CNF;
  358. $iContent = (int)$aEvent['object_id'];
  359. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  360. if(empty($aContent) || !is_array($aContent))
  361. return array();
  362. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  363. return array(
  364. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  365. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  366. 'entry_caption' => $sEntryCaption,
  367. 'entry_author' => $aContent['owner_id'],
  368. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  369. );
  370. }
  371. public function serviceGetNotificationsComment($aEvent)
  372. {
  373. $CNF = &$this->_oConfig->CNF;
  374. $iContent = (int)$aEvent['object_id'];
  375. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  376. if(empty($aContent) || !is_array($aContent))
  377. return array();
  378. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  379. if(!$oComment || !$oComment->isEnabled())
  380. return array();
  381. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  382. return array(
  383. 'entry_sample' => $CNF['T']['txt_sample_single'],
  384. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  385. 'entry_caption' => $sEntryCaption,
  386. 'entry_author' => $aContent['owner_id'],
  387. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  388. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_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 serviceGetNotificationsVote($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. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  400. if(!$oVote || !$oVote->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_vote_single'],
  409. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  410. );
  411. }
  412. public function serviceGetShareElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  413. {
  414. if(!$this->isEnabled())
  415. return '';
  416. $aParams = array_merge($this->_oConfig->getShareDefaults(), $aParams);
  417. return $this->_oTemplate->getShareElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  418. }
  419. public function serviceGetShareCounter($sType, $sAction, $iObjectId)
  420. {
  421. if(!$this->isEnabled())
  422. return '';
  423. $aShared = $this->_oDb->getShared($sType, $sAction, $iObjectId);
  424. return $this->_oTemplate->getShareCounter($aShared);
  425. }
  426. public function serviceGetShareJsScript()
  427. {
  428. if(!$this->isEnabled())
  429. return '';
  430. return $this->_oTemplate->getShareJsScript();
  431. }
  432. public function serviceGetShareJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  433. {
  434. if(!$this->isEnabled())
  435. return '';
  436. return $this->_oTemplate->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  437. }
  438. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  439. {
  440. if(empty($sSystem) || empty($iObjectId))
  441. return '';
  442. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  443. if($oCmts === false)
  444. return '';
  445. $iCounter = (int)$oCmts->getCommentsCount();
  446. return $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  447. 'href' => 'javascript:void(0)',
  448. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  449. 'bx_repeat:attrs' => array(
  450. array('key' => 'onclick', 'value' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")")
  451. ),
  452. 'content' => $iCounter > 0 ? $iCounter : ''
  453. ));
  454. }
  455. public function serviceGetSettingsCheckerHelper()
  456. {
  457. bx_import('FormCheckerHelper', $this->_aModule);
  458. return 'BxTimelineFormCheckerHelper';
  459. }
  460. /*
  461. * COMMON METHODS
  462. */
  463. public function deleteEvent($aEvent)
  464. {
  465. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  466. return false;
  467. $this->onDelete($aEvent);
  468. return true;
  469. }
  470. public function getFormAttachLink()
  471. {
  472. $iUserId = $this->getUserId();
  473. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  474. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  475. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  476. $oForm->initChecker();
  477. if($oForm->isSubmittedAndValid()) {
  478. $sLink = $oForm->getCleanValue('url');
  479. $aMatches = array();
  480. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  481. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  482. $aSiteInfo = bx_get_site_info($sLink, array(
  483. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  484. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  485. ));
  486. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  487. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  488. $sMediaUrl = '';
  489. if(!empty($aSiteInfo['thumbnailUrl']))
  490. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  491. else if(!empty($aSiteInfo['OGImage']))
  492. $sMediaUrl = $aSiteInfo['OGImage'];
  493. $iMediaId = 0;
  494. $oStorage = null;
  495. if(!empty($sMediaUrl)) {
  496. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  497. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  498. }
  499. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  500. if(!empty($iId)) {
  501. if(!empty($oStorage) && !empty($iMediaId))
  502. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  503. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  504. }
  505. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  506. }
  507. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  508. }
  509. public function getFormPost()
  510. {
  511. $iUserId = $this->getUserId();
  512. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_add'), $this->_oTemplate);
  513. $oForm->initChecker();
  514. if($oForm->isSubmittedAndValid()) {
  515. list($sUserName) = $this->getUserInfo($iUserId);
  516. $sType = $oForm->getCleanValue('type');
  517. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  518. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  519. $aContent = array();
  520. //--- Process Text ---//
  521. $sText = $oForm->getCleanValue('text');
  522. $sText = $this->_prepareTextForSave($sText);
  523. $bText = !empty($sText);
  524. unset($oForm->aInputs['text']);
  525. if($bText)
  526. $aContent['text'] = $sText;
  527. //--- Process Link ---//
  528. $aLinkIds = $oForm->getCleanValue('link');
  529. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  530. //--- Process Media ---//
  531. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  532. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  533. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  534. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  535. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  536. return array('msg' => _t('_bx_timeline_txt_err_empty_post'));
  537. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample'));
  538. $sDescription = $bText ? $sText : '';
  539. $iId = $oForm->insert(array(
  540. 'object_id' => $iUserId,
  541. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  542. 'content' => serialize($aContent),
  543. 'title' => $sTitle,
  544. 'description' => $sDescription,
  545. 'date' => time()
  546. ));
  547. if(!empty($iId)) {
  548. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  549. if($bText)
  550. $oMetatags->keywordsAdd($iId, $sText);
  551. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  552. //--- Process Link ---//
  553. if($bLinkIds)
  554. foreach($aLinkIds as $iLinkId)
  555. $this->_oDb->saveLink($iId, $iLinkId);
  556. //--- Process Media ---//
  557. if($bPhotoIds)
  558. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  559. if($bVideoIds)
  560. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  561. $this->onPost($iId);
  562. return array('id' => $iId);
  563. }
  564. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  565. }
  566. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  567. }
  568. public function getCmtsObject($sSystem, $iId)
  569. {
  570. if(empty($sSystem) || (int)$iId == 0)
  571. return false;
  572. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  573. if(!$oCmts->isEnabled())
  574. return false;
  575. return $oCmts;
  576. }
  577. public function getVoteObject($sSystem, $iId)
  578. {
  579. if(empty($sSystem) || (int)$iId == 0)
  580. return false;
  581. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  582. if(!$oVote->isEnabled())
  583. return false;
  584. return $oVote;
  585. }
  586. public function getReportObject($sSystem, $iId)
  587. {
  588. if(empty($sSystem) || (int)$iId == 0)
  589. return false;
  590. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  591. if(!$oReport->isEnabled())
  592. return false;
  593. return $oReport;
  594. }
  595. public function getAttachmentsMenuObject()
  596. {
  597. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  598. $oMenu->addMarkers(array(
  599. 'js_object' => $this->_oConfig->getJsObject('post'),
  600. ));
  601. return $oMenu;
  602. }
  603. public function getManageMenuObject()
  604. {
  605. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  606. }
  607. //--- Check permissions methods ---//
  608. public function isAllowedPost($bPerform = false)
  609. {
  610. if(isAdmin())
  611. return true;
  612. $iUserId = $this->getUserId();
  613. if($iUserId != 0 && $iUserId == $this->_iOwnerId)
  614. return true;
  615. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  616. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  617. if($oProfileOwner !== false)
  618. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  619. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  620. }
  621. public function isAllowedDelete($aEvent, $bPerform = false)
  622. {
  623. if(isAdmin())
  624. return true;
  625. $iUserId = (int)$this->getUserId();
  626. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  627. return true;
  628. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  629. if ($oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']))
  630. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  631. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  632. }
  633. public function isAllowedComment($aEvent, $bPerform = false)
  634. {
  635. $mixedComments = $this->getCommentsData($aEvent['comments']);
  636. if($mixedComments === false)
  637. return false;
  638. list($sSystem, $iObjectId) = $mixedComments;
  639. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  640. $oCmts->addCssJs();
  641. $bResult = true;
  642. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  643. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  644. return $bResult;
  645. }
  646. public function isAllowedVote($aEvent, $bPerform = false)
  647. {
  648. $mixedVotes = $this->getVotesData($aEvent['votes']);
  649. if($mixedVotes === false)
  650. return false;
  651. list($sSystem, $iObjectId) = $mixedVotes;
  652. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  653. $oVote->addCssJs();
  654. $bResult = true;
  655. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  656. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  657. return $bResult;
  658. }
  659. public function isAllowedReport($aEvent, $bPerform = false)
  660. {
  661. $mixedReports = $this->getReportsData($aEvent['reports']);
  662. if($mixedReports === false)
  663. return false;
  664. list($sSystem, $iObjectId) = $mixedReports;
  665. $oReport = $this->getReportObject($sSystem, $iObjectId);
  666. $oReport->addCssJs();
  667. $bResult = true;
  668. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  669. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  670. return $bResult;
  671. }
  672. public function isAllowedShare($aEvent, $bPerform = false)
  673. {
  674. if(isAdmin())
  675. return true;
  676. $iUserId = (int)$this->getUserId();
  677. if($iUserId == 0)
  678. return false;
  679. $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
  680. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  681. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_share', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  682. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  683. }
  684. public function isAllowedPin($aEvent, $bPerform = false)
  685. {
  686. if((int)$aEvent['pinned'] != 0)
  687. return false;
  688. return $this->_isAllowedPin($aEvent, $bPerform);
  689. }
  690. public function isAllowedUnpin($aEvent, $bPerform = false)
  691. {
  692. if((int)$aEvent['pinned'] == 0)
  693. return false;
  694. return $this->_isAllowedPin($aEvent, $bPerform);
  695. }
  696. public function isAllowedMore($aEvent, $bPerform = false)
  697. {
  698. $oMoreMenu = $this->getManageMenuObject();
  699. $oMoreMenu->setEventId($aEvent['id']);
  700. return $oMoreMenu->isVisible();
  701. }
  702. public function onPost($iId)
  703. {
  704. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  705. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  706. $sPostType = 'system';
  707. $iSenderId = $aEvent['owner_id'];
  708. } else {
  709. $sPostType = 'common';
  710. $iSenderId = $aEvent['object_id'];
  711. }
  712. //--- Event -> Post for Alerts Engine ---//
  713. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  714. 'object_author_id' => $aEvent['owner_id']
  715. ));
  716. $oAlert->alert();
  717. //--- Event -> Post for Alerts Engine ---//
  718. }
  719. public function onShare($iId, $aShared = array())
  720. {
  721. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  722. if(empty($aShared)) {
  723. $aContent = unserialize($aEvent['content']);
  724. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  725. if(empty($aShared) || !is_array($aShared))
  726. return;
  727. }
  728. $iUserId = $this->getUserId();
  729. $this->_oDb->insertShareTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aShared['id']);
  730. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares']);
  731. //--- Timeline -> Update for Alerts Engine ---//
  732. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'share', $aShared['id'], $iUserId);
  733. $oAlert->alert();
  734. //--- Timeline -> Update for Alerts Engine ---//
  735. }
  736. public function onDelete($aEvent)
  737. {
  738. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  739. //--- Delete attached photos, videos and links when common event was deleted.
  740. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  741. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  742. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  743. $this->_deleteLinks($aEvent['id']);
  744. }
  745. //--- Update parent event when share event was deleted.
  746. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_SHARE) {
  747. $this->_oDb->deleteShareTrack($aEvent['id']);
  748. $aContent = unserialize($aEvent['content']);
  749. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  750. if(!empty($aShared) && is_array($aShared))
  751. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares'], -1);
  752. }
  753. //--- Find and delete share events when parent event was deleted.
  754. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  755. $aShareEvents = $this->_oDb->getEvents(array('browse' => 'shared_by_descriptor', 'type' => $aEvent['type']));
  756. foreach($aShareEvents as $aShareEvent) {
  757. $aContent = unserialize($aShareEvent['content']);
  758. 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'])))
  759. $this->_oDb->deleteEvent(array('id' => (int)$aShareEvent['id']));
  760. }
  761. //--- Delete associated meta.
  762. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  763. $oMetatags->onDeleteContent($aEvent['id']);
  764. //--- Event -> Delete for Alerts Engine ---//
  765. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $this->getUserId());
  766. $oAlert->alert();
  767. //--- Event -> Delete for Alerts Engine ---//
  768. }
  769. public function getVotesData(&$aVotes)
  770. {
  771. if(empty($aVotes) || !is_array($aVotes))
  772. return false;
  773. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  774. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  775. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  776. if($sSystem == '' || $iObjectId == 0)
  777. return false;
  778. return array($sSystem, $iObjectId, $iCount);
  779. }
  780. public function getReportsData(&$aReports)
  781. {
  782. if(empty($aReports) || !is_array($aReports))
  783. return false;
  784. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  785. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  786. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  787. if($sSystem == '' || $iObjectId == 0)
  788. return false;
  789. return array($sSystem, $iObjectId, $iCount);
  790. }
  791. public function getCommentsData(&$aComments)
  792. {
  793. if(empty($aComments) || !is_array($aComments))
  794. return false;
  795. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  796. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  797. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  798. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  799. return false;
  800. return array($sSystem, $iObjectId, $iCount);
  801. }
  802. /**
  803. * Protected Methods
  804. */
  805. protected function _serviceGetBlockView($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT)
  806. {
  807. if(empty($iProfileId) && bx_get('profile_id') !== false)
  808. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  809. if(empty($iProfileId) && isLogged())
  810. $iProfileId = bx_get_logged_profile_id();
  811. $aBlock = $this->_getBlockView($iProfileId, $sView);
  812. if(!empty($aBlock))
  813. return $aBlock;
  814. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  815. }
  816. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  817. {
  818. if(empty($sProfileModule))
  819. return array();
  820. if(empty($iProfileContentId) && bx_get('id') !== false)
  821. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  822. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  823. if(empty($oProfile))
  824. return array();
  825. return $this->_getBlockView($oProfile->id(), $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  826. }
  827. 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())
  828. {
  829. $aParams = $this->_prepareParams($sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  830. $aParams['view'] = $sView;
  831. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : ((int)$iPerPageDefault > 0 ? $iPerPageDefault : $this->_oConfig->getPerPage());
  832. $this->_iOwnerId = $aParams['owner_id'];
  833. $sContent = $this->_oTemplate->getViewBlock($aParams);
  834. return array('content' => $sContent);
  835. }
  836. protected function _getBlockPost($iProfileId)
  837. {
  838. $this->_iOwnerId = $iProfileId;
  839. if($this->isAllowedPost() !== true)
  840. return array();
  841. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  842. return array('content' => $sContent);
  843. }
  844. protected function _getBlockView($iProfileId, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  845. {
  846. if(!$iProfileId)
  847. return array();
  848. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  849. $aParams['view'] = $sView;
  850. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  851. $this->_iOwnerId = $aParams['owner_id'];
  852. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  853. $sJsObject = $this->_oConfig->getJsObject('view');
  854. $aMenu = array(
  855. array('id' => 'timeline-view-all', 'name' => 'timeline-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  856. array('id' => 'timeline-view-owner', 'name' => 'timeline-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  857. array('id' => 'timeline-view-other', 'name' => 'timeline-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  858. array('id' => 'timeline-get-rss', 'name' => 'timeline-get-rss', 'class' => '', 'link' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $iProfileId . '/', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  859. );
  860. $sContent = '';
  861. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  862. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  863. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  864. $oMenu->setSelected('', 'timeline-view-all');
  865. if (!$sContent)
  866. $sContent = $this->_oTemplate->getViewBlock($aParams);
  867. return array('content' => $sContent, 'menu' => $oMenu);
  868. }
  869. protected function _isAllowedPin($aEvent, $bPerform = false)
  870. {
  871. if(isAdmin())
  872. return true;
  873. $iUserId = (int)$this->getUserId();
  874. if($iUserId == 0)
  875. return false;
  876. if((int)$aEvent['owner_id'] == $iUserId)
  877. return true;
  878. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  879. if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
  880. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  881. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  882. }
  883. protected function _deleteLinks($iId)
  884. {
  885. $aLinks = $this->_oDb->getLinks($iId);
  886. if(empty($aLinks) || !is_array($aLinks))
  887. return;
  888. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  889. foreach($aLinks as $aLink)
  890. if(!empty($aLink['media_id']))
  891. $oStorage->deleteFile($aLink['media_id']);
  892. $this->_oDb->deleteLinks($iId);
  893. }
  894. protected function _saveMedia($sType, $iId, $aItemIds)
  895. {
  896. if(empty($aItemIds) || !is_array($aItemIds))
  897. return;
  898. $iUserId = $this->getUserId();
  899. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  900. foreach($aItemIds as $iItemId)
  901. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  902. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  903. }
  904. protected function _deleteMedia($sType, $iId)
  905. {
  906. $aItems = $this->_oDb->getMedia($sType, $iId);
  907. if(empty($aItems) || !is_array($aItems))
  908. return;
  909. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  910. foreach($aItems as $iItemId)
  911. $oStorage->deleteFile($iItemId);
  912. $this->_oDb->deleteMedia($sType, $iId);
  913. }
  914. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  915. {
  916. return array(
  917. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  918. 'browse' => 'list',
  919. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  920. 'owner_id' => (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId(),
  921. 'filter' => !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL,
  922. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : array(),
  923. 'timeline' => (int)$iTimeline > 0 ? $iTimeline : 0,
  924. 'active' => 1,
  925. 'hidden' => 0,
  926. 'start' => (int)$iStart > 0 ? $iStart : 0,
  927. 'per_page' => (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage(),
  928. );
  929. }
  930. protected function _prepareParamsGet()
  931. {
  932. $aParams = array(
  933. 'browse' => 'list',
  934. 'dynamic_mode' => true,
  935. );
  936. $aParams['view'] = bx_get('view');
  937. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  938. $aParams['type'] = bx_get('type');
  939. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  940. $aParams['owner_id'] = bx_get('owner_id');
  941. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  942. $aParams['start'] = bx_get('start');
  943. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  944. $aParams['per_page'] = bx_get('per_page');
  945. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  946. $aParams['filter'] = bx_get('filter');
  947. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  948. $aParams['modules'] = bx_get('modules');
  949. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  950. $aParams['timeline'] = bx_get('timeline');
  951. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  952. $aParams['active'] = 1;
  953. $aParams['hidden'] = 0;
  954. return $aParams;
  955. }
  956. protected function _prepareTextForSave($s)
  957. {
  958. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  959. }
  960. }
  961. /** @} */