[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 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. 9 // 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. 14 // 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/>. 17 18 /** 19 * plagiarismlib.php - Contains core Plagiarism related functions. 20 * 21 * @since Moodle 2.0 22 * @package moodlecore 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 26 */ 27 28 ///// GENERIC PLAGIARISM FUNCTIONS //////////////////////////////////////////////////// 29 30 if (!defined('MOODLE_INTERNAL')) { 31 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 32 } 33 34 /** 35 * displays the similarity score and provides a link to the full report if allowed. 36 * 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 39 */ 40 function plagiarism_get_links($linkarray) { 41 global $CFG; 42 if (empty($CFG->enableplagiarism)) { 43 return ''; 44 } 45 $plagiarismplugins = plagiarism_load_available_plugins(); 46 $output = ''; 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); 52 } 53 return $output; 54 } 55 56 /** 57 * returns array of plagiarism details about specified file 58 * 59 * @param int $cmid 60 * @param int $userid 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' 64 */ 65 function plagiarism_get_file_results($cmid, $userid, $file) { 66 global $CFG; 67 $allresults = array(); 68 if (empty($CFG->enableplagiarism)) { 69 return $allresults; 70 } 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); 77 } 78 return $allresults; 79 } 80 81 /** 82 * saves/updates plagiarism settings from a modules config page - called by course/modedit.php 83 * 84 * @param object $data - form data 85 */ 86 function plagiarism_save_form_elements($data) { 87 global $CFG; 88 if (empty($CFG->enableplagiarism)) { 89 return ''; 90 } 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); 97 } 98 } 99 100 /** 101 * adds the list of plagiarism settings to a form - called inside modules that have enabled plagiarism 102 * 103 * @param object $mform - Moodle form object 104 * @param object $context - context object 105 * @param string $modulename - Name of the module 106 */ 107 function plagiarism_get_form_elements_module($mform, $context, $modulename = "") { 108 global $CFG; 109 if (empty($CFG->enableplagiarism)) { 110 return ''; 111 } 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); 118 } 119 } 120 /** 121 * updates the status of all files within a module 122 * 123 * @param object $course - full Course object 124 * @param object $cm - full cm object 125 * @return string 126 */ 127 function plagiarism_update_status($course, $cm) { 128 global $CFG; 129 if (empty($CFG->enableplagiarism)) { 130 return ''; 131 } 132 $plagiarismplugins = plagiarism_load_available_plugins(); 133 $output = ''; 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); 139 } 140 return $output; 141 } 142 143 /** 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 146 * @return string 147 */ 148 function plagiarism_print_disclosure($cmid) { 149 global $CFG; 150 if (empty($CFG->enableplagiarism)) { 151 return ''; 152 } 153 $plagiarismplugins = plagiarism_load_available_plugins(); 154 $output = ''; 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); 160 } 161 return $output; 162 } 163 /** 164 * used by admin/cron.php to get similarity scores from submitted files. 165 * 166 */ 167 function plagiarism_cron() { 168 global $CFG; 169 if (empty($CFG->enableplagiarism)) { 170 return ''; 171 } 172 $plagiarismplugins = plagiarism_load_available_plugins(); 173 foreach($plagiarismplugins as $plugin => $dir) { 174 require_once($dir.'/lib.php'); 175 $plagiarismclass = "plagiarism_plugin_$plugin"; 176 $plagiarismplugin = new $plagiarismclass; 177 if (method_exists($plagiarismplugin, 'cron')) { 178 mtrace('Processing cron function for plagiarism_plugin_' . $plugin . '...', ''); 179 cron_trace_time_and_memory(); 180 $plagiarismplugin->cron(); 181 } 182 } 183 } 184 /** 185 * helper function - also loads lib file of plagiarism plugin 186 * @return array of available plugins 187 */ 188 function plagiarism_load_available_plugins() { 189 global $CFG; 190 if (empty($CFG->enableplagiarism)) { 191 return array(); 192 } 193 $plagiarismplugins = core_component::get_plugin_list('plagiarism'); 194 $availableplugins = array(); 195 foreach($plagiarismplugins as $plugin => $dir) { 196 //check this plugin is enabled and a lib file exists. 197 if (get_config('plagiarism', $plugin."_use") && file_exists($dir."/lib.php")) { 198 require_once($dir.'/lib.php'); 199 $plagiarismclass = "plagiarism_plugin_$plugin"; 200 if (class_exists($plagiarismclass)) { 201 $availableplugins[$plugin] = $dir; 202 } 203 } 204 } 205 return $availableplugins; 206 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |