This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
forked from moodlehu/moodle-mod_etherpadlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
174 lines (148 loc) · 5.79 KB
/
view.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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/>.
/**
* This page prints a particular instance of etherpadlite
*
* @package mod_etherpadlite
*
* @author Timo Welde <tjwelde@gmail.com>
* @copyright 2012 Humboldt-Universität zu Berlin <moodle-support@cms.hu-berlin.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$a = optional_param('a', 0, PARAM_INT); // etherpadlite instance ID
if ($id) {
$cm = get_coursemodule_from_id('etherpadlite', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$etherpadlite = $DB->get_record('etherpadlite', array('id' => $cm->instance), '*', MUST_EXIST);
} elseif ($a) {
// Doesn't it ahve to be array('id' => $a)?
$etherpadlite = $DB->get_record('etherpadlite', array('id' => $n), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $etherpadlite->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('etherpadlite', $etherpadlite->id, $course->id, false, MUST_EXIST);
} else {
error('You must specify a course_module ID or an instance ID');
}
// This must be here, so that require login doesn't throw a warning
$PAGE->set_url('/mod/etherpadlite/view.php', array('id' => $cm->id));
require_login($course, true, $cm);
$config = get_config("etherpadlite");
if($config->ssl) {
// https_required doesn't work, if $CFG->loginhttps doesn't work
$CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
if (!isset($_SERVER['HTTPS'])) {
$url = $CFG->httpswwwroot.'/mod/etherpadlite/view.php?id='.$id;
redirect($url);
}
}
// [START] Initialise the session for the Author
// php.ini separator.output auf '&' setzen
$separator = ini_get('arg_separator.output');
ini_set('arg_separator.output', '&');
// set vars
$domain = $config->url;
$padId = $etherpadlite->uri;
$fullurl = "domain.tld";
// make a new intance from the etherpadlite client
$instance = new EtherpadLiteClient($config->apikey,$domain.'api');
// fullurl generation
if(isguestuser() && !etherpadlite_guestsallowed($etherpadlite)) {
try {
$readOnlyID = $instance->getReadOnlyID($padId);
$readOnlyID = $readOnlyID->readOnlyID;
$fullurl = $domain.'ro/'.$readOnlyID;
}
catch (Exception $e) {
//echo "\n\ngetReadOnlyID failed with Message: ".$e->getMessage();
throw $e;
}
}
else {
$fullurl = $domain.'p/'.$padId;
}
// get the groupID
$groupID = explode('$', $padId);
$groupID = $groupID[0];
// create author if not exists for logged in user (with first and lastname)
try {
if(isguestuser() && etherpadlite_guestsallowed($etherpadlite)) {
$author = $instance->createAuthor('Guest-'.etherpadlite_genRandomString());
}
else if(isset($USER->firstname, $USER->lastname)) {
$userName = $USER->firstname.' '.$USER->lastname;
$author = $instance->createAuthorIfNotExistsFor($USER->id, $userName);
}
else {
$author = $instance->createAuthorIfNotExistsFor($USER->id);
}
$authorID = $author->authorID;
//echo "The AuthorID is now $authorID\n\n";
} catch (Exception $e) {
// the pad already exists or something else went wrong
//echo "\n\ncreateAuthor Failed with message: ". $e->getMessage();
throw $e;
}
//$validUntil = mktime(0, 0, 0, date("m"), date("d")+1, date("y")); // +1 day in the future
$validUntil = time() + $config->cookietime;
try{
$sessionID = $instance->createSession($groupID, $authorID, $validUntil);
}
catch (Exception $e) {
//echo "\n\ncreateSession failed with message: ".$e->getMessage();
throw $e;
}
$sessionID = $sessionID->sessionID;
// if we reach the etherpadlite server over https, then the cookie should only be delivered over ssl
$ssl = (stripos($config->url, 'https://')===0)?true:false;
setcookie("sessionID",$sessionID,$validUntil,'/',$config->cookiedomain, $ssl); // Set a cookie
// seperator.output wieder zur�cksetzen
ini_set('arg_separator.output', $separator);
// [END] Etherpad Lite init
$context = context_module::instance($cm->id);
/// Print the page header
$PAGE->set_title("Etherpad Lite: ".format_string($etherpadlite->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);
echo $OUTPUT->header();
/// Print the main part of the page
$summary = format_module_intro('etherpadite', $etherpadlite, $cm->id);
if(isguestuser() && !etherpadlite_guestsallowed($etherpadlite)) {
$summary.= "<br/><br/>".get_string('summaryguest','etherpadlite');
}
if(!empty($summary)) {
echo $OUTPUT->box($summary, 'generalbox mod_introbox', 'etherpadliteintro');
}
echo '<iframe id="etherpadiframe" src ="'.$fullurl.'" width="100%", height="500px"></iframe>';
echo '<script type="text/javascript">
YUI().use(\'resize\', function(Y) {
var resize = new Y.Resize({
//Selector of the node to resize
node: \'#etherpadiframe\',
handles: \'br\'
});
resize.plug(Y.Plugin.ResizeConstrained, {
minWidth: 380,
minHeight: 140,
maxWidth: 1080,
maxHeight: 1080
});
});
</script>
';
/// Finish the page
echo $OUTPUT->footer();