Browse Source

DO NOT USE!!!!!
fix installed themes variable

causefx 7 years ago
parent
commit
163fa2882d
4 changed files with 52 additions and 18 deletions
  1. 1 0
      api/config/default.php
  2. 1 2
      api/functions/organizr-functions.php
  3. 24 7
      api/functions/theme-functions.php
  4. 26 9
      js/functions.js

+ 1 - 0
api/config/default.php

@@ -172,6 +172,7 @@ return array(
 	'themeInstalled' => '',
 	'themeVersion' => '',
 	'installedPlugins' => '',
+	'installedThemes' => '',
 	'authDebug' => false,
 	'customJava' => '',
 	'customThemeJava' => '',

+ 1 - 2
api/functions/organizr-functions.php

@@ -65,8 +65,7 @@ function organizrSpecialSettings()
 		),
 		'misc' => array(
 			'installedPlugins' => $GLOBALS['installedPlugins'],
-			'themeInstalled' => $GLOBALS['themeInstalled'],
-			'themeVersion' => $GLOBALS['themeVersion'],
+			'installedThemes' => $GLOBALS['installedThemes'],
 			'return' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false,
 			'authDebug' => $GLOBALS['authDebug'],
 			'minimalLoginScreen' => $GLOBALS['minimalLoginScreen']

+ 24 - 7
api/functions/theme-functions.php

@@ -14,13 +14,30 @@ function installTheme($theme)
 			return false;
 		}
 	}
-	updateConfig(
-		array(
-			'themeInstalled' => $name,
-			'themeVersion' => $version,
-		)
-	);
-	return true;
+	if ($GLOBALS['installedThemes'] !== '') {
+		$installedThemes = explode('|', $GLOBALS['installedThemes']);
+		foreach ($installedThemes as $k => $v) {
+			$themes = explode(':', $v);
+			$installedThemesList[$themes[0]] = $themes[1];
+		}
+		if (isset($installedThemesList[$name])) {
+			$installedThemesList[$name] = $version;
+			$installedThemesNew = '';
+			foreach ($installedThemesList as $k => $v) {
+				if ($installedThemesNew == '') {
+					$installedThemesNew .= $k . ':' . $v;
+				} else {
+					$installedThemesNew .= '|' . $k . ':' . $v;
+				}
+			}
+		} else {
+			$installedThemesNew = $GLOBALS['installedThemes'] . '|' . $name . ':' . $version;
+		}
+	} else {
+		$installedThemesNew = $name . ':' . $version;
+	}
+	updateConfig(array('installedThemes' => $installedThemesNew));
+	return 'Success!@!' . $installedThemesNew;
 }
 
 function removeTheme($theme)

+ 26 - 9
js/functions.js

@@ -840,7 +840,7 @@ function loadMarketplaceThemesItems(themes){
     var themeList = '';
     $.each(themes, function(i,v) {
         if(v.icon == null || v.icon == ''){ v.icon = 'test.png'; }
-        v.status = pluginStatus(i,v.version);
+        v.status = themeStatus(i,v.version);
         var installButton = (v.status == 'Update Available') ? 'fa fa-download' : 'fa fa-plus';
         var removeButton = (v.status == 'Not Installed') ? 'disabled' : '';
         v.name = i;
@@ -1093,9 +1093,6 @@ function installPlugin(plugin=null){
         return false;
     }
     message('Installing Plugin',plugin.name,activeInfo.settings.notifications.position,"#FFF","success","5000");
-    var installedPluginsList = [];
-    var installedPluginsListNew = '';
-    var installedPlugins = [];
     plugin.downloadList = pluginFileList(plugin.files,plugin.github_folder,'plugins');
     organizrAPI('POST','api/?v1/plugin/install',{plugin:plugin}).success(function(data) {
         var html = JSON.parse(data);
@@ -1117,15 +1114,13 @@ function installTheme(theme=null){
         return false;
     }
     message('Installing Theme',theme.name,activeInfo.settings.notifications.position,"#FFF","success","5000");
-    var installedTheme = activeInfo.settings.misc.themeInstalled;
-    var installedThemeVersion = activeInfo.settings.misc.themeVersion;
     theme.downloadList = pluginFileList(theme.files,theme.github_folder,'themes');
     organizrAPI('POST','api/?v1/theme/install',{theme:theme}).success(function(data) {
         var html = JSON.parse(data);
         console.log(data);
-        if(html.data == true){
-            activeInfo.settings.misc.themeInstalled = theme.name;
-            activeInfo.settings.misc.themeVersion = theme.version;
+        if(html.data.substr(0, 7) == 'Success'){
+            var newThemes = html.data.split('!@!');
+            activeInfo.settings.misc.installedThemes = newThemes[1];
             loadMarketplace('themes');
             message(theme.name+' Installed','Please Click Customize Above to refresh',activeInfo.settings.notifications.position,"#FFF","success","5000");
         }else{
@@ -1158,6 +1153,28 @@ function pluginStatus(name=null,version=null){
         return 'Not Installed';
     }
 }
+function themeStatus(name=null,version=null){
+    var installedThemes = [];
+    var installedThemesList = [];
+    if(activeInfo.settings.misc.installedThemes !== ''){
+        installedThemes = activeInfo.settings.misc.installedThemes.split("|");
+        $.each(installedThemes, function(i,v) {
+            var theme = v.split(":");
+            installedThemesList[theme[0]] = theme[1];
+        });
+        if(typeof installedThemesList[name] !== 'undefined'){
+            if(version !== installedThemesList[name]){
+                return 'Update Available';
+            }else{
+                return 'Up to date';
+            }
+        }else{
+            return 'Not Installed';
+        }
+    }else{
+        return 'Not Installed';
+    }
+}
 function buildHomepageItem(array){
 	var listing = '';
 	if (Array.isArray(array)) {