From e81a3940f3a6dac7aee5e857dfc80c70024fdf6c Mon Sep 17 00:00:00 2001 From: Julian Prieber Date: Tue, 7 Mar 2023 19:43:05 +0100 Subject: [PATCH] Improved loading time on themes page Now lazy loading theme updater with Ajax --- .../views/studio/theme-updater.blade.php | 333 ++++++++++++++ resources/views/studio/theme.blade.php | 407 +++--------------- routes/web.php | 1 + 3 files changed, 387 insertions(+), 354 deletions(-) create mode 100644 resources/views/studio/theme-updater.blade.php diff --git a/resources/views/studio/theme-updater.blade.php b/resources/views/studio/theme-updater.blade.php new file mode 100644 index 0000000..0611ed3 --- /dev/null +++ b/resources/views/studio/theme-updater.blade.php @@ -0,0 +1,333 @@ +@if(auth()->user()->role == 'admin') +@if(env('ENABLE_THEME_UPDATER') == 'true') + +


+
+ Theme updater +
+ + + + + + + 0) { + $verNr = substr($matches[0][0],15); + } + } + + $themeVe = NULL; + if(!isset($verNr)){$verNr = "error";}; + + if ($entry != "." && $entry != "..") { + echo ''; + echo ''; + echo ''; + echo ''; + echo '';} + }} ?> +
Theme name:Update status:Version: 
'; print_r(ucfirst($entry)); + echo '
'; + if(file_exists(base_path('themes') . '/' . $entry . '/readme.md')){ + if(!strpos(file_get_contents(base_path('themes') . '/' . $entry . '/readme.md'), 'Source code:')){$hasSource = false;}else{ + $hasSource = true; + + $text = file_get_contents(base_path('themes') . '/' . $entry . '/readme.md'); + $pattern = '/Source code:.*/'; + preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE); + $sourceURL = substr($matches[0][0],13); + + $replaced = str_replace("https://github.com/", "https://raw.githubusercontent.com/", trim($sourceURL)); + $replaced = $replaced . "/main/readme.md"; + + if (strpos($sourceURL, 'github.com')){ + + ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)'); + try{ + $textGit = file_get_contents($replaced); + $patternGit = '/Theme Version:.*/'; + preg_match($patternGit, $textGit, $matches, PREG_OFFSET_CAPTURE); + $sourceURLGit = substr($matches[0][0],15); + $Vgitt = 'v' . $sourceURLGit; + $verNrv = 'v' . $verNr; + }catch(Exception $ex){ + $themeVe = "error"; + $Vgitt = NULL; + $verNrv = NULL; + } + + if(trim($Vgitt) > trim($verNrv)){ + $updateAv = true; + $GLOBALS['updateAv'] = true; + } else { + $updateAv = false; + } + } else {$themeVe = "error";} + + } + } + + if ($themeVe == "error") { + echo ''; + } elseif ($hasSource == false) { + echo ''; + } elseif($updateAv == true) { + echo ''; + } else { + echo ''; + } + echo '
' . $verNr . '
+
+ Update all themes

+ +
+ +'; +}catch(Exception $ex){} +?> + + + +@endif +@endif \ No newline at end of file diff --git a/resources/views/studio/theme.blade.php b/resources/views/studio/theme.blade.php index f32532d..c429a6a 100644 --- a/resources/views/studio/theme.blade.php +++ b/resources/views/studio/theme.blade.php @@ -15,29 +15,42 @@
- + 0) { + $themeName = substr($matches[0][0],12); + } + } + if($page->theme != $entry and isset($themeName)){ + echo ''; + } + } + } } - } - if($page->theme != $entry and isset($themeName)){echo ''; }}}} ?> - theme != "default" and $page->theme != ""){ - if(file_exists(base_path('themes') . '/' . $page->theme . '/readme.md')){ - $text = file_get_contents(base_path('themes') . '/' . $page->theme . '/readme.md'); - $pattern = '/Theme Name:.*/'; - preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE); - $themeName = substr($matches[0][0],12);} - if(isset($themeName)){echo '';}} ?> - theme == "default" or $page->theme == ""){echo 'selected';} echo '>Default'; ?> + if(file_exists(base_path('themes') . '/' . $page->theme . '/readme.md')){ + $text = file_get_contents(base_path('themes') . '/' . $page->theme . '/readme.md'); + $pattern = '/Theme Name:.*/'; + preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE); + $themeName = substr($matches[0][0],12); + } + echo ''; + } + + echo ''; + ?>
@@ -74,208 +87,8 @@ @if(auth()->user()->role == 'admin') @if(env('ENABLE_THEME_UPDATER') == 'true') - -


