瀏覽代碼

Added WIP NotepadA module

Toby Chui 3 年之前
父節點
當前提交
dc97ed9d86

+ 1 - 1
web/Code Studio/init.agi

@@ -1,5 +1,5 @@
 /*
-	NotepadA Module Registration Information
+	Code Studio Module Registration Information
 	
 	Do not try to call any AJGI users / filepath functions in this script.
 */

+ 80 - 120
web/NotepadA/ace/editor.php → web/NotepadA/ace/editor.html

@@ -1,138 +1,94 @@
-<?php
-/*NotepadA editor.php
-Special modification was made to the script and make the ace editor to work with AOB system.
-This is just part of the system and require php scripts outside this folder to work.
-
-** DO NOT EDIT THIS PAGE WITH NOTEPADA ONLINE EDITOR. **
-** DO NOT EDIT THIS PAGE WITH NOTEPADA ONLINE EDITOR. **
-** DO NOT EDIT THIS PAGE WITH NOTEPADA ONLINE EDITOR. **
-
-*/
-include '../../auth.php';
-?>
 <!DOCTYPE html>
 <html lang="en">
 <!-- Special modification for NotepadA system, ArOZ Online Beta-->
 <head>
-<?php
-//Init of the editor
-function mv($var){
-	if (isset($_GET[$var]) == true && $_GET[$var] != ""){
-		return $_GET[$var];
-	}else{
-		return "";
-	}
-}
-//Default value
-$filename = "";
-$displayName = "";
-$fileExt = "";
-$theme = "tomorrow_night";
-$mode = "php";
-$fontsize = "12"; 
-//check if a correct filename has been provided
-if (mv("filename") != ""){
-	//Editing an existed file
-	$filename = mv("filename");
-	if (file_exists(dirname($filename)) == false){
-		//If the file that should be containing this file is not fonund
-		echo "<code>Requested Directory: " . dirname($filename) . '<br>';
-		echo "<script src='../../script/jquery.min.js'></script><script>$('body').css('background-color','white');function checkIsSaved(){return true;}</script>";
-		$date   = new DateTime(); //this returns the current date time
-		$result = $date->format('Y-m-d H:i:s');
-		die("Error. Target folder was not found on the host device. Please close this tab and reopen if needed.<br><br><hr>Request Time: " . $result . '</code>');
-	}
-	
-	if (!file_exists($filename)){
-		//File not found, creating a new one instead
-		$file = fopen($filename, 'w') or die('Error opening file: ' + $filename); 
-		fclose($file); 
-	}
-	$displayName = $filename;
-	$fileExt = pathinfo($filename, PATHINFO_EXTENSION);
-	//Handle the AOB Upload Manger type of naming methods
-	if (substr($filename,0,5) == "inith"){
-		$nameOnly = basename($filename, "." . $fileExt);
-		$nameOnly = str_replace("inith","",$nameOnly);
-		$displayName = hex2bin($nameOnly) . "." . $fileExt . " (Encoded Filename)";
-	}else{
-		$displayName = basename($filename);
-	}
-	//Set the mode of the editor to the extension of the file, but something this might be incorrect.
-	$mode = $fileExt;
-}else{
-	//Creating a new file instead
-	$filename = "";
-	$displayName = "untitled";
-}
-
-if (mv("theme") != ""){
-	$theme = mv("theme");
-}
-
-if (mv("fontsize") != ""){
-	$fontsize = mv("fontsize");
-}
-
+	<meta charset="UTF-8">
+	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+	<title id='pageTitle'>NotepadA - Loading</title>
+	<script src='../../script/jquery.min.js'></script>
+	<script>
+		$('body').css('background-color','white');
+		function checkIsSaved(){
+			return true;
+		}
+	</script>
+	<script src="../../script/jquery.min.js"></script>
+	<style type="text/css" media="screen">
+		body {
+			overflow: hidden;
+			padding-bottom:5px;
+			background-color:#2b2b2b;
+		}
 
-?>
-  <meta charset="UTF-8">
-  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-  <title><?php echo "Editing " . $displayName;?></title>
-  <script src="../../script/jquery.min.js"></script>
-  <style type="text/css" media="screen">
-    body {
-        overflow: hidden;
-		padding-bottom:5px;
-		background-color:#2b2b2b;
-    }
+		#editor {
+			margin: 0;
+			position: absolute;
+			top: 0;
+			bottom: 15px;
+			left: 0;
+			right: 0;
+		}
 
