diff options
Diffstat (limited to 'mod/bookmarks')
26 files changed, 1233 insertions, 0 deletions
diff --git a/mod/bookmarks/actions/bookmarks/delete.php b/mod/bookmarks/actions/bookmarks/delete.php new file mode 100644 index 000000000..2e9f41438 --- /dev/null +++ b/mod/bookmarks/actions/bookmarks/delete.php @@ -0,0 +1,24 @@ +<?php +/** + * Delete a bookmark + * + * @package Bookmarks + */ + +$guid = get_input('guid'); +$bookmark = get_entity($guid); + +if (elgg_instanceof($bookmark, 'object', 'bookmarks') && $bookmark->canEdit()) { + $container = $bookmark->getContainerEntity(); + if ($bookmark->delete()) { + system_message(elgg_echo("bookmarks:delete:success")); + if (elgg_instanceof($container, 'group')) { + forward("bookmarks/group/$container->guid/all"); + } else { + forward("bookmarks/owner/$container->username"); + } + } +} + +register_error(elgg_echo("bookmarks:delete:failed")); +forward(REFERER); diff --git a/mod/bookmarks/actions/bookmarks/save.php b/mod/bookmarks/actions/bookmarks/save.php new file mode 100644 index 000000000..46090b115 --- /dev/null +++ b/mod/bookmarks/actions/bookmarks/save.php @@ -0,0 +1,90 @@ +<?php +/** +* Elgg bookmarks save action +* +* @package Bookmarks +*/ + +$title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8'); +$description = get_input('description'); +$address = get_input('address'); +$access_id = get_input('access_id'); +$tags = get_input('tags'); +$guid = get_input('guid'); +$share = get_input('share'); +$container_guid = get_input('container_guid', elgg_get_logged_in_user_guid()); + +elgg_make_sticky_form('bookmarks'); + +// don't use elgg_normalize_url() because we don't want +// relative links resolved to this site. +if ($address && !preg_match("#^((ht|f)tps?:)?//#i", $address)) { + $address = "http://$address"; +} + +if (!$title || !$address) { + register_error(elgg_echo('bookmarks:save:failed')); + forward(REFERER); +} + +// see https://bugs.php.net/bug.php?id=51192 +$php_5_2_13_and_below = version_compare(PHP_VERSION, '5.2.14', '<'); +$php_5_3_0_to_5_3_2 = version_compare(PHP_VERSION, '5.3.0', '>=') && + version_compare(PHP_VERSION, '5.3.3', '<'); + +$validated = false; +if ($php_5_2_13_and_below || $php_5_3_0_to_5_3_2) { + $tmp_address = str_replace("-", "", $address); + $validated = filter_var($tmp_address, FILTER_VALIDATE_URL); +} else { + $validated = filter_var($address, FILTER_VALIDATE_URL); +} +if (!$validated) { + register_error(elgg_echo('bookmarks:save:failed')); + forward(REFERER); +} + +if ($guid == 0) { + $bookmark = new ElggObject; + $bookmark->subtype = "bookmarks"; + $bookmark->container_guid = (int)get_input('container_guid', $_SESSION['user']->getGUID()); + $new = true; +} else { + $bookmark = get_entity($guid); + if (!$bookmark->canEdit()) { + system_message(elgg_echo('bookmarks:save:failed')); + forward(REFERRER); + } +} + +$tagarray = string_to_tag_array($tags); + +$bookmark->title = $title; +$bookmark->address = $address; +$bookmark->description = $description; +$bookmark->access_id = $access_id; +$bookmark->tags = $tagarray; + +if ($bookmark->save()) { + + elgg_clear_sticky_form('bookmarks'); + + // @todo + if (is_array($shares) && sizeof($shares) > 0) { + foreach($shares as $share) { + $share = (int) $share; + add_entity_relationship($bookmark->getGUID(), 'share', $share); + } + } + system_message(elgg_echo('bookmarks:save:success')); + + //add to river only if new + if ($new) { + add_to_river('river/object/bookmarks/create','create', elgg_get_logged_in_user_guid(), $bookmark->getGUID()); + } + + forward($bookmark->getURL()); +} else { + register_error(elgg_echo('bookmarks:save:failed')); + forward("bookmarks"); +} diff --git a/mod/bookmarks/graphics/bookmark.gif b/mod/bookmarks/graphics/bookmark.gif Binary files differnew file mode 100644 index 000000000..55c5e3e15 --- /dev/null +++ b/mod/bookmarks/graphics/bookmark.gif diff --git a/mod/bookmarks/graphics/bookmarklet.gif b/mod/bookmarks/graphics/bookmarklet.gif Binary files differnew file mode 100644 index 000000000..45b24709b --- /dev/null +++ b/mod/bookmarks/graphics/bookmarklet.gif diff --git a/mod/bookmarks/languages/en.php b/mod/bookmarks/languages/en.php new file mode 100644 index 000000000..970b39415 --- /dev/null +++ b/mod/bookmarks/languages/en.php @@ -0,0 +1,91 @@ +<?php +/** + * Bookmarks English language file + */ + +$english = array( + + /** + * Menu items and titles + */ + 'bookmarks' => "Bookmarks", + 'bookmarks:add' => "Add a bookmark", + 'bookmarks:edit' => "Edit bookmark", + 'bookmarks:owner' => "%s's bookmarks", + 'bookmarks:friends' => "Friends' bookmarks", + 'bookmarks:everyone' => "All site bookmarks", + 'bookmarks:this' => "Bookmark this page", + 'bookmarks:this:group' => "Bookmark in %s", + 'bookmarks:bookmarklet' => "Get bookmarklet", + 'bookmarks:bookmarklet:group' => "Get group bookmarklet", + 'bookmarks:inbox' => "Bookmarks inbox", + 'bookmarks:morebookmarks' => "More bookmarks", + 'bookmarks:more' => "More", + 'bookmarks:with' => "Share with", + 'bookmarks:new' => "A new bookmark", + 'bookmarks:address' => "Address of the bookmark", + 'bookmarks:none' => 'No bookmarks', + + 'bookmarks:notification' => +'%s added a new bookmark: + +%s - %s +%s + +View and comment on the new bookmark: +%s +', + + 'bookmarks:delete:confirm' => "Are you sure you want to delete this resource?", + + 'bookmarks:numbertodisplay' => 'Number of bookmarks to display', + + 'bookmarks:shared' => "Bookmarked", + 'bookmarks:visit' => "Visit resource", + 'bookmarks:recent' => "Recent bookmarks", + + 'river:create:object:bookmarks' => '%s bookmarked %s', + 'river:comment:object:bookmarks' => '%s commented on a bookmark %s', + 'bookmarks:river:annotate' => 'a comment on this bookmark', + 'bookmarks:river:item' => 'an item', + + 'item:object:bookmarks' => 'Bookmarks', + + 'bookmarks:group' => 'Group bookmarks', + 'bookmarks:enablebookmarks' => 'Enable group bookmarks', + 'bookmarks:nogroup' => 'This group does not have any bookmarks yet', + 'bookmarks:more' => 'More bookmarks', + + 'bookmarks:no_title' => 'No title', + + /** + * Widget and bookmarklet + */ + 'bookmarks:widget:description' => "Display your latest bookmarks.", + + 'bookmarks:bookmarklet:description' => + "The bookmarks bookmarklet allows you to share any resource you find on the web with your friends, or just bookmark it for yourself. To use it, simply drag the following button to your browser's links bar:", + + 'bookmarks:bookmarklet:descriptionie' => + "If you are using Internet Explorer, you will need to right click on the bookmarklet icon, select 'add to favorites', and then the Links bar.", + + 'bookmarks:bookmarklet:description:conclusion' => + "You can then save any page you visit by clicking it at any time.", + + /** + * Status messages + */ + + 'bookmarks:save:success' => "Your item was successfully bookmarked.", + 'bookmarks:delete:success' => "Your bookmark was deleted.", + + /** + * Error messages + */ + + 'bookmarks:save:failed' => "Your bookmark could not be saved. Make sure you've entered a title and address and then try again.", + 'bookmarks:save:invalid' => "The address of the bookmark is invalid and could not be saved.", + 'bookmarks:delete:failed' => "Your bookmark could not be deleted. Please try again.", +); + +add_translation('en', $english);
\ No newline at end of file diff --git a/mod/bookmarks/lib/bookmarks.php b/mod/bookmarks/lib/bookmarks.php new file mode 100644 index 000000000..9a9dff18c --- /dev/null +++ b/mod/bookmarks/lib/bookmarks.php @@ -0,0 +1,46 @@ +<?php +/** + * Bookmarks helper functions + * + * @package Bookmarks + */ + +/** + * Prepare the add/edit form variables + * + * @param ElggObject $bookmark A bookmark object. + * @return array + */ +function bookmarks_prepare_form_vars($bookmark = null) { + // input names => defaults + $values = array( + 'title' => get_input('title', ''), // bookmarklet support + 'address' => get_input('address', ''), + 'description' => '', + 'access_id' => ACCESS_DEFAULT, + 'tags' => '', + 'shares' => array(), + 'container_guid' => elgg_get_page_owner_guid(), + 'guid' => null, + 'entity' => $bookmark, + ); + + if ($bookmark) { + foreach (array_keys($values) as $field) { + if (isset($bookmark->$field)) { + $values[$field] = $bookmark->$field; + } + } + } + + if (elgg_is_sticky_form('bookmarks')) { + $sticky_values = elgg_get_sticky_values('bookmarks'); + foreach ($sticky_values as $key => $value) { + $values[$key] = $value; + } + } + + elgg_clear_sticky_form('bookmarks'); + + return $values; +} diff --git a/mod/bookmarks/manifest.xml b/mod/bookmarks/manifest.xml new file mode 100644 index 000000000..b95af87f8 --- /dev/null +++ b/mod/bookmarks/manifest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> + <name>Bookmarks</name> + <author>Core developers</author> + <version>1.8</version> + <category>bundled</category> + <category>content</category> + <category>widget</category> + <blurb>Add and comment on bookmarks.</blurb> + <description>Adds the ability for users to bookmark internal and external sites. Other users can then comment on the bookmarks.</description> + <website>http://www.elgg.org/</website> + <copyright>See COPYRIGHT.txt</copyright> + <license>GNU General Public License version 2</license> + <requires> + <type>elgg_release</type> + <version>1.8</version> + </requires> + <activate_on_install>true</activate_on_install> +</plugin_manifest> diff --git a/mod/bookmarks/pages/bookmarks/add.php b/mod/bookmarks/pages/bookmarks/add.php new file mode 100644 index 000000000..d80d4a4bc --- /dev/null +++ b/mod/bookmarks/pages/bookmarks/add.php @@ -0,0 +1,22 @@ +<?php +/** + * Add bookmark page + * + * @package Bookmarks + */ + +$page_owner = elgg_get_page_owner_entity(); + +$title = elgg_echo('bookmarks:add'); +elgg_push_breadcrumb($title); + +$vars = bookmarks_prepare_form_vars(); +$content = elgg_view_form('bookmarks/save', array(), $vars); + +$body = elgg_view_layout('content', array( + 'filter' => '', + 'content' => $content, + 'title' => $title, +)); + +echo elgg_view_page($title, $body);
\ No newline at end of file diff --git a/mod/bookmarks/pages/bookmarks/all.php b/mod/bookmarks/pages/bookmarks/all.php new file mode 100644 index 000000000..5c6011ad9 --- /dev/null +++ b/mod/bookmarks/pages/bookmarks/all.php @@ -0,0 +1,33 @@ +<?php +/** + * Elgg bookmarks plugin everyone page + * + * @package ElggBookmarks + */ + +elgg_pop_breadcrumb(); +elgg_push_breadcrumb(elgg_echo('bookmarks')); + +elgg_register_title_button(); + +$content = elgg_list_entities(array( + 'type' => 'object', + 'subtype' => 'bookmarks', + 'full_view' => false, + 'view_toggle_type' => false, +)); + +if (!$content) { + $content = elgg_echo('bookmarks:none'); +} + +$title = elgg_echo('bookmarks:everyone'); + +$body = elgg_view_layout('content', array( + 'filter_context' => 'all', + 'content' => $content, + 'title' => $title, + 'sidebar' => elgg_view('bookmarks/sidebar'), +)); + +echo elgg_view_page($title, $body);
\ No newline at end of file diff --git a/mod/bookmarks/pages/bookmarks/bookmarklet.php b/mod/bookmarks/pages/bookmarks/bookmarklet.php new file mode 100644 index 000000000..99866e385 --- /dev/null +++ b/mod/bookmarks/pages/bookmarks/bookmarklet.php @@ -0,0 +1,36 @@ +<?php +/** +* Elgg bookmarks plugin bookmarklet page +* +* @package Bookmarks +*/ + +gatekeeper(); + +$container_guid = get_input('container_guid'); +$container = get_entity($container_guid); +$page_owner = $container; + +if (elgg_instanceof($container, 'object')) { + $page_owner = $container->getContainerEntity(); +} + +elgg_set_page_owner_guid($page_owner->getGUID()); + +$title = elgg_echo('bookmarks:bookmarklet'); + +if ($page_owner instanceof ElggGroup) { + elgg_push_breadcrumb($page_owner->name, $page_owner->getURL()); +} + +elgg_push_breadcrumb($title); + +$content = elgg_view("bookmarks/bookmarklet"); + +$body = elgg_view_layout('content', array( + 'content' => $content, + 'title' => $title, + 'filter' => false +)); + +echo elgg_view_page($title, $body);
\ No newline at end of file diff --git a/mod/bookmarks/pages/bookmarks/edit.php b/mod/bookmarks/pages/bookmarks/edit.php new file mode 100644 index 000000000..93b143c36 --- /dev/null +++ b/mod/bookmarks/pages/bookmarks/edit.php @@ -0,0 +1,30 @@ +<?php +/** + * Add bookmark page + * + * @package ElggBookmarks + */ + +$bookmark_guid = get_input('guid'); +$bookmark = get_entity($bookmark_guid); + +if (!elgg_instanceof($bookmark, 'object', 'bookmarks') || !$bookmark->canEdit()) { + register_error(elgg_echo('bookmarks:unknown_bookmark')); + forward(REFERRER); +} + +$page_owner = elgg_get_page_owner_entity(); + +$title = elgg_echo('bookmarks:edit'); +elgg_push_breadcrumb($title); + +$vars = bookmarks_prepare_form_vars($bookmark); +$content = elgg_view_form('bookmarks/save', array(), $vars); + +$body = elgg_view_layout('content', array( + 'filter' => '', + 'content' => $content, + 'title' => $title, +)); + +echo elgg_view_page($title, $body);
\ No newline at end of file diff --git a/mod/bookmarks/pages/bookmarks/friends.php b/mod/bookmarks/pages/bookmarks/friends.php new file mode 100644 index 000000000..173996346 --- /dev/null +++ b/mod/bookmarks/pages/bookmarks/friends.php @@ -0,0 +1,33 @@ +<?php +/** + * Elgg bookmarks plugin friends page + * + * @package ElggBookmarks + */ + +$page_owner = elgg_get_page_owner_entity(); +if (!$page_owner) { + forward('', '404'); +} + +elgg_push_breadcrumb($page_owner->name, "bookmarks/owner/$page_owner->username"); +elgg_push_breadcrumb(elgg_echo('friends')); + +elgg_register_title_button(); + +$title = elgg_echo('bookmarks:friends'); + +$content = list_user_friends_objects($page_owner->guid, 'bookmarks', 10, false); +if (!$content) { + $content = elgg_echo('bookmarks:none'); +} + +$params = array( + 'filter_context' => 'friends', + 'content' => $content, + 'title' => $title, +); + +$body = elgg_view_layout('content', $params); + +echo elgg_view_page($title, $body); diff --git a/mod/bookmarks/pages/bookmarks/owner.php b/mod/bookmarks/pages/bookmarks/owner.php new file mode 100644 index 000000000..b7b907916 --- /dev/null +++ b/mod/bookmarks/pages/bookmarks/owner.php @@ -0,0 +1,50 @@ +<?php +/** + * Elgg bookmarks plugin everyone page + * + * @package Bookmarks + */ + +$page_owner = elgg_get_page_owner_entity(); +if (!$page_owner) { + forward('', '404'); +} + +elgg_push_breadcrumb($page_owner->name); + +elgg_register_title_button(); + +$content .= elgg_list_entities(array( + 'type' => 'object', + 'subtype' => 'bookmarks', + 'container_guid' => $page_owner->guid, + 'full_view' => false, + 'view_toggle_type' => false +)); + +if (!$content) { + $content = elgg_echo('bookmarks:none'); +} + +$title = elgg_echo('bookmarks:owner', array($page_owner->name)); + +$filter_context = ''; +if ($page_owner->getGUID() == elgg_get_logged_in_user_guid()) { + $filter_context = 'mine'; +} + +$vars = array( + 'filter_context' => $filter_context, + 'content' => $content, + 'title' => $title, + 'sidebar' => elgg_view('bookmarks/sidebar'), +); + +// don't show filter if out of filter context +if ($page_owner instanceof ElggGroup) { + $vars['filter'] = false; +} + +$body = elgg_view_layout('content', $vars); + +echo elgg_view_page($title, $body);
\ No newline at end of file diff --git a/mod/bookmarks/pages/bookmarks/view.php b/mod/bookmarks/pages/bookmarks/view.php new file mode 100644 index 000000000..70a6a5bfe --- /dev/null +++ b/mod/bookmarks/pages/bookmarks/view.php @@ -0,0 +1,38 @@ +<?php +/** + * View a bookmark + * + * @package ElggBookmarks + */ + +$bookmark = get_entity(get_input('guid')); +if (!$bookmark) { + register_error(elgg_echo('noaccess')); + $_SESSION['last_forward_from'] = current_page_url(); + forward(''); +} + +$page_owner = elgg_get_page_owner_entity(); + +$crumbs_title = $page_owner->name; + +if (elgg_instanceof($page_owner, 'group')) { + elgg_push_breadcrumb($crumbs_title, "bookmarks/group/$page_owner->guid/all"); +} else { + elgg_push_breadcrumb($crumbs_title, "bookmarks/owner/$page_owner->username"); +} + +$title = $bookmark->title; + +elgg_push_breadcrumb($title); + +$content = elgg_view_entity($bookmark, array('full_view' => true)); +$content .= elgg_view_comments($bookmark); + +$body = elgg_view_layout('content', array( + 'content' => $content, + 'title' => $title, + 'filter' => '', +)); + +echo elgg_view_page($title, $body); diff --git a/mod/bookmarks/start.php b/mod/bookmarks/start.php new file mode 100644 index 000000000..caea43587 --- /dev/null +++ b/mod/bookmarks/start.php @@ -0,0 +1,316 @@ +<?php +/** + * Elgg Bookmarks plugin + * + * @package ElggBookmarks + */ + +elgg_register_event_handler('init', 'system', 'bookmarks_init'); + +/** + * Bookmark init + */ +function bookmarks_init() { + + $root = dirname(__FILE__); + elgg_register_library('elgg:bookmarks', "$root/lib/bookmarks.php"); + + // actions + $action_path = "$root/actions/bookmarks"; + elgg_register_action('bookmarks/save', "$action_path/save.php"); + elgg_register_action('bookmarks/delete', "$action_path/delete.php"); + elgg_register_action('bookmarks/share', "$action_path/share.php"); + + // menus + elgg_register_menu_item('site', array( + 'name' => 'bookmarks', + 'text' => elgg_echo('bookmarks'), + 'href' => 'bookmarks/all' + )); + + elgg_register_plugin_hook_handler('register', 'menu:page', 'bookmarks_page_menu'); + elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'bookmarks_owner_block_menu'); + + elgg_register_page_handler('bookmarks', 'bookmarks_page_handler'); + + elgg_extend_view('css/elgg', 'bookmarks/css'); + elgg_extend_view('js/elgg', 'bookmarks/js'); + + elgg_register_widget_type('bookmarks', elgg_echo('bookmarks'), elgg_echo('bookmarks:widget:description')); + + if (elgg_is_logged_in()) { + $user_guid = elgg_get_logged_in_user_guid(); + $address = urlencode(current_page_url()); + + elgg_register_menu_item('extras', array( + 'name' => 'bookmark', + 'text' => elgg_view_icon('push-pin-alt'), + 'href' => "bookmarks/add/$user_guid?address=$address", + 'title' => elgg_echo('bookmarks:this'), + 'rel' => 'nofollow', + )); + } + // Register granular notification for this type + register_notification_object('object', 'bookmarks', elgg_echo('bookmarks:new')); + + // Listen to notification events and supply a more useful message + elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'bookmarks_notify_message'); + + // Register bookmarks view for ecml parsing + elgg_register_plugin_hook_handler('get_views', 'ecml', 'bookmarks_ecml_views_hook'); + + // Register a URL handler for bookmarks + elgg_register_entity_url_handler('object', 'bookmarks', 'bookmark_url'); + + // Register entity type for search + elgg_register_entity_type('object', 'bookmarks'); + + // Groups + add_group_tool_option('bookmarks', elgg_echo('bookmarks:enablebookmarks'), true); + elgg_extend_view('groups/tool_latest', 'bookmarks/group_module'); +} + +/** + * Dispatcher for bookmarks. + * + * URLs take the form of + * All bookmarks: bookmarks/all + * User's bookmarks: bookmarks/owner/<username> + * Friends' bookmarks: bookmarks/friends/<username> + * View bookmark: bookmarks/view/<guid>/<title> + * New bookmark: bookmarks/add/<guid> (container: user, group, parent) + * Edit bookmark: bookmarks/edit/<guid> + * Group bookmarks: bookmarks/group/<guid>/all + * Bookmarklet: bookmarks/bookmarklet/<guid> (user) + * + * Title is ignored + * + * @param array $page + * @return bool + */ +function bookmarks_page_handler($page) { + + elgg_load_library('elgg:bookmarks'); + + if (!isset($page[0])) { + $page[0] = 'all'; + } + + elgg_push_breadcrumb(elgg_echo('bookmarks'), 'bookmarks/all'); + + // old group usernames + if (substr_count($page[0], 'group:')) { + preg_match('/group\:([0-9]+)/i', $page[0], $matches); + $guid = $matches[1]; + if ($entity = get_entity($guid)) { + bookmarks_url_forwarder($page); + } + } + + // user usernames + $user = get_user_by_username($page[0]); + if ($user) { + bookmarks_url_forwarder($page); + } + + $pages = dirname(__FILE__) . '/pages/bookmarks'; + + switch ($page[0]) { + case "all": + include "$pages/all.php"; + break; + + case "owner": + include "$pages/owner.php"; + break; + + case "friends": + include "$pages/friends.php"; + break; + + case "view": + set_input('guid', $page[1]); + include "$pages/view.php"; + break; + case 'read': // Elgg 1.7 compatibility + register_error(elgg_echo("changebookmark")); + forward("bookmarks/view/{$page[1]}"); + break; + + case "add": + gatekeeper(); + include "$pages/add.php"; + break; + + case "edit": + gatekeeper(); + set_input('guid', $page[1]); + include "$pages/edit.php"; + break; + + case 'group': + group_gatekeeper(); + include "$pages/owner.php"; + break; + + case "bookmarklet": + set_input('container_guid', $page[1]); + include "$pages/bookmarklet.php"; + break; + + default: + return false; + } + + elgg_pop_context(); + return true; +} + +/** + * Forward to the new style of URLs + * + * @param string $page + */ +function bookmarks_url_forwarder($page) { + global $CONFIG; + + if (!isset($page[1])) { + $page[1] = 'items'; + } + + switch ($page[1]) { + case "read": + $url = "{$CONFIG->wwwroot}bookmarks/view/{$page[2]}/{$page[3]}"; + break; + case "inbox": + $url = "{$CONFIG->wwwroot}bookmarks/inbox/{$page[0]}"; + break; + case "friends": + $url = "{$CONFIG->wwwroot}bookmarks/friends/{$page[0]}"; + break; + case "add": + $url = "{$CONFIG->wwwroot}bookmarks/add/{$page[0]}"; + break; + case "items": + $url = "{$CONFIG->wwwroot}bookmarks/owner/{$page[0]}"; + break; + case "bookmarklet": + $url = "{$CONFIG->wwwroot}bookmarks/bookmarklet/{$page[0]}"; + break; + } + + register_error(elgg_echo("changebookmark")); + forward($url); +} + +/** + * Populates the ->getUrl() method for bookmarked objects + * + * @param ElggEntity $entity The bookmarked object + * @return string bookmarked item URL + */ +function bookmark_url($entity) { + global $CONFIG; + + $title = $entity->title; + $title = elgg_get_friendly_title($title); + return $CONFIG->url . "bookmarks/view/" . $entity->getGUID() . "/" . $title; +} + +/** + * Add a menu item to an ownerblock + * + * @param string $hook + * @param string $type + * @param array $return + * @param array $params + */ +function bookmarks_owner_block_menu($hook, $type, $return, $params) { + if (elgg_instanceof($params['entity'], 'user')) { + $url = "bookmarks/owner/{$params['entity']->username}"; + $item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks'), $url); + $return[] = $item; + } else { + if ($params['entity']->bookmarks_enable != 'no') { + $url = "bookmarks/group/{$params['entity']->guid}/all"; + $item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks:group'), $url); + $return[] = $item; + } + } + + return $return; +} + +/** + * Returns the body of a notification message + * + * @param string $hook + * @param string $entity_type + * @param string $returnvalue + * @param array $params + */ +function bookmarks_notify_message($hook, $entity_type, $returnvalue, $params) { + $entity = $params['entity']; + $to_entity = $params['to_entity']; + $method = $params['method']; + if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'bookmarks')) { + $descr = $entity->description; + $title = $entity->title; + $owner = $entity->getOwnerEntity(); + + return elgg_echo('bookmarks:notification', array( + $owner->name, + $title, + $entity->address, + $descr, + $entity->getURL() + )); + } + return null; +} + +/** + * Add a page menu menu. + * + * @param string $hook + * @param string $type + * @param array $return + * @param array $params + */ +function bookmarks_page_menu($hook, $type, $return, $params) { + if (elgg_is_logged_in()) { + // only show bookmarklet in bookmark pages + if (elgg_in_context('bookmarks')) { + $page_owner = elgg_get_page_owner_entity(); + if (!$page_owner) { + $page_owner = elgg_get_logged_in_user_entity(); + } + + if ($page_owner instanceof ElggGroup) { + if (!$page_owner->isMember()) { + return $return; + } + $title = elgg_echo('bookmarks:bookmarklet:group'); + } else { + $title = elgg_echo('bookmarks:bookmarklet'); + } + + $return[] = new ElggMenuItem('bookmarklet', $title, 'bookmarks/bookmarklet/' . $page_owner->getGUID()); + } + } + + return $return; +} + +/** + * Return bookmarks views to parse for ecml + * + * @param string $hook + * @param string $type + * @param array $return + * @param array $params + */ +function bookmarks_ecml_views_hook($hook, $type, $return, $params) { + $return['object/bookmarks'] = elgg_echo('item:object:bookmarks'); + return $return; +} diff --git a/mod/bookmarks/views/default/bookmarks/bookmarklet.php b/mod/bookmarks/views/default/bookmarks/bookmarklet.php new file mode 100644 index 000000000..b3e9737fe --- /dev/null +++ b/mod/bookmarks/views/default/bookmarks/bookmarklet.php @@ -0,0 +1,35 @@ +<?php +/** + * Bookmarklet + * + * @package Bookmarks + */ + +$page_owner = elgg_get_page_owner_entity(); + +if ($page_owner instanceof ElggGroup) { + $title = elgg_echo("bookmarks:this:group", array($page_owner->name)); +} else { + $title = elgg_echo("bookmarks:this"); +} + +$guid = $page_owner->getGUID(); + +if (!$name && ($user = elgg_get_logged_in_user_entity())) { + $name = $user->username; +} + +$url = elgg_get_site_url(); +$img = elgg_view('output/img', array( + 'src' => 'mod/bookmarks/graphics/bookmarklet.gif', + 'alt' => $title, +)); +$bookmarklet = "<a href=\"javascript:location.href='{$url}bookmarks/add/$guid?address='" + . "+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)\">" + . $img . "</a>"; + +?> +<p><?php echo elgg_echo("bookmarks:bookmarklet:description"); ?></p> +<p><?php echo $bookmarklet; ?></p> +<p><?php echo elgg_echo("bookmarks:bookmarklet:descriptionie"); ?></p> +<p><?php echo elgg_echo("bookmarks:bookmarklet:description:conclusion"); ?></p> diff --git a/mod/bookmarks/views/default/bookmarks/css.php b/mod/bookmarks/views/default/bookmarks/css.php new file mode 100644 index 000000000..0d734c847 --- /dev/null +++ b/mod/bookmarks/views/default/bookmarks/css.php @@ -0,0 +1,3 @@ +.elgg-icon-bookmark { + background: transparent url(<?php echo elgg_get_site_url();?>mod/bookmarks/graphics/bookmark.gif); +}
\ No newline at end of file diff --git a/mod/bookmarks/views/default/bookmarks/group_module.php b/mod/bookmarks/views/default/bookmarks/group_module.php new file mode 100644 index 000000000..60a727819 --- /dev/null +++ b/mod/bookmarks/views/default/bookmarks/group_module.php @@ -0,0 +1,47 @@ +<?php +/** + * List most recent bookmarks on group profile page + * + * @package Bookmarks + */ + +$group = elgg_get_page_owner_entity(); + +if ($group->bookmarks_enable == "no") { + return true; +} + +$all_link = elgg_view('output/url', array( + 'href' => "bookmarks/group/$group->guid/all", + 'text' => elgg_echo('link:view:all'), + 'is_trusted' => true, +)); + +elgg_push_context('widgets'); +$options = array( + 'type' => 'object', + 'subtype' => 'bookmarks', + 'container_guid' => elgg_get_page_owner_guid(), + 'limit' => 6, + 'full_view' => false, + 'pagination' => false, +); +$content = elgg_list_entities($options); +elgg_pop_context(); + +if (!$content) { + $content = '<p>' . elgg_echo('bookmarks:none') . '</p>'; +} + +$new_link = elgg_view('output/url', array( + 'href' => "bookmarks/add/$group->guid", + 'text' => elgg_echo('bookmarks:add'), + 'is_trusted' => true, +)); + +echo elgg_view('groups/profile/module', array( + 'title' => elgg_echo('bookmarks:group'), + 'content' => $content, + 'all_link' => $all_link, + 'add_link' => $new_link, +)); diff --git a/mod/bookmarks/views/default/bookmarks/js.php b/mod/bookmarks/views/default/bookmarks/js.php new file mode 100644 index 000000000..c36823c09 --- /dev/null +++ b/mod/bookmarks/views/default/bookmarks/js.php @@ -0,0 +1,12 @@ + +elgg.provide('elgg.bookmarks'); + +elgg.bookmarks.init = function() { + // append the title to the url + var title = document.title; + var e = $('a.elgg-bookmark-page'); + var link = e.attr('href') + '&title=' + encodeURIComponent(title); + e.attr('href', link); +}; + +elgg.register_hook_handler('init', 'system', elgg.bookmarks.init); diff --git a/mod/bookmarks/views/default/bookmarks/sidebar.php b/mod/bookmarks/views/default/bookmarks/sidebar.php new file mode 100644 index 000000000..811284ef3 --- /dev/null +++ b/mod/bookmarks/views/default/bookmarks/sidebar.php @@ -0,0 +1,14 @@ +<?php +/** + * Bookmarks sidebar + */ + +echo elgg_view('page/elements/comments_block', array( + 'subtypes' => 'bookmarks', + 'owner_guid' => elgg_get_page_owner_guid(), +)); + +echo elgg_view('page/elements/tagcloud_block', array( + 'subtypes' => 'bookmarks', + 'owner_guid' => elgg_get_page_owner_guid(), +)); diff --git a/mod/bookmarks/views/default/forms/bookmarks/save.php b/mod/bookmarks/views/default/forms/bookmarks/save.php new file mode 100644 index 000000000..7d064a55b --- /dev/null +++ b/mod/bookmarks/views/default/forms/bookmarks/save.php @@ -0,0 +1,59 @@ +<?php +/** + * Edit / add a bookmark + * + * @package Bookmarks + */ + +// once elgg_view stops throwing all sorts of junk into $vars, we can use extract() +$title = elgg_extract('title', $vars, ''); +$desc = elgg_extract('description', $vars, ''); +$address = elgg_extract('address', $vars, ''); +$tags = elgg_extract('tags', $vars, ''); +$access_id = elgg_extract('access_id', $vars, ACCESS_DEFAULT); +$container_guid = elgg_extract('container_guid', $vars); +$guid = elgg_extract('guid', $vars, null); +$shares = elgg_extract('shares', $vars, array()); + +?> +<div> + <label><?php echo elgg_echo('title'); ?></label><br /> + <?php echo elgg_view('input/text', array('name' => 'title', 'value' => $title)); ?> +</div> +<div> + <label><?php echo elgg_echo('bookmarks:address'); ?></label><br /> + <?php echo elgg_view('input/text', array('name' => 'address', 'value' => $address)); ?> +</div> +<div> + <label><?php echo elgg_echo('description'); ?></label> + <?php echo elgg_view('input/longtext', array('name' => 'description', 'value' => $desc)); ?> +</div> +<div> + <label><?php echo elgg_echo('tags'); ?></label> + <?php echo elgg_view('input/tags', array('name' => 'tags', 'value' => $tags)); ?> +</div> +<?php + +$categories = elgg_view('input/categories', $vars); +if ($categories) { + echo $categories; +} + +?> +<div> + <label><?php echo elgg_echo('access'); ?></label><br /> + <?php echo elgg_view('input/access', array('name' => 'access_id', 'value' => $access_id)); ?> +</div> +<div class="elgg-foot"> +<?php + +echo elgg_view('input/hidden', array('name' => 'container_guid', 'value' => $container_guid)); + +if ($guid) { + echo elgg_view('input/hidden', array('name' => 'guid', 'value' => $guid)); +} + +echo elgg_view('input/submit', array('value' => elgg_echo("save"))); + +?> +</div>
\ No newline at end of file diff --git a/mod/bookmarks/views/default/object/bookmarks.php b/mod/bookmarks/views/default/object/bookmarks.php new file mode 100644 index 000000000..83bae2b13 --- /dev/null +++ b/mod/bookmarks/views/default/object/bookmarks.php @@ -0,0 +1,127 @@ +<?php +/** + * Elgg bookmark view + * + * @package ElggBookmarks + */ + +$full = elgg_extract('full_view', $vars, FALSE); +$bookmark = elgg_extract('entity', $vars, FALSE); + +if (!$bookmark) { + return; +} + +$owner = $bookmark->getOwnerEntity(); +$owner_icon = elgg_view_entity_icon($owner, 'tiny'); +$container = $bookmark->getContainerEntity(); +$categories = elgg_view('output/categories', $vars); + +$link = elgg_view('output/url', array('href' => $bookmark->address)); +$description = elgg_view('output/longtext', array('value' => $bookmark->description, 'class' => 'pbl')); + +$owner_link = elgg_view('output/url', array( + 'href' => "bookmarks/owner/$owner->username", + 'text' => $owner->name, + 'is_trusted' => true, +)); +$author_text = elgg_echo('byline', array($owner_link)); + +$date = elgg_view_friendly_time($bookmark->time_created); + +$comments_count = $bookmark->countComments(); +//only display if there are commments +if ($comments_count != 0) { + $text = elgg_echo("comments") . " ($comments_count)"; + $comments_link = elgg_view('output/url', array( + 'href' => $bookmark->getURL() . '#comments', + 'text' => $text, + 'is_trusted' => true, + )); +} else { + $comments_link = ''; +} + +$metadata = elgg_view_menu('entity', array( + 'entity' => $vars['entity'], + 'handler' => 'bookmarks', + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz', +)); + +$subtitle = "$author_text $date $comments_link $categories"; + +// do not show the metadata and controls in widget view +if (elgg_in_context('widgets')) { + $metadata = ''; +} + +if ($full && !elgg_in_context('gallery')) { + + $params = array( + 'entity' => $bookmark, + 'title' => false, + 'metadata' => $metadata, + 'subtitle' => $subtitle, + ); + $params = $params + $vars; + $summary = elgg_view('object/elements/summary', $params); + + $bookmark_icon = elgg_view_icon('push-pin-alt'); + $body = <<<HTML +<div class="bookmark elgg-content mts"> + $bookmark_icon<span class="elgg-heading-basic mbs">$link</span> + $description +</div> +HTML; + + echo elgg_view('object/elements/full', array( + 'entity' => $bookmark, + 'icon' => $owner_icon, + 'summary' => $summary, + 'body' => $body, + )); + +} elseif (elgg_in_context('gallery')) { + echo <<<HTML +<div class="bookmarks-gallery-item"> + <h3>$bookmark->title</h3> + <p class='subtitle'>$owner_link $date</p> +</div> +HTML; +} else { + // brief view + $url = $bookmark->address; + $display_text = $url; + $excerpt = elgg_get_excerpt($bookmark->description); + if ($excerpt) { + $excerpt = " - $excerpt"; + } + + if (strlen($url) > 25) { + $bits = parse_url($url); + if (isset($bits['host'])) { + $display_text = $bits['host']; + } else { + $display_text = elgg_get_excerpt($url, 100); + } + } + + $link = elgg_view('output/url', array( + 'href' => $bookmark->address, + 'text' => $display_text, + )); + + $content = elgg_view_icon('push-pin-alt') . "$link{$excerpt}"; + + $params = array( + 'entity' => $bookmark, + 'metadata' => $metadata, + 'subtitle' => $subtitle, + 'content' => $content, + ); + $params = $params + $vars; + $body = elgg_view('object/elements/summary', $params); + + echo elgg_view_image_block($owner_icon, $body); +} diff --git a/mod/bookmarks/views/default/river/object/bookmarks/create.php b/mod/bookmarks/views/default/river/object/bookmarks/create.php new file mode 100644 index 000000000..388f54ac9 --- /dev/null +++ b/mod/bookmarks/views/default/river/object/bookmarks/create.php @@ -0,0 +1,15 @@ +<?php +/** + * New bookmarks river entry + * + * @package Bookmarks + */ + +$object = $vars['item']->getObjectEntity(); +$excerpt = elgg_get_excerpt($object->description); + +echo elgg_view('river/elements/layout', array( + 'item' => $vars['item'], + 'message' => $excerpt, + 'attachments' => elgg_view('output/url', array('href' => $object->address)), +)); diff --git a/mod/bookmarks/views/default/widgets/bookmarks/content.php b/mod/bookmarks/views/default/widgets/bookmarks/content.php new file mode 100644 index 000000000..0b85017fc --- /dev/null +++ b/mod/bookmarks/views/default/widgets/bookmarks/content.php @@ -0,0 +1,32 @@ +<?php +/** + * Elgg bookmarks widget + * + * @package Bookmarks + */ + +$max = (int) $vars['entity']->num_display; + +$options = array( + 'type' => 'object', + 'subtype' => 'bookmarks', + 'container_guid' => $vars['entity']->owner_guid, + 'limit' => $max, + 'full_view' => FALSE, + 'pagination' => FALSE, +); +$content = elgg_list_entities($options); + +echo $content; + +if ($content) { + $url = "bookmarks/owner/" . elgg_get_page_owner_entity()->username; + $more_link = elgg_view('output/url', array( + 'href' => $url, + 'text' => elgg_echo('bookmarks:more'), + 'is_trusted' => true, + )); + echo "<span class=\"elgg-widget-more\">$more_link</span>"; +} else { + echo elgg_echo('bookmarks:none'); +} diff --git a/mod/bookmarks/views/default/widgets/bookmarks/edit.php b/mod/bookmarks/views/default/widgets/bookmarks/edit.php new file mode 100644 index 000000000..ed9c7fd88 --- /dev/null +++ b/mod/bookmarks/views/default/widgets/bookmarks/edit.php @@ -0,0 +1,24 @@ +<?php +/** + * Elgg bookmark widget edit view + * + * @package Bookmarks + */ + +// set default value +if (!isset($vars['entity']->num_display)) { + $vars['entity']->num_display = 4; +} + +$params = array( + 'name' => 'params[num_display]', + 'value' => $vars['entity']->num_display, + 'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), +); +$dropdown = elgg_view('input/dropdown', $params); + +?> +<div> + <?php echo elgg_echo('bookmarks:numbertodisplay'); ?>: + <?php echo $dropdown; ?> +</div> diff --git a/mod/bookmarks/views/rss/object/bookmarks.php b/mod/bookmarks/views/rss/object/bookmarks.php new file mode 100644 index 000000000..1abda4710 --- /dev/null +++ b/mod/bookmarks/views/rss/object/bookmarks.php @@ -0,0 +1,37 @@ +<?php +/** + * Bookmark RSS object view + * + * @package ElggBookmarks + */ + +$title = $vars['entity']->title; +if (empty($title)) { + $title = strip_tags($vars['entity']->description); + $title = elgg_get_excerpt($title, 32); +} + +$permalink = htmlspecialchars($vars['entity']->getURL(), ENT_NOQUOTES, 'UTF-8'); +$pubdate = date('r', $vars['entity']->getTimeCreated()); + +$url_text = elgg_echo('bookmarks:address'); +$link = elgg_view('output/url', array('href' => $vars['entity']->address)); +$description = $vars['entity']->description . "<p>$url_text: $link</p>"; + +$creator = elgg_view('page/components/creator', $vars); +$georss = elgg_view('page/components/georss', $vars); +$extension = elgg_view('extensions/item'); + +$item = <<<__HTML +<item> + <guid isPermaLink="true">$permalink</guid> + <pubDate>$pubdate</pubDate> + <link>$permalink</link> + <title><![CDATA[$title]]></title> + <description><![CDATA[$description]]></description> + $creator$georss$extension +</item> + +__HTML; + +echo $item; |