PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/zabbix-2.0.1/frontends/php/jsLoader.php

#
PHP | 234 lines | 196 code | 11 blank | 27 comment | 10 complexity | 6ed7913bc31e3745d465dd6784ba148e MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. <?php
  2. /*
  3. ** Zabbix
  4. ** Copyright (C) 2000-2012 Zabbix SIA
  5. **
  6. ** This program is free software; you can redistribute it and/or modify
  7. ** it under the terms of the GNU General Public License as published by
  8. ** the Free Software Foundation; either version 2 of the License, or
  9. ** (at your option) any later version.
  10. **
  11. ** This program is distributed in the hope that it will be useful,
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ** GNU General Public License for more details.
  15. **
  16. ** You should have received a copy of the GNU General Public License
  17. ** along with this program; if not, write to the Free Software
  18. ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. **/
  20. // get language translations
  21. require_once dirname(__FILE__).'/include/gettextwrapper.inc.php';
  22. require_once dirname(__FILE__).'/include/js.inc.php';
  23. require_once dirname(__FILE__).'/include/locales.inc.php';
  24. // if we must provide language constants on language different from English
  25. if (isset($_GET['lang'])) {
  26. if (function_exists('bindtextdomain')) {
  27. // initializing gettext translations depending on language selected by user
  28. $locales = zbx_locale_variants($_GET['lang']);
  29. foreach ($locales as $locale) {
  30. putenv('LC_ALL='.$locale);
  31. putenv('LANG='.$locale);
  32. putenv('LANGUAGE='.$locale);
  33. if (setlocale(LC_ALL, $locale)) {
  34. break;
  35. }
  36. }
  37. bindtextdomain('frontend', 'locale');
  38. bind_textdomain_codeset('frontend', 'UTF-8');
  39. textdomain('frontend');
  40. }
  41. // numeric Locale to default
  42. setlocale(LC_NUMERIC, array('C', 'POSIX', 'en', 'en_US', 'en_US.UTF-8', 'English_United States.1252', 'en_GB', 'en_GB.UTF-8'));
  43. }
  44. // available scripts 'scriptFileName' => 'path relative to js/'
  45. $availableJScripts = array(
  46. 'common.js' => '',
  47. 'menu.js' => '',
  48. 'prototype.js' => '',
  49. 'jquery.js' => 'jquery/',
  50. 'jquery-ui.js' => 'jquery/',
  51. 'gtlc.js' => '',
  52. 'functions.js' => '',
  53. 'main.js' => '',
  54. 'dom.js' => '',
  55. // classes
  56. 'class.bbcode.js' => '',
  57. 'class.calendar.js' => '',
  58. 'class.cdate.js' => '',
  59. 'class.cdebug.js' => '',
  60. 'class.cmap.js' => '',
  61. 'class.cmessages.js' => '',
  62. 'class.cookie.js' => '',
  63. 'class.cscreen.js' => '',
  64. 'class.csuggest.js' => '',
  65. 'class.cswitcher.js' => '',
  66. 'class.ctree.js' => '',
  67. 'class.curl.js' => '',
  68. 'class.rpc.js' => '',
  69. 'class.pmaster.js' => '',
  70. 'class.cviewswitcher.js' => '',
  71. 'init.js' => '',
  72. // templates
  73. 'sysmap.tpl.js' => 'templates/',
  74. 'servercheck.js' => ''
  75. );
  76. $tranStrings = array(
  77. 'gtlc.js' => array(
  78. 'S_ALL_S' => _('All'),
  79. 'S_ZOOM' => _('Zoom'),
  80. 'S_FIXED_SMALL' => _('fixed'),
  81. 'S_DYNAMIC_SMALL' => _('dynamic'),
  82. 'S_NOW_SMALL' => _('now'),
  83. 'S_YEAR_SHORT' => _x('y', 'year short'),
  84. 'S_MONTH_SHORT' => _x('m', 'month short'),
  85. 'S_WEEK_SHORT' => _x('w', 'week short'),
  86. 'S_DAY_SHORT' => _x('d', 'day short'),
  87. 'S_HOUR_SHORT' => _x('h', 'hour short'),
  88. 'S_MINUTE_SHORT' => _x('m', 'minute short'),
  89. ),
  90. 'functions.js' => array(
  91. 'DO_YOU_REPLACE_CONDITIONAL_EXPRESSION_Q' => _('Do you wish to replace the conditional expression?'),
  92. 'S_INSERT_MACRO' => _('Insert macro'),
  93. 'S_CREATE_LOG_TRIGGER' => _('Create trigger'),
  94. 'S_DELETE' => _('Delete'),
  95. 'S_DELETE_KEYWORD_Q' => _('Delete keyword?'),
  96. 'S_DELETE_EXPRESSION_Q' => _('Delete expression?'),
  97. 'S_SIMPLE_GRAPHS' => _('Simple graphs'),
  98. 'S_HISTORY' => _('History'),
  99. 'S_HISTORY_AND_SIMPLE_GRAPHS' => _('History and simple graphs'),
  100. ),
  101. 'class.calendar.js' => array(
  102. 'S_JANUARY' => _('January'),
  103. 'S_FEBRUARY' => _('February'),
  104. 'S_MARCH' => _('March'),
  105. 'S_APRIL' => _('April'),
  106. 'S_MAY' => _('May'),
  107. 'S_JUNE' => _('June'),
  108. 'S_JULY' => _('July'),
  109. 'S_AUGUST' => _('August'),
  110. 'S_SEPTEMBER' => _('September'),
  111. 'S_OCTOBER' => _('October'),
  112. 'S_NOVEMBER' => _('November'),
  113. 'S_DECEMBER' => _('December'),
  114. 'S_MONDAY_SHORT_BIG' => _x('M', 'Monday short'),
  115. 'S_TUESDAY_SHORT_BIG' => _x('T', 'Tuesday short'),
  116. 'S_WEDNESDAY_SHORT_BIG' => _x('W', 'Wednesday short'),
  117. 'S_THURSDAY_SHORT_BIG' => _x('T', 'Thursday short'),
  118. 'S_FRIDAY_SHORT_BIG' => _x('F', 'Friday short'),
  119. 'S_SATURDAY_SHORT_BIG' => _x('S', 'Saturday short'),
  120. 'S_SUNDAY_SHORT_BIG' => _x('S', 'Sunday short'),
  121. 'S_NOW' => _('Now'),
  122. 'S_DONE' => _('Done'),
  123. 'S_TIME' => _('Time'),
  124. ),
  125. 'class.cmap.js' => array(
  126. 'S_ON' => _('On'),
  127. 'S_OFF' => _('Off'),
  128. 'S_HIDDEN' => _('Hidden'),
  129. 'S_SHOWN' => _('Shown'),
  130. 'S_HOST' => _('Host'),
  131. 'S_MAP' => _('Map'),
  132. 'S_TRIGGER' => _('Trigger'),
  133. 'S_HOST_GROUP' => _('Host group'),
  134. 'S_IMAGE' => _('Image'),
  135. 'S_DEFAULT' => _('Default'),
  136. 'S_CLOSE' => _('Close'),
  137. 'S_PLEASE_SELECT_TWO_ELEMENTS' => _('Please select two elements'),
  138. 'S_DOT' => _('Dot'),
  139. 'S_TWO_ELEMENTS_SHOULD_BE_SELECTED' => _('Two elements should be selected'),
  140. 'S_DELETE_SELECTED_ELEMENTS_Q' => _('Delete selected elements?'),
  141. 'S_NEW_ELEMENT' => _('New element'),
  142. 'S_INCORRECT_ELEMENT_MAP_LINK' => _('All links should have "Name" and "URL" specified'),
  143. 'S_EACH_URL_SHOULD_HAVE_UNIQUE' => _('Each URL should have a unique name. Please make sure there is only one URL named'),
  144. 'S_DELETE_LINKS_BETWEEN_SELECTED_ELEMENTS_Q' => _('Delete links between selected elements?'),
  145. 'S_NO_IMAGES' => 'You need to have at least one image uploaded to create map element. Images can be uploaded in Administration->General->Images section.',
  146. 'S_ICONMAP_IS_NOT_ENABLED' => _('Iconmap is not enabled'),
  147. ),
  148. 'class.cmessages.js' => array(
  149. 'S_MUTE' => _('Mute'),
  150. 'S_UNMUTE' => _('Unmute'),
  151. 'S_MESSAGES' => _('Messages'),
  152. 'S_CLEAR' => _('Clear'),
  153. 'S_SNOOZE' => _('Snooze'),
  154. 'S_MOVE' => _('Move'),
  155. ),
  156. 'class.cookie.js' => array(
  157. 'S_MAX_COOKIE_SIZE_REACHED' => _('We are sorry, the maximum possible number of elements to remember has been reached.'),
  158. ),
  159. 'main.js' => array(
  160. 'S_CLOSE' => _('Close'),
  161. 'S_NO_ELEMENTS_SELECTED' => _('No elements selected!'),
  162. ),
  163. 'init.js' => array(
  164. 'Host screens' => _('Host screens'),
  165. 'Go to' => _('Go to'),
  166. 'Latest data' => _('Latest data'),
  167. 'Scripts' => _('Scripts'),
  168. 'Host inventories' => _('Host inventories'),
  169. 'Add service' => _('Add service'),
  170. 'Edit service' => _('Edit service'),
  171. 'Delete service' => _('Delete service'),
  172. 'Delete the selected service?' => _('Delete the selected service?')
  173. )
  174. );
  175. if (empty($_GET['files'])) {
  176. $files = array(
  177. 'prototype.js',
  178. 'jquery.js',
  179. 'jquery-ui.js',
  180. 'common.js',
  181. 'class.cdebug.js',
  182. 'class.cdate.js',
  183. 'class.cookie.js',
  184. 'class.curl.js',
  185. 'class.rpc.js',
  186. 'class.bbcode.js',
  187. 'class.csuggest.js',
  188. 'class.cmessages.js',
  189. 'main.js',
  190. 'functions.js',
  191. 'menu.js',
  192. 'init.js'
  193. );
  194. }
  195. else {
  196. $files = $_GET['files'];
  197. }
  198. $js = 'if(typeof(locale) == "undefined") var locale = {};'."\n";
  199. foreach ($files as $file) {
  200. if (isset($tranStrings[$file])) {
  201. foreach ($tranStrings[$file] as $origStr => $str) {
  202. $js .= "locale['".$origStr."'] = ".zbx_jsvalue($str).";";
  203. }
  204. }
  205. }
  206. foreach ($files as $file) {
  207. if (isset($availableJScripts[$file])) {
  208. $js .= file_get_contents('js/'.$availableJScripts[$file].$file)."\n";
  209. }
  210. }
  211. $jsLength = strlen($js);
  212. $ETag = md5($jsLength);
  213. if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $ETag) {
  214. header('HTTP/1.1 304 Not Modified');
  215. header('ETag: '.$ETag);
  216. exit();
  217. }
  218. header('Content-type: text/javascript; charset=UTF-8');
  219. // breaks if "zlib.output_compression = On"
  220. // header('Content-length: '.$jsLength);
  221. header('Cache-Control: public, must-revalidate');
  222. header('ETag: '.$ETag);
  223. echo $js;