From f6ff517215d63d55c47a212a7a3ee477d4def791 Mon Sep 17 00:00:00 2001 From: marcus Date: Thu, 3 Jul 2008 18:54:08 +0000 Subject: End of day commit of first (semi working) code. Working: - Join/leave on public groups - Create / edit groups Not working: - Private groups - the skin/display of the group - profile main page - widgets Refs #109 Closes #115 git-svn-id: https://code.elgg.org/elgg/trunk@1279 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/groups/actions/addtogroup.php | 79 +++++++++++++ mod/groups/actions/edit.php | 60 ++++++++++ mod/groups/actions/join.php | 54 +++++++++ mod/groups/actions/joinrequest.php | 73 ++++++++++++ mod/groups/actions/leave.php | 39 +++++++ mod/groups/all.php | 37 ++++++ mod/groups/edit.php | 27 +++++ mod/groups/index.php | 28 +++++ mod/groups/languages/en.php | 81 ++++++++++++++ mod/groups/manifest.xml | 9 ++ mod/groups/new.php | 19 ++++ mod/groups/start.php | 124 +++++++++++++++++++++ mod/groups/views/default/forms/groups/edit.php | 56 ++++++++++ mod/groups/views/default/group/group.php | 21 ++++ mod/groups/views/default/groups/groupgallery.php | 25 +++++ mod/groups/views/default/groups/grouplisting.php | 27 +++++ mod/groups/views/default/groups/groupprofile.php | 22 ++++ mod/groups/views/default/groups/icon.php | 68 +++++++++++ mod/groups/views/default/groups/menu/actions.php | 44 ++++++++ .../views/default/groups/menu/adminlinks.php | 3 + mod/groups/views/default/groups/menu/links.php | 3 + .../views/default/groups/menu/ownerlinks.php | 3 + 22 files changed, 902 insertions(+) create mode 100644 mod/groups/actions/addtogroup.php create mode 100644 mod/groups/actions/edit.php create mode 100644 mod/groups/actions/join.php create mode 100644 mod/groups/actions/joinrequest.php create mode 100644 mod/groups/actions/leave.php create mode 100644 mod/groups/all.php create mode 100644 mod/groups/edit.php create mode 100644 mod/groups/index.php create mode 100644 mod/groups/languages/en.php create mode 100644 mod/groups/manifest.xml create mode 100644 mod/groups/new.php create mode 100644 mod/groups/start.php create mode 100644 mod/groups/views/default/forms/groups/edit.php create mode 100644 mod/groups/views/default/group/group.php create mode 100644 mod/groups/views/default/groups/groupgallery.php create mode 100644 mod/groups/views/default/groups/grouplisting.php create mode 100644 mod/groups/views/default/groups/groupprofile.php create mode 100644 mod/groups/views/default/groups/icon.php create mode 100644 mod/groups/views/default/groups/menu/actions.php create mode 100644 mod/groups/views/default/groups/menu/adminlinks.php create mode 100644 mod/groups/views/default/groups/menu/links.php create mode 100644 mod/groups/views/default/groups/menu/ownerlinks.php (limited to 'mod/groups') diff --git a/mod/groups/actions/addtogroup.php b/mod/groups/actions/addtogroup.php new file mode 100644 index 000000000..db697d573 --- /dev/null +++ b/mod/groups/actions/addtogroup.php @@ -0,0 +1,79 @@ +getGUID() == $group->getGUID()) + { + $requests = $user->group_join_request; + if ($requests) + { + foreach ($requests as $request) + { + if ($request == $group->getGUID()) + { + // User has requested to join this group previously, so we can safely add them + + // add them + if ($group->join($user)) + { + + // send welcome email + notify_user($user->getGUID(), "", + sprintf(elgg_echo('groups:welcome:subject'), $group->title), + sprintf(elgg_echo('groups:welcome:body'), $user->name, $group->title, $group->getURL()), + NULL, "email"); + + system_message(elgg_echo('groups:addedtogroup')); + + } + else + system_message(elgg_echo("groups:cantjoin")); + + forward($_SERVER['HTTP_REFERER']); + exit; + } + } + + // Not found in request array, so send an invite and set invite flag + + // Set invite flag + if (!$user->setMetaData('group_invite', $group->getGUID(), "", true)) + system_message(elgg_echo("groups:usernotinvited")); + else + { + // Send email + if (notify_user($user->getGUID(), "", + sprintf(elgg_echo('groups:invite:subject'), $user->name, $group->title), + sprintf(elgg_echo('groups:invite:body'), $user->name, $group->title, "http://{$CONFIG->url}action/groups/join?user_guid={$user->guid}&group_guid={$group->guid}"), + NULL, "email")) + system_message(elgg_echo("groups:userinvited")); + else + system_message(elgg_echo("groups:usernotinvited")); + } + } + } + else + system_message(elgg_echo("groups:notowner")); + + forward($_SERVER['HTTP_REFERER']); + exit; +?> \ No newline at end of file diff --git a/mod/groups/actions/edit.php b/mod/groups/actions/edit.php new file mode 100644 index 000000000..4e9cdf99e --- /dev/null +++ b/mod/groups/actions/edit.php @@ -0,0 +1,60 @@ +group as $shortname => $valuetype) { + $input[$shortname] = get_input($shortname); + if ($valuetype == 'tags') + $input[$shortname] = string_to_tag_array($input[$shortname]); + } + + $user_guid = get_input('user_guid'); + $user = NULL; + if (!$user_guid) $user = $_SESSION['user']; + else + $user = get_entity($user_guid); + + $group_guid = get_input('group_guid'); + + $group = new ElggGroup($group_guid); // load if present, if not create a new group + if (($group_guid) && (!$group->canEdit())) + { + system_message(elgg_echo("groups:cantedit")); + + forward($_SERVER['HTTP_REFERER']); + exit; + } + + // Assume we can edit or this is a new group + if (sizeof($input) > 0) + { + foreach($input as $shortname => $value) { + $group->$shortname = $value; + } + } + + // Get access + $group->access_id = get_input('access_id', 0); + + $group->save(); + + $group->join($user); // Creator always a member + + system_message(elgg_echo("groups:saved")); + + // Forward to the user's profile + forward($group->getUrl()); + exit; +?> \ No newline at end of file diff --git a/mod/groups/actions/join.php b/mod/groups/actions/join.php new file mode 100644 index 000000000..77d2e3021 --- /dev/null +++ b/mod/groups/actions/join.php @@ -0,0 +1,54 @@ +access_id == 2) + { + if ($group->join($user)) + { + system_message(elgg_echo("groups:joined")); + + forward($group->getURL()); + exit; + } + else + system_message(elgg_echo("groups:cantjoin")); + } + else + { + // Closed group, request membership + system_message(elgg_echo('groups:privategroup')); + forward($CONFIG->url . "actions/groups/joinrequest?user_guid=$user_guid&group_guid=$group_guid"); + exit; + } + } + else + system_message(elgg_echo("groups:cantjoin")); + + forward($_SERVER['HTTP_REFERER']); + exit; +?> \ No newline at end of file diff --git a/mod/groups/actions/joinrequest.php b/mod/groups/actions/joinrequest.php new file mode 100644 index 000000000..6288e0e76 --- /dev/null +++ b/mod/groups/actions/joinrequest.php @@ -0,0 +1,73 @@ +isMember($user)) + { + $invites = $user->group_invite; + + if ($invites) + { + foreach ($invites as $invite) + { + if ($invite = $group->getGUID()) + { + if ($group->join($user)) + { + system_message(elgg_echo('groups:joined')); + + forward($group->getURL()); + exit; + } + else + system_message(elgg_echo('groups:cantjoin')); + + forward($_SERVER['HTTP_REFERER']); + exit; + } + + } + + // else email membership requiest + // set flag + + if (!$user->setMetaData('group_join_request', $group->getGUID(), "", true)) + system_message(elgg_echo("groups:joinrequestnotmade")); + else + { + // Send email + if (notify_user($group->owner_guid, "", + sprintf(elgg_echo('groups:request:subject'), $user->name, $group->title), + sprintf(elgg_echo('groups:request:body'), $group->getOwner()->name, $user->name, $group->title, $user->getURL(), "http://{$CONFIG->url}action/groups/addtogroup?user_guid={$user->guid}&group_guid={$group->guid}"), + NULL, "email")) + system_message(elgg_echo("groups:joinrequestmade")); + else + system_message(elgg_echo("groups:joinrequestnotmade")); + } + } + + } + else + system_message(elgg_echo('groups:alreadymember')); + + forward($_SERVER['HTTP_REFERER']); + exit; +?> \ No newline at end of file diff --git a/mod/groups/actions/leave.php b/mod/groups/actions/leave.php new file mode 100644 index 000000000..87f976b3e --- /dev/null +++ b/mod/groups/actions/leave.php @@ -0,0 +1,39 @@ +leave($user)) + system_message(elgg_echo("groups:left")); + else + system_message(elgg_echo("groups:cantleave")); + } + else + system_message(elgg_echo("groups:cantleave")); + + forward($_SERVER['HTTP_REFERER']); + exit; +?> \ No newline at end of file diff --git a/mod/groups/all.php b/mod/groups/all.php new file mode 100644 index 000000000..53d617e42 --- /dev/null +++ b/mod/groups/all.php @@ -0,0 +1,37 @@ +name), $body); + + + +?> \ No newline at end of file diff --git a/mod/groups/edit.php b/mod/groups/edit.php new file mode 100644 index 000000000..dcd6db98d --- /dev/null +++ b/mod/groups/edit.php @@ -0,0 +1,27 @@ +canEdit())) + { + $body = elgg_view_layout('one_column', elgg_view("forms/groups/edit", array('entity' => $group))); + + } else { + $area1 = elgg_echo("groups:noaccess"); + } + + page_draw(elgg_echo("groups:new"), $body); +?> \ No newline at end of file diff --git a/mod/groups/index.php b/mod/groups/index.php new file mode 100644 index 000000000..850fd4c3b --- /dev/null +++ b/mod/groups/index.php @@ -0,0 +1,28 @@ +name), $body); +?> \ No newline at end of file diff --git a/mod/groups/languages/en.php b/mod/groups/languages/en.php new file mode 100644 index 000000000..469f70717 --- /dev/null +++ b/mod/groups/languages/en.php @@ -0,0 +1,81 @@ + "Groups", + 'groups:yours' => "Your groups", + 'groups:user' => "%s's groups", + 'groups:all' => "All groups", + 'groups:new' => "Create a new group", + 'groups:edit' => "Edit a group", + + 'groups:title' => 'Group title', + 'groups:description' => 'Description', + 'groups:interests' => 'Interests', + 'groups:website' => 'Website', + 'groups:membership' => "Membership", + + 'groups:noaccess' => 'No access to group', + 'groups:cantedit' => 'You can not edit this group', + 'groups:saved' => 'Group saved', + + 'groups:joinrequest' => 'Request membership', + 'groups:join' => 'Join group', + 'groups:leave' => 'Leave group', + + + 'groups:privategroup' => 'This group is private, requesting membership.', + 'groups:cantjoin' => 'Can not join group', + 'groups:cantleave' => 'Could not leave group', + 'groups:addedtogroup' => 'Successfully added the user to the group', + 'groups:joinrequestnotmade' => 'Join request could not be made', + 'groups:joinrequestmade' => 'Request to join group successfully made', + 'groups:joined' => 'Successfully joined group!', + 'groups:left' => 'Successfully left group', + 'groups:notowner' => 'Sorry, you are not the owner of this group.', + 'groups:alreadymember' => 'You are already a member of this group!', + 'groups:userinvited' => 'User has been invited.', + 'groups:usernotinvited' => 'User could not be invited.', + + 'groups:invite:subject' => '%s you have been invited to join \'%s\'!', + 'groups:invite:body' => 'Hi %s, + +You have been invited to join the \'%s\' group, click below to confirm: + +%s', + + 'groups:welcome:subject' => 'Welcome to the \'%s\' group!', + 'groups:welcome:body' => 'Hi %s! + +You are now a member of the \'%s\' group! Click below to begin posting! + +%s', + + 'groups:request:subject' => '%s has requested to join \'%s\'', + 'groups:request:body' => 'Hi %s, + +%s has requested to join the \'%s\' group, click below to view their profile: + +%s + +or click below to confirm request: + +%s', + + ); + + add_translation("en",$english); +?> \ No newline at end of file diff --git a/mod/groups/manifest.xml b/mod/groups/manifest.xml new file mode 100644 index 000000000..7b1fe8b87 --- /dev/null +++ b/mod/groups/manifest.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/mod/groups/new.php b/mod/groups/new.php new file mode 100644 index 000000000..d031fc3e8 --- /dev/null +++ b/mod/groups/new.php @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/mod/groups/start.php b/mod/groups/start.php new file mode 100644 index 000000000..b6c177a7d --- /dev/null +++ b/mod/groups/start.php @@ -0,0 +1,124 @@ +wwwroot . "pg/groups/" . $_SESSION['user']->username,array( + menu_item(elgg_echo('groups:new'), $CONFIG->wwwroot."pg/groups/" . $_SESSION['user']->username . "/new/"), + menu_item(elgg_echo('groups:yours'), $CONFIG->wwwroot . "pg/groups/" . $_SESSION['user']->username), + menu_item(elgg_echo('groups:all'), $CONFIG->wwwroot . "pg/groups/" . $_SESSION['user']->username . "/world/"), + ),'groups'); + } + else + { + add_menu(elgg_echo('groups'), $CONFIG->wwwroot . "mod/groups/",array( + menu_item(elgg_echo('groups:all'),$CONFIG->wwwroot."mod/groups/all.php"), + )); + } + + // Register a page handler, so we can have nice URLs + register_page_handler('groups','groups_page_handler'); + + // Register a URL handler for groups + register_entity_url_handler('groups_url','group','all'); + + // Register an icon handler for groups + register_page_handler('icon','groups_icon_handler'); + + // Register some actions + register_action("groups/edit",false, $CONFIG->pluginspath . "groups/actions/edit.php"); + register_action("groups/join",false, $CONFIG->pluginspath . "groups/actions/join.php"); + register_action("groups/leave",false, $CONFIG->pluginspath . "groups/actions/leave.php"); + register_action("groups/joinrequest",false, $CONFIG->pluginspath . "groups/actions/joinrequest.php"); + + register_action("groups/adduser",false, $CONFIG->pluginspath . "groups/actions/adduser.php"); + + + // For now, we'll hard code the groups profile items as follows: + // TODO make this user configurable + + // Language short codes must be of the form "groups:key" + // where key is the array key below + $CONFIG->group = array( + + 'title' => 'text', + 'description' => 'longtext', + //'location' => 'tags', + 'interests' => 'tags', + //'skills' => 'tags', + //'contactemail' => 'email', + //'phone' => 'text', + //'mobile' => 'text', + 'website' => 'url', + + ); + } + + /** + * Group page handler + * + * @param array $page Array of page elements, forwarded by the page handling mechanism + */ + function groups_page_handler($page) + { + global $CONFIG; + + // The username should be the file we're getting + if (isset($page[0])) { + set_input('username',$page[0]); + } + + if (isset($page[1])) + { + switch($page[1]) + { + case "new": + include($CONFIG->pluginspath . "groups/new.php"); + break; + case "world": + include($CONFIG->pluginspath . "groups/all.php"); + break; + } + } + else + { + // Include the standard profile index + include($CONFIG->pluginspath . "groups/index.php"); + } + + } + + /** + * Populates the ->getUrl() method for group objects + * + * @param ElggEntity $entity File entity + * @return string File URL + */ + function groups_url($entity) { + + global $CONFIG; + + return $CONFIG->url . "pg/view/" . $entity->getGUID() . "/"; + + } + + // Make sure the groups initialisation function is called on initialisation + register_elgg_event_handler('init','system','groups_init'); +?> \ No newline at end of file diff --git a/mod/groups/views/default/forms/groups/edit.php b/mod/groups/views/default/forms/groups/edit.php new file mode 100644 index 000000000..7a3a9c353 --- /dev/null +++ b/mod/groups/views/default/forms/groups/edit.php @@ -0,0 +1,56 @@ + +
+ +group) && sizeof($vars['config']->group) > 0) + foreach($vars['config']->group as $shortname => $valtype) { + +?> + +

+ +

+ + + +

+ +

+ +

+ + + " /> +

+ +
\ No newline at end of file diff --git a/mod/groups/views/default/group/group.php b/mod/groups/views/default/group/group.php new file mode 100644 index 000000000..c1f6d282f --- /dev/null +++ b/mod/groups/views/default/group/group.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/mod/groups/views/default/groups/groupgallery.php b/mod/groups/views/default/groups/groupgallery.php new file mode 100644 index 000000000..14ca2f95f --- /dev/null +++ b/mod/groups/views/default/groups/groupgallery.php @@ -0,0 +1,25 @@ + $vars['entity'], + 'size' => 'large', + ) + ); + + $info .= "

