Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modified internal database references to static

Changed the internal variables that Zoph uses to figure out which
database table belongs to which object (as well as the primary keys and
fields that cannot be null) from object variables into static variables.

Also modified the getRecords(), getRecordsFromQuery() and
getTopNfromSQL() and  method to no longer need the class name as a
parameter.

All of the above became possible because Zoph no longer supports PHP
5.2, as "Late Static Binding", which was needed for this change, was
introduced in PHP 5.3.
  • Loading branch information...
commit 9c88955f36286cf19e2ed58f95f428c934167386 1 parent 1b6b601
@jeroenrnl authored
View
28 php/album.inc.php
@@ -32,6 +32,17 @@
*/
class album extends zophTreeTable implements Organizer {
+ /** @var string The name of the database table */
+ protected static $table_name="albums";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("album_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("album");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="albums.php?parent_album_id=";
+
/** @var Cache the count of photos */
private $photoCount;
@@ -42,7 +53,6 @@ class album extends zophTreeTable implements Organizer {
*/
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("album_id must be numeric"); }
- parent::__construct("albums", array("album_id"), array("album"));
$this->set("album_id", $id);
}
@@ -112,7 +122,7 @@ public function removePhoto(photo $photo) {
*/
public function delete() {
parent::delete(array("photo_albums", "group_permissions"));
- $users = user::getRecords("user", "user_id", array("lightbox_id" => $this->get("album_id")));
+ $users = user::getRecords("user_id", array("lightbox_id" => $this->get("album_id")));
if ($users) {
foreach ($users as $user) {
$user->setFields(array("lightbox_id" => "null"));
@@ -158,7 +168,7 @@ public function getChildren($order=null) {
" GROUP BY album_id " .
escape_string($sql_order);
- $this->children=album::getRecordsFromQuery("album", $sql);
+ $this->children=album::getRecordsFromQuery($sql);
return $this->children;
}
@@ -193,7 +203,7 @@ public function getChildrenForUser($order=null) {
" GROUP BY album_id" .
escape_string($sql_order);
- $this->children=album::getRecordsFromQuery("album", $sql);
+ $this->children=album::getRecordsFromQuery($sql);
return $this->children;
}
@@ -462,7 +472,7 @@ function getCoverphoto($autothumb=null,$children=null) {
" and gp.access_level >= p.level " .
$order;
}
- $coverphotos=photo::getRecordsFromQuery("photo", $sql);
+ $coverphotos=photo::getRecordsFromQuery($sql);
$coverphoto=array_shift($coverphotos);
}
@@ -498,7 +508,7 @@ public static function getByName($name) {
$query = "select album_id from " . DB_PREFIX . "albums where $where";
- return album::getRecordsFromQuery("album", $query);
+ return album::getRecordsFromQuery($query);
}
/**
@@ -543,7 +553,7 @@ public static function getTopN() {
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
}
- return parent::getTopNfromSQL("album", $sql);
+ return parent::getTopNfromSQL($sql);
}
@@ -566,7 +576,7 @@ function get_albums($user = null) {
$sql = "select * from " . DB_PREFIX . "albums order by album";
}
- return album::getRecordsFromQuery("album", $sql);
+ return album::getRecordsFromQuery($sql);
}
function get_newer_albums($user_id, $date = null) {
@@ -579,7 +589,7 @@ function get_newer_albums($user_id, $date = null) {
"' AND gp.changedate > '" . escape_string($date) . "' " .
"ORDER BY a.album_id";
- return album::getRecordsFromQuery("album", $sql);
+ return album::getRecordsFromQuery($sql);
}
function get_album_count($user = null) {
View
22 php/category.inc.php
@@ -32,11 +32,21 @@
*/
class category extends zophTreeTable implements Organizer {
+ /** @var string The name of the database table */
+ protected static $table_name="categories";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("category_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("category");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="categories.php?parent_category_id=";
+
var $photoCount;
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("category_id must be numeric"); }
- parent::__construct("categories", array("category_id"), array("category"));
$this->set("category_id", $id);
}
@@ -101,7 +111,7 @@ public function getChildren($order=null) {
" GROUP BY c.category_id " .
$order;
- $this->children=category::getRecordsFromQuery("category", $sql);
+ $this->children=category::getRecordsFromQuery($sql);
return $this->children;
}
@@ -288,7 +298,7 @@ function getCoverphoto($autothumb=null,$children=null) {
" AND gp.access_level >= p.level " .
$order;
}
- $coverphotos=photo::getRecordsFromQuery("photo", $sql);
+ $coverphotos=photo::getRecordsFromQuery($sql);
$coverphoto=array_shift($coverphotos);
}
@@ -401,7 +411,7 @@ public static function getByName($name) {
$query = "select category_id from " . DB_PREFIX . "categories where $where";
- return category::getRecordsFromQuery("category", $query);
+ return category::getRecordsFromQuery($query);
}
/**
@@ -448,7 +458,7 @@ public static function getTopN() {
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
}
- return parent::getTopNfromSQL("category", $sql);
+ return parent::getTopNfromSQL($sql);
}
}
@@ -489,7 +499,7 @@ function get_category_count($user) {
$sql =
"SELECT category_id, parent_category_id FROM " .
DB_PREFIX . "categories as c";
- $cats=category::getRecordsFromQuery("category", $sql);
+ $cats=category::getRecordsFromQuery($sql);
$cat_clean=remove_empty($cats);
return count($cat_clean);
} else {
View
17 php/classes/confItem.inc.php
@@ -27,6 +27,18 @@
* @author Jeroen Roos
*/
abstract class confItem extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="conf";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("conf_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = true;
+ /** @var string URL for this class */
+ protected static $url="config.php#";
+
+
/** @var string Label to display */
protected $label;
/** @var string Longer description of item */
@@ -39,8 +51,6 @@
protected $required=false;
/** @var bool internal, internal settings can not be changed from webinterface */
protected $internal=false;
- /** @var array fields for database */
- public $fields=array();
/**
* Create confItem object
@@ -48,11 +58,8 @@
* @retrun confItem new object
*/
public function __construct($id = 0) {
- $this->keepKeys=true;
if($id === 0 || preg_match("/^[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/", $id)) {
- parent::__construct("conf", array("conf_id"), array(""));
$this->set("conf_id", $id);
-
} else {
log::msg("Illegal configuration id", log::FATAL, log::VARS);
}
View
15 php/classes/photoRelation.inc.php
@@ -32,6 +32,17 @@
*/
class photoRelation extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="photo_relations";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("photo_id_1", "photo_id_2");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = true;
+ /** @var string URL for this class */
+ protected static $url="photo.php?photo_id=";
+
/**
* Create a new relation between two photos.
* order of the photos is not important
@@ -40,10 +51,8 @@ class photoRelation extends zophTable {
* @return photoRelation newly created photoRelation
*/
public function __construct(photo $photo_1, photo $photo_2) {
- parent::__construct("photo_relations", array("photo_id_1", "photo_id_2"), array(""));
$this->set("photo_id_1", $photo_1->getId());
$this->set("photo_id_2", $photo_2->getId());
- $this->keepKeys=true;
}
/**
@@ -133,7 +142,7 @@ public static function getRelated(photo $photo) {
" UNION SELECT photo_id_2 AS photo_id FROM " .
DB_PREFIX . "photo_relations WHERE" .
" photo_id_1 = " . (int) $photo->getId();
- $related=photo::getRecordsFromQuery("photo", $sql);
+ $related=photo::getRecordsFromQuery($sql);
return $related;
}
View
14 php/classes/rating.inc.php
@@ -28,6 +28,17 @@
*/
class rating extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="photo_ratings";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("rating_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("photo_id", "rating", "user_id");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="photo.php?rating_id=";
+
/**
* Create new rating object
@@ -36,7 +47,6 @@ class rating extends zophTable {
*/
public function __construct($id = 0) {
if($id && !is_numeric($id)) { die("rating_id must be numeric"); }
- parent::__construct("photo_ratings", array("rating_id"), array("photo_id", "rating", "user_id"));
$this->set("rating_id", $id);
}
@@ -63,7 +73,7 @@ public static function getRatings(photo $photo = null, user $user = null) {
}
}
- return self::getRecords("rating", null, $constraints);
+ return self::getRecords(null, $constraints);
}
/**
View
2  php/classes/template.inc.php
@@ -256,7 +256,7 @@ public static function createSelectArray(array $records, array $name_fields) {
foreach ($records as $rec) {
// this only makes sense when there is one key
- $id = $rec->get($rec->primary_keys[0]);
+ $id = $rec->getId();
$name = "";
foreach ($name_fields as $n) {
View
327 php/classes/zophTable.inc.php
@@ -35,30 +35,19 @@
*/
abstract class zophTable {
/** @var string The name of the database table */
- public $table_name;
+ protected static $table_name;
/** @var array List of primary keys */
- public $primary_keys;
- /** @var array Contains the values of attributes that will be stored in the db */
- public $fields;
+ protected static $primary_keys=array();
/** @var array Fields that may not be empty */
- public $not_null;
+ protected static $not_null=array();
/** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
- protected $keepKeys = false;
-
- /**
- * This construnctor should be called from the constructor
- * of a subclass.
- * @param string Name of the db table
- * @param array List of primary keys
- * @param array List of fields that may not be NULL
- */
- public function __construct($table_name, array $primary_keys, array $not_null) {
- $this->table_name = DB_PREFIX . $table_name;
- $this->primary_keys = $primary_keys;
- $this->not_null = $not_null;
- $this->fields = array();
- }
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url;
+ /** @var array Contains the values of attributes that will be stored in the db */
+ public $fields=array();
+
/**
* Returns the value of a field
* @param string name of field to get
@@ -80,8 +69,8 @@ public function get($name) {
* @throws ZophException
*/
public function getId() {
- if(sizeof($this->primary_keys)==1) {
- return (int) $this->get($this->primary_keys[0]);
+ if(sizeof(static::$primary_keys)==1) {
+ return (int) $this->get(static::$primary_keys[0]);
} else {
var_dump($this);
throw new ZophException("This class (" . get_class($this) . ") requires a specific getId() implementation, please report a bug");
@@ -114,9 +103,9 @@ public function setFields(array $vars, $prefix = null, $suffix = null, $null=tru
// ignore empty keys or values unless the field must be set.
if ($null) {
- if ((!in_array($key, $this->not_null)) && (empty($key) )) { continue; }
+ if ((!in_array($key, static::$not_null)) && (empty($key) )) { continue; }
} else {
- if ((!in_array($key, $this->not_null)) && (empty($key) || $val == "")) { continue; }
+ if ((!in_array($key, static::$not_null)) && (empty($key) || $val == "")) { continue; }
}
@@ -155,8 +144,7 @@ public function setFields(array $vars, $prefix = null, $suffix = null, $null=tru
* @return bool Whether or not field is listed
*/
public function isKey($name) {
- $keys = $this->primary_keys;
- return in_array($name, $keys);
+ return in_array($name, static::$primary_keys);
}
/**
@@ -165,12 +153,6 @@ public function isKey($name) {
* @todo Should return something more sensible
*/
public function lookup() {
-
- if (!$this->table_name || !$this->primary_keys || !$this->fields) {
- log::msg("Missing data", log::ERROR, log::GENERAL);
- return;
- }
-
$constraint = $this->createConstraints();
if (!$constraint) {
@@ -178,7 +160,7 @@ public function lookup() {
return;
}
- $sql = "select * from $this->table_name where $constraint";
+ $sql = "SELECT * FROM " . DB_PREFIX . static::$table_name . " WHERE $constraint";
return $this->lookupFromSQL($sql);
}
@@ -213,15 +195,10 @@ public function lookupFromSQL($sql) {
* @see group_permissions class.
*/
public function insert() {
-
- if (!$this->table_name || !$this->fields) {
- log::msg("Missing data", log::ERROR, log::GENERAL);
- return;
- }
$names=null;
$values=null;
while (list($name, $value) = each($this->fields)) {
- if ($this->primary_keys && !$this->keepKeys && $this->isKey($name)) {
+ if (!static::$keepKeys && $this->isKey($name)) {
continue;
}
@@ -238,7 +215,7 @@ public function insert() {
else if ($value == "now()") {
/* Lastnotify is normaly set to "now()" and should not be escaped */
$values .= $value ;
- } else if ($value =="" && in_array($name, $this->not_null)) {
+ } else if ($value =="" && in_array($name, static::$not_null)) {
die("<p class='error'><b>$name</b> may not be empty</p>");
} else if ($value !== "") {
$values .= "'" . escape_string($value) . "'";
@@ -248,14 +225,14 @@ public function insert() {
}
- $sql = "insert into $this->table_name ($names) values ($values)";
+ $sql = "INSERT INTO " . DB_PREFIX . static::$table_name . "(" . $names . ") VALUES (" . $values . ")";
query($sql, "Insert failed:");
$id = insert_id();
- if ($this->primary_keys && count($this->primary_keys) == 1) {
- $this->fields[$this->primary_keys[0]] = $id;
+ if (count(static::$primary_keys) == 1) {
+ $this->fields[static::$primary_keys[0]] = $id;
}
return $id;
@@ -275,12 +252,7 @@ public function delete() {
} else {
$extra_tables = null;
}
- $keys = $this->primary_keys;
-
- if (!$this->table_name || !$keys || !$this->fields) {
- log::msg("Missing data", log::ERROR, log::GENERAL);
- return;
- }
+ $keys = static::$primary_keys;
$constraints = $this->createConstraints();
@@ -289,15 +261,14 @@ public function delete() {
return;
}
- $sql = "delete from $this->table_name where $constraints";
+ $sql = "DELETE FROM " . DB_PREFIX . static::$table_name . " WHERE " . $constraints;
query($sql, "Delete failed:");
if ($extra_tables) {
foreach ($extra_tables as $table) {
- $table = DB_PREFIX . $table;
- $sql = "delete from $table where $constraints";
- query($sql, "Delete from $table failed:");
+ $sql = "DELETE FROM " . DB_PREFIX . $table . " WHERE " . $constraints;
+ query($sql, "Delete from " . DB_PREFIX . " $table failed:");
}
}
}
@@ -306,19 +277,10 @@ public function delete() {
* Updates a record.
*/
public function update() {
- $keys = $this->primary_keys;
-
- if (!$this->table_name || !$keys || !$this->fields) {
- log::msg("Missing data", log::ERROR, log::GENERAL);
- return;
- }
+ $keys = static::$primary_keys;
$constraints = $this->createConstraints();
- if (!$constraints) {
- log::msg("No constraint found", log::NOTIFY, log::GENERAL);
- return;
- }
reset($this->fields);
$values=null;
$names=null;
@@ -339,7 +301,7 @@ public function update() {
$values .= "$name = password('" . escape_string($value) . "')";
} else if ($value == "now()" ) {
$values .= "$name = " . $value . "";
- } else if ($value == "" && in_array($name, $this->not_null)) {
+ } else if ($value == "" && in_array($name, static::$not_null)) {
die("<p class='error'><b>$name</b> may not be empty</p>");
} else if ($value !== "" && !is_null($value)) {
$values .= "$name = '" . escape_string($value) . "'";
@@ -350,7 +312,7 @@ public function update() {
if (!$values) { return; }
- $sql = "update $this->table_name set $values where $constraints";
+ $sql = "UPDATE " . DB_PREFIX . static::$table_name ." SET " . $values . " WHERE " . $constraints;
query($sql, "Update failed:");
@@ -384,7 +346,7 @@ public function getDisplayArray() {
public function getEditArray() {
if (!$this->fields) { return; }
- $field_lengths = get_field_lengths($this->table_name);
+ $field_lengths = get_field_lengths(static::$table_name);
$keys = array_keys($field_lengths);
sort($keys);
@@ -505,13 +467,9 @@ public function getDetailsXML(array $details=null) {
/**
* Gets the total count of records in the table for the given class.
* @return int count
- * @todo The 'new' construction needs to be replaced by a static var
*/
public static function getCount() {
- $obj = new static;
- $table = $obj->table_name;
-
- $sql = "select count(*) from $table";
+ $sql = "SELECT COUNT(*) FROM " . DB_PREFIX . static::$table_name;
return static::getCountFromQuery($sql);
}
@@ -523,12 +481,10 @@ public static function getCount() {
* @param string classname
* @param string query SQL query to use
* @return array Table of Top N most popular $class
- * @todo Once minimum PHP version is 5.3, the $class can be replaced by
- * get_called_class()
*/
- protected static function getTopNfromSQL($class, $query) {
+ protected static function getTopNfromSQL($query) {
$pop_array=array();
- $records = $class::getRecordsFromQuery($class, $query);
+ $records = static::getRecordsFromQuery($query);
foreach ($records as $rec) {
$pop_array[$rec->getLink()] = $rec->get("count");
}
@@ -549,18 +505,14 @@ public static function getCountFromQuery($sql) {
* and storing the results in classes of the given type.
* @todo the $class can be removed when PHP5.3 is min version
*/
- public static function getRecords($class, $order = null, $constraints = null,
- $conj = "and", $ops = null) {
-
-
- $obj = new $class;
- $sql = "select * from $obj->table_name";
+ public static function getRecords($order = null, $constraints = null, $conj = "and", $ops = null) {
+ $sql = "SELECT * FROM " . DB_PREFIX . static::$table_name;
if ($constraints) {
while (list($name, $value) = each($constraints)) {
if (!empty($constraint_string)) {
$constraint_string .= " $conj ";
} else {
- $constraint_string = " where ";
+ $constraint_string = " WHERE ";
}
$op = "=";
@@ -575,8 +527,7 @@ public static function getRecords($class, $order = null, $constraints = null,
if ($value == "null" || $value == "''") {
// ok
- }
- else {
+ } else {
$value = "'" . escape_string($value) . "'";
}
@@ -586,12 +537,17 @@ public static function getRecords($class, $order = null, $constraints = null,
}
if ($order) {
- $sql .= " order by $order";
+ $sql .= " ORDER BY $order";
}
- return self::getRecordsFromQuery($class, $sql);
+ return static::getRecordsFromQuery($sql);
}
-
+ /**
+ * Extract a specific class from vars
+ * @param array vars (like $_GET or $_POST)
+ * @param string suffix to add to var key (e.g. _id)
+ * @return array vars for specific class.
+ */
public static function getFromVars(array $vars, $suffix="") {
$class=get_called_class();
$return=array();
@@ -607,10 +563,9 @@ public static function getFromVars(array $vars, $suffix="") {
/**
* Stores the results the the given query in an array of objects of
* this given type.
- * @todo the $class can be removed when PHP5.3 is min version
*/
- public static function getRecordsFromQuery($class, $sql, $min = 0, $num = 0) {
-
+ public static function getRecordsFromQuery($sql, $min = 0, $num = 0) {
+ $class=get_called_class();
$result = query($sql, "Unable to get records");
if ($min) {
@@ -624,30 +579,24 @@ public static function getRecordsFromQuery($class, $sql, $min = 0, $num = 0) {
}
$objs = array();
- if ($class != null) {
- while ((!$limit || $num-- > 0) && $row = fetch_assoc($result)) {
- $obj = new $class;
- $obj->setFields($row);
- $objs[] = $obj;
- }
- } else {
- // use to grab ids, for example
- while ((!$limit || $num-- > 0) && $row = fetch_row($result)) {
- $objs[] = $row[0];
- }
+ while ((!$limit || $num-- > 0) && $row = fetch_assoc($result)) {
+ $obj = new $class;
+ $obj->setFields($row);
+ $objs[] = $obj;
}
free_result($result);
return $objs;
}
+
/**
* Creates a constraint clause based on the given keys
* @param array Fields to use for contstraints
*/
private function createConstraints() {
$constraints=null;
- foreach ($this->primary_keys as $key) {
+ foreach (static::$primary_keys as $key) {
$value = $this->fields[$key];
if (!$value) { continue; }
if (!empty($constraints)) { $constraints .= " and "; }
@@ -655,99 +604,99 @@ private function createConstraints() {
}
return $constraints;
}
-}
-/**
- * Get XML from a database table
- * This is a wrapper around several objects which will call a method from
- * those objects
- * @param string Name of the class to be used
- * @param string Search string
- * @param user Only return records that can be seen by this user
- * @todo This should be replaced by a proper OO construction
- */
-function get_xml($class, $search,$user=null) {
- $search=strtolower($search);
- if($class=="location" || $class=="home" || $class=="work") {
- $class="place";
- } else if ($class=="photographer") {
- $class="person";
- $subclass="photographer";
- } else if ($class=="father" || $class=="mother" || $class=="spouse") {
- $class="person";
- }
-
-
- if($class=="person") {
- $tree=false;
- } else {
- $tree=true;
- }
+ /**
+ * Get XML from a database table
+ * This is a wrapper around several objects which will call a method from
+ * those objects
+ * @param string Name of the class to be used
+ * @param string Search string
+ * @param user Only return records that can be seen by this user
+ * @todo This should be replaced by a proper OO construction
+ */
+ public static function getXML($class, $search,$user=null) {
+ $seach=strtolower($search);
+ if($class=="location" || $class=="home" || $class=="work") {
+ $class="place";
+ } else if ($class=="photographer") {
+ $class="person";
+ $subclass="photographer";
+ } else if ($class=="father" || $class=="mother" || $class=="spouse") {
+ $class="person";
+ }
- if($class=="timezone") {
- $tz=new TimeZone("UTC");
- return $tz->get_xml($search);
- } else if($class=="import_progress") {
- $import=new WebImport($search);
- return $import->get_xml();
- } else if($class=="import_thumbs") {
- return WebImport::getThumbsXML();
- } else if (class_exists($class)) {
- $obj=new $class;
- $rootname=$obj->xml_rootname();
- $nodename=$obj->xml_nodename();
- $idname=$obj->primary_keys[0];
- $xml = new DOMDocument('1.0','UTF-8');
- $rootnode=$xml->createElement($obj->xml_rootname());
- $newchild=$xml->createElement($obj->xml_nodename());
- $key=$xml->createElement("key");
- $title=$xml->createElement("title");
- $key->appendChild($xml->createTextNode("null"));
- $title->appendChild($xml->createTextNode("&nbsp;"));
- $newchild->appendChild($key);
- $newchild->appendChild($title);
- $rootnode->appendChild($newchild);
-
- if ($tree) {
- $obj = $class::getRoot();
- $obj->lookup();
- $tree=$obj->get_xml_tree($xml, $search, $user);
- $rootnode->appendChild($tree);
+ $search=strtolower($search);
+ if($class=="person") {
+ $tree=false;
} else {
- if($class=="person") {
- if($search=="") {
- $search=null;
- }
- if($user->is_admin()) {
- $records=get_all_people($user,$search, true);
- } else {
- if($subclass=="photographer") {
- $records=get_photographers($user,$search,true);
+ $tree=true;
+ }
+
+ if($class=="timezone") {
+ $tz=new TimeZone("UTC");
+ return $tz->get_xml($search);
+ } else if($class=="import_progress") {
+ $import=new WebImport($search);
+ return $import->get_xml();
+ } else if($class=="import_thumbs") {
+ return WebImport::getThumbsXML();
+ } else if (class_exists($class)) {
+ $obj=new $class;
+ $rootname=$obj->xml_rootname();
+ $nodename=$obj->xml_nodename();
+ $idname=$obj::$primary_keys[0];
+
+ $xml = new DOMDocument('1.0','UTF-8');
+ $rootnode=$xml->createElement($obj->xml_rootname());
+ $newchild=$xml->createElement($obj->xml_nodename());
+ $key=$xml->createElement("key");
+ $title=$xml->createElement("title");
+ $key->appendChild($xml->createTextNode("null"));
+ $title->appendChild($xml->createTextNode("&nbsp;"));
+ $newchild->appendChild($key);
+ $newchild->appendChild($title);
+ $rootnode->appendChild($newchild);
+
+ if ($tree) {
+ $obj = $class::getRoot();
+ $obj->lookup();
+ $tree=$obj->get_xml_tree($xml, $search, $user);
+ $rootnode->appendChild($tree);
+ } else {
+ if($class=="person") {
+ if($search=="") {
+ $search=null;
+ }
+ if($user->is_admin()) {
+ $records=get_all_people($user,$search, true);
} else {
- $records=get_photographed_people($user,$search,true);
+ if($subclass=="photographer") {
+ $records=get_photographers($user,$search,true);
+ } else {
+ $records=get_photographed_people($user,$search,true);
+ }
}
- }
- } else {
- $records=get_records($class, $order, $constraints, $conj, $ops);
- }
-
- foreach($records as $record) {
- $newchild=$xml->createElement($nodename);
- $key=$xml->createElement("key");
- $title=$xml->createElement("title");
- $key->appendChild($xml->createTextNode($record->get($idname)));
- $title->appendChild($xml->createTextNode($record->getName()));
- $newchild->appendChild($key);
- $newchild->appendChild($title);
- $rootnode->appendChild($newchild);
- }
+ } else {
+ $records=get_records($class, $order, $constraints, $conj, $ops);
+ }
+
+ foreach($records as $record) {
+ $newchild=$xml->createElement($nodename);
+ $key=$xml->createElement("key");
+ $title=$xml->createElement("title");
+ $key->appendChild($xml->createTextNode($record->get($idname)));
+ $title->appendChild($xml->createTextNode($record->getName()));
+ $newchild->appendChild($key);
+ $newchild->appendChild($title);
+ $rootnode->appendChild($newchild);
+ }
+ }
+ } else {
+ die("illegal class $class");
}
- } else {
- die("illegal class $class");
- }
- $xml->appendChild($rootnode);
- return $xml->saveXML();
+ $xml->appendChild($rootnode);
+ return $xml->saveXML();
+}
}
-
?>
View
23 php/classes/zophTreeTable.inc.php
@@ -65,20 +65,19 @@ public function delete() {
function getChildren($order = null) {
if ($this->children) { return $this->children; }
- if (!$this->primary_keys) { return; }
- $key = $this->primary_keys[0];
- $id = $this->get($key);
+ $key = static::$primary_keys[0];
+ $id = (int) $this->getId();
if (!$id) { return; }
$sql =
- "select * from $this->table_name " .
- "where parent_$key = '" . escape_string($id) . "'";
+ "SELECT * FROM " . static::$table_name .
+ " WHERE parent_ " . $key . "=" . $id;
if ($order) {
- $sql .= " order by $order";
+ $sql .= " ORDER BY $order";
}
- $this->children = zophTreeTable::getRecordsFromQuery(get_class($this), $sql);
+ $this->children = static::getRecordsFromQuery($sql);
return $this->children;
}
@@ -87,9 +86,8 @@ function getChildren($order = null) {
* Gets the ancestors of this record.
*/
function get_ancestors($anc = array()) {
- if (!$this->primary_keys) { return $anc; }
- $key = $this->primary_keys[0];
- $pid = $this->get("parent_$key");
+ $key = static::$primary_keys[0];
+ $pid = $this->get("parent_" . $key);
// root of tree
if ($pid == 0) {
$this->ancestors = $anc;
@@ -112,8 +110,7 @@ function get_ancestors($anc = array()) {
* all of its descendants.
*/
function getBranchIdArray(&$id_array) {
- $key = $this->primary_keys[0];
- $id_array[] = $this->get($key);
+ $id_array[] = (int) $this->getId();
$this->getChildren();
@@ -139,7 +136,7 @@ function getBranchIds() {
function get_xml_tree($xml, $search, $user=null) {
$rootname=$this->xml_rootname();
$nodename=$this->xml_nodename();
- $idname=$this->primary_keys[0];
+ $idname=static::$primary_keys[0];
$newchild=$xml->createElement($nodename);
View
12 php/color_scheme.inc.php
@@ -32,6 +32,17 @@
*/
class color_scheme extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="color_schemes";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("color_scheme_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("name");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="color_schemes.php?color_scheme_id=";
+
private static $current=null;
/**
@@ -40,7 +51,6 @@ class color_scheme extends zophTable {
*/
public function __construct($id = 0) {
if($id && !is_numeric($id)) { die("color_scheme_id must be numeric"); }
- parent::__construct("color_schemes", array("color_scheme_id"), array("name"));
$this->set("color_scheme_id", $id);
}
View
2  php/color_schemes.php
@@ -33,7 +33,7 @@
</h1>
<div class="main">
<?php
- $color_schemes = color_scheme::getRecords("color_scheme", "name");
+ $color_schemes = color_scheme::getRecords("name");
if ($color_schemes) {
foreach($color_schemes as $cs) {
View
16 php/comment.inc.php
@@ -31,9 +31,19 @@
*/
class comment extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="comments";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("comment_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("subject");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="comment.php?comment_id=";
+
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("comment_id must be numeric"); }
- parent::__construct("comments", array("comment_id"), array("subject"));
$this->set("comment_id", $id);
}
@@ -95,7 +105,7 @@ function get_photo() {
$sql = "select photo_id from " . DB_PREFIX . "photo_comments" .
" where comment_id=" . escape_string($this->get("comment_id")) .
" limit 1";
- $result=photo::getRecordsFromQuery("photo", $sql);
+ $result=photo::getRecordsFromQuery($sql);
if($result[0]) {
$result[0]->lookup();
return $result[0];
@@ -163,7 +173,7 @@ function to_html($user, $thumbnail=null) {
}
function get_all_comments() {
- return comment::getRecordsFromQuery("comment", "select comment_id from " . DB_PREFIX . "comments");
+ return comment::getRecordsFromQuery("SELECT comment_id FROM " . DB_PREFIX . "comments");
}
function format_comments($user, $comments) {
View
10 php/database.inc.php
@@ -123,4 +123,14 @@ function db_min_version($version) {
}
}
+ /**
+ * Run a query and return result as an array
+ * @param string SQL query
+ */
+ function getArrayFromQuery($sql) {
+ while ($row = fetch_row($result)) {
+ $objs[] = $row[0];
+ }
+ }
+
?>
View
2  php/getxmldata.php
@@ -31,6 +31,6 @@
echo $obj->getDetailsXML();
} else {
- echo get_xml($object, $search, $user);
+ echo zophTable::getXML($object, $search, $user);
}
?>
View
22 php/group.inc.php
@@ -19,10 +19,20 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class group extends zophTable {
-
- function group($id = 0) {
+ /** @var string The name of the database table */
+ protected static $table_name="groups";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("group_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("group_name");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="group.php?group_id=";
+
+
+ function __construct($id = 0) {
if($id && !is_numeric($id)) { die("user_id must be numeric"); }
- parent::__construct("groups", array("group_id"), array("group_name"));
$this->set("group_id", $id);
}
@@ -55,7 +65,7 @@ function get_albums() {
$sql="SELECT album_id FROM " .
DB_PREFIX . "group_permissions " .
"WHERE group_id=" . escape_string($this->get("group_id"));
- return album::getRecordsFromQuery("album", $sql);
+ return album::getRecordsFromQuery($sql);
}
function getDisplayArray() {
@@ -74,7 +84,7 @@ function get_members() {
DB_PREFIX . "groups_users " .
"WHERE group_id=" . escape_string($this->get("group_id"));
- return user::getRecordsFromQuery("user", $sql);
+ return user::getRecordsFromQuery($sql);
}
function add_member($member_id) {
@@ -150,7 +160,7 @@ function get_members_links($separator="&nbsp;") {
}
function get_groups($order = "group_name") {
- return group::getRecords("group", $order);
+ return group::getRecords($order);
}
?>
View
13 php/group_permissions.inc.php
@@ -23,14 +23,23 @@
*/
class group_permissions extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="group_permissions";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("group_id", "album_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = true;
+ /** @var string URL for this class */
+ protected static $url="group.php?group_id=";
+
function __construct($gid = -1, $aid = -1) {
if($gid && !is_numeric($gid)) { die("group_id must be numeric"); }
if($aid && !is_numeric($aid)) { die("album_id must be numeric"); }
- parent::__construct("group_permissions", array("group_id", "album_id"), array(""));
$this->set("group_id", $gid);
$this->set("album_id", $aid);
- $this->keepKeys=true;
}
function insert() {
View
16 php/page.inc.php
@@ -19,9 +19,19 @@
*/
class page extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="pages";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("page_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("title");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="page.php?page_id=";
+
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("page_id must be numeric"); }
- parent::__construct("pages", array("page_id"), array("title"));
$this->set("page_id", $id);
}
@@ -96,7 +106,7 @@ function get_pagesets() {
$html="";
$sql = "select pageset_id from " . DB_PREFIX . "pages_pageset" .
" where page_id = " . $this->get("page_id");
- $pagesets=pageset::getRecordsFromQuery("pageset", $sql);
+ $pagesets=pageset::getRecordsFromQuery($sql);
if(!empty($pagesets)) {
$html=get_pagesets_table_header();
foreach ($pagesets as $pageset) {
@@ -143,7 +153,7 @@ function get_page_table($pages_array, $pageset_id) {
function get_pages($constraints = null, $conj = "and", $ops = null,
$order = "title") {
- return pageset::getRecords("page", $order, $constraints, $conj, $ops);
+ return pageset::getRecords($order, $constraints, $conj, $ops);
}
function get_pages_select_array($pages_array = null) {
View
20 php/pageset.inc.php
@@ -18,9 +18,19 @@
*/
class pageset extends zophTable {
- function pageset($id = 0) {
+ /** @var string The name of the database table */
+ protected static $table_name="pageset";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("pageset_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("title");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="pageset.php?pageset_id=";
+
+ function __construct($id = 0) {
if($id && !is_numeric($id)) { die("pageset_id must be numeric"); }
- parent::__construct("pageset", array("pageset_id"), array("title"));
$this->set("pageset_id", $id);
$this->set("date","now()");
}
@@ -62,7 +72,7 @@ function get_pages($pagenum=null) {
if($pagenum) {
$sql.=" limit " . escape_string($pagenum) . ",1";
}
- $pages=page::getRecordsFromQuery("page", $sql);
+ $pages=page::getRecordsFromQuery($sql);
return $pages;
}
@@ -178,7 +188,7 @@ function get_list_line() {
function get_all_pagesets() {
$sql = "select pageset_id,title,date,timestamp,user from " . DB_PREFIX . "pageset";
- $pagesets=pageset::getRecordsFromQuery("pageset", $sql);
+ $pagesets=pageset::getRecordsFromQuery($sql);
$html=get_pagesets_table_header();
foreach ($pagesets as $pageset) {
@@ -200,7 +210,7 @@ function get_pagesets_table_header() {
function get_pagesets($constraints = null, $conj = "and", $ops = null,
$order = "title") {
- return pageset::getRecords("pageset", $order, $constraints, $conj, $ops);
+ return pageset::getRecords($order, $constraints, $conj, $ops);
}
function get_pageset_select_array($pageset_array = null) {
View
26 php/person.inc.php
@@ -32,6 +32,17 @@
* @package Zoph
*/
class person extends zophTable implements Organizer {
+ /** @var string The name of the database table */
+ protected static $table_name="people";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("person_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("first_name");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="person.php?person_id=";
+
/** @var location Home address of this person */
public $home;
/** @var location Work address of this person */
@@ -39,7 +50,6 @@ class person extends zophTable implements Organizer {
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("person_id must be numeric"); }
- parent::__construct("people", array("person_id"), array("first_name"));
$this->set("person_id", $id);
}
@@ -328,7 +338,7 @@ function getCoverphoto($autothumb=null) {
" AND gp.access_level >= p.level " .
$order;
}
- $coverphotos=photo::getRecordsFromQuery("photo", $sql);
+ $coverphotos=photo::getRecordsFromQuery($sql);
$coverphoto=array_shift($coverphotos);
}
@@ -462,7 +472,7 @@ public static function getByName($name) {
$sql = "SELECT person_id FROM " . DB_PREFIX . "people WHERE " .
"CONCAT_WS(\" \", lower(first_name), lower(last_name))=" .
"lower(\"" . escape_string($name) . "\")";
- return person::getRecordsFromQuery("person", $sql);
+ return person::getRecordsFromQuery($sql);
}
/**
@@ -502,14 +512,14 @@ public static function getTopN() {
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
}
- return parent::getTopNfromSQL("person", $sql);
+ return static::getTopNfromSQL($sql);
}
}
function get_people($constraints = null, $conj = "and", $ops = null,
$order = "last_name, first_name", $user=null) {
- return person::getRecords("person", $order, $constraints, $conj, $ops);
+ return person::getRecords($order, $constraints, $conj, $ops);
}
function get_people_count($user = null, $search = null) {
@@ -560,7 +570,7 @@ function get_all_people($user = null, $search = null, $search_first = false) {
$sql="SELECT * FROM " . DB_PREFIX . "people AS ppl " . $where .
" ORDER BY last_name, called, first_name";
- return person::getRecordsFromQuery("person", $sql);
+ return person::getRecordsFromQuery($sql);
}
function get_photographed_people($user = null, $search=null, $search_first = false) {
@@ -593,7 +603,7 @@ function get_photographed_people($user = null, $search=null, $search_first = fal
" order by ppl.last_name, ppl.called, ppl.first_name";
}
- return person::getRecordsFromQuery("person", $sql);
+ return person::getRecordsFromQuery($sql);
}
function get_photographers($user = null, $search = null, $search_first = null) {
@@ -626,7 +636,7 @@ function get_photographers($user = null, $search = null, $search_first = null) {
"order by ppl.last_name, ppl.called, ppl.first_name";
}
- return person::getRecordsFromQuery("person", $sql);
+ return person::getRecordsFromQuery($sql);
}
function get_where_for_search($conj, $search, $search_first) {
View
28 php/photo.inc.php
@@ -30,6 +30,17 @@
* @package Zoph
*/
class photo extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="photos";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("photo_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="photo.php?photo_id=";
+
/** @var photographer */
public $photographer;
/** @var location */
@@ -47,7 +58,6 @@ class photo extends zophTable {
*/
public function __construct($id = 0) {
if($id && !is_numeric($id)) { die("photo_id must be numeric"); }
- parent::__construct("photos", array("photo_id"), array(""));
$this->set("photo_id",$id);
}
@@ -302,7 +312,7 @@ public function getAlbums() {
" ORDER BY al.album";
}
- return album::getRecordsFromQuery("album", $sql);
+ return album::getRecordsFromQuery($sql);
}
/**
@@ -316,7 +326,7 @@ public function getCategories() {
"WHERE pc.photo_id = '" . (int) $this->getId() . "'" .
" AND pc.category_id = cat.category_id ORDER BY cat.category";
- return album::getRecordsFromQuery("category", $sql);
+ return category::getRecordsFromQuery($sql);
}
/**
@@ -331,7 +341,7 @@ function getPeople() {
"WHERE pp.photo_id = '" . (int) $this->getId() . "'" .
" AND pp.person_id = p.person_id ORDER BY pp.position";
- return album::getRecordsFromQuery("person", $sql);
+ return person::getRecordsFromQuery($sql);
}
/**
@@ -897,7 +907,7 @@ function getTimeDetails() {
function get_comments() {
$sql = "select comment_id from " . DB_PREFIX . "photo_comments where" .
" photo_id = " . $this->get("photo_id");
- $comments=comment::getRecordsFromQuery("comment", $sql);
+ $comments=comment::getRecordsFromQuery($sql);
return $comments;
}
@@ -1025,7 +1035,7 @@ public static function getPhotosNear($lat, $lon, $distance,
"having distance <= " . $distance .
" order by distance" . $lim;
- $near=photo::getRecordsFromQuery("photo", $sql);
+ $near=photo::getRecordsFromQuery($sql);
return $near;
} else {
return null;
@@ -1038,7 +1048,7 @@ public static function getByName($file, $path=null) {
if(!empty($path)) {
$sql .= " AND path='" . escape_string($path) ."'";
}
- return photo::getRecordsFromQuery("photo", $sql);
+ return photo::getRecordsFromQuery($sql);
}
public function getHashFromFile() {
@@ -1121,7 +1131,7 @@ public function getLatLon(track $track=null, $max_time=300, $interpolate=true,
" ORDER BY abs(timediff(datetime,\"" . date("Y-m-d H:i:s", $utc) . "\")) ASC" .
" LIMIT 1";
- $points=point::getRecordsFromQuery("point", $sql);
+ $points=point::getRecordsFromQuery($sql);
if(sizeof($points) > 0 && $points[0] instanceof point) {
$point=$points[0];
$pointtime=strtotime($point->get("datetime"));
@@ -1290,7 +1300,7 @@ public static function getFromHash($hash, $type="file") {
$sql="SELECT * FROM " . DB_PREFIX . "photos " . $where;
- $photos=photo::getRecordsFromQuery("photo", $sql);
+ $photos=photo::getRecordsFromQuery($sql);
if(is_array($photos) && sizeof($photos) > 0) {
return $photos[0];
} else {
View
15 php/photo_search.inc.php
@@ -126,7 +126,7 @@ function get_photos($vars, $offset, $rows, &$thumbnails, $user = null) {
$query = "select person_id from " . DB_PREFIX . "people where
lower(concat(first_name, \" \", last_name)) like \"$val\"";
- $people = person::getRecordsFromQuery("person", $query);
+ $people = person::getRecordsFromQuery($query);
$key .= "_id";
@@ -317,8 +317,7 @@ function get_photos($vars, $offset, $rows, &$thumbnails, $user = null) {
$no_rate_sql="SELECT DISTINCT(photo_id) FROM " .
DB_PREFIX . "photo_ratings AS pr " .
"WHERE pr.user_id=" . escape_string($ratinguser_id);
-
- $ids = implode(',', zophTable::getRecordsFromQuery(null, $no_rate_sql));
+ $ids = implode(',', getArrayFromQuery($no_rate_sql));
if ($ids) {
$where .= "(ph.photo_id not in ($ids))";
@@ -445,7 +444,7 @@ function get_photos($vars, $offset, $rows, &$thumbnails, $user = null) {
"limit $offset, $rows";
}
- $thumbnails = photo::getRecordsFromQuery("photo", $query);
+ $thumbnails = photo::getRecordsFromQuery($query);
}
@@ -496,8 +495,7 @@ function generate_excluded_albums_clause($excluded_albums, $from, $where) {
if ($where) {
$photo_id_query .= " and $where";
}
-
- $ids = implode(',', zophTable::getRecordsFromQuery(null, $photo_id_query));
+ $ids = implode(',', getArrayFromQuery($photo_id_query));
if ($ids) {
if ($album_constraints || $where) {
@@ -529,7 +527,7 @@ function generate_excluded_categories_clause($excluded_categories, $from, $where
$photo_id_query .= " and $where";
}
- $ids = implode(',', zophTable::getRecordsFromQuery(null, $photo_id_query));
+ $ids = implode(',', getArrayFromQuery($photo_id_query));
if ($ids) {
if ($cat_constraints || $where) {
@@ -560,8 +558,7 @@ function generate_excluded_people_clause($excluded_people, $from, $where) {
if ($where) {
$photo_id_query .= " and $where";
}
-
- $ids = implode(',', zophTable::getRecordsFromQuery(null, $photo_id_query));
+ $ids = implode(',', getArrayFromQuery($photo_id_query));
if ($ids) {
if ($person_constraints || $where) {
View
28 php/place.inc.php
@@ -31,10 +31,20 @@
* @author Jeroen Roos
*/
class place extends zophTreeTable implements Organizer {
+ /** @var string The name of the database table */
+ protected static $table_name="places";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("place_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("title");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="place.php?place_id=";
+
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("place_id must be numeric"); }
- parent::__construct("places", array("place_id"), array("title"));
$this->set("place_id", $id);
}
@@ -134,7 +144,7 @@ public function getChildren($order=null) {
"WHERE pl.parent_place_id=" . (int) $this->getId() .
" GROUP BY pl.place_id " .
$order;
- $this->children=place::getRecordsFromQuery("place", $sql);
+ $this->children=place::getRecordsFromQuery($sql);
return $this->children;
}
@@ -249,7 +259,7 @@ public function getPhotos() {
"' AND gp.access_level >= p.level";
}
- return photo::getRecordsFromQuery("photo", $sql);
+ return photo::getRecordsFromQuery($sql);
}
/**
@@ -369,7 +379,7 @@ public function getCoverphoto($autothumb=null,$children=null) {
" AND gp.access_level >= p.level " .
$order;
}
- $coverphotos=photo::getRecordsFromQuery("photo", $sql);
+ $coverphotos=photo::getRecordsFromQuery($sql);
$coverphoto=array_shift($coverphotos);
}
@@ -488,7 +498,7 @@ public static function getNear($lat, $lon, $distance,
"having distance <= " . $distance .
" order by distance" . $lim;
- $near=place::getRecordsFromQuery("place", $sql);
+ $near=place::getRecordsFromQuery($sql);
return $near;
} else {
return null;
@@ -565,7 +575,7 @@ public static function getByName($name) {
$sql="SELECT place_id from " . DB_PREFIX . "places WHERE " .
" LOWER(title) = \"" . $title . "\";";
- return place::getRecordsFromQuery("place", $sql);
+ return place::getRecordsFromQuery($sql);
}
/**
@@ -611,14 +621,14 @@ public static function getTopN() {
"LIMIT 0, " . (int) $user->prefs->get("reports_top_n");
}
- return parent::getTopNfromSQL("place", $sql);
+ return parent::getTopNfromSQL($sql);
}
}
function get_places($constraints = null, $conj = "and", $ops = null,
$order = "city, title, address") {
- return place::getRecords("place", $order, $constraints, $conj, $ops);
+ return place::getRecords($order, $constraints, $conj, $ops);
}
function get_photographed_places($user = null) {
@@ -649,7 +659,7 @@ function get_photographed_places($user = null) {
"order by plc.city, plc.title";
}
- return place::getRecordsFromQuery("place", $sql);
+ return place::getRecordsFromQuery($sql);
}
function get_places_count($user) {
View
18 php/point.inc.php
@@ -29,12 +29,22 @@
* @package Zoph
*/
class point extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="point";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("point_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url;
+
/**
* Create a point object
*/
public function __construct($id = 0) {
if($id && !is_numeric($id)) { die("point_id must be numeric"); }
- parent::__construct("point", array("point_id"), array());
$this->set("point_id", $id);
}
@@ -86,7 +96,7 @@ public function getNext() {
" track_id = " . escape_string($this->get("track_id")) . " AND " .
" datetime>\"" . escape_string($this->get("datetime")) . "\"" .
" ORDER BY datetime LIMIT 1";
- $points=point::getRecordsFromQuery("point", $sql);
+ $points=point::getRecordsFromQuery($sql);
if(is_array($points) && sizeof($points) > 0) {
return $points[0];
} else {
@@ -102,7 +112,7 @@ public function getPrev() {
" track_id = " . escape_string($this->get("track_id")) . " AND " .
" datetime<\"" . escape_string($this->get("datetime")) . "\"" .
" ORDER BY datetime DESC LIMIT 1";
- $points=point::getRecordsFromQuery("point", $sql);
+ $points=point::getRecordsFromQuery($sql);
if(is_array($points) && sizeof($points) > 0) {
return $points[0];
} else {
@@ -125,7 +135,7 @@ public function getPrev() {
public static function getAll($constraints = null, $conj = "and",
$ops = null, $order = "name") {
- return point::getRecords("point", $order, $constraints, $conj, $ops);
+ return point::getRecords($order, $constraints, $conj, $ops);
}
/**
View
13 php/prefs.inc.php
@@ -21,14 +21,23 @@
*/
class prefs extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="prefs";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("user_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = true;
+ /** @var string URL for this class */
+ protected static $url="prefs.php#";
+
private $color_scheme;
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("user_id must be numeric"); }
- parent::__construct("prefs", array("user_id"), array(""));
$this->set("user_id", $id);
- $this->keepKeys = true;
}
function lookup_color_scheme($force = 0) {
View
2  php/prefs.php
@@ -151,7 +151,7 @@
?>
</dt>
<dd>
-<?php echo create_pulldown("color_scheme_id", $user->prefs->get("color_scheme_id"), template::createSelectArray(color_scheme::getRecords("color_scheme", "name"), array("name"))) ?>
+<?php echo create_pulldown("color_scheme_id", $user->prefs->get("color_scheme_id"), template::createSelectArray(color_scheme::getRecords("name"), array("name"))) ?>
</dd>
<?php
$langs = language::getAll();
View
16 php/saved_search.inc.php
@@ -20,10 +20,20 @@
*/
class search extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="saved_search";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("search_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("name");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="search.php?search_id=";
+
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("search_id must be numeric"); }
- parent::__construct("saved_search", array("search_id"), array("name"));
$this->set("search_id", $id);
}
@@ -62,7 +72,7 @@ public function getEditArray() {
if($user->is_admin()) {
$edit_array[]=array (
translate("Owner"),
- create_pulldown("owner", $this->get("owner"), template::createSelectArray(user::getRecords("user", "user_name"), array("user_name"))));
+ create_pulldown("owner", $this->get("owner"), template::createSelectArray(user::getRecords("user_name"), array("user_name"))));
$edit_array[]=array(
translate("Public"),
create_pulldown("public", $this->get("public"), array("0" => translate("No",0), "1" => translate("Yes",0))) );
@@ -95,7 +105,7 @@ function get_saved_searches($user) {
$sql.=" WHERE (owner=" . escape_string($user->get("user_id")) .
" OR " . "public=TRUE)";
}
- return search::getRecordsFromQuery("search", $sql);
+ return search::getRecordsFromQuery($sql);
}
function get_list_of_saved_searches($user) {
View
2  php/templates/default/blocks/geotag_form.tpl.php
@@ -54,7 +54,7 @@
<legend><?php echo translate("Tracks"); ?></legend>
<input type="radio" name="_tracks" id="tracks" value="all" checked><?php echo translate("All tracks"); ?><br>
<input type="radio" name="_tracks" id="tracks2" value="specific"><?php echo translate("Specific track") . ": " ?>
- <?php echo create_pulldown("_track", "", template::createSelectArray(track::getRecords("track", "track_id"), array("name"))) ?>
+ <?php echo create_pulldown("_track", "", template::createSelectArray(track::getRecords("track_id"), array("name"))) ?>
</fieldset>
</fieldset>
<fieldset class="geotag">
View
20 php/track.inc.php
@@ -26,6 +26,17 @@
* @package Zoph
*/
class track extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="track";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("track_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("name");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="track.php?track_id=";
+
private $points=array();
/**
@@ -37,7 +48,6 @@ class track extends zophTable {
*/
public function __construct($id = 0) {
if($id && !is_numeric($id)) { die("track_id must be numeric"); }
- parent::__construct("track", array("track_id"), array("name"));
$this->set("track_id", $id);
}
@@ -182,7 +192,7 @@ public function getFirstPoint() {
$sql="SELECT * FROM " . DB_PREFIX . "point" .
" WHERE track_id=" . (int) escape_string($this->getId()) .
" ORDER BY datetime ASC LIMIT 1";
- $points=point::getRecordsFromQuery("point", $sql);
+ $points=point::getRecordsFromQuery($sql);
$first=$points[0];
if(($first instanceof point)) {
return $first;
@@ -196,9 +206,9 @@ public function getFirstPoint() {
*/
public function getLastPoint() {
$sql="SELECT * FROM " . DB_PREFIX . "point" .
- " WHERE track_id=" . (int) escape_string($this->getId()) .
+ " WHERE track_id=" . (int) $this->getId() .
" ORDER BY datetime DESC LIMIT 1";
- $points=point::getRecordsFromQuery("point", $sql);
+ $points=point::getRecordsFromQuery($sql);
$last=$points[0];
if(($last instanceof point)) {
return