From ce4f49786863c5583c5fb245f3d81c0d1ce97ef7 Mon Sep 17 00:00:00 2001 From: Jane Adelmann Date: Wed, 6 Feb 2019 15:38:23 +0200 Subject: [PATCH] Change capability name. Add information into README file #1 . Add PHPDOC. Version 2.3. --- README.md | 57 ++++++++++-- classes/plagiarism_pchkorg_api_provider.php | 98 ++++++++++++++++++++ classes/plagiarism_pchkorg_config_model.php | 37 ++++++++ classes/plagiarism_pchkorg_file_loader.php | 21 ----- classes/plagiarism_pchkorg_url_generator.php | 20 ++++ classes/privacy/provider.php | 16 ++++ db/access.php | 32 ------- db/install.php | 7 ++ form/plagiarism_pchkorg_setup_form.php | 19 ++++ form/send_text_form.php | 16 +++- lib.php | 36 +++++++ page/check.php | 9 +- page/report.php | 10 +- settings.php | 5 +- version.php | 4 +- view/check_report.php | 7 ++ view/report.php | 7 ++ view/send_text.php | 7 ++ 18 files changed, 341 insertions(+), 67 deletions(-) delete mode 100644 classes/plagiarism_pchkorg_file_loader.php delete mode 100644 db/access.php diff --git a/README.md b/README.md index 1dc60f7..379756a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,54 @@ -[![Build Status](https://travis-ci.org/PlagiarismCheck/moodle-plagiarism_pchkorg.svg?branch=master)](https://travis-ci.org/PlagiarismCheck/moodle-plagiarism_pchkorg) - - -Plagiarism Check Plugin. - +Plagiarism Check Plugin. [![Build Status](https://travis-ci.org/PlagiarismCheck/moodle-plagiarism_pchkorg.svg?branch=master)](https://travis-ci.org/PlagiarismCheck/moodle-plagiarism_pchkorg) +--------------------- This plugin provide functionality for Plagiarismcheck.org service. Plagiarismcheck.org is a sophisticated similarity search engine. -We advocate for bringing technology into academics to help instructors save time and motivate students write better papers. \ No newline at end of file +We advocate for bringing technology into academics to help instructors save time and motivate students write better papers. + +PlagiarismCheck.org has subscription-based pricing model. More information is available here. + +http://plagiarismcheck.org + +### With PlagiarismCheck you get: + +1) AI Algorithm. + + The algorithm that searches not only for word-to-word match, but also covers: + * word rearrangements + * word substitutions / synonymization + * changes from passive to active voice + * poor paraphrasing + * changes of alphabet from Latin to Cyrillic and vice versa + how_we_detect + +2) Smart report. + + * user can access all sources where similarity has been detected + * similarity found in quotes are highlighted in a different color and can be included/excluded from the total similarity percentage + * similarity found in references are highlighted in a different color and can be included/excluded from the total similarity percentage + +3) Search database. + + Depending on the type of subscription, there are several search options available: + * search via all publicly available resources + * create a personal archive for your school and search through it + * search in closed depositories and libraries + +4) Usability. + * integration can be easily set up by an administrator of a Moodle account + * integration gives a chance to set up who will have an access to the software + * though the integration both students and instructors will have an access to the similarity reports +5) Resubmissions. + + In case an instructor allows to resubmit works, PlagiarismCheck will be able to check all submissions without giving a false positive result + +6) Throughput + * no restrictions on daily usage + * minimum downtime + * no limitations on how soon one can resubmit a work + +7) Excellent customer service +response to clients' requests within 24 hours +24/7 admin support. + + diff --git a/classes/plagiarism_pchkorg_api_provider.php b/classes/plagiarism_pchkorg_api_provider.php index d1782c1..8c32380 100644 --- a/classes/plagiarism_pchkorg_api_provider.php +++ b/classes/plagiarism_pchkorg_api_provider.php @@ -14,16 +14,32 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); +/** + * Class plagiarism_pchkorg_api_provider + */ class plagiarism_pchkorg_api_provider { + /** + * @var + */ private $token; /** * @var string */ private $endpoint; + /** + * @var + */ private $lasterror; /** @@ -40,11 +56,28 @@ class plagiarism_pchkorg_api_provider { $this->lasterror = $lasterror; } + /** + * plagiarism_pchkorg_api_provider constructor. + * + * @param $token + * @param string $endpoint + */ public function __construct($token, $endpoint = 'https://plagiarismcheck.org') { $this->token = $token; $this->endpoint = $endpoint; } + /** + * @param $authorhash + * @param $cousereid + * @param $assignmentid + * @param $submissionid + * @param $attachmentid + * @param $content + * @param $mime + * @param $filename + * @return |null + */ public function send_group_text($authorhash, $cousereid, $assignmentid, $submissionid, $attachmentid, $content, $mime, $filename) { @@ -88,6 +121,18 @@ class plagiarism_pchkorg_api_provider { return $id; } + /** + * @param $boundary + * @param $authorhash + * @param $cousereid + * @param $assignmentid + * @param $submissionid + * @param $attachmentid + * @param $content + * @param $mime + * @param $filename + * @return string + */ private function get_body_for_group($boundary, $authorhash, $cousereid, @@ -114,6 +159,12 @@ class plagiarism_pchkorg_api_provider { return $body; } + /** + * @param $content + * @param $mime + * @param $filename + * @return |null + */ public function send_text($content, $mime, $filename) { $boundary = sprintf('PLAGCHECKBOUNDARY-%s', uniqid(time())); @@ -147,6 +198,12 @@ class plagiarism_pchkorg_api_provider { return $id; } + /** + * @param $name + * @param $value + * @param $boundary + * @return string + */ private function get_part($name, $value, $boundary) { $eol = "\r\n"; @@ -157,6 +214,14 @@ class plagiarism_pchkorg_api_provider { return $part; } + /** + * @param $name + * @param $value + * @param $mime + * @param $filename + * @param $boundary + * @return string + */ private function get_file_part($name, $value, $mime, $filename, $boundary) { $eol = "\r\n"; @@ -169,6 +234,13 @@ class plagiarism_pchkorg_api_provider { return $part; } + /** + * @param $boundary + * @param $content + * @param $mime + * @param $filename + * @return string + */ private function get_body($boundary, $content, $mime, $filename) { $eol = "\r\n"; @@ -180,14 +252,25 @@ class plagiarism_pchkorg_api_provider { return $body; } + /** + * @param $email + * @return string + */ public function user_email_to_hash($email) { return hash('sha256', $this->token . $email); } + /** + * @return bool + */ public function is_group_token() { return 'G-' === \substr($this->token, 0, 2); } + /** + * @param string $email + * @return bool + */ public function is_group_member($email = '') { if (!$this->is_group_token()) { return true; @@ -213,6 +296,10 @@ class plagiarism_pchkorg_api_provider { return false; } + /** + * @param $textid + * @return |null + */ public function check_text($textid) { $curl = new curl(); $response = $curl->get($this->endpoint . '/api/v1/text/' . $textid, array(), array( @@ -235,10 +322,17 @@ class plagiarism_pchkorg_api_provider { return null; } + /** + * @param $id + * @return string + */ public function get_report_action($id) { return "{$this->endpoint}/lms/public-report/{$id}/"; } + /** + * @return string + */ public function generate_api_token() { global $USER; @@ -249,6 +343,10 @@ class plagiarism_pchkorg_api_provider { return $this->token; } + /** + * @param $mime + * @return bool + */ public function is_supported_mime($mime) { return in_array($mime, array( 'application/msword', diff --git a/classes/plagiarism_pchkorg_config_model.php b/classes/plagiarism_pchkorg_config_model.php index 1d7ec15..177e21d 100644 --- a/classes/plagiarism_pchkorg_config_model.php +++ b/classes/plagiarism_pchkorg_config_model.php @@ -14,21 +14,47 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); +/** + * 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 + * @return bool + */ public function is_enabled_for_module($module) { $configs = $this->fetch_by_module($module); $enabled = false; @@ -45,6 +71,10 @@ class plagiarism_pchkorg_config_model { return $enabled; } + /** + * @param $name + * @param $value + */ public function set_system_config($name, $value) { $this->db->delete_records('plagiarism_pchkorg_config', array( 'cm' => 0, @@ -59,6 +89,10 @@ class plagiarism_pchkorg_config_model { $this->db->insert_record('plagiarism_pchkorg_config', $record); } + /** + * @param $name + * @return |null + */ public function get_system_config($name) { $records = $this->db->get_records('plagiarism_pchkorg_config', array( 'cm' => 0, @@ -72,6 +106,9 @@ class plagiarism_pchkorg_config_model { return null; } + /** + * @return array + */ public function get_all_system_config() { $records = $this->db->get_records('plagiarism_pchkorg_config', array( 'cm' => 0, diff --git a/classes/plagiarism_pchkorg_file_loader.php b/classes/plagiarism_pchkorg_file_loader.php deleted file mode 100644 index fea1811..0000000 --- a/classes/plagiarism_pchkorg_file_loader.php +++ /dev/null @@ -1,21 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -class plagiarism_pchkorg_file_loader { - -} diff --git a/classes/plagiarism_pchkorg_url_generator.php b/classes/plagiarism_pchkorg_url_generator.php index ae870ed..23bc79d 100644 --- a/classes/plagiarism_pchkorg_url_generator.php +++ b/classes/plagiarism_pchkorg_url_generator.php @@ -14,9 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); +/** + * Class plagiarism_pchkorg_url_generator + */ class plagiarism_pchkorg_url_generator { + /** + * @param $cmid + * @param $fileid + * @return moodle_url + * @throws moodle_exception + */ public function get_check_url($cmid, $fileid) { return new moodle_url(sprintf( '/plagiarism/pchkorg/page/report.php?cmid=%s&file=%s', @@ -26,6 +42,10 @@ class plagiarism_pchkorg_url_generator { ); } + /** + * @return moodle_url + * @throws moodle_exception + */ public function get_status_url() { return new moodle_url('/plagiarism/pchkorg/page/status.php'); } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 195f984..a7d3ebe 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -14,12 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @package plagiarism_pchkorg + * @category plagiarism + * @copyright PlagiarismCheck.org, https://plagiarismcheck.org/ + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + namespace plagiarism_pchkorg\privacy; defined('MOODLE_INTERNAL') || die(); use core_privacy\local\metadata\collection; +/** + * Class provider + * + * @package plagiarism_pchkorg\privacy + */ class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\plugin\provider { @@ -27,6 +39,10 @@ class provider implements // This trait must be included. use \core_privacy\local\legacy_polyfill; + /** + * @param collection $collection + * @return collection + */ public static function _get_metadata(collection $collection) { $collection->add_subsystem_link( diff --git a/db/access.php b/db/access.php deleted file mode 100644 index 5170442..0000000 --- a/db/access.php +++ /dev/null @@ -1,32 +0,0 @@ -. - -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); -} - -$capabilities = array( - 'plagiarism/pchkorg:check' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'write', - 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( - 'editingteacher' => CAP_ALLOW, - 'teacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW, - ), - ), -); diff --git a/db/install.php b/db/install.php index c7248ec..573e7d5 100644 --- a/db/install.php +++ b/db/install.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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() { diff --git a/form/plagiarism_pchkorg_setup_form.php b/form/plagiarism_pchkorg_setup_form.php index 0f8d346..1dc205a 100644 --- a/form/plagiarism_pchkorg_setup_form.php +++ b/form/plagiarism_pchkorg_setup_form.php @@ -14,10 +14,23 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); +/** + * Class plagiarism_pchkorg_setup_form + */ class plagiarism_pchkorg_setup_form extends moodleform { + /** + * @throws coding_exception + */ public function definition() { $mform = &$this->_form; @@ -42,6 +55,12 @@ class plagiarism_pchkorg_setup_form extends moodleform { $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); } diff --git a/form/send_text_form.php b/form/send_text_form.php index a3f5d53..033fee4 100644 --- a/form/send_text_form.php +++ b/form/send_text_form.php @@ -14,12 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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->libdir . '/formslib.php'); +/** + * Class send_text_form + */ class send_text_form extends moodleform { - // Add elements to form. + + /** + * @throws coding_exception + */ public function definition() { $mform = $this->_form; // Don't forget the underscore! @@ -29,6 +42,5 @@ class send_text_form extends moodleform { $mform->setType('cmid', PARAM_INT); $this->add_action_buttons(false, get_string('pchkorg_submit', 'plagiarism_pchkorg')); - } } diff --git a/lib.php b/lib.php index 291e50f..8568333 100644 --- a/lib.php +++ b/lib.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); global $CFG; @@ -25,6 +32,9 @@ require_once(__DIR__ . '/classes/plagiarism_pchkorg_config_model.php'); require_once(__DIR__ . '/classes/plagiarism_pchkorg_url_generator.php'); require_once(__DIR__ . '/classes/plagiarism_pchkorg_api_provider.php'); +/** + * Class plagiarism_plugin_pchkorg + */ class plagiarism_plugin_pchkorg extends plagiarism_plugin { /** * hook to allow plagiarism specific information to be displayed beside a submission @@ -46,6 +56,10 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { $cmid = $linkarray['cmid']; $file = $linkarray['file']; + $context = null; + if (!empty($cmid)) { + $context = context_module::instance($cmid);// Get context of course. + } if (!$pchkorgconfigmodel->is_enabled_for_module($cmid)) { return ''; @@ -59,6 +73,11 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { return ''; } + $isgranted = !empty($context) && has_capability('mod/assign:view', $context, null); + if (!$isgranted) { + return ''; + } + $where = new \stdClass(); $where->cm = $cmid; $where->fileid = $file->get_id(); @@ -81,6 +100,10 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { /* hook to save plagiarism specific settings on a module settings page * @param object $data - data from an mform submission. */ + /** + * @param $data + * @throws dml_exception + */ public function save_form_elements($data) { global $DB; @@ -113,6 +136,13 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { } } + /** + * @param object $mform + * @param object $context + * @param string $modulename + * @throws coding_exception + * @throws dml_exception + */ public function get_form_elements_module($mform, $context, $modulename = '') { if (!$context || !isset($modulename)) { return; @@ -174,6 +204,12 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { echo $OUTPUT->box_end(); } + /** + * @param $message + * @param null $param + * @return string + * @throws coding_exception + */ public static function trans($message, $param = null) { return get_string($message, 'plagiarism_pchkorg', $param); } diff --git a/page/check.php b/page/check.php index 975d083..c487bff 100644 --- a/page/check.php +++ b/page/check.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @package plagiarism_pchkorg + * @category plagiarism + * @copyright PlagiarismCheck.org, https://plagiarismcheck.org/ + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + require_once(__DIR__ . '/../../../config.php'); require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/../form/send_text_form.php'); @@ -37,7 +44,7 @@ $cm = get_coursemodule_from_id('', $cmid); require_login($cm->course, true, $cm); $context = context_module::instance($cm->id); header('Content-Type: application/json'); -$isgranted = is_viewing($context, null, 'plagiarism/pchkorg:check'); +$isgranted = has_capability('mod/assign:view', $context, null); if (!$isgranted) { die('{error: "access denied"}'); } diff --git a/page/report.php b/page/report.php index cc65d30..62954d1 100644 --- a/page/report.php +++ b/page/report.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @package plagiarism_pchkorg + * @category plagiarism + * @copyright PlagiarismCheck.org, https://plagiarismcheck.org/ + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + require_once(__DIR__ . '/../../../config.php'); require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/../form/send_text_form.php'); @@ -36,7 +43,8 @@ $cm = get_coursemodule_from_id('', $cmid, 0, false, MUST_EXIST); require_login($cm->course, true, $cm); $context = context_module::instance($cm->id);// Get context of course. -$isgranted = is_viewing($context, null, 'plagiarism/pchkorg:check'); +$isgranted = has_capability('mod/assign:view', $context, null); + if (!$isgranted) { die('403 permission denied'); } diff --git a/settings.php b/settings.php index 5ab8378..4c9022e 100644 --- a/settings.php +++ b/settings.php @@ -13,10 +13,11 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** - * pl * plagiarism.php - allows the admin to configure plagiarism stuff - * * @package plagiarism_pchkorg + * @category plagiarism + * @copyright PlagiarismCheck.org, https://plagiarismcheck.org/ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/version.php b/version.php index 74d8e39..67fc64b 100644 --- a/version.php +++ b/version.php @@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die(); if (!isset($plugin)) { $plugin = new stdClass(); } -$plugin->version = 2019020501; +$plugin->version = 2019020601; $plugin->requires = 2017051501; // Requires Moodle 3.3 . -$plugin->release = 'v2.2'; +$plugin->release = 'v2.3'; $plugin->maturity = MATURITY_STABLE; $plugin->component = 'plagiarism_pchkorg'; diff --git a/view/check_report.php b/view/check_report.php index d5efbd2..d69c563 100644 --- a/view/check_report.php +++ b/view/check_report.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); $ajaxurl = new moodle_url('/plagiarism/pchkorg/page/check.php'); diff --git a/view/report.php b/view/report.php index 4e51da7..5c9f219 100644 --- a/view/report.php +++ b/view/report.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); if (empty($error)) { diff --git a/view/send_text.php b/view/send_text.php index a76443d..9c81782 100644 --- a/view/send_text.php +++ b/view/send_text.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * @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(); echo $OUTPUT->header();