diff options
Diffstat (limited to 'mod/blog')
-rw-r--r-- | mod/blog/actions/blog/save.php | 33 | ||||
-rw-r--r-- | mod/blog/lib/blog.php | 8 | ||||
-rw-r--r-- | mod/blog/start.php | 28 | ||||
-rw-r--r-- | mod/blog/views/default/blog/sidebar/archives.php | 2 | ||||
-rw-r--r-- | mod/blog/views/default/forms/blog/save.php | 2 | ||||
-rw-r--r-- | mod/blog/views/default/river/object/blog/create.php | 6 |
6 files changed, 55 insertions, 24 deletions
diff --git a/mod/blog/actions/blog/save.php b/mod/blog/actions/blog/save.php index 070c96398..82a9e6c51 100644 --- a/mod/blog/actions/blog/save.php +++ b/mod/blog/actions/blog/save.php @@ -2,6 +2,12 @@ /** * 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 */ @@ -73,11 +79,7 @@ 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': @@ -99,11 +101,6 @@ foreach ($values as $name => $default) { } break; - // don't try to set the guid - case 'guid': - unset($values['guid']); - break; - default: $values[$name] = $value; break; @@ -115,13 +112,16 @@ if ($save == false) { $values['status'] = 'draft'; } +// 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; } } @@ -151,6 +151,11 @@ if (!$error) { 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(); diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 3c71dfbab..9753f27a8 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -39,8 +39,8 @@ function blog_get_page_content_read($guid = NULL) { elgg_push_breadcrumb($blog->title); $return['content'] = elgg_view_entity($blog, array('full_view' => true)); - //check to see if comment are on - if ($blog->comments_on != 'Off') { + // check to see if we should allow comments + if ($blog->comments_on != 'Off' && $blog->status == 'published') { $return['content'] .= elgg_view_comments($blog); } @@ -363,6 +363,10 @@ function blog_prepare_form_vars($post = NULL, $revision = NULL) { $values[$field] = $post->$field; } } + + if ($post->status == 'draft') { + $values['access_id'] = $post->future_access; + } } if (elgg_is_sticky_form('blog')) { diff --git a/mod/blog/start.php b/mod/blog/start.php index eb6eee05f..e724b91c2 100644 --- a/mod/blog/start.php +++ b/mod/blog/start.php @@ -41,8 +41,8 @@ function blog_init() { // override the default url to view a blog object elgg_register_entity_url_handler('object', 'blog', 'blog_url_handler'); - // notifications - register_notification_object('object', 'blog', elgg_echo('blog:newpost')); + // 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'); // add blog link to @@ -113,14 +113,23 @@ function blog_page_handler($page) { 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': @@ -139,7 +148,11 @@ function blog_page_handler($page) { $params = blog_get_page_content_edit($page_type, $page[1], $page[2]); break; case 'group': - if ($page[2] == 'all') { + $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]); @@ -214,7 +227,14 @@ function blog_entity_menu_setup($hook, $type, $return, $params) { return $return; } - if ($entity->canEdit() && $entity->status != 'published') { + if ($entity->status != 'published') { + // draft status replaces access + foreach ($return as $index => $item) { + if ($item->getName() == 'access') { + unset($return[$index]); + } + } + $status_text = elgg_echo("blog:status:{$entity->status}"); $options = array( 'name' => 'published_status', diff --git a/mod/blog/views/default/blog/sidebar/archives.php b/mod/blog/views/default/blog/sidebar/archives.php index 3d8f28ca4..5098e6e3e 100644 --- a/mod/blog/views/default/blog/sidebar/archives.php +++ b/mod/blog/views/default/blog/sidebar/archives.php @@ -14,7 +14,7 @@ if (elgg_instanceof($page_owner, 'user')) { // This is a limitation of the URL schema. if ($page_owner && $vars['page'] != 'friends') { - $dates = get_entity_dates('object', 'blog', $page_owner->getGUID()); + $dates = array_reverse(get_entity_dates('object', 'blog', $page_owner->getGUID())); if ($dates) { $title = elgg_echo('blog:archives'); diff --git a/mod/blog/views/default/forms/blog/save.php b/mod/blog/views/default/forms/blog/save.php index 36fa2e0e8..f825acca1 100644 --- a/mod/blog/views/default/forms/blog/save.php +++ b/mod/blog/views/default/forms/blog/save.php @@ -10,7 +10,7 @@ $vars['entity'] = $blog; $draft_warning = $vars['draft_warning']; if ($draft_warning) { - $draft_warning = '<span class="message warning">' . $draft_warning . '</span>'; + $draft_warning = '<span class="mbm elgg-text-help">' . $draft_warning . '</span>'; } $action_buttons = ''; diff --git a/mod/blog/views/default/river/object/blog/create.php b/mod/blog/views/default/river/object/blog/create.php index a054c1061..b808f1bdc 100644 --- a/mod/blog/views/default/river/object/blog/create.php +++ b/mod/blog/views/default/river/object/blog/create.php @@ -4,10 +4,12 @@ */ $object = $vars['item']->getObjectEntity(); -$excerpt = strip_tags($object->excerpt); + +$excerpt = $object->excerpt ? $object->excerpt : $object->description; +$excerpt = strip_tags($excerpt); $excerpt = elgg_get_excerpt($excerpt); echo elgg_view('river/elements/layout', array( 'item' => $vars['item'], 'message' => $excerpt, -));
\ No newline at end of file +)); |