Bootstrap.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. require_once CONFIG_PATH . "conf.php";
  3. $CC_CONFIG = Config::getConfig();
  4. require_once CONFIG_PATH . "ACL.php";
  5. require_once 'propel/runtime/lib/Propel.php';
  6. // Since we initialize the database during the configuration check,
  7. // check the $configRun global to avoid reinitializing unnecessarily
  8. if (!isset($configRun) || !$configRun) {
  9. Propel::init(CONFIG_PATH . 'airtime-conf-production.php');
  10. }
  11. require_once CONFIG_PATH . "constants.php";
  12. require_once 'Preference.php';
  13. require_once 'Locale.php';
  14. require_once "DateHelper.php";
  15. require_once "HTTPHelper.php";
  16. require_once "OsPath.php";
  17. require_once "Database.php";
  18. require_once "Timezone.php";
  19. require_once "Auth.php";
  20. require_once __DIR__.'/forms/helpers/ValidationTypes.php';
  21. require_once __DIR__.'/forms/helpers/CustomDecorators.php';
  22. require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
  23. require_once __DIR__.'/upgrade/Upgrades.php';
  24. require_once (APPLICATION_PATH . "/logging/Logging.php");
  25. Logging::setLogPath('/var/log/airtime/zendphp.log');
  26. Config::setAirtimeVersion();
  27. require_once (CONFIG_PATH . 'navigation.php');
  28. Zend_Validate::setDefaultNamespaces("Zend");
  29. Application_Model_Auth::pinSessionToClient(Zend_Auth::getInstance());
  30. $front = Zend_Controller_Front::getInstance();
  31. $front->registerPlugin(new RabbitMqPlugin());
  32. //localization configuration
  33. Application_Model_Locale::configureLocalization();
  34. /* The bootstrap class should only be used to initialize actions that return a view.
  35. Actions that return JSON will not use the bootstrap class! */
  36. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
  37. {
  38. protected function _initDoctype()
  39. {
  40. $this->bootstrap('view');
  41. $view = $this->getResource('view');
  42. $view->doctype('XHTML1_STRICT');
  43. }
  44. protected function _initGlobals()
  45. {
  46. $view = $this->getResource('view');
  47. $baseUrl = Application_Common_OsPath::getBaseDir();
  48. $view->headScript()->appendScript("var baseUrl = '$baseUrl';");
  49. $this->_initTranslationGlobals($view);
  50. $user = Application_Model_User::GetCurrentUser();
  51. if (!is_null($user)){
  52. $userType = $user->getType();
  53. } else {
  54. $userType = "";
  55. }
  56. $view->headScript()->appendScript("var userType = '$userType';");
  57. }
  58. /**
  59. * Ideally, globals should be written to a single js file once
  60. * from a php init function. This will save us from having to
  61. * reinitialize them every request
  62. */
  63. private function _initTranslationGlobals($view) {
  64. $view->headScript()->appendScript("var PRODUCT_NAME = '" . PRODUCT_NAME . "';");
  65. $view->headScript()->appendScript("var USER_MANUAL_URL = '" . USER_MANUAL_URL . "';");
  66. $view->headScript()->appendScript("var COMPANY_NAME = '" . COMPANY_NAME . "';");
  67. }
  68. protected function _initUpgrade() {
  69. /* We need to wrap this here so that we aren't checking when we're running the unit test suite
  70. */
  71. if (getenv("AIRTIME_UNIT_TEST") != 1) {
  72. UpgradeManager::checkIfUpgradeIsNeeded(); //This will do the upgrade too if it's needed...
  73. }
  74. }
  75. protected function _initHeadLink()
  76. {
  77. $CC_CONFIG = Config::getConfig();
  78. $view = $this->getResource('view');
  79. $baseUrl = Application_Common_OsPath::getBaseDir();
  80. $view->headLink()->appendStylesheet($baseUrl.'css/bootstrap.css?'.$CC_CONFIG['airtime_version']);
  81. $view->headLink()->appendStylesheet($baseUrl.'css/redmond/jquery-ui-1.8.8.custom.css?'.$CC_CONFIG['airtime_version']);
  82. $view->headLink()->appendStylesheet($baseUrl.'css/pro_dropdown_3.css?'.$CC_CONFIG['airtime_version']);
  83. $view->headLink()->appendStylesheet($baseUrl.'css/qtip/jquery.qtip.min.css?'.$CC_CONFIG['airtime_version']);
  84. $view->headLink()->appendStylesheet($baseUrl.'css/styles.css?'.$CC_CONFIG['airtime_version']);
  85. $view->headLink()->appendStylesheet($baseUrl.'css/masterpanel.css?'.$CC_CONFIG['airtime_version']);
  86. $view->headLink()->appendStylesheet($baseUrl.'css/tipsy/jquery.tipsy.css?'.$CC_CONFIG['airtime_version']);
  87. }
  88. protected function _initHeadScript()
  89. {
  90. $CC_CONFIG = Config::getConfig();
  91. $view = $this->getResource('view');
  92. $baseUrl = Application_Common_OsPath::getBaseDir();
  93. $view->headScript()->appendFile($baseUrl.'js/libs/jquery-1.8.3.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  94. $view->headScript()->appendFile($baseUrl.'js/libs/jquery-ui-1.8.24.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  95. $view->headScript()->appendFile($baseUrl.'js/bootstrap/bootstrap.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  96. $view->headScript()->appendFile($baseUrl.'js/libs/underscore-min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  97. // $view->headScript()->appendFile($baseUrl.'js/libs/jquery.stickyPanel.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  98. $view->headScript()->appendFile($baseUrl.'js/qtip/jquery.qtip.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  99. $view->headScript()->appendFile($baseUrl.'js/jplayer/jquery.jplayer.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  100. $view->headScript()->appendFile($baseUrl.'js/sprintf/sprintf-0.7-beta1.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  101. $view->headScript()->appendFile($baseUrl.'js/cookie/jquery.cookie.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  102. $view->headScript()->appendFile($baseUrl.'js/i18n/jquery.i18n.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  103. $view->headScript()->appendFile($baseUrl.'locale/general-translation-table?'.$CC_CONFIG['airtime_version'],'text/javascript');
  104. $view->headScript()->appendFile($baseUrl.'locale/datatables-translation-table?'.$CC_CONFIG['airtime_version'],'text/javascript');
  105. $view->headScript()->appendScript("$.i18n.setDictionary(general_dict)");
  106. $view->headScript()->appendScript("var baseUrl='$baseUrl'");
  107. //These timezones are needed to adjust javascript Date objects on the client to make sense to the user's set timezone
  108. //or the server's set timezone.
  109. $serverTimeZone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
  110. $now = new DateTime("now", $serverTimeZone);
  111. $offset = $now->format("Z") * -1;
  112. $view->headScript()->appendScript("var serverTimezoneOffset = {$offset}; //in seconds");
  113. if (class_exists("Zend_Auth", false) && Zend_Auth::getInstance()->hasIdentity()) {
  114. $userTimeZone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
  115. $now = new DateTime("now", $userTimeZone);
  116. $offset = $now->format("Z") * -1;
  117. $view->headScript()->appendScript("var userTimezoneOffset = {$offset}; //in seconds");
  118. }
  119. //scripts for now playing bar
  120. $view->headScript()->appendFile($baseUrl.'js/airtime/airtime_bootstrap.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  121. $view->headScript()->appendFile($baseUrl.'js/airtime/dashboard/helperfunctions.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  122. $view->headScript()->appendFile($baseUrl.'js/airtime/dashboard/dashboard.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  123. $view->headScript()->appendFile($baseUrl.'js/airtime/dashboard/versiontooltip.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  124. $view->headScript()->appendFile($baseUrl.'js/tipsy/jquery.tipsy.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  125. $view->headScript()->appendFile($baseUrl.'js/airtime/common/common.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  126. $view->headScript()->appendFile($baseUrl.'js/airtime/common/audioplaytest.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  127. $user = Application_Model_User::getCurrentUser();
  128. if (!is_null($user)){
  129. $userType = $user->getType();
  130. } else {
  131. $userType = "";
  132. }
  133. $view->headScript()->appendScript("var userType = '$userType';");
  134. if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1) {
  135. $view->headScript()->appendFile($baseUrl.'js/libs/google-analytics.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  136. }
  137. if (Application_Model_Preference::GetPlanLevel() != "disabled"
  138. && !($_SERVER['REQUEST_URI'] == $baseUrl.'Dashboard/stream-player' ||
  139. strncmp($_SERVER['REQUEST_URI'], $baseUrl.'audiopreview/audio-preview', strlen($baseUrl.'audiopreview/audio-preview'))==0)) {
  140. $client_id = Application_Model_Preference::GetClientId();
  141. $view->headScript()->appendScript("var livechat_client_id = '$client_id';");
  142. $view->headScript()->appendFile($baseUrl . 'js/airtime/common/livechat.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  143. }
  144. }
  145. protected function _initViewHelpers()
  146. {
  147. $view = $this->getResource('view');
  148. $view->addHelperPath(APPLICATION_PATH . 'views/helpers', 'Airtime_View_Helper');
  149. }
  150. protected function _initTitle()
  151. {
  152. $view = $this->getResource('view');
  153. $view->headTitle(Application_Model_Preference::GetHeadTitle());
  154. }
  155. protected function _initZFDebug()
  156. {
  157. Zend_Controller_Front::getInstance()->throwExceptions(false);
  158. /*
  159. if (APPLICATION_ENV == "development") {
  160. $autoloader = Zend_Loader_Autoloader::getInstance();
  161. $autoloader->registerNamespace('ZFDebug');
  162. $options = array(
  163. 'plugins' => array('Variables',
  164. 'Exception',
  165. 'Memory',
  166. 'Time')
  167. );
  168. $debug = new ZFDebug_Controller_Plugin_Debug($options);
  169. $this->bootstrap('frontController');
  170. $frontController = $this->getResource('frontController');
  171. $frontController->registerPlugin($debug);
  172. }
  173. */
  174. }
  175. protected function _initRouter()
  176. {
  177. $front = Zend_Controller_Front::getInstance();
  178. $router = $front->getRouter();
  179. $front->setBaseUrl(Application_Common_OsPath::getBaseDir());
  180. $router->addRoute(
  181. 'password-change',
  182. new Zend_Controller_Router_Route('password-change/:user_id/:token', array(
  183. 'module' => 'default',
  184. 'controller' => 'login',
  185. 'action' => 'password-change',
  186. )));
  187. }
  188. }