Skip to content

Commit

Permalink
Merge pull request #1 from TheRolfFR/workspace-2.0
Browse files Browse the repository at this point in the history
Workspace 2.0
  • Loading branch information
TheRolfFR authored Mar 18, 2019
2 parents 6406a62 + 26a2e0b commit 313c36d
Show file tree
Hide file tree
Showing 31 changed files with 2,687 additions and 1,143 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<div align="center" color="#0094D2">
<img src="https://github.com/TheRolfFR/Workspace/blob/master/img/workspace_logo_no_bg.png?raw=true" height="200" alt="W" /><br>
<h1 color="#0094D2">WorkSpace</h1>
<p><a><img src="https://img.shields.io/badge/Drop,-Enjoy%20!-red.svg" alt="Technology Electron" data-canonical-src="https://img.shields.io/badge/Technology-Electron-2979ff.svg" style="max-width:100%;"></a> <a href="http://therolf.fr" rel="nofollow"><img src="https://camo.githubusercontent.com/72538f57abf1d2c52ef495ce1e5d47ea92b39e7f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417574686f722d546865526f6c662d3331613538392e737667" alt="Author TheRolf" data-canonical-src="https://img.shields.io/badge/Author-TheRolf-31a589.svg" style="max-width:100%;"> </a>
<a href="https://raw.githubusercontent.com/TheRolfFR/WorkSpace/master/LICENSE" rel="nofollow"><img src="https://img.shields.io/badge/LICENSE-GNU%20%20LGPL--3.0%20-lightgrey.svg" alt="License: CC BY-NC-SA 4.0" data-canonical-src="https://img.shields.io/badge/LICENSE-GNU%20%20LGPL--3.0%20-lightgrey.svg" style="max-width:100%;"></a></p>
<p> Tool to code your website in your website </p>
<p>Tool to code your website in your website</p>
</div>

