Skip to content

Commit

Permalink
Merge branch 'master_MDL-67872' of https://github.com/danmarsden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 5, 2020
2 parents c2366b8 + c61619f commit 85b9ecd
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions lib/plagiarismlib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -19,16 +18,14 @@
* plagiarismlib.php - Contains core Plagiarism related functions.
*
* @since Moodle 2.0
* @package moodlecore
* @package core
* @subpackage plagiarism
* @copyright 2010 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

///// GENERIC PLAGIARISM FUNCTIONS ////////////////////////////////////////////////////

if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
die('Direct access to this script is forbidden.');
}

/**
Expand All @@ -44,7 +41,7 @@ function plagiarism_get_links($linkarray) {
}
$plagiarismplugins = plagiarism_load_available_plugins();
$output = '';
foreach($plagiarismplugins as $plugin => $dir) {
foreach ($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
Expand All @@ -69,7 +66,7 @@ function plagiarism_get_file_results($cmid, $userid, $file) {
return $allresults;
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
foreach ($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
Expand All @@ -91,7 +88,7 @@ function plagiarism_save_form_elements($data) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
foreach ($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
Expand Down Expand Up @@ -122,7 +119,7 @@ function plagiarism_get_form_elements_module($mform, $context, $modulename = "")
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
foreach ($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
Expand Down Expand Up @@ -151,7 +148,7 @@ function plagiarism_update_status($course, $cm) {
}
$plagiarismplugins = plagiarism_load_available_plugins();
$output = '';
foreach($plagiarismplugins as $plugin => $dir) {
foreach ($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
Expand All @@ -161,18 +158,18 @@ function plagiarism_update_status($course, $cm) {
}

/**
* Function that prints the student disclosure notifying that the files will be checked for plagiarism
* @param integer $cmid - the cmid of this module
* @return string
*/
* Function that prints the student disclosure notifying that the files will be checked for plagiarism
* @param integer $cmid - the cmid of this module
* @return string
*/
function plagiarism_print_disclosure($cmid) {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
$output = '';
foreach($plagiarismplugins as $plugin => $dir) {
foreach ($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
Expand All @@ -182,19 +179,35 @@ function plagiarism_print_disclosure($cmid) {
}

/**
* helper function - also loads lib file of plagiarism plugin
* Helper function - also loads lib file of plagiarism plugin
*
* @todo MDL-67872 the deprecated code in this function to be removed in Moodle 4.3
* @return array of available plugins
*/
function plagiarism_load_available_plugins() {
global $CFG;
static $showndeprecatedmessage = array(); // Only show message once per page load.

if (empty($CFG->enableplagiarism)) {
return array();
}
$plagiarismplugins = core_component::get_plugin_list('plagiarism');
$availableplugins = array();
foreach($plagiarismplugins as $plugin => $dir) {
//check this plugin is enabled and a lib file exists.
if (get_config('plagiarism', $plugin."_use") && file_exists($dir."/lib.php")) {
foreach ($plagiarismplugins as $plugin => $dir) {
// Check this plugin is enabled and a lib file exists.
if (get_config('plagiarism', $plugin."_use")) {
// Deprecated Since Moodle 3.9.
$pluginenabled = true;
if (empty($showndeprecatedmessage[$plugin])) {
$text = 'The setting plagiarism:'.$plugin.'_use is deprecated.';
$text .= ' Use plagiarism_' . $plugin . ':enabled instead';
debugging($text, DEBUG_DEVELOPER);
$showndeprecatedmessage[$plugin] = true;
}
} else {
$pluginenabled = get_config('plagiarism_'.$plugin, 'enabled');
}
if ($pluginenabled && file_exists($dir."/lib.php")) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
if (class_exists($plagiarismclass)) {
Expand Down

0 comments on commit 85b9ecd

Please sign in to comment.