Started work on a new archive management system, Market system, and drag and drop system, Updated update messages

This commit is contained in:
xevidos 2019-09-22 21:35:26 -04:00
parent b1d8b7df7f
commit 24830cc7e8
17 changed files with 1299 additions and 730 deletions

View file

@ -37,8 +37,9 @@ Current Tasks:
Task List:
* Add ability to create shortlinks with certain permissions for users to share.
* Add ability to login with LDAP
* Add archive management
* Add archive management abilities
* Add bookmark files
* Add custom market
* \- Add in new admin interface ( Check admin-portal branch for progress )

View file

@ -0,0 +1,209 @@
<?php
class Archive {
const COMMANDS = array(
"zip" => array(
"compress" => array(
"windows" => "",
"linux" => "zip -r9 %output% %input%",
),
"decompress" => array(
"windows" => "",
"linux" => "unzip %input%",
),
),
);
const EXTENSIONS = array(
"zip" => "zip",
);
const INVALID_FILES = array(
".",
"..",
".DS_Store"
);
const SUPPORTED_TYPES = array(
"gz",
"rar",
"tar",
"tar.gz",
"zip",
);
public static $instance = null;
public $manager = null;
function __construct() {
}
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
public static function get_system() {
$system = "unknown";
if( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
$system = "windows";
} else {
$system = "linux";
}
return $system;
}
public static function compress( $path, $type = "zip" ) {
$response = array();
$supported = self::supports( $type );
$archive = self::get_instance();
if( $supported["status"] === "success" ) {
if( extension_loaded( self::EXTENSIONS["{$type}"] ) ) {
$response = call_user_func( array( $archive, "{$type}_c" ), $path );
} else {
$response = $archive->execute( $type, "compress" );
}
} else {
$response = $supported;
}
return $response;
}
public static function decompress( $file, $path = null ) {
$type = filetype( $file );
$response = array();
$supported = self::supports( $type );
$archive = self::get_instance();
if( $supported["status"] === "success" ) {
if( extension_loaded( self::EXTENSIONS["{$type}"] ) ) {
$response = call_user_func( array( $archive, "{$type}_d" ), $path );
} else {
$response = $archive->execute( $type, "decompress" );
}
} else {
$response = $supported;
}
return $response;
}
public static function supports( $type ) {
$response = array();
$type = strtolower( $type );
if( in_array( $type, self::SUPPORTED_TYPES ) ) {
$system = self::get_system();
$supported = false;
$extension = self::EXTENSIONS["{$type}"];
$command = self::COMMANDS["{$system}"]["{$type}"];
if( extension_loaded( $extension ) ) {
$type_supported = true;
}
if( $type_supported ) {
$response["status"] = "success";
$response["message"] = "Type is supported";
} else {
$response["status"] = "error";
$response["message"] = "The extension or program required to use this type of file does not seem to be installed.";
}
} else {
$response["status"] = "error";
$response["message"] = "The filetype supplied is not currently supported by Codiad's archive management system.";
}
return $response;
}
function zip_c( $path, $output, &$archive = null ) {
if( $archive == null ) {
$path = rtrim( $path, '/' );
//$output = rtrim( $output, '/' ) . '/';
$archive = new ZipArchive();
if( $archive->open( $output, ZIPARCHIVE::CREATE ) !== true ) {
return false;
}
}
$i = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ) );
foreach( $i as $file ) {
$file_name = $file->getBasename();
$file_path = $file->getPathname();
$relative_path = str_replace( $path, "", $file_path );
$relative_path = ltrim( $relative_path, '/' );
if( in_array( $file_name, self::INVALID_FILES ) ) {
continue;
}
if( is_file( $file_path ) ) {
$archive->addFile( $file_path, $relative_path );
} else {
$archive->addEmptyDir( $relative_path );
$this->zip_c( $file_path, $output, $archive );
}
}
$archive->close();
return true;
}
function zip_d( $path, $output ) {
$status = false;
$output = rtrim( $output, '/' ) . '/';
$archive = new ZipArchive();
if ( $archive->open( $path ) === true ) {
$archive->extractTo( $output );
$archive->close();
$status = true;
}
return $status;
}
}
?>

View file