getUrl() . "\">" . $vars['entity']->title . "

"; + + // num users, last activity, owner etc + + + echo elgg_view('search/gallery_listing',array('icon' => $icon, 'info' => $info)); +?> \ No newline at end of file diff --git a/mod/groups/views/default/groups/grouplisting.php b/mod/groups/views/default/groups/grouplisting.php new file mode 100644 index 000000000..1c86f2279 --- /dev/null +++ b/mod/groups/views/default/groups/grouplisting.php @@ -0,0 +1,27 @@ + $vars['entity'], + 'size' => 'small', + ) + ); + + $info .= "

getUrl() . "\">" . $vars['entity']->title . "

"; + + // num users, last activity, owner etc + + echo elgg_view_listing($icon, $info); + +?> \ No newline at end of file diff --git a/mod/groups/views/default/groups/groupprofile.php b/mod/groups/views/default/groups/groupprofile.php new file mode 100644 index 000000000..bf0945c63 --- /dev/null +++ b/mod/groups/views/default/groups/groupprofile.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/mod/groups/views/default/groups/icon.php b/mod/groups/views/default/groups/icon.php new file mode 100644 index 000000000..0a3ce74a4 --- /dev/null +++ b/mod/groups/views/default/groups/icon.php @@ -0,0 +1,68 @@ +icontime) { + $icontime = "{$icontime}"; + } else { + $icontime = "default"; + } + + $name = htmlentities($vars['entity']->title); + + + + $username = $vars['entity']->username; // TODO : How do i do an icon when we have no username? +?> + +
+
+ + "; + + } + if ($vars['entity']->owner_guid == $vars['user']->getGUID()) { + echo elgg_view('groups/menu/ownerlinks',$vars); + } else { + echo elgg_view('groups/menu/links',$vars); + } + } else { + echo elgg_view('groups/menu/links',$vars); + } + + ?> + +
+ title="" /> + \ No newline at end of file diff --git a/mod/groups/views/default/groups/menu/actions.php b/mod/groups/views/default/groups/menu/actions.php new file mode 100644 index 000000000..21101ddb8 --- /dev/null +++ b/mod/groups/views/default/groups/menu/actions.php @@ -0,0 +1,44 @@ +isMember($_SESSION['user'])) + { +?> +

+access_id == 2) + { +?> +

+ +

+getGUID() == $vars['entity']->owner_guid) + { + ?> +

+ \ No newline at end of file diff --git a/mod/groups/views/default/groups/menu/adminlinks.php b/mod/groups/views/default/groups/menu/adminlinks.php new file mode 100644 index 000000000..15c5adc7f --- /dev/null +++ b/mod/groups/views/default/groups/menu/adminlinks.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/mod/groups/views/default/groups/menu/links.php b/mod/groups/views/default/groups/menu/links.php new file mode 100644 index 000000000..15c5adc7f --- /dev/null +++ b/mod/groups/views/default/groups/menu/links.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/mod/groups/views/default/groups/menu/ownerlinks.php b/mod/groups/views/default/groups/menu/ownerlinks.php new file mode 100644 index 000000000..15c5adc7f --- /dev/null +++ b/mod/groups/views/default/groups/menu/ownerlinks.php @@ -0,0 +1,3 @@ + \ No newline at end of file -- cgit v1.2.3