-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_file_upload.php
125 lines (102 loc) · 6.07 KB
/
template_file_upload.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
115
116
117
118
119
120
121
122
123
124
125
<?php /* Template Name: File Upload (Repo) */
acf_form_head();
get_header();
?>
<script>
var meta = null;
window.addEventListener("message",function(msg){
if(event.data.event=="POST_DATA") {
if(event.data.data["cclom:title"])
meta = event.data.data;
if(meta) {
var xhr = new XMLHttpRequest();
xhr.open("POST", "<?php echo WLO_REPO; ?>rest/node/v1/nodes/-home-/-inbox-/children?type=ccm%3Aio&renameIfExists=true&versionComment=MAIN_FILE_UPLOAD", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.crossDomain = true;
xhr.withCredentials = true;
xhr.setRequestHeader("Authorization", "Basic " + btoa("oer_uploader:oer_uploader"));
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status === 200) {
var data=xhr.responseText;
var jsonResponse = JSON.parse(data);
var nodeId = jsonResponse.node.ref.id;
var xhr2 = new XMLHttpRequest();
var formData = new FormData(document.querySelector('#uploadwlo'));
var mimetype = formData.get('file').type;
xhr2.open("POST", "<?php echo WLO_REPO; ?>rest/node/v1/nodes/-home-/"+nodeId+"/content?mimetype="+encodeURIComponent(mimetype), true);
xhr2.setRequestHeader("Authorization", "Basic " + btoa("oer_uploader:oer_uploader"));
//xhr2.setRequestHeader("Content-type", "multipart/form-data");
xhr2.setRequestHeader("Accept", "application/json");
xhr2.onreadystatechange = function() {
if (xhr2.readyState == 4 && xhr2.status === 200) {
var xhr3 = new XMLHttpRequest();
var payload = '{"inherited":true,"permissions":[{"authority":{"authorityName":"GROUP_WLO-Redaktion","authorityType":"GROUP"},"permissions":["Coordinator"]}]}';
xhr3.open("POST", "<?php echo WLO_REPO; ?>rest/node/v1/nodes/-home-/"+nodeId+"/permissions?mailtext=&sendMail=true", true);
xhr3.setRequestHeader("Authorization", "Basic " + btoa("oer_uploader:oer_uploader"));
xhr3.setRequestHeader("Content-type", "application/json");
xhr3.setRequestHeader("Accept", "application/json");
xhr3.onreadystatechange = function() {
if (xhr3.readyState == 4 && xhr3.status === 200) {
var xhr4 = new XMLHttpRequest();
var payload2 = '{"receiver":[{"authorityName":"GROUP_WLO-Redaktion"}],"comment":"Upload via Formular","status":"200_tocheck"}\n';
xhr4.open("PUT", "<?php echo WLO_REPO; ?>rest/node/v1/nodes/-home-/"+nodeId+"/workflow", true);
xhr4.setRequestHeader("Authorization", "Basic " + btoa("oer_uploader:oer_uploader"));
xhr4.setRequestHeader("Content-type", "application/json");
xhr4.setRequestHeader("Accept", "application/json");
xhr4.onreadystatechange = function() {
if (xhr4.readyState == 4 && xhr4.status === 200) {
alert("Datei wurde hochgeladen!");
} else {
console.log("Fehler intern");
}
}
xhr4.send(payload2);
} else {
console.log("Fehler intern");
}
}
xhr3.send(payload);
} else {
console.log("Fehler intern");
}
}
xhr2.send(formData);
} else {
console.log("Fehler extern / OPTIONS");
}
}
xhr.send(JSON.stringify(meta));
}
}
});
function publish(){
document.getElementById("mds").contentWindow.postMessage({event:"PARENT_FETCH_DATA"},'*');
}
</script>
<div class="grid-container">
<div class="grid-x grid-margin-x">
<div class="medium-12 cell">
<h1 class="page-title"><?php the_title(); ?></h1>
</div>
<?php
while ( have_posts() ) : the_post(); ?>
<div class="cell large-8">
<?php
the_content();
?>
</div>
<div class="wlo_file_upload">
<form id="uploadwlo" action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" class="button" name="file" id="file">
<input type="button" class="button success" onclick="document.getElementById('mds').contentWindow.postMessage({event:'PARENT_FETCH_DATA'},'*');" value="Datei hochladen" name="submit">
</form>
<iframe id="mds" class="upload-metadata" src="https://redaktion.openeduhub.net/edu-sharing/components/embed/mds?set=mds_oeh&group=io_wordpress" title="Metadaten" frameBorder="0"></iframe>
</div>
<?php endwhile;
?>
</div>
</div>
</div>
<?php
get_footer();