3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * plagiarismlib.php - Contains core Plagiarism related functions.
23 * @subpackage plagiarism
24 * @copyright 2010 Dan Marsden http://danmarsden.com
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 ///// GENERIC PLAGIARISM FUNCTIONS ////////////////////////////////////////////////////
30 if (!defined('MOODLE_INTERNAL')) {
31 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
35 * displays the similarity score and provides a link to the full report if allowed.
37 * @param object $linkarray contains all relevant information for the plugin to generate a link
38 * @return string - url to allow login/viewing of a similarity report
40 function plagiarism_get_links($linkarray) {
42 if (empty($CFG->enableplagiarism
)) {
45 $plagiarismplugins = plagiarism_load_available_plugins();
47 foreach($plagiarismplugins as $plugin => $dir) {
48 require_once($dir.'/lib.php');
49 $plagiarismclass = "plagiarism_plugin_$plugin";
50 $plagiarismplugin = new $plagiarismclass;
51 $output .= $plagiarismplugin->get_links($linkarray);
57 * returns array of plagiarism details about specified file
61 * @param object $file moodle file object
62 * @return array - sets of details about specified file, one array of details per plagiarism plugin
63 * - each set contains at least 'analyzed', 'score', 'reporturl'
65 function plagiarism_get_file_results($cmid, $userid, $file) {
67 $allresults = array();
68 if (empty($CFG->enableplagiarism
)) {
71 $plagiarismplugins = plagiarism_load_available_plugins();
72 foreach($plagiarismplugins as $plugin => $dir) {
73 require_once($dir.'/lib.php');
74 $plagiarismclass = "plagiarism_plugin_$plugin";
75 $plagiarismplugin = new $plagiarismclass;
76 $allresults[] = $plagiarismplugin->get_file_results($cmid, $userid, $file);
82 * saves/updates plagiarism settings from a modules config page - called by course/modedit.php
84 * @param object $data - form data
86 function plagiarism_save_form_elements($data) {
88 if (empty($CFG->enableplagiarism
)) {
91 $plagiarismplugins = plagiarism_load_available_plugins();
92 foreach($plagiarismplugins as $plugin => $dir) {
93 require_once($dir.'/lib.php');
94 $plagiarismclass = "plagiarism_plugin_$plugin";
95 $plagiarismplugin = new $plagiarismclass;
96 $plagiarismplugin->save_form_elements($data);
101 * adds the list of plagiarism settings to a form - called inside modules that have enabled plagiarism
103 * @param object $mform - Moodle form object
104 * @param object $context - context object
106 function plagiarism_get_form_elements_module($mform, $context) {
108 if (empty($CFG->enableplagiarism
)) {
111 $plagiarismplugins = plagiarism_load_available_plugins();
112 foreach($plagiarismplugins as $plugin => $dir) {
113 require_once($dir.'/lib.php');
114 $plagiarismclass = "plagiarism_plugin_$plugin";
115 $plagiarismplugin = new $plagiarismclass;
116 $plagiarismplugin->get_form_elements_module($mform, $context);
120 * updates the status of all files within a module
122 * @param object $course - full Course object
123 * @param object $cm - full cm object
126 function plagiarism_update_status($course, $cm) {
128 if (empty($CFG->enableplagiarism
)) {
131 $plagiarismplugins = plagiarism_load_available_plugins();
133 foreach($plagiarismplugins as $plugin => $dir) {
134 require_once($dir.'/lib.php');
135 $plagiarismclass = "plagiarism_plugin_$plugin";
136 $plagiarismplugin = new $plagiarismclass;
137 $output .= $plagiarismplugin->update_status($course, $cm);
143 * Function that prints the student disclosure notifying that the files will be checked for plagiarism
144 * @param integer $cmid - the cmid of this module
147 function plagiarism_print_disclosure($cmid) {
149 if (empty($CFG->enableplagiarism
)) {
152 $plagiarismplugins = plagiarism_load_available_plugins();
154 foreach($plagiarismplugins as $plugin => $dir) {
155 require_once($dir.'/lib.php');
156 $plagiarismclass = "plagiarism_plugin_$plugin";
157 $plagiarismplugin = new $plagiarismclass;
158 $output .= $plagiarismplugin->print_disclosure($cmid);
163 * used by admin/cron.php to get similarity scores from submitted files.
166 function plagiarism_cron() {
168 if (empty($CFG->enableplagiarism
)) {
171 $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 $plagiarismplugin->cron();
180 * helper function - also loads lib file of plagiarism plugin
181 * @return array of available plugins
183 function plagiarism_load_available_plugins() {
185 if (empty($CFG->enableplagiarism
)) {
188 $plagiarismplugins = get_plugin_list('plagiarism');
189 $availableplugins = array();
190 foreach($plagiarismplugins as $plugin => $dir) {
191 //check this plugin is enabled and a lib file exists.
192 if (get_config('plagiarism', $plugin."_use") && file_exists($dir."/lib.php")) {
193 require_once($dir.'/lib.php');
194 $plagiarismclass = "plagiarism_plugin_$plugin";
195 if (class_exists($plagiarismclass)) {
196 $availableplugins[$plugin] = $dir;
200 return $availableplugins;