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.php500
1 files changed, 236 insertions, 264 deletions
diff --git a/mod/bookmarks/start.php b/mod/bookmarks/start.php
index de7a95e8f..caea43587 100644
--- a/mod/bookmarks/start.php
+++ b/mod/bookmarks/start.php
@@ -3,253 +3,206 @@
* Elgg Bookmarks plugin
*
* @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/
*/
-// Bookmarks initialisation function
+elgg_register_event_handler('init', 'system', 'bookmarks_init');
+
+/**
+ * Bookmark init
+ */
function bookmarks_init() {
- // Grab the config global
- global $CONFIG;
- //add a tools menu option
- add_menu(elgg_echo('bookmarks'), $CONFIG->wwwroot . 'pg/bookmarks');
+ $root = dirname(__FILE__);
+ elgg_register_library('elgg:bookmarks', "$root/lib/bookmarks.php");
- // Register a page handler, so we can have nice URLs
- register_page_handler('bookmarks', 'bookmarks_page_handler');
+ // 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");
- // Add our CSS
- elgg_extend_view('css', 'bookmarks/css');
+ // menus
+ elgg_register_menu_item('site', array(
+ 'name' => 'bookmarks',
+ 'text' => elgg_echo('bookmarks'),
+ 'href' => 'bookmarks/all'
+ ));
- // Register granular notification for this type
- if (is_callable('register_notification_object')) {
- register_notification_object('object', 'bookmarks', elgg_echo('bookmarks:new'));
- }
+ elgg_register_plugin_hook_handler('register', 'menu:page', 'bookmarks_page_menu');
+ elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'bookmarks_owner_block_menu');
- // Listen to notification events and supply a more useful message
- register_plugin_hook('notify:entity:message', 'object', 'bookmarks_notify_message');
+ elgg_register_page_handler('bookmarks', 'bookmarks_page_handler');
- // Register a URL handler for shared items
- register_entity_url_handler('bookmark_url','object','bookmarks');
+ elgg_extend_view('css/elgg', 'bookmarks/css');
+ elgg_extend_view('js/elgg', 'bookmarks/js');
- // Shares widget
- add_widget_type('bookmarks',elgg_echo("bookmarks"),elgg_echo("bookmarks:widget:description"));
+ elgg_register_widget_type('bookmarks', elgg_echo('bookmarks'), elgg_echo('bookmarks:widget:description'));
- // Register entity type
- register_entity_type('object','bookmarks');
+ if (elgg_is_logged_in()) {
+ $user_guid = elgg_get_logged_in_user_guid();
+ $address = urlencode(current_page_url());
- // Add group menu option
- add_group_tool_option('bookmarks',elgg_echo('bookmarks:enablebookmarks'),true);
+ 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'));
- // Extend Groups profile page
- elgg_extend_view('groups/tool_latest','bookmarks/group_bookmarks');
+ // Listen to notification events and supply a more useful message
+ elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'bookmarks_notify_message');
- // Register profile menu hook
- register_plugin_hook('profile_menu', 'profile', 'bookmarks_profile_menu');
-}
+ // Register bookmarks view for ecml parsing
+ elgg_register_plugin_hook_handler('get_views', 'ecml', 'bookmarks_ecml_views_hook');
-/**
- * Sidebar menu for bookmarks
- *
- */
-function bookmarks_pagesetup() {
- global $CONFIG;
+ // Register a URL handler for bookmarks
+ elgg_register_entity_url_handler('object', 'bookmarks', 'bookmark_url');
- $page_owner = page_owner_entity();
+ // Register entity type for search
+ elgg_register_entity_type('object', 'bookmarks');
- // Add group bookmark menu item
- if (isloggedin()) {
- 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/" . $page_owner->username . '/items');
- }
- }
- }
+ // Groups
+ add_group_tool_option('bookmarks', elgg_echo('bookmarks:enablebookmarks'), true);
+ elgg_extend_view('groups/tool_latest', 'bookmarks/group_module');
}
/**
- * Bookmarks page handler
- * Expects URLs like:
- * pg/bookmarks/username/[friends||items||add||edit||bookmarklet]
+ * 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 From the page_handler function
- * @return true|false Depending on success
+ * @param array $page
+ * @return bool
*/
function bookmarks_page_handler($page) {
- global $CONFIG;
-
- // The first component of a bookmarks URL is the username
- // If the username is set_input()'d and has group:NN in it, magic happens
- // and the page_owner_entity() is the group.
- if (isset($page[0])) {
- $owner_name = $page[0];
- set_input('username', $owner_name);
- // grab the page owner here so the group magic works.
- $owner = page_owner_entity();
- } else {
- set_page_owner(get_loggedin_userid());
- }
-
- // owner name passed but invalid.
- if ($owner_name && !$owner) {
- $sidebar = elgg_view('bookmarks/sidebar', array('object_type' => 'bookmarks'));
- $content = elgg_echo("bookmarks:unknown_user");
+ elgg_load_library('elgg:bookmarks');
- $body = elgg_view_layout('one_column_with_sidebar', $content, $sidebar);
- echo page_draw(sprintf(elgg_echo("bookmarks:user"), page_owner_entity()->name), $body);
-
- return FALSE;
+ if (!isset($page[0])) {
+ $page[0] = 'all';
}
- $logged_in_user = get_loggedin_user();
- $section = (isset($page[1])) ? $page[1] : $section = 'items';
-
- //don't show the all site bookmarks breadcrumb when on the all site bookmarks page
- if(page_owner() != 0){
- elgg_push_breadcrumb(elgg_echo('bookmarks:all'), $CONFIG->wwwroot . 'pg/bookmarks/');
- }
-
- if ($owner) {
- switch($section) {
- case 'friends':
- elgg_push_breadcrumb(sprintf(elgg_echo('bookmarks:friends'), $owner->name));
-
- $content = list_user_friends_objects($owner->getGUID(), 'bookmarks', 10, false, false);
- $context = ($owner == $logged_in_user) ? 'friends' : '';
- break;
-
- default:
- case 'items':
- elgg_push_breadcrumb(sprintf(elgg_echo('bookmarks:user'), $owner->name));
-
- group_gatekeeper();
- $options = array(
- 'type' => 'object',
- 'subtype' => 'bookmarks'
- );
-
- if ($owner instanceof ElggGroup) {
- $options['container_guid'] = $owner->getGUID();
- } else {
- $options['owner_guid'] = $owner->getGUID();
- }
-
- $content = elgg_list_entities($options);
-
- if (!$content && ($owner == $logged_in_user)) {
- $content = elgg_view('help/bookmarks');
- }
-
- $context = ($owner == $logged_in_user) ? 'mine' : '';
- break;
-
- case 'add':
- gatekeeper();
- elgg_push_breadcrumb(elgg_echo('bookmarks:add'));
-
- $vars = array();
- if ($owner instanceof ElggGroup) {
- $vars['container_guid'] = $owner->getGUID();
- }
-
- $context = 'action';
- $content = elgg_view('bookmarks/form', $vars);
- break;
-
- case 'edit':
- gatekeeper();
+ elgg_push_breadcrumb(elgg_echo('bookmarks'), 'bookmarks/all');
- elgg_push_breadcrumb(elgg_echo('bookmarks:edit'));
-
- $vars = array();
- // this will never be the case.
- if ($owner instanceof ElggGroup) {
- $vars['container_guid'] = $owner->getGUID();
- }
-
- $bookmark = (isset($page[2])) ? get_entity($page[2]) : FALSE;
-
- if ($bookmark && elgg_instanceof($bookmark, 'object', 'bookmarks') && $bookmark->canEdit()) {
- $vars['entity'] = $bookmark;
- $context = 'action';
- $content = elgg_view('bookmarks/form', $vars);
- } else {
- $content = elgg_echo('bookmarks:cannot_find_bookmark');
- }
-
- break;
-
- // I don't think this is used.
- case 'bookmarklet':
- gatekeeper();
-
- $content = elgg_view_title(elgg_echo('bookmarks:bookmarklet'));
- $content .= elgg_view('bookmarks/bookmarklet');
-
- break;
+ // 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);
}
+ }
- } else {
- // no owner name passed, show everything.
- $content = elgg_list_entities(array('type' => 'object', 'subtype' => 'bookmarks'));
- $context = 'everyone';
+ // user usernames
+ $user = get_user_by_username($page[0]);
+ if ($user) {
+ bookmarks_url_forwarder($page);
}
- // sidebar
- if ($logged_in_user != $owner) {
- $area3 = elgg_view('bookmarks/ownerblock');
+ $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;
}
- $sidebar = elgg_view('bookmarks/sidebar', array('object_type' => 'bookmarks'));
+ elgg_pop_context();
+ return true;
+}
- if (isloggedin()){
- $sidebar .= elgg_view('bookmarks/bookmarklet');
- }
+/**
+ * Forward to the new style of URLs
+ *
+ * @param string $page
+ */
+function bookmarks_url_forwarder($page) {
+ global $CONFIG;
- // main content
- //if ($owner != $logged_in_user || $context == 'action') {
- $header = elgg_view('navigation/breadcrumbs');
- //}
- //if no user is set
- if(!$owner_name){
- $owner_name = get_loggedin_user()->username;
+ if (!isset($page[1])) {
+ $page[1] = 'items';
}
- //select the header depending on whether a user is looking at their bookmarks or someone elses
- if($owner){
- if ($owner != $logged_in_user && !($owner instanceof ElggGroup)) {
- $header .= elgg_view("page_elements/content_header_member", array(
- 'type' => 'bookmarks'
- ));
- }else{
- $header .= elgg_view("page_elements/content_header", array(
- 'context' => $context,
- 'type' => 'bookmarks',
- 'all_link' => "{$CONFIG->url}pg/bookmarks/",
- 'new_link' => "{$CONFIG->url}pg/bookmarks/{$owner_name}/add"
- ));
- }
- }else{
- $header .= elgg_view("page_elements/content_header", array(
- 'context' => $context,
- 'type' => 'bookmarks',
- 'all_link' => "{$CONFIG->url}pg/bookmarks/",
- 'new_link' => "{$CONFIG->url}pg/bookmarks/{$owner_name}/add"
- ));
+ 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;
}
- $content = $header . $content;
- $body = elgg_view_layout('one_column_with_sidebar', $content, $sidebar);
- echo page_draw(sprintf(elgg_echo("bookmarks:user"), page_owner_entity()->name), $body);
-
- return TRUE;
+ register_error(elgg_echo("changebookmark"));
+ forward($url);
}
-
/**
* Populates the ->getUrl() method for bookmarked objects
*
@@ -257,21 +210,44 @@ function bookmarks_page_handler($page) {
* @return string bookmarked item URL
*/
function bookmark_url($entity) {
-
global $CONFIG;
+
$title = $entity->title;
- $title = friendly_title($title);
- return $CONFIG->url . "pg/bookmarks/" . $entity->getOwnerEntity()->username . "/read/" . $entity->getGUID() . "/" . $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 a more meaningful message
+ * Returns the body of a notification message
*
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
+ * @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'];
@@ -280,65 +256,61 @@ function bookmarks_notify_message($hook, $entity_type, $returnvalue, $params) {
if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'bookmarks')) {
$descr = $entity->description;
$title = $entity->title;
- global $CONFIG;
- $url = $CONFIG->wwwroot . "pg/view/" . $entity->guid;
- if ($method == 'sms') {
- $owner = $entity->getOwnerEntity();
- return $owner->name . ' ' . elgg_echo("bookmarks:via") . ': ' . $url . ' (' . $title . ')';
- }
- if ($method == 'email') {
- $owner = $entity->getOwnerEntity();
- return $owner->name . ' ' . elgg_echo("bookmarks:via") . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
- }
- if ($method == 'web') {
- $owner = $entity->getOwnerEntity();
- return $owner->name . ' ' . elgg_echo("bookmarks:via") . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
- }
-
+ $owner = $entity->getOwnerEntity();
+
+ return elgg_echo('bookmarks:notification', array(
+ $owner->name,
+ $title,
+ $entity->address,
+ $descr,
+ $entity->getURL()
+ ));
}
return null;
}
/**
- * A function to generate an internal code to put on the wire in place of the full url
- * to save space.
- **/
-
-function create_wire_url_code(){
- $chars = "abcdefghijkmnopqrstuvwxyz023456789";
- srand((double)microtime()*1000000);
- $i = 0;
- $code = '';
-
- while ($i <= 4) {
- $num = rand() % 33;
- $tmp = substr($chars, $num, 1);
- $code = $code . $tmp;
- $i++;
- }
- $code = "{{L:" . $code . "}}";
- return $code;
-}
+ * 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();
+ }
-function bookmarks_profile_menu($hook, $entity_type, $return_value, $params) {
- global $CONFIG;
+ if ($page_owner instanceof ElggGroup) {
+ if (!$page_owner->isMember()) {
+ return $return;
+ }
+ $title = elgg_echo('bookmarks:bookmarklet:group');
+ } else {
+ $title = elgg_echo('bookmarks:bookmarklet');
+ }
- $return_value[] = array(
- 'text' => elgg_echo('bookmarks'),
- 'href' => "{$CONFIG->url}pg/bookmarks/{$params['owner']->username}",
- );
+ $return[] = new ElggMenuItem('bookmarklet', $title, 'bookmarks/bookmarklet/' . $page_owner->getGUID());
+ }
+ }
- return $return_value;
+ return $return;
}
-// Make sure the initialisation function is called on initialisation
-register_elgg_event_handler('init','system','bookmarks_init');
-register_elgg_event_handler('pagesetup','system','bookmarks_pagesetup');
-
-// Register actions
-global $CONFIG;
-register_action('bookmarks/add',false,$CONFIG->pluginspath . "bookmarks/actions/add.php");
-register_action('bookmarks/edit',false,$CONFIG->pluginspath . "bookmarks/actions/edit.php");
-register_action('bookmarks/delete',false,$CONFIG->pluginspath . "bookmarks/actions/delete.php");
-register_action('bookmarks/reference',false,$CONFIG->pluginspath . "bookmarks/actions/reference.php");
-register_action('bookmarks/remove',false,$CONFIG->pluginspath . "bookmarks/actions/remove.php");
+/**
+ * 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;
+}