123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace AU\AnonymousComments;
- elgg_make_sticky_form('comments/anon_add');
- elgg_register_plugin_hook_handler('htmlawed', 'config', __NAMESPACE__ . '\\htmlawed_config');
- $anon_name = get_input('anon_name');
- $anon_email = get_input('anon_email');
- $entity_guid = (int) get_input('entity_guid', 0, false);
- $comment_guid = (int) get_input('comment_guid', 0, false);
- $comment_text = get_input('generic_comment');
- if (empty($comment_text)) {
- register_error(elgg_echo("generic_comment:blank"));
- forward(REFERER);
- }
- if (empty($anon_name)) {
- register_error(elgg_echo("AU_anonymous_comments:name_blank"));
- forward(REFERER);
- }
- if (empty($anon_email)) {
- register_error(elgg_echo("AU_anonymous_comments:email_blank"));
- forward(REFERER);
- }
- if (substr_count($comment_text, "http://") > 1 || substr_count($comment_text, "https://") > 1) {
- register_error(elgg_echo("AU_anonymous_comments:no_URLs_allowed"));
- forward(REFERER);
- }
- if (substr_count($comment_text, elgg_echo("AU_anonymous_comments:longtextwarning")) > 0) {
- register_error(elgg_echo("AU_anonymous_comments:didntdelete"));
- forward(REFERER);
- }
-
- $entity = get_entity($entity_guid);
- if (!$entity) {
- register_error(elgg_echo("generic_comment:notfound"));
- forward(REFERER);
- }
- $user = get_anon_user();
- elgg_push_context("AU_anonymous_comments_permissions");
- $comment_text .= "\n\n- " . $anon_name;
- $comment = new \ElggComment();
- $comment->description = $comment_text;
- $comment->owner_guid = $user->getGUID();
- $comment->container_guid = $entity->getGUID();
- $comment->access_id = $entity->access_id;
- $guid = $comment->save();
- if (!$guid) {
- register_error(elgg_echo("generic_comment:failure"));
- forward(REFERER);
- }
- if (!is_moderated($entity)) {
- $owner = $entity->getOwnerEntity();
- notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array(
- $entity->title,
- $anon_name . " ({$anon_email})",
- $comment_text,
- $entity->getURL(),
- $user->name,
- $user->getURL()
- ), $owner->language), array(
- 'object' => $comment,
- 'action' => 'create',
- )
- );
- }
- else {
- $token = get_token($comment);
- $approveURL = elgg_normalize_url("auac/approve/{$comment->guid}/{$token}");
- $deleteURL = elgg_normalize_url("auac/delete/{$comment->guid}/{$token}");
- notify_user($owner->guid, $user->guid, elgg_echo('AU_anonymous_comments:email:subject', array(), $owner->language), elgg_echo('AU_anonymous_comments:email:body', array(
- $entity->title,
- $anon_name . " ({$anon_email}, IP:" . get_ip() . ")",
- $comment_text,
- $entity->getURL(),
- $approveURL,
- $deleteURL
- ), $owner->language), array(
- 'object' => $comment,
- 'action' => 'create',
- )
- );
- }
- if (elgg_get_plugin_setting('add_to_river', PLUGIN_ID) == 'yes') {
- elgg_create_river_item(array(
- 'view' => 'river/object/comment/create',
- 'action_type' => 'comment',
- 'subject_guid' => $user->guid,
- 'object_guid' => $guid,
- 'target_guid' => $entity_guid,
- ));
- }
- if (is_moderated($entity)) {
-
- $comment->disable();
- }
- elgg_pop_context();
- elgg_clear_sticky_form('comments/anon_add');
- system_message(elgg_echo('AU_anonymous_comments:comment_success'));
- forward(REFERER);
|