aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/annotations.php12
-rw-r--r--engine/lib/entities.php7
-rw-r--r--engine/lib/extender.php1
-rw-r--r--engine/lib/metadata.php8
-rw-r--r--engine/lib/relationships.php7
-rw-r--r--engine/lib/river.php71
-rw-r--r--engine/lib/system_log.php45
-rw-r--r--engine/schema/mysql.sql2
8 files changed, 146 insertions, 7 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 8a690769d..e04c302e1 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -98,8 +98,16 @@
function delete()
{
return delete_annotation($this->id);
- }
-
+ }
+
+ // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) { return get_annotation($id); }
}
/**
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 674a6a8fe..d3edb2ef3 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -549,6 +549,13 @@
* Return the class name of the object.
*/
public function getClassName() { return get_class($this); }
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) { return get_entity($id); }
// ITERATOR INTERFACE //////////////////////////////////////////////////////////////
/*
diff --git a/engine/lib/extender.php b/engine/lib/extender.php
index a4e8af879..2f35d4aea 100644
--- a/engine/lib/extender.php
+++ b/engine/lib/extender.php
@@ -146,6 +146,7 @@
*/
public function getClassName() { return get_class($this); }
+
// ITERATOR INTERFACE //////////////////////////////////////////////////////////////
/*
* This lets an entity's attributes be displayed using foreach as a normal array.
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 50edd903b..dd678b599 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -95,6 +95,14 @@
return delete_metadata($this->id);
}
+ // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) { return get_metadata($id); }
}
/**
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index 5b9627860..ba6f0182f 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -184,6 +184,13 @@
*/
public function getClassName() { return get_class($this); }
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) { return get_relationship($id); }
+
// ITERATOR INTERFACE //////////////////////////////////////////////////////////////
/*
* This lets an entity's attributes be displayed using foreach as a normal array.
diff --git a/engine/lib/river.php b/engine/lib/river.php
index d1b55ad11..dd6da4801 100644
--- a/engine/lib/river.php
+++ b/engine/lib/river.php
@@ -11,5 +11,74 @@
* @link http://elgg.org/
*/
- // event listener
+ /**
+ * Extract a list of river events from the current system log.
+ * This function retrieves the objects from the system log and will attempt to render
+ * the view "river/CLASSNAME" where CLASSNAME is the class of the object the system event is referring to.
+ *
+ * This view will be passed the log entry (as 'log_entry') and the object (as 'object') which will be accessable
+ * through the $vars[] array.
+ *
+ * It returns an array of the result of each of these views.
+ *
+ * @param int $limit
+ * @param int $offset
+ * @return array
+ */
+ function get_river_entries($limit = 10, $offset = 0)
+ {
+ // set start limit and offset
+ $cnt = $limit;
+ $off = $offset;
+
+ $exit = false;
+
+ // River objects
+ $river = array();
+
+ do
+ {
+ $log_events = get_system_log("","", $cnt, $off);
+
+ if (!$log_events)
+ $exit = true;
+ else
+ {
+ foreach ($log_events as $log)
+ {
+ // See if we have access to the object we're talking about
+ $class = $log->object_class;
+ $tmp = new $class();
+ $object = $tmp->getObjectFromID($log->object_id);
+
+ // Exists and we have access to it
+ if (is_a($object, $class))
+ {
+ // See if anything can handle it
+ $tam = "";
+
+ // test if view exist and if so
+ $tam = elgg_view("river/$class", array(
+ 'log_entry' => $log,
+ 'object' => $object
+ ));
+
+ if ($tam)
+ {
+ $river[] = $tam;
+ $off++;
+ $cnt--;
+ }
+ }
+ }
+ }
+
+ } while (
+ ($cnt > 0) &&
+ (!$exit)
+ );
+
+ return $river;
+ }
+
?> \ No newline at end of file
diff --git a/engine/lib/system_log.php b/engine/lib/system_log.php
index e47475287..f7a44fb7d 100644
--- a/engine/lib/system_log.php
+++ b/engine/lib/system_log.php
@@ -27,9 +27,50 @@
public function getSystemLogID();
/**
- * Return the class name of the object. Added as a function because get_class causes errors for some reason.
+ * Return the class name of the object.
+ * Added as a function because get_class causes errors for some reason.
*/
public function getClassName();
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id);
+ }
+
+ /**
+ * Retrieve the system log based on a number of parameters.
+ *
+ * @param string $event The event you are searching on.
+ * @param string $class The class of object it effects.
+ * @param int $limit
+ * @param int $offset
+ */
+ function get_system_log($event = "", $class = "", $limit = 10, $offset = 0)
+ {
+ global $CONFIG;
+
+ $event = sanitise_string($event);
+ $class = sanitise_string($class);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+
+ $access = get_access_list();
+
+ $where = array();
+
+ if ($event != "")
+ $where[] = "event='$event'";
+ if ($class!=="")
+ $where[] = "object_class='$class'";
+
+ $query = "SELECT * from {$CONFIG->dbprefix}system_log where 1 ";
+ foreach ($where as $w)
+ $query .= " and $w";
+
+ return get_data($query);
}
/**
@@ -51,7 +92,7 @@
$time = time();
// Create log
- return insert_data("INSERT into {$CONFIG->dbprefix}system_log (object_id, object_class, event, time_created) VALUES ('$object_id','$object_class','$event','$time')");
+ return insert_data("INSERT into {$CONFIG->dbprefix}system_log (object_id, object_class, event, time_created) VALUES ('$object_id','$object_class','$event', '$time')");
}
}
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql
index 859ba2612..33f5e4054 100644
--- a/engine/schema/mysql.sql
+++ b/engine/schema/mysql.sql
@@ -243,8 +243,6 @@ CREATE TABLE `prefix_system_log (
`event` varchar(128) NOT NULL,
- `access_id` int(11) NOT NULL,
-
`time_created` int(11) NOT NULL,
PRIMARY KEY (`id`)