Example #1
0
/**
 * try to detect the source (service) and type of file/media content
 *
 * returns object with 2 properties
 *
 * !!! the same function in smarty/showReps.php
 */
function detectSourceAndType($url)
{
    $source = 'generic';
    $type = 'unknown';
    //1. detect source
    if (strpos($url, 'http://' . HEURIST_SERVER_NAME) == 0 && strpos($url, 'records/files/downloadFile.php') >= 0) {
        $source = 'heurist';
    } else {
        if (strpos($url, 'http://www.flickr.com') == 0) {
            $source = 'flickr';
            $type = 'image';
        } else {
            if (strpos($url, 'http://www.panoramio.com/') == 0) {
                $source = 'panoramio';
                $type = 'image';
            } else {
                if (preg_match('http://(www.)?locr\\.de|locr\\.com', $url)) {
                    $source = 'locr';
                    $type = 'image';
                    //}else if(link.indexOf('http://www.youtube.com/')==0 || link.indexOf('http://youtu.be/')==0){
                } else {
                    if (preg_match('http://(www.)?youtube|youtu\\.be', $url)) {
                        $source = 'youtube';
                        $type = 'video';
                    }
                }
            }
        }
    }
    if ($type == 'xml') {
        $extension = 'xml';
    } else {
        if ($type == 'unknown') {
            //try to detect type by extension and protocol
            //get extension from url - unreliable
            $extension = null;
            $ap = parse_url($url);
            if (array_key_exists('path', $ap)) {
                $path = $ap['path'];
                if ($path) {
                    $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
                }
            }
            $mimeType = findMimeType($extension);
            //from query
            if ($mimeType == '') {
                if (array_key_exists('query', $ap)) {
                    $path = $ap['query'];
                    if ($path) {
                        $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
                    }
                }
                $mimeType = findMimeType($extension);
            }
            //from
            if ($mimeType == '') {
                $extension = strtolower(pathinfo($url, PATHINFO_EXTENSION));
                $mimeType = findMimeType($extension);
            }
            $type = getMediaType($mimeType, $extension);
        }
    }
    return array($source, $type, $extension);
}
Example #2
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 #3
0
if (!empty($blogparams['metaformat'])) {
    $metaformat = $blogparams['metaformat'];
}
$imageW = $imgW = 350;
$imageH = $imgH = 225;
?>

