Exemplo n.º 1
0
function flv_get_duration($url)
{
	global $flv_sitemap_options;
	
	$options = $flv_sitemap_options;

	// duration disallowed -> exit now!
	if (empty($options['allow_duration']))
		return false;
	
	// get site relative path without the first '/'
	$movie_path = substr(flv_make_relative($url),1);
	$server_path = $options['server_path'];
	$file = $server_path . $movie_path;
	
	// get contents of a file into a string
	if (file_exists($file)) {
		$handle = fopen($file, "r");
		$contents = fread($handle, filesize($file));
		fclose($handle);
        
		if (strlen($contents) > 3) {
			if (substr($contents,0,3) == "FLV") {
				$taglen = hexdec(bin2hex(substr($contents,strlen($contents)-3)));
				if (strlen($contents) > $taglen) {
					$duration = hexdec(bin2hex(substr($contents,strlen($contents)-$taglen,3)));
					return $duration;
				}
			}
		}
	}
	return false;
}
Exemplo n.º 2
0
function flv_sitemap_content()
{
	global $wpdb, $flv_sitemap_options, $flv_metakey;
	
	$options = $flv_sitemap_options;
	
	$allow_embed = ($options['allow_embed']) ? "Yes" : "No";
	$player = get_settings('siteurl') . '/wp-content/plugins/flv-embed/flvplayer.swf';
	
	if ($options['allow_thumbnail'])
		$xsl = get_settings('siteurl') . '/wp-content/plugins/flv-embed/sitemap.xsl';
	else
		$xsl = get_settings('siteurl') . '/wp-content/plugins/flv-embed/sitemap2.xsl';
	
	$xml_head = '<?xml version="1.0" encoding="UTF-8"?' . '>';
	$xml_head .= "\n" . '<?xml-stylesheet type="text/xsl" href="' . $xsl . '"?' . '>';
	
	ob_start();
	print <<< XML_HEAD
{$xml_head}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:video="http://www.google.com/schemas/sitemap-video/1.0">

XML_HEAD;

	// read flv custom fields from database
	$flvs = $wpdb->get_results("SELECT meta_value, id, post_title, post_content, post_excerpt
							FROM $wpdb->postmeta, $wpdb->posts
							WHERE meta_key = '$flv_metakey'
							AND post_id = id
							AND post_status = 'publish'
							ORDER BY post_date DESC");

	// if flv custom fields are found
	if (!empty($flvs)) {
		
		// process each flv found in custom fields
		foreach ($flvs as $flv) {
			$metavalue = $flv->meta_value;
			
			$input = explode("\n", $metavalue);
			$arg = count($input);
			
			// extract movie and poster information
			if ($arg == 1)
				$movie = $input[0];
			else if ($arg == 2)
				list($movie, $poster) = $input;
			else if ($arg == 3)
				list($movie, $poster, $duration) = $input;
			
			// attempt to shorten $movie URL with site relative path for player_loc
			$movie_url = flv_make_relative($movie);
			
			if (!empty($movie_url))
				$player_loc = $player . '?file=' . $movie_url;
			else
				$player_loc = $player . '?file=' . $movie;
			
			$loc = get_permalink($flv->id);
			$title = $flv->post_title;
			
			if (empty($flv->post_excerpt))
				$excerpt = flv_fake_excerpt($flv->post_content);
			else
				$excerpt = $flv->post_excerpt;
			
			// thumbnail
			if ($options['allow_thumbnail'])
				$thumbnail = "\n\t\t<video:thumbnail_loc>" . $poster . "</video:thumbnail_loc>";
			
			// duration
			if ($options['allow_duration']) {
				// convert millisecond to second
				$duration = round($duration / 1000);
				$duration = "\n\t\t<video:duration>" . $duration . "</video:duration>";
			}
			
			// family_friendly
			switch($options['family_safe']) {
				case "yes":
					$family_friendly = "Yes";
					break;
				case "no":
					$family_friendly = "No";
					break;
				case "not_sure":
					$family_friendly = "";
					break;
			}
			
			if (!empty($family_friendly)) {
				$family_friendly = "\n\t\t<video:family_friendly>" . $family_friendly . "</video:family_friendly>";
			}
		
			print <<< ITEM
<url>
	<loc>{$loc}</loc>
	<video:video>
		<video:content_loc>{$movie}</video:content_loc>
		<video:player_loc allow_embed="{$allow_embed}">{$player_loc}</video:player_loc>{$thumbnail}
		<video:title><![CDATA[{$title}]]></video:title>
		<video:description><![CDATA[{$excerpt}]]></video:description>{$family_friendly}{$duration}
	</video:video>
</url>

ITEM;
		}
	} else {
		$error = 'ERROR';
	}

	print <<< XML_FOOT
</urlset>

XML_FOOT;

	$output = ob_get_contents();
	ob_end_clean();
	
	// return error if no flv custom field found
	if ($error)
		return $error;
	else
		return $output;
}