diff --git a/application/helpers/hlp_header_helper.php b/application/helpers/hlp_header_helper.php index 68ab2c23f..27dfba5a1 100644 --- a/application/helpers/hlp_header_helper.php +++ b/application/helpers/hlp_header_helper.php @@ -277,75 +277,191 @@ function absoluteJsImportUrl($relurl) * if customJSModules contains at least one vuejs app and customisation files * exist in extensions */ -function extendableApps($includes) +class ExtendableAppsHelper { - if(!isset($includes['customJSModules'])) + private static $instance = null; + + protected $extensions; + + protected $customCSSs; + protected $customJSs; + protected $customJSModules; + + protected $initialised; + protected $appscount; + + protected $extCustomCSSs; + protected $extCustomJSs; + protected $extCustomJSModules; + + private function __construct() { - return; + $this->extensions = array(); + $this->customCSSs = null; + $this->customJSs = null; + $this->customJSModules = null; + + $this->initialised = false; + $this->appscount = 0; + + $this->extCustomCSSs = null; + $this->extCustomJSs = null; + $this->extCustomJSModules = null; } - if(!is_array($includes['customJSModules'])) + public static function getInstance() { - $includes['customJSModules'] = array($includes['customJSModules']); - } - - $extensions = array(); - $fsiterator = new FilesystemIterator(FHCPATH . 'application/extensions'); - foreach ($fsiterator as $fsitem) - { - if(preg_match('/^FHC-Core-/', $fsitem->getBasename())) + if(self::$instance === null) { - $extensions[] = $fsitem->getBasename(); + self::$instance = new ExtendableAppsHelper(); } + return self::$instance; } - $appscount = 0; - $tmpCustomJSModules = array(); - foreach($includes['customJSModules'] as $item) + public function init($customCSSs, $customJSs, $customJSModules) { - $matches = array(); - if(preg_match('#^public/(extensions/FHC-Core-.+)?js/apps/(.*)\.js$#', $item, $matches)) + if($this->initialised) { - $appscount++; + return; + } - $fhcextension = $matches[1]; - $app = $matches[2]; + $this->customCSSs = $customCSSs; + $this->customJSs = $customJSs; + $this->customJSModules = $customJSModules; + $this->initialised = true; - $extend_js_suffix = 'js/extend_app/' . $fhcextension . $app . '.js'; - $extend_css_suffix = 'css/extend_app/' . $fhcextension . $app . '.css'; + if(!isset($this->customJSModules)) + { + return; + } - foreach($extensions as $extension) + if(!is_array($this->customJSModules)) + { + $this->customJSModules = array($this->customJSModules); + } + + if(count($this->customJSModules) < 1) + { + return; + } + + $this->buildExtensionsList(); + $this->prepareExtendedArrays(); + } + + public function getCustomCSSs() + { + if(is_null($this->extCustomCSSs)) + { + return $this->customCSSs; + } + return $this->extCustomCSSs; + } + + public function getCustomJSs() + { + if(is_null($this->extCustomJSs)) + { + return $this->customJSs; + } + return $this->extCustomJSs; + } + + public function getCustomJSModules() + { + if(is_null($this->extCustomJSModules)) + { + return $this->customJSModules; + } + return $this->extCustomJSModules; + } + + protected function buildExtensionsList() + { + $this->extensions = array(); + $fsiterator = new FilesystemIterator(FHCPATH . 'application/extensions'); + foreach ($fsiterator as $fsitem) + { + if(preg_match('/^FHC-Core-/', $fsitem->getBasename())) { - $extend_js = 'public/extensions/' . $extension . '/' . $extend_js_suffix; - $extend_css = 'public/extensions/' . $extension . '/' . $extend_css_suffix; - - if(is_readable(FHCPATH . $extend_js)) - { - array_push($tmpCustomJSModules, $extend_js); - } - - if(is_readable(FHCPATH . $extend_css)) - { - array_push($includes['customCSSs'], $extend_css); - } + $this->extensions[] = $fsitem->getBasename(); } } - array_push($tmpCustomJSModules, $item); } - $includes['customJSModules'] = $tmpCustomJSModules; - if($appscount > 0) + protected function prepareExtendedArrays() { - if(!isset($includes['customJSs'])) + $this->appscount = 0; + $this->initExtCustomCSSs(); + $this->extCustomJSModules = array(); + foreach($this->customJSModules as $item) { - $includes['customJSs'] = array(); + $matches = array(); + if(preg_match('#^public/(extensions/FHC-Core-.+)?js/apps/(.*)\.js$#', $item, $matches)) + { + $this->appscount++; + + $fhcextension = $matches[1]; + $app = $matches[2]; + + $extend_js_suffix = 'js/extend_app/' . $fhcextension . $app . '.js'; + $extend_css_suffix = 'css/extend_app/' . $fhcextension . $app . '.css'; + + foreach($this->extensions as $extension) + { + $extend_js = 'public/extensions/' . $extension . '/' . $extend_js_suffix; + $extend_css = 'public/extensions/' . $extension . '/' . $extend_css_suffix; + + if(is_readable(FHCPATH . $extend_js)) + { + array_push($this->extCustomJSModules, $extend_js); + } + + if(is_readable(FHCPATH . $extend_css)) + { + array_push($this->extCustomCSSs, $extend_css); + } + } + } + array_push($this->extCustomJSModules, $item); } - elseif(!is_array($includes['customJSs'])) + + if($this->appscount > 0) { - $includes['customJSs'] = array($includes['customJSs']); + $this->addFhcAppsJs(); } - array_push($includes['customJSs'], 'public/js/FhcApps.js'); } - return $includes; + protected function initExtCustomCSSs() + { + if(!isset($this->customCSSs)) + { + $this->extCustomCSSs = array(); + } + elseif(!is_array($this->customCSSs)) + { + $this->extCustomCSSs = array($this->customCSSs); + } + else + { + $this->extCustomCSSs = $this->customCSSs; + } + } + + protected function addFhcAppsJs() + { + if(!isset($this->customJSs)) + { + $this->extCustomJSs = array(); + } + elseif(!is_array($this->customJSs)) + { + $this->extCustomJSs = array($this->customJSs); + } + else + { + $this->extCustomJSs = $this->customJSs; + } + array_push($this->extCustomJSs, 'public/js/FhcApps.js'); + } } diff --git a/application/views/Cis/Documents.php b/application/views/Cis/Documents.php index fcafff57c..f34ce3fc1 100644 --- a/application/views/Cis/Documents.php +++ b/application/views/Cis/Documents.php @@ -1,9 +1,9 @@ 'Documents', 'tabulator5' => true, 'customJSModules' => ['public/js/apps/Cis/Documents.js'] -)); +); $this->load->view('templates/CISVUE-Header', $includesArray); ?> diff --git a/application/views/Cis/ProfilUpdate.php b/application/views/Cis/ProfilUpdate.php index 76e195b57..2e69208c7 100644 --- a/application/views/Cis/ProfilUpdate.php +++ b/application/views/Cis/ProfilUpdate.php @@ -1,5 +1,5 @@ 'Profil Änderungen', 'vue3' => true, 'primevue3' => true, @@ -16,7 +16,7 @@ $includesArray = extendableApps(array( 'customCSSs' => array( 'public/css/components/FilterComponent.css','public/css/components/FormUnderline.css' ) -)); +); if(defined("CIS4")) { diff --git a/application/views/CisRouterView/CisRouterView.php b/application/views/CisRouterView/CisRouterView.php index 44f3a3fcc..6ff428362 100644 --- a/application/views/CisRouterView/CisRouterView.php +++ b/application/views/CisRouterView/CisRouterView.php @@ -1,6 +1,6 @@ 'Cis4', 'axios027' => true, 'bootstrap5' => true, @@ -42,7 +42,7 @@ $includesArray = extendableApps(array( 'public/js/apps/Dashboard/Fhc.js', ), -)); +); $this->load->view('templates/CISVUE-Header', $includesArray); ?> diff --git a/application/views/LVVerwaltung.php b/application/views/LVVerwaltung.php index d2856ad3e..4cebae839 100644 --- a/application/views/LVVerwaltung.php +++ b/application/views/LVVerwaltung.php @@ -1,5 +1,5 @@ 'LVVerwaltung', 'axios027' => true, 'bootstrap5' => true, @@ -20,7 +20,7 @@ 'customJSModules' => [ 'public/js/apps/LVVerwaltung.js' ] - )); + ); $this->load->view('templates/FHC-Header', $includesArray); diff --git a/application/views/Studentenverwaltung.php b/application/views/Studentenverwaltung.php index 59b05063e..1cd28d735 100644 --- a/application/views/Studentenverwaltung.php +++ b/application/views/Studentenverwaltung.php @@ -1,5 +1,5 @@ 'Studentenverwaltung', 'axios027' => true, 'bootstrap5' => true, @@ -30,7 +30,7 @@ 'customJSModules' => [ 'public/js/apps/Studentenverwaltung.js' ] - )); + ); $this->load->view('templates/FHC-Header', $includesArray); ?> diff --git a/application/views/codex/bismeldestichtag.php b/application/views/codex/bismeldestichtag.php index fc0311674..37af16cc6 100644 --- a/application/views/codex/bismeldestichtag.php +++ b/application/views/codex/bismeldestichtag.php @@ -1,5 +1,5 @@ 'Bismeldestichtage', 'axios027' => true, 'bootstrap5' => true, @@ -11,7 +11,7 @@ 'customCSSs' => array('vendor/vuejs/vuedatepicker_css/main.css'), 'customJSs' => array('vendor/vuejs/vuedatepicker_js/vue-datepicker.iife.js'), 'customJSModules' => array('public/js/apps/Bismeldestichtag/Bismeldestichtag.js') - )); + ); $this->load->view('templates/FHC-Header', $includesArray); ?> diff --git a/application/views/lehre/Antrag/Create.php b/application/views/lehre/Antrag/Create.php index 56d1e0a28..00e41d1cd 100644 --- a/application/views/lehre/Antrag/Create.php +++ b/application/views/lehre/Antrag/Create.php @@ -1,5 +1,5 @@ 'Antrag auf Änderung des Studierendenstatus', 'cis' => true, 'vue3' => true, @@ -16,7 +16,7 @@ $sitesettings = extendableApps(array( ), 'customJSs' => array( ) -)); +); if(defined('CIS4')){ $this->load->view( diff --git a/application/views/lehre/Antrag/Leitung/List.php b/application/views/lehre/Antrag/Leitung/List.php index f6c95bc86..1225b16b6 100644 --- a/application/views/lehre/Antrag/Leitung/List.php +++ b/application/views/lehre/Antrag/Leitung/List.php @@ -2,7 +2,7 @@ use \DateTime as DateTime; -$sitesettings = extendableApps(array( +$sitesettings = array( 'title' => 'Anträge auf Änderung des Studierendenstatus', 'cis' => true, 'vue3' => true, @@ -25,7 +25,7 @@ $sitesettings = extendableApps(array( ), 'customJSs' => array( ) -)); +); $this->load->view( 'templates/FHC-Header', diff --git a/application/views/lehre/Antrag/Student/List.php b/application/views/lehre/Antrag/Student/List.php index 1b467e576..6d769dafe 100644 --- a/application/views/lehre/Antrag/Student/List.php +++ b/application/views/lehre/Antrag/Student/List.php @@ -1,5 +1,5 @@ 'Antrag auf Änderung des Studierendenstatus', 'cis' => true, 'vue3' => true, @@ -15,7 +15,7 @@ $sitesettings = extendableApps(array( ), 'customJSs' => array( ) -)); +); if(defined('CIS4')){ $this->load->view( diff --git a/application/views/lehre/Antrag/Wiederholung/Student.php b/application/views/lehre/Antrag/Wiederholung/Student.php index 65707cc7b..e51cfd1bc 100644 --- a/application/views/lehre/Antrag/Wiederholung/Student.php +++ b/application/views/lehre/Antrag/Wiederholung/Student.php @@ -1,5 +1,5 @@ 'Antrag Wiederholung vom Studium', 'cis' => true, 'vue3' => true, @@ -19,7 +19,7 @@ $sitesettings = extendableApps(array( ), 'customJSs' => array( ) -)); +); $this->load->view( 'templates/FHC-Header', diff --git a/application/views/lehre/lvplanung/lvTemplateUebersicht.php b/application/views/lehre/lvplanung/lvTemplateUebersicht.php index 8e47677f0..5c873486c 100644 --- a/application/views/lehre/lvplanung/lvTemplateUebersicht.php +++ b/application/views/lehre/lvplanung/lvTemplateUebersicht.php @@ -1,5 +1,5 @@ 'LV Template Übersicht', 'vue3' => true, 'axios027' => true, @@ -14,7 +14,7 @@ $includesArray = extendableApps(array( 'public/css/Fhc.css', 'public/css/lvTemplateUebersicht.css' ) -)); +); $this->load->view('templates/FHC-Header', $includesArray); ?> diff --git a/application/views/system/logs/logsViewer.php b/application/views/system/logs/logsViewer.php index 1d6b50394..ddfe855fe 100644 --- a/application/views/system/logs/logsViewer.php +++ b/application/views/system/logs/logsViewer.php @@ -1,5 +1,5 @@ 'Logs Viewer', 'axios027' => true, 'bootstrap5' => true, @@ -14,7 +14,7 @@ 'ui' => array('bitteEintragWaehlen') ), 'customJSModules' => array('public/js/apps/LogsViewer/LogsViewer.js'), - )); + ); $this->load->view('templates/FHC-Header', $includesArray); ?> diff --git a/application/views/templates/FHC-Footer.php b/application/views/templates/FHC-Footer.php index c816ebf2e..d2eb229f1 100644 --- a/application/views/templates/FHC-Footer.php +++ b/application/views/templates/FHC-Footer.php @@ -17,6 +17,7 @@ $use_vuejs_dev_version = $this->config->item('use_vuejs_dev_version'); // By default set the parameters to null + $customCSSs = isset($customCSSs) ? $customCSSs : null; $customJSs = isset($customJSs) ? $customJSs : null; $customJSModules = isset($customJSModules) ? $customJSModules : null; @@ -191,12 +192,13 @@ // NOTE: keep it as the last but one if ($addons === true) generateAddonsJSsInclude($calledPath.'/'.$calledMethod); - - + $extapphelper = ExtendableAppsHelper::getInstance(); + $extapphelper->init($customCSSs, $customJSs, $customJSModules); + // Eventually required JS // NOTE: keep it as the latest - generateJSsInclude($customJSs); - generateJSModulesInclude($customJSModules); + generateJSsInclude($extapphelper->getCustomJSs()); + generateJSModulesInclude($extapphelper->getCustomJSModules()); ?> diff --git a/application/views/templates/FHC-Header.php b/application/views/templates/FHC-Header.php index f7b5491a1..7b53cbf5d 100644 --- a/application/views/templates/FHC-Header.php +++ b/application/views/templates/FHC-Header.php @@ -9,6 +9,8 @@ $title = isset($title) ? $title : null; $refresh = isset($refresh) ? $refresh : null; $customCSSs = isset($customCSSs) ? $customCSSs : null; + $customJSs = isset($customJSs) ? $customJSs : null; + $customJSModules = isset($customJSModules) ? $customJSModules : null; $skipID = isset($skipID) ? $skipID : null; ?> @@ -132,8 +134,11 @@ //Tags if ($tags === true) generateCSSsInclude('public/css/tags.css'); + $extapphelper = ExtendableAppsHelper::getInstance(); + $extapphelper->init($customCSSs, $customJSs, $customJSModules); + // Eventually required CSS - generateCSSsInclude($customCSSs); // Eventually required CSS + generateCSSsInclude($extapphelper->getCustomCSSs()); // Eventually required CSS ?>