summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/app/class/framework.class.php18
-rw-r--r--examples/app/class/object.class.php155
-rw-r--r--examples/database.class.php73
3 files changed, 0 insertions, 246 deletions
diff --git a/examples/app/class/framework.class.php b/examples/app/class/framework.class.php
index a3c36cb..802c821 100644
--- a/examples/app/class/framework.class.php
+++ b/examples/app/class/framework.class.php
@@ -1,26 +1,8 @@
<?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();
diff --git a/examples/app/class/object.class.php b/examples/app/class/object.class.php
index 7c0b7bb..0c02176 100644
--- a/examples/app/class/object.class.php
+++ b/examples/app/class/object.class.php
@@ -54,161 +54,6 @@ abstract class Object extends Framework
}
/*
- * Populate this object with data from the DB with a given GUID
- */
- function loadObj($guid = null)
- {
- if (is_null($guid))
- return;
-
- if (!$this->isGUID($guid))
- return;
-
- $escdGuid = $this->db->esc($guid);
-
- /* Base fields */
- $query = "SELECT * FROM `" . $this->table . "` WHERE `guid` = '" . $escdGuid . "'";
- $result = $this->db->query($query)[0];
-
- foreach ($this->cols as $col)
- {
- if (isset($result[$col]))
- $this->$col = $result[$col];
- }
-
- /* Child Table fields */
- $query = "SELECT * FROM `" . $this->childTable . "` WHERE `guid` = '" . $escdGuid . "'";
- $result = $this->db->query($query)[0];
-
- foreach ($this->childCols as $col)
- {
- if (isset($result[$col]))
- $this->$col = $result[$col];
- }
- }
-
- /*
- * Write this object to the database
- */
- function saveObj()
- {
- if (isset($this->guid))
- {
- $this->timeUpdated = $this->getCurrentTimestamp();
-
- /* Update Base */
- $updateStr = "";
-
- foreach ($this->cols as $col)
- {
- if (!isset($this->$col))
- continue;
-
- $updateStr .= "`" . $col . "` = '" . $this->db->esc($this->$col) . "', ";
- }
-
- if (strlen($updateStr) > 0)
- {
- $updateStr = substr($updateStr, 0, -2); // remove ", " from the end
- $query = "UPDATE `" . $this->table . "` SET " . $updateStr . " WHERE `guid` = '" . $this->db->esc($this->guid) . "'";
- $this->db->query($query);
- }
-
- /* Update Child */
- $updateStr = "";
-
- foreach ($this->childCols as $col)
- {
- if (!isset($this->$col))
- continue;
-
- $updateStr .= "`" . $col . "` = '" . $this->db->esc($this->$col) . "', ";
- }
-
- if (strlen($updateStr) > 0)
- {
- $updateStr = substr($updateStr, 0, -2); // remove ", " from the end
- $query = "UPDATE `" . $this->childTable . "` SET " . $updateStr . " WHERE `guid` = '" . $this->db->esc($this->guid) . "'";
- $this->db->query($query);
- }
- }
-
- else
- {
- $this->guid = $this->getNewGUID();
- $this->timeCreated = $this->getCurrentTimestamp();
- $this->timeUpdated = $this->timeCreated;
-
- /* Insert Base */
- $colsStr = "";
- $valsStr = "";
-
- foreach ($this->cols as $col)
- {
- if (!isset($this->$col))
- continue;
-
- $colsStr .= "`" . $col . "`, ";
- $valsStr .= "'" . $this->db->esc($this->$col) . "', ";
- }
-
- if (strlen($colsStr) > 0)
- {
- $colsStr = substr($colsStr, 0, -2); // remove ", "
- $valsStr = substr($valsStr, 0, -2);
- $query = "INSERT INTO `" . $this->table . "` (" . $colsStr . ") VALUES (" . $valsStr . ")";
- $this->db->query($query);
- }
-
- /* Insert Child */
- $colsStr = "";
- $valsStr = "";
-
- foreach ($this->childCols as $col)
- {
- if (!isset($this->$col))
- continue;
-
- $colsStr .= "`" . $col . "`, ";
- $valsStr .= "'" . $this->db->esc($this->$col) . "', ";
- }
-
- if (strlen($colsStr) > 0)
- {
- $colsStr = substr($colsStr, 0, -2); // remove ", "
- $valsStr = substr($valsStr, 0, -2);
- $query = "INSERT INTO `" . $this->childTable . "` (" . $colsStr . ") VALUES (" . $valsStr . ")";
- $this->db->query($query);
- }
- }
- }
-
- /*
- * Remove this object from the database
- */
- function delObj()
- {
- if (!isset($this->guid))
- return;
-
- /* Delete Base */
- $query = "DELETE FROM `" . $this->table . "` WHERE `guid` = '" . $this->db->esc($this->guid) . "'";
- $this->db->query($query);
-
- /* Delete Child */
- $query = "DELETE FROM `" . $this->childTable . "` WHERE `guid` = '" . $this->db->esc($this->guid) . "'";
- $this->db->query($query);
-
- /* obj_member garbage collection */
- $query = "DELETE FROM `obj_member` WHERE `guid` = '" . $this->db->esc($this->guid) . "' OR `member` = '" . $this->db->esc($this->guid) . "'";
- $this->db->query($query);
-
- /* msg_read garbage collection */
- $query = "DELETE FROM `msg_read` WHERE `guid` = '" . $this->db->esc($this->guid) . "' OR `user` = '" . $this->db->esc($this->guid) . "'";
- $this->db->query($query);
- }
-
- /*
* Get current timestamp for object database purposes
*/
function getCurrentTimestamp()
diff --git a/examples/database.class.php b/examples/database.class.php
deleted file mode 100644
index c7ef65b..0000000
--- a/examples/database.class.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-/*
- * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * For more information, please refer to UNLICENSE
- */
-
-/*
- * This class provides a common interface to a database. Scrott provides
- * facilities for interacting with any DBMS that we can use in PHP. To
- * provide support for a new DBMS, extend this class and implement the
- * abstract functions. Additionally, update the getInstance() function
- * in this class so that the new implementation is used under appropriate
- * configuration.
- */
-abstract class Database
-{
- private static $instance = NULL;
- protected $db;
-
- /*
- * Return the database instance object, creating it if this is the
- * first call to this function. This function will need maintained
- * as new DBMSs are supported.
- */
- public static function getInstance() : Database
- {
- // todo
- }
-
- /*
- * These functions are to be implemented by DBMS extensions,
- * providing a uniform interface to database engines.
- */
- public abstract function close();
- public abstract function query(string $query) : array;
- public abstract function esc(string $str) : string;
-
- /*
- * This function will lookup the row from the database on the given
- * table containing the given GUID and initialize the class properties
- * on this object based on the given field list.
- */
- public function initObj(string $table, array $fields, string $guid = NULL)
- {
- if (is_null($guid))
- return;
-
- $guid = $this->esc($guid);
- $query = "SELECT * FROM " . $table . " WHERE guid = '" . $guid . "'";
- $res = $this->query($query);
-
- if (!count($res))
- return;
-
- $res = $res[0];
-
- foreach ($fields as $field)
- {
- if (isset($res[$field]))
- $this->$field = $res[$field];
- }
- }
-}
-
-?>