![](https://img.shields.io/github/release/therolffr/workspace.svg?style=flat-square)
![](https://img.shields.io/badge/Drop,%20-enjoy!-red.svg?style=flat-square)
![Repo Size](https://img.shields.io/github/languages/code-size/TheRolfFR/WorkSpace.svg?style=flat-square)
![https://bit.ly/therolf-webite](https://img.shields.io/badge/Author-TheRolf-31a589.svg?style=flat-square)
![https://opensource.org/licenses/NPOSL-3.0](https://img.shields.io/badge/license-NPOSL--3.0-3DA639.svg?style=flat-square)

## New things in WorkSpace 2.0
- No jQuery
- Vue and Vuetify
- Night mode

## Installation
### 1. Unzip WorkSpace in your hosting
### 2. Modify your password

<img src="https://image.noelshack.com/fichiers/2018/06/7/1518371533-screenshot-2018-2-11-workspace-1.jpg" alt="Reset password" />

### 3. Enjoy !

<img src="https://raw.githubusercontent.com/TheRolfFR/WorkSpace/master/img/screen.png" alt="Ennnnjoy !" />

## License

License: <a href="https://raw.githubusercontent.com/TheRolfFR/WorkSpace/master/LICENSE">GNU Lesser General Public License v3.0</a>
License: <a href="https://opensource.org/licenses/NPOSL-3.0">Non-Profit Open Software License 3.0 (NPOSL-3.0)</a>
204 changes: 134 additions & 70 deletions access.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,168 @@
require('verifco.php');

if(connected()) {
function listFolderFiles($dir){
$files = $directories = array();
$ffs = scandir($dir);
/*
INPUT
{
'..' : {
'workspace': {
'css' : {}
'img' : {}
}
}
}
*/

function getFoldersJSON($source, $input) {
$return = $files = $directories = array();

//find in the current folder
$ffs = scandir('..' . $source);

// unset some mean values
unset($ffs[array_search('.', $ffs, true)]);
unset($ffs[array_search('..', $ffs, true)]);

// prevent empty ordered elements
if (count($ffs) < 1)
return;


// push the files and directories in proper arrays;
foreach($ffs as $ff){
if(is_dir($dir.'/'.$ff)){
array_push($directories, $ff . '/');
if(is_dir('..' . $source .'/'.$ff)){
array_push($directories, $ff);
} else {
array_push($files, $ff);
}
}

$result = array_merge($directories, $files);
return $result;
}

function sortByType($array) {
$retour = $types = array();

foreach($array as $element) {
$isfile = (preg_match("#(.+)\.(.+)#", $element)) ? 1 : 0;

if($isfile) {
$ext = preg_replace("#(.+)\.(.+)#", '$2', $element);
$intypes = in_array($ext, $types);
if(!$intypes) {
array_push($types, $ext);
}
// sort
sort($directories);
$files = sortByExtension($files);

// restart if folder inclluded in input else put in in the return
$return['folder'] = array();
foreach($directories as $dir) {
if(array_key_exists($dir, $input)) {
$return['folder'][$source . '/' . $dir . '/'] = getFoldersJSON($source . '/' . $dir, $input[$dir]);
} else {
array_push($retour, $element);
$return['folder'][$source . '/' . $dir . '/'] = $dir;
}
}

// put in the return
$return['file'] = array();
$i = 0;
foreach($files as $file) {
$return['file'][$i] = array($source . '/' . $file=> $file);
$i++;
}

return $return;
}

function sortByExtension($array) {
$return = $extensions = array();

// search all extensions
foreach($array as $file) {
$ext = preg_replace("#(.+)\.(.+)#", '$2', $file);
if(!in_array($ext, $extensions)) {
array_push($extensions, $ext);
}
}
sort($types);
foreach($types as $type) {
foreach($array as $element) {
$pattern = "/(\." . $type . ")$/";
if(preg_match($pattern, $element)) {
array_push($retour, $element);

// sort extensions
sort($extensions);

// sort foreach extensions
foreach($extensions as $ext) {
foreach($array as $file) {
$pattern = "/(\." . $ext . ")$/";
if(preg_match($pattern, $file)) {
array_push($return, $file);
}
}
}
return $retour;

return $return;
}

function format($array, $parent) {
$retour = '<ol class="custoMe">';

foreach ($array as $element) {
if(preg_match('/(.+)\/$/', $element)) {
$retour .= '<li><a class="folder context custoMe" href="' . $parent . $element . '" data-name="folder" data-src="' . $parent . $element . '">' . rtrim($element,'/') . '</a></li>';

function loadFolder($directory) {
$return = $files = $folders = array();

// scan the folder
$ffs = scandir(".." . $directory);

// unset some mean values
unset($ffs[array_search('.', $ffs, true)]);
unset($ffs[array_search('..', $ffs, true)]);

// seperate in folders and files
foreach($ffs as $ff) {
if(is_dir('..' . $directory .'/'.$ff)){
array_push($folders, $ff);
} else {
$ext = trim(preg_replace("#(.+)\.(.+)#", '$2', $element), '.');
$retour .= '<li><a class="context custoMe file ' . $ext . '" href="' . $parent . $element . '" data-name="file" data-src="' . $parent . $element . '" data-ext="' . $ext . '">' . $element . '</a></li>';
array_push($files, $ff);
}
}
$retour .= '</ol>';
return $retour;
}

if(isset($_GET) and !empty($_GET)) {
if(check($_GET['folder'])) {
$folder = htmlspecialchars($_GET['folder']);
print_r( format(sortByType(listFolderFiles('..'.$folder)), $folder) );

sort($folders);
$files = sortByExtension($files);

// put in folder array
$return['folder'] = array();
foreach($folders as $folder) {
$return['folder'][$directory . $folder . '/'] = $folder;
}

// put in the return
$return['file'] = array();
$i = 0;
foreach($files as $file) {
$return['file'][$i] = array($directory . $file=> $file);
$i++;
}
if(check($_GET['file'])) {
$retour = array();

return $return;
}

$dir = '..' . sec($_GET['file']);

if(file_exists($dir)) {
$finfo = finfo_open(FILEINFO_MIME_TYPE); // Retourne le type mime à l'extension mimetype
$mime = finfo_file($finfo, $dir);
finfo_close($finfo);

$type = preg_replace('/(.+)\/(.+)/', '$1', $mime);

array_push($retour, $type);
if($type == 'text') {
array_push($retour, '' . file_get_contents($dir));
if(isset($_POST) and !empty($_POST)) {
if(check($_POST['loadsave'])) {
$loadsave = json_decode($_POST['loadsave'], true);
echo json_encode(getFoldersJSON('', $loadsave[".."]));
} else if(check($_POST["loadfolder"])) {
echo json_encode(loadFolder(htmlspecialchars($_POST["loadfolder"])));
} else {
if(check($_POST['file'])) {
$retour = array();

$dir = '..' . sec($_POST['file']);

if(file_exists($dir)) {
$mime = custom_mime($dir);

array_push($retour, $mime);
if(substr($mime, 0, 4 ) === 'text') {
array_push($retour, '' . file_get_contents($dir));
}

$retour = json_encode($retour);
print_r($retour);
} else {
http_response_code(404);
echo "File not existing";
}

$retour = json_encode($retour);
print_r($retour);
} else {
print_r("File not existing");
http_response_code(400);
echo "no loadsave, loadfolder or file parameter";
}

}
} else {
http_response_code(400);
echo "no POST parameter";
}
} else {
http_response_code(403);
echo "not connected";
return null;
}
?>
16 changes: 11 additions & 5 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function rrmdir($dir) {
}

function cget($get, $get1='', $get2='') {
$f = check($_GET[$get]);
$f = check($_POST[$get]);
if($get1 !== '') {
if($get2 !== '') {
return ($f && cget($get1, $get2));
Expand All @@ -33,7 +33,7 @@ function cget($get, $get1='', $get2='') {
}

function csec($get) {
return sec($_GET[$get]);
return sec($_POST[$get]);
}

function dircopy($source, $dest, $perm = 0755) {
Expand Down Expand Up @@ -62,7 +62,7 @@ function dircopy($source, $dest, $perm = 0755) {
}

if(connected()) {
if(check($_GET)) {
if(check($_POST)) {
if(cget('open','src')) { //open function
//secure vars
$fileorfolder = csec('open');
Expand Down Expand Up @@ -273,13 +273,15 @@ function dircopy($source, $dest, $perm = 0755) {

if(file_exists($src) and (!file_exists($file)) ) {
if (file_put_contents($file, '') !== false) {
echo "done";
$return = "done";
} else {
echo "Cannot create file (" . basename($file) . ")";
$return = "Cannot create file (" . basename($file) . ")";
}
} else {
echo 'the file or the directory already exists';
}

echo $return;
}//

if(cget('newfolder', 'name')) {
Expand All @@ -305,8 +307,12 @@ function dircopy($source, $dest, $perm = 0755) {
echo $retour;
}
} else {
http_response_code(400);
echo 'no parameters sent';
}
} else {
http_response_code(403);
echo 'not connected';
}

?>
Loading

0 comments on commit 313c36d

Please sign in to comment.