Subversion Repositories oidplus

Rev

Rev 417 | Rev 420 | 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. require_once __DIR__ . '/3p/minify/src/Minify.php';
  24. require_once __DIR__ . '/3p/minify/src/JS.php';
  25. require_once __DIR__ . '/3p/minify/src/Exception.php';
  26.  
  27. error_reporting(E_ALL);
  28.  
  29. $files = array();
  30.  
  31. $do_minify = OIDplus::baseConfig()->getValue('MINIFY_JS', true);
  32.  
  33. $files[] = __DIR__ . '/3p/jquery/jquery-3.5.1'.($do_minify ? '.min' : '').'.js';
  34. //$files[] = __DIR__ . '/3p/bootstrap4/js/bootstrap'.($do_minify ? '.min' : '').'.js';
  35. $files[] = __DIR__ . '/3p/bootstrap/js/bootstrap'.($do_minify ? '.min' : '').'.js';
  36. $files[] = __DIR__ . '/3p/jstree/jstree'.($do_minify ? '.min' : '').'.js';
  37. $files[] = __DIR__ . '/3p/tinymce/tinymce'.($do_minify ? '.min' : '').'.js';
  38. $files[] = __DIR__ . '/3p/jquery-ui/jquery-ui'.($do_minify ? '.min' : '').'.js';
  39. $files[] = __DIR__ . '/3p/layout/jquery.layout_and_plugins'.($do_minify ? '.min' : '').'.js';
  40. $files[] = __DIR__ . '/3p/spamspan/spamspan.js'; // does not exist pre-minified
  41. $files[] = __DIR__ . '/3p/bignumber.js/bignumber'.($do_minify ? '.min' : '').'.js';
  42. $files[] = __DIR__ . '/3p/sha3_js/sha3.js'; // does not exist pre-minified
  43.  
  44. # ---
  45.  
  46. $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';';
  47.  
  48. OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null);
  49. $translation_array = OIDplus::getTranslationArray();
  50. $files[] = 'var language_messages = '.json_encode($translation_array).';';
  51.  
  52. //$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX','');
  53. //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';';
  54. $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client
  55.  
  56. $files[] = __DIR__ . '/oidplus_base.js';
  57.  
  58. # ---
  59.  
  60. $manifests = OIDplus::getAllPluginManifests('*Pages', true);
  61. foreach ($manifests as $manifest) {
  62.         foreach ($manifest->getJSFiles() as $js_file) {
  63.                 $files[] = $js_file;
  64.         }
  65. }
  66.  
  67. # ---
  68.  
  69. if ($do_minify) {
  70.         $minifier = null;
  71.         foreach ($files as $file) {
  72.                 if (is_null($minifier)) {
  73.                         $minifier = new Minify\JS($file);
  74.                 } else {
  75.                         $minifier->add($file);
  76.                 }
  77.         }
  78.         $out = is_null($minifier) ? '' : $minifier->minify();
  79. } else {
  80.         $out = '';
  81.         foreach ($files as $file) {
  82.                 if (file_exists($file)) {
  83.                         $out .= file_get_contents($file)."\n";
  84.                 } else {
  85.                         $out .= "$file\n";
  86.                 }
  87.         }
  88. }
  89.  
  90. # ---
  91.  
  92. httpOutWithETag($out, 'application/javascript', 'oidplus.js');
  93.