aboutsummaryrefslogtreecommitdiff
path: root/mod/bookmarks/actions
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-03 03:25:25 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-03 03:25:25 +0000
commitd4e4268d11612408e4989a5c57f69fcb2febe8aa (patch)
tree2b3b041a5f4e17bea674a44f07c3df5c7f3811dd /mod/bookmarks/actions
parentb232f52a5273a44e28de239cbacc1e4e4b8cc8b3 (diff)
downloadelgg-d4e4268d11612408e4989a5c57f69fcb2febe8aa.tar.gz
elgg-d4e4268d11612408e4989a5c57f69fcb2febe8aa.tar.bz2
Refs #2680: First pass at porting the 1.7 bookmarks to 1.8. Functional, but code is still messy.
git-svn-id: http://code.elgg.org/elgg/trunk@7998 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/bookmarks/actions')
-rw-r--r--mod/bookmarks/actions/add.php49
-rw-r--r--mod/bookmarks/actions/bookmarks/add.php82
-rw-r--r--mod/bookmarks/actions/bookmarks/delete.php29
-rw-r--r--[-rwxr-xr-x]mod/bookmarks/actions/bookmarks/edit.php (renamed from mod/bookmarks/actions/edit.php)0
-rw-r--r--mod/bookmarks/actions/delete.php20
-rwxr-xr-xmod/bookmarks/actions/reference.php34
-rwxr-xr-xmod/bookmarks/actions/remove.php34
7 files changed, 111 insertions, 137 deletions
diff --git a/mod/bookmarks/actions/add.php b/mod/bookmarks/actions/add.php
deleted file mode 100644
index b17ce76a4..000000000
--- a/mod/bookmarks/actions/add.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/**
- * Elgg bookmarks add/save action
- *
- * @package ElggBookmarks
- */
-
-//set some required variables
-$title = strip_tags(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);
-
-if (!$title || !$address) {
- register_error(elgg_echo('bookmarks:save:failed'));
- forward(REFERER);
-}
-
-// don't allow malicious code.
-// put this in a context of a link so HTMLawed knows how to filter correctly.
-$xss_test = "<a href=\"$address\"></a>";
-if ($xss_test != filter_tags($xss_test)) {
- register_error(elgg_echo('bookmarks:save:failed'));
- forward(REFERER);
-}
-
-//create a new bookmark object
-$entity = new ElggObject;
-$entity->subtype = "bookmarks";
-$entity->owner_guid = get_loggedin_userid();
-$entity->container_guid = (int)get_input('container_guid', get_loggedin_userid());
-$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;
-
-if ($entity->save()) {
- system_message(elgg_echo('bookmarks:save:success'));
- //add to river
- add_to_river('river/object/bookmarks/create','create',get_loggedin_userid(),$entity->guid);
-} else {
- register_error(elgg_echo('bookmarks:save:failed'));
-}
-$account = get_entity((int)get_input('container_guid', get_loggedin_userid()));
-forward("pg/bookmarks/" . $account->username); \ No newline at end of file
diff --git a/mod/bookmarks/actions/bookmarks/add.php b/mod/bookmarks/actions/bookmarks/add.php
new file mode 100644
index 000000000..7d8204ca5
--- /dev/null
+++ b/mod/bookmarks/actions/bookmarks/add.php
@@ -0,0 +1,82 @@
+<?php
+/**
+* Elgg bookmarks add/save action
+*
+* @package ElggBookmarks
+*/
+
+gatekeeper();
+
+$title = strip_tags(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());
+
+if (!$title || !$address) {
+ register_error(elgg_echo('bookmarks:save:failed'));
+ forward(REFERER);
+}
+
+// don't allow malicious code.
+// put this in a context of a link so HTMLawed knows how to filter correctly.
+$xss_test = "<a href=\"$address\"></a>";
+if ($xss_test != filter_tags($xss_test)) {
+ register_error(elgg_echo('bookmarks:save:failed'));
+ forward(REFERER);
+}
+
+$tags = get_input('tags');
+$tagarray = string_to_tag_array($tags);
+
+$new_bookmark = FALSE;
+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());
+
+ $new_bookmark = TRUE;
+
+} 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
+ if ($new_bookmark) {
+ 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");
+}
diff --git a/mod/bookmarks/actions/bookmarks/delete.php b/mod/bookmarks/actions/bookmarks/delete.php
new file mode 100644
index 000000000..48b4a2dd8
--- /dev/null
+++ b/mod/bookmarks/actions/bookmarks/delete.php
@@ -0,0 +1,29 @@
+<?php
+
+ /**
+ * Elgg bookmarks delete action
+ *
+ * @package ElggBookmarks
+ */
+
+ $guid = get_input('bookmark_guid',0);
+ if ($entity = get_entity($guid)) {
+
+ $container = get_entity($entity->container_guid);
+ if ($entity->canEdit()) {
+
+ if ($entity->delete()) {
+
+ system_message(elgg_echo("bookmarks:delete:success"));
+ forward("pg/bookmarks/owner/$container->username/");
+
+ }
+
+ }
+
+ }
+
+ register_error(elgg_echo("bookmarks:delete:failed"));
+ forward(REFERER);
+
+?> \ No newline at end of file
diff --git a/mod/bookmarks/actions/edit.php b/mod/bookmarks/actions/bookmarks/edit.php
index 87de1c5e2..87de1c5e2 100755..100644
--- a/mod/bookmarks/actions/edit.php
+++ b/mod/bookmarks/actions/bookmarks/edit.php
diff --git a/mod/bookmarks/actions/delete.php b/mod/bookmarks/actions/delete.php
deleted file mode 100644
index 23de80146..000000000
--- a/mod/bookmarks/actions/delete.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-/**
- * Elgg bookmarks delete action
- *
- * @package ElggBookmarks
- */
-
-$guid = get_input('bookmark_guid',0);
-if ($entity = get_entity($guid)) {
- if ($entity->canEdit()) {
- $container = get_entity($entity->container_guid);
- if ($entity->delete()) {
- system_message(elgg_echo("bookmarks:delete:success"));
- forward("pg/bookmarks/$container->username/");
- }
- }
-}
-
-register_error(elgg_echo("bookmarks:delete:failed"));
-forward(REFERER); \ No newline at end of file
diff --git a/mod/bookmarks/actions/reference.php b/mod/bookmarks/actions/reference.php
deleted file mode 100755
index 515ac1ed1..000000000
--- a/mod/bookmarks/actions/reference.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?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
deleted file mode 100755
index f704a5cc3..000000000
--- a/mod/bookmarks/actions/remove.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?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