diff options
Diffstat (limited to 'mod/blog')
26 files changed, 1486 insertions, 1073 deletions
diff --git a/mod/blog/actions/blog/auto_save_revision.php b/mod/blog/actions/blog/auto_save_revision.php index a67939e9f..e33edfaab 100644 --- a/mod/blog/actions/blog/auto_save_revision.php +++ b/mod/blog/actions/blog/auto_save_revision.php @@ -3,15 +3,11 @@ * Action called by AJAX periodic auto saving when editing. * * @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/ */ $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'); @@ -41,9 +37,12 @@ if ($title && $description) { $blog->access_id = ACCESS_PRIVATE; $blog->title = $title; $blog->description = $description; - $blog->excerpt = blog_make_excerpt($excerpt); - // must be present or doesn't show up when metadata sorting. - $blog->publish_date = time(); + $blog->excerpt = elgg_get_excerpt($excerpt); + + // mark this as a brand new post so we can work out the + // river / revision logic in the real save action. + $blog->new_post = TRUE; + if (!$blog->save()) { $error = elgg_echo('blog:error:cannot_save'); } @@ -64,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. @@ -86,4 +85,5 @@ if ($error) { $msg = elgg_echo('blog:message:saved'); $json = array('success' => TRUE, 'message' => $msg, 'guid' => $blog->getGUID()); echo json_encode($json); -}
\ No newline at end of file +} +exit; diff --git a/mod/blog/actions/blog/delete.php b/mod/blog/actions/blog/delete.php index 8fa1ff889..ca4eb8a7f 100644 --- a/mod/blog/actions/blog/delete.php +++ b/mod/blog/actions/blog/delete.php @@ -3,18 +3,20 @@ * Delete blog entity * * @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/ */ $blog_guid = get_input('guid'); $blog = get_entity($blog_guid); 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')); + 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')); } @@ -22,4 +24,4 @@ if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { register_error(elgg_echo('blog:error:post_not_found')); } -forward($_SERVER['HTTP_REFERER']);
\ No newline at end of file +forward(REFERER);
\ No newline at end of file diff --git a/mod/blog/actions/blog/save.php b/mod/blog/actions/blog/save.php index eca711f60..82a9e6c51 100644 --- a/mod/blog/actions/blog/save.php +++ b/mod/blog/actions/blog/save.php @@ -2,20 +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 - * @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/ */ // 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'); @@ -26,31 +31,31 @@ 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_value = $blog->description; - $new_post = FALSE; + $revision_text = $blog->description; + $new_post = $blog->new_post; } 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' => '', 'description' => '', 'status' => 'draft', - 'publish_date' => time(), 'access_id' => ACCESS_DEFAULT, 'comments_on' => 'On', 'excerpt' => '', 'tags' => '', - 'container_guid' => '' + 'container_guid' => (int)get_input('container_guid'), ); // fail if a required entity isn't set @@ -58,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"); @@ -70,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 = blog_make_excerpt($value); - } else { - $value = blog_make_excerpt($values['description']); + $values[$name] = elgg_get_excerpt($value); } - $values[$name] = $value; break; case 'container_guid': @@ -99,32 +101,27 @@ foreach ($values as $name => $default) { } break; - case 'publish_date': - if (!$value = strtotime($value)) { - $value = time(); - } - - $values[$name] = $value; - break; - - // don't try to set the guid - case 'guid': - unset($values['guid']); - break; - default: $values[$name] = $value; break; } } +// if preview, force status to be draft +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; } } @@ -132,19 +129,49 @@ 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'); - // if this was an edit, create a revision - if (!$new_post && $revision_value) { - // create a revision annotation - $blog->annotate('blog_revision', $revision_value); + // no longer a brand new post. + $blog->deleteMetadata('new_post'); + + // if this was an edit, create a revision annotation + if (!$new_post && $revision_text) { + $blog->annotate('blog_revision', $revision_text); } system_message(elgg_echo('blog:message:saved')); - forward($success_forward_url); + + $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"); + } } else { register_error(elgg_echo('blog:error:cannot_save')); forward($error_forward_url); @@ -153,12 +180,3 @@ if (!$error) { register_error($error); forward($error_forward_url); } - -// forward with success or failure -if ($error) { - register_error($error); - forward($error_forward_url); -} else { - system_message(elgg_echo('blog:message:saved')); - forward($success_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 f363aa7b2..000000000 --- a/mod/blog/blog_lib.php +++ /dev/null @@ -1,230 +0,0 @@ -<?php -/** - * Blog helper functions - * - * @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/ - */ - - -/** - * 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) { - $content = elgg_view('page_elements/content_header', array('context' => $context, 'type' => 'blog')); - - if ($guid) { - $blog = get_entity($guid); - - if (!elgg_instanceof($blog, 'object', 'blog') || ($blog->status != 'final' && $blog->owner_guid != get_loggedin_userid())) { - $content .= elgg_echo('blog:error:post_not_found'); - } else { - elgg_push_breadcrumb($blog->title, $blog->getURL()); - $content .= elgg_view_entity($blog, TRUE); - } - } else { - $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; - } - - // show all posts for admin or users looking at their own blogs - // show only published posts for other users. - if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { - $options['metadata_name_value_pairs'] = array( - array('name' => 'status', 'value' => 'published'), - array('name' => 'publish_date', 'operand' => '<', 'value' => time()) - ); - } - - $content .= elgg_list_entities_from_metadata($options); - } - - 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, $upper) { - $now = time(); - - $content = elgg_view('page_elements/content_header', array('context' => $context, '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 - ); - } - - $content .= elgg_list_entities_from_metadata($options); - - return array( - 'content' => $content - ); -} - -/** - * Returns an appropriate excerpt for a blog. - * - * @param string $text - * @return string - */ -function blog_make_excerpt($text) { - return substr(strip_tags($text), 0, 300); -} - -/** - * 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('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); -} - -/** - * Extended class to override the time_created - */ -class ElggBlog extends ElggObject { - protected function initialise_attributes() { - parent::initialise_attributes(); - - // override the default file subtype. - $this->attributes['subtype'] = 'blog'; - } - - /** - * Override the value returned for time_created - */ - public function __get($name) { - if ($name == 'time_created') { - $name = 'time_created'; - } - - return $this->get($name); - } -}
\ No newline at end of file diff --git a/mod/blog/classes/ElggBlog.php b/mod/blog/classes/ElggBlog.php new file mode 100644 index 000000000..8d4401c57 --- /dev/null +++ b/mod/blog/classes/ElggBlog.php @@ -0,0 +1,42 @@ +<?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 { + + /** + * Set subtype to blog. + */ + protected function initializeAttributes() { + parent::initializeAttributes(); + + $this->attributes['subtype'] = "blog"; + } + + /** + * 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 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 f98cc6059..5248a6f51 100644 --- a/mod/blog/languages/en.php +++ b/mod/blog/languages/en.php @@ -1,50 +1,78 @@ <?php /** - * Blog English langauge file. + * Blog English language file. * */ $english = array( - 'item:object:blog' => 'Blog', + 'blog' => 'Blogs', 'blog:blogs' => 'Blogs', - 'blog:owned_blogs' => '%s blogs', 'blog:revisions' => 'Revisions', 'blog:archives' => 'Archives', - 'blog:blog' => 'Blog', - 'blog:yours' => 'Your blog', - 'blog:all' => 'All blogs', - 'blog:friends' => 'Friends\' blogs', + 'item:object:blog' => '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', 'blog:status:draft' => 'Draft', 'blog:status:published' => 'Published', - 'blog:status:unsaved_draft' => 'Recovered Draft', + 'blog:status:unsaved_draft' => 'Unsaved Draft', 'blog:revision' => 'Revision', 'blog:auto_saved_revision' => 'Auto Saved Revision', - 'blog:owner_title' => '%s\'s blogs', // messages '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: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 + '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);
\ No newline at end of file +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 483e83fab..29ee1bfc8 100644 --- a/mod/blog/manifest.xml +++ b/mod/blog/manifest.xml @@ -1,10 +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" /> +<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 3c497088a..e724b91c2 100644 --- a/mod/blog/start.php +++ b/mod/blog/start.php @@ -3,194 +3,300 @@ * Blogs * * @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/ * * @todo - * Show your blog posts - * Show friends blog posts - * Widget - * - * Group blogs - * Forward to container instead of owner - * - * Pingbacks - * Notifications + * - Either drop support for "publish date" or duplicate more entity getter + * functions to work with a non-standard time_created. + * - 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'), "{$CONFIG->wwwroot}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'); - // run the setup upon activations or to upgrade old installations. - run_function_once('blog_runonce', '1269370108'); + // 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); - elgg_extend_view('css', 'blog/css'); + // routing of urls + elgg_register_page_handler('blog', 'blog_page_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'); + // 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')); - register_plugin_hook('notify:entity:message', 'object', 'blog_notify_message'); + // 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 + 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 group option add_group_tool_option('blog', elgg_echo('blog:enableblog'), true); + elgg_extend_view('groups/tool_latest', 'blog/group_module'); - //add_widget_type('blog', elgg_echo('blog'), elgg_echo('blog:widget:description'), 'profile, dashboard'); + // add a blog widget + elgg_register_widget_type('blog', elgg_echo('blog'), elgg_echo('blog:widget:description')); - $action_path = dirname(__FILE__) . '/actions/blog'; + // 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"); - 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"); -} + // 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; - elgg_push_breadcrumb(elgg_echo('blog:blogs'), "{$CONFIG->site->url}pg/blog"); + elgg_load_library('elgg:blog'); - // see if we're showing all or just a user's - if (isset($page[0]) && !empty($page[0])) { - $username = $page[0]; + // 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($_SERVER['HTTP_REFERER']); - } + // push all blogs breadcrumb + elgg_push_breadcrumb(elgg_echo('blog:blogs'), "blog/all"); - set_page_owner($user->getGUID()); - $crumbs_title = sprintf(elgg_echo('blog:owned_blogs'), $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 = sprintf(elgg_echo('blog:title:user_blogs'), $user->name); - $content_info = blog_get_page_content_read($user->getGUID(), $page2); - break; - - case 'new': - case 'edit': - //$sidebar = elgg_view('blog/sidebar_edit', array('blog_guid' => $page2)); - $content_info = blog_get_page_content_edit($page2, $page3); - break; - - case 'archive': - $content_info = blog_get_page_content_archive($user->getGUID(), $page2, $page3); - break; - - case 'friends': - //@todo make it go - $content = elgg_view('page_elements/content_header', array('context' => $content, 'type' => 'blog')); - $content .= blog_get_page_content_archive($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 .= elgg_view('blog/sidebar_menu'); - if (isset($content_info['sidebar'])) { - $sidebar .= $content_info['sidebar']; + $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; + } + + 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)); } - $content = elgg_view('navigation/breadcrumbs') . $content_info['content']; - $body = elgg_view_layout('one_column_with_sidebar', $content, $sidebar); + $body = elgg_view_layout('content', $params); - page_draw($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) { - global $CONFIG; - - if (!$user = get_entity($entity->owner_guid)) { + if (!$entity->getOwnerEntity()) { // default to a standard view if no owner. return FALSE; } - $friendly_title = friendly_title($entity->title); + $friendly_title = elgg_get_friendly_title($entity->title); + + return "blog/view/{$entity->guid}/$friendly_title"; +} + +/** + * Add a menu item to an ownerblock + */ +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; + } + } - $url = "{$CONFIG->site->url}pg/blog/{$user->username}/read/{$entity->getGUID()}/$friendly_title"; - return $url; + return $return; } /** - * Add menu items for groups + * Add particular blog links/info to entity menu */ -function blog_page_setup() { - global $CONFIG; - $page_owner = page_owner_entity(); - - if ($page_owner instanceof ElggGroup && get_context() == 'groups') { - if($page_owner->blog_enable != "no") { - $url = "{$CONFIG->wwwroot}pg/blog/{$page_owner->username}/items"; - add_submenu_item(elgg_echo('blog:groups:group_blogs'), $url); +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]); + } } + + $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; } -register_elgg_event_handler('init', 'system', 'blog_init'); +/** + * 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; +} + +/** + * 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 3cddd3105..12ac4df2a 100644 --- a/mod/blog/views/default/blog/css.php +++ b/mod/blog/views/default/blog/css.php @@ -3,20 +3,12 @@ * Blog CSS * * @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/ */ ?> -.blogpost { - border-bottom:1px dotted #CCCCCC; + +/* Blog Plugin */ + +/* force tinymce input height for a more useful editing / blog creation area */ +form#blog-post-edit #description_parent #description_ifr { + height:400px !important; } -.blogpost .body { - margin-top:5px; - margin-bottom:10px; - display:block; -} -.blogpost .body p { - line-height: 1.4em; -}
\ 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 b2b494c7a..000000000 --- a/mod/blog/views/default/blog/forms/edit.php +++ /dev/null @@ -1,312 +0,0 @@ -<?php -/** - * Edit blog form - * - * @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/ - */ - -// 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 = "{$vars['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' => $values['excerpt'] -)); - -$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'); -$never = 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/datepicker', array( - 'internalname' => 'publish_date', - 'internalid' => 'blog_publish_date', - 'value' => $values['publish_date'] -)); - -// 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']; - -// 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 id="blog_save_status"> - $save_status <span id="blog_save_status_time">$never</span> -</p> - -<p> - <label for="blog_publish_date">$publish_date_label</label> - $publish_date_input -</p> - - -<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> - -$guid_input -$container_guid_input -$forward_input - -$action_buttons - -<span> - -___END; - -echo elgg_view('input/form', array( - 'internalname' => 'blog_post', - 'action' => "{$vars['url']}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.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 $vars['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(); - - $('#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 new file mode 100644 index 000000000..cd2e7f3d8 --- /dev/null +++ b/mod/blog/views/default/blog/sidebar/revisions.php @@ -0,0 +1,79 @@ +<?php +/** + * Blog sidebar menu showing revisions + * + * @package Blog + */ + +//If editing a post, show the previous revisions and drafts. +$blog = elgg_extract('entity', $vars, FALSE); + +if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { + $owner = $blog->getOwnerEntity(); + $revisions = array(); + + $auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1); + if ($auto_save_annotations) { + $revisions[] = $auto_save_annotations[0]; + } + + // count(FALSE) == 1! AHHH!!! + $saved_revisions = $blog->getAnnotations('blog_revision', 10, 0, 'time_created DESC'); + if ($saved_revisions) { + $revision_count = count($saved_revisions); + } else { + $revision_count = 0; + } + + $revisions = array_merge($revisions, $saved_revisions); + + if ($revisions) { + $title = elgg_echo('blog:revisions'); + + $n = count($revisions); + $body = '<ul class="blog-revisions">'; + + $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'), + 'is_trusted' => true, + )); + + $time = "<span class='elgg-subtext'>" + . elgg_view_friendly_time($blog->time_created) . "</span>"; + + $body .= "<li>$load : $time</li>"; + } + + foreach ($revisions as $revision) { + $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, + 'is_trusted' => true, + )); + + $text = "$load: $time"; + $class = 'class="auto-saved"'; + + $n--; + + $body .= "<li $class>$text</li>"; + } + + $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 d75c28aad..000000000 --- a/mod/blog/views/default/blog/sidebar_edit.php +++ /dev/null @@ -1,65 +0,0 @@ -<?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 deleted file mode 100644 index a3fe1c181..000000000 --- a/mod/blog/views/default/blog/sidebar_menu.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php -/** - * Blog sidebar menu. - * - * @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/ - */ - -// 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 = page_owner_entity(); - -// 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 elgg_view_title(elgg_echo('blog:archives')); - - echo '<ul>'; - 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 = page_owner_entity(); - $link = $CONFIG->wwwroot . 'pg/blog/' . $page_owner->username . '/archive/' . $timestamplow . '/' . $timestamphigh; - //add_submenu_item(sprintf(elgg_echo('date:month:' . substr($date,4,2)), substr($date, 0, 4)), $link, 'filter'); - $month = sprintf(elgg_echo('date:month:' . substr($date,4,2)), substr($date, 0, 4)); - echo "<li><a href=\"$link\" title=\"$month\">$month</a><li>"; - } - - echo '</ul>'; - } -} - -// temporarily force tag-cloud display -$tags = display_tagcloud(0, 100, 'tags'); -echo <<<___END -<h3>Tagcloud</h3> -<div class="tagcloud sidebar">$tags</div> -<a href="{$vars['url']}mod/tagcloud/tagcloud.php">All site tags</a> -___END; - -?>
\ 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 deleted file mode 100644 index f777316ec..000000000 --- a/mod/blog/views/default/blog/sidebar_revisions.php +++ /dev/null @@ -1,70 +0,0 @@ -<?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/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/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 fb996fb19..4403a6006 100644 --- a/mod/blog/views/default/object/blog.php +++ b/mod/blog/views/default/object/blog.php @@ -3,114 +3,97 @@ * View for blog objects * * @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/ */ -$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 = $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->publish_date); +if (!$excerpt) { + $excerpt = elgg_get_excerpt($blog->description); +} + +$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_link = "<a href=\"{$blog->getURL()}#annotations\">" . sprintf(elgg_echo("comments"), $comments_count) . '</a>'; + $comments_count = $blog->countComments(); + //only display if there are commments + 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. -$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( - 'href' => $delete_url, - 'text' => elgg_echo('delete'), - 'confirm' => elgg_echo('deleteconfirm') - )) . "</span>"; +$metadata = elgg_view_menu('entity', array( + 'entity' => $vars['entity'], + 'handler' => 'blog', + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz', +)); - $status = ''; - if ($blog->status != 'published') { - $status_text = elgg_echo("blog:status:{$blog->status}"); - $status = "<span class='blog_status'>$status_text</a>"; - } +$subtitle = "$author_text $date $comments_link $categories"; - $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')) .$edit; - if ($full) { - if ($blog->comments_on != 'Off') { - $comments = elgg_view_comments($blog); - } else { - $comments = ''; - } - $like = elgg_view_likes($blog); - $owner_title = sprintf(elgg_echo('blog:owner_title'), $owner->name); -echo <<<___END -<div class="blogpost clearfloat"> - <div id="content_header" class="clearfloat"> - <div class="content_header_title"><h2>$owner_title</h2></div> - </div> - <div class="entity_listing_icon"> - $owner_icon - </div> - <div class="entity_listing_info"> - <div class="entity_metadata">$edit</div> - <p class="entity_title">{$blog->title}</p> - <p class="entity_subtext"> - $date - $categories - $comments_link - </p> - <p class="tags">$tags</p> - <span class="body">$body</span> - </div> -</div> -$like -$comments + $body = elgg_view('output/longtext', array( + 'value' => $blog->description, + 'class' => 'blog-post', + )); -___END; + $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 clearfloat"> - <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"> - $date - $categories - $comments_link - </p> - <p class="tags">$tags</p> - <p>$excerpt</p> - </div> -</div> + // brief view + + $params = array( + 'entity' => $blog, + 'metadata' => $metadata, + 'subtitle' => $subtitle, + 'content' => $excerpt, + ); + $params = $params + $vars; + $list_body = elgg_view('object/elements/summary', $params); -___END; -}
\ No newline at end of file + 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 new file mode 100644 index 000000000..b808f1bdc --- /dev/null +++ b/mod/blog/views/default/river/object/blog/create.php @@ -0,0 +1,15 @@ +<?php +/** + * Blog river view. + */ + +$object = $vars['item']->getObjectEntity(); + +$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, +)); 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> |
