Browse Source

DO NOT USE!!!!!
added custom theme java box
started work on theme marketplace
new api endpoints for theme management

causefx 7 years ago
parent
commit
4470794f2a

+ 1 - 0
api/config/default.php

@@ -174,5 +174,6 @@ return array(
 	'installedPlugins' => '',
 	'authDebug' => false,
 	'customJava' => '',
+	'customThemeJava' => '',
 	'minimalLoginScreen' => false
 );

+ 18 - 0
api/functions/organizr-functions.php

@@ -754,6 +754,7 @@ function loadAppearance()
 	$appearance['customCss'] = $GLOBALS['customCss'];
 	$appearance['customThemeCss'] = $GLOBALS['customThemeCss'];
 	$appearance['customJava'] = $GLOBALS['customJava'];
+	$appearance['customThemeJava'] = $GLOBALS['customThemeJava'];
 	return $appearance;
 }
 
@@ -1062,6 +1063,23 @@ function getCustomizeAppearance()
 					'attr' => 'rows="10"',
 				),
 			),
+			'Theme Javascript' => array(
+				array(
+					'type' => 'html',
+					'override' => 12,
+					'label' => 'Theme Javascript',
+					'html' => '<button type="button" class="hidden saveJavaTheme btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customThemeJavaEditor" style="height:300px">' . $GLOBALS['customThemeJava'] . '</div>'
+				),
+				array(
+					'type' => 'textbox',
+					'name' => 'customThemeJava',
+					'class' => 'hidden javaThemeTextarea',
+					'label' => '',
+					'value' => $GLOBALS['customThemeJava'],
+					'placeholder' => 'No <script> tags needed',
+					'attr' => 'rows="10"',
+				),
+			),
 		);
 	}
 }

+ 53 - 0
api/functions/theme-functions.php

@@ -0,0 +1,53 @@
+<?php
+function installTheme($theme)
+{
+	$name = $theme['data']['theme']['name'];
+	$version = $theme['data']['theme']['version'];
+	foreach ($theme['data']['theme']['downloadList'] as $k => $v) {
+		$file = array(
+			'from' => $v['githubPath'],
+			'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'] . $v['fileName']),
+			'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'])
+		);
+		if (!downloadFileToPath($file['from'], $file['to'], $file['path'])) {
+			writeLog('error', 'Theme Function -  Downloaded File Failed  for: ' . $v['githubPath'], $GLOBALS['organizrUser']['username']);
+			return false;
+		}
+	}
+	updateConfig(
+		array(
+			'themeInstalled' => $name,
+			'themeVersion' => $version,
+		)
+	);
+	return true;
+}
+
+function removeTheme($theme)
+{
+	$name = $theme['data']['theme']['name'];
+	$version = $theme['data']['theme']['version'];
+	foreach ($theme['data']['theme']['downloadList'] as $k => $v) {
+		$file = array(
+			'from' => $v['githubPath'],
+			'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'] . $v['fileName']),
+			'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'])
+		);
+		if (!rrmdir($file['to'])) {
+			writeLog('error', 'Theme Function -  Remove File Failed  for: ' . $v['githubPath'], $GLOBALS['organizrUser']['username']);
+			return false;
+		}
+	}
+	if ($GLOBALS['themeInstalled'] !== '') {
+		$installedTheme = $GLOBALS['themeInstalled'];
+		if ($installedTheme == $name) {
+			updateConfig(
+				array(
+					'themeInstalled' => '',
+					'themeVersion' => '',
+				)
+			);
+		}
+	}
+	return true;
+}

+ 38 - 0
api/index.php

@@ -935,6 +935,44 @@ switch ($function) {
 				break;
 		}
 		break;
