aboutsummaryrefslogtreecommitdiff
path: root/mod/blog
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-05 03:02:46 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-05 03:02:46 +0000
commit60c803f7104116b93433e417a197331f78bcb23b (patch)
treec56ae918155ac431b3665070f8ab23258a25b3a2 /mod/blog
parentf6efaba63af8100f7cebcbd9414e04ff4187c6c2 (diff)
downloadelgg-60c803f7104116b93433e417a197331f78bcb23b.tar.gz
elgg-60c803f7104116b93433e417a197331f78bcb23b.tar.bz2
Clean-up of the blog plugin - now using urls from 1.7.5
git-svn-id: http://code.elgg.org/elgg/trunk@7535 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/blog')
-rw-r--r--mod/blog/actions/blog/delete.php2
-rw-r--r--mod/blog/actions/blog/save.php4
-rw-r--r--mod/blog/languages/en.php3
-rw-r--r--mod/blog/lib/blog.php123
-rw-r--r--mod/blog/start.php103
-rw-r--r--mod/blog/views/default/blog/css.php36
-rw-r--r--mod/blog/views/default/blog/forms/edit.php12
-rw-r--r--mod/blog/views/default/blog/sidebar_menu.php4
-rw-r--r--mod/blog/views/default/blog/sidebar_revisions.php6
-rw-r--r--mod/blog/views/default/object/blog.php4
10 files changed, 167 insertions, 130 deletions
diff --git a/mod/blog/actions/blog/delete.php b/mod/blog/actions/blog/delete.php
index d338fd2df..a4606f17f 100644
--- a/mod/blog/actions/blog/delete.php
+++ b/mod/blog/actions/blog/delete.php
@@ -12,7 +12,7 @@ if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
$container = get_entity($blog->container_guid);
if ($blog->delete()) {
system_message(elgg_echo('blog:message:deleted_post'));
- forward("pg/blog/$container->username/read/");
+ forward("pg/blog/owner/$container->username/");
} else {
register_error(elgg_echo('blog:error:cannot_delete_post'));
}
diff --git a/mod/blog/actions/blog/save.php b/mod/blog/actions/blog/save.php
index 448c76037..11d366a44 100644
--- a/mod/blog/actions/blog/save.php
+++ b/mod/blog/actions/blog/save.php
@@ -10,7 +10,7 @@
// store errors to pass along
$error = FALSE;
-$error_forward_url = $_SERVER['HTTP_REFERER'];
+$error_forward_url = REFERER;
$user = get_loggedin_user();
// edit or create a new entity
@@ -22,7 +22,7 @@ if ($guid) {
$blog = $entity;
} else {
register_error(elgg_echo('blog:error:post_not_found'));
- forward(get_input('forward', $_SERVER['HTTP_REFERER']));
+ forward(get_input('forward', REFERER));
}
$success_forward_url = get_input('forward', $blog->getURL());
diff --git a/mod/blog/languages/en.php b/mod/blog/languages/en.php
index 7f3954426..843d62932 100644
--- a/mod/blog/languages/en.php
+++ b/mod/blog/languages/en.php
@@ -43,9 +43,12 @@ $english = array(
'blog:error:post_not_found' => 'This post has been removed or is invalid.',
'blog:messages:warning:draft' => 'There is an unsaved draft of this post!',
'blog:edit_revision_notice' => '(Old version)',
+ 'blog:message:deleted_post' => 'Blog post deleted.',
+ 'blog:error:cannot_delete_post' => 'Cannot delete blog post.',
'blog:none' => 'No blogs found',
'blog:error:missing:title' => 'Please enter a blog title!',
'blog:error:missing:description' => 'Please enter the body of your blog!',
+ 'blog:error:cannot_edit_post' => 'This post may not exist or you may not have permissions to edit it.',
// river
'blog:river:create' => '%s wrote a new blog post',
diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php
index 4db3effde..108f300cb 100644
--- a/mod/blog/lib/blog.php
+++ b/mod/blog/lib/blog.php
@@ -12,66 +12,79 @@
* @param int $guid of a blog entity.
* @return string html
*/
-function blog_get_page_content_read($owner_guid = NULL, $guid = NULL) {
- global $CONFIG;
+function blog_get_page_content_read($guid = NULL) {
$return = array();
- if ($guid) {
- $blog = get_entity($guid);
+ $blog = get_entity($guid);
- // no header or tabs for viewing an individual blog
- $return['filter'] = '';
- $return['header'] = '';
+ // no header or tabs for viewing an individual blog
+ $return['filter'] = '';
+ $return['header'] = '';
- if (!elgg_instanceof($blog, 'object', 'blog') || ($blog->status != 'published' && !$blog->canEdit())) {
- $return['content'] = elgg_echo('blog:error:post_not_found');
- } else {
- elgg_push_breadcrumb($blog->title, $blog->getURL());
- $return['content'] = elgg_view_entity($blog, TRUE);
- //check to see if comment are on
- if ($blog->comments_on != 'Off') {
- $return['content'] .= elgg_view_comments($blog);
- }
- }
- } else {
+ if (!elgg_instanceof($blog, 'object', 'blog') || !$blog->canEdit()) {
+ $return['content'] = elgg_echo('blog:error:post_not_found');
+ return $return;
+ }
- $return['filter_context'] = $owner_guid ? 'mine' : 'everyone';
+ elgg_push_breadcrumb($blog->title, $blog->getURL());
+ $return['content'] = elgg_view_entity($blog, TRUE);
+ //check to see if comment are on
+ if ($blog->comments_on != 'Off') {
+ $return['content'] .= elgg_view_comments($blog);
+ }
- $options = array(
- 'type' => 'object',
- 'subtype' => 'blog',
- 'full_view' => FALSE,
- //'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int')
- );
+ return $return;
+}
- $loggedin_userid = get_loggedin_userid();
- if ($owner_guid) {
- $options['owner_guid'] = $owner_guid;
-/*
- if ($owner_guid != $loggedin_userid) {
- // do not show content header when viewing other users' posts
- $content = elgg_view('page_elements/content_header_member', array('type' => 'blog'));
- }
- *
+/**
+ * Returns HTML for listing a user's or all blogs.
+ *
+ * @param int $owner_guid The GUID of the page owner or NULL for all blogs
+ * @return string html
*/
- }
+function blog_get_page_content_list($owner_guid = NULL) {
- // show all posts for admin or users looking at their own blogs
- // show only published posts for other users.
- if (!(isadminloggedin() || (isloggedin() && $owner_guid == $loggedin_userid))) {
- $options['metadata_name_value_pairs'] = array(
- array('name' => 'status', 'value' => 'published'),
- //array('name' => 'publish_date', 'operand' => '<', 'value' => time())
- );
- }
+ $return = array();
- $list = elgg_list_entities_from_metadata($options);
- if (!$list) {
- $return['content'] = elgg_echo('blog:none');
- } else {
- $return['content'] = $list;
+ $return['filter_context'] = $owner_guid ? 'mine' : 'everyone';
+
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'blog',
+ 'full_view' => FALSE,
+ //'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int')
+ );
+
+ $loggedin_userid = get_loggedin_userid();
+ if ($owner_guid) {
+ $options['owner_guid'] = $owner_guid;
+
+ if ($owner_guid == $loggedin_userid) {
+ $return['filter_context'] = 'mine';
+ } else{
+ // do not show button or select a tab when viewing someone else's posts
+ $return['filter_context'] = 'none';
+ $return['buttons'] = '';
}
+ } else {
+ $return['filter_context'] = 'everyone';
+ }
+
+ // show all posts for admin or users looking at their own blogs
+ // show only published posts for other users.
+ if (!(isadminloggedin() || (isloggedin() && $owner_guid == $loggedin_userid))) {
+ $options['metadata_name_value_pairs'] = array(
+ array('name' => 'status', 'value' => 'published'),
+ //array('name' => 'publish_date', 'operand' => '<', 'value' => time())
+ );
+ }
+
+ $list = elgg_list_entities_from_metadata($options);
+ if (!$list) {
+ $return['content'] = elgg_echo('blog:none');
+ } else {
+ $return['content'] = $list;
}
return $return;
@@ -105,10 +118,10 @@ function blog_get_page_content_edit($guid, $revision = NULL) {
elgg_push_breadcrumb(elgg_echo('edit'));
$content = elgg_view('blog/forms/edit', $vars);
- $sidebar = elgg_view('blog/sidebar_revisions', array('entity' => $blog));
+ $sidebar = elgg_view('blog/sidebar_revisions', $vars);
//$sidebar .= elgg_view('blog/sidebar_related');
} else {
- $content = elgg_echo('blog:error:post_not_found');
+ $content = elgg_echo('blog:error:cannot_edit_post');
}
} else {
elgg_push_breadcrumb(elgg_echo('blog:new'));
@@ -127,12 +140,11 @@ function blog_get_page_content_edit($guid, $revision = NULL) {
/**
* Show blogs with publish dates between $lower and $upper
*
- * @param unknown_type $owner_guid
- * @param unknown_type $lower
- * @param unknown_type $upper
+ * @param int $owner_guid The GUID of the owner of this page
+ * @param int $lower Unix timestamp
+ * @param int $upper Unix timestamp
*/
function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) {
- global $CONFIG;
$now = time();
@@ -201,13 +213,12 @@ function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) {
}
/**
- * Returns a view of the user's friend's posts.
+ * Returns a list of the user's friend's posts.
*
* @param int $user_guid
* @return string
*/
function blog_get_page_content_friends($user_guid) {
- global $CONFIG;
elgg_push_breadcrumb(elgg_echo('friends'));
diff --git a/mod/blog/start.php b/mod/blog/start.php
index 9e3b8f300..f0967367d 100644
--- a/mod/blog/start.php
+++ b/mod/blog/start.php
@@ -9,7 +9,6 @@
* functions to work with a non-standard time_created.
* Show friends blog posts
* Widget
- *
* Pingbacks
* Notifications
*/
@@ -23,7 +22,7 @@ function blog_init() {
elgg_register_library('elgg:blog', elgg_get_plugin_path() . 'blog/lib/blog.php');
- add_menu(elgg_echo('blog:blogs'), "pg/blog/", array());
+ add_menu(elgg_echo('blog:blogs'), "pg/blog/all/", array());
// run the setup upon activations or to upgrade old installations.
run_function_once('blog_runonce', '1269370108');
@@ -71,36 +70,53 @@ function blog_runonce() {
/**
* Dispatches blog pages.
- * To maintain URL backward compatibility, expects old-style URLs like:
- * pg/blog/[username/[read|edit|archive|new/[time_start|guid/[time_end|title]]]]
+ * URLs take the form of
+ * pg/blog/[all|owner|read|edit|archive|new]/[username]/[time_start|guid]/[time_end|title]
*
- * Without a username, show all blogs
- * Without an action (read|edit|archive|new), forward to pg/blog/username/read.
+ * Without an action, show all blogs
* Without a guid, show all post for that user.
* Title is ignored
*
* If archive, uses time_start/end
*
- * @todo There is no way to say "show me archive view for all blog posts" with the
- * current URL scheme because $param[0] is the username instead of an action.
- * Could do something hideous like make '*' mean "all users" (since a username can't be *).
- * Can't change the URL scheme because of URL compatibility.
+ * @todo no archives for all blogs or friends
*
* @param array $page
* @return NULL
*/
function blog_page_handler($page) {
- global $CONFIG;
+
+ // @todo remove the forwarder in 1.9
+ // forward to correct URL for bookmaarks pre-1.7.5
+ // 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)) {
+ blog_url_forwarder($page);
+ }
+ }
+ // user usernames
+ $user = get_user_by_username($page[0]);
+ if ($user) {
+ blog_url_forwarder($page);
+ }
elgg_load_library('elgg:blog');
// push breadcrumb
- elgg_push_breadcrumb(elgg_echo('blog:blogs'), "pg/blog");
+ elgg_push_breadcrumb(elgg_echo('blog:blogs'), "pg/blog/all/");
- // see if we're showing all or just a user's
- if (isset($page[0]) && !empty($page[0])) {
- $username = $page[0];
+ if (!isset($page[0])) {
+ $page[0] = 'all';
+ }
+ // if username not set, we are showing all blog posts
+ if (!isset($page[1])) {
+ $title = elgg_echo('blog:title:all_blogs');
+ $params = blog_get_page_content_list();
+ } else {
+ $username = $page[1];
// forward away if invalid user.
if (!$user = get_user_by_username($username)) {
register_error('blog:error:unknown_username');
@@ -109,18 +125,23 @@ function blog_page_handler($page) {
set_page_owner($user->getGUID());
$crumbs_title = elgg_echo('blog:owned_blogs', array($user->name));
- $crumbs_url = "pg/blog/$username/read";
+ $crumbs_url = "pg/blog/owner/$username/";
elgg_push_breadcrumb($crumbs_title, $crumbs_url);
- $action = isset($page[1]) ? $page[1] : FALSE;
+ $action = $page[0];
// yeah these are crap names, but they're used for different things.
$page2 = isset($page[2]) ? $page[2] : FALSE;
$page3 = isset($page[3]) ? $page[3] : FALSE;
switch ($action) {
+ case 'owner':
+ $title = elgg_echo('blog:title:user_blogs', array($user->name));
+ $params = blog_get_page_content_list($user->getGUID());
+ break;
+
case 'read':
$title = elgg_echo('blog:title:user_blogs', array($user->name));
- $params = blog_get_page_content_read($user->getGUID(), $page2);
+ $params = blog_get_page_content_read($page2);
break;
case 'new':
@@ -141,16 +162,13 @@ function blog_page_handler($page) {
break;
default:
- forward("pg/blog/$username/read/");
+ forward("pg/blog/owner/$username/");
break;
}
- } else {
- $title = elgg_echo('blog:title:all_blogs');
- $params = blog_get_page_content_read();
}
$sidebar_menu = elgg_view('blog/sidebar_menu', array(
- 'page' => isset($page[1]) ? $page[1] : FALSE,
+ 'page' => $action,
));
$params['sidebar'] .= $sidebar_menu;
@@ -161,6 +179,40 @@ function blog_page_handler($page) {
}
/**
+ * Forward to the new style of URLs
+ *
+ * @param string $page
+ */
+function blog_url_forwarder($page) {
+ global $CONFIG;
+
+ if (!isset($page[1])) {
+ $page[1] = 'owner';
+ }
+
+ switch ($page[1]) {
+ case "read":
+ $url = "{$CONFIG->wwwroot}pg/blog/read/{$page[2]}/{$page[3]}";
+ break;
+ case "archive":
+ $url = "{$CONFIG->wwwroot}pg/blog/archive/{$page[0]}/{$page[2]}/{$page[3]}";
+ break;
+ case "friends":
+ $url = "{$CONFIG->wwwroot}pg/blog/friends/{$page[0]}/";
+ break;
+ case "new":
+ $url = "{$CONFIG->wwwroot}pg/blog/new/{$page[0]}/";
+ break;
+ case "owner":
+ $url = "{$CONFIG->wwwroot}pg/blog/owner/{$page[0]}/";
+ break;
+ }
+
+ register_error(elgg_echo("changebookmark"));
+ forward($url);
+}
+
+/**
* Format and return the correct URL for blogs.
*
* @param ElggObject $entity
@@ -174,7 +226,7 @@ function blog_url_handler($entity) {
$friendly_title = elgg_get_friendly_title($entity->title);
- return "pg/blog/{$user->username}/read/{$entity->guid}/$friendly_title";
+ return "pg/blog/read/{$user->username}/{$entity->guid}/$friendly_title";
}
/**
@@ -192,12 +244,11 @@ function blog_ecml_views_hook($hook, $entity_type, $return_value, $params) {
}
function blog_profile_menu($hook, $entity_type, $return_value, $params) {
- global $CONFIG;
if (!($params['owner'] instanceof ElggGroup)) {
$return_value[] = array(
'text' => elgg_echo('blog'),
- 'href' => "pg/blog/{$params['owner']->username}/read",
+ 'href' => "pg/blog/owner/{$params['owner']->username}/",
);
}
diff --git a/mod/blog/views/default/blog/css.php b/mod/blog/views/default/blog/css.php
index 5808cc167..12ac4df2a 100644
--- a/mod/blog/views/default/blog/css.php
+++ b/mod/blog/views/default/blog/css.php
@@ -5,40 +5,10 @@
* @package Blog
*/
?>
-.blogpost .entity-listing-icon {
- margin-top:6px;
-}
-.blogpost .entity-listing-info {
- margin-top:4px;
-}
-.blog_post {
- border-top:1px solid #CCCCCC;
- border-bottom:1px dotted #CCCCCC;
- margin:10px 0 0;
- padding-bottom:40px;
- padding-top:10px;
-}
-.blog_post p {
- line-height: 1.4em;
- padding-bottom:12px;
-}
-.blog_archives {
- list-style: none;
- margin-bottom:0;
- padding-left:0;
-}
-/* blogs list view */
-.entity-listing.blog .entity-metadata {
- min-width:400px;
- text-align: right;
-}
+/* Blog Plugin */
-/* blogs edit/create form */
-form#blog_post_edit .submit-button {
- margin-right:15px;
-}
/* force tinymce input height for a more useful editing / blog creation area */
-form#blog_post_edit #description_parent #description_ifr {
+form#blog-post-edit #description_parent #description_ifr {
height:400px !important;
-} \ No newline at end of file
+}
diff --git a/mod/blog/views/default/blog/forms/edit.php b/mod/blog/views/default/blog/forms/edit.php
index e9fb7d37f..8900fed25 100644
--- a/mod/blog/views/default/blog/forms/edit.php
+++ b/mod/blog/views/default/blog/forms/edit.php
@@ -205,7 +205,7 @@ $categories_input
<div class="divider"></div>
<p class="margin-none margin-top entity-subtext">
- $save_status <span class="blog_save_status_time">$saved</span>
+ $save_status <span class="blog-save-status-time">$saved</span>
</p>
$guid_input
@@ -217,7 +217,7 @@ $action_buttons
___END;
echo elgg_view('input/form', array(
- 'internalid' => 'blog_post_edit',
+ 'internalid' => 'blog-post-edit',
'internalname' => 'blog_post',
'action' => "action/blog/save",
'body' => $form_body
@@ -244,10 +244,12 @@ elgg_clear_sticky_form('blog');
var d = new Date();
var mins = d.getMinutes() + '';
- if (mins.length == 1) mins = '0' + mins;
- $(".blog_save_status_time").html(d.toLocaleDateString() + " @ " + d.getHours() + ":" + mins);
+ if (mins.length == 1) {
+ mins = '0' + mins;
+ }
+ $(".blog-save-status-time").html(d.toLocaleDateString() + " @ " + d.getHours() + ":" + mins);
} else {
- $(".blog_save_status_time").html("<?php echo elgg_echo('error'); ?>");
+ $(".blog-save-status-time").html("<?php echo elgg_echo('error'); ?>");
}
}
diff --git a/mod/blog/views/default/blog/sidebar_menu.php b/mod/blog/views/default/blog/sidebar_menu.php
index 10798d7a4..0be818c5a 100644
--- a/mod/blog/views/default/blog/sidebar_menu.php
+++ b/mod/blog/views/default/blog/sidebar_menu.php
@@ -40,14 +40,14 @@ if ($page_owner && $vars['page'] != 'friends') {
if ($dates) {
$title = elgg_echo('blog:archives');
- $content = '<ul class="blog_archives">';
+ $content = '<ul class="blog-archives">';
foreach($dates as $date) {
$date = $date->yearmonth;
$timestamplow = mktime(0, 0, 0, substr($date,4,2) , 1, substr($date, 0, 4));
$timestamphigh = mktime(0, 0, 0, ((int) substr($date, 4, 2)) + 1, 1, substr($date, 0, 4));
- $link = elgg_get_site_url() . 'pg/blog/' . $page_owner->username . '/archive/' . $timestamplow . '/' . $timestamphigh;
+ $link = elgg_get_site_url() . 'pg/blog/archive/' . $page_owner->username . '/' . $timestamplow . '/' . $timestamphigh;
$month = elgg_echo('date:month:' . substr($date, 4, 2), array(substr($date, 0, 4)));
$content .= "<li><a href=\"$link\" title=\"$month\">$month</a></li>";
}
diff --git a/mod/blog/views/default/blog/sidebar_revisions.php b/mod/blog/views/default/blog/sidebar_revisions.php
index fc5170ddc..ca0a642f2 100644
--- a/mod/blog/views/default/blog/sidebar_revisions.php
+++ b/mod/blog/views/default/blog/sidebar_revisions.php
@@ -31,9 +31,9 @@ if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
$title = elgg_echo('blog:revisions');
$n = count($revisions);
- $body = '<ul class="blog_revisions">';
+ $body = '<ul class="blog-revisions">';
- $load_base_url = "pg/blog/{$owner->username}/edit/{$blog->getGUID()}/";
+ $load_base_url = "pg/blog/edit/{$owner->username}/{$blog->getGUID()}/";
// show the "published revision"
if ($blog->status == 'published') {
@@ -63,7 +63,7 @@ if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
));
$text = "$load: $time";
- $class = 'class="auto_saved"';
+ $class = 'class="auto-saved"';
$n--;
diff --git a/mod/blog/views/default/object/blog.php b/mod/blog/views/default/object/blog.php
index 0638c2fc4..7e6be0b21 100644
--- a/mod/blog/views/default/object/blog.php
+++ b/mod/blog/views/default/object/blog.php
@@ -20,7 +20,7 @@ $excerpt = $blog->excerpt;
$body = autop($blog->description);
$owner_icon = elgg_view('profile/icon', array('entity' => $owner, 'size' => 'tiny'));
-$owner_blog_link = "<a href=\"" . elgg_get_site_url() . "pg/blog/$owner->username\">{$owner->name}</a>";
+$owner_blog_link = "<a href=\"" . elgg_get_site_url() . "pg/blog/owner/$owner->username\">{$owner->name}</a>";
$author_text = elgg_echo('blog:author_by_line', array($owner_blog_link));
if ($blog->tags) {
$tags = "<p class=\"elgg-tags\">" . elgg_view('output/tags', array('tags' => $blog->tags)) . "</p>";
@@ -48,7 +48,7 @@ $edit = elgg_view('output/access', array('entity' => $vars['entity']));
// links to delete or edit.
if ($blog->canEdit()) {
- $edit_url = elgg_get_site_url()."pg/blog/{$owner->username}/edit/{$blog->getGUID()}/";
+ $edit_url = elgg_get_site_url()."pg/blog/edit/{$owner->username}/{$blog->getGUID()}/";
$edit_link = "<span class='entity-edit'><a href=\"$edit_url\">" . elgg_echo('edit') . '</a></span>';
$delete_url = "action/blog/delete?guid={$blog->getGUID()}";