Commit 4a6903f7 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Move objectionable forms from view library (Bug #1298646)"

parents 73f9396e 2df0d557
......@@ -45,6 +45,13 @@ $string['Help'] = 'Help';
$string['closehelp'] = 'Close help';
$string['applychanges'] = 'Apply changes';
$string['general'] = 'General';
// Objectionable strings.
$string['complaint'] = 'Complaint';
$string['notifyadministrator'] = 'Notify administrator';
$string['notifyadministratorconfirm'] = 'Are you sure you wish to report this page as containing objectionable material?';
$string['notobjectionable'] = 'Not objectionable';
$string['reportobjectionablematerial'] = 'Report objectionable material';
$string['reportsent'] = 'Your report has been sent.';
// responsive design strings
$string['tabs'] = 'Tabs';
$string['tab'] = 'tab';
......
......@@ -119,15 +119,9 @@ $string['addtowatchlistartefact'] = 'Add page "%s" to watchlist';
$string['removefromwatchlistartefact'] = 'Remove page "%s" from watchlist';
$string['alreadyinwatchlist'] = 'This page is already on your watchlist.';
$string['attachedfileaddedtofolder'] = "The attached file %s has been added to your '%s' folder.";
$string['complaint'] = 'Complaint';
$string['date'] = 'Date';
$string['notifyadministrator'] = 'Notify administrator';
$string['notifyadministratorconfirm'] = 'Are you sure you wish to report this page as containing objectionable material?';
$string['print'] = 'Print';
$string['reportobjectionablematerial'] = 'Report objectionable material';
$string['reportsent'] = 'Your report has been sent.';
$string['viewobjectionableunmark'] = 'This page, or something within it, has been reported as containing objectionable content. If this is no longer the case, you can click the button to remove this notice and notify the other administrators.';
$string['notobjectionable'] = 'Not objectionable';
$string['viewunobjectionablesubject'] = 'Page %s was marked as not objectionable by %s.';
$string['viewunobjectionablebody'] = '%s has looked at %s by %s and marked it as no longer containing objectionable material.';
$string['updatewatchlistfailed'] = 'Update of watchlist failed';
......
......@@ -889,6 +889,7 @@ class ActivityTypeObjectionable extends ActivityTypeAdmin {
if (empty($this->strings->subject)) {
$this->overridemessagecontents = true;
$viewtitle = $this->view->get('title');
$this->strings = new stdClass();
if (empty($this->artefact)) {
$this->strings->subject = (object) array(
'key' => 'objectionablecontentview',
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
/**
* Returns a form to report objectionable material.
*
* @returns array Form elements.
*/
function objection_form() {
$form = array(
'name' => 'objection_form',
'method' => 'post',
'class' => 'js-safe-hidden',
'jsform' => true,
'autofocus' => false,
'elements' => array(),
'jssuccesscallback' => 'objectionSuccess',
);
$form['elements']['message'] = array(
'type' => 'textarea',
'title' => get_string('complaint'),
'rows' => 5,
'cols' => 80,
'rules' => array(
'required' => true
)
);
$form['elements']['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('notifyadministrator'), get_string('cancel')),
'confirm' => array(get_string('notifyadministratorconfirm')),
);
return $form;
}
function objection_form_submit(Pieform $form, $values) {
global $USER, $view, $artefact;
if (!$USER->is_logged_in()) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
require_once('activity.php');
db_begin();
// The objectionable access record ensures the view is visible
// to admins, and also marks the view as objectionable.
$accessrecord = (object) array(
'view' => $view->get('id'),
'accesstype' => 'objectionable',
'allowcomments' => 1,
'approvecomments' => 0,
'visible' => 0,
'ctime' => db_format_timestamp(time()),
);
delete_records('view_access', 'view', $view->get('id'), 'accesstype', 'objectionable', 'visible', 0);
insert_record('view_access', $accessrecord);
$data = new StdClass();
$data->view = $view->get('id');
$data->message = $values['message'];
$data->reporter = $USER->get('id');
$data->ctime = time();
if ($artefact) {
$data->artefact = $artefact->get('id');
}
activity_occurred('objectionable', $data);
db_commit();
if ($artefact) {
$goto = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefact->get('id') . '&view='.$view->get('id');
}
else {
$goto = $view->get_url();
}
$form->reply(PIEFORM_OK, array(
'message' => get_string('reportsent'),
'goto' => $goto,
)
);
}
function objection_form_cancel_submit(Pieform $form) {
global $view;
$form->reply(PIEFORM_OK, array(
'goto' => $view->get_url(),
)
);
}
/**
* Returns a form to mark a view as unobjectionable,
* if the user is allowed to do that.
*
* @returns array Form elements.
*/
function notrude_form() {
global $USER, $view;
$owner = $view->get('owner');
if (!(($owner && ($USER->get('admin') || $USER->is_admin_for_user($owner)))
|| ($view->get('group') && $USER->get('admin')))) {
return;
}
$access = View::user_access_records($view->get('id'), $USER->get('id'));
if (empty($access)) {
return;
}
$isrude = false;
foreach ($access as $a) {
// Nasty hack: If the objectionable access record has a stop date, it
// means that one of the admins has already dealt with it, so we don't
// mark the view as objectionable.
if ($a->accesstype == 'objectionable' && empty($a->stopdate)) {
$isrude = true;
break;
}
}
if (!$isrude) {
return;
}
return array(
'name' => 'notrude_form',
'method' => 'post',
'elements' => array(
'text' => array(
'type' => 'html',
'value' => get_string('viewobjectionableunmark', 'view'),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('notobjectionable'),
),
),
);
}
function notrude_form_submit(Pieform $form, $values) {
global $view, $artefact, $USER;
require_once('activity.php');
db_begin();
// Set exipiry date on view access record.
$accessrecord = (object) array(
'view' => $view->get('id'),
'accesstype' => 'objectionable',
'allowcomments' => 1,
'approvecomments' => 0,
'visible' => 0,
'stopdate' => db_format_timestamp(time() + 60*60*24*7),
'ctime' => db_format_timestamp(time()),
);
delete_records('view_access', 'view', $view->get('id'), 'accesstype', 'objectionable', 'visible', 0);
insert_record('view_access', $accessrecord);
// Send notification to other admins.
$reportername = display_default_name($USER);
if ($artefact) {
$goto = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefact->get('id') . '&view=' . $view->get('id');
}
else {
$goto = $view->get_url();
}
$data = (object) array(
'view' => $view->get('id'),
'reporter' => $USER->get('id'),
'subject' => false,
'message' => false,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'viewunobjectionablesubject',
'section' => 'view',
'args' => array($view->get('title'), $reportername),
),
'message' => (object) array(
'key' => 'viewunobjectionablebody',
'section' => 'view',
'args' => array($reportername, $view->get('title'), $view->formatted_owner()),
),
),
);
activity_occurred('objectionable', $data);
db_commit();
$form->reply(PIEFORM_OK, array(
'message' => get_string('messagesent'),
'goto' => $goto,
)
);
}
......@@ -4744,52 +4744,6 @@ class View {
return false;
}
// Returns a form to mark a view as unobjectionable, if the user is allowed
// to do that.
function notrude_form() {
global $USER;
$owner = $this->get('owner');
if (!(($owner && ($USER->get('admin') || $USER->is_admin_for_user($owner)))
|| ($this->get('group') && $USER->get('admin')))) {
return;
}
$access = self::user_access_records($this->id, $USER->get('id'));
if (empty($access)) {
return;
}
$isrude = false;
foreach ($access as $a) {
// Nasty hack: If the objectionable access record has a stop date, it
// means that one of the admins has already dealt with it, so we don't
// mark the view as objectionable.
if ($a->accesstype == 'objectionable' && empty($a->stopdate)) {
$isrude = true;
break;
}
}
if (!$isrude) {
return;
}
return array(
'name' => 'viewnotrude',
'elements' => array(
'text' => array(
'type' => 'html',
'value' => get_string('viewobjectionableunmark', 'view'),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('notobjectionable', 'view'),
),
),
);
}
/**
* Determine whether the current view is of a type which can be themed.
* Certain view types do not respect themes when displayed.
......@@ -5357,156 +5311,6 @@ function view_group_submission_form_submit(Pieform $form, $values) {
redirect('/view/submit.php?' . http_build_query($params));
}
function objection_form() {
$form = array(
'name' => 'objection_form',
'method' => 'post',
'class' => 'js-safe-hidden',
'plugintype' => 'core',
'pluginname' => 'view',
'jsform' => true,
'autofocus' => false,
'elements' => array(),
'jssuccesscallback' => 'objectionSuccess',
);
$form['elements']['message'] = array(
'type' => 'textarea',
'title' => get_string('complaint', 'view'),
'rows' => 5,
'cols' => 80,
'rules' => array(
'required' => true
)
);
$form['elements']['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('notifyadministrator', 'view'), get_string('cancel')),
'confirm' => array(get_string('notifyadministratorconfirm', 'view')),
);
return $form;
}
function objection_form_submit(Pieform $form, $values) {
global $USER, $view, $artefact;
if (!$USER->is_logged_in()) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
require_once('activity.php');
db_begin();
// The objectionable access record ensures the view is visible
// to admins, and also marks the view as objectionable.
$accessrecord = (object) array(
'view' => $view->get('id'),
'accesstype' => 'objectionable',
'allowcomments' => 1,
'approvecomments' => 0,
'visible' => 0,
'ctime' => db_format_timestamp(time()),
);
delete_records('view_access', 'view', $view->get('id'), 'accesstype', 'objectionable', 'visible', 0);
insert_record('view_access', $accessrecord);
$data = new StdClass;
$data->view = $view->get('id');
$data->message = $values['message'];
$data->reporter = $USER->get('id');
$data->ctime = time();
if ($artefact) {
$data->artefact = $artefact->get('id');
}
activity_occurred('objectionable', $data);
db_commit();
if ($artefact) {
$goto = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefact->get('id') . '&view='.$view->get('id');
}
else {
$goto = $view->get_url();
}
$form->reply(PIEFORM_OK, array(
'message' => get_string('reportsent', 'view'),
'goto' => $goto,
));
}
function viewnotrude_submit(Pieform $form, $values) {
global $view, $artefact, $USER;
require_once('activity.php');
db_begin();
// Set exipiry date on view access record
$accessrecord = (object) array(
'view' => $view->get('id'),
'accesstype' => 'objectionable',
'allowcomments' => 1,
'approvecomments' => 0,
'visible' => 0,
'stopdate' => db_format_timestamp(time() + 60*60*24*7),
'ctime' => db_format_timestamp(time()),
);
delete_records('view_access', 'view', $view->get('id'), 'accesstype', 'objectionable', 'visible', 0);
insert_record('view_access', $accessrecord);
// Send notification to other admins
$reportername = display_default_name($USER);
if ($artefact) {
$goto = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefact->get('id') . '&view='.$view->get('id');
}
else {
$goto = $view->get_url();
}
$data = (object) array(
'view' => $view->get('id'),
'reporter' => $USER->get('id'),
'subject' => false,
'message' => false,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'viewunobjectionablesubject',
'section' => 'view',
'args' => array($view->get('title'), $reportername),
),
'message' => (object) array(
'key' => 'viewunobjectionablebody',
'section' => 'view',
'args' => array($reportername, $view->get('title'), $view->formatted_owner()),
),
),
);
activity_occurred('objectionable', $data);
db_commit();
$form->reply(PIEFORM_OK, array(
'message' => get_string('messagesent'),
'goto' => $goto,
));
}
function objection_form_cancel_submit(Pieform $form) {
global $view;
$form->reply(PIEFORM_OK, array(
'goto' => $view->get_url(),
));
}
/**
* display format for author names in views - firstname
*/
......
{if $LOGGEDIN}
<a id="objection_link" class="objection" href="">{str tag=reportobjectionablematerial section=view}</a>
<a id="objection_link" class="objection" href="">{str tag=reportobjectionablematerial}</a>
{/if}
<a id="print_link" class="print" href="" onclick="window.print(); return false;">{str tag=print section=view}</a>
{if $LOGGEDIN}
......
......@@ -2,7 +2,7 @@
<a id="add_feedback_link" class="feedback" href="">{str tag=placefeedback section=artefact.comment}</a>
{/if}
{if $LOGGEDIN}
<a id="objection_link" class="objection" href="">{str tag=reportobjectionablematerial section=view}</a>
<a id="objection_link" class="objection" href="">{str tag=reportobjectionablematerial}</a>
{/if}
<a id="print_link" class="print" href="" onclick="window.print(); return false;">{str tag=print section=view}</a>
{if $LOGGEDIN}
......
......@@ -17,6 +17,7 @@ define('SECTION_PAGE', 'artefact');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'objectionable.php');
safe_require('artefact', 'comment');
$artefactid = param_integer('artefact');
......@@ -153,7 +154,7 @@ if ($artefact->get('allowcomments')) {
$javascript[] = 'jquery.rating';
}
$objectionform = pieform(objection_form());
if ($notrudeform = $view->notrude_form()) {
if ($notrudeform = notrude_form()) {
$notrudeform = pieform($notrudeform);
}
......
......@@ -19,6 +19,7 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'collection.php');
require_once(get_config('libroot') . 'objectionable.php');
require_once('institution.php');
require_once('group.php');
safe_require('artefact', 'comment');
......@@ -175,7 +176,7 @@ if (!empty($releaseform) || ($commenttype = $view->user_comments_allowed($USER))
}
if ($USER->is_logged_in()) {
$objectionform = pieform(objection_form());
if ($notrudeform = $view->notrude_form()) {
if ($notrudeform = notrude_form()) {
$notrudeform = pieform($notrudeform);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment