From 10e5db3119afca7060a680517393518be3aa54ab Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 27 Jun 2008 15:20:33 +0000 Subject: Brought generic comments into Elgg core git-svn-id: https://code.elgg.org/elgg/trunk@1185 36083f99-b078-4883-b0ff-0f9b5a30f544 --- actions/comments/add.php | 41 +++++++++++++++++++++ actions/comments/delete.php | 35 ++++++++++++++++++ engine/lib/elgglib.php | 35 +++++++++++++++--- languages/en.php | 13 ++++++- views/default/annotation/generic_comment.php | 54 ++++++++++++++++++++++++++++ views/default/comments/forms/edit.php | 38 ++++++++++++++++++++ 6 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 actions/comments/add.php create mode 100644 actions/comments/delete.php create mode 100644 views/default/annotation/generic_comment.php create mode 100644 views/default/comments/forms/edit.php diff --git a/actions/comments/add.php b/actions/comments/add.php new file mode 100644 index 000000000..4f3d5eee8 --- /dev/null +++ b/actions/comments/add.php @@ -0,0 +1,41 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + // Make sure we're logged in; forward to the front page if not + if (!isloggedin()) forward(); + + // Get input + $entity_guid = (int) get_input('entity_guid'); + $comment_text = get_input('generic_comment'); + + // Let's see if we can get an entity with the specified GUID + if ($entity = get_entity($entity_guid)) { + + // If posting the comment was successful, say so + if ($entity->annotate('generic_comment',$comment_text,$entity->access_id, $_SESSION['guid'])) { + + system_message(elgg_echo("generic_comment:posted")); + + } else { + system_message(elgg_echo("generic_comment:failure")); + } + + } else { + + system_message(elgg_echo("generic_comment:notfound")); + + } + + // Forward to the + forward($entity->getURL()); + +?> \ No newline at end of file diff --git a/actions/comments/delete.php b/actions/comments/delete.php new file mode 100644 index 000000000..26875942c --- /dev/null +++ b/actions/comments/delete.php @@ -0,0 +1,35 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + // Ensure we're logged in + if (!isloggedin()) forward(); + + // Make sure we can get the comment in question + $annotation_id = (int) get_input('annotation_id'); + if ($comment = get_annotation($annotation_id)) { + + $entity = get_entity($comment->entity_guid); + + if ($comment->canEdit()) { + $comment->delete(); + system_message(elgg_echo("generic_comment:deleted")); + forward($entity->getURL()); + } + + } else { + $url = ""; + } + + system_message(elgg_echo("generic_comment:notdeleted")); + forward($entity->getURL()); + +?> \ No newline at end of file diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 3b8e444d7..d4feabf53 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -321,7 +321,7 @@ $name = get_metastring($intname); } if (empty($name)) { return ""; } - + if (elgg_view_exists("annotation/{$name}")) { return elgg_view("annotation/{$name}",array( 'annotation' => $annotation, @@ -413,7 +413,7 @@ )); $html .= $nav; - + if (is_array($annotations) && sizeof($annotations) > 0) { foreach($annotations as $annotation) { $html .= elgg_view_annotation($annotation, "", false); @@ -422,7 +422,7 @@ if ($count) $html .= $nav; - + return $html; } @@ -463,6 +463,25 @@ } + /** + * Automatically views comments and a comment form relating to the given entity + * + * @param ElggEntity $entity The entity to comment on + * @return string|false The HTML (etc) for the comments, or false on failure + */ + function elgg_view_comments($entity){ + + if (!($entity instanceof ElggEntity)) return false; + + $comments = list_annotations($entity->getGUID(),'generic_comment'); + + //display the comment form + $comments .= elgg_view('comments/forms/edit',array('entity' => $entity)); + + return $comments; + + } + /** * Wrapper function to display search listings. * @@ -1491,7 +1510,13 @@ $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; } - - + + function elgg_init() { + // Important actions + register_action('comments/add'); + register_action('comments/delete'); + } + + register_elgg_event_handler('init','system','elgg_init'); ?> \ No newline at end of file diff --git a/languages/en.php b/languages/en.php index 13d2ce306..44bf369ae 100644 --- a/languages/en.php +++ b/languages/en.php @@ -506,7 +506,18 @@ Your password has been reset to: %s", */ 'xmlrpc:noinputdata' => "Input data missing", - + /** + * Comments + */ + + 'generic_comments:add' => "Add a comment", + 'generic_comments:text' => "Comment", + 'generic_comment:posted' => "Your comment was successfully posted.", + 'generic_comment:deleted' => "Your comment was successfully deleted.", + 'generic_comment:blank' => "Sorry; you need to actually put something in your comment before we can save it.", + 'generic_comment:notfound' => "Sorry; we could not find the specified item.", + 'generic_comment:notdeleted' => "Sorry; we could not delete this comment.", + 'generic_comment:failure' => "An unexpected error occurred when adding your comment. Please try again.", /** * Languages according to ISO 639-1 diff --git a/views/default/annotation/generic_comment.php b/views/default/annotation/generic_comment.php new file mode 100644 index 000000000..a18bd9eb3 --- /dev/null +++ b/views/default/annotation/generic_comment.php @@ -0,0 +1,54 @@ + + + +
+ +
+ get_entity($vars['annotation']->owner_guid), 'size' => 'tiny')); + ?> +
+

+ owner_guid)->username . " on " . friendly_time($vars['annotation']->time_created); ?> +

+ + +

$vars['annotation']->value)); ?>

+ + canEdit()) { + + ?> +

+ $vars['url'] . "action/comments/delete&annotation_id=" . $vars['annotation']->id, + 'text' => elgg_echo('delete'), + 'confirm' => elgg_echo('deleteconfirm'), + )); + + ?> +

+ + + +
\ No newline at end of file diff --git a/views/default/comments/forms/edit.php b/views/default/comments/forms/edit.php new file mode 100644 index 000000000..f28a53b36 --- /dev/null +++ b/views/default/comments/forms/edit.php @@ -0,0 +1,38 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + * + * @uses $vars['entity'] + */ + + if (isset($vars['entity'])) { + +?> + +
+

+ +

+

+ +

+

+ + " /> +

+
+ + \ No newline at end of file -- cgit v1.2.3