/
mobileprocessor.php
69 lines (56 loc) · 2.21 KB
/
mobileprocessor.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
<?php
require_once("../../config.php");
require_once("lib.php");
require_once("classAudioFile.php");
$id = optional_param('id', 0, PARAM_INT);
$uid = optional_param('uid', 0, PARAM_INT);
$time = optional_param('time', 0, PARAM_INT);
if ($id) {
if (! $cm = $DB->get_record("course_modules", array("id"=> $id))) {
error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record("course", array("id"=> $cm->course))) {
error("Course is misconfigured");
}
if (! $videoboard = $DB->get_record("videoboard", array("id"=> $cm->instance))) {
error("Course module is incorrect");
}
} else {
if (! $videoboard = $DB->get_record("videoboard", array("id"=> $a))) {
error("Course module is incorrect");
}
if (! $course = $DB->get_record("course", array("id"=> $videoboard->course))) {
error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("videoboard", $videoboard->id, $course->id)) {
error("Course Module ID was incorrect");
}
}
$linktofile = $CFG->wwwroot.'/mod/videoboard/file.php?file='.$videoboard->fileid;
$file = videoboard_getfileid($videoboard->fileid);
$AF = new AudioFile;
if (is_file($file->fullpatch)) {
$AF->loadFile($file->fullpatch);
$duration = round($AF->wave_length);
if (empty($duration)) {
$m = new mp3file($file->fullpatch);
$a = $m->get_metadata();
$duration = $a['Length'];
}
}
if ($uid)
$USER = $DB->get_record("user", array("id"=> $uid));
if (empty($time))
$time = time();
$json = array(
"play" => $linktofile,
"title" => $videoboard->name,
"descr" => strip_tags($videoboard->intro),
"type" => 'videoboard',
"id" => $id,
"cid" => $course->id,
"uid" => $USER->id,
"filename" => str_replace(" ", "_", $USER->username)."_".date("Ymd_Hi", $time),
"duration" => $duration
);
echo json_encode($json);