diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-03-18 21:45:48 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-03-18 21:45:48 +0000 |
commit | 94ccaa1a5f6c927674698f1788f95241dce5bc29 (patch) | |
tree | ec666baad142c7aea5644aa0f386e161ee0511f8 /mod/blog/views/default | |
parent | a12e51d597b5ca22af44609b778eca66ca681492 (diff) | |
download | elgg-94ccaa1a5f6c927674698f1788f95241dce5bc29.tar.gz elgg-94ccaa1a5f6c927674698f1788f95241dce5bc29.tar.bz2 |
Updated blog to support multiple revisions and automatic saving of drafts.
git-svn-id: http://code.elgg.org/elgg/trunk@5437 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/blog/views/default')
-rw-r--r-- | mod/blog/views/default/blog/forms/edit.php | 90 | ||||
-rw-r--r-- | mod/blog/views/default/blog/sidebar_edit.php | 65 | ||||
-rw-r--r-- | mod/blog/views/default/blog/sidebar_menu.php | 6 | ||||
-rw-r--r-- | mod/blog/views/default/blog/sidebar_revisions.php | 70 | ||||
-rw-r--r-- | mod/blog/views/default/object/blog.php | 25 |
5 files changed, 214 insertions, 42 deletions
diff --git a/mod/blog/views/default/blog/forms/edit.php b/mod/blog/views/default/blog/forms/edit.php index b19898573..83ee8208e 100644 --- a/mod/blog/views/default/blog/forms/edit.php +++ b/mod/blog/views/default/blog/forms/edit.php @@ -9,11 +9,12 @@ * @link http://elgg.org/ */ +// input names => defaults $values = array( 'title' => NULL, 'description' => NULL, - 'status' => 'final', - //'publish_date' => NULL, + 'status' => 'published', + 'publish_date' => NULL, 'access_id' => ACCESS_DEFAULT, 'comments_on' => 'On', 'excerpt' => NULL, @@ -25,17 +26,42 @@ $values = array( $forward = $_SERVER['HTTP_REFERER']; $action_buttons = ''; -$guid_input = ''; $delete_link = ''; +$draft_warning = ''; // if entity is set, we're editing. if (isset ($vars['entity'])) { $blog = $vars['entity']; if ($blog && ($blog instanceof ElggObject) && ($blog->getSubtype() == 'blog')) { - foreach (array_keys($values) as $field) { - $values[$field] = $blog->$field; - } + // 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; @@ -48,8 +74,6 @@ if (isset ($vars['entity'])) { 'text' => elgg_echo('delete'), 'class' => 'action_button disabled' )); - - $guid_input = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $values['guid'])); } $save_button = elgg_view('input/submit', array('value' => elgg_echo('save'), 'class' => 'submit_button')); @@ -77,7 +101,7 @@ $body_input = elgg_view('input/longtext', array( )); $save_status = elgg_echo('blog:save_status'); -$never = elgg_echo('never'); +$never = elgg_echo('blog:never'); $status_label = elgg_echo('blog:status'); $status_input = elgg_view('input/pulldown', array( @@ -85,8 +109,8 @@ $status_input = elgg_view('input/pulldown', array( 'internalid' => 'blog_status', 'value' => $values['status'], 'options_values' => array( - 'draft' => elgg_echo('blog:draft'), - 'final' => elgg_echo('blog:final') + 'draft' => elgg_echo('blog:status:draft'), + 'published' => elgg_echo('blog:status:published') ) )); @@ -121,12 +145,20 @@ $publish_date_input = elgg_view('input/datepicker', array( // 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)); -$page_title = elgg_echo('blog:edit')." ".$values['title']; +$page_title = elgg_echo('blog:edit') . " " . $values['title']; + +// 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 @@ -137,13 +169,12 @@ $form_body = <<<___END $excerpt_input </p> -<p> - <label for="blog_description">$body_label</label> - $body_input -</p> +<label for="blog_description">$body_label</label> +$body_input +<br /> <p id="blog_save_status"> - $save_status:<span id="blog_save_status_time">$never</span> + $save_status <span id="blog_save_status_time">$never</span> </p> <p> @@ -190,6 +221,8 @@ echo elgg_view('input/form', array( 'body' => $form_body )); +elgg_clear_sticky_form('blog'); + ?> <script type="text/javascript"> @@ -201,13 +234,16 @@ echo elgg_view('input/form', array( function blogSaveDraftCallback(data, textStatus, XHR) { if (textStatus == 'success' && data.success == true) { var form = $('form[name=blog_post]'); - form.append('<input type="hidden" name="guid" value="' + data.guid + '" />'); + + // 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.getHours() + ":" + mins); - } else { $("#blog_save_status_time").html("<?php echo elgg_echo('error'); ?>"); } @@ -218,16 +254,16 @@ echo elgg_view('input/form', array( tinyMCE.triggerSave(); } - // only save when content exists + // only save on changed content var form = $('form[name=blog_post]'); - var title = form.children('input[name=title]').val(); - var description = form.children('textarea[name=description]').val(); + var description = form.find('textarea[name=description]').val(); + var title = form.find('input[name=title]').val(); - if (!(title && description)) { + if (!(description && title) || (description == oldDescription)) { return false; } - var draftURL = "<?php echo $vars['url']; ?>action/blog/save?ajax=1"; + var draftURL = "<?php echo $vars['url']; ?>action/blog/auto_save_revision"; var postData = form.serializeArray(); // force draft status @@ -238,10 +274,12 @@ echo elgg_view('input/form', array( }); $.post(draftURL, postData, blogSaveDraftCallback, 'json'); - } - $(document).ready(function(){ + $(document).ready(function() { + // get a copy of the body to compare for auto save + oldDescription = $('form[name=blog_post]').find('textarea[name=description]').val(); + $('#excerpt.excerpt').each(function(){ var allowed = 200; diff --git a/mod/blog/views/default/blog/sidebar_edit.php b/mod/blog/views/default/blog/sidebar_edit.php new file mode 100644 index 000000000..d75c28aad --- /dev/null +++ b/mod/blog/views/default/blog/sidebar_edit.php @@ -0,0 +1,65 @@ +<?php +/** + * Blog sidebar menu for editing / creating a blog post. + * + * @package Blog + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.org/ + */ + +//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 = "{$vars['url']}pg/blog/{$owner->username}/edit/{$blog->getGUID()}/"; + + foreach ($revisions as $revision) { + $time = 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 index 71bb1ec39..8ecec9a53 100644 --- a/mod/blog/views/default/blog/sidebar_menu.php +++ b/mod/blog/views/default/blog/sidebar_menu.php @@ -31,14 +31,8 @@ Owned blogs; $loggedin_user = get_loggedin_user(); $page_owner = page_owner_entity(); -if ($loggedin_user) { - -} ?> -<ul class="submenu"> - <li><a href="">Drafts</a></li> -</ul> <?php // include a view for plugins to extend echo elgg_view("blogs/sidebar", array("object_type" => 'blog')); diff --git a/mod/blog/views/default/blog/sidebar_revisions.php b/mod/blog/views/default/blog/sidebar_revisions.php new file mode 100644 index 000000000..f777316ec --- /dev/null +++ b/mod/blog/views/default/blog/sidebar_revisions.php @@ -0,0 +1,70 @@ +<?php +/** + * Blog sidebar menu showing revisions + * + * @package Blog + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.org/ + */ + +//If editing a post, show the previous revisions and drafts. +$blog = isset($vars['entity']) ? $vars['entity'] : FALSE; + + +if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { + $owner = $blog->getOwnerEntity(); + $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 '<h3>' . elgg_echo('blog:revisions') . '</h3>'; + + $n = count($revisions); + + echo '<ul class="blog_revisions">'; + $load_base_url = "{$vars['url']}pg/blog/{$owner->username}/edit/{$blog->getGUID()}/"; + + foreach ($revisions as $revision) { + $time = 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') . " $n"; + $text = "$name: $time $load"; + $class = 'class="auto_saved"'; + } + + $n--; + + echo <<<___END +<li $class> +$text +</li> + +___END; + } + + echo '</ul>'; + } +}
\ 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 f1240256a..4a8541261 100644 --- a/mod/blog/views/default/object/blog.php +++ b/mod/blog/views/default/object/blog.php @@ -24,9 +24,10 @@ $excerpt = $blog->excerpt; $body = $blog->description; $owner_icon = elgg_view("profile/icon",array('entity' => $owner, 'size' => 'tiny')); $tags = elgg_view('output/tags', array('tags' => $blog->tags)); -$date = friendly_time($blog->time_created); +$date = friendly_time($blog->publish_date); -if ($blog->comments_on == 'Yes') { +// The "on" status changes for comments, so best to check for !Off +if ($blog->comments_on != 'Off') { $comments_count = elgg_count_comments($blog); $comments_link = "<a href=\"{$blog->getURL()}#annotations\">" . sprintf(elgg_echo("comments"), $comments_count) . '</a>'; } else { @@ -34,27 +35,31 @@ if ($blog->comments_on == 'Yes') { } // links to delete or edit. +$edit = ''; if ($blog->canEdit()) { $edit_url = "{$vars['url']}pg/blog/{$owner->username}/edit/{$blog->getGUID()}/"; $edit_link = "<a href=\"$edit_url\">" . elgg_echo('edit') . '</a>'; $delete_url = "{$vars['url']}action/blog/delete?guid={$blog->getGUID()}"; - $delete_link = "<span class='delete_button'>".elgg_view('output/confirmlink', array( + $delete_link = "<span class='delete_button'>" . elgg_view('output/confirmlink', array( 'href' => $delete_url, 'text' => elgg_echo('delete'), 'confirm' => elgg_echo('deleteconfirm') - ))."</span>"; + )) . "</span>"; - $edit = "$edit_link $delete_link"; -} else { - $edit = ''; + $status = ''; + if ($blog->status != 'published') { + $status_text = elgg_echo("blog:status:{$blog->status}"); + $status = "<span class='blog_status'>$status_text</a>"; + } + + $edit = "$status $edit_link $delete_link"; } // include a view for plugins to extend $edit = elgg_view("blogs/options", array("object_type" => 'blog')) .$edit; if ($full) { - // The "on" status changes for comments, so best to check for !Off if ($blog->comments_on != 'Off') { $comments = elgg_view_comments($blog); } else { @@ -67,7 +72,7 @@ echo <<<___END <div class="blogpost clearfloat"> <div id="content_header" class="clearfloat"> <div class="content_header_title"><h2>$owner_title</h2></div> - </div> + </div> <div class="entity_listing_icon"> $owner_icon </div> @@ -90,7 +95,7 @@ ___END; } else { echo <<<___END -<div class="blog entity_listing clearfloat"> +<div class="blog $status_class entity_listing clearfloat"> <div class="entity_listing_icon"> $owner_icon </div> |