Skip to content

Commit

Permalink
feature(plugins): adds several reported content features
Browse files Browse the repository at this point in the history
Ajaxifies the reporting form (form page still BC) and delete/archive
actions. Sorts un-archived reports at the top of results. More compact
report display, and clicking reported link opens page in an iframe
in colorbox.

Fixes Elgg#5379, Elgg#6082, Elgg#5380
  • Loading branch information
mrclay committed Dec 25, 2014
1 parent ab77add commit a13d29d
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 105 deletions.
49 changes: 25 additions & 24 deletions mod/reportedcontent/actions/reportedcontent/add.php
Expand Up @@ -9,31 +9,32 @@
$address = get_input('address');
$access = ACCESS_PRIVATE; //this is private and only admins can see it

if ($title && $address) {
$fail = function () use ($address) {
register_error(elgg_echo('reportedcontent:failed'));
forward($address);
};

$report = new ElggObject;
$report->subtype = "reported_content";
$report->owner_guid = elgg_get_logged_in_user_guid();
$report->title = $title;
$report->address = $address;
$report->description = $description;
$report->access_id = $access;
if (!$title || !$address) {
$fail();
}

if ($report->save()) {
if (!elgg_trigger_plugin_hook('reportedcontent:add', 'system', array('report' => $report), true)) {
$report->delete();
register_error(elgg_echo('reportedcontent:failed'));
} else {
system_message(elgg_echo('reportedcontent:success'));
$report->state = "active";
}
forward($address);
} else {
register_error(elgg_echo('reportedcontent:failed'));
forward($address);
}
} else {
$report = new ElggObject;
$report->subtype = "reported_content";
$report->owner_guid = elgg_get_logged_in_user_guid();
$report->title = $title;
$report->address = $address;
$report->description = $description;
$report->access_id = $access;

register_error(elgg_echo('reportedcontent:failed'));
forward($address);
if (!$report->save()) {
$fail();
}

if (!elgg_trigger_plugin_hook('reportedcontent:add', 'system', array('report' => $report), true)) {
$report->delete();
$fail();
}

system_message(elgg_echo('reportedcontent:success'));
$report->state = "active";
forward($address);
27 changes: 13 additions & 14 deletions mod/reportedcontent/actions/reportedcontent/archive.php
Expand Up @@ -8,20 +8,19 @@
$guid = (int) get_input('guid');

$report = get_entity($guid);
if (!$report || $report->getSubtype() !== "reported_content" || !$report->canEdit()) {
register_error(elgg_echo("reportedcontent:notarchived"));
forward(REFERER);
}

// Make sure we actually have permission to edit
if ($report->getSubtype() == "reported_content" && $report->canEdit()) {

// allow another plugin to override
if (!elgg_trigger_plugin_hook('reportedcontent:archive', 'system', array('report' => $report), TRUE)) {
system_message(elgg_echo("reportedcontent:notarchived"));
forward(REFERER);
}

// change the state
$report->state = "archived";

system_message(elgg_echo("reportedcontent:archived"));

// allow another plugin to override
if (!elgg_trigger_plugin_hook('reportedcontent:archive', 'system', ['report' => $report], true)) {
register_error(elgg_echo("reportedcontent:notarchived"));
forward(REFERER);
}

// change the state
$report->state = "archived";

system_message(elgg_echo("reportedcontent:archived"));
forward(REFERER);
30 changes: 15 additions & 15 deletions mod/reportedcontent/actions/reportedcontent/delete.php
Expand Up @@ -8,21 +8,21 @@
$guid = (int) get_input('guid');

$report = get_entity($guid);
if (!$report || $report->getSubtype() !== "reported_content" || !$report->canEdit()) {
register_error(elgg_echo("reportedcontent:notdeleted"));
forward(REFERER);
}

// Make sure we actually have permission to delete
if ($report->getSubtype() == "reported_content" && $report->canEdit()) {

// give another plugin a chance to override
if (!elgg_trigger_plugin_hook('reportedcontent:delete', 'system', array('report' => $report), TRUE)) {
register_error(elgg_echo("reportedcontent:notdeleted"));
forward(REFERER);
}

if ($report->delete()) {
system_message(elgg_echo("reportedcontent:deleted"));
} else {
register_error(elgg_echo("reportedcontent:notdeleted"));
}

// give another plugin a chance to override
if (!elgg_trigger_plugin_hook('reportedcontent:delete', 'system', array('report' => $report), true)) {
register_error(elgg_echo("reportedcontent:notdeleted"));
forward(REFERER);
}

if ($report->delete()) {
system_message(elgg_echo("reportedcontent:deleted"));
} else {
register_error(elgg_echo("reportedcontent:notdeleted"));
}

forward(REFERER);
13 changes: 8 additions & 5 deletions mod/reportedcontent/start.php
Expand Up @@ -21,19 +21,17 @@ function reportedcontent_init() {

// Extend footer with report content link
if (elgg_is_logged_in()) {
$href = "javascript:elgg.forward('reportedcontent/add'";
$href .= "+'?address='+encodeURIComponent(location.href)";
$href .= "+'&title='+encodeURIComponent(document.title));";

elgg_register_menu_item('extras', array(
'name' => 'report_this',
'href' => $href,
'href' => 'reportedcontent/add',
'title' => elgg_echo('reportedcontent:this:tooltip'),
'text' => elgg_view_icon('report-this'),
'priority' => 500,
'section' => 'default',
'link_class' => 'elgg-lightbox',
));
}
elgg_require_js('reportedcontent');

elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'reportedcontent_user_hover_menu');

Expand Down Expand Up @@ -66,6 +64,11 @@ function reportedcontent_page_handler($page) {
// only logged in users can report things
elgg_gatekeeper();

if (elgg_extract(0, $page) === 'add' && elgg_is_xhr()) {
echo elgg_view('resources/reportedcontent/add_form');
return true;
}

$title = elgg_echo('reportedcontent:this');

$content = elgg_view_form('reportedcontent/add');
Expand Down
Expand Up @@ -5,7 +5,15 @@
* @package ElggReportedContent
*/

$list = elgg_list_entities(array('type' => 'object', 'subtype' => 'reported_content'));
$list = elgg_list_entities_from_metadata([
'type' => 'object',
'subtype' => 'reported_content',
'order_by_metadata' => [
'name' => 'state',
'direction' => 'ASC',
'as' => 'text',
],
]);
if (!$list) {
$list = '<p class="mtm">' . elgg_echo('reportedcontent:none') . '</p>';
}
Expand Down
23 changes: 17 additions & 6 deletions mod/reportedcontent/views/default/forms/reportedcontent/add.php
Expand Up @@ -29,11 +29,11 @@
<label>
<?php
echo elgg_echo('reportedcontent:address');
echo elgg_view('input/url', array(
'name' => 'address',
'value' => $address,
));

echo elgg_view('input/url', [
'name' => 'address',
'value' => $address,
'readonly' => (bool)$address,
]);
?>
</label>
</div>
Expand All @@ -42,7 +42,7 @@
<?php echo elgg_echo('reportedcontent:description'); ?>
</label>
<?php
echo elgg_view('input/longtext',array(
echo elgg_view('input/plaintext',array(
'name' => 'description',
'value' => $description,
));
Expand All @@ -53,5 +53,16 @@
echo elgg_view('input/submit', array(
'value' => elgg_echo('reportedcontent:report'),
));
if (elgg_is_xhr()) {
$js = 'elgg.ui.lightbox.close()';
} else {
$js = 'history.go(-1)';
}
echo elgg_view('output/url', [
'value' => "javascript:$js",
'text' => elgg_echo('cancel'),
'class' => 'elgg-button elgg-button-cancel mls',
'is_trusted' => true,
]);
?>
</div>
50 changes: 50 additions & 0 deletions mod/reportedcontent/views/default/js/reportedcontent.js
@@ -0,0 +1,50 @@
define(function (require) {
var elgg = require('elgg'),
$ = require('jquery');

var $a = $('.elgg-menu-item-report-this a');
if ($a.length) {
$a[0].href += '?address=' + encodeURIComponent(location.href) +
'&title=' + encodeURIComponent(document.title);
}

$(document).on('submit', '.elgg-form-reportedcontent-add', function (e) {
e.preventDefault();
var $form = $(this);
elgg.action($form[0].action, {
data: $form.serialize(),
success: function (data) {
if (data.status == 0) {
elgg.ui.lightbox.close();
}
}
});
});

$(document).on('click', '.elgg-item-object-reported_content', function (e) {
var $clicked = $(e.target),
$li = $(this);

if ($clicked.is('a[data-elgg-action]')) {
var action = $clicked.data('elggAction');
elgg.action(action.name, {
data: action.data,
success: function (data) {
if (data.status == -1) {
return;
}

if (action.name === 'reportedcontent/delete') {
$li.slideUp();
} else {
$clicked.fadeOut();
$li.find('.reported-content-active')
.removeClass('reported-content-active')
.addClass('reported-content-archived');
}
}
});
return false;
}
})
});
74 changes: 36 additions & 38 deletions mod/reportedcontent/views/default/object/reported_content.php
Expand Up @@ -6,11 +6,9 @@
*/

$report = $vars['entity'];
/* @var ElggObject $report */
$reporter = $report->getOwnerEntity();

$archive_url = elgg_get_site_url() . "action/reportedcontent/archive?guid=$report->guid";
$delete_url = elgg_get_site_url() . "action/reportedcontent/delete?guid=$report->guid";

//find out if the report is current or archive
if ($report->state == 'archived') {
$reportedcontent_background = "reported-content-archived";
Expand All @@ -26,59 +24,59 @@
<?php
if ($report->state != 'archived') {
$params = array(
'href' => $archive_url,
'href' => 'javascript:',
'text' => elgg_echo('reportedcontent:archive'),
'is_action' => true,
'is_trusted' => true,
'class' => 'elgg-button elgg-button-action',
'data-elgg-action' => json_encode([
'name' => 'reportedcontent/archive',
'data' => [
'guid' => $report->guid,
]
]),
);
echo elgg_view('output/url', $params);
}
$params = array(
'href' => $delete_url,
'href' => 'javascript:',
'text' => elgg_echo('reportedcontent:delete'),
'is_action' => true,
'is_trusted' => true,
'class' => 'elgg-button elgg-button-action',
'data-elgg-action' => json_encode([
'name' => 'reportedcontent/delete',
'data' => [
'guid' => $report->guid,
]
]),
);
echo elgg_view('output/url', $params);
?>
</div>
<p>
<b><?php echo elgg_echo('reportedcontent:by'); ?>:</b>
<?php echo elgg_view('output/url', array(
'href' => $reporter->getURL(),
'text' => $reporter->name,
'is_trusted' => true,
));
?>,
<?php echo elgg_view_friendly_time($report->time_created); ?>
</p>
<p>
<b><?php echo elgg_echo('title'); ?>:</b>
<?php echo $report->title; ?>
<p>
<b><?php echo elgg_echo('reportedcontent:objecturl'); ?>:</b>
<?php echo elgg_view('output/url', array(
<h3 class="mbm">
<?php echo elgg_view('output/url', [
'text' => $report->title,
'href' => $report->address,
'text' => elgg_echo('reportedcontent:visit'),
'is_trusted' => true,
));
'class' => 'elgg-reported-content-address elgg-lightbox',
'data-colorbox-opts' => json_encode([
'width' => '85%',
'height' => '85%',
'iframe' => true,
]),
]);
?>
</p>
<p>
<?php echo elgg_view('output/url', array(
'href' => "#report-$report->guid",
'text' => elgg_echo('more_info'),
'rel' => "toggle",
));
</h3>
<p><b><?php echo elgg_echo('reportedcontent:by') ?></b>
<?php echo elgg_view('output/url', [
'href' => $reporter->getURL(),
'text' => $reporter->name,
'is_trusted' => true,
]);
echo " " . elgg_view_friendly_time($report->time_created);
?>
</p>
</div>
<div class="report-details hidden" id="report-<?php echo $report->getGUID();?>">
<p>
<b><?php echo elgg_echo('reportedcontent:reason'); ?>:</b>
<?php echo $report->description; ?>
</p>
<?php if ($report->description): ?>
<p><?php echo $report->description; ?></p>
<?php endif; ?>
</div>
</div>
@@ -0,0 +1,3 @@
<?php

echo elgg_view_form('reportedcontent/add');

0 comments on commit a13d29d

Please sign in to comment.