Merge branch 'MDL-77272-main' of https://github.com/SergioComeron/moodle
[moodle.git] / lib / plagiarismlib.php
blob7f1c9f1b8277e40e8b8ca271fb52792a5b9adeea
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.
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/>.
17 /**
18 * plagiarismlib.php - Contains core Plagiarism related functions.
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
27 if (!defined('MOODLE_INTERNAL')) {
28 die('Direct access to this script is forbidden.');
31 /**
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) {
38 global $CFG;
39 if (empty($CFG->enableplagiarism)) {
40 return '';
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);
50 if (!empty($output)) {
51 return html_writer::span($output, 'core_plagiarism_links');
53 return '';
56 /**
57 * returns array of plagiarism details about specified file
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'
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;
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);
82 return $allresults;
85 /**
86 * Allows a plagiarism plugin to print a button/link at the top of activity overview report pages.
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
94 function plagiarism_update_status($course, $cm) {
95 global $CFG;
96 if (empty($CFG->enableplagiarism)) {
97 return '';
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;
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);
112 $output .= $plagiarismplugin->update_status($course, $cm);
114 return $output;
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
122 function plagiarism_print_disclosure($cmid) {
123 global $CFG;
124 if (empty($CFG->enableplagiarism)) {
125 return '';
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);
135 return $output;
139 * Helper function - also loads lib file of plagiarism plugin
141 * @return array of available plugins
143 function plagiarism_load_available_plugins() {
144 global $CFG;
146 if (empty($CFG->enableplagiarism)) {
147 return array();
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;
162 return $availableplugins;