aboutsummaryrefslogtreecommitdiff
path: root/mod/blog
diff options
context:
space:
mode:
Diffstat (limited to 'mod/blog')
-rw-r--r--mod/blog/actions/blog/auto_save_revision.php8
-rw-r--r--mod/blog/actions/blog/delete.php6
-rw-r--r--mod/blog/actions/blog/save.php109
-rw-r--r--mod/blog/activate.php10
-rw-r--r--mod/blog/blog_lib.php276
-rw-r--r--mod/blog/classes/ElggBlog.php48
-rw-r--r--mod/blog/deactivate.php6
-rw-r--r--mod/blog/languages/en.php44
-rw-r--r--mod/blog/lib/blog.php478
-rw-r--r--mod/blog/manifest.xml27
-rw-r--r--mod/blog/start.php359
-rw-r--r--mod/blog/views/default/blog/css.php38
-rw-r--r--mod/blog/views/default/blog/forms/edit.php316
-rw-r--r--mod/blog/views/default/blog/group_module.php46
-rw-r--r--mod/blog/views/default/blog/sidebar.php30
-rw-r--r--mod/blog/views/default/blog/sidebar/archives.php34
-rw-r--r--mod/blog/views/default/blog/sidebar/revisions.php (renamed from mod/blog/views/default/blog/sidebar_revisions.php)46
-rw-r--r--mod/blog/views/default/blog/sidebar_edit.php61
-rw-r--r--mod/blog/views/default/blog/sidebar_menu.php65
-rw-r--r--mod/blog/views/default/forms/blog/save.php166
-rw-r--r--mod/blog/views/default/input/datetime.php46
-rw-r--r--mod/blog/views/default/js/blog/save_draft.php67
-rw-r--r--mod/blog/views/default/object/blog.php158
-rw-r--r--mod/blog/views/default/river/object/blog/create.php30
-rw-r--r--mod/blog/views/default/widgets/blog/content.php30
-rw-r--r--mod/blog/views/default/widgets/blog/edit.php22
26 files changed, 1366 insertions, 1160 deletions
diff --git a/mod/blog/actions/blog/auto_save_revision.php b/mod/blog/actions/blog/auto_save_revision.php
index d400dda90..e33edfaab 100644
--- a/mod/blog/actions/blog/auto_save_revision.php
+++ b/mod/blog/actions/blog/auto_save_revision.php
@@ -6,8 +6,8 @@
*/
$guid = get_input('guid');
-$user = get_loggedin_user();
-$title = get_input('title');
+$user = elgg_get_logged_in_user_entity();
+$title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
$description = get_input('description');
$excerpt = get_input('excerpt');
@@ -38,8 +38,6 @@ if ($title && $description) {
$blog->title = $title;
$blog->description = $description;
$blog->excerpt = elgg_get_excerpt($excerpt);
- // must be present or doesn't show up when metadata sorting.
- $blog->publish_date = time();
// mark this as a brand new post so we can work out the
// river / revision logic in the real save action.
@@ -65,7 +63,7 @@ if ($title && $description) {
if (!$auto_save) {
$annotation_id = $blog->annotate('blog_auto_save', $description);
} elseif ($auto_save instanceof ElggAnnotation && $auto_save->value != $description) {
- $blog->clearAnnotations('blog_auto_save');
+ $blog->deleteAnnotations('blog_auto_save');
$annotation_id = $blog->annotate('blog_auto_save', $description);
} elseif ($auto_save instanceof ElggAnnotation && $auto_save->value == $description) {
// this isn't an error because we have an up to date annotation.
diff --git a/mod/blog/actions/blog/delete.php b/mod/blog/actions/blog/delete.php
index d338fd2df..ca4eb8a7f 100644
--- a/mod/blog/actions/blog/delete.php
+++ b/mod/blog/actions/blog/delete.php
@@ -12,7 +12,11 @@ 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/");
+ if (elgg_instanceof($container, 'group')) {
+ forward("blog/group/$container->guid/all");
+ } else {
+ forward("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..82a9e6c51 100644
--- a/mod/blog/actions/blog/save.php
+++ b/mod/blog/actions/blog/save.php
@@ -2,16 +2,25 @@
/**
* Save blog entity
*
+ * Can be called by clicking save button or preview button. If preview button,
+ * we automatically save as draft. The preview button is only available for
+ * non-published drafts.
+ *
+ * Drafts are saved with the access set to private.
+ *
* @package Blog
*/
// start a new sticky form session in case of failure
-//elgg_make_sticky_form();
+elgg_make_sticky_form('blog');
+
+// save or preview
+$save = (bool)get_input('save');
// store errors to pass along
$error = FALSE;
-$error_forward_url = $_SERVER['HTTP_REFERER'];
-$user = get_loggedin_user();
+$error_forward_url = REFERER;
+$user = elgg_get_logged_in_user_entity();
// edit or create a new entity
$guid = get_input('guid');
@@ -22,9 +31,8 @@ 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());
// save some data for revisions once we save the new edit
$revision_text = $blog->description;
@@ -32,10 +40,12 @@ if ($guid) {
} else {
$blog = new ElggBlog();
$blog->subtype = 'blog';
- $success_forward_url = get_input('forward');
$new_post = TRUE;
}
+// set the previous status for the hooks to update the time_created and river entries
+$old_status = $blog->status;
+
// set defaults and required values.
$values = array(
'title' => '',
@@ -45,7 +55,7 @@ $values = array(
'comments_on' => 'On',
'excerpt' => '',
'tags' => '',
- 'container_guid' => ''
+ 'container_guid' => (int)get_input('container_guid'),
);
// fail if a required entity isn't set
@@ -53,7 +63,11 @@ $required = array('title', 'description');
// load from POST and do sanity and access checking
foreach ($values as $name => $default) {
- $value = get_input($name, $default);
+ if ($name === 'title') {
+ $value = htmlspecialchars(get_input('title', $default, false), ENT_QUOTES, 'UTF-8');
+ } else {
+ $value = get_input($name, $default);
+ }
if (in_array($name, $required) && empty($value)) {
$error = elgg_echo("blog:error:missing:$name");
@@ -65,20 +79,13 @@ foreach ($values as $name => $default) {
switch ($name) {
case 'tags':
- if ($value) {
- $values[$name] = string_to_tag_array($value);
- } else {
- unset ($values[$name]);
- }
+ $values[$name] = string_to_tag_array($value);
break;
case 'excerpt':
if ($value) {
- $value = elgg_get_excerpt($value);
- } else {
- $value = elgg_get_excerpt($values['description']);
+ $values[$name] = elgg_get_excerpt($value);
}
- $values[$name] = $value;
break;
case 'container_guid':
@@ -94,36 +101,27 @@ foreach ($values as $name => $default) {
}
break;
- // don't try to set the guid
- case 'guid':
- unset($values['guid']);
- break;
-
default:
$values[$name] = $value;
break;
}
}
-// build publish_date
-//$publish_month = get_input('publish_month');
-//$publish_day = get_input('publish_day');
-//$publish_year = get_input('publish_year');
-//$publish_hour = get_input('publish_hour');
-//$publish_minute = get_input('publish_minute');
-//$datetime = "$publish_year-$publish_month-$publish_day $publish_hour:$publish_minute:00";
-//$values['publish_date'] = date('U', strtotime($datetime));
+// if preview, force status to be draft
+if ($save == false) {
+ $values['status'] = 'draft';
+}
-// setting publish_date to now until the problems with locale dates can be resolved.
-$values['publish_date'] = time();
+// if draft, set access to private and cache the future access
+if ($values['status'] == 'draft') {
+ $values['future_access'] = $values['access_id'];
+ $values['access_id'] = ACCESS_PRIVATE;
+}
// assign values to the entity, stopping on error.
if (!$error) {
foreach ($values as $name => $value) {
- if (FALSE === ($blog->$name = $value)) {
- $error = elgg_echo('blog:error:cannot_save' . "$name=$value");
- break;
- }
+ $blog->$name = $value;
}
}
@@ -131,13 +129,13 @@ if (!$error) {
if (!$error) {
if ($blog->save()) {
// remove sticky form entries
- elgg_clear_sticky_form();
+ elgg_clear_sticky_form('blog');
// remove autosave draft if exists
- $blog->clearAnnotations('blog_auto_save');
+ $blog->deleteAnnotations('blog_auto_save');
// no longer a brand new post.
- $blog->clearMetadata('new_post');
+ $blog->deleteMetadata('new_post');
// if this was an edit, create a revision annotation
if (!$new_post && $revision_text) {
@@ -146,11 +144,34 @@ if (!$error) {
system_message(elgg_echo('blog:message:saved'));
- // @todo do we want to alert on updates?
- if ($new_post && $blog->status == 'published') {
- add_to_river('river/object/blog/create', 'create', get_loggedin_userid(), $blog->getGUID());
+ $status = $blog->status;
+
+ // add to river if changing status or published, regardless of new post
+ // because we remove it for drafts.
+ if (($new_post || $old_status == 'draft') && $status == 'published') {
+ add_to_river('river/object/blog/create', 'create', $blog->owner_guid, $blog->getGUID());
+
+ // we only want notifications sent when post published
+ register_notification_object('object', 'blog', elgg_echo('blog:newpost'));
+ elgg_trigger_event('publish', 'object', $blog);
+
+ // reset the creation time for posts that move from draft to published
+ if ($guid) {
+ $blog->time_created = time();
+ $blog->save();
+ }
+ } elseif ($old_status == 'published' && $status == 'draft') {
+ elgg_delete_river(array(
+ 'object_guid' => $blog->guid,
+ 'action_type' => 'create',
+ ));
+ }
+
+ if ($blog->status == 'published' || $save == false) {
+ forward($blog->getURL());
+ } else {
+ forward("blog/edit/$blog->guid");
}
- forward($success_forward_url);
} else {
register_error(elgg_echo('blog:error:cannot_save'));
forward($error_forward_url);
@@ -158,4 +179,4 @@ if (!$error) {
} else {
register_error($error);
forward($error_forward_url);
-} \ No newline at end of file
+}
diff --git a/mod/blog/activate.php b/mod/blog/activate.php
new file mode 100644
index 000000000..a90525291
--- /dev/null
+++ b/mod/blog/activate.php
@@ -0,0 +1,10 @@
+<?php
+/**
+ * Register the ElggBlog class for the object/blog subtype
+ */
+
+if (get_subtype_id('object', 'blog')) {
+ update_subtype('object', 'blog', 'ElggBlog');
+} else {
+ add_subtype('object', 'blog', 'ElggBlog');
+}
diff --git a/mod/blog/blog_lib.php b/mod/blog/blog_lib.php
deleted file mode 100644
index 52d629a99..000000000
--- a/mod/blog/blog_lib.php
+++ /dev/null
@@ -1,276 +0,0 @@
-<?php
-/**
- * Blog helper functions
- *
- * @package Blog
- */
-
-
-/**
- * Returns HTML for a blog post.
- *
- * @param int $guid of a blog entity.
- * @return string html
- */
-function blog_get_page_content_read($owner_guid = NULL, $guid = NULL) {
- global $CONFIG;
-
- if ($guid) {
- $blog = get_entity($guid);
-
- if (!elgg_instanceof($blog, 'object', 'blog') || ($blog->status != 'published' && !$blog->canEdit())) {
- $content = elgg_echo('blog:error:post_not_found');
- } else {
- elgg_push_breadcrumb($blog->title, $blog->getURL());
- $content = elgg_view_entity($blog, TRUE);
- //check to see if comment are on
- if ($blog->comments_on != 'Off') {
- $content .= elgg_view_comments($blog);
- }
- }
- } else {
- $content = elgg_view('page_elements/content_header', array(
- 'context' => $owner_guid ? 'mine' : 'everyone',
- 'type' => 'blog',
- 'all_link' => "{$CONFIG->site->url}pg/blog"
- ));
-
- $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) {
- // do not show content header when viewing other users' posts
- $content = elgg_view('page_elements/content_header_member', array('type' => 'blog'));
- }
- }
-
- // 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) {
- $content .= elgg_echo('blog:none');
- } else {
- $content .= $list;
- }
- }
-
- return array('content' => $content);
-}
-
-/**
- * Returns HTML to edit a blog post.
- *
- * @param int $guid
- * @param int annotation id optional revision to edit
- * @return string html
- */
-function blog_get_page_content_edit($guid, $revision = NULL) {
- $vars = array();
- if ($guid) {
- $blog = get_entity((int)$guid);
-
- if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
- $vars['entity'] = $blog;
-
- if ($revision) {
- $revision = get_annotation((int)$revision);
- $vars['revision'] = $revision;
-
- if (!$revision || !($revision->entity_guid == $guid)) {
- $content = elgg_echo('blog:error:revision_not_found');
- }
- }
-
- elgg_push_breadcrumb($blog->title, $blog->getURL());
- 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_related');
- } else {
- $content = elgg_echo('blog:error:post_not_found');
- }
- } else {
- elgg_push_breadcrumb(elgg_echo('blog:new'));
- $content = elgg_view('blog/forms/edit', $vars);
- //$sidebar = elgg_view('blog/sidebar_related');
- }
-
- return array('content' => $content, 'sidebar' => $sidebar);
-}
-
-/**
- * Show blogs with publish dates between $lower and $upper
- *
- * @param unknown_type $owner_guid
- * @param unknown_type $lower
- * @param unknown_type $upper
- */
-function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) {
- global $CONFIG;
-
- $now = time();
-
- elgg_push_breadcrumb(elgg_echo('blog:archives'));
- $content = elgg_view('page_elements/content_header_member', array('type' => 'blog'));
-
- if ($lower) {
- $lower = (int)$lower;
- }
-
- if ($upper) {
- $upper = (int)$upper;
- }
-
- $options = array(
- 'type' => 'object',
- 'subtype' => 'blog',
- 'full_view' => FALSE,
- 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'),
- );
-
- if ($owner_guid) {
- $options['owner_guid'] = $owner_guid;
- }
-
- // admin / owners can see any posts
- // everyone else can only see published posts
- if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) {
- if ($upper > $now) {
- $upper = $now;
- }
-
- $options['metadata_name_value_pairs'] = array(
- array('name' => 'status', 'value' => 'published')
- );
- }
-
- if ($lower) {
- $options['metadata_name_value_pairs'][] = array(
- 'name' => 'publish_date',
- 'operand' => '>',
- 'value' => $lower
- );
- }
-
- if ($upper) {
- $options['metadata_name_value_pairs'][] = array(
- 'name' => 'publish_date',
- 'operand' => '<',
- 'value' => $upper
- );
- }
-
- $list = elgg_list_entities_from_metadata($options);
- if (!$list) {
- $content .= elgg_echo('blog:none');
- } else {
- $content .= $list;
- }
-
- return array(
- 'content' => $content
- );
-}
-
-/**
- * Returns a view 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'));
-
- $content = elgg_view('page_elements/content_header', array(
- 'context' => 'friends',
- 'type' => 'blog',
- 'all_link' => "{$CONFIG->site->url}pg/blog"
- ));
-
- if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) {
- $content .= elgg_echo('friends:none:you');
- } else {
- $options = array(
- 'type' => 'object',
- 'subtype' => 'blog',
- 'full_view' => FALSE,
- 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'),
- );
-
- foreach ($friends as $friend) {
- $options['container_guids'][] = $friend->getGUID();
- }
-
- // admin / owners can see any posts
- // everyone else can only see published posts
- if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) {
- if ($upper > $now) {
- $upper = $now;
- }
-
- $options['metadata_name_value_pairs'][] = array(
- array('name' => 'status', 'value' => 'published')
- );
- }
-
- $list = elgg_list_entities_from_metadata($options);
- if (!$list) {
- $content .= elgg_echo('blog:none');
- } else {
- $content .= $list;
- }
- }
-
- return array('content' => $content);
-}
-
-/**
- * Returns a list of years and months for all blogs optionally for a user.
- * Very similar to get_entity_dates() except uses a metadata field.
- *
- * @param mixed $user_guid
- */
-function blog_get_blog_months($user_guid = NULL, $container_guid = NULL) {
- global $CONFIG;
-
- $subtype = get_subtype_id('object', 'blog');
-
- $q = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(mdv.string)) AS yearmonth
- FROM {$CONFIG->dbprefix}entities e, {$CONFIG->dbprefix}metadata, {$CONFIG->dbprefix}metastrings mdn, {$CONFIG->dbprefix}metastrings mdv
- WHERE e.guid = {$CONFIG->dbprefix}metadata.entity_guid
- AND {$CONFIG->dbprefix}metadata.name_id = mdn.id
- AND {$CONFIG->dbprefix}metadata.value_id = mdv.id
- AND mdn.string = 'publish_date'";
-
- if ($user_guid) {
- $user_guid = (int)$user_guid;
- $q .= " AND e.owner_guid = $user_guid";
- }
-
- if ($container_guid) {
- $container_guid = (int)$container_guid;
- $q .= " AND e.container_guid = $container_guid";
- }
-
- $q .= ' AND ' . get_access_sql_suffix('e');
-
- return get_data($q);
-}
diff --git a/mod/blog/classes/ElggBlog.php b/mod/blog/classes/ElggBlog.php
index 7a64a1777..8d4401c57 100644
--- a/mod/blog/classes/ElggBlog.php
+++ b/mod/blog/classes/ElggBlog.php
@@ -1,6 +1,10 @@
<?php
/**
* Extended class to override the time_created
+ *
+ * @property string $status The published status of the blog post (published, draft)
+ * @property string $comments_on Whether commenting is allowed (Off, On)
+ * @property string $excerpt An excerpt of the blog post used when displaying the post
*/
class ElggBlog extends ElggObject {
@@ -14,29 +18,25 @@ class ElggBlog extends ElggObject {
}
/**
- * @todo this won't work until we have date l10n working.
- * Rewrite the time created to be publish time.
- * This is a bit dirty, but required for proper sorting.
+ * Can a user comment on this blog?
+ *
+ * @see ElggObject::canComment()
+ *
+ * @param int $user_guid User guid (default is logged in user)
+ * @return bool
+ * @since 1.8.0
*/
-// public function save() {
-// if (parent::save()) {
-// global $CONFIG;
-//
-// // try to grab the publish date, but default to now.
-// foreach (array('publish_date', 'time_created') as $field) {
-// if (isset($this->$field) && $this->field) {
-// $published = $this->field;
-// break;
-// }
-// }
-// if (!$published) {
-// $published = time();
-// }
-//
-// $sql = "UPDATE {$CONFIG->dbprefix}entities SET time_created = '$published', time_updated = '$published' WHERE guid = '{$this->getGUID()}'";
-// return update_data($sql);
-// }
-//
-// return FALSE;
-// }
+ public function canComment($user_guid = 0) {
+ $result = parent::canComment($user_guid);
+ if ($result == false) {
+ return $result;
+ }
+
+ if ($this->comments_on == 'Off') {
+ return false;
+ }
+
+ return true;
+ }
+
} \ No newline at end of file
diff --git a/mod/blog/deactivate.php b/mod/blog/deactivate.php
new file mode 100644
index 000000000..4a275fa94
--- /dev/null
+++ b/mod/blog/deactivate.php
@@ -0,0 +1,6 @@
+<?php
+/**
+ * Deregister the ElggBlog class
+ */
+
+update_subtype('object', 'blog');
diff --git a/mod/blog/languages/en.php b/mod/blog/languages/en.php
index 7f3954426..5248a6f51 100644
--- a/mod/blog/languages/en.php
+++ b/mod/blog/languages/en.php
@@ -7,25 +7,26 @@
$english = array(
'blog' => 'Blogs',
'blog:blogs' => 'Blogs',
- 'blog:owned_blogs' => '%s',
'blog:revisions' => 'Revisions',
'blog:archives' => 'Archives',
'blog:blog' => 'Blog',
- 'blog:author_by_line' => 'By %s',
'item:object:blog' => 'Blogs',
- 'blog:title:user_blogs' => '%s\'s Blogs',
- 'blog:title:all_blogs' => 'All Site Blogs',
- 'blog:title:friends' => 'All Friends\' Blogs',
+ 'blog:title:user_blogs' => '%s\'s blogs',
+ 'blog:title:all_blogs' => 'All site blogs',
+ 'blog:title:friends' => 'Friends\' blogs',
+
+ 'blog:group' => 'Group blog',
+ 'blog:enableblog' => 'Enable group blog',
+ 'blog:write' => 'Write a blog post',
// Editing
- 'blog:new' => 'New blog post',
+ 'blog:add' => 'Add blog post',
'blog:edit' => 'Edit blog post',
'blog:excerpt' => 'Excerpt',
'blog:body' => 'Body',
'blog:save_status' => 'Last saved: ',
'blog:never' => 'Never',
- 'blog:publish_date' => 'Publish Date',
// Statuses
'blog:status' => 'Status',
@@ -40,15 +41,38 @@ $english = array(
'blog:message:saved' => 'Blog post saved.',
'blog:error:cannot_save' => 'Cannot save blog post.',
'blog:error:cannot_write_to_container' => 'Insufficient access to save blog to group.',
- '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:none' => 'No blogs found',
+ 'blog:message:deleted_post' => 'Blog post deleted.',
+ 'blog:error:cannot_delete_post' => 'Cannot delete blog post.',
+ 'blog:none' => 'No blog posts',
'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.',
+ 'blog:error:revision_not_found' => 'Cannot find this revision.',
// river
- 'blog:river:create' => '%s wrote a new blog post',
+ 'river:create:object:blog' => '%s published a blog post %s',
+ 'river:comment:object:blog' => '%s commented on the blog %s',
+
+ // notifications
+ 'blog:newpost' => 'A new blog post',
+ 'blog:notification' =>
+'
+%s made a new blog post.
+
+%s
+%s
+
+View and comment on the new blog post:
+%s
+',
+
+ // widget
+ 'blog:widget:description' => 'Display your latest blog posts',
+ 'blog:moreblogs' => 'More blog posts',
+ 'blog:numbertodisplay' => 'Number of blog posts to display',
+ 'blog:noblogs' => 'No blog posts'
);
add_translation('en', $english);
diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php
new file mode 100644
index 000000000..9753f27a8
--- /dev/null
+++ b/mod/blog/lib/blog.php
@@ -0,0 +1,478 @@
+<?php
+/**
+ * Blog helper functions
+ *
+ * @package Blog
+ */
+
+
+/**
+ * Get page components to view a blog post.
+ *
+ * @param int $guid GUID of a blog entity.
+ * @return array
+ */
+function blog_get_page_content_read($guid = NULL) {
+
+ $return = array();
+
+ $blog = get_entity($guid);
+
+ // no header or tabs for viewing an individual blog
+ $return['filter'] = '';
+
+ if (!elgg_instanceof($blog, 'object', 'blog')) {
+ register_error(elgg_echo('noaccess'));
+ $_SESSION['last_forward_from'] = current_page_url();
+ forward('');
+ }
+
+ $return['title'] = $blog->title;
+
+ $container = $blog->getContainerEntity();
+ $crumbs_title = $container->name;
+ if (elgg_instanceof($container, 'group')) {
+ elgg_push_breadcrumb($crumbs_title, "blog/group/$container->guid/all");
+ } else {
+ elgg_push_breadcrumb($crumbs_title, "blog/owner/$container->username");
+ }
+
+ elgg_push_breadcrumb($blog->title);
+ $return['content'] = elgg_view_entity($blog, array('full_view' => true));
+ // check to see if we should allow comments
+ if ($blog->comments_on != 'Off' && $blog->status == 'published') {
+ $return['content'] .= elgg_view_comments($blog);
+ }
+
+ return $return;
+}
+
+/**
+ * Get page components to list a user's or 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) {
+
+ $return = array();
+
+ $return['filter_context'] = $container_guid ? 'mine' : 'all';
+
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'blog',
+ 'full_view' => false,
+ );
+
+ $current_user = elgg_get_logged_in_user_entity();
+
+ if ($container_guid) {
+ // access check for closed groups
+ group_gatekeeper();
+
+ $options['container_guid'] = $container_guid;
+ $container = get_entity($container_guid);
+ if (!$container) {
+
+ }
+ $return['title'] = elgg_echo('blog:title:user_blogs', array($container->name));
+
+ $crumbs_title = $container->name;
+ elgg_push_breadcrumb($crumbs_title);
+
+ if ($current_user && ($container_guid == $current_user->guid)) {
+ $return['filter_context'] = 'mine';
+ } else if (elgg_instanceof($container, 'group')) {
+ $return['filter'] = false;
+ } else {
+ // do not show button or select a tab when viewing someone else's posts
+ $return['filter_context'] = 'none';
+ }
+ } else {
+ $return['filter_context'] = 'all';
+ $return['title'] = elgg_echo('blog:title:all_blogs');
+ elgg_pop_breadcrumb();
+ elgg_push_breadcrumb(elgg_echo('blog:blogs'));
+ }
+
+ elgg_register_title_button();
+
+ // show all posts for admin or users looking at their own blogs
+ // show only published posts for other users.
+ $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'),
+ );
+ }
+
+ $list = elgg_list_entities_from_metadata($options);
+ if (!$list) {
+ $return['content'] = elgg_echo('blog:none');
+ } else {
+ $return['content'] = $list;
+ }
+
+ return $return;
+}
+
+/**
+ * Get page components to list of the user's friends' posts.
+ *
+ * @param int $user_guid
+ * @return array
+ */
+function blog_get_page_content_friends($user_guid) {
+
+ $user = get_user($user_guid);
+ if (!$user) {
+ forward('blog/all');
+ }
+
+ $return = array();
+
+ $return['filter_context'] = 'friends';
+ $return['title'] = elgg_echo('blog:title:friends');
+
+ $crumbs_title = $user->name;
+ elgg_push_breadcrumb($crumbs_title, "blog/owner/{$user->username}");
+ elgg_push_breadcrumb(elgg_echo('friends'));
+
+ elgg_register_title_button();
+
+ if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) {
+ $return['content'] .= elgg_echo('friends:none:you');
+ return $return;
+ } else {
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'blog',
+ 'full_view' => FALSE,
+ );
+
+ foreach ($friends as $friend) {
+ $options['container_guids'][] = $friend->getGUID();
+ }
+
+ // admin / owners can see any posts
+ // everyone else can only see published posts
+ $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')
+ );
+ }
+
+ $list = elgg_list_entities_from_metadata($options);
+ if (!$list) {
+ $return['content'] = elgg_echo('blog:none');
+ } else {
+ $return['content'] = $list;
+ }
+ }
+
+ return $return;
+}
+
+/**
+ * Get page components to show blogs with publish dates between $lower and $upper
+ *
+ * @param int $owner_guid The GUID of the owner of this page
+ * @param int $lower Unix timestamp
+ * @param int $upper Unix timestamp
+ * @return array
+ */
+function blog_get_page_content_archive($owner_guid, $lower = 0, $upper = 0) {
+
+ $now = time();
+
+ $owner = get_entity($owner_guid);
+ elgg_set_page_owner_guid($owner_guid);
+
+ $crumbs_title = $owner->name;
+ if (elgg_instanceof($owner, 'user')) {
+ $url = "blog/owner/{$owner->username}";
+ } else {
+ $url = "blog/group/$owner->guid/all";
+ }
+ elgg_push_breadcrumb($crumbs_title, $url);
+ elgg_push_breadcrumb(elgg_echo('blog:archives'));
+
+ if ($lower) {
+ $lower = (int)$lower;
+ }
+
+ if ($upper) {
+ $upper = (int)$upper;
+ }
+
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'blog',
+ 'full_view' => FALSE,
+ );
+
+ if ($owner_guid) {
+ $options['container_guid'] = $owner_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;
+ }
+
+ $options['metadata_name_value_pairs'] = array(
+ array('name' => 'status', 'value' => 'published')
+ );
+ }
+
+ if ($lower) {
+ $options['created_time_lower'] = $lower;
+ }
+
+ if ($upper) {
+ $options['created_time_upper'] = $upper;
+ }
+
+ $list = elgg_list_entities_from_metadata($options);
+ if (!$list) {
+ $content = elgg_echo('blog:none');
+ } else {
+ $content = $list;
+ }
+
+ $title = elgg_echo('date:month:' . date('m', $lower), array(date('Y', $lower)));
+
+ return array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+ );
+}
+
+/**
+ * Get page components to edit/create a blog post.
+ *
+ * @param string $page 'edit' or 'new'
+ * @param int $guid GUID of blog post or container
+ * @param int $revision Annotation id for revision to edit (optional)
+ * @return array
+ */
+function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) {
+
+ elgg_load_js('elgg.blog');
+
+ $return = array(
+ 'filter' => '',
+ );
+
+ $vars = array();
+ $vars['id'] = 'blog-post-edit';
+ $vars['class'] = 'elgg-form-alt';
+
+ $sidebar = '';
+ if ($page == 'edit') {
+ $blog = get_entity((int)$guid);
+
+ $title = elgg_echo('blog:edit');
+
+ if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
+ $vars['entity'] = $blog;
+
+ $title .= ": \"$blog->title\"";
+
+ if ($revision) {
+ $revision = elgg_get_annotation_from_id((int)$revision);
+ $vars['revision'] = $revision;
+ $title .= ' ' . elgg_echo('blog:edit_revision_notice');
+
+ if (!$revision || !($revision->entity_guid == $guid)) {
+ $content = elgg_echo('blog:error:revision_not_found');
+ $return['content'] = $content;
+ $return['title'] = $title;
+ return $return;
+ }
+ }
+
+ $body_vars = blog_prepare_form_vars($blog, $revision);
+
+ elgg_push_breadcrumb($blog->title, $blog->getURL());
+ elgg_push_breadcrumb(elgg_echo('edit'));
+
+ elgg_load_js('elgg.blog');
+
+ $content = elgg_view_form('blog/save', $vars, $body_vars);
+ $sidebar = elgg_view('blog/sidebar/revisions', $vars);
+ } else {
+ $content = elgg_echo('blog:error:cannot_edit_post');
+ }
+ } else {
+ elgg_push_breadcrumb(elgg_echo('blog:add'));
+ $body_vars = blog_prepare_form_vars(null);
+
+ $title = elgg_echo('blog:add');
+ $content = elgg_view_form('blog/save', $vars, $body_vars);
+ }
+
+ $return['title'] = $title;
+ $return['content'] = $content;
+ $return['sidebar'] = $sidebar;
+ return $return;
+}
+
+/**
+ * Pull together blog variables for the save form
+ *
+ * @param ElggBlog $post
+ * @param ElggAnnotation $revision
+ * @return array
+ */
+function blog_prepare_form_vars($post = NULL, $revision = NULL) {
+
+ // input names => defaults
+ $values = array(
+ 'title' => NULL,
+ 'description' => NULL,
+ 'status' => 'published',
+ 'access_id' => ACCESS_DEFAULT,
+ 'comments_on' => 'On',
+ 'excerpt' => NULL,
+ 'tags' => NULL,
+ 'container_guid' => NULL,
+ 'guid' => NULL,
+ 'draft_warning' => '',
+ );
+
+ if ($post) {
+ foreach (array_keys($values) as $field) {
+ if (isset($post->$field)) {
+ $values[$field] = $post->$field;
+ }
+ }
+
+ if ($post->status == 'draft') {
+ $values['access_id'] = $post->future_access;
+ }
+ }
+
+ if (elgg_is_sticky_form('blog')) {
+ $sticky_values = elgg_get_sticky_values('blog');
+ foreach ($sticky_values as $key => $value) {
+ $values[$key] = $value;
+ }
+ }
+
+ elgg_clear_sticky_form('blog');
+
+ if (!$post) {
+ return $values;
+ }
+
+ // load the revision annotation if requested
+ if ($revision instanceof ElggAnnotation && $revision->entity_guid == $post->getGUID()) {
+ $values['revision'] = $revision;
+ $values['description'] = $revision->value;
+ }
+
+ // display a notice if there's an autosaved annotation
+ // and we're not editing it.
+ if ($auto_save_annotations = $post->getAnnotations('blog_auto_save', 1)) {
+ $auto_save = $auto_save_annotations[0];
+ } else {
+ $auto_save = false;
+ }
+
+ if ($auto_save && $auto_save->id != $revision->id) {
+ $values['draft_warning'] = elgg_echo('blog:messages:warning:draft');
+ }
+
+ return $values;
+}
+
+/**
+ * Forward to the new style of URLs
+ *
+ * Pre-1.7.5
+ * Group blogs page: /blog/group:<container_guid>/
+ * Group blog view: /blog/group:<container_guid>/read/<guid>/<title>
+ * 1.7.5-1.8
+ * Group blogs page: /blog/owner/group:<container_guid>/
+ * Group blog view: /blog/read/<guid>
+ *
+ *
+ * @param string $page
+ */
+function blog_url_forwarder($page) {
+
+ $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 (preg_match('~/group\:([0-9]+)/~', "/{$page[0]}/{$page[1]}/", $matches)) {
+ $guid = $matches[1];
+ $entity = get_entity($guid);
+ if (elgg_instanceof($entity, 'group')) {
+ if (!empty($page[2])) {
+ $url = "blog/view/$page[2]/";
+ } else {
+ $url = "blog/group/$guid/all";
+ }
+ register_error(elgg_echo("changebookmark"));
+ forward($url . $qs);
+ }
+ }
+
+ if (empty($page[0])) {
+ return;
+ }
+
+ // user usernames
+ $user = get_user_by_username($page[0]);
+ if (!$user) {
+ return;
+ }
+
+ if (empty($page[1])) {
+ $page[1] = 'owner';
+ }
+
+ switch ($page[1]) {
+ case "read":
+ $url = "blog/view/{$page[2]}/{$page[3]}";
+ break;
+ case "archive":
+ $url = "blog/archive/{$page[0]}/{$page[2]}/{$page[3]}";
+ break;
+ case "friends":
+ $url = "blog/friends/{$page[0]}";
+ break;
+ case "new":
+ $url = "blog/add/$user->guid";
+ break;
+ case "owner":
+ $url = "blog/owner/{$page[0]}";
+ break;
+ }
+
+ register_error(elgg_echo("changebookmark"));
+ forward($url . $qs);
+}
diff --git a/mod/blog/manifest.xml b/mod/blog/manifest.xml
index d88eaa994..29ee1bfc8 100644
--- a/mod/blog/manifest.xml
+++ b/mod/blog/manifest.xml
@@ -1,12 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin_manifest>
- <field key="author" value="Curverider" />
- <field key="version" value="1.8" />
- <field key="description" value="Elgg blog plugin" />
- <field key="website" value="http://www.elgg.org/" />
- <field key="copyright" value="(C) Curverider 2008-2010" />
- <field key="licence" value="GNU Public License version 2" />
- <field key="elgg_version" value="2010030101" />
- <field key="elgg_install_state" value="enabled" />
- <field key="admin_interface" value="simple" />
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Blog</name>
+ <author>Core developers</author>
+ <version>1.8</version>
+ <category>bundled</category>
+ <category>content</category>
+ <category>widget</category>
+ <blurb>Blog plugin</blurb>
+ <description>Adds simple blogging capabilities to your Elgg installation.</description>
+ <website>http://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/blog/start.php b/mod/blog/start.php
index 386870fd4..e724b91c2 100644
--- a/mod/blog/start.php
+++ b/mod/blog/start.php
@@ -5,203 +5,298 @@
* @package Blog
*
* @todo
- * Either drop support for "publish date" or duplicate more entity getter
+ * - Either drop support for "publish date" or duplicate more entity getter
* functions to work with a non-standard time_created.
- * Show friends blog posts
- * Widget
- *
- * Pingbacks
- * Notifications
+ * - Pingbacks
+ * - Notifications
+ * - River entry for posts saved as drafts and later published
*/
+elgg_register_event_handler('init', 'system', 'blog_init');
+
/**
* Init blog plugin.
- *
- * @return TRUE
*/
function blog_init() {
- global $CONFIG;
- require_once dirname(__FILE__) . '/blog_lib.php';
- add_menu(elgg_echo('blog:blogs'), "pg/blog/", array());
+ elgg_register_library('elgg:blog', elgg_get_plugins_path() . 'blog/lib/blog.php');
+
+ // add a site navigation item
+ $item = new ElggMenuItem('blog', elgg_echo('blog:blogs'), 'blog/all');
+ elgg_register_menu_item('site', $item);
+
+ elgg_register_event_handler('upgrade', 'upgrade', 'blog_run_upgrades');
+
+ // add to the main css
+ elgg_extend_view('css/elgg', 'blog/css');
+
+ // register the blog's JavaScript
+ $blog_js = elgg_get_simplecache_url('js', 'blog/save_draft');
+ elgg_register_simplecache_view('js/blog/save_draft');
+ elgg_register_js('elgg.blog', $blog_js);
- // run the setup upon activations or to upgrade old installations.
- run_function_once('blog_runonce', '1269370108');
+ // routing of urls
+ elgg_register_page_handler('blog', 'blog_page_handler');
- elgg_extend_view('css', 'blog/css');
+ // override the default url to view a blog object
+ elgg_register_entity_url_handler('object', 'blog', 'blog_url_handler');
- register_elgg_event_handler('pagesetup', 'system', 'blog_page_setup');
- register_page_handler('blog', 'blog_page_handler');
- register_entity_url_handler('blog_url_handler', 'object', 'blog');
+ // notifications - need to register for unique event because of draft/published status
+ elgg_register_event_handler('publish', 'object', 'object_notifications');
+ elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'blog_notify_message');
- // notifications
- register_notification_object('object', 'blog', elgg_echo('blog:newpost'));
- register_plugin_hook('notify:entity:message', 'object', 'blog_notify_message');
+ // add blog link to
+ elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'blog_owner_block_menu');
// pingbacks
- //register_elgg_event_handler('create', 'object', 'blog_incoming_ping');
- //register_plugin_hook('pingback:object:subtypes', 'object', 'blog_pingback_subtypes');
+ //elgg_register_event_handler('create', 'object', 'blog_incoming_ping');
+ //elgg_register_plugin_hook_handler('pingback:object:subtypes', 'object', 'blog_pingback_subtypes');
// Register for search.
- register_entity_type('object', 'blog');
+ elgg_register_entity_type('object', 'blog');
- //add_widget_type('blog', elgg_echo('blog'), elgg_echo('blog:widget:description'), 'profile, dashboard');
+ // Add group option
+ add_group_tool_option('blog', elgg_echo('blog:enableblog'), true);
+ elgg_extend_view('groups/tool_latest', 'blog/group_module');
- $action_path = dirname(__FILE__) . '/actions/blog';
+ // add a blog widget
+ elgg_register_widget_type('blog', elgg_echo('blog'), elgg_echo('blog:widget:description'));
- register_action('blog/save', FALSE, "$action_path/save.php");
- register_action('blog/auto_save_revision', FALSE, "$action_path/auto_save_revision.php");
- register_action('blog/delete', FALSE, "$action_path/delete.php");
+ // register actions
+ $action_path = elgg_get_plugins_path() . 'blog/actions/blog';
+ elgg_register_action('blog/save', "$action_path/save.php");
+ elgg_register_action('blog/auto_save_revision', "$action_path/auto_save_revision.php");
+ elgg_register_action('blog/delete', "$action_path/delete.php");
- // ecml
- register_plugin_hook('get_views', 'ecml', 'blog_ecml_views_hook');
-
- // Register profile menu hook
- register_plugin_hook('profile_menu', 'profile', 'blog_profile_menu');
-}
+ // entity menu
+ elgg_register_plugin_hook_handler('register', 'menu:entity', 'blog_entity_menu_setup');
-/**
- * Register entity class for object:blog -> ElggBlog
- */
-function blog_runonce() {
- if (!update_subtype('object', 'blog', 'ElggBlog')) {
- add_subtype('object', 'blog', 'ElggBlog');
- }
+ // ecml
+ elgg_register_plugin_hook_handler('get_views', 'ecml', 'blog_ecml_views_hook');
}
/**
* 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
+ * All blogs: blog/all
+ * User's blogs: blog/owner/<username>
+ * Friends' blog: blog/friends/<username>
+ * User's archives: blog/archives/<username>/<time_start>/<time_stop>
+ * Blog post: blog/view/<guid>/<title>
+ * New post: blog/add/<guid>
+ * Edit post: blog/edit/<guid>/<revision>
+ * Preview post: blog/preview/<guid>
+ * Group blog: blog/group/<guid>/all
*
- * Without a username, show all blogs
- * Without an action (read|edit|archive|new), forward to pg/blog/username/read.
- * 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
+ * @return bool
*/
function blog_page_handler($page) {
- global $CONFIG;
- // see if we're showing all or just a user's
- if (isset($page[0]) && !empty($page[0])) {
- $username = $page[0];
+ elgg_load_library('elgg:blog');
- // push breadcrumb
- elgg_push_breadcrumb(elgg_echo('blog:blogs'), "{$CONFIG->site->url}pg/blog");
+ // forward to correct URL for blog pages pre-1.8
+ blog_url_forwarder($page);
- // forward away if invalid user.
- if (!$user = get_user_by_username($username)) {
- register_error('blog:error:unknown_username');
- forward(REFERER);
- }
+ // push all blogs breadcrumb
+ elgg_push_breadcrumb(elgg_echo('blog:blogs'), "blog/all");
- set_page_owner($user->getGUID());
- $crumbs_title = elgg_echo('blog:owned_blogs', array($user->name));
- $crumbs_url = "{$CONFIG->site->url}pg/blog/$username/read";
- elgg_push_breadcrumb($crumbs_title, $crumbs_url);
-
- $action = isset($page[1]) ? $page[1] : FALSE;
- // 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 'read':
- $title = elgg_echo('blog:title:user_blogs', array($user->name));
- $content_info = blog_get_page_content_read($user->getGUID(), $page2);
- break;
-
- case 'new':
- case 'edit':
- gatekeeper();
- $title = elgg_echo('blog:edit');
- $content_info = blog_get_page_content_edit($page2, $page3);
- break;
-
- case 'archive':
- $title = elgg_echo('blog:archives');
- $content_info = blog_get_page_content_archive($user->getGUID(), $page2, $page3);
- break;
-
- case 'friends':
- $title = elgg_echo('blog:title:friends');
- $content_info = blog_get_page_content_friends($user->getGUID());
- break;
-
- default:
- forward("pg/blog/$username/read/");
- break;
- }
- } else {
- $title = elgg_echo('blog:title:all_blogs');
- $content_info = blog_get_page_content_read();
+ if (!isset($page[0])) {
+ $page[0] = 'all';
}
- $sidebar = isset($content_info['sidebar']) ? $content_info['sidebar'] : '';
-
- $sidebar .= elgg_view('blog/sidebar_menu', array(
- 'page' => isset($page[1]) ? $page[1] : FALSE,
- ));
+ $page_type = $page[0];
+ switch ($page_type) {
+ case 'owner':
+ $user = get_user_by_username($page[1]);
+ if (!$user) {
+ forward('', '404');
+ }
+ $params = blog_get_page_content_list($user->guid);
+ break;
+ case 'friends':
+ $user = get_user_by_username($page[1]);
+ if (!$user) {
+ forward('', '404');
+ }
+ $params = blog_get_page_content_friends($user->guid);
+ break;
+ case 'archive':
+ $user = get_user_by_username($page[1]);
+ if (!$user) {
+ forward('', '404');
+ }
+ $params = blog_get_page_content_archive($user->guid, $page[2], $page[3]);
+ break;
+ case 'view':
+ $params = blog_get_page_content_read($page[1]);
+ break;
+ case 'read': // Elgg 1.7 compatibility
+ register_error(elgg_echo("changebookmark"));
+ forward("blog/view/{$page[1]}");
+ break;
+ case 'add':
+ gatekeeper();
+ $params = blog_get_page_content_edit($page_type, $page[1]);
+ break;
+ case 'edit':
+ gatekeeper();
+ $params = blog_get_page_content_edit($page_type, $page[1], $page[2]);
+ break;
+ case 'group':
+ $group = get_entity($page[1]);
+ if (!elgg_instanceof($group, 'group')) {
+ forward('', '404');
+ }
+ if (!isset($page[2]) || $page[2] == 'all') {
+ $params = blog_get_page_content_list($page[1]);
+ } else {
+ $params = blog_get_page_content_archive($page[1], $page[3], $page[4]);
+ }
+ break;
+ case 'all':
+ $params = blog_get_page_content_list();
+ break;
+ default:
+ return false;
+ }
- $content = elgg_view('navigation/breadcrumbs') . $content_info['content'];
+ if (isset($params['sidebar'])) {
+ $params['sidebar'] .= elgg_view('blog/sidebar', array('page' => $page_type));
+ } else {
+ $params['sidebar'] = elgg_view('blog/sidebar', array('page' => $page_type));
+ }
- $body = elgg_view_layout('one_column_with_sidebar', $content, $sidebar);
+ $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
+ echo elgg_view_page($params['title'], $body);
+ return true;
}
/**
- * Format and return the correct URL for blogs.
+ * Format and return the URL for blogs.
*
- * @param ElggObject $entity
+ * @param ElggObject $entity Blog object
* @return string URL of blog.
*/
function blog_url_handler($entity) {
- if (!$user = get_entity($entity->owner_guid)) {
+ if (!$entity->getOwnerEntity()) {
// default to a standard view if no owner.
return FALSE;
}
$friendly_title = elgg_get_friendly_title($entity->title);
- return "pg/blog/{$user->username}/read/{$entity->guid}/$friendly_title";
+ return "blog/view/{$entity->guid}/$friendly_title";
}
/**
- * Register blogs with ECML.
- *
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $return_value
- * @param unknown_type $params
+ * Add a menu item to an ownerblock
*/
-function blog_ecml_views_hook($hook, $entity_type, $return_value, $params) {
- $return_value['object/blog'] = elgg_echo('blog:blogs');
+function blog_owner_block_menu($hook, $type, $return, $params) {
+ if (elgg_instanceof($params['entity'], 'user')) {
+ $url = "blog/owner/{$params['entity']->username}";
+ $item = new ElggMenuItem('blog', elgg_echo('blog'), $url);
+ $return[] = $item;
+ } else {
+ if ($params['entity']->blog_enable != "no") {
+ $url = "blog/group/{$params['entity']->guid}/all";
+ $item = new ElggMenuItem('blog', elgg_echo('blog:group'), $url);
+ $return[] = $item;
+ }
+ }
- return $return_value;
+ return $return;
}
-function blog_profile_menu($hook, $entity_type, $return_value, $params) {
- global $CONFIG;
+/**
+ * Add particular blog links/info to entity menu
+ */
+function blog_entity_menu_setup($hook, $type, $return, $params) {
+ if (elgg_in_context('widgets')) {
+ return $return;
+ }
+
+ $entity = $params['entity'];
+ $handler = elgg_extract('handler', $params, false);
+ if ($handler != 'blog') {
+ return $return;
+ }
+
+ if ($entity->status != 'published') {
+ // draft status replaces access
+ foreach ($return as $index => $item) {
+ if ($item->getName() == 'access') {
+ unset($return[$index]);
+ }
+ }
- if (!($params['owner'] instanceof ElggGroup)) {
- $return_value[] = array(
- 'text' => elgg_echo('blog'),
- 'href' => "pg/blog/{$params['owner']->username}/read",
+ $status_text = elgg_echo("blog:status:{$entity->status}");
+ $options = array(
+ 'name' => 'published_status',
+ 'text' => "<span>$status_text</span>",
+ 'href' => false,
+ 'priority' => 150,
);
+ $return[] = ElggMenuItem::factory($options);
+ }
+
+ return $return;
+}
+
+/**
+ * Set the notification message body
+ *
+ * @param string $hook Hook name
+ * @param string $type Hook type
+ * @param string $message The current message body
+ * @param array $params Parameters about the blog posted
+ * @return string
+ */
+function blog_notify_message($hook, $type, $message, $params) {
+ $entity = $params['entity'];
+ $to_entity = $params['to_entity'];
+ $method = $params['method'];
+ if (elgg_instanceof($entity, 'object', 'blog')) {
+ $descr = $entity->excerpt;
+ $title = $entity->title;
+ $owner = $entity->getOwnerEntity();
+ return elgg_echo('blog:notification', array(
+ $owner->name,
+ $title,
+ $descr,
+ $entity->getURL()
+ ));
}
+ return null;
+}
+
+/**
+ * Register blogs with ECML.
+ */
+function blog_ecml_views_hook($hook, $entity_type, $return_value, $params) {
+ $return_value['object/blog'] = elgg_echo('blog:blogs');
return $return_value;
}
-register_elgg_event_handler('init', 'system', 'blog_init');
+/**
+ * Upgrade from 1.7 to 1.8.
+ */
+function blog_run_upgrades($event, $type, $details) {
+ $blog_upgrade_version = elgg_get_plugin_setting('upgrade_version', 'blogs');
+
+ if (!$blog_upgrade_version) {
+ // When upgrading, check if the ElggBlog class has been registered as this
+ // was added in Elgg 1.8
+ if (!update_subtype('object', 'blog', 'ElggBlog')) {
+ add_subtype('object', 'blog', 'ElggBlog');
+ }
+
+ elgg_set_plugin_setting('upgrade_version', 1, 'blogs');
+ }
+}
diff --git a/mod/blog/views/default/blog/css.php b/mod/blog/views/default/blog/css.php
index 7578f5955..12ac4df2a 100644
--- a/mod/blog/views/default/blog/css.php
+++ b/mod/blog/views/default/blog/css.php
@@ -5,42 +5,10 @@
* @package Blog
*/
?>
-.blogpost {
- border-bottom:1px dotted #CCCCCC;
-}
-.blogpost .entity_listing_icon {
- margin-top:6px;
-}
-.blogpost .entity_listing_info {
- margin-top:4px;
-}
-.blog_post {
- border-top:1px solid #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
deleted file mode 100644
index 2b07fae94..000000000
--- a/mod/blog/views/default/blog/forms/edit.php
+++ /dev/null
@@ -1,316 +0,0 @@
-<?php
-/**
- * Edit blog form
- *
- * @package Blog
- */
-
-// input names => defaults
-$values = array(
- 'title' => NULL,
- 'description' => NULL,
- 'status' => 'published',
- 'publish_date' => NULL,
- 'access_id' => ACCESS_DEFAULT,
- 'comments_on' => 'On',
- 'excerpt' => NULL,
- 'tags' => NULL,
- 'container_guid' => NULL,
- 'guid' => NULL
-);
-
-$forward = $_SERVER['HTTP_REFERER'];
-
-$action_buttons = '';
-$delete_link = '';
-$draft_warning = '';
-
-// if entity is set, we're editing.
-if (isset ($vars['entity'])) {
- $blog = $vars['entity'];
-
- if (elgg_instanceof($blog, 'object', 'blog')) {
- // passed in values override sticky values in input views
- // if in a sticky form, don't send the overrides and let the view figure it out.
- //if (!elgg_is_sticky_form()) {
- foreach (array_keys($values) as $field) {
- $values[$field] = $blog->$field;
- }
-
- // load the revision annotation if requested
- if (isset($vars['revision']) && $vars['revision'] instanceof ElggAnnotation && $vars['revision']->entity_guid == $blog->getGUID()) {
- $revision = $vars['revision'];
- $values['description'] = $vars['revision']->value;
- }
-
- // display a notice if there's an autosaved annotation
- // and we're not editing it.
- if ($auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1)) {
- $auto_save = $auto_save_annotations[0];
- } else {
- $auto_save == FALSE;
- }
-
- if ($auto_save && $auto_save->id != $revision->id) {
- $draft_warning = '<span class="message warning">'
- . elgg_echo('blog:messages:warning:draft')
- . '</span>';
- }
-
- //}
- } else {
- echo elgg_echo('blog:error:post_not_found');
- return FALSE;
- }
-
- // add a delete button if editing
- $delete_url = "action/blog/delete?guid={$blog->getGUID()}";
- $delete_link = elgg_view('output/confirmlink', array(
- 'href' => $delete_url,
- 'text' => elgg_echo('delete'),
- 'class' => 'action_button disabled'
- ));
-}
-
-$save_button = elgg_view('input/submit', array('value' => elgg_echo('save'), 'class' => 'submit_button'));
-$action_buttons = $save_button . $delete_link;
-
-$title_label = elgg_echo('title');
-$title_input = elgg_view('input/text', array(
- 'internalname' => 'title',
- 'internalid' => 'blog_title',
- 'value' => $values['title']
-));
-
-$excerpt_label = elgg_echo('blog:excerpt');
-$excerpt_input = elgg_view('input/text', array(
- 'internalname' => 'excerpt',
- 'internalid' => 'blog_excerpt',
- 'value' => html_entity_decode($values['excerpt'], ENT_COMPAT, 'UTF-8')
-));
-
-$body_label = elgg_echo('blog:body');
-$body_input = elgg_view('input/longtext', array(
- 'internalname' => 'description',
- 'internalid' => 'blog_description',
- 'value' => $values['description']
-));
-
-$save_status = elgg_echo('blog:save_status');
-if ($values['publish_date']) {
- $saved = date('F j, Y @ H:i', $values['publish_date']);
-} else {
- $saved = elgg_echo('blog:never');
-}
-
-$status_label = elgg_echo('blog:status');
-$status_input = elgg_view('input/pulldown', array(
- 'internalname' => 'status',
- 'internalid' => 'blog_status',
- 'value' => $values['status'],
- 'options_values' => array(
- 'draft' => elgg_echo('blog:status:draft'),
- 'published' => elgg_echo('blog:status:published')
- )
-));
-
-$comments_label = elgg_echo('comments');
-$comments_input = elgg_view('input/pulldown', array(
- 'internalname' => 'comments_on',
- 'internalid' => 'blog_comments_on',
- 'value' => $values['comments_on'],
- 'options_values' => array('On' => elgg_echo('on'), 'Off' => elgg_echo('off'))
-));
-
-$tags_label = elgg_echo('tags');
-$tags_input = elgg_view('input/tags', array(
- 'internalname' => 'tags',
- 'internalid' => 'blog_tags',
- 'value' => $values['tags']
-));
-
-$access_label = elgg_echo('access');
-$access_input = elgg_view('input/access', array(
- 'internalname' => 'access_id',
- 'internalid' => 'blog_access_id',
- 'value' => $values['access_id']
-));
-
-$publish_date_label = elgg_echo('blog:publish_date');
-$publish_date_input = elgg_view('input/datetime', array(
- 'internalname' => 'publish_date',
- 'internalid' => 'blog_publish_date',
- 'value' => $values['publish_date']
-));
-
-$categories_input = elgg_view('categories', $vars);
-
-// hidden inputs
-//$container_guid_input = elgg_view('input/hidden', array('internalname' => 'container_guid', 'value' => $values['container_guid']));
-$guid_input = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $values['guid']));
-$forward_input = elgg_view('input/hidden', array('internalname' => 'forward', 'value' => $forward));
-
-// editing or creating.
-if (isset($values['guid'])) {
- $page_title = elgg_echo('blog:edit') . ": \"{$values['title']}\"";
-} else {
- $page_title = elgg_echo('blog:new');
-}
-
-// display notice if editing an old revision
-if (isset($vars['revision']) && $vars['revision'] instanceof ElggAnnotation) {
- $page_title .= ' ' . elgg_echo('blog:edit_revision_notice');
-}
-
-$form_body = <<<___END
-<h2>$page_title</h2>
-
-$draft_warning
-
-<p class="margin_top">
- <label for="blog_title">$title_label</label>
- $title_input
-</p>
-
-<p>
- <label for="blog_excerpt">$excerpt_label</label>
-$excerpt_input
-</p>
-
-<label for="blog_description">$body_label</label>
-$body_input
-<br />
-
-<p>
- <label for="blog_tags">$tags_label</label>
- $tags_input
-</p>
-
-<p>
- <label for="blog_comments_on">$comments_label</label>
- $comments_input
-</p>
-
-<p>
- <label for="blog_access_id">$access_label</label>
- $access_input
-</p>
-
-<p>
- <label for="blog_status">$status_label</label>
- $status_input
-</p>
-
-$categories_input
-
-<div class="divider"></div>
-<p class="margin_none margin_top entity_subtext">
- $save_status <span class="blog_save_status_time">$saved</span>
-</p>
-
-$guid_input
-$container_guid_input
-$forward_input
-
-$action_buttons
-
-___END;
-
-echo elgg_view('input/form', array(
- 'internalid' => 'blog_post_edit',
- 'internalname' => 'blog_post',
- 'action' => "action/blog/save",
- 'body' => $form_body
-));
-
-elgg_clear_sticky_form('blog');
-
-?>
-
-<script type="text/javascript">
- setInterval("blogSaveDraft()", 60000);
-
- /*
- * Attempt to save and update the input with the guid.
- */
- function blogSaveDraftCallback(data, textStatus, XHR) {
- if (textStatus == 'success' && data.success == true) {
- var form = $('form[name=blog_post]');
-
- // update the guid input element for new posts that now have a guid
- form.find('input[name=guid]').val(data.guid);
-
- oldDescription = form.find('textarea[name=description]').val();
-
- 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);
- } else {
- $(".blog_save_status_time").html("<?php echo elgg_echo('error'); ?>");
- }
- }
-
- function blogSaveDraft() {
- if (typeof(tinyMCE) != 'undefined') {
- tinyMCE.triggerSave();
- }
-
- // only save on changed content
- var form = $('form[name=blog_post]');
- var description = form.find('textarea[name=description]').val();
- var title = form.find('input[name=title]').val();
-
- if (!(description && title) || (description == oldDescription)) {
- return false;
- }
-
- var draftURL = "<?php echo elgg_get_site_url(); ?>action/blog/auto_save_revision";
- var postData = form.serializeArray();
-
- // force draft status
- $(postData).each(function(i, e) {
- if (e.name == 'status') {
- e.value = 'draft';
- }
- });
-
- $.post(draftURL, postData, blogSaveDraftCallback, 'json');
- }
-
- $(document).ready(function() {
- // get a copy of the body to compare for auto save
- oldDescription = $('form[name=blog_post]').find('textarea[name=description]').val();
-
-/* we don't seems to be using the text counter anymore�
- $('#excerpt.excerpt').each(function(){
- var allowed = 200;
-
- // set the initial value
- $('#countervalue').text(allowed);
-
- // bind on key up event
- $(this).keyup(function(){
- var counter_value = ((allowed - ($(this).val().length)));
-
- $("#countervalue").removeClass();
-
- if ((counter_value > 10)) {
- $("#countervalue").addClass("positive");
- }
- else if ((counter_value <= 10) && (counter_value >= 0)) {
- $("#countervalue").addClass("gettingclose");
- }
- else if ((counter_value < 0)) {
- $("#countervalue").addClass("negative");
- }
-
- // insert new length
- $('#countervalue').text(counter_value);
-
- });
- });
-*/
- });
-
-</script> \ No newline at end of file
diff --git a/mod/blog/views/default/blog/group_module.php b/mod/blog/views/default/blog/group_module.php
new file mode 100644
index 000000000..6082cdafd
--- /dev/null
+++ b/mod/blog/views/default/blog/group_module.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Group blog module
+ */
+
+$group = elgg_get_page_owner_entity();
+
+if ($group->blog_enable == "no") {
+ return true;
+}
+
+$all_link = elgg_view('output/url', array(
+ 'href' => "blog/group/$group->guid/all",
+ 'text' => elgg_echo('link:view:all'),
+ 'is_trusted' => true,
+));
+
+elgg_push_context('widgets');
+$options = array(
+ 'type' => 'object',
+ 'subtype' => 'blog',
+ 'container_guid' => elgg_get_page_owner_guid(),
+ 'metadata_name_value_pairs' => array('name' => 'status', 'value' => 'published'),
+ 'limit' => 6,
+ 'full_view' => false,
+ 'pagination' => false,
+);
+$content = elgg_list_entities_from_metadata($options);
+elgg_pop_context();
+
+if (!$content) {
+ $content = '<p>' . elgg_echo('blog:none') . '</p>';
+}
+
+$new_link = elgg_view('output/url', array(
+ 'href' => "blog/add/$group->guid",
+ 'text' => elgg_echo('blog:write'),
+ 'is_trusted' => true,
+));
+
+echo elgg_view('groups/profile/module', array(
+ 'title' => elgg_echo('blog:group'),
+ 'content' => $content,
+ 'all_link' => $all_link,
+ 'add_link' => $new_link,
+));
diff --git a/mod/blog/views/default/blog/sidebar.php b/mod/blog/views/default/blog/sidebar.php
new file mode 100644
index 000000000..0ae2b431c
--- /dev/null
+++ b/mod/blog/views/default/blog/sidebar.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Blog sidebar
+ *
+ * @package Blog
+ */
+
+// fetch & display latest comments
+if ($vars['page'] == 'all') {
+ echo elgg_view('page/elements/comments_block', array(
+ 'subtypes' => 'blog',
+ ));
+} elseif ($vars['page'] == 'owner') {
+ echo elgg_view('page/elements/comments_block', array(
+ 'subtypes' => 'blog',
+ 'owner_guid' => elgg_get_page_owner_guid(),
+ ));
+}
+
+// only users can have archives at present
+if ($vars['page'] == 'owner' || $vars['page'] == 'group') {
+ echo elgg_view('blog/sidebar/archives', $vars);
+}
+
+if ($vars['page'] != 'friends') {
+ echo elgg_view('page/elements/tagcloud_block', array(
+ 'subtypes' => 'blog',
+ 'owner_guid' => elgg_get_page_owner_guid(),
+ ));
+}
diff --git a/mod/blog/views/default/blog/sidebar/archives.php b/mod/blog/views/default/blog/sidebar/archives.php
new file mode 100644
index 000000000..5098e6e3e
--- /dev/null
+++ b/mod/blog/views/default/blog/sidebar/archives.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Blog archives
+ */
+
+$loggedin_user = elgg_get_logged_in_user_entity();
+$page_owner = elgg_get_page_owner_entity();
+
+if (elgg_instanceof($page_owner, 'user')) {
+ $url_segment = 'blog/archive/' . $page_owner->username;
+} else {
+ $url_segment = 'blog/group/' . $page_owner->getGUID() . '/archive';
+}
+
+// This is a limitation of the URL schema.
+if ($page_owner && $vars['page'] != 'friends') {
+ $dates = array_reverse(get_entity_dates('object', 'blog', $page_owner->getGUID()));
+
+ if ($dates) {
+ $title = elgg_echo('blog:archives');
+ $content = '<ul class="blog-archives">';
+ foreach ($dates as $date) {
+ $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() . $url_segment . '/' . $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>";
+ }
+ $content .= '</ul>';
+
+ echo elgg_view_module('aside', $title, $content);
+ }
+} \ No newline at end of file
diff --git a/mod/blog/views/default/blog/sidebar_revisions.php b/mod/blog/views/default/blog/sidebar/revisions.php
index e53ba9e52..cd2e7f3d8 100644
--- a/mod/blog/views/default/blog/sidebar_revisions.php
+++ b/mod/blog/views/default/blog/sidebar/revisions.php
@@ -6,18 +6,20 @@
*/
//If editing a post, show the previous revisions and drafts.
-$blog = isset($vars['entity']) ? $vars['entity'] : FALSE;
+$blog = elgg_extract('entity', $vars, FALSE);
if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
$owner = $blog->getOwnerEntity();
$revisions = array();
- if ($auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1)) {
+ $auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1);
+ if ($auto_save_annotations) {
$revisions[] = $auto_save_annotations[0];
}
// count(FALSE) == 1! AHHH!!!
- if ($saved_revisions = $blog->getAnnotations('blog_revision', 10, 0, 'time_created DESC')) {
+ $saved_revisions = $blog->getAnnotations('blog_revision', 10, 0, 'time_created DESC');
+ if ($saved_revisions) {
$revision_count = count($saved_revisions);
} else {
$revision_count = 0;
@@ -26,52 +28,52 @@ if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
$revisions = array_merge($revisions, $saved_revisions);
if ($revisions) {
- echo '<h3>' . elgg_echo('blog:revisions') . '</h3>';
+ $title = elgg_echo('blog:revisions');
$n = count($revisions);
- echo '<ul class="blog_revisions">';
+ $body = '<ul class="blog-revisions">';
- $load_base_url = "pg/blog/{$owner->username}/edit/{$blog->getGUID()}/";
+ $load_base_url = "blog/edit/{$blog->getGUID()}";
// show the "published revision"
if ($blog->status == 'published') {
$load = elgg_view('output/url', array(
'href' => $load_base_url,
- 'text' => elgg_echo('blog:status:published')
+ 'text' => elgg_echo('blog:status:published'),
+ 'is_trusted' => true,
));
- $time = "<span class='entity_subtext'>".elgg_view_friendly_time($blog->publish_date)."</span>";
+ $time = "<span class='elgg-subtext'>"
+ . elgg_view_friendly_time($blog->time_created) . "</span>";
- echo '<li>
- ' . $load . ": $time
- </li>";
+ $body .= "<li>$load : $time</li>";
}
foreach ($revisions as $revision) {
- $time = "<span class='entity_subtext'>".elgg_view_friendly_time($revision->time_created)."</span>";
+ $time = "<span class='elgg-subtext'>"
+ . elgg_view_friendly_time($revision->time_created) . "</span>";
+
if ($revision->name == 'blog_auto_save') {
$revision_lang = elgg_echo('blog:auto_saved_revision');
} else {
$revision_lang = elgg_echo('blog:revision') . " $n";
}
$load = elgg_view('output/url', array(
- 'href' => $load_base_url . $revision->id,
- 'text' => $revision_lang
+ 'href' => "$load_base_url/$revision->id",
+ 'text' => $revision_lang,
+ 'is_trusted' => true,
));
$text = "$load: $time";
- $class = 'class="auto_saved"';
+ $class = 'class="auto-saved"';
$n--;
- echo <<<___END
-<li $class>
-$text
-</li>
-
-___END;
+ $body .= "<li $class>$text</li>";
}
- echo '</ul>';
+ $body .= '</ul>';
+
+ echo elgg_view_module('aside', $title, $body);
}
} \ No newline at end of file
diff --git a/mod/blog/views/default/blog/sidebar_edit.php b/mod/blog/views/default/blog/sidebar_edit.php
deleted file mode 100644
index 9b56f9a73..000000000
--- a/mod/blog/views/default/blog/sidebar_edit.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/**
- * Blog sidebar menu for editing / creating a blog post.
- *
- * @package Blog
- */
-
-//If editing a post, show the previous revisions and drafts.
-$blog_guid = isset($vars['blog_guid']) ? $vars['blog_guid'] : FALSE;
-$blog = get_entity($blog_guid);
-
-if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
- $revisions = array();
- if ($auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1)) {
- $revisions[] = $auto_save_annotations[0];
- }
-
- // count(FALSE) == 1! AHHH!!!
- if ($saved_revisions = $blog->getAnnotations('blog_revision', 10, 0, 'time_created DESC')) {
- $revision_count = count($saved_revisions);
- } else {
- $revision_count = 0;
- }
-
- $revisions = array_merge($revisions, $saved_revisions);
-}
-
-if ($revisions) {
- echo '<ul class="blog_revisions">';
- $load_base_url = "pg/blog/{$owner->username}/edit/{$blog->getGUID()}/";
-
- foreach ($revisions as $revision) {
- $time = elgg_view_friendly_time($revision->time_created);
- $load = elgg_view('output/url', array(
- 'href' => $load_base_url . $revision->id,
- 'text' => elgg_echo('load')
- ));
-
-
- if ($revision->name == 'blog_auto_save') {
- $name = elgg_echo('blog:auto_saved_revision');
- $text = "$name: $time $load";
- $class = 'class="auto_saved"';
- } else {
- $name = elgg_echo('blog:revision');
- $text = "$name: $time $load";
- $class = 'class="auto_saved"';
-
- $revision_count--;
- }
-
- echo <<<___END
-<li $class>
-$text
-</li>
-
-___END;
- }
-
- echo '</ul>';
-} \ No newline at end of file
diff --git a/mod/blog/views/default/blog/sidebar_menu.php b/mod/blog/views/default/blog/sidebar_menu.php
deleted file mode 100644
index 120237ac5..000000000
--- a/mod/blog/views/default/blog/sidebar_menu.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-/**
- * Blog sidebar menu.
- *
- * @package Blog
- */
-
-// a few cases to consider:
-// 1. looking at all posts
-// 2. looking at a user's post
-// 3. looking at your posts
-
-/*
-Logged in or not doesn't matter unless you're looking at your blog.
- Does it matter then on the side bar?
-
-All blogs:
- Archives
-
-Owned blogs;
- Archives
-*/
-
-$loggedin_user = get_loggedin_user();
-$page_owner = elgg_get_page_owner();
-
-// include a view for plugins to extend
-echo elgg_view("blogs/sidebar", array("object_type" => 'blog'));
-
-// fetch & display latest comments on all blog posts
-$comments = get_annotations(0, "object", "blog", "generic_comment", "", 0, 4, 0, "desc");
-echo elgg_view('annotation/latest_comments', array('comments' => $comments));
-
-// only show archives for users or groups.
-// This is a limitation of the URL schema.
-if ($page_owner) {
- $dates = blog_get_blog_months($user);
-
- if ($dates) {
- echo "<h3>" . elgg_echo('blog:archives') . "</h3>";
- echo '<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));
-
- if (!isset($page_owner)) {
- $page_owner = elgg_get_page_owner();
- }
-
- $link = elgg_get_site_url() . 'pg/blog/' . $page_owner->username . '/archive/' . $timestamplow . '/' . $timestamphigh;
- $month = elgg_echo('date:month:' . substr($date, 4, 2), array(substr($date, 0, 4)));
- echo "<li><a href=\"$link\" title=\"$month\">$month</a></li>";
- }
-
- echo '</ul>';
- }
-
- // friends page lists all tags; mine lists owner's
- $owner_guid = ($vars['page'] == 'friends') ? '' : $page_owner->getGUID();
- echo display_tagcloud(0, 50, 'tags', 'object', 'blog', $owner_guid);
-} else {
- echo display_tagcloud(0, 50, 'tags', 'object', 'blog');
-}
diff --git a/mod/blog/views/default/forms/blog/save.php b/mod/blog/views/default/forms/blog/save.php
new file mode 100644
index 000000000..f825acca1
--- /dev/null
+++ b/mod/blog/views/default/forms/blog/save.php
@@ -0,0 +1,166 @@
+<?php
+/**
+ * Edit blog form
+ *
+ * @package Blog
+ */
+
+$blog = get_entity($vars['guid']);
+$vars['entity'] = $blog;
+
+$draft_warning = $vars['draft_warning'];
+if ($draft_warning) {
+ $draft_warning = '<span class="mbm elgg-text-help">' . $draft_warning . '</span>';
+}
+
+$action_buttons = '';
+$delete_link = '';
+$preview_button = '';
+
+if ($vars['guid']) {
+ // add a delete button if editing
+ $delete_url = "action/blog/delete?guid={$vars['guid']}";
+ $delete_link = elgg_view('output/confirmlink', array(
+ 'href' => $delete_url,
+ 'text' => elgg_echo('delete'),
+ 'class' => 'elgg-button elgg-button-delete float-alt'
+ ));
+}
+
+// published blogs do not get the preview button
+if (!$vars['guid'] || ($blog && $blog->status != 'published')) {
+ $preview_button = elgg_view('input/submit', array(
+ 'value' => elgg_echo('preview'),
+ 'name' => 'preview',
+ 'class' => 'mls',
+ ));
+}
+
+$save_button = elgg_view('input/submit', array(
+ 'value' => elgg_echo('save'),
+ 'name' => 'save',
+));
+$action_buttons = $save_button . $preview_button . $delete_link;
+
+$title_label = elgg_echo('title');
+$title_input = elgg_view('input/text', array(
+ 'name' => 'title',
+ 'id' => 'blog_title',
+ 'value' => $vars['title']
+));
+
+$excerpt_label = elgg_echo('blog:excerpt');
+$excerpt_input = elgg_view('input/text', array(
+ 'name' => 'excerpt',
+ 'id' => 'blog_excerpt',
+ 'value' => _elgg_html_decode($vars['excerpt'])
+));
+
+$body_label = elgg_echo('blog:body');
+$body_input = elgg_view('input/longtext', array(
+ 'name' => 'description',
+ 'id' => 'blog_description',
+ 'value' => $vars['description']
+));
+
+$save_status = elgg_echo('blog:save_status');
+if ($vars['guid']) {
+ $entity = get_entity($vars['guid']);
+ $saved = date('F j, Y @ H:i', $entity->time_created);
+} else {
+ $saved = elgg_echo('blog:never');
+}
+
+$status_label = elgg_echo('blog:status');
+$status_input = elgg_view('input/dropdown', array(
+ 'name' => 'status',
+ 'id' => 'blog_status',
+ 'value' => $vars['status'],
+ 'options_values' => array(
+ 'draft' => elgg_echo('blog:status:draft'),
+ 'published' => elgg_echo('blog:status:published')
+ )
+));
+
+$comments_label = elgg_echo('comments');
+$comments_input = elgg_view('input/dropdown', array(
+ 'name' => 'comments_on',
+ 'id' => 'blog_comments_on',
+ 'value' => $vars['comments_on'],
+ 'options_values' => array('On' => elgg_echo('on'), 'Off' => elgg_echo('off'))
+));
+
+$tags_label = elgg_echo('tags');
+$tags_input = elgg_view('input/tags', array(
+ 'name' => 'tags',
+ 'id' => 'blog_tags',
+ 'value' => $vars['tags']
+));
+
+$access_label = elgg_echo('access');
+$access_input = elgg_view('input/access', array(
+ 'name' => 'access_id',
+ 'id' => 'blog_access_id',
+ 'value' => $vars['access_id']
+));
+
+$categories_input = elgg_view('input/categories', $vars);
+
+// hidden inputs
+$container_guid_input = elgg_view('input/hidden', array('name' => 'container_guid', 'value' => elgg_get_page_owner_guid()));
+$guid_input = elgg_view('input/hidden', array('name' => 'guid', 'value' => $vars['guid']));
+
+
+echo <<<___HTML
+
+$draft_warning
+
+<div>
+ <label for="blog_title">$title_label</label>
+ $title_input
+</div>
+
+<div>
+ <label for="blog_excerpt">$excerpt_label</label>
+ $excerpt_input
+</div>
+
+<div>
+ <label for="blog_description">$body_label</label>
+ $body_input
+</div>
+
+<div>
+ <label for="blog_tags">$tags_label</label>
+ $tags_input
+</div>
+
+$categories_input
+
+<div>
+ <label for="blog_comments_on">$comments_label</label>
+ $comments_input
+</div>
+
+<div>
+ <label for="blog_access_id">$access_label</label>
+ $access_input
+</div>
+
+<div>
+ <label for="blog_status">$status_label</label>
+ $status_input
+</div>
+
+<div class="elgg-foot">
+ <div class="elgg-subtext mbm">
+ $save_status <span class="blog-save-status-time">$saved</span>
+ </div>
+
+ $guid_input
+ $container_guid_input
+
+ $action_buttons
+</div>
+
+___HTML;
diff --git a/mod/blog/views/default/input/datetime.php b/mod/blog/views/default/input/datetime.php
deleted file mode 100644
index 5586464f1..000000000
--- a/mod/blog/views/default/input/datetime.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * A date-time view for the blog publication date.
- */
-
-// default date to current time
-$publish_date = ($vars['value']) ? $vars['value'] : time();
-
-$months = array();
-for ($i=1; $i <= 12; $i++) {
- $value = str_pad($i, 2, '0', STR_PAD_LEFT);
- $months[$value] = date('M', strtotime("$value/01/2010"));
-}
-
-$month = elgg_view('input/pulldown', array(
- 'internalname' => 'publish_month',
- 'value' => date('m', $publish_date),
- 'options_values' => $months,
- 'class' => 'blog_publish_month',
-));
-
-$day = elgg_view('input/text', array(
- 'internalname' => 'publish_day',
- 'value' => date('d', $publish_date),
- 'class' => 'blog_publish_day',
-));
-
-$year = elgg_view('input/text', array(
- 'internalname' => 'publish_year',
- 'value' => date('Y', $publish_date),
- 'class' => 'blog_publish_year',
-));
-
-$hour = elgg_view('input/text', array(
- 'internalname' => 'publish_hour',
- 'value' => date('H', $publish_date),
- 'class' => 'blog_publish_hour',
-));
-
-$minute = elgg_view('input/text', array(
- 'internalname' => 'publish_minute',
- 'value' => date('i', $publish_date),
- 'class' => 'blog_publish_minute',
-));
-
-echo "$month $day, $year @ $hour:$minute";
diff --git a/mod/blog/views/default/js/blog/save_draft.php b/mod/blog/views/default/js/blog/save_draft.php
new file mode 100644
index 000000000..8cd07ff5d
--- /dev/null
+++ b/mod/blog/views/default/js/blog/save_draft.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Save draft through ajax
+ *
+ * @package Blog
+ */
+?>
+elgg.provide('elgg.blog');
+
+/*
+ * Attempt to save and update the input with the guid.
+ */
+elgg.blog.saveDraftCallback = function(data, textStatus, XHR) {
+ if (textStatus == 'success' && data.success == true) {
+ var form = $('form[id=blog-post-edit]');
+
+ // update the guid input element for new posts that now have a guid
+ form.find('input[name=guid]').val(data.guid);
+
+ oldDescription = form.find('textarea[name=description]').val();
+
+ 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);
+ } else {
+ $(".blog-save-status-time").html(elgg.echo('error'));
+ }
+};
+
+elgg.blog.saveDraft = function() {
+ if (typeof(tinyMCE) != 'undefined') {
+ tinyMCE.triggerSave();
+ }
+
+ // only save on changed content
+ var form = $('form[id=blog-post-edit]');
+ var description = form.find('textarea[name=description]').val();
+ var title = form.find('input[name=title]').val();
+
+ if (!(description && title) || (description == oldDescription)) {
+ return false;
+ }
+
+ var draftURL = elgg.config.wwwroot + "action/blog/auto_save_revision";
+ var postData = form.serializeArray();
+
+ // force draft status
+ $(postData).each(function(i, e) {
+ if (e.name == 'status') {
+ e.value = 'draft';
+ }
+ });
+
+ $.post(draftURL, postData, elgg.blog.saveDraftCallback, 'json');
+};
+
+elgg.blog.init = function() {
+ // get a copy of the body to compare for auto save
+ oldDescription = $('form[id=blog-post-edit]').find('textarea[name=description]').val();
+
+ setInterval(elgg.blog.saveDraft, 60000);
+};
+
+elgg.register_hook_handler('init', 'system', elgg.blog.init); \ No newline at end of file
diff --git a/mod/blog/views/default/object/blog.php b/mod/blog/views/default/object/blog.php
index 7f91ae608..4403a6006 100644
--- a/mod/blog/views/default/object/blog.php
+++ b/mod/blog/views/default/object/blog.php
@@ -5,119 +5,95 @@
* @package Blog
*/
-$full = (isset($vars['full'])) ? $vars['full'] : FALSE;
-$blog = (isset($vars['entity'])) ? $vars['entity'] : FALSE;
+$full = elgg_extract('full_view', $vars, FALSE);
+$blog = elgg_extract('entity', $vars, FALSE);
if (!$blog) {
- return '';
+ return TRUE;
}
-$owner = get_entity($blog->owner_guid);
-$container = get_entity($blog->container_guid);
-$linked_title = "<a href=\"{$blog->getURL()}\" title=\"" . htmlentities($blog->title) . "\">{$blog->title}</a>";
-$categories = elgg_view('categories/view', $vars);
+$owner = $blog->getOwnerEntity();
+$container = $blog->getContainerEntity();
+$categories = elgg_view('output/categories', $vars);
$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>";
-$author_text = elgg_echo('blog:author_by_line', array($owner_blog_link));
-if($blog->tags){
- $tags = "<p class=\"tags\">" . elgg_view('output/tags', array('tags' => $blog->tags)) . "</p>";
-}else{
- $tags = "";
+if (!$excerpt) {
+ $excerpt = elgg_get_excerpt($blog->description);
}
-$date = elgg_view_friendly_time($blog->publish_date);
+
+$owner_icon = elgg_view_entity_icon($owner, 'tiny');
+$owner_link = elgg_view('output/url', array(
+ 'href' => "blog/owner/$owner->username",
+ 'text' => $owner->name,
+ 'is_trusted' => true,
+));
+$author_text = elgg_echo('byline', array($owner_link));
+$date = elgg_view_friendly_time($blog->time_created);
// The "on" status changes for comments, so best to check for !Off
if ($blog->comments_on != 'Off') {
- $comments_count = elgg_count_comments($blog);
+ $comments_count = $blog->countComments();
//only display if there are commments
- if($comments_count != 0){
- $comments_link = "<a href=\"{$blog->getURL()}#annotations\">" . elgg_echo("comments") . " (". $comments_count .")</a>";
- }else{
+ if ($comments_count != 0) {
+ $text = elgg_echo("comments") . " ($comments_count)";
+ $comments_link = elgg_view('output/url', array(
+ 'href' => $blog->getURL() . '#blog-comments',
+ 'text' => $text,
+ 'is_trusted' => true,
+ ));
+ } else {
$comments_link = '';
}
} else {
$comments_link = '';
}
-// links to delete or edit.
-
-// access is always shown.
-$edit = elgg_view('output/access', array('entity' => $vars['entity']));
+$metadata = elgg_view_menu('entity', array(
+ 'entity' => $vars['entity'],
+ 'handler' => 'blog',
+ 'sort_by' => 'priority',
+ 'class' => 'elgg-menu-hz',
+));
-if ($blog->canEdit()) {
- $edit_url = elgg_get_site_url()."pg/blog/{$owner->username}/edit/{$blog->getGUID()}/";
- $edit_link = "<span class='entity_edit'><a href=\"$edit_url\">" . elgg_echo('edit') . '</a></span>';
+$subtitle = "$author_text $date $comments_link $categories";
- $delete_url = "action/blog/delete?guid={$blog->getGUID()}";
- $delete_link = "<span class='delete_button'>" . elgg_view('output/confirmlink', array(
- 'href' => $delete_url,
- 'text' => elgg_echo('delete'),
- 'confirm' => elgg_echo('deleteconfirm')
- )) . "</span>";
-
- $status = '';
- if ($blog->status != 'published') {
- $status_text = elgg_echo("blog:status:{$blog->status}");
- $status = "<span class='blog_status'>$status_text</span>";
- }
-
- $edit .= "$status $edit_link $delete_link";
+// do not show the metadata and controls in widget view
+if (elgg_in_context('widgets')) {
+ $metadata = '';
}
- // include a view for plugins to extend
- $edit = elgg_view("blogs/options", array("object_type" => 'blog', 'entity' => $blog)) .
- elgg_view_likes($blog) . // include likes
- $edit;
-
if ($full) {
-echo <<<___END
-<div class="blogpost clearfix">
- <div id="content_header" class="clearfix">
- <div class="content_header_title"><h2>{$blog->title}</h2></div>
- </div>
- <div class="clearfix">
- <div class="entity_listing_icon">
- $owner_icon
- </div>
- <div class="entity_listing_info">
- <div class="entity_metadata">$edit</div>
- <p class="entity_subtext">
- $author_text
- $date
- $categories
- $comments_link
- </p>
- $tags
- </div>
- </div>
- <div class='blog_post'>$body</div>
-</div>
-
-___END;
+ $body = elgg_view('output/longtext', array(
+ 'value' => $blog->description,
+ 'class' => 'blog-post',
+ ));
+
+ $params = array(
+ 'entity' => $blog,
+ 'title' => false,
+ 'metadata' => $metadata,
+ 'subtitle' => $subtitle,
+ );
+ $params = $params + $vars;
+ $summary = elgg_view('object/elements/summary', $params);
+
+ echo elgg_view('object/elements/full', array(
+ 'summary' => $summary,
+ 'icon' => $owner_icon,
+ 'body' => $body,
+ ));
} else {
- echo <<<___END
-<div class="blog $status_class entity_listing clearfix">
- <div class="entity_listing_icon">
- $owner_icon
- </div>
- <div class="entity_listing_info">
- <div class="entity_metadata">$edit</div>
- <p class="entity_title">$linked_title</p>
- <p class="entity_subtext">
- $author_text
- $date
- $categories
- $comments_link
- </p>
- $tags
- <p>$excerpt</p>
- </div>
-</div>
-
-___END;
+ // brief view
+
+ $params = array(
+ 'entity' => $blog,
+ 'metadata' => $metadata,
+ 'subtitle' => $subtitle,
+ 'content' => $excerpt,
+ );
+ $params = $params + $vars;
+ $list_body = elgg_view('object/elements/summary', $params);
+
+ echo elgg_view_image_block($owner_icon, $list_body);
}
diff --git a/mod/blog/views/default/river/object/blog/create.php b/mod/blog/views/default/river/object/blog/create.php
index d311c5883..b808f1bdc 100644
--- a/mod/blog/views/default/river/object/blog/create.php
+++ b/mod/blog/views/default/river/object/blog/create.php
@@ -3,27 +3,13 @@
* Blog river view.
*/
-$performed_by = get_entity($vars['item']->subject_guid);
-$object = get_entity($vars['item']->object_guid);
-$url = $object->getURL();
-$contents = strip_tags($object->excerpt);
+$object = $vars['item']->getObjectEntity();
-$url = "<a href=\"{$performed_by->getURL()}\">{$performed_by->name}</a>";
-$title = elgg_echo('blog:river:create', array($url));
-$string .= $title . " <a href=\"{$object->getURL()}\">{$object->title}</a> <span class='entity_subtext'>" . elgg_view_friendly_time($object->time_created);
+$excerpt = $object->excerpt ? $object->excerpt : $object->description;
+$excerpt = strip_tags($excerpt);
+$excerpt = elgg_get_excerpt($excerpt);
-if (isloggedin()) {
- $string .= '<a class="river_comment_form_button link">' . elgg_echo('generic_comments:text') . '</a>';
- $string .= elgg_view('likes/forms/link', array('entity' => $object));
-}
-$string .= "</span>";
-
-$string .= '<div class="river_content_display">';
-$string .= '<div class="river_object_blog_create"></div>';
-if (strlen($contents) > 200) {
- $string .= substr($contents, 0, strpos($contents, ' ', 200)) . '&hellip;';
-} else {
- $string .= $contents;
-}
-$string .= '</div>';
-echo $string; \ No newline at end of file
+echo elgg_view('river/elements/layout', array(
+ 'item' => $vars['item'],
+ 'message' => $excerpt,
+));
diff --git a/mod/blog/views/default/widgets/blog/content.php b/mod/blog/views/default/widgets/blog/content.php
new file mode 100644
index 000000000..330171662
--- /dev/null
+++ b/mod/blog/views/default/widgets/blog/content.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * User blog widget display view
+ */
+
+$num = $vars['entity']->num_display;
+
+$options = array(
+ 'type' => 'object',
+ 'subtype' => 'blog',
+ 'container_guid' => $vars['entity']->owner_guid,
+ 'limit' => $num,
+ 'full_view' => FALSE,
+ 'pagination' => FALSE,
+);
+$content = elgg_list_entities($options);
+
+echo $content;
+
+if ($content) {
+ $blog_url = "blog/owner/" . elgg_get_page_owner_entity()->username;
+ $more_link = elgg_view('output/url', array(
+ 'href' => $blog_url,
+ 'text' => elgg_echo('blog:moreblogs'),
+ 'is_trusted' => true,
+ ));
+ echo "<span class=\"elgg-widget-more\">$more_link</span>";
+} else {
+ echo elgg_echo('blog:noblogs');
+}
diff --git a/mod/blog/views/default/widgets/blog/edit.php b/mod/blog/views/default/widgets/blog/edit.php
new file mode 100644
index 000000000..30c3b2e73
--- /dev/null
+++ b/mod/blog/views/default/widgets/blog/edit.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * User blog widget edit view
+ */
+
+// 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('blog:numbertodisplay'); ?>:
+ <?php echo $dropdown; ?>
+</div>