Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Function that prints the student disclosure notifying that the files will be checked for plagiarism
58
 * @param integer $cmid - the cmid of this module
59
 * @return string
60
 */
61
function plagiarism_print_disclosure($cmid) {
62
    global $CFG;
63
    if (empty($CFG->enableplagiarism)) {
64
        return '';
65
    }
66
    $plagiarismplugins = plagiarism_load_available_plugins();
67
    $output = '';
68
    foreach ($plagiarismplugins as $plugin => $dir) {
69
        require_once($dir.'/lib.php');
70
        $plagiarismclass = "plagiarism_plugin_$plugin";
71
        $plagiarismplugin = new $plagiarismclass;
72
        $output .= $plagiarismplugin->print_disclosure($cmid);
73
    }
74
    return $output;
75
}
76
 
77
/**
78
 * Helper function - also loads lib file of plagiarism plugin
79
 *
80
 * @return array of available plugins
81
 */
82
function plagiarism_load_available_plugins() {
83
    global $CFG;
84
 
85
    if (empty($CFG->enableplagiarism)) {
86
        return array();
87
    }
88
    $plagiarismplugins = core_component::get_plugin_list('plagiarism');
89
    $availableplugins = array();
90
    foreach ($plagiarismplugins as $plugin => $dir) {
91
        // Check this plugin is enabled and a lib file exists.
92
        $pluginenabled = get_config('plagiarism_'.$plugin, 'enabled');
93
        if ($pluginenabled && file_exists($dir."/lib.php")) {
94
            require_once($dir.'/lib.php');
95
            $plagiarismclass = "plagiarism_plugin_$plugin";
96
            if (class_exists($plagiarismclass)) {
97
                $availableplugins[$plugin] = $dir;
98
            }
99
        }
100
    }
101
    return $availableplugins;
102
}