-    #editor {
-        margin: 0;
-        position: absolute;
-        top: 0;
-        bottom: 15px;
-        left: 0;
-        right: 0;
-    }
-	
-  </style>
+	</style>
 </head>
 <body>
-<pre id="editor"><?php
-	if ($filename != ""){
-		echo str_replace("<","&lt;",file_get_contents($filename));
-	}
-
-?></pre>
+<pre id="editor"></pre>
 
 <script src="src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
 <script>
-	var filename = "<?php echo $filename;?>";
-	var filepath = "<?php echo str_replace("\\",'/',realpath($filename));?>";
+	//Get the filename, path and other information from the hash
+	var filename = "";
+	var filepath = "";
 	var lastSave = "";
-	//Init editor
-    var editor = ace.edit("editor");
-    editor.setTheme("ace/theme/<?php echo $theme;?>");
-	var detectMode = getMode(filepath);
-	//console.log("[NotepadA] Chaning mode to " + detectMode.toLowerCase());
-	if ( detectMode != undefined){
-		editor.session.setMode("ace/mode/" + detectMode.toLowerCase());
-		
+	var fontsize = 12;
+	var theme = "github";
+
+	var editor;
+
+	if (window.location.hash.length > 0){
+		var payload = window.location.hash.substr(1);
+		payload = JSON.parse(decodeURIComponent(payload));
+		filepath = payload.filename;
+		let basename = payload.filename.split("/").pop();
+		filename = basename;
+		fontsize = payload.fontsize;
+		theme = payload.theme;
+
+		console.log("NotepadA editor loaded: ", payload);
+
+		//Load the content of the file
+		$.get("../../media?file=" + filepath, function(fileContent){
+			$("#editor").html(fileContent);
+
+			//Start the editor
+			StartEditor();
+		});
 	}else{
-		//Default mode: php
-		editor.session.setMode("ace/mode/php");
+		alert("Invalid use of editor!")
 	}
-	editor.setOptions({
-	  //fontFamily: "tahoma",
-	  fontSize: "<?php echo $fontsize;?>pt"
-	});
-	
-	$(document).ready(function(){
-		//Initial assume saved
+
+	function StartEditor(){
+		//Init editor
+		editor = ace.edit("editor");
+		editor.setTheme("ace/theme/" + theme);
+		var detectMode = getMode(filepath);
+		//console.log("[NotepadA] Chaning mode to " + detectMode.toLowerCase());
+		if ( detectMode != undefined){
+			editor.session.setMode("ace/mode/" + detectMode.toLowerCase());
+			
+		}else{
+			//Default mode: php
+			editor.session.setMode("ace/mode/php");
+		}
+		editor.setOptions({
+			//fontFamily: "tahoma",
+			fontSize: fontsize + "pt"
+		});
+
 		lastSave = editor.getValue();
-		
-	});
+	}
+	
+	
 	//Listener for Ctrl+S
 	$(window).keypress(function(event) {
 		if (!(event.which == 115 && event.ctrlKey) && !(event.which == 19)) return true;
@@ -181,6 +137,10 @@ if (mv("fontsize") != ""){
 	}
 	
 	function checkIsSaved(){
+		if (typeof(editor) == "undefined"){
+			//Editor not started
+			return
+		}
 		if (lastSave ==  editor.getValue()){
 			return true;
 		}else{

二進制
web/NotepadA/img/desktop_icon.png


二進制
web/NotepadA/img/desktop_icon.psd


+ 0 - 0
web/NotepadA/img/function_icon.png → web/NotepadA/img/function_icon_legacy.png


二進制
web/NotepadA/img/icon.png


二進制
web/NotepadA/img/icon.psd


二進制
web/NotepadA/img/small_icon.png


二進制
web/NotepadA/img/small_icon.psd


+ 26 - 131
web/NotepadA/index.php → web/NotepadA/index.html

@@ -1,9 +1,3 @@
-<?php
-include_once '../auth.php';
-if (!file_exists("tmp")){
-	mkdir("tmp",0777,true);
-}
-?>
 <!DOCTYPE html>
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <html lang="en">
@@ -71,7 +65,7 @@ if (!file_exists("tmp")){
 		display:inline;
 		padding-left: 8px;
 		padding-right: 1px;
-		marign-left:1px;
+		margin-left:1px;
 		height:25px;
 		border-bottom: 3px solid #878787;
 		cursor: pointer;
@@ -189,7 +183,6 @@ if (!file_exists("tmp")){
 	<button onClick="startTooggleMenu(this);">File</button>
 	<button onClick="startTooggleMenu(this);">Edit</button>
 	<button onClick="startTooggleMenu(this);">Search</button>
-	<button onClick="startTooggleMenu(this);">Utils</button>
 	<button onClick="startTooggleMenu(this);">Theme</button>
 	<button onClick="startTooggleMenu(this);">Font_Size</button>
 	<button onClick="startTooggleMenu(this);">About</button>
@@ -285,21 +278,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
 	<hr>
 	<button style="background-color:white;border: 1px solid #707070;" onClick="$('#specialCharInsert').hide();">Close</button><p style="font-size:50%;display:inline-block;padding-left:20px;" id="scid">N/A</p>
 </div>
-<?php
-	$draginFilePath = "";
-	if (isset($_GET['filepath'])){
-		$rootRealPath = str_replace("\\","/",realpath("../")). "/";
-		if (file_exists($_GET['filepath']) == false){
-			$_GET['filepath'] = "../" . $_GET['filepath'];
-		}
-		$fileRealPath = str_replace("\\","/",realpath($_GET['filepath']));
-		$draginFilePath = str_replace($rootRealPath,"",$fileRealPath);
-		echo $_GET['filepath'];
-	}
-?>
 <script>
 //Global variables
-var dragIn = "<?php echo $draginFilePath;?>";
+var dragIn = "";
 var theme = 'github';
 var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
 var is_safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
@@ -307,7 +288,7 @@ var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox')
 var lastSelectedMenuItem = "";
 var username = loadStorage("ArOZusername");
 var fontsize = 12;
-var VDI = !(!parent.isFunctionBar);
+var VDI = ao_module_virtualDesktop;
 var openedFilePath = [];
 var previousSavedState = true;
 var currentSaveAsPath = "";
@@ -318,7 +299,6 @@ var functionList = {
 	File: ["📄 New","📂 Open File","Run in FloatWindow","Open current directory","Reload","💾 Save","💾 Save As","Close All Tabs","🖨 Print","Exit"],
 	Edit: ["⤺ Undo","⤻ Redo","Open in New Tab","Insert Special Characters"],
 	Search:["Find / Replace"],
-	Utils:["🗃 Open Cache folder","🎨 Color Picker","📱 Mobile Preview","📔 CSS Document","📘 System Icons","🏗 gcc Builder"],
 	Theme:["ambiance","chaos","chrome","clouds","clouds_midnight","cobalt","crimson_editor","dawn","dracula","dreamweaver","eclipse","github","gob","gruvbox","idle_fingers","iplastic","katzenmilch","kr_theme","kuroir","merbivore","merbivore_soft","mono_industrial","monokai","pastel_on_dark","solarized_dark","solarized_light","sqlserver","terminal","textmate","tomorrow","tomorrow_night","tomorrow_night_blue","tomorrow_night_bright","tomorrow_night_eighties","twilight","vibrant_ink","xcode"],
 	Font_Size:["8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"],
 	About:["About NotepadA"]
@@ -340,8 +320,6 @@ function initNotepadA(){
 		$(".topbar").css("padding-left","0px");
 	}
 	
-	ao_module_setGlassEffectMode()
-	ao_module_setWindowIcon("code");
 	//ao_module_setWindowSize(1080,600);
 	if (loadStorage("NotepadA_" + username + "_sessionFiles") != ""){
 		var pages = JSON.parse(loadStorage("NotepadA_" + username + "_sessionFiles"));
@@ -405,27 +383,18 @@ function newEditor(filepath){
         return;
     }
 	let tabid = Math.round((new Date()).getTime());
-	var fileInternalIdentifier = "../../";
-	var external = false;
-	if (filepath.substring(0,14) == "/media/storage"){
-		//This file is stored in external stoarge path. Use real path instead.
-		fileInternalIdentifier = "";
-		external = true;
-	}else if (filepath.includes("SystemAOB/functions/extDiskAccess.php?file=")){
-		
-		//This file is opened using file explorer and it has attached an opener with the file.
-		filepath = filepath.replace("SystemAOB/functions/extDiskAccess.php?file=","");
-		external = true;
+	let payload = {
+		"theme": theme,
+		"filename": filepath,
+		"fontsize": fontsize,
+		"timestamp": Date.now() //Add this to make sure browser dont cache resp
 	}
-	var tab = '<div class="fileTab" tabid="'+tabid+'" framematch="ca'+tabid+'" filename="' + fileInternalIdentifier + filepath +'">\
-					loading... <div class="closeBtn">⨯</div>\
-					</div>';
-	
-	var editorRelative = "../../";
-	if (external){
-		editorRelative = "";
-	}
-	var frame = '<div style="position:fixed;width:100%;"><iframe id="ca'+tabid+'" class="editor" src="ace/editor.php?theme='+theme+'&filename=' + editorRelative +filepath+'&fontsize=' + fontsize + '" width="100%" frameBorder="0"></iframe></div>';
+
+	let encodedPayload = encodeURIComponent(JSON.stringify(payload))
+	var tab = `<div class="fileTab" tabid="${tabid}" framematch="ca${tabid}" filename="${filepath}">
+				loading... <div class="closeBtn">⨯</div>
+				</div>`;
+	var frame = `<div style="position:fixed;width:100%;"><iframe id="ca${tabid}" class="editor" src="ace/editor.html#${encodedPayload}" width="100%" frameBorder="0"></iframe></div>`;
 	$("#tabs").append(tab);
 	$("#codeArea").append(frame);
 	updateFrameAttr('ca' + tabid);
@@ -665,9 +634,6 @@ function bindListener(){
 		}else if (lastSelectedMenuItem == "Edit"){
 		    handleEditMenu($(this).text());
 		    $("#topbarMenu").hide();
-		}else if (lastSelectedMenuItem == "Utils"){
-			 handleCacheMenu($(this).text());
-		    $("#topbarMenu").hide();
 		}else{
 			alert(lastSelectedMenuItem);
 		}
@@ -676,65 +642,6 @@ function bindListener(){
 	
 }
 
-function handleCacheMenu(itemText){
-	var indexvalue = functionList.Utils.indexOf(itemText);
-	switch (indexvalue){
-		case 0:
-			var url = "SystemAOB/functions/file_system/index.php?controlLv=2&finishing=embedded&subdir=NotepadA/tmp";
-			if (!VDI){
-				window.open("../" + url);
-				break;
-			}
-			var uid = Math.round((new Date()).getTime() / 1000);
-			var title = "NotepadA" + " - Cache View";
-			var icon = "folder open";
-			newfw(url,title,icon,uid,1080,580);
-			break;
-		case 1:
-			var url = "NotepadA/utils/colorpicker/";
-			var uid = "colorpicker";
-			var title = "NotepadA" + " - Color Picker";
-			var icon = "tint";
-			newfw(url,title,icon,uid,360,196,undefined,undefined,false,true);
-			break;
-		case 2:
-			var id = getFocusedTab()[0];
-			var filepath = $("#" + id)[0].contentWindow.getFilepath().replace("../","");
-			//Change the filepath relative from AOR to the preview script's relative path
-			filepath = "../../../" + filepath;
-			var url = "NotepadA/utils/mobipreview/index.php?preview=" + filepath;
-			var uid = Math.round((new Date()).getTime() / 1000);
-			var title = "NotepadA" + " - Mobile Preview";
-			var icon = "mobile";
-			newfw(url,title,icon,uid,335,550,undefined,undefined,true,true);
-			break;
-		case 3:
-			//Open the CSS document in a new float window
-			var url = "NotepadA/utils/tocasdoc/index.php";
-			var uid = Math.round((new Date()).getTime() / 1000);
-			var title = "NotepadA" + " - CSS LookUp";
-			var icon = "css3";
-			newfw(url,title,icon,uid,450,565,undefined,undefined,true,true);
-			break;
-		case 4:
-			//Open the CSS document in a new float window
-			var url = "NotepadA/utils/tocasdoc/icons.php";
-			var uid = Math.round((new Date()).getTime() / 1000);
-			var title = "NotepadA" + " - System Icon List";
-			var icon = "bookmark";
-			newfw(url,title,icon,uid,335,550,undefined,undefined,false,true);
-			break;
-		case 5:
-			//Open gcc builder
-			var url = "NotepadA/utils/gcci/index.php";
-			var uid = Math.round((new Date()).getTime() / 1000);
-			var title = "NotepadA" + " - GCCI";
-			var icon = "code";
-			newfw(url,title,icon,uid,420,550,undefined,undefined,false,true,ao_module_windowID);
-			break;
-	}
-}
-
 function handleEditMenu(itemText){
     var indexvalue = functionList.Edit.indexOf(itemText);
 	switch (indexvalue){
@@ -811,10 +718,13 @@ function launchFocusedTabSearchBox(){
 }
 
 function handleOpenFileFunctionCall(fileData){
-	result = JSON.parse(fileData);
-	result = result[0]; //As only one file will be selected each time
-	var filepath = result.filepath;
-	var filename = result.filename;
+	if (fileData.length == 0){
+		return;
+	}
+
+	fileData = fileData[0];
+	var filepath = fileData.filepath;
+	var filename = fileData.filename;
 	var match = false;
 	var tabid = "";
 	$(".fileTab").each(function(){
@@ -842,12 +752,7 @@ function handleFileMenu(itemText){
 			break;
 		case 1:
 			//Open a file by fileSelector
-			var uid = new Date().getTime();
-			if (VDI){
-				ao_module_openFileSelector(uid,"handleOpenFileFunctionCall");
-			}else{
-				ao_module_openFileSelectorTab(uid,"../",true,"file",handleOpenFileFunctionCall);
-			}
+			ao_module_openFileSelector(handleOpenFileFunctionCall, "user:/Desktop", "file", false);
 			break;
 		case 2:
 			//Run this script in floatWindow
@@ -1027,6 +932,7 @@ function initFontSize(){
 
 function setStorage(configName,configValue){
 	//localStorage.setItem(name, value);
+	/*
 	$.ajax({
 	  type: 'POST',
 	  url: "../SystemAOB/functions/user/userGlobalConfig.php",
@@ -1034,25 +940,14 @@ function setStorage(configName,configValue){
 	  success: function(data){},
 	  async:true
 	});
+	*/
+	ao_module_storage.setStorage("NotepadA", configName, configValue);
 	return true;
 }
 
 function loadStorage(configName){
-	/* if (localStorage.getItem(name) == null){
-		return "";
-	}else{
-		return localStorage.getItem(name);
-	} */
 	var result = "";
-	$.ajax({
-	  type: 'POST',
-	  url: "../SystemAOB/functions/user/userGlobalConfig.php",
-	  data: {module: "NotepadA",name:configName},
-	  success: function(data){result = data;},
-	  error: function(data){result = "";},
-	  async:false,
-	  timeout: 3000
-	});
+	ao_module_storage.loadStorage("NotepadA", configName);
 	return result;
 }
 

+ 28 - 0
web/NotepadA/init.agi

@@ -0,0 +1,28 @@
+/*
+	NotepadA Module Registration Information
+	
+	Do not try to call any AJGI users / filepath functions in this script.
+*/
+
+//Create database for this module
+newDBTableIfNotExists("Code Studio")
+
+//Define the launchInfo for the module
+var moduleLaunchInfo = {
+    Name: "NotepadA",
+	Desc: "The legacy NotepadA from ArOZ Online Beta",
+	Group: "Office",
+	IconPath: "NotepadA/img/small_icon.png",
+	Version: "2.0",
+	StartDir: "NotepadA/index.html",
+	SupportFW: true,
+	LaunchFWDir: "NotepadA/index.html",
+	SupportEmb: true,
+	LaunchEmb: "NotepadA/embedded.html",
+	InitFWSize: [1024, 600],
+	InitEmbSize: [360, 200],
+	SupportedExt: [".txt", ".md", ".php", ".html", ".js", ".htm", ".csv", ".json", ".xml"]
+}
+
+//Register the module
+registerModule(JSON.stringify(moduleLaunchInfo));

+ 2 - 1
web/script/ao_module.js

@@ -151,7 +151,7 @@ function ao_module_setWindowTheme(newtheme="dark"){
 }   
 
 //Check if there are any windows with the same path. 
-//If yes, replace its hash content and reload to the new one and clise the current floatWindow
+//If yes, replace its hash content and reload to the new one and close the current floatWindow
 function ao_module_makeSingleInstance(){
     $(window.parent.document).find(".floatWindow").each(function(){
         if ($(this).attr("windowid") == ao_module_windowID){
@@ -173,6 +173,7 @@ function ao_module_makeSingleInstance(){
     return false
 }
 
+
 //Close the current window
 function ao_module_close(){
     if (!ao_module_virtualDesktop){