aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-04 17:36:44 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-04 17:36:44 +0000
commitd06f87fadb1b88f8ae251ada0461dd2cebf84a00 (patch)
tree5e90ffdb4dcc46978bcde6bd839243aad02d7799 /mod
parent4ec8a466b8ae9bfcb495b57cc1c90ac8de3533e2 (diff)
downloadelgg-d06f87fadb1b88f8ae251ada0461dd2cebf84a00.tar.gz
elgg-d06f87fadb1b88f8ae251ada0461dd2cebf84a00.tar.bz2
Blog edit updates
git-svn-id: https://code.elgg.org/elgg/trunk@408 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod')
-rw-r--r--mod/blog/actions/edit.php68
-rw-r--r--mod/blog/edit.php11
-rw-r--r--mod/blog/start.php6
-rw-r--r--mod/blog/views/default/blog/forms/edit.php15
-rw-r--r--mod/blog/views/default/object/blog.php16
5 files changed, 111 insertions, 5 deletions
diff --git a/mod/blog/actions/edit.php b/mod/blog/actions/edit.php
new file mode 100644
index 000000000..07f285510
--- /dev/null
+++ b/mod/blog/actions/edit.php
@@ -0,0 +1,68 @@
+<?php
+
+ /**
+ * Elgg blog: edit post action
+ *
+ * @package ElggBlog
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Ben Werdmuller <ben@curverider.co.uk>
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */
+
+ // Make sure we're logged in (send us to the front page if not)
+ if (!isloggedin()) forward();
+
+ // Get input data
+ $guid = (int) get_input('blogpost');
+ $title = get_input('blogtitle');
+ $body = get_input('blogbody');
+ $tags = get_input('blogtags');
+
+ // Make sure we actually have permission to edit
+ $blog = get_entity($guid);
+ if ($blog->subtype = "blog" && $blog->canEdit()) {
+
+ // Cache to the session
+ $_SESSION['blogtitle'] = $title;
+ $_SESSION['blogbody'] = $body;
+ $_SESSION['blogtags'] = $tags;
+
+ // Convert string of tags into a preformatted array
+ $tagarray = string_to_tag_array($tags);
+
+ // Make sure the title / description aren't blank
+ if (empty($title) || empty($body)) {
+ register_error(elgg_echo("blog:blank"));
+ forward("mod/blog/add.php");
+
+ // Otherwise, save the blog post
+ } else {
+
+ // For now, set its access to public (we'll add an access dropdown shortly)
+ $blog->access_id = 2;
+ // Set its title and description appropriately
+ $blog->title = $title;
+ $blog->description = $body;
+ // Before we can set metadata, we need to save the blog post
+ if (!$blog->save()) {
+ register_error(elgg_echo("blog:error"));
+ forward("mod/blog/add.php");
+ }
+ // Now let's add tags. We can pass an array directly to the object property! Easy.
+ $blog->clearMetadata('tags');
+ if (is_array($tagarray)) {
+ $blog->tags = $tagarray;
+ }
+ // Success message
+ system_message(elgg_echo("blog:posted"));
+ // Remove the blog post cache
+ unset($_SESSION['blogtitle']); unset($_SESSION['blogbody']); unset($_SESSION['blogtags']);
+ // Forward to the main blog page
+ forward("mod/blog/?username=" . $_SESSION['user']->username);
+
+ }
+
+ }
+
+?> \ No newline at end of file
diff --git a/mod/blog/edit.php b/mod/blog/edit.php
index 4da1a4814..262973f54 100644
--- a/mod/blog/edit.php
+++ b/mod/blog/edit.php
@@ -14,7 +14,16 @@
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
// Get the post, if it exists
- if (get_object())
+ $blogpost = (int) get_input('blogpost');
+ if ($post = get_entity($blogpost)) {
+
+ if ($post->canEdit()) {
+
+ $body = elgg_view("blog/forms/edit", array('entity' => $post));
+
+ }
+
+ }
// Display page
page_draw(sprintf(elgg_echo('blog:editpost'),$post->title),$body);
diff --git a/mod/blog/start.php b/mod/blog/start.php
index d7def030d..e257a2d5c 100644
--- a/mod/blog/start.php
+++ b/mod/blog/start.php
@@ -35,6 +35,11 @@
menu_item(elgg_echo('blog:addpost'),$CONFIG->wwwroot."mod/blog/add.php"),
menu_item(elgg_echo('blog:everyone'),$CONFIG->wwwroot."mod/blog/everyone.php"),
));
+ // And for logged out users
+ } else {
+ add_menu(elgg_echo('blog'), $CONFIG->wwwroot . "mod/blog/",array(
+ menu_item(elgg_echo('blog:everyone'),$CONFIG->wwwroot."mod/blog/everyone.php"),
+ ));
}
// Extend system CSS with our own styles, which are defined in the blog/css view
@@ -48,6 +53,7 @@
// Register actions
global $CONFIG;
register_action("blog/add",false,$CONFIG->pluginspath . "blog/actions/add.php");
+ register_action("blog/edit",false,$CONFIG->pluginspath . "blog/actions/edit.php");
register_action("blog/comments/add",false,$CONFIG->pluginspath . "blog/actions/comments/add.php");
?> \ 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
index fb069961b..ff8ae8767 100644
--- a/mod/blog/views/default/blog/forms/edit.php
+++ b/mod/blog/views/default/blog/forms/edit.php
@@ -13,12 +13,12 @@
*/
// Set title, form destination
- if (isset($vars['object'])) {
+ if (isset($vars['entity'])) {
$title = sprintf(elgg_echo("blog:editpost"),$object->title);
$action = "blog/edit";
- $title = $vars['object']->title;
- $body = $vars['object']->description;
- $tags = $vars['object']->tags;
+ $title = $vars['entity']->title;
+ $body = $vars['entity']->description;
+ $tags = $vars['entity']->tags;
} else {
$title = elgg_echo("blog:addpost");
$action = "blog/add";
@@ -76,6 +76,13 @@
?>
</p>
<p>
+ <?php
+
+ if (isset($vars['entity'])) {
+ ?><input type="hidden" name="blogpost" value="<?php echo $vars['entity']->getGUID(); ?>" /><?php
+ }
+
+ ?>
<input type="submit" value="<?php echo elgg_echo('save'); ?>" />
</p>
diff --git a/mod/blog/views/default/object/blog.php b/mod/blog/views/default/object/blog.php
index b136267d7..6fcf041ba 100644
--- a/mod/blog/views/default/object/blog.php
+++ b/mod/blog/views/default/object/blog.php
@@ -44,6 +44,22 @@
?>
</p>
+ <?php
+
+ if ($vars['entity']->canEdit()) {
+ ?>
+ <a href="<?php echo $vars['url']; ?>mod/blog/edit.php?blogpost=<?php echo $vars['entity']->getGUID(); ?>"><?php echo elgg_echo("edit"); ?></a>
+ <a href="<?php echo $vars['url']; ?>mod/blog/delete.php?blogpost=<?php echo $vars['entity']->getGUID(); ?>"><?php echo elgg_echo("delete"); ?></a>
+ <?php
+
+ // Allow the menu to be extended
+ echo elgg_view("editmenu",array('entity' => $vars['entity']));
+
+ ?>
+ <?php
+ }
+
+ ?>
</div>
<?php