コード例 #1
0
ファイル: lib.php プロジェクト: e-rasvet/voiceshadow
function voiceshadow_cron()
{
    global $DB, $CFG;
    if ($CFG->voiceshadow_convert == 1) {
        if ($data = $DB->get_record_sql("SELECT * FROM {voiceshadow_process} WHERE `status` = 'open' LIMIT 1")) {
            $from = voiceshadow_getfileid($data->itemid);
            $add = new stdClass();
            $add->id = $data->id;
            $add->status = 'send';
            $DB->update_record("voiceshadow_process", $add);
            $ch = curl_init();
            if ($data->type == 'audio/wav') {
                $datasend = array('name' => $data->name, 'mconverter_wav' => '@' . $from->fullpatch);
            }
            if ($data->type == 'audio/mp4') {
                $datasend = array('name' => $data->name, 'mconverter_wav' => '@' . $from->fullpatch);
            }
            curl_setopt($ch, CURLOPT_URL, $CFG->voiceshadow_convert_url . '/send.php');
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $datasend);
            curl_exec($ch);
        } else {
            if ($dataall = $DB->get_records_sql("SELECT * FROM {voiceshadow_process} WHERE `status` = 'send'")) {
                foreach ($dataall as $data) {
                    if (!($item = $DB->get_record("voiceshadow_files", array("itemoldid" => $data->itemid)))) {
                        if (!($item = $DB->get_record("voiceshadow_comments", array("itemoldid" => $data->itemid)))) {
                            if ($voiceshadow = $DB->get_record("voiceshadow", array("fileid" => $data->itemid))) {
                                $module = $DB->get_record("modules", array("name" => "voiceshadow"));
                                $instance = $DB->get_record("course_modules", array("module" => $module->id, "instance" => $voiceshadow->id));
                                $item = new stdClass();
                                $item->userid = $voiceshadow->teacher;
                                $item->instance = $instance->id;
                                $item->id = $voiceshadow->id;
                                $item->filename = "voiceshadow_" . $voiceshadow->id;
                                $table = 'voiceshadow';
                            } else {
                                $DB->delete_records('voiceshadow_process', array('id' => $data->id));
                                return true;
                            }
                        } else {
                            $table = 'voiceshadow_comments';
                        }
                    } else {
                        $table = 'voiceshadow_files';
                    }
                    $student = $DB->get_record("user", array("id" => $item->userid));
                    $context = get_context_instance(CONTEXT_MODULE, $item->instance);
                    $fs = get_file_storage();
                    $file_record = new stdClass();
                    $file_record->component = 'mod_voiceshadow';
                    $file_record->contextid = $context->id;
                    $file_record->userid = $item->userid;
                    $file_record->filearea = 'private';
                    $file_record->filepath = "/";
                    $file_record->itemid = $item->id;
                    $file_record->license = $CFG->sitedefaultlicense;
                    $file_record->author = fullname($student);
                    $file_record->source = '';
                    $json = json_decode(file_get_contents($CFG->voiceshadow_convert_url . "/get.php?name={$data->name}.mp3"));
                    if (!empty($json->url)) {
                        $DB->delete_records('voiceshadow_process', array('id' => $data->id));
                        $to = $CFG->dataroot . "/temp/" . $item->filename . ".mp3";
                        file_put_contents($to, file_get_contents($json->url));
                        $file_record->filename = $item->filename . ".mp3";
                        $itemid = $fs->create_file_from_pathname($file_record, $to);
                        $file = voiceshadow_getfileid($itemid->get_id());
                        @chmod($file->fullpatch, 0755);
                        if ($table == 'voiceshadow') {
                            $DB->set_field($table, "fileid", $itemid->get_id(), array("id" => $item->id));
                        } else {
                            $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $item->id));
                        }
                        unlink($to);
                        break;
                    }
                }
            }
        }
    } else {
        /*
        * Old method
        */
        if ($data = $DB->get_record_sql("SELECT * FROM {voiceshadow_process} LIMIT 1")) {
            $DB->delete_records('voiceshadow_process', array('id' => $data->id));
            if (!($item = $DB->get_record("voiceshadow_files", array("itemoldid" => $data->itemid)))) {
                $item = $DB->get_record("voiceshadow_comments", array("itemoldid" => $data->itemid));
                $table = 'voiceshadow_comments';
            } else {
                $table = 'voiceshadow_files';
            }
            $student = $DB->get_record("user", array("id" => $item->userid));
            $context = get_context_instance(CONTEXT_MODULE, $item->instance);
            $fs = get_file_storage();
            $file_record = new stdClass();
            $file_record->component = 'mod_voiceshadow';
            $file_record->contextid = $context->id;
            $file_record->userid = $item->userid;
            $file_record->filearea = 'private';
            $file_record->filepath = "/";
            $file_record->itemid = $item->id;
            $file_record->license = $CFG->sitedefaultlicense;
            $file_record->author = fullname($student);
            $file_record->source = '';
            if (in_array($data->type, json_decode(VOICESHADOW_AUDIOTYPES))) {
                $from = voiceshadow_getfileid($data->itemid);
                $to = $CFG->dataroot . "/temp/" . $item->filename . ".mp3";
                voiceshadow_runExternal("/usr/local/bin/ffmpeg -y -i {$from->fullpatch} -acodec libmp3lame -ab 68k -ar 44100 {$to}", $code);
                $file_record->filename = $item->filename . ".mp3";
                $itemid = $fs->create_file_from_pathname($file_record, $to);
                $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $item->id));
                unlink($to);
            }
        }
    }
    return true;
}
コード例 #2
0
        error("Course module is incorrect");
    }
} else {
    if (!($voiceshadow = $DB->get_record("voiceshadow", array("id" => $a)))) {
        error("Course module is incorrect");
    }
    if (!($course = $DB->get_record("course", array("id" => $voiceshadow->course)))) {
        error("Course is misconfigured");
    }
    if (!($cm = get_coursemodule_from_instance("voiceshadow", $voiceshadow->id, $course->id))) {
        error("Course Module ID was incorrect");
    }
}
$name = "var{$var}";
$linktofile = $CFG->wwwroot . '/mod/voiceshadow/file.php?file=' . $voiceshadow->{$name};
$file = voiceshadow_getfileid($voiceshadow->{$name});
$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();
コード例 #3
0
ファイル: file.php プロジェクト: e-rasvet/voiceshadow
<?php

require_once "../../config.php";
require_once "lib.php";
$fileid = optional_param('file', NULL, PARAM_INT);
$file = voiceshadow_getfileid($fileid);
header("Content-type: audio/x-mpeg");
if (isset($_SERVER['HTTP_RANGE'])) {
    rangeDownload($file->fullpatch);
} else {
    header("Content-Length: " . filesize($file->fullpatch));
    readfile($file->fullpatch);
}