Browse Source

Use settings

Tim Fry 4 tháng trước cách đây
mục cha
commit
6861518d53
2 tập tin đã thay đổi với 25 bổ sung35 xóa
  1. 7 20
      file_list.php
  2. 18 15
      index.php

+ 7 - 20
file_list.php

@@ -106,13 +106,13 @@
 	if (!isset($_SESSION)) { session_start(); }
 	if (!isset($_SESSION)) { session_start(); }
 	switch ($_SESSION["app"]["edit"]["dir"]) {
 	switch ($_SESSION["app"]["edit"]["dir"]) {
 		case 'scripts':
 		case 'scripts':
-			$edit_directory = $_SESSION['switch']['scripts']['dir'];
+			$edit_directory = $settings->get('switch', 'scripts');
 			break;
 			break;
 		case 'php':
 		case 'php':
-			$edit_directory = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH;
+			$edit_directory = dirname(__DIR__, 2);
 			break;
 			break;
 		case 'grammar':
 		case 'grammar':
-			$edit_directory = $_SESSION['switch']['grammar']['dir'];
+			$edit_directory = $settings->get('switch', 'grammar');
 			break;
 			break;
 		case 'provision':
 		case 'provision':
 			switch (PHP_OS) {
 			switch (PHP_OS) {
@@ -159,19 +159,13 @@
 			}
 			}
 			break;
 			break;
 		case 'xml':
 		case 'xml':
-			$edit_directory = $_SESSION['switch']['conf']['dir'];
+			$edit_directory = $settings->get('switch', 'conf');
 			break;
 			break;
-	}
-	if (!isset($edit_directory) && is_array($_SESSION['editor']['path'])) {
-		foreach ($_SESSION['editor']['path'] as $path) {
-			if ($_SESSION["app"]["edit"]["dir"] == $path) {
-				$edit_directory = $path;
-				break;
-			}
-		}
+		default:
+			//do not allow unknown settings
+			exit();
 	}
 	}
 
 
-
 // keyboard shortcut bindings
 // keyboard shortcut bindings
 echo "<script src='".PROJECT_PATH."/resources/jquery/jquery-3.6.1.min.js'></script>\n";
 echo "<script src='".PROJECT_PATH."/resources/jquery/jquery-3.6.1.min.js'></script>\n";
 echo "<script src='https://code.jquery.com/jquery-migrate-3.1.0.js'></script>\n";
 echo "<script src='https://code.jquery.com/jquery-migrate-3.1.0.js'></script>\n";
@@ -190,17 +184,10 @@ echo "<body style='margin: 0px; padding: 5px;'>\n";
 
 
 echo "<div style='text-align: left; padding-top: 3px; padding-bottom: 3px;'><a href='javascript:void(0);' onclick=\"window.open('file_options.php','filewin','left=20,top=20,width=310,height=350,toolbar=0,resizable=0');\" style='text-decoration:none;' title='".$text['label-files']."'><img src='resources/images/icon_gear.png' border='0' align='absmiddle' style='margin: 0px 2px 4px -1px;'>".$text['label-files']."</a></div>\n";
 echo "<div style='text-align: left; padding-top: 3px; padding-bottom: 3px;'><a href='javascript:void(0);' onclick=\"window.open('file_options.php','filewin','left=20,top=20,width=310,height=350,toolbar=0,resizable=0');\" style='text-decoration:none;' title='".$text['label-files']."'><img src='resources/images/icon_gear.png' border='0' align='absmiddle' style='margin: 0px 2px 4px -1px;'>".$text['label-files']."</a></div>\n";
 echo "<div style='text-align: left; margin-left: -16px;'>\n";
 echo "<div style='text-align: left; margin-left: -16px;'>\n";
