Removed processes, now a class, moved 4 other files

This commit is contained in:
mattpass
2020-05-09 13:17:11 +01:00
parent 9c68dad990
commit daf3a3ba75
20 changed files with 14 additions and 344 deletions

View File

@@ -3,10 +3,6 @@ if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
?>
<!--
Purpose: This file is run when ICEcoder editor has loaded
Langs: Anything - PHP, JS etc
//-->
<script>
ICEcoder = parent.ICEcoder;
CodeMirror.commands.autocomplete = function(cm) {
@@ -124,28 +120,7 @@ ICEcoder.lineCommentToggleSub = function(cM, cursorPos, linePos, lineContent, lC
}
if (!cM.somethingSelected()) {cM.setCursor(linePos, cursorPos+adjustCursor)};
}
// Indicate if the nesting structure of the code is OK
ICEcoder.updateNestingIndicator = function() {
var cM, cMdiff, thisCM, testToken, nestOK, fileName, fileExt;
cM = ICEcoder.getcMInstance();
cMdiff = ICEcoder.getcMdiffInstance();
thisCM = ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
nestOK = true;
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName) {
fileExt = fileName.split(".");
fileExt = fileExt[fileExt.length-1];
}
if (thisCM && fileName && ["js","coffee","ts","css","less","sql","erl","yaml","java","jl","c","cpp","ino","cs","go","lua","pl","scss"].indexOf(fileExt)==-1) {
testToken = thisCM.getTokenAt({line:thisCM.lineCount(),ch:thisCM.lineInfo(thisCM.lineCount()-1).text.length});
nestOK = testToken.type && testToken.type.indexOf("error") == -1 ? true : false;
}
ICEcoder.nestValid.style.background = nestOK ? "#0b0" : "#f00";
ICEcoder.nestValid.title = nestOK ? "Nesting OK" : "Nesting Broken";
}
};
// Determine which area of the document we're in
ICEcoder.caretLocationType = function() {

View File

@@ -2,13 +2,6 @@
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a user saves a file, has $fileLoc and $fileName strings available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "SAVE >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName."\n");
// fclose($fh);
// Compiling Sass and LESS files (.scss and .less to .css version, with same name, in same dir)
$fileName = basename($file);

13
lib/on-load.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
require "icecoder.php";
use ICEcoder\ExtraProcesses;
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
$extraProcesses = new ExtraProcesses();
$doNext = $extraProcesses->onLoad();
echo '<script>' . $doNext . '</script>';
?>

View File

@@ -1,10 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run after a bug check, has $result string and $status arrays available to it
// Langs: PHP only
// Example:
// $fh = fopen(dirname(__FILE__)."/../bug-logs.log", 'a');
// fwrite($fh, "Bug check on: ".date("D dS M Y h:i:sa")."\nresult: ".$result.", status array:".var_export($status, true)."\n");
// fclose($fh);

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a file or dir is deleted, has $fileLoc and $fileName strings available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "DELETED >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('deleted');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a file or dir is moved, has $fileLoc and $fileName strings available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "MOVED >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('moved');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a file or dir is pasted, has $fileLoc, $fileName and $dest strings available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "PASTE >>> ".date("D dS M Y h:i:sa").": ".$dest."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('pasted');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a file or dir has its perms changed, has $fileLoc, $fileName and $_GET['perms'] strings available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "PERMS >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName." = ".$_GET['perms']."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('perms changed');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a file or dir is renamed, has $fileLoc and $fileName strings available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "RENAMED >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('renamed');";
$doNext .= "";

View File

@@ -1,13 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a file is loaded, has $fileLoc and $fileName strings available to it
// Langs: PHP (tho can output JS via PHP echo, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "LOAD >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName."\n");
// fclose($fh);
// If JS is needed, echo within string below, eg echo "alert('loaded');";
echo "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a file has text in it replaced, has $_GET['fileRef'] string available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "REPLACED TEXT >>> ".date("D dS M Y h:i:sa").": ".$_GET['fileRef']."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('renamed');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when files are uploaded, has $uploads array available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "UPLOAD >>> ".date("D dS M Y h:i:sa").": ".($uploads[0]->name)."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('uploaded');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a remote file is loaded, has $file string available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "GET REMOTE FILE >>> ".date("D dS M Y h:i:sa").": ".$file."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('got remote file');";
$doNext .= "";

View File

@@ -1,14 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
?>
<!--
Purpose: This file is run when ICEcoder has loaded
Langs: Anything - PHP, JS etc
Example:
//-->
<script>
// ICEcoder.openFile('/index.html');
// alert('Thanks for using ICEcoder');
</script>

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a dir is created, has $fileLoc and $fileName strings available to it
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "NEW DIR >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('new dir');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a login fail occurs
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../user-access.log", 'a');
// fwrite($fh, "FAIL ".date("D dS M Y h:i:sa").": ".$_POST['username']."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('user login failed');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a user logs in
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../user-access.log", 'a');
// fwrite($fh, "login ".date("D dS M Y h:i:sa").": ".$_SESSION['username']."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('logged in');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a user logs out
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../user-access.log", 'a');
// fwrite($fh, "logout ".date("D dS M Y h:i:sa").": ".$_SESSION['username']."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('logout');";
$doNext .= "";

View File

@@ -1,16 +0,0 @@
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
// Purpose: This file is run when a new user sets up
// Langs: PHP (tho can concat JS within $doNext string, see below)
// Example:
// $fh = fopen(dirname(__FILE__)."/../user-access.log", 'a');
// fwrite($fh, "NEW >>> ".date("D dS M Y h:i:sa").": ".$_SESSION['username']."\n");
// fclose($fh);
if (false === isset($doNext)) {
$doNext = "";
}
// If JS is needed, add within $doNext string below, eg $doNext .= ";alert('new user');";
$doNext .= "";

View File

@@ -1,66 +0,0 @@
<?php
// Only run internally on server, not from internet
if (isset($_SERVER['HTTP_HOST'])) {
die("Server side script only");
} else {
echo "Checking for changes via git diff every 2 secs...\n";
}
// Require a re-index dir/file data next time we index
function requireReIndexNextTime() {
// If we have a data/index.php file
if (file_exists(dirname(__FILE__)."/../data/index.php")) {
// Get serialized array back out of PHP file inside a comment block as prevIndexData
$prevIndexData = file_get_contents(dirname(__FILE__)."/../data/index.php");
if (strpos($prevIndexData, "<?php") !== false) {
$prevIndexData = str_replace("<?php\n/*\n\n", "", $prevIndexData);
$prevIndexData = str_replace("\n\n*/\n?>", "", $prevIndexData);
$prevIndexData = unserialize($prevIndexData);
// Set timestamp back to epoch to force a re-index next time
$prevIndexData['timestamps']['indexed'] = 0;
file_put_contents(dirname(__FILE__)."/../data/index.php", "<?php\n/*\n\n".serialize($prevIndexData)."\n\n*/\n?".">");
}
}
}
// Run continuously
while(true) {
// Get git diff output as a string and MD5 it as a checksum
$thisMD5 = shell_exec("cd .. && git diff | md5sum");
// If we have a previous checksum value and the current is different to it
if (isset($prevMD5) && $thisMD5 !== $prevMD5) {
echo "Changed ".date("Y-m-d g:i:s a (U)")."\n";
// Set timestamp of last index to 0 to force a re-index next time we index
requireReIndexNextTime();
// Get a list of all that's changed, into an array (filtered to remove false entries)
$gitData = shell_exec("cd .. && { git diff --name-only --staged ; git ls-files --other --modified --exclude-standard ;} | sort | uniq");
$diffLines = explode("\n", $gitData);
$output = ["paths" => array_filter($diffLines)];
// Store the serialized array in PHP comment block for pick up
file_put_contents(dirname(__FILE__)."/../data/git-diff.php", "<?php\n/*\n\n".serialize($output)."\n\n*/\n?".">");
// Set Git contents
$output = [];
$paths = array_filter($diffLines);
shell_exec("cd ..");
for ($i=0; $i<count($paths); $i++) {
if (strpos(mime_content_type(dirname(__FILE__)."/../../".$paths[$i]), "text") !== false) {
$content = shell_exec("cd .. && git show HEAD:".$paths[$i]);
$wd = dirname(dirname(dirname(__FILE__)));
if ($content !== "") {
$output[$wd."/".$paths[$i]] = [
"type" => "modified",
"lastHash" => "abc123",
"lastHashContent" => $content
];
}
}
}
file_put_contents(dirname(__FILE__)."/../data/git-content.php", "<?php\n/*\n\n".serialize($output)."\n\n*/\n?".">");
}
// Set prev MD5 to this one, ready for next time, sleep for 2 secs before loop starts again
$prevMD5 = $thisMD5;
sleep(2);
}
?>