Browse Source

More custom homepage items (FR#202285)
version 2.1.525

CauseFX 4 năm trước cách đây
mục cha
commit
0a61ae81bd

+ 36 - 11
api/classes/organizr.class.php

@@ -60,7 +60,7 @@ class Organizr
 	
 	// ===================================
 	// Organizr Version
-	public $version = '2.1.496';
+	public $version = '2.1.525';
 	// ===================================
 	// Quick php Version check
 	public $minimumPHP = '7.3';
@@ -638,6 +638,14 @@ class Organizr
 				$this->upgradeToVersion($versionCheck);
 			}
 			// End Upgrade check start for version above
+			// Upgrade check start for version below
+			$versionCheck = '2.1.525';
+			if ($compare->lessThan($oldVer, $versionCheck)) {
+				$updateDB = false;
+				$oldVer = $versionCheck;
+				$this->upgradeToVersion($versionCheck);
+			}
+			// End Upgrade check start for version above
 			if ($updateDB == true) {
 				//return 'Upgraded Needed - Current Version '.$oldVer.' - New Version: '.$versionCheck;
 				// Upgrade database to latest version
@@ -817,6 +825,22 @@ class Organizr
 		return $this->createConfig($current);
 	}
 	
+	public function removeConfigItem($new, $current = false)
+	{
+		// Get config if not supplied
+		if ($current === false) {
+			$current = $this->config;
+		} elseif (is_string($current) && is_file($current)) {
+			$current = $this->loadConfig($current);
+		}
+		// Inject Parts
+		foreach ($new as $k) {
+			unset($current[$k]);
+		}
+		// Return Create
+		return $this->createConfig($current);
+	}
+	
 	public function loadConfig($path = null)
 	{
 		$path = ($path) ? $path : $this->userConfigPath;
@@ -4044,17 +4068,18 @@ class Organizr
 		$inputList = '<form id="homepage-values" class="row">';
 		foreach ($homepageOrder as $key => $val) {
 			switch ($key) {
-				case 'homepageOrdercustomhtml':
-					$class = 'bg-info';
-					$image = 'plugins/images/tabs/custom1.png';
-					if (!$this->config['homepageCustomHTMLoneEnabled']) {
-						$class .= ' faded';
-					}
-					break;
-				case 'homepageOrdercustomhtmlTwo':
+				case 'homepageOrdercustomhtml01':
+				case 'homepageOrdercustomhtml02':
+				case 'homepageOrdercustomhtml03':
+				case 'homepageOrdercustomhtml04':
+				case 'homepageOrdercustomhtml05':
+				case 'homepageOrdercustomhtml06':
+				case 'homepageOrdercustomhtml07':
+				case 'homepageOrdercustomhtml08':
+					$iteration = substr($key, -2);
 					$class = 'bg-info';
-					$image = 'plugins/images/tabs/custom2.png';
-					if (!$this->config['homepageCustomHTMLtwoEnabled']) {
+					$image = 'plugins/images/tabs/HTML5.png';
+					if (!$this->config['homepageCustomHTML' . $iteration . 'Enabled']) {
 						$class .= ' faded';
 					}
 					break;

+ 32 - 8
api/config/default.php

@@ -180,10 +180,30 @@ return array(
 	'homepageCalendarEnabled' => false,
 	'homepageCalendarAuth' => '4',
 	'calendariCal' => '',
-	'homepageCustomHTMLoneEnabled' => false,
-	'homepageCustomHTMLoneAuth' => '1',
-	'homepageCustomHTMLtwoEnabled' => false,
-	'homepageCustomHTMLtwoAuth' => '1',
+	'homepageCustomHTML01Enabled' => false,
+	'homepageCustomHTML01Auth' => '1',
+	'customHTML01' => '',
+	'homepageCustomHTML02Enabled' => false,
+	'homepageCustomHTML02Auth' => '1',
+	'customHTML02' => '',
+	'homepageCustomHTML03Enabled' => false,
+	'homepageCustomHTML03Auth' => '1',
+	'customHTML03' => '',
+	'homepageCustomHTML04Enabled' => false,
+	'homepageCustomHTML04Auth' => '1',
+	'customHTML04' => '',
+	'homepageCustomHTML05Enabled' => false,
+	'homepageCustomHTML05Auth' => '1',
+	'customHTML05' => '',
+	'homepageCustomHTML06Enabled' => false,
+	'homepageCustomHTML06Auth' => '1',
+	'customHTML06' => '',
+	'homepageCustomHTML07Enabled' => false,
+	'homepageCustomHTML07Auth' => '1',
+	'customHTML07' => '',
+	'homepageCustomHTML08Enabled' => false,
+	'homepageCustomHTML08Auth' => '1',
+	'customHTML08' => '',
 	'homepageDelugeEnabled' => false,
 	'homepageDelugeAuth' => '1',
 	'homepageJdownloaderEnabled' => false,
@@ -248,8 +268,8 @@ return array(
 	'homepageHealthChecksShowTags' => false,
 	'healthChecksDisableCertCheck' => false,
 	'healthChecksUseCustomCertificate' => false,
-	'homepageOrdercustomhtml' => '1',
-	'homepageOrdercustomhtmlTwo' => '2',
+	'homepageOrdercustomhtml01' => '1',
+	'homepageOrdercustomhtml02' => '2',
 	'homepageOrdertransmission' => '3',
 	'homepageOrderqBittorrent' => '4',
 	'homepageOrderdeluge' => '5',
@@ -279,6 +299,12 @@ return array(
 	'homepageOrderjellyfinnowplaying' => '29',
 	'homepageOrderjellyfinrecent' => '30',
 	'homepageOrderJackett' => '31',
+	'homepageOrdercustomhtml03' => '32',
+	'homepageOrdercustomhtml04' => '33',
+	'homepageOrdercustomhtml05' => '34',
+	'homepageOrdercustomhtml06' => '35',
+	'homepageOrdercustomhtml07' => '36',
+	'homepageOrdercustomhtml08' => '37',
 	'homepageShowStreamNames' => false,
 	'homepageShowStreamNamesAuth' => '1',
 	'homepageUseCustomStreamNames' => false,
@@ -317,8 +343,6 @@ return array(
 	'calendarLocale' => 'en',
 	'customCss' => '',
 	'customThemeCss' => '',
-	'customHTMLone' => '',
-	'customHTMLtwo' => '',
 	'mediaSearch' => false,
 	'mediaSearchType' => '',
 	'mediaSearchAuth' => '1',

+ 1 - 1
api/functions/option-functions.php

@@ -257,7 +257,7 @@ trait OptionsFunction
 					'type' => 'html',
 					'override' => 12,
 					'label' => 'Custom Code',
-					'html' => '<button type="button" class="hidden save' . $name . 'Textarea btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="' . $name . 'Editor" style="height:300px">' . htmlentities($this->config[$name]) . '</div>'
+					'html' => '<div id="' . $name . 'Editor" style="height:300px">' . htmlentities($this->config[$name]) . '</div>'
 				];
 				break;
 			// CALENDAR ITEMS

+ 48 - 0
api/functions/upgrade-functions.php

@@ -10,6 +10,8 @@ trait UpgradeFunctions
 				$this->upgradeHomepageTabURL();
 			case '2.1.400':
 				$this->removeOldPluginDirectoriesAndFiles();
+			case '2.1.525':
+				$this->removeOldCustomHTML();
 			default:
 				$this->setAPIResponse('success', 'Ran update function for version: ' . $version, 200);
 				return true;
@@ -77,4 +79,50 @@ trait UpgradeFunctions
 		}
 		return true;
 	}
+	
+	public function removeOldCustomHTML()
+	{
+		$updateItems = [];
+		if ($this->config['homepageCustomHTMLoneEnabled']) {
+			if ($this->config['homepageCustomHTMLoneEnabled'] !== '') {
+				$updateItemsNew = ['homepageCustomHTML01Enabled' => $this->config['homepageCustomHTMLoneEnabled']];
+				$updateItems = array_merge($updateItems, $updateItemsNew);
+			}
+		}
+		if ($this->config['homepageCustomHTMLoneAuth']) {
+			if ($this->config['homepageCustomHTMLoneAuth'] !== '') {
+				$updateItemsNew = ['homepageCustomHTML01Auth' => $this->config['homepageCustomHTMLoneAuth']];
+				$updateItems = array_merge($updateItems, $updateItemsNew);
+			}
+		}
+		if ($this->config['customHTMLone']) {
+			if ($this->config['customHTMLone'] !== '') {
+				$updateItemsNew = ['customHTML01' => $this->config['customHTMLone']];
+				$updateItems = array_merge($updateItems, $updateItemsNew);
+			}
+		}
+		if ($this->config['homepageCustomHTMLtwoEnabled']) {
+			if ($this->config['homepageCustomHTMLtwoEnabled'] !== '') {
+				$updateItemsNew = ['homepageCustomHTML02Enabled' => $this->config['homepageCustomHTMLtwoEnabled']];
+				$updateItems = array_merge($updateItems, $updateItemsNew);
+			}
+		}
+		if ($this->config['homepageCustomHTMLtwoAuth']) {
+			if ($this->config['homepageCustomHTMLtwoAuth'] !== '') {
+				$updateItemsNew = ['homepageCustomHTML02Auth' => $this->config['homepageCustomHTMLtwoAuth']];
+				$updateItems = array_merge($updateItems, $updateItemsNew);
+			}
+		}
+		if ($this->config['customHTMLtwo']) {
+			if ($this->config['customHTMLtwo'] !== '') {
+				$updateItemsNew = ['customHTML02' => $this->config['customHTMLtwo']];
+				$updateItems = array_merge($updateItems, $updateItemsNew);
+			}
+		}
+		if (!empty($updateItems)) {
+			$this->updateConfig($updateItems);
+		}
+		$this->removeConfigItem(['homepageOrdercustomhtml', 'homepageOrdercustomhtmlTwo', 'homepageCustomHTMLoneEnabled', 'homepageCustomHTMLoneAuth', 'customHTMLone', 'homepageCustomHTMLtwoEnabled', 'homepageCustomHTMLtwoAuth', 'customHTMLtwo']);
+		return true;
+	}
 }

+ 95 - 62
api/homepage/html.php

@@ -2,40 +2,17 @@
 
 trait HTMLHomepageItem
 {
-	public function htmlOneSettingsArray($infoOnly = false)
+	public function customHtmlNumber()
 	{
-		$homepageInformation = [
-			'name' => 'CustomHTML-1',
-			'enabled' => strpos('personal,business', $this->config['license']) !== false,
-			'image' => 'plugins/images/tabs/custom1.png',
-			'category' => 'Custom',
-			'settingsArray' => __FUNCTION__
-		];
-		if ($infoOnly) {
-			return $homepageInformation;
-		}
-		$homepageSettings = [
-			'debug' => true,
-			'settings' => [
-				'Enable' => [
-					$this->settingsOption('enable', 'homepageCustomHTMLoneEnabled'),
-					$this->settingsOption('auth', 'homepageCustomHTMLoneAuth'),
-				],
-				'Code' => [
-					$this->settingsOption('pre-code-editor', 'customHTMLone'),
-					$this->settingsOption('code-editor', 'customHTMLone'),
-				]
-			]
-		];
-		return array_merge($homepageInformation, $homepageSettings);
+		return 8;
 	}
 	
-	public function htmlTwoSettingsArray($infoOnly = false)
+	public function customHtmlSettingsArray($infoOnly = false)
 	{
 		$homepageInformation = [
-			'name' => 'CustomHTML-2',
+			'name' => 'CustomHTML',
 			'enabled' => strpos('personal,business', $this->config['license']) !== false,
-			'image' => 'plugins/images/tabs/custom2.png',
+			'image' => 'plugins/images/tabs/HTML5.png',
 			'category' => 'Custom',
 			'settingsArray' => __FUNCTION__
 		];
@@ -44,46 +21,36 @@ trait HTMLHomepageItem
 		}
 		$homepageSettings = [
 			'debug' => true,
-			'settings' => [
-				'Enable' => [
-					$this->settingsOption('enable', 'homepageCustomHTMLtwoEnabled'),
-					$this->settingsOption('auth', 'homepageCustomHTMLtwoAuth'),
-				],
-				'Code' => [
-					$this->settingsOption('pre-code-editor', 'customHTMLtwo'),
-					$this->settingsOption('code-editor', 'customHTMLtwo'),
-				]
-			]
+			'settings' => []
 		];
+		for ($i = 1; $i <= $this->customHtmlNumber(); $i++) {
+			$i = sprintf('%02d', $i);
+			$homepageSettings['settings']['Custom HTML ' . $i] = array(
+				$this->settingsOption('enable', 'homepageCustomHTML' . $i . 'Enabled'),
+				$this->settingsOption('auth', 'homepageCustomHTML' . $i . 'Auth'),
+				$this->settingsOption('pre-code-editor', 'customHTML' . $i),
+				$this->settingsOption('code-editor', 'customHTML' . $i, ['label' => 'Custom HTML Code']),
+			);
+		}
 		return array_merge($homepageInformation, $homepageSettings);
 	}
 	
 	public function htmlHomepagePermissions($key = null)
 	{
-		$permissions = [
-			'one' => [
+		for ($i = 1; $i <= $this->customHtmlNumber(); $i++) {
+			$i = sprintf('%02d', $i);
+			$permissions[$i] = [
 				'enabled' => [
-					'homepageCustomHTMLoneEnabled'
+					'homepageCustomHTML' . $i . 'Enabled'
 				],
 				'auth' => [
-					'homepageCustomHTMLoneAuth'
+					'homepageCustomHTML' . $i . 'Auth'
 				],
 				'not_empty' => [
-					'customHTMLone'
+					'customHTML' . $i
 				]
-			],
-			'two' => [
-				'enabled' => [
-					'homepageCustomHTMLtwoEnabled'
-				],
-				'auth' => [
-					'homepageCustomHTMLtwoAuth'
-				],
-				'not_empty' => [
-					'customHTMLtwo'
-				]
-			]
-		];
+			];
+		}
 		if (array_key_exists($key, $permissions)) {
 			return $permissions[$key];
 		} elseif ($key == 'all') {
@@ -93,23 +60,89 @@ trait HTMLHomepageItem
 		}
 	}
 	
-	public function homepageOrdercustomhtml()
+	public function homepageOrdercustomhtml01()
+	{
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('01'))) {
+			return '
+				<div id="' . __FUNCTION__ . '">
+					' . $this->config['customHTML01'] . '
+				</div>
+				';
+		}
+	}
+	
+	public function homepageOrdercustomhtml02()
+	{
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('02'))) {
+			return '
+				<div id="' . __FUNCTION__ . '">
+					' . $this->config['customHTML02'] . '
+				</div>
+				';
+		}
+	}
+	
+	public function homepageOrdercustomhtml03()
+	{
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('03'))) {
+			return '
+				<div id="' . __FUNCTION__ . '">
+					' . $this->config['customHTML03'] . '
+				</div>
+				';
+		}
+	}
+	
+	public function homepageOrdercustomhtml04()
+	{
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('04'))) {
+			return '
+				<div id="' . __FUNCTION__ . '">
+					' . $this->config['customHTML04'] . '
+				</div>
+				';
+		}
+	}
+	
+	public function homepageOrdercustomhtml05()
+	{
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('05'))) {
+			return '
+				<div id="' . __FUNCTION__ . '">
+					' . $this->config['customHTML05'] . '
+				</div>
+				';
+		}
+	}
+	
+	public function homepageOrdercustomhtml06()
+	{
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('06'))) {
+			return '
+				<div id="' . __FUNCTION__ . '">
+					' . $this->config['customHTML06'] . '
+				</div>
+				';
+		}
+	}
+	
+	public function homepageOrdercustomhtml07()
 	{
-		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('one'))) {
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('07'))) {
 			return '
 				<div id="' . __FUNCTION__ . '">
-					' . $this->config['customHTMLone'] . '
+					' . $this->config['customHTML07'] . '
 				</div>
 				';
 		}
 	}
 	