-
- Theme updater -
- - - - - - - 0) { - $verNr = substr($matches[0][0],15); - } - } - - $themeVe = NULL; - if(!isset($verNr)){$verNr = "error";}; - - if ($entry != "." && $entry != "..") { - echo ''; - echo ''; - echo ''; - echo ''; - echo '';} - }} ?> -
Theme name:Update status:Version: 
'; print_r(ucfirst($entry)); - echo '
'; - if(file_exists(base_path('themes') . '/' . $entry . '/readme.md')){ - if(!strpos(file_get_contents(base_path('themes') . '/' . $entry . '/readme.md'), 'Source code:')){$hasSource = false;}else{ - $hasSource = true; - - $text = file_get_contents(base_path('themes') . '/' . $entry . '/readme.md'); - $pattern = '/Source code:.*/'; - preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE); - $sourceURL = substr($matches[0][0],13); - - $replaced = str_replace("https://github.com/", "https://raw.githubusercontent.com/", trim($sourceURL)); - $replaced = $replaced . "/main/readme.md"; - - if (strpos($sourceURL, 'github.com')){ - - ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)'); - try{ - $textGit = file_get_contents($replaced); - $patternGit = '/Theme Version:.*/'; - preg_match($patternGit, $textGit, $matches, PREG_OFFSET_CAPTURE); - $sourceURLGit = substr($matches[0][0],15); - $Vgitt = 'v' . $sourceURLGit; - $verNrv = 'v' . $verNr; - }catch(Exception $ex){ - $themeVe = "error"; - $Vgitt = NULL; - $verNrv = NULL; - } - - if(trim($Vgitt) > trim($verNrv)){ - $updateAv = true; - $GLOBALS['updateAv'] = true; - } else { - $updateAv = false; - } - } else {$themeVe = "error";} - - } - } - - if ($themeVe == "error") { - echo ''; - } elseif ($hasSource == false) { - echo ''; - } elseif($updateAv == true) { - echo ''; - } else { - echo ''; - } - echo '
' . $verNr . '
-
- Update all themes

- -
- -'; -}catch(Exception $ex){} -?> - +
+
@endif @endif @@ -338,141 +151,27 @@ try{ if($GLOBALS['updateAv'] == true) echo ' element - this.el = el; - // Store the element - this.summary = el.querySelector('summary'); - // Store the
element - this.content = el.querySelector('.content'); - - // Store the animation object (so we can cancel it if needed) - this.animation = null; - // Store if the element is closing - this.isClosing = false; - // Store if the element is expanding - this.isExpanding = false; - // Detect user clicks on the summary element - this.summary.addEventListener('click', (e) => this.onClick(e)); - } - - onClick(e) { - // Stop default behaviour from the browser - e.preventDefault(); - // Add an overflow on the
to avoid content overflowing - this.el.style.overflow = 'hidden'; - // Check if the element is being closed or is already closed - if (this.isClosing || !this.el.open) { - this.open(); - // Check if the element is being openned or is already open - } else if (this.isExpanding || this.el.open) { - this.shrink(); - } - } - - shrink() { - // Set the element as "being closed" - this.isClosing = true; - - // Store the current height of the element - const startHeight = `${this.el.offsetHeight}px`; - // Calculate the height of the summary - const endHeight = `${this.summary.offsetHeight}px`; - - // If there is already an animation running - if (this.animation) { - // Cancel the current animation - this.animation.cancel(); - } - - // Start a WAAPI animation - this.animation = this.el.animate({ - // Set the keyframes from the startHeight to endHeight - height: [startHeight, endHeight] - }, { - duration: 400 - , easing: 'ease-out' - }); - - // When the animation is complete, call onAnimationFinish() - this.animation.onfinish = () => this.onAnimationFinish(false); - // If the animation is cancelled, isClosing variable is set to false - this.animation.oncancel = () => this.isClosing = false; - } - - open() { - // Apply a fixed height on the element - this.el.style.height = `${this.el.offsetHeight}px`; - // Force the [open] attribute on the details element - this.el.open = true; - // Wait for the next frame to call the expand function - window.requestAnimationFrame(() => this.expand()); - } - - expand() { - // Set the element as "being expanding" - this.isExpanding = true; - // Get the current fixed height of the element - const startHeight = `${this.el.offsetHeight}px`; - // Calculate the open height of the element (summary height + content height) - const endHeight = `${this.summary.offsetHeight + this.content.offsetHeight}px`; - - // If there is already an animation running - if (this.animation) { - // Cancel the current animation - this.animation.cancel(); - } - - // Start a WAAPI animation - this.animation = this.el.animate({ - // Set the keyframes from the startHeight to endHeight - height: [startHeight, endHeight] - }, { - duration: 400 - , easing: 'ease-out' - }); - // When the animation is complete, call onAnimationFinish() - this.animation.onfinish = () => this.onAnimationFinish(true); - // If the animation is cancelled, isExpanding variable is set to false - this.animation.oncancel = () => this.isExpanding = false; - } - - onAnimationFinish(open) { - // Set the open attribute based on the parameter - this.el.open = open; - // Clear the stored animation - this.animation = null; - // Reset isClosing & isExpanding - this.isClosing = false; - this.isExpanding = false; - // Remove the overflow hidden and the fixed height - this.el.style.height = this.el.style.overflow = ''; - } - } - - document.querySelectorAll('details').forEach((el) => { - new Accordion(el); - }); - -
- -@endpush @endif @endforeach + + -@endsection +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index fffd1e6..5fdcd73 100755 --- a/routes/web.php +++ b/routes/web.php @@ -166,6 +166,7 @@ Route::group([ Route::get('/update/theme', [AdminController::class, 'updateThemes'])->name('updateThemes'); Route::get('/panel/config', [AdminController::class, 'showConfig'])->name('showConfig'); Route::post('/panel/config', [AdminController::class, 'editConfig'])->name('editConfig'); + Route::get('/theme-updater', function () {return view('studio/theme-updater', []);}); Route::get('/update', function () {return view('update', []);}); Route::get('/backup', function () {return view('backup', []);});