diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-03 03:25:25 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-03 03:25:25 +0000 |
commit | d4e4268d11612408e4989a5c57f69fcb2febe8aa (patch) | |
tree | 2b3b041a5f4e17bea674a44f07c3df5c7f3811dd /mod/bookmarks/actions/bookmarks | |
parent | b232f52a5273a44e28de239cbacc1e4e4b8cc8b3 (diff) | |
download | elgg-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/bookmarks')
-rw-r--r-- | mod/bookmarks/actions/bookmarks/add.php | 82 | ||||
-rw-r--r-- | mod/bookmarks/actions/bookmarks/delete.php | 29 | ||||
-rw-r--r-- | mod/bookmarks/actions/bookmarks/edit.php | 33 |
3 files changed, 144 insertions, 0 deletions
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/bookmarks/edit.php b/mod/bookmarks/actions/bookmarks/edit.php new file mode 100644 index 000000000..87de1c5e2 --- /dev/null +++ b/mod/bookmarks/actions/bookmarks/edit.php @@ -0,0 +1,33 @@ +<?php +/** + * Elgg bookmarks edit action + * + */ + +//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 |