Compare commits

..

10 Commits
v4.2 ... v4.3

Author SHA1 Message Date
Matt Pass
7ef86360d8 Version 4.3 2014-09-26 15:32:28 +01:00
Matt Pass
746b133a9a Filetype identification fixes & improvements
Look to fileExt to determine the file type by extension rather than
string in fileName which is the path. This means .c isn't mistakenly
picked up in paths such as /httpdocs/mydomain.com/file.rb
Simplified code with 2 improved ternary statements
2014-09-26 14:38:59 +01:00
Matt Pass
c141fc2864 Selected text + tab = indent auto
Instead of single tabs
2014-09-26 12:44:06 +01:00
Matt Pass
cc5cd166be Only if no headers sent, set the 3 headers 2014-09-26 11:59:03 +01:00
Matt Pass
2409bc19c2 Compile Sass and LESS on save if plugins available 2014-09-24 12:28:59 +01:00
Matt Pass
297e482b11 Recursive only if githubDiff, no anim if > 50
Only include github.js if in githubDiff mode
Only do recursive dir loading if in gitHub diff mode
Move folderItems splitting out of loop to avoid unnecessary processing
showFiles now begins the process of displaying files - animated into
view (using setInterval) if less than 50 items, or shows immediately (by
setting showContent and skipping recursion) if more
showNextFile() is a function to actually display a file or if the end,
kick off the process of adding deleted files/dirs
2014-09-23 18:40:49 +01:00
Matt Pass
46c1bdce02 Fixes to allow new items to be created
Store original $file value in $fileOrig
rtrim [NEW] from the $file path as that is messing with realpath
checking
Move debugging alert and console.log line into the for loop and use
allFiles[$i]
If a local path and not the doc root or parent dir starts with the doc
root
Check on $fileOrig when saving as
2014-09-23 16:49:47 +01:00
Matt Pass
be74745318 Links added for info on 2 types of auth token 2014-09-18 18:08:05 +01:00
Matt Pass
cd2e2747c5 Max length of 50 chars added to title 2014-09-18 18:02:03 +01:00
Matt Pass
3a7e728871 No autocomplete on the GitHub auth input field 2014-09-18 17:51:14 +01:00
11 changed files with 284 additions and 188 deletions

View File

@@ -3,7 +3,7 @@
ICEcoder is a web IDE / browser based code editor, which allows you to develop websites directly within the web browser. It uses the brilliant CodeMirror for code highlighting & editing, with a slick IDE wrapped around it to make the whole thing work. ICEcoder is a web IDE / browser based code editor, which allows you to develop websites directly within the web browser. It uses the brilliant CodeMirror for code highlighting & editing, with a slick IDE wrapped around it to make the whole thing work.
<img src="https://icecoder.net/images/icecoder-v4-2-browser-code-editor.png" alt="ICEcoder web IDE"> <img src="https://icecoder.net/images/icecoder-v4-3-browser-code-editor.png" alt="ICEcoder web IDE">
###Requirements ###Requirements
You can run ICEcoder either online or locally, on Linux, Windows or Mac based platforms. The only requirement is to have PHP 5 available (5.3 recommended). You can have this either as a vanilla installation or via a program such as WAMP or XAMPP (for Windows) or MAMP (for Mac). You can run ICEcoder either online or locally, on Linux, Windows or Mac based platforms. The only requirement is to have PHP 5 available (5.3 recommended). You can have this either as a vanilla installation or via a program such as WAMP or XAMPP (for Windows) or MAMP (for Mac).

View File