@ -1,55 +0,0 @@
<?php
/**
* @author umbalaconmeogia at NOSPAM dot gmail dot com
* @link http://www.php.net/manual/de/class.ziparchive.php#110719
*/
class DirZip
{
/**
* Add files and sub-directories in a folder to zip file.
* @param string $folder
* @param ZipArchive $zipFile
* @param int $exclusiveLength Number of text to be exclusived from the file path.
*/
private static function folderToZip($folder, &$zipFile, $exclusiveLength)
{
$handle = opendir($folder);
while ($f = readdir($handle)) {
if ($f != '.' && $f != '..') {
$filePath = "$folder/$f";
// Remove prefix from file path before add to zip.
$localPath = substr($filePath, $exclusiveLength);
if (is_file($filePath)) {
$zipFile->addFile($filePath, $localPath);
} elseif (is_dir($filePath)) {
// Add sub-directory.
$zipFile->addEmptyDir($localPath);
self::folderToZip($filePath, $zipFile, $exclusiveLength);
}
}
}
closedir($handle);
}
/**
* Zip a folder (include itself).
* Usage:
* DirZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');
*
* @param string $sourcePath Path of directory to be zip.
* @param string $outZipPath Path of output zip file.
*/
public static function zipDir($sourcePath, $outZipPath)
{
$pathInfo = pathInfo($sourcePath);
$parentPath = $pathInfo['dirname'];
$dirName = $pathInfo['basename'];
$z = new ZipArchive();
$z->open($outZipPath, ZIPARCHIVE::CREATE);
$z->addEmptyDir($dirName);
self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
$z->close();
}
}

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
* Copyright (c) Codiad & Kent Safranski (codiad.com), Telaaedifex distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
@ -318,9 +318,16 @@ class Filemanager extends Common {
while( false !== ( $object = readdir( $handle ) ) ) {
if( $object != "." && $object != ".." && $object != $this->controller ) {
if( $object != "." && $object != ".." && $object != "" ) {
if ( is_dir( $path . '/' . $object ) ) {
$full_path = $path . '/' . $object;
if( is_link( $full_path ) ) {
$full_path = readlink( $full_path );
}
if ( is_dir( $full_path ) ) {
$type = "directory";
$size = count( glob( $path . '/' . $object . '/*' ) );

View file

@ -11,6 +11,12 @@
"applies-to" : "directory-only",
"onclick": "codiad.filemanager.createNode($('#context-menu').attr('data-path'),'directory');"
},
{
"title": "Archive",
"icon": "icon-folder",
"applies-to" : "directory-only",
"onclick": "codiad.filemanager.archive( $('#context-menu').attr('data-path') );"
},
{
"title": "Break",
"icon": null,

View file

@ -86,9 +86,20 @@ if( isset( $_GET["destination"] ) ) {
//////////////////////////////////////////////////////////////////
$Filemanager = new Filemanager();
$Archive = new Archive();
switch( $action ) {
case 'archive':
if( ! isset( $_GET["path"] ) ) {
exit( formatJSEND( "error", "No path specified." ) );
}
//$Archive->compress( );
break;
case 'create':
if( isset( $_GET["type"] ) ) {

View file

@ -49,7 +49,7 @@ if (isset($_GET['type']) && ($_GET['type']=='directory' || $_GET['type']=='root'
$filename .= '.zip';
$download_file = $targetPath.$filename;
DirZip::zipDir($dir, $targetPath .$filename);
Archive::compress( $dir, $targetPath . $filename );
} elseif (isAvailable('system') && stripos(PHP_OS, 'win') === false) {
# Execute the tar command and save file
$filename .= '.tar.gz';

File diff suppressed because it is too large Load diff

View file

@ -1,24 +1,42 @@
/*
* Copyright (c) Codiad & daeks (codiad.com), distributed
* Copyright (c) Codiad & daeks (codiad.com), and Isaac Brown (telaaedifex.com), distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
(function(global, $){
( function( global, $ ) {
var codiad = global.codiad;
let codiad = global.codiad;
$( function() {
codiad.market.init();
});
codiad.market = {
controller: 'components/market/controller.php',
dialog: 'components/market/dialog.php',
init: function() {},
get_installed_plugins: function() {},
get_installed_themes: function() {},
get_plugins: function() {},
get_themes: function() {},
install: function() {},
search: function() {},
uninstall: function() {},
update: function() {},
};
})( this, jQuery );
$(function() {
codiad.market.init();
});
codiad.market = {
controller: 'components/market/controller.php',
dialog: 'components/market/dialog.php',
init: function() {
},
/*
//////////////////////////////////////////////////////////////////
// Open marketplace
@ -99,4 +117,5 @@
});
},
};
})(this, jQuery);
*/

View file

@ -262,12 +262,6 @@ class Project extends Common {
OR id IN ( SELECT project FROM access WHERE user = ? );";
$bind_variables = array( $_SESSION["user"], $_SESSION["user_id"] );
$return = $sql->query( $query, $bind_variables, array() );
if( empty( $return ) ) {
$return = formatJSEND( "error", "No projects found." );
}
return( $return );
}
@ -337,16 +331,17 @@ class Project extends Common {
public function GetFirst() {
if( ! is_array( $this->projects ) || empty( $this->projects ) ) {
return null;
}
$this->name = $this->projects[0]['name'];
$this->path = $this->projects[0]['path'];
// Set Sessions
$_SESSION['project'] = $this->path;
if ( ! $this->no_return ) {
echo formatJSEND( "success", $this->projects[0] );
}
return $this->projects[0];
}
//////////////////////////////////////////////////////////////////

View file

@ -154,7 +154,15 @@ if( $_GET['action'] == 'get_current' ) {
$Project->no_return = true;
}
$Project->GetFirst();
$project = $Project->GetFirst();
if( $project == null ) {
exit( formatJSEND( "error", "Error, Could not load a projet." ) );
} else {
exit( formatJSEND( "success", $project ) );
}
} else {
// Load current
@ -162,7 +170,7 @@ if( $_GET['action'] == 'get_current' ) {
$project_name = $Project->GetName();
if( ! $no_return ) {
echo formatJSEND( "success", array( "name" => $project_name, "path" => $_SESSION['project'] ) );
exit( formatJSEND( "success", array( "name" => $project_name, "path" => $_SESSION['project'] ) ) );
}
}
}

View file

@ -0,0 +1,107 @@
<?php
require_once('../../common.php');
class Tasks {
function __construct() {}
static function build_command( $command, $arguments = array() ) {
$query = "";
$query .= "& echo $!";
return $query;
}
public static function create_task( $command, $arguments = array() ) {
$return = array(
"status" => "none",
"message" => "",
);
$command = self::build_command( $command, $arguments );
if( function_exists( "exec" ) ) {
} elseif( function_exists( "shell_exec" ) ) {
} elseif( function_exists( "system" ) ) {
} else {
$return["status"] = "error";
$return["message"] = "Could not find an enabled shell execution function.";
}
return $return;
}
public static function get_task( $id ) {
$return = array(
"status" => "none",
"message" => "",
);
if( is_numeric( $id ) ) {
if( function_exists( "exec" ) ) {
} elseif( function_exists( "shell_exec" ) ) {
} elseif( function_exists( "system" ) ) {
} else {
$return["status"] = "error";
$return["message"] = "Could not find an enabled shell execution function.";
}
} else {
$return["status"] = "error";
$return["message"] = "Invalid PID";
}
return $return;
}
public static function kill_task( $id ) {
$return = array(
"status" => "none",
"message" => "",
);
if( is_numeric( $id ) ) {
$command = "kill -9 {$id}";
if( function_exists( "exec" ) ) {
} elseif( function_exists( "shell_exec" ) ) {
} elseif( function_exists( "system" ) ) {
} else {
$return["status"] = "error";
$return["message"] = "Could not find an enabled shell execution function.";
}
} else {
$return["status"] = "error";
$return["message"] = "Invalid PID";
}
return $return;
}
}
?>

View file

@ -0,0 +1,29 @@
<?php
require_once('./class.tasks.php');
if( isset( $_POST["action"] ) ) {
$action = $_POST["action"];
} elseif( isset( $_GET["action"] ) ) {
$action = $_GET["action"];
} else {
exit( formatJSEND( "error", "No action was specified" ) );
}
switch( $action ) {
case( "get_task" ):
break;
default:
exit( formatJSEND( "error", "An invalid action was specified" ) );
break;
}
?>

55
components/tasks/init.js Normal file
View file

@ -0,0 +1,55 @@
( function( global, $ ) {
var codiad = global.codiad;
$( function() {
codiad.project.init();
});
codiad.tasks = {
controller: 'components/tasks/controller.php',
init: function() {},
get_task: function( id ) {
let _this = this;
$.ajax({
url: _this.controller,
type: "POST",
dataType: 'JSON',
data: {
"action": 'mypit_email_save_email',
"data": JSON.stringify( data ),
},
success: function( result ) {
if( ! isNaN( result ) ) {
_this.current_id = result;
}
console.log( result );
},
error: function(jqXHR, textStatus, errorThrown) {
document.getElementById( 'mypit_message' ).style.color = "#a94442";
document.getElementById( 'mypit_message' ).style.backgroundColor = "#f2dede";
document.getElementById( 'mypit_message' ).style.borderColor = "#ebccd1";
document.getElementById( 'mypit_message' ).innerHTML = "<p style='text-align: center;'>Error saving email. Please contact the system administrator.</p>";
document.getElementById( 'mypit_message' ).style.display = "block";
jQuery('html, body').animate( {scrollTop: 0}, 300 );
console.log('jqXHR:');
console.log(jqXHR);
console.log('textStatus:');
console.log(textStatus);
console.log('errorThrown:');
console.log(errorThrown);
throw "Error sending emails!";
}
});
},
}
});

View file

@ -66,11 +66,11 @@ switch($_GET['action']){
?>
<br><br><b><label><?php echo htmlentities("Your current version of Codiad is up to date."); ?></label></b>
<?php
if( $vars[0]['data']['name'] != '' ) {
/*if( $vars[0]['data']['name'] != '' ) {
?>
<em><?php i18n("Last update was done by "); ?><?php echo $vars[0]['data']['name']; ?>.</em>
<?php
}
}*/
}
?>
<?php

View file

@ -41,7 +41,7 @@
$('#modal-content form')
.die('submit'); // Prevent form bubbling
codiad.modal.load(500, this.dialog + '?action=check');
$('#modal-content').html('<div id="modal-loading"></div><div align="center">' + i18n("Contacting GitHub...") + '</div><br>');
$('#modal-content').html('<div id="modal-loading"></div><div align="center">' + i18n("Contacting Git Server...") + '</div><br>');
},
check_for_update: function () {

View file

@ -421,3 +421,7 @@
#file-manager .loading {
background-image: url(images/spinner.gif);
}
#file-manager .drag_over {
background-color: #4a4a4a;
border-radius: 10px;
}