diff options
Diffstat (limited to 'mod/activity')
-rw-r--r-- | mod/activity/all.php | 24 | ||||
-rw-r--r-- | mod/activity/friends.php | 31 | ||||
-rw-r--r-- | mod/activity/index.php | 29 | ||||
-rw-r--r-- | mod/activity/languages/en.php | 29 | ||||
-rw-r--r-- | mod/activity/manifest.xml | 9 | ||||
-rw-r--r-- | mod/activity/start.php | 288 | ||||
-rw-r--r-- | mod/activity/views/default/activity/dashboard.php | 14 | ||||
-rw-r--r-- | mod/activity/views/default/activity/wrapper.php | 51 | ||||
-rw-r--r-- | mod/activity/views/default/settings/activity/edit.php | 11 |
9 files changed, 486 insertions, 0 deletions
diff --git a/mod/activity/all.php b/mod/activity/all.php new file mode 100644 index 000000000..b844bffd4 --- /dev/null +++ b/mod/activity/all.php @@ -0,0 +1,24 @@ +<?php + /** + * Elgg activity plugin. + * + * @package ElggActivity + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + + $limit = get_input('limit', 20); + $offset = get_input('offset'); + $type = get_input('type'); + $subtype = get_input('subtype'); + $title = elgg_view_title(elgg_echo('activity:all')); + + $body = elgg_view('activity/dashboard', array('activity' => activity_get_activity($limit, $offset, $type, $subtype))); + + page_draw(elgg_echo('activity:all'),elgg_view_layout("two_column_left_sidebar", '', $title . $body)); + +?>
\ No newline at end of file diff --git a/mod/activity/friends.php b/mod/activity/friends.php new file mode 100644 index 000000000..da9e142b4 --- /dev/null +++ b/mod/activity/friends.php @@ -0,0 +1,31 @@ +<?php + /** + * Elgg activity plugin. + * + * @package ElggActivity + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + + $owner = page_owner_entity(); + $limit = get_input('limit', 20); + $offset = get_input('offset'); + + $title_txt = sprintf(elgg_echo('activity:person:friends'), $owner->name); + $title = elgg_view_title($title_txt); + + $activity = activity_get_activity($limit, $offset, $type, $subtype, page_owner(), 'friend'); + if (count($activity)>0) + $body = ""; + else + $body = elgg_echo('activity:nofriendactivity'); + + + + page_draw($title_txt, elgg_view_layout("two_column_left_sidebar", '', $title . $body)); + +?>
\ No newline at end of file diff --git a/mod/activity/index.php b/mod/activity/index.php new file mode 100644 index 000000000..090ebc0c2 --- /dev/null +++ b/mod/activity/index.php @@ -0,0 +1,29 @@ +<?php + /** + * Elgg activity plugin. + * + * @package ElggActivity + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + + $limit = get_input('limit', 20); + $offset = get_input('offset'); + $type = get_input('type'); + $subtype = get_input('subtype'); + $title = elgg_view_title(elgg_echo('activity:your')); + + if (page_owner()) + { + $body = elgg_view('activity/dashboard', array('activity' => activity_get_activity($limit, $offset, $type, $subtype, page_owner()))); + } + else + $body = elgg_echo('activity:usernotfound'); + + page_draw(elgg_echo('activity:your'),elgg_view_layout("two_column_left_sidebar", '', $title . $body)); + +?>
\ No newline at end of file diff --git a/mod/activity/languages/en.php b/mod/activity/languages/en.php new file mode 100644 index 000000000..116884b7b --- /dev/null +++ b/mod/activity/languages/en.php @@ -0,0 +1,29 @@ +<?php + /** + * Elgg activity plugin language pack. + * + * @package ElggActivity + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + $english = array( + + 'activity:all' => 'Site activity', + 'activity:your' => 'Your activity', + 'activity:friends' => 'Your friend\'s activity', + 'activity:person' => '%s\'s activity', + 'activity:person:friends' => '%s\'s friend\'s activity', + + 'activity:useasdashboard' => 'Do you wish to use the activity stream as the dashboard?', + + 'activity:noactivity' => 'Sorry, there is currently no activity that matches your search criteria', + + 'activity:usernotfound' => 'User not found', + 'activity:nofriendactivity' => 'No activity, perhaps you should add some more friends?', + ); + + add_translation("en",$english); +?>
\ No newline at end of file diff --git a/mod/activity/manifest.xml b/mod/activity/manifest.xml new file mode 100644 index 000000000..afbca482f --- /dev/null +++ b/mod/activity/manifest.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest> + <field key="author" value="Marcus Povey" /> + <field key="version" value="1.0" /> + <field key="description" value="A rich activity river providing a useful summary of activity." /> + <field key="website" value="http://www.elgg.org/" /> + <field key="copyright" value="(C) Curverider 2008" /> + <field key="licence" value="GNU Public License version 2" /> +</plugin_manifest>
\ No newline at end of file diff --git a/mod/activity/start.php b/mod/activity/start.php new file mode 100644 index 000000000..73f4cfc70 --- /dev/null +++ b/mod/activity/start.php @@ -0,0 +1,288 @@ +<?php + /** + * Elgg activity plugin. + * + * @package ElggActivity + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + /** + * Initialise the activity. + * + */ + function activity_init() + { + global $CONFIG; + + // Register and optionally replace the dashboard + if (get_plugin_setting('useasdashboard', 'activity') == 'yes') + register_page_handler('dashboard','activity_page_handler'); + + // Page handler + register_page_handler('activity','activity_page_handler'); + + // Activity main menu + if (isloggedin()) + { + add_menu(elgg_echo('activity:your'), $CONFIG->wwwroot . "pg/activity/{$_SESSION['user']->username}/", array(), 'activity'); + } + } + + /** + * Post init gumph. + */ + function activity_page_setup() + { + global $CONFIG; + + if ((get_context()=='activity') || (get_context()=='dashboard')) + { + add_submenu_item(elgg_echo('activity:your'), $CONFIG->wwwroot."pg/activity/{$_SESSION['user']->username}/"); + add_submenu_item(elgg_echo('activity:friends'), $CONFIG->wwwroot."pg/activity/{$_SESSION['user']->username}/friends/"); + add_submenu_item(elgg_echo('activity:all'), $CONFIG->wwwroot."pg/activity/"); + } + } + + /** + * Page handler for activity. + * + * @param unknown_type $page + */ + function activity_page_handler($page) + { + global $CONFIG; + + if ($page[0]) + set_input('username', $page[0]); + + if ($page[0]) { + if ($page[1]) + { + switch ($page[1]) + { + case 'friends' : + include($CONFIG->pluginspath . "activity/friends.php"); + break; + } + } + else + include($CONFIG->pluginspath . "activity/index.php"); + } else + include($CONFIG->pluginspath . "activity/all.php"); + } + + /** + * Pull activity from the system log. + * + * This works in a similar way to the river code, but looks for activity views instead. + * + * @param int $limit Limit the query. + * @param int $offset Execute from the given object + * @param mixed $type A type, or array of types to look for. Note: This is how they appear in the SYSTEM LOG. + * @param mixed $subtype A subtype, or array of types to look for. Note: This is how they appear in the SYSTEM LOG. + * @param mixed $owner_guid The guid or a collection of GUIDs + * @param string $owner_relationship If defined, the relationship between $owner_guid and the entity owner_guid - so "is $owner_guid $owner_relationship with $entity->owner_guid" + * @return array An array of pre-rendered elgg_views on the data. + */ + function activity_get_activity($limit = 10, $offset = 0, $type = "", $subtype = "", $owner_guid = "", $owner_relationship = "" ) + { + global $CONFIG; + + $limit = (int)$limit; + $offset = (int)$offset; + + if (!is_array($type)) + $type = array(sanitise_string($type)); + else + foreach ($type as $k => $v) + $type[$k] = sanitise_string($v); + + if (!is_array($subtype)) + $subtype = array(sanitise_string($subtype)); + else + foreach ($subtype as $k => $v) + $subtype[$k] = sanitise_string($v); + + if (is_array($owner_guid)) + foreach ($owner_guid as $k => $v) + $owner_guid[$k] = (int)$v; + else + $owner_guid = array((int)$owner_guid); + + $owner_relationship = sanitise_string($owner_relationship); + + // Get a list of possible views + $activity_events= array(); + $activity_views = array_merge(elgg_view_tree('activity'), elgg_view_tree('river')); // Join activity with river + + $done = array(); + + foreach ($activity_views as $view) + { + $fragments = explode('/', $view); + $tmp = explode('/',$view, 2); + $tmp = $tmp[1]; + + if ((isset($fragments[0])) && (($fragments[0] == 'river') || ($fragments[0] == 'activity')) + && (!in_array($tmp, $done))) + { + if (isset($fragments[1])) + { + $f = array(); + for ($n = 1; $n < count($fragments); $n++) + { + $val = sanitise_string($fragments[$n]); + switch($n) + { + case 1: $key = 'type'; break; + case 2: $key = 'subtype'; break; + case 3: $key = 'event'; break; + } + $f[$key] = $val; + } + $activity_events[] = $f; + } + + $done[] = $tmp; + } + + + } + + $n = 0; + foreach ($activity_events as $details) + { + // Get what we're talking about + + if ($details['subtype'] == 'default') $details['subtype'] = ''; + + if (($details['type']) && ($details['event'])) { + if ($n>0) $obj_query .= " or "; + + $access = ""; + if ($details['type']!='relationship') + $access = " and " . get_access_sql_suffix('sl'); + + $obj_query .= "( sl.object_type='{$details['type']}' and sl.object_subtype='{$details['subtype']}' and sl.event='{$details['event']}' $access )"; + + $n++; + } + + } + + // User + if (count($owner_guid) && ($owner_guid[0]!=0)) + $user = " and sl.performed_by_guid in (".implode(',', $owner_guid).")"; + + // Relationship + $relationship_query = ""; + $relationship_join = ""; + if ($relationship) + { + $relationship_join = " join {$CONFIG->dbprefix}entity_relationships r on sl.performed_by_guid=r.entity_guid "; + $relationship_query = "r.relationship = '$relationship'"; + } + + $query = "SELECT sl.* from {$CONFIG->dbprefix}system_log sl $relationship_join where 1 $user and $relationship_query ($obj_query) order by sl.time_created desc limit $offset, $limit"; + $log_data = get_data($query); + + // until count reached, loop through and render + $activity = array(); + + if ($log_data) + { + foreach ($log_data as $log) + { + // See if we have access to the object we're talking about + $event = $log->event; + $class = $log->object_class; + $type = $log->object_type; + $subtype = $log->object_subtype; + $tmp = new $class(); + $object = $tmp->getObjectFromID($log->object_id); + $by_user_obj = get_entity($log->performed_by_guid); + + // Belts and braces + if ($object instanceof $class) + { + $tam = ""; + + // Construct the statement + $statement_object = $object; // Simple object, we don't need to do more + + // This is a relationship, slighty more complicated + if ($object instanceof ElggRelationship) { + + $statement_object = array( + 'subject' => get_entity($object->guid_one), + 'relationship' => $object->relationship,// Didn' cast to int here deliberately + 'object' => get_entity($object->guid_two) + ); + + // Metadata or annotations, also slightly more complicated + } else if ($object instanceof ElggExtender) { + $statement_object = array( + 'subject' => $object, + 'object' => get_entity($object->entity_guid) + ); + } + + // Put together a river statement + $statement = new ElggRiverStatement($by_user_obj, $event, $statement_object); + + // Now construct and call the appropriate views + + if ($subtype == "widget") { // Special case for widgets + $subtype = "widget/" . $object->handler; + } + if ($subtype == '') + $subtype = 'default'; + + + $activity_view = 'activity'; + if (!elgg_view_exists("$activity_view/$type/$subtype/$event")) + $activity_view = 'river'; + + $tam = elgg_view("$activity_view/$type/$subtype/$event", array( + 'statement' => $statement + )); + + + // Giftwrap + if (!empty($tam)) { + $tam = elgg_view("activity/wrapper",array( + 'entry' => $tam, + 'time' => $log->time_created, + 'event' => $event, + 'statement' => $statement + )); + } + + $activity[] = $tam; + } + } + } + + return $activity; + + } + + // river index with tabs to drill down + + + + + /// BONUS POINTS + + // comment on feed items + + // comment on search terms/ tags + + + // Initialise plugin + register_elgg_event_handler('init','system','activity_init'); + register_elgg_event_handler('pagesetup','system','activity_page_setup'); +?>
\ No newline at end of file diff --git a/mod/activity/views/default/activity/dashboard.php b/mod/activity/views/default/activity/dashboard.php new file mode 100644 index 000000000..3e626b49f --- /dev/null +++ b/mod/activity/views/default/activity/dashboard.php @@ -0,0 +1,14 @@ +<?php + /// Extract the activity + $activity = $vars['activity']; +?> +<div id="activity"> + <?php + if (($activity) && (count($activity))) + { + foreach ($activity as $a) echo $a; + } + else + echo elgg_echo('activity:noactivity'); + ?> +</div>
\ No newline at end of file diff --git a/mod/activity/views/default/activity/wrapper.php b/mod/activity/views/default/activity/wrapper.php new file mode 100644 index 000000000..88ba6ef57 --- /dev/null +++ b/mod/activity/views/default/activity/wrapper.php @@ -0,0 +1,51 @@ +<?php + + /** + * Elgg activity 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 + * @link http://elgg.com/ + */ + + $statement = $vars['statement']; + $time = $vars['time']; + $event = $vars['event']; + $entry = $vars['entry']; + + if ($statement->getObject() instanceof ElggEntity) { + + $obj = $statement->getObject(); + $subtype = $obj->getSubtype(); + if (empty($subtype)) $subtype = $obj->type; + if (empty($subtype)) $subtype = "general"; + } else if (is_array($statement->getObject())) { + $obj = $statement->getObject(); + $subtype = "relationship_" . $obj['relationship']; + } +?> +<div class="activity_item"> + + <div class="activity_<?php echo $subtype; ?>"> + <div class="activity_<?php echo $event; ?>"> + <p class="activity_<?php echo $subtype; ?>_<?php echo $event; ?>"> + <?php + + echo $vars['entry']; + + ?> + <span class="activity_item_time"> + (<?php + + echo friendly_time($time); + + ?>) + </span> + </p> + </div> + </div> + +</div> diff --git a/mod/activity/views/default/settings/activity/edit.php b/mod/activity/views/default/settings/activity/edit.php new file mode 100644 index 000000000..bfb1a9dbe --- /dev/null +++ b/mod/activity/views/default/settings/activity/edit.php @@ -0,0 +1,11 @@ +<?php +?> +<p> + <?php echo elgg_echo('activity:useasdashboard'); ?> + + <select name="params[useasdashboard]"> + <option value="yes" <?php if ($vars['entity']->useasdashboard == 'yes') echo " selected=\"yes\" "; ?>><?php echo elgg_echo('option:yes'); ?></option> + <option value="no" <?php if ($vars['entity']->useasdashboard != 'yes') echo " selected=\"yes\" "; ?>><?php echo elgg_echo('option:no'); ?></option> + </select> + +</p> |