aboutsummaryrefslogtreecommitdiff
path: root/mod/blog
diff options
context:
space:
mode:
Diffstat (limited to 'mod/blog')
-rw-r--r--mod/blog/languages/en.php1
-rw-r--r--mod/blog/lib/blog.php226
-rw-r--r--mod/blog/views/default/blog/forms/edit.php318
-rw-r--r--mod/blog/views/default/forms/blog/save.php157
-rw-r--r--mod/blog/views/default/js/blog/save_draft.php97
5 files changed, 407 insertions, 392 deletions
diff --git a/mod/blog/languages/en.php b/mod/blog/languages/en.php
index 843d62932..15708f30b 100644
--- a/mod/blog/languages/en.php
+++ b/mod/blog/languages/en.php
@@ -49,6 +49,7 @@ $english = array(
'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',
diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php
index 108f300cb..b1c7c280f 100644
--- a/mod/blog/lib/blog.php
+++ b/mod/blog/lib/blog.php
@@ -7,10 +7,10 @@
/**
- * Returns HTML for a blog post.
+ * Get page components to view a blog post.
*
- * @param int $guid of a blog entity.
- * @return string html
+ * @param int $guid GUID of a blog entity.
+ * @return array
*/
function blog_get_page_content_read($guid = NULL) {
@@ -38,10 +38,10 @@ function blog_get_page_content_read($guid = NULL) {
}
/**
- * Returns HTML for listing a user's or all blogs.
+ * Get page components to list a user's or all blogs.
*
* @param int $owner_guid The GUID of the page owner or NULL for all blogs
- * @return string html
+ * @return array
*/
function blog_get_page_content_list($owner_guid = NULL) {
@@ -91,60 +91,66 @@ function blog_get_page_content_list($owner_guid = NULL) {
}
/**
- * Returns HTML to edit a blog post.
+ * Get page components to list of the user's friends' posts.
*
- * @param int $guid
- * @param int annotation id optional revision to edit
- * @return string html
+ * @param int $user_guid
+ * @return array
*/
-function blog_get_page_content_edit($guid, $revision = NULL) {
- $vars = array();
- if ($guid) {
- $blog = get_entity((int)$guid);
+function blog_get_page_content_friends($user_guid) {
- if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
- $vars['entity'] = $blog;
+ elgg_push_breadcrumb(elgg_echo('friends'));
- if ($revision) {
- $revision = get_annotation((int)$revision);
- $vars['revision'] = $revision;
+ $return = array();
- if (!$revision || !($revision->entity_guid == $guid)) {
- $content = elgg_echo('blog:error:revision_not_found');
- }
+ $return['filter_context'] = 'friends';
+
+ 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,
+ '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;
}
- elgg_push_breadcrumb($blog->title, $blog->getURL());
- elgg_push_breadcrumb(elgg_echo('edit'));
+ $options['metadata_name_value_pairs'][] = array(
+ array('name' => 'status', 'value' => 'published')
+ );
+ }
- $content = elgg_view('blog/forms/edit', $vars);
- $sidebar = elgg_view('blog/sidebar_revisions', $vars);
- //$sidebar .= elgg_view('blog/sidebar_related');
+ $list = elgg_list_entities_from_metadata($options);
+ if (!$list) {
+ $return['content'] = elgg_echo('blog:none');
} else {
- $content = elgg_echo('blog:error:cannot_edit_post');
+ $return['content'] = $list;
}
- } 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,
- 'header' => '',
- 'filter' => '',
- );
+ return $return;
}
/**
- * Show blogs with publish dates between $lower and $upper
+ * 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) {
+function blog_get_page_content_archive($owner_guid, $lower = 0, $upper = 0) {
$now = time();
@@ -213,62 +219,134 @@ function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) {
}
/**
- * Returns a list of the user's friend's posts.
+ * Get page components to edit a blog post.
*
- * @param int $user_guid
- * @return string
+ * @param int $guid GUID of blog post
+ * @param int $revision Annotation id for revision to edit (optional)
+ * @return array
*/
-function blog_get_page_content_friends($user_guid) {
+function blog_get_page_content_edit($guid, $revision = NULL) {
- elgg_push_breadcrumb(elgg_echo('friends'));
+ $return = array(
+ 'buttons' => '',
+ 'filter' => '',
+ );
- $return = array();
+ $vars = array();
+ $vars['internalid'] = 'blog-post-edit';
+ $vars['internalname'] = 'blog_post';
- $return['filter_context'] = 'friends';
+ if ($guid) {
+ $blog = get_entity((int)$guid);
- 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,
- 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'),
- );
+ $title = elgg_echo('blog:edit');
- foreach ($friends as $friend) {
- $options['container_guids'][] = $friend->getGUID();
- }
+ if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
+ $vars['entity'] = $blog;
- // 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;
+ $title .= ": \"$blog->title\"";
+
+ if ($revision) {
+ $revision = get_annotation((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;
+ }
}
- $options['metadata_name_value_pairs'][] = array(
- array('name' => 'status', 'value' => 'published')
- );
- }
+ $body_vars = blog_prepare_form_vars($blog, $revision);
- $list = elgg_list_entities_from_metadata($options);
- if (!$list) {
- $return['content'] = elgg_echo('blog:none');
+ elgg_push_breadcrumb($blog->title, $blog->getURL());
+ elgg_push_breadcrumb(elgg_echo('edit'));
+
+ $content = elgg_view_form('blog/save', $vars, $body_vars);
+ $content .= elgg_view('js/blog/save_draft');
+ $sidebar = elgg_view('blog/sidebar_revisions', $vars);
} else {
- $return['content'] = $list;
+ $content = elgg_echo('blog:error:cannot_edit_post');
}
+ } else {
+ elgg_push_breadcrumb(elgg_echo('blog:new'));
+ $body_vars = blog_prepare_form_vars($blog);
+
+ $title = elgg_echo('blog:new');
+ $content = elgg_view_form('blog/save', $vars, $body_vars);
+ $content .= elgg_view('js/blog/save_draft');
}
- return $return;
+ $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',
+ 'publish_date' => NULL,
+ 'access_id' => ACCESS_DEFAULT,
+ 'comments_on' => 'On',
+ 'excerpt' => NULL,
+ 'tags' => NULL,
+ 'container_guid' => NULL,
+ 'guid' => NULL,
+ 'draft_warning' => '',
+ );
+
+ if (!$post) {
+ return $values;
+ }
+
+ foreach (array_keys($values) as $field) {
+ $values[$field] = $post->$field;
+ }
+
+ // 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');
+ }
+
+ elgg_clear_sticky_form('blog');
+
+ return $values;
}
/**
* 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
+ * @param int $user_guid
+ * @param int $container_guid
+ * @return array
*/
function blog_get_blog_months($user_guid = NULL, $container_guid = NULL) {
global $CONFIG;
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 8900fed25..000000000
--- a/mod/blog/views/default/blog/forms/edit.php
+++ /dev/null
@@ -1,318 +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')));
-$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/forms/blog/save.php b/mod/blog/views/default/forms/blog/save.php
new file mode 100644
index 000000000..022473e9d
--- /dev/null
+++ b/mod/blog/views/default/forms/blog/save.php
@@ -0,0 +1,157 @@
+<?php
+/**
+ * Edit blog form
+ *
+ * @package Blog
+ */
+
+$forward = $_SERVER['HTTP_REFERER'];
+
+$draft_warning = $vars['draft_warning'];
+if ($draft_warning) {
+ $draft_warning = '<span class="message warning">' . $draft_warning . '</span>';
+}
+
+$action_buttons = '';
+$delete_link = '';
+
+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' => 'action-button disabled'
+ ));
+}
+
+$save_button = elgg_view('input/submit', array('value' => elgg_echo('save')));
+$action_buttons = $save_button . $delete_link;
+
+$title_label = elgg_echo('title');
+$title_input = elgg_view('input/text', array(
+ 'internalname' => 'title',
+ 'internalid' => 'blog_title',
+ 'value' => $vars['title']
+));
+
+$excerpt_label = elgg_echo('blog:excerpt');
+$excerpt_input = elgg_view('input/text', array(
+ 'internalname' => 'excerpt',
+ 'internalid' => 'blog_excerpt',
+ 'value' => html_entity_decode($vars['excerpt'], ENT_COMPAT, 'UTF-8')
+));
+
+$body_label = elgg_echo('blog:body');
+$body_input = elgg_view('input/longtext', array(
+ 'internalname' => 'description',
+ 'internalid' => 'blog_description',
+ 'value' => $vars['description']
+));
+
+$save_status = elgg_echo('blog:save_status');
+if ($vars['publish_date']) {
+ $saved = date('F j, Y @ H:i', $vars['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' => $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/pulldown', array(
+ 'internalname' => 'comments_on',
+ 'internalid' => '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(
+ 'internalname' => 'tags',
+ 'internalid' => 'blog_tags',
+ 'value' => $vars['tags']
+));
+
+$access_label = elgg_echo('access');
+$access_input = elgg_view('input/access', array(
+ 'internalname' => 'access_id',
+ 'internalid' => 'blog_access_id',
+ 'value' => $vars['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' => $vars['publish_date']
+));
+
+$categories_input = elgg_view('categories', $vars);
+
+// hidden inputs
+//$container_guid_input = elgg_view('input/hidden', array('internalname' => 'container_guid', 'value' => $vars['container_guid']));
+$guid_input = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $vars['guid']));
+$forward_input = elgg_view('input/hidden', array('internalname' => 'forward', 'value' => $forward));
+
+
+echo <<<___HTML
+
+$draft_warning
+
+<p class="mtm">
+ <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
+
+<p class="ptm pbm mbn entity-subtext elgg_hrt">
+ $save_status <span class="blog-save-status-time">$saved</span>
+</p>
+
+$guid_input
+$container_guid_input
+$forward_input
+
+$action_buttons
+
+___HTML;
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..177ecc1df
--- /dev/null
+++ b/mod/blog/views/default/js/blog/save_draft.php
@@ -0,0 +1,97 @@
+<?php
+/**
+ * Save draft through ajax
+ *
+ * @package 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>