aboutsummaryrefslogtreecommitdiff
path: root/mod/bookmarks/actions
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-03 23:15:07 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-03 23:15:07 +0000
commit0320936f29dd83534b5af386a981131be7981a9a (patch)
tree1d524f4a43c5974bf10b1177a8935754ee176ec5 /mod/bookmarks/actions
parente2ba75ce7dad46f87c43b7ef256e79053af5566e (diff)
downloadelgg-0320936f29dd83534b5af386a981131be7981a9a.tar.gz
elgg-0320936f29dd83534b5af386a981131be7981a9a.tar.bz2
Updated bookmarks with new interface.
git-svn-id: http://code.elgg.org/elgg/trunk@5266 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/bookmarks/actions')
-rw-r--r--mod/bookmarks/actions/add.php107
-rw-r--r--mod/bookmarks/actions/delete.php47
-rwxr-xr-xmod/bookmarks/actions/edit.php35
-rwxr-xr-xmod/bookmarks/actions/reference.php34
-rwxr-xr-xmod/bookmarks/actions/remove.php34
5 files changed, 160 insertions, 97 deletions
diff --git a/mod/bookmarks/actions/add.php b/mod/bookmarks/actions/add.php
index a074719b1..be2f79f82 100644
--- a/mod/bookmarks/actions/add.php
+++ b/mod/bookmarks/actions/add.php
@@ -1,72 +1,41 @@
<?php
-
- /**
- * Elgg bookmarks add/save action
- *
- * @package ElggBookmarks
- * @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-2010
- * @link http://elgg.org/
- */
+/**
+ * Elgg bookmarks add/save action
+ *
+ * @package ElggBookmarks
+ * @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-2010
+ * @link http://elgg.org/
+ */
- gatekeeper();
-
- $title = get_input('title');
- $guid = get_input('bookmark_guid',0);
- $description = get_input('description');
- $address = get_input('address');
- $access = get_input('access');
- $shares = get_input('shares',array());
+gatekeeper();
+action_gatekeeper();
+//set some required variables
+$title = get_input('title');
+$address = get_input('address');
+$notes = get_input('notes');
+$access = get_input('access');
+$tags = get_input('tags');
+$tagarray = string_to_tag_array($tags);
+//create a new bookmark object
+$entity = new ElggObject;
+$entity->subtype = "bookmarks";
+$entity->owner_guid = get_loggedin_user()->getGUID();
+$entity->container_guid = (int)get_input('container_guid', get_loggedin_user()->getGUID());
+$entity->title = $title;
+$entity->description = $notes;
+$entity->address = $address;
+$entity->access_id = $access;
+$entity->link_version = create_wire_url_code();//returns a random code in the form {{L:1hp56}}
+$entity->tags = $tagarray;
- $tags = get_input('tags');
- $tagarray = string_to_tag_array($tags);
-
- if ($guid == 0) {
-
- $entity = new ElggObject;
- $entity->subtype = "bookmarks";
- $entity->owner_guid = $_SESSION['user']->getGUID();
- $entity->container_guid = (int)get_input('container_guid', $_SESSION['user']->getGUID());
-
- } else {
-
- $canedit = false;
- if ($entity = get_entity($guid)) {
- if ($entity->canEdit()) {
- $canedit = true;
- }
- }
- if (!$canedit) {
- system_message(elgg_echo('notfound'));
- forward("pg/bookmarks");
- }
-
- }
-
- $entity->title = $title;
- $entity->address = $address;
- $entity->description = $description;
- $entity->access_id = $access;
- $entity->tags = $tagarray;
-
- if ($entity->save()) {
- $entity->clearRelationships();
- $entity->shares = $shares;
-
- if (is_array($shares) && sizeof($shares) > 0) {
- foreach($shares as $share) {
- $share = (int) $share;
- add_entity_relationship($entity->getGUID(),'share',$share);
- }
- }
- system_message(elgg_echo('bookmarks:save:success'));
- //add to river
- add_to_river('river/object/bookmarks/create','create',$_SESSION['user']->guid,$entity->guid);
- forward($entity->getURL());
- } else {
- register_error(elgg_echo('bookmarks:save:failed'));
- forward("pg/bookmarks");
- }
-
-?>
+if ($entity->save()) {
+ system_message(elgg_echo('bookmarks:save:success'));
+ //add to river
+ add_to_river('river/object/bookmarks/create','create',$_SESSION['user']->guid,$entity->guid);
+} else {
+ register_error(elgg_echo('bookmarks:save:failed'));
+}
+$account = get_entity((int)get_input('container_guid', get_loggedin_user()->getGUID()));
+forward("pg/bookmarks/" . $account->username); \ No newline at end of file
diff --git a/mod/bookmarks/actions/delete.php b/mod/bookmarks/actions/delete.php
index 217197b24..5a35d44f5 100644
--- a/mod/bookmarks/actions/delete.php
+++ b/mod/bookmarks/actions/delete.php
@@ -1,32 +1,23 @@
<?php
+/**
+ * Elgg bookmarks delete action
+ *
+ * @package ElggBookmarks
+ * @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-2010
+ * @link http://elgg.org/
+ */
- /**
- * Elgg bookmarks delete action
- *
- * @package ElggBookmarks
- * @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-2010
- * @link http://elgg.org/
- */
-
- $guid = get_input('bookmark_guid',0);
- if ($entity = get_entity($guid)) {
-
- if ($entity->canEdit()) {
-
- if ($entity->delete()) {
-
- system_message(elgg_echo("bookmarks:delete:success"));
- forward("pg/bookmarks/");
-
- }
-
- }
-
+$guid = get_input('bookmark_guid',0);
+if ($entity = get_entity($guid)) {
+ if ($entity->canEdit()) {
+ if ($entity->delete()) {
+ system_message(elgg_echo("bookmarks:delete:success"));
+ forward($_SERVER['HTTP_REFERER']);
}
+ }
+}
- register_error(elgg_echo("bookmarks:delete:failed"));
- forward("pg/bookmarks/");
-
-?> \ No newline at end of file
+register_error(elgg_echo("bookmarks:delete:failed"));
+forward($_SERVER['HTTP_REFERER']); \ No newline at end of file
diff --git a/mod/bookmarks/actions/edit.php b/mod/bookmarks/actions/edit.php
new file mode 100755
index 000000000..16e324154
--- /dev/null
+++ b/mod/bookmarks/actions/edit.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Elgg bookmarks edit action
+ *
+ */
+
+gatekeeper();
+action_gatekeeper();
+//set some required variables
+$guid = get_input('guid');
+$title = get_input('title');
+$address = get_input('address');
+$notes = get_input('notes');
+$access = get_input('access');
+$tags = get_input('tags');
+$tagarray = string_to_tag_array($tags);
+
+// Make sure we actually have permission to edit
+$bookmark = get_entity($guid);
+if ($bookmark->getSubtype() == "bookmarks" && $bookmark->canEdit()) {
+ $bookmark->title = $title;
+ $bookmark->description = $notes;
+ $bookmark->address = $address;
+ $bookmark->access_id = $access;
+ $bookmark->tags = $tagarray;
+ if ($bookmark->save()) {
+ system_message(elgg_echo('bookmarks:edit:success'));
+ } else {
+ system_message(elgg_echo('bookmarks:edit:fail'));
+ }
+}else{
+ system_message(elgg_echo('bookmarks:edit:fail'));
+}
+$account = get_entity($bookmark->container_guid);
+forward("pg/bookmarks/" . $account->username); \ No newline at end of file
diff --git a/mod/bookmarks/actions/reference.php b/mod/bookmarks/actions/reference.php
new file mode 100755
index 000000000..ae79b78cd
--- /dev/null
+++ b/mod/bookmarks/actions/reference.php
@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * Elgg bookmarks add as reference
+ * Guid one is the object, guid two is the bookmark, 'reference' is the relationship name
+ */
+
+//set some variables
+$object_guid = get_input('object_guid');
+$bookmark_guid = get_input('reference');
+$object = get_entity($object_guid);
+$bookmark = get_entity($bookmark_guid);
+//check both the object and bookmark exist
+if($bookmark && $object){
+ //check the user can add a reference
+ if($object->canEdit()){
+ //create a relationship between the object and bookmark
+ if(add_entity_relationship($object_guid, "reference", $bookmark_guid)){
+ // Success message
+ system_message(elgg_echo("bookmarks:referenceadded"));
+ }else{
+ // Failure message
+ system_message(elgg_echo("bookmarks:referenceerror"));
+ }
+ }else{
+ // Failure message
+ system_message(elgg_echo("bookmarks:referenceerror"));
+ }
+}else{
+ // Failure message
+ system_message(elgg_echo("bookmarks:referenceerror"));
+}
+
+forward($object->getURL()); \ No newline at end of file
diff --git a/mod/bookmarks/actions/remove.php b/mod/bookmarks/actions/remove.php
new file mode 100755
index 000000000..b8b1ad6a3
--- /dev/null
+++ b/mod/bookmarks/actions/remove.php
@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * Elgg bookmarks remove a reference
+ * Guid one is the object, guid two is the bookmark, 'reference' is the relationship name
+ */
+
+//set some variables
+$object_guid = get_input('object_guid');
+$bookmark_guid = get_input('bookmark');
+$object = get_entity($object_guid);
+$bookmark = get_entity($bookmark_guid);
+//check both the object and bookmark exist
+if($bookmark && $object){
+ //check the user can add a reference
+ if($object->canEdit()){
+ //remove the relationship between the object and bookmark
+ if(remove_entity_relationship($object_guid, "reference", $bookmark_guid)){
+ // Success message
+ system_message(elgg_echo("bookmarks:removed"));
+ }else{
+ // Failure message
+ system_message(elgg_echo("bookmarks:removederror"));
+ }
+ }else{
+ // Failure message
+ system_message(elgg_echo("bookmarks:removederror"));
+ }
+}else{
+ // Failure message
+ system_message(elgg_echo("bookmarks:removederror"));
+}
+
+forward($object->getURL()); \ No newline at end of file