aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/river2.php252
-rw-r--r--engine/schema/mysql.sql19
-rw-r--r--engine/schema/upgrades/2009021201.sql19
-rw-r--r--version.php4
-rw-r--r--views/default/river/item/list.php17
-rw-r--r--views/default/river/item/wrapper.php38
6 files changed, 347 insertions, 2 deletions
diff --git a/engine/lib/river2.php b/engine/lib/river2.php
new file mode 100644
index 000000000..577cefc16
--- /dev/null
+++ b/engine/lib/river2.php
@@ -0,0 +1,252 @@
+<?php
+
+ /**
+ * Elgg river 2.0.
+ * Functions for listening for and generating the river separately from the system log.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.org/
+ */
+
+ /**
+ * Adds an item to the river.
+ *
+ * @param string $view The view that will handle the river item (must exist)
+ * @param string $action_type An arbitrary one-word string to define the action (eg 'comment', 'create')
+ * @param int $subject_guid The GUID of the entity doing the action
+ * @param int $object_guid The GUID of the entity being acted upon
+ * @param int $access_id The access ID of the river item (default: same as the object)
+ * @param int $posted The UNIX epoch timestamp of the river item (default: now)
+ * @return true|false Depending on success
+ */
+ function add_to_river(
+ $view,
+ $action_type,
+ $subject_guid,
+ $object_guid,
+ $access_id = -1,
+ $posted = 0
+ ) {
+
+ // Sanitise variables
+ if (!elgg_view_exists($view)) return false;
+ if (!($subject = get_entity($subject_guid))) return false;
+ if (!($object = get_entity($object_guid))) return false;
+ if (empty($action_type)) return false;
+ if ($posted == 0) $posted = time();
+ if ($access_id == -1) $access_id = $object->access_id;
+
+ $type = $object->getType();
+ $subtype = $object->getSubtype();
+
+ $action_type = sanitise_string($action_type);
+
+ // Load config
+ global $CONFIG;
+
+ // Attempt to save river item; return success status
+ return insert_data("insert into {$CONFIG->dbprefix}river " .
+ " set type = '{$type}', " .
+ " subtype = '{$subtype}', " .
+ " action_type = '{$action_type}', " .
+ " access_id = {$access_id}, " .
+ " view = '{$view}', " .
+ " subject_guid = {$subject_guid}, " .
+ " object_guid = {$object_guid}, " .
+ " posted = {$posted} ");
+
+ }
+
+ /**
+ * Removes all items relating to a particular acting entity from the river
+ *
+ * @param int $subject_guid The GUID of the entity
+ * @return true|false Depending on success
+ */
+ function remove_from_river_by_subject(
+ $subject_guid
+ ) {
+
+ // Sanitise
+ $subject_guid = (int) $subject_guid;
+
+ // Load config
+ global $CONFIG;
+
+ // Remove
+ return delete_data("delete from {$CONFIG->dbprefix}river where subject_guid = {$subject_guid}");
+
+ }
+
+ /**
+ * Removes all items relating to a particular entity being acted upon from the river
+ *
+ * @param int $object_guid The GUID of the entity
+ * @return true|false Depending on success
+ */
+ function remove_from_river_by_object(
+ $object_guid
+ ) {
+
+ // Sanitise
+ $object_guid = (int) $object_guid;
+
+ // Load config
+ global $CONFIG;
+
+ // Remove
+ return delete_data("delete from {$CONFIG->dbprefix}river where object_guid = {$object_guid}");
+
+ }
+
+ /**
+ * Retrieves items from the river. All parameters are optional.
+ *
+ * @param int|array $subject_guid Acting entity to restrict to. Default: all
+ * @param int|array $object_guid Entity being acted on to restrict to. Default: all
+ * @param string $subject_relationship If set to a relationship type, this will use $subject_guid as the starting point and set the subjects to be all users this entity has this relationship with (eg 'friend'). Default: blank
+ * @param string $type The type of entity to restrict to. Default: all
+ * @param string $subtype The subtype of entity to restrict to. Default: all
+ * @param string $action_type The type of river action to restrict to. Default: all
+ * @param int $limit The number of items to retrieve. Default: 20
+ * @param int $offset The page offset. Default: 0
+ * @param int $posted_min The minimum time period to look at. Default: none
+ * @param int $posted_max The maximum time period to look at. Default: none
+ * @return array|false Depending on success
+ */
+ function get_river_items(
+ $subject_guid = 0,
+ $object_guid = 0,
+ $subject_relationship = '',
+ $type = '',
+ $subtype = '',
+ $action_type = '',
+ $limit = 20,
+ $offset = 0,
+ $posted_min = 0,
+ $posted_max = 0
+ ) {
+
+ // Sanitise variables
+ if (!is_array($subject_guid)) {
+ $subject_guid = (int) $subject_guid;
+ } else {
+ foreach($subject_guid as $key => $temp) {
+ $subject_guid[$key] = (int) $temp;
+ }
+ }
+ if (!is_array($object_guid)) {
+ $object_guid = (int) $object_guid;
+ } else {
+ foreach($object_guid as $key => $temp) {
+ $object_guid[$key] = (int) $temp;
+ }
+ }
+ if (!empty($type)) $action_type = sanitise_string($type);
+ if (!empty($subtype)) $action_type = sanitise_string($subtype);
+ if (!empty($action_type)) $action_type = sanitise_string($action_type);
+ $limit = (int) $limit;
+ $offset = (int) $offset;
+ $posted_min = (int) $posted_min;
+ $posted_max = (int) $posted_max;
+
+ // Construct 'where' clauses for the river
+ $where = array();
+ $where[] = get_access_sql_suffix();
+
+ if (empty($subject_relationship)) {
+ if (!empty($subject_guid))
+ if (!is_array($subject_guid)) {
+ $where[] = " subject_guid = {$subject_guid} ";
+ } else {
+ $where[] = " subject_guid in (" . implode(',',$subject_guid) . ") ";
+ }
+ } else {
+ if (!is_array($subject_guid))
+ if ($entities = get_entities_from_relationship($subject_relationship,$subject_guid,false,'','',0,'',9999)) {
+ $guids = array();
+ foreach($entities as $entity) $guids[] = (int) $entity->guid;
+ $guids[] = $subject_guid;
+ $where[] = " subject_guid in (" . implode(',',$guids) . ") ";
+ }
+ }
+ if (!empty($object_guid))
+ if (!is_array($object_guid)) {
+ $where[] = " object_guid = {$object_guid} ";
+ } else {
+ $where[] = " object_guid in (" . implode(',',$object_guid) . ") ";
+ }
+ if (!empty($type)) $where[] = " type = '{$type}' ";
+ if (!empty($subtype)) $where[] = " subtype = '{$subtype}' ";
+ if (!empty($action_type)) $where[] = " action_type = '{$action_type}' ";
+ if (!empty($posted_min)) $where[] = " posted > {$posted_min} ";
+ if (!empty($posted_max)) $where[] = " posted < {$posted_max} ";
+
+ $whereclause = implode(' and ', $where);
+
+ // Construct main SQL
+ $sql = "select id,type,subtype,action_type,access_id,view,subject_guid,object_guid,posted from {$CONFIG->dbprefix}river where {$whereclause} limit {$offset},{$limit}";
+
+ // Get data
+ return get_data($sql);
+
+ }
+
+ /**
+ * Returns a human-readable representation of a river item
+ *
+ * @see get_river_items
+ *
+ * @param stdClass $item A river item object as returned from get_river_items
+ * @return string|false Depending on success
+ */
+ function elgg_view_river_item($item) {
+ if (isset($item->view)) {
+
+ if (elgg_view_exists($item->view)) {
+ $body = elgg_view($item->view,array(
+ 'item' => $item
+ ));
+ }
+ return elgg_view('river/item/wrapper',array(
+ 'item' => $item,
+ 'body' => $body
+ ));
+
+ }
+ return false;
+ }
+
+ function elgg_view_river_items($subject_guid = 0,
+ $object_guid = 0,
+ $subject_relationship = '',
+ $type = '',
+ $subtype = '',
+ $action_type = '',
+ $limit = 20,
+ $posted_min = 0,
+ $posted_max = 0) {
+
+ // Get input from outside world and sanitise it
+ $offset = (int) get_input('offset',0);
+
+ // Get river items, if they exist
+ if ($riveritems = get_river_items($subject_guid,$object_guid,$subject_relationship,$type,$subtype,$action_type,$limit,$offset,$posted_min,$posted_max)) {
+
+ return elgg_view('river/item/list',array(
+ 'limit' => $limit,
+ 'offset' => $offset,
+ 'items' => $riveritems,
+ ));
+
+ }
+
+ return '';
+
+ }
+
+?> \ No newline at end of file
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql
index 2a62d3c92..87e8adafb 100644
--- a/engine/schema/mysql.sql
+++ b/engine/schema/mysql.sql
@@ -349,3 +349,22 @@ CREATE TABLE `prefix_system_log` (
KEY `river_key` (`object_type`, `object_subtype`, `event`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+-- River
+ CREATE TABLE `prefix_river` (
+ `id` INT NOT NULL AUTO_INCREMENT ,
+ `type` VARCHAR( 8 ) NOT NULL ,
+ `subtype` VARCHAR( 32 ) NOT NULL ,
+ `action_type` VARCHAR( 32 ) NOT NULL ,
+ `access_id` INT NOT NULL ,
+ `view` TEXT NOT NULL ,
+ `subject_guid` INT NOT NULL ,
+ `object_guid` INT NOT NULL ,
+ `posted` INT NOT NULL ,
+ PRIMARY KEY ( `id` ) ,
+ KEY `type` (`type`),
+ KEY `action_type` (`action_type`),
+ KEY `access_id` (`access_id`),
+ KEY `subject_guid` (`subject_guid`),
+ KEY `object_guid` (`object_guid`,),
+ KEY `posted` (`posted`)
+) ENGINE = MYISAM DEFAULT CHARSET=utf8; \ No newline at end of file
diff --git a/engine/schema/upgrades/2009021201.sql b/engine/schema/upgrades/2009021201.sql
new file mode 100644
index 000000000..e3edf66ba
--- /dev/null
+++ b/engine/schema/upgrades/2009021201.sql
@@ -0,0 +1,19 @@
+-- River
+ CREATE TABLE IF NOT EXISTS `prefix_river` (
+ `id` INT NOT NULL AUTO_INCREMENT ,
+ `type` VARCHAR( 8 ) NOT NULL ,
+ `subtype` VARCHAR( 32 ) NOT NULL ,
+ `action_type` VARCHAR( 32 ) NOT NULL ,
+ `access_id` INT NOT NULL ,
+ `view` TEXT NOT NULL ,
+ `subject_guid` INT NOT NULL ,
+ `object_guid` INT NOT NULL ,
+ `posted` INT NOT NULL ,
+ PRIMARY KEY ( `id` ) ,
+ KEY `type` (`type`),
+ KEY `action_type` (`action_type`),
+ KEY `access_id` (`access_id`),
+ KEY `subject_guid` (`subject_guid`),
+ KEY `object_guid` (`object_guid`),
+ KEY `posted` (`posted`)
+) ENGINE = MYISAM DEFAULT CHARSET=utf8; \ No newline at end of file
diff --git a/version.php b/version.php
index f5c3d5c8f..8ce8f88db 100644
--- a/version.php
+++ b/version.php
@@ -13,9 +13,9 @@
* @link http://elgg.org/
*/
- $version = 2009012301; // YYYYMMDD = Elgg Date
+ $version = 2009021201; // YYYYMMDD = Elgg Date
// XX = Interim incrementer
- $release = '1.2'; // Human-friendly version name
+ $release = '1.4'; // Human-friendly version name
?> \ No newline at end of file
diff --git a/views/default/river/item/list.php b/views/default/river/item/list.php
new file mode 100644
index 000000000..781c18a48
--- /dev/null
+++ b/views/default/river/item/list.php
@@ -0,0 +1,17 @@
+
+<div class="river_item_list">
+<?php
+
+ if (isset($vars['items']) && is_array($vars['items'])) {
+
+ if (!empty($vars['items']))
+ foreach($vars['items'] as $item) {
+
+ echo elgg_view_river_item($item);
+
+ }
+
+ }
+
+?>
+</div> \ No newline at end of file
diff --git a/views/default/river/item/wrapper.php b/views/default/river/item/wrapper.php
new file mode 100644
index 000000000..efa377ceb
--- /dev/null
+++ b/views/default/river/item/wrapper.php
@@ -0,0 +1,38 @@
+<?php
+
+ /**
+ * Elgg river item wrapper.
+ * Wraps all river items.
+ *
+ * @package Elgg
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.com/
+ */
+
+
+?>
+
+ <div class="river_item">
+ <div class="river_<?php echo $vars['item']->type; ?>">
+ <div class="river_<?php echo $vars['item']->subtype; ?>">
+ <div class="river_<?php echo $vars['item']->action_type; ?>">
+ <div class="river_<?php echo $vars['item']->type; ?>_<?php echo $vars['item']->subtype; ?>_<?php echo $vars['item']->action_type; ?>">
+ <span class="river_item_time">
+ <?php
+
+ echo $vars['body'];
+
+ ?>
+ (<?php
+
+ echo friendly_time($vars['item']->posted);
+
+ ?>)
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div> \ No newline at end of file