diff options
-rw-r--r-- | actions/friends/add.php | 35 | ||||
-rw-r--r-- | actions/friends/remove.php | 35 | ||||
-rw-r--r-- | engine/lib/social.php | 2 | ||||
-rw-r--r-- | engine/lib/users.php | 68 | ||||
-rw-r--r-- | friends/index.php | 37 | ||||
-rw-r--r-- | friends/of.php | 37 | ||||
-rw-r--r-- | languages/en.php | 25 | ||||
-rw-r--r-- | mod/profile/views/default/profile/menu.php | 33 | ||||
-rw-r--r-- | mod/profile/views/default/profile/userdetails.php | 78 | ||||
-rw-r--r-- | mod/profile/views/default/user/user.php | 65 | ||||
-rw-r--r-- | views/default/friends/list.php | 27 |
11 files changed, 378 insertions, 64 deletions
diff --git a/actions/friends/add.php b/actions/friends/add.php new file mode 100644 index 000000000..ab413a6ba --- /dev/null +++ b/actions/friends/add.php @@ -0,0 +1,35 @@ +<?php
+
+ /**
+ * Elgg add friend action
+ *
+ * @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
+ * @link http://elgg.org/
+ */
+
+ // Ensure we are logged in
+ gatekeeper();
+
+ // Get the GUID of the user to friend
+ $friend_guid = get_input('friend');
+ $friend = get_entity($friend_guid);
+
+ // Get the user
+ if ($_SESSION['user']->addFriend($friend_guid)) {
+
+ system_message(sprintf(elgg_echo("friends:add:successful"),$friend->name));
+
+ } else {
+
+ system_message(sprintf(elgg_echo("friends:add:failure"),$friend->name));
+
+ }
+
+ // Forward to the user friends page
+ forward("pg/friends/" . $_SESSION['user']->username . "/");
+
+?>
\ No newline at end of file diff --git a/actions/friends/remove.php b/actions/friends/remove.php new file mode 100644 index 000000000..b6a846fa6 --- /dev/null +++ b/actions/friends/remove.php @@ -0,0 +1,35 @@ +<?php
+
+ /**
+ * Elgg remove friend action
+ *
+ * @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
+ * @link http://elgg.org/
+ */
+
+ // Ensure we are logged in
+ gatekeeper();
+
+ // Get the GUID of the user to friend
+ $friend_guid = get_input('friend');
+ $friend = get_entity($friend_guid);
+
+ // Get the user
+ if ($_SESSION['user']->removeFriend($friend_guid) && get_class($friend) == "ElggUser") {
+
+ system_message(sprintf(elgg_echo("friends:remove:successful"),$friend->name));
+
+ } else {
+
+ system_message(sprintf(elgg_echo("friends:remove:failure"),$friend->name));
+
+ }
+
+ // Forward to the user friends page
+ forward("pg/friends/" . $_SESSION['user']->username . "/");
+
+?>
\ No newline at end of file diff --git a/engine/lib/social.php b/engine/lib/social.php index bc66c0466..14328376e 100644 --- a/engine/lib/social.php +++ b/engine/lib/social.php @@ -62,6 +62,8 @@ }
// Set the shout words blacklist, these do not become tags when the string is converted
+ // Any language packs should include their own!
+
GLOBAL $CONFIG;
$CONFIG->wordblacklist = array(
'and',
diff --git a/engine/lib/users.php b/engine/lib/users.php index 358abc133..ffa39570a 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -216,7 +216,7 @@ *
* @return true|false
*/
- function isFriend() { return user_is_friend($this->getGUID(), $_SESSION['id']); }
+ function isFriend() { return user_is_friend($_SESSION['guid'], $this->getGUID()); }
/**
* Determines whether this user is friends with another user
@@ -244,6 +244,16 @@ */
function getFriends($subtype = "", $limit = 10, $offset = 0) { return get_user_friends($this->getGUID(), $subtype, $limit, $offset); }
+ /**
+ * Retrieves a list of people who have made this user a friend
+ *
+ * @param string $subtype Optionally, the subtype of user to filter to (leave blank for all)
+ * @param int $limit The number of users to retrieve
+ * @param int $offset Indexing offset, if any
+ * @return array|false Array of ElggUsers, or false, depending on success
+ */
+ function getFriendsOf($subtype = "", $limit = 10, $offset = 0) { return get_user_friends_of($this->getGUID(), $subtype, $limit, $offset); }
+
/**
* Get an array of ElggObjects owned by this user.
*
@@ -404,6 +414,9 @@ function user_add_friend($user_guid, $friend_guid) {
$user_guid = (int) $user_guid;
$friend_guid = (int) $friend_guid;
+ if (!$friend = get_entity($friend_guid)) return false;
+ if (!$user = get_entity($user_guid)) return false;
+ if (get_class($user) != "ElggUser" || get_class($friend) != "ElggUser") return false;
return add_entity_relationship($user_guid, "friend", $friend_guid);
}
@@ -443,6 +456,19 @@ function get_user_friends($user_guid, $subtype = "", $limit = 10, $offset = 0) {
return get_entities_from_relationship("friend",$user_guid,false,"user",$subtype,0,"time_created desc",$limit,$offset);
}
+
+ /**
+ * Obtains the people who have made a given user a friend
+ *
+ * @param int $user_guid The user's GUID
+ * @param string $subtype The subtype of users, if any
+ * @param int $limit Number of results to return (default 10)
+ * @param int $offset Indexing offset, if any
+ * @return false|array Either an array of ElggUsers or false, depending on success
+ */
+ function get_user_friends_of($user_guid, $subtype = "", $limit = 10, $offset = 0) {
+ return get_entities_from_relationship("friend",$user_guid,true,"user",$subtype,0,"time_created desc",$limit,$offset);
+ }
/**
* Obtains a list of objects owned by a user
@@ -617,8 +643,48 @@ }
+ /**
+ * Page handler for friends
+ *
+ */
+ function friends_page_handler($page_elements) {
+
+ if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) {
+ set_page_owner($user->getGUID());
+ }
+ require_once(dirname(dirname(dirname(__FILE__))) . "/friends/index.php");
+
+ }
+
+ /**
+ * Page handler for friends of
+ *
+ */
+ function friends_of_page_handler($page_elements) {
+
+ if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) {
+ set_page_owner($user->getGUID());
+ }
+ require_once(dirname(dirname(dirname(__FILE__))) . "/friends/of.php");
+
+ }
+
+ /**
+ * Users initialisation function, which establishes the page handler
+ *
+ */
+ function users_init() {
+
+ register_page_handler('friends','friends_page_handler');
+ register_page_handler('friendsof','friends_of_page_handler');
+
+ }
+
//register actions *************************************************************
register_action("register",true);
+ register_action("friends/add");
+ register_action("friends/remove");
+ register_event_handler('init','system','users_init',0);
?>
\ No newline at end of file diff --git a/friends/index.php b/friends/index.php new file mode 100644 index 000000000..6629a2fc6 --- /dev/null +++ b/friends/index.php @@ -0,0 +1,37 @@ +<?php
+
+ /**
+ * Elgg friends page
+ *
+ * @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
+ * @link http://elgg.org/
+ */
+
+ if (!$owner = page_owner_entity()) {
+ gatekeeper();
+ $owner = $_SESSION['user'];
+ }
+
+ $offset = (int) get_input('offset');
+
+ if ($friends = $owner->getFriends("",50,$offset)) {
+
+ $body = elgg_view("friends/list",array('friends' => $friends));
+
+ } else {
+
+ if (page_owner() != $_SESSION['guid']) {
+ $body = elgg_echo("friends:none");
+ } else {
+ $body = elgg_echo("friends:none:you");
+ }
+
+ }
+
+ echo page_draw(sprintf(elgg_echo("friends:owned"),$owner->name),$body);
+
+?>
\ No newline at end of file diff --git a/friends/of.php b/friends/of.php new file mode 100644 index 000000000..7886c6c14 --- /dev/null +++ b/friends/of.php @@ -0,0 +1,37 @@ +<?php
+
+ /**
+ * Elgg friends of page
+ *
+ * @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
+ * @link http://elgg.org/
+ */
+
+ if (!$owner = page_owner_entity()) {
+ gatekeeper();
+ $owner = $_SESSION['user'];
+ }
+
+ $offset = (int) get_input('offset');
+
+ if ($friends = $owner->getFriendsOf("",50,$offset)) {
+
+ $body = elgg_view("friends/list",array('friends' => $friends));
+
+ } else {
+
+ if (page_owner() != $_SESSION['guid']) {
+ $body = elgg_echo("friends:of:none");
+ } else {
+ $body = elgg_echo("friends:of:none:you");
+ }
+
+ }
+
+ echo page_draw(sprintf(elgg_echo("friends:of:owned"),$owner->name),$body);
+
+?>
\ No newline at end of file diff --git a/languages/en.php b/languages/en.php index ee2af4200..b5bd07fed 100644 --- a/languages/en.php +++ b/languages/en.php @@ -54,6 +54,31 @@ 'profile' => "Profile",
/**
+ * Friends
+ */
+
+ 'friends' => "Friends",
+ 'friends:yours' => "Your friends",
+ 'friends:owned' => "%s's friends",
+ 'friend:add' => "Add friend",
+ 'friend:remove' => "Remove friend",
+
+ 'friends:add:successful' => "You have successfully added %s as a friend.",
+ 'friends:add:failure' => "We couldn't add %s as a friend. Please try again.",
+
+ 'friends:remove:successful' => "You have successfully removed %s from your friends.",
+ 'friends:remove:failure' => "We couldn't remove %s from your friends. Please try again.",
+
+ 'friends:none' => "This user hasn't added anyone as a friend yet.",
+ 'friends:none:you' => "You haven't added anyone as a friend! Search for your interests to begin finding people to follow.",
+
+ 'friends:of:none' => "Nobody has added this user as a friend yet.",
+ 'friends:of:none:you' => "Nobody has added you as a friend yet. Start adding content and fill in your profile to let people find you!",
+
+ 'friends:of' => "Friends of",
+ 'friends:of:owned' => "People who have made %s a friend",
+
+ /**
* Search
*/
diff --git a/mod/profile/views/default/profile/menu.php b/mod/profile/views/default/profile/menu.php new file mode 100644 index 000000000..463301398 --- /dev/null +++ b/mod/profile/views/default/profile/menu.php @@ -0,0 +1,33 @@ +<?php
+
+ /**
+ * Elgg profile menu
+ *
+ * @package ElggProfile
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Ben Werdmuller <ben@curverider.co.uk>
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ *
+ * @uses $vars['entity'] The user entity
+ */
+
+ if (isloggedin() && $vars['entity']->getGUID() != $vars['user']->getGUID()) {
+
+ if ($vars['entity']->isFriend()) {
+
+ echo "<p><a href=\"{$vars['url']}action/friends/remove?friend={$vars['entity']->getGUID()}\">" . elgg_echo("friend:remove") . "</a></p>";
+
+ } else {
+
+ echo "<p><a href=\"{$vars['url']}action/friends/add?friend={$vars['entity']->getGUID()}\">" . elgg_echo("friend:add") . "</a></p>";
+
+ }
+
+ echo "<p> </p>";
+
+ }
+
+?>
+ <p><a href="<?php echo $vars['url']; ?>pg/friends/<?php echo $vars['entity']->username ?>/"><?php echo sprintf(elgg_echo("friends:owned"),$vars['entity']->name) ?></a></p>
+ <p><a href="<?php echo $vars['url']; ?>pg/friendsof/<?php echo $vars['entity']->username ?>/"><?php echo sprintf(elgg_echo("friends:of:owned"),$vars['entity']->name) ?></a></p>
\ No newline at end of file diff --git a/mod/profile/views/default/profile/userdetails.php b/mod/profile/views/default/profile/userdetails.php new file mode 100644 index 000000000..c405e78a9 --- /dev/null +++ b/mod/profile/views/default/profile/userdetails.php @@ -0,0 +1,78 @@ +<?php
+
+ /**
+ * Elgg user display (details)
+ *
+ * @package ElggProfile
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Ben Werdmuller <ben@curverider.co.uk>
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ *
+ * @uses $vars['entity'] The user entity
+ */
+
+ if ($vars['full'] == true) {
+ $iconsize = "large";
+ } else {
+ $iconsize = "medium";
+ }
+ echo elgg_view(
+ "profile/icon", array(
+ 'entity' => $vars['entity'],
+ 'align' => "right",
+ 'size' => $iconsize,
+ )
+ );
+
+?>
+ <h2><a href="<?php echo $vars['entity']->getUrl(); ?>"><?php echo $vars['entity']->name; ?></a></h2>
+ <?php
+
+ if ($vars['full'] == true) {
+
+ ?>
+ <p><b><?php echo elgg_echo("profile:aboutme"); ?></b></p>
+ <p><?php echo nl2br($vars['entity']->description); ?></p>
+ <?php
+
+ if (is_array($vars['config']->profile) && sizeof($vars['config']->profile) > 0)
+ foreach($vars['config']->profile as $shortname => $valtype) {
+ if ($shortname != "description") {
+ $value = $vars['entity']->$shortname;
+ if (!empty($value)) {
+
+ ?>
+
+ <p>
+ <b><?php
+
+ echo elgg_echo("profile:{$shortname}");
+
+ ?>: </b>
+ <?php
+
+ echo elgg_view("output/{$valtype}",array('value' => $vars['entity']->$shortname));
+
+ ?>
+
+ </p>
+
+ <?php
+ }
+ }
+ }
+
+ }
+
+ if ($vars['entity']->canEdit()) {
+
+ ?>
+ <p>
+ <a href="<?php echo $vars['url']; ?>mod/profile/edit.php"><?php echo elgg_echo("edit"); ?></a>
+ </p>
+ <?php
+
+ }
+
+ ?>
\ No newline at end of file diff --git a/mod/profile/views/default/user/user.php b/mod/profile/views/default/user/user.php index 102932233..345a8aabb 100644 --- a/mod/profile/views/default/user/user.php +++ b/mod/profile/views/default/user/user.php @@ -12,67 +12,6 @@ * @uses $vars['entity'] The user entity
*/
- if ($vars['full'] == true) {
- $iconsize = "large";
- } else {
- $iconsize = "medium";
- }
- echo elgg_view(
- "profile/icon", array(
- 'entity' => $vars['entity'],
- 'align' => "right",
- 'size' => $iconsize,
- )
- );
-
-?>
- <h2><a href="<?php echo $vars['entity']->getUrl(); ?>"><?php echo $vars['entity']->name; ?></a></h2>
- <?php
-
- if ($vars['full'] == true) {
-
- ?>
- <p><b><?php echo elgg_echo("profile:aboutme"); ?></b></p>
- <p><?php echo nl2br($vars['entity']->description); ?></p>
- <?php
-
- if (is_array($vars['config']->profile) && sizeof($vars['config']->profile) > 0)
- foreach($vars['config']->profile as $shortname => $valtype) {
- if ($shortname != "description") {
- $value = $vars['entity']->$shortname;
- if (!empty($value)) {
-
- ?>
-
- <p>
- <b><?php
-
- echo elgg_echo("profile:{$shortname}");
-
- ?>: </b>
- <?php
-
- echo elgg_view("output/{$valtype}",array('value' => $vars['entity']->$shortname));
-
- ?>
-
- </p>
-
- <?php
- }
- }
- }
-
- }
-
- if ($vars['entity']->canEdit()) {
-
- ?>
- <p>
- <a href="<?php echo $vars['url']; ?>mod/profile/edit.php"><?php echo elgg_echo("edit"); ?></a>
- </p>
- <?php
-
- }
+ echo elgg_view_layout("one_column",elgg_view("profile/userdetails",$vars),elgg_view("profile/menu",$vars));
- ?>
\ No newline at end of file +?>
\ No newline at end of file diff --git a/views/default/friends/list.php b/views/default/friends/list.php new file mode 100644 index 000000000..20676a2b7 --- /dev/null +++ b/views/default/friends/list.php @@ -0,0 +1,27 @@ +<?php
+
+ /**
+ * Elgg friends list
+ * Lists a user's friends
+ *
+ * @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
+ * @link http://elgg.org/
+ *
+ * @uses $vars['friends'] The array of ElggUser objects
+ */
+
+ if (is_array($vars['friends']) && sizeof($vars['friends']) > 0) {
+
+ foreach($vars['friends'] as $friend) {
+
+ echo elgg_view_entity($friend,"",false);
+
+ }
+
+ }
+
+?>
\ No newline at end of file |