Subversion Repositories oidplus

Rev

Rev 462 | Rev 486 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. use MatthiasMullie\Minify;
  21.  
  22. require_once __DIR__ . '/../includes/oidplus.inc.php';
  23.  
  24. require_once __DIR__ . '/../3p/minify/src/Minify.php';
  25. require_once __DIR__ . '/../3p/minify/src/JS.php';
  26. require_once __DIR__ . '/../3p/minify/src/Exception.php';
  27.  
  28. error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0);
  29.  
  30. $files = array();
  31.  
  32. $files[] = __DIR__ . '/../3p/sha3_js/sha3.js'; // https://github.com/emn178/js-sha3
  33.  
  34. $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';';
  35.  
  36. OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null);
  37. $translation_array = OIDplus::getTranslationArray();
  38. $files[] = 'var language_messages = '.json_encode($translation_array).';';
  39.  
  40. //$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX','');
  41. //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';';
  42. $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client
  43.  
  44. $files[] = 'var setupdir = "'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";';
  45. $files[] = 'var rebuild_callbacks = [];';
  46. $files[] = 'var rebuild_config_callbacks = [];';
  47. $files[] = 'var plugin_combobox_change_callbacks = [];';
  48.  
  49. OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', array('OIDplus','registerDatabasePlugin'));
  50. $manifests = OIDplus::getAllPluginManifests('database', true);
  51. foreach ($manifests as $manifest) {
  52.         foreach ($manifest->getJsFilesSetup() as $js_file) {
  53.                 if (!file_exists($js_file)) {
  54.                         $files[] = "console.error('Script file not found: $js_file');";
  55.                 } else {
  56.                         $files[] = $js_file;
  57.                 }
  58.         }
  59. }
  60.  
  61. $files[] = __DIR__ . '/includes/setup_base.js';
  62.  
  63. # ---
  64.  
  65. $minifier = null;
  66. $out = '';
  67.  
  68. foreach ($files as $file) {
  69.         if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
  70.                 if (is_null($minifier)) {
  71.                         $minifier = new Minify\JS($file);
  72.                 } else {
  73.                         $minifier->add($file);
  74.                 }
  75.         } else {
  76.                 if (file_exists($file)) {
  77.                         $out .= file_get_contents($file)."\n";
  78.                 } else {
  79.                         $out .= "$file\n";
  80.                 }
  81.         }
  82. }
  83.  
  84. if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
  85.         $out = $minifier->minify();
  86. }
  87.  
  88. # ---
  89.  
  90. if (OIDplus::baseConfig()->getValue('DEBUG')) {
  91.         // In debug mode, we might get PHP error messages (see "error_reporting" above),
  92.         // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!)
  93.         header('Content-Type:application/javascript');
  94.         echo $out;
  95. } else {
  96.         httpOutWithETag($out, 'application/javascript', 'oidplus_setup.js');
  97. }
  98.