From d6d89e3d9fd8d717950e7a618adcc4038836948b Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 7 Oct 2019 17:14:28 +0100 Subject: [PATCH] Implement initial theme update UI logic. Looks like we have Unicode issues though :-/ --- module_index.json | 2 +- modules/feature-theme-gallery.php | 36 +++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/module_index.json b/module_index.json index b3eb12c..03901fb 100755 --- a/module_index.json +++ b/module_index.json @@ -155,7 +155,7 @@ "version": "0.3", "author": "Starbeamrainbowlabs", "description": "Adds a theme gallery page and optional automatic theme updates. Contacts a remote server, where IP addresses are stored in automatic server logs for security and attack mitigation purposes.", - "lastupdate": 1570462781, + "lastupdate": 1570464807, "optional": false, "extra_data": [] }, diff --git a/modules/feature-theme-gallery.php b/modules/feature-theme-gallery.php index 4cfb143..ede0a1a 100644 --- a/modules/feature-theme-gallery.php +++ b/modules/feature-theme-gallery.php @@ -111,8 +111,37 @@ register_module([ // Set the new theme's id $settings->css_theme_gallery_selected_id = $_GET["theme-selector"]; + $gallery_urls = explode(" ", $settings->css_theme_gallery_index_url); + + // Find the URL of the selected theme + // FUTURE: Figure out a way to pass this information through the UI interface instead to avoid a re-download? + $theme_autoupdate_url = null; + foreach($gallery_urls as $url) { + $next_index = json_decode(@file_get_contents($url)); + if(empty($next_index)) { + error_log("Error: Failed to download theme idnex file from '$url' when setting the wiki theme."); + continue; + } + foreach($next_index as $next_theme) { + if($next_theme->id == $settings->css_theme_gallery_selected_id) { + $theme_autoupdate_url = dirname($url) . "/{$next_theme->id}/theme.css"; + break; + } + } + if($theme_autoupdate_url !== null) break; + } + if($theme_autoupdate_url === null) { + http_response_code(503); + exit(page_renderer::render_main("Failed to set theme - Error - $settings->sitename)", "

Oops! $settings->sitename couldn't find the theme you selected. Perhaps it has been changed or deleted, or perhaps there was an error during the download process.

+

Try heading back to the theme gallery and trying again.

")); + } + $settings->css_theme_autoupdate_url = $theme_autoupdate_url; + + if(!theme_update(true)) { + http_response_code(503); + exit(page_renderer::render_main("Failed to download theme - $settings->sitename", "

Oops! $settings->sitename wasn't able to download the theme you selected. If you're the administrator, try checking the PHP server logs. If not, try contacting $settings->sitename's administrator, who's contact details can be found at the bottom of every page.

")); + } - // TODO: Set the autoupdate_url here // TODO: Add option to disable theme updates if(!save_settings()) { @@ -120,9 +149,12 @@ register_module([ exit(page_renderer::render_main("Server error - $settings->sitename", "

Oops! $settings->sitename wasn't able to save the peppermint.json settings file back to disk. If you're the administrator, try checking the permissions on disk. If not, try contacting $settings->sitename's administrator, who's contact details can be found at the bottom of every page.

")); } - + http_response_code(200); + exit(page_renderer::render_main("Theme Changed - $settings->sitename", "

$settings->sitename's theme was changed successfully to $settings->css_theme_gallery_selected_id.

+

Go to the homepage.

")); }); + // TODO: Fill this in properly add_help_section("26-random-redirect", "Jumping to a random page", "

$settings->sitename has a function that can send you to a random page. To use it, click here. $settings->admindetails_name ($settings->sitename's adminstrator) may have added it to one of the menus.

"); } ]);