Example #1
0
function select_media(&$out, &$lang)
{
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.multimedia.php';
    $form = new Form();
    $from = importVar("from");
    $item_id = (int) importVar("item_id");
    $src = "";
    $title = "";
    $path = "";
    switch ($from) {
        case "cms":
            if (!canAccessCmsMedia()) {
                die("You can't access!");
            }
            $path = _FPATH_INTERNAL;
            $relative_path = _FPATH;
            $preview_path = _PPATH;
            $qtxt = "SELECT t1.fname, t1.real_fname, t1.media_url, t2.title FROM " . $GLOBALS["prefix_cms"] . "_media as t1 ";
            $qtxt .= "LEFT JOIN " . $GLOBALS["prefix_cms"] . "_media_info as t2 ON (t2.idm=t1.idMedia) ";
            $qtxt .= "WHERE t1.idMedia='" . $item_id . "' AND t1.publish='1'";
            $q = sql_query($qtxt);
            if ($q && mysql_num_rows($q) > 0) {
                $row = mysql_fetch_array($q);
                $src = $row["real_fname"];
                $title = $row["title"];
                if (!empty($row["media_url"])) {
                    $src = $row["media_url"];
                } else {
                    $src = $row["real_fname"];
                }
            }
            break;
        case "personal":
            if (!canAccessPersonalMedia()) {
                die("You can't access!");
            }
            $user_id = Docebo::user()->getIdSt();
            $path = _USER_FPATH_INTERNAL;
            $relative_path = _USER_FPATH;
            $preview_path = _USER_FPATH;
            $qtxt = "SELECT real_fname, media_url FROM " . $GLOBALS["prefix_fw"] . "_user_file ";
            $qtxt .= "WHERE id='" . $item_id . "' AND user_idst='" . $user_id . "' AND type='image'";
            $q = sql_query($qtxt);
            if ($q && mysql_num_rows($q) > 0) {
                $row = mysql_fetch_array($q);
                if (!empty($row["media_url"])) {
                    $src = $row["media_url"];
                } else {
                    $src = $row["real_fname"];
                }
            }
            break;
    }
    //	$src=rawurlencode($src);
    $res = "";
    $url = getPopupBaseUrl() . "&op=main";
    if (!empty($row["media_url"])) {
        $media_url = $row["media_url"];
        $popup_file_path = $media_url;
    } else {
        $popup_file_path = $path . $src;
    }
    addMediaPopupJS($popup_file_path);
    // TODO: remove inline style
    if (file_exists($preview_path . $src)) {
        $style = "width: 100px; padding: 2px; border: 1px solid #AAAAAA; margin-bottom: 0.4em;";
        $res .= "<img style=\"" . $style . "\" src=\"" . $preview_path . $src . "\" alt=\"" . $title . "\" title=\"" . $title . "\" />\n";
    } else {
        $media_type = getMediaType($src);
        $style = "width: 64px; padding: 2px; border: 1px solid #AAAAAA; margin-bottom: 0.4em;";
        $res .= "<img style=\"" . $style . "\" src=\"" . getPathImage('fw') . "media/" . $media_type . ".png\" alt=\"" . $title . "\" title=\"" . $title . "\" />\n";
    }
    $res .= $form->openForm("popup_form", $url, false, false, '', "onSubmit=\"insItem();\" onReset=\"closePopup();\"");
    $res .= $form->openElementSpace();
    $type = getPopupSelType();
    switch ($type) {
        case "image":
            $res .= $form->getTextfield($lang->def("_ALT_TXT"), "alt_text", "alt_text", 255, $title);
            $res .= $form->getTextfield($lang->def("_TITLE"), "title_text", "title_text", 255, $title);
            //$res.=$form->getTextfield($lang->def("_BORDER"), "border", "border", 3, "0");
            break;
        case "flash":
            $flash_info = getSwfInfoArray($relative_path . $src);
            $res .= $form->getTextfield($lang->def("_WIDTH"), "width", "width", 4, $flash_info["width"]);
            $res .= $form->getTextfield($lang->def("_HEIGHT"), "height", "height", 4, $flash_info["height"]);
            $res .= $form->getTextfield($lang->def("_BGCOLOR"), "bgcolor", "border", 7, "#FFF");
            break;
        case "audio":
        case "video":
        case "streaming":
            require_once _base_ . '/lib/lib.json.php';
            $json = new Services_JSON();
            if (!empty($media_url)) {
                $code = getStreamingEmbed($media_url, FALSE, $src);
            } else {
                $cut_from = strlen($GLOBALS["where_files_relative"]);
                $base_relative_path = $GLOBALS["base_where_files_relative"] . substr($relative_path, $cut_from);
                $current_pl = Get::cur_plat();
                $site_file_path = getPLSetting($current_pl, "url") . $base_relative_path;
                $code = getEmbedPlay($site_file_path, $src, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE);
            }
            $code = '<div>' . $code . '</div>';
            $core_url = getPLSetting("framework", "url");
            $bad_path = $GLOBALS["where_framework_relative"] . "/addons/players/";
            $good_path = $core_url . "addons/players/";
            $code = str_replace($bad_path, $good_path, $code);
            $content = array("code" => $code);
            $embed_code = $json->encode($content);
            $res .= $form->getHidden("embed_code", "embed_code", rawurlencode($embed_code));
            $res .= $src;
            break;
    }
    $res .= $form->closeElementSpace();
    $res .= $form->openButtonSpace();
    $res .= $form->getButton('apply', 'apply', $lang->def('_SAVE'));
    $res .= $form->getReset('undo', 'undo', $lang->def('_UNDO'));
    $res .= $form->closeButtonSpace();
    $res .= $form->closeForm();
    $out->add($res);
}
Example #2
0
function getFlashPluginCode($src, $bgcolor = FALSE, $width = FALSE, $height = FALSE)
{
    $res = "";
    $flashvars = FALSE;
    $pos = strpos($src, "?");
    if ($pos !== FALSE) {
        $flashvars = substr($src, $pos + 1);
        $src = substr($src, 0, $pos);
    }
    $info = getSwfInfoArray($src);
    if ($info["error"] !== FALSE) {
        return "\n\n<!-- Swf Load Error: " . $info["error"] . " - File: " . $src . " -->\n\n";
    }
    $bg = $bgcolor !== FALSE ? $bgcolor : "#FFFFFF";
    $w = $width !== FALSE ? $width : $info["width"];
    $h = $height !== FALSE ? $height : $info["height"];
    if ($width !== false && $height === false) {
        $w = $width;
        $h = round($info["height"] / $info['width'] * $width);
    }
    if ($width === false && $height !== false) {
        $w = round($info["width"] / $info['height'] * $height);
        $h = $height;
    }
    $res .= '<object type="application/x-shockwave-flash" data="' . $src . '" width="' . $w . '" height="' . $h . '" align="middle">' . "\n";
    if ($flashvars !== FALSE && !empty($flashvars)) {
        $res .= '	<param name="flashvars" value="' . $flashvars . '" />' . "\n";
    }
    $res .= '	<param name="movie" value="' . $src . '" />' . "\n";
    $res .= '	<param name="bgcolor" value="' . $bg . '" />' . "\n";
    $res .= '	<param name="quality" value="high" />' . "\n";
    $res .= '	<param name="wmode" value="transparent">' . "\n";
    $res .= '</object>	' . "\n";
    // Commented code is not XHTML 1.1 compatible
    /* $res.='<embed src="'.$src.'" ';
    	$res.='quality="high" bgcolor="'.$bg.'" width="'.$w.'" height="'.$h.'" ';
    	$res.='align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" ';
    	$res.='pluginspage="http://www.macromedia.com/go/getflashplayer" />'; */
    return $res;
}