BxTimelineModule.php 56 KB

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