From 54a3c3e7e9e70c4770010e442e95f734200d03f9 Mon Sep 17 00:00:00 2001
From: brettp
Date: Thu, 15 Oct 2009 04:41:46 +0000
Subject: Standardized gobs of files.
git-svn-id: http://code.elgg.org/elgg/trunk@3548 36083f99-b078-4883-b0ff-0f9b5a30f544
---
engine/lib/calendar.php | 951 ++++++++--------
engine/lib/configuration.php | 404 +++----
engine/lib/cron.php | 106 +-
engine/lib/exceptions.php | 321 +++---
engine/lib/export.php | 472 ++++----
engine/lib/extender.php | 851 +++++++-------
engine/lib/filestore.php | 2469 ++++++++++++++++++++--------------------
engine/lib/group.php | 1723 ++++++++++++++--------------
engine/lib/input.php | 692 ++++++------
engine/lib/install.php | 233 ++--
engine/lib/languages.php | 480 ++++----
engine/lib/location.php | 492 ++++----
engine/lib/mb_wrapper.php | 113 +-
engine/lib/memcache.php | 354 +++---
engine/lib/metadata.php | 1707 ++++++++++++++--------------
engine/lib/metastrings.php | 340 +++---
engine/lib/notification.php | 822 +++++++-------
engine/lib/objects.php | 645 ++++++-----
engine/lib/opendd.php | 691 ++++++------
engine/lib/pagehandler.php | 210 ++--
engine/lib/pageowner.php | 354 +++---
engine/lib/pam.php | 155 ++-
engine/lib/ping.php | 88 +-
engine/lib/plugins.php | 1380 +++++++++++------------
engine/lib/query.php | 449 ++++----
engine/lib/relationships.php | 1886 ++++++++++++++++---------------
engine/lib/river2.php | 548 +++++----
engine/lib/search.php | 88 +-
engine/lib/sites.php | 1085 +++++++++---------
engine/lib/social.php | 233 ++--
engine/lib/statistics.php | 205 ++--
engine/lib/system_log.php | 559 ++++-----
engine/lib/tags.php | 333 +++---
engine/lib/users.php | 2562 +++++++++++++++++++++---------------------
engine/lib/usersettings.php | 147 ++-
engine/lib/version.php | 229 ++--
engine/lib/widgets.php | 228 ++--
37 files changed, 12323 insertions(+), 12282 deletions(-)
diff --git a/engine/lib/calendar.php b/engine/lib/calendar.php
index 1f25eda44..a9d6dfadf 100644
--- a/engine/lib/calendar.php
+++ b/engine/lib/calendar.php
@@ -1,93 +1,96 @@
site_guid;
-
- $where = array();
-
- if (is_array($type)) {
- $tempwhere = "";
- if (sizeof($type))
+ public function getCalendarEndTime();
+}
+
+/**
+ * Return a timestamp for the start of a given day (defaults today).
+ *
+ */
+function get_day_start($day = null, $month = null, $year = null) {
+ return mktime(0, 0, 0, $month, $day, $year);
+}
+
+/**
+ * Return a timestamp for the end of a given day (defaults today).
+ *
+ */
+function get_day_end($day = null, $month = null, $year = null) {
+ return mktime(23, 59, 59, $month, $day, $year);
+}
+
+/**
+ * Return the notable entities for a given time period.
+ *
+ * @param int $start_time The start time as a unix timestamp.
+ * @param int $end_time The end time as a unix timestamp.
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param string $order_by The field to order by; by default, time_created desc
+ * @param int $limit The number of entities to return; 10 by default
+ * @param int $offset The indexing offset, 0 by default
+ * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param int|array $container_guid The container or containers to get entities from (default: all containers).
+ */
+function get_notable_entities($start_time, $end_time, $type = "", $subtype = "", $owner_guid = 0, $order_by = "asc", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null) {
+ global $CONFIG;
+
+ if ($subtype === false || $subtype === null || $subtype === 0) {
+ return false;
+ }
+
+ $start_time = (int)$start_time;
+ $end_time = (int)$end_time;
+ $order_by = sanitise_string($order_by);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0) {
+ $site_guid = $CONFIG->site_guid;
+ }
+
+ $where = array();
+
+ if (is_array($type)) {
+ $tempwhere = "";
+ if (sizeof($type)) {
foreach($type as $typekey => $subtypearray) {
foreach($subtypearray as $subtypeval) {
$typekey = sanitise_string($typekey);
@@ -98,397 +101,429 @@
}
if (!empty($tempwhere)) $tempwhere .= " or ";
$tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
- }
+ }
}
- if (!empty($tempwhere)) $where[] = "({$tempwhere})";
-
- } else {
-
- $type = sanitise_string($type);
- $subtype = get_subtype_id($type, $subtype);
-
- if ($type != "")
- $where[] = "e.type='$type'";
- if ($subtype!=="")
- $where[] = "e.subtype=$subtype";
-
}
-
- if ($owner_guid != "") {
- if (!is_array($owner_guid)) {
- $owner_array = array($owner_guid);
- $owner_guid = (int) $owner_guid;
- $where[] = "e.owner_guid = '$owner_guid'";
- } else if (sizeof($owner_guid) > 0) {
- $owner_array = array_map('sanitise_int', $owner_guid);
- // Cast every element to the owner_guid array to int
- $owner_guid = implode(",",$owner_guid); //
- $where[] = "e.owner_guid in ({$owner_guid})" ; //
- }
- if (is_null($container_guid)) {
- $container_guid = $owner_array;
- }
+ if (!empty($tempwhere)) {
+ $where[] = "({$tempwhere})";
}
-
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
-
- if (!is_null($container_guid)) {
- if (is_array($container_guid)) {
- foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
- $where[] = "e.container_guid in (" . implode(",",$container_guid) . ")";
- } else {
- $container_guid = (int) $container_guid;
- $where[] = "e.container_guid = {$container_guid}";
- }
- }
-
- // Add the calendar stuff
- $cal_join = "
- JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
- JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
- JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
-
- JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
- JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
- JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
- ";
- $where[] = "cal_start_name.string='calendar_start'";
- $where[] = "cal_start_value.string>=$start_time";
- $where[] = "cal_end_name.string='calendar_end'";
- $where[] = "cal_end_value.string <= $end_time";
-
-
- if (!$count) {
- $query = "SELECT e.* from {$CONFIG->dbprefix}entities e $cal_join where ";
- } else {
- $query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e $cal_join where ";
+ } else {
+ $type = sanitise_string($type);
+ $subtype = get_subtype_id($type, $subtype);
+
+ if ($type != "") {
+ $where[] = "e.type='$type'";
}
- foreach ($where as $w)
- $query .= " $w and ";
-
- $query .= get_access_sql_suffix('e'); // Add access controls
-
- if (!$count) {
- $query .= " order by n.calendar_start $order_by";
- if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
- $dt = get_data($query, "entity_row_to_elggstar");
- return $dt;
- } else {
- $total = get_data_row($query);
- return $total->total;
+
+ if ($subtype!=="") {
+ $where[] = "e.subtype=$subtype";
}
-
}
-
- /**
- * Return the notable entities for a given time period based on an item of metadata.
- *
- * @param int $start_time The start time as a unix timestamp.
- * @param int $end_time The end time as a unix timestamp.
- * @param mixed $meta_name
- * @param mixed $meta_value
- * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
- * @param string $entity_subtype The subtype of the entity.
- * @param int $limit
- * @param int $offset
- * @param string $order_by Optional ordering.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
- *
- * @return int|array A list of entities, or a count if $count is set to true
- */
- function get_notable_entities_from_metadata($start_time, $end_time, $meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false)
- {
- global $CONFIG;
-
- $meta_n = get_metastring_id($meta_name);
- $meta_v = get_metastring_id($meta_value);
-
- $start_time = (int)$start_time;
- $end_time = (int)$end_time;
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- $limit = (int)$limit;
- $offset = (int)$offset;
- if ($order_by == "") $order_by = "e.time_created desc";
- $order_by = sanitise_string($order_by);
- $site_guid = (int) $site_guid;
- if ((is_array($owner_guid) && (count($owner_guid)))) {
- foreach($owner_guid as $key => $guid) {
- $owner_guid[$key] = (int) $guid;
- }
- } else {
+
+ if ($owner_guid != "") {
+ if (!is_array($owner_guid)) {
+ $owner_array = array($owner_guid);
$owner_guid = (int) $owner_guid;
+ $where[] = "e.owner_guid = '$owner_guid'";
+ } else if (sizeof($owner_guid) > 0) {
+ $owner_array = array_map('sanitise_int', $owner_guid);
+ // Cast every element to the owner_guid array to int
+ $owner_guid = implode(",",$owner_guid); //
+ $where[] = "e.owner_guid in ({$owner_guid})" ; //
}
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- //$access = get_access_list();
-
- $where = array();
-
- if ($entity_type!="")
- $where[] = "e.type='$entity_type'";
- if ($entity_subtype)
- $where[] = "e.subtype=$entity_subtype";
- if ($meta_name!="")
- $where[] = "m.name_id='$meta_n'";
- if ($meta_value!="")
- $where[] = "m.value_id='$meta_v'";
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
- if (is_array($owner_guid)) {
- $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
- } else if ($owner_guid > 0)
- $where[] = "e.container_guid = {$owner_guid}";
-
- // Add the calendar stuff
- $cal_join = "
- JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
- JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
- JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
-
- JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
- JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
- JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
- ";
- $where[] = "cal_start_name.string='calendar_start'";
- $where[] = "cal_start_value.string>=$start_time";
- $where[] = "cal_end_name.string='calendar_end'";
- $where[] = "cal_end_value.string <= $end_time";
-
- if (!$count) {
- $query = "SELECT distinct e.* ";
- } else {
- $query = "SELECT count(distinct e.guid) as total ";
+ if (is_null($container_guid)) {
+ $container_guid = $owner_array;
}
-
- $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid $cal_join where";
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix("e"); // Add access controls
- $query .= ' and ' . get_access_sql_suffix("m"); // Add access controls
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
+ }
+
+ if ($site_guid > 0) {
+ $where[] = "e.site_guid = {$site_guid}";
+ }
+
+ if (!is_null($container_guid)) {
+ if (is_array($container_guid)) {
+ foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
+ $where[] = "e.container_guid in (" . implode(",",$container_guid) . ")";
} else {
- if ($row = get_data_row($query))
- return $row->total;
+ $container_guid = (int) $container_guid;
+ $where[] = "e.container_guid = {$container_guid}";
}
- return false;
-
}
-
- /**
- * Return the notable entities for a given time period based on their relationship.
- *
- * @param int $start_time The start time as a unix timestamp.
- * @param int $end_time The end time as a unix timestamp.
- * @param string $relationship The relationship eg "friends_of"
- * @param int $relationship_guid The guid of the entity to use query
- * @param bool $inverse_relationship Reverse the normal function of the query to instead say "give me all entities for whome $relationship_guid is a $relationship of"
- * @param string $type
- * @param string $subtype
- * @param int $owner_guid
- * @param string $order_by
- * @param int $limit
- * @param int $offset
- * @param boolean $count Set to true if you want to count the number of entities instead (default false)
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @return array|int|false An array of entities, or the number of entities, or false on failure
- */
- function get_noteable_entities_from_relationship($start_time, $end_time, $relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0)
- {
- global $CONFIG;
-
- $start_time = (int)$start_time;
- $end_time = (int)$end_time;
- $relationship = sanitise_string($relationship);
- $relationship_guid = (int)$relationship_guid;
- $inverse_relationship = (bool)$inverse_relationship;
- $type = sanitise_string($type);
- $subtype = get_subtype_id($type, $subtype);
- $owner_guid = (int)$owner_guid;
- if ($order_by == "") $order_by = "time_created desc";
- $order_by = sanitise_string($order_by);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- //$access = get_access_list();
-
- $where = array();
-
- if ($relationship!="")
- $where[] = "r.relationship='$relationship'";
- if ($relationship_guid)
- $where[] = ($inverse_relationship ? "r.guid_two='$relationship_guid'" : "r.guid_one='$relationship_guid'");
- if ($type != "")
- $where[] = "e.type='$type'";
- if ($subtype)
- $where[] = "e.subtype=$subtype";
- if ($owner_guid != "")
- $where[] = "e.container_guid='$owner_guid'";
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
-
- // Add the calendar stuff
- $cal_join = "
- JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
- JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
- JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
-
- JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
- JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
- JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
- ";
- $where[] = "cal_start_name.string='calendar_start'";
- $where[] = "cal_start_value.string>=$start_time";
- $where[] = "cal_end_name.string='calendar_end'";
- $where[] = "cal_end_value.string <= $end_time";
-
- // Select what we're joining based on the options
- $joinon = "e.guid = r.guid_one";
- if (!$inverse_relationship)
- $joinon = "e.guid = r.guid_two";
-
- if ($count) {
- $query = "SELECT count(distinct e.guid) as total ";
- } else {
- $query = "SELECT distinct e.* ";
+
+ // Add the calendar stuff
+ $cal_join = "
+ JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
+ JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
+ JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
+
+ JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
+ JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
+ JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
+ ";
+ $where[] = "cal_start_name.string='calendar_start'";
+ $where[] = "cal_start_value.string>=$start_time";
+ $where[] = "cal_end_name.string='calendar_end'";
+ $where[] = "cal_end_value.string <= $end_time";
+
+
+ if (!$count) {
+ $query = "SELECT e.* from {$CONFIG->dbprefix}entities e $cal_join where ";
+ } else {
+ $query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e $cal_join where ";
+ }
+ foreach ($where as $w) {
+ $query .= " $w and ";
+ }
+
+ $query .= get_access_sql_suffix('e'); // Add access controls
+
+ if (!$count) {
+ $query .= " order by n.calendar_start $order_by";
+ // Add order and limit
+ if ($limit) {
+ $query .= " limit $offset, $limit";
}
- $query .= " from {$CONFIG->dbprefix}entity_relationships r JOIN {$CONFIG->dbprefix}entities e on $joinon $cal_join where ";
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix("e"); // Add access controls
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
- } else {
- if ($count = get_data_row($query)) {
- return $count->total;
- }
+ $dt = get_data($query, "entity_row_to_elggstar");
+
+ return $dt;
+ } else {
+ $total = get_data_row($query);
+ return $total->total;
+ }
+}
+
+/**
+ * Return the notable entities for a given time period based on an item of metadata.
+ *
+ * @param int $start_time The start time as a unix timestamp.
+ * @param int $end_time The end time as a unix timestamp.
+ * @param mixed $meta_name
+ * @param mixed $meta_value
+ * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
+ * @param string $entity_subtype The subtype of the entity.
+ * @param int $limit
+ * @param int $offset
+ * @param string $order_by Optional ordering.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ *
+ * @return int|array A list of entities, or a count if $count is set to true
+ */
+function get_notable_entities_from_metadata($start_time, $end_time, $meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
+ global $CONFIG;
+
+ $meta_n = get_metastring_id($meta_name);
+ $meta_v = get_metastring_id($meta_value);
+
+ $start_time = (int)$start_time;
+ $end_time = (int)$end_time;
+ $entity_type = sanitise_string($entity_type);
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ if ($order_by == "") {
+ $order_by = "e.time_created desc";
+ }
+ $order_by = sanitise_string($order_by);
+ $site_guid = (int) $site_guid;
+ if ((is_array($owner_guid) && (count($owner_guid)))) {
+ foreach($owner_guid as $key => $guid) {
+ $owner_guid[$key] = (int) $guid;
}
- return false;
+ } else {
+ $owner_guid = (int) $owner_guid;
}
-
- /**
- * Get all entities for today.
- *
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param string $order_by The field to order by; by default, time_created desc
- * @param int $limit The number of entities to return; 10 by default
- * @param int $offset The indexing offset, 0 by default
- * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param int|array $container_guid The container or containers to get entities from (default: all containers).
- */
- function get_todays_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null)
- {
- $day_start = get_day_start();
- $day_end = get_day_end();
-
- return get_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $order_by, $limit, $offset, $count, $site_guid, $container_guid);
- }
-
- /**
- * Get entities for today from metadata.
- *
- * @param mixed $meta_name
- * @param mixed $meta_value
- * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
- * @param string $entity_subtype The subtype of the entity.
- * @param int $limit
- * @param int $offset
- * @param string $order_by Optional ordering.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
- *
- * @return int|array A list of entities, or a count if $count is set to true
- */
- function get_todays_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false)
- {
- $day_start = get_day_start();
- $day_end = get_day_end();
-
- return get_notable_entities_from_metadata($day_start, $day_end, $meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, $order_by, $site_guid, $count);
- }
-
- /**
- * Get entities for today from a relationship
- *
- * @param string $relationship The relationship eg "friends_of"
- * @param int $relationship_guid The guid of the entity to use query
- * @param bool $inverse_relationship Reverse the normal function of the query to instead say "give me all entities for whome $relationship_guid is a $relationship of"
- * @param string $type
- * @param string $subtype
- * @param int $owner_guid
- * @param string $order_by
- * @param int $limit
- * @param int $offset
- * @param boolean $count Set to true if you want to count the number of entities instead (default false)
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @return array|int|false An array of entities, or the number of entities, or false on failure
- */
- function get_todays_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0)
- {
- $day_start = get_day_start();
- $day_end = get_day_end();
-
- return get_notable_entities_from_relationship($day_start, $day_end, $relationship, $relationship_guid, $inverse_relationship, $type, $subtype, $owner_guid, $order_by, $limit, $offset, $count, $site_guid);
- }
-
- /**
- * Returns a viewable list of entities for a given time period.
- *
- * @see elgg_view_entity_list
- *
- * @param int $start_time The start time as a unix timestamp.
- * @param int $end_time The end time as a unix timestamp.
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param int $limit The number of entities to display per page (default: 10)
- * @param true|false $fullview Whether or not to display the full view (default: true)
- * @param true|false $viewtypetoggle Whether or not to allow gallery view
- * @param true|false $pagination Display pagination? Default: true
- * @return string A viewable list of entities
- */
- function list_notable_entities($start_time, $end_time, $type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $navigation = true) {
-
- $offset = (int) get_input('offset');
- $count = get_notable_entities($start_time, $end_time, $type, $subtype, $owner_guid, "", $limit, $offset, true);
- $entities = get_notable_entities($start_time, $end_time,$type, $subtype, $owner_guid, "", $limit, $offset);
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $navigation);
-
+ if ($site_guid == 0) {
+ $site_guid = $CONFIG->site_guid;
}
-
- /**
- * Return a list of today's entities.
- *
- * @see list_notable_entities
- *
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param int $limit The number of entities to display per page (default: 10)
- * @param true|false $fullview Whether or not to display the full view (default: true)
- * @param true|false $viewtypetoggle Whether or not to allow gallery view
- * @param true|false $pagination Display pagination? Default: true
- * @return string A viewable list of entities
- */
- function list_todays_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $navigation = true) {
-
- $day_start = get_day_start();
- $day_end = get_day_end();
-
- return list_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $limit, $fullview, $viewtypetoggle, $navigation);
- }
-?>
\ No newline at end of file
+
+ //$access = get_access_list();
+
+ $where = array();
+
+ if ($entity_type!="") {
+ $where[] = "e.type='$entity_type'";
+ }
+
+ if ($entity_subtype) {
+ $where[] = "e.subtype=$entity_subtype";
+ }
+
+ if ($meta_name!="") {
+ $where[] = "m.name_id='$meta_n'";
+ }
+
+ if ($meta_value!="") {
+ $where[] = "m.value_id='$meta_v'";
+ }
+
+ if ($site_guid > 0) {
+ $where[] = "e.site_guid = {$site_guid}";
+ }
+
+ if (is_array($owner_guid)) {
+ $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
+ } else if ($owner_guid > 0) {
+ $where[] = "e.container_guid = {$owner_guid}";
+ }
+
+ // Add the calendar stuff
+ $cal_join = "
+ JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
+ JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
+ JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
+
+ JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
+ JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
+ JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
+ ";
+
+ $where[] = "cal_start_name.string='calendar_start'";
+ $where[] = "cal_start_value.string>=$start_time";
+ $where[] = "cal_end_name.string='calendar_end'";
+ $where[] = "cal_end_value.string <= $end_time";
+
+ if (!$count) {
+ $query = "SELECT distinct e.* ";
+ } else {
+ $query = "SELECT count(distinct e.guid) as total ";
+ }
+
+ $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid $cal_join where";
+ foreach ($where as $w) {
+ $query .= " $w and ";
+ }
+
+ // Add access controls
+ $query .= get_access_sql_suffix("e");
+ $query .= ' and ' . get_access_sql_suffix("m");
+
+ if (!$count) {
+ // Add order and limit
+ $query .= " order by $order_by limit $offset, $limit";
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($row = get_data_row($query)) {
+ return $row->total;
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Return the notable entities for a given time period based on their relationship.
+ *
+ * @param int $start_time The start time as a unix timestamp.
+ * @param int $end_time The end time as a unix timestamp.
+ * @param string $relationship The relationship eg "friends_of"
+ * @param int $relationship_guid The guid of the entity to use query
+ * @param bool $inverse_relationship Reverse the normal function of the query to instead say "give me all entities for whome $relationship_guid is a $relationship of"
+ * @param string $type
+ * @param string $subtype
+ * @param int $owner_guid
+ * @param string $order_by
+ * @param int $limit
+ * @param int $offset
+ * @param boolean $count Set to true if you want to count the number of entities instead (default false)
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @return array|int|false An array of entities, or the number of entities, or false on failure
+ */
+function get_noteable_entities_from_relationship($start_time, $end_time, $relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0) {
+ global $CONFIG;
+
+ $start_time = (int)$start_time;
+ $end_time = (int)$end_time;
+ $relationship = sanitise_string($relationship);
+ $relationship_guid = (int)$relationship_guid;
+ $inverse_relationship = (bool)$inverse_relationship;
+ $type = sanitise_string($type);
+ $subtype = get_subtype_id($type, $subtype);
+ $owner_guid = (int)$owner_guid;
+ if ($order_by == "") {
+ $order_by = "time_created desc";
+ }
+ $order_by = sanitise_string($order_by);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0) {
+ $site_guid = $CONFIG->site_guid;
+ }
+
+ //$access = get_access_list();
+
+ $where = array();
+
+ if ($relationship!="") {
+ $where[] = "r.relationship='$relationship'";
+ }
+ if ($relationship_guid) {
+ $where[] = ($inverse_relationship ? "r.guid_two='$relationship_guid'" : "r.guid_one='$relationship_guid'");
+ }
+ if ($type != "") {
+ $where[] = "e.type='$type'";
+ }
+ if ($subtype) {
+ $where[] = "e.subtype=$subtype";
+ }
+ if ($owner_guid != "") {
+ $where[] = "e.container_guid='$owner_guid'";
+ }
+ if ($site_guid > 0) {
+ $where[] = "e.site_guid = {$site_guid}";
+ }
+
+ // Add the calendar stuff
+ $cal_join = "
+ JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
+ JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
+ JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
+
+ JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
+ JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
+ JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
+ ";
+ $where[] = "cal_start_name.string='calendar_start'";
+ $where[] = "cal_start_value.string>=$start_time";
+ $where[] = "cal_end_name.string='calendar_end'";
+ $where[] = "cal_end_value.string <= $end_time";
+
+ // Select what we're joining based on the options
+ $joinon = "e.guid = r.guid_one";
+ if (!$inverse_relationship) {
+ $joinon = "e.guid = r.guid_two";
+ }
+
+ if ($count) {
+ $query = "SELECT count(distinct e.guid) as total ";
+ } else {
+ $query = "SELECT distinct e.* ";
+ }
+ $query .= " from {$CONFIG->dbprefix}entity_relationships r JOIN {$CONFIG->dbprefix}entities e on $joinon $cal_join where ";
+ foreach ($where as $w) {
+ $query .= " $w and ";
+ }
+ // Add access controls
+ $query .= get_access_sql_suffix("e");
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($count = get_data_row($query)) {
+ return $count->total;
+ }
+ }
+ return false;
+}
+
+/**
+ * Get all entities for today.
+ *
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param string $order_by The field to order by; by default, time_created desc
+ * @param int $limit The number of entities to return; 10 by default
+ * @param int $offset The indexing offset, 0 by default
+ * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param int|array $container_guid The container or containers to get entities from (default: all containers).
+ */
+function get_todays_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null) {
+ $day_start = get_day_start();
+ $day_end = get_day_end();
+
+ return get_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $order_by, $limit, $offset, $count, $site_guid, $container_guid);
+}
+
+/**
+ * Get entities for today from metadata.
+ *
+ * @param mixed $meta_name
+ * @param mixed $meta_value
+ * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
+ * @param string $entity_subtype The subtype of the entity.
+ * @param int $limit
+ * @param int $offset
+ * @param string $order_by Optional ordering.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ *
+ * @return int|array A list of entities, or a count if $count is set to true
+ */
+function get_todays_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
+ $day_start = get_day_start();
+ $day_end = get_day_end();
+
+ return get_notable_entities_from_metadata($day_start, $day_end, $meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, $order_by, $site_guid, $count);
+}
+
+/**
+ * Get entities for today from a relationship
+ *
+ * @param string $relationship The relationship eg "friends_of"
+ * @param int $relationship_guid The guid of the entity to use query
+ * @param bool $inverse_relationship Reverse the normal function of the query to instead say "give me all entities for whome $relationship_guid is a $relationship of"
+ * @param string $type
+ * @param string $subtype
+ * @param int $owner_guid
+ * @param string $order_by
+ * @param int $limit
+ * @param int $offset
+ * @param boolean $count Set to true if you want to count the number of entities instead (default false)
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @return array|int|false An array of entities, or the number of entities, or false on failure
+ */
+function get_todays_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0) {
+ $day_start = get_day_start();
+ $day_end = get_day_end();
+
+ return get_notable_entities_from_relationship($day_start, $day_end, $relationship, $relationship_guid, $inverse_relationship, $type, $subtype, $owner_guid, $order_by, $limit, $offset, $count, $site_guid);
+}
+
+/**
+ * Returns a viewable list of entities for a given time period.
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param int $start_time The start time as a unix timestamp.
+ * @param int $end_time The end time as a unix timestamp.
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param int $limit The number of entities to display per page (default: 10)
+ * @param true|false $fullview Whether or not to display the full view (default: true)
+ * @param true|false $viewtypetoggle Whether or not to allow gallery view
+ * @param true|false $pagination Display pagination? Default: true
+ * @return string A viewable list of entities
+ */
+function list_notable_entities($start_time, $end_time, $type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $navigation = true) {
+ $offset = (int) get_input('offset');
+ $count = get_notable_entities($start_time, $end_time, $type, $subtype, $owner_guid, "", $limit, $offset, true);
+ $entities = get_notable_entities($start_time, $end_time,$type, $subtype, $owner_guid, "", $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $navigation);
+}
+
+/**
+ * Return a list of today's entities.
+ *
+ * @see list_notable_entities
+ *
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param int $limit The number of entities to display per page (default: 10)
+ * @param true|false $fullview Whether or not to display the full view (default: true)
+ * @param true|false $viewtypetoggle Whether or not to allow gallery view
+ * @param true|false $pagination Display pagination? Default: true
+ * @return string A viewable list of entities
+ */
+function list_todays_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $navigation = true) {
+ $day_start = get_day_start();
+ $day_end = get_day_end();
+
+ return list_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $limit, $fullview, $viewtypetoggle, $navigation);
+}
\ No newline at end of file
diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php
index 9aa5d2174..17b3cd04a 100644
--- a/engine/lib/configuration.php
+++ b/engine/lib/configuration.php
@@ -1,213 +1,213 @@
site_id;
-
- return delete_data("delete from {$CONFIG->dbprefix}config where name='$name' and site_guid=$site_guid");
- }
+/**
+ * Unset a config option.
+ *
+ * @param string $name The name of the field.
+ * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default).
+ * @return mixed
+ */
+function unset_config($name, $site_guid = 0) {
+ global $CONFIG;
+
+ $name = mysql_real_escape_string($name);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0) {
+ $site_guid = (int) $CONFIG->site_id;
+ }
+
+ return delete_data("delete from {$CONFIG->dbprefix}config where name='$name' and site_guid=$site_guid");
+}
+
+/**
+ * Sets a configuration value
+ *
+ * @param string $name The name of the configuration value
+ * @param string $value Its value
+ * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
+ * @return false|int 1 or false depending on success or failure
+ */
+function set_config($name, $value, $site_guid = 0) {
+ global $CONFIG;
+
+ // Unset existing
+ unset_config($name,$site_guid);
+
+ $name = mysql_real_escape_string($name);
+ $value = mysql_real_escape_string($value);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0) {
+ $site_guid = (int) $CONFIG->site_id;
+ }
+ $CONFIG->$name = $value;
+ $value = sanitise_string(serialize($value));
+
+ return insert_data("insert into {$CONFIG->dbprefix}config set name = '{$name}', value = '{$value}', site_guid = {$site_guid}");
+}
+
+/**
+ * Gets a configuration value
+ *
+ * @param string $name The name of the config value
+ * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
+ * @return mixed|false Depending on success
+ */
+function get_config($name, $site_guid = 0) {
+ global $CONFIG;
- /**
- * Sets a configuration value
- *
- * @param string $name The name of the configuration value
- * @param string $value Its value
- * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
- * @return false|int 1 or false depending on success or failure
- */
- function set_config($name, $value, $site_guid = 0) {
-
- global $CONFIG;
-
- // Unset existing
- unset_config($name,$site_guid);
-
- $name = mysql_real_escape_string($name);
- $value = mysql_real_escape_string($value);
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = (int) $CONFIG->site_id;
- $CONFIG->$name = $value;
- $value = sanitise_string(serialize($value));
-
- return insert_data("insert into {$CONFIG->dbprefix}config set name = '{$name}', value = '{$value}', site_guid = {$site_guid}");
-
+ if (isset($CONFIG->$name)) {
+ return $CONFIG->$name;
+ }
+ $name = mysql_real_escape_string($name);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0) {
+ $site_guid = (int) $CONFIG->site_id;
+ }
+ if ($result = get_data_row("SELECT value FROM {$CONFIG->dbprefix}config
+ WHERE name = '{$name}' and site_guid = {$site_guid}")) {
+ $result = $result->value;
+ $result = unserialize($result->value);
+ $CONFIG->$name = $result;
+ return $result;
+ }
+
+ return false;
+}
+
+/**
+ * Gets all the configuration details in the config database for a given site.
+ *
+ * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
+ */
+function get_all_config($site_guid = 0) {
+ global $CONFIG;
+
+ $site_guid = (int) $site_guid;
+
+ if ($site_guid == 0) {
+ $site_guid = (int) $CONFIG->site_id;
+ }
+
+ if ($result = get_data("SELECT * from {$CONFIG->dbprefix}config where site_guid = {$site_guid}")) {
+ foreach ($result as $r) {
+ $name = $r->name;
+ $value = $r->value;
+ $CONFIG->$name = unserialize($value);
}
- /**
- * Gets a configuration value
- *
- * @param string $name The name of the config value
- * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
- * @return mixed|false Depending on success
- */
- function get_config($name, $site_guid = 0) {
-
- global $CONFIG;
- if (isset($CONFIG->$name))
- return $CONFIG->$name;
- $name = mysql_real_escape_string($name);
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = (int) $CONFIG->site_id;
- if ($result = get_data_row("SELECT value from {$CONFIG->dbprefix}config where name = '{$name}' and site_guid = {$site_guid}")) {
- $result = $result->value;
- $result = unserialize($result->value);
- $CONFIG->$name = $result;
- return $result;
- }
- return false;
-
+ return true;
+ }
+ return false;
+}
+
+/**
+ * If certain configuration elements don't exist, autodetect sensible defaults
+ *
+ * @uses $CONFIG The main configuration global
+ *
+ */
+function set_default_config() {
+ global $CONFIG;
+
+ if (empty($CONFIG->path)) {
+ $CONFIG->path = str_replace("\\","/",dirname(dirname(dirname(__FILE__)))) . "/";
+ }
+
+ if (empty($CONFIG->viewpath)) {
+ $CONFIG->viewpath = $CONFIG->path . "views/";
+ }
+
+ if (empty($CONFIG->pluginspath)) {
+ $CONFIG->pluginspath = $CONFIG->path . "mod/";
+ }
+
+ if (empty($CONFIG->wwwroot)) {
+ /*
+ $CONFIG->wwwroot = "http://" . $_SERVER['SERVER_NAME'];
+
+ $request = $_SERVER['REQUEST_URI'];
+
+ if (strripos($request,"/") < (strlen($request) - 1)) {
+ // addressing a file directly, not a dir
+ $request = substr($request, 0, strripos($request,"/")+1);
}
-
- /**
- * Gets all the configuration details in the config database for a given site.
- *
- * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
- */
- function get_all_config($site_guid = 0)
- {
- global $CONFIG;
-
- $site_guid = (int) $site_guid;
-
- if ($site_guid == 0)
- $site_guid = (int) $CONFIG->site_id;
-
- if ($result = get_data("SELECT * from {$CONFIG->dbprefix}config where site_guid = {$site_guid}")) {
- foreach ($result as $r)
- {
- $name = $r->name;
- $value = $r->value;
- $CONFIG->$name = unserialize($value);
- }
-
- return true;
- }
- return false;
+
+ $CONFIG->wwwroot .= $request;
+ */
+ $pathpart = str_replace("//","/",str_replace($_SERVER['DOCUMENT_ROOT'],"",$CONFIG->path));
+ if (substr($pathpart,0,1) != "/") {
+ $pathpart = "/" . $pathpart;
}
+ $CONFIG->wwwroot = "http://" . $_SERVER['HTTP_HOST'] . $pathpart;
+ }
+
+ if (empty($CONFIG->url)) {
+ $CONFIG->url = $CONFIG->wwwroot;
+ }
+
+ if (empty($CONFIG->sitename)) {
+ $CONFIG->sitename = "New Elgg site";
+ }
+
+ if (empty($CONFIG->language)) {
+ $CONFIG->language = "en";
+ }
+}
- /**
- * If certain configuration elements don't exist, autodetect sensible defaults
- *
- * @uses $CONFIG The main configuration global
- *
- */
- function set_default_config() {
-
- global $CONFIG;
- if (empty($CONFIG->path))
- $CONFIG->path = str_replace("\\","/",dirname(dirname(dirname(__FILE__)))) . "/";
-
- if (empty($CONFIG->viewpath))
- $CONFIG->viewpath = $CONFIG->path . "views/";
-
- if (empty($CONFIG->pluginspath))
- $CONFIG->pluginspath = $CONFIG->path . "mod/";
-
- if (empty($CONFIG->wwwroot)) {
- /*
- $CONFIG->wwwroot = "http://" . $_SERVER['SERVER_NAME'];
-
- $request = $_SERVER['REQUEST_URI'];
-
- if (strripos($request,"/") < (strlen($request) - 1)) {
- // addressing a file directly, not a dir
- $request = substr($request, 0, strripos($request,"/")+1);
- }
-
- $CONFIG->wwwroot .= $request;
- */
- $pathpart = str_replace("//","/",str_replace($_SERVER['DOCUMENT_ROOT'],"",$CONFIG->path));
- if (substr($pathpart,0,1) != "/") $pathpart = "/" . $pathpart;
- $CONFIG->wwwroot = "http://" . $_SERVER['HTTP_HOST'] . $pathpart;
-
- }
-
- if (empty($CONFIG->url))
- $CONFIG->url = $CONFIG->wwwroot;
-
- if (empty($CONFIG->sitename))
- $CONFIG->sitename = "New Elgg site";
-
- if (empty($CONFIG->language))
- $CONFIG->language = "en";
+/**
+ * Function that provides some config initialisation on system init
+ *
+ */
+function configuration_init() {
+ global $CONFIG;
+ if (is_installed() || is_db_installed()) {
+ $path = datalist_get('path');
+ if (!empty($path)) {
+ $CONFIG->path = $path;
}
-
- /**
- * Function that provides some config initialisation on system init
- *
- */
-
- function configuration_init() {
-
- global $CONFIG;
-
- if (is_installed() || is_db_installed()) {
-
- $path = datalist_get('path');
- if (!empty($path))
- $CONFIG->path = $path;
- $dataroot = datalist_get('dataroot');
- if (!empty($dataroot))
- $CONFIG->dataroot = $dataroot;
- $simplecache_enabled = datalist_get('simplecache_enabled');
- if ($simplecache_enabled !== false) {
- $CONFIG->simplecache_enabled = $simplecache_enabled;
- } else {
- $CONFIG->simplecache_enabled = 1;
- }
- $viewpath_cache_enabled = datalist_get('viewpath_cache_enabled');
- if ($viewpath_cache_enabled !== false) {
- $CONFIG->viewpath_cache_enabled = $viewpath_cache_enabled;
- } else {
- $CONFIG->viewpath_cache_enabled = 1;
- }
- if (isset($CONFIG->site) && ($CONFIG->site instanceof ElggSite)) {
- $CONFIG->wwwroot = $CONFIG->site->url;
- $CONFIG->sitename = $CONFIG->site->name;
- $CONFIG->sitedescription = $CONFIG->site->description;
- $CONFIG->siteemail = $CONFIG->site->email;
- }
- $CONFIG->url = $CONFIG->wwwroot;
-
- // Load default settings from database
- get_all_config();
-
- return true;
- }
+ $dataroot = datalist_get('dataroot');
+ if (!empty($dataroot)) {
+ $CONFIG->dataroot = $dataroot;
}
-
- /**
- * Register config_init
- */
-
- register_elgg_event_handler('boot','system','configuration_init',10);
-
-?>
\ No newline at end of file
+ $simplecache_enabled = datalist_get('simplecache_enabled');
+ if ($simplecache_enabled !== false) {
+ $CONFIG->simplecache_enabled = $simplecache_enabled;
+ } else {
+ $CONFIG->simplecache_enabled = 1;
+ }
+ $viewpath_cache_enabled = datalist_get('viewpath_cache_enabled');
+ if ($viewpath_cache_enabled !== false) {
+ $CONFIG->viewpath_cache_enabled = $viewpath_cache_enabled;
+ } else {
+ $CONFIG->viewpath_cache_enabled = 1;
+ }
+ if (isset($CONFIG->site) && ($CONFIG->site instanceof ElggSite)) {
+ $CONFIG->wwwroot = $CONFIG->site->url;
+ $CONFIG->sitename = $CONFIG->site->name;
+ $CONFIG->sitedescription = $CONFIG->site->description;
+ $CONFIG->siteemail = $CONFIG->site->email;
+ }
+ $CONFIG->url = $CONFIG->wwwroot;
+
+ // Load default settings from database
+ get_all_config();
+
+ return true;
+ }
+}
+
+/**
+ * Register config_init
+ */
+
+register_elgg_event_handler('boot', 'system', 'configuration_init', 10);
\ No newline at end of file
diff --git a/engine/lib/cron.php b/engine/lib/cron.php
index e991e49a2..b4952e2ee 100644
--- a/engine/lib/cron.php
+++ b/engine/lib/cron.php
@@ -1,61 +1,57 @@
path . "engine/handlers/cron_handler.php");
- }
- else
- forward();
- }
+/**
+ * Initialisation
+ *
+ */
+function cron_init() {
+ // Register a pagehandler for cron
+ register_page_handler('cron','cron_page_handler');
+}
+/**
+ * Cron handler for redirecting pages.
+ *
+ * @param unknown_type $page
+ */
+function cron_page_handler($page) {
+ global $CONFIG;
- // Register a startup event
- register_elgg_event_handler('init','system','cron_init');
+ if ($page[0]) {
+ switch (strtolower($page[0])) {
+ case 'minute' :
+ case 'fiveminute' :
+ case 'fifteenmin' :
+ case 'halfhour' :
+ case 'hourly' :
+ case 'daily' :
+ case 'weekly' :
+ case 'monthly':
+ case 'yearly' :
+ case 'reboot' :
+ set_input('period', $page[0]);
+ break;
+ default :
+ throw new CronException(sprintf(elgg_echo('CronException:unknownperiod'), $page[0]));
+ }
+
+ // Include cron handler
+ include($CONFIG->path . "engine/handlers/cron_handler.php");
+ } else {
+ forward();
+ }
+}
-?>
\ No newline at end of file
+// Register a startup event
+register_elgg_event_handler('init','system','cron_init');
\ No newline at end of file
diff --git a/engine/lib/exceptions.php b/engine/lib/exceptions.php
index 95f2bfc82..ccf017062 100644
--- a/engine/lib/exceptions.php
+++ b/engine/lib/exceptions.php
@@ -1,162 +1,161 @@
- * @link http://elgg.org/
- */
-
- // Top level //////////////////////////////////////////////////////////////////////////////
-
- /**
- * IOException
- * An IO Exception, throw when an IO Exception occurs. Subclass for specific IO Exceptions.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class IOException extends Exception {}
-
- /**
- * ClassException
- * A class Exception, throw when there is a class error.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class ClassException extends Exception {}
-
- /**
- * ConfigurationException
- * There is a configuration error
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class ConfigurationException extends Exception {}
-
- /**
- * SecurityException
- * An Security Exception, throw when a Security Exception occurs. Subclass for specific Security Execeptions (access problems etc)
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class SecurityException extends Exception {}
-
- /**
- * ClassNotFoundException
- * An database exception, throw when a database exception happens, subclass if more detail is needed.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class DatabaseException extends Exception {}
-
- /**
- * APIException
- * The API Exception class, thrown by the API layer when an API call has an issue.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class APIException extends Exception {}
-
- /**
- * CallException
- * An exception thrown when there is a problem calling something.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class CallException extends Exception {}
-
- /**
- * Data format exception
- * An exception thrown when there is a problem in the format of some data.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class DataFormatException extends Exception {}
-
- // Class exceptions ///////////////////////////////////////////////////////////////////////
-
- /**
- * InvalidClassException
- * An invalid class Exception, throw when a class is invalid.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class InvalidClassException extends ClassException {}
-
- /**
- * ClassNotFoundException
- * An Class not found Exception, throw when an class can not be found occurs.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class ClassNotFoundException extends ClassException {}
-
- // Configuration exceptions ///////////////////////////////////////////////////////////////
-
- /**
- * InstallationException
- * Thrown when there is a major problem with the installation.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class InstallationException extends ConfigurationException {}
-
- // Call exceptions ////////////////////////////////////////////////////////////////////////
-
- /**
- * NotImplementedException
- * Thrown when a method or function has not been implemented, primarily used in development... you should
- * not see these!
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class NotImplementedException extends CallException {}
-
- /**
- * InvalidParameterException
- * A parameter is invalid.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class InvalidParameterException extends CallException {}
-
- // Installation exception /////////////////////////////////////////////////////////////////
-
- /**
- * RegistrationException
- * Could not register a new user for whatever reason.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Exceptions
- */
- class RegistrationException extends InstallationException {}
-?>
\ No newline at end of file
+/**
+ * Exceptions.
+ * Define some globally useful exception classes.
+ *
+ * @package Elgg
+ * @subpackage Exceptions
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+
+// Top level //////////////////////////////////////////////////////////////////////////////
+
+/**
+ * IOException
+ * An IO Exception, throw when an IO Exception occurs. Subclass for specific IO Exceptions.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class IOException extends Exception {}
+
+/**
+ * ClassException
+ * A class Exception, throw when there is a class error.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class ClassException extends Exception {}
+
+/**
+ * ConfigurationException
+ * There is a configuration error
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class ConfigurationException extends Exception {}
+
+/**
+ * SecurityException
+ * An Security Exception, throw when a Security Exception occurs. Subclass for specific Security Execeptions (access problems etc)
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class SecurityException extends Exception {}
+
+/**
+ * ClassNotFoundException
+ * An database exception, throw when a database exception happens, subclass if more detail is needed.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class DatabaseException extends Exception {}
+
+/**
+ * APIException
+ * The API Exception class, thrown by the API layer when an API call has an issue.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class APIException extends Exception {}
+
+/**
+ * CallException
+ * An exception thrown when there is a problem calling something.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class CallException extends Exception {}
+
+/**
+ * Data format exception
+ * An exception thrown when there is a problem in the format of some data.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class DataFormatException extends Exception {}
+
+// Class exceptions ///////////////////////////////////////////////////////////////////////
+
+/**
+ * InvalidClassException
+ * An invalid class Exception, throw when a class is invalid.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class InvalidClassException extends ClassException {}
+
+/**
+ * ClassNotFoundException
+ * An Class not found Exception, throw when an class can not be found occurs.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class ClassNotFoundException extends ClassException {}
+
+// Configuration exceptions ///////////////////////////////////////////////////////////////
+
+/**
+ * InstallationException
+ * Thrown when there is a major problem with the installation.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class InstallationException extends ConfigurationException {}
+
+// Call exceptions ////////////////////////////////////////////////////////////////////////
+
+/**
+ * NotImplementedException
+ * Thrown when a method or function has not been implemented, primarily used in development... you should
+ * not see these!
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class NotImplementedException extends CallException {}
+
+/**
+ * InvalidParameterException
+ * A parameter is invalid.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class InvalidParameterException extends CallException {}
+
+// Installation exception /////////////////////////////////////////////////////////////////
+
+/**
+ * RegistrationException
+ * Could not register a new user for whatever reason.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class RegistrationException extends InstallationException {}
\ No newline at end of file
diff --git a/engine/lib/export.php b/engine/lib/export.php
index 0e487faab..e3acace5f 100644
--- a/engine/lib/export.php
+++ b/engine/lib/export.php
@@ -1,262 +1,256 @@
guid);
- else if ($object instanceof ElggExtender) {
- $type = $object->type;
- if ($type == 'volatile')
- $uuid = guid_to_uuid($object->entity_guid). $type . "/{$object->name}/";
- else
- $uuid = guid_to_uuid($object->entity_guid). $type . "/{$object->id}/";
-
- return $uuid;
- } else if ($object instanceof ElggRelationship) {
- return guid_to_uuid($object->guid_one) . "relationship/{$object->id}/";
+ public function import(ODD $data);
+}
+
+/**
+ * Export exception
+ *
+ * @package Elgg
+ * @subpackage Exceptions
+ *
+ */
+class ExportException extends DataFormatException {}
+
+/**
+ * Import exception
+ *
+ * @package Elgg
+ * @subpackage Exceptions
+ */
+class ImportException extends DataFormatException {}
+
+/**
+ * Get a UUID from a given object.
+ *
+ * @param $object The object either an ElggEntity, ElggRelationship or ElggExtender
+ * @return the UUID or false
+ */
+function get_uuid_from_object($object) {
+ if ($object instanceof ElggEntity) {
+ return guid_to_uuid($object->guid);
+ } else if ($object instanceof ElggExtender) {
+ $type = $object->type;
+ if ($type == 'volatile') {
+ $uuid = guid_to_uuid($object->entity_guid). $type . "/{$object->name}/";
+ } else {
+ $uuid = guid_to_uuid($object->entity_guid). $type . "/{$object->id}/";
}
-
-
- return false;
+
+ return $uuid;
+ } else if ($object instanceof ElggRelationship) {
+ return guid_to_uuid($object->guid_one) . "relationship/{$object->id}/";
}
-
- /**
- * Generate a UUID from a given GUID.
- *
- * @param int $guid The GUID of an object.
- */
- function guid_to_uuid($guid)
- {
- global $CONFIG;
-
- return $CONFIG->wwwroot . "export/opendd/$guid/";
+
+ return false;
+}
+
+/**
+ * Generate a UUID from a given GUID.
+ *
+ * @param int $guid The GUID of an object.
+ */
+function guid_to_uuid($guid) {
+ global $CONFIG;
+
+ return $CONFIG->wwwroot . "export/opendd/$guid/";
+}
+
+/**
+ * Test to see if a given uuid is for this domain, returning true if so.
+ * @param $uuid
+ * @return bool
+ */
+function is_uuid_this_domain($uuid) {
+ global $CONFIG;
+
+ if (strpos($uuid, $CONFIG->wwwroot) === 0) {
+ return true;
}
-
- /**
- * Test to see if a given uuid is for this domain, returning true if so.
- * @param $uuid
- * @return bool
- */
- function is_uuid_this_domain($uuid)
- {
- global $CONFIG;
-
- if (strpos($uuid, $CONFIG->wwwroot) === 0)
- return true;
-
- return false;
+
+ return false;
+}
+
+/**
+ * This function attempts to retrieve a previously imported entity via its UUID.
+ *
+ * @param $uuid
+ */
+function get_entity_from_uuid($uuid) {
+ $uuid = sanitise_string($uuid);
+
+ $entities = get_entities_from_metadata("import_uuid", $uuid);
+
+ if ($entities) {
+ return $entities[0];
}
-
- /**
- * This function attempts to retrieve a previously imported entity via its UUID.
- *
- * @param $uuid
- */
- function get_entity_from_uuid($uuid)
- {
- $uuid = sanitise_string($uuid);
-
- $entities = get_entities_from_metadata("import_uuid", $uuid);
-
- if ($entities)
- return $entities[0];
-
- return false;
+
+ return false;
+}
+
+/**
+ * Tag a previously created guid with the uuid it was imported on.
+ *
+ * @param int $guid
+ * @param string $uuid
+ */
+function add_uuid_to_guid($guid, $uuid) {
+ $guid = (int)$guid;
+ $uuid = sanitise_string($uuid);
+
+ return create_metadata($guid, "import_uuid", $uuid);
+}
+
+
+$IMPORTED_DATA = array();
+$IMPORTED_OBJECT_COUNTER = 0;
+
+/**
+ * This function processes an element, passing elements to the plugin stack to see if someone will
+ * process it.
+ *
+ * If nobody processes the top level element, the sub level elements are processed.
+ *
+ * @param ODD $odd The odd element to process
+ */
+function __process_element(ODD $odd) {
+ global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
+
+ // See if anyone handles this element, return true if it is.
+ if ($odd) {
+ $handled = trigger_plugin_hook("import", "all", array("element" => $odd), $to_be_serialised);
}
-
- /**
- * Tag a previously created guid with the uuid it was imported on.
- *
- * @param int $guid
- * @param string $uuid
- */
- function add_uuid_to_guid($guid, $uuid)
- {
- $guid = (int)$guid;
- $uuid = sanitise_string($uuid);
-
- return create_metadata($guid, "import_uuid", $uuid);
+
+ // If not, then see if any of its sub elements are handled
+ if ($handled) {
+ // Increment validation counter
+ $IMPORTED_OBJECT_COUNTER ++;
+ // Return the constructed object
+ $IMPORTED_DATA[] = $handled;
+
+ return true;
}
-
-
+
+ return false;
+}
+
+function exportAsArray($guid) {
+ $guid = (int)$guid;
+
+ // Initialise the array
+ $to_be_serialised = array();
+
+ // Trigger a hook to
+ $to_be_serialised = trigger_plugin_hook("export", "all", array("guid" => $guid), $to_be_serialised);
+
+ // Sanity check
+ if ((!is_array($to_be_serialised)) || (count($to_be_serialised)==0)) {
+ throw new ExportException(sprintf(elgg_echo('ExportException:NoSuchEntity'), $guid));
+ }
+
+ return $to_be_serialised;
+}
+
+/**
+ * Export a GUID.
+ *
+ * This function exports a GUID and all information related to it in an XML format.
+ *
+ * This function makes use of the "serialise" plugin hook, which is passed an array to which plugins
+ * should add data to be serialised to.
+ *
+ * @see ElggEntity for an example of its usage.
+ * @param int $guid The GUID.
+ * @param ODDWrapperFactory $wrapper Optional wrapper permitting the export process to embed ODD in other document formats.
+ * @return xml
+ */
+function export($guid) {
+ $odd = new ODDDocument(exportAsArray($guid));
+
+ return ODD_Export($odd);
+}
+
+/**
+ * Import an XML serialisation of an object.
+ * This will make a best attempt at importing a given xml doc.
+ *
+ * @param string $xml
+ * @return bool
+ * @throws Exception if there was a problem importing the data.
+ */
+function import($xml) {
+ global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
+
$IMPORTED_DATA = array();
$IMPORTED_OBJECT_COUNTER = 0;
-
- /**
- * This function processes an element, passing elements to the plugin stack to see if someone will
- * process it.
- *
- * If nobody processes the top level element, the sub level elements are processed.
- *
- * @param ODD $odd The odd element to process
- */
- function __process_element(ODD $odd)
- {
- global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
-
- // See if anyone handles this element, return true if it is.
- if ($odd)
- $handled = trigger_plugin_hook("import", "all", array("element" => $odd), $to_be_serialised);
-
- // If not, then see if any of its sub elements are handled
- if ($handled)
- {
- $IMPORTED_OBJECT_COUNTER ++; // Increment validation counter
- $IMPORTED_DATA[] = $handled; // Return the constructed object
-
- return true;
- }
-
- return false;
- }
-
- function exportAsArray($guid)
- {
-
- $guid = (int)$guid;
-
- // Initialise the array
- $to_be_serialised = array();
-
- // Trigger a hook to
- $to_be_serialised = trigger_plugin_hook("export", "all", array("guid" => $guid), $to_be_serialised);
-
- // Sanity check
- if ((!is_array($to_be_serialised)) || (count($to_be_serialised)==0)) throw new ExportException(sprintf(elgg_echo('ExportException:NoSuchEntity'), $guid));
-
- return $to_be_serialised;
- }
-
- /**
- * Export a GUID.
- *
- * This function exports a GUID and all information related to it in an XML format.
- *
- * This function makes use of the "serialise" plugin hook, which is passed an array to which plugins
- * should add data to be serialised to.
- *
- * @see ElggEntity for an example of its usage.
- * @param int $guid The GUID.
- * @param ODDWrapperFactory $wrapper Optional wrapper permitting the export process to embed ODD in other document formats.
- * @return xml
- */
- function export($guid)
- {
- $odd = new ODDDocument(exportAsArray($guid));
-
- return ODD_Export($odd);
+
+ $document = ODD_Import($xml);
+ if (!$document) {
+ throw new ImportException(elgg_echo('ImportException:NoODDElements'));
}
-
- /**
- * Import an XML serialisation of an object.
- * This will make a best attempt at importing a given xml doc.
- *
- * @param string $xml
- * @return bool
- * @throws Exception if there was a problem importing the data.
- */
- function import($xml)
- {
- global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
-
- $IMPORTED_DATA = array();
- $IMPORTED_OBJECT_COUNTER = 0;
-
- $document = ODD_Import($xml);
- if (!$document)
- throw new ImportException(elgg_echo('ImportException:NoODDElements'));
-
- foreach ($document as $element)
- __process_element($element);
-
- if ($IMPORTED_OBJECT_COUNTER!= count($IMPORTED_DATA))
- throw new ImportException(elgg_echo('ImportException:NotAllImported'));
-
- return true;
+
+ foreach ($document as $element) {
+ __process_element($element);
}
-
- /**
- * Register the OpenDD import action
- */
- function export_init()
- {
- global $CONFIG;
-
- register_action("import/opendd", false);
+ if ($IMPORTED_OBJECT_COUNTER!= count($IMPORTED_DATA)) {
+ throw new ImportException(elgg_echo('ImportException:NotAllImported'));
}
-
- // Register a startup event
- register_elgg_event_handler('init','system','export_init',100);
-?>
\ No newline at end of file
+
+ return true;
+}
+
+
+/**
+ * Register the OpenDD import action
+ */
+function export_init() {
+ global $CONFIG;
+
+ register_action("import/opendd", false);
+}
+
+// Register a startup event
+register_elgg_event_handler('init', 'system', 'export_init', 100);
\ No newline at end of file
diff --git a/engine/lib/extender.php b/engine/lib/extender.php
index 456a1f778..cbcdd6eb7 100644
--- a/engine/lib/extender.php
+++ b/engine/lib/extender.php
@@ -1,450 +1,469 @@
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']));
- }
+ 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 of this annotation.
- *
- * @return mixed
- */
- public function getOwner()
- {
- return $this->owner_guid;
- }
- /**
- * Return the owner entity
- *
- * @return mixed
- */
- public function getOwnerEntity()
- {
- return get_user($this->owner_guid);
+ return $this->attributes[$name];
}
-
- /**
- * Returns the entity this is attached to
- *
- * @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();
-
- /**
- * Determines whether or not the specified user can edit this
- *
- * @param int $user_guid The GUID of the user (defaults to currently logged in user)
- * @return true|false
- */
- 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.
- */
- 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.
- */
- public function getClassName() { return get_class($this); }
-
- /**
- * 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 $this->type; }
-
- /**
- * Return a subtype. For metadata & annotations this is the 'name' and for relationship this is the relationship type.
- */
- 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) ) {
- $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects
- }
- }
-
- function offsetExists($offset)
- {
- return array_key_exists($offset, $this->attributes);
- }
- }
-
+ return null;
+ }
+
/**
- * Detect the value_type for a given value.
- * Currently this is very crude.
- *
- * TODO: Make better!
+ * Set an attribute
*
+ * @param string $name
* @param mixed $value
- * @param string $value_type If specified, overrides the detection.
- * @return string
+ * @param string $value_type
+ * @return boolean
*/
- function detect_extender_valuetype($value, $value_type = "")
- {
- if ($value_type!="")
- return $value_type;
-
- // This is crude
- if (is_int($value)) return 'integer';
- if (is_numeric($value)) return 'text'; // Catch floating point values which are not integer
-
- return 'text';
+ 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;
}
-
+
/**
- * Utility function used by import_extender_plugin_hook() to process an ODDMetaData and add it to an entity.
- * This function does not hit ->save() on the entity (this lets you construct in memory)
+ * Return the owner of this annotation.
*
- * @param ElggEntity The entity to add the data to.
- * @param ODDMetaData $element The OpenDD element
- * @return bool
+ * @return mixed
*/
- function oddmetadata_to_elggextender(ElggEntity $entity, ODDMetaData $element)
- {
- // Get the type of extender (metadata, type, attribute etc)
- $type = $element->getAttribute('type');
- $attr_name = $element->getAttribute('name');
- $attr_val = $element->getBody();
-
- switch ($type)
- {
- case 'volatile' : break; // Ignore volatile items
- case 'annotation' :
- $entity->annotate($attr_name, $attr_val);
- break;
- case 'metadata' :
- $entity->setMetaData($attr_name, $attr_val, "", true);
- break;
- default : // Anything else assume attribute
- $entity->set($attr_name, $attr_val);
- }
-
- // Set time if appropriate
- $attr_time = $element->getAttribute('published');
- if ($attr_time)
- $entity->set('time_updated', $attr_time);
-
- return true;
+ public function getOwner() {
+ return $this->owner_guid;
}
-
+
/**
- * Handler called by trigger_plugin_hook on the "import" event.
+ * Return the owner entity
+ *
+ * @return mixed
*/
- function import_extender_plugin_hook($hook, $entity_type, $returnvalue, $params)
- {
- $element = $params['element'];
-
- $tmp = NULL;
-
- if ($element instanceof ODDMetaData)
- {
- // Recall entity
- $entity_uuid = $element->getAttribute('entity_uuid');
- $entity = get_entity_from_uuid($entity_uuid);
- if (!$entity)
- throw new ImportException(sprintf(elgg_echo('ImportException:GUIDNotFound'), $entity_uuid));
-
- oddmetadata_to_elggextender($entity, $element);
-
- // Save
- if (!$entity->save())
- throw new ImportException(sprintf(elgg_echo('ImportException:ProblemUpdatingMeta'), $attr_name, $entity_uuid));
-
- return true;
- }
+ public function getOwnerEntity() {
+ return get_user($this->owner_guid);
+ }
+
+ /**
+ * Returns the entity this is attached to
+ *
+ * @return ElggEntity The enttiy
+ */
+ public function getEntity() {
+ return get_entity($this->entity_guid);
}
-
+
/**
- * Determines whether or not the specified user can edit the specified piece of extender
+ * Save this data to the appropriate database table.
+ */
+ abstract public function save();
+
+ /**
+ * Delete this data.
+ */
+ abstract public function delete();
+
+ /**
+ * Determines whether or not the specified user can edit this
*
- * @param int $extender_id The ID of the piece of extender
- * @param string $type 'metadata' or 'annotation'
- * @param int $user_guid The GUID of the user
+ * @param int $user_guid The GUID of the user (defaults to currently logged in user)
* @return true|false
*/
- function can_edit_extender($extender_id, $type, $user_guid = 0) {
-
- if (!isloggedin())
- return false;
-
- $user_guid = (int)$user_guid;
- $user = get_entity($user_guid);
- if (!$user) $user = get_loggedin_user();
-
- $functionname = "get_{$type}";
- if (is_callable($functionname)) {
- $extender = $functionname($extender_id);
- } else return false;
-
- if (!is_a($extender,"ElggExtender")) return false;
-
- // If the owner is the specified user, great! They can edit.
- if ($extender->getOwner() == $user->getGUID()) return true;
-
- // If the user can edit the entity this is attached to, great! They can edit.
- if (can_edit_entity($extender->entity_guid,$user->getGUID())) return true;
-
- // Trigger plugin hooks
- return trigger_plugin_hook('permissions_check',$type,array('entity' => $entity, 'user' => $user),false);
-
- }
-
+ public function canEdit($user_guid = 0) {
+ return can_edit_extender($this->id,$this->type,$user_guid);
+ }
+
/**
- * Sets the URL handler for a particular extender type and name.
- * It is recommended that you do not call this directly, instead use one of the wrapper functions in the
- * subtype files.
+ * Return a url for this extender.
*
- * @param string $function_name The function to register
- * @param string $extender_type Extender type
- * @param string $extender_name The name of the extender
- * @return true|false Depending on success
+ * @return string
*/
- function register_extender_url_handler($function_name, $extender_type = "all", $extender_name = "all") {
- global $CONFIG;
-
- if (!is_callable($function_name)) return false;
-
- if (!isset($CONFIG->extender_url_handler)) {
- $CONFIG->extender_url_handler = array();
- }
- if (!isset($CONFIG->extender_url_handler[$extender_type])) {
- $CONFIG->extender_url_handler[$extender_type] = array();
- }
- $CONFIG->extender_url_handler[$extender_type][$extender_name] = $function_name;
-
- return true;
-
+ public abstract function getURL();
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues() {
+ return array(
+ 'id',
+ 'entity_guid',
+ 'name',
+ 'value',
+ 'value_type',
+ 'owner_guid',
+ 'type',
+ );
}
-
+
/**
- * Get the URL of a given elgg extender.
- * Used by get_annotation_url and get_metadata_url.
+ * Export this object
*
- * @param ElggExtender $extender
+ * @return array
*/
- function get_extender_url(ElggExtender $extender)
- {
- global $CONFIG;
-
- $view = elgg_get_viewtype();
-
- $guid = $extender->entity_guid;
- $type = $extender->type;
-
- $url = "";
-
- $function = "";
- if (isset($CONFIG->extender_url_handler[$type][$extender->name]))
- $function = $CONFIG->extender_url_handler[$type][$extender->name];
- if (isset($CONFIG->extender_url_handler[$type]['all']))
- $function = $CONFIG->extender_url_handler[$type]['all'];
- if (isset($CONFIG->extender_url_handler['all']['all']))
- $function = $CONFIG->extender_url_handler['all']['all'];
-
- if (is_callable($function)) {
- $url = $function($extender);
+ 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.
+ */
+ public function getClassName() {
+ return get_class($this);
+ }
+
+ /**
+ * 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 $this->type;
+ }
+
+ /**
+ * Return a subtype. For metadata & annotations this is the 'name' and
+ * for relationship this is the relationship type.
+ */
+ 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];
}
-
- if ($url == "") {
- $nameid = $extender->id;
- if ($type == 'volatile')
- $nameid== $extender->name;
- $url = $CONFIG->wwwroot . "export/$view/$guid/$type/$nameid/";
- }
- return $url;
- }
-
- /** Register the hook */
- register_plugin_hook("import", "all", "import_extender_plugin_hook", 2);
-
-?>
+ }
+
+ 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);
+ }
+}
+
+/**
+ * Detect the value_type for a given value.
+ * Currently this is very crude.
+ *
+ * TODO: Make better!
+ *
+ * @param mixed $value
+ * @param string $value_type If specified, overrides the detection.
+ * @return string
+ */
+function detect_extender_valuetype($value, $value_type = "") {
+ if ($value_type!="") {
+ return $value_type;
+ }
+
+ // This is crude
+ if (is_int($value)) {
+ return 'integer';
+ }
+ // Catch floating point values which are not integer
+ if (is_numeric($value)) {
+ return 'text';
+ }
+
+ return 'text';
+}
+
+/**
+ * Utility function used by import_extender_plugin_hook() to process an ODDMetaData and add it to an entity.
+ * This function does not hit ->save() on the entity (this lets you construct in memory)
+ *
+ * @param ElggEntity The entity to add the data to.
+ * @param ODDMetaData $element The OpenDD element
+ * @return bool
+ */
+function oddmetadata_to_elggextender(ElggEntity $entity, ODDMetaData $element) {
+ // Get the type of extender (metadata, type, attribute etc)
+ $type = $element->getAttribute('type');
+ $attr_name = $element->getAttribute('name');
+ $attr_val = $element->getBody();
+
+ switch ($type) {
+ // Ignore volatile items
+ case 'volatile' :
+ break;
+ case 'annotation' :
+ $entity->annotate($attr_name, $attr_val);
+ break;
+ case 'metadata' :
+ $entity->setMetaData($attr_name, $attr_val, "", true);
+ break;
+ default : // Anything else assume attribute
+ $entity->set($attr_name, $attr_val);
+ }
+
+ // Set time if appropriate
+ $attr_time = $element->getAttribute('published');
+ if ($attr_time) {
+ $entity->set('time_updated', $attr_time);
+ }
+
+ return true;
+}
+
+/**
+ * Handler called by trigger_plugin_hook on the "import" event.
+ */
+function import_extender_plugin_hook($hook, $entity_type, $returnvalue, $params) {
+ $element = $params['element'];
+
+ $tmp = NULL;
+
+ if ($element instanceof ODDMetaData) {
+ // Recall entity
+ $entity_uuid = $element->getAttribute('entity_uuid');
+ $entity = get_entity_from_uuid($entity_uuid);
+ if (!$entity) {
+ throw new ImportException(sprintf(elgg_echo('ImportException:GUIDNotFound'), $entity_uuid));
+ }
+
+ oddmetadata_to_elggextender($entity, $element);
+
+ // Save
+ if (!$entity->save()) {
+ throw new ImportException(sprintf(elgg_echo('ImportException:ProblemUpdatingMeta'), $attr_name, $entity_uuid));
+ }
+
+ return true;
+ }
+}
+
+/**
+ * Determines whether or not the specified user can edit the specified piece of extender
+ *
+ * @param int $extender_id The ID of the piece of extender
+ * @param string $type 'metadata' or 'annotation'
+ * @param int $user_guid The GUID of the user
+ * @return true|false
+ */
+function can_edit_extender($extender_id, $type, $user_guid = 0) {
+ if (!isloggedin()) {
+ return false;
+ }
+
+ $user_guid = (int)$user_guid;
+ $user = get_entity($user_guid);
+ if (!$user) {
+ $user = get_loggedin_user();
+ }
+
+ $functionname = "get_{$type}";
+ if (is_callable($functionname)) {
+ $extender = $functionname($extender_id);
+ } else {
+ return false;
+ }
+
+ if (!is_a($extender,"ElggExtender")) {
+ return false;
+ }
+
+ // If the owner is the specified user, great! They can edit.
+ if ($extender->getOwner() == $user->getGUID()) {
+ return true;
+ }
+
+ // If the user can edit the entity this is attached to, great! They can edit.
+ if (can_edit_entity($extender->entity_guid,$user->getGUID())) {
+ return true;
+ }
+
+ // Trigger plugin hooks
+ return trigger_plugin_hook('permissions_check',$type,array('entity' => $entity, 'user' => $user),false);
+}
+
+/**
+ * Sets the URL handler for a particular extender type and name.
+ * It is recommended that you do not call this directly, instead use one of the wrapper functions in the
+ * subtype files.
+ *
+ * @param string $function_name The function to register
+ * @param string $extender_type Extender type
+ * @param string $extender_name The name of the extender
+ * @return true|false Depending on success
+ */
+function register_extender_url_handler($function_name, $extender_type = "all", $extender_name = "all") {
+ global $CONFIG;
+
+ if (!is_callable($function_name)) {
+ return false;
+ }
+
+ if (!isset($CONFIG->extender_url_handler)) {
+ $CONFIG->extender_url_handler = array();
+ }
+ if (!isset($CONFIG->extender_url_handler[$extender_type])) {
+ $CONFIG->extender_url_handler[$extender_type] = array();
+ }
+ $CONFIG->extender_url_handler[$extender_type][$extender_name] = $function_name;
+
+ return true;
+}
+
+/**
+ * Get the URL of a given elgg extender.
+ * Used by get_annotation_url and get_metadata_url.
+ *
+ * @param ElggExtender $extender
+ */
+function get_extender_url(ElggExtender $extender) {
+ global $CONFIG;
+
+ $view = elgg_get_viewtype();
+
+ $guid = $extender->entity_guid;
+ $type = $extender->type;
+
+ $url = "";
+
+ $function = "";
+ if (isset($CONFIG->extender_url_handler[$type][$extender->name])) {
+ $function = $CONFIG->extender_url_handler[$type][$extender->name];
+ }
+
+ if (isset($CONFIG->extender_url_handler[$type]['all'])) {
+ $function = $CONFIG->extender_url_handler[$type]['all'];
+ }
+
+ if (isset($CONFIG->extender_url_handler['all']['all'])) {
+ $function = $CONFIG->extender_url_handler['all']['all'];
+ }
+
+ if (is_callable($function)) {
+ $url = $function($extender);
+ }
+
+ if ($url == "") {
+ $nameid = $extender->id;
+ if ($type == 'volatile') {
+ $nameid== $extender->name;
+ }
+ $url = $CONFIG->wwwroot . "export/$view/$guid/$type/$nameid/";
+ }
+ return $url;
+}
+
+/** Register the hook */
+register_plugin_hook("import", "all", "import_extender_plugin_hook", 2);
\ No newline at end of file
diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php
index a7df5a8f0..852fbae8f 100644
--- a/engine/lib/filestore.php
+++ b/engine/lib/filestore.php
@@ -1,1346 +1,1319 @@
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);
-
- }
-
+ abstract public function write($f, $data);
+
/**
- * @class ElggDiskFilestore
- * This class uses disk storage to save data.
- * @author Curverider Ltd
+ * 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.
*/
- class ElggDiskFilestore extends ElggFilestore
- {
- /**
- * Directory root.
- */
- private $dir_root;
-
- /**
- * Default depth of file directory matrix
- */
- private $matrix_depth = 5;
-
- /**
- * Construct a disk filestore using the given directory root.
- *
- * @param string $directory_root Root directory, must end in "/"
- */
- public function __construct($directory_root = "")
- {
- global $CONFIG;
-
- if ($directory_root)
- $this->dir_root = $directory_root;
- else
- $this->dir_root = $CONFIG->dataroot;
- }
-
- public function open(ElggFile $file, $mode)
- {
- $fullname = $this->getFilenameOnFilestore($file);
-
- // Split into path and name
- $ls = strrpos($fullname,"/");
- if ($ls===false) $ls = 0;
-
- $path = substr($fullname, 0, $ls);
- $name = substr($fullname, $ls);
-
- // Try and create the directory
- try { $this->make_directory_root($path); } catch (Exception $e){}
-
- if (($mode!='write') && (!file_exists($fullname)))
- return false;
-
- switch ($mode)
- {
- case "read" : $mode = "r+b"; break;
- case "write" : $mode = "w+b"; break;
- case "append" : $mode = "a+b"; break;
- default: throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:UnrecognisedFileMode'), $mode));
- }
-
- return fopen($fullname, $mode);
-
- }
-
- public function write($f, $data)
- {
- return fwrite($f, $data);
- }
-
- public function read($f, $length, $offset = 0)
- {
- if ($offset)
- $this->seek($f, $offset);
-
- return fread($f, $length);
- }
-
- public function close($f)
- {
- return fclose($f);
+ 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);
+}
+
+/**
+ * @class ElggDiskFilestore
+ * This class uses disk storage to save data.
+ * @author Curverider Ltd
+ */
+class ElggDiskFilestore extends ElggFilestore {
+ /**
+ * Directory root.
+ */
+ private $dir_root;
+
+ /**
+ * Default depth of file directory matrix
+ */
+ private $matrix_depth = 5;
+
+ /**
+ * Construct a disk filestore using the given directory root.
+ *
+ * @param string $directory_root Root directory, must end in "/"
+ */
+ public function __construct($directory_root = "") {
+ global $CONFIG;
+
+ if ($directory_root) {
+ $this->dir_root = $directory_root;
+ } else {
+ $this->dir_root = $CONFIG->dataroot;
}
-
- public function delete(ElggFile $file)
- {
- $filename = $this->getFilenameOnFilestore($file);
- if (file_exists($filename)) {
- return unlink($filename);
- } else {
- return true;
- }
+ }
+
+ public function open(ElggFile $file, $mode) {
+ $fullname = $this->getFilenameOnFilestore($file);
+
+ // Split into path and name
+ $ls = strrpos($fullname,"/");
+ if ($ls===false) {
+ $ls = 0;
}
-
- public function seek($f, $position)
- {
- return fseek($f, $position);
+
+ $path = substr($fullname, 0, $ls);
+ $name = substr($fullname, $ls);
+
+ // Try and create the directory
+ try {
+ $this->make_directory_root($path);
+ } catch (Exception $e) {
+
}
-
- public function tell($f)
- {
- return ftell($f);
+
+ if (($mode!='write') && (!file_exists($fullname))) {
+ return false;
}
-
- public function eof($f)
- {
- return feof($f);
+
+ switch ($mode) {
+ case "read" :
+ $mode = "r+b";
+ break;
+ case "write" :
+ $mode = "w+b";
+ break;
+ case "append" :
+ $mode = "a+b";
+ break;
+ default:
+ throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:UnrecognisedFileMode'), $mode));
}
-
- public function getFileSize(ElggFile $file)
- {
- return filesize($this->getFilenameOnFilestore($file));
+
+ return fopen($fullname, $mode);
+
+ }
+
+ public function write($f, $data) {
+ return fwrite($f, $data);
+ }
+
+ public function read($f, $length, $offset = 0) {
+ if ($offset) {
+ $this->seek($f, $offset);
}
-
- public function getFilenameOnFilestore(ElggFile $file)
- {
- $owner = $file->getOwnerEntity();
- if (!$owner)
- $owner = get_loggedin_user();
-
- if ((!$owner) || (!$owner->username)) throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:MissingOwner'), $file->getFilename(), $file->guid));
-
- return $this->dir_root . $this->make_file_matrix($owner->username) . $file->getFilename();
+
+ return fread($f, $length);
+ }
+
+ public function close($f) {
+ return fclose($f);
+ }
+
+ public function delete(ElggFile $file) {
+ $filename = $this->getFilenameOnFilestore($file);
+ if (file_exists($filename)) {
+ return unlink($filename);
+ } else {
+ return true;
}
-
- public function grabFile(ElggFile $file) {
-
- return file_get_contents($file->getFilenameOnFilestore());
-
+ }
+
+ public function seek($f, $position) {
+ return fseek($f, $position);
+ }
+
+ public function tell($f) {
+ return ftell($f);
+ }
+
+ public function eof($f) {
+ return feof($f);
+ }
+
+ public function getFileSize(ElggFile $file) {
+ return filesize($this->getFilenameOnFilestore($file));
+ }
+
+ public function getFilenameOnFilestore(ElggFile $file) {
+ $owner = $file->getOwnerEntity();
+ if (!$owner) {
+ $owner = get_loggedin_user();
}
-
- public function exists(ElggFile $file)
- {
- return file_exists($this->getFilenameOnFilestore($file));
+
+ if ((!$owner) || (!$owner->username)) {
+ throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:MissingOwner'), $file->getFilename(), $file->guid));
}
-
- public function getSize($prefix,$container_guid) {
- if ($container_guid && ($container=get_entity($container_guid)) && ($username = $container->username)) {
- return get_dir_size($this->dir_root.$this->make_file_matrix($username).$prefix);
- } else {
- return false;
- }
+
+ return $this->dir_root . $this->make_file_matrix($owner->username) . $file->getFilename();
+ }
+
+ public function grabFile(ElggFile $file) {
+ return file_get_contents($file->getFilenameOnFilestore());
+ }
+
+ public function exists(ElggFile $file) {
+ return file_exists($this->getFilenameOnFilestore($file));
+ }
+
+ public function getSize($prefix,$container_guid) {
+ if ($container_guid && ($container=get_entity($container_guid)) && ($username = $container->username)) {
+ return get_dir_size($this->dir_root.$this->make_file_matrix($username).$prefix);
+ } else {
+ return false;
}
-
- /**
- * Make the directory root.
- *
- * @param string $dirroot
- */
- protected function make_directory_root($dirroot)
- {
- if (!file_exists($dirroot))
- if (!@mkdir($dirroot, 0700, true))
+ }
+
+ /**
+ * Make the directory root.
+ *
+ * @param string $dirroot
+ */
+ protected function make_directory_root($dirroot) {
+ if (!file_exists($dirroot)) {
+ if (!@mkdir($dirroot, 0700, true)) {
throw new IOException(sprintf(elgg_echo('IOException:CouldNotMake'), $dirroot));
-
- return true;
- }
-
- /**
- * Multibyte string tokeniser.
- *
- * Splits a string into an array. Will fail safely if mbstring is not installed (although this may still
- * not handle .
- *
- * @param string $string String
- * @param string $charset The charset, defaults to UTF8
- * @return array
- */
- private function mb_str_split($string, $charset = 'UTF8')
- {
- if (is_callable('mb_substr'))
- {
- $length = mb_strlen($string);
- $array = array();
-
- while ($length)
- {
- $array[] = mb_substr($string, 0, 1, $charset);
- $string = mb_substr($string, 1, $length, $charset);
-
- $length = mb_strlen($string);
- }
-
- return $array;
}
- else
- return str_split($string);
-
- return false;
- }
-
- /**
- * Construct the filename matrix.
- *
- * @param string $filename
- */
- protected function make_file_matrix($filename)
- {
- $invalid_fs_chars = '*\'\\/"!$%^&*.%(){}[]#~?<>;|¬`@-+=';
-
- $matrix = "";
-
- $name = $filename;
- $filename = $this->mb_str_split($filename);
- if (!$filename) return false;
-
- $len = count($filename);
- if ($len>$this->matrix_depth)
- $len = $this->matrix_depth;
-
- for ($n = 0; $n < $len; $n++) {
-
- // Prevent a matrix being formed with unsafe characters
- $char = $filename[$n];
- if (strpos($invalid_fs_chars, $char)!==false)
- $char = '_';
-
- $matrix .= $char . "/";
- }
-
- return $matrix.$name."/";
}
-
- public function getParameters()
- {
- return array("dir_root" => $this->dir_root);
- }
-
- public function setParameters(array $parameters)
- {
- if (isset($parameters['dir_root']))
- {
- $this->dir_root = $parameters['dir_root'];
- return true;
+
+ return true;
+ }
+
+ /**
+ * Multibyte string tokeniser.
+ *
+ * Splits a string into an array. Will fail safely if mbstring is not installed (although this may still
+ * not handle .
+ *
+ * @param string $string String
+ * @param string $charset The charset, defaults to UTF8
+ * @return array
+ */
+ private function mb_str_split($string, $charset = 'UTF8') {
+ if (is_callable('mb_substr')) {
+ $length = mb_strlen($string);
+ $array = array();
+
+ while ($length) {
+ $array[] = mb_substr($string, 0, 1, $charset);
+ $string = mb_substr($string, 1, $length, $charset);
+
+ $length = mb_strlen($string);
}
-
- return false;
+
+ return $array;
+ } else {
+ return str_split($string);
}
+
+ return false;
}
-
+
/**
- * @class ElggFile
- * This class represents a physical file.
- *
- * Usage:
- * Create a new ElggFile object and specify a filename, and optionally a FileStore (if one isn't specified
- * then the default is assumed.
- *
- * Open the file using the appropriate mode, and you will be able to read and write to the file.
- *
- * Optionally, you can also call the file's save() method, this will turn the file into an entity in the
- * system and permit you to do things like attach tags to the file etc. This is not done automatically since
- * there are many occasions where you may want access to file data on datastores using the ElggFile interface
- * but do not want to create an Entity reference to it in the system (temporary files for example).
- *
- * @author Curverider Ltd
+ * Construct the filename matrix.
+ *
+ * @param string $filename
*/
- class ElggFile extends ElggObject
- {
- /** Filestore */
- private $filestore;
-
- /** File handle used to identify this file in a filestore. Created by open. */
- private $handle;
-
- protected function initialise_attributes()
- {
- parent::initialise_attributes();
-
- $this->attributes['subtype'] = "file";
+ protected function make_file_matrix($filename) {
+ $invalid_fs_chars = '*\'\\/"!$%^&*.%(){}[]#~?<>;|¬`@-+=';
+
+ $matrix = "";
+
+ $name = $filename;
+ $filename = $this->mb_str_split($filename);
+ if (!$filename) {
+ return false;
}
-
- public function __construct($guid = null)
- {
- parent::__construct($guid);
-
- // Set default filestore
- $this->filestore = $this->getFilestore();
+
+ $len = count($filename);
+ if ($len>$this->matrix_depth) {
+ $len = $this->matrix_depth;
}
-
- /**
- * Set the filename of this file.
- *
- * @param string $name The filename.
- */
- public function setFilename($name) { $this->filename = $name; }
-
- /**
- * Return the filename.
- */
- public function getFilename() { return $this->filename; }
-
- /**
- * Return the filename of this file as it is/will be stored on the filestore, which may be different
- * to the filename.
- */
- public function getFilenameOnFilestore() { return $this->filestore->getFilenameOnFilestore($this); }
-
- /*
- * Return the size of the filestore associated with this file
- *
- */
- public function getFilestoreSize($prefix='',$container_guid=0) {
- if (!$container_guid) {
- $container_guid = $this->container_guid;
+
+ for ($n = 0; $n < $len; $n++) {
+ // Prevent a matrix being formed with unsafe characters
+ $char = $filename[$n];
+ if (strpos($invalid_fs_chars, $char)!==false) {
+ $char = '_';
}
- $fs = $this->getFilestore();
- return $fs->getSize($prefix,$container_guid);
- }
-
- /**
- * Get the mime type of the file.
- */
- public function getMimeType()
- {
- if ($this->mimetype)
- return $this->mimetype;
-
- // TODO : Guess mimetype if not here
- }
-
- /**
- * Set the mime type of the file.
- *
- * @param $mimetype The mimetype
- */
- public function setMimeType($mimetype) { return $this->mimetype = $mimetype; }
-
- /**
- * Set the optional file description.
- *
- * @param string $description The description.
- */
- public function setDescription($description) { $this->description = $description; }
-
- /**
- * Open the file with the given mode
- *
- * @param string $mode Either read/write/append
- */
- public function open($mode)
- {
- if (!$this->getFilename())
- throw new IOException(elgg_echo('IOException:MissingFileName'));
-
- // See if file has already been saved
- // seek on datastore, parameters and name?
-
- // Sanity check
- if (
- ($mode!="read") &&
- ($mode!="write") &&
- ($mode!="append")
- )
- throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:UnrecognisedFileMode'), $mode));
-
- // Get the filestore
- $fs = $this->getFilestore();
-
- // Ensure that we save the file details to object store
- //$this->save();
-
- // Open the file handle
- $this->handle = $fs->open($this, $mode);
-
- return $this->handle;
- }
-
- /**
- * Write some data.
- *
- * @param string $data The data
- */
- public function write($data)
- {
- $fs = $this->getFilestore();
-
- return $fs->write($this->handle, $data);
- }
-
- /**
- * Read some data.
- *
- * @param int $length Amount to read.
- * @param int $offset The offset to start from.
- */
- public function read($length, $offset = 0)
- {
- $fs = $this->getFilestore();
-
- return $fs->read($this->handle, $length, $offset);
- }
-
- /**
- * Gets the full contents of this file.
- *
- * @return mixed The file contents.
- */
- public function grabFile() {
-
- $fs = $this->getFilestore();
- return $fs->grabFile($this);
-
+
+ $matrix .= $char . "/";
}
-
- /**
- * Close the file and commit changes
- */
- public function close()
- {
- $fs = $this->getFilestore();
-
- if ($fs->close($this->handle))
- {
- $this->handle = NULL;
-
- return true;
- }
-
- return false;
+
+ return $matrix.$name."/";
+ }
+
+ public function getParameters() {
+ return array("dir_root" => $this->dir_root);
+ }
+
+ public function setParameters(array $parameters) {
+ if (isset($parameters['dir_root'])) {
+ $this->dir_root = $parameters['dir_root'];
+ return true;
}
-
- /**
- * Delete this file.
- */
- public function delete()
- {
- $fs = $this->getFilestore();
- if ($fs->delete($this)) {
- return parent::delete();
- }
+
+ return false;
+ }
+}
+
+/**
+ * @class ElggFile
+ * This class represents a physical file.
+ *
+ * Usage:
+ * Create a new ElggFile object and specify a filename, and optionally a FileStore (if one isn't specified
+ * then the default is assumed.
+ *
+ * Open the file using the appropriate mode, and you will be able to read and write to the file.
+ *
+ * Optionally, you can also call the file's save() method, this will turn the file into an entity in the
+ * system and permit you to do things like attach tags to the file etc. This is not done automatically since
+ * there are many occasions where you may want access to file data on datastores using the ElggFile interface
+ * but do not want to create an Entity reference to it in the system (temporary files for example).
+ *
+ * @author Curverider Ltd
+ */
+class ElggFile extends ElggObject {
+ /** Filestore */
+ private $filestore;
+
+ /** File handle used to identify this file in a filestore. Created by open. */
+ private $handle;
+
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['subtype'] = "file";
+ }
+
+ public function __construct($guid = null) {
+ parent::__construct($guid);
+
+ // Set default filestore
+ $this->filestore = $this->getFilestore();
+ }
+
+ /**
+ * Set the filename of this file.
+ *
+ * @param string $name The filename.
+ */
+ public function setFilename($name) {
+ $this->filename = $name;
+ }
+
+ /**
+ * Return the filename.
+ */
+ public function getFilename() {
+ return $this->filename;
+ }
+
+ /**
+ * Return the filename of this file as it is/will be stored on the filestore, which may be different
+ * to the filename.
+ */
+ public function getFilenameOnFilestore() {
+ return $this->filestore->getFilenameOnFilestore($this);
+ }
+
+ /*
+ * Return the size of the filestore associated with this file
+ *
+ */
+ public function getFilestoreSize($prefix='',$container_guid=0) {
+ if (!$container_guid) {
+ $container_guid = $this->container_guid;
}
-
- /**
- * Seek a position in the file.
- *
- * @param int $position
- */
- public function seek($position)
- {
- $fs = $this->getFilestore();
-
- return $fs->seek($this->handle, $position);
+ $fs = $this->getFilestore();
+ return $fs->getSize($prefix,$container_guid);
+ }
+
+ /**
+ * Get the mime type of the file.
+ */
+ public function getMimeType() {
+ if ($this->mimetype) {
+ return $this->mimetype;
}
-
- /**
- * Return the current position of the file.
- *
- * @return int The file position
- */
- public function tell()
- {
- $fs = $this->getFilestore();
-
- return $fs->tell($this->handle);
+
+ // TODO : Guess mimetype if not here
+ }
+
+ /**
+ * Set the mime type of the file.
+ *
+ * @param $mimetype The mimetype
+ */
+ public function setMimeType($mimetype) {
+ return $this->mimetype = $mimetype;
+ }
+
+ /**
+ * Set the optional file description.
+ *
+ * @param string $description The description.
+ */
+ public function setDescription($description) {
+ $this->description = $description;
+ }
+
+ /**
+ * Open the file with the given mode
+ *
+ * @param string $mode Either read/write/append
+ */
+ public function open($mode) {
+ if (!$this->getFilename()) {
+ throw new IOException(elgg_echo('IOException:MissingFileName'));
}
-
- /**
- * Return the size of the file in bytes.
- */
- public function size()
- {
- return $this->filestore->getFileSize($this);
+
+ // See if file has already been saved
+ // seek on datastore, parameters and name?
+
+ // Sanity check
+ if (
+ ($mode!="read") &&
+ ($mode!="write") &&
+ ($mode!="append")
+ ) {
+ throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:UnrecognisedFileMode'), $mode));
}
-
- /**
- * Return a boolean value whether the file handle is at the end of the file
- */
- public function eof()
- {
- $fs = $this->getFilestore();
-
- return $fs->eof($this->handle);
+
+ // Get the filestore
+ $fs = $this->getFilestore();
+
+ // Ensure that we save the file details to object store
+ //$this->save();
+
+ // Open the file handle
+ $this->handle = $fs->open($this, $mode);
+
+ return $this->handle;
+ }
+
+ /**
+ * Write some data.
+ *
+ * @param string $data The data
+ */
+ public function write($data) {
+ $fs = $this->getFilestore();
+
+ return $fs->write($this->handle, $data);
+ }
+
+ /**
+ * Read some data.
+ *
+ * @param int $length Amount to read.
+ * @param int $offset The offset to start from.
+ */
+ public function read($length, $offset = 0) {
+ $fs = $this->getFilestore();
+
+ return $fs->read($this->handle, $length, $offset);
+ }
+
+ /**
+ * Gets the full contents of this file.
+ *
+ * @return mixed The file contents.
+ */
+ public function grabFile() {
+ $fs = $this->getFilestore();
+ return $fs->grabFile($this);
+ }
+
+ /**
+ * Close the file and commit changes
+ */
+ public function close() {
+ $fs = $this->getFilestore();
+
+ if ($fs->close($this->handle)) {
+ $this->handle = NULL;
+
+ return true;
}
-
- public function exists()
- {
- $fs = $this->getFilestore();
-
- return $fs->exists($this);
+
+ return false;
+ }
+
+ /**
+ * Delete this file.
+ */
+ public function delete() {
+ $fs = $this->getFilestore();
+ if ($fs->delete($this)) {
+ return parent::delete();
}
-
- /**
- * Set a filestore.
- *
- * @param ElggFilestore $filestore The file store.
- */
- public function setFilestore(ElggFilestore $filestore)
- {
- $this->filestore = $filestore;
+ }
+
+ /**
+ * Seek a position in the file.
+ *
+ * @param int $position
+ */
+ public function seek($position) {
+ $fs = $this->getFilestore();
+
+ return $fs->seek($this->handle, $position);
+ }
+
+ /**
+ * Return the current position of the file.
+ *
+ * @return int The file position
+ */
+ public function tell() {
+ $fs = $this->getFilestore();
+
+ return $fs->tell($this->handle);
+ }
+
+ /**
+ * Return the size of the file in bytes.
+ */
+ public function size() {
+ return $this->filestore->getFileSize($this);
+ }
+
+ /**
+ * Return a boolean value whether the file handle is at the end of the file
+ */
+ public function eof() {
+ $fs = $this->getFilestore();
+
+ return $fs->eof($this->handle);
+ }
+
+ public function exists() {
+ $fs = $this->getFilestore();
+
+ return $fs->exists($this);
+ }
+
+ /**
+ * Set a filestore.
+ *
+ * @param ElggFilestore $filestore The file store.
+ */
+ public function setFilestore(ElggFilestore $filestore) {
+ $this->filestore = $filestore;
+ }
+
+ /**
+ * Return a filestore suitable for saving this file.
+ * This filestore is either a pre-registered filestore, a filestore loaded from metatags saved
+ * along side this file, or the system default.
+ */
+ protected function getFilestore() {
+ // Short circuit if already set.
+ if ($this->filestore) {
+ return $this->filestore;
}
-
- /**
- * Return a filestore suitable for saving this file.
- * This filestore is either a pre-registered filestore, a filestore loaded from metatags saved
- * along side this file, or the system default.
- */
- protected function getFilestore()
- {
- // Short circuit if already set.
- if ($this->filestore)
- return $this->filestore;
-
-
- // If filestore meta set then retrieve filestore TODO: Better way of doing this?
- $metas = get_metadata_for_entity($this->guid);
- $parameters = array();
- if (is_array($metas))
- foreach ($metas as $meta)
- {
- if (strpos($meta->name, "filestore::")!==false)
- {
+
+ // If filestore meta set then retrieve filestore TODO: Better way of doing this?
+ $metas = get_metadata_for_entity($this->guid);
+ $parameters = array();
+ if (is_array($metas)) {
+ foreach ($metas as $meta) {
+ if (strpos($meta->name, "filestore::")!==false) {
// Filestore parameter tag
$comp = explode("::", $meta->name);
- $name = $comp[1];
-
+ $name = $comp[1];
+
$parameters[$name] = $meta->value;
}
}
-
- // If parameters loaded then create new filestore
- if (count($parameters)!=0)
- {
- // Create new filestore object
- if ((!isset($parameters['filestore'])) || (!class_exists($parameters['filestore'])))
- throw new ClassNotFoundException(elgg_echo('ClassNotFoundException:NotFoundNotSavedWithFile'));
-
- $this->filestore = new $parameters['filestore']();
-
- // Set parameters
- $this->filestore->setParameters($parameters);
+ }
+
+ // If parameters loaded then create new filestore
+ if (count($parameters)!=0) {
+ // Create new filestore object
+ if ((!isset($parameters['filestore'])) || (!class_exists($parameters['filestore']))) {
+ throw new ClassNotFoundException(elgg_echo('ClassNotFoundException:NotFoundNotSavedWithFile'));
}
-
- // if still nothing then set filestore to default
- if (!$this->filestore)
- $this->filestore = get_default_filestore();
+ $this->filestore = new $parameters['filestore']();
- return $this->filestore;
+ // Set parameters
+ $this->filestore->setParameters($parameters);
}
-
- public function save()
- {
- if (!parent::save())
- return false;
-
- // Save datastore metadata
- $params = $this->filestore->getParameters();
- foreach ($params as $k => $v)
- $this->setMetaData("filestore::$k", $v);
-
- // Now make a note of the filestore class
- $this->setMetaData("filestore::filestore", get_class($this->filestore));
-
- return true;
+
+
+ // if still nothing then set filestore to default
+ if (!$this->filestore) {
+ $this->filestore = get_default_filestore();
}
-
+
+ return $this->filestore;
}
-
- /**
- * Get the size of the specified directory.
- *
- * @param string $dir The full path of the directory
- * @return int The size of the directory.
- */
- function get_dir_size($dir,$totalsize = 0){
- $handle = @opendir($dir);
- while ($file = @readdir ($handle)){
- if (eregi("^\.{1,2}$",$file))
- continue;
- if(is_dir($dir.$file)){
- $totalsize = get_dir_size($dir.$file."/",$totalsize);
- } else{
- $totalsize += filesize($dir.$file);
- }
- }
- @closedir($handle);
-
- return($totalsize);
- }
-
- /**
- * Get the contents of an uploaded file.
- * (Returns false if there was an issue.)
- *
- * @param string $input_name The name of the file input field on the submission form
- * @return mixed|false The contents of the file, or false on failure.
- */
- function get_uploaded_file($input_name) {
-
- // If the file exists ...
- if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
- return file_get_contents($_FILES[$input_name]['tmp_name']);
+
+ public function save() {
+ if (!parent::save()) {
+ return false;
}
- return false;
-
+
+ // Save datastore metadata
+ $params = $this->filestore->getParameters();
+ foreach ($params as $k => $v) {
+ $this->setMetaData("filestore::$k", $v);
+ }
+
+ // Now make a note of the filestore class
+ $this->setMetaData("filestore::filestore", get_class($this->filestore));
+
+ return true;
}
-
- /**
- * Gets the jpeg contents of the resized version of an uploaded image
- * (Returns false if the uploaded file was not an image)
- *
- * @param string $input_name The name of the file input field on the submission form
- * @param int $maxwidth The maximum width of the resized image
- * @param int $maxheight The maximum height of the resized image
- * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
- * @return false|mixed The contents of the resized image, or false on failure
- */
- function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false) {
- // If our file exists ...
- if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
-
- return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight, $square);
-
+}
+
+/**
+ * Get the size of the specified directory.
+ *
+ * @param string $dir The full path of the directory
+ * @return int The size of the directory.
+ */
+function get_dir_size($dir, $totalsize = 0){
+ $handle = @opendir($dir);
+ while ($file = @readdir ($handle)){
+ if (eregi("^\.{1,2}$", $file)) {
+ continue;
+ }
+ if(is_dir($dir . $file)) {
+ $totalsize = get_dir_size($dir . $file . "/", $totalsize);
+ } else{
+ $totalsize += filesize($dir . $file);
}
-
- return false;
}
-
- /**
- * Gets the jpeg contents of the resized version of an already uploaded image
- * (Returns false if the uploaded file was not an image)
- *
- * @param string $input_name The name of the file input field on the submission form
- * @param int $maxwidth The maximum width of the resized image
- * @param int $maxheight The maximum height of the resized image
- * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
- * @return false|mixed The contents of the resized image, or false on failure
- */
- function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
-
- // Get the size information from the image
- if ($imgsizearray = getimagesize($input_name)) {
-
- // Get width and height
- $width = $imgsizearray[0];
- $height = $imgsizearray[1];
+ @closedir($handle);
+
+ return($totalsize);
+}
+
+/**
+ * Get the contents of an uploaded file.
+ * (Returns false if there was an issue.)
+ *
+ * @param string $input_name The name of the file input field on the submission form
+ * @return mixed|false The contents of the file, or false on failure.
+ */
+function get_uploaded_file($input_name) {
+ // If the file exists ...
+ if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
+ return file_get_contents($_FILES[$input_name]['tmp_name']);
+ }
+ return false;
+}
+
+/**
+ * Gets the jpeg contents of the resized version of an uploaded image
+ * (Returns false if the uploaded file was not an image)
+ *
+ * @param string $input_name The name of the file input field on the submission form
+ * @param int $maxwidth The maximum width of the resized image
+ * @param int $maxheight The maximum height of the resized image
+ * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
+ * @return false|mixed The contents of the resized image, or false on failure
+ */
+function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false) {
+ // If our file exists ...
+ if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
+ return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight, $square);
+ }
+
+ return false;
+}
+
+/**
+ * Gets the jpeg contents of the resized version of an already uploaded image
+ * (Returns false if the uploaded file was not an image)
+ *
+ * @param string $input_name The name of the file input field on the submission form
+ * @param int $maxwidth The maximum width of the resized image
+ * @param int $maxheight The maximum height of the resized image
+ * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
+ * @return false|mixed The contents of the resized image, or false on failure
+ */
+function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
+ // Get the size information from the image
+ if ($imgsizearray = getimagesize($input_name)) {
+ // Get width and height
+ $width = $imgsizearray[0];
+ $height = $imgsizearray[1];
+ $newwidth = $width;
+ $newheight = $height;
+
+ // Square the image dimensions if we're wanting a square image
+ if ($square) {
+ if ($width < $height) {
+ $height = $width;
+ } else {
+ $width = $height;
+ }
+
$newwidth = $width;
$newheight = $height;
-
- // Square the image dimensions if we're wanting a square image
- if ($square) {
- if ($width < $height) {
- $height = $width;
+ }
+
+ if ($width > $maxwidth) {
+ $newheight = floor($height * ($maxwidth / $width));
+ $newwidth = $maxwidth;
+ }
+
+ if ($newheight > $maxheight) {
+ $newwidth = floor($newwidth * ($maxheight / $newheight));
+ $newheight = $maxheight;
+ }
+
+ $accepted_formats = array(
+ 'image/jpeg' => 'jpeg',
+ 'image/png' => 'png',
+ 'image/gif' => 'gif'
+ );
+
+ // If it's a file we can manipulate ...
+ if (array_key_exists($imgsizearray['mime'],$accepted_formats)) {
+ $function = "imagecreatefrom" . $accepted_formats[$imgsizearray['mime']];
+ $newimage = imagecreatetruecolor($newwidth,$newheight);
+
+ if (is_callable($function) && $oldimage = $function($input_name)) {
+ // Crop the image if we need a square
+ if ($square) {
+ if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
+ $widthoffset = floor(($imgsizearray[0] - $width) / 2);
+ $heightoffset = floor(($imgsizearray[1] - $height) / 2);
+ } else {
+ $widthoffset = $x1;
+ $heightoffset = $y1;
+ $width = ($x2 - $x1);
+ $height = $width;
+ }
} else {
- $width = $height;
- }
-
- $newwidth = $width;
- $newheight = $height;
-
- }
-
- if ($width > $maxwidth) {
- $newheight = floor($height * ($maxwidth / $width));
- $newwidth = $maxwidth;
- }
- if ($newheight > $maxheight) {
- $newwidth = floor($newwidth * ($maxheight / $newheight));
- $newheight = $maxheight;
- }
-
- $accepted_formats = array(
- 'image/jpeg' => 'jpeg',
- 'image/png' => 'png',
- 'image/gif' => 'gif'
- );
-
- // If it's a file we can manipulate ...
- if (array_key_exists($imgsizearray['mime'],$accepted_formats)) {
-
- $function = "imagecreatefrom" . $accepted_formats[$imgsizearray['mime']];
- $newimage = imagecreatetruecolor($newwidth,$newheight);
-
- if (is_callable($function) && $oldimage = $function($input_name)) {
-
- // Crop the image if we need a square
- if ($square) {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $widthoffset = floor(($imgsizearray[0] - $width) / 2);
- $heightoffset = floor(($imgsizearray[1] - $height) / 2);
- } else {
- $widthoffset = $x1;
- $heightoffset = $y1;
- $width = ($x2 - $x1);
- $height = $width;
- }
+ if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
+ $widthoffset = 0;
+ $heightoffset = 0;
} else {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $widthoffset = 0;
- $heightoffset = 0;
- } else {
- $widthoffset = $x1;
- $heightoffset = $y1;
- $width = ($x2 - $x1);
- $height = ($y2 - $y1);
- }
- }//else {
- // Resize and return the image contents!
- if ($square) {
- $newheight = $maxheight;
- $newwidth = $maxwidth;
- }
- imagecopyresampled($newimage, $oldimage, 0,0,$widthoffset,$heightoffset,$newwidth,$newheight,$width,$height);
- //}
-
- // imagecopyresized($newimage, $oldimage, 0,0,0,0,$newwidth,$newheight,$width,$height);
- ob_start();
- imagejpeg($newimage, null, 90);
- $jpeg = ob_get_clean();
- return $jpeg;
-
- }
-
+ $widthoffset = $x1;
+ $heightoffset = $y1;
+ $width = ($x2 - $x1);
+ $height = ($y2 - $y1);
+ }
+ }//else {
+ // Resize and return the image contents!
+ if ($square) {
+ $newheight = $maxheight;
+ $newwidth = $maxwidth;
+ }
+ imagecopyresampled($newimage, $oldimage, 0,0,$widthoffset,$heightoffset,$newwidth,$newheight,$width,$height);
+ //}
+
+ // imagecopyresized($newimage, $oldimage, 0,0,0,0,$newwidth,$newheight,$width,$height);
+ ob_start();
+ imagejpeg($newimage, null, 90);
+ $jpeg = ob_get_clean();
+ return $jpeg;
}
-
}
-
- return false;
}
-
-
- // putting these here for now
-
- function file_delete($guid) {
- if ($file = get_entity($guid)) {
-
- if ($file->canEdit()) {
-
- $container = get_entity($file->container_guid);
-
- $thumbnail = $file->thumbnail;
- $smallthumb = $file->smallthumb;
- $largethumb = $file->largethumb;
- if ($thumbnail) {
-
- $delfile = new ElggFile();
- $delfile->owner_guid = $file->owner_guid;
- $delfile->setFilename($thumbnail);
- $delfile->delete();
-
- }
- if ($smallthumb) {
-
- $delfile = new ElggFile();
- $delfile->owner_guid = $file->owner_guid;
- $delfile->setFilename($smallthumb);
- $delfile->delete();
-
- }
- if ($largethumb) {
-
- $delfile = new ElggFile();
- $delfile->owner_guid = $file->owner_guid;
- $delfile->setFilename($largethumb);
- $delfile->delete();
-
- }
-
- return $file->delete();
+
+ return false;
+}
+
+
+// putting these here for now
+
+function file_delete($guid) {
+ if ($file = get_entity($guid)) {
+ if ($file->canEdit()) {
+ $container = get_entity($file->container_guid);
+
+ $thumbnail = $file->thumbnail;
+ $smallthumb = $file->smallthumb;
+ $largethumb = $file->largethumb;
+ if ($thumbnail) {
+ $delfile = new ElggFile();
+ $delfile->owner_guid = $file->owner_guid;
+ $delfile->setFilename($thumbnail);
+ $delfile->delete();
+ }
+ if ($smallthumb) {
+ $delfile = new ElggFile();
+ $delfile->owner_guid = $file->owner_guid;
+ $delfile->setFilename($smallthumb);
+ $delfile->delete();
}
+ if ($largethumb) {
+ $delfile = new ElggFile();
+ $delfile->owner_guid = $file->owner_guid;
+ $delfile->setFilename($largethumb);
+ $delfile->delete();
+ }
+
+ return $file->delete();
}
-
- return false;
}
-
- /**
- * Returns an overall file type from the mimetype
- *
- * @param string $mimetype The MIME type
- * @return string The overall type
- */
- function file_get_general_file_type($mimetype) {
-
- switch($mimetype) {
-
- case "application/msword":
- return "document";
- break;
- case "application/pdf":
- return "document";
- break;
-
- }
-
- if (substr_count($mimetype,'text/'))
+
+ return false;
+}
+
+/**
+ * Returns an overall file type from the mimetype
+ *
+ * @param string $mimetype The MIME type
+ * @return string The overall type
+ */
+function file_get_general_file_type($mimetype) {
+ switch($mimetype) {
+
+ case "application/msword":
return "document";
-
- if (substr_count($mimetype,'audio/'))
- return "audio";
-
- if (substr_count($mimetype,'image/'))
- return "image";
-
- if (substr_count($mimetype,'video/'))
- return "video";
-
- if (substr_count($mimetype,'opendocument'))
- return "document";
-
- return "general";
-
- }
-
- function file_handle_upload($prefix,$subtype,$plugin) {
- $desc = get_input("description");
- $tags = get_input("tags");
- $tags = explode(",", $tags);
- $folder = get_input("folder_text");
- if (!$folder) {
- $folder = get_input("folder_select");
+ break;
+ case "application/pdf":
+ return "document";
+ break;
+ }
+
+ if (substr_count($mimetype,'text/')) {
+ return "document";
+ }
+
+ if (substr_count($mimetype,'audio/')) {
+ return "audio";
+ }
+
+ if (substr_count($mimetype,'image/')) {
+ return "image";
+ }
+
+ if (substr_count($mimetype,'video/')) {
+ return "video";
+ }
+
+ if (substr_count($mimetype,'opendocument')) {
+ return "document";
+ }
+
+ return "general";
+}
+
+function file_handle_upload($prefix,$subtype,$plugin) {
+ $desc = get_input("description");
+ $tags = get_input("tags");
+ $tags = explode(",", $tags);
+ $folder = get_input("folder_text");
+ if (!$folder) {
+ $folder = get_input("folder_select");
+ }
+ $access_id = (int) get_input("access_id");
+ $container_guid = (int) get_input('container_guid', 0);
+ if (!$container_guid) {
+ $container_guid == get_loggedin_userid();
+ }
+
+ // Extract file from, save to default filestore (for now)
+
+ // see if a plugin has set a quota for this user
+ $file_quota = trigger_plugin_hook("$plugin:quotacheck",'user',array('container_guid'=>$container_guid));
+ if (!$file_quota) {
+ // no, see if there is a generic quota set
+ $file_quota = get_plugin_setting('quota', $plugin);
+ }
+ if ($file_quota) {
+ // convert to megabytes
+ $file_quota = $file_quota*1000*1024;
+ }
+
+ // handle uploaded files
+ $number_of_files = get_input('number_of_files',0);
+ $quota_exceeded = false;
+ $bad_mime_type = false;
+
+ for ($i = 0; $i < $number_of_files; $i++) {
+ $title = get_input("title_".$i);
+ $uploaded = $_FILES["upload_".$i];
+ if (!$uploaded || !$uploaded['name']) {
+ // no such file, so skip it
+ continue;
}
- $access_id = (int) get_input("access_id");
- $container_guid = (int) get_input('container_guid', 0);
- if (!$container_guid)
- $container_guid == get_loggedin_userid();
-
- // Extract file from, save to default filestore (for now)
-
- // see if a plugin has set a quota for this user
- $file_quota = trigger_plugin_hook("$plugin:quotacheck",'user',array('container_guid'=>$container_guid));
- if (!$file_quota) {
- // no, see if there is a generic quota set
- $file_quota = get_plugin_setting('quota', $plugin);
+ if ($plugin == "photo") {
+ // do a mime type test
+ if (in_array($uploaded['type'],array('image/jpeg','image/gif','image/png','image/jpg','image/jpe','image/pjpeg','image/x-png'))) {
+ $file = new PhotoPluginFile();
+ } else {
+ $bad_mime_type = true;
+ break;
+ }
+ } else {
+ $file = new FilePluginFile();
}
+ $dir_size = $file->getFilestoreSize($prefix,$container_guid);
+ $filestorename = strtolower(time().$uploaded['name']);
+ $file->setFilename($prefix.$filestorename);
+ $file->setMimeType($uploaded['type']);
+
+ $file->originalfilename = $uploaded['name'];
+
+ $file->subtype = $subtype;
+
+ $file->access_id = $access_id;
+
+ $uf = get_uploaded_file('upload_'.$i);
+
if ($file_quota) {
- // convert to megabytes
- $file_quota = $file_quota*1000*1024;
- }
-
- // handle uploaded files
- $number_of_files = get_input('number_of_files',0);
- $quota_exceeded = false;
- $bad_mime_type = false;
-
- for ($i = 0; $i < $number_of_files; $i++) {
-
- $title = get_input("title_".$i);
- $uploaded = $_FILES["upload_".$i];
- if (!$uploaded || !$uploaded['name']) {
- // no such file, so skip it
- continue;
+ $file_size = strlen($uf);
+ if (($dir_size + $file_size) > $file_quota) {
+ $quota_exceeded = true;
}
- if ($plugin == "photo") {
- // do a mime type test
- if (in_array($uploaded['type'],array('image/jpeg','image/gif','image/png','image/jpg','image/jpe','image/pjpeg','image/x-png'))) {
- $file = new PhotoPluginFile();
- } else {
- $bad_mime_type = true;
- break;
- }
-
- } else {
- $file = new FilePluginFile();
- }
- $dir_size = $file->getFilestoreSize($prefix,$container_guid);
- $filestorename = strtolower(time().$uploaded['name']);
- $file->setFilename($prefix.$filestorename);
- $file->setMimeType($uploaded['type']);
-
- $file->originalfilename = $uploaded['name'];
-
- $file->subtype = $subtype;
-
- $file->access_id = $access_id;
-
- $uf = get_uploaded_file('upload_'.$i);
-
- if ($file_quota) {
- $file_size = strlen($uf);
- if (($dir_size + $file_size) > $file_quota) {
- $quota_exceeded = true;
- }
+ }
+
+ if (!$quota_exceeded) {
+ // all clear, so try to save the data
+
+ $file->open("write");
+ $file->write($uf);
+ $file->close();
+
+ $file->title = $title;
+ $file->description = $desc;
+ if ($container_guid) {
+ $file->container_guid = $container_guid;
}
-
- if (!$quota_exceeded) {
- // all clear, so try to save the data
-
- $file->open("write");
- $file->write($uf);
- $file->close();
-
- $file->title = $title;
- $file->description = $desc;
- if ($container_guid)
- $file->container_guid = $container_guid;
-
- // Save tags
- $file->tags = $tags;
-
- $file->simpletype = file_get_general_file_type($uploaded['type']);
- $file->folder = $folder;
-
- $result = $file->save();
-
- if ($result)
- {
-
- // Generate thumbnail (if image)
- if (substr_count($file->getMimeType(),'image/'))
- {
- $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),60,60, true);
- $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),153,153, true);
- $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),600,600, false);
- if ($thumbnail) {
- $thumb = new ElggFile();
- $thumb->setMimeType($uploaded['type']);
-
- $thumb->setFilename($prefix."thumb".$filestorename);
- $thumb->open("write");
- $thumb->write($thumbnail);
- $thumb->close();
-
- $file->thumbnail = $prefix."thumb".$filestorename;
-
- $thumb->setFilename($prefix."smallthumb".$filestorename);
- $thumb->open("write");
- $thumb->write($thumbsmall);
- $thumb->close();
- $file->smallthumb = $prefix."smallthumb".$filestorename;
-
- $thumb->setFilename($prefix."largethumb".$filestorename);
- $thumb->open("write");
- $thumb->write($thumblarge);
- $thumb->close();
- $file->largethumb = $prefix."largethumb".$filestorename;
-
- }
+
+ // Save tags
+ $file->tags = $tags;
+
+ $file->simpletype = file_get_general_file_type($uploaded['type']);
+ $file->folder = $folder;
+
+ $result = $file->save();
+
+ if ($result) {
+
+ // Generate thumbnail (if image)
+ if (substr_count($file->getMimeType(),'image/')) {
+ $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),60,60, true);
+ $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),153,153, true);
+ $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),600,600, false);
+ if ($thumbnail) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($uploaded['type']);
+
+ $thumb->setFilename($prefix."thumb".$filestorename);
+ $thumb->open("write");
+ $thumb->write($thumbnail);
+ $thumb->close();
+
+ $file->thumbnail = $prefix."thumb".$filestorename;
+
+ $thumb->setFilename($prefix."smallthumb".$filestorename);
+ $thumb->open("write");
+ $thumb->write($thumbsmall);
+ $thumb->close();
+ $file->smallthumb = $prefix."smallthumb".$filestorename;
+
+ $thumb->setFilename($prefix."largethumb".$filestorename);
+ $thumb->open("write");
+ $thumb->write($thumblarge);
+ $thumb->close();
+ $file->largethumb = $prefix."largethumb".$filestorename;
}
-
- // add to this user's file folders
- file_add_to_folders($folder,$container_guid,$plugin);
-
- add_to_river("river/object/$plugin/create",'create',$_SESSION['user']->guid,$file->guid);
- } else {
- break;
}
+
+ // add to this user's file folders
+ file_add_to_folders($folder,$container_guid,$plugin);
+
+ add_to_river("river/object/$plugin/create",'create',$_SESSION['user']->guid,$file->guid);
} else {
break;
}
+ } else {
+ break;
}
-
- if ($quota_exceeded) {
- echo elgg_echo("$plugin:quotaexceeded");
- } else if ($bad_mime_type) {
- echo elgg_echo("$plugin:badmimetype");
- } else if ($result) {
- if ($number_of_files > 1) {
- echo elgg_echo("$plugin:saved_multi");
- } else {
- echo elgg_echo("$plugin:saved");
- }
- } else {
- if ($number_of_files > 1) {
- echo elgg_echo("$plugin:uploadfailed_multi");
- } else {
- echo elgg_echo("$plugin:uploadfailed");
- }
+ }
+
+ if ($quota_exceeded) {
+ echo elgg_echo("$plugin:quotaexceeded");
+ } else if ($bad_mime_type) {
+ echo elgg_echo("$plugin:badmimetype");
+ } else if ($result) {
+ if ($number_of_files > 1) {
+ echo elgg_echo("$plugin:saved_multi");
+ } else {
+ echo elgg_echo("$plugin:saved");
+ }
+ } else {
+ if ($number_of_files > 1) {
+ echo elgg_echo("$plugin:uploadfailed_multi");
+ } else {
+ echo elgg_echo("$plugin:uploadfailed");
}
}
-
- function file_add_to_folders($folder,$container_guid,$plugin) {
- if ($container_guid && ($container = get_entity($container_guid))) {
- $folder_field_name = 'elgg_'.$plugin.'_folders';
- $folders = $container->$folder_field_name;
- if ($folders) {
- if (is_array($folders)) {
- if (!in_array($folder,$folders)) {
- $folders[] = $folder;
- $container->$folder_field_name = $folders;
- }
- } else {
- if ($folders != $folder) {
- $container->$folder_field_name = array($folders,$folder);
- }
+}
+
+function file_add_to_folders($folder,$container_guid,$plugin) {
+ if ($container_guid && ($container = get_entity($container_guid))) {
+ $folder_field_name = 'elgg_'.$plugin.'_folders';
+ $folders = $container->$folder_field_name;
+ if ($folders) {
+ if (is_array($folders)) {
+ if (!in_array($folder,$folders)) {
+ $folders[] = $folder;
+ $container->$folder_field_name = $folders;
+ }
+ } else {
+ if ($folders != $folder) {
+ $container->$folder_field_name = array($folders,$folder);
}
- } else {
- $container->$folder_field_name = $folder;
}
+ } else {
+ $container->$folder_field_name = $folder;
}
}
-
- function file_handle_save($forward,$plugin) {
- // Get variables
- $title = get_input("title");
- $desc = get_input("description");
- $tags = get_input("tags");
- $folder = get_input("folder_text");
- if (!$folder) {
- $folder = get_input("folder_select");
+}
+
+function file_handle_save($forward,$plugin) {
+ // Get variables
+ $title = get_input("title");
+ $desc = get_input("description");
+ $tags = get_input("tags");
+ $folder = get_input("folder_text");
+ if (!$folder) {
+ $folder = get_input("folder_select");
+ }
+ $access_id = (int) get_input("access_id");
+
+ $guid = (int) get_input('file_guid');
+
+ if (!$file = get_entity($guid)) {
+ register_error(elgg_echo("$plugin:uploadfailed"));
+ forward($forward . $_SESSION['user']->username);
+ exit;
+ }
+
+ $result = false;
+
+ $container_guid = $file->container_guid;
+ $container = get_entity($container_guid);
+
+ if ($file->canEdit()) {
+ $file->access_id = $access_id;
+ $file->title = $title;
+ $file->description = $desc;
+ $file->folder = $folder;
+ // add to this user's file folders
+ file_add_to_folders($folder,$container_guid,$plugin);
+
+ // Save tags
+ $tags = explode(",", $tags);
+ $file->tags = $tags;
+
+ $result = $file->save();
+ }
+
+ if ($result) {
+ system_message(elgg_echo("$plugin:saved"));
+ } else {
+ register_error(elgg_echo("$plugin:uploadfailed"));
+ }
+ forward($forward . $container->username);
+}
+
+/**
+ * Manage a file download.
+ *
+ * @param unknown_type $plugin
+ * @param unknown_type $file_guid If not specified then file_guid will be found in input.
+ */
+function file_manage_download($plugin, $file_guid = "") {
+ // Get the guid
+ $file_guid = (int)$file_guid;
+
+ if (!$file_guid) {
+ $file_guid = (int)get_input("file_guid");
+ }
+
+ // Get the file
+ $file = get_entity($file_guid);
+
+ if ($file) {
+ $mime = $file->getMimeType();
+ if (!$mime) {
+ $mime = "application/octet-stream";
}
- $access_id = (int) get_input("access_id");
-
- $guid = (int) get_input('file_guid');
-
- if (!$file = get_entity($guid)) {
- register_error(elgg_echo("$plugin:uploadfailed"));
- forward($forward . $_SESSION['user']->username);
- exit;
+
+ $filename = $file->originalfilename;
+
+ header("Content-type: $mime");
+ if (strpos($mime, "image/")!==false) {
+ header("Content-Disposition: inline; filename=\"$filename\"");
+ } else {
+ header("Content-Disposition: attachment; filename=\"$filename\"");
}
-
- $result = false;
-
- $container_guid = $file->container_guid;
- $container = get_entity($container_guid);
-
- if ($file->canEdit()) {
-
- $file->access_id = $access_id;
- $file->title = $title;
- $file->description = $desc;
- $file->folder = $folder;
- // add to this user's file folders
- file_add_to_folders($folder,$container_guid,$plugin);
-
- // Save tags
- $tags = explode(",", $tags);
- $file->tags = $tags;
-
- $result = $file->save();
+
+ echo $file->grabFile();
+ exit;
+ } else {
+ register_error(elgg_echo("$plugin:downloadfailed"));
+ }
+}
+
+/**
+ * Manage the download of a file icon.
+ *
+ * @param unknown_type $plugin
+ * @param unknown_type $file_guid The guid, if not specified this is obtained from the input.
+ */
+function file_manage_icon_download($plugin, $file_guid = "") {
+ // Get the guid
+ $file_guid = (int)$file_guid;
+
+ if (!$file_guid) {
+ $file_guid = (int)get_input("file_guid");
+ }
+
+ // Get the file
+ $file = get_entity($file_guid);
+
+ if ($file) {
+ $mime = $file->getMimeType();
+ if (!$mime) {
+ $mime = "application/octet-stream";
}
-
- if ($result)
- system_message(elgg_echo("$plugin:saved"));
- else
- register_error(elgg_echo("$plugin:uploadfailed"));
-
- forward($forward . $container->username);
- }
-
- /**
- * Manage a file download.
- *
- * @param unknown_type $plugin
- * @param unknown_type $file_guid If not specified then file_guid will be found in input.
- */
- function file_manage_download($plugin, $file_guid = "") {
- // Get the guid
- $file_guid = (int)$file_guid;
-
- if (!$file_guid)
- $file_guid = (int)get_input("file_guid");
-
- // Get the file
- $file = get_entity($file_guid);
-
- if ($file)
- {
- $mime = $file->getMimeType();
- if (!$mime) $mime = "application/octet-stream";
-
- $filename = $file->originalfilename;
-
- header("Content-type: $mime");
- if (strpos($mime, "image/")!==false)
- header("Content-Disposition: inline; filename=\"$filename\"");
- else
- header("Content-Disposition: attachment; filename=\"$filename\"");
-
- echo $file->grabFile();
- exit;
+
+ $filename = $file->thumbnail;
+
+ header("Content-type: $mime");
+ if (strpos($mime, "image/")!==false) {
+ header("Content-Disposition: inline; filename=\"$filename\"");
+ } else {
+ header("Content-Disposition: attachment; filename=\"$filename\"");
}
- else
- register_error(elgg_echo("$plugin:downloadfailed"));
- }
-
- /**
- * Manage the download of a file icon.
- *
- * @param unknown_type $plugin
- * @param unknown_type $file_guid The guid, if not specified this is obtained from the input.
- */
- function file_manage_icon_download($plugin, $file_guid = "") {
- // Get the guid
- $file_guid = (int)$file_guid;
-
- if (!$file_guid)
- $file_guid = (int)get_input("file_guid");
-
- // Get the file
- $file = get_entity($file_guid);
-
- if ($file)
+
+ $readfile = new ElggFile();
+ $readfile->owner_guid = $file->owner_guid;
+ $readfile->setFilename($filename);
+
+ /*
+ if ($file->open("read"));
{
- $mime = $file->getMimeType();
- if (!$mime) $mime = "application/octet-stream";
-
- $filename = $file->thumbnail;
-
- header("Content-type: $mime");
- if (strpos($mime, "image/")!==false)
- header("Content-Disposition: inline; filename=\"$filename\"");
- else
- header("Content-Disposition: attachment; filename=\"$filename\"");
-
-
- $readfile = new ElggFile();
- $readfile->owner_guid = $file->owner_guid;
- $readfile->setFilename($filename);
-
- /*
- if ($file->open("read"));
+ while (!$file->eof())
{
- while (!$file->eof())
- {
- echo $file->read(10240, $file->tell());
- }
+ echo $file->read(10240, $file->tell());
}
- */
-
- $contents = $readfile->grabFile();
- if (empty($contents)) {
- echo file_get_contents(dirname(dirname(__FILE__)) . "/graphics/icons/general.jpg" );
+ }
+ */
+
+ $contents = $readfile->grabFile();
+ if (empty($contents)) {
+ echo file_get_contents(dirname(dirname(__FILE__)) . "/graphics/icons/general.jpg" );
+ } else {
+ echo $contents;
+ }
+ exit;
+ } else {
+ register_error(elgg_echo("$plugin:downloadfailed"));
+ }
+}
+
+function file_display_thumbnail($file_guid,$size) {
+ // Get file entity
+ if ($file = get_entity($file_guid)) {
+ $simpletype = $file->simpletype;
+ if ($simpletype == "image") {
+ // Get file thumbnail
+ if ($size == "small") {
+ $thumbfile = $file->smallthumb;
} else {
+ $thumbfile = $file->largethumb;
+ }
+
+ // Grab the file
+ if ($thumbfile && !empty($thumbfile)) {
+ $readfile = new ElggFile();
+ $readfile->owner_guid = $file->owner_guid;
+ $readfile->setFilename($thumbfile);
+ $mime = $file->getMimeType();
+ $contents = $readfile->grabFile();
+
+ header("Content-type: $mime");
echo $contents;
+ exit;
}
- exit;
- }
- else
- register_error(elgg_echo("$plugin:downloadfailed"));
- }
-
- function file_display_thumbnail($file_guid,$size) {
- // Get file entity
- if ($file = get_entity($file_guid)) {
- $simpletype = $file->simpletype;
- if ($simpletype == "image") {
- // Get file thumbnail
- if ($size == "small") {
- $thumbfile = $file->smallthumb;
- } else {
- $thumbfile = $file->largethumb;
- }
-
- // Grab the file
- if ($thumbfile && !empty($thumbfile)) {
- $readfile = new ElggFile();
- $readfile->owner_guid = $file->owner_guid;
- $readfile->setFilename($thumbfile);
- $mime = $file->getMimeType();
- $contents = $readfile->grabFile();
-
- header("Content-type: $mime");
- echo $contents;
- exit;
-
- }
- }
}
}
-
- function file_set_page_owner($file) {
- $page_owner = page_owner_entity();
- if ($page_owner === false || is_null($page_owner)) {
- $container_guid = $file->container_guid;
- if (!empty($container_guid))
- if ($page_owner = get_entity($container_guid)) {
- set_page_owner($page_owner->guid);
- }
- if (empty($page_owner)) {
- $page_owner = $_SESSION['user'];
- set_page_owner($_SESSION['guid']);
+}
+
+function file_set_page_owner($file) {
+ $page_owner = page_owner_entity();
+ if ($page_owner === false || is_null($page_owner)) {
+ $container_guid = $file->container_guid;
+ if (!empty($container_guid)) {
+ if ($page_owner = get_entity($container_guid)) {
+ set_page_owner($page_owner->guid);
}
}
- }
- /// Variable holding the default datastore
- $DEFAULT_FILE_STORE = NULL;
-
- /**
- * Return the default filestore.
- *
- * @return ElggFilestore
- */
- function get_default_filestore()
- {
- global $DEFAULT_FILE_STORE;
-
- return $DEFAULT_FILE_STORE;
- }
-
- /**
- * Set the default filestore for the system.
- */
- function set_default_filestore(ElggFilestore $filestore)
- {
- global $DEFAULT_FILE_STORE;
-
- $DEFAULT_FILE_STORE = $filestore;
-
- return true;
+ if (empty($page_owner)) {
+ $page_owner = $_SESSION['user'];
+ set_page_owner($_SESSION['guid']);
+ }
}
+}
- /**
- * Run once and only once.
- */
- function filestore_run_once()
- {
- // Register a class
- add_subtype("object", "file", "ElggFile");
- }
-
- /**
- * Initialise the file modules.
- * Listens to system boot and registers any appropriate file types and classes
- */
- function filestore_init()
- {
- global $CONFIG;
-
- // Now register a default filestore
- set_default_filestore(new ElggDiskFilestore($CONFIG->dataroot));
-
- // Now run this stuff, but only once
- run_function_once("filestore_run_once");
- }
-
- // Register a startup event
- register_elgg_event_handler('init','system','filestore_init',100);
-?>
+/// Variable holding the default datastore
+$DEFAULT_FILE_STORE = NULL;
+
+/**
+ * Return the default filestore.
+ *
+ * @return ElggFilestore
+ */
+function get_default_filestore() {
+ global $DEFAULT_FILE_STORE;
+
+ return $DEFAULT_FILE_STORE;
+}
+
+/**
+ * Set the default filestore for the system.
+ */
+function set_default_filestore(ElggFilestore $filestore) {
+ global $DEFAULT_FILE_STORE;
+
+ $DEFAULT_FILE_STORE = $filestore;
+
+ return true;
+}
+
+/**
+ * Run once and only once.
+ */
+function filestore_run_once() {
+ // Register a class
+ add_subtype("object", "file", "ElggFile");
+}
+
+/**
+ * Initialise the file modules.
+ * Listens to system boot and registers any appropriate file types and classes
+ */
+function filestore_init() {
+ global $CONFIG;
+
+ // Now register a default filestore
+ set_default_filestore(new ElggDiskFilestore($CONFIG->dataroot));
+
+ // Now run this stuff, but only once
+ run_function_once("filestore_run_once");
+}
+
+// Register a startup event
+register_elgg_event_handler('init', 'system', 'filestore_init', 100);
\ No newline at end of file
diff --git a/engine/lib/group.php b/engine/lib/group.php
index 2941855f7..664837a27 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -1,937 +1,970 @@
attributes['type'] = "group";
+ $this->attributes['name'] = "";
+ $this->attributes['description'] = "";
+ $this->attributes['tables_split'] = 2;
+ }
/**
- * @class ElggGroup Class representing a container for other elgg entities.
- * @author Curverider Ltd
+ * 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.
*/
- 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));
+ 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)
- {
- foreach ($guid->attributes as $key => $value)
- $this->attributes[$key] = $value;
+ }
+ // Is $guid is an ElggGroup? Use a copy constructor
+ else if ($guid instanceof ElggGroup) {
+ 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)) IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid));
+ }
+ // 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)) {
+ 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();
+
+ else {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue'));
}
- 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 = "");
+ * Add an ElggObject to this group.
+ *
+ * @param ElggObject $object The object.
+ * @return bool
*/
-
- /**
- * 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));
- }
+ public function addObjectToGroup(ElggObject $object) {
+ return add_object_to_group($this->getGUID(), $object->getGUID());
+ }
- /**
- * 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
+ * Remove an object from the containing group.
+ *
+ * @param int $guid The guid of the object.
+ * @return bool
*/
-
- /**
- * 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);
- }
+ public function removeObjectFromGroup($guid) {
+ return remove_object_from_group($this->getGUID(), $guid);
+ }
-
-
- /**
- * 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())) $this->attributes['tables_loaded'] ++; // If $row isn't a cached copy then increment the counter
-
- // 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',
- ));
+ 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 = "");
+ */
+
/**
- * Get the group entity.
- *
- * @param int $guid
+ * For compatibility with Friendable
*/
- function get_group_entity_as_row($guid)
- {
- global $CONFIG;
-
- $guid = (int)$guid;
-
- /*$row = retrieve_cached_entity_row($guid);
- if ($row)
- {
- // We have already cached this object, so retrieve its value from the cache
- if (isset($CONFIG->debug) && $CONFIG->debug)
- error_log("** Retrieving sub part of GUID:$guid from cache");
-
- return $row;
- }
- else
- {*/
- // Object not cached, load it.
- if (isset($CONFIG->debug) && $CONFIG->debug == true)
- error_log("** Sub part of GUID:$guid loaded from DB");
-
- return get_data_row("SELECT * from {$CONFIG->dbprefix}groups_entity where guid=$guid");
- //}
+ public function addFriend($friend_guid) {
+ return $this->join(get_entity($friend_guid));
}
/**
- * Create or update the extras table for a given group.
- * Call create_entity first.
- *
- * @param int $guid
- * @param string $name
- * @param string $description
+ * For compatibility with Friendable
*/
- function create_group_entity($guid, $name, $description)
- {
- global $CONFIG;
-
- $guid = (int)$guid;
- $name = sanitise_string($name);
- $description = sanitise_string($description);
-
- $row = get_entity_as_row($guid);
-
- if ($row)
- {
- // Exists and you have access to it
- if ($exists = get_data_row("SELECT guid from {$CONFIG->dbprefix}groups_entity WHERE guid = {$guid}")) {
- $result = update_data("UPDATE {$CONFIG->dbprefix}groups_entity set name='$name', description='$description' where guid=$guid");
- if ($result!=false)
- {
- // Update succeeded, continue
- $entity = get_entity($guid);
- if (trigger_elgg_event('update',$entity->type,$entity)) {
- return $guid;
- } else {
- $entity->delete();
- //delete_entity($guid);
- }
- }
- }
- else
- {
- // Update failed, attempt an insert.
- $result = insert_data("INSERT into {$CONFIG->dbprefix}groups_entity (guid, name, description) values ($guid, '$name','$description')");
- if ($result!==false) {
- $entity = get_entity($guid);
- if (trigger_elgg_event('create',$entity->type,$entity)) {
- return $guid;
- } else {
- $entity->delete();
- //delete_entity($guid);
- }
- }
- }
- }
-
- return false;
+ public function removeFriend($friend_guid) {
+ return $this->leave(get_entity($friend_guid));
}
-
-
+
/**
- * THIS FUNCTION IS DEPRECATED.
- *
- * Delete a group's extra data.
- *
- * @param int $guid The guid of the group
- * @return bool
+ * For compatibility with Friendable
*/
- function delete_group_entity($guid)
- {
- system_message(sprintf(elgg_echo('deprecatedfunction'), 'delete_user_entity'));
-
- return 1; // Always return that we have deleted one row in order to not break existing code.
+ public function isFriend() {
+ return $this->isMember();
}
-
+
/**
- * Add an object to the given group.
- *
- * @param int $group_guid The group to add the object to.
- * @param int $object_guid The guid of the elgg object (must be ElggObject or a child thereof)
- * @return bool
+ * For compatibility with Friendable
*/
- function add_object_to_group($group_guid, $object_guid)
- {
- $group_guid = (int)$group_guid;
- $object_guid = (int)$object_guid;
-
- $group = get_entity($group_guid);
- $object = get_entity($object_guid);
-
- if ((!$group) || (!$object)) return false;
-
- if (!($group instanceof ElggGroup))
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $group_guid, 'ElggGroup'));
-
- if (!($object instanceof ElggObject))
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $object_guid, 'ElggObject'));
-
- $object->container_guid = $group_guid;
- return $object->save();
- }
-
+ public function isFriendsWith($user_guid) {
+ return $this->isMember($user_guid);
+ }
+
/**
- * Remove an object from the given group.
- *
- * @param int $group_guid The group to remove the object from
- * @param int $object_guid The object to remove
+ * For compatibility with Friendable
*/
- function remove_object_from_group($group_guid, $object_guid)
- {
- $group_guid = (int)$group_guid;
- $object_guid = (int)$object_guid;
-
- $group = get_entity($group_guid);
- $object = get_entity($object_guid);
-
- if ((!$group) || (!$object)) return false;
-
- if (!($group instanceof ElggGroup))
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $group_guid, 'ElggGroup'));
-
- if (!($object instanceof ElggObject))
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $object_guid, 'ElggObject'));
-
- $object->container_guid = $object->owner_guid;
- return $object->save();
- }
-
+ public function isFriendOf($user_guid) {
+ return $this->isMember($user_guid);
+ }
+
/**
- * Return an array of objects in a given container.
- * @see get_entities()
- *
- * @param int $group_guid The container (defaults to current page owner)
- * @param string $subtype The subtype
- * @param int $owner_guid Owner
- * @param int $site_guid The site
- * @param string $order_by Order
- * @param unknown_type $limit Limit on number of elements to return, by default 10.
- * @param unknown_type $offset Where to start, by default 0.
- * @param unknown_type $count Whether to return the entities or a count of them.
+ * For compatibility with Friendable
*/
- function get_objects_in_group($group_guid, $subtype = "", $owner_guid = 0, $site_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false)
- {
- global $CONFIG;
-
- if ($subtype === false || $subtype === null || $subtype === 0)
- return false;
-
- $subtype = get_subtype_id('object', $subtype);
-
- if ($order_by == "") $order_by = "e.time_created desc";
- $order_by = sanitise_string($order_by);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- $container_guid = (int)$group_guid;
- if ($container_guid == 0)
- $container_guid = page_owner();
-
- $where = array();
-
- $where[] = "e.type='object'";
- if ($subtype!=="")
- $where[] = "e.subtype=$subtype";
- if ($owner_guid != "") {
- if (!is_array($owner_guid)) {
- $owner_guid = (int) $owner_guid;
- $where[] = "e.container_guid = '$owner_guid'";
- } else if (sizeof($owner_guid) > 0) {
- // Cast every element to the owner_guid array to int
- $owner_guid = array_map("sanitise_int", $owner_guid);
- $owner_guid = implode(",",$owner_guid);
- $where[] = "e.container_guid in ({$owner_guid})";
- }
- }
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
-
- if ($container_guid > 0)
- $where[] = "e.container_guid = {$container_guid}";
-
- if (!$count) {
- $query = "SELECT * from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where ";
- } else {
- $query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where ";
- }
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix('e'); // Add access controls
- if (!$count) {
- $query .= " order by $order_by";
- if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
-
- $dt = get_data($query, "entity_row_to_elggstar");
- return $dt;
- } else {
- $total = get_data_row($query);
- return $total->total;
- }
+ public function getFriends($subtype = "", $limit = 10, $offset = 0) {
+ return get_group_members($this->getGUID(), $limit, $offset);
}
-
+
/**
- * Get all the entities from metadata from a group.
- *
- * @param int $group_guid The ID of the group.
- * @param mixed $meta_name
- * @param mixed $meta_value
- * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
- * @param string $entity_subtype The subtype of the entity.
- * @param int $limit
- * @param int $offset
- * @param string $order_by Optional ordering.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ * For compatibility with Friendable
*/
- function get_entities_from_metadata_groups($group_guid, $meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false)
- {
- global $CONFIG;
-
- $meta_n = get_metastring_id($meta_name);
- $meta_v = get_metastring_id($meta_value);
-
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- $limit = (int)$limit;
- $offset = (int)$offset;
- if ($order_by == "") $order_by = "e.time_created desc";
- $order_by = sanitise_string($order_by);
- $site_guid = (int) $site_guid;
- if (is_array($owner_guid)) {
- foreach($owner_guid as $key => $guid) {
- $owner_guid[$key] = (int) $guid;
- }
- } else {
- $owner_guid = (int) $owner_guid;
- }
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- $container_guid = (int)$group_guid;
- if ($container_guid == 0)
- $container_guid = page_owner();
-
- //$access = get_access_list();
-
- $where = array();
-
- if ($entity_type!="")
- $where[] = "e.type='$entity_type'";
- if ($entity_subtype)
- $where[] = "e.subtype=$entity_subtype";
- if ($meta_name!="")
- $where[] = "m.name_id='$meta_n'";
- if ($meta_value!="")
- $where[] = "m.value_id='$meta_v'";
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
- if ($container_guid > 0)
- $where[] = "e.container_guid = {$container_guid}";
- if (is_array($owner_guid)) {
- $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
- } else if ($owner_guid > 0)
- $where[] = "e.container_guid = {$owner_guid}";
-
- if (!$count) {
- $query = "SELECT distinct e.* ";
- } else {
- $query = "SELECT count(e.guid) as total ";
- }
-
- $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid join {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid where";
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix("e"); // Add access controls
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
- } else {
- if ($row = get_data_row($query))
- return $row->total;
- }
- return false;
+ public function getFriendsOf($subtype = "", $limit = 10, $offset = 0) {
+ return get_group_members($this->getGUID(), $limit, $offset);
}
-
+
/**
- * As get_entities_from_metadata_groups() but with multiple entities.
+ * Get objects contained in this group.
*
- * @param int $group_guid The ID of the group.
- * @param array $meta_array Array of 'name' => 'value' pairs
- * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
- * @param string $entity_subtype The subtype of the entity.
- * @param int $limit
+ * @param string $subtype
+ * @param int $limit
* @param int $offset
- * @param string $order_by Optional ordering.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
- * @return int|array List of ElggEntities, or the total number if count is set to false
+ * @return mixed
*/
- function get_entities_from_metadata_groups_multi($group_guid, $meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false)
- {
- global $CONFIG;
-
- if (!is_array($meta_array) || sizeof($meta_array) == 0) {
- return false;
- }
-
- $where = array();
-
- $mindex = 1;
- $join = "";
- foreach($meta_array as $meta_name => $meta_value) {
- $meta_n = get_metastring_id($meta_name);
- $meta_v = get_metastring_id($meta_value);
- $join .= " JOIN {$CONFIG->dbprefix}metadata m{$mindex} on e.guid = m{$mindex}.entity_guid join {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid ";
- if ($meta_name!="")
- $where[] = "m{$mindex}.name_id='$meta_n'";
- if ($meta_value!="")
- $where[] = "m{$mindex}.value_id='$meta_v'";
- $mindex++;
- }
-
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- $limit = (int)$limit;
- $offset = (int)$offset;
- if ($order_by == "") $order_by = "e.time_created desc";
- $order_by = sanitise_string($order_by);
- $owner_guid = (int) $owner_guid;
-
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- //$access = get_access_list();
-
- if ($entity_type!="")
- $where[] = "e.type = '{$entity_type}'";
- if ($entity_subtype)
- $where[] = "e.subtype = {$entity_subtype}";
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
- if ($owner_guid > 0)
- $where[] = "e.owner_guid = {$owner_guid}";
- if ($container_guid > 0)
- $where[] = "e.container_guid = {$container_guid}";
-
- if ($count) {
- $query = "SELECT count(e.guid) as total ";
- } else {
- $query = "SELECT distinct e.* ";
- }
-
- $query .= " from {$CONFIG->dbprefix}entities e {$join} where";
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix("e"); // Add access controls
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
- } else {
- if ($count = get_data_row($query)) {
- return $count->total;
- }
- }
- return false;
+ 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
+ */
+
/**
- * Return a list of this group's members.
- *
- * @param int $group_guid The ID of the container/group.
- * @param int $limit The limit
- * @param int $offset The offset
- * @param int $site_guid The site
- * @param bool $count Return the users (false) or the count of them (true)
+ * Get a list of group members.
+ *
+ * @param int $limit
+ * @param int $offset
* @return mixed
*/
- function get_group_members($group_guid, $limit = 10, $offset = 0, $site_guid = 0, $count = false)
- {
- return get_entities_from_relationship('member', $group_guid, true, 'user', '', 0, "", $limit, $offset, $count, $site_guid);
+ public function getMembers($limit = 10, $offset = 0, $count = false) {
+ return get_group_members($this->getGUID(), $limit, $offset, 0 , $count);
}
-
+
/**
- * Return whether a given user is a member of the group or not.
- *
- * @param int $group_guid The group ID
- * @param int $user_guid The user guid
+ * Returns whether the current group is public membership or not.
* @return bool
*/
- function is_group_member($group_guid, $user_guid)
- {
- return check_entity_relationship($user_guid, 'member', $group_guid);
+ public function isPublicMembership() {
+ if ($this->membership == ACCESS_PUBLIC) {
+ return true;
+ }
+
+ return false;
}
-
+
/**
- * Join a user to a group.
- *
- * @param int $group_guid The group.
- * @param int $user_guid The user.
+ * Return whether a given user is a member of this group or not.
+ *
+ * @param ElggUser $user The user
+ * @return bool
*/
- function join_group($group_guid, $user_guid)
- {
- $result = add_entity_relationship($user_guid, 'member', $group_guid);
- trigger_elgg_event('join','group',array('group' => get_entity($group_guid), 'user' => get_entity($user_guid)));
- return $result;
+ 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());
}
-
+
/**
- * Remove a user from a group.
- *
- * @param int $group_guid The group.
- * @param int $user_guid The user.
+ * Join an elgg user to this group.
+ *
+ * @param ElggUser $user
+ * @return bool
*/
- function leave_group($group_guid, $user_guid)
- {
- $result = remove_entity_relationship($user_guid, 'member', $group_guid);
- trigger_elgg_event('leave','group',array('group' => get_entity($group_guid), 'user' => get_entity($user_guid)));
- return $result;
+ public function join(ElggUser $user) {
+ return join_group($this->getGUID(), $user->getGUID());
}
-
+
/**
- * Return all groups a user is a member of.
+ * Remove a user from the group.
*
- * @param unknown_type $user_guid
+ * @param ElggUser $user
*/
- function get_users_membership($user_guid)
- {
- return get_entities_from_relationship('member', $user_guid, false);
+ public function leave(ElggUser $user) {
+ return leave_group($this->getGUID(), $user->getGUID());
}
-
+
/**
- * Checks access to a group.
+ * 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 boolean $forward If set to true (default), will forward the page; if set to false, will return true or false.
- * @return true|false If $forward is set to false.
+ * @param int $guid
*/
- function group_gatekeeper($forward = true) {
-
- $allowed = true;
- $url = '';
-
- if ($group = page_owner_entity()) {
- if ($group instanceof ElggGroup) {
- $url = $group->getURL();
- if (
- ((!isloggedin()) && (!$group->isPublicMembership())) ||
- ((!$group->isMember(get_loggedin_user()) && (!$group->isPublicMembership())))
- ) $allowed = false;
-
- // Admin override
- if (isadminloggedin()) $allowed = true;
- }
+ protected function load($guid) {
+ // Test to see if we have the generic stuff
+ if (!parent::load($guid)) {
+ return false;
}
-
- if ($forward && $allowed == false) {
- forward($url);
- exit;
+
+ // 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 $allowed;
-
+
+ return true;
}
-
+
/**
- * Manages group tool options
- *
- * @param string $name Name of the group tool option
- * @param string $label Used for the group edit form
- * @param boolean $default_on True if this option should be active by default
- *
- **/
-
- function add_group_tool_option($name,$label,$default_on=true) {
- global $CONFIG;
-
- if (!isset($CONFIG->group_tool_options)) {
- $CONFIG->group_tool_options = array();
+ * Override the save function.
+ */
+ public function save() {
+ // Save generic stuff
+ if (!parent::save()) {
+ return false;
}
-
- $group_tool_option = new stdClass;
-
- $group_tool_option->name = $name;
- $group_tool_option->label = $label;
- $group_tool_option->default_on = $default_on;
-
- $CONFIG->group_tool_options[] = $group_tool_option;
- }
-
+
+ // Now save specific stuff
+ return create_group_entity($this->get('guid'), $this->get('name'), $this->get('description'));
+ }
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
/**
- * Searches for a group based on a complete or partial name or description
- *
- * @param string $criteria The partial or full name or description
- * @param int $limit Limit of the search.
- * @param int $offset Offset.
- * @param string $order_by The order.
- * @param boolean $count Whether to return the count of results or just the results.
+ * Return an array of fields which can be exported.
*/
- function search_for_group($criteria, $limit = 10, $offset = 0, $order_by = "", $count = false)
+ public function getExportableValues() {
+ return array_merge(parent::getExportableValues(), array(
+ 'name',
+ 'description',
+ ));
+ }
+}
+
+/**
+ * Get the group entity.
+ *
+ * @param int $guid
+ */
+function get_group_entity_as_row($guid) {
+ global $CONFIG;
+
+ $guid = (int)$guid;
+
+ /*$row = retrieve_cached_entity_row($guid);
+ if ($row)
{
- global $CONFIG;
-
- $criteria = sanitise_string($criteria);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $order_by = sanitise_string($order_by);
-
- $access = get_access_sql_suffix("e");
-
- if ($order_by == "") $order_by = "e.time_created desc";
-
- if ($count) {
- $query = "SELECT count(e.guid) as total ";
- } else {
- $query = "SELECT e.* ";
- }
- $query .= "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}groups_entity g on e.guid=g.guid where ";
- // $query .= " match(u.name,u.username) against ('$criteria') ";
- $query .= "(g.name like \"%{$criteria}%\" or g.description like \"%{$criteria}%\")";
- $query .= " and $access";
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
+ // We have already cached this object, so retrieve its value from the cache
+ if (isset($CONFIG->debug) && $CONFIG->debug)
+ error_log("** Retrieving sub part of GUID:$guid from cache");
+
+ return $row;
+ }
+ else
+ {*/
+ // Object not cached, load it.
+ if (isset($CONFIG->debug) && $CONFIG->debug == true) {
+ error_log("** Sub part of GUID:$guid loaded from DB");
+ }
+
+ return get_data_row("SELECT * from {$CONFIG->dbprefix}groups_entity where guid=$guid");
+ //}
+}
+
+/**
+ * Create or update the extras table for a given group.
+ * Call create_entity first.
+ *
+ * @param int $guid
+ * @param string $name
+ * @param string $description
+ */
+function create_group_entity($guid, $name, $description) {
+ global $CONFIG;
+
+ $guid = (int)$guid;
+ $name = sanitise_string($name);
+ $description = sanitise_string($description);
+
+ $row = get_entity_as_row($guid);
+
+ if ($row) {
+ // Exists and you have access to it
+ if ($exists = get_data_row("SELECT guid from {$CONFIG->dbprefix}groups_entity WHERE guid = {$guid}")) {
+ $result = update_data("UPDATE {$CONFIG->dbprefix}groups_entity set name='$name', description='$description' where guid=$guid");
+ if ($result!=false) {
+ // Update succeeded, continue
+ $entity = get_entity($guid);
+ if (trigger_elgg_event('update',$entity->type,$entity)) {
+ return $guid;
+ } else {
+ $entity->delete();
+ //delete_entity($guid);
+ }
+ }
} else {
- if ($count = get_data_row($query)) {
- return $count->total;
+ // Update failed, attempt an insert.
+ $result = insert_data("INSERT into {$CONFIG->dbprefix}groups_entity (guid, name, description) values ($guid, '$name','$description')");
+ if ($result!==false) {
+ $entity = get_entity($guid);
+ if (trigger_elgg_event('create',$entity->type,$entity)) {
+ return $guid;
+ } else {
+ $entity->delete();
+ //delete_entity($guid);
+ }
}
}
+ }
+
+ return false;
+}
+
+
+/**
+ * THIS FUNCTION IS DEPRECATED.
+ *
+ * Delete a group's extra data.
+ *
+ * @param int $guid The guid of the group
+ * @return bool
+ */
+function delete_group_entity($guid) {
+ system_message(sprintf(elgg_echo('deprecatedfunction'), 'delete_user_entity'));
+
+ // Always return that we have deleted one row in order to not break existing code.
+ return 1;
+}
+
+/**
+ * Add an object to the given group.
+ *
+ * @param int $group_guid The group to add the object to.
+ * @param int $object_guid The guid of the elgg object (must be ElggObject or a child thereof)
+ * @return bool
+ */
+function add_object_to_group($group_guid, $object_guid) {
+ $group_guid = (int)$group_guid;
+ $object_guid = (int)$object_guid;
+
+ $group = get_entity($group_guid);
+ $object = get_entity($object_guid);
+
+ if ((!$group) || (!$object)) {
return false;
}
-
- /**
- * Returns a formatted list of groups suitable for injecting into search.
- *
- */
- function search_list_groups_by_name($hook, $user, $returnvalue, $tag) {
- // Change this to set the number of groups that display on the search page
- $threshold = 4;
+ if (!($group instanceof ElggGroup)) {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $group_guid, 'ElggGroup'));
+ }
+
+ if (!($object instanceof ElggObject)) {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $object_guid, 'ElggObject'));
+ }
+
+ $object->container_guid = $group_guid;
+ return $object->save();
+}
+
+/**
+ * Remove an object from the given group.
+ *
+ * @param int $group_guid The group to remove the object from
+ * @param int $object_guid The object to remove
+ */
+function remove_object_from_group($group_guid, $object_guid) {
+ $group_guid = (int)$group_guid;
+ $object_guid = (int)$object_guid;
+
+ $group = get_entity($group_guid);
+ $object = get_entity($object_guid);
+
+ if ((!$group) || (!$object)) {
+ return false;
+ }
+
+ if (!($group instanceof ElggGroup)) {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $group_guid, 'ElggGroup'));
+ }
+
+ if (!($object instanceof ElggObject)) {
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $object_guid, 'ElggObject'));
+ }
+
+ $object->container_guid = $object->owner_guid;
+ return $object->save();
+}
+
+/**
+ * Return an array of objects in a given container.
+ * @see get_entities()
+ *
+ * @param int $group_guid The container (defaults to current page owner)
+ * @param string $subtype The subtype
+ * @param int $owner_guid Owner
+ * @param int $site_guid The site
+ * @param string $order_by Order
+ * @param unknown_type $limit Limit on number of elements to return, by default 10.
+ * @param unknown_type $offset Where to start, by default 0.
+ * @param unknown_type $count Whether to return the entities or a count of them.
+ */
+function get_objects_in_group($group_guid, $subtype = "", $owner_guid = 0, $site_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false) {
+ global $CONFIG;
+
+ if ($subtype === false || $subtype === null || $subtype === 0) {
+ return false;
+ }
+
+ $subtype = get_subtype_id('object', $subtype);
+
+ if ($order_by == "") {
+ $order_by = "e.time_created desc";
+ }
+ $order_by = sanitise_string($order_by);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0) {
+ $site_guid = $CONFIG->site_guid;
+ }
+
+ $container_guid = (int)$group_guid;
+ if ($container_guid == 0) {
+ $container_guid = page_owner();
+ }
+
+ $where = array();
+
+ $where[] = "e.type='object'";
+ if ($subtype!=="") {
+ $where[] = "e.subtype=$subtype";
+ }
+ if ($owner_guid != "") {
+ if (!is_array($owner_guid)) {
+ $owner_guid = (int) $owner_guid;
+ $where[] = "e.container_guid = '$owner_guid'";
+ } else if (sizeof($owner_guid) > 0) {
+ // Cast every element to the owner_guid array to int
+ $owner_guid = array_map("sanitise_int", $owner_guid);
+ $owner_guid = implode(",",$owner_guid);
+ $where[] = "e.container_guid in ({$owner_guid})";
+ }
+ }
+ if ($site_guid > 0) {
+ $where[] = "e.site_guid = {$site_guid}";
+ }
+
+ if ($container_guid > 0) {
+ $where[] = "e.container_guid = {$container_guid}";
+ }
+
+ if (!$count) {
+ $query = "SELECT * from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where ";
+ } else {
+ $query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where ";
+ }
+ foreach ($where as $w) {
+ $query .= " $w and ";
+ }
+
+ // Add access controls
+ $query .= get_access_sql_suffix('e');
+ if (!$count) {
+ $query .= " order by $order_by";
+
+ // Add order and limit
+ if ($limit) {
+ $query .= " limit $offset, $limit";
+ }
+
+ $dt = get_data($query, "entity_row_to_elggstar");
+ return $dt;
+ } else {
+ $total = get_data_row($query);
+ return $total->total;
+ }
+}
+
+/**
+ * Get all the entities from metadata from a group.
+ *
+ * @param int $group_guid The ID of the group.
+ * @param mixed $meta_name
+ * @param mixed $meta_value
+ * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
+ * @param string $entity_subtype The subtype of the entity.
+ * @param int $limit
+ * @param int $offset
+ * @param string $order_by Optional ordering.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ */
+function get_entities_from_metadata_groups($group_guid, $meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
+ global $CONFIG;
+
+ $meta_n = get_metastring_id($meta_name);
+ $meta_v = get_metastring_id($meta_value);
+
+ $entity_type = sanitise_string($entity_type);
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ if ($order_by == "") {
+ $order_by = "e.time_created desc";
+ }
+ $order_by = sanitise_string($order_by);
+ $site_guid = (int) $site_guid;
+ if (is_array($owner_guid)) {
+ foreach($owner_guid as $key => $guid) {
+ $owner_guid[$key] = (int) $guid;
+ }
+ } else {
+ $owner_guid = (int) $owner_guid;
+ }
+ if ($site_guid == 0) {
+ $site_guid = $CONFIG->site_guid;
+ }
+
+ $container_guid = (int)$group_guid;
+ if ($container_guid == 0) {
+ $container_guid = page_owner();
+ }
+
+ //$access = get_access_list();
+
+ $where = array();
+
+ if ($entity_type!="") {
+ $where[] = "e.type='$entity_type'";
+ }
+ if ($entity_subtype) {
+ $where[] = "e.subtype=$entity_subtype";
+ }
+ if ($meta_name!="") {
+ $where[] = "m.name_id='$meta_n'";
+ }
+ if ($meta_value!="") {
+ $where[] = "m.value_id='$meta_v'";
+ }
+ if ($site_guid > 0) {
+ $where[] = "e.site_guid = {$site_guid}";
+ }
+ if ($container_guid > 0) {
+ $where[] = "e.container_guid = {$container_guid}";
+ }
+
+ if (is_array($owner_guid)) {
+ $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
+ } else if ($owner_guid > 0)
+ $where[] = "e.container_guid = {$owner_guid}";
+
+ if (!$count) {
+ $query = "SELECT distinct e.* ";
+ } else {
+ $query = "SELECT count(e.guid) as total ";
+ }
+
+ $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid join {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid where";
+ foreach ($where as $w) {
+ $query .= " $w and ";
+ }
+
+ // Add access controls
+ $query .= get_access_sql_suffix("e");
+
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($row = get_data_row($query)) {
+ return $row->total;
+ }
+ }
+ return false;
+}
+
+/**
+ * As get_entities_from_metadata_groups() but with multiple entities.
+ *
+ * @param int $group_guid The ID of the group.
+ * @param array $meta_array Array of 'name' => 'value' pairs
+ * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
+ * @param string $entity_subtype The subtype of the entity.
+ * @param int $limit
+ * @param int $offset
+ * @param string $order_by Optional ordering.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ * @return int|array List of ElggEntities, or the total number if count is set to false
+ */
+function get_entities_from_metadata_groups_multi($group_guid, $meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
+ global $CONFIG;
+
+ if (!is_array($meta_array) || sizeof($meta_array) == 0) {
+ return false;
+ }
+
+ $where = array();
+
+ $mindex = 1;
+ $join = "";
+ foreach($meta_array as $meta_name => $meta_value) {
+ $meta_n = get_metastring_id($meta_name);
+ $meta_v = get_metastring_id($meta_value);
+ $join .= " JOIN {$CONFIG->dbprefix}metadata m{$mindex} on e.guid = m{$mindex}.entity_guid join {$CONFIG->dbprefix}objects_entity o on e.guid = o.guid ";
+ if ($meta_name!="") {
+ $where[] = "m{$mindex}.name_id='$meta_n'";
+ }
+
+ if ($meta_value!="") {
+ $where[] = "m{$mindex}.value_id='$meta_v'";
+ }
+
+ $mindex++;
+ }
+
+ $entity_type = sanitise_string($entity_type);
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ if ($order_by == "") {
+ $order_by = "e.time_created desc";
+ }
+ $order_by = sanitise_string($order_by);
+ $owner_guid = (int) $owner_guid;
+
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0) {
+ $site_guid = $CONFIG->site_guid;
+ }
+
+ //$access = get_access_list();
+
+ if ($entity_type!="") {
+ $where[] = "e.type = '{$entity_type}'";
+ }
+
+ if ($entity_subtype) {
+ $where[] = "e.subtype = {$entity_subtype}";
+ }
+
+ if ($site_guid > 0) {
+ $where[] = "e.site_guid = {$site_guid}";
+ }
+
+ if ($owner_guid > 0) {
+ $where[] = "e.owner_guid = {$owner_guid}";
+ }
+
+ if ($container_guid > 0) {
+ $where[] = "e.container_guid = {$container_guid}";
+ }
+
+ if ($count) {
+ $query = "SELECT count(e.guid) as total ";
+ } else {
+ $query = "SELECT distinct e.* ";
+ }
+
+ $query .= " from {$CONFIG->dbprefix}entities e {$join} where";
+ foreach ($where as $w) {
+ $query .= " $w and ";
+ }
+ $query .= get_access_sql_suffix("e"); // Add access controls
+
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($count = get_data_row($query)) {
+ return $count->total;
+ }
+ }
+ return false;
+}
+
+/**
+ * Return a list of this group's members.
+ *
+ * @param int $group_guid The ID of the container/group.
+ * @param int $limit The limit
+ * @param int $offset The offset
+ * @param int $site_guid The site
+ * @param bool $count Return the users (false) or the count of them (true)
+ * @return mixed
+ */
+function get_group_members($group_guid, $limit = 10, $offset = 0, $site_guid = 0, $count = false) {
+ return get_entities_from_relationship('member', $group_guid, true, 'user', '', 0, "", $limit, $offset, $count, $site_guid);
+}
+
+/**
+ * Return whether a given user is a member of the group or not.
+ *
+ * @param int $group_guid The group ID
+ * @param int $user_guid The user guid
+ * @return bool
+ */
+function is_group_member($group_guid, $user_guid) {
+ return check_entity_relationship($user_guid, 'member', $group_guid);
+}
+
+/**
+ * Join a user to a group.
+ *
+ * @param int $group_guid The group.
+ * @param int $user_guid The user.
+ */
+function join_group($group_guid, $user_guid) {
+ $result = add_entity_relationship($user_guid, 'member', $group_guid);
+ trigger_elgg_event('join', 'group', array('group' => get_entity($group_guid), 'user' => get_entity($user_guid)));
+ return $result;
+}
+
+/**
+ * Remove a user from a group.
+ *
+ * @param int $group_guid The group.
+ * @param int $user_guid The user.
+ */
+function leave_group($group_guid, $user_guid) {
+ $result = remove_entity_relationship($user_guid, 'member', $group_guid);
+ trigger_elgg_event('leave', 'group', array('group' => get_entity($group_guid), 'user' => get_entity($user_guid)));
+ return $result;
+}
+
+/**
+ * Return all groups a user is a member of.
+ *
+ * @param unknown_type $user_guid
+ */
+function get_users_membership($user_guid) {
+ return get_entities_from_relationship('member', $user_guid, false);
+}
- $object = get_input('object');
-
- if (!get_input('offset') && (empty($object) || $object == 'group'))
+/**
+ * Checks access to a group.
+ *
+ * @param boolean $forward If set to true (default), will forward the page; if set to false, will return true or false.
+ * @return true|false If $forward is set to false.
+ */
+function group_gatekeeper($forward = true) {
+ $allowed = true;
+ $url = '';
+
+ if ($group = page_owner_entity()) {
+ if ($group instanceof ElggGroup) {
+ $url = $group->getURL();
+ if (
+ ((!isloggedin()) && (!$group->isPublicMembership())) ||
+ ((!$group->isMember(get_loggedin_user()) && (!$group->isPublicMembership())))
+ ) {
+ $allowed = false;
+ }
+
+ // Admin override
+ if (isadminloggedin()) {
+ $allowed = true;
+ }
+ }
+ }
+
+ if ($forward && $allowed == false) {
+ forward($url);
+ exit;
+ }
+
+ return $allowed;
+}
+
+/**
+ * Manages group tool options
+ *
+ * @param string $name Name of the group tool option
+ * @param string $label Used for the group edit form
+ * @param boolean $default_on True if this option should be active by default
+ *
+ **/
+
+function add_group_tool_option($name,$label,$default_on=true) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->group_tool_options)) {
+ $CONFIG->group_tool_options = array();
+ }
+
+ $group_tool_option = new stdClass;
+
+ $group_tool_option->name = $name;
+ $group_tool_option->label = $label;
+ $group_tool_option->default_on = $default_on;
+
+ $CONFIG->group_tool_options[] = $group_tool_option;
+}
+
+/**
+ * Searches for a group based on a complete or partial name or description
+ *
+ * @param string $criteria The partial or full name or description
+ * @param int $limit Limit of the search.
+ * @param int $offset Offset.
+ * @param string $order_by The order.
+ * @param boolean $count Whether to return the count of results or just the results.
+ */
+function search_for_group($criteria, $limit = 10, $offset = 0, $order_by = "", $count = false) {
+ global $CONFIG;
+
+ $criteria = sanitise_string($criteria);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $order_by = sanitise_string($order_by);
+
+ $access = get_access_sql_suffix("e");
+
+ if ($order_by == "") {
+ $order_by = "e.time_created desc";
+ }
+
+ if ($count) {
+ $query = "SELECT count(e.guid) as total ";
+ } else {
+ $query = "SELECT e.* ";
+ }
+ $query .= "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}groups_entity g on e.guid=g.guid where ";
+ // $query .= " match(u.name,u.username) against ('$criteria') ";
+ $query .= "(g.name like \"%{$criteria}%\" or g.description like \"%{$criteria}%\")";
+ $query .= " and $access";
+
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($count = get_data_row($query)) {
+ return $count->total;
+ }
+ }
+ return false;
+}
+
+/**
+ * Returns a formatted list of groups suitable for injecting into search.
+ *
+ */
+function search_list_groups_by_name($hook, $user, $returnvalue, $tag) {
+ // Change this to set the number of groups that display on the search page
+ $threshold = 4;
+
+ $object = get_input('object');
+
+ if (!get_input('offset') && (empty($object) || $object == 'group')) {
if ($groups = search_for_group($tag,$threshold)) {
-
$countgroups = search_for_group($tag,0,0,"",true);
-
+
$return = elgg_view('group/search/startblurb',array('count' => $countgroups, 'tag' => $tag));
foreach($groups as $group) {
$return .= elgg_view_entity($group);
}
$return .= elgg_view('group/search/finishblurb',array('count' => $countgroups, 'threshold' => $threshold, 'tag' => $tag));
return $return;
-
}
-
}
-
- /**
- * Displays a list of group objects that have been searched for.
- *
- * @see elgg_view_entity_list
- *
- * @param string $tag Search criteria
- * @param int $limit The number of entities to display on a page
- * @return string The list in a form suitable to display
- */
- function list_group_search($tag, $limit = 10) {
-
- $offset = (int) get_input('offset');
- $limit = (int) $limit;
- $count = (int) search_for_group($tag, 10, 0, '', true);
- $entities = search_for_group($tag, $limit, $offset);
-
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, false);
-
- }
-
- /**
- * Performs initialisation functions for groups
- *
- */
- function group_init() {
- // Register an entity type
- register_entity_type('group','');
-
- // Register a search hook
- register_plugin_hook('search','all','search_list_groups_by_name');
- }
-
- register_elgg_event_handler('init','system','group_init');
-
-?>
+}
+
+/**
+ * Displays a list of group objects that have been searched for.
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param string $tag Search criteria
+ * @param int $limit The number of entities to display on a page
+ * @return string The list in a form suitable to display
+ */
+function list_group_search($tag, $limit = 10) {
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = (int) search_for_group($tag, 10, 0, '', true);
+ $entities = search_for_group($tag, $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, false);
+
+}
+
+/**
+ * Performs initialisation functions for groups
+ *
+ */
+function group_init() {
+ // Register an entity type
+ register_entity_type('group','');
+
+ // Register a search hook
+ register_plugin_hook('search','all','search_list_groups_by_name');
+}
+
+register_elgg_event_handler('init','system','group_init');
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 49eb63f13..289542547 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -1,376 +1,362 @@
-
- * @link http://elgg.org/
- */
-
- /**
- * Get some input from variables passed on the GET or POST line.
- *
- * @param $variable string The variable we want to return.
- * @param $default mixed A default value for the variable if it is not found.
- * @param $filter_result If true then the result is filtered for bad tags.
- */
- function get_input($variable, $default = "", $filter_result = true)
- {
-
- global $CONFIG;
-
- if (isset($CONFIG->input[$variable])) {
- $var = $CONFIG->input[$variable];
-
- if ($filter_result)
- $var = filter_tags($var);
-
- return $var;
+/**
+ * Parameter input functions.
+ * This file contains functions for getting input from get/post variables.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+
+/**
+ * Get some input from variables passed on the GET or POST line.
+ *
+ * @param $variable string The variable we want to return.
+ * @param $default mixed A default value for the variable if it is not found.
+ * @param $filter_result If true then the result is filtered for bad tags.
+ */
+function get_input($variable, $default = "", $filter_result = true) {
+
+ global $CONFIG;
+
+ if (isset($CONFIG->input[$variable])) {
+ $var = $CONFIG->input[$variable];
+
+ if ($filter_result) {
+ $var = filter_tags($var);
}
-
- if (isset($_REQUEST[$variable])) {
-
- if (is_array($_REQUEST[$variable])) {
- $var = $_REQUEST[$variable];
- } else {
- $var = trim($_REQUEST[$variable]);
- }
-
- if ($filter_result)
- $var = filter_tags($var);
- return $var;
-
+ return $var;
+ }
+
+ if (isset($_REQUEST[$variable])) {
+ if (is_array($_REQUEST[$variable])) {
+ $var = $_REQUEST[$variable];
+ } else {
+ $var = trim($_REQUEST[$variable]);
}
- return $default;
+ if ($filter_result) {
+ $var = filter_tags($var);
+ }
+ return $var;
}
-
- /**
- * Sets an input value that may later be retrieved by get_input
- *
- * @param string $variable The name of the variable
- * @param string $value The value of the variable
- */
- function set_input($variable, $value) {
-
- global $CONFIG;
- if (!isset($CONFIG->input))
- $CONFIG->input = array();
-
- if (is_array($value))
- {
- foreach ($value as $key => $val)
- $value[$key] = trim($val);
-
- $CONFIG->input[trim($variable)] = $value;
+
+ return $default;
+}
+
+/**
+ * Sets an input value that may later be retrieved by get_input
+ *
+ * @param string $variable The name of the variable
+ * @param string $value The value of the variable
+ */
+function set_input($variable, $value) {
+ global $CONFIG;
+ if (!isset($CONFIG->input)) {
+ $CONFIG->input = array();
+ }
+
+ if (is_array($value)) {
+ foreach ($value as $key => $val) {
+ $value[$key] = trim($val);
}
- else
- $CONFIG->input[trim($variable)] = trim($value);
-
+
+ $CONFIG->input[trim($variable)] = $value;
+ } else {
+ $CONFIG->input[trim($variable)] = trim($value);
}
-
- /**
- * Filter tags from a given string based on registered hooks.
- * @param $var
- * @return mixed The filtered result
- */
- function filter_tags($var)
- {
- return trigger_plugin_hook('validate', 'input', null, $var);
+}
+
+/**
+ * Filter tags from a given string based on registered hooks.
+ * @param $var
+ * @return mixed The filtered result
+ */
+function filter_tags($var) {
+ return trigger_plugin_hook('validate', 'input', null, $var);
+}
+
+/**
+ * Sanitise file paths for input, ensuring that they begin and end with slashes etc.
+ *
+ * @param string $path The path
+ * @return string
+ */
+function sanitise_filepath($path) {
+ // Convert to correct UNIX paths
+ $path = str_replace('\\', '/', $path);
+
+ // Sort trailing slash
+ $path = trim($path);
+ $path = rtrim($path, " /");
+ $path = $path . "/";
+
+ return $path;
+}
+
+
+/**
+ * Takes a string and turns any URLs into formatted links
+ *
+ * @param string $text The input string
+ * @return string The output stirng with formatted links
+ **/
+function parse_urls($text) {
+ return preg_replace_callback('/(?"\'\!\(\)]+)/i',
+ create_function(
+ '$matches',
+ '
+ $url = $matches[1];
+ $urltext = str_replace("/", "/", $url);
+ return "$urltext";
+ '
+ ), $text);
+}
+
+function autop($pee, $br = 1) {
+ $pee = $pee . "\n"; // just to make things a little easier, pad the end
+ $pee = preg_replace('|
\s*
|', "\n\n", $pee);
+ // Space things out a little
+ $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
+ $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
+ $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
+ $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
+ if ( strpos($pee, '
', '', $pee);
+ $pee = preg_replace('!\s*(?' . $allblocks . '[^>]*>)!', "$1", $pee);
+ $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
+ if ($br) {
+ $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "", $matches[0]);'), $pee);
+ $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks
+ $pee = str_replace('', "\n", $pee);
}
-
-
- /**
- * Takes a string and turns any URLs into formatted links
- *
- * @param string $text The input string
- * @return string The output stirng with formatted links
- **/
- function parse_urls($text) {
-
- return preg_replace_callback('/(?"\'\!\(\)]+)/i',
- create_function(
- '$matches',
- '
- $url = $matches[1];
- $urltext = str_replace("/", "/", $url);
- return "$urltext";
- '
- ), $text);
- }
-
- function autop($pee, $br = 1) {
- $pee = $pee . "\n"; // just to make things a little easier, pad the end
- $pee = preg_replace('|
\s*
|', "\n\n", $pee);
- // Space things out a little
- $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
- $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
- $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
- $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
- if ( strpos($pee, '