Beispiel #1
0
function ins_personal_media()
{
    if (!canAccessPersonalMedia()) {
        die("You can't access!");
    }
    include_once _base_ . '/lib/lib.upload.php';
    include_once _base_ . '/lib/lib.multimedia.php';
    $url = getPopupBaseUrl() . "&op=personal";
    $user_id = Docebo::user()->getIdSt();
    $is_streaming = FALSE;
    if (isset($_FILES["file"]["name"]) && !empty($_FILES["file"]["name"])) {
        $fname = $_FILES["file"]["name"];
        $size = $_FILES["file"]["size"];
        $tmp_fname = $_FILES["file"]["tmp_name"];
        $real_fname = $user_id . '_' . mt_rand(0, 100) . '_' . time() . '_' . $fname;
    } else {
        $media_url = $_POST["media_url"];
        $fname = "";
        $real_fname = "";
        if (!empty($media_url)) {
            $is_streaming = TRUE;
            if (isYouTube($media_url)) {
                $fname = str_replace("http://www.", "", strtolower($media_url));
            } else {
                $fname = basename($media_url);
                $fname = strpos($fname, "?") !== FALSE ? preg_replace("/(\\?.*)/", "", $fname) : $fname;
            }
        }
    }
    if (!$is_streaming) {
        $valid_ext = array("png", "mng", "gif", "jpg", "jpeg", "wmv", "flv", "mov", "mp3", "swf", "mp4");
        $ext = strtolower(end(explode(".", $fname)));
        if (!in_array($ext, $valid_ext)) {
            Util::jump_to($url . '&result=invalid_ext');
        }
        sl_open_fileoperations();
        $f1 = sl_upload($tmp_fname, _USER_FPATH_INTERNAL . $real_fname);
        sl_close_fileoperations();
        if (!$f1) {
            // upload error
            Util::jump_to($url . '&result=upload_err');
        }
    }
    $qtxt = "INSERT INTO " . $GLOBALS["prefix_fw"] . "_user_file ";
    $qtxt .= " ( user_idst, type, fname, real_fname, media_url, size, uldate ) VALUES ";
    $qtxt .= " ('" . $user_id . "', 'image', '" . $fname . "', '" . addslashes($real_fname) . "', '" . $media_url . "', '" . $size . "', NOW())";
    $q = sql_query($qtxt);
    Util::jump_to($url . '&result=' . ($q ? 'upload_ok' : 'upload_err'));
}
function getStreamingEmbed($url, $ext = FALSE, $filename = FALSE)
{
    $res = "";
    if (isYouTube($url)) {
        $video_id = getYouTubeId($url);
        $res = getYouTubeCode($video_id);
        return $res;
    }
    if ($ext === FALSE) {
        if ($filename === FALSE) {
            $filename = basename($url);
            $filename = strpos($filename, "?") !== FALSE ? preg_replace("/(\\?.*)/", "", $filename) : $filename;
        }
        $ext = end(explode(".", $filename));
    }
    switch ($ext) {
        case "flv":
            $res .= getDoceboFlashPlayer($url);
            break;
        case "swf":
            $res .= getFlashPluginCode($url);
            break;
        case "wmv":
            $res = "";
            $res .= '<object width="400px"  height="300px" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">';
            $res .= '<param name="filename" value="' . $url . '">';
            $res .= '<param name="Showcontrols" value="True">';
            $res .= '<param name="autostart" value="false">';
            $res .= '<embed type="application/x-mplayer2" src="' . $url . '"  height="300px" width="400px" autostart="false"></embed>';
            $res .= '</object>';
            return $res;
            break;
    }
    return $res;
}