BxMobileAppsModule.php 2.8 KB

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