Пример #1
0
function videoboard_cron()
{
    global $DB, $CFG;
    if ($data = $DB->get_record_sql("SELECT * FROM {videoboard_process} WHERE `status`='open' LIMIT 1")) {
        $CFG->videoboard_convert = 0;
        if (in_array($data->type, json_decode(VIDEOBOARD_VIDEOTYPES))) {
            $CFG->videoboard_convert = $CFG->videoboard_video_convert;
        } else {
            if (in_array($data->type, json_decode(VIDEOBOARD_AUDIOTYPES))) {
                $CFG->videoboard_convert = $CFG->videoboard_audio_convert;
            }
        }
        //Check converting method local or mserver
        if ($CFG->videoboard_convert == 1) {
            if (strstr($CFG->videoboard_convert_url, "ffmpeg")) {
                $CFG->videoboard_convert = 2;
            }
        }
        //local
        if ($CFG->videoboard_convert == 1) {
            $from = videoboard_getfileid($data->itemid);
            $add = new stdClass();
            $add->id = $data->id;
            $add->status = 'send';
            $DB->update_record("videoboard_process", $add);
            $ch = curl_init();
            if (in_array($data->type, json_decode(VIDEOBOARD_AUDIOTYPES))) {
                $datasend = array('name' => $data->name, 'mconverter_wav' => '@' . $from->fullpatch);
            }
            if (in_array($data->type, json_decode(VIDEOBOARD_VIDEOTYPES))) {
                $datasend = array('name' => $data->name, 'mconverter_m4a' => '@' . $from->fullpatch);
            }
            curl_setopt($ch, CURLOPT_URL, $CFG->videoboard_convert_url . '/send.php');
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $datasend);
            curl_exec($ch);
        } else {
            if ($CFG->videoboard_convert == 3) {
                $from = videoboard_getfileid($data->itemid);
                $add = new stdClass();
                $add->id = $data->id;
                $add->status = 'send';
                $DB->update_record("videoboard_process", $add);
                if (in_array($data->type, json_decode(VIDEOBOARD_VIDEOTYPES))) {
                    if ($item = $DB->get_record("videoboard_files", array("itemoldid" => $data->itemid))) {
                        $table = 'videoboard_files';
                    } else {
                        if ($item = $DB->get_record("videoboard_comments", array("itemoldid" => $data->itemid))) {
                            $table = 'videoboard_comments';
                        }
                    }
                    @set_include_path($CFG->dirroot . '/mod/videoboard/library');
                    require_once "Zend/Gdata/ClientLogin.php";
                    require_once "Zend/Gdata/HttpClient.php";
                    require_once "Zend/Gdata/YouTube.php";
                    require_once "Zend/Gdata/App/HttpException.php";
                    require_once 'Zend/Uri/Http.php';
                    $authenticationURL = 'https://www.google.com/youtube/accounts/ClientLogin';
                    $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = $CFG->videoboard_youtube_email, $password = $CFG->videoboard_youtube_password, $service = 'youtube', $client = null, $source = 'VideoBoard', $loginToken = null, $loginCaptcha = null, $authenticationURL);
                    $yt = new Zend_Gdata_YouTube($httpClient, 'VideoBoard', NULL, $CFG->videoboard_youtube_apikey);
                    $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
                    /// unlisted upload
                    $accessControlElement = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
                    $accessControlElement->extensionAttributes = array(array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'), array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied'));
                    $myVideoEntry->extensionElements = array($accessControlElement);
                    $filesource = $yt->newMediaFileSource($from->fullpatch);
                    $filesource->setContentType($data->type);
                    $filesource->setSlug('slug');
                    $myVideoEntry->setMediaSource($filesource);
                    $myVideoEntry->setVideoTitle($from->author);
                    $myVideoEntry->setVideoDescription($from->author);
                    $myVideoEntry->setVideoCategory('Education');
                    $myVideoEntry->SetVideoTags('videoboard');
                    //$myVideoEntry->setVideoDeveloperTags(array($item->id));
                    //$yt->registerPackage('Zend_Gdata_Geo');
                    //$yt->registerPackage('Zend_Gdata_Geo_Extension');
                    //$where = $yt->newGeoRssWhere();
                    //$position = $yt->newGmlPos('37.0 -122.0');
                    //$where->point = $yt->newGmlPoint($position);
                    //$myVideoEntry->setWhere($where);
                    $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
                    try {
                        $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
                    } catch (Zend_Gdata_App_HttpException $httpException) {
                        echo $httpException->getRawResponseBody();
                        $DB->delete_records('videoboard_process', array('id' => $data->id));
                    } catch (Zend_Gdata_App_Exception $e) {
                        echo $e->getMessage();
                        $DB->delete_records('videoboard_process', array('id' => $data->id));
                    }
                    $itemidyoutube = $newEntry->getVideoId();
                    if (!empty($itemidyoutube)) {
                        $DB->set_field($table, "itemyoutube", $itemidyoutube, array("id" => $item->id));
                    }
                    $DB->delete_records('videoboard_process', array('id' => $data->id));
                } else {
                    $DB->delete_records('videoboard_process', array('id' => $data->id));
                }
            } else {
                if ($CFG->videoboard_convert == 2) {
                    ///Old method
                    $DB->delete_records('videoboard_process', array('id' => $data->id));
                    if (!($item = $DB->get_record("videoboard_files", array("itemoldid" => $data->itemid)))) {
                        $item = $DB->get_record("videoboard_comments", array("itemoldid" => $data->itemid));
                        $table = 'videoboard_comments';
                    } else {
                        $table = 'videoboard_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_videoboard';
                    $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(VIDEOBOARD_VIDEOTYPES))) {
                        $from = videoboard_getfileid($data->itemid);
                        $to = $CFG->dataroot . "/temp/" . $item->filename . ".mp4";
                        $toimg = $CFG->dataroot . "/temp/" . $item->filename . ".jpg";
                        videoboard_runExternal("/opt/handbrake/HandBrakeCLI -Z Universal -i {$from->fullpatch} -o {$to} -w 432 -l 320", $code);
                        videoboard_runExternal("{$CFG->videoboard_convert_url} -i {$to} -f image2 -s 432x320 {$toimg}", $code);
                        $file_record->filename = $item->filename . ".mp4";
                        $itemid = $fs->create_file_from_pathname($file_record, $to);
                        $file_record->filename = $item->filename . ".jpg";
                        $itemimgid = $fs->create_file_from_pathname($file_record, $toimg);
                        $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $item->id));
                        $DB->set_field($table, "itemimgid", $itemimgid->get_id(), array("id" => $item->id));
                        unlink($to);
                        unlink($toimg);
                    } else {
                        if (in_array($data->type, json_decode(VIDEOBOARD_AUDIOTYPES))) {
                            $from = videoboard_getfileid($data->itemid);
                            $to = $CFG->dataroot . "/temp/" . $item->filename . ".mp3";
                            videoboard_runExternal("{$CFG->videoboard_convert_url} -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);
                        }
                    }
                }
            }
        }
    }
    ///Check convert server file ready
    if ($dataall = $DB->get_records_sql("SELECT * FROM {videoboard_process} WHERE `status` = 'send'")) {
        foreach ($dataall as $data) {
            if (!($item = $DB->get_record("videoboard_files", array("itemoldid" => $data->itemid)))) {
                if (!($item = $DB->get_record("videoboard_comments", array("itemoldid" => $data->itemid)))) {
                    if ($videoboard = $DB->get_record("videoboard", array("fileid" => $data->itemid))) {
                        $module = $DB->get_record("modules", array("name" => "videoboard"));
                        $instance = $DB->get_record("course_modules", array("module" => $module->id, "instance" => $videoboard->id));
                        $item = new stdClass();
                        $item->userid = $videoboard->teacher;
                        $item->instance = $instance->id;
                        $item->id = $videoboard->id;
                        $item->filename = "videoboard_" . $videoboard->id;
                        $table = 'videoboard';
                    } else {
                        $DB->delete_records('videoboard_process', array('id' => $data->id));
                        return true;
                    }
                } else {
                    $table = 'videoboard_comments';
                }
            } else {
                $table = 'videoboard_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_videoboard';
            $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(VIDEOBOARD_VIDEOTYPES)) && $CFG->videoboard_video_convert == 1) {
                $json = json_decode(file_get_contents($CFG->videoboard_convert_url . "/get.php?name={$data->name}.mp4"));
                $jsonimg = json_decode(file_get_contents($CFG->videoboard_convert_url . "/get.php?name={$data->name}.jpg"));
            } else {
                if ($CFG->videoboard_audio_convert == 1) {
                    $json = json_decode(file_get_contents($CFG->videoboard_convert_url . "/get.php?name={$data->name}.mp3"));
                }
            }
            if (@(!empty($json->url))) {
                $DB->delete_records('videoboard_process', array('id' => $data->id));
                if (in_array($data->type, json_decode(VIDEOBOARD_VIDEOTYPES))) {
                    $to = $CFG->dataroot . "/temp/" . $item->filename . ".mp4";
                    file_put_contents($to, file_get_contents($json->url));
                    $file_record->filename = $item->filename . ".mp4";
                    $itemid = $fs->create_file_from_pathname($file_record, $to);
                    $file = videoboard_getfileid($itemid->get_id());
                    @chmod($file->fullpatch, 0755);
                    $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $item->id));
                    $toimg = $CFG->dataroot . "/temp/" . $item->filename . ".jpg";
                    file_put_contents($toimg, file_get_contents($jsonimg->url));
                    $file_record->filename = $item->filename . ".jpg";
                    $itemid = $fs->create_file_from_pathname($file_record, $toimg);
                    $file = videoboard_getfileid($itemid->get_id());
                    @chmod($file->fullpatch, 0755);
                    $DB->set_field($table, "itemimgid", $itemid->get_id(), array("id" => $item->id));
                } else {
                    $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 = videoboard_getfileid($itemid->get_id());
                    @chmod($file->fullpatch, 0755);
                    $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $item->id));
                }
                unlink($to);
                @unlink($toimg);
                break;
            }
        }
    }
    return true;
}
Пример #2
0
 $data->userid = $USER->id;
 $data->summary = $summary;
 $data->filename = $filename;
 $data->fileid = $fileid;
 $data->time = time();
 if (!empty($submitfile)) {
     if ($file = videoboard_getfile($submitfile)) {
         $data->itemoldid = $file->id;
         ///Update submited file params
         $DB->execute("UPDATE {files} \nSET `contextid`={$context->id}, \n`component`='mod_videoboard', \n`filearea`='private', \n`itemid`={$unicalid}\nWHERE  `component` LIKE  'user'\nAND  `filearea` LIKE  'draft'\nAND  `itemid` ={$submitfile}");
         ///No convert
         if ($file->mimetype == "audio/mp3") {
             $data->itemid = $file->id;
         }
     } else {
         if ($file = videoboard_getfileid($submitfile)) {
             $data->itemoldid = $file->id;
         }
     }
     if (!empty($data->itemoldid) && empty($data->itemid)) {
         $add = new stdClass();
         $add->itemid = $file->id;
         $add->type = $file->mimetype;
         $add->status = 'open';
         $add->name = md5($CFG->wwwroot . '_' . time());
         $add->time = time();
         $DB->insert_record("videoboard_process", $add);
     }
 }
 if (!empty($commentid)) {
     $data->id = $commentid;
Пример #3
0
<?php

require_once "../../config.php";
require_once "lib.php";
$fileid = optional_param('file', NULL, PARAM_INT);
$file = videoboard_getfileid($fileid);
header("Content-type: audio/x-mpeg");
if (isset($_SERVER['HTTP_RANGE'])) {
    videoboard_rangeDownload($file->fullpatch);
} else {
    header("Content-Length: " . filesize($file->fullpatch));
    readfile($file->fullpatch);
}
Пример #4
0
    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();