From 79128c747888ac2f586f6679e1af78b4aa1b711a Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 5 Dec 2010 21:38:36 +0000 Subject: blog plugin now uses the new elgg_view_form() function git-svn-id: http://code.elgg.org/elgg/trunk@7540 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/views.php | 2 +- mod/blog/languages/en.php | 1 + mod/blog/lib/blog.php | 226 ++++++++++++------ mod/blog/views/default/blog/forms/edit.php | 318 -------------------------- mod/blog/views/default/forms/blog/save.php | 157 +++++++++++++ mod/blog/views/default/js/blog/save_draft.php | 97 ++++++++ views/default/css/screen.php | 9 + 7 files changed, 417 insertions(+), 393 deletions(-) delete mode 100644 mod/blog/views/default/blog/forms/edit.php create mode 100644 mod/blog/views/default/forms/blog/save.php create mode 100644 mod/blog/views/default/js/blog/save_draft.php diff --git a/engine/lib/views.php b/engine/lib/views.php index 5d7c21002..3885babf1 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -1023,7 +1023,7 @@ function elgg_view_listing($icon, $info) { * * * Then elgg_view_form('login') generates: - *
+ * * ...security tokens... * * diff --git a/mod/blog/languages/en.php b/mod/blog/languages/en.php index 843d62932..15708f30b 100644 --- a/mod/blog/languages/en.php +++ b/mod/blog/languages/en.php @@ -49,6 +49,7 @@ $english = array( 'blog:error:missing:title' => 'Please enter a blog title!', 'blog:error:missing:description' => 'Please enter the body of your blog!', 'blog:error:cannot_edit_post' => 'This post may not exist or you may not have permissions to edit it.', + 'blog:error:revision_not_found' => 'Cannot find this revision.', // river 'blog:river:create' => '%s wrote a new blog post', diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 108f300cb..b1c7c280f 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -7,10 +7,10 @@ /** - * Returns HTML for a blog post. + * Get page components to view a blog post. * - * @param int $guid of a blog entity. - * @return string html + * @param int $guid GUID of a blog entity. + * @return array */ function blog_get_page_content_read($guid = NULL) { @@ -38,10 +38,10 @@ function blog_get_page_content_read($guid = NULL) { } /** - * Returns HTML for listing a user's or all blogs. + * Get page components to list a user's or all blogs. * * @param int $owner_guid The GUID of the page owner or NULL for all blogs - * @return string html + * @return array */ function blog_get_page_content_list($owner_guid = NULL) { @@ -91,60 +91,66 @@ function blog_get_page_content_list($owner_guid = NULL) { } /** - * Returns HTML to edit a blog post. + * Get page components to list of the user's friends' posts. * - * @param int $guid - * @param int annotation id optional revision to edit - * @return string html + * @param int $user_guid + * @return array */ -function blog_get_page_content_edit($guid, $revision = NULL) { - $vars = array(); - if ($guid) { - $blog = get_entity((int)$guid); +function blog_get_page_content_friends($user_guid) { - if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { - $vars['entity'] = $blog; + elgg_push_breadcrumb(elgg_echo('friends')); - if ($revision) { - $revision = get_annotation((int)$revision); - $vars['revision'] = $revision; + $return = array(); - if (!$revision || !($revision->entity_guid == $guid)) { - $content = elgg_echo('blog:error:revision_not_found'); - } + $return['filter_context'] = 'friends'; + + if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) { + $return['content'] .= elgg_echo('friends:none:you'); + return $return; + } else { + $options = array( + 'type' => 'object', + 'subtype' => 'blog', + 'full_view' => FALSE, + 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'), + ); + + foreach ($friends as $friend) { + $options['container_guids'][] = $friend->getGUID(); + } + + // admin / owners can see any posts + // everyone else can only see published posts + if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { + if ($upper > $now) { + $upper = $now; } - elgg_push_breadcrumb($blog->title, $blog->getURL()); - elgg_push_breadcrumb(elgg_echo('edit')); + $options['metadata_name_value_pairs'][] = array( + array('name' => 'status', 'value' => 'published') + ); + } - $content = elgg_view('blog/forms/edit', $vars); - $sidebar = elgg_view('blog/sidebar_revisions', $vars); - //$sidebar .= elgg_view('blog/sidebar_related'); + $list = elgg_list_entities_from_metadata($options); + if (!$list) { + $return['content'] = elgg_echo('blog:none'); } else { - $content = elgg_echo('blog:error:cannot_edit_post'); + $return['content'] = $list; } - } else { - elgg_push_breadcrumb(elgg_echo('blog:new')); - $content = elgg_view('blog/forms/edit', $vars); - //$sidebar = elgg_view('blog/sidebar_related'); } - return array( - 'content' => $content, - 'sidebar' => $sidebar, - 'header' => '', - 'filter' => '', - ); + return $return; } /** - * Show blogs with publish dates between $lower and $upper + * Get page components to show blogs with publish dates between $lower and $upper * * @param int $owner_guid The GUID of the owner of this page * @param int $lower Unix timestamp * @param int $upper Unix timestamp + * @return array */ -function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) { +function blog_get_page_content_archive($owner_guid, $lower = 0, $upper = 0) { $now = time(); @@ -213,62 +219,134 @@ function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) { } /** - * Returns a list of the user's friend's posts. + * Get page components to edit a blog post. * - * @param int $user_guid - * @return string + * @param int $guid GUID of blog post + * @param int $revision Annotation id for revision to edit (optional) + * @return array */ -function blog_get_page_content_friends($user_guid) { +function blog_get_page_content_edit($guid, $revision = NULL) { - elgg_push_breadcrumb(elgg_echo('friends')); + $return = array( + 'buttons' => '', + 'filter' => '', + ); - $return = array(); + $vars = array(); + $vars['internalid'] = 'blog-post-edit'; + $vars['internalname'] = 'blog_post'; - $return['filter_context'] = 'friends'; + if ($guid) { + $blog = get_entity((int)$guid); - if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) { - $return['content'] .= elgg_echo('friends:none:you'); - return $return; - } else { - $options = array( - 'type' => 'object', - 'subtype' => 'blog', - 'full_view' => FALSE, - 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'), - ); + $title = elgg_echo('blog:edit'); - foreach ($friends as $friend) { - $options['container_guids'][] = $friend->getGUID(); - } + if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { + $vars['entity'] = $blog; - // admin / owners can see any posts - // everyone else can only see published posts - if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { - if ($upper > $now) { - $upper = $now; + $title .= ": \"$blog->title\""; + + if ($revision) { + $revision = get_annotation((int)$revision); + $vars['revision'] = $revision; + $title .= ' ' . elgg_echo('blog:edit_revision_notice'); + + if (!$revision || !($revision->entity_guid == $guid)) { + $content = elgg_echo('blog:error:revision_not_found'); + $return['content'] = $content; + $return['title'] = $title; + return $return; + } } - $options['metadata_name_value_pairs'][] = array( - array('name' => 'status', 'value' => 'published') - ); - } + $body_vars = blog_prepare_form_vars($blog, $revision); - $list = elgg_list_entities_from_metadata($options); - if (!$list) { - $return['content'] = elgg_echo('blog:none'); + elgg_push_breadcrumb($blog->title, $blog->getURL()); + elgg_push_breadcrumb(elgg_echo('edit')); + + $content = elgg_view_form('blog/save', $vars, $body_vars); + $content .= elgg_view('js/blog/save_draft'); + $sidebar = elgg_view('blog/sidebar_revisions', $vars); } else { - $return['content'] = $list; + $content = elgg_echo('blog:error:cannot_edit_post'); } + } else { + elgg_push_breadcrumb(elgg_echo('blog:new')); + $body_vars = blog_prepare_form_vars($blog); + + $title = elgg_echo('blog:new'); + $content = elgg_view_form('blog/save', $vars, $body_vars); + $content .= elgg_view('js/blog/save_draft'); } - return $return; + $return['title'] = $title; + $return['content'] = $content; + $return['sidebar'] = $sidebar; + return $return; +} + +/** + * Pull together blog variables for the save form + * + * @param ElggBlog $post + * @param ElggAnnotation $revision + * @return array + */ +function blog_prepare_form_vars($post = NULL, $revision = NULL) { + + // input names => defaults + $values = array( + 'title' => NULL, + 'description' => NULL, + 'status' => 'published', + 'publish_date' => NULL, + 'access_id' => ACCESS_DEFAULT, + 'comments_on' => 'On', + 'excerpt' => NULL, + 'tags' => NULL, + 'container_guid' => NULL, + 'guid' => NULL, + 'draft_warning' => '', + ); + + if (!$post) { + return $values; + } + + foreach (array_keys($values) as $field) { + $values[$field] = $post->$field; + } + + // load the revision annotation if requested + if ($revision instanceof ElggAnnotation && $revision->entity_guid == $post->getGUID()) { + $values['revision'] = $revision; + $values['description'] = $revision->value; + } + + // display a notice if there's an autosaved annotation + // and we're not editing it. + if ($auto_save_annotations = $post->getAnnotations('blog_auto_save', 1)) { + $auto_save = $auto_save_annotations[0]; + } else { + $auto_save == FALSE; + } + + if ($auto_save && $auto_save->id != $revision->id) { + $values['draft_warning'] = elgg_echo('blog:messages:warning:draft'); + } + + elgg_clear_sticky_form('blog'); + + return $values; } /** * Returns a list of years and months for all blogs optionally for a user. * Very similar to get_entity_dates() except uses a metadata field. * - * @param mixed $user_guid + * @param int $user_guid + * @param int $container_guid + * @return array */ function blog_get_blog_months($user_guid = NULL, $container_guid = NULL) { global $CONFIG; diff --git a/mod/blog/views/default/blog/forms/edit.php b/mod/blog/views/default/blog/forms/edit.php deleted file mode 100644 index 8900fed25..000000000 --- a/mod/blog/views/default/blog/forms/edit.php +++ /dev/null @@ -1,318 +0,0 @@ - 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 = '' - . elgg_echo('blog:messages:warning:draft') - . ''; - } - - //} - } else { - echo elgg_echo('blog:error:post_not_found'); - return FALSE; - } - - // add a delete button if editing - $delete_url = "action/blog/delete?guid={$blog->getGUID()}"; - $delete_link = elgg_view('output/confirmlink', array( - 'href' => $delete_url, - 'text' => elgg_echo('delete'), - 'class' => 'action-button disabled' - )); -} - -$save_button = elgg_view('input/submit', array('value' => elgg_echo('save'))); -$action_buttons = $save_button . $delete_link; - -$title_label = elgg_echo('title'); -$title_input = elgg_view('input/text', array( - 'internalname' => 'title', - 'internalid' => 'blog_title', - 'value' => $values['title'] -)); - -$excerpt_label = elgg_echo('blog:excerpt'); -$excerpt_input = elgg_view('input/text', array( - 'internalname' => 'excerpt', - 'internalid' => 'blog_excerpt', - 'value' => html_entity_decode($values['excerpt'], ENT_COMPAT, 'UTF-8') -)); - -$body_label = elgg_echo('blog:body'); -$body_input = elgg_view('input/longtext', array( - 'internalname' => 'description', - 'internalid' => 'blog_description', - 'value' => $values['description'] -)); - -$save_status = elgg_echo('blog:save_status'); -if ($values['publish_date']) { - $saved = date('F j, Y @ H:i', $values['publish_date']); -} else { - $saved = elgg_echo('blog:never'); -} - -$status_label = elgg_echo('blog:status'); -$status_input = elgg_view('input/pulldown', array( - 'internalname' => 'status', - 'internalid' => 'blog_status', - 'value' => $values['status'], - 'options_values' => array( - 'draft' => elgg_echo('blog:status:draft'), - 'published' => elgg_echo('blog:status:published') - ) -)); - -$comments_label = elgg_echo('comments'); -$comments_input = elgg_view('input/pulldown', array( - 'internalname' => 'comments_on', - 'internalid' => 'blog_comments_on', - 'value' => $values['comments_on'], - 'options_values' => array('On' => elgg_echo('on'), 'Off' => elgg_echo('off')) -)); - -$tags_label = elgg_echo('tags'); -$tags_input = elgg_view('input/tags', array( - 'internalname' => 'tags', - 'internalid' => 'blog_tags', - 'value' => $values['tags'] -)); - -$access_label = elgg_echo('access'); -$access_input = elgg_view('input/access', array( - 'internalname' => 'access_id', - 'internalid' => 'blog_access_id', - 'value' => $values['access_id'] -)); - -$publish_date_label = elgg_echo('blog:publish_date'); -$publish_date_input = elgg_view('input/datetime', array( - 'internalname' => 'publish_date', - 'internalid' => 'blog_publish_date', - 'value' => $values['publish_date'] -)); - -$categories_input = elgg_view('categories', $vars); - -// hidden inputs -//$container_guid_input = elgg_view('input/hidden', array('internalname' => 'container_guid', 'value' => $values['container_guid'])); -$guid_input = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $values['guid'])); -$forward_input = elgg_view('input/hidden', array('internalname' => 'forward', 'value' => $forward)); - -// editing or creating. -if (isset($values['guid'])) { - $page_title = elgg_echo('blog:edit') . ": \"{$values['title']}\""; -} else { - $page_title = elgg_echo('blog:new'); -} - -// display notice if editing an old revision -if (isset($vars['revision']) && $vars['revision'] instanceof ElggAnnotation) { - $page_title .= ' ' . elgg_echo('blog:edit_revision_notice'); -} - -$form_body = <<<___END -

$page_title

- -$draft_warning - -

- - $title_input -

- -

- -$excerpt_input -

- - -$body_input -
- -

- - $tags_input -

- -

- - $comments_input -

- -

- - $access_input -

- -

- - $status_input -

- -$categories_input - -
-

- $save_status $saved -

- -$guid_input -$container_guid_input -$forward_input - -$action_buttons - -___END; - -echo elgg_view('input/form', array( - 'internalid' => 'blog-post-edit', - 'internalname' => 'blog_post', - 'action' => "action/blog/save", - 'body' => $form_body -)); - -elgg_clear_sticky_form('blog'); - -?> - - \ No newline at end of file diff --git a/mod/blog/views/default/forms/blog/save.php b/mod/blog/views/default/forms/blog/save.php new file mode 100644 index 000000000..022473e9d --- /dev/null +++ b/mod/blog/views/default/forms/blog/save.php @@ -0,0 +1,157 @@ +' . $draft_warning . ''; +} + +$action_buttons = ''; +$delete_link = ''; + +if ($vars['guid']) { + // add a delete button if editing + $delete_url = "action/blog/delete?guid={$vars['guid']}"; + $delete_link = elgg_view('output/confirmlink', array( + 'href' => $delete_url, + 'text' => elgg_echo('delete'), + 'class' => 'action-button disabled' + )); +} + +$save_button = elgg_view('input/submit', array('value' => elgg_echo('save'))); +$action_buttons = $save_button . $delete_link; + +$title_label = elgg_echo('title'); +$title_input = elgg_view('input/text', array( + 'internalname' => 'title', + 'internalid' => 'blog_title', + 'value' => $vars['title'] +)); + +$excerpt_label = elgg_echo('blog:excerpt'); +$excerpt_input = elgg_view('input/text', array( + 'internalname' => 'excerpt', + 'internalid' => 'blog_excerpt', + 'value' => html_entity_decode($vars['excerpt'], ENT_COMPAT, 'UTF-8') +)); + +$body_label = elgg_echo('blog:body'); +$body_input = elgg_view('input/longtext', array( + 'internalname' => 'description', + 'internalid' => 'blog_description', + 'value' => $vars['description'] +)); + +$save_status = elgg_echo('blog:save_status'); +if ($vars['publish_date']) { + $saved = date('F j, Y @ H:i', $vars['publish_date']); +} else { + $saved = elgg_echo('blog:never'); +} + +$status_label = elgg_echo('blog:status'); +$status_input = elgg_view('input/pulldown', array( + 'internalname' => 'status', + 'internalid' => 'blog_status', + 'value' => $vars['status'], + 'options_values' => array( + 'draft' => elgg_echo('blog:status:draft'), + 'published' => elgg_echo('blog:status:published') + ) +)); + +$comments_label = elgg_echo('comments'); +$comments_input = elgg_view('input/pulldown', array( + 'internalname' => 'comments_on', + 'internalid' => 'blog_comments_on', + 'value' => $vars['comments_on'], + 'options_values' => array('On' => elgg_echo('on'), 'Off' => elgg_echo('off')) +)); + +$tags_label = elgg_echo('tags'); +$tags_input = elgg_view('input/tags', array( + 'internalname' => 'tags', + 'internalid' => 'blog_tags', + 'value' => $vars['tags'] +)); + +$access_label = elgg_echo('access'); +$access_input = elgg_view('input/access', array( + 'internalname' => 'access_id', + 'internalid' => 'blog_access_id', + 'value' => $vars['access_id'] +)); + +$publish_date_label = elgg_echo('blog:publish_date'); +$publish_date_input = elgg_view('input/datetime', array( + 'internalname' => 'publish_date', + 'internalid' => 'blog_publish_date', + 'value' => $vars['publish_date'] +)); + +$categories_input = elgg_view('categories', $vars); + +// hidden inputs +//$container_guid_input = elgg_view('input/hidden', array('internalname' => 'container_guid', 'value' => $vars['container_guid'])); +$guid_input = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $vars['guid'])); +$forward_input = elgg_view('input/hidden', array('internalname' => 'forward', 'value' => $forward)); + + +echo <<<___HTML + +$draft_warning + +

+ + $title_input +

+ +

+ + $excerpt_input +

+ + +$body_input +
+ +

+ + $tags_input +

+ +

+ + $comments_input +

+ +

+ + $access_input +

+ +

+ + $status_input +

+ +$categories_input + +

+ $save_status $saved +

+ +$guid_input +$container_guid_input +$forward_input + +$action_buttons + +___HTML; diff --git a/mod/blog/views/default/js/blog/save_draft.php b/mod/blog/views/default/js/blog/save_draft.php new file mode 100644 index 000000000..177ecc1df --- /dev/null +++ b/mod/blog/views/default/js/blog/save_draft.php @@ -0,0 +1,97 @@ + + + diff --git a/views/default/css/screen.php b/views/default/css/screen.php index d12591fe2..895e263bf 100644 --- a/views/default/css/screen.php +++ b/views/default/css/screen.php @@ -237,6 +237,15 @@ h2 { float: left; } +.elgg_hrt { + border-top: 1px solid #CCCCCC; +} + +.elgg_hrb { + border-bottom: 1px solid #CCCCCC; +} + + /* *************************************** PAGE LAYOUT - MAIN BLOCKS POSITIONING *************************************** */ -- cgit v1.2.3