aboutsummaryrefslogtreecommitdiff
path: root/mod/bookmarks/start.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/bookmarks/start.php')
-rw-r--r--mod/bookmarks/start.php156
1 files changed, 73 insertions, 83 deletions
diff --git a/mod/bookmarks/start.php b/mod/bookmarks/start.php
index a4cba4805..90dd89f18 100644
--- a/mod/bookmarks/start.php
+++ b/mod/bookmarks/start.php
@@ -6,7 +6,6 @@
*/
elgg_register_event_handler('init', 'system', 'bookmarks_init');
-elgg_register_event_handler('pagesetup', 'system', 'bookmarks_pagesetup');
/**
* Bookmark init
@@ -15,22 +14,26 @@ function bookmarks_init() {
global $CONFIG;
$root = dirname(__FILE__);
-
elgg_register_library('elgg:bookmarks', "$root/lib/bookmarks.php");
- $action_path = "$root/actions/bookmarks";
+ // actions
+ $action_path = "$root/actions/bookmarks";
elgg_register_action('bookmarks/save', "$action_path/save.php", 'logged_in');
elgg_register_action('bookmarks/delete', "$action_path/delete.php", 'logged_in');
elgg_register_action('bookmarks/share', "$action_path/share.php", 'logged_in');
- //add a tools menu option
- $item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks'), 'pg/bookmarks/all');
- elgg_register_menu_item('site', $item);
+ // menus
+ elgg_register_menu_item('site', array(
+ 'name' => 'bookmarks',
+ 'title' => elgg_echo('bookmarks'),
+ 'url' => 'pg/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_plugin_hook_handler('register', 'menu:user_hover', 'bookmarks_user_hover_menu');
- // Register a page handler, so we can have nice URLs
- elgg_register_page_handler('bookmarks', 'bookmarks_page_handler');
- // Add our CSS
+ elgg_register_page_handler('bookmarks', 'bookmarks_page_handler');
elgg_extend_view('css/screen', 'bookmarks/css');
// Register granular notification for this type
@@ -41,79 +44,15 @@ function bookmarks_init() {
// Listen to notification events and supply a more useful message
elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'bookmarks_notify_message');
- // Register a URL handler for shared items
+ // Register a URL handler for bookmarks
elgg_register_entity_url_handler('object','bookmarks', 'bookmark_url');
- // Shares widget
- elgg_register_widget_type('bookmarks',elgg_echo("bookmarks"),elgg_echo("bookmarks:widget:description"));
-
- // Register entity type
- elgg_register_entity_type('object','bookmarks');
-
- // Add group menu option
- add_group_tool_option('bookmarks',elgg_echo('bookmarks:enablebookmarks'),true);
-
- elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'bookmarks_owner_block_menu');
-
- // Extend Groups profile page
- elgg_extend_view('groups/tool_latest','bookmarks/group_bookmarks');
-
- // Register profile menu hook
- elgg_register_plugin_hook_handler('profile_menu', 'profile', 'bookmarks_profile_menu');
-}
-
-/**
- * Sidebar menu for bookmarks
- *
- */
-function bookmarks_pagesetup() {
- global $CONFIG;
-
- $page_owner = page_owner_entity();
-
- //add submenu options
- if (get_context() == "bookmarks") {
-
- if (elgg_is_logged_in()) {
- // link to add bookmark form
- if ($page_owner instanceof ElggGroup) {
- if ($page_owner->isMember(elgg_get_logged_in_user_entity())) {
- add_submenu_item(elgg_echo('bookmarks:add'), $CONFIG->wwwroot."pg/bookmarks/add/" . $page_owner->username);
- }
- } else {
- add_submenu_item(elgg_echo('bookmarks:add'), $CONFIG->wwwroot."pg/bookmarks/add/" . $_SESSION['user']->username);
- add_submenu_item(elgg_echo('bookmarks:inbox'),$CONFIG->wwwroot."pg/bookmarks/inbox/" . $_SESSION['user']->username);
- }
- if (page_owner()) {
- add_submenu_item(sprintf(elgg_echo('bookmarks:read'), $page_owner->name),$CONFIG->wwwroot."pg/bookmarks/owner/" . $page_owner->username);
- }
- if (!$page_owner instanceof ElggGroup) {
- add_submenu_item(elgg_echo('bookmarks:friends'),$CONFIG->wwwroot."pg/bookmarks/friends/" . $_SESSION['user']->username);
- }
- }
-
- if (!$page_owner instanceof ElggGroup) {
- add_submenu_item(elgg_echo('bookmarks:everyone'),$CONFIG->wwwroot."pg/bookmarks/all/");
- }
-
- // Bookmarklet
- if ((elgg_is_logged_in()) && (page_owner()) && (can_write_to_container(0, page_owner()))) {
-
- $bmtext = elgg_echo('bookmarks:bookmarklet');
- if ($page_owner instanceof ElggGroup) {
- $bmtext = elgg_echo('bookmarks:bookmarklet:group');
- }
- add_submenu_item($bmtext, $CONFIG->wwwroot . "pg/bookmarks/bookmarklet/{$page_owner->username}/");
- }
-
- }
-
- if ($page_owner instanceof ElggGroup && get_context() == 'groups') {
- if ($page_owner->bookmarks_enable != "no") {
- add_submenu_item(sprintf(elgg_echo("bookmarks:group"),$page_owner->name), $CONFIG->wwwroot . "pg/bookmarks/owner/" . $page_owner->username);
- }
- }
+ // 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_bookmarks');
}
/**
@@ -137,6 +76,7 @@ function bookmarks_page_handler($page) {
elgg_load_library('elgg:bookmarks');
elgg_push_breadcrumb(elgg_echo('bookmarks'), 'pg/bookmarks/all');
+ elgg_push_context('bookmarks');
// old group usernames
if (substr_count($page[0], 'group:')) {
@@ -187,7 +127,7 @@ function bookmarks_page_handler($page) {
break;
case "bookmarklet":
- set_input('username', $page[1]);
+ set_input('container_guid', $page[1]);
include "$pages/bookmarklet.php";
break;
@@ -195,6 +135,8 @@ function bookmarks_page_handler($page) {
return false;
}
+ elgg_pop_context();
+
return true;
}
@@ -254,12 +196,12 @@ function bookmark_url($entity) {
*/
function bookmarks_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
- $url = "pg/bookmarks/owner/{$params['user']->username}";
+ $url = "pg/bookmarks/owner/{$params['entity']->username}";
$item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks'), $url);
$return[] = $item;
} else {
- if ($params['entity']->bookmarks_enable != "no") {
- $url = "pg/bookmarks/owner/{$params['entity']->username}";
+ if ($params['entity']->bookmarks_enable != 'no') {
+ $url = "pg/bookmarks/group/{$params['entity']->guid}/owner";
$item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks:group'), $url);
$return[] = $item;
}
@@ -300,4 +242,52 @@ function bookmarks_notify_message($hook, $entity_type, $returnvalue, $params) {
}
return null;
+}
+
+/**
+ * Add a user hover menu.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $return
+ * @param unknown_type $params
+ */
+function bookmarks_user_hover_menu($hook, $type, $return, $params) {
+ $user = $params['entity'];
+
+ $title = elgg_echo('bookmarks');
+ $url = "pg/bookmarks/owner/$user->username";
+ $return[] = new ElggMenuItem('bookmarks', $title, $url);
+
+ return $return;
+}
+
+/**
+ * Add a page menu menu.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $return
+ * @param unknown_type $params
+ */
+function bookmarks_page_menu($hook, $type, $return, $params) {
+ if (elgg_is_logged_in()) {
+ $url = 'pg/bookmarks/add/' . elgg_get_logged_in_user_guid()
+ . '?address=' . urlencode(current_page_url());
+ $return[] = new ElggMenuItem('bookmark_this_page', elgg_echo('bookmarks:this'), $url);
+
+ // only show bookmarklet in bookmark pages
+ if (elgg_in_context('bookmarks')) {
+ $page_owner = elgg_get_page_owner_entity();
+ if ($page_owner instanceof ElggGroup) {
+ $title = elgg_echo('bookmarks:bookmarklet:group');
+ } else {
+ $title = elgg_echo('bookmarks:bookmarklet');
+ }
+
+ $return[] = new ElggMenuItem('bookmarklet', $title, 'pg/bookmarks/bookmarklet/' . $page_owner->getGUID());
+ }
+ }
+
+ return $return;
} \ No newline at end of file