+	case 'v1_theme_install':
+		switch ($method) {
+			case 'POST':
+				if (qualifyRequest(1)) {
+					$result['status'] = 'success';
+					$result['statusText'] = 'success';
+					$result['data'] = installTheme($_POST);
+				} else {
+					$result['status'] = 'error';
+					$result['statusText'] = 'API/Token invalid or not set';
+					$result['data'] = null;
+				}
+				break;
+			default:
+				$result['status'] = 'error';
+				$result['statusText'] = 'The function requested is not defined for method: ' . $method;
+				break;
+		}
+		break;
+	case 'v1_theme_remove':
+		switch ($method) {
+			case 'POST':
+				if (qualifyRequest(1)) {
+					$result['status'] = 'success';
+					$result['statusText'] = 'success';
+					$result['data'] = removeTheme($_POST);
+				} else {
+					$result['status'] = 'error';
+					$result['statusText'] = 'API/Token invalid or not set';
+					$result['data'] = null;
+				}
+				break;
+			default:
+				$result['status'] = 'error';
+				$result['statusText'] = 'The function requested is not defined for method: ' . $method;
+				break;
+		}
+		break;
 	case 'v1_user_edit':
 		switch ($method) {
 			case 'POST':

+ 0 - 1
api/pages/settings-plugins.php

@@ -4,7 +4,6 @@ if (file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
 <script>
 	buildPlugins();
 </script>
-<script src="plugins/bower_components/bootstrap-treeview-master/dist/bootstrap-treeview.min.js"></script>
 <div id="main-plugin-area"></div>
 <form id="about-plugin-form" class="mfp-hide white-popup-block mfp-with-anim">
     <h2 id="about-plugin-title">Loading...</h2>

+ 31 - 0
api/pages/settings.php

@@ -73,6 +73,7 @@ if (file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
                         <ul class="nav customtab2 nav-tabs" role="tablist">
                             <li onclick="changeSettingsMenu(\'Settings::Customize::Appearance\');loadSettingsPage(\'api/?v1/settings/customize/appearance\',\'#settings-customize-appearance\',\'Customize Appearance\');" role="presentation" class=""><a href="#settings-customize-appearance" aria-controls="home" role="tab" data-toggle="tab" aria-expanded="false"><span class="visible-xs"><i class="ti-eye"></i></span><span class="hidden-xs" lang="en">Appearance</span></a>
                             </li>
+                            <li onclick="changeSettingsMenu(\'Settings::Customize::Marketplace\');loadMarketplace(\'themes\');" role="presentation" class=""><a href="#settings-customize-marketplace" aria-controls="home" role="tab" data-toggle="tab" aria-expanded="false"><span class="visible-xs"><i class="ti-layout-list-thumb"></i></span><span class="hidden-xs" lang="en">Marketplace</span></a></li>
                         </ul>
                         <!-- Tab panes -->
                         <div class="tab-content">
@@ -80,6 +81,31 @@ if (file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
                                 <h2 lang="en">Loading...</h2>
                                 <div class="clearfix"></div>
                             </div>
+                            <div role="tabpanel" class="tab-pane fade" id="settings-customize-marketplace">
+								<div class="panel bg-org panel-info">
+									<div class="panel-heading">
+										<span lang="en">Theme Marketplace</span>
+									</div>
+									<div class="panel-wrapper collapse in" aria-expanded="true">
+										<div class="table-responsive">
+					                        <table class="table table-hover manage-u-table">
+					                            <thead>
+					                                <tr>
+					                                    <th width="70" class="text-center" lang="en">THEME</th>
+					                                    <th></th>
+					                                    <th lang="en">CATEGORY</th>
+					                                    <th lang="en">STATUS</th>
+					                                    <th lang="en" style="text-align:center">INFO</th>
+					                                    <th lang="en" style="text-align:center">INSTALL</th>
+					                                    <th lang="en" style="text-align:center">DELETE</th>
+					                                </tr>
+					                            </thead>
+					                            <tbody id="manageThemeTable"></tbody>
+					                        </table>
+					                    </div>
+									</div>
+								</div>
+							</div>
                         </div>
                     </section>
                     <! -- USER MANAGEMENT -->
@@ -263,5 +289,10 @@ if (file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
     <!--./row-->
 </div>
 <!-- /.container-fluid -->
+<form id="about-theme-form" class="mfp-hide white-popup-block mfp-with-anim">
+    <h2 id="about-theme-title">Loading...</h2>
+    <div class="clearfix"></div>
+    <div id="about-theme-body" class=""></div>
+</form>
 ';
 }

+ 3 - 1
index.php

@@ -38,8 +38,8 @@
 	<?php echo pluginFiles('css'); ?>
     <link id="theme" href="css/themes/Organizr.css?v=<?php echo $GLOBALS['installedVersion']; ?>" rel="stylesheet">
     <style id="user-appearance"></style>
-    <style id="custom-css"></style>
     <style id="custom-theme-css"></style>
+    <style id="custom-css"></style>
     <!--[if lt IE 9]>
     <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
     <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
@@ -167,12 +167,14 @@
 <script src="plugins/bower_components/tinymce/tinymce.min.js"></script>
 <script src="plugins/bower_components/multiselect/js/jquery.multi-select.js"></script>
 <script src="plugins/bower_components/mousetrap/mousetrap.min.js"></script>
+<script src="plugins/bower_components/bootstrap-treeview-master/dist/bootstrap-treeview.min.js"></script>
 <script src="js/jquery.mousewheel.min.js"></script>
 <script src="js/plyr.js"></script>
 <script src="js/simplebar.js"></script>
 <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
 <script src="js/functions.js?v=<?php echo $GLOBALS['installedVersion']; ?>"></script>
 <script src="js/custom.min.js?v=<?php echo $GLOBALS['installedVersion']; ?>"></script>
+<script id="custom-theme-javascript"></script>
 <script id="custom-javascript"></script>
 <?php echo pluginFiles('js'); ?>
 </body>

+ 3 - 0
js/custom.js

@@ -1025,6 +1025,9 @@ $(document).on("click", ".saveThemeCss", function () {
 $(document).on("click", ".saveJava", function () {
     $('.javaTextarea').val(javaEditor.getValue()).trigger('change');
 });
+$(document).on("click", ".saveThemeJava", function () {
+    $('.javaThemeTextarea').val(javaThemeEditor.getValue()).trigger('change');
+});
 $(document).on("click", ".savecustomHTMLoneTextarea", function () {
     $('.customHTMLoneTextarea').val(customHTMLoneEditor.getValue()).trigger('change');
 });

File diff suppressed because it is too large
+ 0 - 0
js/custom.min.js


+ 146 - 7
js/functions.js

@@ -836,6 +836,38 @@ function loadMarketplacePluginsItems(plugins){
     });
     $('#managePluginTable').html(pluginList);
 }
+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);
+        var installButton = (v.status == 'Update Available') ? 'fa fa-download' : 'fa fa-plus';
+        var removeButton = (v.status == 'Not Installed') ? 'disabled' : '';
+        v.name = i;
+        themeList += `
+            <tr class="themeManagement" data-name="`+i+`" data-version="`+v.version+`">
+                <td class="text-center el-element-overlay">
+                    <div class="el-card-item p-0">
+                        <div class="el-card-avatar el-overlay-1 m-0">
+                            <img alt="user-img" src="`+v.icon+`" width="45">
+                        </div>
+                    </div>
+                </td>
+                <td>`+i+`
+                    <br><span class="text-muted">`+v.version+`</span>
+                    <br><span class="text-muted">`+v.author+`</span>
+                </td>
+                <td>`+v.category+`</td>
+                <td>`+v.status+`</td>
+                <td style="text-align:center"><button type="button" onclick='aboutTheme(`+JSON.stringify(v)+`);' class="btn btn-success btn-outline btn-circle btn-lg popup-with-form" href="#about-theme-form" data-effect="mfp-3d-unfold"><i class="fa fa-info"></i></button></td>
+                <td style="text-align:center"><button type="button" onclick='installTheme(`+JSON.stringify(v)+`);' class="btn btn-info btn-outline btn-circle btn-lg"><i class="`+installButton+`"></i></button></td>
+                <td style="text-align:center"><button type="button" onclick='removeTheme(`+JSON.stringify(v)+`);' class="btn btn-danger btn-outline btn-circle btn-lg" `+removeButton+`><i class="fa fa-trash"></i></button></td>
+            </tr>
+        `;
+
+    });
+    $('#manageThemeTable').html(themeList);
+}
 function aboutPluginImages(images){
     var imageList = '';
     if(Object.keys(images).length !== 0){
@@ -878,7 +910,7 @@ function aboutPluginFiles(fileList){
     });
     return files;
 }
