edit.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Create/edit a blog
  4. */
  5. gatekeeper();
  6. elgg_load_library("elgg:blog");
  7. elgg_require_js('elgg/blog/save_draft');
  8. // get inputs
  9. $page_type = get_input("page_type");
  10. $guid = (int) get_input("guid");
  11. $revision = get_input("revision");
  12. $params = array(
  13. "filter" => ""
  14. );
  15. $vars = array();
  16. $vars["id"] = "blog-post-edit";
  17. $vars["name"] = "blog_post";
  18. $vars["class"] = "elgg-form-alt";
  19. $vars["enctype"] = "multipart/form-data";
  20. $sidebar = "";
  21. if ($page_type == "edit") {
  22. $blog = get_entity($guid);
  23. $title = elgg_echo("blog:edit");
  24. if (elgg_instanceof($blog, "object", "blog") && $blog->canEdit()) {
  25. $vars["entity"] = $blog;
  26. $title .= ": " . $blog->title;
  27. if ($revision) {
  28. $revision = elgg_get_annotation_from_id((int)$revision);
  29. $vars["revision"] = $revision;
  30. $title .= " " . elgg_echo("blog:edit_revision_notice");
  31. if (!$revision || !($revision->entity_guid == $guid)) {
  32. $content = elgg_echo("blog:error:revision_not_found");
  33. $params["content"] = $content;
  34. $params["title"] = $title;
  35. return $params;
  36. }
  37. }
  38. $body_vars = blog_prepare_form_vars($blog, $revision);
  39. elgg_push_breadcrumb($blog->title, $blog->getURL());
  40. elgg_push_breadcrumb(elgg_echo("edit"));
  41. $content = elgg_view_form("blog/save", $vars, $body_vars);
  42. $sidebar = elgg_view("blog/sidebar/revisions", $vars);
  43. } else {
  44. $content = elgg_echo("blog:error:cannot_edit_post");
  45. }
  46. } else {
  47. if (!$guid) {
  48. $container = elgg_get_logged_in_user_entity();
  49. } else {
  50. $container = get_entity($guid);
  51. }
  52. elgg_push_breadcrumb(elgg_echo("blog:add"));
  53. $body_vars = blog_prepare_form_vars();
  54. $title = elgg_echo("blog:add");
  55. $content = elgg_view_form("blog/save", $vars, $body_vars);
  56. }
  57. $params["title"] = $title;
  58. $params["content"] = $content;
  59. $params["sidebar"] = $sidebar;
  60. $params["sidebar"] .= elgg_view("blog/sidebar", array("page" => $page_type));
  61. $body = elgg_view_layout("content", $params);
  62. echo elgg_view_page($params["title"], $body);