-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditvideo.php
199 lines (162 loc) · 6.44 KB
/
editvideo.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
// This file is part of YouTube Video Playlist block for 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/>.
/**
* Script to let a user edit the properties of a particular YouTube video.
*
* @package block
* @subpackage youtube_video
* @author Paul Holden, Greenhead College, 31st July 2007 (http://gcmoodle.greenhead.ac.uk/external/youtube/)
* @copyright 2012 Andy Chan, CITE, HKU <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir .'/simplepie/moodle_simplepie.php');
class video_edit_form extends moodleform {
protected $isadding;
protected $caneditshared;
protected $title = '';
protected $description = '';
protected $url = '';
function __construct($actionurl, $isadding, $caneditshared) {
$this->isadding = $isadding;
$this->caneditshared = $caneditshared;
parent::moodleform($actionurl);
}
function definition() {
$mform =& $this->_form;
// Then show the fields about where this block appears.
$mform->addElement('header', 'youtubeeditvideoheader', get_string('formaltitle', 'block_youtube_video'));
$mform->addElement('text', 'url', get_string('video_url', 'block_youtube_video'), array('size' => 60));
$mform->setType('url', PARAM_URL);
$mform->addRule('url', null, 'required');
$mform->addElement('text', 'title', get_string('edit_title', 'block_youtube_video'), array('size' => 60));
$mform->setType('title', PARAM_NOTAGS);
$mform->addRule('title', null, 'required');
$editoroptions = array();
$mform->addElement('editor', 'description', get_string('description'), null, $editoroptions);
$mform->setType('description', PARAM_CLEANHTML);
if ($this->caneditshared) {
$mform->addElement('selectyesno', 'shared', get_string('edit_shared', 'block_youtube_video'));
$mform->setDefault('shared', 0);
}
$submitlabal = null; // Default
if ($this->isadding) {
$submitlabal = get_string('add_new_video', 'block_youtube_video');
}
$this->add_action_buttons(true, $submitlabal);
}
function definition_after_data(){
}
function validation($data, $files) {
$errors = parent::validation($data, $files);
return $errors;
}
function get_data() {
$data = parent::get_data();
if ($data) {
if($this->title){
$data->title = $this->title;
}
if($this->description){
$data->description = $this->description;
}
// Process URL
if ($this->url) {
$data->url = $this->url;
}
if (strpos($data->url,'&rel=0') === FALSE) {
if (strpos($data->url,'&rel=1') === FALSE) {
$data->url .= '&rel=0';
} else {
$data->url = str_replace('&rel=1','&rel=0',$data->url);
}
}
$data->url = str_replace('http://youtu.be/', 'http://www.youtube.com/watch?v=', $data->url);
}
return $data;
}
}
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
$courseid = optional_param('courseid', 0, PARAM_INTEGER);
$videoid = optional_param('videoid', 0, PARAM_INTEGER); // 0 mean create new.
if ($courseid == SITEID) {
$courseid = 0;
}
if ($courseid) {
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$PAGE->set_course($course);
$context = $PAGE->context;
} else {
$context = get_context_instance(CONTEXT_SYSTEM);
$PAGE->set_context($context);
}
$managesharedvideos = has_capability('block/youtube_video:manageanyvideos', $context);
if (!$managesharedvideos) {
require_capability('block/youtube_video:manageownvideos', $context);
}
$urlparams = array('videoid' => $videoid);
if ($courseid) {
$urlparams['courseid'] = $courseid;
}
if ($returnurl) {
$urlparams['returnurl'] = $returnurl;
}
$managevideos = new moodle_url('/blocks/youtube_video/managevideos.php', $urlparams);
$PAGE->set_url('/blocks/youtube_video/editvideo.php', $urlparams);
$PAGE->set_pagelayout('base');
if ($videoid) {
$isadding = false;
$videorecord = $DB->get_record('block_youtube_video', array('id' => $videoid), '*', MUST_EXIST);
} else {
$isadding = true;
$videorecord = new stdClass;
}
$mform = new video_edit_form($PAGE->url, $isadding, $managesharedvideos);
$mform->set_data($videorecord);
if ($mform->is_cancelled()) {
redirect($managevideos);
} else if ($data = $mform->get_data()) {
$data->courseid = $courseid;
$data->description = $data->description['text'];
if (!$managesharedvideos) {
$data->shared = 0;
}
if ($isadding) {
$DB->insert_record('block_youtube_video', $data);
} else {
$data->id = $videoid;
$DB->update_record('block_youtube_video', $data);
}
redirect($managevideos);
} else {
if ($isadding) {
$strtitle = get_string('add_new_video', 'block_youtube_video');
} else {
$strtitle = get_string('edit_video', 'block_youtube_video');
}
$PAGE->set_title($strtitle);
$PAGE->set_heading($strtitle);
$settingsurl = new moodle_url('/admin/settings.php?section=blocksettingyoutube_video');
$PAGE->navbar->add(get_string('blocks'));
$PAGE->navbar->add(get_string('formaltitle', 'block_youtube_video'), $settingsurl);
$PAGE->navbar->add(get_string('tab_managevids', 'block_youtube_video'));
$PAGE->navbar->add($strtitle);
echo $OUTPUT->header();
echo $OUTPUT->heading($strtitle, 2);
$mform->display();
echo $OUTPUT->footer();
}