summaryrefslogtreecommitdiffstats
path: root/examples/class/framework.class.php
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-01-15 05:57:19 -0500
committerMalf Furious <m@lfurio.us>2017-01-15 05:57:19 -0500
commit0d53041fc67e13fc53cca0c993ec1a7a31a5a16e (patch)
treec2d3c6a43aa3ba16fe2207f76c4c0a3ce4033772 /examples/class/framework.class.php
parentfeb61662d2359414837787111cf0f37e1f57fb5f (diff)
downloadscrott-0d53041fc67e13fc53cca0c993ec1a7a31a5a16e.tar.gz
scrott-0d53041fc67e13fc53cca0c993ec1a7a31a5a16e.zip
Reorganize examples/ directory
Diffstat (limited to 'examples/class/framework.class.php')
-rw-r--r--examples/class/framework.class.php126
1 files changed, 126 insertions, 0 deletions
diff --git a/examples/class/framework.class.php b/examples/class/framework.class.php
new file mode 100644
index 0000000..802c821
--- /dev/null
+++ b/examples/class/framework.class.php
@@ -0,0 +1,126 @@
+<?php
+
+/* Define Scrott version number */
+define("__VERSION__", "v0.0");
+
+/* 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;
+ }
+}
+
+?>