-function pluginFileList(fileList,folder){
+function pluginFileList(fileList,folder,type){
     var files = [];
     $.each(fileList, function(i,v) {
         var splitFiles = v.split('|');
@@ -888,13 +920,84 @@ function pluginFileList(fileList,folder){
             var arrayPush = {
                 "fileName": v,
                 "path": prePath,
-                "githubPath": 'https://raw.githubusercontent.com/causefx/Organizr/v2-plugins/'+folder+prePath+v,
+                "githubPath": 'https://raw.githubusercontent.com/causefx/Organizr/v2-'+type+'/'+folder+prePath+v,
             };
             files.push(arrayPush);
         });
     });
     return files;
 }
+function aboutTheme(theme){
+    var files = aboutPluginFiles(theme.files);
+    console.log(files);
+    console.log(JSON.stringify(files));
+    var imageList = aboutPluginImages(theme.images);
+    var homepageLink = (theme.website !== '' || theme.website !== null) ? 'onclick="window.open(\''+theme.website+'\',\'_blank\');"' : ' ';
+
+    var infoBox = `
+    <div class="row">
+        <div class="col-lg-6 col-sm-12 col-xs-12">
+            <div class="row">
+                <div class="col-lg-12 col-sm-12 col-xs-12">
+                    <div class="white-box p-10" id="aboutThemeScroll">
+                        `+theme.description+`
+                    </div>
+                </div>
+                <div class="clearfix">&nbsp;</div>
+                <div class="col-lg-4 col-sm-4 col-xs-12">
+                    <div class="white-box mouse">
+                        <ul class="list-inline two-part text-center m-b-0">
+                            <li><i class="icon-envelope-open text-info"></i></li>
+                        </ul>
+                    </div>
+                </div>
+                <div class="col-lg-4 col-sm-4 col-xs-12">
+                    <div class="white-box mouse" `+homepageLink+`>
+                        <ul class="list-inline two-part text-center m-b-0">
+                            <li><i class="icon-home text-danger"></i></li>
+                        </ul>
+                    </div>
+                </div>
+                <div class="col-lg-4 col-sm-4 col-xs-12">
+                    <div class="white-box mouse" onclick="$('.themeFileList').toggleClass('hidden');">
+                        <ul class="list-inline two-part text-center m-b-0">
+                            <li><i class="icon-folder text-purple"></i></li>
+                        </ul>
+                    </div>
+                </div>
+                <div class="col-sm-12 col-xs-12 themeFileList hidden">
+                    <div id="treeviewTheme" class=""></div>
+                </div>
+            </div>
+        </div>
+        <div class="col-lg-6 col-sm-12 col-xs-12">
+            <div class="news-slide m-b-15">
+                <div class="vcarousel slide">
+                    <!-- Carousel items -->
+                    <div class="carousel-inner">
+                        `+imageList+`
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>`;
+    $('#about-theme-title').html(theme.name+'&nbsp;<small>'+theme.version+'</small>');
+    $('#about-theme-body').html(infoBox);
+    $('.vcarousel').carousel({
+        interval: 3000
+    });
+    $('#treeviewTheme').treeview({
+        levels: 1,
+        expandIcon: 'ti-angle-right',
+        onhoverColor: "rgba(0, 0, 0, 0.05)",
+        selectedBackColor: "#03a9f3",
+        collapseIcon: 'ti-angle-down',
+        data: JSON.stringify(files)
+    });
+    $('#aboutThemeScroll').slimScroll({
+        height: '225px'
+    });
+}
 function aboutPlugin(plugin){
     var files = aboutPluginFiles(plugin.files);
     var imageList = aboutPluginImages(plugin.images);
@@ -969,7 +1072,7 @@ function removePlugin(plugin=null){
         return false;
     }
     message('Removing Plugin',plugin.name,activeInfo.settings.notifications.position,"#FFF","success","5000");
-    plugin.downloadList = pluginFileList(plugin.files,plugin.github_folder);
+    plugin.downloadList = pluginFileList(plugin.files,plugin.github_folder,'plugins');
     organizrAPI('POST','api/?v1/plugin/remove',{plugin:plugin}).success(function(data) {
         var html = JSON.parse(data);
         if(html.data.substr(0, 7) == 'Success'){
@@ -993,7 +1096,7 @@ function installPlugin(plugin=null){
     var installedPluginsList = [];
     var installedPluginsListNew = '';
     var installedPlugins = [];
-    plugin.downloadList = pluginFileList(plugin.files,plugin.github_folder);
+    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);
         if(html.data.substr(0, 7) == 'Success'){
@@ -1009,6 +1112,30 @@ function installPlugin(plugin=null){
         console.error("Organizr Function: Connection Failed");
     });
 }
+function installTheme(theme=null){
+    if(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.substr(0, 7) == 'Success'){
+            activeInfo.settings.misc.themeInstalled = theme.name;
+            activeInfo.settings.misc.themeVersion = theme.version;
+            loadMarketplace('themes');
+            message(theme.name+' Installed','Please Click Customize Above to refresh',activeInfo.settings.notifications.position,"#FFF","success","5000");
+        }else{
+            message('Install Failed',html.data,activeInfo.settings.notifications.position,"#FFF","warning","10000");
+        }
+    }).fail(function(xhr) {
+        message('Install Failed',plugin.name,activeInfo.settings.notifications.position,"#FFF","warning","5000");
+        console.error("Organizr Function: Connection Failed");
+    });
+}
 function pluginStatus(name=null,version=null){
     var installedPlugins = [];
     var installedPluginsList = [];
@@ -1222,6 +1349,15 @@ function buildCustomizeAppearance(){
         javaEditor.session.on('change', function(delta) {
             $('.javaTextarea').val(javaEditor.getValue());
             $('#customize-appearance-form-save').removeClass('hidden');
+        });
+        javaThemeEditor = ace.edit("customThemeJavaEditor");
+        var JavaThemeMode = ace.require("ace/mode/javascript").Mode;
+        javaThemeEditor.session.setMode(new JavaThemeMode());
+        javaThemeEditor.setTheme("ace/theme/idle_fingers");
+        javaThemeEditor.setShowPrintMargin(false);
+        javaThemeEditor.session.on('change', function(delta) {
+            $('.javaThemeTextarea').val(javaThemeEditor.getValue());
+            $('#customize-appearance-form-save').removeClass('hidden');
         });
 		$("input.pick-a-color").ColorPickerSliders({
 			placement: 'bottom',
@@ -2501,12 +2637,15 @@ function loadAppearance(appearance){
 	if(cssSettings !== ''){
 		$('#user-appearance').html(cssSettings);
 	}
-	if(appearance.customCss !== ''){
-		$('#custom-css').html(appearance.customCss);
-	}
     if(appearance.customThemeCss !== ''){
         $('#custom-theme-css').html(appearance.customThemeCss);
     }
+    if(appearance.customCss !== ''){
+        $('#custom-css').html(appearance.customCss);
+    }
+    if(appearance.customThemeJava !== ''){
+        $('#custom-theme-javascript').html(appearance.customThemeJava);
+    }
     if(appearance.customJava !== ''){
         $('#custom-javascript').html(appearance.customJava);
     }

Some files were not shown because too many files changed in this diff