-	public function homepageOrdercustomhtmlTwo()
+	public function homepageOrdercustomhtml08()
 	{
-		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('two'))) {
+		if ($this->homepageItemPermissions($this->htmlHomepagePermissions('08'))) {
 			return '
 				<div id="' . __FUNCTION__ . '">
-					' . $this->config['customHTMLtwo'] . '
+					' . $this->config['customHTML08'] . '
 				</div>
 				';
 		}

+ 0 - 6
js/custom.js

@@ -1064,12 +1064,6 @@ $(document).on("click", ".saveJava", function () {
 $(document).on("click", ".saveThemeJava", function () {
     $('.javaThemeTextarea').val(javaThemeEditor.getValue()).trigger('change');
 });
-$(document).on("click", ".savecustomHTMLoneTextarea", function () {
-    $('.customHTMLoneTextarea').val(customHTMLoneEditor.getValue()).trigger('change');
-});
-$(document).on("click", ".savecustomHTMLtwoTextarea", function () {
-    $('.customHTMLtwoTextarea').val(customHTMLtwoEditor.getValue()).trigger('change');
-});
 
 $(document).on('focusout', 'input.pick-a-color-custom-options', function(e) {
     var original = $(this).attr('data-original');

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
js/custom.min.js


+ 19 - 22
js/functions.js

@@ -23,6 +23,7 @@ var tabInformation = {};
 var tabActionsList = [];
 tabActionsList['refresh'] = [];
 tabActionsList['close'] = [];
+var customHTMLEditorObject = [];
 $.xhrPool = [];
 // Add new jquery serializeObject function
 $.fn.serializeObject = function()
@@ -1722,27 +1723,23 @@ function homepageItemFormHTML(v){
 function clearHomepageOriginal(){
 	$('#editHomepageItem').html('');
 }
-function completeHomepageLoad(item){
-	if(item == 'CustomHTML-1'){
-		customHTMLoneEditor = ace.edit("customHTMLoneEditor");
-		let HTMLMode = ace.require("ace/mode/html").Mode;
-		customHTMLoneEditor.session.setMode(new HTMLMode());
-		customHTMLoneEditor.setTheme("ace/theme/idle_fingers");
-		customHTMLoneEditor.setShowPrintMargin(false);
-		customHTMLoneEditor.session.on('change', function(delta) {
-			$('.customHTMLoneTextarea').val(customHTMLoneEditor.getValue());
-			$('#homepage-CustomHTML-1-form-save').removeClass('hidden');
-		});
-	}
-	if(item == 'CustomHTML-2'){
-		customHTMLtwoEditor = ace.edit("customHTMLtwoEditor");
-		let HTMLMode = ace.require("ace/mode/html").Mode;
-		customHTMLtwoEditor.session.setMode(new HTMLMode());
-		customHTMLtwoEditor.setTheme("ace/theme/idle_fingers");
-		customHTMLtwoEditor.setShowPrintMargin(false);
-		customHTMLtwoEditor.session.on('change', function(delta) {
-			$('.customHTMLtwoTextarea').val(customHTMLtwoEditor.getValue());
-			$('#homepage-CustomHTML-2-form-save').removeClass('hidden');
+function completeHomepageLoad(item, data){
+	if(item == 'CustomHTML'){
+		let iteration = 0;
+		$.each(data.settings, function(i,customItem) {
+			let iterationString = (parseInt(iteration, 10) + 101).toString().substr(1);
+			let customEditor = 'customHTML'+iterationString+'Editor';
+			let customTextarea = 'customHTML'+iterationString+'Textarea';
+			let HTMLMode = ace.require("ace/mode/html").Mode;
+			customHTMLEditorObject[iterationString] = ace.edit(customEditor);
+			customHTMLEditorObject[iterationString].session.setMode(new HTMLMode());
+			customHTMLEditorObject[iterationString].setTheme("ace/theme/idle_fingers");
+			customHTMLEditorObject[iterationString].setShowPrintMargin(false);
+			customHTMLEditorObject[iterationString].session.on('change', function(delta) {
+				$('.' + customTextarea).val(customHTMLEditorObject[iterationString].getValue());
+				$('#homepage-CustomHTML-form-save').removeClass('hidden');
+			});
+			iteration++;
 		});
 	}
 	pageLoad();
@@ -1775,7 +1772,7 @@ function editHomepageItem(item){
 					delay: 0,
 					fullscreen: true,
 					clone: false,
-					onComplete: completeHomepageLoad(item),
+					onComplete: completeHomepageLoad(item, response.data),
 					onClose: clearHomepageOriginal
 				},loader:{active:true}
 			}).open();

+ 7 - 0
js/version.json

@@ -418,5 +418,12 @@
     "new": "Self Signed SSL Cert option to all homepage items (#1177)|shortcut function for menu clicking - WIP",
     "fixed": "move google js to load only when config value setup (#1699)|tooltips to homepage settings ui buttons|First IPA typo to Free IPA|typo and sort LDAP options|now playing spacing",
     "notes": ""
+  },
+  "2.1.525": {
+    "date": "2021-08-29 21:40",
+    "title": "Added more Custom HTML homepage items",
+    "new": "",
+    "fixed": "",
+    "notes": ""
   }
 }

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác