-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimport_metadata.php
114 lines (102 loc) · 3.5 KB
/
import_metadata.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
// This file is part of Moodle - http://moodle.org/
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Get repository properties and generate app properties - put them to configuration
*
* @package mod_edusharing
* @copyright metaVentis GmbH — http://metaventis.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @todo Implement as moustache template
*/
use mod_edusharing\EduSharingService;
use mod_edusharing\EduSharingUserException;
use mod_edusharing\MetaDataFrontend;
use mod_edusharing\MetadataLogic;
use mod_edusharing\PluginRegistrationFrontend;
use mod_edusharing\UtilityFunctions;
require_once(dirname(__FILE__) . '/../../config.php');
global $CFG;
require_once($CFG->dirroot . '/mod/edusharing/eduSharingAutoloader.php');
try {
require_login();
} catch (Exception $exception) {
echo $exception->getMessage();
unset($exception);
exit();
}
echo '<html>
<head>
<title>edu-sharing metadata import</title>
<link rel="stylesheet" href="import_metadata_style.css" />
</head>
<body>
<div class="h5p-header">
<h1>Import metadata from an edu-sharing repository</h1>
</div>
<div class="wrap">';
if (!is_siteadmin()) {
echo '<h3>Access denied!</h3>';
echo '<p>Please login with your admin account in moodle.</p>';
exit();
}
if (isset($_POST['repoReg'])) {
if (!empty($_POST['appId'])) {
set_config('application_appid', $_POST['appId'], 'edusharing');
}
if (!empty($_POST['host_aliases'])) {
set_config('application_host_aliases', $_POST['host_aliases'], 'edusharing');
}
echo PluginRegistrationFrontend::register_plugin($_POST['repoUrl'], $_POST['repoAdmin'], $_POST['repoPwd']);
exit();
}
$filename = '';
try {
$metadataurl = optional_param('mdataurl', '', PARAM_NOTAGS);
} catch (Exception $exception) {
// This exception is stupid.
unset($exception);
}
if (!empty($metadataurl)) {
try {
$utils = new UtilityFunctions();
$appid = $utils->get_config_entry('application_appid');
if (empty($appid)) {
$utils->set_config_entry('application_appid', uniqid('moodle_'));
}
$service = new MetadataLogic(new EduSharingService());
$service->import_metadata($metadataurl);
echo '<h3 class="edu_success">Import successful.</h3>';
} catch (EduSharingUserException $edusharinguserexception) {
echo $edusharinguserexception->get_html_message();
} catch (Exception $exception) {
echo '<p style="background: #FF8170">Unexpected error - please try again later<br></p>';
}
if ($service->reloadform) {
echo MetaDataFrontend::get_meta_data_form();
}
$repoform = MetaDataFrontend::get_repo_form();
if ($repoform !== null) {
echo $repoform;
}
exit();
}
echo MetaDataFrontend::get_meta_data_form();
$repoform = MetaDataFrontend::get_repo_form();
if ($repoform !== null) {
echo $repoform;
}
echo '</div></body></html>';
exit();