BxTimelineModule.php 48 KB

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