diff options
Diffstat (limited to 'mod/groups/actions')
24 files changed, 773 insertions, 720 deletions
diff --git a/mod/groups/actions/addtogroup.php b/mod/groups/actions/addtogroup.php deleted file mode 100644 index f891ab9af..000000000 --- a/mod/groups/actions/addtogroup.php +++ /dev/null @@ -1,102 +0,0 @@ -<?php - - /** - * Add a user to a group - * - * @package ElggGroups - * @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/ - */ - - // Load configuration - global $CONFIG; - - gatekeeper(); - - $forward_url = get_input('forward_url', $_SERVER['HTTP_REFERER']); - $user_guid = get_input('user_guid'); - if (!is_array($user_guid)) - $user_guid = array($user_guid); - $group_guid = get_input('group_guid'); - - if (sizeof($user_guid)) - foreach ($user_guid as $u_id) - { - $requested = false; - - $user = get_entity($u_id); - $group = get_entity($group_guid); - if ( $user && $group) { - - if ($_SESSION['user']->getGUID() == $group->owner_guid) - { - $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->isMember($user)) && ($group->join($user))) - { - - // send welcome email - notify_user($user->getGUID(), $group->owner_guid, - sprintf(elgg_echo('groups:welcome:subject'), $group->name), - sprintf(elgg_echo('groups:welcome:body'), $user->name, $group->name, $group->getURL()), - NULL, "email"); - - system_message(elgg_echo('groups:addedtogroup')); - - } - else - register_error(elgg_echo("groups:cantjoin")); - - $requested = true; - } - } - } - - if (!$requested) - { - // Not found in request array, so send an invite and set invite flag - $methods = $user->group_invite; - if (($methods) && (!is_array($methods))) - $methods = array($methods); - if (!$methods) $methods=array(); - $methods[] = $group->getGUID(); - $methods = array_unique($methods); - - // Set invite flag - //if (!$user->setMetaData('group_invite', $group->getGUID(), "", true)) - if (!$user->setMetaData('group_invite', $methods)) { - //if (!$user->group_invite = $methods) { - register_error(elgg_echo("groups:usernotinvited")); - } - else - { - // Send email - if (notify_user($user->getGUID(), $group->owner_guid, - sprintf(elgg_echo('groups:invite:subject'), $user->name, $group->name), - sprintf(elgg_echo('groups:invite:body'), $user->name, $group->name, "{$CONFIG->url}action/groups/join?user_guid={$user->guid}&group_guid={$group->guid}"), - NULL, "email")) - system_message(elgg_echo("groups:userinvited")); - else - register_error(elgg_echo("groups:usernotinvited")); - } - }
- }
- else
- register_error(elgg_echo("groups:notowner")); - } - } - - forward($forward_url); -?>
\ No newline at end of file diff --git a/mod/groups/actions/discussion/delete.php b/mod/groups/actions/discussion/delete.php new file mode 100644 index 000000000..f307aa091 --- /dev/null +++ b/mod/groups/actions/discussion/delete.php @@ -0,0 +1,29 @@ +<?php +/** + * Delete topic action + * + */ + +$topic_guid = (int) get_input('guid'); + +$topic = get_entity($topic_guid); +if (!$topic || !$topic->getSubtype() == "groupforumtopic") { + register_error(elgg_echo('discussion:error:notdeleted')); + forward(REFERER); +} + +if (!$topic->canEdit()) { + register_error(elgg_echo('discussion:error:permissions')); + forward(REFERER); +} + +$container = $topic->getContainerEntity(); + +$result = $topic->delete(); +if ($result) { + system_message(elgg_echo('discussion:topic:deleted')); +} else { + register_error(elgg_echo('discussion:error:notdeleted')); +} + +forward("discussion/owner/$container->guid"); diff --git a/mod/groups/actions/discussion/reply/delete.php b/mod/groups/actions/discussion/reply/delete.php new file mode 100644 index 000000000..88c6b79d6 --- /dev/null +++ b/mod/groups/actions/discussion/reply/delete.php @@ -0,0 +1,26 @@ +<?php +/** + * Delete discussion reply + */ + +$id = (int) get_input('annotation_id'); + +$reply = elgg_get_annotation_from_id($id); +if (!$reply || $reply->name != 'group_topic_post') { + register_error(elgg_echo('discussion:reply:error:notdeleted')); + forward(REFERER); +} + +if (!$reply->canEdit()) { + register_error(elgg_echo('discussion:error:permissions')); + forward(REFERER); +} + +$result = $reply->delete(); +if ($result) { + system_message(elgg_echo('discussion:reply:deleted')); +} else { + register_error(elgg_echo('discussion:reply:error:notdeleted')); +} + +forward(REFERER); diff --git a/mod/groups/actions/discussion/reply/save.php b/mod/groups/actions/discussion/reply/save.php new file mode 100644 index 000000000..f8be8aa2c --- /dev/null +++ b/mod/groups/actions/discussion/reply/save.php @@ -0,0 +1,58 @@ +<?php +/** + * Post a reply to discussion topic + * + */ + +// Get input +$entity_guid = (int) get_input('entity_guid'); +$text = get_input('group_topic_post'); +$annotation_id = (int) get_input('annotation_id'); + +// reply cannot be empty +if (empty($text)) { + register_error(elgg_echo('grouppost:nopost')); + forward(REFERER); +} + +$topic = get_entity($entity_guid); +if (!$topic) { + register_error(elgg_echo('grouppost:nopost')); + forward(REFERER); +} + +$user = elgg_get_logged_in_user_entity(); + +$group = $topic->getContainerEntity(); +if (!$group->canWriteToContainer()) { + register_error(elgg_echo('groups:notmember')); + forward(REFERER); +} + +// if editing a reply, make sure it's valid +if ($annotation_id) { + $annotation = elgg_get_annotation_from_id($annotation_id); + if (!$annotation->canEdit()) { + register_error(elgg_echo('groups:notowner')); + forward(REFERER); + } + + $annotation->value = $text; + if (!$annotation->save()) { + system_message(elgg_echo('groups:forumpost:error')); + forward(REFERER); + } + system_message(elgg_echo('groups:forumpost:edited')); +} else { + // add the reply to the forum topic + $reply_id = $topic->annotate('group_topic_post', $text, $topic->access_id, $user->guid); + if ($reply_id == false) { + system_message(elgg_echo('groupspost:failure')); + forward(REFERER); + } + + add_to_river('river/annotation/group_topic_post/reply', 'reply', $user->guid, $topic->guid, "", 0, $reply_id); + system_message(elgg_echo('groupspost:success')); +} + +forward(REFERER); diff --git a/mod/groups/actions/discussion/save.php b/mod/groups/actions/discussion/save.php new file mode 100644 index 000000000..b3e9da654 --- /dev/null +++ b/mod/groups/actions/discussion/save.php @@ -0,0 +1,75 @@ +<?php +/** + * Topic save action + */ + +// Get variables +$title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8'); +$desc = get_input("description"); +$status = get_input("status"); +$access_id = (int) get_input("access_id"); +$container_guid = (int) get_input('container_guid'); +$guid = (int) get_input('topic_guid'); +$tags = get_input("tags"); + +elgg_make_sticky_form('topic'); + +// validation of inputs +if (!$title || !$desc) { + register_error(elgg_echo('discussion:error:missing')); + forward(REFERER); +} + +$container = get_entity($container_guid); +if (!$container || !$container->canWriteToContainer(0, 'object', 'groupforumtopic')) { + register_error(elgg_echo('discussion:error:permissions')); + forward(REFERER); +} + +// check whether this is a new topic or an edit +$new_topic = true; +if ($guid > 0) { + $new_topic = false; +} + +if ($new_topic) { + $topic = new ElggObject(); + $topic->subtype = 'groupforumtopic'; +} else { + // load original file object + $topic = new ElggObject($guid); + if (!$topic || !$topic->canEdit()) { + register_error(elgg_echo('discussion:topic:notfound')); + forward(REFERER); + } +} + +$topic->title = $title; +$topic->description = $desc; +$topic->status = $status; +$topic->access_id = $access_id; +$topic->container_guid = $container_guid; + +$tags = explode(",", $tags); +$topic->tags = $tags; + +$result = $topic->save(); + +if (!$result) { + register_error(elgg_echo('discussion:error:notsaved')); + forward(REFERER); +} + +// topic saved so clear sticky form +elgg_clear_sticky_form('topic'); + + +// handle results differently for new topics and topic edits +if ($new_topic) { + system_message(elgg_echo('discussion:topic:created')); + add_to_river('river/object/groupforumtopic/create', 'create', elgg_get_logged_in_user_guid(), $topic->guid); +} else { + system_message(elgg_echo('discussion:topic:updated')); +} + +forward($topic->getURL()); diff --git a/mod/groups/actions/edit.php b/mod/groups/actions/edit.php deleted file mode 100644 index 8a99e98e6..000000000 --- a/mod/groups/actions/edit.php +++ /dev/null @@ -1,124 +0,0 @@ -<?php - /** - * Elgg groups plugin edit action. - * - * @package ElggGroups - * @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/ - */ - - // Load configuration - global $CONFIG; - - // Get group fields - $input = array(); - foreach($CONFIG->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())) - { - register_error(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; - } - } - - // Validate create - if (!$group->name) - { - register_error(elgg_echo("groups:notitle")); - - forward($_SERVER['HTTP_REFERER']); - exit; - } - - // Group membership - switch (get_input('membership')) - { - case 0: $group->membership = 0; - case 1 :$group->membership = 1; break; - case 2: - default: $group->membership = 2; - } - - // Get access - $group->access_id = get_input('access_id', 0); - - $group->save(); - - if (!$group->isMember($user)) - $group->join($user); // Creator always a member - - - // Now see if we have a file icon - if ((isset($_FILES['icon'])) && (substr_count($_FILES['icon']['type'],'image/'))) - { - $prefix = "groups/".$group->guid; - - $filehandler = new ElggFile(); - $filehandler->owner_guid = $group->owner_guid; - $filehandler->setFilename($prefix . ".jpg"); - $filehandler->open("write"); - $filehandler->write(get_uploaded_file('icon')); - $filehandler->close(); - - $thumbtiny = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),25,25, true); - $thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),40,40, true); - $thumbmedium = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),100,100, true); - $thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),200,200, false); - if ($thumbtiny) { - - $thumb = new ElggFile(); - $thumb->setMimeType('image/jpeg'); - - $thumb->setFilename($prefix."tiny.jpg"); - $thumb->open("write"); - $thumb->write($thumbtiny); - $thumb->close(); - - $thumb->setFilename($prefix."small.jpg"); - $thumb->open("write"); - $thumb->write($thumbsmall); - $thumb->close(); - - $thumb->setFilename($prefix."medium.jpg"); - $thumb->open("write"); - $thumb->write($thumbmedium); - $thumb->close(); - - $thumb->setFilename($prefix."large.jpg"); - $thumb->open("write"); - $thumb->write($thumblarge); - $thumb->close(); - - } - } - - 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/forums/addpost.php b/mod/groups/actions/forums/addpost.php deleted file mode 100644 index d18cd1fd0..000000000 --- a/mod/groups/actions/forums/addpost.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php
-
- /**
- * Elgg groups: add topic post action
- *
- * @package ElggGroups
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider <info@elgg.com>
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
-
- // Make sure we're logged in; forward to the front page if not
- if (!isloggedin()) forward();
-
- // Check the user is a group member
- $group_entity = get_entity(get_input('group_guid'));
- if (!$group_entity->isMember($vars['user'])) forward();
-
- // Get input
- $topic_guid = (int) get_input('topic_guid');
- $group_guid = (int) get_input('group_guid');
- $post = get_input('topic_post');
-
- // Let's see if we can get an entity with the specified GUID, and that it's a group forum topic
- if ($topic = get_entity($topic_guid)) {
- if ($topic->getSubtype() == "groupforumtopic") {
-
- //check the user posted a message
- if($post){
- // If posting the comment was successful, say so
- if ($topic->annotate('group_topic_post',$post,$topic->access_id, $_SESSION['guid'])) {
-
- system_message(elgg_echo("groupspost:success"));
-
- } else {
- system_message(elgg_echo("groupspost:failure"));
- }
- }else{
- system_message(elgg_echo("groupspost:nopost"));
- }
-
- }
-
- } else {
-
- system_message(elgg_echo("groupstopic:notfound"));
-
- }
-
- // Forward to the group forum page
- global $CONFIG;
- $url = $CONFIG->wwwroot . "mod/groups/topicposts.php?topic={$topic_guid}&group_guid={$group_guid}";
- forward($url);
-
-?>
\ No newline at end of file diff --git a/mod/groups/actions/forums/addtopic.php b/mod/groups/actions/forums/addtopic.php deleted file mode 100644 index e96815aa0..000000000 --- a/mod/groups/actions/forums/addtopic.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php
-
- /**
- * Elgg groups plugin add topic action.
- *
- * @package ElggGroups
- * @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/
- */
-
- // Make sure we're logged in; forward to the front page if not
- if (!isloggedin()) forward();
-
- // Check the user is a group member
- $group_entity = get_entity(get_input('group_guid'));
- if (!$group_entity->isMember($vars['user'])) forward();
-
- // Get input data
- $title = get_input('topictitle');
- $message = get_input('topicmessage');
- $tags = get_input('topictags');
- $access = get_input('access_id');
- $group_guid = (int) get_input('group_guid');
- $user = $_SESSION['user']->getGUID(); // you need to be logged in to comment on a group forum
- $status = get_input('status'); // sticky, resolved, closed
-
- // Convert string of tags into a preformatted array
- $tagarray = string_to_tag_array($tags);
-
- // Make sure the title / message aren't blank
- if (empty($title) || empty($message)) {
- register_error(elgg_echo("grouptopic:blank"));
- forward("pg/groups/forum/{$group_guid}/");
-
- // Otherwise, save the topic
- } else {
-
- // Initialise a new ElggObject
- $grouptopic = new ElggObject();
- // Tell the system it's a group forum topic
- $grouptopic->subtype = "groupforumtopic";
- // Set its owner to the current user
- $grouptopic->owner_guid = $user;
- // Set the group it belongs to
- $grouptopic->container_guid = $group_guid;
- // For now, set its access to public (we'll add an access dropdown shortly)
- $grouptopic->access_id = $access;
- // Set its title and description appropriately
- $grouptopic->title = $title;
- // Before we can set metadata, we need to save the topic
- if (!$grouptopic->save()) {
- register_error(elgg_echo("grouptopic:error"));
- forward("pg/groups/forum/{$group_guid}/");
- }
- // Now let's add tags. We can pass an array directly to the object property! Easy.
- if (is_array($tagarray)) {
- $grouptopic->tags = $tagarray;
- }
- // add metadata
- $grouptopic->status = $status; // the current status i.e sticky, closed, resolved, open
-
- // now add the topic message as an annotation
- $grouptopic->annotate('group_topic_post',$message,$access, $user);
-
- // Success message
- system_message(elgg_echo("grouptopic:created"));
-
- // Forward to the group forum page
- global $CONFIG;
- $url = $CONFIG->wwwroot . "pg/groups/forum/{$group_guid}/";
- forward($url);
-
- }
-
-?>
-
diff --git a/mod/groups/actions/forums/deletepost.php b/mod/groups/actions/forums/deletepost.php deleted file mode 100644 index d84525b13..000000000 --- a/mod/groups/actions/forums/deletepost.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php
-
- /**
- * Elgg Groups: delete topic comment action
- *
- * @package ElggGroups
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider <info@elgg.com>
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
-
- // Ensure we're logged in
- if (!isloggedin()) forward();
-
-
- // Make sure we can get the comment in question
- $post_id = (int) get_input('post');
- $group_guid = (int) get_input('group');
- $topic_guid = (int) get_input('topic');
-
- if ($post = get_annotation($post_id)) {
-
- //check that the user can edit
- if ($post->canEdit()) {
-
- //delete
- $post->delete();
- //display confirmation message
- system_message(elgg_echo("grouppost:deleted"));
-
- }
-
- } else {
- $url = "";
- system_message(elgg_echo("grouppost:notdeleted"));
- }
-
- // Forward to the group forum page
- global $CONFIG;
- $url = $CONFIG->wwwroot . "mod/groups/topicposts.php?topic={$topic_guid}&group_guid={$group_guid}";
- forward($url);
-
-?>
\ No newline at end of file diff --git a/mod/groups/actions/forums/deletetopic.php b/mod/groups/actions/forums/deletetopic.php deleted file mode 100644 index 3882e698b..000000000 --- a/mod/groups/actions/forums/deletetopic.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php
-
- /**
- * Elgg Groups: delete topic action
- *
- * @package ElggGroups
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider <info@elgg.com>
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
-
- // Make sure we're logged in; forward to the front page if not
- if (!isloggedin()) forward();
-
- // Check the user is a group member
- $group_entity = get_entity(get_input('group'));
- if (!$group_entity->isMember($vars['user'])) forward();
-
- // Get input data
- $topic_guid = (int) get_input('topic');
- $group_guid = (int) get_input('group');
-
- // Make sure we actually have permission to edit
- $topic = get_entity($topic_guid);
- if ($topic->getSubtype() == "groupforumtopic") {
-
- // Get owning user
- // $owner = get_entity($topic->getOwner());
- // Delete it!
- $rowsaffected = $topic->delete();
- if ($rowsaffected > 0) {
- // Success message
- system_message(elgg_echo("groupstopic:deleted"));
- } else {
- system_message(elgg_echo("groupstopic:notdeleted"));
- }
- // Forward to the group forum page
- global $CONFIG;
- $url = $CONFIG->wwwroot . "pg/groups/forum/{$group_guid}/";
- forward($url);
-
- }
-
-?>
\ No newline at end of file diff --git a/mod/groups/actions/forums/edittopic.php b/mod/groups/actions/forums/edittopic.php deleted file mode 100644 index 865af2173..000000000 --- a/mod/groups/actions/forums/edittopic.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php
-
- /**
- * Elgg groups plugin edit topic action.
- *
- * @package ElggGroups
- * @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/
- */
-
- // Make sure we're logged in (send us to the front page if not)
- if (!isloggedin()) forward();
-
- // Check the user is a group member
- $group_entity = get_entity(get_input('group_guid'));
- if (!$group_entity->isMember($vars['user'])) forward();
-
-
- // Get input data
- $title = get_input('topictitle');
- $message = get_input('topicmessage');
- $message_id = get_input('message_id');
- $tags = get_input('topictags');
- $topic_guid = get_input('topic');
- $access = get_input('access_id');
- $group_guid = get_input('group_guid');
- $user = $_SESSION['user']->getGUID(); // you need to be logged in to comment on a group forum
- $status = get_input('status'); // sticky, resolved, closed
-
- // Convert string of tags into a preformatted array
- $tagarray = string_to_tag_array($tags);
-
- // Make sure we actually have permission to edit
- $topic = get_entity($topic_guid);
-
- if ($topic->getSubtype() == "groupforumtopic") {
-
- // Convert string of tags into a preformatted array
- $tagarray = string_to_tag_array($tags);
-
- // Make sure the title isn't blank
- if (empty($title) || empty($message)) {
- register_error(elgg_echo("groupstopic:blank"));
-
- // Otherwise, save the forum
- } else {
-
- $topic->access_id = $access;
-
- // Set its title
- $topic->title = $title;
-
- // if no tags are present, clear existing ones
- if (is_array($tagarray)) {
- $topic->tags = $tagarray;
- } else $topic->clearMetadata('tags');
-
- // edit metadata
- $topic->status = $status; // the current status i.e sticky, closed, resolved
-
- // now let's edit the message annotation
- update_annotation($message_id, "group_topic_post", $message, "",$user, $access);
-
- // save the changes
- if (!$topic->save()) {
- // register_error(elgg_echo("forumtopic:error"));
- }
-
- // Success message
- system_message(elgg_echo("forumtopic:edited"));
-
- }
- }
-
- // Forward to the group forum page
- global $CONFIG;
- $url = $CONFIG->wwwroot . "pg/groups/forum/{$group_guid}/";
- forward($url);
-
-?>
-
diff --git a/mod/groups/actions/groups/delete.php b/mod/groups/actions/groups/delete.php new file mode 100644 index 000000000..2ff6c339c --- /dev/null +++ b/mod/groups/actions/groups/delete.php @@ -0,0 +1,42 @@ +<?php +/** + * Delete a group + */ + +$guid = (int) get_input('guid'); +if (!$guid) { + // backward compatible + elgg_deprecated_notice("Use 'guid' for group delete action", 1.8); + $guid = (int)get_input('group_guid'); +} +$entity = get_entity($guid); + +if (!$entity->canEdit()) { + register_error(elgg_echo('group:notdeleted')); + forward(REFERER); +} + +if (($entity) && ($entity instanceof ElggGroup)) { + // delete group icons + $owner_guid = $entity->owner_guid; + $prefix = "groups/" . $entity->guid; + $imagenames = array('.jpg', 'tiny.jpg', 'small.jpg', 'medium.jpg', 'large.jpg'); + $img = new ElggFile(); + $img->owner_guid = $owner_guid; + foreach ($imagenames as $name) { + $img->setFilename($prefix . $name); + $img->delete(); + } + + // delete group + if ($entity->delete()) { + system_message(elgg_echo('group:deleted')); + } else { + register_error(elgg_echo('group:notdeleted')); + } +} else { + register_error(elgg_echo('group:notdeleted')); +} + +$url_name = elgg_get_logged_in_user_entity()->username; +forward(elgg_get_site_url() . "groups/member/{$url_name}"); diff --git a/mod/groups/actions/groups/edit.php b/mod/groups/actions/groups/edit.php new file mode 100644 index 000000000..f19b90566 --- /dev/null +++ b/mod/groups/actions/groups/edit.php @@ -0,0 +1,235 @@ +<?php +/** + * Elgg groups plugin edit action. + * + * @package ElggGroups + */ + +elgg_make_sticky_form('groups'); + +/** + * wrapper for recursive array walk decoding + */ +function profile_array_decoder(&$v) { + $v = _elgg_html_decode($v); +} + +// Get group fields +$input = array(); +foreach (elgg_get_config('group') as $shortname => $valuetype) { + $input[$shortname] = get_input($shortname); + + // @todo treat profile fields as unescaped: don't filter, encode on output + if (is_array($input[$shortname])) { + array_walk_recursive($input[$shortname], 'profile_array_decoder'); + } else { + $input[$shortname] = _elgg_html_decode($input[$shortname]); + } + + if ($valuetype == 'tags') { + $input[$shortname] = string_to_tag_array($input[$shortname]); + } +} + +$input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8'); + +$user = elgg_get_logged_in_user_entity(); + +$group_guid = (int)get_input('group_guid'); +$is_new_group = $group_guid == 0; + +if ($is_new_group + && (elgg_get_plugin_setting('limited_groups', 'groups') == 'yes') + && !$user->isAdmin()) { + register_error(elgg_echo("groups:cantcreate")); + forward(REFERER); +} + +$group = new ElggGroup($group_guid); // load if present, if not create a new group +if ($group_guid && !$group->canEdit()) { + register_error(elgg_echo("groups:cantedit")); + forward(REFERER); +} + +// Assume we can edit or this is a new group +if (sizeof($input) > 0) { + foreach($input as $shortname => $value) { + // update access collection name if group name changes + if (!$is_new_group && $shortname == 'name' && $value != $group->name) { + $group_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); + $ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $group_name); + $acl = get_access_collection($group->group_acl); + if ($acl) { + // @todo Elgg api does not support updating access collection name + $db_prefix = elgg_get_config('dbprefix'); + $query = "UPDATE {$db_prefix}access_collections SET name = '$ac_name' + WHERE id = $group->group_acl"; + update_data($query); + } + } + + $group->$shortname = $value; + } +} + +// Validate create +if (!$group->name) { + register_error(elgg_echo("groups:notitle")); + forward(REFERER); +} + + +// Set group tool options +$tool_options = elgg_get_config('group_tool_options'); +if ($tool_options) { + foreach ($tool_options as $group_option) { + $option_toggle_name = $group_option->name . "_enable"; + $option_default = $group_option->default_on ? 'yes' : 'no'; + $group->$option_toggle_name = get_input($option_toggle_name, $option_default); + } +} + +// Group membership - should these be treated with same constants as access permissions? +$is_public_membership = (get_input('membership') == ACCESS_PUBLIC); +$group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE; + +if ($is_new_group) { + $group->access_id = ACCESS_PUBLIC; +} + +$old_owner_guid = $is_new_group ? 0 : $group->owner_guid; +$new_owner_guid = (int) get_input('owner_guid'); + +$owner_has_changed = false; +$old_icontime = null; +if (!$is_new_group && $new_owner_guid && $new_owner_guid != $old_owner_guid) { + // verify new owner is member and old owner/admin is logged in + if (is_group_member($group_guid, $new_owner_guid) && ($old_owner_guid == $user->guid || $user->isAdmin())) { + $group->owner_guid = $new_owner_guid; + $group->container_guid = $new_owner_guid; + + $metadata = elgg_get_metadata(array( + 'guid' => $group_guid, + 'limit' => false, + )); + if ($metadata) { + foreach ($metadata as $md) { + if ($md->owner_guid == $old_owner_guid) { + $md->owner_guid = $new_owner_guid; + $md->save(); + } + } + } + + // @todo Remove this when #4683 fixed + $owner_has_changed = true; + $old_icontime = $group->icontime; + } +} + +$must_move_icons = ($owner_has_changed && $old_icontime); + +$group->save(); + +// Invisible group support +// @todo this requires save to be called to create the acl for the group. This +// is an odd requirement and should be removed. Either the acl creation happens +// in the action or the visibility moves to a plugin hook +if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') { + $visibility = (int)get_input('vis', '', false); + if ($visibility != ACCESS_PUBLIC && $visibility != ACCESS_LOGGED_IN) { + $visibility = $group->group_acl; + } + + if ($group->access_id != $visibility) { + $group->access_id = $visibility; + } +} + +$group->save(); + +// group saved so clear sticky form +elgg_clear_sticky_form('groups'); + +// group creator needs to be member of new group and river entry created +if ($is_new_group) { + + // @todo this should not be necessary... + elgg_set_page_owner_guid($group->guid); + + $group->join($user); + add_to_river('river/group/create', 'create', $user->guid, $group->guid, $group->access_id); +} + +$has_uploaded_icon = (!empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/')); + +if ($has_uploaded_icon) { + + $icon_sizes = elgg_get_config('icon_sizes'); + + $prefix = "groups/" . $group->guid; + + $filehandler = new ElggFile(); + $filehandler->owner_guid = $group->owner_guid; + $filehandler->setFilename($prefix . ".jpg"); + $filehandler->open("write"); + $filehandler->write(get_uploaded_file('icon')); + $filehandler->close(); + $filename = $filehandler->getFilenameOnFilestore(); + + $sizes = array('tiny', 'small', 'medium', 'large'); + + $thumbs = array(); + foreach ($sizes as $size) { + $thumbs[$size] = get_resized_image_from_existing_file( + $filename, + $icon_sizes[$size]['w'], + $icon_sizes[$size]['h'], + $icon_sizes[$size]['square'] + ); + } + + if ($thumbs['tiny']) { // just checking if resize successful + $thumb = new ElggFile(); + $thumb->owner_guid = $group->owner_guid; + $thumb->setMimeType('image/jpeg'); + + foreach ($sizes as $size) { + $thumb->setFilename("{$prefix}{$size}.jpg"); + $thumb->open("write"); + $thumb->write($thumbs[$size]); + $thumb->close(); + } + + $group->icontime = time(); + } +} + +// @todo Remove this when #4683 fixed +if ($must_move_icons) { + $filehandler = new ElggFile(); + $filehandler->setFilename('groups'); + $filehandler->owner_guid = $old_owner_guid; + $old_path = $filehandler->getFilenameOnFilestore(); + + $sizes = array('', 'tiny', 'small', 'medium', 'large'); + + if ($has_uploaded_icon) { + // delete those under old owner + foreach ($sizes as $size) { + unlink("$old_path/{$group_guid}{$size}.jpg"); + } + } else { + // move existing to new owner + $filehandler->owner_guid = $group->owner_guid; + $new_path = $filehandler->getFilenameOnFilestore(); + + foreach ($sizes as $size) { + rename("$old_path/{$group_guid}{$size}.jpg", "$new_path/{$group_guid}{$size}.jpg"); + } + } +} + +system_message(elgg_echo("groups:saved")); + +forward($group->getUrl()); diff --git a/mod/groups/actions/groups/featured.php b/mod/groups/actions/groups/featured.php new file mode 100644 index 000000000..4cb9f8122 --- /dev/null +++ b/mod/groups/actions/groups/featured.php @@ -0,0 +1,27 @@ +<?php +/** + * Feature a group + * + * @package ElggGroups + */ + +$group_guid = get_input('group_guid'); +$action = get_input('action_type'); + +$group = get_entity($group_guid); + +if (!elgg_instanceof($group, 'group')) { + register_error(elgg_echo('groups:featured_error')); + forward(REFERER); +} + +//get the action, is it to feature or unfeature +if ($action == "feature") { + $group->featured_group = "yes"; + system_message(elgg_echo('groups:featuredon', array($group->name))); +} else { + $group->featured_group = "no"; + system_message(elgg_echo('groups:unfeatured', array($group->name))); +} + +forward(REFERER); diff --git a/mod/groups/actions/groups/membership/add.php b/mod/groups/actions/groups/membership/add.php new file mode 100644 index 000000000..de0cba613 --- /dev/null +++ b/mod/groups/actions/groups/membership/add.php @@ -0,0 +1,42 @@ +<?php +/** + * Add users to a group + * + * @package ElggGroups + */ +$logged_in_user = elgg_get_logged_in_user_entity(); + +$user_guid = get_input('user_guid'); +if (!is_array($user_guid)) { + $user_guid = array($user_guid); +} +$group_guid = get_input('group_guid'); +$group = get_entity($group_guid); + +if (sizeof($user_guid)) { + foreach ($user_guid as $u_id) { + $user = get_user($u_id); + + if ($user && $group && $group->canEdit()) { + if (!$group->isMember($user)) { + if (groups_join_group($group, $user)) { + + // send welcome email to user + notify_user($user->getGUID(), $group->owner_guid, + elgg_echo('groups:welcome:subject', array($group->name)), + elgg_echo('groups:welcome:body', array( + $user->name, + $group->name, + $group->getURL()) + )); + + system_message(elgg_echo('groups:addedtogroup')); + } else { + // huh + } + } + } + } +} + +forward(REFERER); diff --git a/mod/groups/actions/groups/membership/delete_invite.php b/mod/groups/actions/groups/membership/delete_invite.php new file mode 100644 index 000000000..d21aa0309 --- /dev/null +++ b/mod/groups/actions/groups/membership/delete_invite.php @@ -0,0 +1,24 @@ +<?php +/** + * Delete an invitation to join a group. + * + * @package ElggGroups + */ + +$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid()); +$group_guid = get_input('group_guid'); + +$user = get_entity($user_guid); + +// invisible groups require overriding access to delete invite +$old_access = elgg_set_ignore_access(true); +$group = get_entity($group_guid); +elgg_set_ignore_access($old_access); + +// If join request made +if (check_entity_relationship($group->guid, 'invited', $user->guid)) { + remove_entity_relationship($group->guid, 'invited', $user->guid); + system_message(elgg_echo("groups:invitekilled")); +} + +forward(REFERER); diff --git a/mod/groups/actions/groups/membership/delete_request.php b/mod/groups/actions/groups/membership/delete_request.php new file mode 100644 index 000000000..883c9d748 --- /dev/null +++ b/mod/groups/actions/groups/membership/delete_request.php @@ -0,0 +1,20 @@ +<?php +/** + * Delete a request to join a closed group. + * + * @package ElggGroups + */ + +$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid()); +$group_guid = get_input('group_guid'); + +$user = get_entity($user_guid); +$group = get_entity($group_guid); + +// If join request made +if (check_entity_relationship($user->guid, 'membership_request', $group->guid)) { + remove_entity_relationship($user->guid, 'membership_request', $group->guid); + system_message(elgg_echo("groups:joinrequestkilled")); +} + +forward(REFERER); diff --git a/mod/groups/actions/groups/membership/invite.php b/mod/groups/actions/groups/membership/invite.php new file mode 100644 index 000000000..a96165b0e --- /dev/null +++ b/mod/groups/actions/groups/membership/invite.php @@ -0,0 +1,56 @@ +<?php +/** + * Invite users to join a group + * + * @package ElggGroups + */ + +$logged_in_user = elgg_get_logged_in_user_entity(); + +$user_guids = get_input('user_guid'); +if (!is_array($user_guids)) { + $user_guids = array($user_guids); +} +$group_guid = get_input('group_guid'); +$group = get_entity($group_guid); + +if (count($user_guids) > 0 && elgg_instanceof($group, 'group') && $group->canEdit()) { + foreach ($user_guids as $guid) { + $user = get_user($guid); + if (!$user) { + continue; + } + + if (check_entity_relationship($group->guid, 'invited', $user->guid)) { + register_error(elgg_echo("groups:useralreadyinvited")); + continue; + } + + if (check_entity_relationship($user->guid, 'member', $group->guid)) { + // @todo add error message + continue; + } + + // Create relationship + add_entity_relationship($group->guid, 'invited', $user->guid); + + // Send notification + $url = elgg_normalize_url("groups/invitations/$user->username"); + $result = notify_user($user->getGUID(), $group->owner_guid, + elgg_echo('groups:invite:subject', array($user->name, $group->name)), + elgg_echo('groups:invite:body', array( + $user->name, + $logged_in_user->name, + $group->name, + $url, + )), + NULL); + if ($result) { + system_message(elgg_echo("groups:userinvited")); + } else { + register_error(elgg_echo("groups:usernotinvited")); + } + } +} + +forward(REFERER); diff --git a/mod/groups/actions/groups/membership/join.php b/mod/groups/actions/groups/membership/join.php new file mode 100644 index 000000000..b4f4e280c --- /dev/null +++ b/mod/groups/actions/groups/membership/join.php @@ -0,0 +1,72 @@ +<?php +/** + * Join a group + * + * Three states: + * open group so user joins + * closed group so request sent to group owner + * closed group with invite so user joins + * + * @package ElggGroups + */ + +global $CONFIG; + +$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid()); +$group_guid = get_input('group_guid'); + +$user = get_entity($user_guid); + +// access bypass for getting invisible group +$ia = elgg_set_ignore_access(true); +$group = get_entity($group_guid); +elgg_set_ignore_access($ia); + +if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) { + + // join or request + $join = false; + if ($group->isPublicMembership() || $group->canEdit($user->guid)) { + // anyone can join public groups and admins can join any group + $join = true; + } else { + if (check_entity_relationship($group->guid, 'invited', $user->guid)) { + // user has invite to closed group + $join = true; + } + } + + if ($join) { + if (groups_join_group($group, $user)) { + system_message(elgg_echo("groups:joined")); + forward($group->getURL()); + } else { + register_error(elgg_echo("groups:cantjoin")); + } + } else { + add_entity_relationship($user->guid, 'membership_request', $group->guid); + + // Notify group owner + $url = "{$CONFIG->url}groups/requests/$group->guid"; + $subject = elgg_echo('groups:request:subject', array( + $user->name, + $group->name, + )); + $body = elgg_echo('groups:request:body', array( + $group->getOwnerEntity()->name, + $user->name, + $group->name, + $user->getURL(), + $url, + )); + if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) { + system_message(elgg_echo("groups:joinrequestmade")); + } else { + register_error(elgg_echo("groups:joinrequestnotmade")); + } + } +} else { + register_error(elgg_echo("groups:cantjoin")); +} + +forward(REFERER); diff --git a/mod/groups/actions/groups/membership/leave.php b/mod/groups/actions/groups/membership/leave.php new file mode 100644 index 000000000..4f34c7dde --- /dev/null +++ b/mod/groups/actions/groups/membership/leave.php @@ -0,0 +1,36 @@ +<?php +/** + * Leave a group action. + * + * @package ElggGroups + */ + +$user_guid = get_input('user_guid'); +$group_guid = get_input('group_guid'); + +$user = NULL; +if (!$user_guid) { + $user = elgg_get_logged_in_user_entity(); +} else { + $user = get_entity($user_guid); +} + +$group = get_entity($group_guid); + +elgg_set_page_owner_guid($group->guid); + +if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) { + if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) { + if ($group->leave($user)) { + system_message(elgg_echo("groups:left")); + } else { + register_error(elgg_echo("groups:cantleave")); + } + } else { + register_error(elgg_echo("groups:cantleave")); + } +} else { + register_error(elgg_echo("groups:cantleave")); +} + +forward(REFERER); diff --git a/mod/groups/actions/groups/membership/remove.php b/mod/groups/actions/groups/membership/remove.php new file mode 100644 index 000000000..650d35286 --- /dev/null +++ b/mod/groups/actions/groups/membership/remove.php @@ -0,0 +1,31 @@ +<?php +/** + * Remove a user from a group + * + * @package ElggGroups + */ + +$user_guid = get_input('user_guid'); +$group_guid = get_input('group_guid'); + +$user = get_entity($user_guid); +$group = get_entity($group_guid); + +elgg_set_page_owner_guid($group->guid); + +if (($user instanceof ElggUser) && ($group instanceof ElggGroup) && $group->canEdit()) { + // Don't allow removing group owner + if ($group->getOwnerGUID() != $user->getGUID()) { + if ($group->leave($user)) { + system_message(elgg_echo("groups:removed", array($user->name))); + } else { + register_error(elgg_echo("groups:cantremove")); + } + } else { + register_error(elgg_echo("groups:cantremove")); + } +} else { + register_error(elgg_echo("groups:cantremove")); +} + +forward(REFERER); diff --git a/mod/groups/actions/join.php b/mod/groups/actions/join.php deleted file mode 100644 index 8ac583198..000000000 --- a/mod/groups/actions/join.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - /** - * Join a group action. - * - * @package ElggGroups - * @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/ - */ - - // Load configuration - global $CONFIG; - - gatekeeper(); - - $user_guid = get_input('user_guid'); - $group_guid = get_input('group_guid'); - - $user = NULL; - if (!$user_guid) $user = $_SESSION['user']; - else - $user = get_entity($user_guid); - - $group = get_entity($group_guid); - - if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) - { - if ($group->isPublicMembership()) - { - if ($group->join($user)) - { - system_message(elgg_echo("groups:joined")); - - // Remove any invite or join request flags - remove_metadata($user->guid, 'group_invite', $group->guid); - remove_metadata($user->guid, 'group_join_request', $group->guid); - - forward($group->getURL()); - exit; - } - else - register_error(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 - register_error(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 deleted file mode 100644 index f46eb1b2a..000000000 --- a/mod/groups/actions/joinrequest.php +++ /dev/null @@ -1,91 +0,0 @@ -<?php - /** - * User requests to join a closed group. - * - * @package ElggGroups - * @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/ - */ - - // Load configuration - global $CONFIG; - - gatekeeper(); - - $user_guid = get_input('user_guid'); - $group_guid = get_input('group_guid'); - - $user = NULL; - if (!$user_guid) $user = $_SESSION['user']; - else - $user = get_entity($user_guid); - - $group = get_entity($group_guid); - - if (!$group->isMember($user)) - { - $invites = $user->group_invite; - - if ($invites) - { - if (!is_array($invites)) - $invites = array($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 - - // Permit multiple values - $methods = $user->group_join_request; - if (($methods) && (!is_array($methods))) - $methods = array($methods); - if (!$methods) $methods=array(); - $methods[] = $group->getGUID(); - $methods = array_unique($methods); - - //if (!$user->setMetaData('group_join_request', $group->getGUID(), "", true)) - if (!$user->group_join_request = $methods) - system_message(elgg_echo("groups:joinrequestnotmade")); - else - { - - // Send email - if (notify_user($group->owner_guid, $user->getGUID(), - sprintf(elgg_echo('groups:request:subject'), $user->name, $group->name), - sprintf(elgg_echo('groups:request:body'), $group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), "{$CONFIG->url}action/groups/addtogroup?user_guid={$user->guid}&group_guid={$group->guid}"), - NULL, "email")) - system_message(elgg_echo("groups:joinrequestmade")); - else - register_error(elgg_echo("groups:joinrequestnotmade")); - } - - - } - else - register_error(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 deleted file mode 100644 index e28b1bb97..000000000 --- a/mod/groups/actions/leave.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - /** - * Leave a group action. - * - * @package ElggGroups - * @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/ - */ - - // Load configuration - global $CONFIG; - - gatekeeper(); - - $user_guid = get_input('user_guid'); - $group_guid = get_input('group_guid'); - - $user = NULL; - if (!$user_guid) $user = $_SESSION['user']; - else - $user = get_entity($user_guid); - - $group = get_entity($group_guid); - - if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) - { - if ($group->leave($user)) - system_message(elgg_echo("groups:left")); - else - register_error(elgg_echo("groups:cantleave")); - } - else - register_error(elgg_echo("groups:cantleave")); - - forward($_SERVER['HTTP_REFERER']); - exit; -?>
\ No newline at end of file |
