-<?php\r
-/**\r
- * API Exception Stub\r
- *\r
- * Generic parent class for API exceptions.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Exceptions.Stub\r
- */\r
+<?php
+/**
+ * API Exception Stub
+ *
+ * Generic parent class for API exceptions.
+ *
+ * @package Elgg.Core
+ * @subpackage Exceptions.Stub
+ */
class APIException extends Exception {}
\ No newline at end of file
-<?php\r
-/**\r
- * The access control component of the query class.\r
- *\r
- * @todo probably remove.\r
- * @access private\r
- * @package Elgg.Core\r
- * @subpackage Unimplemented\r
- */\r
-class AccessControlQueryComponent extends QueryComponent {\r
- /**\r
- * Construct the ACL.\r
- *\r
- * @param string $acl_table The table where the access control field is.\r
- * @param string $acl_field The field containing the access control.\r
- * @param string $object_owner_table The table containing the owner information for the stuff you're retrieving.\r
- * @param string $object_owner_id_field The field in $object_owner_table containing the owner information\r
- */\r
- function __construct($acl_table = "entities", $acl_field = "access_id", $object_owner_table = "entities", $object_owner_id_field = "owner_guid") {\r
- global $CONFIG;\r
-\r
- $this->acl_table = $CONFIG->dbprefix . sanitise_string($acl_table);\r
- $this->acl_field = sanitise_string($acl_field);\r
- $this->object_owner_table = $CONFIG->dbprefix . sanitise_string($object_owner_table);\r
- $this->object_owner_id_field = sanitise_string($object_owner_id_field);\r
- }\r
-\r
- function __toString() {\r
- //$access = get_access_list();\r
- // KJ - changed to use get_access_sql_suffix\r
- // Note: currently get_access_sql_suffix is hardwired to use\r
- // $acl_field = "access_id", $object_owner_table = $acl_table, and\r
- // $object_owner_id_field = "owner_guid"\r
- // @todo recode get_access_sql_suffix to make it possible to specify alternate field names\r
- return "and ".get_access_sql_suffix($this->acl_table); // Add access controls\r
-\r
- //return "and ({$this->acl_table}.{$this->acl_field} in {$access} or ({$this->acl_table}.{$this->acl_field} = 0 and {$this->object_owner_table}.{$this->object_owner_id_field} = {$_SESSION['id']}))";\r
- }\r
+<?php
+/**
+ * The access control component of the query class.
+ *
+ * @todo probably remove.
+ * @access private
+ * @package Elgg.Core
+ * @subpackage Unimplemented
+ */
+class AccessControlQueryComponent extends QueryComponent {
+ /**
+ * Construct the ACL.
+ *
+ * @param string $acl_table The table where the access control field is.
+ * @param string $acl_field The field containing the access control.
+ * @param string $object_owner_table The table containing the owner information for the stuff you're retrieving.
+ * @param string $object_owner_id_field The field in $object_owner_table containing the owner information
+ */
+ function __construct($acl_table = "entities", $acl_field = "access_id", $object_owner_table = "entities", $object_owner_id_field = "owner_guid") {
+ global $CONFIG;
+
+ $this->acl_table = $CONFIG->dbprefix . sanitise_string($acl_table);
+ $this->acl_field = sanitise_string($acl_field);
+ $this->object_owner_table = $CONFIG->dbprefix . sanitise_string($object_owner_table);
+ $this->object_owner_id_field = sanitise_string($object_owner_id_field);
+ }
+
+ function __toString() {
+ //$access = get_access_list();
+ // KJ - changed to use get_access_sql_suffix
+ // Note: currently get_access_sql_suffix is hardwired to use
+ // $acl_field = "access_id", $object_owner_table = $acl_table, and
+ // $object_owner_id_field = "owner_guid"
+ // @todo recode get_access_sql_suffix to make it possible to specify alternate field names
+ return "and ".get_access_sql_suffix($this->acl_table); // Add access controls
+
+ //return "and ({$this->acl_table}.{$this->acl_field} in {$access} or ({$this->acl_table}.{$this->acl_field} = 0 and {$this->object_owner_table}.{$this->object_owner_id_field} = {$_SESSION['id']}))";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Call Exception Stub\r
- *\r
- * Generic parent class for Call exceptions\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Exceptions.Stub\r
- */\r
+<?php
+/**
+ * Call Exception Stub
+ *
+ * Generic parent class for Call exceptions
+ *
+ * @package Elgg.Core
+ * @subpackage Exceptions.Stub
+ */
class CallException extends Exception {}
\ No newline at end of file
-<?php\r
-/**\r
- * Class Exception\r
- *\r
- * A generic parent class for Class exceptions\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Exceptions.Stub\r
- */\r
-class ClassException extends Exception {}\r
+<?php
+/**
+ * Class Exception
+ *
+ * A generic parent class for Class exceptions
+ *
+ * @package Elgg.Core
+ * @subpackage Exceptions.Stub
+ */
+class ClassException extends Exception {}
-<?php\r
-/**\r
- * Class not found\r
- *\r
- * Thrown when trying to load a class that doesn't exist.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Exceptions\r
- */\r
+<?php
+/**
+ * Class not found
+ *
+ * Thrown when trying to load a class that doesn't exist.
+ *
+ * @package Elgg.Core
+ * @subpackage Exceptions
+ */
class ClassNotFoundException extends ClassException {}
\ No newline at end of file
-<?php\r
-/**\r
- * Configuration exception\r
- *\r
- * A generic parent class for Configuration exceptions\r
- *\r
- * @package Elgg\r
- * @subpackage Exceptions.Stub\r
- */\r
-class ConfigurationException extends Exception {}\r
+<?php
+/**
+ * Configuration exception
+ *
+ * A generic parent class for Configuration exceptions
+ *
+ * @package Elgg
+ * @subpackage Exceptions.Stub
+ */
+class ConfigurationException extends Exception {}
-<?php\r
-/**\r
- * Cron exception\r
- *\r
- * A generic parent class for cron exceptions\r
- *\r
- * @package Elgg\r
- * @subpackage Exceptions.Stub\r
- */\r
+<?php
+/**
+ * Cron exception
+ *
+ * A generic parent class for cron exceptions
+ *
+ * @package Elgg
+ * @subpackage Exceptions.Stub
+ */
class CronException extends Exception {}
\ No newline at end of file
-<?php\r
-/**\r
- * Data format exception\r
- * An exception thrown when there is a problem in the format of some data.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Exceptions.Stub\r
- */\r
-class DataFormatException extends Exception {}\r
+<?php
+/**
+ * Data format exception
+ * An exception thrown when there is a problem in the format of some data.
+ *
+ * @package Elgg.Core
+ * @subpackage Exceptions.Stub
+ */
+class DataFormatException extends Exception {}
-<?php\r
-/**\r
- * Database Exception\r
- *\r
- * A generic parent class for database exceptions\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Exceptions.Stub\r
- */\r
-class DatabaseException extends Exception {}\r
+<?php
+/**
+ * Database Exception
+ *
+ * A generic parent class for database exceptions
+ *
+ * @package Elgg.Core
+ * @subpackage Exceptions.Stub
+ */
+class DatabaseException extends Exception {}
-<?php\r
-/**\r
- * Delete query\r
- *\r
- * @todo probably remove.\r
- * @access private\r
- * @package Elgg.Core\r
- * @subpackage Unimplemented\r
- */\r
-class DeleteQueryTypeQueryComponent extends QueryTypeQueryComponent\r
-{\r
- function __construct()\r
- {\r
- $this->query_type = "DELETE FROM";\r
- }\r
-}\r
+<?php
+/**
+ * Delete query
+ *
+ * @todo probably remove.
+ * @access private
+ * @package Elgg.Core
+ * @subpackage Unimplemented
+ */
+class DeleteQueryTypeQueryComponent extends QueryTypeQueryComponent
+{
+ function __construct()
+ {
+ $this->query_type = "DELETE FROM";
+ }
+}
-<?php\r
-/**\r
- * Class used to determin if access is being ignored.\r
- *\r
- * @access private\r
- * @todo I don't remember why this was required beyond scope concerns.\r
- * @see elgg_get_ignore_access()\r
- * @package Elgg.Core\r
- * @subpackage Access\r
- */\r
-class ElggAccess {\r
- /**\r
- * Bypass Elgg's access control if true.\r
- * @var bool\r
- */\r
- private $ignore_access;\r
-\r
- /**\r
- * Get current ignore access setting.\r
- * @return bool\r
- */\r
- public function get_ignore_access() {\r
- return $this->ignore_access;\r
- }\r
-\r
- /**\r
- * Set ignore access.\r
- *\r
- * @param $ignore bool true || false to ignore\r
- * @return bool Previous setting\r
- */\r
- public function set_ignore_access($ignore = true) {\r
- $prev = $this->ignore_access;\r
- $this->ignore_access = $ignore;\r
-\r
- return $prev;\r
- }\r
+<?php
+/**
+ * Class used to determin if access is being ignored.
+ *
+ * @access private
+ * @todo I don't remember why this was required beyond scope concerns.
+ * @see elgg_get_ignore_access()
+ * @package Elgg.Core
+ * @subpackage Access
+ */
+class ElggAccess {
+ /**
+ * Bypass Elgg's access control if true.
+ * @var bool
+ */
+ private $ignore_access;
+
+ /**
+ * Get current ignore access setting.
+ * @return bool
+ */
+ public function get_ignore_access() {
+ return $this->ignore_access;
+ }
+
+ /**
+ * Set ignore access.
+ *
+ * @param $ignore bool true || false to ignore
+ * @return bool Previous setting
+ */
+ public function set_ignore_access($ignore = true) {
+ $prev = $this->ignore_access;
+ $this->ignore_access = $ignore;
+
+ return $prev;
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Elgg Annotations\r
- *\r
- * Annotations allow you to attach bits of information to entities.\r
- * They are essentially the same as metadata, but with additional\r
- * helper functions.\r
- *\r
- * @internal Annotations are stored in the annotations table.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage DataModel.Annotations\r
- * @link http://docs.elgg.org/DataModel/Annotations\r
- */\r
-class ElggAnnotation extends ElggExtender {\r
-\r
- /**\r
- * Construct a new annotation, optionally from a given id value or db object.\r
- *\r
- * @param mixed $id\r
- */\r
- function __construct($id = null) {\r
- $this->attributes = array();\r
-\r
- if (!empty($id)) {\r
- if ($id instanceof stdClass) {\r
- $annotation = $id;\r
- } else {\r
- $annotation = get_annotation($id);\r
- }\r
-\r
- if ($annotation) {\r
- $objarray = (array) $annotation;\r
-\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
-\r
- $this->attributes['type'] = "annotation";\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Class member get overloading\r
- *\r
- * @param string $name\r
- * @return mixed\r
- */\r
- function __get($name) {\r
- return $this->get($name);\r
- }\r
-\r
- /**\r
- * Class member set overloading\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- * @return void\r
- */\r
- function __set($name, $value) {\r
- return $this->set($name, $value);\r
- }\r
-\r
- /**\r
- * Save this instance\r
- *\r
- * @return int an object id\r
- */\r
- function save() {\r
- if ($this->id > 0) {\r
- return update_annotation($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id);\r
- } else {\r
- $this->id = create_annotation($this->entity_guid, $this->name, $this->value,\r
- $this->value_type, $this->owner_guid, $this->access_id);\r
-\r
- if (!$this->id) {\r
- throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class()));\r
- }\r
- return $this->id;\r
- }\r
- }\r
-\r
- /**\r
- * Delete the annotation.\r
- */\r
- function delete() {\r
- return delete_annotation($this->id);\r
- }\r
-\r
- /**\r
- * Get a url for this annotation.\r
- *\r
- * @return string\r
- */\r
- public function getURL() {\r
- return get_annotation_url($this->id);\r
- }\r
-\r
- // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * For a given ID, return the object associated with it.\r
- * This is used by the river functionality primarily.\r
- * This is useful for checking access permissions etc on objects.\r
- */\r
- public function getObjectFromID($id) {\r
- return get_annotation($id);\r
- }\r
+<?php
+/**
+ * Elgg Annotations
+ *
+ * Annotations allow you to attach bits of information to entities.
+ * They are essentially the same as metadata, but with additional
+ * helper functions.
+ *
+ * @internal Annotations are stored in the annotations table.
+ *
+ * @package Elgg.Core
+ * @subpackage DataModel.Annotations
+ * @link http://docs.elgg.org/DataModel/Annotations
+ */
+class ElggAnnotation extends ElggExtender {
+
+ /**
+ * Construct a new annotation, optionally from a given id value or db object.
+ *
+ * @param mixed $id
+ */
+ function __construct($id = null) {
+ $this->attributes = array();
+
+ if (!empty($id)) {
+ if ($id instanceof stdClass) {
+ $annotation = $id;
+ } else {
+ $annotation = get_annotation($id);
+ }
+
+ if ($annotation) {
+ $objarray = (array) $annotation;
+
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+
+ $this->attributes['type'] = "annotation";
+ }
+ }
+ }
+
+ /**
+ * Class member get overloading
+ *
+ * @param string $name
+ * @return mixed
+ */
+ function __get($name) {
+ return $this->get($name);
+ }
+
+ /**
+ * Class member set overloading
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return void
+ */
+ function __set($name, $value) {
+ return $this->set($name, $value);
+ }
+
+ /**
+ * Save this instance
+ *
+ * @return int an object id
+ */
+ function save() {
+ if ($this->id > 0) {
+ return update_annotation($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id);
+ } else {
+ $this->id = create_annotation($this->entity_guid, $this->name, $this->value,
+ $this->value_type, $this->owner_guid, $this->access_id);
+
+ if (!$this->id) {
+ throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class()));
+ }
+ return $this->id;
+ }
+ }
+
+ /**
+ * Delete the annotation.
+ */
+ function delete() {
+ return delete_annotation($this->id);
+ }
+
+ /**
+ * Get a url for this annotation.
+ *
+ * @return string
+ */
+ public function getURL() {
+ return get_annotation_url($this->id);
+ }
+
+ // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) {
+ return get_annotation($id);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * ElggCache The elgg cache superclass.\r
- * This defines the interface for a cache (wherever that cache is stored).\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Cache\r
- */\r
-abstract class ElggCache implements\r
- // Override for array access\r
- ArrayAccess {\r
- /**\r
- * Variables for the cache object.\r
- *\r
- * @var array\r
- */\r
- private $variables;\r
-\r
- /**\r
- * Set the constructor.\r
- */\r
- function __construct() {\r
- $this->variables = array();\r
- }\r
-\r
- /**\r
- * Set a cache variable.\r
- *\r
- * @param string $variable\r
- * @param string $value\r
- */\r
- public function set_variable($variable, $value) {\r
- if (!is_array($this->variables)) {\r
- $this->variables = array();\r
- }\r
-\r
- $this->variables[$variable] = $value;\r
- }\r
-\r
- /**\r
- * Get variables for this cache.\r
- *\r
- * @param string $variable\r
- * @return mixed The variable or null;\r
- */\r
- public function get_variable($variable) {\r
- if (isset($this->variables[$variable])) {\r
- return $this->variables[$variable];\r
- }\r
-\r
- return null;\r
- }\r
-\r
- /**\r
- * Class member get overloading, returning key using $this->load defaults.\r
- *\r
- * @param string $key\r
- * @return mixed\r
- */\r
- function __get($key) {\r
- return $this->load($key);\r
- }\r
-\r
- /**\r
- * Class member set overloading, setting a key using $this->save defaults.\r
- *\r
- * @param string $key\r
- * @param mixed $value\r
- * @return mixed\r
- */\r
- function __set($key, $value) {\r
- return $this->save($key, $value);\r
- }\r
-\r
- /**\r
- * Supporting isset, using $this->load() with default values.\r
- *\r
- * @param string $key The name of the attribute or metadata.\r
- * @return bool\r
- */\r
- function __isset($key) {\r
- return (bool)$this->load($key);\r
- }\r
-\r
- /**\r
- * Supporting unsetting of magic attributes.\r
- *\r
- * @param string $key The name of the attribute or metadata.\r
- */\r
- function __unset($key) {\r
- return $this->delete($key);\r
- }\r
-\r
- /**\r
- * Save data in a cache.\r
- *\r
- * @param string $key\r
- * @param string $data\r
- * @return bool\r
- */\r
- abstract public function save($key, $data);\r
-\r
- /**\r
- * Load data from the cache using a given key.\r
- *\r
- * @param string $key\r
- * @param int $offset\r
- * @param int $limit\r
- * @return mixed The stored data or false.\r
- */\r
- abstract public function load($key, $offset = 0, $limit = null);\r
-\r
- /**\r
- * Invalidate a key\r
- *\r
- * @param string $key\r
- * @return bool\r
- */\r
- abstract public function delete($key);\r
-\r
- /**\r
- * Clear out all the contents of the cache.\r
- *\r
- */\r
- abstract public function clear();\r
-\r
- /**\r
- * Add a key only if it doesn't already exist.\r
- * Implemented simply here, if you extend this class and your caching engine provides a better way then\r
- * override this accordingly.\r
- *\r
- * @param string $key\r
- * @param string $data\r
- * @return bool\r
- */\r
- public function add($key, $data) {\r
- if (!isset($this[$key])) {\r
- return $this->save($key, $data);\r
- }\r
-\r
- return false;\r
- }\r
-\r
- // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////\r
- function offsetSet($key, $value) {\r
- $this->save($key, $value);\r
- }\r
-\r
- function offsetGet($key) {\r
- return $this->load($key);\r
- }\r
-\r
- function offsetUnset($key) {\r
- if ( isset($this->key) ) {\r
- unset($this->key);\r
- }\r
- }\r
-\r
- function offsetExists($offset) {\r
- return isset($this->$offset);\r
- }\r
+<?php
+/**
+ * ElggCache The elgg cache superclass.
+ * This defines the interface for a cache (wherever that cache is stored).
+ *
+ * @package Elgg.Core
+ * @subpackage Cache
+ */
+abstract class ElggCache implements
+ // Override for array access
+ ArrayAccess {
+ /**
+ * Variables for the cache object.
+ *
+ * @var array
+ */
+ private $variables;
+
+ /**
+ * Set the constructor.
+ */
+ function __construct() {
+ $this->variables = array();
+ }
+
+ /**
+ * Set a cache variable.
+ *
+ * @param string $variable
+ * @param string $value
+ */
+ public function set_variable($variable, $value) {
+ if (!is_array($this->variables)) {
+ $this->variables = array();
+ }
+
+ $this->variables[$variable] = $value;
+ }
+
+ /**
+ * Get variables for this cache.
+ *
+ * @param string $variable
+ * @return mixed The variable or null;
+ */
+ public function get_variable($variable) {
+ if (isset($this->variables[$variable])) {
+ return $this->variables[$variable];
+ }
+
+ return null;
+ }
+
+ /**
+ * Class member get overloading, returning key using $this->load defaults.
+ *
+ * @param string $key
+ * @return mixed
+ */
+ function __get($key) {
+ return $this->load($key);
+ }
+
+ /**
+ * Class member set overloading, setting a key using $this->save defaults.
+ *
+ * @param string $key
+ * @param mixed $value
+ * @return mixed
+ */
+ function __set($key, $value) {
+ return $this->save($key, $value);
+ }
+
+ /**
+ * Supporting isset, using $this->load() with default values.
+ *
+ * @param string $key The name of the attribute or metadata.
+ * @return bool
+ */
+ function __isset($key) {
+ return (bool)$this->load($key);
+ }
+
+ /**
+ * Supporting unsetting of magic attributes.
+ *
+ * @param string $key The name of the attribute or metadata.
+ */
+ function __unset($key) {
+ return $this->delete($key);
+ }
+
+ /**
+ * Save data in a cache.
+ *
+ * @param string $key
+ * @param string $data
+ * @return bool
+ */
+ abstract public function save($key, $data);
+
+ /**
+ * Load data from the cache using a given key.
+ *
+ * @param string $key
+ * @param int $offset
+ * @param int $limit
+ * @return mixed The stored data or false.
+ */
+ abstract public function load($key, $offset = 0, $limit = null);
+
+ /**
+ * Invalidate a key
+ *
+ * @param string $key
+ * @return bool
+ */
+ abstract public function delete($key);
+
+ /**
+ * Clear out all the contents of the cache.
+ *
+ */
+ abstract public function clear();
+
+ /**
+ * Add a key only if it doesn't already exist.
+ * Implemented simply here, if you extend this class and your caching engine provides a better way then
+ * override this accordingly.
+ *
+ * @param string $key
+ * @param string $data
+ * @return bool
+ */
+ public function add($key, $data) {
+ if (!isset($this[$key])) {
+ return $this->save($key, $data);
+ }
+
+ return false;
+ }
+
+ // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
+ function offsetSet($key, $value) {
+ $this->save($key, $value);
+ }
+
+ function offsetGet($key) {
+ return $this->load($key);
+ }
+
+ function offsetUnset($key) {
+ if ( isset($this->key) ) {
+ unset($this->key);
+ }
+ }
+
+ function offsetExists($offset) {
+ return isset($this->$offset);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * The parent class for all Elgg Entities.\r
- *\r
- * An ElggEntity is one of the basic data models in Elgg. It is the primary\r
- * means of storing and retrieving data from the database. An ElggEntity\r
- * represents one row of the entities table.\r
- *\r
- * The ElggEntity class handles CRUD operations for the entities table.\r
- * ElggEntity should always be extended by another class to handle CRUD\r
- * operations on the type-specific table.\r
- *\r
- * ElggEntity uses magic methods for get and set, so any property that isn't\r
- * declared will be assumed to be metadata and written to the database\r
- * as metadata on the object. All children classes must declare which\r
- * properties are columns of the type table or they will be assumed\r
- * to be metadata. See ElggObject::initialise_entities() for examples.\r
- *\r
- * Core supports 4 types of entities: ElggObject, ElggUser, ElggGroup, and\r
- * ElggSite.\r
- *\r
- * @tip Most plugin authors will want to extend the ElggObject class\r
- * instead of this class.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage DataMode.Entities\r
- * @link http://docs.elgg.org/DataModel/ElggEntity\r
- */\r
-abstract class ElggEntity implements\r
- Notable, // Calendar interface\r
- Locatable, // Geocoding interface\r
- Exportable, // Allow export of data\r
- Importable, // Allow import of data\r
- Loggable, // Can events related to this object class be logged\r
- Iterator, // Override foreach behaviour\r
- ArrayAccess // Override for array access\r
-{\r
- /**\r
- * The main attributes of an entity.\r
- * Blank entries for all database fields should be created by the constructor.\r
- * Subclasses should add to this in their constructors.\r
- * Any field not appearing in this will be viewed as a\r
- */\r
- protected $attributes;\r
-\r
- /**\r
- * If set, overrides the value of getURL()\r
- */\r
- protected $url_override;\r
-\r
- /**\r
- * Icon override, overrides the value of getIcon().\r
- */\r
- protected $icon_override;\r
-\r
- /**\r
- * Holds metadata until entity is saved. Once the entity is saved, metadata are written immediately to the database.\r
- */\r
- protected $temp_metadata;\r
-\r
- /**\r
- * Holds annotations until entity is saved. Once the entity is saved, annotations are written immediately to the database.\r
- */\r
- protected $temp_annotations;\r
-\r
-\r
- /**\r
- * Volatile data structure for this object, allows for storage of data\r
- * in-memory that isn't sync'd back to the metadata table.\r
- */\r
- protected $volatile;\r
-\r
- /**\r
- * Initialise the attributes array.\r
- *\r
- * This is vital to distinguish between metadata and base parameters.\r
- *\r
- * @return void\r
- */\r
- protected function initialise_attributes() {\r
- initialise_entity_cache();\r
-\r
- // Create attributes array if not already created\r
- if (!is_array($this->attributes)) {\r
- $this->attributes = array();\r
- }\r
- if (!is_array($this->temp_metadata)) {\r
- $this->temp_metadata = array();\r
- }\r
- if (!is_array($this->temp_annotations)) {\r
- $this->temp_annotations = array();\r
- }\r
- if (!is_array($this->volatile)) {\r
- $this->volatile = array();\r
- }\r
-\r
- $this->attributes['guid'] = "";\r
- $this->attributes['type'] = "";\r
- $this->attributes['subtype'] = "";\r
-\r
- $this->attributes['owner_guid'] = get_loggedin_userid();\r
- $this->attributes['container_guid'] = get_loggedin_userid();\r
-\r
- $this->attributes['site_guid'] = 0;\r
- $this->attributes['access_id'] = ACCESS_PRIVATE;\r
- $this->attributes['time_created'] = "";\r
- $this->attributes['time_updated'] = "";\r
- $this->attributes['last_action'] = '';\r
- $this->attributes['enabled'] = "yes";\r
-\r
- // There now follows a bit of a hack\r
- /* Problem: To speed things up, some objects are split over several tables, this means that it requires\r
- * n number of database reads to fully populate an entity. This causes problems for caching and create events\r
- * since it is not possible to tell whether a subclassed entity is complete.\r
- * Solution: We have two counters, one 'tables_split' which tells whatever is interested how many tables\r
- * are going to need to be searched in order to fully populate this object, and 'tables_loaded' which is how\r
- * many have been loaded thus far.\r
- * If the two are the same then this object is complete.\r
- *\r
- * Use: isFullyLoaded() to check\r
- */\r
- $this->attributes['tables_split'] = 1;\r
- $this->attributes['tables_loaded'] = 0;\r
- }\r
-\r
- /**\r
- * Clone an entity\r
- *\r
- * Resets the guid so that the entity can be saved as a distinct entity from\r
- * the original. Creation time will be set when this new entity is saved.\r
- * The owner and container guids come from the original entity. The clone\r
- * method copies metadata but does not copy annotations or private settings.\r
- *\r
- * @note metadata will have its owner and access id set when the entity is saved\r
- * and it will be the same as that of the entity.\r
- */\r
- public function __clone() {\r
- $orig_entity = get_entity($this->guid);\r
- if (!$orig_entity) {\r
- elgg_log("Failed to clone entity with GUID $this->guid", "ERROR");\r
- return;\r
- }\r
-\r
- $metadata_array = get_metadata_for_entity($this->guid);\r
-\r
- $this->attributes['guid'] = "";\r
-\r
- $this->attributes['subtype'] = $orig_entity->getSubtype();\r
-\r
- // copy metadata over to new entity - slightly convoluted due to\r
- // handling of metadata arrays\r
- if (is_array($metadata_array)) {\r
- // create list of metadata names\r
- $metadata_names = array();\r
- foreach ($metadata_array as $metadata) {\r
- $metadata_names[] = $metadata['name'];\r
- }\r
- // arrays are stored with multiple enties per name\r
- $metadata_names = array_unique($metadata_names);\r
-\r
- // move the metadata over\r
- foreach ($metadata_names as $name) {\r
- $this->set($name, $orig_entity->$name);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Return the value of a property.\r
- *\r
- * If $name is defined in $this->attributes that value is returned, otherwise it will\r
- * pull from the entity's metadata.\r
- *\r
- * Q: Why are we not using __get overload here?\r
- * A: Because overload operators cause problems during subclassing, so we put the code here and\r
- * create overloads in subclasses.\r
- * @todo What problems are these?\r
- *\r
- * @warning Subtype is returned as an id rather than the subtype string. Use getSubtype()\r
- * to get the subtype string.\r
- *\r
- * @param string $name\r
- * @return mixed Returns the value of a given value, or null.\r
- */\r
- public function get($name) {\r
- // See if its in our base attributes\r
- if (isset($this->attributes[$name])) {\r
- return $this->attributes[$name];\r
- }\r
-\r
- // No, so see if its in the meta data for this entity\r
- $meta = $this->getMetaData($name);\r
-\r
- // getMetaData returns NULL if $name is not found\r
- return $meta;\r
- }\r
-\r
- /**\r
- * Sets the value of a property.\r
- *\r
- * If $name is defined in $this->attributes that value is set, otherwise it will\r
- * set the appropriate item of metadata.\r
- *\r
- * @warning It is important that your class populates $this->attributes with keys for all base attributes, anything\r
- * not in their gets set as METADATA.\r
- *\r
- * Q: Why are we not using __set overload here?\r
- * A: Because overload operators cause problems during subclassing, so we put the code here and\r
- * create overloads in subclasses.\r
- * @todo What problems?\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- */\r
- public function set($name, $value) {\r
- if (array_key_exists($name, $this->attributes)) {\r
- // Certain properties should not be manually changed!\r
- switch ($name) {\r
- case 'guid':\r
- case 'time_created':\r
- case 'time_updated':\r
- case 'last_action':\r
- return FALSE;\r
- break;\r
- default:\r
- $this->attributes[$name] = $value;\r
- break;\r
- }\r
- } else {\r
- return $this->setMetaData($name, $value);\r
- }\r
-\r
- return TRUE;\r
- }\r
-\r
- /**\r
- * Return the value of a piece of metadata.\r
- *\r
- * @param string $name\r
- * @return mixed The value, or NULL if not found.\r
- */\r
- public function getMetaData($name) {\r
- if ((int) ($this->guid) > 0) {\r
- $md = get_metadata_byname($this->getGUID(), $name);\r
- } else {\r
- if (isset($this->temp_metadata[$name])) {\r
- return $this->temp_metadata[$name];\r
- }\r
- }\r
-\r
- if ($md && !is_array($md)) {\r
- return $md->value;\r
- } else if ($md && is_array($md)) {\r
- return metadata_array_to_values($md);\r
- }\r
-\r
- return null;\r
- }\r
-\r
- /**\r
- * Return an attribute or a piece of metadata.\r
- *\r
- * @param string $name\r
- * @return mixed\r
- */\r
- function __get($name) {\r
- return $this->get($name);\r
- }\r
-\r
- /**\r
- * Set an attribute or a piece of metadata.\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- * @return mixed\r
- */\r
- function __set($name, $value) {\r
- return $this->set($name, $value);\r
- }\r
-\r
- /**\r
- * Test if property is set either as an attribute or metadata.\r
- *\r
- * @tip Use isset($entity->property)\r
- *\r
- * @param string $name The name of the attribute or metadata.\r
- * @return bool\r
- */\r
- function __isset($name) {\r
- return $this->$name !== NULL;\r
- }\r
-\r
- /**\r
- * Unset a property from metadata or attribute.\r
- *\r
- * @warning If you use this to unset an attribute, you must save the object!\r
- *\r
- * @param string $name The name of the attribute or metadata.\r
- */\r
- function __unset($name) {\r
- if (array_key_exists($name, $this->attributes)) {\r
- $this->attributes[$name] = "";\r
- }\r
- else {\r
- $this->clearMetaData($name);\r
- }\r
- }\r
-\r
- /**\r
- * Set a piece of metadata.\r
- *\r
- * @tip Plugin authors should use the magic methods.\r
- *\r
- * @access private\r
- * @param string $name Name of the metadata\r
- * @param mixed $value Value of the metadata\r
- * @param string $value_type Types supported: integer and string. Will auto-identify if not set\r
- * @param bool $multiple (does not support associative arrays)\r
- * @return bool\r
- */\r
- public function setMetaData($name, $value, $value_type = "", $multiple = false) {\r
- if (is_array($value)) {\r
- unset($this->temp_metadata[$name]);\r
- remove_metadata($this->getGUID(), $name);\r
- foreach ($value as $v) {\r
- if ((int) $this->guid > 0) {\r
- $multiple = true;\r
- if (!create_metadata($this->getGUID(), $name, $v, $value_type,\r
- $this->getOwner(), $this->getAccessID(), $multiple)) {\r
- return false;\r
- }\r
- } else {\r
- if (($multiple) && (isset($this->temp_metadata[$name]))) {\r
- if (!is_array($this->temp_metadata[$name])) {\r
- $tmp = $this->temp_metadata[$name];\r
- $this->temp_metadata[$name] = array();\r
- $this->temp_metadata[$name][] = $tmp;\r
- }\r
-\r
- $this->temp_metadata[$name][] = $value;\r
- }\r
- else {\r
- $this->temp_metadata[$name] = $value;\r
- }\r
- }\r
- }\r
-\r
- return true;\r
- } else {\r
- unset($this->temp_metadata[$name]);\r
- if ((int) $this->guid > 0) {\r
- $result = create_metadata($this->getGUID(), $name, $value, $value_type, $this->getOwner(), $this->getAccessID(), $multiple);\r
- return (bool)$result;\r
- } else {\r
- if (($multiple) && (isset($this->temp_metadata[$name]))) {\r
- if (!is_array($this->temp_metadata[$name])) {\r
- $tmp = $this->temp_metadata[$name];\r
- $this->temp_metadata[$name] = array();\r
- $this->temp_metadata[$name][] = $tmp;\r
- }\r
-\r
- $this->temp_metadata[$name][] = $value;\r
- }\r
- else {\r
- $this->temp_metadata[$name] = $value;\r
- }\r
-\r
- return true;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Remove metadata\r
- *\r
- * @warning Calling this with no or empty arguments will clear all metadata on the entity.\r
- * @param string The name of the metadata to clear\r
- * @return mixed The n\r
- */\r
- public function clearMetaData($name = "") {\r
- if (empty($name)) {\r
- return clear_metadata($this->getGUID());\r
- } else {\r
- return remove_metadata($this->getGUID(), $name);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get a piece of volatile (non-persisted) data on this entity.\r
- *\r
- * @param string $name The name of the volatile data\r
- * @return mixed The value or NULL if not found.\r
- */\r
- public function getVolatileData($name) {\r
- if (!is_array($this->volatile)) {\r
- $this->volatile = array();\r
- }\r
-\r
- if (array_key_exists($name, $this->volatile)) {\r
- return $this->volatile[$name];\r
- } else {\r
- return NULL;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Set a piece of volatile (non-persisted) data on this entity\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- */\r
- public function setVolatileData($name, $value) {\r
- if (!is_array($this->volatile)) {\r
- $this->volatile = array();\r
- }\r
-\r
- $this->volatile[$name] = $value;\r
- }\r
-\r
-\r
- /**\r
- * Remove all relationships to and from this entity.\r
- *\r
- * @return true\r
- * @todo This should actually return if it worked.\r
- * @see ElggEntity::addRelationship()\r
- * @see ElggEntity::removeRelationship()\r
- */\r
- public function clearRelationships() {\r
- remove_entity_relationships($this->getGUID());\r
- remove_entity_relationships($this->getGUID(), "", true);\r
- return true;\r
- }\r
-\r
- /**\r
- * Add a relationship between this an another entity.\r
- *\r
- * @tip Read the relationship like "$guid is a $relationship of this entity."\r
- *\r
- * @param int $guid Entity to link to.\r
- * @param string $relationship The type of relationship.\r
- * @return bool\r
- * @see ElggEntity::removeRelationship()\r
- * @see ElggEntity::clearRelationships()\r
- */\r
- public function addRelationship($guid, $relationship) {\r
- return add_entity_relationship($this->getGUID(), $relationship, $guid);\r
- }\r
-\r
- /**\r
- * Remove a relationship\r
- *\r
- * @param int $guid\r
- * @param str $relationship\r
- * @return bool\r
- * @see ElggEntity::addRelationship()\r
- * @see ElggEntity::clearRelationships()\r
- */\r
- public function removeRelationship($guid, $relationship) {\r
- return remove_entity_relationship($this->getGUID(), $relationship, $guid);\r
- }\r
-\r
- /**\r
- * Adds a private setting to this entity.\r
- *\r
- * Private settings are similar to metadata but will not\r
- * be searched and there are fewer helper functions for them.\r
- *\r
- * @param $name\r
- * @param $value\r
- * @return bool\r
- * @link http://docs.elgg.org/DataModel/Entities/PrivateSettings\r
- */\r
- function setPrivateSetting($name, $value) {\r
- return set_private_setting($this->getGUID(), $name, $value);\r
- }\r
-\r
- /**\r
- * Returns a private setting value\r
- *\r
- * @param $name\r
- * @return mixed\r
- */\r
- function getPrivateSetting($name) {\r
- return get_private_setting($this->getGUID(), $name);\r
- }\r
-\r
- /**\r
- * Removes private setting\r
- *\r
- * @param $name\r
- * @return bool\r
- */\r
- function removePrivateSetting($name) {\r
- return remove_private_setting($this->getGUID(), $name);\r
- }\r
-\r
- /**\r
- * Adds an annotation to an entity.\r
- *\r
- * @warning By default, annotations are private.\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- * @param int $access_id\r
- * @param int $owner_id\r
- * @param string $vartype\r
- * @link http://docs.elgg.org/DataModel/Annotations\r
- */\r
- function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_id = 0, $vartype = "") {\r
- if ((int) $this->guid > 0) {\r
- return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_id, $access_id);\r
- } else {\r
- $this->temp_annotations[$name] = $value;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Returns an array of annotations.\r
- *\r
- * @param string $name\r
- * @param int $limit\r
- * @param int $offset\r
- * @param string $order asc or desc\r
- * @return array\r
- */\r
- function getAnnotations($name, $limit = 50, $offset = 0, $order="asc") {\r
- if ((int) ($this->guid) > 0) {\r
- return get_annotations($this->getGUID(), "", "", $name, "", 0, $limit, $offset, $order);\r
- } else {\r
- return $this->temp_annotations[$name];\r
- }\r
- }\r
-\r
- /**\r
- * Remove an annotation or all annotations for this entity.\r
- *\r
- * @warning Calling this method with no or an empty argument will remove all annotations on the entity.\r
- *\r
- * @param string $name\r
- * @return bool\r
- */\r
- function clearAnnotations($name = "") {\r
- return clear_annotations($this->getGUID(), $name);\r
- }\r
-\r
- /**\r
- * Count annotations.\r
- *\r
- * @param string $name The type of annotation.\r
- * @return int\r
- */\r
- function countAnnotations($name = "") {\r
- return count_annotations($this->getGUID(), "", "", $name);\r
- }\r
-\r
- /**\r
- * Get the average of an integer type annotation.\r
- *\r
- * @param string $name\r
- * @return int\r
- */\r
- function getAnnotationsAvg($name) {\r
- return get_annotations_avg($this->getGUID(), "", "", $name);\r
- }\r
-\r
- /**\r
- * Get the sum of integer type annotations of a given name.\r
- *\r
- * @param string $name\r
- * @return int\r
- */\r
- function getAnnotationsSum($name) {\r
- return get_annotations_sum($this->getGUID(), "", "", $name);\r
- }\r
-\r
- /**\r
- * Get the minimum of integer type annotations of given name.\r
- *\r
- * @param string $name\r
- * @return int\r
- */\r
- function getAnnotationsMin($name) {\r
- return get_annotations_min($this->getGUID(), "", "", $name);\r
- }\r
-\r
- /**\r
- * Get the maximum of integer type annotations of a given name.\r
- *\r
- * @param string $name\r
- * @return int\r
- */\r
- function getAnnotationsMax($name) {\r
- return get_annotations_max($this->getGUID(), "", "", $name);\r
- }\r
-\r
- /**\r
- * Gets an array of entities with a relationship to this entity.\r
- *\r
- * @param string $relationship Relationship type (eg "friends")\r
- * @param true|false $inverse Is this an inverse relationship?\r
- * @param int $limit Number of elements to return\r
- * @param int $offset Indexing offset\r
- * @return array|false An array of entities or false on failure\r
- */\r
- function getEntitiesFromRelationship($relationship, $inverse = false, $limit = 50, $offset = 0) {\r
- return elgg_get_entities_from_relationship(array(\r
- 'relationship' => $relationship,\r
- 'relationship_guid' => $this->getGUID(),\r
- 'inverse_relationship' => $inverse,\r
- 'limit' => $limit,\r
- 'offset' => $offset\r
- ));\r
- }\r
-\r
- /**\r
- * Gets the number of of entities from a specific relationship type\r
- *\r
- * @param string $relationship Relationship type (eg "friends")\r
- * @param bool $inverse_relationship\r
- * @return int|false The number of entities or false on failure\r
- */\r
- function countEntitiesFromRelationship($relationship, $inverse_relationship = FALSE) {\r
- return elgg_get_entities_from_relationship(array(\r
- 'relationship' => $relationship,\r
- 'relationship_guid' => $this->getGUID(),\r
- 'inverse_relationship' => $inverse_relationship,\r
- 'count' => TRUE\r
- ));\r
- }\r
-\r
- /**\r
- * Can a user edit this entity.\r
- *\r
- * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)\r
- * @return true|false\r
- */\r
- function canEdit($user_guid = 0) {\r
- return can_edit_entity($this->getGUID(), $user_guid);\r
- }\r
-\r
- /**\r
- * Can a user edit metadata on this entity\r
- *\r
- * @param ElggMetadata $metadata The piece of metadata to specifically check\r
- * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)\r
- * @return true|false\r
- */\r
- function canEditMetadata($metadata = null, $user_guid = 0) {\r
- return can_edit_entity_metadata($this->getGUID(), $user_guid, $metadata);\r
- }\r
-\r
- /**\r
- * Can a user write to this entity's container.\r
- *\r
- * @param int $user_guid The user.\r
- * @return bool\r
- */\r
- public function canWriteToContainer($user_guid = 0) {\r
- return can_write_to_container($user_guid, $this->getGUID());\r
- }\r
-\r
- /**\r
- * Returns the access_id.\r
- *\r
- * @return int The access ID\r
- */\r
- public function getAccessID() {\r
- return $this->get('access_id');\r
- }\r
-\r
- /**\r
- * Returns the guid.\r
- *\r
- * @return int GUID\r
- */\r
- public function getGUID() {\r
- return $this->get('guid');\r
- }\r
-\r
- /**\r
- * Return the guid of the entity's owner.\r
- *\r
- * @return int The owner GUID\r
- */\r
- public function getOwner() {\r
- return $this->get('owner_guid');\r
- }\r
-\r
- /**\r
- * Returns the ElggEntity or child object of the owner of the entity.\r
- *\r
- * @return ElggEntity The owning user\r
- */\r
- public function getOwnerEntity() {\r
- return get_entity($this->get('owner_guid'));\r
- }\r
-\r
- /**\r
- * Returns the entity type\r
- *\r
- * @return string Entity type\r
- */\r
- public function getType() {\r
- return $this->get('type');\r
- }\r
-\r
- /**\r
- * Returns the entity subtype string\r
- *\r
- * @note This returns a string. If you want the id, use ElggEntity::subtype.\r
- *\r
- * @return string The entity subtype\r
- */\r
- public function getSubtype() {\r
- // If this object hasn't been saved, then return the subtype string.\r
- if (!((int) $this->guid > 0)) {\r
- return $this->get('subtype');\r
- }\r
-\r
- return get_subtype_from_id($this->get('subtype'));\r
- }\r
-\r
- /**\r
- * Returns the UNIX epoch time that this entity was created\r
- *\r
- * @return int UNIX epoch time\r
- */\r
- public function getTimeCreated() {\r
- return $this->get('time_created');\r
- }\r
-\r
- /**\r
- * Returns the UNIX epoch time that this entity was last updated\r
- *\r
- * @return int UNIX epoch time\r
- */\r
- public function getTimeUpdated() {\r
- return $this->get('time_updated');\r
- }\r
-\r
- /**\r
- * Returns the URL for this entity\r
- *\r
- * @return string The URL\r
- * @see register_entity_url_handler()\r
- * @see ElggEntity::setURL()\r
- */\r
- public function getURL() {\r
- if (!empty($this->url_override)) {\r
- return $this->url_override;\r
- }\r
- return get_entity_url($this->getGUID());\r
- }\r
-\r
- /**\r
- * Overrides the URL returned by getURL()\r
- *\r
- * @warning This override exists only for the life of the object.\r
- *\r
- * @param string $url The new item URL\r
- * @return string The URL\r
- */\r
- public function setURL($url) {\r
- $this->url_override = $url;\r
- return $url;\r
- }\r
-\r
- /**\r
- * Returns a URL for the entity's icon.\r
- *\r
- * @param string $size Either 'large', 'medium', 'small' or 'tiny'\r
- * @return string The url or false if no url could be worked out.\r
- * @see get_entity_icon_url()\r
- */\r
- public function getIcon($size = 'medium') {\r
- if (isset($this->icon_override[$size])) {\r
- return $this->icon_override[$size];\r
- }\r
- return get_entity_icon_url($this, $size);\r
- }\r
-\r
- /**\r
- * Set an icon override for an icon and size.\r
- *\r
- * @warning This override exists only for the life of the object.\r
- *\r
- * @param string $url The url of the icon.\r
- * @param string $size The size its for.\r
- * @return bool\r
- */\r
- public function setIcon($url, $size = 'medium') {\r
- $url = sanitise_string($url);\r
- $size = sanitise_string($size);\r
-\r
- if (!$this->icon_override) {\r
- $this->icon_override = array();\r
- }\r
- $this->icon_override[$size] = $url;\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Tests to see whether the object has been fully loaded.\r
- *\r
- * @return bool\r
- */\r
- public function isFullyLoaded() {\r
- return ! ($this->attributes['tables_loaded'] < $this->attributes['tables_split']);\r
- }\r
-\r
- /**\r
- * Save attributes to the entities table.\r
- *\r
- * @return bool\r
- * @throws IOException\r
- */\r
- public function save() {\r
- $guid = (int) $this->guid;\r
- if ($guid > 0) {\r
- cache_entity($this);\r
-\r
- return update_entity(\r
- $this->get('guid'),\r
- $this->get('owner_guid'),\r
- $this->get('access_id'),\r
- $this->get('container_guid')\r
- );\r
- } else {\r
- // Create a new entity (nb: using attribute array directly 'cos set function does something special!)\r
- $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']);\r
- if (!$this->attributes['guid']) {\r
- throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));\r
- }\r
-\r
- // Save any unsaved metadata\r
- // @todo How to capture extra information (access id etc)\r
- if (sizeof($this->temp_metadata) > 0) {\r
- foreach($this->temp_metadata as $name => $value) {\r
- $this->$name = $value;\r
- unset($this->temp_metadata[$name]);\r
- }\r
- }\r
-\r
- // Save any unsaved annotations metadata.\r
- // @todo How to capture extra information (access id etc)\r
- if (sizeof($this->temp_annotations) > 0) {\r
- foreach($this->temp_annotations as $name => $value) {\r
- $this->annotate($name, $value);\r
- unset($this->temp_annotations[$name]);\r
- }\r
- }\r
-\r
- // set the subtype to id now rather than a string\r
- $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']);\r
-\r
- // Cache object handle\r
- if ($this->attributes['guid']) {\r
- cache_entity($this);\r
- }\r
-\r
- return $this->attributes['guid'];\r
- }\r
- }\r
-\r
- /**\r
- * Loads attributes from the entities table into the object.\r
- *\r
- * @param int $guid\r
- * @return bool\r
- */\r
- protected function load($guid) {\r
- $row = get_entity_as_row($guid);\r
-\r
- if ($row) {\r
- // Create the array if necessary - all subclasses should test before creating\r
- if (!is_array($this->attributes)) {\r
- $this->attributes = array();\r
- }\r
-\r
- // Now put these into the attributes array as core values\r
- $objarray = (array) $row;\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
-\r
- // Increment the portion counter\r
- if (!$this->isFullyLoaded()) {\r
- $this->attributes['tables_loaded']++;\r
- }\r
-\r
- // Cache object handle\r
- if ($this->attributes['guid']) {\r
- cache_entity($this);\r
- }\r
-\r
- return true;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Disable this entity.\r
- *\r
- * Disabled entities are not returned by getter functions.\r
- * To enable an entity, use {@link enable_entity()}.\r
- *\r
- * Recursively disabling an entity will disable all entities\r
- * owned or contained by the parent entity.\r
- *\r
- * @internal Disabling an entity sets the 'enabled' column to 'no'.\r
- *\r
- * @param string $reason Optional reason\r
- * @param bool $recursive Recursively disable all contained entities?\r
- * @return bool\r
- * @see enable_entity()\r
- * @see ElggEntity::enable()\r
- */\r
- public function disable($reason = "", $recursive = true) {\r
- return disable_entity($this->get('guid'), $reason, $recursive);\r
- }\r
-\r
- /**\r
- * Enable an entity\r
- *\r
- * @warning Disabled entities can't be loaded unless\r
- * {@link access_show_hidden_entities(true)} has been called.\r
- *\r
- * @see enable_entity()\r
- * @see access_show_hiden_entities()\r
- * @return bool\r
- */\r
- public function enable() {\r
- return enable_entity($this->get('guid'));\r
- }\r
-\r
- /**\r
- * Is this entity enabled?\r
- *\r
- * @return boolean\r
- */\r
- public function isEnabled() {\r
- if ($this->enabled == 'yes') {\r
- return true;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Delete this entity.\r
- *\r
- * @return bool\r
- */\r
- public function delete() {\r
- return delete_entity($this->get('guid'));\r
- }\r
-\r
- /*\r
- * LOCATABLE INTERFACE\r
- */\r
-\r
- /**\r
- * Sets the 'location' metadata for the entity\r
- *\r
- * @todo Unimplemented\r
- * @param string $location\r
- * @return true\r
- */\r
- public function setLocation($location) {\r
- $location = sanitise_string($location);\r
-\r
- $this->location = $location;\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Set latitude and longitude metadata tags for a given entity.\r
- *\r
- * @param float $lat\r
- * @param float $long\r
- * @return true\r
- * @todo Unimplemented\r
- */\r
- public function setLatLong($lat, $long) {\r
- $lat = sanitise_string($lat);\r
- $long = sanitise_string($long);\r
-\r
- $this->set('geo:lat', $lat);\r
- $this->set('geo:long', $long);\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Return the entity's latitude.\r
- *\r
- * @return int\r
- * @todo Unimplemented\r
- */\r
- public function getLatitude() {\r
- return $this->get('geo:lat');\r
- }\r
-\r
- /**\r
- * Return the entity's longitude\r
- *\r
- * @return Int\r
- */\r
- public function getLongitude() {\r
- return $this->get('geo:long');\r
- }\r
-\r
- /**\r
- * Return the entity's location\r
- *\r
- * @return string\r
- */\r
- public function getLocation() {\r
- return $this->get('location');\r
- }\r
-\r
- /*\r
- * NOTABLE INTERFACE\r
- */\r
-\r
- /**\r
- * Set the time and duration of an object\r
- *\r
- * @param int $hour If ommitted, now is assumed.\r
- * @param int $minute If ommitted, now is assumed.\r
- * @param int $second If ommitted, now is assumed.\r
- * @param int $day If ommitted, now is assumed.\r
- * @param int $month If ommitted, now is assumed.\r
- * @param int $year If ommitted, now is assumed.\r
- * @param int $duration Duration of event, remainder of the day is assumed.\r
- * @return true\r
- * @todo Unimplemented\r
- */\r
- public function setCalendarTimeAndDuration($hour = NULL, $minute = NULL, $second = NULL, $day = NULL, $month = NULL, $year = NULL, $duration = NULL) {\r
- $start = mktime($hour, $minute, $second, $month, $day, $year);\r
- $end = $start + abs($duration);\r
- if (!$duration) {\r
- $end = get_day_end($day,$month,$year);\r
- }\r
-\r
- $this->calendar_start = $start;\r
- $this->calendar_end = $end;\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Returns the start timestamp.\r
- *\r
- * @return int\r
- * @todo Unimplemented\r
- */\r
- public function getCalendarStartTime() {\r
- return (int)$this->calendar_start;\r
- }\r
-\r
- /**\r
- * Returns the end timestamp.\r
- *\r
- * @todo Unimplemented\r
- */\r
- public function getCalendarEndTime() {\r
- return (int)$this->calendar_end;\r
- }\r
-\r
- /*\r
- * EXPORTABLE INTERFACE\r
- */\r
-\r
- /**\r
- * Returns an array of fields which can be exported.\r
- *\r
- * @return array\r
- */\r
- public function getExportableValues() {\r
- return array(\r
- 'guid',\r
- 'type',\r
- 'subtype',\r
- 'time_created',\r
- 'time_updated',\r
- 'container_guid',\r
- 'owner_guid',\r
- 'site_guid'\r
- );\r
- }\r
-\r
- /**\r
- * Export this class into an array of ODD Elements containing all necessary fields.\r
- * Override if you wish to return more information than can be found in $this->attributes (shouldn't happen)\r
- *\r
- * @return array\r
- */\r
- public function export() {\r
- $tmp = array();\r
-\r
- // Generate uuid\r
- $uuid = guid_to_uuid($this->getGUID());\r
-\r
- // Create entity\r
- $odd = new ODDEntity(\r
- $uuid,\r
- $this->attributes['type'],\r
- get_subtype_from_id($this->attributes['subtype'])\r
- );\r
-\r
- $tmp[] = $odd;\r
-\r
- $exportable_values = $this->getExportableValues();\r
-\r
- // Now add its attributes\r
- foreach ($this->attributes as $k => $v) {\r
- $meta = NULL;\r
-\r
- if (in_array( $k, $exportable_values)) {\r
- switch ($k) {\r
- case 'guid' : // Dont use guid in OpenDD\r
- case 'type' : // Type and subtype already taken care of\r
- case 'subtype' :\r
- break;\r
-\r
- case 'time_created' : // Created = published\r
- $odd->setAttribute('published', date("r", $v));\r
- break;\r
-\r
- case 'site_guid' : // Container\r
- $k = 'site_uuid';\r
- $v = guid_to_uuid($v);\r
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);\r
- break;\r
-\r
- case 'container_guid' : // Container\r
- $k = 'container_uuid';\r
- $v = guid_to_uuid($v);\r
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);\r
- break;\r
-\r
- case 'owner_guid' : // Convert owner guid to uuid, this will be stored in metadata\r
- $k = 'owner_uuid';\r
- $v = guid_to_uuid($v);\r
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);\r
- break;\r
-\r
- default :\r
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);\r
- }\r
-\r
- // set the time of any metadata created\r
- if ($meta) {\r
- $meta->setAttribute('published', date("r",$this->time_created));\r
- $tmp[] = $meta;\r
- }\r
- }\r
- }\r
-\r
- // Now we do something a bit special.\r
- /*\r
- * This provides a rendered view of the entity to foreign sites.\r
- */\r
-\r
- elgg_set_viewtype('default');\r
- $view = elgg_view_entity($this, true);\r
- elgg_set_viewtype();\r
-\r
- $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid, 'renderedentity', $view , 'volatile');\r
-\r
- return $tmp;\r
- }\r
-\r
- /*\r
- * IMPORTABLE INTERFACE\r
- */\r
-\r
- /**\r
- * Import data from an parsed ODD xml data array.\r
- *\r
- * @param array $data\r
- * @param int $version\r
- * @return true\r
- */\r
- public function import(ODD $data) {\r
- if (!($data instanceof ODDEntity)) {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass'));\r
- }\r
-\r
- // Set type and subtype\r
- $this->attributes['type'] = $data->getAttribute('class');\r
- $this->attributes['subtype'] = $data->getAttribute('subclass');\r
-\r
- // Set owner\r
- $this->attributes['owner_guid'] = get_loggedin_userid(); // Import as belonging to importer.\r
-\r
- // Set time\r
- $this->attributes['time_created'] = strtotime($data->getAttribute('published'));\r
- $this->attributes['time_updated'] = time();\r
-\r
- return true;\r
- }\r
-\r
- /*\r
- * SYSTEM LOG INTERFACE\r
- */\r
-\r
- /**\r
- * Return an identification for the object for storage in the system log.\r
- * This id must be an integer.\r
- *\r
- * @return int\r
- */\r
- public function getSystemLogID() {\r
- return $this->getGUID();\r
- }\r
-\r
- /**\r
- * Return the class name of the object.\r
- */\r
- public function getClassName() {\r
- return get_class($this);\r
- }\r
-\r
- /**\r
- * For a given ID, return the object associated with it.\r
- * This is used by the river functionality primarily.\r
- *\r
- * This is useful for checking access permissions etc on objects.\r
- * @return guid\r
- */\r
- public function getObjectFromID($id) {\r
- return get_entity($id);\r
- }\r
-\r
- /**\r
- * Returns the GUID of the owner of this entity.\r
- *\r
- * @return int Owner guid\r
- */\r
- public function getObjectOwnerGUID() {\r
- return $this->owner_guid;\r
- }\r
-\r
- /**\r
- * Returns tags for this entity.\r
- *\r
- * @warning Tags must be registered by {@link elgg_register_tag_metadata_name()}.\r
- *\r
- * @param array $tag_names Optionally restrict by tag metadata names.\r
- * @return array\r
- */\r
- public function getTags($tag_names = NULL) {\r
- global $CONFIG;\r
-\r
- if ($tag_names && !is_array($tag_names)) {\r
- $tag_names = array($tag_names);\r
- }\r
-\r
- $valid_tags = elgg_get_registered_tag_metadata_names();\r
- $entity_tags = array();\r
-\r
- foreach ($valid_tags as $tag_name) {\r
- if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {\r
- continue;\r
- }\r
-\r
- if ($tags = $this->$tag_name) {\r
- // if a single tag, metadata returns a string.\r
- // if multiple tags, metadata returns an array.\r
- if (is_array($tags)) {\r
- $entity_tags = array_merge($entity_tags, $tags);\r
- } else {\r
- $entity_tags[] = $tags;\r
- }\r
- }\r
- }\r
-\r
- return $entity_tags;\r
- }\r
-\r
- /*\r
- * ITERATOR INTERFACE\r
- */\r
-\r
- /*\r
- * This lets an entity's attributes be displayed using foreach as a normal array.\r
- * Example: http://www.sitepoint.com/print/php5-standard-library\r
- */\r
- private $valid = FALSE;\r
-\r
- function rewind() {\r
- $this->valid = (FALSE !== reset($this->attributes));\r
- }\r
-\r
- function current() {\r
- return current($this->attributes);\r
- }\r
-\r
- function key() {\r
- return key($this->attributes);\r
- }\r
-\r
- function next() {\r
- $this->valid = (FALSE !== next($this->attributes));\r
- }\r
-\r
- function valid() {\r
- return $this->valid;\r
- }\r
-\r
- /*\r
- * ARRAY ACCESS INTERFACE\r
- */\r
-\r
- /*\r
- * This lets an entity's attributes be accessed like an associative array.\r
- * Example: http://www.sitepoint.com/print/php5-standard-library\r
- */\r
- function offsetSet($key, $value) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- function offsetGet($key) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- return $this->attributes[$key];\r
- }\r
- }\r
-\r
- function offsetUnset($key) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects\r
- }\r
- }\r
-\r
- function offsetExists($offset) {\r
- return array_key_exists($offset, $this->attributes);\r
- }\r
+<?php
+/**
+ * The parent class for all Elgg Entities.
+ *
+ * An ElggEntity is one of the basic data models in Elgg. It is the primary
+ * means of storing and retrieving data from the database. An ElggEntity
+ * represents one row of the entities table.
+ *
+ * The ElggEntity class handles CRUD operations for the entities table.
+ * ElggEntity should always be extended by another class to handle CRUD
+ * operations on the type-specific table.
+ *
+ * ElggEntity uses magic methods for get and set, so any property that isn't
+ * declared will be assumed to be metadata and written to the database
+ * as metadata on the object. All children classes must declare which
+ * properties are columns of the type table or they will be assumed
+ * to be metadata. See ElggObject::initialise_entities() for examples.
+ *
+ * Core supports 4 types of entities: ElggObject, ElggUser, ElggGroup, and
+ * ElggSite.
+ *
+ * @tip Most plugin authors will want to extend the ElggObject class
+ * instead of this class.
+ *
+ * @package Elgg.Core
+ * @subpackage DataMode.Entities
+ * @link http://docs.elgg.org/DataModel/ElggEntity
+ */
+abstract class ElggEntity implements
+ Notable, // Calendar interface
+ Locatable, // Geocoding interface
+ Exportable, // Allow export of data
+ Importable, // Allow import of data
+ Loggable, // Can events related to this object class be logged
+ Iterator, // Override foreach behaviour
+ ArrayAccess // Override for array access
+{
+ /**
+ * The main attributes of an entity.
+ * Blank entries for all database fields should be created by the constructor.
+ * Subclasses should add to this in their constructors.
+ * Any field not appearing in this will be viewed as a
+ */
+ protected $attributes;
+
+ /**
+ * If set, overrides the value of getURL()
+ */
+ protected $url_override;
+
+ /**
+ * Icon override, overrides the value of getIcon().
+ */
+ protected $icon_override;
+
+ /**
+ * Holds metadata until entity is saved. Once the entity is saved, metadata are written immediately to the database.
+ */
+ protected $temp_metadata;
+
+ /**
+ * Holds annotations until entity is saved. Once the entity is saved, annotations are written immediately to the database.
+ */
+ protected $temp_annotations;
+
+
+ /**
+ * Volatile data structure for this object, allows for storage of data
+ * in-memory that isn't sync'd back to the metadata table.
+ */
+ protected $volatile;
+
+ /**
+ * Initialise the attributes array.
+ *
+ * This is vital to distinguish between metadata and base parameters.
+ *
+ * @return void
+ */
+ protected function initialise_attributes() {
+ initialise_entity_cache();
+
+ // Create attributes array if not already created
+ if (!is_array($this->attributes)) {
+ $this->attributes = array();
+ }
+ if (!is_array($this->temp_metadata)) {
+ $this->temp_metadata = array();
+ }
+ if (!is_array($this->temp_annotations)) {
+ $this->temp_annotations = array();
+ }
+ if (!is_array($this->volatile)) {
+ $this->volatile = array();
+ }
+
+ $this->attributes['guid'] = "";
+ $this->attributes['type'] = "";
+ $this->attributes['subtype'] = "";
+
+ $this->attributes['owner_guid'] = get_loggedin_userid();
+ $this->attributes['container_guid'] = get_loggedin_userid();
+
+ $this->attributes['site_guid'] = 0;
+ $this->attributes['access_id'] = ACCESS_PRIVATE;
+ $this->attributes['time_created'] = "";
+ $this->attributes['time_updated'] = "";
+ $this->attributes['last_action'] = '';
+ $this->attributes['enabled'] = "yes";
+
+ // There now follows a bit of a hack
+ /* Problem: To speed things up, some objects are split over several tables, this means that it requires
+ * n number of database reads to fully populate an entity. This causes problems for caching and create events
+ * since it is not possible to tell whether a subclassed entity is complete.
+ * Solution: We have two counters, one 'tables_split' which tells whatever is interested how many tables
+ * are going to need to be searched in order to fully populate this object, and 'tables_loaded' which is how
+ * many have been loaded thus far.
+ * If the two are the same then this object is complete.
+ *
+ * Use: isFullyLoaded() to check
+ */
+ $this->attributes['tables_split'] = 1;
+ $this->attributes['tables_loaded'] = 0;
+ }
+
+ /**
+ * Clone an entity
+ *
+ * Resets the guid so that the entity can be saved as a distinct entity from
+ * the original. Creation time will be set when this new entity is saved.
+ * The owner and container guids come from the original entity. The clone
+ * method copies metadata but does not copy annotations or private settings.
+ *
+ * @note metadata will have its owner and access id set when the entity is saved
+ * and it will be the same as that of the entity.
+ */
+ public function __clone() {
+ $orig_entity = get_entity($this->guid);
+ if (!$orig_entity) {
+ elgg_log("Failed to clone entity with GUID $this->guid", "ERROR");
+ return;
+ }
+
+ $metadata_array = get_metadata_for_entity($this->guid);
+
+ $this->attributes['guid'] = "";
+
+ $this->attributes['subtype'] = $orig_entity->getSubtype();
+
+ // copy metadata over to new entity - slightly convoluted due to
+ // handling of metadata arrays
+ if (is_array($metadata_array)) {
+ // create list of metadata names
+ $metadata_names = array();
+ foreach ($metadata_array as $metadata) {
+ $metadata_names[] = $metadata['name'];
+ }
+ // arrays are stored with multiple enties per name
+ $metadata_names = array_unique($metadata_names);
+
+ // move the metadata over
+ foreach ($metadata_names as $name) {
+ $this->set($name, $orig_entity->$name);
+ }
+ }
+ }
+
+ /**
+ * Return the value of a property.
+ *
+ * If $name is defined in $this->attributes that value is returned, otherwise it will
+ * pull from the entity's metadata.
+ *
+ * Q: Why are we not using __get overload here?
+ * A: Because overload operators cause problems during subclassing, so we put the code here and
+ * create overloads in subclasses.
+ * @todo What problems are these?
+ *
+ * @warning Subtype is returned as an id rather than the subtype string. Use getSubtype()
+ * to get the subtype string.
+ *
+ * @param string $name
+ * @return mixed Returns the value of a given value, or null.
+ */
+ public function get($name) {
+ // See if its in our base attributes
+ if (isset($this->attributes[$name])) {
+ return $this->attributes[$name];
+ }
+
+ // No, so see if its in the meta data for this entity
+ $meta = $this->getMetaData($name);
+
+ // getMetaData returns NULL if $name is not found
+ return $meta;
+ }
+
+ /**
+ * Sets the value of a property.
+ *
+ * If $name is defined in $this->attributes that value is set, otherwise it will
+ * set the appropriate item of metadata.
+ *
+ * @warning It is important that your class populates $this->attributes with keys for all base attributes, anything
+ * not in their gets set as METADATA.
+ *
+ * Q: Why are we not using __set overload here?
+ * A: Because overload operators cause problems during subclassing, so we put the code here and
+ * create overloads in subclasses.
+ * @todo What problems?
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function set($name, $value) {
+ if (array_key_exists($name, $this->attributes)) {
+ // Certain properties should not be manually changed!
+ switch ($name) {
+ case 'guid':
+ case 'time_created':
+ case 'time_updated':
+ case 'last_action':
+ return FALSE;
+ break;
+ default:
+ $this->attributes[$name] = $value;
+ break;
+ }
+ } else {
+ return $this->setMetaData($name, $value);
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * Return the value of a piece of metadata.
+ *
+ * @param string $name
+ * @return mixed The value, or NULL if not found.
+ */
+ public function getMetaData($name) {
+ if ((int) ($this->guid) > 0) {
+ $md = get_metadata_byname($this->getGUID(), $name);
+ } else {
+ if (isset($this->temp_metadata[$name])) {
+ return $this->temp_metadata[$name];
+ }
+ }
+
+ if ($md && !is_array($md)) {
+ return $md->value;
+ } else if ($md && is_array($md)) {
+ return metadata_array_to_values($md);
+ }
+
+ return null;
+ }
+
+ /**
+ * Return an attribute or a piece of metadata.
+ *
+ * @param string $name
+ * @return mixed
+ */
+ function __get($name) {
+ return $this->get($name);
+ }
+
+ /**
+ * Set an attribute or a piece of metadata.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return mixed
+ */
+ function __set($name, $value) {
+ return $this->set($name, $value);
+ }
+
+ /**
+ * Test if property is set either as an attribute or metadata.
+ *
+ * @tip Use isset($entity->property)
+ *
+ * @param string $name The name of the attribute or metadata.
+ * @return bool
+ */
+ function __isset($name) {
+ return $this->$name !== NULL;
+ }
+
+ /**
+ * Unset a property from metadata or attribute.
+ *
+ * @warning If you use this to unset an attribute, you must save the object!
+ *
+ * @param string $name The name of the attribute or metadata.
+ */
+ function __unset($name) {
+ if (array_key_exists($name, $this->attributes)) {
+ $this->attributes[$name] = "";
+ }
+ else {
+ $this->clearMetaData($name);
+ }
+ }
+
+ /**
+ * Set a piece of metadata.
+ *
+ * @tip Plugin authors should use the magic methods.
+ *
+ * @access private
+ * @param string $name Name of the metadata
+ * @param mixed $value Value of the metadata
+ * @param string $value_type Types supported: integer and string. Will auto-identify if not set
+ * @param bool $multiple (does not support associative arrays)
+ * @return bool
+ */
+ public function setMetaData($name, $value, $value_type = "", $multiple = false) {
+ if (is_array($value)) {
+ unset($this->temp_metadata[$name]);
+ remove_metadata($this->getGUID(), $name);
+ foreach ($value as $v) {
+ if ((int) $this->guid > 0) {
+ $multiple = true;
+ if (!create_metadata($this->getGUID(), $name, $v, $value_type,
+ $this->getOwner(), $this->getAccessID(), $multiple)) {
+ return false;
+ }
+ } else {
+ if (($multiple) && (isset($this->temp_metadata[$name]))) {
+ if (!is_array($this->temp_metadata[$name])) {
+ $tmp = $this->temp_metadata[$name];
+ $this->temp_metadata[$name] = array();
+ $this->temp_metadata[$name][] = $tmp;
+ }
+
+ $this->temp_metadata[$name][] = $value;
+ }
+ else {
+ $this->temp_metadata[$name] = $value;
+ }
+ }
+ }
+
+ return true;
+ } else {
+ unset($this->temp_metadata[$name]);
+ if ((int) $this->guid > 0) {
+ $result = create_metadata($this->getGUID(), $name, $value, $value_type, $this->getOwner(), $this->getAccessID(), $multiple);
+ return (bool)$result;
+ } else {
+ if (($multiple) && (isset($this->temp_metadata[$name]))) {
+ if (!is_array($this->temp_metadata[$name])) {
+ $tmp = $this->temp_metadata[$name];
+ $this->temp_metadata[$name] = array();
+ $this->temp_metadata[$name][] = $tmp;
+ }
+
+ $this->temp_metadata[$name][] = $value;
+ }
+ else {
+ $this->temp_metadata[$name] = $value;
+ }
+
+ return true;
+ }
+ }
+ }
+
+ /**
+ * Remove metadata
+ *
+ * @warning Calling this with no or empty arguments will clear all metadata on the entity.
+ * @param string The name of the metadata to clear
+ * @return mixed The n
+ */
+ public function clearMetaData($name = "") {
+ if (empty($name)) {
+ return clear_metadata($this->getGUID());
+ } else {
+ return remove_metadata($this->getGUID(), $name);
+ }
+ }
+
+
+ /**
+ * Get a piece of volatile (non-persisted) data on this entity.
+ *
+ * @param string $name The name of the volatile data
+ * @return mixed The value or NULL if not found.
+ */
+ public function getVolatileData($name) {
+ if (!is_array($this->volatile)) {
+ $this->volatile = array();
+ }
+
+ if (array_key_exists($name, $this->volatile)) {
+ return $this->volatile[$name];
+ } else {
+ return NULL;
+ }
+ }
+
+
+ /**
+ * Set a piece of volatile (non-persisted) data on this entity
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function setVolatileData($name, $value) {
+ if (!is_array($this->volatile)) {
+ $this->volatile = array();
+ }
+
+ $this->volatile[$name] = $value;
+ }
+
+
+ /**
+ * Remove all relationships to and from this entity.
+ *
+ * @return true
+ * @todo This should actually return if it worked.
+ * @see ElggEntity::addRelationship()
+ * @see ElggEntity::removeRelationship()
+ */
+ public function clearRelationships() {
+ remove_entity_relationships($this->getGUID());
+ remove_entity_relationships($this->getGUID(), "", true);
+ return true;
+ }
+
+ /**
+ * Add a relationship between this an another entity.
+ *
+ * @tip Read the relationship like "$guid is a $relationship of this entity."
+ *
+ * @param int $guid Entity to link to.
+ * @param string $relationship The type of relationship.
+ * @return bool
+ * @see ElggEntity::removeRelationship()
+ * @see ElggEntity::clearRelationships()
+ */
+ public function addRelationship($guid, $relationship) {
+ return add_entity_relationship($this->getGUID(), $relationship, $guid);
+ }
+
+ /**
+ * Remove a relationship
+ *
+ * @param int $guid
+ * @param str $relationship
+ * @return bool
+ * @see ElggEntity::addRelationship()
+ * @see ElggEntity::clearRelationships()
+ */
+ public function removeRelationship($guid, $relationship) {
+ return remove_entity_relationship($this->getGUID(), $relationship, $guid);
+ }
+
+ /**
+ * Adds a private setting to this entity.
+ *
+ * Private settings are similar to metadata but will not
+ * be searched and there are fewer helper functions for them.
+ *
+ * @param $name
+ * @param $value
+ * @return bool
+ * @link http://docs.elgg.org/DataModel/Entities/PrivateSettings
+ */
+ function setPrivateSetting($name, $value) {
+ return set_private_setting($this->getGUID(), $name, $value);
+ }
+
+ /**
+ * Returns a private setting value
+ *
+ * @param $name
+ * @return mixed
+ */
+ function getPrivateSetting($name) {
+ return get_private_setting($this->getGUID(), $name);
+ }
+
+ /**
+ * Removes private setting
+ *
+ * @param $name
+ * @return bool
+ */
+ function removePrivateSetting($name) {
+ return remove_private_setting($this->getGUID(), $name);
+ }
+
+ /**
+ * Adds an annotation to an entity.
+ *
+ * @warning By default, annotations are private.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param int $access_id
+ * @param int $owner_id
+ * @param string $vartype
+ * @link http://docs.elgg.org/DataModel/Annotations
+ */
+ function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_id = 0, $vartype = "") {
+ if ((int) $this->guid > 0) {
+ return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_id, $access_id);
+ } else {
+ $this->temp_annotations[$name] = $value;
+ }
+ return true;
+ }
+
+ /**
+ * Returns an array of annotations.
+ *
+ * @param string $name
+ * @param int $limit
+ * @param int $offset
+ * @param string $order asc or desc
+ * @return array
+ */
+ function getAnnotations($name, $limit = 50, $offset = 0, $order="asc") {
+ if ((int) ($this->guid) > 0) {
+ return get_annotations($this->getGUID(), "", "", $name, "", 0, $limit, $offset, $order);
+ } else {
+ return $this->temp_annotations[$name];
+ }
+ }
+
+ /**
+ * Remove an annotation or all annotations for this entity.
+ *
+ * @warning Calling this method with no or an empty argument will remove all annotations on the entity.
+ *
+ * @param string $name
+ * @return bool
+ */
+ function clearAnnotations($name = "") {
+ return clear_annotations($this->getGUID(), $name);
+ }
+
+ /**
+ * Count annotations.
+ *
+ * @param string $name The type of annotation.
+ * @return int
+ */
+ function countAnnotations($name = "") {
+ return count_annotations($this->getGUID(), "", "", $name);
+ }
+
+ /**
+ * Get the average of an integer type annotation.
+ *
+ * @param string $name
+ * @return int
+ */
+ function getAnnotationsAvg($name) {
+ return get_annotations_avg($this->getGUID(), "", "", $name);
+ }
+
+ /**
+ * Get the sum of integer type annotations of a given name.
+ *
+ * @param string $name
+ * @return int
+ */
+ function getAnnotationsSum($name) {
+ return get_annotations_sum($this->getGUID(), "", "", $name);
+ }
+
+ /**
+ * Get the minimum of integer type annotations of given name.
+ *
+ * @param string $name
+ * @return int
+ */
+ function getAnnotationsMin($name) {
+ return get_annotations_min($this->getGUID(), "", "", $name);
+ }
+
+ /**
+ * Get the maximum of integer type annotations of a given name.
+ *
+ * @param string $name
+ * @return int
+ */
+ function getAnnotationsMax($name) {
+ return get_annotations_max($this->getGUID(), "", "", $name);
+ }
+
+ /**
+ * Gets an array of entities with a relationship to this entity.
+ *
+ * @param string $relationship Relationship type (eg "friends")
+ * @param true|false $inverse Is this an inverse relationship?
+ * @param int $limit Number of elements to return
+ * @param int $offset Indexing offset
+ * @return array|false An array of entities or false on failure
+ */
+ function getEntitiesFromRelationship($relationship, $inverse = false, $limit = 50, $offset = 0) {
+ return elgg_get_entities_from_relationship(array(
+ 'relationship' => $relationship,
+ 'relationship_guid' => $this->getGUID(),
+ 'inverse_relationship' => $inverse,
+ 'limit' => $limit,
+ 'offset' => $offset
+ ));
+ }
+
+ /**
+ * Gets the number of of entities from a specific relationship type
+ *
+ * @param string $relationship Relationship type (eg "friends")
+ * @param bool $inverse_relationship
+ * @return int|false The number of entities or false on failure
+ */
+ function countEntitiesFromRelationship($relationship, $inverse_relationship = FALSE) {
+ return elgg_get_entities_from_relationship(array(
+ 'relationship' => $relationship,
+ 'relationship_guid' => $this->getGUID(),
+ 'inverse_relationship' => $inverse_relationship,
+ 'count' => TRUE
+ ));
+ }
+
+ /**
+ * Can a user edit this entity.
+ *
+ * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)
+ * @return true|false
+ */
+ function canEdit($user_guid = 0) {
+ return can_edit_entity($this->getGUID(), $user_guid);
+ }
+
+ /**
+ * Can a user edit metadata on this entity
+ *
+ * @param ElggMetadata $metadata The piece of metadata to specifically check
+ * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)
+ * @return true|false
+ */
+ function canEditMetadata($metadata = null, $user_guid = 0) {
+ return can_edit_entity_metadata($this->getGUID(), $user_guid, $metadata);
+ }
+
+ /**
+ * Can a user write to this entity's container.
+ *
+ * @param int $user_guid The user.
+ * @return bool
+ */
+ public function canWriteToContainer($user_guid = 0) {
+ return can_write_to_container($user_guid, $this->getGUID());
+ }
+
+ /**
+ * Returns the access_id.
+ *
+ * @return int The access ID
+ */
+ public function getAccessID() {
+ return $this->get('access_id');
+ }
+
+ /**
+ * Returns the guid.
+ *
+ * @return int GUID
+ */
+ public function getGUID() {
+ return $this->get('guid');
+ }
+
+ /**
+ * Return the guid of the entity's owner.
+ *
+ * @return int The owner GUID
+ */
+ public function getOwner() {
+ return $this->get('owner_guid');
+ }
+
+ /**
+ * Returns the ElggEntity or child object of the owner of the entity.
+ *
+ * @return ElggEntity The owning user
+ */
+ public function getOwnerEntity() {
+ return get_entity($this->get('owner_guid'));
+ }
+
+ /**
+ * Returns the entity type
+ *
+ * @return string Entity type
+ */
+ public function getType() {
+ return $this->get('type');
+ }
+
+ /**
+ * Returns the entity subtype string
+ *
+ * @note This returns a string. If you want the id, use ElggEntity::subtype.
+ *
+ * @return string The entity subtype
+ */
+ public function getSubtype() {
+ // If this object hasn't been saved, then return the subtype string.
+ if (!((int) $this->guid > 0)) {
+ return $this->get('subtype');
+ }
+
+ return get_subtype_from_id($this->get('subtype'));
+ }
+
+ /**
+ * Returns the UNIX epoch time that this entity was created
+ *
+ * @return int UNIX epoch time
+ */
+ public function getTimeCreated() {
+ return $this->get('time_created');
+ }
+
+ /**
+ * Returns the UNIX epoch time that this entity was last updated
+ *
+ * @return int UNIX epoch time
+ */
+ public function getTimeUpdated() {
+ return $this->get('time_updated');
+ }
+
+ /**
+ * Returns the URL for this entity
+ *
+ * @return string The URL
+ * @see register_entity_url_handler()
+ * @see ElggEntity::setURL()
+ */
+ public function getURL() {
+ if (!empty($this->url_override)) {
+ return $this->url_override;
+ }
+ return get_entity_url($this->getGUID());
+ }
+
+ /**
+ * Overrides the URL returned by getURL()
+ *
+ * @warning This override exists only for the life of the object.
+ *
+ * @param string $url The new item URL
+ * @return string The URL
+ */
+ public function setURL($url) {
+ $this->url_override = $url;
+ return $url;
+ }
+
+ /**
+ * Returns a URL for the entity's icon.
+ *
+ * @param string $size Either 'large', 'medium', 'small' or 'tiny'
+ * @return string The url or false if no url could be worked out.
+ * @see get_entity_icon_url()
+ */
+ public function getIcon($size = 'medium') {
+ if (isset($this->icon_override[$size])) {
+ return $this->icon_override[$size];
+ }
+ return get_entity_icon_url($this, $size);
+ }
+
+ /**
+ * Set an icon override for an icon and size.
+ *
+ * @warning This override exists only for the life of the object.
+ *
+ * @param string $url The url of the icon.
+ * @param string $size The size its for.
+ * @return bool
+ */
+ public function setIcon($url, $size = 'medium') {
+ $url = sanitise_string($url);
+ $size = sanitise_string($size);
+
+ if (!$this->icon_override) {
+ $this->icon_override = array();
+ }
+ $this->icon_override[$size] = $url;
+
+ return true;
+ }
+
+ /**
+ * Tests to see whether the object has been fully loaded.
+ *
+ * @return bool
+ */
+ public function isFullyLoaded() {
+ return ! ($this->attributes['tables_loaded'] < $this->attributes['tables_split']);
+ }
+
+ /**
+ * Save attributes to the entities table.
+ *
+ * @return bool
+ * @throws IOException
+ */
+ public function save() {
+ $guid = (int) $this->guid;
+ if ($guid > 0) {
+ cache_entity($this);
+
+ return update_entity(
+ $this->get('guid'),
+ $this->get('owner_guid'),
+ $this->get('access_id'),
+ $this->get('container_guid')
+ );
+ } else {
+ // Create a new entity (nb: using attribute array directly 'cos set function does something special!)
+ $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']);
+ if (!$this->attributes['guid']) {
+ throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
+ }
+
+ // Save any unsaved metadata
+ // @todo How to capture extra information (access id etc)
+ if (sizeof($this->temp_metadata) > 0) {
+ foreach($this->temp_metadata as $name => $value) {
+ $this->$name = $value;
+ unset($this->temp_metadata[$name]);
+ }
+ }
+
+ // Save any unsaved annotations metadata.
+ // @todo How to capture extra information (access id etc)
+ if (sizeof($this->temp_annotations) > 0) {
+ foreach($this->temp_annotations as $name => $value) {
+ $this->annotate($name, $value);
+ unset($this->temp_annotations[$name]);
+ }
+ }
+
+ // set the subtype to id now rather than a string
+ $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']);
+
+ // Cache object handle
+ if ($this->attributes['guid']) {
+ cache_entity($this);
+ }
+
+ return $this->attributes['guid'];
+ }
+ }
+
+ /**
+ * Loads attributes from the entities table into the object.
+ *
+ * @param int $guid
+ * @return bool
+ */
+ protected function load($guid) {
+ $row = get_entity_as_row($guid);
+
+ if ($row) {
+ // Create the array if necessary - all subclasses should test before creating
+ if (!is_array($this->attributes)) {
+ $this->attributes = array();
+ }
+
+ // Now put these into the attributes array as core values
+ $objarray = (array) $row;
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+
+ // Increment the portion counter
+ if (!$this->isFullyLoaded()) {
+ $this->attributes['tables_loaded']++;
+ }
+
+ // Cache object handle
+ if ($this->attributes['guid']) {
+ cache_entity($this);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Disable this entity.
+ *
+ * Disabled entities are not returned by getter functions.
+ * To enable an entity, use {@link enable_entity()}.
+ *
+ * Recursively disabling an entity will disable all entities
+ * owned or contained by the parent entity.
+ *
+ * @internal Disabling an entity sets the 'enabled' column to 'no'.
+ *
+ * @param string $reason Optional reason
+ * @param bool $recursive Recursively disable all contained entities?
+ * @return bool
+ * @see enable_entity()
+ * @see ElggEntity::enable()
+ */
+ public function disable($reason = "", $recursive = true) {
+ return disable_entity($this->get('guid'), $reason, $recursive);
+ }
+
+ /**
+ * Enable an entity
+ *
+ * @warning Disabled entities can't be loaded unless
+ * {@link access_show_hidden_entities(true)} has been called.
+ *
+ * @see enable_entity()
+ * @see access_show_hiden_entities()
+ * @return bool
+ */
+ public function enable() {
+ return enable_entity($this->get('guid'));
+ }
+
+ /**
+ * Is this entity enabled?
+ *
+ * @return boolean
+ */
+ public function isEnabled() {
+ if ($this->enabled == 'yes') {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Delete this entity.
+ *
+ * @return bool
+ */
+ public function delete() {
+ return delete_entity($this->get('guid'));
+ }
+
+ /*
+ * LOCATABLE INTERFACE
+ */
+
+ /**
+ * Sets the 'location' metadata for the entity
+ *
+ * @todo Unimplemented
+ * @param string $location
+ * @return true
+ */
+ public function setLocation($location) {
+ $location = sanitise_string($location);
+
+ $this->location = $location;
+
+ return true;
+ }
+
+ /**
+ * Set latitude and longitude metadata tags for a given entity.
+ *
+ * @param float $lat
+ * @param float $long
+ * @return true
+ * @todo Unimplemented
+ */
+ public function setLatLong($lat, $long) {
+ $lat = sanitise_string($lat);
+ $long = sanitise_string($long);
+
+ $this->set('geo:lat', $lat);
+ $this->set('geo:long', $long);
+
+ return true;
+ }
+
+ /**
+ * Return the entity's latitude.
+ *
+ * @return int
+ * @todo Unimplemented
+ */
+ public function getLatitude() {
+ return $this->get('geo:lat');
+ }
+
+ /**
+ * Return the entity's longitude
+ *
+ * @return Int
+ */
+ public function getLongitude() {
+ return $this->get('geo:long');
+ }
+
+ /**
+ * Return the entity's location
+ *
+ * @return string
+ */
+ public function getLocation() {
+ return $this->get('location');
+ }
+
+ /*
+ * NOTABLE INTERFACE
+ */
+
+ /**
+ * Set the time and duration of an object
+ *
+ * @param int $hour If ommitted, now is assumed.
+ * @param int $minute If ommitted, now is assumed.
+ * @param int $second If ommitted, now is assumed.
+ * @param int $day If ommitted, now is assumed.
+ * @param int $month If ommitted, now is assumed.
+ * @param int $year If ommitted, now is assumed.
+ * @param int $duration Duration of event, remainder of the day is assumed.
+ * @return true
+ * @todo Unimplemented
+ */
+ public function setCalendarTimeAndDuration($hour = NULL, $minute = NULL, $second = NULL, $day = NULL, $month = NULL, $year = NULL, $duration = NULL) {
+ $start = mktime($hour, $minute, $second, $month, $day, $year);
+ $end = $start + abs($duration);
+ if (!$duration) {
+ $end = get_day_end($day,$month,$year);
+ }
+
+ $this->calendar_start = $start;
+ $this->calendar_end = $end;
+
+ return true;
+ }
+
+ /**
+ * Returns the start timestamp.
+ *
+ * @return int
+ * @todo Unimplemented
+ */
+ public function getCalendarStartTime() {
+ return (int)$this->calendar_start;
+ }
+
+ /**
+ * Returns the end timestamp.
+ *
+ * @todo Unimplemented
+ */
+ public function getCalendarEndTime() {
+ return (int)$this->calendar_end;
+ }
+
+ /*
+ * EXPORTABLE INTERFACE
+ */
+
+ /**
+ * Returns an array of fields which can be exported.
+ *
+ * @return array
+ */
+ public function getExportableValues() {
+ return array(
+ 'guid',
+ 'type',
+ 'subtype',
+ 'time_created',
+ 'time_updated',
+ 'container_guid',
+ 'owner_guid',
+ 'site_guid'
+ );
+ }
+
+ /**
+ * Export this class into an array of ODD Elements containing all necessary fields.
+ * Override if you wish to return more information than can be found in $this->attributes (shouldn't happen)
+ *
+ * @return array
+ */
+ public function export() {
+ $tmp = array();
+
+ // Generate uuid
+ $uuid = guid_to_uuid($this->getGUID());
+
+ // Create entity
+ $odd = new ODDEntity(
+ $uuid,
+ $this->attributes['type'],
+ get_subtype_from_id($this->attributes['subtype'])
+ );
+
+ $tmp[] = $odd;
+
+ $exportable_values = $this->getExportableValues();
+
+ // Now add its attributes
+ foreach ($this->attributes as $k => $v) {
+ $meta = NULL;
+
+ if (in_array( $k, $exportable_values)) {
+ switch ($k) {
+ case 'guid' : // Dont use guid in OpenDD
+ case 'type' : // Type and subtype already taken care of
+ case 'subtype' :
+ break;
+
+ case 'time_created' : // Created = published
+ $odd->setAttribute('published', date("r", $v));
+ break;
+
+ case 'site_guid' : // Container
+ $k = 'site_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ case 'container_guid' : // Container
+ $k = 'container_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ case 'owner_guid' : // Convert owner guid to uuid, this will be stored in metadata
+ $k = 'owner_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ default :
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ }
+
+ // set the time of any metadata created
+ if ($meta) {
+ $meta->setAttribute('published', date("r",$this->time_created));
+ $tmp[] = $meta;
+ }
+ }
+ }
+
+ // Now we do something a bit special.
+ /*
+ * This provides a rendered view of the entity to foreign sites.
+ */
+
+ elgg_set_viewtype('default');
+ $view = elgg_view_entity($this, true);
+ elgg_set_viewtype();
+
+ $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid, 'renderedentity', $view , 'volatile');
+
+ return $tmp;
+ }
+
+ /*
+ * IMPORTABLE INTERFACE
+ */
+
+ /**
+ * Import data from an parsed ODD xml data array.
+ *
+ * @param array $data
+ * @param int $version
+ * @return true
+ */
+ public function import(ODD $data) {
+ if (!($data instanceof ODDEntity)) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass'));
+ }
+
+ // Set type and subtype
+ $this->attributes['type'] = $data->getAttribute('class');
+ $this->attributes['subtype'] = $data->getAttribute('subclass');
+
+ // Set owner
+ $this->attributes['owner_guid'] = get_loggedin_userid(); // Import as belonging to importer.
+
+ // Set time
+ $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
+ $this->attributes['time_updated'] = time();
+
+ return true;
+ }
+
+ /*
+ * SYSTEM LOG INTERFACE
+ */
+
+ /**
+ * Return an identification for the object for storage in the system log.
+ * This id must be an integer.
+ *
+ * @return int
+ */
+ public function getSystemLogID() {
+ return $this->getGUID();
+ }
+
+ /**
+ * Return the class name of the object.
+ */
+ public function getClassName() {
+ return get_class($this);
+ }
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ *
+ * This is useful for checking access permissions etc on objects.
+ * @return guid
+ */
+ public function getObjectFromID($id) {
+ return get_entity($id);
+ }
+
+ /**
+ * Returns the GUID of the owner of this entity.
+ *
+ * @return int Owner guid
+ */
+ public function getObjectOwnerGUID() {
+ return $this->owner_guid;
+ }
+
+ /**
+ * Returns tags for this entity.
+ *
+ * @warning Tags must be registered by {@link elgg_register_tag_metadata_name()}.
+ *
+ * @param array $tag_names Optionally restrict by tag metadata names.
+ * @return array
+ */
+ public function getTags($tag_names = NULL) {
+ global $CONFIG;
+
+ if ($tag_names && !is_array($tag_names)) {
+ $tag_names = array($tag_names);
+ }
+
+ $valid_tags = elgg_get_registered_tag_metadata_names();
+ $entity_tags = array();
+
+ foreach ($valid_tags as $tag_name) {
+ if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
+ continue;
+ }
+
+ if ($tags = $this->$tag_name) {
+ // if a single tag, metadata returns a string.
+ // if multiple tags, metadata returns an array.
+ if (is_array($tags)) {
+ $entity_tags = array_merge($entity_tags, $tags);
+ } else {
+ $entity_tags[] = $tags;
+ }
+ }
+ }
+
+ return $entity_tags;
+ }
+
+ /*
+ * ITERATOR INTERFACE
+ */
+
+ /*
+ * This lets an entity's attributes be displayed using foreach as a normal array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+ private $valid = FALSE;
+
+ function rewind() {
+ $this->valid = (FALSE !== reset($this->attributes));
+ }
+
+ function current() {
+ return current($this->attributes);
+ }
+
+ function key() {
+ return key($this->attributes);
+ }
+
+ function next() {
+ $this->valid = (FALSE !== next($this->attributes));
+ }
+
+ function valid() {
+ return $this->valid;
+ }
+
+ /*
+ * ARRAY ACCESS INTERFACE
+ */
+
+ /*
+ * This lets an entity's attributes be accessed like an associative array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+ function offsetSet($key, $value) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ function offsetGet($key) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ return $this->attributes[$key];
+ }
+ }
+
+ function offsetUnset($key) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects
+ }
+ }
+
+ function offsetExists($offset) {
+ return array_key_exists($offset, $this->attributes);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * The base class for ElggEntity extenders.\r
- *\r
- * Extenders allow you to attach extended information to an\r
- * ElggEntity. Core supports two: ElggAnnotation, ElggMetadata,\r
- * and ElggRelationship\r
- *\r
- * Saving the extender data to database is handled by the child class.\r
- *\r
- * @tip Plugin authors would probably want to extend either ElggAnnotation\r
- * or ElggMetadata instead of this class.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage DataModel.Extender\r
- * @see ElggAnnotation\r
- * @see ElggMetadata\r
- * @link http://docs.elgg.org/DataModel/Extenders\r
- */\r
-abstract class ElggExtender implements\r
- Exportable,\r
- Loggable, // Can events related to this object class be logged\r
- Iterator, // Override foreach behaviour\r
- ArrayAccess // Override for array access\r
-{\r
- /**\r
- * Holds attributes to save to database\r
- *\r
- * @var array\r
- */\r
- protected $attributes;\r
-\r
- /**\r
- * Returns an attribute\r
- *\r
- * @param string $name\r
- * @return mixed\r
- */\r
- protected function get($name) {\r
- if (isset($this->attributes[$name])) {\r
- // Sanitise value if necessary\r
- if ($name=='value') {\r
- switch ($this->attributes['value_type']) {\r
- case 'integer' :\r
- return (int)$this->attributes['value'];\r
-\r
- //case 'tag' :\r
- //case 'file' :\r
- case 'text' :\r
- return ($this->attributes['value']);\r
-\r
- default :\r
- throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $this->attributes['value_type']));\r
- }\r
- }\r
-\r
- return $this->attributes[$name];\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * Set an attribute\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- * @param string $value_type\r
- * @return boolean\r
- */\r
- protected function set($name, $value, $value_type = "") {\r
- $this->attributes[$name] = $value;\r
- if ($name == 'value') {\r
- $this->attributes['value_type'] = detect_extender_valuetype($value, $value_type);\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Return the owner guid of this extender.\r
- *\r
- * @return int\r
- */\r
- public function getOwner() {\r
- return $this->owner_guid;\r
- }\r
-\r
- /**\r
- * Return the owner entity.\r
- *\r
- * @return ElggEntity|false\r
- * @since 1.7.0\r
- */\r
- public function getOwnerEntity() {\r
- return get_user($this->owner_guid);\r
- }\r
-\r
- /**\r
- * Return the entity this describes.\r
- *\r
- * @return ElggEntity The enttiy\r
- */\r
- public function getEntity() {\r
- return get_entity($this->entity_guid);\r
- }\r
-\r
- /**\r
- * Save this data to the appropriate database table.\r
- */\r
- abstract public function save();\r
-\r
- /**\r
- * Delete this data.\r
- */\r
- abstract public function delete();\r
-\r
- /**\r
- * Returns if a user can edit this extended data.\r
- *\r
- * @param int $user_guid The GUID of the user (defaults to currently logged in user)\r
- * @return bool\r
- */\r
- public function canEdit($user_guid = 0) {\r
- return can_edit_extender($this->id,$this->type,$user_guid);\r
- }\r
-\r
- /**\r
- * Return a url for this extender.\r
- *\r
- * @return string\r
- */\r
- public abstract function getURL();\r
-\r
- /*\r
- * EXPORTABLE INTERFACE\r
- */\r
-\r
- /**\r
- * Return an array of fields which can be exported.\r
- *\r
- * @return array\r
- */\r
- public function getExportableValues() {\r
- return array(\r
- 'id',\r
- 'entity_guid',\r
- 'name',\r
- 'value',\r
- 'value_type',\r
- 'owner_guid',\r
- 'type',\r
- );\r
- }\r
-\r
- /**\r
- * Export this object\r
- *\r
- * @return array\r
- */\r
- public function export() {\r
- $uuid = get_uuid_from_object($this);\r
-\r
- $meta = new ODDMetadata($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));\r
- $meta->setAttribute('published', date("r", $this->time_created));\r
-\r
- return $meta;\r
- }\r
-\r
- /*\r
- * SYSTEM LOG INTERFACE\r
- */\r
-\r
- /**\r
- * Return an identification for the object for storage in the system log.\r
- * This id must be an integer.\r
- *\r
- * @return int\r
- */\r
- public function getSystemLogID() {\r
- return $this->id;\r
- }\r
-\r
- /**\r
- * Return the class name of the object.\r
- *\r
- * @return string\r
- */\r
- public function getClassName() {\r
- return get_class($this);\r
- }\r
-\r
- /**\r
- * Return the GUID of the owner of this object.\r
- *\r
- * @return int\r
- */\r
- public function getObjectOwnerGUID() {\r
- return $this->owner_guid;\r
- }\r
-\r
- /**\r
- * Return a type of extension.\r
- *\r
- * @return string\r
- */\r
- public function getType() {\r
- return $this->type;\r
- }\r
-\r
- /**\r
- * Return a subtype. For metadata & annotations this is the 'name' and\r
- * for relationship this is the relationship type.\r
- *\r
- * @return string\r
- */\r
- public function getSubtype() {\r
- return $this->name;\r
- }\r
-\r
-\r
- /*\r
- * ITERATOR INTERFACE\r
- */\r
-\r
- /*\r
- * This lets an entity's attributes be displayed using foreach as a normal array.\r
- * Example: http://www.sitepoint.com/print/php5-standard-library\r
- */\r
- private $valid = FALSE;\r
-\r
- function rewind() {\r
- $this->valid = (FALSE !== reset($this->attributes));\r
- }\r
-\r
- function current() {\r
- return current($this->attributes);\r
- }\r
-\r
- function key() {\r
- return key($this->attributes);\r
- }\r
-\r
- function next() {\r
- $this->valid = (FALSE !== next($this->attributes));\r
- }\r
-\r
- function valid() {\r
- return $this->valid;\r
- }\r
-\r
- /*\r
- * ARRAY ACCESS INTERFACE\r
- */\r
-\r
- /*\r
- * This lets an entity's attributes be accessed like an associative array.\r
- * Example: http://www.sitepoint.com/print/php5-standard-library\r
- */\r
- function offsetSet($key, $value) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- function offsetGet($key) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- return $this->attributes[$key];\r
- }\r
- }\r
-\r
- function offsetUnset($key) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- // Full unsetting is dangerious for our objects\r
- $this->attributes[$key] = "";\r
- }\r
- }\r
-\r
- function offsetExists($offset) {\r
- return array_key_exists($offset, $this->attributes);\r
- }\r
-}\r
+<?php
+/**
+ * The base class for ElggEntity extenders.
+ *
+ * Extenders allow you to attach extended information to an
+ * ElggEntity. Core supports two: ElggAnnotation, ElggMetadata,
+ * and ElggRelationship
+ *
+ * Saving the extender data to database is handled by the child class.
+ *
+ * @tip Plugin authors would probably want to extend either ElggAnnotation
+ * or ElggMetadata instead of this class.
+ *
+ * @package Elgg.Core
+ * @subpackage DataModel.Extender
+ * @see ElggAnnotation
+ * @see ElggMetadata
+ * @link http://docs.elgg.org/DataModel/Extenders
+ */
+abstract class ElggExtender implements
+ Exportable,
+ Loggable, // Can events related to this object class be logged
+ Iterator, // Override foreach behaviour
+ ArrayAccess // Override for array access
+{
+ /**
+ * Holds attributes to save to database
+ *
+ * @var array
+ */
+ protected $attributes;
+
+ /**
+ * Returns an attribute
+ *
+ * @param string $name
+ * @return mixed
+ */
+ protected function get($name) {
+ if (isset($this->attributes[$name])) {
+ // Sanitise value if necessary
+ if ($name=='value') {
+ switch ($this->attributes['value_type']) {
+ case 'integer' :
+ return (int)$this->attributes['value'];
+
+ //case 'tag' :
+ //case 'file' :
+ case 'text' :
+ return ($this->attributes['value']);
+
+ default :
+ throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $this->attributes['value_type']));
+ }
+ }
+
+ return $this->attributes[$name];
+ }
+ return null;
+ }
+
+ /**
+ * Set an attribute
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param string $value_type
+ * @return boolean
+ */
+ protected function set($name, $value, $value_type = "") {
+ $this->attributes[$name] = $value;
+ if ($name == 'value') {
+ $this->attributes['value_type'] = detect_extender_valuetype($value, $value_type);
+ }
+
+ return true;
+ }
+
+ /**
+ * Return the owner guid of this extender.
+ *
+ * @return int
+ */
+ public function getOwner() {
+ return $this->owner_guid;
+ }
+
+ /**
+ * Return the owner entity.
+ *
+ * @return ElggEntity|false
+ * @since 1.7.0
+ */
+ public function getOwnerEntity() {
+ return get_user($this->owner_guid);
+ }
+
+ /**
+ * Return the entity this describes.
+ *
+ * @return ElggEntity The enttiy
+ */
+ public function getEntity() {
+ return get_entity($this->entity_guid);
+ }
+
+ /**
+ * Save this data to the appropriate database table.
+ */
+ abstract public function save();
+
+ /**
+ * Delete this data.
+ */
+ abstract public function delete();
+
+ /**
+ * Returns if a user can edit this extended data.
+ *
+ * @param int $user_guid The GUID of the user (defaults to currently logged in user)
+ * @return bool
+ */
+ public function canEdit($user_guid = 0) {
+ return can_edit_extender($this->id,$this->type,$user_guid);
+ }
+
+ /**
+ * Return a url for this extender.
+ *
+ * @return string
+ */
+ public abstract function getURL();
+
+ /*
+ * EXPORTABLE INTERFACE
+ */
+
+ /**
+ * Return an array of fields which can be exported.
+ *
+ * @return array
+ */
+ public function getExportableValues() {
+ return array(
+ 'id',
+ 'entity_guid',
+ 'name',
+ 'value',
+ 'value_type',
+ 'owner_guid',
+ 'type',
+ );
+ }
+
+ /**
+ * Export this object
+ *
+ * @return array
+ */
+ public function export() {
+ $uuid = get_uuid_from_object($this);
+
+ $meta = new ODDMetadata($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
+ $meta->setAttribute('published', date("r", $this->time_created));
+
+ return $meta;
+ }
+
+ /*
+ * SYSTEM LOG INTERFACE
+ */
+
+ /**
+ * Return an identification for the object for storage in the system log.
+ * This id must be an integer.
+ *
+ * @return int
+ */
+ public function getSystemLogID() {
+ return $this->id;
+ }
+
+ /**
+ * Return the class name of the object.
+ *
+ * @return string
+ */
+ public function getClassName() {
+ return get_class($this);
+ }
+
+ /**
+ * Return the GUID of the owner of this object.
+ *
+ * @return int
+ */
+ public function getObjectOwnerGUID() {
+ return $this->owner_guid;
+ }
+
+ /**
+ * Return a type of extension.
+ *
+ * @return string
+ */
+ public function getType() {
+ return $this->type;
+ }
+
+ /**
+ * Return a subtype. For metadata & annotations this is the 'name' and
+ * for relationship this is the relationship type.
+ *
+ * @return string
+ */
+ public function getSubtype() {
+ return $this->name;
+ }
+
+
+ /*
+ * ITERATOR INTERFACE
+ */
+
+ /*
+ * This lets an entity's attributes be displayed using foreach as a normal array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+ private $valid = FALSE;
+
+ function rewind() {
+ $this->valid = (FALSE !== reset($this->attributes));
+ }
+
+ function current() {
+ return current($this->attributes);
+ }
+
+ function key() {
+ return key($this->attributes);
+ }
+
+ function next() {
+ $this->valid = (FALSE !== next($this->attributes));
+ }
+
+ function valid() {
+ return $this->valid;
+ }
+
+ /*
+ * ARRAY ACCESS INTERFACE
+ */
+
+ /*
+ * This lets an entity's attributes be accessed like an associative array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+ function offsetSet($key, $value) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ function offsetGet($key) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ return $this->attributes[$key];
+ }
+ }
+
+ function offsetUnset($key) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ // Full unsetting is dangerious for our objects
+ $this->attributes[$key] = "";
+ }
+ }
+
+ function offsetExists($offset) {
+ return array_key_exists($offset, $this->attributes);
+ }
+}
-<?php\r
-/**\r
- * ElggFileCache\r
- * Store cached data in a file store.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage API\r
- */\r
-class ElggFileCache extends ElggCache {\r
- /**\r
- * Set the Elgg cache.\r
- *\r
- * @param string $cache_path The cache path.\r
- * @param int $max_age Maximum age in seconds, 0 if no limit.\r
- * @param int $max_size Maximum size of cache in seconds, 0 if no limit.\r
- */\r
- function __construct($cache_path, $max_age = 0, $max_size = 0) {\r
- $this->set_variable("cache_path", $cache_path);\r
- $this->set_variable("max_age", $max_age);\r
- $this->set_variable("max_size", $max_size);\r
-\r
- if ($cache_path=="") {\r
- throw new ConfigurationException(elgg_echo('ConfigurationException:NoCachePath'));\r
- }\r
- }\r
-\r
- /**\r
- * Create and return a handle to a file.\r
- *\r
- * @param string $filename\r
- * @param string $rw\r
- */\r
- protected function create_file($filename, $rw = "rb") {\r
- // Create a filename matrix\r
- $matrix = "";\r
- $depth = strlen($filename);\r
- if ($depth > 5) {\r
- $depth = 5;\r
- }\r
-\r
- // Create full path\r
- $path = $this->get_variable("cache_path") . $matrix;\r
- if (!is_dir($path)) {\r
- mkdir($path, 0700, true);\r
- }\r
-\r
- // Open the file\r
- if ((!file_exists($path . $filename)) && ($rw=="rb")) {\r
- return false;\r
- }\r
-\r
- return fopen($path . $filename, $rw);\r
- }\r
-\r
- /**\r
- * Create a sanitised filename for the file.\r
- *\r
- * @param string $filename\r
- */\r
- protected function sanitise_filename($filename) {\r
- // @todo : Writeme\r
-\r
- return $filename;\r
- }\r
-\r
- /**\r
- * Save a key\r
- *\r
- * @param string $key\r
- * @param string $data\r
- * @return boolean\r
- */\r
- public function save($key, $data) {\r
- $f = $this->create_file($this->sanitise_filename($key), "wb");\r
- if ($f) {\r
- $result = fwrite($f, $data);\r
- fclose($f);\r
-\r
- return $result;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Load a key\r
- *\r
- * @param string $key\r
- * @param int $offset\r
- * @param int $limit\r
- * @return string\r
- */\r
- public function load($key, $offset = 0, $limit = null) {\r
- $f = $this->create_file($this->sanitise_filename($key));\r
- if ($f) {\r
- //fseek($f, $offset);\r
- if (!$limit) {\r
- $limit = -1;\r
- }\r
- $data = stream_get_contents($f, $limit, $offset);\r
-\r
- fclose($f);\r
-\r
- return $data;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Invalidate a given key.\r
- *\r
- * @param string $key\r
- * @return bool\r
- */\r
- public function delete($key) {\r
- $dir = $this->get_variable("cache_path");\r
- \r
- if (file_exists($dir.$key)) {\r
- return unlink($dir.$key);\r
- }\r
- return TRUE;\r
- }\r
-\r
- public function clear() {\r
- // @todo writeme\r
- }\r
-\r
- public function __destruct() {\r
- // @todo Check size and age, clean up accordingly\r
- $size = 0;\r
- $dir = $this->get_variable("cache_path");\r
-\r
- // Short circuit if both size and age are unlimited\r
- if (($this->get_variable("max_age")==0) && ($this->get_variable("max_size")==0)) {\r
- return;\r
- }\r
-\r
- $exclude = array(".","..");\r
-\r
- $files = scandir($dir);\r
- if (!$files) {\r
- throw new IOException(sprintf(elgg_echo('IOException:NotDirectory'), $dir));\r
- }\r
-\r
- // Perform cleanup\r
- foreach ($files as $f) {\r
- if (!in_array($f, $exclude)) {\r
- $stat = stat($dir.$f);\r
-\r
- // Add size\r
- $size .= $stat['size'];\r
-\r
- // Is this older than my maximum date?\r
- if (($this->get_variable("max_age")>0) && (time() - $stat['mtime'] > $this->get_variable("max_age"))) {\r
- unlink($dir.$f);\r
- }\r
-\r
- // @todo Size\r
- }\r
- }\r
- }\r
+<?php
+/**
+ * ElggFileCache
+ * Store cached data in a file store.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage API
+ */
+class ElggFileCache extends ElggCache {
+ /**
+ * Set the Elgg cache.
+ *
+ * @param string $cache_path The cache path.
+ * @param int $max_age Maximum age in seconds, 0 if no limit.
+ * @param int $max_size Maximum size of cache in seconds, 0 if no limit.
+ */
+ function __construct($cache_path, $max_age = 0, $max_size = 0) {
+ $this->set_variable("cache_path", $cache_path);
+ $this->set_variable("max_age", $max_age);
+ $this->set_variable("max_size", $max_size);
+
+ if ($cache_path=="") {
+ throw new ConfigurationException(elgg_echo('ConfigurationException:NoCachePath'));
+ }
+ }
+
+ /**
+ * Create and return a handle to a file.
+ *
+ * @param string $filename
+ * @param string $rw
+ */
+ protected function create_file($filename, $rw = "rb") {
+ // Create a filename matrix
+ $matrix = "";
+ $depth = strlen($filename);
+ if ($depth > 5) {
+ $depth = 5;
+ }
+
+ // Create full path
+ $path = $this->get_variable("cache_path") . $matrix;
+ if (!is_dir($path)) {
+ mkdir($path, 0700, true);
+ }
+
+ // Open the file
+ if ((!file_exists($path . $filename)) && ($rw=="rb")) {
+ return false;
+ }
+
+ return fopen($path . $filename, $rw);
+ }
+
+ /**
+ * Create a sanitised filename for the file.
+ *
+ * @param string $filename
+ */
+ protected function sanitise_filename($filename) {
+ // @todo : Writeme
+
+ return $filename;
+ }
+
+ /**
+ * Save a key
+ *
+ * @param string $key
+ * @param string $data
+ * @return boolean
+ */
+ public function save($key, $data) {
+ $f = $this->create_file($this->sanitise_filename($key), "wb");
+ if ($f) {
+ $result = fwrite($f, $data);
+ fclose($f);
+
+ return $result;
+ }
+
+ return false;
+ }
+
+ /**
+ * Load a key
+ *
+ * @param string $key
+ * @param int $offset
+ * @param int $limit
+ * @return string
+ */
+ public function load($key, $offset = 0, $limit = null) {
+ $f = $this->create_file($this->sanitise_filename($key));
+ if ($f) {
+ //fseek($f, $offset);
+ if (!$limit) {
+ $limit = -1;
+ }
+ $data = stream_get_contents($f, $limit, $offset);
+
+ fclose($f);
+
+ return $data;
+ }
+
+ return false;
+ }
+
+ /**
+ * Invalidate a given key.
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function delete($key) {
+ $dir = $this->get_variable("cache_path");
+
+ if (file_exists($dir.$key)) {
+ return unlink($dir.$key);
+ }
+ return TRUE;
+ }
+
+ public function clear() {
+ // @todo writeme
+ }
+
+ public function __destruct() {
+ // @todo Check size and age, clean up accordingly
+ $size = 0;
+ $dir = $this->get_variable("cache_path");
+
+ // Short circuit if both size and age are unlimited
+ if (($this->get_variable("max_age")==0) && ($this->get_variable("max_size")==0)) {
+ return;
+ }
+
+ $exclude = array(".","..");
+
+ $files = scandir($dir);
+ if (!$files) {
+ throw new IOException(sprintf(elgg_echo('IOException:NotDirectory'), $dir));
+ }
+
+ // Perform cleanup
+ foreach ($files as $f) {
+ if (!in_array($f, $exclude)) {
+ $stat = stat($dir.$f);
+
+ // Add size
+ $size .= $stat['size'];
+
+ // Is this older than my maximum date?
+ if (($this->get_variable("max_age")>0) && (time() - $stat['mtime'] > $this->get_variable("max_age"))) {
+ unlink($dir.$f);
+ }
+
+ // @todo Size
+ }
+ }
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class ElggFilestore\r
- * This class defines the interface for all elgg data repositories.\r
- * @author Curverider Ltd\r
- */\r
-abstract class ElggFilestore {\r
- /**\r
- * Attempt to open the file $file for storage or writing.\r
- *\r
- * @param ElggFile $file\r
- * @param string $mode "read", "write", "append"\r
- * @return mixed A handle to the opened file or false on error.\r
- */\r
- abstract public function open(ElggFile $file, $mode);\r
-\r
- /**\r
- * Write data to a given file handle.\r
- *\r
- * @param mixed $f The file handle - exactly what this is depends on the file system\r
- * @param string $data The binary string of data to write\r
- * @return int Number of bytes written.\r
- */\r
- abstract public function write($f, $data);\r
-\r
- /**\r
- * Read data from a filestore.\r
- *\r
- * @param mixed $f The file handle\r
- * @param int $length Length in bytes to read.\r
- * @param int $offset The optional offset.\r
- * @return mixed String of data or false on error.\r
- */\r
- abstract public function read($f, $length, $offset = 0);\r
-\r
- /**\r
- * Seek a given position within a file handle.\r
- *\r
- * @param mixed $f The file handle.\r
- * @param int $position The position.\r
- */\r
- abstract public function seek($f, $position);\r
-\r
- /**\r
- * Return a whether the end of a file has been reached.\r
- *\r
- * @param mixed $f The file handle.\r
- * @return boolean\r
- */\r
- abstract public function eof($f);\r
-\r
- /**\r
- * Return the current position in an open file.\r
- *\r
- * @param mixed $f The file handle.\r
- * @return int\r
- */\r
- abstract public function tell($f);\r
-\r
- /**\r
- * Close a given file handle.\r
- *\r
- * @param mixed $f\r
- */\r
- abstract public function close($f);\r
-\r
- /**\r
- * Delete the file associated with a given file handle.\r
- *\r
- * @param ElggFile $file\r
- */\r
- abstract public function delete(ElggFile $file);\r
-\r
- /**\r
- * Return the size in bytes for a given file.\r
- *\r
- * @param ElggFile $file\r
- */\r
- abstract public function getFileSize(ElggFile $file);\r
-\r
- /**\r
- * Return the filename of a given file as stored on the filestore.\r
- *\r
- * @param ElggFile $file\r
- */\r
- abstract public function getFilenameOnFilestore(ElggFile $file);\r
-\r
- /**\r
- * Get the filestore's creation parameters as an associative array.\r
- * Used for serialisation and for storing the creation details along side a file object.\r
- *\r
- * @return array\r
- */\r
- abstract public function getParameters();\r
-\r
- /**\r
- * Set the parameters from the associative array produced by $this->getParameters().\r
- */\r
- abstract public function setParameters(array $parameters);\r
-\r
- /**\r
- * Get the contents of the whole file.\r
- *\r
- * @param mixed $file The file handle.\r
- * @return mixed The file contents.\r
- */\r
- abstract public function grabFile(ElggFile $file);\r
-\r
- /**\r
- * Return whether a file physically exists or not.\r
- *\r
- * @param ElggFile $file\r
- */\r
- abstract public function exists(ElggFile $file);\r
+<?php
+/**
+ * @class ElggFilestore
+ * This class defines the interface for all elgg data repositories.
+ * @author Curverider Ltd
+ */
+abstract class ElggFilestore {
+ /**
+ * Attempt to open the file $file for storage or writing.
+ *
+ * @param ElggFile $file
+ * @param string $mode "read", "write", "append"
+ * @return mixed A handle to the opened file or false on error.
+ */
+ abstract public function open(ElggFile $file, $mode);
+
+ /**
+ * Write data to a given file handle.
+ *
+ * @param mixed $f The file handle - exactly what this is depends on the file system
+ * @param string $data The binary string of data to write
+ * @return int Number of bytes written.
+ */
+ abstract public function write($f, $data);
+
+ /**
+ * Read data from a filestore.
+ *
+ * @param mixed $f The file handle
+ * @param int $length Length in bytes to read.
+ * @param int $offset The optional offset.
+ * @return mixed String of data or false on error.
+ */
+ abstract public function read($f, $length, $offset = 0);
+
+ /**
+ * Seek a given position within a file handle.
+ *
+ * @param mixed $f The file handle.
+ * @param int $position The position.
+ */
+ abstract public function seek($f, $position);
+
+ /**
+ * Return a whether the end of a file has been reached.
+ *
+ * @param mixed $f The file handle.
+ * @return boolean
+ */
+ abstract public function eof($f);
+
+ /**
+ * Return the current position in an open file.
+ *
+ * @param mixed $f The file handle.
+ * @return int
+ */
+ abstract public function tell($f);
+
+ /**
+ * Close a given file handle.
+ *
+ * @param mixed $f
+ */
+ abstract public function close($f);
+
+ /**
+ * Delete the file associated with a given file handle.
+ *
+ * @param ElggFile $file
+ */
+ abstract public function delete(ElggFile $file);
+
+ /**
+ * Return the size in bytes for a given file.
+ *
+ * @param ElggFile $file
+ */
+ abstract public function getFileSize(ElggFile $file);
+
+ /**
+ * Return the filename of a given file as stored on the filestore.
+ *
+ * @param ElggFile $file
+ */
+ abstract public function getFilenameOnFilestore(ElggFile $file);
+
+ /**
+ * Get the filestore's creation parameters as an associative array.
+ * Used for serialisation and for storing the creation details along side a file object.
+ *
+ * @return array
+ */
+ abstract public function getParameters();
+
+ /**
+ * Set the parameters from the associative array produced by $this->getParameters().
+ */
+ abstract public function setParameters(array $parameters);
+
+ /**
+ * Get the contents of the whole file.
+ *
+ * @param mixed $file The file handle.
+ * @return mixed The file contents.
+ */
+ abstract public function grabFile(ElggFile $file);
+
+ /**
+ * Return whether a file physically exists or not.
+ *
+ * @param ElggFile $file
+ */
+ abstract public function exists(ElggFile $file);
}
\ No newline at end of file
-<?php\r
-\r
-/**\r
- * @class ElggGroup Class representing a container for other elgg entities.\r
- * @author Curverider Ltd\r
- */\r
-class ElggGroup extends ElggEntity\r
- implements Friendable {\r
-\r
- protected function initialise_attributes() {\r
- parent::initialise_attributes();\r
-\r
- $this->attributes['type'] = "group";\r
- $this->attributes['name'] = "";\r
- $this->attributes['description'] = "";\r
- $this->attributes['tables_split'] = 2;\r
- }\r
-\r
- /**\r
- * Construct a new user entity, optionally from a given id value.\r
- *\r
- * @param mixed $guid If an int, load that GUID.\r
- * If a db row then will attempt to load the rest of the data.\r
- * @throws Exception if there was a problem creating the user.\r
- */\r
- function __construct($guid = null) {\r
- $this->initialise_attributes();\r
-\r
- if (!empty($guid)) {\r
- // Is $guid is a DB row - either a entity row, or a user table row.\r
- if ($guid instanceof stdClass) {\r
- // Load the rest\r
- if (!$this->load($guid->guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));\r
- }\r
- }\r
- // Is $guid is an ElggGroup? Use a copy constructor\r
- else if ($guid instanceof ElggGroup) {\r
- elgg_deprecated_notice('This type of usage of the ElggGroup constructor was deprecated. Please use the clone method.', 1.7);\r
-\r
- foreach ($guid->attributes as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
- // Is this is an ElggEntity but not an ElggGroup = ERROR!\r
- else if ($guid instanceof ElggEntity) {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggGroup'));\r
- }\r
- // We assume if we have got this far, $guid is an int\r
- else if (is_numeric($guid)) {\r
- if (!$this->load($guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));\r
- }\r
- }\r
-\r
- else {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Add an ElggObject to this group.\r
- *\r
- * @param ElggObject $object The object.\r
- * @return bool\r
- */\r
- public function addObjectToGroup(ElggObject $object) {\r
- return add_object_to_group($this->getGUID(), $object->getGUID());\r
- }\r
-\r
- /**\r
- * Remove an object from the containing group.\r
- *\r
- * @param int $guid The guid of the object.\r
- * @return bool\r
- */\r
- public function removeObjectFromGroup($guid) {\r
- return remove_object_from_group($this->getGUID(), $guid);\r
- }\r
-\r
- public function get($name) {\r
- if ($name == 'username') {\r
- return 'group:' . $this->getGUID();\r
- }\r
- return parent::get($name);\r
- }\r
-\r
-/**\r
- * Start friendable compatibility block:\r
- *\r
- * public function addFriend($friend_guid);\r
- public function removeFriend($friend_guid);\r
- public function isFriend();\r
- public function isFriendsWith($user_guid);\r
- public function isFriendOf($user_guid);\r
- public function getFriends($subtype = "", $limit = 10, $offset = 0);\r
- public function getFriendsOf($subtype = "", $limit = 10, $offset = 0);\r
- public function getObjects($subtype="", $limit = 10, $offset = 0);\r
- public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0);\r
- public function countObjects($subtype = "");\r
- */\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function addFriend($friend_guid) {\r
- return $this->join(get_entity($friend_guid));\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function removeFriend($friend_guid) {\r
- return $this->leave(get_entity($friend_guid));\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function isFriend() {\r
- return $this->isMember();\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function isFriendsWith($user_guid) {\r
- return $this->isMember($user_guid);\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function isFriendOf($user_guid) {\r
- return $this->isMember($user_guid);\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function getFriends($subtype = "", $limit = 10, $offset = 0) {\r
- return get_group_members($this->getGUID(), $limit, $offset);\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function getFriendsOf($subtype = "", $limit = 10, $offset = 0) {\r
- return get_group_members($this->getGUID(), $limit, $offset);\r
- }\r
-\r
- /**\r
- * Get objects contained in this group.\r
- *\r
- * @param string $subtype\r
- * @param int $limit\r
- * @param int $offset\r
- * @return mixed\r
- */\r
- public function getObjects($subtype="", $limit = 10, $offset = 0) {\r
- return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", $limit, $offset, false);\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0) {\r
- return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", $limit, $offset, false);\r
- }\r
-\r
- /**\r
- * For compatibility with Friendable\r
- */\r
- public function countObjects($subtype = "") {\r
- return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", 10, 0, true);\r
- }\r
-\r
-/**\r
- * End friendable compatibility block\r
- */\r
-\r
- /**\r
- * Get a list of group members.\r
- *\r
- * @param int $limit\r
- * @param int $offset\r
- * @return mixed\r
- */\r
- public function getMembers($limit = 10, $offset = 0, $count = false) {\r
- return get_group_members($this->getGUID(), $limit, $offset, 0 , $count);\r
- }\r
-\r
- /**\r
- * Returns whether the current group is public membership or not.\r
- * @return bool\r
- */\r
- public function isPublicMembership() {\r
- if ($this->membership == ACCESS_PUBLIC) {\r
- return true;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Return whether a given user is a member of this group or not.\r
- *\r
- * @param ElggUser $user The user\r
- * @return bool\r
- */\r
- public function isMember($user = 0) {\r
- if (!($user instanceof ElggUser)) {\r
- $user = get_loggedin_user();\r
- }\r
- if (!($user instanceof ElggUser)) {\r
- return false;\r
- }\r
- return is_group_member($this->getGUID(), $user->getGUID());\r
- }\r
-\r
- /**\r
- * Join an elgg user to this group.\r
- *\r
- * @param ElggUser $user\r
- * @return bool\r
- */\r
- public function join(ElggUser $user) {\r
- return join_group($this->getGUID(), $user->getGUID());\r
- }\r
-\r
- /**\r
- * Remove a user from the group.\r
- *\r
- * @param ElggUser $user\r
- */\r
- public function leave(ElggUser $user) {\r
- return leave_group($this->getGUID(), $user->getGUID());\r
- }\r
-\r
- /**\r
- * Override the load function.\r
- * This function will ensure that all data is loaded (were possible), so\r
- * if only part of the ElggGroup is loaded, it'll load the rest.\r
- *\r
- * @param int $guid\r
- */\r
- protected function load($guid) {\r
- // Test to see if we have the generic stuff\r
- if (!parent::load($guid)) {\r
- return false;\r
- }\r
-\r
- // Check the type\r
- if ($this->attributes['type']!='group') {\r
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));\r
- }\r
-\r
- // Load missing data\r
- $row = get_group_entity_as_row($guid);\r
- if (($row) && (!$this->isFullyLoaded())) {\r
- // If $row isn't a cached copy then increment the counter\r
- $this->attributes['tables_loaded'] ++;\r
- }\r
-\r
- // Now put these into the attributes array as core values\r
- $objarray = (array) $row;\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Override the save function.\r
- */\r
- public function save() {\r
- // Save generic stuff\r
- if (!parent::save()) {\r
- return false;\r
- }\r
-\r
- // Now save specific stuff\r
- return create_group_entity($this->get('guid'), $this->get('name'), $this->get('description'));\r
- }\r
-\r
- // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * Return an array of fields which can be exported.\r
- */\r
- public function getExportableValues() {\r
- return array_merge(parent::getExportableValues(), array(\r
- 'name',\r
- 'description',\r
- ));\r
- }\r
+<?php
+
+/**
+ * @class ElggGroup Class representing a container for other elgg entities.
+ * @author Curverider Ltd
+ */
+class ElggGroup extends ElggEntity
+ implements Friendable {
+
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['type'] = "group";
+ $this->attributes['name'] = "";
+ $this->attributes['description'] = "";
+ $this->attributes['tables_split'] = 2;
+ }
+
+ /**
+ * Construct a new user entity, optionally from a given id value.
+ *
+ * @param mixed $guid If an int, load that GUID.
+ * If a db row then will attempt to load the rest of the data.
+ * @throws Exception if there was a problem creating the user.
+ */
+ function __construct($guid = null) {
+ $this->initialise_attributes();
+
+ if (!empty($guid)) {
+ // Is $guid is a DB row - either a entity row, or a user table row.
+ if ($guid instanceof stdClass) {
+ // Load the rest
+ if (!$this->load($guid->guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));
+ }
+ }
+ // Is $guid is an ElggGroup? Use a copy constructor
+ else if ($guid instanceof ElggGroup) {
+ elgg_deprecated_notice('This type of usage of the ElggGroup constructor was deprecated. Please use the clone method.', 1.7);
+
+ foreach ($guid->attributes as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ }
+ // Is this is an ElggEntity but not an ElggGroup = ERROR!
+ else if ($guid instanceof ElggEntity) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggGroup'));
+ }
+ // We assume if we have got this far, $guid is an int
+ else if (is_numeric($guid)) {
+ if (!$this->load($guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));
+ }
+ }
+
+ else {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));
+ }
+ }
+ }
+
+ /**
+ * Add an ElggObject to this group.
+ *
+ * @param ElggObject $object The object.
+ * @return bool
+ */
+ public function addObjectToGroup(ElggObject $object) {
+ return add_object_to_group($this->getGUID(), $object->getGUID());
+ }
+
+ /**
+ * Remove an object from the containing group.
+ *
+ * @param int $guid The guid of the object.
+ * @return bool
+ */
+ public function removeObjectFromGroup($guid) {
+ return remove_object_from_group($this->getGUID(), $guid);
+ }
+
+ public function get($name) {
+ if ($name == 'username') {
+ return 'group:' . $this->getGUID();
+ }
+ return parent::get($name);
+ }
+
+/**
+ * Start friendable compatibility block:
+ *
+ * public function addFriend($friend_guid);
+ public function removeFriend($friend_guid);
+ public function isFriend();
+ public function isFriendsWith($user_guid);
+ public function isFriendOf($user_guid);
+ public function getFriends($subtype = "", $limit = 10, $offset = 0);
+ public function getFriendsOf($subtype = "", $limit = 10, $offset = 0);
+ public function getObjects($subtype="", $limit = 10, $offset = 0);
+ public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0);
+ public function countObjects($subtype = "");
+ */
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function addFriend($friend_guid) {
+ return $this->join(get_entity($friend_guid));
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function removeFriend($friend_guid) {
+ return $this->leave(get_entity($friend_guid));
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function isFriend() {
+ return $this->isMember();
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function isFriendsWith($user_guid) {
+ return $this->isMember($user_guid);
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function isFriendOf($user_guid) {
+ return $this->isMember($user_guid);
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function getFriends($subtype = "", $limit = 10, $offset = 0) {
+ return get_group_members($this->getGUID(), $limit, $offset);
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function getFriendsOf($subtype = "", $limit = 10, $offset = 0) {
+ return get_group_members($this->getGUID(), $limit, $offset);
+ }
+
+ /**
+ * Get objects contained in this group.
+ *
+ * @param string $subtype
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
+ */
+ public function getObjects($subtype="", $limit = 10, $offset = 0) {
+ return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", $limit, $offset, false);
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0) {
+ return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", $limit, $offset, false);
+ }
+
+ /**
+ * For compatibility with Friendable
+ */
+ public function countObjects($subtype = "") {
+ return get_objects_in_group($this->getGUID(), $subtype, 0, 0, "", 10, 0, true);
+ }
+
+/**
+ * End friendable compatibility block
+ */
+
+ /**
+ * Get a list of group members.
+ *
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
+ */
+ public function getMembers($limit = 10, $offset = 0, $count = false) {
+ return get_group_members($this->getGUID(), $limit, $offset, 0 , $count);
+ }
+
+ /**
+ * Returns whether the current group is public membership or not.
+ * @return bool
+ */
+ public function isPublicMembership() {
+ if ($this->membership == ACCESS_PUBLIC) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Return whether a given user is a member of this group or not.
+ *
+ * @param ElggUser $user The user
+ * @return bool
+ */
+ public function isMember($user = 0) {
+ if (!($user instanceof ElggUser)) {
+ $user = get_loggedin_user();
+ }
+ if (!($user instanceof ElggUser)) {
+ return false;
+ }
+ return is_group_member($this->getGUID(), $user->getGUID());
+ }
+
+ /**
+ * Join an elgg user to this group.
+ *
+ * @param ElggUser $user
+ * @return bool
+ */
+ public function join(ElggUser $user) {
+ return join_group($this->getGUID(), $user->getGUID());
+ }
+
+ /**
+ * Remove a user from the group.
+ *
+ * @param ElggUser $user
+ */
+ public function leave(ElggUser $user) {
+ return leave_group($this->getGUID(), $user->getGUID());
+ }
+
+ /**
+ * Override the load function.
+ * This function will ensure that all data is loaded (were possible), so
+ * if only part of the ElggGroup is loaded, it'll load the rest.
+ *
+ * @param int $guid
+ */
+ protected function load($guid) {
+ // Test to see if we have the generic stuff
+ if (!parent::load($guid)) {
+ return false;
+ }
+
+ // Check the type
+ if ($this->attributes['type']!='group') {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));
+ }
+
+ // Load missing data
+ $row = get_group_entity_as_row($guid);
+ if (($row) && (!$this->isFullyLoaded())) {
+ // If $row isn't a cached copy then increment the counter
+ $this->attributes['tables_loaded'] ++;
+ }
+
+ // Now put these into the attributes array as core values
+ $objarray = (array) $row;
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+
+ return true;
+ }
+
+ /**
+ * Override the save function.
+ */
+ public function save() {
+ // Save generic stuff
+ if (!parent::save()) {
+ return false;
+ }
+
+ // Now save specific stuff
+ return create_group_entity($this->get('guid'), $this->get('name'), $this->get('description'));
+ }
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues() {
+ return array_merge(parent::getExportableValues(), array(
+ 'name',
+ 'description',
+ ));
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * ElggHMACCache\r
- * Store cached data in a temporary database, only used by the HMAC stuff.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage API\r
- */\r
-class ElggHMACCache extends ElggCache {\r
- /**\r
- * Set the Elgg cache.\r
- *\r
- * @param int $max_age Maximum age in seconds, 0 if no limit.\r
- */\r
- function __construct($max_age = 0) {\r
- $this->set_variable("max_age", $max_age);\r
- }\r
-\r
- /**\r
- * Save a key\r
- *\r
- * @param string $key\r
- * @param string $data\r
- * @return boolean\r
- */\r
- public function save($key, $data) {\r
- global $CONFIG;\r
-\r
- $key = sanitise_string($key);\r
- $time = time();\r
-\r
- return insert_data("INSERT into {$CONFIG->dbprefix}hmac_cache (hmac, ts) VALUES ('$key', '$time')");\r
- }\r
-\r
- /**\r
- * Load a key\r
- *\r
- * @param string $key\r
- * @param int $offset\r
- * @param int $limit\r
- * @return string\r
- */\r
- public function load($key, $offset = 0, $limit = null) {\r
- global $CONFIG;\r
-\r
- $key = sanitise_string($key);\r
-\r
- $row = get_data_row("SELECT * from {$CONFIG->dbprefix}hmac_cache where hmac='$key'");\r
- if ($row) {\r
- return $row->hmac;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Invalidate a given key.\r
- *\r
- * @param string $key\r
- * @return bool\r
- */\r
- public function delete($key) {\r
- global $CONFIG;\r
-\r
- $key = sanitise_string($key);\r
-\r
- return delete_data("DELETE from {$CONFIG->dbprefix}hmac_cache where hmac='$key'");\r
- }\r
-\r
- /**\r
- * Clear out all the contents of the cache.\r
- *\r
- * Not currently implemented in this cache type.\r
- */\r
- public function clear() {\r
- return true;\r
- }\r
-\r
- /**\r
- * Clean out old stuff.\r
- *\r
- */\r
- public function __destruct() {\r
- global $CONFIG;\r
-\r
- $time = time();\r
- $age = (int)$this->get_variable("max_age");\r
-\r
- $expires = $time-$age;\r
-\r
- delete_data("DELETE from {$CONFIG->dbprefix}hmac_cache where ts<$expires");\r
- }\r
+<?php
+/**
+ * ElggHMACCache
+ * Store cached data in a temporary database, only used by the HMAC stuff.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage API
+ */
+class ElggHMACCache extends ElggCache {
+ /**
+ * Set the Elgg cache.
+ *
+ * @param int $max_age Maximum age in seconds, 0 if no limit.
+ */
+ function __construct($max_age = 0) {
+ $this->set_variable("max_age", $max_age);
+ }
+
+ /**
+ * Save a key
+ *
+ * @param string $key
+ * @param string $data
+ * @return boolean
+ */
+ public function save($key, $data) {
+ global $CONFIG;
+
+ $key = sanitise_string($key);
+ $time = time();
+
+ return insert_data("INSERT into {$CONFIG->dbprefix}hmac_cache (hmac, ts) VALUES ('$key', '$time')");
+ }
+
+ /**
+ * Load a key
+ *
+ * @param string $key
+ * @param int $offset
+ * @param int $limit
+ * @return string
+ */
+ public function load($key, $offset = 0, $limit = null) {
+ global $CONFIG;
+
+ $key = sanitise_string($key);
+
+ $row = get_data_row("SELECT * from {$CONFIG->dbprefix}hmac_cache where hmac='$key'");
+ if ($row) {
+ return $row->hmac;
+ }
+
+ return false;
+ }
+
+ /**
+ * Invalidate a given key.
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function delete($key) {
+ global $CONFIG;
+
+ $key = sanitise_string($key);
+
+ return delete_data("DELETE from {$CONFIG->dbprefix}hmac_cache where hmac='$key'");
+ }
+
+ /**
+ * Clear out all the contents of the cache.
+ *
+ * Not currently implemented in this cache type.
+ */
+ public function clear() {
+ return true;
+ }
+
+ /**
+ * Clean out old stuff.
+ *
+ */
+ public function __destruct() {
+ global $CONFIG;
+
+ $time = time();
+ $age = (int)$this->get_variable("max_age");
+
+ $expires = $time-$age;
+
+ delete_data("DELETE from {$CONFIG->dbprefix}hmac_cache where ts<$expires");
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Memcache wrapper class.\r
- * @author Curverider Ltd <info@elgg.com>\r
- */\r
-class ElggMemcache extends ElggSharedMemoryCache {\r
- /**\r
- * Minimum version of memcached needed to run\r
- *\r
- */\r
- private static $MINSERVERVERSION = '1.1.12';\r
-\r
- /**\r
- * Memcache object\r
- */\r
- private $memcache;\r
-\r
- /**\r
- * Expiry of saved items (default timeout after a day to prevent anything getting too stale)\r
- */\r
- private $expires = 86400;\r
-\r
- /**\r
- * The version of memcache running\r
- */\r
- private $version = 0;\r
-\r
- /**\r
- * Connect to memcache.\r
- *\r
- * @param string $cache_id The namespace for this cache to write to - note, namespaces of the same name are shared!\r
- */\r
- function __construct($namespace = 'default') {\r
- global $CONFIG;\r
-\r
- $this->setNamespace($namespace);\r
-\r
- // Do we have memcache?\r
- if (!class_exists('Memcache')) {\r
- throw new ConfigurationException(elgg_echo('memcache:notinstalled'));\r
- }\r
-\r
- // Create memcache object\r
- $this->memcache = new Memcache;\r
-\r
- // Now add servers\r
- if (!$CONFIG->memcache_servers) {\r
- throw new ConfigurationException(elgg_echo('memcache:noservers'));\r
- }\r
-\r
- if (is_callable($this->memcache, 'addServer')) {\r
- foreach ($CONFIG->memcache_servers as $server) {\r
- if (is_array($server)) {\r
- $this->memcache->addServer(\r
- $server[0],\r
- isset($server[1]) ? $server[1] : 11211,\r
- isset($server[2]) ? $server[2] : true,\r
- isset($server[3]) ? $server[3] : null,\r
- isset($server[4]) ? $server[4] : 1,\r
- isset($server[5]) ? $server[5] : 15,\r
- isset($server[6]) ? $server[6] : true\r
- );\r
-\r
- } else {\r
- $this->memcache->addServer($server, 11211);\r
- }\r
- }\r
- } else {\r
- elgg_log(elgg_echo('memcache:noaddserver'), 'ERROR');\r
-\r
- $server = $CONFIG->memcache_servers[0];\r
- if (is_array($server)) {\r
- $this->memcache->connect($server[0], $server[1]);\r
- } else {\r
- $this->memcache->addServer($server, 11211);\r
- }\r
- }\r
-\r
- // Get version\r
- $this->version = $this->memcache->getversion();\r
- if (version_compare($this->version, ElggMemcache::$MINSERVERVERSION, '<')) {\r
- throw new ConfigurationException(sprintf(elgg_echo('memcache:versiontoolow'), ElggMemcache::$MINSERVERVERSION, $this->version));\r
- }\r
-\r
- // Set some defaults\r
- if (isset($CONFIG->memcache_expires)) {\r
- $this->expires = $CONFIG->memcache_expires;\r
- }\r
- }\r
-\r
- /**\r
- * Set the default expiry.\r
- *\r
- * @param int $expires The lifetime as a unix timestamp or time from now. Defaults forever.\r
- */\r
- public function setDefaultExpiry($expires = 0) {\r
- $this->expires = $expires;\r
- }\r
-\r
- /**\r
- * Combine a key with the namespace.\r
- * Memcache can only accept <250 char key. If the given key is too long it is shortened.\r
- *\r
- * @param string $key The key\r
- * @return string The new key.\r
- */\r
- private function make_memcache_key($key) {\r
- $prefix = $this->getNamespace() . ":";\r
-\r
- if (strlen($prefix.$key)> 250) {\r
- $key = md5($key);\r
- }\r
-\r
- return $prefix.$key;\r
- }\r
-\r
- public function save($key, $data) {\r
- $key = $this->make_memcache_key($key);\r
-\r
- $result = $this->memcache->set($key, $data, null, $this->expires);\r
- if (!$result) {\r
- elgg_log("MEMCACHE: FAILED TO SAVE $key", 'ERROR');\r
- }\r
-\r
- return $result;\r
- }\r
-\r
- public function load($key, $offset = 0, $limit = null) {\r
- $key = $this->make_memcache_key($key);\r
-\r
- $result = $this->memcache->get($key);\r
- if (!$result) {\r
- elgg_log("MEMCACHE: FAILED TO LOAD $key", 'ERROR');\r
- }\r
-\r
- return $result;\r
- }\r
-\r
- public function delete($key) {\r
- $key = $this->make_memcache_key($key);\r
-\r
- return $this->memcache->delete($key, 0);\r
- }\r
-\r
- public function clear() {\r
- // DISABLE clearing for now - you must use delete on a specific key.\r
- return true;\r
-\r
- // @todo Namespaces as in #532\r
- }\r
-}\r
+<?php
+/**
+ * Memcache wrapper class.
+ * @author Curverider Ltd <info@elgg.com>
+ */
+class ElggMemcache extends ElggSharedMemoryCache {
+ /**
+ * Minimum version of memcached needed to run
+ *
+ */
+ private static $MINSERVERVERSION = '1.1.12';
+
+ /**
+ * Memcache object
+ */
+ private $memcache;
+
+ /**
+ * Expiry of saved items (default timeout after a day to prevent anything getting too stale)
+ */
+ private $expires = 86400;
+
+ /**
+ * The version of memcache running
+ */
+ private $version = 0;
+
+ /**
+ * Connect to memcache.
+ *
+ * @param string $cache_id The namespace for this cache to write to - note, namespaces of the same name are shared!
+ */
+ function __construct($namespace = 'default') {
+ global $CONFIG;
+
+ $this->setNamespace($namespace);
+
+ // Do we have memcache?
+ if (!class_exists('Memcache')) {
+ throw new ConfigurationException(elgg_echo('memcache:notinstalled'));
+ }
+
+ // Create memcache object
+ $this->memcache = new Memcache;
+
+ // Now add servers
+ if (!$CONFIG->memcache_servers) {
+ throw new ConfigurationException(elgg_echo('memcache:noservers'));
+ }
+
+ if (is_callable($this->memcache, 'addServer')) {
+ foreach ($CONFIG->memcache_servers as $server) {
+ if (is_array($server)) {
+ $this->memcache->addServer(
+ $server[0],
+ isset($server[1]) ? $server[1] : 11211,
+ isset($server[2]) ? $server[2] : true,
+ isset($server[3]) ? $server[3] : null,
+ isset($server[4]) ? $server[4] : 1,
+ isset($server[5]) ? $server[5] : 15,
+ isset($server[6]) ? $server[6] : true
+ );
+
+ } else {
+ $this->memcache->addServer($server, 11211);
+ }
+ }
+ } else {
+ elgg_log(elgg_echo('memcache:noaddserver'), 'ERROR');
+
+ $server = $CONFIG->memcache_servers[0];
+ if (is_array($server)) {
+ $this->memcache->connect($server[0], $server[1]);
+ } else {
+ $this->memcache->addServer($server, 11211);
+ }
+ }
+
+ // Get version
+ $this->version = $this->memcache->getversion();
+ if (version_compare($this->version, ElggMemcache::$MINSERVERVERSION, '<')) {
+ throw new ConfigurationException(sprintf(elgg_echo('memcache:versiontoolow'), ElggMemcache::$MINSERVERVERSION, $this->version));
+ }
+
+ // Set some defaults
+ if (isset($CONFIG->memcache_expires)) {
+ $this->expires = $CONFIG->memcache_expires;
+ }
+ }
+
+ /**
+ * Set the default expiry.
+ *
+ * @param int $expires The lifetime as a unix timestamp or time from now. Defaults forever.
+ */
+ public function setDefaultExpiry($expires = 0) {
+ $this->expires = $expires;
+ }
+
+ /**
+ * Combine a key with the namespace.
+ * Memcache can only accept <250 char key. If the given key is too long it is shortened.
+ *
+ * @param string $key The key
+ * @return string The new key.
+ */
+ private function make_memcache_key($key) {
+ $prefix = $this->getNamespace() . ":";
+
+ if (strlen($prefix.$key)> 250) {
+ $key = md5($key);
+ }
+
+ return $prefix.$key;
+ }
+
+ public function save($key, $data) {
+ $key = $this->make_memcache_key($key);
+
+ $result = $this->memcache->set($key, $data, null, $this->expires);
+ if (!$result) {
+ elgg_log("MEMCACHE: FAILED TO SAVE $key", 'ERROR');
+ }
+
+ return $result;
+ }
+
+ public function load($key, $offset = 0, $limit = null) {
+ $key = $this->make_memcache_key($key);
+
+ $result = $this->memcache->get($key);
+ if (!$result) {
+ elgg_log("MEMCACHE: FAILED TO LOAD $key", 'ERROR');
+ }
+
+ return $result;
+ }
+
+ public function delete($key) {
+ $key = $this->make_memcache_key($key);
+
+ return $this->memcache->delete($key, 0);
+ }
+
+ public function clear() {
+ // DISABLE clearing for now - you must use delete on a specific key.
+ return true;
+
+ // @todo Namespaces as in #532
+ }
+}
-<?php\r
-\r
-/**\r
- * ElggMetadata\r
- * This class describes metadata that can be attached to ElggEntities.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Core\r
- */\r
-class ElggMetadata extends ElggExtender {\r
- /**\r
- * Construct a new site object, optionally from a given id value or row.\r
- *\r
- * @param mixed $id\r
- */\r
- function __construct($id = null) {\r
- $this->attributes = array();\r
-\r
- if (!empty($id)) {\r
- // Create from db row\r
- if ($id instanceof stdClass) {\r
- $metadata = $id;\r
- } else {\r
- $metadata = get_metadata($id);\r
- }\r
-\r
- if ($metadata) {\r
- $objarray = (array) $metadata;\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- $this->attributes['type'] = "metadata";\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Class member get overloading\r
- *\r
- * @param string $name\r
- * @return mixed\r
- */\r
- function __get($name) {\r
- return $this->get($name);\r
- }\r
-\r
- /**\r
- * Class member set overloading\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- * @return mixed\r
- */\r
- function __set($name, $value) {\r
- return $this->set($name, $value);\r
- }\r
-\r
- /**\r
- * Determines whether or not the user can edit this piece of metadata\r
- *\r
- * @return true|false Depending on permissions\r
- */\r
- function canEdit() {\r
- if ($entity = get_entity($this->get('entity_guid'))) {\r
- return $entity->canEditMetadata($this);\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * Save matadata object\r
- *\r
- * @return int the metadata object id\r
- */\r
- function save() {\r
- if ($this->id > 0) {\r
- return update_metadata($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id);\r
- } else {\r
- $this->id = create_metadata($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id);\r
- if (!$this->id) {\r
- throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class()));\r
- }\r
- return $this->id;\r
- }\r
- }\r
-\r
- /**\r
- * Delete a given metadata.\r
- */\r
- function delete() {\r
- return delete_metadata($this->id);\r
- }\r
-\r
- /**\r
- * Get a url for this item of metadata.\r
- *\r
- * @return string\r
- */\r
- public function getURL() {\r
- return get_metadata_url($this->id);\r
- }\r
-\r
- // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * For a given ID, return the object associated with it.\r
- * This is used by the river functionality primarily.\r
- * This is useful for checking access permissions etc on objects.\r
- */\r
- public function getObjectFromID($id) {\r
- return get_metadata($id);\r
- }\r
+<?php
+
+/**
+ * ElggMetadata
+ * This class describes metadata that can be attached to ElggEntities.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Core
+ */
+class ElggMetadata extends ElggExtender {
+ /**
+ * Construct a new site object, optionally from a given id value or row.
+ *
+ * @param mixed $id
+ */
+ function __construct($id = null) {
+ $this->attributes = array();
+
+ if (!empty($id)) {
+ // Create from db row
+ if ($id instanceof stdClass) {
+ $metadata = $id;
+ } else {
+ $metadata = get_metadata($id);
+ }
+
+ if ($metadata) {
+ $objarray = (array) $metadata;
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ $this->attributes['type'] = "metadata";
+ }
+ }
+ }
+
+ /**
+ * Class member get overloading
+ *
+ * @param string $name
+ * @return mixed
+ */
+ function __get($name) {
+ return $this->get($name);
+ }
+
+ /**
+ * Class member set overloading
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return mixed
+ */
+ function __set($name, $value) {
+ return $this->set($name, $value);
+ }
+
+ /**
+ * Determines whether or not the user can edit this piece of metadata
+ *
+ * @return true|false Depending on permissions
+ */
+ function canEdit() {
+ if ($entity = get_entity($this->get('entity_guid'))) {
+ return $entity->canEditMetadata($this);
+ }
+ return false;
+ }
+
+ /**
+ * Save matadata object
+ *
+ * @return int the metadata object id
+ */
+ function save() {
+ if ($this->id > 0) {
+ return update_metadata($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id);
+ } else {
+ $this->id = create_metadata($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id);
+ if (!$this->id) {
+ throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class()));
+ }
+ return $this->id;
+ }
+ }
+
+ /**
+ * Delete a given metadata.
+ */
+ function delete() {
+ return delete_metadata($this->id);
+ }
+
+ /**
+ * Get a url for this item of metadata.
+ *
+ * @return string
+ */
+ public function getURL() {
+ return get_metadata_url($this->id);
+ }
+
+ // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) {
+ return get_metadata($id);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Elgg Object\r
- *\r
- * Elgg objects are the most common means of storing information in the database.\r
- * They are a child class of ElggEntity, so receive all the benefits of the Entities,\r
- * but also include a title and description field.\r
- *\r
- * An ElggObject represents a row from the objects_entity table, as well\r
- * as the related row in the entities table as represented by the parent\r
- * ElggEntity object.\r
- *\r
- * @internal Title and description are stored in the objects_entity table.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage DataModel.Object\r
- */\r
-class ElggObject extends ElggEntity {\r
- /**\r
- * Initialise the attributes array to include the type,\r
- * title, and description.\r
- */\r
- protected function initialise_attributes() {\r
- parent::initialise_attributes();\r
-\r
- $this->attributes['type'] = "object";\r
- $this->attributes['title'] = "";\r
- $this->attributes['description'] = "";\r
- $this->attributes['tables_split'] = 2;\r
- }\r
-\r
- /**\r
- * Load or create a new ElggObject.\r
- *\r
- * If no arguments are passed, create a new entity.\r
- * If an argument is passed as an int, attempt to load that object by guid.\r
- * If an argument is passed as an object, assume that it is as database result object and attempt to load\r
- * by $obj->guid.\r
- *\r
- * @param mixed $guid If an int, load that GUID. If a db row then will attempt to load the rest of the data.\r
- * @throws IOException If passed an incorrect guid\r
- * @throws InvalidParameterException If passed an Elgg* Entity that isn't an ElggObject\r
- */\r
- function __construct($guid = null) {\r
- $this->initialise_attributes();\r
-\r
- if (!empty($guid)) {\r
- // Is $guid is a DB row - either a entity row, or a object table row.\r
- if ($guid instanceof stdClass) {\r
- // Load the rest\r
- if (!$this->load($guid->guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));\r
- }\r
- }\r
-\r
- // Is $guid is an ElggObject? Use a copy constructor\r
- else if ($guid instanceof ElggObject) {\r
- elgg_deprecated_notice('This type of usage of the ElggObject constructor was deprecated. Please use the clone method.', 1.7);\r
-\r
- foreach ($guid->attributes as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- // Is this is an ElggEntity but not an ElggObject = ERROR!\r
- else if ($guid instanceof ElggEntity) {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggObject'));\r
- }\r
-\r
- // We assume if we have got this far, $guid is an int\r
- else if (is_numeric($guid)) {\r
- if (!$this->load($guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));\r
- }\r
- }\r
-\r
- else {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Loads the full ElggObject when given a guid.\r
- *\r
- * @param int $guid\r
- * @return bool\r
- * @throws InvalidClassException\r
- */\r
- protected function load($guid) {\r
- // Test to see if we have the generic stuff\r
- if (!parent::load($guid)) {\r
- return false;\r
- }\r
-\r
- // Check the type\r
- if ($this->attributes['type']!='object') {\r
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));\r
- }\r
-\r
- // Load missing data\r
- $row = get_object_entity_as_row($guid);\r
- if (($row) && (!$this->isFullyLoaded())) {\r
- // If $row isn't a cached copy then increment the counter\r
- $this->attributes['tables_loaded'] ++;\r
- }\r
-\r
- // Now put these into the attributes array as core values\r
- $objarray = (array) $row;\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Saves object-specific attributes.\r
- *\r
- * @internal Object attributes are saved in the objects_entity table.\r
- *\r
- * @return bool\r
- */\r
- public function save() {\r
- // Save ElggEntity attributes\r
- if (!parent::save()) {\r
- return false;\r
- }\r
-\r
- // Save ElggObject-specific attributes\r
- return create_object_entity($this->get('guid'), $this->get('title'), $this->get('description'), $this->get('container_guid'));\r
- }\r
-\r
- /**\r
- * Return sites that this object is a member of\r
- *\r
- * Site membership is determined by relationships and not site_guid.d\r
- *\r
- * @param string $subtype Optionally, the subtype of result we want to limit to\r
- * @param int $limit The number of results to return\r
- * @param int $offset Any indexing offset\r
- * @todo This should be moved to ElggEntity\r
- * @todo Unimplemented\r
- */\r
- function getSites($subtype="", $limit = 10, $offset = 0) {\r
- return get_site_objects($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * Add this object to a site\r
- *\r
- * @param int $site_guid The guid of the site to add it to\r
- * @return bool\r
- */\r
- function addToSite($site_guid) {\r
- return add_site_object($this->getGUID(), $site_guid);\r
- }\r
-\r
- /**\r
- * Set the container for this object.\r
- *\r
- * @param int $container_guid The ID of the container.\r
- * @return bool\r
- */\r
- function setContainer($container_guid) {\r
- $container_guid = (int)$container_guid;\r
-\r
- return $this->set('container_guid', $container_guid);\r
- }\r
-\r
- /**\r
- * Returns the container GUID of this object.\r
- *\r
- * @return int\r
- */\r
- function getContainer() {\r
- return $this->get('container_guid');\r
- }\r
-\r
- /**\r
- * Returns the contain entity for this object.\r
- *\r
- * @return mixed ElggGroup object or false.\r
- */\r
- function getContainerEntity() {\r
- $result = get_entity($this->getContainer());\r
-\r
- if (($result) && ($result instanceof ElggGroup)) {\r
- return $result;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Get the collections associated with a object.\r
- *\r
- * @param string $subtype Optionally, the subtype of result we want to limit to\r
- * @param int $limit The number of results to return\r
- * @param int $offset Any indexing offset\r
- * @return unknown\r
- */\r
- //public function getCollections($subtype="", $limit = 10, $offset = 0) { get_object_collections($this->getGUID(), $subtype, $limit, $offset); }\r
-\r
- /*\r
- * EXPORTABLE INTERFACE\r
- */\r
-\r
- /**\r
- * Return an array of fields which can be exported.\r
- *\r
- * @return array\r
- */\r
- public function getExportableValues() {\r
- return array_merge(parent::getExportableValues(), array(\r
- 'title',\r
- 'description',\r
- ));\r
- }\r
+<?php
+/**
+ * Elgg Object
+ *
+ * Elgg objects are the most common means of storing information in the database.
+ * They are a child class of ElggEntity, so receive all the benefits of the Entities,
+ * but also include a title and description field.
+ *
+ * An ElggObject represents a row from the objects_entity table, as well
+ * as the related row in the entities table as represented by the parent
+ * ElggEntity object.
+ *
+ * @internal Title and description are stored in the objects_entity table.
+ *
+ * @package Elgg.Core
+ * @subpackage DataModel.Object
+ */
+class ElggObject extends ElggEntity {
+ /**
+ * Initialise the attributes array to include the type,
+ * title, and description.
+ */
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['type'] = "object";
+ $this->attributes['title'] = "";
+ $this->attributes['description'] = "";
+ $this->attributes['tables_split'] = 2;
+ }
+
+ /**
+ * Load or create a new ElggObject.
+ *
+ * If no arguments are passed, create a new entity.
+ * If an argument is passed as an int, attempt to load that object by guid.
+ * If an argument is passed as an object, assume that it is as database result object and attempt to load
+ * by $obj->guid.
+ *
+ * @param mixed $guid If an int, load that GUID. If a db row then will attempt to load the rest of the data.
+ * @throws IOException If passed an incorrect guid
+ * @throws InvalidParameterException If passed an Elgg* Entity that isn't an ElggObject
+ */
+ function __construct($guid = null) {
+ $this->initialise_attributes();
+
+ if (!empty($guid)) {
+ // Is $guid is a DB row - either a entity row, or a object table row.
+ if ($guid instanceof stdClass) {
+ // Load the rest
+ if (!$this->load($guid->guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));
+ }
+ }
+
+ // Is $guid is an ElggObject? Use a copy constructor
+ else if ($guid instanceof ElggObject) {
+ elgg_deprecated_notice('This type of usage of the ElggObject constructor was deprecated. Please use the clone method.', 1.7);
+
+ foreach ($guid->attributes as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ // Is this is an ElggEntity but not an ElggObject = ERROR!
+ else if ($guid instanceof ElggEntity) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggObject'));
+ }
+
+ // We assume if we have got this far, $guid is an int
+ else if (is_numeric($guid)) {
+ if (!$this->load($guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));
+ }
+ }
+
+ else {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));
+ }
+ }
+ }
+
+ /**
+ * Loads the full ElggObject when given a guid.
+ *
+ * @param int $guid
+ * @return bool
+ * @throws InvalidClassException
+ */
+ protected function load($guid) {
+ // Test to see if we have the generic stuff
+ if (!parent::load($guid)) {
+ return false;
+ }
+
+ // Check the type
+ if ($this->attributes['type']!='object') {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));
+ }
+
+ // Load missing data
+ $row = get_object_entity_as_row($guid);
+ if (($row) && (!$this->isFullyLoaded())) {
+ // If $row isn't a cached copy then increment the counter
+ $this->attributes['tables_loaded'] ++;
+ }
+
+ // Now put these into the attributes array as core values
+ $objarray = (array) $row;
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+
+ return true;
+ }
+
+ /**
+ * Saves object-specific attributes.
+ *
+ * @internal Object attributes are saved in the objects_entity table.
+ *
+ * @return bool
+ */
+ public function save() {
+ // Save ElggEntity attributes
+ if (!parent::save()) {
+ return false;
+ }
+
+ // Save ElggObject-specific attributes
+ return create_object_entity($this->get('guid'), $this->get('title'), $this->get('description'), $this->get('container_guid'));
+ }
+
+ /**
+ * Return sites that this object is a member of
+ *
+ * Site membership is determined by relationships and not site_guid.d
+ *
+ * @param string $subtype Optionally, the subtype of result we want to limit to
+ * @param int $limit The number of results to return
+ * @param int $offset Any indexing offset
+ * @todo This should be moved to ElggEntity
+ * @todo Unimplemented
+ */
+ function getSites($subtype="", $limit = 10, $offset = 0) {
+ return get_site_objects($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * Add this object to a site
+ *
+ * @param int $site_guid The guid of the site to add it to
+ * @return bool
+ */
+ function addToSite($site_guid) {
+ return add_site_object($this->getGUID(), $site_guid);
+ }
+
+ /**
+ * Set the container for this object.
+ *
+ * @param int $container_guid The ID of the container.
+ * @return bool
+ */
+ function setContainer($container_guid) {
+ $container_guid = (int)$container_guid;
+
+ return $this->set('container_guid', $container_guid);
+ }
+
+ /**
+ * Returns the container GUID of this object.
+ *
+ * @return int
+ */
+ function getContainer() {
+ return $this->get('container_guid');
+ }
+
+ /**
+ * Returns the contain entity for this object.
+ *
+ * @return mixed ElggGroup object or false.
+ */
+ function getContainerEntity() {
+ $result = get_entity($this->getContainer());
+
+ if (($result) && ($result instanceof ElggGroup)) {
+ return $result;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get the collections associated with a object.
+ *
+ * @param string $subtype Optionally, the subtype of result we want to limit to
+ * @param int $limit The number of results to return
+ * @param int $offset Any indexing offset
+ * @return unknown
+ */
+ //public function getCollections($subtype="", $limit = 10, $offset = 0) { get_object_collections($this->getGUID(), $subtype, $limit, $offset); }
+
+ /*
+ * EXPORTABLE INTERFACE
+ */
+
+ /**
+ * Return an array of fields which can be exported.
+ *
+ * @return array
+ */
+ public function getExportableValues() {
+ return array_merge(parent::getExportableValues(), array(
+ 'title',
+ 'description',
+ ));
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Stores site-side plugin settings as private data.\r
- *\r
- * This class is currently a stub, allowing a plugin to\r
- * save settings in an object's private settings for each site.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Plugins.Settings\r
- */\r
-class ElggPlugin extends ElggObject {\r
- protected function initialise_attributes() {\r
- parent::initialise_attributes();\r
-\r
- $this->attributes['subtype'] = "plugin";\r
- }\r
-\r
- public function __construct($guid = null) {\r
- parent::__construct($guid);\r
- }\r
-\r
- /**\r
- * Get a value from private settings.\r
- *\r
- * @param string $name\r
- * @return mixed\r
- */\r
- public function get($name) {\r
- // See if its in our base attribute\r
- if (isset($this->attributes[$name])) {\r
- return $this->attributes[$name];\r
- }\r
-\r
- // No, so see if its in the private data store.\r
- // get_private_setting() returns false if it doesn't exist\r
- $meta = get_private_setting($this->guid, $name);\r
-\r
- if ($meta === false) {\r
- // Can't find it, so return null\r
- return NULL;\r
- }\r
-\r
- return $meta;\r
- }\r
-\r
- /**\r
- * Save a value to private settings.\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- */\r
- public function set($name, $value) {\r
- if (array_key_exists($name, $this->attributes)) {\r
- // Check that we're not trying to change the guid!\r
- if ((array_key_exists('guid', $this->attributes)) && ($name=='guid')) {\r
- return false;\r
- }\r
-\r
- $this->attributes[$name] = $value;\r
- } else {\r
- return set_private_setting($this->guid, $name, $value);\r
- }\r
-\r
- return true;\r
- }\r
+<?php
+/**
+ * Stores site-side plugin settings as private data.
+ *
+ * This class is currently a stub, allowing a plugin to
+ * save settings in an object's private settings for each site.
+ *
+ * @package Elgg.Core
+ * @subpackage Plugins.Settings
+ */
+class ElggPlugin extends ElggObject {
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['subtype'] = "plugin";
+ }
+
+ public function __construct($guid = null) {
+ parent::__construct($guid);
+ }
+
+ /**
+ * Get a value from private settings.
+ *
+ * @param string $name
+ * @return mixed
+ */
+ public function get($name) {
+ // See if its in our base attribute
+ if (isset($this->attributes[$name])) {
+ return $this->attributes[$name];
+ }
+
+ // No, so see if its in the private data store.
+ // get_private_setting() returns false if it doesn't exist
+ $meta = get_private_setting($this->guid, $name);
+
+ if ($meta === false) {
+ // Can't find it, so return null
+ return NULL;
+ }
+
+ return $meta;
+ }
+
+ /**
+ * Save a value to private settings.
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function set($name, $value) {
+ if (array_key_exists($name, $this->attributes)) {
+ // Check that we're not trying to change the guid!
+ if ((array_key_exists('guid', $this->attributes)) && ($name=='guid')) {
+ return false;
+ }
+
+ $this->attributes[$name] = $value;
+ } else {
+ return set_private_setting($this->guid, $name, $value);
+ }
+
+ return true;
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Relationship class.\r
- *\r
- * @package Elgg.Core\r
- * @subpackage Core\r
- */\r
-class ElggRelationship implements\r
- Importable,\r
- Exportable,\r
- Loggable, // Can events related to this object class be logged\r
- Iterator, // Override foreach behaviour\r
- ArrayAccess // Override for array access\r
- {\r
- /**\r
- * This contains the site's main properties (id, etc)\r
- * @var array\r
- */\r
- protected $attributes;\r
-\r
- /**\r
- * Construct a new site object, optionally from a given id value or row.\r
- *\r
- * @param mixed $id\r
- */\r
- function __construct($id = null) {\r
- $this->attributes = array();\r
-\r
- if (!empty($id)) {\r
- if ($id instanceof stdClass) {\r
- $relationship = $id; // Create from db row\r
- } else {\r
- $relationship = get_relationship($id);\r
- }\r
-\r
- if ($relationship) {\r
- $objarray = (array) $relationship;\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Class member get overloading\r
- *\r
- * @param string $name\r
- * @return mixed\r
- */\r
- function __get($name) {\r
- if (isset($this->attributes[$name])) {\r
- return $this->attributes[$name];\r
- }\r
-\r
- return null;\r
- }\r
-\r
- /**\r
- * Class member set overloading\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- * @return mixed\r
- */\r
- function __set($name, $value) {\r
- $this->attributes[$name] = $value;\r
- return true;\r
- }\r
-\r
- /**\r
- * Save the relationship\r
- *\r
- * @return int the relationship id\r
- */\r
- public function save() {\r
- if ($this->id > 0) {\r
- delete_relationship($this->id);\r
- }\r
-\r
- $this->id = add_entity_relationship($this->guid_one, $this->relationship, $this->guid_two);\r
- if (!$this->id) {\r
- throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class()));\r
- }\r
-\r
- return $this->id;\r
- }\r
-\r
- /**\r
- * Delete a given relationship.\r
- */\r
- public function delete() {\r
- return delete_relationship($this->id);\r
- }\r
-\r
- /**\r
- * Get a URL for this relationship.\r
- *\r
- * @return string\r
- */\r
- public function getURL() {\r
- return get_relationship_url($this->id);\r
- }\r
-\r
- // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * Return an array of fields which can be exported.\r
- */\r
- public function getExportableValues() {\r
- return array(\r
- 'id',\r
- 'guid_one',\r
- 'relationship',\r
- 'guid_two'\r
- );\r
- }\r
-\r
- /**\r
- * Export this relationship\r
- *\r
- * @return array\r
- */\r
- public function export() {\r
- $uuid = get_uuid_from_object($this);\r
- $relationship = new ODDRelationship(\r
- guid_to_uuid($this->guid_one),\r
- $this->relationship,\r
- guid_to_uuid($this->guid_two)\r
- );\r
-\r
- $relationship->setAttribute('uuid', $uuid);\r
-\r
- return $relationship;\r
- }\r
-\r
- // IMPORTABLE INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * Import a relationship\r
- *\r
- * @param array $data\r
- * @param int $version\r
- * @return ElggRelationship\r
- * @throws ImportException\r
- */\r
- public function import(ODD $data) {\r
- if (!($element instanceof ODDRelationship)) {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass'));\r
- }\r
-\r
- $uuid_one = $data->getAttribute('uuid1');\r
- $uuid_two = $data->getAttribute('uuid2');\r
-\r
- // See if this entity has already been imported, if so then we need to link to it\r
- $entity1 = get_entity_from_uuid($uuid_one);\r
- $entity2 = get_entity_from_uuid($uuid_two);\r
- if (($entity1) && ($entity2)) {\r
- // Set the item ID\r
- $this->attributes['guid_one'] = $entity1->getGUID();\r
- $this->attributes['guid_two'] = $entity2->getGUID();\r
-\r
- // Map verb to relationship\r
- //$verb = $data->getAttribute('verb');\r
- //$relationship = get_relationship_from_verb($verb);\r
- $relationship = $data->getAttribute('type');\r
-\r
- if ($relationship) {\r
- $this->attributes['relationship'] = $relationship;\r
- // save\r
- $result = $this->save();\r
- if (!$result) {\r
- throw new ImportException(sprintf(elgg_echo('ImportException:ProblemSaving'), get_class()));\r
- }\r
-\r
- return $this;\r
- }\r
- }\r
- }\r
-\r
- // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * Return an identification for the object for storage in the system log.\r
- * This id must be an integer.\r
- *\r
- * @return int\r
- */\r
- public function getSystemLogID() {\r
- return $this->id;\r
- }\r
-\r
- /**\r
- * Return the class name of the object.\r
- */\r
- public function getClassName() {\r
- return get_class($this);\r
- }\r
-\r
- /**\r
- * For a given ID, return the object associated with it.\r
- * This is used by the river functionality primarily.\r
- * This is useful for checking access permissions etc on objects.\r
- */\r
- public function getObjectFromID($id) {\r
- return get_relationship($id);\r
- }\r
-\r
- /**\r
- * Return the GUID of the owner of this object.\r
- */\r
- public function getObjectOwnerGUID() {\r
- return $this->owner_guid;\r
- }\r
-\r
- /**\r
- * Return a type of the object - eg. object, group, user, relationship, metadata, annotation etc\r
- */\r
- public function getType() {\r
- return 'relationship';\r
- }\r
-\r
- /**\r
- * Return a subtype. For metadata & annotations this is the 'name' and for relationship this is the relationship type.\r
- */\r
- public function getSubtype() {\r
- return $this->relationship;\r
- }\r
-\r
- // ITERATOR INTERFACE //////////////////////////////////////////////////////////////\r
- /*\r
- * This lets an entity's attributes be displayed using foreach as a normal array.\r
- * Example: http://www.sitepoint.com/print/php5-standard-library\r
- */\r
-\r
- private $valid = FALSE;\r
-\r
- function rewind() {\r
- $this->valid = (FALSE !== reset($this->attributes));\r
- }\r
-\r
- function current() {\r
- return current($this->attributes);\r
- }\r
-\r
- function key() {\r
- return key($this->attributes);\r
- }\r
-\r
- function next() {\r
- $this->valid = (FALSE !== next($this->attributes));\r
- }\r
-\r
- function valid() {\r
- return $this->valid;\r
- }\r
-\r
- // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////\r
- /*\r
- * This lets an entity's attributes be accessed like an associative array.\r
- * Example: http://www.sitepoint.com/print/php5-standard-library\r
- */\r
-\r
- function offsetSet($key, $value) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- function offsetGet($key) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- return $this->attributes[$key];\r
- }\r
- }\r
-\r
- function offsetUnset($key) {\r
- if ( array_key_exists($key, $this->attributes) ) {\r
- $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects\r
- }\r
- }\r
-\r
- function offsetExists($offset) {\r
- return array_key_exists($offset, $this->attributes);\r
- }\r
+<?php
+/**
+ * Relationship class.
+ *
+ * @package Elgg.Core
+ * @subpackage Core
+ */
+class ElggRelationship implements
+ Importable,
+ Exportable,
+ Loggable, // Can events related to this object class be logged
+ Iterator, // Override foreach behaviour
+ ArrayAccess // Override for array access
+ {
+ /**
+ * This contains the site's main properties (id, etc)
+ * @var array
+ */
+ protected $attributes;
+
+ /**
+ * Construct a new site object, optionally from a given id value or row.
+ *
+ * @param mixed $id
+ */
+ function __construct($id = null) {
+ $this->attributes = array();
+
+ if (!empty($id)) {
+ if ($id instanceof stdClass) {
+ $relationship = $id; // Create from db row
+ } else {
+ $relationship = get_relationship($id);
+ }
+
+ if ($relationship) {
+ $objarray = (array) $relationship;
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ }
+ }
+ }
+
+ /**
+ * Class member get overloading
+ *
+ * @param string $name
+ * @return mixed
+ */
+ function __get($name) {
+ if (isset($this->attributes[$name])) {
+ return $this->attributes[$name];
+ }
+
+ return null;
+ }
+
+ /**
+ * Class member set overloading
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return mixed
+ */
+ function __set($name, $value) {
+ $this->attributes[$name] = $value;
+ return true;
+ }
+
+ /**
+ * Save the relationship
+ *
+ * @return int the relationship id
+ */
+ public function save() {
+ if ($this->id > 0) {
+ delete_relationship($this->id);
+ }
+
+ $this->id = add_entity_relationship($this->guid_one, $this->relationship, $this->guid_two);
+ if (!$this->id) {
+ throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class()));
+ }
+
+ return $this->id;
+ }
+
+ /**
+ * Delete a given relationship.
+ */
+ public function delete() {
+ return delete_relationship($this->id);
+ }
+
+ /**
+ * Get a URL for this relationship.
+ *
+ * @return string
+ */
+ public function getURL() {
+ return get_relationship_url($this->id);
+ }
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues() {
+ return array(
+ 'id',
+ 'guid_one',
+ 'relationship',
+ 'guid_two'
+ );
+ }
+
+ /**
+ * Export this relationship
+ *
+ * @return array
+ */
+ public function export() {
+ $uuid = get_uuid_from_object($this);
+ $relationship = new ODDRelationship(
+ guid_to_uuid($this->guid_one),
+ $this->relationship,
+ guid_to_uuid($this->guid_two)
+ );
+
+ $relationship->setAttribute('uuid', $uuid);
+
+ return $relationship;
+ }
+
+ // IMPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Import a relationship
+ *
+ * @param array $data
+ * @param int $version
+ * @return ElggRelationship
+ * @throws ImportException
+ */
+ public function import(ODD $data) {
+ if (!($element instanceof ODDRelationship)) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass'));
+ }
+
+ $uuid_one = $data->getAttribute('uuid1');
+ $uuid_two = $data->getAttribute('uuid2');
+
+ // See if this entity has already been imported, if so then we need to link to it
+ $entity1 = get_entity_from_uuid($uuid_one);
+ $entity2 = get_entity_from_uuid($uuid_two);
+ if (($entity1) && ($entity2)) {
+ // Set the item ID
+ $this->attributes['guid_one'] = $entity1->getGUID();
+ $this->attributes['guid_two'] = $entity2->getGUID();
+
+ // Map verb to relationship
+ //$verb = $data->getAttribute('verb');
+ //$relationship = get_relationship_from_verb($verb);
+ $relationship = $data->getAttribute('type');
+
+ if ($relationship) {
+ $this->attributes['relationship'] = $relationship;
+ // save
+ $result = $this->save();
+ if (!$result) {
+ throw new ImportException(sprintf(elgg_echo('ImportException:ProblemSaving'), get_class()));
+ }
+
+ return $this;
+ }
+ }
+ }
+
+ // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an identification for the object for storage in the system log.
+ * This id must be an integer.
+ *
+ * @return int
+ */
+ public function getSystemLogID() {
+ return $this->id;
+ }
+
+ /**
+ * Return the class name of the object.
+ */
+ public function getClassName() {
+ return get_class($this);
+ }
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) {
+ return get_relationship($id);
+ }
+
+ /**
+ * Return the GUID of the owner of this object.
+ */
+ public function getObjectOwnerGUID() {
+ return $this->owner_guid;
+ }
+
+ /**
+ * Return a type of the object - eg. object, group, user, relationship, metadata, annotation etc
+ */
+ public function getType() {
+ return 'relationship';
+ }
+
+ /**
+ * Return a subtype. For metadata & annotations this is the 'name' and for relationship this is the relationship type.
+ */
+ public function getSubtype() {
+ return $this->relationship;
+ }
+
+ // ITERATOR INTERFACE //////////////////////////////////////////////////////////////
+ /*
+ * This lets an entity's attributes be displayed using foreach as a normal array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+
+ private $valid = FALSE;
+
+ function rewind() {
+ $this->valid = (FALSE !== reset($this->attributes));
+ }
+
+ function current() {
+ return current($this->attributes);
+ }
+
+ function key() {
+ return key($this->attributes);
+ }
+
+ function next() {
+ $this->valid = (FALSE !== next($this->attributes));
+ }
+
+ function valid() {
+ return $this->valid;
+ }
+
+ // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
+ /*
+ * This lets an entity's attributes be accessed like an associative array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+
+ function offsetSet($key, $value) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ function offsetGet($key) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ return $this->attributes[$key];
+ }
+ }
+
+ function offsetUnset($key) {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects
+ }
+ }
+
+ function offsetExists($offset) {
+ return array_key_exists($offset, $this->attributes);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Magic session class.\r
- * This class is intended to extend the $_SESSION magic variable by providing an API hook\r
- * to plug in other values.\r
- *\r
- * Primarily this is intended to provide a way of supplying "logged in user" details without touching the session\r
- * (which can cause problems when accessed server side).\r
- *\r
- * If a value is present in the session then that value is returned, otherwise a plugin hook 'session:get', '$var' is called,\r
- * where $var is the variable being requested.\r
- *\r
- * Setting values will store variables in the session in the normal way.\r
- *\r
- * LIMITATIONS: You can not access multidimensional arrays\r
- *\r
- * This is EXPERIMENTAL.\r
- */\r
-class ElggSession implements ArrayAccess {\r
- /** Local cache of trigger retrieved variables */\r
- private static $__localcache;\r
-\r
- function __isset($key) {\r
- return $this->offsetExists($key);\r
- }\r
-\r
- /** Set a value, go straight to session. */\r
- function offsetSet($key, $value) {\r
- $_SESSION[$key] = $value;\r
- }\r
-\r
- /**\r
- * Get a variable from either the session, or if its not in the session attempt to get it from\r
- * an api call.\r
- */\r
- function offsetGet($key) {\r
- if (!ElggSession::$__localcache) {\r
- ElggSession::$__localcache = array();\r
- }\r
-\r
- if (isset($_SESSION[$key])) {\r
- return $_SESSION[$key];\r
- }\r
-\r
- if (isset(ElggSession::$__localcache[$key])) {\r
- return ElggSession::$__localcache[$key];\r
- }\r
-\r
- $value = NULL;\r
- $value = trigger_plugin_hook('session:get', $key, NULL, $value);\r
-\r
- ElggSession::$__localcache[$key] = $value;\r
-\r
- return ElggSession::$__localcache[$key];\r
- }\r
-\r
- /**\r
- * Unset a value from the cache and the session.\r
- */\r
- function offsetUnset($key) {\r
- unset(ElggSession::$__localcache[$key]);\r
- unset($_SESSION[$key]);\r
- }\r
-\r
- /**\r
- * Return whether the value is set in either the session or the cache.\r
- */\r
- function offsetExists($offset) {\r
- if (isset(ElggSession::$__localcache[$offset])) {\r
- return true;\r
- }\r
-\r
- if (isset($_SESSION[$offset])) {\r
- return true;\r
- }\r
-\r
- if ($this->offsetGet($offset)){\r
- return true;\r
- }\r
- }\r
-\r
-\r
- // Alias functions\r
- function get($key) {\r
- return $this->offsetGet($key);\r
- }\r
-\r
- function set($key, $value) {\r
- return $this->offsetSet($key, $value);\r
- }\r
-\r
- function del($key) {\r
- return $this->offsetUnset($key);\r
- }\r
+<?php
+/**
+ * Magic session class.
+ * This class is intended to extend the $_SESSION magic variable by providing an API hook
+ * to plug in other values.
+ *
+ * Primarily this is intended to provide a way of supplying "logged in user" details without touching the session
+ * (which can cause problems when accessed server side).
+ *
+ * If a value is present in the session then that value is returned, otherwise a plugin hook 'session:get', '$var' is called,
+ * where $var is the variable being requested.
+ *
+ * Setting values will store variables in the session in the normal way.
+ *
+ * LIMITATIONS: You can not access multidimensional arrays
+ *
+ * This is EXPERIMENTAL.
+ */
+class ElggSession implements ArrayAccess {
+ /** Local cache of trigger retrieved variables */
+ private static $__localcache;
+
+ function __isset($key) {
+ return $this->offsetExists($key);
+ }
+
+ /** Set a value, go straight to session. */
+ function offsetSet($key, $value) {
+ $_SESSION[$key] = $value;
+ }
+
+ /**
+ * Get a variable from either the session, or if its not in the session attempt to get it from
+ * an api call.
+ */
+ function offsetGet($key) {
+ if (!ElggSession::$__localcache) {
+ ElggSession::$__localcache = array();
+ }
+
+ if (isset($_SESSION[$key])) {
+ return $_SESSION[$key];
+ }
+
+ if (isset(ElggSession::$__localcache[$key])) {
+ return ElggSession::$__localcache[$key];
+ }
+
+ $value = NULL;
+ $value = trigger_plugin_hook('session:get', $key, NULL, $value);
+
+ ElggSession::$__localcache[$key] = $value;
+
+ return ElggSession::$__localcache[$key];
+ }
+
+ /**
+ * Unset a value from the cache and the session.
+ */
+ function offsetUnset($key) {
+ unset(ElggSession::$__localcache[$key]);
+ unset($_SESSION[$key]);
+ }
+
+ /**
+ * Return whether the value is set in either the session or the cache.
+ */
+ function offsetExists($offset) {
+ if (isset(ElggSession::$__localcache[$offset])) {
+ return true;
+ }
+
+ if (isset($_SESSION[$offset])) {
+ return true;
+ }
+
+ if ($this->offsetGet($offset)){
+ return true;
+ }
+ }
+
+
+ // Alias functions
+ function get($key) {
+ return $this->offsetGet($key);
+ }
+
+ function set($key, $value) {
+ return $this->offsetSet($key, $value);
+ }
+
+ function del($key) {
+ return $this->offsetUnset($key);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Shared memory cache description.\r
- * Extends ElggCache with functions useful to shared memory style caches (static variables, memcache etc)\r
- */\r
-abstract class ElggSharedMemoryCache extends ElggCache {\r
- /**\r
- * Namespace variable used to keep various bits of the cache\r
- * separate.\r
- *\r
- * @var string\r
- */\r
- private $namespace;\r
-\r
- /**\r
- * Set the namespace of this cache.\r
- * This is useful for cache types (like memcache or static variables) where there is one large\r
- * flat area of memory shared across all instances of the cache.\r
- *\r
- * @param string $namespace\r
- */\r
- public function setNamespace($namespace = "default") {\r
- $this->namespace = $namespace;\r
- }\r
-\r
- /**\r
- * Get the namespace currently defined.\r
- *\r
- * @return string\r
- */\r
- public function getNamespace() {\r
- return $this->namespace;\r
- }\r
+<?php
+/**
+ * Shared memory cache description.
+ * Extends ElggCache with functions useful to shared memory style caches (static variables, memcache etc)
+ */
+abstract class ElggSharedMemoryCache extends ElggCache {
+ /**
+ * Namespace variable used to keep various bits of the cache
+ * separate.
+ *
+ * @var string
+ */
+ private $namespace;
+
+ /**
+ * Set the namespace of this cache.
+ * This is useful for cache types (like memcache or static variables) where there is one large
+ * flat area of memory shared across all instances of the cache.
+ *
+ * @param string $namespace
+ */
+ public function setNamespace($namespace = "default") {
+ $this->namespace = $namespace;
+ }
+
+ /**
+ * Get the namespace currently defined.
+ *
+ * @return string
+ */
+ public function getNamespace() {
+ return $this->namespace;
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * ElggSite\r
- * Representation of a "site" in the system.\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Core\r
- */\r
-class ElggSite extends ElggEntity {\r
- /**\r
- * Initialise the attributes array.\r
- * This is vital to distinguish between metadata and base parameters.\r
- *\r
- * Place your base parameters here.\r
- */\r
- protected function initialise_attributes() {\r
- parent::initialise_attributes();\r
-\r
- $this->attributes['type'] = "site";\r
- $this->attributes['name'] = "";\r
- $this->attributes['description'] = "";\r
- $this->attributes['url'] = "";\r
- $this->attributes['tables_split'] = 2;\r
- }\r
-\r
- /**\r
- * Construct a new site object, optionally from a given id value.\r
- *\r
- * @param mixed $guid If an int, load that GUID.\r
- * If a db row then will attempt to load the rest of the data.\r
- * @throws Exception if there was a problem creating the site.\r
- */\r
- function __construct($guid = null) {\r
- $this->initialise_attributes();\r
-\r
- if (!empty($guid)) {\r
- // Is $guid is a DB row - either a entity row, or a site table row.\r
- if ($guid instanceof stdClass) {\r
- // Load the rest\r
- if (!$this->load($guid->guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));\r
- }\r
- }\r
-\r
- // Is $guid is an ElggSite? Use a copy constructor\r
- else if ($guid instanceof ElggSite) {\r
- elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7);\r
- \r
- foreach ($guid->attributes as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- // Is this is an ElggEntity but not an ElggSite = ERROR!\r
- else if ($guid instanceof ElggEntity) {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggSite'));\r
- }\r
-\r
- // See if this is a URL\r
- else if (strpos($guid, "http") !== false) {\r
- $guid = get_site_by_url($guid);\r
- foreach ($guid->attributes as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- // We assume if we have got this far, $guid is an int\r
- else if (is_numeric($guid)) {\r
- if (!$this->load($guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));\r
- }\r
- }\r
-\r
- else {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Override the load function.\r
- * This function will ensure that all data is loaded (were possible), so\r
- * if only part of the ElggSite is loaded, it'll load the rest.\r
- *\r
- * @param int $guid\r
- */\r
- protected function load($guid) {\r
- // Test to see if we have the generic stuff\r
- if (!parent::load($guid)) {\r
- return false;\r
- }\r
-\r
- // Check the type\r
- if ($this->attributes['type']!='site') {\r
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));\r
- }\r
-\r
- // Load missing data\r
- $row = get_site_entity_as_row($guid);\r
- if (($row) && (!$this->isFullyLoaded())) {\r
- // If $row isn't a cached copy then increment the counter\r
- $this->attributes['tables_loaded'] ++;\r
- }\r
-\r
- // Now put these into the attributes array as core values\r
- $objarray = (array) $row;\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Override the save function.\r
- */\r
- public function save() {\r
- // Save generic stuff\r
- if (!parent::save()) {\r
- return false;\r
- }\r
-\r
- // Now save specific stuff\r
- return create_site_entity($this->get('guid'), $this->get('name'), $this->get('description'), $this->get('url'));\r
- }\r
-\r
- /**\r
- * Delete this site.\r
- */\r
- public function delete() {\r
- global $CONFIG;\r
- if ($CONFIG->site->getGUID() == $this->guid) {\r
- throw new SecurityException('SecurityException:deletedisablecurrentsite');\r
- }\r
-\r
- return parent::delete();\r
- }\r
-\r
- /**\r
- * Disable override to add safety rail.\r
- *\r
- * @param unknown_type $reason\r
- */\r
- public function disable($reason = "") {\r
- global $CONFIG;\r
-\r
- if ($CONFIG->site->getGUID() == $this->guid) {\r
- throw new SecurityException('SecurityException:deletedisablecurrentsite');\r
- }\r
-\r
- return parent::disable($reason);\r
- }\r
-\r
- /**\r
- * Return a list of users using this site.\r
- *\r
- * @param int $limit\r
- * @param int $offset\r
- * @return array of ElggUsers\r
- */\r
- public function getMembers($limit = 10, $offset = 0) {\r
- get_site_members($this->getGUID(), $limit, $offset);\r
- }\r
-\r
- /**\r
- * Add a user to the site.\r
- *\r
- * @param int $user_guid\r
- */\r
- public function addUser($user_guid) {\r
- return add_site_user($this->getGUID(), $user_guid);\r
- }\r
-\r
- /**\r
- * Remove a site user.\r
- *\r
- * @param int $user_guid\r
- */\r
- public function removeUser($user_guid) {\r
- return remove_site_user($this->getGUID(), $user_guid);\r
- }\r
-\r
- /**\r
- * Get an array of member ElggObjects.\r
- *\r
- * @param string $subtype\r
- * @param int $limit\r
- * @param int $offset\r
- */\r
- public function getObjects($subtype="", $limit = 10, $offset = 0) {\r
- get_site_objects($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * Add an object to the site.\r
- *\r
- * @param int $user_id\r
- */\r
- public function addObject($object_guid) {\r
- return add_site_object($this->getGUID(), $object_guid);\r
- }\r
-\r
- /**\r
- * Remove a site user.\r
- *\r
- * @param int $user_id\r
- */\r
- public function removeObject($object_guid) {\r
- return remove_site_object($this->getGUID(), $object_guid);\r
- }\r
-\r
- /**\r
- * Get the collections associated with a site.\r
- *\r
- * @param string $type\r
- * @param int $limit\r
- * @param int $offset\r
- * @return unknown\r
- */\r
- public function getCollections($subtype="", $limit = 10, $offset = 0) {\r
- get_site_collections($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * Return an array of fields which can be exported.\r
- */\r
- public function getExportableValues() {\r
- return array_merge(parent::getExportableValues(), array(\r
- 'name',\r
- 'description',\r
- 'url',\r
- ));\r
- }\r
- \r
- public function check_walled_garden() {\r
- global $CONFIG;\r
- \r
- if ($CONFIG->walled_garden && !isloggedin()) {\r
- // hook into the index system call at the highest priority\r
- register_plugin_hook('index', 'system', 'elgg_walled_garden_index', 1);\r
- \r
- if (!$this->is_public_page()) {\r
- register_error(elgg_echo('loggedinrequired'));\r
- forward();\r
- }\r
- }\r
- }\r
- \r
- public function is_public_page($url='') {\r
- global $CONFIG;\r
- \r
- if (empty($url)) {\r
- $url = current_page_url();\r
- \r
- // do not check against URL queries\r
- if ($pos = strpos($url, '?')) {\r
- $url = substr($url, 0, $pos);\r
- }\r
- }\r
- \r
- // always allow index page\r
- if ($url == $CONFIG->url) {\r
- return TRUE;\r
- }\r
- \r
- // default public pages\r
- $defaults = array(\r
- 'action/login',\r
- 'pg/register',\r
- 'action/register',\r
- 'account/forgotten_password\.php',\r
- 'action/user/requestnewpassword',\r
- 'pg/resetpassword',\r
- 'upgrade\.php',\r
- 'xml-rpc\.php',\r
- 'mt/mt-xmlrpc\.cgi',\r
- '_css/css\.css',\r
- '_css/js\.php',\r
- );\r
- \r
- // include a hook for plugin authors to include public pages\r
- $plugins = trigger_plugin_hook('public_pages', 'walled_garden', NULL, array());\r
- \r
- // lookup admin-specific public pages\r
- \r
- // allow public pages\r
- foreach (array_merge($defaults, $plugins) as $public) {\r
- $pattern = "`^{$CONFIG->url}$public/*$`i";\r
- if (preg_match($pattern, $url)) {\r
- return TRUE;\r
- }\r
- }\r
- \r
- // non-public page\r
- return FALSE;\r
- }\r
-}\r
+<?php
+/**
+ * ElggSite
+ * Representation of a "site" in the system.
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Core
+ */
+class ElggSite extends ElggEntity {
+ /**
+ * Initialise the attributes array.
+ * This is vital to distinguish between metadata and base parameters.
+ *
+ * Place your base parameters here.
+ */
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['type'] = "site";
+ $this->attributes['name'] = "";
+ $this->attributes['description'] = "";
+ $this->attributes['url'] = "";
+ $this->attributes['tables_split'] = 2;
+ }
+
+ /**
+ * Construct a new site object, optionally from a given id value.
+ *
+ * @param mixed $guid If an int, load that GUID.
+ * If a db row then will attempt to load the rest of the data.
+ * @throws Exception if there was a problem creating the site.
+ */
+ function __construct($guid = null) {
+ $this->initialise_attributes();
+
+ if (!empty($guid)) {
+ // Is $guid is a DB row - either a entity row, or a site table row.
+ if ($guid instanceof stdClass) {
+ // Load the rest
+ if (!$this->load($guid->guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));
+ }
+ }
+
+ // Is $guid is an ElggSite? Use a copy constructor
+ else if ($guid instanceof ElggSite) {
+ elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7);
+
+ foreach ($guid->attributes as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ // Is this is an ElggEntity but not an ElggSite = ERROR!
+ else if ($guid instanceof ElggEntity) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggSite'));
+ }
+
+ // See if this is a URL
+ else if (strpos($guid, "http") !== false) {
+ $guid = get_site_by_url($guid);
+ foreach ($guid->attributes as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ // We assume if we have got this far, $guid is an int
+ else if (is_numeric($guid)) {
+ if (!$this->load($guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));
+ }
+ }
+
+ else {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));
+ }
+ }
+ }
+
+ /**
+ * Override the load function.
+ * This function will ensure that all data is loaded (were possible), so
+ * if only part of the ElggSite is loaded, it'll load the rest.
+ *
+ * @param int $guid
+ */
+ protected function load($guid) {
+ // Test to see if we have the generic stuff
+ if (!parent::load($guid)) {
+ return false;
+ }
+
+ // Check the type
+ if ($this->attributes['type']!='site') {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));
+ }
+
+ // Load missing data
+ $row = get_site_entity_as_row($guid);
+ if (($row) && (!$this->isFullyLoaded())) {
+ // If $row isn't a cached copy then increment the counter
+ $this->attributes['tables_loaded'] ++;
+ }
+
+ // Now put these into the attributes array as core values
+ $objarray = (array) $row;
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+
+ return true;
+ }
+
+ /**
+ * Override the save function.
+ */
+ public function save() {
+ // Save generic stuff
+ if (!parent::save()) {
+ return false;
+ }
+
+ // Now save specific stuff
+ return create_site_entity($this->get('guid'), $this->get('name'), $this->get('description'), $this->get('url'));
+ }
+
+ /**
+ * Delete this site.
+ */
+ public function delete() {
+ global $CONFIG;
+ if ($CONFIG->site->getGUID() == $this->guid) {
+ throw new SecurityException('SecurityException:deletedisablecurrentsite');
+ }
+
+ return parent::delete();
+ }
+
+ /**
+ * Disable override to add safety rail.
+ *
+ * @param unknown_type $reason
+ */
+ public function disable($reason = "") {
+ global $CONFIG;
+
+ if ($CONFIG->site->getGUID() == $this->guid) {
+ throw new SecurityException('SecurityException:deletedisablecurrentsite');
+ }
+
+ return parent::disable($reason);
+ }
+
+ /**
+ * Return a list of users using this site.
+ *
+ * @param int $limit
+ * @param int $offset
+ * @return array of ElggUsers
+ */
+ public function getMembers($limit = 10, $offset = 0) {
+ get_site_members($this->getGUID(), $limit, $offset);
+ }
+
+ /**
+ * Add a user to the site.
+ *
+ * @param int $user_guid
+ */
+ public function addUser($user_guid) {
+ return add_site_user($this->getGUID(), $user_guid);
+ }
+
+ /**
+ * Remove a site user.
+ *
+ * @param int $user_guid
+ */
+ public function removeUser($user_guid) {
+ return remove_site_user($this->getGUID(), $user_guid);
+ }
+
+ /**
+ * Get an array of member ElggObjects.
+ *
+ * @param string $subtype
+ * @param int $limit
+ * @param int $offset
+ */
+ public function getObjects($subtype="", $limit = 10, $offset = 0) {
+ get_site_objects($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * Add an object to the site.
+ *
+ * @param int $user_id
+ */
+ public function addObject($object_guid) {
+ return add_site_object($this->getGUID(), $object_guid);
+ }
+
+ /**
+ * Remove a site user.
+ *
+ * @param int $user_id
+ */
+ public function removeObject($object_guid) {
+ return remove_site_object($this->getGUID(), $object_guid);
+ }
+
+ /**
+ * Get the collections associated with a site.
+ *
+ * @param string $type
+ * @param int $limit
+ * @param int $offset
+ * @return unknown
+ */
+ public function getCollections($subtype="", $limit = 10, $offset = 0) {
+ get_site_collections($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues() {
+ return array_merge(parent::getExportableValues(), array(
+ 'name',
+ 'description',
+ 'url',
+ ));
+ }
+
+ public function check_walled_garden() {
+ global $CONFIG;
+
+ if ($CONFIG->walled_garden && !isloggedin()) {
+ // hook into the index system call at the highest priority
+ register_plugin_hook('index', 'system', 'elgg_walled_garden_index', 1);
+
+ if (!$this->is_public_page()) {
+ register_error(elgg_echo('loggedinrequired'));
+ forward();
+ }
+ }
+ }
+
+ public function is_public_page($url='') {
+ global $CONFIG;
+
+ if (empty($url)) {
+ $url = current_page_url();
+
+ // do not check against URL queries
+ if ($pos = strpos($url, '?')) {
+ $url = substr($url, 0, $pos);
+ }
+ }
+
+ // always allow index page
+ if ($url == $CONFIG->url) {
+ return TRUE;
+ }
+
+ // default public pages
+ $defaults = array(
+ 'action/login',
+ 'pg/register',
+ 'action/register',
+ 'account/forgotten_password\.php',
+ 'action/user/requestnewpassword',
+ 'pg/resetpassword',
+ 'upgrade\.php',
+ 'xml-rpc\.php',
+ 'mt/mt-xmlrpc\.cgi',
+ '_css/css\.css',
+ '_css/js\.php',
+ );
+
+ // include a hook for plugin authors to include public pages
+ $plugins = trigger_plugin_hook('public_pages', 'walled_garden', NULL, array());
+
+ // lookup admin-specific public pages
+
+ // allow public pages
+ foreach (array_merge($defaults, $plugins) as $public) {
+ $pattern = "`^{$CONFIG->url}$public/*$`i";
+ if (preg_match($pattern, $url)) {
+ return TRUE;
+ }
+ }
+
+ // non-public page
+ return FALSE;
+ }
+}
-<?php\r
-/**\r
- * ElggStaticVariableCache\r
- * Dummy cache which stores values in a static array. Using this makes future replacements to other caching back\r
- * ends (eg memcache) much easier.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage API\r
- */\r
-class ElggStaticVariableCache extends ElggSharedMemoryCache {\r
- /**\r
- * The cache.\r
- *\r
- * @var unknown_type\r
- */\r
- private static $__cache;\r
-\r
- /**\r
- * Create the variable cache.\r
- *\r
- * This function creates a variable cache in a static variable in memory, optionally with a given namespace (to avoid overlap).\r
- *\r
- * @param string $namespace The namespace for this cache to write to - note, namespaces of the same name are shared!\r
- */\r
- function __construct($namespace = 'default') {\r
- $this->setNamespace($namespace);\r
- $this->clear();\r
- }\r
-\r
- public function save($key, $data) {\r
- $namespace = $this->getNamespace();\r
-\r
- ElggStaticVariableCache::$__cache[$namespace][$key] = $data;\r
-\r
- return true;\r
- }\r
-\r
- public function load($key, $offset = 0, $limit = null) {\r
- $namespace = $this->getNamespace();\r
-\r
- if (isset(ElggStaticVariableCache::$__cache[$namespace][$key])) {\r
- return ElggStaticVariableCache::$__cache[$namespace][$key];\r
- }\r
-\r
- return false;\r
- }\r
-\r
- public function delete($key) {\r
- $namespace = $this->getNamespace();\r
-\r
- unset(ElggStaticVariableCache::$__cache[$namespace][$key]);\r
-\r
- return true;\r
- }\r
-\r
- public function clear() {\r
- $namespace = $this->getNamespace();\r
-\r
- if (!isset(ElggStaticVariableCache::$__cache)) {\r
- ElggStaticVariableCache::$__cache = array();\r
- }\r
-\r
- ElggStaticVariableCache::$__cache[$namespace] = array();\r
- }\r
+<?php
+/**
+ * ElggStaticVariableCache
+ * Dummy cache which stores values in a static array. Using this makes future replacements to other caching back
+ * ends (eg memcache) much easier.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage API
+ */
+class ElggStaticVariableCache extends ElggSharedMemoryCache {
+ /**
+ * The cache.
+ *
+ * @var unknown_type
+ */
+ private static $__cache;
+
+ /**
+ * Create the variable cache.
+ *
+ * This function creates a variable cache in a static variable in memory, optionally with a given namespace (to avoid overlap).
+ *
+ * @param string $namespace The namespace for this cache to write to - note, namespaces of the same name are shared!
+ */
+ function __construct($namespace = 'default') {
+ $this->setNamespace($namespace);
+ $this->clear();
+ }
+
+ public function save($key, $data) {
+ $namespace = $this->getNamespace();
+
+ ElggStaticVariableCache::$__cache[$namespace][$key] = $data;
+
+ return true;
+ }
+
+ public function load($key, $offset = 0, $limit = null) {
+ $namespace = $this->getNamespace();
+
+ if (isset(ElggStaticVariableCache::$__cache[$namespace][$key])) {
+ return ElggStaticVariableCache::$__cache[$namespace][$key];
+ }
+
+ return false;
+ }
+
+ public function delete($key) {
+ $namespace = $this->getNamespace();
+
+ unset(ElggStaticVariableCache::$__cache[$namespace][$key]);
+
+ return true;
+ }
+
+ public function clear() {
+ $namespace = $this->getNamespace();
+
+ if (!isset(ElggStaticVariableCache::$__cache)) {
+ ElggStaticVariableCache::$__cache = array();
+ }
+
+ ElggStaticVariableCache::$__cache[$namespace] = array();
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * ElggUser\r
- *\r
- * Representation of a "user" in the system.\r
- *\r
- * @package Elgg\r
- * @subpackage Core\r
- */\r
-class ElggUser extends ElggEntity\r
- implements Friendable {\r
- /**\r
- * Initialise the attributes array.\r
- * This is vital to distinguish between metadata and base parameters.\r
- *\r
- * Place your base parameters here.\r
- */\r
- protected function initialise_attributes() {\r
- parent::initialise_attributes();\r
-\r
- $this->attributes['type'] = "user";\r
- $this->attributes['name'] = "";\r
- $this->attributes['username'] = "";\r
- $this->attributes['password'] = "";\r
- $this->attributes['salt'] = "";\r
- $this->attributes['email'] = "";\r
- $this->attributes['language'] = "";\r
- $this->attributes['code'] = "";\r
- $this->attributes['banned'] = "no";\r
- $this->attributes['admin'] = 'no';\r
- $this->attributes['tables_split'] = 2;\r
- }\r
-\r
- /**\r
- * Construct a new user entity, optionally from a given id value.\r
- *\r
- * @param mixed $guid If an int, load that GUID.\r
- * If a db row then will attempt to load the rest of the data.\r
- * @throws Exception if there was a problem creating the user.\r
- */\r
- function __construct($guid = null) {\r
- $this->initialise_attributes();\r
-\r
- if (!empty($guid)) {\r
- // Is $guid is a DB row - either a entity row, or a user table row.\r
- if ($guid instanceof stdClass) {\r
- // Load the rest\r
- if (!$this->load($guid->guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));\r
- }\r
- }\r
-\r
- // See if this is a username\r
- else if (is_string($guid)) {\r
- $guid = get_user_by_username($guid);\r
- foreach ($guid->attributes as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- // Is $guid is an ElggUser? Use a copy constructor\r
- else if ($guid instanceof ElggUser) {\r
- elgg_deprecated_notice('This type of usage of the ElggUser constructor was deprecated. Please use the clone method.', 1.7);\r
-\r
- foreach ($guid->attributes as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
- }\r
-\r
- // Is this is an ElggEntity but not an ElggUser = ERROR!\r
- else if ($guid instanceof ElggEntity) {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggUser'));\r
- }\r
-\r
- // We assume if we have got this far, $guid is an int\r
- else if (is_numeric($guid)) {\r
- if (!$this->load($guid)) {\r
- throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));\r
- }\r
- }\r
-\r
- else {\r
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Override the load function.\r
- * This function will ensure that all data is loaded (were possible), so\r
- * if only part of the ElggUser is loaded, it'll load the rest.\r
- *\r
- * @param int $guid\r
- * @return true|false\r
- */\r
- protected function load($guid) {\r
- // Test to see if we have the generic stuff\r
- if (!parent::load($guid)) {\r
- return false;\r
- }\r
-\r
- // Check the type\r
- if ($this->attributes['type']!='user') {\r
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));\r
- }\r
-\r
- // Load missing data\r
- $row = get_user_entity_as_row($guid);\r
- if (($row) && (!$this->isFullyLoaded())) {\r
- // If $row isn't a cached copy then increment the counter\r
- $this->attributes['tables_loaded'] ++;\r
- }\r
-\r
- // Now put these into the attributes array as core values\r
- $objarray = (array) $row;\r
- foreach($objarray as $key => $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Saves this user to the database.\r
- * @return true|false\r
- */\r
- public function save() {\r
- // Save generic stuff\r
- if (!parent::save()) {\r
- return false;\r
- }\r
-\r
- // Now save specific stuff\r
- return create_user_entity($this->get('guid'), $this->get('name'), $this->get('username'), $this->get('password'), $this->get('salt'), $this->get('email'), $this->get('language'), $this->get('code'));\r
- }\r
-\r
- /**\r
- * User specific override of the entity delete method.\r
- *\r
- * @return bool\r
- */\r
- public function delete() {\r
- global $USERNAME_TO_GUID_MAP_CACHE, $CODE_TO_GUID_MAP_CACHE;\r
-\r
- // clear cache\r
- if (isset($USERNAME_TO_GUID_MAP_CACHE[$this->username])) {\r
- unset($USERNAME_TO_GUID_MAP_CACHE[$this->username]);\r
- }\r
- if (isset($CODE_TO_GUID_MAP_CACHE[$this->code])) {\r
- unset($CODE_TO_GUID_MAP_CACHE[$this->code]);\r
- }\r
-\r
- // Delete owned data\r
- clear_annotations_by_owner($this->guid);\r
- clear_metadata_by_owner($this->guid);\r
- clear_user_files($this);\r
-\r
- // Delete entity\r
- return parent::delete();\r
- }\r
-\r
- /**\r
- * Ban this user.\r
- *\r
- * @param string $reason Optional reason\r
- */\r
- public function ban($reason = "") {\r
- return ban_user($this->guid, $reason);\r
- }\r
-\r
- /**\r
- * Unban this user.\r
- */\r
- public function unban() {\r
- return unban_user($this->guid);\r
- }\r
-\r
- /**\r
- * Is this user banned or not?\r
- *\r
- * @return bool\r
- */\r
- public function isBanned() {\r
- return $this->banned == 'yes';\r
- }\r
-\r
- /**\r
- * Is this user admin?\r
- *\r
- * @return bool\r
- */\r
- public function isAdmin() {\r
-\r
- // for backward compatibility we need to pull this directly\r
- // from the attributes instead of using the magic methods.\r
- // this can be removed in 1.9\r
- // return $this->admin == 'yes';\r
- return $this->attributes['admin'] == 'yes';\r
- }\r
-\r
- /**\r
- * Make the user an admin\r
- *\r
- * @return bool\r
- */\r
- public function makeAdmin() {\r
- if (make_user_admin($this->guid)) {\r
- $this->attributes['admin'] = 'yes';\r
- return TRUE;\r
- }\r
- return FALSE;\r
- }\r
-\r
- /**\r
- * Remove the admin flag for user\r
- *\r
- * @return bool\r
- */\r
- public function removeAdmin() {\r
- if (remove_user_admin($this->guid)) {\r
- $this->attributes['admin'] = 'no';\r
- return TRUE;\r
- }\r
- return FALSE;\r
- }\r
-\r
- /**\r
- * Get sites that this user is a member of\r
- *\r
- * @param string $subtype Optionally, the subtype of result we want to limit to\r
- * @param int $limit The number of results to return\r
- * @param int $offset Any indexing offset\r
- */\r
- function getSites($subtype="", $limit = 10, $offset = 0) {\r
- // return get_site_users($this->getGUID(), $subtype, $limit, $offset);\r
- return get_user_sites($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * Add this user to a particular site\r
- *\r
- * @param int $site_guid The guid of the site to add it to\r
- * @return true|false\r
- */\r
- function addToSite($site_guid) {\r
- // return add_site_user($this->getGUID(), $site_guid);\r
- return add_site_user($site_guid, $this->getGUID());\r
- }\r
-\r
- /**\r
- * Remove this user from a particular site\r
- *\r
- * @param int $site_guid The guid of the site to remove it from\r
- * @return true|false\r
- */\r
- function removeFromSite($site_guid) {\r
- //return remove_site_user($this->getGUID(), $site_guid);\r
- return remove_site_user($site_guid, $this->getGUID());\r
- }\r
-\r
- /**\r
- * Adds a user to this user's friends list\r
- *\r
- * @param int $friend_guid The GUID of the user to add\r
- * @return true|false Depending on success\r
- */\r
- function addFriend($friend_guid) {\r
- return user_add_friend($this->getGUID(), $friend_guid);\r
- }\r
-\r
- /**\r
- * Removes a user from this user's friends list\r
- *\r
- * @param int $friend_guid The GUID of the user to remove\r
- * @return true|false Depending on success\r
- */\r
- function removeFriend($friend_guid) {\r
- return user_remove_friend($this->getGUID(), $friend_guid);\r
- }\r
-\r
- /**\r
- * Determines whether or not this user is a friend of the currently logged in user\r
- *\r
- * @return true|false\r
- */\r
- function isFriend() {\r
- return user_is_friend(get_loggedin_userid(), $this->getGUID());\r
- }\r
-\r
- /**\r
- * Determines whether this user is friends with another user\r
- *\r
- * @param int $user_guid The GUID of the user to check is on this user's friends list\r
- * @return true|false\r
- */\r
- function isFriendsWith($user_guid) {\r
- return user_is_friend($this->getGUID(), $user_guid);\r
- }\r
-\r
- /**\r
- * Determines whether or not this user is on another user's friends list\r
- *\r
- * @param int $user_guid The GUID of the user to check against\r
- * @return true|false\r
- */\r
- function isFriendOf($user_guid) {\r
- return user_is_friend($user_guid, $this->getGUID());\r
- }\r
-\r
- /**\r
- * Retrieves a list of this user's friends\r
- *\r
- * @param string $subtype Optionally, the subtype of user to filter to (leave blank for all)\r
- * @param int $limit The number of users to retrieve\r
- * @param int $offset Indexing offset, if any\r
- * @return array|false Array of ElggUsers, or false, depending on success\r
- */\r
- function getFriends($subtype = "", $limit = 10, $offset = 0) {\r
- return get_user_friends($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * Retrieves a list of people who have made this user a friend\r
- *\r
- * @param string $subtype Optionally, the subtype of user to filter to (leave blank for all)\r
- * @param int $limit The number of users to retrieve\r
- * @param int $offset Indexing offset, if any\r
- * @return array|false Array of ElggUsers, or false, depending on success\r
- */\r
- function getFriendsOf($subtype = "", $limit = 10, $offset = 0) {\r
- return get_user_friends_of($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * Get an array of ElggObjects owned by this user.\r
- *\r
- * @param string $subtype The subtype of the objects, if any\r
- * @param int $limit Number of results to return\r
- * @param int $offset Any indexing offset\r
- */\r
- public function getObjects($subtype="", $limit = 10, $offset = 0) {\r
- return get_user_objects($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * Get an array of ElggObjects owned by this user's friends.\r
- *\r
- * @param string $subtype The subtype of the objects, if any\r
- * @param int $limit Number of results to return\r
- * @param int $offset Any indexing offset\r
- */\r
- public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0) {\r
- return get_user_friends_objects($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * Counts the number of ElggObjects owned by this user\r
- *\r
- * @param string $subtype The subtypes of the objects, if any\r
- * @return int The number of ElggObjects\r
- */\r
- public function countObjects($subtype = "") {\r
- return count_user_objects($this->getGUID(), $subtype);\r
- }\r
-\r
- /**\r
- * Get the collections associated with a user.\r
- *\r
- * @param string $subtype Optionally, the subtype of result we want to limit to\r
- * @param int $limit The number of results to return\r
- * @param int $offset Any indexing offset\r
- * @return unknown\r
- */\r
- public function getCollections($subtype="", $limit = 10, $offset = 0) {\r
- return get_user_collections($this->getGUID(), $subtype, $limit, $offset);\r
- }\r
-\r
- /**\r
- * If a user's owner is blank, return its own GUID as the owner\r
- *\r
- * @return int User GUID\r
- */\r
- function getOwner() {\r
- if ($this->owner_guid == 0) {\r
- return $this->getGUID();\r
- }\r
-\r
- return $this->owner_guid;\r
- }\r
-\r
- // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////\r
-\r
- /**\r
- * Return an array of fields which can be exported.\r
- */\r
- public function getExportableValues() {\r
- return array_merge(parent::getExportableValues(), array(\r
- 'name',\r
- 'username',\r
- 'language',\r
- ));\r
- }\r
-\r
- // backward compatibility with admin flag\r
- // remove for 1.9\r
- public function __set($name, $value) {\r
- if ($name == 'admin' || $name == 'siteadmin') {\r
- elgg_deprecated_notice('The admin/siteadmin metadata are not longer used. Use ElggUser->makeAdmin() and ElggUser->removeAdmin().', '1.7.1');\r
-\r
- if ($value == 'yes' || $value == '1') {\r
- $this->makeAdmin();\r
- } else {\r
- $this->removeAdmin();\r
- }\r
- }\r
- return parent::__set($name, $value);\r
- }\r
-\r
- public function __get($name) {\r
- if ($name == 'admin' || $name == 'siteadmin') {\r
- elgg_deprecated_notice('The admin/siteadmin metadata are not longer used. Use ElggUser->isAdmin().', '1.7.1');\r
- return $this->isAdmin();\r
- }\r
-\r
- return parent::__get($name);\r
- }\r
-}\r
+<?php
+/**
+ * ElggUser
+ *
+ * Representation of a "user" in the system.
+ *
+ * @package Elgg
+ * @subpackage Core
+ */
+class ElggUser extends ElggEntity
+ implements Friendable {
+ /**
+ * Initialise the attributes array.
+ * This is vital to distinguish between metadata and base parameters.
+ *
+ * Place your base parameters here.
+ */
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['type'] = "user";
+ $this->attributes['name'] = "";
+ $this->attributes['username'] = "";
+ $this->attributes['password'] = "";
+ $this->attributes['salt'] = "";
+ $this->attributes['email'] = "";
+ $this->attributes['language'] = "";
+ $this->attributes['code'] = "";
+ $this->attributes['banned'] = "no";
+ $this->attributes['admin'] = 'no';
+ $this->attributes['tables_split'] = 2;
+ }
+
+ /**
+ * Construct a new user entity, optionally from a given id value.
+ *
+ * @param mixed $guid If an int, load that GUID.
+ * If a db row then will attempt to load the rest of the data.
+ * @throws Exception if there was a problem creating the user.
+ */
+ function __construct($guid = null) {
+ $this->initialise_attributes();
+
+ if (!empty($guid)) {
+ // Is $guid is a DB row - either a entity row, or a user table row.
+ if ($guid instanceof stdClass) {
+ // Load the rest
+ if (!$this->load($guid->guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid));
+ }
+ }
+
+ // See if this is a username
+ else if (is_string($guid)) {
+ $guid = get_user_by_username($guid);
+ foreach ($guid->attributes as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ // Is $guid is an ElggUser? Use a copy constructor
+ else if ($guid instanceof ElggUser) {
+ elgg_deprecated_notice('This type of usage of the ElggUser constructor was deprecated. Please use the clone method.', 1.7);
+
+ foreach ($guid->attributes as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ // Is this is an ElggEntity but not an ElggUser = ERROR!
+ else if ($guid instanceof ElggEntity) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggUser'));
+ }
+
+ // We assume if we have got this far, $guid is an int
+ else if (is_numeric($guid)) {
+ if (!$this->load($guid)) {
+ throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));
+ }
+ }
+
+ else {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));
+ }
+ }
+ }
+
+ /**
+ * Override the load function.
+ * This function will ensure that all data is loaded (were possible), so
+ * if only part of the ElggUser is loaded, it'll load the rest.
+ *
+ * @param int $guid
+ * @return true|false
+ */
+ protected function load($guid) {
+ // Test to see if we have the generic stuff
+ if (!parent::load($guid)) {
+ return false;
+ }
+
+ // Check the type
+ if ($this->attributes['type']!='user') {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));
+ }
+
+ // Load missing data
+ $row = get_user_entity_as_row($guid);
+ if (($row) && (!$this->isFullyLoaded())) {
+ // If $row isn't a cached copy then increment the counter
+ $this->attributes['tables_loaded'] ++;
+ }
+
+ // Now put these into the attributes array as core values
+ $objarray = (array) $row;
+ foreach($objarray as $key => $value) {
+ $this->attributes[$key] = $value;
+ }
+
+ return true;
+ }
+
+ /**
+ * Saves this user to the database.
+ * @return true|false
+ */
+ public function save() {
+ // Save generic stuff
+ if (!parent::save()) {
+ return false;
+ }
+
+ // Now save specific stuff
+ return create_user_entity($this->get('guid'), $this->get('name'), $this->get('username'), $this->get('password'), $this->get('salt'), $this->get('email'), $this->get('language'), $this->get('code'));
+ }
+
+ /**
+ * User specific override of the entity delete method.
+ *
+ * @return bool
+ */
+ public function delete() {
+ global $USERNAME_TO_GUID_MAP_CACHE, $CODE_TO_GUID_MAP_CACHE;
+
+ // clear cache
+ if (isset($USERNAME_TO_GUID_MAP_CACHE[$this->username])) {
+ unset($USERNAME_TO_GUID_MAP_CACHE[$this->username]);
+ }
+ if (isset($CODE_TO_GUID_MAP_CACHE[$this->code])) {
+ unset($CODE_TO_GUID_MAP_CACHE[$this->code]);
+ }
+
+ // Delete owned data
+ clear_annotations_by_owner($this->guid);
+ clear_metadata_by_owner($this->guid);
+ clear_user_files($this);
+
+ // Delete entity
+ return parent::delete();
+ }
+
+ /**
+ * Ban this user.
+ *
+ * @param string $reason Optional reason
+ */
+ public function ban($reason = "") {
+ return ban_user($this->guid, $reason);
+ }
+
+ /**
+ * Unban this user.
+ */
+ public function unban() {
+ return unban_user($this->guid);
+ }
+
+ /**
+ * Is this user banned or not?
+ *
+ * @return bool
+ */
+ public function isBanned() {
+ return $this->banned == 'yes';
+ }
+
+ /**
+ * Is this user admin?
+ *
+ * @return bool
+ */
+ public function isAdmin() {
+
+ // for backward compatibility we need to pull this directly
+ // from the attributes instead of using the magic methods.
+ // this can be removed in 1.9
+ // return $this->admin == 'yes';
+ return $this->attributes['admin'] == 'yes';
+ }
+
+ /**
+ * Make the user an admin
+ *
+ * @return bool
+ */
+ public function makeAdmin() {
+ if (make_user_admin($this->guid)) {
+ $this->attributes['admin'] = 'yes';
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Remove the admin flag for user
+ *
+ * @return bool
+ */
+ public function removeAdmin() {
+ if (remove_user_admin($this->guid)) {
+ $this->attributes['admin'] = 'no';
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Get sites that this user is a member of
+ *
+ * @param string $subtype Optionally, the subtype of result we want to limit to
+ * @param int $limit The number of results to return
+ * @param int $offset Any indexing offset
+ */
+ function getSites($subtype="", $limit = 10, $offset = 0) {
+ // return get_site_users($this->getGUID(), $subtype, $limit, $offset);
+ return get_user_sites($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * Add this user to a particular site
+ *
+ * @param int $site_guid The guid of the site to add it to
+ * @return true|false
+ */
+ function addToSite($site_guid) {
+ // return add_site_user($this->getGUID(), $site_guid);
+ return add_site_user($site_guid, $this->getGUID());
+ }
+
+ /**
+ * Remove this user from a particular site
+ *
+ * @param int $site_guid The guid of the site to remove it from
+ * @return true|false
+ */
+ function removeFromSite($site_guid) {
+ //return remove_site_user($this->getGUID(), $site_guid);
+ return remove_site_user($site_guid, $this->getGUID());
+ }
+
+ /**
+ * Adds a user to this user's friends list
+ *
+ * @param int $friend_guid The GUID of the user to add
+ * @return true|false Depending on success
+ */
+ function addFriend($friend_guid) {
+ return user_add_friend($this->getGUID(), $friend_guid);
+ }
+
+ /**
+ * Removes a user from this user's friends list
+ *
+ * @param int $friend_guid The GUID of the user to remove
+ * @return true|false Depending on success
+ */
+ function removeFriend($friend_guid) {
+ return user_remove_friend($this->getGUID(), $friend_guid);
+ }
+
+ /**
+ * Determines whether or not this user is a friend of the currently logged in user
+ *
+ * @return true|false
+ */
+ function isFriend() {
+ return user_is_friend(get_loggedin_userid(), $this->getGUID());
+ }
+
+ /**
+ * Determines whether this user is friends with another user
+ *
+ * @param int $user_guid The GUID of the user to check is on this user's friends list
+ * @return true|false
+ */
+ function isFriendsWith($user_guid) {
+ return user_is_friend($this->getGUID(), $user_guid);
+ }
+
+ /**
+ * Determines whether or not this user is on another user's friends list
+ *
+ * @param int $user_guid The GUID of the user to check against
+ * @return true|false
+ */
+ function isFriendOf($user_guid) {
+ return user_is_friend($user_guid, $this->getGUID());
+ }
+
+ /**
+ * Retrieves a list of this user's friends
+ *
+ * @param string $subtype Optionally, the subtype of user to filter to (leave blank for all)
+ * @param int $limit The number of users to retrieve
+ * @param int $offset Indexing offset, if any
+ * @return array|false Array of ElggUsers, or false, depending on success
+ */
+ function getFriends($subtype = "", $limit = 10, $offset = 0) {
+ return get_user_friends($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * Retrieves a list of people who have made this user a friend
+ *
+ * @param string $subtype Optionally, the subtype of user to filter to (leave blank for all)
+ * @param int $limit The number of users to retrieve
+ * @param int $offset Indexing offset, if any
+ * @return array|false Array of ElggUsers, or false, depending on success
+ */
+ function getFriendsOf($subtype = "", $limit = 10, $offset = 0) {
+ return get_user_friends_of($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * Get an array of ElggObjects owned by this user.
+ *
+ * @param string $subtype The subtype of the objects, if any
+ * @param int $limit Number of results to return
+ * @param int $offset Any indexing offset
+ */
+ public function getObjects($subtype="", $limit = 10, $offset = 0) {
+ return get_user_objects($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * Get an array of ElggObjects owned by this user's friends.
+ *
+ * @param string $subtype The subtype of the objects, if any
+ * @param int $limit Number of results to return
+ * @param int $offset Any indexing offset
+ */
+ public function getFriendsObjects($subtype = "", $limit = 10, $offset = 0) {
+ return get_user_friends_objects($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * Counts the number of ElggObjects owned by this user
+ *
+ * @param string $subtype The subtypes of the objects, if any
+ * @return int The number of ElggObjects
+ */
+ public function countObjects($subtype = "") {
+ return count_user_objects($this->getGUID(), $subtype);
+ }
+
+ /**
+ * Get the collections associated with a user.
+ *
+ * @param string $subtype Optionally, the subtype of result we want to limit to
+ * @param int $limit The number of results to return
+ * @param int $offset Any indexing offset
+ * @return unknown
+ */
+ public function getCollections($subtype="", $limit = 10, $offset = 0) {
+ return get_user_collections($this->getGUID(), $subtype, $limit, $offset);
+ }
+
+ /**
+ * If a user's owner is blank, return its own GUID as the owner
+ *
+ * @return int User GUID
+ */
+ function getOwner() {
+ if ($this->owner_guid == 0) {
+ return $this->getGUID();
+ }
+
+ return $this->owner_guid;
+ }
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues() {
+ return array_merge(parent::getExportableValues(), array(
+ 'name',
+ 'username',
+ 'language',
+ ));
+ }
+
+ // backward compatibility with admin flag
+ // remove for 1.9
+ public function __set($name, $value) {
+ if ($name == 'admin' || $name == 'siteadmin') {
+ elgg_deprecated_notice('The admin/siteadmin metadata are not longer used. Use ElggUser->makeAdmin() and ElggUser->removeAdmin().', '1.7.1');
+
+ if ($value == 'yes' || $value == '1') {
+ $this->makeAdmin();
+ } else {
+ $this->removeAdmin();
+ }
+ }
+ return parent::__set($name, $value);
+ }
+
+ public function __get($name) {
+ if ($name == 'admin' || $name == 'siteadmin') {
+ elgg_deprecated_notice('The admin/siteadmin metadata are not longer used. Use ElggUser->isAdmin().', '1.7.1');
+ return $this->isAdmin();
+ }
+
+ return parent::__get($name);
+ }
+}
-<?php\r
-\r
-/**\r
- * Override ElggObject in order to store widget data in ultra-private stores.\r
- */\r
-class ElggWidget extends ElggObject {\r
- protected function initialise_attributes() {\r
- parent::initialise_attributes();\r
-\r
- $this->attributes['subtype'] = "widget";\r
- }\r
-\r
- public function __construct($guid = null) {\r
- parent::__construct($guid);\r
- }\r
-\r
- /**\r
- * Override entity get and sets in order to save data to private data store.\r
- */\r
- public function get($name) {\r
- // See if its in our base attribute\r
- if (isset($this->attributes[$name])) {\r
- return $this->attributes[$name];\r
- }\r
-\r
- // No, so see if its in the private data store.\r
- $meta = get_private_setting($this->guid, $name);\r
- if ($meta) {\r
- return $meta;\r
- }\r
-\r
- // Can't find it, so return null\r
- return null;\r
- }\r
-\r
- /**\r
- * Override entity get and sets in order to save data to private data store.\r
- */\r
- public function set($name, $value) {\r
- if (array_key_exists($name, $this->attributes)) {\r
- // Check that we're not trying to change the guid!\r
- if ((array_key_exists('guid', $this->attributes)) && ($name=='guid')) {\r
- return false;\r
- }\r
-\r
- $this->attributes[$name] = $value;\r
- } else {\r
- return set_private_setting($this->guid, $name, $value);\r
- }\r
-\r
- return true;\r
- }\r
+<?php
+
+/**
+ * Override ElggObject in order to store widget data in ultra-private stores.
+ */
+class ElggWidget extends ElggObject {
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['subtype'] = "widget";
+ }
+
+ public function __construct($guid = null) {
+ parent::__construct($guid);
+ }
+
+ /**
+ * Override entity get and sets in order to save data to private data store.
+ */
+ public function get($name) {
+ // See if its in our base attribute
+ if (isset($this->attributes[$name])) {
+ return $this->attributes[$name];
+ }
+
+ // No, so see if its in the private data store.
+ $meta = get_private_setting($this->guid, $name);
+ if ($meta) {
+ return $meta;
+ }
+
+ // Can't find it, so return null
+ return null;
+ }
+
+ /**
+ * Override entity get and sets in order to save data to private data store.
+ */
+ public function set($name, $value) {
+ if (array_key_exists($name, $this->attributes)) {
+ // Check that we're not trying to change the guid!
+ if ((array_key_exists('guid', $this->attributes)) && ($name=='guid')) {
+ return false;
+ }
+
+ $this->attributes[$name] = $value;
+ } else {
+ return set_private_setting($this->guid, $name, $value);
+ }
+
+ return true;
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * ErrorResult\r
- * The error result class.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Core\r
- */\r
-class ErrorResult extends GenericResult {\r
- // Fail with no specific code\r
- public static $RESULT_FAIL = -1 ;\r
-\r
- public static $RESULT_FAIL_APIKEY_DISABLED = -30;\r
- public static $RESULT_FAIL_APIKEY_INACTIVE = -31;\r
- public static $RESULT_FAIL_APIKEY_INVALID = -32;\r
-\r
- // Invalid, expired or missing auth token\r
- public static $RESULT_FAIL_AUTHTOKEN = -20;\r
-\r
- public function ErrorResult($message, $code = "", Exception $exception = NULL) {\r
- if ($code == "") {\r
- $code = ErrorResult::$RESULT_FAIL;\r
- }\r
-\r
- if ($exception!=NULL) {\r
- $this->setResult($exception->__toString());\r
- }\r
-\r
- $this->setStatusCode($code, $message);\r
- }\r
-\r
- /**\r
- * Get a new instance of the ErrorResult.\r
- *\r
- * @param string $message\r
- * @param int $code\r
- * @param Exception $exception Optional exception for generating a stack trace.\r
- */\r
- public static function getInstance($message, $code = "", Exception $exception = NULL) {\r
- // Return a new error object.\r
- return new ErrorResult($message, $code, $exception);\r
- }\r
+<?php
+/**
+ * ErrorResult
+ * The error result class.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Core
+ */
+class ErrorResult extends GenericResult {
+ // Fail with no specific code
+ public static $RESULT_FAIL = -1 ;
+
+ public static $RESULT_FAIL_APIKEY_DISABLED = -30;
+ public static $RESULT_FAIL_APIKEY_INACTIVE = -31;
+ public static $RESULT_FAIL_APIKEY_INVALID = -32;
+
+ // Invalid, expired or missing auth token
+ public static $RESULT_FAIL_AUTHTOKEN = -20;
+
+ public function ErrorResult($message, $code = "", Exception $exception = NULL) {
+ if ($code == "") {
+ $code = ErrorResult::$RESULT_FAIL;
+ }
+
+ if ($exception!=NULL) {
+ $this->setResult($exception->__toString());
+ }
+
+ $this->setStatusCode($code, $message);
+ }
+
+ /**
+ * Get a new instance of the ErrorResult.
+ *
+ * @param string $message
+ * @param int $code
+ * @param Exception $exception Optional exception for generating a stack trace.
+ */
+ public static function getInstance($message, $code = "", Exception $exception = NULL) {
+ // Return a new error object.
+ return new ErrorResult($message, $code, $exception);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * Export exception\r
- *\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- *\r
- */\r
+<?php
+/**
+ * Export exception
+ *
+ * @package Elgg
+ * @subpackage Exceptions
+ *
+ */
class ExportException extends DataFormatException {}
\ No newline at end of file
-<?php\r
-/**\r
- * Define an interface for all ODD exportable objects.\r
- *\r
- * @package Elgg\r
- * @subpackage Core\r
- * @author Curverider Ltd\r
- */\r
-interface Exportable {\r
- /**\r
- * This must take the contents of the object and convert it to exportable ODD\r
- * @return object or array of objects.\r
- */\r
- public function export();\r
-\r
- /**\r
- * Return a list of all fields that can be exported.\r
- * This should be used as the basis for the values returned by export()\r
- */\r
- public function getExportableValues();\r
+<?php
+/**
+ * Define an interface for all ODD exportable objects.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ */
+interface Exportable {
+ /**
+ * This must take the contents of the object and convert it to exportable ODD
+ * @return object or array of objects.
+ */
+ public function export();
+
+ /**
+ * Return a list of all fields that can be exported.
+ * This should be used as the basis for the values returned by export()
+ */
+ public function getExportableValues();
}
\ No newline at end of file
-<?php\r
-/**\r
- * GenericResult Result superclass.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Core\r
- */\r
-abstract class GenericResult {\r
- /**\r
- * The status of the result.\r
- * @var int\r
- */\r
- private $status_code;\r
-\r
- /**\r
- * Message returned along with the status which is almost always an error message.\r
- * This must be human readable, understandable and localised.\r
- * @var string\r
- */\r
- private $message;\r
-\r
- /**\r
- * Result store.\r
- * Attach result specific informaton here.\r
- *\r
- * @var mixed. Should probably be an object of some sort.\r
- */\r
- private $result;\r
-\r
- /**\r
- * Set a status code and optional message.\r
- *\r
- * @param int $status The status code.\r
- * @param string $message The message.\r
- */\r
- protected function setStatusCode($status, $message = "") {\r
- $this->status_code = $status;\r
- $this->message = $message;\r
- }\r
-\r
- /**\r
- * Set the result.\r
- *\r
- * @param mixed $result\r
- */\r
- protected function setResult($result) {\r
- $this->result = $result;\r
- }\r
-\r
- protected function getStatusCode() {\r
- return $this->status_code;\r
- }\r
-\r
- protected function getStatusMessage() {\r
- return $this->message;\r
- }\r
-\r
- protected function getResult() {\r
- return $this->result;\r
- }\r
-\r
- /**\r
- * Serialise to a standard class.\r
- *\r
- * DEVNOTE: The API is only interested in data, we can not easily serialise\r
- * custom classes without the need for 1) the other side being PHP, 2) you need to have the class\r
- * definition installed, 3) its the right version!\r
- *\r
- * Therefore, I'm not bothering.\r
- *\r
- * Override this to include any more specific information, however api results should be attached to the\r
- * class using setResult().\r
- *\r
- * if $CONFIG->debug is set then additional information about the runtime environment and authentication will be\r
- * returned.\r
- *\r
- * @return stdClass Object containing the serialised result.\r
- */\r
- public function export() {\r
- global $ERRORS, $CONFIG, $_PAM_HANDLERS_MSG;\r
-\r
- $result = new stdClass;\r
-\r
- $result->status = $this->getStatusCode();\r
- if ($this->getStatusMessage()!="") {\r
- $result->message = $this->getStatusMessage();\r
- }\r
-\r
- $resultdata = $this->getResult();\r
- if (isset($resultdata)) {\r
- $result->result = $resultdata;\r
- }\r
-\r
- if (isset($CONFIG->debug)) {\r
- if (count($ERRORS)) {\r
- $result->runtime_errors = $ERRORS;\r
- }\r
-\r
- if (count($_PAM_HANDLERS_MSG)) {\r
- $result->pam = $_PAM_HANDLERS_MSG;\r
- }\r
- }\r
-\r
- return $result;\r
- }\r
+<?php
+/**
+ * GenericResult Result superclass.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Core
+ */
+abstract class GenericResult {
+ /**
+ * The status of the result.
+ * @var int
+ */
+ private $status_code;
+
+ /**
+ * Message returned along with the status which is almost always an error message.
+ * This must be human readable, understandable and localised.
+ * @var string
+ */
+ private $message;
+
+ /**
+ * Result store.
+ * Attach result specific informaton here.
+ *
+ * @var mixed. Should probably be an object of some sort.
+ */
+ private $result;
+
+ /**
+ * Set a status code and optional message.
+ *
+ * @param int $status The status code.
+ * @param string $message The message.
+ */
+ protected function setStatusCode($status, $message = "") {
+ $this->status_code = $status;
+ $this->message = $message;
+ }
+
+ /**
+ * Set the result.
+ *
+ * @param mixed $result
+ */
+ protected function setResult($result) {
+ $this->result = $result;
+ }
+
+ protected function getStatusCode() {
+ return $this->status_code;
+ }
+
+ protected function getStatusMessage() {
+ return $this->message;
+ }
+
+ protected function getResult() {
+ return $this->result;
+ }
+
+ /**
+ * Serialise to a standard class.
+ *
+ * DEVNOTE: The API is only interested in data, we can not easily serialise
+ * custom classes without the need for 1) the other side being PHP, 2) you need to have the class
+ * definition installed, 3) its the right version!
+ *
+ * Therefore, I'm not bothering.
+ *
+ * Override this to include any more specific information, however api results should be attached to the
+ * class using setResult().
+ *
+ * if $CONFIG->debug is set then additional information about the runtime environment and authentication will be
+ * returned.
+ *
+ * @return stdClass Object containing the serialised result.
+ */
+ public function export() {
+ global $ERRORS, $CONFIG, $_PAM_HANDLERS_MSG;
+
+ $result = new stdClass;
+
+ $result->status = $this->getStatusCode();
+ if ($this->getStatusMessage()!="") {
+ $result->message = $this->getStatusMessage();
+ }
+
+ $resultdata = $this->getResult();
+ if (isset($resultdata)) {
+ $result->result = $resultdata;
+ }
+
+ if (isset($CONFIG->debug)) {
+ if (count($ERRORS)) {
+ $result->runtime_errors = $ERRORS;
+ }
+
+ if (count($_PAM_HANDLERS_MSG)) {
+ $result->pam = $_PAM_HANDLERS_MSG;
+ }
+ }
+
+ return $result;
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * IOException\r
- * An IO Exception, throw when an IO Exception occurs. Subclass for specific IO Exceptions.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
-class IOException extends Exception {}\r
+<?php
+/**
+ * IOException
+ * An IO Exception, throw when an IO Exception occurs. Subclass for specific IO Exceptions.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class IOException extends Exception {}
-<?php\r
-/**\r
- * Import exception\r
- *\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
+<?php
+/**
+ * Import exception
+ *
+ * @package Elgg
+ * @subpackage Exceptions
+ */
class ImportException extends DataFormatException {}
\ No newline at end of file
-<?php\r
-/**\r
- * Define an interface for all ODD importable objects.\r
- * @author Curverider Ltd\r
- */\r
-interface Importable {\r
- /**\r
- * Accepts an array of data to import, this data is parsed from the XML produced by export.\r
- * The function should return the constructed object data, or NULL.\r
- *\r
- * @param ODD $data\r
- * @return bool\r
- * @throws ImportException if there was a critical error importing data.\r
- */\r
- public function import(ODD $data);\r
-}\r
+<?php
+/**
+ * Define an interface for all ODD importable objects.
+ * @author Curverider Ltd
+ */
+interface Importable {
+ /**
+ * Accepts an array of data to import, this data is parsed from the XML produced by export.
+ * The function should return the constructed object data, or NULL.
+ *
+ * @param ODD $data
+ * @return bool
+ * @throws ImportException if there was a critical error importing data.
+ */
+ public function import(ODD $data);
+}
-<?php\r
-/**\r
- * @class InsertQueryTypeQueryComponent\r
- * An insert query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class InsertQueryTypeQueryComponent extends QueryTypeQueryComponent\r
-{\r
- function __construct()\r
- {\r
- $this->query_type = "INSERT INTO";\r
- }\r
-}\r
+<?php
+/**
+ * @class InsertQueryTypeQueryComponent
+ * An insert query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class InsertQueryTypeQueryComponent extends QueryTypeQueryComponent
+{
+ function __construct()
+ {
+ $this->query_type = "INSERT INTO";
+ }
+}
-<?php\r
-/**\r
- * InstallationException\r
- * Thrown when there is a major problem with the installation.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
-class InstallationException extends ConfigurationException {}\r
+<?php
+/**
+ * InstallationException
+ * Thrown when there is a major problem with the installation.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class InstallationException extends ConfigurationException {}
-<?php\r
-/**\r
- * InvalidClassException\r
- * An invalid class Exception, throw when a class is invalid.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
-class InvalidClassException extends ClassException {}\r
+<?php
+/**
+ * InvalidClassException
+ * An invalid class Exception, throw when a class is invalid.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class InvalidClassException extends ClassException {}
-<?php\r
-/**\r
- * InvalidParameterException\r
- * A parameter is invalid.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
-class InvalidParameterException extends CallException {}\r
+<?php
+/**
+ * InvalidParameterException
+ * A parameter is invalid.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class InvalidParameterException extends CallException {}
-<?php\r
-/**\r
- * @class JoinQueryComponent Join query.\r
- * Represents a join query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class JoinQueryComponent extends QueryComponent\r
-{\r
- /**\r
- * Construct a join query.\r
- * @param string $table Table one to join...\r
- * @param string $field Field 1 with...\r
- * @param string $table2 Table 2 ...\r
- * @param string $field2 Field...\r
- * @param string $operator Using this operator\r
- */\r
- function __construct($table1, $field1, $table2, $field2, $operator = "=")\r
- {\r
- global $CONFIG;\r
-\r
- $this->table1 = $CONFIG->dbprefix . sanitise_string($table1);\r
- $this->field1 = sanitise_string($field1);\r
- $this->table2 = $CONFIG->dbprefix . sanitise_string($table2);\r
- $this->field2 = sanitise_string($field2);\r
- $this->operator = sanitise_string($operator);\r
- }\r
-\r
- function __toString()\r
- {\r
- return "join {$this->table2} on {$this->$table}.{$this->$field} {$this->$operator} {$this->$table2}.{$this->$field2}";\r
- }\r
-}\r
+<?php
+/**
+ * @class JoinQueryComponent Join query.
+ * Represents a join query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class JoinQueryComponent extends QueryComponent
+{
+ /**
+ * Construct a join query.
+ * @param string $table Table one to join...
+ * @param string $field Field 1 with...
+ * @param string $table2 Table 2 ...
+ * @param string $field2 Field...
+ * @param string $operator Using this operator
+ */
+ function __construct($table1, $field1, $table2, $field2, $operator = "=")
+ {
+ global $CONFIG;
+
+ $this->table1 = $CONFIG->dbprefix . sanitise_string($table1);
+ $this->field1 = sanitise_string($field1);
+ $this->table2 = $CONFIG->dbprefix . sanitise_string($table2);
+ $this->field2 = sanitise_string($field2);
+ $this->operator = sanitise_string($operator);
+ }
+
+ function __toString()
+ {
+ return "join {$this->table2} on {$this->$table}.{$this->$field} {$this->$operator} {$this->$table2}.{$this->$field2}";
+ }
+}
-<?php\r
-/**\r
- * @class LimitOffsetQueryComponent\r
- * Limit and offset clauses of a query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class LimitOffsetQueryComponent extends QueryComponent\r
-{\r
- /**\r
- * Specify a limit and an offset.\r
- *\r
- * @param int $limit The limit.\r
- * @param int $offset The offset.\r
- */\r
- function __construct($limit = 25, $offset = 0)\r
- {\r
- $this->limit = (int)$limit;\r
- $this->offset = (int)$offset;\r
- }\r
-\r
- function __toString()\r
- {\r
- return "limit {$this->offset}, {$this->limit}";\r
- }\r
-}\r
+<?php
+/**
+ * @class LimitOffsetQueryComponent
+ * Limit and offset clauses of a query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class LimitOffsetQueryComponent extends QueryComponent
+{
+ /**
+ * Specify a limit and an offset.
+ *
+ * @param int $limit The limit.
+ * @param int $offset The offset.
+ */
+ function __construct($limit = 25, $offset = 0)
+ {
+ $this->limit = (int)$limit;
+ $this->offset = (int)$offset;
+ }
+
+ function __toString()
+ {
+ return "limit {$this->offset}, {$this->limit}";
+ }
+}
-<?php\r
-\r
-/**\r
- * Define an interface for geo-tagging entities.\r
- *\r
- */\r
-interface Locatable {\r
- /** Set a location text */\r
- public function setLocation($location);\r
-\r
- /**\r
- * Set latitude and longitude tags for a given entity.\r
- *\r
- * @param float $lat\r
- * @param float $long\r
- */\r
- public function setLatLong($lat, $long);\r
-\r
- /**\r
- * Get the contents of the ->geo:lat field.\r
- *\r
- */\r
- public function getLatitude();\r
-\r
- /**\r
- * Get the contents of the ->geo:lat field.\r
- *\r
- */\r
- public function getLongitude();\r
-\r
- /**\r
- * Get the ->location metadata.\r
- *\r
- */\r
- public function getLocation();\r
+<?php
+
+/**
+ * Define an interface for geo-tagging entities.
+ *
+ */
+interface Locatable {
+ /** Set a location text */
+ public function setLocation($location);
+
+ /**
+ * Set latitude and longitude tags for a given entity.
+ *
+ * @param float $lat
+ * @param float $long
+ */
+ public function setLatLong($lat, $long);
+
+ /**
+ * Get the contents of the ->geo:lat field.
+ *
+ */
+ public function getLatitude();
+
+ /**
+ * Get the contents of the ->geo:lat field.
+ *
+ */
+ public function getLongitude();
+
+ /**
+ * Get the ->location metadata.
+ *
+ */
+ public function getLocation();
}
\ No newline at end of file
-<?php\r
-/**\r
- * Interface that provides an interface which must be implemented by all objects wishing to be\r
- * recorded in the system log (and by extension the river).\r
- *\r
- * This interface defines a set of methods that permit the system log functions to hook in and retrieve\r
- * the necessary information and to identify what events can actually be logged.\r
- *\r
- * To have events involving your object to be logged simply implement this interface.\r
- *\r
- * @author Curverider Ltd\r
- */\r
-interface Loggable {\r
- /**\r
- * Return an identification for the object for storage in the system log.\r
- * This id must be an integer.\r
- *\r
- * @return int\r
- */\r
- public function getSystemLogID();\r
-\r
- /**\r
- * Return the class name of the object.\r
- * Added as a function because get_class causes errors for some reason.\r
- */\r
- public function getClassName();\r
-\r
- /**\r
- * Return the type of the object - eg. object, group, user, relationship, metadata, annotation etc\r
- */\r
- public function getType();\r
-\r
- /**\r
- * Return a subtype. For metadata & annotations this is the 'name' and for relationship this is the relationship type.\r
- */\r
- public function getSubtype();\r
-\r
- /**\r
- * For a given ID, return the object associated with it.\r
- * This is used by the river functionality primarily.\r
- * This is useful for checking access permissions etc on objects.\r
- */\r
- public function getObjectFromID($id);\r
-\r
- /**\r
- * Return the GUID of the owner of this object.\r
- */\r
- public function getObjectOwnerGUID();\r
+<?php
+/**
+ * Interface that provides an interface which must be implemented by all objects wishing to be
+ * recorded in the system log (and by extension the river).
+ *
+ * This interface defines a set of methods that permit the system log functions to hook in and retrieve
+ * the necessary information and to identify what events can actually be logged.
+ *
+ * To have events involving your object to be logged simply implement this interface.
+ *
+ * @author Curverider Ltd
+ */
+interface Loggable {
+ /**
+ * Return an identification for the object for storage in the system log.
+ * This id must be an integer.
+ *
+ * @return int
+ */
+ public function getSystemLogID();
+
+ /**
+ * Return the class name of the object.
+ * Added as a function because get_class causes errors for some reason.
+ */
+ public function getClassName();
+
+ /**
+ * Return the type of the object - eg. object, group, user, relationship, metadata, annotation etc
+ */
+ public function getType();
+
+ /**
+ * Return a subtype. For metadata & annotations this is the 'name' and for relationship this is the relationship type.
+ */
+ public function getSubtype();
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id);
+
+ /**
+ * Return the GUID of the owner of this object.
+ */
+ public function getObjectOwnerGUID();
}
\ No newline at end of file
-<?php\r
-/**\r
- * NotImplementedException\r
- * Thrown when a method or function has not been implemented, primarily used in development... you should\r
- * not see these!\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
-class NotImplementedException extends CallException {}\r
+<?php
+/**
+ * NotImplementedException
+ * Thrown when a method or function has not been implemented, primarily used in development... you should
+ * not see these!
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class NotImplementedException extends CallException {}
-<?php\r
-/**\r
- * Calendar interface for events.\r
- *\r
- */\r
-interface Notable {\r
- /**\r
- * Calendar functionality.\r
- * This function sets the time of an object on a calendar listing.\r
- *\r
- * @param int $hour If ommitted, now is assumed.\r
- * @param int $minute If ommitted, now is assumed.\r
- * @param int $second If ommitted, now is assumed.\r
- * @param int $day If ommitted, now is assumed.\r
- * @param int $month If ommitted, now is assumed.\r
- * @param int $year If ommitted, now is assumed.\r
- * @param int $duration Duration of event, remainder of the day is assumed.\r
- */\r
- public function setCalendarTimeAndDuration($hour = NULL, $minute = NULL, $second = NULL, $day = NULL, $month = NULL, $year = NULL, $duration = NULL);\r
-\r
- /**\r
- * Return the start timestamp.\r
- */\r
- public function getCalendarStartTime();\r
-\r
- /**\r
- * Return the end timestamp.\r
- */\r
- public function getCalendarEndTime();\r
+<?php
+/**
+ * Calendar interface for events.
+ *
+ */
+interface Notable {
+ /**
+ * Calendar functionality.
+ * This function sets the time of an object on a calendar listing.
+ *
+ * @param int $hour If ommitted, now is assumed.
+ * @param int $minute If ommitted, now is assumed.
+ * @param int $second If ommitted, now is assumed.
+ * @param int $day If ommitted, now is assumed.
+ * @param int $month If ommitted, now is assumed.
+ * @param int $year If ommitted, now is assumed.
+ * @param int $duration Duration of event, remainder of the day is assumed.
+ */
+ public function setCalendarTimeAndDuration($hour = NULL, $minute = NULL, $second = NULL, $day = NULL, $month = NULL, $year = NULL, $duration = NULL);
+
+ /**
+ * Return the start timestamp.
+ */
+ public function getCalendarStartTime();
+
+ /**
+ * Return the end timestamp.
+ */
+ public function getCalendarEndTime();
}
\ No newline at end of file
-<?php\r
-/**\r
- * Notification exception.\r
- * @author Curverider Ltd\r
- */\r
-class NotificationException extends Exception {}\r
+<?php
+/**
+ * Notification exception.
+ * @author Curverider Ltd
+ */
+class NotificationException extends Exception {}
-<?php\r
-/**\r
- * Open Data Definition (ODD) superclass.\r
- * @package Elgg\r
- * @subpackage Core\r
- * @author Curverider Ltd\r
- */\r
-abstract class ODD {\r
- /**\r
- * Attributes.\r
- */\r
- private $attributes = array();\r
-\r
- /**\r
- * Optional body.\r
- */\r
- private $body;\r
-\r
- /**\r
- * Construct an ODD document with initial values.\r
- */\r
- public function __construct() {\r
- $this->body = "";\r
- }\r
-\r
- public function getAttributes() {\r
- return $this->attributes;\r
- }\r
-\r
- public function setAttribute($key, $value) {\r
- $this->attributes[$key] = $value;\r
- }\r
-\r
- public function getAttribute($key) {\r
- if (isset($this->attributes[$key])) {\r
- return $this->attributes[$key];\r
- }\r
-\r
- return NULL;\r
- }\r
-\r
- public function setBody($value) {\r
- $this->body = $value;\r
- }\r
-\r
- public function getBody() {\r
- return $this->body;\r
- }\r
-\r
- /**\r
- * Set the published time.\r
- *\r
- * @param int $time Unix timestamp\r
- */\r
- public function setPublished($time) {\r
- $this->attributes['published'] = date("r", $time);\r
- }\r
-\r
- /**\r
- * Return the published time as a unix timestamp.\r
- *\r
- * @return int or false on failure.\r
- */\r
- public function getPublishedAsTime() {\r
- return strtotime($this->attributes['published']);\r
- }\r
-\r
- /**\r
- * For serialisation, implement to return a string name of the tag eg "header" or "metadata".\r
- * @return string\r
- */\r
- abstract protected function getTagName();\r
-\r
- /**\r
- * Magic function to generate valid ODD XML for this item.\r
- */\r
- public function __toString() {\r
- // Construct attributes\r
- $attr = "";\r
- foreach ($this->attributes as $k => $v) {\r
- $attr .= ($v!="") ? "$k=\"$v\" " : "";\r
- }\r
-\r
- $body = $this->getBody();\r
- $tag = $this->getTagName();\r
-\r
- $end = "/>";\r
- if ($body!="") {\r
- $end = "><![CDATA[$body]]></{$tag}>";\r
- }\r
-\r
- return "<{$tag} $attr" . $end . "\n";\r
- }\r
-}\r
+<?php
+/**
+ * Open Data Definition (ODD) superclass.
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ */
+abstract class ODD {
+ /**
+ * Attributes.
+ */
+ private $attributes = array();
+
+ /**
+ * Optional body.
+ */
+ private $body;
+
+ /**
+ * Construct an ODD document with initial values.
+ */
+ public function __construct() {
+ $this->body = "";
+ }
+
+ public function getAttributes() {
+ return $this->attributes;
+ }
+
+ public function setAttribute($key, $value) {
+ $this->attributes[$key] = $value;
+ }
+
+ public function getAttribute($key) {
+ if (isset($this->attributes[$key])) {
+ return $this->attributes[$key];
+ }
+
+ return NULL;
+ }
+
+ public function setBody($value) {
+ $this->body = $value;
+ }
+
+ public function getBody() {
+ return $this->body;
+ }
+
+ /**
+ * Set the published time.
+ *
+ * @param int $time Unix timestamp
+ */
+ public function setPublished($time) {
+ $this->attributes['published'] = date("r", $time);
+ }
+
+ /**
+ * Return the published time as a unix timestamp.
+ *
+ * @return int or false on failure.
+ */
+ public function getPublishedAsTime() {
+ return strtotime($this->attributes['published']);
+ }
+
+ /**
+ * For serialisation, implement to return a string name of the tag eg "header" or "metadata".
+ * @return string
+ */
+ abstract protected function getTagName();
+
+ /**
+ * Magic function to generate valid ODD XML for this item.
+ */
+ public function __toString() {
+ // Construct attributes
+ $attr = "";
+ foreach ($this->attributes as $k => $v) {
+ $attr .= ($v!="") ? "$k=\"$v\" " : "";
+ }
+
+ $body = $this->getBody();
+ $tag = $this->getTagName();
+
+ $end = "/>";
+ if ($body!="") {
+ $end = "><![CDATA[$body]]></{$tag}>";
+ }
+
+ return "<{$tag} $attr" . $end . "\n";
+ }
+}
-<?php\r
-/**\r
- * @class ODDDocument ODD Document container.\r
- * This class is used during import and export to construct.\r
- * @author Curverider Ltd\r
- */\r
-class ODDDocument implements Iterator {\r
- /**\r
- * ODD Version\r
- *\r
- * @var string\r
- */\r
- private $ODDSupportedVersion = "1.0";\r
-\r
- /**\r
- * Elements of the document.\r
- */\r
- private $elements;\r
-\r
- /**\r
- * Optional wrapper factory.\r
- */\r
- private $wrapperfactory;\r
-\r
- public function __construct(array $elements = NULL) {\r
- if ($elements) {\r
- if (is_array($elements)) {\r
- $this->elements = $elements;\r
- } else {\r
- $this->addElement($elements);\r
- }\r
- } else {\r
- $this->elements = array();\r
- }\r
- }\r
-\r
- /**\r
- * Return the version of ODD being used.\r
- *\r
- * @return string\r
- */\r
- public function getVersion() {\r
- return $this->ODDSupportedVersion;\r
- }\r
-\r
- public function getNumElements() {\r
- return count($this->elements);\r
- }\r
-\r
- public function addElement(ODD $element) {\r
- if (!is_array($this->elements)) {\r
- $this->elements = array();\r
- $this->elements[] = $element;\r
- }\r
- }\r
-\r
- public function addElements(array $elements) {\r
- foreach ($elements as $element) {\r
- $this->addElement($element);\r
- }\r
- }\r
-\r
- public function getElements() {\r
- return $this->elements;\r
- }\r
-\r
- /**\r
- * Set an optional wrapper factory to optionally embed the ODD document in another format.\r
- */\r
- public function setWrapperFactory(ODDWrapperFactory $factory) {\r
- $this->wrapperfactory = $factory;\r
- }\r
-\r
- /**\r
- * Magic function to generate valid ODD XML for this item.\r
- */\r
- public function __toString() {\r
- $xml = "";\r
-\r
- if ($this->wrapperfactory) {\r
- // A wrapper has been provided\r
- $wrapper = $this->wrapperfactory->getElementWrapper($this); // Get the wrapper for this element\r
-\r
- $xml = $wrapper->wrap($this); // Wrap this element (and subelements)\r
- } else {\r
- // Output begin tag\r
- $generated = date("r");\r
- $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";\r
-\r
- // Get XML for elements\r
- foreach ($this->elements as $element) {\r
- $xml .= "$element";\r
- }\r
-\r
- // Output end tag\r
- $xml .= "</odd>\n";\r
- }\r
-\r
- return $xml;\r
- }\r
-\r
- // ITERATOR INTERFACE //////////////////////////////////////////////////////////////\r
- /*\r
- * This lets an entity's attributes be displayed using foreach as a normal array.\r
- * Example: http://www.sitepoint.com/print/php5-standard-library\r
- */\r
-\r
- private $valid = FALSE;\r
-\r
- function rewind() {\r
- $this->valid = (FALSE !== reset($this->elements));\r
- }\r
-\r
- function current() {\r
- return current($this->elements);\r
- }\r
-\r
- function key() {\r
- return key($this->elements);\r
- }\r
-\r
- function next() {\r
- $this->valid = (FALSE !== next($this->elements));\r
- }\r
-\r
- function valid() {\r
- return $this->valid;\r
- }\r
-}\r
+<?php
+/**
+ * @class ODDDocument ODD Document container.
+ * This class is used during import and export to construct.
+ * @author Curverider Ltd
+ */
+class ODDDocument implements Iterator {
+ /**
+ * ODD Version
+ *
+ * @var string
+ */
+ private $ODDSupportedVersion = "1.0";
+
+ /**
+ * Elements of the document.
+ */
+ private $elements;
+
+ /**
+ * Optional wrapper factory.
+ */
+ private $wrapperfactory;
+
+ public function __construct(array $elements = NULL) {
+ if ($elements) {
+ if (is_array($elements)) {
+ $this->elements = $elements;
+ } else {
+ $this->addElement($elements);
+ }
+ } else {
+ $this->elements = array();
+ }
+ }
+
+ /**
+ * Return the version of ODD being used.
+ *
+ * @return string
+ */
+ public function getVersion() {
+ return $this->ODDSupportedVersion;
+ }
+
+ public function getNumElements() {
+ return count($this->elements);
+ }
+
+ public function addElement(ODD $element) {
+ if (!is_array($this->elements)) {
+ $this->elements = array();
+ $this->elements[] = $element;
+ }
+ }
+
+ public function addElements(array $elements) {
+ foreach ($elements as $element) {
+ $this->addElement($element);
+ }
+ }
+
+ public function getElements() {
+ return $this->elements;
+ }
+
+ /**
+ * Set an optional wrapper factory to optionally embed the ODD document in another format.
+ */
+ public function setWrapperFactory(ODDWrapperFactory $factory) {
+ $this->wrapperfactory = $factory;
+ }
+
+ /**
+ * Magic function to generate valid ODD XML for this item.
+ */
+ public function __toString() {
+ $xml = "";
+
+ if ($this->wrapperfactory) {
+ // A wrapper has been provided
+ $wrapper = $this->wrapperfactory->getElementWrapper($this); // Get the wrapper for this element
+
+ $xml = $wrapper->wrap($this); // Wrap this element (and subelements)
+ } else {
+ // Output begin tag
+ $generated = date("r");
+ $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";
+
+ // Get XML for elements
+ foreach ($this->elements as $element) {
+ $xml .= "$element";
+ }
+
+ // Output end tag
+ $xml .= "</odd>\n";
+ }
+
+ return $xml;
+ }
+
+ // ITERATOR INTERFACE //////////////////////////////////////////////////////////////
+ /*
+ * This lets an entity's attributes be displayed using foreach as a normal array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+
+ private $valid = FALSE;
+
+ function rewind() {
+ $this->valid = (FALSE !== reset($this->elements));
+ }
+
+ function current() {
+ return current($this->elements);
+ }
+
+ function key() {
+ return key($this->elements);
+ }
+
+ function next() {
+ $this->valid = (FALSE !== next($this->elements));
+ }
+
+ function valid() {
+ return $this->valid;
+ }
+}
-<?php\r
-\r
-/**\r
- * ODD Entity class.\r
- * @package Elgg\r
- * @subpackage Core\r
- * @author Curverider Ltd\r
- */\r
-class ODDEntity extends ODD {\r
- function __construct($uuid, $class, $subclass = "") {\r
- parent::__construct();\r
-\r
- $this->setAttribute('uuid', $uuid);\r
- $this->setAttribute('class', $class);\r
- $this->setAttribute('subclass', $subclass);\r
- }\r
-\r
- protected function getTagName() { return "entity"; }\r
-}\r
-\r
-/**\r
- * ODD Metadata class.\r
- * @package Elgg\r
- * @subpackage Core\r
- * @author Curverider Ltd\r
- */\r
-class ODDMetaData extends ODD {\r
- function __construct($uuid, $entity_uuid, $name, $value, $type = "", $owner_uuid = "") {\r
- parent::__construct();\r
-\r
- $this->setAttribute('uuid', $uuid);\r
- $this->setAttribute('entity_uuid', $entity_uuid);\r
- $this->setAttribute('name', $name);\r
- $this->setAttribute('type', $type);\r
- $this->setAttribute('owner_uuid', $owner_uuid);\r
- $this->setBody($value);\r
- }\r
-\r
- protected function getTagName() {\r
- return "metadata";\r
- }\r
-}\r
-\r
-/**\r
- * ODD Relationship class.\r
- * @package Elgg\r
- * @subpackage Core\r
- * @author Curverider Ltd\r
- */\r
-class ODDRelationship extends ODD {\r
- function __construct($uuid1, $type, $uuid2) {\r
- parent::__construct();\r
-\r
- $this->setAttribute('uuid1', $uuid1);\r
- $this->setAttribute('type', $type);\r
- $this->setAttribute('uuid2', $uuid2);\r
- }\r
-\r
- protected function getTagName() { return "relationship"; }\r
+<?php
+
+/**
+ * ODD Entity class.
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ */
+class ODDEntity extends ODD {
+ function __construct($uuid, $class, $subclass = "") {
+ parent::__construct();
+
+ $this->setAttribute('uuid', $uuid);
+ $this->setAttribute('class', $class);
+ $this->setAttribute('subclass', $subclass);
+ }
+
+ protected function getTagName() { return "entity"; }
+}
+
+/**
+ * ODD Metadata class.
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ */
+class ODDMetaData extends ODD {
+ function __construct($uuid, $entity_uuid, $name, $value, $type = "", $owner_uuid = "") {
+ parent::__construct();
+
+ $this->setAttribute('uuid', $uuid);
+ $this->setAttribute('entity_uuid', $entity_uuid);
+ $this->setAttribute('name', $name);
+ $this->setAttribute('type', $type);
+ $this->setAttribute('owner_uuid', $owner_uuid);
+ $this->setBody($value);
+ }
+
+ protected function getTagName() {
+ return "metadata";
+ }
+}
+
+/**
+ * ODD Relationship class.
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ */
+class ODDRelationship extends ODD {
+ function __construct($uuid1, $type, $uuid2) {
+ parent::__construct();
+
+ $this->setAttribute('uuid1', $uuid1);
+ $this->setAttribute('type', $type);
+ $this->setAttribute('uuid2', $uuid2);
+ }
+
+ protected function getTagName() { return "relationship"; }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class OrderQueryComponent\r
- * Order the query results.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class OrderQueryComponent extends QueryComponent\r
-{\r
- function __construct($table, $field, $order = "asc")\r
- {\r
- global $CONFIG;\r
-\r
- $this->table = $CONFIG->dbprefix . sanitise_string($table);\r
- $this->field = sanitise_string($field);\r
- $this->order = sanitise_string($order);\r
- }\r
-\r
- function __toString()\r
- {\r
- return "order by {$this->table}.{$this->field} {$this->order}";\r
- }\r
-}\r
+<?php
+/**
+ * @class OrderQueryComponent
+ * Order the query results.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class OrderQueryComponent extends QueryComponent
+{
+ function __construct($table, $field, $order = "asc")
+ {
+ global $CONFIG;
+
+ $this->table = $CONFIG->dbprefix . sanitise_string($table);
+ $this->field = sanitise_string($field);
+ $this->order = sanitise_string($order);
+ }
+
+ function __toString()
+ {
+ return "order by {$this->table}.{$this->field} {$this->order}";
+ }
+}
-<?php\r
-/**\r
- * PluginException\r
- *\r
- * A plugin Exception, thrown when an Exception occurs relating to the plugin mechanism. Subclass for specific plugin Exceptions.\r
- *\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
+<?php
+/**
+ * PluginException
+ *
+ * A plugin Exception, thrown when an Exception occurs relating to the plugin mechanism. Subclass for specific plugin Exceptions.
+ *
+ * @package Elgg
+ * @subpackage Exceptions
+ */
class PluginException extends Exception {}
\ No newline at end of file
-<?php\r
-/**\r
- * @class Query Provides a framework to construct complex queries in a safer environment.\r
- *\r
- * The usage of this class depends on the type of query you are executing, but the basic idea is to\r
- * construct a query out of pluggable classes.\r
- *\r
- * Once constructed SQL can be generated using the toString method, this should happen automatically\r
- * if you pass the Query object to get_data or similar.\r
- *\r
- * To construct a query, create a new Query() object and begin populating it with the various classes\r
- * that define the various aspects of the query.\r
- *\r
- * Notes:\r
- * - You do not have to specify things in any particular order, provided you specify all required\r
- * components.\r
- * - With database tables you do not have to specify your db prefix, this will be added automatically.\r
- * - When constructing your query keep an eye on the error log - any problems will get spit out here.\r
- * Note also that __toString won't let you throw Exceptions (!!!) so these are caught and echoed to\r
- * the log instead.\r
- *\r
- * Here is an example of a select query which requests some data out of the entities table with an\r
- * order and limit that uses a subset where and some normal where queries:\r
- *\r
- * <blockquote>\r
- * // Construct the query\r
- * $query = new Query();\r
- *\r
- * // Say which table we're interested in\r
- * $query->addTable(new TableQueryComponent("entities"));\r
- *\r
- * // What fields are we interested in\r
- * $query->addSelectField(new SelectFieldQueryComponent("entities","*"));\r
- *\r
- * // Add access control (Default access control uses default fields on entities table.\r
- * // Note that it will error without something specified here!\r
- * $query->setAccessControl(new AccessControlQueryComponent());\r
- *\r
- * // Set a limit and offset, may be omitted.\r
- * $query->setLimitAndOffset(new LimitOffsetQueryComponent(10,0));\r
- *\r
- * // Specify the order, may be omitted\r
- * $query->setOrder(new OrderQueryComponent("entities", "subtype", "desc"));\r
- *\r
- * // Construct a where query\r
- * //\r
- * // This demonstrates a WhereSet which lets you have sub wheres, a\r
- * // WhereStatic which lets you compare a table field against a value and a\r
- * // Where which lets you compare a table/field with another table/field.\r
- * $query->addWhere(\r
- * new WhereSetQueryComponent(\r
- * array(\r
- * new WhereStaticQueryComponent("entities", "subtype","=", 1),\r
- * new WhereQueryComponent("entities","subtype","=", "entities", "subtype")\r
- * )\r
- * )\r
- * );\r
- *\r
- * get_data($query);\r
- * </blockquote>\r
- *\r
- * @author Curverider Ltd\r
- */\r
-class Query\r
-{\r
-\r
- /// The limit of the query\r
- private $limit_and_offset;\r
-\r
- /// Fields to return on a query\r
- private $fields;\r
-\r
- /// Tables to use in a from query\r
- private $tables;\r
-\r
- /// Join tables\r
- private $joins;\r
-\r
- /// Set values\r
- private $sets;\r
-\r
- /// Where query\r
- private $where;\r
-\r
- /// Order by\r
- private $order;\r
-\r
- /// The query type\r
- private $query_type;\r
-\r
- /// ACL\r
- private $access_control;\r
-\r
- /**\r
- * Construct query & initialise variables\r
- */\r
- function __construct()\r
- {\r
- $this->fields = array();\r
- $this->tables = array();\r
- $this->joins = array();\r
- $this->where = array();\r
- $this->sets = array();\r
-\r
- $this->setQueryType(new SelectQueryTypeQueryComponent());\r
- }\r
-\r
- /**\r
- * Add limits and offsets to the query.\r
- *\r
- * @param LimitOffsetQueryComponent $component The limit and offset.\r
- */\r
- public function setLimitAndOffset(LimitOffsetQueryComponent $component) { $this->limit_and_offset = $component; }\r
-\r
- /**\r
- * Reset and set the field to the select statement.\r
- *\r
- * @param SelectFieldQueryComponent $component Table and field component.\r
- */\r
- public function setSelectField(SelectFieldQueryComponent $component)\r
- {\r
- $this->fields = array();\r
- return $this->addSelectField($component);\r
- }\r
-\r
- /**\r
- * Add a select field.\r
- *\r
- * @param SelectFieldQueryComponent $component Add a component.\r
- */\r
- public function addSelectField(SelectFieldQueryComponent $component) { $this->fields[] = $component; }\r
-\r
- /**\r
- * Add a join to the component.\r
- *\r
- * @param JoinQueryComponent $component The join.\r
- */\r
- public function addJoin(JoinQueryComponent $component) { $this->joins[] = $component; }\r
-\r
- /**\r
- * Set a field value in an update or insert statement.\r
- *\r
- * @param SetQueryComponent $component Fields to set.\r
- */\r
- public function addSet(SetQueryComponent $component) { $this->sets[] = $component; }\r
-\r
- /**\r
- * Set the query type, i.e. "select", "update", "insert" & "delete".\r
- *\r
- * @param QueryTypeQueryComponent $component The query type.\r
- */\r
- public function setQueryType(QueryTypeQueryComponent $component) { $this->query_type = $component; }\r
-\r
- /**\r
- * Attach an order component.\r
- *\r
- * @param OrderQueryComponent $component The order component.\r
- */\r
- public function setOrder(OrderQueryComponent $component) { $this->order = $component; }\r
-\r
- /**\r
- * Add a table to the query.\r
- *\r
- * @param TableQueryComponent $component Table to add.\r
- */\r
- public function addTable(TableQueryComponent $component) { $this->tables[] = $component; }\r
-\r
- /**\r
- * Add a where clause to the query.\r
- *\r
- * @param WhereQueryComponent $component The where component\r
- */\r
- public function addWhere(WhereQueryComponent $component) { $this->where[] = $component; }\r
-\r
- /**\r
- * Set access control.\r
- *\r
- * @param AccessControlQueryComponent $component Access control.\r
- */\r
- public function setAccessControl(AccessControlQueryComponent $component) { $this->access_control = $component; }\r
-\r
- public function __toString()\r
- {\r
- global $CONFIG;\r
-\r
- $sql = "";\r
-\r
- try\r
- {\r
- // Query prefix & fields\r
- if (!empty($this->query_type))\r
- {\r
- $sql .= "{$this->query_type} ";\r
-\r
- if (!empty($this->fields))\r
- {\r
- $fields = "";\r
-\r
- foreach ($this->fields as $field)\r
- $fields .= "$field";\r
-\r
- $sql .= " $fields from ";\r
- }\r
- else\r
- throw new DatabaseException(elgg_echo('DatabaseException:SelectFieldsMissing'));\r
- }\r
- else\r
- throw new DatabaseException(elgg_echo('DatabaseException:UnspecifiedQueryType'));\r
-\r
- // Tables\r
- if (!empty($this->tables))\r
- {\r
- foreach($this->tables as $table)\r
- $sql .= "$table, ";\r
-\r
- $sql = trim($sql, ", ");\r
- }\r
- else\r
- throw new DatabaseException(elgg_echo('DatabaseException:NoTablesSpecified'));\r
-\r
- // Joins on select queries\r
- if ($this->query_type->query_type == 'select')\r
- {\r
- if (!empty($this->joins))\r
- {\r
- foreach($this->joins as $join)\r
- $sql .= "$join ";\r
- }\r
- }\r
-\r
- // Setting values\r
- if (\r
- ($this->query_type->query_type == 'update') ||\r
- ($this->query_type->query_type == 'insert')\r
- )\r
- {\r
- $sql .= "set ";\r
-\r
- foreach ($this->sets as $set)\r
- $sql .= "$set, ";\r
-\r
- $sql = trim($sql, ", ") . " ";\r
- }\r
-\r
- // Where\r
- if (!empty($this->where))\r
- {\r
- $sql .= " where 1 ";\r
-\r
- foreach ($this->where as $where)\r
- $sql .= "$where ";\r
- }\r
-\r
- // Access control\r
- if (!empty($this->access_control))\r
- {\r
-\r
- // Catch missing Where\r
- if (empty($this->where))\r
- $sql .= " where 1 ";\r
-\r
- $sql .= "{$this->access_control} ";\r
- }\r
- else\r
- throw new DatabaseException(elgg_echo('DatabaseException:NoACL'));\r
-\r
- // Order by\r
- if (!empty($this->order))\r
- $sql .= "{$this->order} ";\r
-\r
- // Limits\r
- if (!empty($this->limit_and_offset))\r
- $sql .= "{$this->limit_and_offset} ";\r
-\r
-\r
-\r
- } catch (Exception $e) {\r
- trigger_error($e, E_USER_WARNING);\r
- }\r
-\r
-\r
- return $sql;\r
- }\r
-\r
-}\r
-\r
+<?php
+/**
+ * @class Query Provides a framework to construct complex queries in a safer environment.
+ *
+ * The usage of this class depends on the type of query you are executing, but the basic idea is to
+ * construct a query out of pluggable classes.
+ *
+ * Once constructed SQL can be generated using the toString method, this should happen automatically
+ * if you pass the Query object to get_data or similar.
+ *
+ * To construct a query, create a new Query() object and begin populating it with the various classes
+ * that define the various aspects of the query.
+ *
+ * Notes:
+ * - You do not have to specify things in any particular order, provided you specify all required
+ * components.
+ * - With database tables you do not have to specify your db prefix, this will be added automatically.
+ * - When constructing your query keep an eye on the error log - any problems will get spit out here.
+ * Note also that __toString won't let you throw Exceptions (!!!) so these are caught and echoed to
+ * the log instead.
+ *
+ * Here is an example of a select query which requests some data out of the entities table with an
+ * order and limit that uses a subset where and some normal where queries:
+ *
+ * <blockquote>
+ * // Construct the query
+ * $query = new Query();
+ *
+ * // Say which table we're interested in
+ * $query->addTable(new TableQueryComponent("entities"));
+ *
+ * // What fields are we interested in
+ * $query->addSelectField(new SelectFieldQueryComponent("entities","*"));
+ *
+ * // Add access control (Default access control uses default fields on entities table.
+ * // Note that it will error without something specified here!
+ * $query->setAccessControl(new AccessControlQueryComponent());
+ *
+ * // Set a limit and offset, may be omitted.
+ * $query->setLimitAndOffset(new LimitOffsetQueryComponent(10,0));
+ *
+ * // Specify the order, may be omitted
+ * $query->setOrder(new OrderQueryComponent("entities", "subtype", "desc"));
+ *
+ * // Construct a where query
+ * //
+ * // This demonstrates a WhereSet which lets you have sub wheres, a
+ * // WhereStatic which lets you compare a table field against a value and a
+ * // Where which lets you compare a table/field with another table/field.
+ * $query->addWhere(
+ * new WhereSetQueryComponent(
+ * array(
+ * new WhereStaticQueryComponent("entities", "subtype","=", 1),
+ * new WhereQueryComponent("entities","subtype","=", "entities", "subtype")
+ * )
+ * )
+ * );
+ *
+ * get_data($query);
+ * </blockquote>
+ *
+ * @author Curverider Ltd
+ */
+class Query
+{
+
+ /// The limit of the query
+ private $limit_and_offset;
+
+ /// Fields to return on a query
+ private $fields;
+
+ /// Tables to use in a from query
+ private $tables;
+
+ /// Join tables
+ private $joins;
+
+ /// Set values
+ private $sets;
+
+ /// Where query
+ private $where;
+
+ /// Order by
+ private $order;
+
+ /// The query type
+ private $query_type;
+
+ /// ACL
+ private $access_control;
+
+ /**
+ * Construct query & initialise variables
+ */
+ function __construct()
+ {
+ $this->fields = array();
+ $this->tables = array();
+ $this->joins = array();
+ $this->where = array();
+ $this->sets = array();
+
+ $this->setQueryType(new SelectQueryTypeQueryComponent());
+ }
+
+ /**
+ * Add limits and offsets to the query.
+ *
+ * @param LimitOffsetQueryComponent $component The limit and offset.
+ */
+ public function setLimitAndOffset(LimitOffsetQueryComponent $component) { $this->limit_and_offset = $component; }
+
+ /**
+ * Reset and set the field to the select statement.
+ *
+ * @param SelectFieldQueryComponent $component Table and field component.
+ */
+ public function setSelectField(SelectFieldQueryComponent $component)
+ {
+ $this->fields = array();
+ return $this->addSelectField($component);
+ }
+
+ /**
+ * Add a select field.
+ *
+ * @param SelectFieldQueryComponent $component Add a component.
+ */
+ public function addSelectField(SelectFieldQueryComponent $component) { $this->fields[] = $component; }
+
+ /**
+ * Add a join to the component.
+ *
+ * @param JoinQueryComponent $component The join.
+ */
+ public function addJoin(JoinQueryComponent $component) { $this->joins[] = $component; }
+
+ /**
+ * Set a field value in an update or insert statement.
+ *
+ * @param SetQueryComponent $component Fields to set.
+ */
+ public function addSet(SetQueryComponent $component) { $this->sets[] = $component; }
+
+ /**
+ * Set the query type, i.e. "select", "update", "insert" & "delete".
+ *
+ * @param QueryTypeQueryComponent $component The query type.
+ */
+ public function setQueryType(QueryTypeQueryComponent $component) { $this->query_type = $component; }
+
+ /**
+ * Attach an order component.
+ *
+ * @param OrderQueryComponent $component The order component.
+ */
+ public function setOrder(OrderQueryComponent $component) { $this->order = $component; }
+
+ /**
+ * Add a table to the query.
+ *
+ * @param TableQueryComponent $component Table to add.
+ */
+ public function addTable(TableQueryComponent $component) { $this->tables[] = $component; }
+
+ /**
+ * Add a where clause to the query.
+ *
+ * @param WhereQueryComponent $component The where component
+ */
+ public function addWhere(WhereQueryComponent $component) { $this->where[] = $component; }
+
+ /**
+ * Set access control.
+ *
+ * @param AccessControlQueryComponent $component Access control.
+ */
+ public function setAccessControl(AccessControlQueryComponent $component) { $this->access_control = $component; }
+
+ public function __toString()
+ {
+ global $CONFIG;
+
+ $sql = "";
+
+ try
+ {
+ // Query prefix & fields
+ if (!empty($this->query_type))
+ {
+ $sql .= "{$this->query_type} ";
+
+ if (!empty($this->fields))
+ {
+ $fields = "";
+
+ foreach ($this->fields as $field)
+ $fields .= "$field";
+
+ $sql .= " $fields from ";
+ }
+ else
+ throw new DatabaseException(elgg_echo('DatabaseException:SelectFieldsMissing'));
+ }
+ else
+ throw new DatabaseException(elgg_echo('DatabaseException:UnspecifiedQueryType'));
+
+ // Tables
+ if (!empty($this->tables))
+ {
+ foreach($this->tables as $table)
+ $sql .= "$table, ";
+
+ $sql = trim($sql, ", ");
+ }
+ else
+ throw new DatabaseException(elgg_echo('DatabaseException:NoTablesSpecified'));
+
+ // Joins on select queries
+ if ($this->query_type->query_type == 'select')
+ {
+ if (!empty($this->joins))
+ {
+ foreach($this->joins as $join)
+ $sql .= "$join ";
+ }
+ }
+
+ // Setting values
+ if (
+ ($this->query_type->query_type == 'update') ||
+ ($this->query_type->query_type == 'insert')
+ )
+ {
+ $sql .= "set ";
+
+ foreach ($this->sets as $set)
+ $sql .= "$set, ";
+
+ $sql = trim($sql, ", ") . " ";
+ }
+
+ // Where
+ if (!empty($this->where))
+ {
+ $sql .= " where 1 ";
+
+ foreach ($this->where as $where)
+ $sql .= "$where ";
+ }
+
+ // Access control
+ if (!empty($this->access_control))
+ {
+
+ // Catch missing Where
+ if (empty($this->where))
+ $sql .= " where 1 ";
+
+ $sql .= "{$this->access_control} ";
+ }
+ else
+ throw new DatabaseException(elgg_echo('DatabaseException:NoACL'));
+
+ // Order by
+ if (!empty($this->order))
+ $sql .= "{$this->order} ";
+
+ // Limits
+ if (!empty($this->limit_and_offset))
+ $sql .= "{$this->limit_and_offset} ";
+
+
+
+ } catch (Exception $e) {
+ trigger_error($e, E_USER_WARNING);
+ }
+
+
+ return $sql;
+ }
+
+}
+
-<?php\r
-/**\r
- * @class QueryComponent Query component superclass.\r
- * Component of a query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-abstract class QueryComponent\r
-{\r
- /**\r
- * Associative array of fields and values\r
- */\r
- private $fields;\r
-\r
- function __construct()\r
- {\r
- $this->fields = array();\r
- }\r
-\r
- /**\r
- * Class member get overloading\r
- *\r
- * @param string $name\r
- * @return mixed\r
- */\r
- function __get($name) {\r
- return $this->fields[$name];\r
- }\r
-\r
- /**\r
- * Class member set overloading\r
- *\r
- * @param string $name\r
- * @param mixed $value\r
- * @return void\r
- */\r
- function __set($name, $value) {\r
- $this->fields[$name] = $value;\r
-\r
- return true;\r
- }\r
-}\r
+<?php
+/**
+ * @class QueryComponent Query component superclass.
+ * Component of a query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+abstract class QueryComponent
+{
+ /**
+ * Associative array of fields and values
+ */
+ private $fields;
+
+ function __construct()
+ {
+ $this->fields = array();
+ }
+
+ /**
+ * Class member get overloading
+ *
+ * @param string $name
+ * @return mixed
+ */
+ function __get($name) {
+ return $this->fields[$name];
+ }
+
+ /**
+ * Class member set overloading
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return void
+ */
+ function __set($name, $value) {
+ $this->fields[$name] = $value;
+
+ return true;
+ }
+}
-<?php\r
-/**\r
- * @class QueryTypeQueryComponent\r
- * What type of query is this?\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-abstract class QueryTypeQueryComponent extends QueryComponent\r
-{\r
- function __toString()\r
- {\r
- return $this->query_type;\r
- }\r
-}\r
+<?php
+/**
+ * @class QueryTypeQueryComponent
+ * What type of query is this?
+ * @author Curverider Ltd
+ * @see Query
+ */
+abstract class QueryTypeQueryComponent extends QueryComponent
+{
+ function __toString()
+ {
+ return $this->query_type;
+ }
+}
-<?php\r
-/**\r
- * RegistrationException\r
- * Could not register a new user for whatever reason.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
+<?php
+/**
+ * RegistrationException
+ * Could not register a new user for whatever reason.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Exceptions
+ */
class RegistrationException extends InstallationException {}
\ No newline at end of file
-<?php\r
-/**\r
- * SecurityException\r
- * An Security Exception, throw when a Security Exception occurs. Subclass for specific Security Execeptions (access problems etc)\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Exceptions\r
- */\r
-class SecurityException extends Exception {}\r
+<?php
+/**
+ * SecurityException
+ * An Security Exception, throw when a Security Exception occurs. Subclass for specific Security Execeptions (access problems etc)
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class SecurityException extends Exception {}
-<?php\r
-/**\r
- * @class SelectFieldQueryComponent Class representing a select field.\r
- * This class represents a select field component.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class SelectFieldQueryComponent extends QueryComponent\r
-{\r
- /**\r
- * Construct a select field component\r
- *\r
- * @param string $table The table containing the field.\r
- * @param string $field The field or "*"\r
- */\r
- function __construct($table, $field)\r
- {\r
- global $CONFIG;\r
-\r
- $this->table = $CONFIG->dbprefix . sanitise_string($table);\r
- $this->field = sanitise_string($field);\r
- }\r
-\r
- function __toString()\r
- {\r
- return "{$this->table}.{$this->field}";\r
- }\r
-}\r
+<?php
+/**
+ * @class SelectFieldQueryComponent Class representing a select field.
+ * This class represents a select field component.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class SelectFieldQueryComponent extends QueryComponent
+{
+ /**
+ * Construct a select field component
+ *
+ * @param string $table The table containing the field.
+ * @param string $field The field or "*"
+ */
+ function __construct($table, $field)
+ {
+ global $CONFIG;
+
+ $this->table = $CONFIG->dbprefix . sanitise_string($table);
+ $this->field = sanitise_string($field);
+ }
+
+ function __toString()
+ {
+ return "{$this->table}.{$this->field}";
+ }
+}
-<?php\r
-/**\r
- * @class SelectQueryTypeQueryComponent\r
- * A select query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class SelectQueryTypeQueryComponent extends QueryTypeQueryComponent\r
-{\r
- function __construct()\r
- {\r
- $this->query_type = "SELECT";\r
- }\r
-}\r
+<?php
+/**
+ * @class SelectQueryTypeQueryComponent
+ * A select query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class SelectQueryTypeQueryComponent extends QueryTypeQueryComponent
+{
+ function __construct()
+ {
+ $this->query_type = "SELECT";
+ }
+}
-<?php\r
-/**\r
- * @class SetQueryComponent Set query.\r
- * Represents an update set query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class SetQueryComponent extends QueryComponent\r
-{\r
- /**\r
- * Construct a setting query\r
- *\r
- * @param string $table The table to modify\r
- * @param string $field The field to modify\r
- * @param mixed $value The value to set it to\r
- */\r
- function __construct($table, $field, $value)\r
- {\r
- global $CONFIG;\r
-\r
- $this->table = $CONFIG->dbprefix . sanitise_string($table);\r
- $this->field = sanitise_string($field);\r
- if (is_numeric($value))\r
- $this->value = (int)$value;\r
- else\r
- $this->value = "'".sanitise_string($value)."'";\r
- }\r
-\r
- function __toString()\r
- {\r
- return "{$this->table}.{$this->field}={$this->value}";\r
- }\r
-}\r
+<?php
+/**
+ * @class SetQueryComponent Set query.
+ * Represents an update set query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class SetQueryComponent extends QueryComponent
+{
+ /**
+ * Construct a setting query
+ *
+ * @param string $table The table to modify
+ * @param string $field The field to modify
+ * @param mixed $value The value to set it to
+ */
+ function __construct($table, $field, $value)
+ {
+ global $CONFIG;
+
+ $this->table = $CONFIG->dbprefix . sanitise_string($table);
+ $this->field = sanitise_string($field);
+ if (is_numeric($value))
+ $this->value = (int)$value;
+ else
+ $this->value = "'".sanitise_string($value)."'";
+ }
+
+ function __toString()
+ {
+ return "{$this->table}.{$this->field}={$this->value}";
+ }
+}
-<?php\r
-/**\r
- * @class SimpleQuery A wrapper for Query which provides simple interface for common functions.\r
- *\r
- * This class provides simple interface functions for constructing a (reasonably) standard database\r
- * query.\r
- *\r
- * The constructor for this class sets a number of defaults, for example sets default access controls\r
- * and a limit and offset - to change this then set it manually.\r
- *\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class SimpleQuery extends Query\r
-{\r
- function __construct()\r
- {\r
- parent::__construct();\r
-\r
- // Set a default query type (select)\r
- $this->simpleQueryType();\r
-\r
- // Set a default access control\r
- $this->simpleAccessControl();\r
-\r
- // Set default limit and offset\r
- $this->simpleLimitAndOffset();\r
- }\r
-\r
- /**\r
- * Set the query type.\r
- *\r
- * @param string $type The type of search - available are "select", "update", "delete", "insert".\r
- */\r
- public function simpleQueryType($type = "select")\r
- {\r
- $type = strtolower(sanitise_string($type));\r
-\r
- switch ($type)\r
- {\r
- case "insert" :\r
- return $this->setQueryType(InsertQueryTypeQueryComponent());\r
- break;\r
- case "delete" :\r
- return $this->setQueryType(DeleteQueryTypeQueryComponent());\r
- break;\r
- case "update" :\r
- return $this->setQueryType(UpdateQueryTypeQueryComponent());\r
- break;\r
- default: return $this->setQueryType(SelectQueryTypeQueryComponent());\r
- }\r
- }\r
-\r
- /**\r
- * Set a field to query in a select statement.\r
- *\r
- * @param string $table Table to query.\r
- * @param string $field Field in that table.\r
- */\r
- public function simpleSelectField($table, $field) { return $this->setSelectField(new SelectFieldQueryComponent($table, $field)); }\r
-\r
- /**\r
- * Add a select field to query in a select statement.\r
- *\r
- * @param string $table Table to query.\r
- * @param string $field Field in that table.\r
- */\r
- public function simpleAddSelectField($table, $field) { return $this->addSelectField(new SelectFieldQueryComponent($table, $field)); }\r
-\r
- /**\r
- * Add a set value to an update query.\r
- *\r
- * @param string $table The table to update.\r
- * @param string $field The field in the table.\r
- * @param mixed $value The value to set it to.\r
- */\r
- public function simpleSet($table, $field, $value) { return $this->addSet(new SetQueryComponent($table, $field, $value)); }\r
-\r
- /**\r
- * Add a join to the table.\r
- *\r
- * @param string $table Table one to join...\r
- * @param string $field Field 1 with...\r
- * @param string $table2 Table 2 ...\r
- * @param string $field2 Field...\r
- * @param string $operator Using this operator\r
- */\r
- public function simpleJoin($table1, $field1, $table2, $field2, $operator = "=") { return $this->addJoin(new JoinQueryComponent($table1, $field1, $table2, $field2, $operator)); }\r
-\r
- /**\r
- * Add a table to the query.\r
- *\r
- * @param string $table The table.\r
- */\r
- public function simpleTable($table) { return $this->addTable(new TableQueryComponent($table)); }\r
-\r
- /**\r
- * Compare one table/field to another table/field.\r
- *\r
- * @param string $left_table The table on the left of the operator\r
- * @param string $left_field The left field\r
- * @param string $operator The operator eg "=" or "<"\r
- * @param string $right_table The table on the right of the operator\r
- * @param string $right_field The right field\r
- * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"\r
- */\r
- public function simpleWhereOnTable($left_table, $left_field, $operator, $right_table, $right_field, $link_operator = "and") { return $this->addWhere(new WhereQueryComponent($left_table, $left_field, $operator, $right_table, $right_field, $link_operator)); }\r
-\r
- /**\r
- * Compare one table/field to a value.\r
- *\r
- * @param string $left_table The table on the left of the operator\r
- * @param string $left_field The left field\r
- * @param string $operator The operator eg "=" or "<"\r
- * @param string $value The value\r
- * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"\r
- */\r
- public function simpleWhereOnValue($left_table, $left_field, $operator, $value, $link_operator = "and") { return $this->addWhere(new WhereStaticQueryComponent($left_table, $left_field, $operator, $value, $link_operator)); }\r
-\r
- /**\r
- * Set access control.\r
- *\r
- * @param string $acl_table The table where the access control field is.\r
- * @param string $acl_field The field containing the access control.\r
- * @param string $object_owner_id_field The field in $object_owner_table containing the owner information.\r
- */\r
- public function simpleAccessControl($acl_table = "entities", $acl_field = "access_id", $object_owner_id_field = "owner_guid") { return $this->setAccessControl(new AccessControlQueryComponent($acl_table, $acl_field, $acl_table, $object_owner_id_field)); }\r
-\r
- /**\r
- * Set the limit and offset.\r
- *\r
- * @param int $limit The limit.\r
- * @param int $offset The offset.\r
- */\r
- public function simpleLimitAndOffset($limit = 25, $offset = 0) { return $this->setLimitAndOffset(new LimitOffsetQueryComponent($limit, $offset)); }\r
-\r
- /**\r
- * Set the order query.\r
- *\r
- * @param string $table The table to query\r
- * @param string $field The field to query\r
- * @param string $order Order the query\r
- */\r
- public function simpleOrder($table, $field, $order = "desc")\r
- {\r
- $table = sanitise_string($table);\r
- $field = sanitise_string($field);\r
- $order = strtolower(sanitise_string($order));\r
-\r
- return $this->setOrder(new OrderQueryComponent($table, $field, $order)); break;\r
- }\r
-}\r
+<?php
+/**
+ * @class SimpleQuery A wrapper for Query which provides simple interface for common functions.
+ *
+ * This class provides simple interface functions for constructing a (reasonably) standard database
+ * query.
+ *
+ * The constructor for this class sets a number of defaults, for example sets default access controls
+ * and a limit and offset - to change this then set it manually.
+ *
+ * @author Curverider Ltd
+ * @see Query
+ */
+class SimpleQuery extends Query
+{
+ function __construct()
+ {
+ parent::__construct();
+
+ // Set a default query type (select)
+ $this->simpleQueryType();
+
+ // Set a default access control
+ $this->simpleAccessControl();
+
+ // Set default limit and offset
+ $this->simpleLimitAndOffset();
+ }
+
+ /**
+ * Set the query type.
+ *
+ * @param string $type The type of search - available are "select", "update", "delete", "insert".
+ */
+ public function simpleQueryType($type = "select")
+ {
+ $type = strtolower(sanitise_string($type));
+
+ switch ($type)
+ {
+ case "insert" :
+ return $this->setQueryType(InsertQueryTypeQueryComponent());
+ break;
+ case "delete" :
+ return $this->setQueryType(DeleteQueryTypeQueryComponent());
+ break;
+ case "update" :
+ return $this->setQueryType(UpdateQueryTypeQueryComponent());
+ break;
+ default: return $this->setQueryType(SelectQueryTypeQueryComponent());
+ }
+ }
+
+ /**
+ * Set a field to query in a select statement.
+ *
+ * @param string $table Table to query.
+ * @param string $field Field in that table.
+ */
+ public function simpleSelectField($table, $field) { return $this->setSelectField(new SelectFieldQueryComponent($table, $field)); }
+
+ /**
+ * Add a select field to query in a select statement.
+ *
+ * @param string $table Table to query.
+ * @param string $field Field in that table.
+ */
+ public function simpleAddSelectField($table, $field) { return $this->addSelectField(new SelectFieldQueryComponent($table, $field)); }
+
+ /**
+ * Add a set value to an update query.
+ *
+ * @param string $table The table to update.
+ * @param string $field The field in the table.
+ * @param mixed $value The value to set it to.
+ */
+ public function simpleSet($table, $field, $value) { return $this->addSet(new SetQueryComponent($table, $field, $value)); }
+
+ /**
+ * Add a join to the table.
+ *
+ * @param string $table Table one to join...
+ * @param string $field Field 1 with...
+ * @param string $table2 Table 2 ...
+ * @param string $field2 Field...
+ * @param string $operator Using this operator
+ */
+ public function simpleJoin($table1, $field1, $table2, $field2, $operator = "=") { return $this->addJoin(new JoinQueryComponent($table1, $field1, $table2, $field2, $operator)); }
+
+ /**
+ * Add a table to the query.
+ *
+ * @param string $table The table.
+ */
+ public function simpleTable($table) { return $this->addTable(new TableQueryComponent($table)); }
+
+ /**
+ * Compare one table/field to another table/field.
+ *
+ * @param string $left_table The table on the left of the operator
+ * @param string $left_field The left field
+ * @param string $operator The operator eg "=" or "<"
+ * @param string $right_table The table on the right of the operator
+ * @param string $right_field The right field
+ * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"
+ */
+ public function simpleWhereOnTable($left_table, $left_field, $operator, $right_table, $right_field, $link_operator = "and") { return $this->addWhere(new WhereQueryComponent($left_table, $left_field, $operator, $right_table, $right_field, $link_operator)); }
+
+ /**
+ * Compare one table/field to a value.
+ *
+ * @param string $left_table The table on the left of the operator
+ * @param string $left_field The left field
+ * @param string $operator The operator eg "=" or "<"
+ * @param string $value The value
+ * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"
+ */
+ public function simpleWhereOnValue($left_table, $left_field, $operator, $value, $link_operator = "and") { return $this->addWhere(new WhereStaticQueryComponent($left_table, $left_field, $operator, $value, $link_operator)); }
+
+ /**
+ * Set access control.
+ *
+ * @param string $acl_table The table where the access control field is.
+ * @param string $acl_field The field containing the access control.
+ * @param string $object_owner_id_field The field in $object_owner_table containing the owner information.
+ */
+ public function simpleAccessControl($acl_table = "entities", $acl_field = "access_id", $object_owner_id_field = "owner_guid") { return $this->setAccessControl(new AccessControlQueryComponent($acl_table, $acl_field, $acl_table, $object_owner_id_field)); }
+
+ /**
+ * Set the limit and offset.
+ *
+ * @param int $limit The limit.
+ * @param int $offset The offset.
+ */
+ public function simpleLimitAndOffset($limit = 25, $offset = 0) { return $this->setLimitAndOffset(new LimitOffsetQueryComponent($limit, $offset)); }
+
+ /**
+ * Set the order query.
+ *
+ * @param string $table The table to query
+ * @param string $field The field to query
+ * @param string $order Order the query
+ */
+ public function simpleOrder($table, $field, $order = "desc")
+ {
+ $table = sanitise_string($table);
+ $field = sanitise_string($field);
+ $order = strtolower(sanitise_string($order));
+
+ return $this->setOrder(new OrderQueryComponent($table, $field, $order)); break;
+ }
+}
-<?php\r
-/**\r
- * SuccessResult\r
- * Generic success result class, extend if you want to do something special.\r
- *\r
- * @author Curverider Ltd <info@elgg.com>\r
- * @package Elgg\r
- * @subpackage Core\r
- */\r
-class SuccessResult extends GenericResult {\r
- public static $RESULT_SUCCESS = 0; // Do not change this from 0\r
-\r
- public function SuccessResult($result) {\r
- $this->setResult($result);\r
- $this->setStatusCode(SuccessResult::$RESULT_SUCCESS);\r
- }\r
-\r
- public static function getInstance($result) {\r
- // Return a new error object.\r
- return new SuccessResult($result);\r
- }\r
+<?php
+/**
+ * SuccessResult
+ * Generic success result class, extend if you want to do something special.
+ *
+ * @author Curverider Ltd <info@elgg.com>
+ * @package Elgg
+ * @subpackage Core
+ */
+class SuccessResult extends GenericResult {
+ public static $RESULT_SUCCESS = 0; // Do not change this from 0
+
+ public function SuccessResult($result) {
+ $this->setResult($result);
+ $this->setStatusCode(SuccessResult::$RESULT_SUCCESS);
+ }
+
+ public static function getInstance($result) {
+ // Return a new error object.
+ return new SuccessResult($result);
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class TableQueryComponent\r
- * List of tables to select from or insert into.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class TableQueryComponent extends QueryComponent\r
-{\r
- function __construct($table)\r
- {\r
- global $CONFIG;\r
-\r
- $this->table = $CONFIG->dbprefix . sanitise_string($table);\r
- }\r
-\r
- function __toString()\r
- {\r
- return $this->table;\r
- }\r
-}\r
+<?php
+/**
+ * @class TableQueryComponent
+ * List of tables to select from or insert into.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class TableQueryComponent extends QueryComponent
+{
+ function __construct($table)
+ {
+ global $CONFIG;
+
+ $this->table = $CONFIG->dbprefix . sanitise_string($table);
+ }
+
+ function __toString()
+ {
+ return $this->table;
+ }
+}
-<?php\r
-/**\r
- * @class UpdateQueryTypeQueryComponent\r
- * An update query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class UpdateQueryTypeQueryComponent extends QueryTypeQueryComponent\r
-{\r
- function __construct()\r
- {\r
- $this->query_type = "UPDATE";\r
- }\r
-}\r
+<?php
+/**
+ * @class UpdateQueryTypeQueryComponent
+ * An update query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class UpdateQueryTypeQueryComponent extends QueryTypeQueryComponent
+{
+ function __construct()
+ {
+ $this->query_type = "UPDATE";
+ }
+}
-<?php\r
-/**\r
- * @class WhereQueryComponent\r
- * A component of a where query.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class WhereQueryComponent extends QueryComponent\r
-{\r
- /**\r
- * A where query.\r
- *\r
- * @param string $left_table The table on the left of the operator\r
- * @param string $left_field The left field\r
- * @param string $operator The operator eg "=" or "<"\r
- * @param string $right_table The table on the right of the operator\r
- * @param string $right_field The right field\r
- * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"\r
- */\r
- function __construct($left_table, $left_field, $operator, $right_table, $right_field, $link_operator = "and")\r
- {\r
- global $CONFIG;\r
-\r
- $this->link_operator = sanitise_string($link_operator);\r
- $this->left_table = $CONFIG->dbprefix . sanitise_string($left_table);\r
- $this->left_field = sanitise_string($left_field);\r
- $this->operator = sanitise_string($operator);\r
- $this->right_table = $CONFIG->dbprefix . sanitise_string($right_table);\r
- $this->right_field = sanitise_string($right_field);\r
- }\r
-\r
- /**\r
- * Return the SQL without the link operator.\r
- */\r
- public function toStringNoLink()\r
- {\r
- return "{$this->left_table }.{$this->left_field} {$this->operator} {$this->right_table}.{$this->right_field}";\r
- }\r
-\r
- function __toString()\r
- {\r
- return "{$this->link_operator} " . $this->toStringNoLink();\r
- }\r
-}\r
+<?php
+/**
+ * @class WhereQueryComponent
+ * A component of a where query.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class WhereQueryComponent extends QueryComponent
+{
+ /**
+ * A where query.
+ *
+ * @param string $left_table The table on the left of the operator
+ * @param string $left_field The left field
+ * @param string $operator The operator eg "=" or "<"
+ * @param string $right_table The table on the right of the operator
+ * @param string $right_field The right field
+ * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"
+ */
+ function __construct($left_table, $left_field, $operator, $right_table, $right_field, $link_operator = "and")
+ {
+ global $CONFIG;
+
+ $this->link_operator = sanitise_string($link_operator);
+ $this->left_table = $CONFIG->dbprefix . sanitise_string($left_table);
+ $this->left_field = sanitise_string($left_field);
+ $this->operator = sanitise_string($operator);
+ $this->right_table = $CONFIG->dbprefix . sanitise_string($right_table);
+ $this->right_field = sanitise_string($right_field);
+ }
+
+ /**
+ * Return the SQL without the link operator.
+ */
+ public function toStringNoLink()
+ {
+ return "{$this->left_table }.{$this->left_field} {$this->operator} {$this->right_table}.{$this->right_field}";
+ }
+
+ function __toString()
+ {
+ return "{$this->link_operator} " . $this->toStringNoLink();
+ }
+}
-<?php\r
-/**\r
- * @class WhereSetQueryComponent\r
- * A where query that may contain other where queries (in brackets).\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class WhereSetQueryComponent extends WhereQueryComponent\r
-{\r
- /**\r
- * Construct a subset of wheres.\r
- *\r
- * @param array $wheres An array of WhereQueryComponent\r
- * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"\r
- */\r
- function __construct(array $wheres, $link_operator = "and")\r
- {\r
- $this->link_operator = sanitise_string($link_operator);\r
- $this->wheres = $wheres;\r
- }\r
-\r
- public function toStringNoLink()\r
- {\r
- $cnt = 0;\r
- $string = " (";\r
- foreach ($this->wheres as $where) {\r
- if (!($where instanceof WhereQueryComponent))\r
- throw new DatabaseException(elgg_echo('DatabaseException:WhereSetNonQuery'));\r
-\r
- if (!$cnt)\r
- $string.= $where->toStringNoLink();\r
- else\r
- $string.=" $where ";\r
-\r
- $cnt ++;\r
- }\r
- $string .= ")";\r
-\r
- return $string;\r
- }\r
-}\r
+<?php
+/**
+ * @class WhereSetQueryComponent
+ * A where query that may contain other where queries (in brackets).
+ * @author Curverider Ltd
+ * @see Query
+ */
+class WhereSetQueryComponent extends WhereQueryComponent
+{
+ /**
+ * Construct a subset of wheres.
+ *
+ * @param array $wheres An array of WhereQueryComponent
+ * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"
+ */
+ function __construct(array $wheres, $link_operator = "and")
+ {
+ $this->link_operator = sanitise_string($link_operator);
+ $this->wheres = $wheres;
+ }
+
+ public function toStringNoLink()
+ {
+ $cnt = 0;
+ $string = " (";
+ foreach ($this->wheres as $where) {
+ if (!($where instanceof WhereQueryComponent))
+ throw new DatabaseException(elgg_echo('DatabaseException:WhereSetNonQuery'));
+
+ if (!$cnt)
+ $string.= $where->toStringNoLink();
+ else
+ $string.=" $where ";
+
+ $cnt ++;
+ }
+ $string .= ")";
+
+ return $string;
+ }
+}
-<?php\r
-/**\r
- * @class WhereStaticQueryComponent\r
- * A component of a where query where there is no right hand table, rather a static value.\r
- * @author Curverider Ltd\r
- * @see Query\r
- */\r
-class WhereStaticQueryComponent extends WhereQueryComponent\r
-{\r
- /**\r
- * A where query.\r
- *\r
- * @param string $left_table The table on the left of the operator\r
- * @param string $left_field The left field\r
- * @param string $operator The operator eg "=" or "<"\r
- * @param string $value The value\r
- * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"\r
- */\r
- function __construct($left_table, $left_field, $operator, $value, $link_operator = "and")\r
- {\r
- global $CONFIG;\r
-\r
- $this->link_operator = sanitise_string($link_operator);\r
- $this->left_table = $CONFIG->dbprefix . sanitise_string($left_table);\r
- $this->left_field = sanitise_string($left_field);\r
- $this->operator = sanitise_string($operator);\r
- if (is_numeric($value))\r
- $this->value = (int)$value;\r
- else\r
- $this->value = "'".sanitise_string($value)."'";\r
- }\r
-\r
- /**\r
- * Return the SQL without the link operator.\r
- */\r
- public function toStringNoLink()\r
- {\r
- return "{$this->left_table }.{$this->left_field} {$this->operator} {$this->value}";\r
- }\r
-}\r
+<?php
+/**
+ * @class WhereStaticQueryComponent
+ * A component of a where query where there is no right hand table, rather a static value.
+ * @author Curverider Ltd
+ * @see Query
+ */
+class WhereStaticQueryComponent extends WhereQueryComponent
+{
+ /**
+ * A where query.
+ *
+ * @param string $left_table The table on the left of the operator
+ * @param string $left_field The left field
+ * @param string $operator The operator eg "=" or "<"
+ * @param string $value The value
+ * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"
+ */
+ function __construct($left_table, $left_field, $operator, $value, $link_operator = "and")
+ {
+ global $CONFIG;
+
+ $this->link_operator = sanitise_string($link_operator);
+ $this->left_table = $CONFIG->dbprefix . sanitise_string($left_table);
+ $this->left_field = sanitise_string($left_field);
+ $this->operator = sanitise_string($operator);
+ if (is_numeric($value))
+ $this->value = (int)$value;
+ else
+ $this->value = "'".sanitise_string($value)."'";
+ }
+
+ /**
+ * Return the SQL without the link operator.
+ */
+ public function toStringNoLink()
+ {
+ return "{$this->left_table }.{$this->left_field} {$this->operator} {$this->value}";
+ }
+}
-<?php\r
-\r
-/**\r
- * @class XMLRPCArrayParameter An array containing other XMLRPCParameter objects.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCArrayParameter extends XMLRPCParameter\r
-{\r
- /**\r
- * Construct an array.\r
- *\r
- * @param array $parameters Optional array of parameters, if not provided then addField must be used.\r
- */\r
- function __construct($parameters = NULL)\r
- {\r
- parent::__construct();\r
- \r
- if (is_array($parameters))\r
- {\r
- foreach ($parameters as $v)\r
- $this->addField($v);\r
- }\r
- }\r
- \r
- /**\r
- * Add a field to the container.\r
- *\r
- * @param XMLRPCParameter $value The value.\r
- */\r
- public function addField(XMLRPCParameter $value)\r
- {\r
- if (!is_array($this->value))\r
- $this->value = array();\r
- \r
- $this->value[] = $value;\r
- }\r
- \r
- function __toString() \r
- {\r
- $params = "";\r
- foreach ($this->value as $value)\r
- {\r
- $params .= "$value";\r
- }\r
- \r
- return "<array><data>$params</data></array>";\r
- }\r
+<?php
+
+/**
+ * @class XMLRPCArrayParameter An array containing other XMLRPCParameter objects.
+ * @author Curverider Ltd
+ */
+class XMLRPCArrayParameter extends XMLRPCParameter
+{
+ /**
+ * Construct an array.
+ *
+ * @param array $parameters Optional array of parameters, if not provided then addField must be used.
+ */
+ function __construct($parameters = NULL)
+ {
+ parent::__construct();
+
+ if (is_array($parameters))
+ {
+ foreach ($parameters as $v)
+ $this->addField($v);
+ }
+ }
+
+ /**
+ * Add a field to the container.
+ *
+ * @param XMLRPCParameter $value The value.
+ */
+ public function addField(XMLRPCParameter $value)
+ {
+ if (!is_array($this->value))
+ $this->value = array();
+
+ $this->value[] = $value;
+ }
+
+ function __toString()
+ {
+ $params = "";
+ foreach ($this->value as $value)
+ {
+ $params .= "$value";
+ }
+
+ return "<array><data>$params</data></array>";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCBase64Parameter A base 64 encoded blob of binary.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCBase64Parameter extends XMLRPCParameter\r
-{\r
- /**\r
- * Construct a base64 encoded block\r
- *\r
- * @param string $blob Unencoded binary blob\r
- */\r
- function __construct($blob)\r
- {\r
- parent::__construct();\r
- \r
- $this->value = base64_encode($blob);\r
- }\r
- \r
- function __toString() \r
- {\r
- return "<value><base64>{$value}</base64></value>";\r
- }\r
+<?php
+/**
+ * @class XMLRPCBase64Parameter A base 64 encoded blob of binary.
+ * @author Curverider Ltd
+ */
+class XMLRPCBase64Parameter extends XMLRPCParameter
+{
+ /**
+ * Construct a base64 encoded block
+ *
+ * @param string $blob Unencoded binary blob
+ */
+ function __construct($blob)
+ {
+ parent::__construct();
+
+ $this->value = base64_encode($blob);
+ }
+
+ function __toString()
+ {
+ return "<value><base64>{$value}</base64></value>";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCBoolParameter A boolean.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCBoolParameter extends XMLRPCParameter\r
-{\r
- function __construct($value)\r
- {\r
- parent::__construct();\r
- \r
- $this->value = (bool)$value; \r
- }\r
- \r
- function __toString() \r
- {\r
- $code = ($this->value) ? "1" : "0";\r
- return "<value><boolean>{$code}</boolean></value>";\r
- }\r
+<?php
+/**
+ * @class XMLRPCBoolParameter A boolean.
+ * @author Curverider Ltd
+ */
+class XMLRPCBoolParameter extends XMLRPCParameter
+{
+ function __construct($value)
+ {
+ parent::__construct();
+
+ $this->value = (bool)$value;
+ }
+
+ function __toString()
+ {
+ $code = ($this->value) ? "1" : "0";
+ return "<value><boolean>{$code}</boolean></value>";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCCall\r
- * This class represents \r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCCall\r
-{\r
- /** Method name */\r
- private $methodname;\r
- /** Parameters */\r
- private $params;\r
- \r
- /**\r
- * Construct a new XML RPC Call\r
- *\r
- * @param string $xml\r
- */\r
- function __construct($xml)\r
- {\r
- $this->parse($xml);\r
- }\r
- \r
- /**\r
- * Return the method name associated with the call.\r
- *\r
- * @return string\r
- */\r
- public function getMethodName() { return $this->methodname; }\r
- \r
- /**\r
- * Return the parameters.\r
- * Returns a nested array of XmlElement.\r
- * \r
- * @see XmlElement \r
- * @return array\r
- */\r
- public function getParameters() { return $this->params; }\r
- \r
- /**\r
- * Parse the xml into its components according to spec. \r
- * This first version is a little primitive. \r
- *\r
- * @param string $xml\r
- */\r
- private function parse($xml)\r
- {\r
- $xml = xml_to_object($xml);\r
- \r
- // sanity check\r
- if ((isset($xml->name)) && (strcasecmp($xml->name, "methodCall")!=0))\r
- throw new CallException(elgg_echo('CallException:NotRPCCall'));\r
- \r
- // method name\r
- $this->methodname = $xml->children[0]->content;\r
- \r
- // parameters \r
- $this->params = $xml->children[1]->children; \r
- }\r
+<?php
+/**
+ * @class XMLRPCCall
+ * This class represents
+ * @author Curverider Ltd
+ */
+class XMLRPCCall
+{
+ /** Method name */
+ private $methodname;
+ /** Parameters */
+ private $params;
+
+ /**
+ * Construct a new XML RPC Call
+ *
+ * @param string $xml
+ */
+ function __construct($xml)
+ {
+ $this->parse($xml);
+ }
+
+ /**
+ * Return the method name associated with the call.
+ *
+ * @return string
+ */
+ public function getMethodName() { return $this->methodname; }
+
+ /**
+ * Return the parameters.
+ * Returns a nested array of XmlElement.
+ *
+ * @see XmlElement
+ * @return array
+ */
+ public function getParameters() { return $this->params; }
+
+ /**
+ * Parse the xml into its components according to spec.
+ * This first version is a little primitive.
+ *
+ * @param string $xml
+ */
+ private function parse($xml)
+ {
+ $xml = xml_to_object($xml);
+
+ // sanity check
+ if ((isset($xml->name)) && (strcasecmp($xml->name, "methodCall")!=0))
+ throw new CallException(elgg_echo('CallException:NotRPCCall'));
+
+ // method name
+ $this->methodname = $xml->children[0]->content;
+
+ // parameters
+ $this->params = $xml->children[1]->children;
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCDateParameter An ISO8601 data and time.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCDateParameter extends XMLRPCParameter\r
-{\r
- /**\r
- * Construct a date\r
- *\r
- * @param int $timestamp The unix timestamp, or blank for "now".\r
- */\r
- function __construct($timestamp = 0)\r
- {\r
- parent::__construct();\r
- \r
- $this->value = $timestamp;\r
- if (!$timestamp)\r
- $this->value = time(); \r
- }\r
- \r
- function __toString() \r
- {\r
- $value = date('c', $this->value);\r
- return "<value><dateTime.iso8601>{$value}</dateTime.iso8601></value>";\r
- }\r
+<?php
+/**
+ * @class XMLRPCDateParameter An ISO8601 data and time.
+ * @author Curverider Ltd
+ */
+class XMLRPCDateParameter extends XMLRPCParameter
+{
+ /**
+ * Construct a date
+ *
+ * @param int $timestamp The unix timestamp, or blank for "now".
+ */
+ function __construct($timestamp = 0)
+ {
+ parent::__construct();
+
+ $this->value = $timestamp;
+ if (!$timestamp)
+ $this->value = time();
+ }
+
+ function __toString()
+ {
+ $value = date('c', $this->value);
+ return "<value><dateTime.iso8601>{$value}</dateTime.iso8601></value>";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCDoubleParameter A double precision signed floating point number.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCDoubleParameter extends XMLRPCParameter\r
-{\r
- function __construct($value)\r
- {\r
- parent::__construct();\r
- \r
- $this->value = (float)$value; \r
- }\r
- \r
- function __toString() \r
- {\r
- return "<value><double>{$this->value}</double></value>";\r
- }\r
-}\r
+<?php
+/**
+ * @class XMLRPCDoubleParameter A double precision signed floating point number.
+ * @author Curverider Ltd
+ */
+class XMLRPCDoubleParameter extends XMLRPCParameter
+{
+ function __construct($value)
+ {
+ parent::__construct();
+
+ $this->value = (float)$value;
+ }
+
+ function __toString()
+ {
+ return "<value><double>{$this->value}</double></value>";
+ }
+}
-<?php\r
-\r
-/**\r
- * @class XMLRPCErrorResponse\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCErrorResponse extends XMLRPCResponse\r
-{ \r
- /**\r
- * Set the error response and error code.\r
- *\r
- * @param string $message The message\r
- * @param int $code Error code (default = system error as defined by http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php)\r
- */\r
- function __construct($message, $code = -32400)\r
- {\r
- $this->addParameter(\r
- new XMLRPCStructParameter(\r
- array (\r
- 'faultCode' => new XMLRPCIntParameter($code),\r
- 'faultString' => new XMLRPCStringParameter($message)\r
- )\r
- )\r
- );\r
- }\r
- \r
- /**\r
- * Output to XML.\r
- */\r
- public function __toString()\r
- {\r
- return "<methodResponse><fault><value>{$this->parameters[0]}</value></fault></methodResponse>";\r
- }\r
+<?php
+
+/**
+ * @class XMLRPCErrorResponse
+ * @author Curverider Ltd
+ */
+class XMLRPCErrorResponse extends XMLRPCResponse
+{
+ /**
+ * Set the error response and error code.
+ *
+ * @param string $message The message
+ * @param int $code Error code (default = system error as defined by http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php)
+ */
+ function __construct($message, $code = -32400)
+ {
+ $this->addParameter(
+ new XMLRPCStructParameter(
+ array (
+ 'faultCode' => new XMLRPCIntParameter($code),
+ 'faultString' => new XMLRPCStringParameter($message)
+ )
+ )
+ );
+ }
+
+ /**
+ * Output to XML.
+ */
+ public function __toString()
+ {
+ return "<methodResponse><fault><value>{$this->parameters[0]}</value></fault></methodResponse>";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCIntParameter An Integer.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCIntParameter extends XMLRPCParameter\r
-{\r
- function __construct($value)\r
- {\r
- parent::__construct();\r
- \r
- $this->value = (int)$value; \r
- }\r
- \r
- function __toString() \r
- {\r
- return "<value><i4>{$this->value}</i4></value>";\r
- }\r
-}\r
+<?php
+/**
+ * @class XMLRPCIntParameter An Integer.
+ * @author Curverider Ltd
+ */
+class XMLRPCIntParameter extends XMLRPCParameter
+{
+ function __construct($value)
+ {
+ parent::__construct();
+
+ $this->value = (int)$value;
+ }
+
+ function __toString()
+ {
+ return "<value><i4>{$this->value}</i4></value>";
+ }
+}
-<?php\r
-/**\r
- * @class XMLRPCParameter Superclass for all RPC parameters.\r
- * @author Curverider Ltd\r
- */\r
-abstract class XMLRPCParameter\r
-{\r
- protected $value;\r
-\r
- function __construct() { }\r
- \r
+<?php
+/**
+ * @class XMLRPCParameter Superclass for all RPC parameters.
+ * @author Curverider Ltd
+ */
+abstract class XMLRPCParameter
+{
+ protected $value;
+
+ function __construct() { }
+
}
\ No newline at end of file
-<?php\r
-\r
-/**\r
- * @class XMLRPCResponse XML-RPC Response. \r
- * @author Curverider Ltd\r
- */\r
-abstract class XMLRPCResponse\r
-{\r
- /** An array of parameters */\r
- protected $parameters = array();\r
- \r
- /**\r
- * Add a parameter here.\r
- *\r
- * @param XMLRPCParameter $param The parameter.\r
- */\r
- public function addParameter(XMLRPCParameter $param)\r
- {\r
- if (!is_array($this->parameters))\r
- $this->parameters = array();\r
- \r
- $this->parameters[] = $param;\r
- }\r
-\r
- public function addInt($value) { $this->addParameter(new XMLRPCIntParameter($value)); }\r
- public function addString($value) { $this->addParameter(new XMLRPCStringParameter($value)); }\r
- public function addDouble($value) { $this->addParameter(new XMLRPCDoubleParameter($value)); }\r
- public function addBoolean($value) { $this->addParameter(new XMLRPCBoolParameter($value)); }\r
+<?php
+
+/**
+ * @class XMLRPCResponse XML-RPC Response.
+ * @author Curverider Ltd
+ */
+abstract class XMLRPCResponse
+{
+ /** An array of parameters */
+ protected $parameters = array();
+
+ /**
+ * Add a parameter here.
+ *
+ * @param XMLRPCParameter $param The parameter.
+ */
+ public function addParameter(XMLRPCParameter $param)
+ {
+ if (!is_array($this->parameters))
+ $this->parameters = array();
+
+ $this->parameters[] = $param;
+ }
+
+ public function addInt($value) { $this->addParameter(new XMLRPCIntParameter($value)); }
+ public function addString($value) { $this->addParameter(new XMLRPCStringParameter($value)); }
+ public function addDouble($value) { $this->addParameter(new XMLRPCDoubleParameter($value)); }
+ public function addBoolean($value) { $this->addParameter(new XMLRPCBoolParameter($value)); }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCStringParameter A string.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCStringParameter extends XMLRPCParameter\r
-{\r
- function __construct($value)\r
- {\r
- parent::__construct();\r
- \r
- $this->value = $value; \r
- }\r
- \r
- function __toString() \r
- {\r
- $value = htmlentities($this->value);\r
- return "<value><string>{$value}</string></value>";\r
- }\r
-}\r
+<?php
+/**
+ * @class XMLRPCStringParameter A string.
+ * @author Curverider Ltd
+ */
+class XMLRPCStringParameter extends XMLRPCParameter
+{
+ function __construct($value)
+ {
+ parent::__construct();
+
+ $this->value = $value;
+ }
+
+ function __toString()
+ {
+ $value = htmlentities($this->value);
+ return "<value><string>{$value}</string></value>";
+ }
+}
-<?php\r
-\r
-/**\r
- * @class XMLRPCStructParameter A structure containing other XMLRPCParameter objects.\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCStructParameter extends XMLRPCParameter\r
-{\r
- /**\r
- * Construct a struct.\r
- *\r
- * @param array $parameters Optional associated array of parameters, if not provided then addField must be used.\r
- */\r
- function __construct($parameters = NULL)\r
- {\r
- parent::__construct();\r
- \r
- if (is_array($parameters))\r
- {\r
- foreach ($parameters as $k => $v)\r
- $this->addField($k, $v);\r
- }\r
- }\r
- \r
- /**\r
- * Add a field to the container.\r
- *\r
- * @param string $name The name of the field.\r
- * @param XMLRPCParameter $value The value.\r
- */\r
- public function addField($name, XMLRPCParameter $value)\r
- {\r
- if (!is_array($this->value))\r
- $this->value = array();\r
- \r
- $this->value[$name] = $value;\r
- }\r
- \r
- function __toString() \r
- {\r
- $params = "";\r
- foreach ($this->value as $k => $v)\r
- {\r
- $params .= "<member><name>$k</name>$v</member>";\r
- }\r
- \r
- return "<value><struct>$params</struct></value>";\r
- }\r
+<?php
+
+/**
+ * @class XMLRPCStructParameter A structure containing other XMLRPCParameter objects.
+ * @author Curverider Ltd
+ */
+class XMLRPCStructParameter extends XMLRPCParameter
+{
+ /**
+ * Construct a struct.
+ *
+ * @param array $parameters Optional associated array of parameters, if not provided then addField must be used.
+ */
+ function __construct($parameters = NULL)
+ {
+ parent::__construct();
+
+ if (is_array($parameters))
+ {
+ foreach ($parameters as $k => $v)
+ $this->addField($k, $v);
+ }
+ }
+
+ /**
+ * Add a field to the container.
+ *
+ * @param string $name The name of the field.
+ * @param XMLRPCParameter $value The value.
+ */
+ public function addField($name, XMLRPCParameter $value)
+ {
+ if (!is_array($this->value))
+ $this->value = array();
+
+ $this->value[$name] = $value;
+ }
+
+ function __toString()
+ {
+ $params = "";
+ foreach ($this->value as $k => $v)
+ {
+ $params .= "<member><name>$k</name>$v</member>";
+ }
+
+ return "<value><struct>$params</struct></value>";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XMLRPCSuccessResponse\r
- * @author Curverider Ltd\r
- */\r
-class XMLRPCSuccessResponse extends XMLRPCResponse\r
-{\r
- /**\r
- * Output to XML.\r
- */\r
- public function __toString()\r
- {\r
- $params = "";\r
- foreach ($this->parameters as $param)\r
- $params .= "<param>$param</param>\n";\r
- \r
- return "<methodResponse><params>$params</params></methodResponse>";\r
- }\r
+<?php
+/**
+ * @class XMLRPCSuccessResponse
+ * @author Curverider Ltd
+ */
+class XMLRPCSuccessResponse extends XMLRPCResponse
+{
+ /**
+ * Output to XML.
+ */
+ public function __toString()
+ {
+ $params = "";
+ foreach ($this->parameters as $param)
+ $params .= "<param>$param</param>\n";
+
+ return "<methodResponse><params>$params</params></methodResponse>";
+ }
}
\ No newline at end of file
-<?php\r
-/**\r
- * @class XmlElement\r
- * A class representing an XML element for import.\r
- */\r
-class XmlElement \r
-{\r
- /** The name of the element */\r
- public $name;\r
- \r
- /** The attributes */\r
- public $attributes;\r
- \r
- /** CData */\r
- public $content;\r
- \r
- /** Child elements */\r
- public $children;\r
+<?php
+/**
+ * @class XmlElement
+ * A class representing an XML element for import.
+ */
+class XmlElement
+{
+ /** The name of the element */
+ public $name;
+
+ /** The attributes */
+ public $attributes;
+
+ /** CData */
+ public $content;
+
+ /** Child elements */
+ public $children;
};
\ No newline at end of file