Beispiel #1
0
function flv_add_meta($post_id) {
	global $wpdb, $flv_options, $flv_sitemap_options, $flv_metakey, $flv_metavalues;

	// jump out of function if sitemap feature is not enabled
	if (!$flv_options['sitemap']) {
		return $post_id;
	}

	$content = $wpdb->get_var("SELECT post_content
							FROM $wpdb->posts
							WHERE ID = '$post_id'");

	// parse post content for FLV embed tags
	$content = preg_replace_callback( "/\[flv:(([^]]+))]/i", "flv_gen_meta", $content );

	// process each metavalues
	foreach ($flv_metavalues as $metavalue) {
		// read flv custom fields from database for current post_id
		$flvs = $wpdb->get_results("SELECT meta_value, meta_id
								FROM $wpdb->postmeta
								WHERE post_id = '$post_id'
								AND meta_key = '$flv_metakey'");

		// status flag for database operations
		$update = 0;
		$delete = 0;
		$write = 1;

		// if flv custom field already exist, test its content and update the value with new flv path when applicable
		if (!empty($flvs)) {
			$del_metaids = array();		// array that stores flv to be deleted
			
			$input = explode("\n", $metavalue);
			$movie = $input[0];
			
			$file = basename($movie);
			
			// check to see if existing flv custom field can be updated
			foreach ($flvs as $flv) {
				if (stristr($flv->meta_value, $file)) {
					$metaid = $flv->meta_id;
					$update = 1;
				// check to see if existing meta is valid (i.e. flv url is not a dead link)
				} else  {
					$input_meta = explode("\n", $flv->meta_value);
					$url = $input_meta[0];
					
					$headers = wp_get_http_headers($url);
					$code = (int) $headers['response'];
					
					// client error
					if ($code >= 400 && $code < 500) {
						$delete = 1;
						array_push($del_metaids, $flv->meta_id);
					}
				}
			}
		}
		
		// disable custom field writing for YouTube links
		if (stristr($metavalue,"youtube.com")) {
			$write = 0;
		}
		
		// update existing flv custom field
		if ($update) {
			$results=  $wpdb->query("UPDATE $wpdb->postmeta
								SET meta_value = '$metavalue'
								WHERE post_id = '$post_id'
								AND meta_id = '$metaid'
								AND meta_key = '$flv_metakey'");
								
		// or write flv custom field to database
		} else if ($write) {
			$results = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value)
									VALUES ('$post_id', '$flv_metakey', '$metavalue')");
		}
		
		// delete dead flv
		if ($delete) {
			foreach ($del_metaids as $del_metaid) {
				$results=  $wpdb->query("DELETE FROM $wpdb->postmeta
									WHERE post_id = '$post_id'
									AND meta_id = '$del_metaid'
									AND meta_key = '$flv_metakey'");				
			}
		}
	}
	
	// check if flv embed tags are found within current post
	if (!empty($metavalue)) {
		// rebuild video sitemap if allowed
		if ($flv_sitemap_options['allow_auto']) {
			// get post status...
			$post_status = $wpdb->get_var("SELECT post_status
						FROM $wpdb->posts
						WHERE ID = '$post_id'");
			// only rebuild if post is already published
			if ($post_status == 'publish')
				flv_sitemap_build();
		}
	}
	
	// clear the array
	$flv_metavalues = array();
	
	return $post_id;
}
Beispiel #2
0
function flv_sitemap_options_panel()
{
	global $flv_sitemap_options;
	
	// test if options should be updated
	if (isset($_POST['options_update'])) {
		$options = explode(',', stripslashes($_POST['page_options']));
		
		if ($options) {
			// retrieve option values from POST variables
			foreach ($options as $option) {
				$option = trim($option);
				$value = trim(stripslashes($_POST[$option]));
				
				// update each sitemap option submitted through POST variables
				if ( ($option == 'server_path') && (!empty($value)) )
					$flv_sitemap_options[$option] = trailingslashit($value);	
				else if ( ($option != 'sitemap_name') || (($option == 'sitemap_name') && (!empty($value))) )
					$flv_sitemap_options[$option] = $value;
			}
			
			// update database option
			if (update_option("flv_sitemap_options", $flv_sitemap_options))
				echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
			else
				echo '<div id="message" class="updated fade"><p>No setting was changed since last update.</p></div>';
		} else {
			echo '<div id="message" class="error"><p>No setting value found!</p></div>';
		}
		
	} else if (isset($_POST['sitemap_build'])) {
		$result = flv_sitemap_build();
		
		list($error,$message) = $result;
		
		if (!$error) {
			echo '<div id="message" class="updated fade"><p>' . $message . '</p></div>';
		} else {
			echo '<div id="message" class="error"><p>' . $message . '</p></div>';
		}
		
	} else if (isset($_POST['update_custom_fields'])) {
		$success = flv_update_custom();
		
		if ($success) {
			echo '<div id="message" class="updated fade"><p>Successfully updated custom fields data!</p></div>';
		} else {
			echo '<div id="message" class="error"><p>Custom fields update failed!</p></div>';
		}
	
	} else if (isset($_POST['force_ping'])) {
		$last_ping = flv_ping_google(1);
		
		if ($last_ping == $flv_sitemap_options['last_ping']) {
			echo '<div id="message" class="error"><p>Pinging Google failed!</p></div>';
		} else {
			$flv_sitemap_options['last_ping'] = $last_ping;
			update_option("flv_sitemap_options", $flv_sitemap_options);
			echo '<div id="message" class="updated fade"><p>Google was successfully pinged!</p></div>';
		}
	}
	
	
	// settings used in admin panel
	$options = $flv_sitemap_options;
	$url = get_settings('siteurl') . '/';
	$sitemap = $url . $flv_sitemap_options['sitemap_name'];
	$path = ABSPATH;
	
	
	// checkbox value
	if ($options['allow_embed'])
		$allow_embed_check = 'checked="checked"';
	if ($options['allow_thumbnail'])
		$allow_thumbnail_check = 'checked="checked"';
	if ($options['allow_auto'])
		$allow_auto_check = 'checked="checked"';
	if ($options['allow_duration'])
		$allow_duration_check = 'checked="checked"';
	
	// select box value
	switch($options['family_safe']) {
		case "yes":
			$family_safe_yes = 'selected="selected"';
			break;
		case "no":
			$family_safe_no = 'selected="selected"';
			break;		
		case "not_sure":
			$family_safe_not_sure = 'selected="selected"';
			break;
	}	
	
	// last built
	if (!empty($options['last_built'])) {
		$built = $options['built'];
		//$last_built = date("F d, Y g:i a", $options['last_built']);
		$last_built = flv_time_since($options['last_built']);
		if ($built)
			$status = "Your <a href=\"$sitemap\" title=\"Video Sitemap\">video sitemap</a> was last successfully built $last_built ago.";
		else
			$status = "Your <a href=\"$sitemap\" title=\"Video Sitemap\">video sitemap</a> is <strong style='font-size: 1.2em'>not properly built</strong> and it was last modified $last_built ago.";
	} else {
		$status = "Your video sitemap was never successfully built.";
	}
	
	// last ping
	if (!empty($options['last_ping'])) {
		$last_ping= flv_time_since($options['last_ping']);
		$status .= " Google was last successfully pinged about your sitemap updates $last_ping ago.";
	} else {
		$status .= " Google was never successfully pinged about your sitemap updates.";
	}

print <<< ADMIN_PANEL
<div class="wrap">
	<h2>Video Sitemap Options</h2>
		<form method="post" id="flv_option">

		<h3>Video Sitemap Settings</h3>
			<p>If you see this page, it means sitemap feature is enabled for your <a href="./options-general.php?page=flv-embed.php">FLV Embed</a> plugin.</p>
			
			<table class="form-table">
				<tr>
					<th scope="row">Video sitemap filename</th>
					<td>
						{$url} <input name="sitemap_name" type="text" id="sitemap_name" class="code" value="{$options['sitemap_name']}" size="40" /><br />
						Make sure this file is writable on the server (chmod it "664" or "666")
					</td>
				</tr>
				<tr>
					<th scope="row">Settings</th>
					<td>
						<label for="allow_embed">
						<input name="allow_embed" type="checkbox" id="allow_embed" value="1" {$allow_embed_check} />
						Allow Google to embed your video in the search results on <code>http://video.google.com.</code>
						</label>

						<br />

						<label for="allow_thumbnail">
						<input name="allow_thumbnail" type="checkbox" id="allow_thumbnail" value="1" {$allow_thumbnail_check} />
						Use poster image as thumbnail where applicable. If disabled, Google will automatically generate a set of representative thumbnail images from your actual video content
						</label>

						<br />
						
						<label for="allow_auto">
						<input name="allow_auto" type="checkbox" id="allow_auto" value="1" {$allow_auto_check} />
						Allow FLV Embed to automatically generate new video sitemap everytime a published post with FLV embed tags is updated (may slow down save post process)
						</label>

						<br />
						
						<label for="allow_duration">
						<input name="allow_duration" type="checkbox" id="allow_duration" value="1" {$allow_duration_check} />
						Allow FLV Embed to detect duration of your FLV file when adding custom fields (requires server path below to be configured and may slow down save post process)
						</label>
					</td>
				</tr>
			</table>
			
			<p>For duration detection to work properly, FLV files must be hosted on the same server as your blog. Site relative path to the embedded FLV file will be appended to the server path below when trying to fetch the FLV for duration detection.</p>
			
			<table class="form-table">
				<tr>
					<th scope="row">Server path to site root</th>
					<td>
						<input name="server_path" type="text" id="server_path" class="code" value="{$options['server_path']}" size="40" /><br />
						Hint: server path to your blog root is <code>$path</code>
					</td>
				</tr>
				<tr>
					<th scope="row">Family safe content</th>
					<td>
						<select name="family_safe" id="family_safe">
						<option value="yes" {$family_safe_yes}>Yes</option>
						<option value="no" {$family_safe_no}>No</option>
						<option value="not_sure" {$family_safe_not_sure}>Not all</option>
						</select><br />
						Select "Not all" to disable <code>family_friendly</code> field for sitemap
					</td>
				</tr>
			</table>
		
			<p class="submit">
				<input type="submit" name="options_update" value="Save Changes" />
				<input type="hidden" name="page_options" value="sitemap_name,allow_embed,allow_thumbnail,allow_auto,allow_duration,server_path,family_safe" />
			</p>
		
		&nbsp;
		
		<h3>Build Video Sitemap</h3>
			<p>Clicking the build sitemap button will generate a new video sitemap. {$status}</p>
		
			<p class="submit">
				<input type="submit" name="force_ping" value="Force Ping Now " />
				<input type="submit" name="sitemap_build" value="Build Video Sitemap Now" />
			</p>
		
		&nbsp;
		
		<h3>Update Custom Fields</h3>
			<p>Clicking the following button will insert or update FLV custom field data for all published posts. It might take a while to complete depending on the amount of published posts so far. You should manually rebuild the sitemap once FLV custom fields are updated.</p>
		
			<p class="submit">
				<input type="submit" name="update_custom_fields" value="Update Custom Fields Now" />
			</p>
		
		</form>
</div>
ADMIN_PANEL;

}