BxBaseServiceMobileApps.php 1.9 KB

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