Check file type before other checks
This commit is contained in:
parent
19baa5109f
commit
070672f974
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package plagiarism_pchkorg
|
||||||
|
* @category plagiarism
|
||||||
|
* @copyright PlagiarismCheck.org, https://plagiarismcheck.org/
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
require_once($CFG->dirroot . '/plagiarism/pchkorg/lib.php');
|
||||||
|
|
||||||
|
class plagiarism_pchkorg_observer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the assignment assessable_uploaded event.
|
||||||
|
*
|
||||||
|
* @param \assignsubmission_file\event\assessable_uploaded $event
|
||||||
|
*/
|
||||||
|
public static function assignsubmission_file_uploaded(
|
||||||
|
\assignsubmission_file\event\assessable_uploaded $event) {
|
||||||
|
$eventdata = $event->get_data();
|
||||||
|
$eventdata['eventtype'] = 'file_uploaded';
|
||||||
|
$eventdata['other']['modulename'] = 'assign';
|
||||||
|
|
||||||
|
$plugin = new plagiarism_plugin_pchkorg();
|
||||||
|
$plugin->event_handler($eventdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the assignment assessable_uploaded event.
|
||||||
|
*
|
||||||
|
* @param \assignsubmission_onlinetext\event\assessable_uploaded $event
|
||||||
|
*/
|
||||||
|
public static function assignsubmission_onlinetext_uploaded(
|
||||||
|
\assignsubmission_onlinetext\event\assessable_uploaded $event) {
|
||||||
|
$eventdata = $event->get_data();
|
||||||
|
$eventdata['eventtype'] = 'content_uploaded';
|
||||||
|
$eventdata['other']['modulename'] = 'assign';
|
||||||
|
|
||||||
|
$plugin = new plagiarism_plugin_pchkorg();
|
||||||
|
$plugin->event_handler($eventdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the assignment assessable_submitted event.
|
||||||
|
*
|
||||||
|
* @param \mod_assign\event\assessable_submitted $event
|
||||||
|
*/
|
||||||
|
public static function assignsubmission_submitted(
|
||||||
|
\mod_assign\event\assessable_submitted $event) {
|
||||||
|
$eventdata = $event->get_data();
|
||||||
|
$eventdata['eventtype'] = 'assessable_submitted';
|
||||||
|
$eventdata['other']['modulename'] = 'assign';
|
||||||
|
|
||||||
|
$plugin = new plagiarism_plugin_pchkorg();
|
||||||
|
$plugin->event_handler($eventdata);
|
||||||
|
}
|
||||||
|
}
|
|
@ -63,6 +63,8 @@ class plagiarism_pchkorg_api_provider {
|
||||||
* @param string $endpoint
|
* @param string $endpoint
|
||||||
*/
|
*/
|
||||||
public function __construct($token, $endpoint = 'https://plagiarismcheck.org') {
|
public function __construct($token, $endpoint = 'https://plagiarismcheck.org') {
|
||||||
|
|
||||||
|
$this->endpoint = 'http://plagcheck.local';
|
||||||
$this->token = $token;
|
$this->token = $token;
|
||||||
$this->endpoint = $endpoint;
|
$this->endpoint = $endpoint;
|
||||||
}
|
}
|
||||||
|
@ -257,6 +259,7 @@ class plagiarism_pchkorg_api_provider {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function user_email_to_hash($email) {
|
public function user_email_to_hash($email) {
|
||||||
|
// We don't send raw user email to service.
|
||||||
return hash('sha256', $this->token . $email);
|
return hash('sha256', $this->token . $email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,24 +279,31 @@ class plagiarism_pchkorg_api_provider {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$curl = new curl();
|
static $resultmap = array();
|
||||||
$response = $curl->post($this->endpoint . '/lms/moodle/is-group-member/', array(
|
|
||||||
'token' => $this->token,
|
|
||||||
'hash' => $this->user_email_to_hash($email)
|
|
||||||
), array(
|
|
||||||
'CURLOPT_RETURNTRANSFER' => true,
|
|
||||||
'CURLOPT_FOLLOWLOCATION' => true,
|
|
||||||
'CURLOPT_SSL_VERIFYHOST' => false,
|
|
||||||
'CURLOPT_SSL_VERIFYPEER' => false,
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($json = json_decode($response)) {
|
if (!array_key_exists($email, $resultmap)) {
|
||||||
if (true == $json->is_member) {
|
$resultmap[$email] = false;
|
||||||
return true;
|
$curl = new curl();
|
||||||
|
$response = $curl->post($this->endpoint . '/lms/moodle/is-group-member/', array(
|
||||||
|
'token' => $this->token,
|
||||||
|
'hash' => $this->user_email_to_hash($email)
|
||||||
|
), array(
|
||||||
|
'CURLOPT_RETURNTRANSFER' => true,
|
||||||
|
'CURLOPT_FOLLOWLOCATION' => true,
|
||||||
|
'CURLOPT_SSL_VERIFYHOST' => false,
|
||||||
|
'CURLOPT_SSL_VERIFYPEER' => false,
|
||||||
|
// The maximum number of seconds to allow cURL functions to execute.
|
||||||
|
'CURLOPT_TIMEOUT' => 2
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($json = json_decode($response)) {
|
||||||
|
if (true == $json->is_member) {
|
||||||
|
$resultmap[$email] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return $resultmap[$email];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,48 +27,36 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* Class plagiarism_pchkorg_config_model
|
* Class plagiarism_pchkorg_config_model
|
||||||
*/
|
*/
|
||||||
class plagiarism_pchkorg_config_model {
|
class plagiarism_pchkorg_config_model {
|
||||||
/**
|
|
||||||
* @var
|
|
||||||
*/
|
|
||||||
private $db;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* plagiarism_pchkorg_config_model constructor.
|
|
||||||
*
|
|
||||||
* @param $DB
|
|
||||||
*/
|
|
||||||
public function __construct($DB) {
|
|
||||||
$this->db = $DB;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $module
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function fetch_by_module($module) {
|
|
||||||
return $this->db->get_records('plagiarism_pchkorg_config', array(
|
|
||||||
'cm' => $module,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $module
|
* @param $module
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function is_enabled_for_module($module) {
|
public function is_enabled_for_module($module) {
|
||||||
$configs = $this->fetch_by_module($module);
|
global $DB;
|
||||||
$enabled = false;
|
|
||||||
foreach ($configs as $record) {
|
static $resultmap = array();
|
||||||
switch ($record->name) {
|
// This will be called only once per module.
|
||||||
case 'pchkorg_module_use':
|
if (!array_key_exists($module, $resultmap)) {
|
||||||
$enabled = '1' == $record->value;
|
$configs = $DB->get_records('plagiarism_pchkorg_config', array(
|
||||||
break;
|
'cm' => $module,
|
||||||
default:
|
));
|
||||||
break;
|
|
||||||
|
$enabled = false;
|
||||||
|
foreach ($configs as $record) {
|
||||||
|
switch ($record->name) {
|
||||||
|
case 'pchkorg_module_use':
|
||||||
|
$enabled = '1' == $record->value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resultmap[$module] = $enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $enabled;
|
return $resultmap[$module];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +64,9 @@ class plagiarism_pchkorg_config_model {
|
||||||
* @param $value
|
* @param $value
|
||||||
*/
|
*/
|
||||||
public function set_system_config($name, $value) {
|
public function set_system_config($name, $value) {
|
||||||
$this->db->delete_records('plagiarism_pchkorg_config', array(
|
global $DB;
|
||||||
|
|
||||||
|
$DB->delete_records('plagiarism_pchkorg_config', array(
|
||||||
'cm' => 0,
|
'cm' => 0,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
));
|
));
|
||||||
|
@ -86,7 +76,7 @@ class plagiarism_pchkorg_config_model {
|
||||||
$record->name = $name;
|
$record->name = $name;
|
||||||
$record->value = $value;
|
$record->value = $value;
|
||||||
|
|
||||||
$this->db->insert_record('plagiarism_pchkorg_config', $record);
|
$DB->insert_record('plagiarism_pchkorg_config', $record);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,28 +84,40 @@ class plagiarism_pchkorg_config_model {
|
||||||
* @return |null
|
* @return |null
|
||||||
*/
|
*/
|
||||||
public function get_system_config($name) {
|
public function get_system_config($name) {
|
||||||
$records = $this->db->get_records('plagiarism_pchkorg_config', array(
|
global $DB;
|
||||||
'cm' => 0,
|
|
||||||
'name' => $name,
|
|
||||||
));
|
|
||||||
|
|
||||||
foreach ($records as $record) {
|
// SQL query will be called only one per one setting name.
|
||||||
return $record->value;
|
static $resultsmap = array();
|
||||||
|
if (!array_key_exists($name, $resultsmap)) {
|
||||||
|
$records = $DB->get_records('plagiarism_pchkorg_config', array(
|
||||||
|
'cm' => 0,
|
||||||
|
'name' => $name,
|
||||||
|
));
|
||||||
|
|
||||||
|
foreach ($records as $record) {
|
||||||
|
$resultsmap[$name] = $record->value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return $resultsmap[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_all_system_config() {
|
public function get_all_system_config() {
|
||||||
$records = $this->db->get_records('plagiarism_pchkorg_config', array(
|
global $DB;
|
||||||
'cm' => 0,
|
|
||||||
));
|
static $map = array();
|
||||||
$map = array();
|
if (empty($map)) {
|
||||||
foreach ($records as $record) {
|
$records = $DB->get_records('plagiarism_pchkorg_config', array(
|
||||||
$map[$record->name] = $record->value;
|
'cm' => 0,
|
||||||
|
));
|
||||||
|
|
||||||
|
foreach ($records as $record) {
|
||||||
|
$map[$record->name] = $record->value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $map;
|
return $map;
|
||||||
|
|
|
@ -55,11 +55,12 @@ class provider implements
|
||||||
'plagiarism_pchkorg_files',
|
'plagiarism_pchkorg_files',
|
||||||
array(
|
array(
|
||||||
'cm' => 'privacy:metadata:plagiarism_pchkorg_files:cm',
|
'cm' => 'privacy:metadata:plagiarism_pchkorg_files:cm',
|
||||||
'fileid' => 'privacy:metadata:forum_discussion_subs:fileid',
|
'fileid' => 'privacy:metadata:plagiarism_pchkorg_files:fileid',
|
||||||
'userid' => 'privacy:metadata:forum_discussion_subs:userid',
|
'userid' => 'privacy:metadata:plagiarism_pchkorg_files:userid',
|
||||||
'score' => 'privacy:metadata:forum_discussion_subs:score',
|
'score' => 'privacy:metadata:plagiarism_pchkorg_files:score',
|
||||||
'textid' => 'privacy:metadata:forum_discussion_subs:textid',
|
'textid' => 'privacy:metadata:plagiarism_pchkorg_files:textid',
|
||||||
'reportid' => 'privacy:metadata:forum_discussion_subs:reportid',
|
'reportid' => 'privacy:metadata:plagiarism_pchkorg_files:reportid',
|
||||||
|
'signature' => 'privacy:metadata:plagiarism_pchkorg_files:signature',
|
||||||
|
|
||||||
),
|
),
|
||||||
'privacy:metadata:plagiarism_pchkorg_files'
|
'privacy:metadata:plagiarism_pchkorg_files'
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?php
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package plagiarism_pchkorg
|
|
||||||
* @category plagiarism
|
|
||||||
* @copyright PlagiarismCheck.org, https://plagiarismcheck.org/
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
function xmldb_plagiarism_pchkorg_install() {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$installed = $DB->get_record('config_plugins', array('plugin' => 'plagiarism_pchkorg', 'name' => 'version'));
|
|
||||||
|
|
||||||
return $installed ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function xmldb_plagiarism_upgrade() {
|
|
||||||
return true;
|
|
||||||
}
|
|
|
@ -1,38 +1,39 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="plagiarism/pchkorg/db" VERSION="20190122" COMMENT="XMLDB file for Moodle plagiarism/pchkorg plugin."
|
<XMLDB PATH="plagiarism/pchkorg/db" VERSION="20190318" COMMENT="XMLDB file for Moodle plagiarism/pchkorg plugin."
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||||
>
|
>
|
||||||
<TABLES>
|
<TABLES>
|
||||||
<TABLE NAME="plagiarism_pchkorg_files" COMMENT="info about submitted files">
|
<TABLE NAME="plagiarism_pchkorg_files" COMMENT="info about submitted files">
|
||||||
<FIELDS>
|
<FIELDS>
|
||||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||||
<FIELD NAME="cm" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="cm" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="fileid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="fileid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="state" TYPE="int" LENGTH="3" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="state" TYPE="int" LENGTH="3" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="score" TYPE="float" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="score" TYPE="float" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="created_at" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
<FIELD NAME="created_at" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||||
<FIELD NAME="textid" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="textid" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="reportid" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="reportid" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
|
||||||
</FIELDS>
|
<FIELD NAME="signature" TYPE="char" LENGTH="40" NOTNULL="false" DEFAULT="NULL" SEQUENCE="false" COMMENT="Sha1 signature of content"/>
|
||||||
<KEYS>
|
</FIELDS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
<KEYS>
|
||||||
<KEY NAME="cm" TYPE="foreign" FIELDS="cm" REFTABLE="course_modules" REFFIELDS="id"/>
|
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||||
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
|
<KEY NAME="cm" TYPE="foreign" FIELDS="cm" REFTABLE="course_modules" REFFIELDS="id"/>
|
||||||
</KEYS>
|
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
|
||||||
</TABLE>
|
</KEYS>
|
||||||
<TABLE NAME="plagiarism_pchkorg_config" COMMENT="config for modules">
|
</TABLE>
|
||||||
<FIELDS>
|
<TABLE NAME="plagiarism_pchkorg_config" COMMENT="config for modules">
|
||||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
<FIELDS>
|
||||||
<FIELD NAME="cm" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
<FIELD NAME="cm" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="value" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||||
</FIELDS>
|
<FIELD NAME="value" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||||
<KEYS>
|
</FIELDS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
<KEYS>
|
||||||
<KEY NAME="cm" TYPE="foreign" FIELDS="cm" REFTABLE="course_modules" REFFIELDS="id"/>
|
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||||
</KEYS>
|
<KEY NAME="cm" TYPE="foreign" FIELDS="cm" REFTABLE="course_modules" REFFIELDS="id"/>
|
||||||
</TABLE>
|
</KEYS>
|
||||||
</TABLES>
|
</TABLE>
|
||||||
|
</TABLES>
|
||||||
</XMLDB>
|
</XMLDB>
|
|
@ -38,7 +38,7 @@ class plagiarism_pchkorg_setup_form extends moodleform {
|
||||||
$mform->addElement(
|
$mform->addElement(
|
||||||
'select',
|
'select',
|
||||||
$setting = 'pchkorg_use',
|
$setting = 'pchkorg_use',
|
||||||
self::trans('pchkorg_use'),
|
get_string('pchkorg_use', 'plagiarism_pchkorg'),
|
||||||
array(get_string('no'), get_string('yes'))
|
array(get_string('no'), get_string('yes'))
|
||||||
);
|
);
|
||||||
$mform->addHelpButton('pchkorg_use', 'pchkorg_use', 'plagiarism_pchkorg');
|
$mform->addHelpButton('pchkorg_use', 'pchkorg_use', 'plagiarism_pchkorg');
|
||||||
|
@ -47,21 +47,11 @@ class plagiarism_pchkorg_setup_form extends moodleform {
|
||||||
$mform->setDefault($setting, false);
|
$mform->setDefault($setting, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mform->addElement('password', 'pchkorg_token', self::trans('pchkorg_token'));
|
$mform->addElement('password', 'pchkorg_token', get_string('pchkorg_token', 'plagiarism_pchkorg'));
|
||||||
$mform->addHelpButton('pchkorg_token', 'pchkorg_token', 'plagiarism_pchkorg');
|
$mform->addHelpButton('pchkorg_token', 'pchkorg_token', 'plagiarism_pchkorg');
|
||||||
$mform->addRule('pchkorg_token', null, 'required', null, 'client');
|
$mform->addRule('pchkorg_token', null, 'required', null, 'client');
|
||||||
$mform->setType('pchkorg_token', PARAM_TEXT);
|
$mform->setType('pchkorg_token', PARAM_TEXT);
|
||||||
|
|
||||||
$this->add_action_buttons(true);
|
$this->add_action_buttons(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $message
|
|
||||||
* @param null $param
|
|
||||||
* @return string
|
|
||||||
* @throws coding_exception
|
|
||||||
*/
|
|
||||||
public static function trans($message, $param = null) {
|
|
||||||
return get_string($message, 'plagiarism_pchkorg', $param);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ $string['pchkorg_submit'] = 'Submit';
|
||||||
$string['pchkorg_check_for_plagiarism_report'] = 'View report';
|
$string['pchkorg_check_for_plagiarism_report'] = 'View report';
|
||||||
$string['savedconfigsuccess'] = 'Settings had been changed';
|
$string['savedconfigsuccess'] = 'Settings had been changed';
|
||||||
$string['pchkorg_check_for_plagiarism'] = 'Check for plagiarism';
|
$string['pchkorg_check_for_plagiarism'] = 'Check for plagiarism';
|
||||||
|
$string['pchkorg_disclosure'] = 'Submission will be sent to plagiarismcheck.org for check';
|
||||||
|
|
||||||
$string['privacy:metadata:plagiarism_pchkorg_files'] =
|
$string['privacy:metadata:plagiarism_pchkorg_files'] =
|
||||||
'Table with information about a file within moodle system belonge to a check in plagiarismcheck.org system.';
|
'Table with information about a file within moodle system belonge to a check in plagiarismcheck.org system.';
|
||||||
|
@ -45,6 +46,7 @@ $string['privacy:metadata:plagiarism_pchkorg_files:userid'] = 'Identity of user
|
||||||
$string['privacy:metadata:plagiarism_pchkorg_files:score'] = 'Originality score';
|
$string['privacy:metadata:plagiarism_pchkorg_files:score'] = 'Originality score';
|
||||||
$string['privacy:metadata:plagiarism_pchkorg_files:textid'] = 'Identity of originality check';
|
$string['privacy:metadata:plagiarism_pchkorg_files:textid'] = 'Identity of originality check';
|
||||||
$string['privacy:metadata:plagiarism_pchkorg_files:reportid'] = 'Identity of originality report';
|
$string['privacy:metadata:plagiarism_pchkorg_files:reportid'] = 'Identity of originality report';
|
||||||
|
$string['privacy:metadata:plagiarism_pchkorg_files:signature'] = 'Sha1 signature of content';
|
||||||
|
|
||||||
$string['privacy:metadata:plagiarism_pchkorg_config'] = 'Table with module settings';
|
$string['privacy:metadata:plagiarism_pchkorg_config'] = 'Table with module settings';
|
||||||
$string['privacy:metadata:plagiarism_pchkorg_config:cm'] = 'Course module identity';
|
$string['privacy:metadata:plagiarism_pchkorg_config:cm'] = 'Course module identity';
|
||||||
|
|
87
lib.php
87
lib.php
|
@ -45,30 +45,41 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
|
||||||
*/
|
*/
|
||||||
public function get_links($linkarray) {
|
public function get_links($linkarray) {
|
||||||
global $DB, $USER;
|
global $DB, $USER;
|
||||||
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model($DB);
|
|
||||||
$urlgenerator = new plagiarism_pchkorg_url_generator();
|
|
||||||
$apiprovider = new plagiarism_pchkorg_api_provider($pchkorgconfigmodel->get_system_config('pchkorg_token'));
|
|
||||||
|
|
||||||
|
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
|
||||||
|
$urlgenerator = new plagiarism_pchkorg_url_generator();
|
||||||
|
$apitoken = $pchkorgconfigmodel->get_system_config('pchkorg_token');
|
||||||
|
$apiprovider = new plagiarism_pchkorg_api_provider($apitoken);
|
||||||
|
|
||||||
|
$cmid = $linkarray['cmid'];
|
||||||
|
$file = $linkarray['file'];
|
||||||
|
|
||||||
|
// We can do nothing with submissions which we can not handle.
|
||||||
|
if (!$apiprovider->is_supported_mime($file->get_mimetype())) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// SQL will be called only once, result is static.
|
||||||
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
|
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
|
||||||
if ('1' !== $config) {
|
if ('1' !== $config) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmid = $linkarray['cmid'];
|
|
||||||
$file = $linkarray['file'];
|
|
||||||
$context = null;
|
$context = null;
|
||||||
if (!empty($cmid)) {
|
if (!empty($cmid)) {
|
||||||
$context = context_module::instance($cmid);// Get context of course.
|
$context = context_module::instance($cmid);// Get context of course.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SQL will be called only once per page. There is static result inside.
|
||||||
if (!$pchkorgconfigmodel->is_enabled_for_module($cmid)) {
|
if (!$pchkorgconfigmodel->is_enabled_for_module($cmid)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$apiprovider->is_supported_mime($file->get_mimetype())) {
|
// Only for some type of account, method will call a remote HTTP API.
|
||||||
return '';
|
// The API will be called only once, because result is static.
|
||||||
}
|
// Also, there is timeout 2 seconds for response.
|
||||||
|
// Even if service is unavailable, method will try call only once.
|
||||||
|
// Also, we don't use use raw user email.
|
||||||
if (!$apiprovider->is_group_member($USER->email)) {
|
if (!$apiprovider->is_group_member($USER->email)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -107,7 +118,7 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
|
||||||
public function save_form_elements($data) {
|
public function save_form_elements($data) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model($DB);
|
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
|
||||||
|
|
||||||
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
|
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
|
||||||
if ('1' != $config) {
|
if ('1' != $config) {
|
||||||
|
@ -144,12 +155,12 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
|
||||||
* @throws dml_exception
|
* @throws dml_exception
|
||||||
*/
|
*/
|
||||||
public function get_form_elements_module($mform, $context, $modulename = '') {
|
public function get_form_elements_module($mform, $context, $modulename = '') {
|
||||||
if (!$context || !isset($modulename)) {
|
if (!$context || !isset($modulename) || 'mod_assign' !== $modulename) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model($DB);
|
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
|
||||||
|
|
||||||
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
|
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
|
||||||
if ('1' == $config) {
|
if ('1' == $config) {
|
||||||
|
@ -160,17 +171,15 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
|
||||||
'cm' => $cm,
|
'cm' => $cm,
|
||||||
));
|
));
|
||||||
if (!empty($records)) {
|
if (!empty($records)) {
|
||||||
foreach ($records as $record) {
|
$mform->setDefault($records[0]->name, $records[0]->value);
|
||||||
$mform->setDefault($record->name, $record->value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$mform->addElement('header', 'plagiarism_pchkorg', self::trans('pluginname'));
|
$mform->addElement('header', 'plagiarism_pchkorg', get_string('pluginname', 'plagiarism_pchkorg'));
|
||||||
$mform->addElement(
|
$mform->addElement(
|
||||||
'select',
|
'select',
|
||||||
$setting = 'pchkorg_module_use',
|
$setting = 'pchkorg_module_use',
|
||||||
self::trans('pchkorg_module_use'),
|
get_string('pchkorg_module_use', 'plagiarism_pchkorg'),
|
||||||
array(get_string('no'), get_string('yes'))
|
array(get_string('no'), get_string('yes'))
|
||||||
);
|
);
|
||||||
$mform->addHelpButton('pchkorg_module_use', 'pchkorg_module_use', 'plagiarism_pchkorg');
|
$mform->addHelpButton('pchkorg_module_use', 'pchkorg_module_use', 'plagiarism_pchkorg');
|
||||||
|
@ -188,29 +197,41 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function print_disclosure($cmid) {
|
public function print_disclosure($cmid) {
|
||||||
global $OUTPUT, $DB;
|
global $OUTPUT;
|
||||||
|
|
||||||
$configmodel = new plagiarism_pchkorg_config_model($DB);
|
if (empty($cmid)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
|
// Get course details.
|
||||||
|
$cm = get_coursemodule_from_id('', $cmid);
|
||||||
|
|
||||||
|
if ($cm->modname != 'assign') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$configmodel = new plagiarism_pchkorg_config_model();
|
||||||
|
|
||||||
|
$enabled = $configmodel->get_system_config('pchkorg_use');
|
||||||
|
if ($enabled !== '1') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($configmodel->is_enabled_for_module($cmid) != '1') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = '';
|
||||||
|
|
||||||
|
$result .= $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
|
||||||
|
|
||||||
$formatoptions = new stdClass;
|
$formatoptions = new stdClass;
|
||||||
$formatoptions->noclean = true;
|
$formatoptions->noclean = true;
|
||||||
$formatoptions->cmid = $cmid;
|
$formatoptions->cmid = $cmid;
|
||||||
$text = $configmodel->get_system_config('plagiarism_pchkorg');
|
|
||||||
|
|
||||||
echo format_text($text, FORMAT_MOODLE, $formatoptions);
|
$result .= format_text(get_string('pchkorg_disclosure', 'plagiarism_pchkorg'), FORMAT_MOODLE, $formatoptions);
|
||||||
|
$result .= $OUTPUT->box_end();
|
||||||
|
|
||||||
echo $OUTPUT->box_end();
|
return $result;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $message
|
|
||||||
* @param null $param
|
|
||||||
* @return string
|
|
||||||
* @throws coding_exception
|
|
||||||
*/
|
|
||||||
public static function trans($message, $param = null) {
|
|
||||||
return get_string($message, 'plagiarism_pchkorg', $param);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,7 @@ require_once(__DIR__ . '/../classes/plagiarism_pchkorg_api_provider.php');
|
||||||
|
|
||||||
global $PAGE, $CFG, $OUTPUT, $DB, $USER;
|
global $PAGE, $CFG, $OUTPUT, $DB, $USER;
|
||||||
|
|
||||||
require_login();
|
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
|
||||||
|
|
||||||
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model($DB);
|
|
||||||
$urlgenerator = new plagiarism_pchkorg_url_generator();
|
$urlgenerator = new plagiarism_pchkorg_url_generator();
|
||||||
$apiprovider = new plagiarism_pchkorg_api_provider(
|
$apiprovider = new plagiarism_pchkorg_api_provider(
|
||||||
$pchkorgconfigmodel->get_system_config('pchkorg_token')
|
$pchkorgconfigmodel->get_system_config('pchkorg_token')
|
||||||
|
@ -42,9 +40,10 @@ $cmid = (int) required_param('cmid', PARAM_INT); // Course Module ID
|
||||||
$fileid = (int) required_param('file', PARAM_INT); // plagiarism file id.
|
$fileid = (int) required_param('file', PARAM_INT); // plagiarism file id.
|
||||||
$cm = get_coursemodule_from_id('', $cmid);
|
$cm = get_coursemodule_from_id('', $cmid);
|
||||||
require_login($cm->course, true, $cm);
|
require_login($cm->course, true, $cm);
|
||||||
|
|
||||||
$context = context_module::instance($cm->id);
|
$context = context_module::instance($cm->id);
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
$isgranted = has_capability('mod/assign:view', $context, null);
|
$isgranted = has_capability('mod/assign:grade', $context, null);
|
||||||
if (!$isgranted) {
|
if (!$isgranted) {
|
||||||
die('{error: "access denied"}');
|
die('{error: "access denied"}');
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,7 @@ require_once(__DIR__ . '/../classes/plagiarism_pchkorg_api_provider.php');
|
||||||
|
|
||||||
global $PAGE, $CFG, $OUTPUT, $DB, $USER;
|
global $PAGE, $CFG, $OUTPUT, $DB, $USER;
|
||||||
|
|
||||||
require_login();
|
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
|
||||||
|
|
||||||
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model($DB);
|
|
||||||
$urlgenerator = new plagiarism_pchkorg_url_generator();
|
$urlgenerator = new plagiarism_pchkorg_url_generator();
|
||||||
$apiprovider = new plagiarism_pchkorg_api_provider($pchkorgconfigmodel->get_system_config('pchkorg_token'));
|
$apiprovider = new plagiarism_pchkorg_api_provider($pchkorgconfigmodel->get_system_config('pchkorg_token'));
|
||||||
|
|
||||||
|
@ -88,7 +86,6 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) { // Form submission.
|
||||||
die('404 not exists');
|
die('404 not exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($apiprovider->is_group_token()) {
|
if ($apiprovider->is_group_token()) {
|
||||||
$textid = $apiprovider->send_group_text(
|
$textid = $apiprovider->send_group_text(
|
||||||
$apiprovider->user_email_to_hash($USER->email),
|
$apiprovider->user_email_to_hash($USER->email),
|
||||||
|
@ -108,7 +105,6 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) { // Form submission.
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$message = '';
|
$message = '';
|
||||||
if (null !== $textid) {
|
if (null !== $textid) {
|
||||||
$filerecord = new \stdClass();
|
$filerecord = new \stdClass();
|
||||||
|
|
|
@ -30,9 +30,7 @@ require_once($CFG->dirroot . '/plagiarism/pchkorg/form/plagiarism_pchkorg_setup_
|
||||||
require_once(__DIR__ . '/classes/plagiarism_pchkorg_config_model.php');
|
require_once(__DIR__ . '/classes/plagiarism_pchkorg_config_model.php');
|
||||||
require_once(__DIR__ . '/lib.php');
|
require_once(__DIR__ . '/lib.php');
|
||||||
|
|
||||||
global $DB;
|
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
|
||||||
|
|
||||||
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model($DB);
|
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
admin_externalpage_setup('plagiarismpchkorg');
|
admin_externalpage_setup('plagiarismpchkorg');
|
||||||
|
@ -64,8 +62,6 @@ if (($data = $mform->get_data()) && confirm_sesskey()) {
|
||||||
$OUTPUT->notification(get_string('savedconfigsuccess', 'plagiarism_pchkorg'), 'notifysuccess');
|
$OUTPUT->notification(get_string('savedconfigsuccess', 'plagiarism_pchkorg'), 'notifysuccess');
|
||||||
}
|
}
|
||||||
|
|
||||||
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model($DB);
|
|
||||||
|
|
||||||
$plagiarismsettings = $pchkorgconfigmodel->get_all_system_config();
|
$plagiarismsettings = $pchkorgconfigmodel->get_all_system_config();
|
||||||
|
|
||||||
$mform->set_data($plagiarismsettings);
|
$mform->set_data($plagiarismsettings);
|
||||||
|
|
|
@ -26,12 +26,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
if (!isset($plugin)) {
|
if (!isset($plugin)) {
|
||||||
$plugin = new stdClass();
|
$plugin = new stdClass();
|
||||||
}
|
}
|
||||||
$plugin->version = 2019020601;
|
$plugin->version = 2019031801;
|
||||||
$plugin->requires = 2017051501; // Requires Moodle 3.3 .
|
$plugin->requires = 2017051501; // Requires Moodle 3.3 .
|
||||||
$plugin->release = 'v2.3';
|
$plugin->release = 'v3.1';
|
||||||
$plugin->maturity = MATURITY_STABLE;
|
$plugin->maturity = MATURITY_STABLE;
|
||||||
|
|
||||||
$plugin->component = 'plagiarism_pchkorg';
|
$plugin->component = 'plagiarism_pchkorg';
|
||||||
$plugin->dependencies = array(
|
$plugin->dependencies = array(
|
||||||
'mod_assign' => ANY_VERSION,
|
'mod_assign' => ANY_VERSION,
|
||||||
);
|
);
|
|
@ -30,7 +30,7 @@ if (empty($error)) {
|
||||||
<form id="plagiarism_pchkorg_report_id" action="<?php echo htmlspecialchars($action) ?>" method="post">
|
<form id="plagiarism_pchkorg_report_id" action="<?php echo htmlspecialchars($action) ?>" method="post">
|
||||||
<input type="hidden" name="token" value="<?php echo htmlspecialchars($token) ?>"/>
|
<input type="hidden" name="token" value="<?php echo htmlspecialchars($token) ?>"/>
|
||||||
<input type="hidden" name="lms-type" value="moodle"/>
|
<input type="hidden" name="lms-type" value="moodle"/>
|
||||||
<input type="submit" value="<?php echo get_string('pchkorg_check_for_plagiarism_report', 'plagiarism_pchkorg');?>">
|
<input type="submit" value="<?php echo get_string('pchkorg_check_for_plagiarism_report', 'plagiarism_pchkorg'); ?>">
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue