BxTimelineModule.php 56 KB

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