-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.php
173 lines (122 loc) · 4.3 KB
/
lib.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
<?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/>.
/**
* Playlist resource plugin
*
* This plugin provides a simple container for a list of URLs that
* can be referenced by the RTMP filter plugin
*
* @author Fred Woolard <woolardfa@appstate.edu>
* @copyright (c) 2013 Appalachian State Universtiy, Boone, NC
* @license GNU General Public License version 3
* @package mod
* @subpackage playlist
*/
defined('MOODLE_INTERNAL') || die;
/**
* @param string $feature FEATURE_xx constant for requested feature
* @return bool|null True if module supports feature, false if not, null if doesn't know
*/
function playlist_supports($feature)
{
switch($feature) {
case FEATURE_IDNUMBER: return true;
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_GROUPMEMBERSONLY: return false;
case FEATURE_MOD_INTRO: return false;
case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_NO_VIEW_LINK: return false;
default: return null;
}
}
function playlist_page_type_list($pagetype, $parentcontext, $currentcontext)
{
return array('mod-playlist-*' => get_string('page-mod-playlist-x', 'mod_playlist'));
}
function playlist_get_view_actions()
{
return array('view', 'view all');
}
function playlist_get_post_actions()
{
return array('update', 'add');
}
function playlist_reset_userdata($data)
{
return array();
}
/**
* Add a new playlist instance
*
* @param stdClass $playlist
* @return int
* @uses $DB
*/
function playlist_add_instance($playlist, $form)
{
global $DB;
$playlist->list = playlist_clean_list($playlist->list);
return $DB->insert_record('playlist', $playlist);
}
/**
* Update a playlist instance
*
* @param stdClass $playlist
* @return boolean
* @uses $DB
*/
function playlist_update_instance($playlist, $form)
{
global $DB;
$playlist->id = $playlist->instance;
$playlist->list = playlist_clean_list($playlist->list);
return (boolean)$DB->update_record('playlist', $playlist);
}
/**
* Delete a playlist instance
*
* @param int $id
* @return boolean
* @uses $DB
*/
function playlist_delete_instance($id)
{
global $DB;
return (boolean)$DB->delete_records('playlist', array('id' => $id));
}
/**
* Clean the submitted playlist (text)
*
*/
function playlist_clean_list($list_text)
{
$buf = array();
$list = array_map('trim', explode("\n", $list_text));
foreach ($list as $item) {
if (empty($item)) continue;
@list($url, $name) = array_map('trim', explode(',', $item, 2));
if (empty($url)) continue;
$url = str_replace(' ', '+', $url);
$name = clean_param(trim($name), PARAM_TEXT);
$buf[] = $url . (empty($name) ? '' : ",$name");
} // foreach
return implode("\n", array_unique($buf));
}