Subversion Repositories oidplus

Rev

Rev 1036 | Rev 1050 | 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 - 2021 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. error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0);
  25. @ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? '1' : '0');
  26.  
  27. $files = array();
  28.  
  29. // Note: Currently we do not use process_file() like in oidplus.min.js.php to fix relative paths
  30. //       since this script currently has no relvate resources that need to be loaded
  31. $files[] = __DIR__ . '/../vendor/emn178/js-sha3/src/sha3.js'; // https://github.com/emn178/js-sha3
  32. $files[] = __DIR__ . '/../vendor/components/jquery/jquery.js';
  33.  
  34. $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::getDefaultLang()).';';
  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('TABLENAME_PREFIX','');
  41. //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';';
  42. $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide TABLENAME_PREFIX from the client
  43.  
  44. $files[] = 'var setupdir = "'.((OIDplus::isSSL() ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";';
  45. $files[] = 'var rebuild_callbacks = [];'; // Ask the database or captcha plugins for verification of their data
  46. $files[] = /*db*/'var rebuild_config_callbacks = [];'; // Get config strings to be placed in the baseconfig file // TODO: rename to dbrebuild_config_callbacks
  47. $files[] = /*db*/'var plugin_combobox_change_callbacks = [];'; // TODO: rename to dbplugin_combobox_change_callbacks
  48. $files[] = /*captcha*/'var captcha_rebuild_config_callbacks = [];'; // Get config strings to be placed in the baseconfig file
  49. $files[] = /*captcha*/'var captcha_plugin_combobox_change_callbacks = [];';
  50.  
  51. $manifests = OIDplus::getAllPluginManifests('database,captcha', true);
  52. foreach ($manifests as $manifest) {
  53.         foreach ($manifest->getJsFilesSetup() as $js_file) {
  54.                 if (!file_exists($js_file)) {
  55.                         $files[] = "console.error('Script file not found: $js_file');";
  56.                 } else {
  57.                         $files[] = $js_file;
  58.                 }
  59.         }
  60. }
  61.  
  62. $files[] = __DIR__ . '/../includes/oidplus_functions.js';
  63. $files[] = __DIR__ . '/../includes/oidplus_language.js';
  64. $files[] = __DIR__ . '/includes/setup_base.js';
  65.  
  66. # ---
  67.  
  68. $minifier = null;
  69. $out = '';
  70.  
  71. foreach ($files as $file) {
  72.         if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
  73.                 if (is_null($minifier)) {
  74.                         $minifier = new Minify\JS($file);
  75.                 } else {
  76.                         $minifier->add($file);
  77.                 }
  78.         } else {
  79.                 if (file_exists($file)) {
  80.                         $out .= file_get_contents($file)."\n";
  81.                 } else {
  82.                         $out .= "$file\n";
  83.                 }
  84.         }
  85. }
  86.  
  87. if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
  88.         $out = $minifier->minify();
  89. }
  90.  
  91. # ---
  92.  
  93. if (OIDplus::baseConfig()->getValue('DEBUG')) {
  94.         // In debug mode, we might get PHP error messages (see "error_reporting" above),
  95.         // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!)
  96.         header('Content-Type:application/javascript');
  97.         echo $out;
  98. } else {
  99.         httpOutWithETag($out, 'application/javascript', 'oidplus_setup.js');
  100. }
  101.