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
105 * @param string $modulename - Name of the module
107 function plagiarism_get_form_elements_module($mform, $context, $modulename = "") {
109 if (empty($CFG->enableplagiarism
)) {
112 $plagiarismplugins = plagiarism_load_available_plugins();
113 foreach($plagiarismplugins as $plugin => $dir) {
114 require_once($dir.'/lib.php');
115 $plagiarismclass = "plagiarism_plugin_$plugin";
116 $plagiarismplugin = new $plagiarismclass;
117 $plagiarismplugin->get_form_elements_module($mform, $context, $modulename);
121 * updates the status of all files within a module
123 * @param object $course - full Course object
124 * @param object $cm - full cm object
127 function plagiarism_update_status($course, $cm) {
129 if (empty($CFG->enableplagiarism
)) {
132 $plagiarismplugins = plagiarism_load_available_plugins();
134 foreach($plagiarismplugins as $plugin => $dir) {
135 require_once($dir.'/lib.php');
136 $plagiarismclass = "plagiarism_plugin_$plugin";
137 $plagiarismplugin = new $plagiarismclass;
138 $output .= $plagiarismplugin->update_status($course, $cm);
144 * Function that prints the student disclosure notifying that the files will be checked for plagiarism
145 * @param integer $cmid - the cmid of this module
148 function plagiarism_print_disclosure($cmid) {
150 if (empty($CFG->enableplagiarism
)) {
153 $plagiarismplugins = plagiarism_load_available_plugins();
155 foreach($plagiarismplugins as $plugin => $dir) {
156 require_once($dir.'/lib.php');
157 $plagiarismclass = "plagiarism_plugin_$plugin";
158 $plagiarismplugin = new $plagiarismclass;
159 $output .= $plagiarismplugin->print_disclosure($cmid);
165 * helper function - also loads lib file of plagiarism plugin
166 * @return array of available plugins
168 function plagiarism_load_available_plugins() {
170 if (empty($CFG->enableplagiarism
)) {
173 $plagiarismplugins = core_component
::get_plugin_list('plagiarism');
174 $availableplugins = array();
175 foreach($plagiarismplugins as $plugin => $dir) {
176 //check this plugin is enabled and a lib file exists.
177 if (get_config('plagiarism', $plugin."_use") && file_exists($dir."/lib.php")) {
178 require_once($dir.'/lib.php');
179 $plagiarismclass = "plagiarism_plugin_$plugin";
180 if (class_exists($plagiarismclass)) {
181 $availableplugins[$plugin] = $dir;
185 return $availableplugins;