Example #1
0
<?php

namespace AU\AnonymousComments;

$values = elgg_get_sticky_values('comments/anon_add');
elgg_clear_sticky_form('comments/anon_add');
//provide instructions to the user
if (is_moderated($vars['entity'])) {
    echo "<div style=\"clear: both\">" . elgg_echo('AU_anonymous_comments:moderated_notice') . "</div>";
}
echo '<div>';
echo '<label class="required">' . elgg_echo('AU_anonymous_comments:name') . '</label>';
echo elgg_view('input/text', array('name' => 'anon_name', 'value' => $values['anon_name'], 'class' => 'AU-anonymous-comments-field'));
echo '</div>';
echo '<div class="pts">';
echo '<label class="required">' . elgg_echo('AU_anonymous_comments:email') . '</label>';
echo elgg_view('input/email', array('name' => 'anon_email', 'value' => $values['anon_email'], 'class' => 'AU-anonymous-comments-field'));
echo elgg_view('output/longtext', array('value' => elgg_echo('AU_anonymous_comments:email:help'), 'class' => 'elgg-subtext'));
echo '</div>';
echo '<div class="pts">';
echo "<label>" . elgg_echo("generic_comments:text") . "</label>";
echo elgg_view('input/longtext', array('name' => 'generic_comment', 'value' => elgg_echo('AU_anonymous_comments:longtextwarning')));
echo '</div>';
echo '<div class="elgg-foot">';
echo elgg_view('input/hidden', array('name' => 'entity_guid', 'value' => $vars['entity']->guid));
echo elgg_view('input/submit', array('value' => elgg_echo("AU_anonymous_comments:post:comment")));
echo '</div>';
Example #2
0
$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'));
}
// Add to river
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)) {
    // disable the comment until approved
    $comment->disable();
}
elgg_pop_context();
elgg_clear_sticky_form('comments/anon_add');
system_message(elgg_echo('AU_anonymous_comments:comment_success'));
forward(REFERER);
Example #3
0
/**
 * This function checks if the entity is being moderated, if so we need to count
 * and return the number of APPROVED comments, not total comments
 * called by commments:count plugin hook
 * 
 * @param type $hook
 * @param type $type
 * @param type $returnvalue
 * @param type $params
 * @return int
 */
function comment_count_hook($hook, $type, $return, $params)
{
    if (!is_moderated($params['entity'])) {
        return $return;
    }
    if (!$params['entity']->canEdit()) {
        return $return;
    }
    // can edit the content? can moderate
    // set a flag for us to see disabled comments
    $show_hidden = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    $options = array('type' => 'object', 'subtype' => 'comment', 'container_guid' => $params['entity']->guid, 'count' => true);
    $total = (int) elgg_get_entities($options);
    // restore the flag
    access_show_hidden_entities($show_hidden);
    return $total;
}