diff --git a/common.php b/common.php
index f7036b9..63bb4bc 100755
--- a/common.php
+++ b/common.php
@@ -44,9 +44,9 @@ class Common {
}
}
- if( file_exists( $path . 'config.php' ) ) {
+ if( file_exists( __DIR__ . '/config.php' ) ) {
- require_once( $path . 'config.php' );
+ require_once( __DIR__ . '/config.php' );
}
if( ! defined( 'BASE_PATH' ) ) {
diff --git a/components/autosave/init.js b/components/autosave/init.js
index a6cfba9..d677483 100755
--- a/components/autosave/init.js
+++ b/components/autosave/init.js
@@ -151,7 +151,7 @@
if( content == _this.content ) {
- var session = codiad.active.sessions[path];
+ let session = codiad.active.sessions[path];
if( typeof session != 'undefined' ) {
session.untainted = content;
@@ -171,7 +171,7 @@
/*
- _this code caused issues even though it is the proper way to save something.
+ this code caused issues even though it is the proper way to save something.
Whenever in collaboration, the server constantly gave a wrong file version error.
let path = codiad.active.getPath();
@@ -183,7 +183,7 @@
_this.content = content;
codiad.active.save;
codiad.filemanager.saveFile( path, content, localStorage.removeItem( path ), false );
- var session = codiad.active.sessions[path];
+ let session = codiad.active.sessions[path];
if( typeof session != 'undefined' ) {
session.untainted = content;
diff --git a/components/filemanager/init.js b/components/filemanager/init.js
index 09423cb..0271620 100755
--- a/components/filemanager/init.js
+++ b/components/filemanager/init.js
@@ -59,13 +59,13 @@
// Initialize node listener
this.nodeListener();
- this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.auto_reload_preview" ) == "true" );
+ this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
console.log( this.auto_reload );
amplify.subscribe( 'settings.save', async function() {
- let option = ( await codiad.settings.get_option( "codiad.filemanager.auto_reload_preview" ) == "true" );
+ let option = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
if( option != codiad.filemanager.auto_reload ) {
//codiad.auto_save.reload_interval();
@@ -81,7 +81,6 @@
if( _this.auto_reload && editor !== null ) {
- _this.preview.addEventListener( "beforeunload", _this.closePreview );
codiad.editor.getActive().addEventListener( "change", _this.refreshPreview );
}
});
@@ -483,7 +482,6 @@
if( _this.auto_reload && editor !== null ) {
- _this.preview.addEventListener( "beforeunload", _this.closePreview );
codiad.editor.getActive().addEventListener( "change", _this.refreshPreview );
}
@@ -494,12 +492,6 @@
});
},
- closePreview: function( event ) {
-
- _this = codiad.filemanager;
- _this.preview = null;
- },
-
refreshPreview: function( event ) {
_this = codiad.filemanager;
@@ -509,7 +501,22 @@
return;
}
- _this.preview.location.reload();
+ try {
+
+ if( ( typeof _this.preview.location.reload ) == "undefined" ) {
+
+ _this.preview = null;
+ codiad.editor.getActive().removeEventListener( "change", _this.refreshPreview );
+ return;
+ }
+ _this.preview.location.reload();
+ } catch( e ) {
+
+ console.log( e );
+ codiad.message.error( 'Please close your previously opened preview window.' );
+ _this.preview = null;
+ codiad.editor.getActive().removeEventListener( "change", _this.refreshPreview );
+ }
},
openInModal: function(path) {
diff --git a/components/install/process.php b/components/install/process.php
index 618014f..8b76484 100755
--- a/components/install/process.php
+++ b/components/install/process.php
@@ -94,43 +94,28 @@ if ( ! ( defined( "DBHOST" ) && defined( "DBNAME" ) && defined( "DBUSER" ) && de
$dbuser = $_POST['dbuser'];
$dbpass = $_POST['dbpass'];
- $connection = new PDO( "{$dbtype}:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass );
+ try {
+
+ $connection = new PDO( "{$dbtype}:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass );
+ } catch( exception $e ) {
+
+ die( "Could not connect to database." );
+ die();
+ }
$bind_vars = array();
$bind = "";
$sql = "
--- phpMyAdmin SQL Dump
--- version 4.6.6deb5
--- https://www.phpmyadmin.net/
---
--- Host: localhost:3306
--- Generation Time: Dec 11, 2018 at 05:31 PM
--- Server version: 5.7.24-0ubuntu0.18.04.1
--- PHP Version: 7.2.10-0ubuntu0.18.04.1
-
-SET SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO';
-SET time_zone = '+00:00';
-
-
-/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
-/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
-/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
-/*!40101 SET NAMES utf8mb4 */;
-
---
--- Database: code_test
---
-
--- --------------------------------------------------------
--
-- Table structure for table options
--
CREATE TABLE IF NOT EXISTS options (
- id int(11) NOT NULL,
+ id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
- value text NOT NULL
-) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ value text NOT NULL,
+ CONSTRAINT option_name UNIQUE (name)
+);
-- --------------------------------------------------------
@@ -139,12 +124,13 @@ CREATE TABLE IF NOT EXISTS options (
--
CREATE TABLE IF NOT EXISTS projects (
- id int(11) NOT NULL,
+ id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
path varchar(255) NOT NULL,
owner varchar(255) NOT NULL,
- access text
-) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ access text,
+ CONSTRAINT project UNIQUE (path, owner)
+);
-- --------------------------------------------------------
@@ -153,7 +139,7 @@ CREATE TABLE IF NOT EXISTS projects (
--
CREATE TABLE IF NOT EXISTS users (
- id int(11) NOT NULL,
+ id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name varchar(255) DEFAULT NULL,
last_name varchar(255) DEFAULT NULL,
username varchar(255) NOT NULL,
@@ -162,79 +148,22 @@ CREATE TABLE IF NOT EXISTS users (
project varchar(255) DEFAULT NULL,
access varchar(255) NOT NULL,
groups text,
- token text
-) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ token text,
+ CONSTRAINT username UNIQUE (username)
+);
--
-- Table structure for table user_options
--
CREATE TABLE IF NOT EXISTS user_options (
- id int(11) NOT NULL,
+ id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
username varchar(255) NOT NULL,
- value text NOT NULL
-) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ value text NOT NULL,
+ CONSTRAINT option_name UNIQUE (name,username)
+);
---
--- Indexes for dumped tables
---
-
---
--- Indexes for table options
---
-ALTER TABLE options
- ADD PRIMARY KEY (id),
- ADD UNIQUE KEY option_name (name);
-
---
--- Indexes for table projects
---
-ALTER TABLE projects
- ADD PRIMARY KEY (id),
- ADD UNIQUE KEY project_path (path,owner);
-
---
--- Indexes for table users
---
-ALTER TABLE users
- ADD PRIMARY KEY (id),
- ADD UNIQUE KEY username (username);
-
---
--- Indexes for table user_options
---
-ALTER TABLE user_options
- ADD PRIMARY KEY (id),
- ADD UNIQUE KEY option_name (name,username);
-
---
--- AUTO_INCREMENT for dumped tables
---
-
---
--- AUTO_INCREMENT for table options
---
-ALTER TABLE options
- MODIFY id int(11) NOT NULL AUTO_INCREMENT;
---
--- AUTO_INCREMENT for table projects
---
-ALTER TABLE projects
- MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=41;
---
--- AUTO_INCREMENT for table users
---
-ALTER TABLE users
- MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=79;
---
--- AUTO_INCREMENT for table user_options
---
-ALTER TABLE user_options
- MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2541;
-/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
-/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
-/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
";
try {
@@ -242,8 +171,13 @@ ALTER TABLE user_options
$result = $connection->exec($sql);
} catch( PDOException $e ) {
- echo $e->getMessage();
- die();
+ die($e->getMessage());
+ }
+
+ $error = $connection->errorInfo();
+ if( ! $error[0] == "00000" ) {
+
+ die( $error[2] );
}
//////////////////////////////////////////////////////////////////
@@ -281,7 +215,7 @@ ALTER TABLE user_options
}
}
- $bind_vars = array(
+ $bind_variables = array(
$project_name,
$project_path,
$username
@@ -289,8 +223,14 @@ ALTER TABLE user_options
$query = "INSERT INTO projects(name, path, owner) VALUES (?,?,?);";
$statement = $connection->prepare( $query );
$statement->execute( $bind_variables );
+ $error = $statement->errorInfo();
- $bind_vars = array(
+ if( ! $error[0] == "00000" ) {
+
+ die( $error[2] );
+ }
+
+ $bind_variables = array(
"",
"",
$username,
@@ -301,19 +241,23 @@ ALTER TABLE user_options
"",
""
);
- $query = "INSERT INTO users(first_name, last_name, username, password, email, project, access, groups, token) VALUES (?,?,?,PASSWORD(?),?,?,?,?,?)";
+ $query = "INSERT INTO users(first_name, last_name, username, password, email, project, access, groups, token) VALUES (?,?,?,?,?,?,?,?,?)";
$statement = $connection->prepare( $query );
$statement->execute( $bind_variables );
+ $error = $statement->errorInfo();
+ if( ! $error[0] == "00000" ) {
+
+ die( $error[2] );
+ }
-
-
+
/**
* Create sessions path.
*/
if ( ! is_dir( $sessions ) ) {
-
+
mkdir( $sessions, 00755 );
}
diff --git a/components/install/view.php b/components/install/view.php
index a4c1bda..635a82d 100755
--- a/components/install/view.php
+++ b/components/install/view.php
@@ -345,7 +345,7 @@ if ($newrelic) {
if(data=='success'){
window.location.reload();
}else{
- alert("An Error Occoured
"+data);
+ alert("An Error Occoured\n"+data);
}
});
}
diff --git a/components/project/class.project.php b/components/project/class.project.php
index a6d3d14..90bf48b 100755
--- a/components/project/class.project.php
+++ b/components/project/class.project.php
@@ -18,7 +18,7 @@ class Project extends Common {
public $path = '';
public $gitrepo = false;
public $gitbranch = '';
- public $projects = '';
+ public $projects = array();
public $no_return = false;
public $assigned = false;
public $command_exec = '';
@@ -58,12 +58,9 @@ class Project extends Common {
$bind_variables = array( $project_name, $project_path, $owner );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" );
- if( $return > 0 ) {
+ if( ! ( $return > 0 ) ) {
- formatJSEND( "success", "Created project $project_name" );
- } else {
-
- formatJSEND( "error", "Error creating project $project_name" );
+ exit( formatJSEND( "error", "Error creating project $project_name" ) );
}
}
@@ -377,6 +374,13 @@ class Project extends Common {
if( ! $this->public_project && ! $this->isAbsPath( $this->path ) ) {
+ $user_path = WORKSPACE . '/' . preg_replace( '/[^\w-]/', '', strtolower( $_SESSION["user"] ) );
+
+ if( ! is_dir( $user_path ) ) {
+
+ mkdir( $user_path, 0755, true );
+ }
+
$this->path = $_SESSION["user"] . '/' . $this->path;
}
diff --git a/components/project/controller.php b/components/project/controller.php
index f87aa0a..0af8186 100755
--- a/components/project/controller.php
+++ b/components/project/controller.php
@@ -6,7 +6,6 @@
* [root]/license.txt for more. This information must remain intact.
*/
-
require_once('../../common.php');
require_once('./class.project.php');
@@ -19,6 +18,12 @@ checkSession();
$Project = new Project();
$Project->projects = $Project->get_projects();
+if( ! is_array( $Project->projects ) ) {
+
+ $Project->projects = array();
+}
+
+
if( $_GET['action'] == 'add_user' ) {
$invalid_users = array(
diff --git a/components/project/init.js b/components/project/init.js
index e396251..9516ad0 100755
--- a/components/project/init.js
+++ b/components/project/init.js
@@ -275,7 +275,7 @@
//////////////////////////////////////////////////////////////////
loadSide: async function() {
- this._sideExpanded = ( await codiad.settings.get_option( "codiad.projects.SideExpaned" ) == "true" );
+ this._sideExpanded = ( await codiad.settings.get_option( "codiad.projects.sideExpanded" ) == "true" );
$( '.sb-projects-content' ).load( this.dialog + '?action=sidelist&trigger='+ await codiad.settings.get_option( 'codiad.editor.fileManagerTrigger' ) );
if ( ! this._sideExpanded ) {
@@ -323,7 +323,7 @@
projectsExpand: function() {
this._sideExpanded = true;
- codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded );
+ codiad.settings.update_option( 'codiad.projects.sideExpanded', this._sideExpanded );
$( '#side-projects' ).css( 'height', 276 + 'px' );
$( '.project-list-title' ).css( 'right', 0 );
$( '.sb-left-content' ).css( 'bottom', 276 + 'px' );
@@ -335,7 +335,7 @@
projectsCollapse: function() {
this._sideExpanded = false;
- codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded );
+ codiad.settings.update_option( 'codiad.projects.sideExpanded', this._sideExpanded );
$( '#side-projects' ).css( 'height', 33 + 'px' );
$( '.project-list-title' ).css( 'right', 0 );
$( '.sb-left-content' ).css( 'bottom', 33 + 'px' );
diff --git a/components/settings/class.settings.php b/components/settings/class.settings.php
index e0bf46a..57b423b 100755
--- a/components/settings/class.settings.php
+++ b/components/settings/class.settings.php
@@ -11,10 +11,6 @@ class Settings {
const DEFAULT_OPTIONS = array(
array(
"name" => "codiad.editor.autocomplete",
- "value" => "false",
- ),
- array(
- "name" => "codiad.editor.autosave",
"value" => "true",
),
array(
@@ -67,14 +63,18 @@ class Settings {
),
array(
"name" => "codiad.editor.wrapMode",
- "value" => "false",
- ),
- array(
- "name" => "codiad.settings.autosave",
"value" => "true",
),
array(
- "name" => "codiad.settings.plugin.sync",
+ "name" => "codiad.filemanager.autoReloadPreview",
+ "value" => "true",
+ ),
+ array(
+ "name" => "codiad.projects.sideExpanded",
+ "value" => "true",
+ ),
+ array(
+ "name" => "codiad.settings.autosave",
"value" => "true",
),
array(
diff --git a/components/settings/dialog.php b/components/settings/dialog.php
index 942dc05..a9c0d56 100755
--- a/components/settings/dialog.php
+++ b/components/settings/dialog.php
@@ -140,7 +140,7 @@
case "codiad.settings.autosave":
var bool_val = (val == "true");
break;
- case "codiad.filemanager.auto_reload_preview":
+ case "codiad.filemanager.autoReloadPreview":
var bool_val = (val == "true");
break;
}
diff --git a/components/settings/settings.system.php b/components/settings/settings.system.php
index b4b1a73..b37cdcb 100755
--- a/components/settings/settings.system.php
+++ b/components/settings/settings.system.php
@@ -17,7 +17,7 @@