1
0

BxTimelineModule.php 50 KB

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