blob: a3c36cb215e90cdacdbc547bee25561f5cede09c (
plain) (
blame)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
<?php
/*
* SCROTT Copyright (C) 2016 Malf Furious
*
* Scrott is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Scrott is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*/
/* Define Scrott version number */
define("__VERSION__", "v0.0");
/* Include the Scrott system-level configuration file if it exists */
is_file("scrott.conf.php") &&
require_once "scrott.conf.php";
/* Init PHP session */
session_start();
require_once "class/mysql.class.php";
require_once "class/user.class.php";
/*
* Global functions / operations and access to contextual or session-based information
*/
abstract class Framework
{
static $dbobj = null;
/*
* Check for the existence of Scrott's system-level config
*/
function scrottConfExists()
{
global $_SCROTT;
return isset($_SCROTT['conf']);
}
/*
* Get the absolute path on this server for the root of this app
*/
function ar()
{
return substr($_SERVER['PHP_SELF'], 0, -10); // 10 = length of "/index.php"
}
/*
* Get the absolute path to the current page
*/
function ap()
{
return $this->ar() . $_REQUEST['path'];
}
/*
* Redirect to the given URL and die
*/
function redirectTo($url)
{
header("Location: " . $url);
exit;
}
/*
* Get a user object for the currently logged in user. Returns false if session is logged out.
*/
function getCurrentUser()
{
if (isset($_SESSION['userguid']))
{
$user = new User($_SESSION['userguid']);
if ($user->type == "user")
return $user;
$this->setCurrentUser();
}
return false;
}
/*
* Get the IP address the client held when the current session began
*/
function getOriginIP()
{
return $_SESSION['userip'];
}
/*
* Set the current logged in user
*/
function setCurrentUser($user = null)
{
if ($user != null && isset($user->guid))
{
$_SESSION['userguid'] = $user->guid;
$_SESSION['userip'] = $_SERVER['REMOTE_ADDR'];
}
else
{
unset($_SESSION['userguid']);
unset($_SESSION['userip']);
}
}
/*
* Get or create the app's database connection object (this is a singleton object and dependent on system-level config)
*/
static function getDbConnection()
{
global $_SCROTT;
if (self::$dbobj != null)
return self::$dbobj;
switch ($_SCROTT['dbEngine'])
{
case "mysql":
$host = $_SCROTT['dbAddress'];
$username = $_SCROTT['dbUser'];
$password = $_SCROTT['dbPass'];
$dbName = $_SCROTT['dbName'];
self::$dbobj = new Mysql($host, $username, $password, $dbName);
break;
default:
throw new Exception("Problem with Scrott Configuration. Invalid database engine specified.");
break;
}
return self::$dbobj;
}
}
?>
|