@@ -151,7 +151,9 @@ h2 {color: rgba(0,198,255,0.7)}
<script> <script>
CodeMirror.keyMap.ICEcoder = { CodeMirror.keyMap.ICEcoder = {
// "Tab": "defaultTab", **Now used by Emmet** "Tab": function(cm) {
return cm.somethingSelected() ? cm.execCommand("indentAuto") : CodeMirror.Pass // Falls through to default or Emmet plugin
},
"Shift-Tab": "indentLess", "Shift-Tab": "indentLess",
"Ctrl-Space": "autocomplete", "Ctrl-Space": "autocomplete",
"Ctrl-Up" : false, "Ctrl-Up" : false,

View File

@@ -1,7 +1,7 @@
<?php <?php
// ICEcoder system settings // ICEcoder system settings
$ICEcoderSettings = array( $ICEcoderSettings = array(
"versionNo" => "4.2", "versionNo" => "4.3",
"codeMirrorDir" => "CodeMirror-4.2", "codeMirrorDir" => "CodeMirror-4.2",
"docRoot" => $_SERVER['DOCUMENT_ROOT'], "docRoot" => $_SERVER['DOCUMENT_ROOT'],
"demoMode" => false, "demoMode" => false,

View File

@@ -1,6 +1,6 @@
<?php <?php
$ICEcoderUserSettings = array( $ICEcoderUserSettings = array(
"versionNo" => "4.2", "versionNo" => "4.3",
"root" => "", "root" => "",
"checkUpdates" => true, "checkUpdates" => true,
"openLastFiles" => true, "openLastFiles" => true,

View File

@@ -15,9 +15,15 @@ $file = str_replace("|","/",strClean(
: $_GET['file'] : $_GET['file']
)); ));
// Put the original $file var aside for use
$fileOrig = $file;
// Trim any +'s or spaces from the end of file // Trim any +'s or spaces from the end of file
$file = rtrim(rtrim($file,'+'),' '); $file = rtrim(rtrim($file,'+'),' ');
// Also remove [NEW] from $file, we can consider $_GET['action'] or $fileOrig to pick that up
$file = rtrim($file,'[NEW]');
// Make each path in $file a full path (; seperated list) // Make each path in $file a full path (; seperated list)
$allFiles = explode(";",$file); $allFiles = explode(";",$file);
for ($i=0; $i<count($allFiles); $i++) { for ($i=0; $i<count($allFiles); $i++) {
@@ -34,18 +40,24 @@ $fileName = basename($file);
// Check through all files to make sure they're valid/safe // Check through all files to make sure they're valid/safe
$allFiles = explode(";",$file); $allFiles = explode(";",$file);
for ($i=0; $i<count($allFiles); $i++) { for ($i=0; $i<count($allFiles); $i++) {
// Uncomment to alert and console.log the action and file, useful for debugging
// echo ";alert('".xssClean($_GET['action'],"html")." : ".$allFiles[$i]."');console.log('".xssClean($_GET['action'],"html")." : ".$allFiles[$i]."');";
// Die if the file requested isn't something we expect // Die if the file requested isn't something we expect
if( if(
($_GET['action']!="getRemoteFile" && $_GET['action']!="upload" && strpos(realpath($allFiles[$i]),realpath($docRoot)) !== 0) || // A local folder that isn't the doc root or starts with the doc root
($_GET['action']=="getRemoteFile" && strpos($allFiles[$i],"http") !== 0) ($_GET['action']!="getRemoteFile" &&
) { rtrim($allFiles[$i],"/") !== rtrim($docRoot,"/") &&
die("alert('Sorry - problem with file/folder requested');window.history.back();</script>"); strpos(realpath(rtrim(dirname($allFiles[$i]),"/")),realpath(rtrim($docRoot,"/"))) !== 0
) ||
// Or a remote URL that doesn't start http
($_GET['action']=="getRemoteFile" && strpos($allFiles[$i],"http") !== 0)
) {
die("alert('Sorry! - problem with file requested');</script>");
}; };
} }
// Uncomment to alert and console.log the action and file, useful for debugging
// echo ";alert('".xssClean($_GET['action'],"html")." : ".$file."');console.log('".xssClean($_GET['action'],"html")." : ".$file."');";
// If we're due to open a file... // If we're due to open a file...
if ($_GET['action']=="load") { if ($_GET['action']=="load") {
echo 'action="load";'; echo 'action="load";';
@@ -461,7 +473,7 @@ if (action=="load") {
<script> <script>
if (action=="save") { if (action=="save") {
<?php <?php
if (strpos($file,"[NEW]")>0||$saveType=="saveAs") { if (strpos($fileOrig,"[NEW]")>0||$saveType=="saveAs") {
?> ?>
fileLoc = '<?php echo $fileLoc;?>'; fileLoc = '<?php echo $fileLoc;?>';
newFileName = top.ICEcoder.getInput('<?php echo $t['Enter filename to...']; ?> '+(fileLoc!='' ? fileLoc : '/'),''); newFileName = top.ICEcoder.getInput('<?php echo $t['Enter filename to...']; ?> '+(fileLoc!='' ? fileLoc : '/'),'');
@@ -475,7 +487,7 @@ if (action=="save") {
document.saveFile.newFileName.value = '<?php echo $docRoot; ?>' + newFileName; document.saveFile.newFileName.value = '<?php echo $docRoot; ?>' + newFileName;
<?php ;};?> <?php ;};?>
if ("undefined" == typeof newFileName || (newFileName && "undefined" == typeof overwriteOK) || ("undefined" != typeof overwriteOK && overwriteOK)) { if ("undefined" == typeof newFileName || (newFileName && "undefined" == typeof overwriteOK) || ("undefined" != typeof overwriteOK && overwriteOK)) {
top.ICEcoder.serverMessage('<b><?php echo $t['Saving']; ?></b><br>'+ <?php echo strpos($file,"[NEW]")>0 ? "newFileName" : "'$file'"; ?>); top.ICEcoder.serverMessage('<b><?php echo $t['Saving']; ?></b><br>'+ <?php echo strpos($fileOrig,"[NEW]")>0 ? "newFileName" : "'$file'"; ?>);
document.saveFile.contents.value = top.document.getElementById('saveTemp1').value; document.saveFile.contents.value = top.document.getElementById('saveTemp1').value;
document.saveFile.submit(); document.saveFile.submit();
} else { } else {

View File

@@ -18,93 +18,98 @@ $t = $text['get-branch'];
<title>ICEcoder v <?php echo $ICEcoder["versionNo"];?> get branch</title> <title>ICEcoder v <?php echo $ICEcoder["versionNo"];?> get branch</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex, nofollow"> <meta name="robots" content="noindex, nofollow">
<?php if ($_SESSION['githubDiff']) { ?>
<script src="github.js"></script> <script src="github.js"></script>
<?php ;}; ?>
</head> </head>
<body> <body>
<?php <?php
// Function to sort given values alphabetically // Need to get dir contents recursively? (Used by GitHub diff mode)
function alphasort($a, $b) { if ($_SESSION['githubDiff']) {
return strcmp($a->getPathname(), $b->getPathname()); // Function to sort given values alphabetically
} function alphasort($a, $b) {
return strcmp($a->getPathname(), $b->getPathname());
// Class to put forward the values for sorting
class SortingIterator implements IteratorAggregate {
private $iterator = null;
public function __construct(Traversable $iterator, $callback) {
$array = iterator_to_array($iterator);
usort($array, $callback);
$this->iterator = new ArrayIterator($array);
} }
public function getIterator() {
return $this->iterator; // Class to put forward the values for sorting
class SortingIterator implements IteratorAggregate {
private $iterator = null;
public function __construct(Traversable $iterator, $callback) {
$array = iterator_to_array($iterator);
usort($array, $callback);
$this->iterator = new ArrayIterator($array);
}
public function getIterator() {
return $this->iterator;
}
} }
}
// Get a full list of dirs & files and begin sorting using above class & function // Get a full list of dirs & files and begin sorting using above class & function
$path = $docRoot.$iceRoot; $path = $docRoot.$iceRoot;
$objectList = new SortingIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST), 'alphasort'); $objectList = new SortingIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST), 'alphasort');
// Iterator to get files // Iterator to get files
$iter = new RecursiveIteratorIterator( $iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
); );
// Check if dir has .gitignore file // Check if dir has .gitignore file
function hasGitignore($dir) { function hasGitignore($dir) {
return is_file("$dir/.gitignore"); return is_file("$dir/.gitignore");
}
// Get a list of .gitignore files into $gi array
$gi = array();
if(hasGitignore($path)) {
$gi[] = "$path/.gitignore";
}
foreach ($iter as $scanpath) {
if (is_dir($scanpath) && strpos($scanpath,".git") == false) {
$thisDir = str_replace("\\","/",$scanpath);
if(hasGitignore($thisDir)) {
$gi[] = $thisDir."/.gitignore";
} }
}
}
// Get $matches array containing existing files listed in .gitignore // Get a list of .gitignore files into $gi array
function parseGitignore($file) { # $file = '/absolute/path/to/.gitignore' $gi = array();
$dir = dirname($file); if(hasGitignore($path)) {
$matches = array(); $gi[] = "$path/.gitignore";
$lines = file($file); }
foreach ($lines as $line) { foreach ($iter as $scanpath) {
$line = trim($line); if (is_dir($scanpath) && strpos($scanpath,".git") == false) {
if ($line === '') continue; # empty line $thisDir = str_replace("\\","/",$scanpath);
if (substr($line, 0, 1) == '#') continue; # a comment if(hasGitignore($thisDir)) {
if (substr($line, 0, 1) == '!') { # negated glob $gi[] = $thisDir."/.gitignore";
$line = substr($line, 1); }
$files = array_diff(glob("$dir/*"), glob("$dir/$line")); }
} else { # normal glob
$files = glob("$dir/$line");
}
$matches = array_merge($matches, $files);
}
return $matches;
}
// Cycle through all .gitignore files running above function to get a list of $excluded files
// Exclude the .git dir as first item as we don't want to see that
$excluded = array("/.git");
foreach ($gi as $scanpath) {
$excludedTest = (parseGitignore($scanpath));
if (count($excludedTest) > 0) {
$excluded = array_merge($excluded, $excludedTest);
} }
}
$objectListArray = array(); // Get $matches array containing existing files listed in .gitignore
foreach ($objectList as $objectRef) { function parseGitignore($file) { # $file = '/absolute/path/to/.gitignore'
$fileFolderName = @ltrim(substr(str_replace("\\","/",$objectRef->getPathname()), strlen($path)),"/"); $dir = dirname($file);
array_push($objectListArray,$fileFolderName); $matches = array();
$lines = file($file);
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') continue; # empty line
if (substr($line, 0, 1) == '#') continue; # a comment
if (substr($line, 0, 1) == '!') { # negated glob
$line = substr($line, 1);
$files = array_diff(glob("$dir/*"), glob("$dir/$line"));
} else { # normal glob
$files = glob("$dir/$line");
}
$matches = array_merge($matches, $files);
}
return $matches;
}
// Cycle through all .gitignore files running above function to get a list of $excluded files
// Exclude the .git dir as first item as we don't want to see that
$excluded = array("/.git");
foreach ($gi as $scanpath) {
$excludedTest = (parseGitignore($scanpath));
if (count($excludedTest) > 0) {
$excluded = array_merge($excluded, $excludedTest);
}
}
$objectListArray = array();
foreach ($objectList as $objectRef) {
$fileFolderName = @ltrim(substr(str_replace("\\","/",$objectRef->getPathname()), strlen($path)),"/");
array_push($objectListArray,$fileFolderName);
}
} }
// If we're just getting a branch, get that and set as the finalArray // If we're just getting a branch, get that and set as the finalArray
@@ -319,61 +324,77 @@ if ($_SESSION['githubDiff']) {
x.parentNode.removeChild(x); x.parentNode.removeChild(x);
} }
folderContent = document.getElementById('branch').innerHTML; folderContent = document.getElementById('branch').innerHTML;
folderItems = folderContent.split("\n");
showFiles = function () { showFiles = function() {
// Now animate folders & files into view // Now display folders & files
i=0;
animFolders = setInterval(function() { // Animate into view?
i++; if (folderItems.length <= 50) {
showFileI=0;
animFolders = setInterval(function() {
showFileI++;
showNextFile('progressive');
},4);
// Display immediately
} else {
showFileJ = folderItems.length;
showContent = folderContent;
showNextFile();
}
}
showNextFile = function(progressive) {
if (progressive) {
showContent = ""; showContent = "";
folderItems = folderContent.split("\n"); for (showFileJ=0; showFileJ<=showFileI; showFileJ++) {
for (j=0; j<=i; j++) { showContent += folderItems[showFileJ];
showContent += folderItems[j]; if (showFileJ<showFileI) {showContent += "\n";};
if (j<i) {showContent += "\n";};
} }
showContent = showContent.slice(28); }
if (j==folderItems.length) { showContent = showContent.slice(28);
clearInterval(animFolders); if (showFileJ==folderItems.length) {
showContent = showContent.slice(0,-2); // If we've been animating into view, clear that interval
// If we've got some deleted files (as we're in GitHub diff mode), add those into the file manager if ("undefined" != typeof animFolders) {clearInterval(animFolders);};
if ("undefined" != typeof top.deletedPaths && top.deletedPaths.length > 0) { showContent = showContent.slice(0,-2);
k = 0; // If we've got some deleted files (as we're in GitHub diff mode), add those into the file manager
top.addDeletedFiles = setInterval(function() { if ("undefined" != typeof top.deletedPaths && top.deletedPaths.length > 0) {
fSplit = top.deletedPaths[k].lastIndexOf("/"); i = 0;
thePath = top.deletedPaths[k].substr(0,fSplit); top.addDeletedFiles = setInterval(function() {
theFile = top.deletedPaths[k].substr(fSplit+1); fSplit = top.deletedPaths[i].lastIndexOf("/");
thePath = top.deletedPaths[i].substr(0,fSplit);
theFile = top.deletedPaths[i].substr(fSplit+1);
// If it's not excluded // If it's not excluded
if ("undefined" != typeof excludedArray && excludedArray.indexOf((thePath == "" ? "" : "/" + thePath)+"/"+theFile) == -1) { if ("undefined" != typeof excludedArray && excludedArray.indexOf((thePath == "" ? "" : "/" + thePath)+"/"+theFile) == -1) {
// If we're adding a deleted dir/file in a sub-dir // If we're adding a deleted dir/file in a sub-dir
if ("<?php echo $location;?>" == "/"+thePath) { if ("<?php echo $location;?>" == "/"+thePath) {
top.ICEcoder.updateFileManagerList('add','/'+thePath,theFile,false,false,false,'file'); top.ICEcoder.updateFileManagerList('add','/'+thePath,theFile,false,false,false,'file');
// If we're adding a deleted dir/file at the root level // If we're adding a deleted dir/file at the root level
} else {
// Folder
if (thePath != "") {
top.ICEcoder.updateFileManagerList('add',top.iceRoot,thePath,false,false,false,'folder');
// File
} else { } else {
// Folder top.ICEcoder.updateFileManagerList('add',top.iceRoot+thePath,theFile,false,false,false,'file');
if (thePath != "") {
top.ICEcoder.updateFileManagerList('add',top.iceRoot,thePath,false,false,false,'folder');
// File
} else {
top.ICEcoder.updateFileManagerList('add',top.iceRoot+thePath,theFile,false,false,false,'file');
}
} }
}
k++;
if ("undefined" == typeof top.deletedPaths[k]) {
clearInterval(top.addDeletedFiles);
} }
},20); }
} i++;
setTimeout(function(){top.ICEcoder.redoTabHighlight(top.ICEcoder.selectedTab);},4); if ("undefined" == typeof top.deletedPaths[i]) {
if (!top.ICEcoder.fmReady) {top.ICEcoder.fmReady=true;}; clearInterval(top.addDeletedFiles);
}
},20);
} }
newUL.innerHTML = showContent; setTimeout(function(){top.ICEcoder.redoTabHighlight(top.ICEcoder.selectedTab);},4);
locNest.parentNode.insertBefore(newUL,locNest.nextSibling); if (!top.ICEcoder.fmReady) {top.ICEcoder.fmReady=true;};
},4); }
newUL.innerHTML = showContent;
locNest.parentNode.insertBefore(newUL,locNest.nextSibling);
} }
// If we're not in githubDiff mode, show files here // If we're not in githubDiff mode, show files here

View File

@@ -131,7 +131,7 @@ if (!$demoMode && isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] && isset
echo $action == "commit" ? "Commit files" : "Pull files"; ?></h1> echo $action == "commit" ? "Commit files" : "Pull files"; ?></h1>
<form name="commitDetails"> <form name="commitDetails">
Title:<br><input type="text" name="commitTitle" id="commitTitle" value="" style="width: 300px; margin: 5px 0 15px 0"><br> Title:<br><input type="text" name="commitTitle" id="commitTitle" value="" style="width: 300px; margin: 5px 0 15px 0" maxlength="50"><br>
Message:<br><textarea name="commitMessage" id="commitMessage" style="width: 300px; height: 118px; margin: 5px 0 15px 0"></textarea> Message:<br><textarea name="commitMessage" id="commitMessage" style="width: 300px; height: 118px; margin: 5px 0 15px 0"></textarea>
</form> </form>

View File

@@ -25,9 +25,11 @@ if (($_GET || $_POST) && (!isset($_REQUEST["csrf"]) || $_REQUEST["csrf"] !== $_S
POST: ".xssClean(var_export($_POST, true),"html")); POST: ".xssClean(var_export($_POST, true),"html"));
} }
// Set our security related headers if (!headers_sent()) {
header("X-Frame-Options: SAMEORIGIN"); // Only frames of same origin // Set our security related headers
header("X-XSS-Protection: 1; mode=block"); // Turn on IE8-9 XSS prevention tools header("X-Frame-Options: SAMEORIGIN"); // Only frames of same origin
// header("X-Content-Security-Policy: allow 'self'"); // Only allows JS on same domain & not inline to run header("X-XSS-Protection: 1; mode=block"); // Turn on IE8-9 XSS prevention tools
header("X-Content-Type-Options: nosniff"); // Prevent MIME based attacks // header("X-Content-Security-Policy: allow 'self'"); // Only allows JS on same domain & not inline to run
header("X-Content-Type-Options: nosniff"); // Prevent MIME based attacks
}
?> ?>

View File

@@ -218,8 +218,8 @@ function findSequence(goal) {
<div> <div>
<h2>github</h2> <h2>github</h2>
<?php echo $t['auth token'];?> <span class="info" title="<?php echo $t['Required to get...'];?>">[?]</span><br> <?php echo $t['auth token'];?> <span class="info" title="<?php echo $t['Required to get...'];?>">[?]</span> &nbsp; <a href="https://help.github.com/articles/creating-an-access-token-for-command-line-use" target="_blank" class="info">Personal Access Token</a> &nbsp; <a href="(http://developer.github.com/v3/oauth" target="_blank" class="info">Client/Secret Pair Token</a><br>
<input type="text" name="githubAuthToken" style="width: 300px" onkeydown="showButton()" value="<?php echo $ICEcoder["githubAuthToken"];?>"> <input type="text" name="githubAuthToken" style="width: 320px" onkeydown="showButton()" value="<?php echo $ICEcoder["githubAuthToken"];?>" autocomplete="off">
</div> </div>
</span> </span>

View File

@@ -13,35 +13,39 @@ CodeMirror.commands.autocomplete = function(cm) {
// Switch the CodeMirror mode on demand // Switch the CodeMirror mode on demand
top.ICEcoder.switchMode = function(mode) { top.ICEcoder.switchMode = function(mode) {
var cM, fileName; var cM, fileName, fileExt;
cM = top.ICEcoder.getcMInstance(); cM = top.ICEcoder.getcMInstance();
fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
if (cM && mode) { if (cM && mode) {
cM.setOption("mode",mode); cM.setOption("mode",mode);
} else if (cM && fileName) { } else if (cM && fileName) {
fileName.indexOf('.js')>0 ? cM.setOption("mode","text/javascript") fileExt = fileName.split(".");
: fileName.indexOf('.coffee')>0 ? cM.setOption("mode","text/x-coffeescript") fileExt = fileExt[fileExt.length-1];
: fileName.indexOf('.rb')>0 ? cM.setOption("mode","text/x-ruby") cM.setOption("mode",
: fileName.indexOf('.py')>0 ? cM.setOption("mode","text/x-python") fileExt == "js" ? "text/javascript"
: fileName.indexOf('.css')>0 ? cM.setOption("mode","text/css") : fileExt == "coffee" ? "text/x-coffeescript"
: fileName.indexOf('.less')>0 ? cM.setOption("mode","text/x-less") : fileExt == "rb" ? "text/x-ruby"
: fileName.indexOf('.md')>0 ? cM.setOption("mode","text/x-markdown") : fileExt == "py" ? "text/x-python"
: fileName.indexOf('.xml')>0 ? cM.setOption("mode","application/xml") : fileExt == "css" ? "text/css"
: fileName.indexOf('.sql')>0 ? cM.setOption("mode","text/x-mysql") // also text/x-sql, text/x-mariadb, text/x-cassandra or text/x-plsql : fileExt == "less" ? "text/x-less"
: fileName.indexOf('.erl')>0 ? cM.setOption("mode","text/x-erlang") : fileExt == "md" ? "text/x-markdown"
: fileName.indexOf('.yaml')>0 ? cM.setOption("mode","text/x-yaml") : fileExt == "xml" ? "application/xml"
: fileName.indexOf('.java')>0 ? cM.setOption("mode","text/x-java") : fileExt == "sql" ? "text/x-mysql" // also text/x-sql, text/x-mariadb, text/x-cassandra or text/x-plsql
: fileName.indexOf('.jl')>0 ? cM.setOption("mode","text/x-julia") : fileExt == "erl" ? "text/x-erlang"
: fileName.indexOf('.c')>0 ? cM.setOption("mode","text/x-csrc") : fileExt == "yaml" ? "text/x-yaml"
: fileName.indexOf('.cpp')>0 ? cM.setOption("mode","text/x-c++src") : fileExt == "java" ? "text/x-java"
: fileName.indexOf('.cs')>0 ? cM.setOption("mode","text/x-csharp") : fileExt == "jl" ? "text/x-julia"
: fileName.indexOf('.go')>0 ? cM.setOption("mode","text/x-go") : fileExt == "c" ? "text/x-csrc"
: fileName.indexOf('.lua')>0 ? cM.setOption("mode","text/x-lua") : fileExt == "cpp" ? "text/x-c++src"
: fileName.indexOf('.pl')>0 ? cM.setOption("mode","text/x-perl") : fileExt == "cs" ? "text/x-csharp"
: fileName.indexOf('.rs')>0 ? cM.setOption("mode","text/x-rustsrc") : fileExt == "go" ? "text/x-go"
: fileName.indexOf('.scss')>0 ? cM.setOption("mode","text/x-sass") : fileExt == "lua" ? "text/x-lua"
: cM.setOption("mode","application/x-httpd-php"); : fileExt == "pl" ? "text/x-perl"
: fileExt == "rs" ? "text/x-rustsrc"
: fileExt == "scss" ? "text/x-sass"
: "application/x-httpd-php"
);
} }
} }
@@ -112,9 +116,12 @@ top.ICEcoder.lineCommentToggleSub = function(cM, cursorPos, linePos, lineContent
// Work out the nesting depth location on demand and update our display if required // Work out the nesting depth location on demand and update our display if required
top.ICEcoder.getNestLocationSub = function(nestCheck, fileName) { top.ICEcoder.getNestLocationSub = function(nestCheck, fileName) {
var events; var events, fileExt;
if (["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileName.split(".")[1])<0 && fileExt = fileName.split(".");
fileExt = fileExt[fileExt.length-1];
if (["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileExt)<0 &&
(nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)) { (nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)) {
// Then for all the array items, output as the nest display // Then for all the array items, output as the nest display
@@ -134,12 +141,16 @@ top.ICEcoder.getNestLocationSub = function(nestCheck, fileName) {
// Indicate if the nesting structure of the code is OK // Indicate if the nesting structure of the code is OK
top.ICEcoder.updateNestingIndicator = function() { top.ICEcoder.updateNestingIndicator = function() {
var cM, testToken, nestOK, fileName; var cM, testToken, nestOK, fileName, fileExt;
cM = top.ICEcoder.getcMInstance(); cM = top.ICEcoder.getcMInstance();
nestOK = true; nestOK = true;
fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
if (cM && fileName && ["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileName.split(".")[1])==-1) { if (fileName) {
fileExt = fileName.split(".");
fileExt = fileExt[fileExt.length-1];
}
if (cM && fileName && ["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileExt)==-1) {
testToken = cM.getTokenAt({line:cM.lineCount(),ch:cM.lineInfo(cM.lineCount()-1).text.length}); testToken = cM.getTokenAt({line:cM.lineCount(),ch:cM.lineInfo(cM.lineCount()-1).text.length});
nestOK = testToken.type && testToken.type.indexOf("error") == -1 ? true : false; nestOK = testToken.type && testToken.type.indexOf("error") == -1 ? true : false;
} }
@@ -149,7 +160,7 @@ top.ICEcoder.updateNestingIndicator = function() {
// Determine which area of the document we're in // Determine which area of the document we're in
top.ICEcoder.caretLocationType = function() { top.ICEcoder.caretLocationType = function() {
var cM, caretLocType, caretChunk, fileName; var cM, caretLocType, caretChunk, fileName, fileExt;
cM = top.ICEcoder.getcMInstance(); cM = top.ICEcoder.getcMInstance();
caretLocType = "Unknown"; caretLocType = "Unknown";
@@ -163,27 +174,31 @@ top.ICEcoder.caretLocationType = function() {
fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
if (fileName) { if (fileName) {
if (fileName.indexOf(".js")>0) {caretLocType="JavaScript"} fileExt = fileName.split(".");
else if (fileName.indexOf(".coffee")>0) {caretLocType="CoffeeScript"} fileExt = fileExt[fileExt.length-1];
else if (fileName.indexOf(".py")>0) {caretLocType="Python"} caretLocType =
else if (fileName.indexOf(".rb")>0) {caretLocType="Ruby"} fileExt == "js" ? "JavaScript"
else if (fileName.indexOf(".css")>0) {caretLocType="CSS"} : fileExt == "coffee" ? "CoffeeScript"
else if (fileName.indexOf(".less")>0) {caretLocType="LESS"} : fileExt == "py" ? "Python"
else if (fileName.indexOf(".md")>0) {caretLocType="Markdown"} : fileExt == "rb" ? "Ruby"
else if (fileName.indexOf(".xml")>0) {caretLocType="XML"} : fileExt == "css" ? "CSS"
else if (fileName.indexOf(".sql")>0) {caretLocType="SQL"} : fileExt == "less" ? "LESS"
else if (fileName.indexOf(".yaml")>0) {caretLocType="YAML"} : fileExt == "md" ? "Markdown"
else if (fileName.indexOf(".java")>0) {caretLocType="Java"} : fileExt == "xml" ? "XML"
else if (fileName.indexOf(".erl")>0) {caretLocType="Erlang"} : fileExt == "sql" ? "SQL"
else if (fileName.indexOf(".jl")>0) {caretLocType="Julia"} : fileExt == "yaml" ? "YAML"
else if (fileName.indexOf(".c")>0 && fileName.indexOf(".cpp")<0 && fileName.indexOf(".cs")<0) {caretLocType="C"} : fileExt == "java" ? "Java"
else if (fileName.indexOf(".cpp")>0) {caretLocType="C++"} : fileExt == "erl" ? "Erlang"
else if (fileName.indexOf(".cs")>0) {caretLocType="C#"} : fileExt == "jl" ? "Julia"
else if (fileName.indexOf(".go")>0) {caretLocType="Go"} : fileExt == "c" ? "C"
else if (fileName.indexOf(".lua")>0) {caretLocType="Lua"} : fileExt == "cpp" ? "C++"
else if (fileName.indexOf(".pl")>0) {caretLocType="Perl"} : fileExt == "cs" ? "C#"
else if (fileName.indexOf(".rs")>0) {caretLocType="Rust"} : fileExt == "go" ? "Go"
else if (fileName.indexOf(".scss")>0) {caretLocType="Sass"}; : fileExt == "lua" ? "Lua"
: fileExt == "pl" ? "Perl"
: fileExt == "rs" ? "Rust"
: fileExt == "scss" ? "Sass"
: "Content";
} }
top.ICEcoder.caretLocType = caretLocType; top.ICEcoder.caretLocType = caretLocType;

View File

@@ -5,4 +5,48 @@
// $fh = fopen(dirname(__FILE__)."/../file-saves.log", 'a'); // $fh = fopen(dirname(__FILE__)."/../file-saves.log", 'a');
// fwrite($fh, "save ".date("D dS M Y h:i:sa").": ".$file."\n"); // fwrite($fh, "save ".date("D dS M Y h:i:sa").": ".$file."\n");
// fclose($fh); // fclose($fh);
// Compiling Sass and LESS files (.scss and .less to .css version, with same name, in same dir)
$fileName = basename($file);
$fileNameExtPos = strrpos($fileName,".");
$filePieces = explode(".",$file);
$fileExt = $filePieces[count($filePieces)-1];
// SCSS Compiling if we have SCSSPHP plugin installed
if (strtolower($fileExt) == "scss" && file_exists(dirname(__FILE__)."/../plugins/scssphp/scss.inc.php")) {
// Load the SCSSPHP lib and start a new instance
require dirname(__FILE__)."/../plugins/scssphp/scss.inc.php";
$scss = new scssc();
// Set the import path and formatting type
$scss->setImportPaths(dirname($file)."/");
$scss->setFormatter('scss_formatter_compressed'); // scss_formatter, scss_formatter_nested, scss_formatter_compressed
try {
$scssContent = $scss->compile('@import "'.$fileName.'"');
$fh = fopen(substr($file, 0, -$fileNameExtPos)."css", 'w');
fwrite($fh, $scssContent);
fclose($fh);
} catch (Exception $e) {
echo ";top.ICEcoder.message('Couldn\'t compile your Sass, error info below:\\n\\n".$e->getMessage()."');";
}
}
// LESS Compiling if we have LESSPHP plugin installed
if (strtolower($fileExt) == "less" && file_exists(dirname(__FILE__)."/../plugins/lessphp/lessc.inc.php")) {
// Load the LESSPHP lib and start a new instance
require dirname(__FILE__)."/../plugins/lessphp/lessc.inc.php";
$less = new lessc();
// Set the formatting type and if we want to preserve comments
$less->setFormatter('lessjs'); // lessjs (same style used in LESS for JS), compressed (no whitespace) or classic (LESSPHP's original formatting)
$less->setPreserveComments(false); // true or false
try {
$less->checkedCompile($file, substr($file, 0, -$fileNameExtPos)."css"); // Note: Only recompiles if changed
} catch (Exception $e) {
echo ";top.ICEcoder.message('Couldn\'t compile your LESS, error info below:\\n\\n".$e->getMessage()."');";
}
}
?> ?>