Skip to content

Commit b46c09e

Browse files
committed
Code restructured...
1 parent c345804 commit b46c09e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2145
-415
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/public/compressed
33
/storage/*
44
/vendor
5+
/.idea

app/App.php

-19
This file was deleted.

app/Controllers/AuthController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
2+
namespace Controllers;
23

3-
namespace App\Controllers;
4+
use Controller;
45

56
class AuthController extends Controller {
67
public function getRegister() {}
78

89
public function postRegister() {}
910

1011
public function getLogin() {
11-
template('auth\login')
12+
view('auth\login');
1213
}
1314

1415
public function postLogin() {}

app/Controllers/Controller.php

-11
This file was deleted.

app/Controllers/DesktopController.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?php
2+
namespace Controllers;
23

3-
namespace App\Controllers;
4-
4+
use Controller;
55
use FAL\LocalFS;
6-
use App\Models\Desktop;
6+
use Models\FS;
77

88
class DesktopController extends Controller {
99
protected $model;
1010
protected $fs;
1111

1212
public function __construct() {
1313
parent::__construct();
14-
$this->model = new Desktop();
14+
$this->model = new FS();
1515
$this->fs = new LocalFS($this->model->getPath());
1616
}
1717

1818
public function getIndex() {
19-
template('desktop', ['desktopItems' => array_merge($this->fs->listDir(), $this->fs->listDir('/../default/'))]);
19+
view('desktop', ['desktopItems' => array_merge($this->fs->listDir(), $this->fs->listDir('/../default/'))]);
2020
}
2121
}
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2+
namespace Controllers;
23

3-
namespace App\Controllers;
4+
use Controller;
45

56
class DirectoryController extends Controller {}

app/Controllers/EditorController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2+
namespace Controllers;
23

3-
namespace App\Controllers;
4-
4+
use Controller;
55
use FAL\LocalFS;
6-
use App\Models\FS;
6+
use Models\FS;
77

88
class EditorController extends Controller {
99
protected $model;
@@ -16,6 +16,6 @@ public function __construct() {
1616
}
1717

1818
public function getIndex() {
19-
template('editor', ['fileTree' => array_merge($this->fs->listDir(null, null, true), $this->fs->listDir('/../default/', null, true)), 'projects' => true]);
19+
view('editor', ['fileTree' => array_merge($this->fs->listDir(null, null, true), $this->fs->listDir('/../default/', null, true)), 'projects' => true]);
2020
}
2121
}

app/Controllers/FilesController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2+
namespace Controllers;
23

3-
namespace App\Controllers;
4+
use Controller;
45

56
class FilesController extends Controller {}

app/Controllers/IndexController.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
2+
namespace Controllers;
3+
4+
use Controller;
25

3-
namespace App\Controllers;
46
class IndexController extends Controller {
57
public function getIndex() {
6-
template('index');
8+
view('index');
79
}
810

911
public function getApiIndex() {
10-
echo json_encode(['success' => true]);
12+
json(['success' => true]);
1113
}
1214
}

app/Models/FS.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?php
22

3-
namespace App\Models;
3+
namespace Models;
44

5+
use Model;
56
use DB\SQL\Schema;
67

78
class FS extends Model {
89
protected $id = null, $path = null, $user = null, $table = 'desktop', $fields = array();
910

1011
public function __construct() {
1112
$this->user = user();
12-
$this->fields = array_merge(array('session_id' => array('belongs-to-one' => ($user?'App\Models\User':'App\Models\Session'))), $this->fields);
13+
$this->fields = array_merge(array('session_id' => array('belongs-to-one' => ($user?'Models\User':'Models\Session'))), $this->fields);
1314
parent::__construct();
1415

1516
$this->id = $this->user?:(new Session())->load(array('ip = ? AND agent = ?', $this->app->IP, $this->app->AGENT))->last()->_id;
16-
$this->path = root_path('/storage/root/'.$this->id);
17+
$this->path = base_path('/storage/root/'.$this->id);
1718
if($this->load(array('session_id = ?', $this->id))->dry()) {
1819
$this->newSession($this->id);
1920
}else{

app/Models/Model.php

-34
This file was deleted.

app/Models/Profile.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22

3-
namespace App\Models;
3+
namespace Models;
44

5+
use Model;
56
use DB\SQL\Schema;
67

78
class Profile extends Model {
89
protected $table = 'profile',
910
$fields = array(
1011
'uid' => array(
11-
'belongs-to-one' => 'App\Models\User'
12+
'belongs-to-one' => 'Models\User'
1213
),
1314
'username' => array(
1415
'type' => Schema::DT_VARCHAR128,

app/Models/Session.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace App\Models;
3+
namespace Models;
44

5+
use Model;
56
use DB\SQL\Schema;
67

78
class Session extends \DB\Cortex {
@@ -23,7 +24,7 @@ class Session extends \DB\Cortex {
2324
'type' => Schema::DT_VARCHAR128
2425
),
2526
'desktop' => array(
26-
'has-one' => array('App\Models\Desktop', 'session_id')
27+
'has-one' => array('Models\Desktop', 'session_id')
2728
)
2829
);
2930
}

app/Models/User.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace App\Models;
3+
namespace Models;
44

5+
use Model;
56
use Bcrypt;
67
use DB\SQL\Schema;
78

@@ -34,7 +35,7 @@ class User extends Model {
3435
'default' => false
3536
),
3637
'desktop' => array(
37-
'has-one' => array('App\Models\Desktop', 'session_id')
38+
'has-one' => array('Models\Desktop', 'session_id')
3839
)
3940
);
4041

bootstrap/app.php

+73-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,80 @@
11
<?php
2+
$dir = __DIR__;
3+
require $dir.'/../vendor/autoload.php';
4+
require $dir.'/helpers.php';
25

3-
require(__DIR__.'/../vendor/autoload.php');
6+
$app = Base::instance();
7+
$app->config($dir.'/config.ini;');
8+
_load(array('config', 'routes'));
9+
$ver = $app->get('APP.VER');
10+
$env = strtolower($app->ENV);
11+
$isApi = is_api();
412

5-
$f3 = Base::instance();
13+
$app->mset(array(
14+
'AUTOLOAD' => '../app/',
15+
'DEBUG' => $env === strtolower($app->DEBUG_ENV) ? 3 : 0
16+
));
617

7-
loadConfig($f3);
8-
loadRoutes($f3);
18+
$db_type = strtoupper($app->DB_TYPE);
19+
if(isset($db_type)) {
20+
switch($db_type) {
21+
case 'JIG':
22+
$app->set('DB', new DB\Jig($app->DB_PATH, DB\Jig::FORMAT_JSON));
23+
break;
24+
case 'SQL':
25+
case 'MYSQL':
26+
$app->set('DB', new DB\SQL('mysql:host='.$app->DB_HOST.';port='.$app->DB_PORT.';dbname='.$app->DB_PREFIX.$app->DB_NAME, $app->DB_USER, $app->DB_PSWD));
27+
break;
28+
case 'PGSQL':
29+
$app->set('DB', new DB\SQL('pgsql:host='.$app->DB_HOST.';dbname='.$app->DB_PREFIX.$app->DB_NAME, $app->DB_USER, $app->DB_PSWD));
30+
break;
31+
case 'SQLSRV':
32+
$app->set('DB', new DB\SQL('sqlsrv:SERVER='.$app->DB_HOST.';Database='.$app->DB_PREFIX.$app->DB_NAME, $app->DB_USER, $app->DB_PSWD));
33+
break;
34+
case 'SQLITE':
35+
$app->set('DB', new DB\SQL('sqlite:'.$app->DB_PATH));
36+
break;
37+
case 'MONGO':
38+
$app->set('DB', new DB\Mongo('mongodb://'.$app->DB_HOST.':'.$app->DB_PORT, $app->DB_PREFIX.$app->DB_NAME));
39+
break;
40+
}
41+
}
942

10-
$db = $f3->set('DB', new DB\Jig($f3->get('DB_PATH'), DB\Jig::FORMAT_JSON));
11-
$session = new DB\Jig\Session($db, 'sessions', null, 'csrf');
43+
$type = _getDBType($db_type);
44+
if ($app->CSRF && $app->DB && ('Jig' == $type || 'SQL' == $type || 'Mongo' == $type)) {
45+
$session = 'DB\\'.$type.'\\Session';
46+
$nsession = new $session($app->DB, 'SESSIONS', null, 'CSRF');
47+
} elseif ($app->CSRF) {
48+
$nsession = new Session(null, 'CSRF');
49+
} else {
50+
if ($app->DB && ($type == 'Jig' || $type == 'Mongo' || $type == 'SQL')) {
51+
$session = str_ireplace('/', '', 'DB\/'.$type.'\Session');
52+
$nsession = new $session($app->DB);
53+
} else {
54+
$nsession = new Session();
55+
}
56+
}
57+
$app->set('SESSION', $nsession);
1258

13-
$assets = Assets::instance();
14-
$f3->set('ASSETS.onFileNotFound',function($file) use ($f3){
15-
echo 'file not found: '.$file;
16-
});
59+
if(!$isApi) {
60+
if('dev' === $env) {
61+
Falsum\Run::handler($app->DEBUG != 3);
62+
$app->route('GET @reloadr: /reloadr', 'Controller->reloadr');
63+
}else{
64+
$app->set('ONERROR', 'Controllers\Controller->error');
65+
Assets::instance();
66+
$app->set('ASSETS.onFileNotFound', function ($file) {
67+
echo 'file not found: '.$file;
68+
});
69+
}
70+
}
1771

18-
return $f3;
72+
if(!file_exists(base_path('storage/app/installed'))) {
73+
if($isApi) {
74+
json('App is not installed yet!', 'error');
75+
} else{
76+
$app->route('GET @install: /install', 'Controllers\IntallController->install');
77+
}
78+
}
79+
80+
return $app;

bootstrap/config.ini

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[GLOBALS]
2+
APP.NAME = LW
3+
APP.VER = 1.0.0
4+
APP.IV = fedcba9876543210
5+
APP.KEY = 0123456789abcdef
6+
FIREBASE_API_KEY = AAAACzsLzqQ:APA91bGC3KnjcHzcg04V148LQVFp1rv0M_gZsylem6pGOwbBp2uyB6Ll528NI-2KY92-6GzXmooOKFCrdt45lT22DVYOf1721RG60xPZtV7CXcGRp2k1OR6XP_1y5O_jwU_ydbhLZ9GR
7+
8+
ENV = dev
9+
DEBUG_ENV = dev
10+
SECRET = base64:HqICsIHs2ciVm1l7dHo1uFX3fh2fLy1EY5QTN9D5miE=
11+
FALLBACK = en
12+
TZ = UTC
13+
ENCODING = UTF-8
14+
CACHE = true
15+
CSRF = true
16+
17+
DB_TYPE = jig
18+
DB_HOST = localhost
19+
DB_PORT = 3306
20+
DB_USER = root
21+
DB_PSWD = toor
22+
DB_NAME = codehive
23+
DB_PREFIX = ch_
24+
DB_TABLE_PREFIX = ch_
25+
DB_PATH = ../storage/db/
26+
DB_SESSION = true
27+
28+
UI = ../resources/views/
29+
LOCALES = ../resources/lang/
30+
TEMP = ../storage/app/temp/
31+
LOGS = ../storage/app/logs/
32+
UPLOADS = ../public/uploads/
33+
34+
[RELOADR]
35+
FREQ = 5000
36+
DIRS = resources/,public/assets/
37+
FILES =
38+
FILTER.EXCEPT = .git,
39+
FILTER.ACCEPT = php,htm,css,js

0 commit comments

Comments
 (0)