1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
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.
|
|
|
8 |
//
|
|
|
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* plagiarismlib.php - Contains core Plagiarism related functions.
|
|
|
19 |
*
|
|
|
20 |
* @since Moodle 2.0
|
|
|
21 |
* @package core
|
|
|
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
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
if (!defined('MOODLE_INTERNAL')) {
|
|
|
28 |
die('Direct access to this script is forbidden.');
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* displays the similarity score and provides a link to the full report if allowed.
|
|
|
33 |
*
|
|
|
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
|
|
|
36 |
*/
|
|
|
37 |
function plagiarism_get_links($linkarray) {
|
|
|
38 |
global $CFG;
|
|
|
39 |
if (empty($CFG->enableplagiarism)) {
|
|
|
40 |
return '';
|
|
|
41 |
}
|
|
|
42 |
$plagiarismplugins = plagiarism_load_available_plugins();
|
|
|
43 |
$output = '';
|
|
|
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);
|
|
|
49 |
}
|
|
|
50 |
if (!empty($output)) {
|
|
|
51 |
return html_writer::span($output, 'core_plagiarism_links');
|
|
|
52 |
}
|
|
|
53 |
return '';
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* returns array of plagiarism details about specified file
|
|
|
58 |
*
|
|
|
59 |
* @deprecated Since Moodle 4.0. - this function was a placeholder and not used in core.
|
|
|
60 |
* @todo MDL-71326 This is to be moved from here to deprecatedlib.php in Moodle 4.4
|
|
|
61 |
* @param int $cmid
|
|
|
62 |
* @param int $userid
|
|
|
63 |
* @param object $file moodle file object
|
|
|
64 |
* @return array - sets of details about specified file, one array of details per plagiarism plugin
|
|
|
65 |
* - each set contains at least 'analyzed', 'score', 'reporturl'
|
|
|
66 |
*/
|
|
|
67 |
function plagiarism_get_file_results($cmid, $userid, $file) {
|
|
|
68 |
global $CFG;
|
|
|
69 |
$text = 'plagiarism_get_file_results is deprecated, please use plagiarism_get_links() or plugin specific functions.';
|
|
|
70 |
debugging($text, DEBUG_DEVELOPER);
|
|
|
71 |
$allresults = array();
|
|
|
72 |
if (empty($CFG->enableplagiarism)) {
|
|
|
73 |
return $allresults;
|
|
|
74 |
}
|
|
|
75 |
$plagiarismplugins = plagiarism_load_available_plugins();
|
|
|
76 |
foreach ($plagiarismplugins as $plugin => $dir) {
|
|
|
77 |
require_once($dir.'/lib.php');
|
|
|
78 |
$plagiarismclass = "plagiarism_plugin_$plugin";
|
|
|
79 |
$plagiarismplugin = new $plagiarismclass;
|
|
|
80 |
$allresults[] = $plagiarismplugin->get_file_results($cmid, $userid, $file);
|
|
|
81 |
}
|
|
|
82 |
return $allresults;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Allows a plagiarism plugin to print a button/link at the top of activity overview report pages.
|
|
|
87 |
*
|
|
|
88 |
* @deprecated Since Moodle 4.0 - Please use {plugin name}_before_standard_top_of_body_html instead.
|
|
|
89 |
* @todo MDL-71326 Remove this method.
|
|
|
90 |
* @param object $course - full Course object
|
|
|
91 |
* @param object $cm - full cm object
|
|
|
92 |
* @return string
|
|
|
93 |
*/
|
|
|
94 |
function plagiarism_update_status($course, $cm) {
|
|
|
95 |
global $CFG;
|
|
|
96 |
if (empty($CFG->enableplagiarism)) {
|
|
|
97 |
return '';
|
|
|
98 |
}
|
|
|
99 |
$plagiarismplugins = plagiarism_load_available_plugins();
|
|
|
100 |
$output = '';
|
|
|
101 |
foreach ($plagiarismplugins as $plugin => $dir) {
|
|
|
102 |
require_once($dir.'/lib.php');
|
|
|
103 |
$plagiarismclass = "plagiarism_plugin_$plugin";
|
|
|
104 |
$plagiarismplugin = new $plagiarismclass;
|
|
|
105 |
|
|
|
106 |
$reflectionmethod = new ReflectionMethod($plagiarismplugin, 'update_status');
|
|
|
107 |
if ($reflectionmethod->getDeclaringClass()->getName() == get_class($plagiarismplugin)) {
|
|
|
108 |
$text = 'plagiarism_plugin::update_status() is deprecated.';
|
|
|
109 |
$text .= ' Use plagiarism_' . $plugin . '_before_standard_top_of_body_html() instead';
|
|
|
110 |
debugging($text, DEBUG_DEVELOPER);
|
|
|
111 |
}
|
|
|
112 |
$output .= $plagiarismplugin->update_status($course, $cm);
|
|
|
113 |
}
|
|
|
114 |
return $output;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Function that prints the student disclosure notifying that the files will be checked for plagiarism
|
|
|
119 |
* @param integer $cmid - the cmid of this module
|
|
|
120 |
* @return string
|
|
|
121 |
*/
|
|
|
122 |
function plagiarism_print_disclosure($cmid) {
|
|
|
123 |
global $CFG;
|
|
|
124 |
if (empty($CFG->enableplagiarism)) {
|
|
|
125 |
return '';
|
|
|
126 |
}
|
|
|
127 |
$plagiarismplugins = plagiarism_load_available_plugins();
|
|
|
128 |
$output = '';
|
|
|
129 |
foreach ($plagiarismplugins as $plugin => $dir) {
|
|
|
130 |
require_once($dir.'/lib.php');
|
|
|
131 |
$plagiarismclass = "plagiarism_plugin_$plugin";
|
|
|
132 |
$plagiarismplugin = new $plagiarismclass;
|
|
|
133 |
$output .= $plagiarismplugin->print_disclosure($cmid);
|
|
|
134 |
}
|
|
|
135 |
return $output;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* Helper function - also loads lib file of plagiarism plugin
|
|
|
140 |
*
|
|
|
141 |
* @return array of available plugins
|
|
|
142 |
*/
|
|
|
143 |
function plagiarism_load_available_plugins() {
|
|
|
144 |
global $CFG;
|
|
|
145 |
|
|
|
146 |
if (empty($CFG->enableplagiarism)) {
|
|
|
147 |
return array();
|
|
|
148 |
}
|
|
|
149 |
$plagiarismplugins = core_component::get_plugin_list('plagiarism');
|
|
|
150 |
$availableplugins = array();
|
|
|
151 |
foreach ($plagiarismplugins as $plugin => $dir) {
|
|
|
152 |
// Check this plugin is enabled and a lib file exists.
|
|
|
153 |
$pluginenabled = get_config('plagiarism_'.$plugin, 'enabled');
|
|
|
154 |
if ($pluginenabled && file_exists($dir."/lib.php")) {
|
|
|
155 |
require_once($dir.'/lib.php');
|
|
|
156 |
$plagiarismclass = "plagiarism_plugin_$plugin";
|
|
|
157 |
if (class_exists($plagiarismclass)) {
|
|
|
158 |
$availableplugins[$plugin] = $dir;
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
return $availableplugins;
|
|
|
163 |
}
|