BxBaseServiceMobileApps.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services for mobile apps.
  11. */
  12. class BxBaseServiceMobileApps extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. /**
  19. * Get injection code required for mobile apps
  20. * @return string with Styles and JS code
  21. */
  22. public function serviceInjection()
  23. {
  24. if (false === strpos($_SERVER['HTTP_USER_AGENT'], 'UNAMobileApp'))
  25. return '';
  26. $this->mobileRedirects();
  27. $oMenu = BxDolMenu::getObjectInstance('sys_account_notifications'); // sys_toolbar_member
  28. $a = $oMenu->getMenuItems();
  29. $iBubbles = 0;
  30. $aBubbles = array();
  31. foreach ($a as $r) {
  32. if (!$r['bx_if:addon']['condition'])
  33. continue;
  34. $aBubbles[$r['name']] = $r['bx_if:addon']['content']['addon'];
  35. $iBubbles += $r['bx_if:addon']['content']['addon'];
  36. }
  37. $s = BxDolTemplate::getInstance()->parseHtmlByName('mobile_apps_styles.html', array());
  38. $s .= BxDolTemplate::getInstance()->parseHtmlByName('mobile_apps_js.html', array(
  39. 'msg' => json_encode(array(
  40. 'loggedin' => isLogged(),
  41. 'bubbles_num' => $iBubbles ? $iBubbles : '',
  42. 'bubbles' => $aBubbles,
  43. 'push_tags' => array('user' => bx_get_logged_profile_id())
  44. ))
  45. ));
  46. return $s;
  47. }
  48. protected function mobileRedirects()
  49. {
  50. $bLoggedIn = isLogged() ? 1 : 0;
  51. $i = bx_get('i');
  52. // only several pages are available for guest, for other pages user is redirected to login page
  53. $aI = array('forgot-password' => 1, 'create-account' => 1, 'terms' => 1, 'privacy' => 1, 'contact' => 1, 'about' => 1, 'home' => 1);
  54. if (!$bLoggedIn && !preg_match('/searchKeyword.php$/', $_SERVER['PHP_SELF']) && !preg_match('/member.php$/', $_SERVER['PHP_SELF']) && !isset($aI[$i])) {
  55. header("Location: " . BX_DOL_URL_ROOT);
  56. exit;
  57. }
  58. // for logged in members some pages aren't available as well
  59. $aI = array('forgot-password' => 1, 'create-account' => 1, 'login' => 1);
  60. if ($bLoggedIn && isset($aI[$i])) {
  61. header("Location: " . BX_DOL_URL_ROOT);
  62. exit;
  63. }
  64. }
  65. }
  66. /** @} */