<?php 
while (have_posts()) {
    the_post();
    $sourceData = get_post_meta($post->ID, "sourceData", true);
    $sourceOpen = get_post_meta($post->ID, "sourceOpen", true);
    $useResizer = get_post_meta($post->ID, "useResizer", true);
    $cropPos = get_post_meta($post->ID, "cropPos", true);
    $cropPos = $cropPos == '' ? 'c' : $cropPos;
    $sourceType = getMediaType($sourceData);
    $sourceStr = getSource($sourceData, $imgW, $imgH);
    ?>
	<div id="post-<?php 
    the_ID();
    ?>
"  <?php 
    post_class('blogitem');
    ?>
>
		<h3><?php 
    the_title();
    ?>
</h3>
		<?php 
    if (has_post_thumbnail() || !empty($sourceStr) && $sourceOpen == 'e') {
Example #4
0
function getSource($sourceData, $imageW, $imageH)
{
    if (!empty($sourceData)) {
        $embedCode = '';
        $sourceType = getMediaType(trim($sourceData));
        $mediaParams = getParamsFromUrl(trim($sourceData));
        if (empty($sourceType)) {
            return '';
        }
        if ($sourceType == 'vimeo') {
            $embedCode = '<iframe src="http://player.vimeo.com/video/' . $mediaParams['v'] . '?title=0&amp;byline=0&amp;portrait=0" width="' . $imageW . '" height="' . $imageH . '" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
        } elseif ($sourceType == 'youtube') {
            $embedCode = '<iframe width="' . $imageW . '" height="' . $imageH . '" src="http://www.youtube.com/embed/' . $mediaParams['v'] . '?wmode=transparent&rel=0" frameborder="0" allowfullscreen></iframe>';
        } elseif ($sourceType == 'jwplayer') {
            $rand = createRandomKey(5);
            $embedCode = '<div id="jwEP' . $rand . '" style="width:' . $imageW . 'px; height:' . $imageH . 'px;"></div>
							<script>
							jwplayer("jwEP' . $rand . '").setup({
								flashplayer: "' . get_template_directory_uri() . '/jwplayer/player.swf",
								autostart: false,
								skin: "' . get_template_directory_uri() . '/jwplayer/glow/glow.xml",
								file: "' . $mediaParams['vurl'] . '",
								height: ' . $imageH . ',
								width: ' . $imageW . '
								});
							</script>';
        } elseif ($sourceType == 'flash') {
            $rand = createRandomKey(5);
            $embedCode = '<div id="flashContent' . $rand . '">
								<p>You need to <a href="http://www.adobe.com/products/flashplayer/" target="_blank">upgrade your Flash Player</a> to version 10 or newer.</p>  
							</div>
							<script type="text/javascript">  
									var flashvars = {};  
									var attributes = {};  
									attributes.wmode = "transparent";
									attributes.play = "true";
									attributes.menu = "false";
									attributes.scale = "showall";
									attributes.wmode = "transparent";
									attributes.allowfullscreen = "true";
									attributes.allowscriptaccess = "always";
									attributes.allownetworking = "all";					
									swfobject.embedSWF("' . $mediaParams['vurl'] . '", "flashContent' . $rand . '", "' . $imageW . '", "' . $imageH . '", "10", "' . get_template_directory_uri() . '/js/expressInstall.swf", flashvars, attributes);  
							</script>';
        }
        return $embedCode;
    }
}
Example #5
0
/**
 * @param string 	$fname name of the file we want to check
 *
 * @return boolean FALSE if not a media; TRUE if valid media
 */
function isMedia($fname)
{
    $res = FALSE;
    if (getMediaType($fname) !== FALSE) {
        $res = TRUE;
    }
    return $res;
}
function sh_blog($attr, $content = null)
{
    global $paged, $wpdb, $more, $blogparams, $pageTitle;
    $blogparams = $attr;
    $cats = '';
    $postperpage = 10;
    $directlink = true;
    if ($blogparams['directlink'] == 'true') {
        $directlink = true;
    }
    if (!empty($blogparams['postperpage'])) {
        $postperpage = $blogparams['postperpage'];
    }
    if (!empty($blogparams['cats'])) {
        $cats = $blogparams['cats'];
    }
    $dataformat = 'd.m.Y';
    $metaformat = 'posted, comments, tag';
    $useImage = true;
    if (!empty($blogparams['dateformat'])) {
        $dataformat = $blogparams['dateformat'];
    }
    if (!empty($blogparams['metaformat'])) {
        $metaformat = $blogparams['metaformat'];
    }
    $imageW = $imgW = 350;
    $imageH = $imgH = 225;
    wp_reset_postdata();
    $the_query_arr = 'post_type=post&posts_per_page=' . $postperpage . '&cat=' . $cats . '&paged=' . $paged;
    $the_query = new WP_Query($the_query_arr);
    $re = '';
    while ($the_query->have_posts()) {
        $the_query->the_post();
        $sourceData = get_post_meta(get_the_ID(), "sourceData", true);
        $sourceOpen = get_post_meta(get_the_ID(), "sourceOpen", true);
        $useResizer = get_post_meta(get_the_ID(), "useResizer", true);
        $cropPos = get_post_meta(get_the_ID(), "cropPos", true);
        $cropPos = $cropPos == '' ? 'c' : $cropPos;
        $sourceType = getMediaType($sourceData);
        $sourceStr = getSource($sourceData, $imgW, $imgH);
        $blogClass = '';
        $blogClassArr = get_post_class(array('blogitem'), get_the_ID());
        foreach ($blogClassArr as $blogClassArrItem) {
            $blogClass .= $blogClassArrItem . ' ';
        }
        $re .= '<div id="post-' . get_the_ID() . '" class="' . $blogClass . '">
		<h3>' . get_the_title() . '</h3>';
        if (has_post_thumbnail() || !empty($sourceStr) && $sourceOpen == 'e') {
            $thumbnail_src = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
            if ($useResizer == 'use') {
                $thumbnail_url = get_template_directory_uri() . '/includes/timthumb.php?src=' . $thumbnail_src . '&h=' . $imageH . '&w=' . $imageW . '&zc=1&a=' . $cropPos . '&q=100';
            } else {
                $thumbnail_url = $thumbnail_src;
            }
            $useImage = true;
            $re .= '<div class="blogimage">
			<div class="image_frame">';
            if ($sourceOpen == 'm' || empty($sourceOpen) || empty($sourceData)) {
                if (!$directlink) {
                    $re .= '<a href="' . (empty($sourceData) ? $thumbnail_src : $sourceData) . '" title="' . get_the_title() . '">';
                } else {
                    $re .= '<a href="#!' . get_ajax_permalink() . '" title="' . get_the_title() . '">';
                }
                $re .= '<img ' . ($directlink ? 'class="nomodal"' : '') . ' src="' . $thumbnail_url . '" width="' . $imgW . '" height="' . $imgH . '" alt="' . get_the_title() . '" />

					<div class="hoverWrapperBg"></div>
					<div class="hoverWrapper">
						<span class="link" rel="#!' . get_ajax_permalink() . '"></span>';
                if (!$directlink) {
                    $modalClass = 'modal';
                    if ($sourceType == 'vimeo' || $sourceType == 'youtube' || $sourceType == 'jwplayer') {
                        $modalClass = 'modalVideo';
                    }
                    $re .= '<span class="' . $modalClass . '"></span>';
                }
                $re .= '</div>';
                $re .= '</a>';
            } elseif ($sourceOpen == 'e') {
                $re .= '<div style="position: relative; width:' . $imageW . 'px; height:' . $imageH . 'px; background-image: none; opacity: 1;">
					' . $sourceStr . '
				</div>';
            }
            $re .= '</div>
		</div>';
        } else {
            $useImage = false;
        }
        $re .= '<div class="blogcontent" ' . (!$useImage ? 'style="width:600px; margin-left:0"' : '') . '>
			<div class="blogdatemeta">';
        if ($dataformat != 'none') {
            $re .= '<div class="blogdate">' . get_the_time($dataformat) . '</div>';
        }
        if ($metaformat != 'none') {
            $re .= '<div class="meta-links">';
            if (strpos($metaformat, 'posted') !== false) {
                $re .= '<a class="meta-author" href="javascript:void(0);" rel="' . posted_on_template() . '"></a>';
            }
            if (strpos($metaformat, 'comments') !== false) {
                $commentCount = get_comments_number(get_the_ID());
                if ($commentCount == 0) {
                    $commentStr = __('No Comment', 'rb');
                } elseif ($commentCount == 1) {
                    $commentStr = __('1 Comment', 'rb');
                } else {
                    $commentStr = $commentCount . __('Comments', 'rb');
                }
                $re .= '<a class="meta-comments" href="javascript:void(0);" rel="' . $commentStr . '"></a>';
            }
            if (strpos($metaformat, 'tag') !== false) {
                $tags_list = wp_get_post_tags(get_the_ID(), array('fields' => 'names'));
                if ($tags_list) {
                    $re .= '<a class="meta-tags" href="javascript:void(0);" rel="' . implode(' ,', $tags_list) . '"></a>';
                }
            }
            $re .= '</div>';
        }
        $re .= '</div> 
			<p>';
        $more = 0;
        $re .= get_the_content('') . '
			</p>
			<a class="morelink" href="#!' . get_ajax_permalink() . '">' . __('READ MORE', 'rb') . '</a>
		</div>
		<hr class="seperator"/>
		<div class="clearfix"></div>
	</div>';
    }
    if (function_exists('wp_pagenavi')) {
        $re .= wp_pagenavi(array('query' => $the_query, 'options' => array('return_string' => true)));
    }
    wp_reset_postdata();
    $re .= '
	<div class="divider" style="height:10px"></div>
	<div class="clearfix"></div>';
    return $re;
}