1
0

BxTimelineModule.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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['description']) ? strmaxtextlen($aContent['description'], $this->_oConfig->getCharsDisplayMaxSnippet(), '...') : '';
  385. if(!empty($sEntryCaption))
  386. $sEntryCaption = _t('_bx_timeline_ntfs_txt_object_caption', $sEntryCaption);
  387. return array(
  388. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  389. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  390. 'entry_caption' => $sEntryCaption,
  391. 'entry_author' => $aContent['owner_id'],
  392. '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.
  393. );
  394. }
  395. public function serviceGetNotificationsComment($aEvent)
  396. {
  397. $CNF = &$this->_oConfig->CNF;
  398. $iContent = (int)$aEvent['object_id'];
  399. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  400. if(empty($aContent) || !is_array($aContent))
  401. return array();
  402. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  403. if(!$oComment || !$oComment->isEnabled())
  404. return array();
  405. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  406. return array(
  407. 'entry_sample' => $CNF['T']['txt_sample_single'],
  408. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  409. 'entry_caption' => $sEntryCaption,
  410. 'entry_author' => $aContent['owner_id'],
  411. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  412. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  413. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  414. );
  415. }
  416. public function serviceGetNotificationsVote($aEvent)
  417. {
  418. $CNF = &$this->_oConfig->CNF;
  419. $iContent = (int)$aEvent['object_id'];
  420. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  421. if(empty($aContent) || !is_array($aContent))
  422. return array();
  423. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  424. if(!$oVote || !$oVote->isEnabled())
  425. return array();
  426. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  427. return array(
  428. 'entry_sample' => $CNF['T']['txt_sample_single'],
  429. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  430. 'entry_caption' => $sEntryCaption,
  431. 'entry_author' => $aContent['owner_id'],
  432. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  433. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  434. );
  435. }
  436. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  437. {
  438. if(!$this->isEnabled())
  439. return '';
  440. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  441. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  442. }
  443. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  444. {
  445. if(!$this->isEnabled())
  446. return '';
  447. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  448. return $this->_oTemplate->getRepostCounter($aReposted);
  449. }
  450. public function serviceGetRepostJsScript()
  451. {
  452. if(!$this->isEnabled())
  453. return '';
  454. return $this->_oTemplate->getRepostJsScript();
  455. }
  456. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  457. {
  458. if(!$this->isEnabled())
  459. return '';
  460. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  461. }
  462. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  463. {
  464. if(empty($sSystem) || empty($iObjectId))
  465. return '';
  466. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  467. if($oCmts === false)
  468. return '';
  469. $iCounter = (int)$oCmts->getCommentsCount();
  470. return $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  471. 'href' => 'javascript:void(0)',
  472. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  473. 'bx_repeat:attrs' => array(
  474. array('key' => 'onclick', 'value' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")")
  475. ),
  476. 'content' => $iCounter > 0 ? $iCounter : ''
  477. ));
  478. }
  479. public function serviceGetSettingsCheckerHelper()
  480. {
  481. bx_import('FormCheckerHelper', $this->_aModule);
  482. return 'BxTimelineFormCheckerHelper';
  483. }
  484. /*
  485. * COMMON METHODS
  486. */
  487. public function deleteEvent($aEvent)
  488. {
  489. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  490. return false;
  491. $this->onDelete($aEvent);
  492. return true;
  493. }
  494. public function getFormAttachLink()
  495. {
  496. $iUserId = $this->getUserId();
  497. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  498. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  499. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  500. $oForm->initChecker();
  501. if($oForm->isSubmittedAndValid()) {
  502. $sLink = $oForm->getCleanValue('url');
  503. $aMatches = array();
  504. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  505. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  506. $aSiteInfo = bx_get_site_info($sLink, array(
  507. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  508. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  509. ));
  510. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  511. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  512. $sMediaUrl = '';
  513. if(!empty($aSiteInfo['thumbnailUrl']))
  514. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  515. else if(!empty($aSiteInfo['OGImage']))
  516. $sMediaUrl = $aSiteInfo['OGImage'];
  517. $iMediaId = 0;
  518. $oStorage = null;
  519. if(!empty($sMediaUrl)) {
  520. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  521. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  522. }
  523. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  524. if(!empty($iId)) {
  525. if(!empty($oStorage) && !empty($iMediaId))
  526. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  527. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  528. }
  529. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  530. }
  531. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  532. }
  533. public function getFormPost()
  534. {
  535. $iUserId = $this->getUserId();
  536. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_add'), $this->_oTemplate);
  537. $oForm->initChecker();
  538. if($oForm->isSubmittedAndValid()) {
  539. list($sUserName) = $this->getUserInfo($iUserId);
  540. $sType = $oForm->getCleanValue('type');
  541. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  542. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  543. $aContent = array();
  544. //--- Process Text ---//
  545. $sText = $oForm->getCleanValue('text');
  546. $sText = $this->_prepareTextForSave($sText);
  547. $bText = !empty($sText);
  548. unset($oForm->aInputs['text']);
  549. if($bText)
  550. $aContent['text'] = $sText;
  551. //--- Process Link ---//
  552. $aLinkIds = $oForm->getCleanValue('link');
  553. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  554. //--- Process Media ---//
  555. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  556. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  557. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  558. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  559. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  560. return array('msg' => _t('_bx_timeline_txt_err_empty_post'));
  561. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample_with_article'));
  562. $sDescription = $bText ? $sText : '';
  563. $iId = $oForm->insert(array(
  564. 'object_id' => $iUserId,
  565. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  566. 'content' => serialize($aContent),
  567. 'title' => $sTitle,
  568. 'description' => $sDescription,
  569. 'date' => time()
  570. ));
  571. if(!empty($iId)) {
  572. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  573. if($bText)
  574. $oMetatags->keywordsAdd($iId, $sText);
  575. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  576. //--- Process Link ---//
  577. if($bLinkIds)
  578. foreach($aLinkIds as $iLinkId)
  579. $this->_oDb->saveLink($iId, $iLinkId);
  580. //--- Process Media ---//
  581. if($bPhotoIds)
  582. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  583. if($bVideoIds)
  584. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  585. $this->onPost($iId);
  586. return array('id' => $iId);
  587. }
  588. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  589. }
  590. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  591. }
  592. public function getCmtsObject($sSystem, $iId)
  593. {
  594. if(empty($sSystem) || (int)$iId == 0)
  595. return false;
  596. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  597. if(!$oCmts || !$oCmts->isEnabled())
  598. return false;
  599. return $oCmts;
  600. }
  601. public function getViewObject($sSystem, $iId)
  602. {
  603. if(empty($sSystem) || (int)$iId == 0)
  604. return false;
  605. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  606. if(!$oView || !$oView->isEnabled())
  607. return false;
  608. return $oView;
  609. }
  610. public function getVoteObject($sSystem, $iId)
  611. {
  612. if(empty($sSystem) || (int)$iId == 0)
  613. return false;
  614. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  615. if(!$oVote || !$oVote->isEnabled())
  616. return false;
  617. return $oVote;
  618. }
  619. public function getReportObject($sSystem, $iId)
  620. {
  621. if(empty($sSystem) || (int)$iId == 0)
  622. return false;
  623. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  624. if(!$oReport || !$oReport->isEnabled())
  625. return false;
  626. return $oReport;
  627. }
  628. public function getAttachmentsMenuObject()
  629. {
  630. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  631. $oMenu->addMarkers(array(
  632. 'js_object' => $this->_oConfig->getJsObject('post'),
  633. ));
  634. return $oMenu;
  635. }
  636. public function getManageMenuObject()
  637. {
  638. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  639. }
  640. //--- Check permissions methods ---//
  641. public function isAllowedPost($bPerform = false)
  642. {
  643. if(isAdmin())
  644. return true;
  645. $iUserId = $this->getUserId();
  646. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  647. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  648. if($oProfileOwner !== false)
  649. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  650. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  651. }
  652. public function isAllowedDelete($aEvent, $bPerform = false)
  653. {
  654. if(!isLogged())
  655. return false;
  656. if(isAdmin())
  657. return true;
  658. $iUserId = (int)$this->getUserId();
  659. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  660. return true;
  661. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  662. $oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']);
  663. if($oProfileOwner !== false)
  664. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  665. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  666. }
  667. public function isAllowedComment($aEvent, $bPerform = false)
  668. {
  669. $mixedComments = $this->getCommentsData($aEvent['comments']);
  670. if($mixedComments === false)
  671. return false;
  672. list($sSystem, $iObjectId) = $mixedComments;
  673. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  674. $oCmts->addCssJs();
  675. $bResult = true;
  676. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  677. if($oProfileOwner !== false)
  678. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  679. return $bResult;
  680. }
  681. public function isAllowedViewCounter($aEvent, $bPerform = false)
  682. {
  683. $mixedViews = $this->getViewsData($aEvent['views']);
  684. if($mixedViews === false)
  685. return false;
  686. list($sSystem, $iObjectId) = $mixedViews;
  687. $oView = $this->getViewObject($sSystem, $iObjectId);
  688. $bResult = true;
  689. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  690. if($oProfileOwner !== false)
  691. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  692. return $bResult;
  693. }
  694. public function isAllowedVote($aEvent, $bPerform = false)
  695. {
  696. $mixedVotes = $this->getVotesData($aEvent['votes']);
  697. if($mixedVotes === false)
  698. return false;
  699. list($sSystem, $iObjectId) = $mixedVotes;
  700. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  701. $oVote->addCssJs();
  702. $bResult = true;
  703. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  704. if($oProfileOwner !== false)
  705. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  706. return $bResult;
  707. }
  708. public function isAllowedReport($aEvent, $bPerform = false)
  709. {
  710. $mixedReports = $this->getReportsData($aEvent['reports']);
  711. if($mixedReports === false)
  712. return false;
  713. list($sSystem, $iObjectId) = $mixedReports;
  714. $oReport = $this->getReportObject($sSystem, $iObjectId);
  715. $oReport->addCssJs();
  716. $bResult = true;
  717. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  718. if($oProfileOwner !== false)
  719. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  720. return $bResult;
  721. }
  722. public function isAllowedRepost($aEvent, $bPerform = false)
  723. {
  724. if(isAdmin())
  725. return true;
  726. $iUserId = (int)$this->getUserId();
  727. if($iUserId == 0)
  728. return false;
  729. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  730. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  731. if($oProfileOwner !== false)
  732. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  733. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  734. }
  735. public function isAllowedSend($aEvent, $bPerform = false)
  736. {
  737. if(isAdmin())
  738. return true;
  739. $iUserId = (int)$this->getUserId();
  740. if($iUserId == 0)
  741. return false;
  742. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  743. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  744. if($oProfileOwner !== false)
  745. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  746. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  747. }
  748. public function isAllowedPin($aEvent, $bPerform = false)
  749. {
  750. if((int)$aEvent['pinned'] != 0)
  751. return false;
  752. return $this->_isAllowedPin($aEvent, $bPerform);
  753. }
  754. public function isAllowedUnpin($aEvent, $bPerform = false)
  755. {
  756. if((int)$aEvent['pinned'] == 0)
  757. return false;
  758. return $this->_isAllowedPin($aEvent, $bPerform);
  759. }
  760. public function isAllowedMore($aEvent, $bPerform = false)
  761. {
  762. $oMoreMenu = $this->getManageMenuObject();
  763. $oMoreMenu->setEventId($aEvent['id']);
  764. return $oMoreMenu->isVisible();
  765. }
  766. public function onPost($iId)
  767. {
  768. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  769. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  770. $sPostType = 'system';
  771. $iSenderId = $aEvent['owner_id'];
  772. } else {
  773. $sPostType = 'common';
  774. $iSenderId = $aEvent['object_id'];
  775. }
  776. //--- Event -> Post for Alerts Engine ---//
  777. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  778. 'object_author_id' => $aEvent['owner_id']
  779. ));
  780. $oAlert->alert();
  781. //--- Event -> Post for Alerts Engine ---//
  782. }
  783. public function onRepost($iId, $aReposted = array())
  784. {
  785. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  786. if(empty($aReposted)) {
  787. $aContent = unserialize($aEvent['content']);
  788. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  789. if(empty($aReposted) || !is_array($aReposted))
  790. return;
  791. }
  792. $iUserId = $this->getUserId();
  793. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  794. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  795. //--- Timeline -> Update for Alerts Engine ---//
  796. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  797. 'repost_id' => $iId,
  798. 'object_author_id' => $aReposted['owner_id'],
  799. ));
  800. $oAlert->alert();
  801. //--- Timeline -> Update for Alerts Engine ---//
  802. }
  803. public function onDelete($aEvent)
  804. {
  805. $iUserId = $this->getUserId();
  806. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  807. //--- Delete attached photos, videos and links when common event was deleted.
  808. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  809. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  810. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  811. $this->_deleteLinks($aEvent['id']);
  812. }
  813. //--- Update parent event when repost event was deleted.
  814. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  815. if($bRepost) {
  816. $this->_oDb->deleteRepostTrack($aEvent['id']);
  817. $aContent = unserialize($aEvent['content']);
  818. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  819. if(!empty($aReposted) && is_array($aReposted))
  820. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  821. }
  822. //--- Find and delete repost events when parent event was deleted.
  823. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  824. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  825. foreach($aRepostEvents as $aRepostEvent) {
  826. $aContent = unserialize($aRepostEvent['content']);
  827. 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) {
  828. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  829. 'repost_id' => $aRepostEvent['id'],
  830. ));
  831. $oAlert->alert();
  832. }
  833. }
  834. //--- Delete associated meta.
  835. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  836. $oMetatags->onDeleteContent($aEvent['id']);
  837. //--- Event -> Delete for Alerts Engine ---//
  838. if($bRepost)
  839. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  840. 'repost_id' => $aEvent['id'],
  841. ));
  842. else
  843. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  844. $oAlert->alert();
  845. //--- Event -> Delete for Alerts Engine ---//
  846. }
  847. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = '', $aModules = array(), $iTimeline = 0)
  848. {
  849. return $this->_prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  850. }
  851. public function getViewsData(&$aViews)
  852. {
  853. if(empty($aViews) || !is_array($aViews))
  854. return false;
  855. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  856. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  857. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  858. if($sSystem == '' || $iObjectId == 0)
  859. return false;
  860. return array($sSystem, $iObjectId, $iCount);
  861. }
  862. public function getVotesData(&$aVotes)
  863. {
  864. if(empty($aVotes) || !is_array($aVotes))
  865. return false;
  866. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  867. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  868. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  869. if($sSystem == '' || $iObjectId == 0)
  870. return false;
  871. return array($sSystem, $iObjectId, $iCount);
  872. }
  873. public function getReportsData(&$aReports)
  874. {
  875. if(empty($aReports) || !is_array($aReports))
  876. return false;
  877. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  878. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  879. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  880. if($sSystem == '' || $iObjectId == 0)
  881. return false;
  882. return array($sSystem, $iObjectId, $iCount);
  883. }
  884. public function getCommentsData(&$aComments)
  885. {
  886. if(empty($aComments) || !is_array($aComments))
  887. return false;
  888. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  889. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  890. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  891. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  892. return false;
  893. return array($sSystem, $iObjectId, $iCount);
  894. }
  895. /**
  896. * Protected Methods
  897. */
  898. protected function _serviceGetBlockView($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT)
  899. {
  900. if(empty($iProfileId) && bx_get('profile_id') !== false)
  901. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  902. if(empty($iProfileId) && isLogged())
  903. $iProfileId = bx_get_logged_profile_id();
  904. $aBlock = $this->_getBlockView($iProfileId, $sView);
  905. if(!empty($aBlock))
  906. return $aBlock;
  907. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  908. }
  909. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  910. {
  911. if(empty($sProfileModule))
  912. return array();
  913. if(empty($iProfileContentId) && bx_get('id') !== false)
  914. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  915. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  916. if(empty($oProfile))
  917. return array();
  918. return $this->_getBlockView($oProfile->id(), $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  919. }
  920. protected function _serviceGetBlockViewHome($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  921. {
  922. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_PUBLIC . '/';
  923. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  924. return $this->_serviceGetBlockViewByType($iProfileId, $sView, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  925. }
  926. 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())
  927. {
  928. $aParams = $this->_prepareParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  929. $aParams['view'] = $sView;
  930. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : ((int)$iPerPageDefault > 0 ? $iPerPageDefault : $this->_oConfig->getPerPage());
  931. $this->_iOwnerId = $aParams['owner_id'];
  932. $sContent = $this->_oTemplate->getViewBlock($aParams);
  933. return array('content' => $sContent);
  934. }
  935. protected function _getBlockPost($iProfileId)
  936. {
  937. $this->_iOwnerId = $iProfileId;
  938. if($this->isAllowedPost() !== true)
  939. return array();
  940. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  941. return array('content' => $sContent);
  942. }
  943. protected function _getBlockView($iProfileId, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  944. {
  945. if(!$iProfileId)
  946. return array();
  947. $aParams = $this->_prepareParams($sView, BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  948. $aParams['view'] = $sView;
  949. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  950. $this->_iOwnerId = $aParams['owner_id'];
  951. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  952. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $iProfileId . '/';
  953. $sJsObject = $this->_oConfig->getJsObject('view');
  954. $aMenu = array(
  955. 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),
  956. 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)),
  957. 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')),
  958. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  959. );
  960. $sContent = '';
  961. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  962. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  963. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  964. $oMenu->setSelected('', $sView . '-view-all');
  965. if (!$sContent)
  966. $sContent = $this->_oTemplate->getViewBlock($aParams);
  967. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  968. return array('content' => $sContent, 'menu' => $oMenu);
  969. }
  970. protected function _isAllowedPin($aEvent, $bPerform = false)
  971. {
  972. if(isAdmin())
  973. return true;
  974. $iUserId = (int)$this->getUserId();
  975. if($iUserId == 0)
  976. return false;
  977. if((int)$aEvent['owner_id'] == $iUserId)
  978. return true;
  979. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  980. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  981. if($oProfileOwner !== false)
  982. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  983. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  984. }
  985. protected function _deleteLinks($iId)
  986. {
  987. $aLinks = $this->_oDb->getLinks($iId);
  988. if(empty($aLinks) || !is_array($aLinks))
  989. return;
  990. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  991. foreach($aLinks as $aLink)
  992. if(!empty($aLink['media_id']))
  993. $oStorage->deleteFile($aLink['media_id']);
  994. $this->_oDb->deleteLinks($iId);
  995. }
  996. protected function _saveMedia($sType, $iId, $aItemIds)
  997. {
  998. if(empty($aItemIds) || !is_array($aItemIds))
  999. return;
  1000. $iUserId = $this->getUserId();
  1001. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1002. foreach($aItemIds as $iItemId)
  1003. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  1004. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  1005. }
  1006. protected function _deleteMedia($sType, $iId)
  1007. {
  1008. $aItems = $this->_oDb->getMedia($sType, $iId);
  1009. if(empty($aItems) || !is_array($aItems))
  1010. return;
  1011. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1012. foreach($aItems as $iItemId)
  1013. $oStorage->deleteFile($iItemId);
  1014. $this->_oDb->deleteMedia($sType, $iId);
  1015. }
  1016. protected function _prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  1017. {
  1018. return array(
  1019. 'view' => !empty($sView) ? $sView : BX_TIMELINE_VIEW_DEFAULT,
  1020. 'browse' => 'list',
  1021. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  1022. 'owner_id' => (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId(),
  1023. 'filter' => !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL,
  1024. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : array(),
  1025. 'timeline' => (int)$iTimeline > 0 ? $iTimeline : 0,
  1026. 'active' => 1,
  1027. 'hidden' => 0,
  1028. 'start' => (int)$iStart > 0 ? $iStart : 0,
  1029. 'per_page' => (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage(),
  1030. );
  1031. }
  1032. protected function _prepareParamsGet()
  1033. {
  1034. $aParams = array(
  1035. 'browse' => 'list',
  1036. 'dynamic_mode' => true,
  1037. );
  1038. $aParams['view'] = bx_get('view');
  1039. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  1040. $aParams['type'] = bx_get('type');
  1041. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  1042. $aParams['owner_id'] = bx_get('owner_id');
  1043. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  1044. $aParams['start'] = bx_get('start');
  1045. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  1046. $aParams['per_page'] = bx_get('per_page');
  1047. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  1048. $aParams['filter'] = bx_get('filter');
  1049. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  1050. $aParams['modules'] = bx_get('modules');
  1051. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  1052. $aParams['timeline'] = bx_get('timeline');
  1053. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  1054. $aParams['active'] = 1;
  1055. $aParams['hidden'] = 0;
  1056. return $aParams;
  1057. }
  1058. protected function _prepareTextForSave($s)
  1059. {
  1060. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  1061. }
  1062. }
  1063. /** @} */