diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-27 15:20:33 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-27 15:20:33 +0000 |
commit | 10e5db3119afca7060a680517393518be3aa54ab (patch) | |
tree | ec6c1eb164c3d73120bfa2632ebfad3189a94faa | |
parent | 5aa81ebf7107556b39336a326abc421d715c3650 (diff) | |
download | elgg-10e5db3119afca7060a680517393518be3aa54ab.tar.gz elgg-10e5db3119afca7060a680517393518be3aa54ab.tar.bz2 |
Brought generic comments into Elgg core
git-svn-id: https://code.elgg.org/elgg/trunk@1185 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | actions/comments/add.php | 41 | ||||
-rw-r--r-- | actions/comments/delete.php | 35 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 35 | ||||
-rw-r--r-- | languages/en.php | 13 | ||||
-rw-r--r-- | views/default/annotation/generic_comment.php | 54 | ||||
-rw-r--r-- | views/default/comments/forms/edit.php | 38 |
6 files changed, 210 insertions, 6 deletions
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 @@ +<?php
+
+ /**
+ * Elgg add comment action
+ *
+ * @package Elgg
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider <curverider.co.uk>
+ * @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 @@ +<?php
+
+ /**
+ * Elgg delete comment action
+ *
+ * @package Elgg
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider <curverider.co.uk>
+ * @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;
}
@@ -464,6 +464,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.
*
* @param string $icon The icon for the listing
@@ -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 @@ +<?php
+
+ /**
+ * Elgg generic comment
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+?>
+
+
+ <div class="generic_comment"><!-- start of generic_comment div -->
+
+ <div style="float:left;width:60px;">
+ <?php
+ echo elgg_view("profile/icon",array('entity' => get_entity($vars['annotation']->owner_guid), 'size' => 'tiny'));
+ ?>
+ </div>
+ <p>
+ <?php echo get_user($vars['annotation']->owner_guid)->username . " on " . friendly_time($vars['annotation']->time_created); ?>
+ </p>
+
+ <!-- output the actual comment -->
+ <p><?php echo elgg_view("output/longtext",array("value" => $vars['annotation']->value)); ?></p>
+
+ <?php
+
+ // if the user looking at the comment can edit, show the delete link
+ if ($vars['annotation']->canEdit()) {
+
+ ?>
+ <p>
+ <?php
+
+ echo elgg_view("output/confirmlink",array(
+ 'href' => $vars['url'] . "action/comments/delete&annotation_id=" . $vars['annotation']->id,
+ 'text' => elgg_echo('delete'),
+ 'confirm' => elgg_echo('deleteconfirm'),
+ ));
+
+ ?>
+ </p>
+
+ <?php
+ } //end of can edit if statement
+ ?>
+
+ </div><!-- end of generic_comment div -->
\ 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 @@ +<?php
+
+ /**
+ * Elgg comments add form
+ *
+ * @package Elgg
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd <info@curverider.co.uk>
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ *
+ * @uses $vars['entity']
+ */
+
+ if (isset($vars['entity'])) {
+
+?>
+
+ <form action="<?php echo $vars['url']; ?>action/comments/add" method="post">
+ <h3>
+ <?php echo elgg_echo("generic_comments:add"); ?>
+ </h3>
+ <p>
+ <label><?php echo elgg_echo("generic_comments:text"); ?><br />
+ <textarea name="generic_comment" value="" id="generic_comment" class="expanding" /></textarea>
+ </label>
+ </p>
+ <p>
+ <input type="hidden" name="entity_guid" value="<?php echo $vars['entity']->getGUID(); ?>" />
+ <input type="submit" value="<?php echo elgg_echo("save"); ?>" />
+ </p>
+ </form>
+
+<?php
+
+ }
+
+?>
\ No newline at end of file |