kritbit

kritbit Commit Details


Date:2015-11-18 21:25:31 (9 years 1 month ago)
Author:Natalie Adams
Branch:master
Commit:3c5d9730e7d4934c5c073b79e3a328d4cdf642e1
Parents: 3134e1212a8cfacb6ee122f0a3d69ebcae50a835
Message:Adding models adding migrations updating framework

Changes:

File differences

web/application/controllers/base.php
44
55
66
7
8
79
810
9
11
12
1013
1114
1215
......
1417
1518
1619
17
18
19
2020
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
21
22
23
24
3725
26
3827
3928
4029
......
4231
4332
4433
45
34
4635
4736
37
4838
49
50
39
5140
5241
53
54
42
5543
44
45
46
47
48
49
50
51
52
5653
5754
58
55
5956
6057
6158
......
6461
6562
6663
64
65
66
67
68
6769
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
6891
6992
abstract class base extends \system\engine\HF_Controller {
/** @var \application\models\Users $user */
protected $user = null;
protected $session = null;
protected $sessionData = null;
public function isLoggedIn() {
protected $loginRequired = true;
protected function isLoggedIn() {
if (!$this->sessionData && !isset($this->sessionData->userId)) {
header("Location: /login");
return false;
return true;
}
}
public function __construct($config, $core, $tpl)
{
parent::__construct($config, $core, $tpl);
if ($this->config["DATABASE_TYPE"] == "SQLITE") {
$this->pdo = new PDO("sqlite:kritbot.sqlite3");
\vendor\DB\DB::$c = $this->pdo;
} else {
$this->pdo = new PDO(
"mysql:dbname={$this->config['MYSQL_DBNAME']};host={$this->config['MYSQL_HOST']}",
$this->config['MYSQL_USER'],
$this->config['MYSQL_PASS'],
array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
)
);
\vendor\DB\DB::$c = $this->pdo;
}
protected function loadRender($template, $parameters=array()) {
$newParameters = array_merge($parameters, ["user" => $this->user]);
return parent::loadRender($template, $newParameters);
}
protected function isUserLoggedIn() {
if (isset($_COOKIE["session"])) {
$validSession = Sessions::getByField("sessionid", $_COOKIE["session"]);
if ($validSession) {
$this->session = $validSession[0];
$this->sessionData = json_decode($this->session->data);
if ($this->sessionData == null) {
return;
return false;
}
$this->user = \application\models\Users::getByField("id", $this->sessionData->userId)[0];
return true;
} catch (\Exception $e) {
setcookie("session", "", time() - 3600);
header("Location: /login");
return false;
}
} else {
setcookie("session", "", time() - 3600);
header("Location: /login");
return false;
}
}
return false;
}
protected function login() {
if (isset($_COOKIE["session"])) {
if (!$this->user) {
header("Location: /login");
}
} else {
$bool = true;
$bytes = openssl_random_pseudo_bytes (10, $bool);
$bytes = openssl_random_pseudo_bytes(10, $bool);
$sessionId = bin2hex($bytes);
$this->session = new Sessions();
$this->session->ip = $_SERVER["REMOTE_ADDR"];
$this->session->save();
setcookie("session", $sessionId, 2147483647);
}
}
public function __construct($config, $core, $tpl)
{
parent::__construct($config, $core, $tpl);
if ($this->config["DATABASE_TYPE"] == "SQLITE") {
$this->pdo = new PDO("sqlite:kritbot.sqlite3");
\vendor\DB\DB::$c = $this->pdo;
} else {
$this->pdo = new PDO(
"mysql:dbname={$this->config['MYSQL_DBNAME']};host={$this->config['MYSQL_HOST']}",
$this->config['MYSQL_USER'],
$this->config['MYSQL_PASS'],
array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
)
);
\vendor\DB\DB::$c = $this->pdo;
}
$this->isUserLoggedIn();
if ($this->loginRequired) {
$this->login();
}
}
}
web/application/controllers/history.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class history extends base
{
public $loginRequired = false;
protected function checkAccess($job) {
if ($job->view_private == 1 && !$this->user) {
header("Location: /login");
return false;
}
if ($job->view_private == 1 && $this->user && $this->user->id != $job->user_id) {
header("Location: /");
return false;
}
return true;
}
public function view($id) {
$idArr = explode("-", $id);
if (count($idArr) == 2) {
/** @var \application\models\Histories $historyArr */
$historyArr = \application\models\Histories::getByField("jobs_id", $idArr[1]);
/** @var \application\models\Jobs[] $jobObject */
$jobObject = \application\models\Jobs::getByField("id", $idArr[1]);
if ($this->checkAccess($jobObject[0])) {
echo $this->loadRender("history.html", ["jobid" => $idArr[1], "histories" => $historyArr]);
}
}
}
public function log($jobId, $logId) {
$jobObject = \application\models\Jobs::getByField("id", $jobId);
if ($this->checkAccess($jobObject[0])) {
/** @var \application\models\Histories[] $historyArr */
$historyArr = \application\models\Histories::getByField("id", $logId);
echo $historyArr[0]->output;
}
}
}
web/application/controllers/job.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
class job extends base {
public function add() {
if (!isset($_POST["jobName"])) {
echo $this->loadRender("add.html");
} else {
$data = $_POST;
$data["user_id"] = $this->user->id;
\application\models\Jobs::create($data)->save();
header("Location: /");
}
}
public function edit($id) {
/** @var \application\models\Jobs $job */
$job = \application\models\Jobs::getByField("id", $id);
if ($job && $job[0]->user_id == $this->user->id) { //secuirty check
if (isset($_POST["jobName"])) {
$job[0]->update($_POST)->save();
header("Location: /");
} else {
echo $this->loadRender("add.html", ["job" => $job[0]]);
}
} else {
header("Location: /");
}
}
public function delete($id) {
$job = \application\models\Jobs::getByField("id", $id);
if ($job && $job[0]->user_id == $this->user->id) { //secuirty check
$job[0]->deleteRelated(["histories"]);
$job[0]->delete();
header("Location: /");
} else {
header("Location: /");
}
}
}
web/application/controllers/login.php
55
66
77
8
9
10
811
912
1013
use application\models\Users;
class login extends base {
protected $loginRequired = false;
private function accessDenied() {
return "ACCESS DENIED";
}
web/application/controllers/main.php
44
55
66
7
8
9
10
11
12
13
7
8
149
1510
{
public function index()
{
if ($this->isLoggedIn()) {
echo "Hello - " . $this->sessionData->userId;
echo "email = " . $this->user->email;
}
//echo "hello";
$jobs = \application\models\Jobs::getByField("user_id", $this->user->id);
echo $this->loadRender("main.html", ["jobs" => $jobs]);
}
}
web/application/migrations/1.php
11
22
3
4
35
46
57
<?php
use \vendor\DB\DB;
echo "Creating session table..." . PHP_EOL;
DB::query("CREATE TABLE sessions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
web/application/migrations/2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
use \vendor\DB\DB;
echo "Creating job table..." . PHP_EOL;
DB::query("CREATE TABLE jobs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
jobName VARCHAR(255),
runType VARCHAR(255),
runScript TEXT,
cron VARCHAR(255),
failScript TEXT,
last_run DATETIME,
last_result INTEGER,
api_key VARCHAR(255),
view_private INTEGER,
user_id INTEGER
);");
DB::query("INSERT INTO jobs VALUES (null, 'test', 1, 'TESTING', '*/5 * * *', 'TESTING', '2015-01-01', 0, '', 0, 1)");
DB::query("INSERT INTO jobs VALUES (null, 'test2', 1, 'TESTING', '*/5 * * *', 'TESTING', '2015-01-01', 0, '', 1, 1)");
web/application/migrations/3.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
use \vendor\DB\DB;
echo "Creating history table...";
DB::query("CREATE TABLE histories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
output TEXT,
jobs_id INTEGER,
run_date DATETIME,
time_taken INTEGER,
result INTEGER
);");
DB::query("INSERT INTO histories VALUES (null, 'THIS IS ONLY A TEST', 1, '2015-01-01', 10, 0)");
web/application/models/Histories.php
1
2
3
4
5
6
7
8
9
10
11
<?php
namespace application\models;
class Histories extends \system\engine\HF_Model {
public $output;
public $jobs_id;
public $run_date;
public $time_taken;
public $result;
}
web/application/models/Jobs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace application\models;
class Jobs extends \system\engine\HF_Model {
public $jobName;
public $runType;
public $runScript;
public $cron;
public $failScript;
public $last_run;
public $last_result;
public $user_id;
public $api_key;
public $view_private;
public $h2o_safe = true;
public function getRunType() {
switch ($this->runType) {
case "1":
return "Ran by Kritbit";
break;
case "2":
return "External Source";
break;
}
return "";
}
public function getLastRun() {
if ($this->last_run == "") {
return "Never";
} else {
return $this->last_run;
}
}
}
web/application/models/Sessions.php
33
44
55
6
76
87
98
namespace application\models;
class Sessions extends \system\engine\HF_Model {
public $id;
public $sessionid;
public $ip;
public $userAgent;
web/application/models/Users.php
66
77
88
9
109
1110
class Users extends HF_Model
{
public $id;
public $email;
}
web/application/views/add.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<h1>Add job</h1>
</div>
<form method="post" class="form-horizontal">
<div class="form-group col-sm-10">
<label for="jobName" class="col-sm-2 control-label">Job Name</label>
<div class="col-sm-10">
<input type="text" value="{{job.jobName}}" class="form-control" name="jobName" id="jobName" placeholder="Job Name">
</div>
</div>
<br>
<br>
<div class="col-sm-10 form-group container">
<label class="col-sm-2 control-label" for="dropdownMenu1">Run Type:</label>
<div id="dropdown1" class="col-sm-10 dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span id="selectedType">Ran by Kritbit</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li data-type="1"><a href="#">Ran by Kritbit</a></li>
<li data-type="2"><a href="#">External Source</a></li>
</ul>
<input type="hidden" id="runType" name="runType" value="{{job.runType}}">
</div>
</div>
<br>
<br>
<div class="form-group col-sm-10">
<label class="col-sm-2 control-label" for="script">Script for Kritbit to run:</label>
<div class="col-sm-10">
<textarea class="form-control" rows="6" name="runScript" id="script">{{job.runScript}}</textarea>
</div>
</div>
<br>
<br>
<div class="form-group col-sm-10">
<label class="col-sm-2 control-label" for="runCondition">When to run:</label>
<div class="col-sm-10">
<input type="text" value="{{job.cron}}" class="form-control" name="cron" id="runCondition" placeholder="Cron style">
</div>
</div>
<br>
<br>
<div class="form-group col-sm-10">
<label class="col-sm-2 control-label" for="failScript">Script to run on failure:</label>
<div class="col-sm-10">
<textarea class="form-control" rows="6" name="failScript" id="failScript">{{job.failScript}}</textarea>
</div>
</div>
<div class="form-group col-sm-10">
<label class="col-sm-2 control-label" for="private">Require login to view history:</label>
<div class="checkbox">
<label>
<input {% if job.view_private == 1 %}checked="checked"{% endif %} name="view_private" id="private" type="checkbox"> Yes
</label>
</div>
</div>
<div class="col-sm-10 form-group">
<div class="col-sm-offset-2 col-sm-10">
{% if job %}
<button type="submit" class="btn btn-default">Update</button>
{% else %}
<button type="submit" class="btn btn-default">Create</button>
{% endif %}
</div>
</div>
</form>
<script type="text/javascript">
$(function () {
$('#dropdown1 li').on('click', function(){
$("#runType").val($(this).data("type"));
$("#selectedType").text($(this).text());
//$('#datebox').val($(this).text());
});
});
</script>
{% endblock %}
web/application/views/base.html
33
44
55
6
7
6
7
88
9
9
1010
1111
1212
......
1717
1818
1919
20
21
22
2023
2124
25
26
2227
2328
2429
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="media/js/jquery.js"></script>
<script src="media/js/jqueryui.js"></script>
<script src="/media/js/jquery.js"></script>
<script src="/media/js/jqueryui.js"></script>
<link rel="stylesheet" type="text/css" href="media/css/jqueryui.css" />
<link rel="stylesheet" type="text/css" href="/media/css/jqueryui.css" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
<title>{{title}}</title>
<style type="text/css">
</style>
</head>
<body>
{% include "menu.html" %}
{% block menu %}{% endblock %}
{% block content %}{% endblock %}
</body>
</html>
web/application/views/history.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<h1>Job list</h1>
</div>
<table align="center" style="width: 60%;" class="table table-hover">
<thead>
<tr>
<th>Output</th>
<th>Run Date</th>
<th>Time Taken</th>
<th>Result</th>
</tr>
</thead>
<tbody>
{% if !histories %}
<tr>
<td align="center" colspan="4">No results</td>
</tr>
{% endif %}
{% for history in histories %}
<tr>
<td><a class="btn btn-default" href="/history/log/{{jobid}}/{{history.id}}/" role="button">View</a></td>
<td>{{history.run_date}}</td>
<td>{{history.time_taken}}</td>
<td>{{history.result}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
web/application/views/login.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{% extends "base.html" %}
{% block content %}
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
{% endblock %}
web/application/views/main.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{% extends "base.html" %}
{% block content %}
<div class="page-header">
<h1>Job list</h1>
</div>
<table align="center" style="width: 60%;" class="table table-hover">
<thead>
<tr>
<th>Edit</th>
<th>Name</th>
<th>Run Type</th>
<th>Cron</th>
<th>Last Run</th>
<th>Last Result</th>
<th>History</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for job in jobs %}
<tr>
<td><a class="btn btn-default" href="/job/edit/{{job.id}}" role="button">Edit</a></td>
<td>{{job.jobName}}</td>
<td>{{job.getRunType}}</td>
<td>{{job.cron}}</td>
<td>{{job.getLastRun}}</td>
<td>{{job.last_result}}</td>
<td><a class="btn btn-default" href="/history/view/{{job.jobName}}-{{job.id}}" role="button">History</a></td>
<td><a class="btn btn-danger" href="/job/delete/{{job.id}}" role="button">Delete</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
web/application/views/menu.html
1
12
23
34
......
89
910
1011
11
12
1213
1314
1415
1516
1617
17
18
19
20
21
22
23
24
25
26
27
28
29
18
19
20
3021
3122
3223
......
3627
3728
3829
39
40
30
31
4132
4233
4334
......
4637
4738
4839
49
40
5041
5142
5243
53
44
45
{% block menu %}
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Kribot</a>
<a class="navbar-brand" href="/">Kritbot</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
<li><a href="/job/add">Add Job<span class="sr-only">(current)</span></a></li>
<li><a href="/">List Jobs<span class="sr-only">(current)</span></a></li>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<li><a href="/login/logout">Logout - {{user.email}}</a></li>
<!-- <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</li> -->
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</nav>
{% endblock %}
web/migrations.php
11
22
3
4
5
36
47
58
69
710
8
9
10
11
1112
<?php
spl_autoload_extensions(".php"); // comma-separated list
spl_autoload_register();
foreach (glob("system/vendor/*.php") as $filename)
{
include $filename;
}
require('system/engine/HF_Core.php');
$core = new HF_Core();
$core = new \system\engine\HF_Core(true);
$core->runMigrations();
web/system/engine/HF_Controller.php
1515
1616
1717
18
18
1919
2020
2121
$this->core = $core;
}
public function loadRender($template, $parameters=array())
protected function loadRender($template, $parameters=array())
{
$this->tpl->loadTemplate($template);
return $this->tpl->render($parameters);
web/system/engine/HF_Core.php
2121
2222
2323
24
24
2525
2626
2727
......
3838
3939
4040
41
41
42
4243
4344
4445
......
108109
109110
110111
111
112
112113
113114
114115
......
140141
141142
142143
143
144
144145
145146
146
147
147148
148149
149150
......
327328
328329
329330
330
331
331
332
333
334
335
336
337
332338
333339
334340
private $config = array();
private $tpl;
public function __construct()
public function __construct($migrations=false)
{
$config = include("system/engine/config-default.php");
if (is_file("application/config.php"))
));
set_error_handler("\\system\\engine\\HF_Core::error_handler");
//set_exception_handler("\\system\\engine\\HF_Core::exception_handler");
$this->findController();
if (!$migrations)
$this->findController();
}
public static function exception_handler($e) {
include_once($path . $arr[$i] . ".php");
if ($i + 1 < count($arr)) // if there is a define after the controller name - this would be the method name
{
$this->loadController(new $arr[$i]($this->config, $this, $this->tpl), $arr[$i], $arr[$i+1], array_slice ($arr, 2));
$this->loadController(new $arr[$i]($this->config, $this, $this->tpl), $arr[$i], $arr[$i+1], array_slice ($arr, 3));
} else { // call index
$this->loadController(new $arr[$i]($this->config, $this, $this->tpl), $arr[$i], "index");
}
if (is_file(getcwd() . "/application/status.php"))
{
include_once (getcwd() . "/application/status.php");
$this->loadController(new HF_Status($this->config, $this, $this->tpl), "HF_Status", "Status404");
$this->loadController(new HF_Status($this->config, $this, $this->tpl), "\\system\\engine\\HF_Status", "Status404");
} else {
include_once(getcwd() . "/system/engine/status.php");
$this->loadController(new HF_Status($this->config, $this, $this->tpl), "HF_Status", "Status404");
$this->loadController(new HF_Status($this->config, $this, $this->tpl), "\\system\\engine\\HF_Status", "Status404");
}
}
foreach (glob("application/migrations/*.php") as $filename)
{
if (!in_array($filename, $migrationArray)) {
include $filename;
DB::insert("migrations", ["migration" => $filename, "ran_at" => (new \DateTime())->format("Y-m-d")]);
try {
include $filename;
DB::insert("migrations", ["migration" => $filename, "ran_at" => (new \DateTime())->format("Y-m-d")]);
} catch (\Exception $e) {
echo "[HF_Core] - Migration error - $e";
exit(1);
}
}
web/system/engine/HF_Model.php
66
77
88
9
10
11
12
9
10
11
12
13
14
15
1316
14
15
16
17
18
19
20
21
17
18
19
2220
21
2322
2423
2524
......
3837
3938
4039
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
4170
4271
4372
abstract class HF_Model {
protected $id = null;
public static function saveFromArray($data) {
$fieldMap = [];
$table = strtolower(get_class());
public $id = null;
public static function create($data) {
$obj = new static();
$function = new \ReflectionClass(get_called_class());
$table = strtolower($function->getShortName());
foreach(DB::getColumns($table) as $column) {
$fieldMap[$column] = $data[$column];
}
if ($fieldMap["id"] == null) {
DB::insert($table, $fieldMap);
} else {
$updateFields = $fieldMap;
unset($updateFields["id"]);
DB::update($table, $updateFields, $fieldMap["id"]);
if (isset($data[$column])) {
$obj->$column = $data[$column];
}
}
return $obj;
}
public function save() {
}
}
public function update($data) {
$function = new \ReflectionClass(get_called_class());
$table = strtolower($function->getShortName());
foreach(DB::getColumns($table) as $column) {
if ($column == "id" || strpos($column, "_id") !== false) {
continue; // Don't allow to override id
}
if (isset($data[$column])) {
$this->$column = $data[$column];
}
}
return $this;
}
public function delete() {
$function = new \ReflectionClass(get_called_class());
$table = strtolower($function->getShortName());
if ($this->id) {
DB::query("DELETE FROM $table WHERE id = " . $this->id);
}
}
public function deleteRelated($tables = []) {
$function = new \ReflectionClass(get_called_class());
$table = strtolower($function->getShortName());
foreach($tables as $relatedTable) {
DB::query("DELETE FROM $relatedTable WHERE $table" . "_id = " . $this->id);
}
}
public static function getByField($field, $value) {
$function = new \ReflectionClass(get_called_class());
$table = strtolower($function->getShortName());
web/system/vendor/h2o.php
1111
1212
1313
14
1415
1516
1617
require H2O_ROOT.'h2o/errors.php';
require H2O_ROOT.'h2o/filters.php';
require H2O_ROOT.'h2o/context.php';
require H2O_ROOT.'h2o/parser.php';
/**
* Example:

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.12771s using 14 queries.