2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * plagiarismlib.php - Contains core Plagiarism related functions.
22 * @subpackage plagiarism
23 * @copyright 2010 Dan Marsden http://danmarsden.com
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 if (!defined('MOODLE_INTERNAL')) {
28 die('Direct access to this script is forbidden.');
32 * displays the similarity score and provides a link to the full report if allowed.
34 * @param object $linkarray contains all relevant information for the plugin to generate a link
35 * @return string - url to allow login/viewing of a similarity report
37 function plagiarism_get_links($linkarray) {
39 if (empty($CFG->enableplagiarism
)) {
42 $plagiarismplugins = plagiarism_load_available_plugins();
44 foreach ($plagiarismplugins as $plugin => $dir) {
45 require_once($dir.'/lib.php');
46 $plagiarismclass = "plagiarism_plugin_$plugin";
47 $plagiarismplugin = new $plagiarismclass;
48 $output .= $plagiarismplugin->get_links($linkarray);
54 * returns array of plagiarism details about specified file
58 * @param object $file moodle file object
59 * @return array - sets of details about specified file, one array of details per plagiarism plugin
60 * - each set contains at least 'analyzed', 'score', 'reporturl'
62 function plagiarism_get_file_results($cmid, $userid, $file) {
64 $allresults = array();
65 if (empty($CFG->enableplagiarism
)) {
68 $plagiarismplugins = plagiarism_load_available_plugins();
69 foreach ($plagiarismplugins as $plugin => $dir) {
70 require_once($dir.'/lib.php');
71 $plagiarismclass = "plagiarism_plugin_$plugin";
72 $plagiarismplugin = new $plagiarismclass;
73 $allresults[] = $plagiarismplugin->get_file_results($cmid, $userid, $file);
79 * saves/updates plagiarism settings from a modules config page - called by course/modedit.php
81 * @deprecated Since Moodle 3.9. MDL-65835 Please use {plugin name}_coursemodule_edit_post_actions() instead.
82 * @todo MDL-67526 This is to be moved from here to deprecatedlib.php in Moodle 4.1
83 * @param object $data - form data
85 function plagiarism_save_form_elements($data) {
87 if (empty($CFG->enableplagiarism
)) {
90 $plagiarismplugins = plagiarism_load_available_plugins();
91 foreach ($plagiarismplugins as $plugin => $dir) {
92 require_once($dir.'/lib.php');
93 $plagiarismclass = "plagiarism_plugin_$plugin";
94 $plagiarismplugin = new $plagiarismclass;
96 $reflectionmethod = new ReflectionMethod($plagiarismplugin, 'save_form_elements');
97 if ($reflectionmethod->getDeclaringClass()->getName() == get_class($plagiarismplugin)) {
98 $text = 'plagiarism_plugin::save_form_elements() is deprecated.';
99 $text .= ' Use plagiarism_' . $plugin . '_coursemodule_edit_post_actions() instead';
100 debugging($text, DEBUG_DEVELOPER
);
103 $plagiarismplugin->save_form_elements($data);
108 * adds the list of plagiarism settings to a form - called inside modules that have enabled plagiarism
110 * @deprecated Since Moodle 3.9. MDL-65835 Please use {plugin name}_coursemodule_standard_elements() instead.
111 * @todo MDL-67526 This is to be moved from here to deprecatedlib.php in Moodle 4.1
112 * @param object $mform - Moodle form object
113 * @param object $context - context object
114 * @param string $modulename - Name of the module
116 function plagiarism_get_form_elements_module($mform, $context, $modulename = "") {
118 if (empty($CFG->enableplagiarism
)) {
121 $plagiarismplugins = plagiarism_load_available_plugins();
122 foreach ($plagiarismplugins as $plugin => $dir) {
123 require_once($dir.'/lib.php');
124 $plagiarismclass = "plagiarism_plugin_$plugin";
125 $plagiarismplugin = new $plagiarismclass;
127 $reflectionmethod = new ReflectionMethod($plagiarismplugin, 'get_form_elements_module');
128 if ($reflectionmethod->getDeclaringClass()->getName() == get_class($plagiarismplugin)) {
129 $text = 'plagiarism_plugin::get_form_elements_module() is deprecated.';
130 $text .= ' Use plagiarism_' . $plugin . '_coursemodule_standard_elements() instead';
131 debugging($text, DEBUG_DEVELOPER
);
134 $plagiarismplugin->get_form_elements_module($mform, $context, $modulename);
138 * updates the status of all files within a module
140 * @param object $course - full Course object
141 * @param object $cm - full cm object
144 function plagiarism_update_status($course, $cm) {
146 if (empty($CFG->enableplagiarism
)) {
149 $plagiarismplugins = plagiarism_load_available_plugins();
151 foreach ($plagiarismplugins as $plugin => $dir) {
152 require_once($dir.'/lib.php');
153 $plagiarismclass = "plagiarism_plugin_$plugin";
154 $plagiarismplugin = new $plagiarismclass;
155 $output .= $plagiarismplugin->update_status($course, $cm);
161 * Function that prints the student disclosure notifying that the files will be checked for plagiarism
162 * @param integer $cmid - the cmid of this module
165 function plagiarism_print_disclosure($cmid) {
167 if (empty($CFG->enableplagiarism
)) {
170 $plagiarismplugins = plagiarism_load_available_plugins();
172 foreach ($plagiarismplugins as $plugin => $dir) {
173 require_once($dir.'/lib.php');
174 $plagiarismclass = "plagiarism_plugin_$plugin";
175 $plagiarismplugin = new $plagiarismclass;
176 $output .= $plagiarismplugin->print_disclosure($cmid);
182 * Helper function - also loads lib file of plagiarism plugin
184 * @todo MDL-67872 the deprecated code in this function to be removed in Moodle 4.1
185 * @return array of available plugins
187 function plagiarism_load_available_plugins() {
189 static $showndeprecatedmessage = array(); // Only show message once per page load.
191 if (empty($CFG->enableplagiarism
)) {
194 $plagiarismplugins = core_component
::get_plugin_list('plagiarism');
195 $availableplugins = array();
196 foreach ($plagiarismplugins as $plugin => $dir) {
197 // Check this plugin is enabled and a lib file exists.
198 if (get_config('plagiarism', $plugin."_use")) {
199 // Deprecated Since Moodle 3.9.
200 $pluginenabled = true;
201 if (empty($showndeprecatedmessage[$plugin])) {
202 $text = 'The setting plagiarism:'.$plugin.'_use is deprecated.';
203 $text .= ' Use plagiarism_' . $plugin . ':enabled instead';
204 debugging($text, DEBUG_DEVELOPER
);
205 $showndeprecatedmessage[$plugin] = true;
208 $pluginenabled = get_config('plagiarism_'.$plugin, 'enabled');
210 if ($pluginenabled && file_exists($dir."/lib.php")) {
211 require_once($dir.'/lib.php');
212 $plagiarismclass = "plagiarism_plugin_$plugin";
213 if (class_exists($plagiarismclass)) {
214 $availableplugins[$plugin] = $dir;
218 return $availableplugins;