From 388080a1ada96423816e62b86196f7bee3e7afa4 Mon Sep 17 00:00:00 2001 From: Sem Date: Mon, 5 Nov 2012 09:09:34 +0100 Subject: Fixes #4904. Elgg 1.7 group blog RSS links forward correctly now. --- mod/blog/lib/blog.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mod/blog') diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 4622a9e7e..34ea5a01c 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -403,12 +403,12 @@ function blog_url_forwarder($page) { global $CONFIG; // group usernames - if (substr_count($page[0], 'group:')) { - preg_match('/group\:([0-9]+)/i', $page[0], $matches); + if (substr_count($page[1], 'group:')) { + preg_match('/group\:([0-9]+)/i', $page[1], $matches); $guid = $matches[1]; $entity = get_entity($guid); if ($entity) { - $url = "{$CONFIG->wwwroot}blog/group/$guid/all"; + $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); register_error(elgg_echo("changebookmark")); forward($url); } -- cgit v1.2.3 From 45480715e699ed61cd2b70242c323de99d7325c5 Mon Sep 17 00:00:00 2001 From: Sem Date: Tue, 6 Nov 2012 05:44:26 +0100 Subject: Refs #4904. Forwarding pre and post-1.7.5 blog urls. --- mod/blog/lib/blog.php | 18 +++++++++++++++--- mod/blog/start.php | 3 +-- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'mod/blog') diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 34ea5a01c..1ccfe4dc4 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -396,6 +396,14 @@ function blog_prepare_form_vars($post = NULL, $revision = NULL) { /** * Forward to the new style of URLs + * + * Pre-1.7.5 + * Group blogs page: /blog/group:/ + * Group blog view: /blog/group:/read// + * 1.7.5-1.8 + * Group blogs page: /blog/owner/group:<container_guid>/ + * Group blog view: /blog/read/<guid> + * * * @param string $page */ @@ -403,12 +411,16 @@ function blog_url_forwarder($page) { global $CONFIG; // group usernames - if (substr_count($page[1], 'group:')) { - preg_match('/group\:([0-9]+)/i', $page[1], $matches); + if (substr_count("$page[0]/$page[1]", 'group:')) { + preg_match('/group\:([0-9]+)/i', "$page[0]/$page[1]", $matches); $guid = $matches[1]; $entity = get_entity($guid); if ($entity) { - $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); + if (isset($page[2])) { + $url = "{$CONFIG->wwwroot}blog/view/$page[2]/?view=" . elgg_get_viewtype(); + } else { + $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); + } register_error(elgg_echo("changebookmark")); forward($url); } diff --git a/mod/blog/start.php b/mod/blog/start.php index 9faf1794e..8cbaf5cca 100644 --- a/mod/blog/start.php +++ b/mod/blog/start.php @@ -99,8 +99,7 @@ function blog_page_handler($page) { elgg_load_library('elgg:blog'); - // @todo remove the forwarder in 1.9 - // forward to correct URL for blog pages pre-1.7.5 + // forward to correct URL for blog pages pre-1.8 blog_url_forwarder($page); // push all blogs breadcrumb -- cgit v1.2.3 From 4f01b88b9fc1fe476189d53df7a34303502ba17e Mon Sep 17 00:00:00 2001 From: Sem <sembrestels@riseup.net> Date: Thu, 15 Nov 2012 01:16:42 +0100 Subject: Refs #4904. Checking if page has segments before using them. --- mod/blog/lib/blog.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mod/blog') diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 1ccfe4dc4..4dcc7d56e 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -411,8 +411,8 @@ function blog_url_forwarder($page) { global $CONFIG; // group usernames - if (substr_count("$page[0]/$page[1]", 'group:')) { - preg_match('/group\:([0-9]+)/i', "$page[0]/$page[1]", $matches); + if (substr_count(implode('/', $page), 'group:')) { + preg_match('/group\:([0-9]+)/i', implode('/', $page), $matches); $guid = $matches[1]; $entity = get_entity($guid); if ($entity) { @@ -426,6 +426,10 @@ function blog_url_forwarder($page) { } } + if (!isset($page[0])) { + return; + } + // user usernames $user = get_user_by_username($page[0]); if (!$user) { -- cgit v1.2.3 From 5cce825ba165da9430b514a9c11532968e6c5af8 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 15 Nov 2012 00:56:51 -0500 Subject: Blog forwarder cleanup & viewtype propagation --- mod/blog/lib/blog.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'mod/blog') diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 4dcc7d56e..db6b7846f 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -408,25 +408,31 @@ function blog_prepare_form_vars($post = NULL, $revision = NULL) { * @param string $page */ function blog_url_forwarder($page) { - global $CONFIG; + + $viewtype = elgg_get_viewtype(); + $qs = ($viewtype === 'default') ? "" : "?view=$viewtype"; + + $url = "blog/all"; + + // easier to work with & no notices + $page = array_pad($page, 4, ""); // group usernames - if (substr_count(implode('/', $page), 'group:')) { - preg_match('/group\:([0-9]+)/i', implode('/', $page), $matches); + if (preg_match('~/group\:([0-9]+)/~', "/{$page[0]}/{$page[1]}/", $matches)) { $guid = $matches[1]; $entity = get_entity($guid); - if ($entity) { - if (isset($page[2])) { - $url = "{$CONFIG->wwwroot}blog/view/$page[2]/?view=" . elgg_get_viewtype(); + if (elgg_instanceof($entity, 'group')) { + if (!empty($page[2])) { + $url = "blog/view/$page[2]/"; } else { - $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); + $url = "blog/group/$guid/all"; } register_error(elgg_echo("changebookmark")); - forward($url); + forward($url . $qs); } } - if (!isset($page[0])) { + if (empty($page[0])) { return; } @@ -436,28 +442,28 @@ function blog_url_forwarder($page) { return; } - if (!isset($page[1])) { + if (empty($page[1])) { $page[1] = 'owner'; } switch ($page[1]) { case "read": - $url = "{$CONFIG->wwwroot}blog/view/{$page[2]}/{$page[3]}"; + $url = "blog/view/{$page[2]}/{$page[3]}"; break; case "archive": - $url = "{$CONFIG->wwwroot}blog/archive/{$page[0]}/{$page[2]}/{$page[3]}"; + $url = "blog/archive/{$page[0]}/{$page[2]}/{$page[3]}"; break; case "friends": - $url = "{$CONFIG->wwwroot}blog/friends/{$page[0]}"; + $url = "blog/friends/{$page[0]}"; break; case "new": - $url = "{$CONFIG->wwwroot}blog/add/$user->guid"; + $url = "blog/add/$user->guid"; break; case "owner": - $url = "{$CONFIG->wwwroot}blog/owner/{$page[0]}"; + $url = "blog/owner/{$page[0]}"; break; } register_error(elgg_echo("changebookmark")); - forward($url); + forward($url . $qs); } -- cgit v1.2.3 From 8a1cd5595970f6be4cfd3d8f10509cae8e51f192 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 15 Nov 2012 01:04:58 -0500 Subject: Blog lib cleanup, logic simplification, remove notices & unused code --- mod/blog/lib/blog.php | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'mod/blog') diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index db6b7846f..3c71dfbab 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -50,7 +50,7 @@ function blog_get_page_content_read($guid = NULL) { /** * Get page components to list a user's or all blogs. * - * @param int $owner_guid The GUID of the page owner or NULL for all blogs + * @param int $container_guid The GUID of the page owner or NULL for all blogs * @return array */ function blog_get_page_content_list($container_guid = NULL) { @@ -62,10 +62,11 @@ function blog_get_page_content_list($container_guid = NULL) { $options = array( 'type' => 'object', 'subtype' => 'blog', - 'full_view' => FALSE, + 'full_view' => false, ); - $loggedin_userid = elgg_get_logged_in_user_guid(); + $current_user = elgg_get_logged_in_user_entity(); + if ($container_guid) { // access check for closed groups group_gatekeeper(); @@ -80,7 +81,7 @@ function blog_get_page_content_list($container_guid = NULL) { $crumbs_title = $container->name; elgg_push_breadcrumb($crumbs_title); - if ($container_guid == $loggedin_userid) { + if ($current_user && ($container_guid == $current_user->guid)) { $return['filter_context'] = 'mine'; } else if (elgg_instanceof($container, 'group')) { $return['filter'] = false; @@ -99,7 +100,13 @@ function blog_get_page_content_list($container_guid = NULL) { // show all posts for admin or users looking at their own blogs // show only published posts for other users. - if (!(elgg_is_admin_logged_in() || (elgg_is_logged_in() && $container_guid == $loggedin_userid))) { + $show_only_published = true; + if ($current_user) { + if (($current_user->guid == $container_guid) || $current_user->isAdmin()) { + $show_only_published = false; + } + } + if ($show_only_published) { $options['metadata_name_value_pairs'] = array( array('name' => 'status', 'value' => 'published'), ); @@ -155,11 +162,14 @@ function blog_get_page_content_friends($user_guid) { // admin / owners can see any posts // everyone else can only see published posts - if (!(elgg_is_admin_logged_in() || (elgg_is_logged_in() && $owner_guid == elgg_get_logged_in_user_guid()))) { - if ($upper > $now) { - $upper = $now; + $show_only_published = true; + $current_user = elgg_get_logged_in_user_entity(); + if ($current_user) { + if (($user_guid == $current_user->guid) || $current_user->isAdmin()) { + $show_only_published = false; } - + } + if ($show_only_published) { $options['metadata_name_value_pairs'][] = array( array('name' => 'status', 'value' => 'published') ); @@ -240,9 +250,9 @@ function blog_get_page_content_archive($owner_guid, $lower = 0, $upper = 0) { $list = elgg_list_entities_from_metadata($options); if (!$list) { - $content .= elgg_echo('blog:none'); + $content = elgg_echo('blog:none'); } else { - $content .= $list; + $content = $list; } $title = elgg_echo('date:month:' . date('m', $lower), array(date('Y', $lower))); @@ -274,6 +284,7 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) { $vars['id'] = 'blog-post-edit'; $vars['class'] = 'elgg-form-alt'; + $sidebar = ''; if ($page == 'edit') { $blog = get_entity((int)$guid); @@ -310,14 +321,8 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) { $content = elgg_echo('blog:error:cannot_edit_post'); } } else { - if (!$guid) { - $container = elgg_get_logged_in_user_entity(); - } else { - $container = get_entity($guid); - } - elgg_push_breadcrumb(elgg_echo('blog:add')); - $body_vars = blog_prepare_form_vars($blog); + $body_vars = blog_prepare_form_vars(null); $title = elgg_echo('blog:add'); $content = elgg_view_form('blog/save', $vars, $body_vars); @@ -384,7 +389,7 @@ function blog_prepare_form_vars($post = NULL, $revision = NULL) { if ($auto_save_annotations = $post->getAnnotations('blog_auto_save', 1)) { $auto_save = $auto_save_annotations[0]; } else { - $auto_save == FALSE; + $auto_save = false; } if ($auto_save && $auto_save->id != $revision->id) { -- cgit v1.2.3