-if (function_exists('apcu_enabled') && apcu_enabled() && apcu_exists('edit_html_list')) {
-	echo apcu_fetch('edit_html_list');
-	exit();
-}
 
 
 if (file_exists($edit_directory)) {
 if (file_exists($edit_directory)) {
 	$edit_html_list = recur_dir($edit_directory);
 	$edit_html_list = recur_dir($edit_directory);
 
 
-	if (function_exists('apcu_enabled') && apcu_enabled()) {
-		apcu_store('edit_html_list', $edit_html_list); // only available for 5 minutes
-	}
 	echo $edit_html_list;
 	echo $edit_html_list;
 }
 }
 
 

+ 18 - 15
index.php

@@ -43,46 +43,49 @@
 	$text = $language->get();
 	$text = $language->get();
 
 
 //set the directory title and mode
 //set the directory title and mode
-	$_SESSION["app"]["edit"]["dir"] = $_GET["dir"];
-	$title = escape($_GET["dir"]);
-	unset($mode);
 	switch ($_GET["dir"]) {
 	switch ($_GET["dir"]) {
 		case 'xml':
 		case 'xml':
 			$title = 'XML';
 			$title = 'XML';
 			$mode = 'xml';
 			$mode = 'xml';
+			$dir = 'xml';
 			break;
 			break;
 		case 'provision':
 		case 'provision':
 			$title = 'Provision';
 			$title = 'Provision';
 			$mode = 'xml';
 			$mode = 'xml';
+			$dir = 'provision';
 			break;
 			break;
 		case 'php':
 		case 'php':
 			$title = 'PHP';
 			$title = 'PHP';
 			$mode = 'php';
 			$mode = 'php';
+			$dir = 'php';
 			break;
 			break;
 		case 'scripts':
 		case 'scripts':
 			$title = 'Scripts';
 			$title = 'Scripts';
 			$mode = 'lua';
 			$mode = 'lua';
+			$dir = 'scripts';
 			break;
 			break;
 		case 'grammar':
 		case 'grammar':
 			$title = 'Grammar';
 			$title = 'Grammar';
 			$mode = 'xml';
 			$mode = 'xml';
-		default: $mode = 'text';
+			$dir = 'grammar';
+			break;
+		default:
+			$mode = 'text';
+			$dir = '';
 	}
 	}
 
 
+//save the sanitized value
+	$_SESSION['app']['edit']['dir'] = $dir;
+
 //load editor preferences/defaults
 //load editor preferences/defaults
-	$setting_size = !empty($_SESSION["editor"]["font_size"]["text"]) ? $_SESSION["editor"]["font_size"]["text"] : '12px';
-	$setting_theme = !empty($_SESSION["editor"]["theme"]["text"]) ? $_SESSION["editor"]["theme"]["text"] : 'cobalt';
-	$setting_invisibles = isset($_SESSION['editor']['invisibles']['text']) ? $_SESSION['editor']['invisibles']["text"] : 'false';
-	$setting_indenting = isset($_SESSION['editor']['indent_guides']['text']) ? $_SESSION['editor']['indent_guides']["text"]: 'false';
-	$setting_numbering = isset($_SESSION['editor']['line_numbers']['text']) ? $_SESSION['editor']['line_numbers']["text"] : 'true';
+	$setting_size       = $settings->get('editor', 'font_size', '12px');
+	$setting_theme      = $settings->get('editor', 'theme', 'cobalt');
+	$setting_invisibles = $settings->get('editor', 'invisibles','false');
+	$setting_indenting  = $settings->get('editor', 'indent_guides','false');
+	$setting_numbering  = $settings->get('editor', 'line_numbers','true');
 
 
 //get and then set the favicon
 //get and then set the favicon
-	if (isset($_SESSION['theme']['favicon']['text'])){
-		$favicon = $_SESSION['theme']['favicon']['text'];
-	}
-	else {
-		$favicon = PROJECT_ROOT .'/themes/default/favicon.ico';
-	}
+	$favicon = $settings->get('theme', 'favicon', PROJECT_ROOT .'/themes/default/favicon.ico');
 
 
 //create a token
 //create a token
 	$key_name = '/app/edit/'.$mode;
 	$key_name = '/app/edit/'.$mode;