BxBaseServiceMobileApps.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. foreach ($a as $r)
  31. $iBubbles += $r['bx_if:addon']['condition'] ? $r['bx_if:addon']['content']['addon'] : 0;
  32. $s = BxDolTemplate::getInstance()->parseHtmlByName('mobile_apps_styles.html', array());
  33. $s .= BxDolTemplate::getInstance()->parseHtmlByName('mobile_apps_js.html', array(
  34. 'msg' => json_encode(array(
  35. 'loggedin' => isLogged(),
  36. 'bubbles' => $iBubbles ? $iBubbles : '',
  37. ))
  38. ));
  39. return $s;
  40. }
  41. protected function mobileRedirects()
  42. {
  43. $bLoggedIn = isLogged() ? 1 : 0;
  44. $i = bx_get('i');
  45. // only several pages are available for guest, for other pages user is redirected to login page
  46. $aI = array('forgot-password' => 1, 'create-account' => 1, 'terms' => 1, 'privacy' => 1, 'contact' => 1, 'about' => 1, 'home' => 1);
  47. if (!$bLoggedIn && !preg_match('/searchKeyword.php$/', $_SERVER['PHP_SELF']) && !preg_match('/member.php$/', $_SERVER['PHP_SELF']) && !isset($aI[$i])) {
  48. header("Location: " . BX_DOL_URL_ROOT);
  49. exit;
  50. }
  51. // for logged in members some pages aren't available as well
  52. $aI = array('forgot-password' => 1, 'create-account' => 1, 'login' => 1);
  53. if ($bLoggedIn && isset($aI[$i])) {
  54. header("Location: " . BX_DOL_URL_ROOT);
  55. exit;
  56. }
  57. }
  58. }
  59. /** @} */