1
0

BxTimelineModule.php 51 KB

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