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 * saves/updates plagiarism settings from a modules config page - called by course/modedit.php
59 * @param object $data - form data
61 function plagiarism_save_form_elements($data) {
63 if (empty($CFG->enableplagiarism
)) {
66 $plagiarismplugins = plagiarism_load_available_plugins();
67 foreach($plagiarismplugins as $plugin => $dir) {
68 require_once($dir.'/lib.php');
69 $plagiarismclass = "plagiarism_plugin_$plugin";
70 $plagiarismplugin = new $plagiarismclass;
71 $plagiarismplugin->save_form_elements($data);
76 * adds the list of plagiarism settings to a form - called inside modules that have enabled plagiarism
78 * @param object $mform - Moodle form object
79 * @param object $context - context object
81 function plagiarism_get_form_elements_module($mform, $context) {
83 if (empty($CFG->enableplagiarism
)) {
86 $plagiarismplugins = plagiarism_load_available_plugins();
87 foreach($plagiarismplugins as $plugin => $dir) {
88 require_once($dir.'/lib.php');
89 $plagiarismclass = "plagiarism_plugin_$plugin";
90 $plagiarismplugin = new $plagiarismclass;
91 $plagiarismplugin->get_form_elements_module($mform, $context);
95 * updates the status of all files within a module
97 * @param object $course - full Course object
98 * @param object $cm - full cm object
100 function plagiarism_update_status($course, $cm) {
102 if (empty($CFG->enableplagiarism
)) {
105 $plagiarismplugins = plagiarism_load_available_plugins();
106 foreach($plagiarismplugins as $plugin => $dir) {
107 require_once($dir.'/lib.php');
108 $plagiarismclass = "plagiarism_plugin_$plugin";
109 $plagiarismplugin = new $plagiarismclass;
110 $plagiarismplugin->update_status($course, $cm);
115 * Function that prints the student disclosure notifying that the files will be checked for plagiarism
116 * @param integer $cmid - the cmid of this module
118 function plagiarism_print_disclosure($cmid) {
120 if (empty($CFG->enableplagiarism
)) {
123 $plagiarismplugins = plagiarism_load_available_plugins();
124 foreach($plagiarismplugins as $plugin => $dir) {
125 require_once($dir.'/lib.php');
126 $plagiarismclass = "plagiarism_plugin_$plugin";
127 $plagiarismplugin = new $plagiarismclass;
128 $plagiarismplugin->print_disclosure($cmid);
132 * used by admin/cron.php to get similarity scores from submitted files.
135 function plagiarism_cron() {
137 if (empty($CFG->enableplagiarism
)) {
140 $plagiarismplugins = plagiarism_load_available_plugins();
141 foreach($plagiarismplugins as $plugin => $dir) {
142 require_once($dir.'/lib.php');
143 $plagiarismclass = "plagiarism_plugin_$plugin";
144 $plagiarismplugin = new $plagiarismclass;
145 $plagiarismplugin->cron();
149 * helper function - also loads lib file of plagiarism plugin
150 * @return array of available plugins
152 function plagiarism_load_available_plugins() {
154 if (empty($CFG->enableplagiarism
)) {
157 $plagiarismplugins = get_plugin_list('plagiarism');
158 $availableplugins = array();
159 foreach($plagiarismplugins as $plugin => $dir) {
160 //check this plugin is enabled and a lib file exists.
161 if (get_config('plagiarism', $plugin."_use") && file_exists($dir."/lib.php")) {
162 require_once($dir.'/lib.php');
163 $plagiarismclass = "plagiarism_plugin_$plugin";
164 if (class_exists($plagiarismclass)) {
165 $availableplugins[$plugin] = $dir;
169 return $availableplugins;