1
0

BxTimelineModule.php 52 KB

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