Index: podpress_feed_functions.php
===================================================================
--- podpress_feed_functions.php	(Revision 195094)
+++ podpress_feed_functions.php	(Arbeitskopie)
@@ -19,17 +19,12 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-107  USA
 */
 	/*************************************************************/
-	/* feed generation functions                                 */
+	/* feed generation functions                                 		 */
 	/*************************************************************/
 	
 	function podPress_feedSafeContent($input, $aggressive = false) {
 		GLOBAL $podPress;
-		/*
-		// if the feed should not be protect agressively (option in the backend) then return immediately
-		if ( ('no' == strtolower($podPress->settings['protectFeed']) OR FALSE === $podPress->settings['protectFeed']) AND FALSE === $aggressive) {
-			return $input;
-		}
-		*/
+
 		// replace the relevant characters with their HTML entities
 		if (TRUE === $aggressive OR 'yes' == strtolower($podPress->settings['protectFeed']) OR TRUE === $podPress->settings['protectFeed'] ) { // this option is only reachable via php source code and via the WP backend
 			if (TRUE === version_compare(PHP_VERSION, '5.2.3', '>=')) {
@@ -152,49 +147,68 @@
 			$rss_category = $podPress->settings['rss_category'];
 		}
 		
-		$data['rss_ttl'] = get_option('rss_ttl');
-		if(!empty($data['rss_ttl']) && $data['rss_ttl'] < 1440) {
-			$data['rss_ttl'] = 1440;
-		}
 		echo '<!-- podcast_generator="podPress/'.PODPRESS_VERSION.'" - maintenance_release="'.PODPRESS_MAINTENANCE_VERSION.'" -->'."\n";
+		
 		if (empty($data['rss_copyright'])) {
 			echo '	<copyright>'.podPress_feedSafeContent(__('Copyright', 'podpress').' &#xA9; '. date('Y',time())).' '.get_bloginfo('blogname').' '.$podPress->settings['rss_license_url'].'</copyright>'."\n";
 		} else {
 			echo '	<copyright>'.podPress_feedSafeContent($data['rss_copyright']).' '.$podPress->settings['rss_license_url'].'</copyright>'."\n";
 		}
-		if($data['new-feed-url'] == 'Enable') {
-			if(!empty($data['podcastFeedURL']) && !strpos(strtolower($data['podcastFeedURL']), 'phobos.apple.com') && !strpos(strtolower($data['podcastFeedURL']), 'itpc://')) {
-				echo '		<itunes:new-feed-url>'.podPress_feedSafeContent($data['podcastFeedURL']).'</itunes:new-feed-url>'."\n";
+		
+		if (FALSE !== $data['admin_email'] AND FALSE === empty($data['admin_email'])) {
+			if ('' != trim($data['author'])) {
+				$admin_name = ' ('.podPress_feedSafeContent($data['author']).')';
+			} else {
+				$admin_name = '';
 			}
+			echo '	<managingEditor>'.podPress_feedSafeContent($data['admin_email']).$admin_name.'</managingEditor>'."\n";
+			echo '	<webMaster>'.podPress_feedSafeContent($data['admin_email']).$admin_name.'</webMaster>'."\n";
 		}
-		echo '	<managingEditor>'.podPress_feedSafeContent(stripslashes(get_option('admin_email'))).' ('.podPress_feedSafeContent($data['author']).')</managingEditor>'."\n";
-		echo '	<webMaster>'.podPress_feedSafeContent(get_option('admin_email')).' ('.podPress_feedSafeContent($data['author']).')</webMaster>'."\n";
+		
 		echo '	<category>'.podPress_feedSafeContent($rss_category).'</category>'."\n";
+		
+		$data['rss_ttl'] = get_option('rss_ttl');
+		if(!empty($data['rss_ttl']) && $data['rss_ttl'] < 1440) {
+			$data['rss_ttl'] = 1440;
+		}
 		if(!empty($data['rss_ttl'])) {
 			echo '	<ttl>'.$data['rss_ttl'].'</ttl>'."\n";
 		}
-		echo '	<itunes:keywords>'.podPress_stringLimiter(podPress_feedSafeContent($data['keywords']), 255).'</itunes:keywords>'."\n";
+		
+		if ('' != trim($data['rss_image'])) {
+			echo '	<image>'."\n";
+			echo '		<url>'.$data['rss_image'].'</url>'."\n";
+			echo '		<title>'.podPress_feedSafeContent(get_bloginfo('blogname')).'</title>'."\n";
+			echo '		<link>'.get_bloginfo('siteurl').'</link>'."\n";
+			echo '		<width>144</width>'."\n";
+			echo '		<height>144</height>'."\n";
+			echo '	</image>'."\n";
+		}
+		
+		// iTunes - tags for the channnel:
+		if($data['new-feed-url'] == 'Enable') {
+			if(!empty($data['podcastFeedURL']) && !strpos(strtolower($data['podcastFeedURL']), 'phobos.apple.com') && !strpos(strtolower($data['podcastFeedURL']), 'itpc://')) {
+				echo '		<itunes:new-feed-url>'.podPress_feedSafeContent($data['podcastFeedURL']).'</itunes:new-feed-url>'."\n";
+			}
+		}
 		echo '	<itunes:subtitle>'.podPress_stringLimiter(podPress_feedSafeContent($data['subtitle']), 255).'</itunes:subtitle>'."\n";
 		echo '	<itunes:summary>'.podPress_stringLimiter(podPress_feedSafeContent($data['summary']), 4000).'</itunes:summary>'."\n";
+		echo '	<itunes:keywords>'.podPress_stringLimiter(podPress_feedSafeContent($data['keywords']), 255).'</itunes:keywords>'."\n";
+		echo podPress_getiTunesCategoryTags();
 		echo '	<itunes:author>'.podPress_feedSafeContent($data['author']).'</itunes:author>'."\n";
-		echo podPress_getiTunesCategoryTags();
 		echo '	<itunes:owner>'."\n";
 		echo '		<itunes:name>'.stripslashes(podPress_feedSafeContent($data['author'])).'</itunes:name>'."\n";
 		echo '		<itunes:email>'.podPress_feedSafeContent($data['admin_email']).'</itunes:email>'."\n";
 		echo '	</itunes:owner>'."\n";
-		if(empty($data['block'])) {
-			$data['block'] = 'No';
+		if ('yes' == strtolower($data['block']) OR 'no' == strtolower($data['block'])) {
+			echo '	<itunes:block>'.strtolower($data['block']).'</itunes:block>'."\n";
+		} else {
+			echo '	<itunes:block>no</itunes:block>'."\n";
 		}
-		echo '	<itunes:block>'.$data['block'].'</itunes:block>'."\n";
 		echo '	<itunes:explicit>'.podPress_feedSafeContent(strtolower($data['explicit'])).'</itunes:explicit>'."\n";
-		echo '	<itunes:image href="'.$data['image'].'" />'."\n";
-		echo '	<image>'."\n";
-		echo '		<url>'.$data['rss_image'].'</url>'."\n";
-		echo '		<title>'.podPress_feedSafeContent(get_bloginfo('blogname')).'</title>'."\n";
-		echo '		<link>'.get_bloginfo('siteurl').'</link>'."\n";
-		echo '		<width>144</width>'."\n";
-		echo '		<height>144</height>'."\n";
-		echo '	</image>'."\n";
+		if ('' != trim($data['image'])) {
+			echo '	<itunes:image href="'.$data['image'].'" />'."\n";
+		}
 	}
 
 	function podPress_rss2_item() {
@@ -253,38 +267,35 @@
 			}
 			echo '		<itunes:author>'.podPress_feedSafeContent($post->podPressPostSpecific['itunes:author']).'</itunes:author>'."\n";
 
-			if($post->podPressPostSpecific['itunes:explicit'] == 'Default') {
+			if ($post->podPressPostSpecific['itunes:explicit'] == 'Default') {
 				$post->podPressPostSpecific['itunes:explicit'] = $podPress->settings['iTunes']['explicit'];
-				if(empty($post->podPressPostSpecific['itunes:explicit'])) {
-					$post->podPressPostSpecific['itunes:explicit'] = 'No';
-				}
 			}
+			if ( '' == trim($post->podPressPostSpecific['itunes:explicit']) OR ('' != trim($post->podPressPostSpecific['itunes:explicit']) AND 'no' != strtolower($post->podPressPostSpecific['itunes:explicit']) AND 'yes' != strtolower($post->podPressPostSpecific['itunes:explicit']) AND 'clean' != strtolower($post->podPressPostSpecific['itunes:explicit'])) ) {
+				$post->podPressPostSpecific['itunes:explicit'] = 'No';
+			}
 			echo '		<itunes:explicit>'.podPress_feedSafeContent(strtolower($post->podPressPostSpecific['itunes:explicit'])).'</itunes:explicit>'."\n";
 
-			if($post->podPressPostSpecific['itunes:block'] == 'Default') {
+			if ($post->podPressPostSpecific['itunes:block'] == 'Default') {
 				$post->podPressPostSpecific['itunes:block'] = $podPress->settings['iTunes']['block'];
-				if(empty($post->podPressPostSpecific['itunes:block'])) {
-					$post->podPressPostSpecific['itunes:block'] = 'No';
-				}
 			}
-			if(empty($post->podPressPostSpecific['itunes:block'])) {
+			if ( '' == trim($post->podPressPostSpecific['itunes:block']) OR ('' != trim($post->podPressPostSpecific['itunes:block']) AND 'no' != strtolower($post->podPressPostSpecific['itunes:block']) AND 'yes' != strtolower($post->podPressPostSpecific['itunes:block'])) ) {
 				$post->podPressPostSpecific['itunes:block'] = 'No';
 			}
-			echo '		<itunes:block>'.podPress_feedSafeContent($post->podPressPostSpecific['itunes:block']).'</itunes:block>'."\n";
+			echo '		<itunes:block>'.podPress_feedSafeContent(strtolower($post->podPressPostSpecific['itunes:block'])).'</itunes:block>'."\n";
 			//echo '<comments>'. get_comments_link() .'</comments>'."\n";
+			
+			$episodeLicenseTags = podPress_getEpisodeLicenseTags();
+			if ($episodeLicenseTags != '')
+			{
+				echo $episodeLicenseTags;
+			}
 		}
-		$episodeLicenseTags = podPress_getEpisodeLicenseTags();
-		if ($episodeLicenseTags != '')
-		{
-			echo $episodeLicenseTags;
-		}
-		if(isset($post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold'])) {
+		if (isset($post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold'])) {
 			$post_meta_cache[$blog_id][$post->ID]['enclosure'] = $post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold'];
 			unset($post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold']);
 		}
 	}
 
-
 	function podPress_atom_head() {
 		GLOBAL $podPress;
 		if(!isset($podPress->settings['category_data'])) {
@@ -308,15 +319,14 @@
 
 	function podPress_atom_entry() {
 		$enclosureTag = podPress_getEnclosureTags('atom');
-		if ($enclosureTag != '') // if no enclosure tag, no need for iTunes tags
-		{
+		if ($enclosureTag != '') { // if no enclosure tag, no need for iTunes tags
 			echo $enclosureTag;
+			
+			$episodeLicenseTags = podPress_getEpisodeLicenseTags('atom');
+			if ($episodeLicenseTags != '')	{
+				echo $episodeLicenseTags;
+			}
 		}
-		$episodeLicenseTags = podPress_getEpisodeLicenseTags('atom');
-		if ($episodeLicenseTags != '')
-		{
-			echo $episodeLicenseTags;
-		}
 	}
 
 	function podPress_xspf_playlist() {
@@ -525,96 +535,100 @@
 		return $exists;
 	}
 
-function podpress_strtomilliseconds($durationstr) {
-	$dstr_parts=explode(':', $durationstr);
-	$nr_dstr_parts=count($dstr_parts);
-	if (1 < $nr_dstr_parts AND 5 > $nr_dstr_parts) {
-		switch ($nr_dstr_parts) {
-			case 2 :
-				// this method is only good if the input data which consist of two parts is most likely in the format m:s because 
-				// m:s
-				$duration = podpress_strtomilliseconds_core(1, 2, $dstr_parts);
-				if ($durationstr != podpress_millisecondstostring($duration)) {
-					// h:m
-					$duration = podpress_strtomilliseconds_core(0, 2, $dstr_parts);
+	function podpress_strtomilliseconds($durationstr) {
+		// This function converts a string which is parted by at least one double point into a milliseconds value.
+		// Because there different possible combinations of the given time string the function tries to find out what was given to it by using the inverse function.
+		// But because the uncertainty of the nature of the input value the methods of this function are certainly not bullet prove if the input value is a duration string with a milliseconds value and less than 3 parts.
+		// Better ideas are welcome! Write a ticket http://plugins.trac.wordpress.org/ or post to the forum: http://wordpress.org/support/forum/10
+		$dstr_parts=explode(':', $durationstr);
+		$nr_dstr_parts=count($dstr_parts);
+		if (1 < $nr_dstr_parts AND 5 > $nr_dstr_parts) {
+			switch ($nr_dstr_parts) {
+				case 2 :
+					// this method is only good if the input data which consist of two parts is most likely in the format m:s because 
+					// m:s
+					$duration = podpress_strtomilliseconds_core(1, 2, $dstr_parts);
 					if ($durationstr != podpress_millisecondstostring($duration)) {
-						// s:ms
-						$duration = podpress_strtomilliseconds_core(2, 2, $dstr_parts);
+						// h:m
+						$duration = podpress_strtomilliseconds_core(0, 2, $dstr_parts);
+						if ($durationstr != podpress_millisecondstostring($duration)) {
+							// s:ms
+							$duration = podpress_strtomilliseconds_core(2, 2, $dstr_parts);
+						}
 					}
-				}
-			break;
-			case 3 :
-				// h:m:s
-				$duration = podpress_strtomilliseconds_core(0, 3, $dstr_parts);
-				if ($durationstr != podpress_millisecondstostring($duration)) {
-					// m:s:ms
-					$duration = podpress_strtomilliseconds_core(1, 3, $dstr_parts);
-				}
-			break;
-			case 4 :
-				$duration = podpress_strtomilliseconds_core(0, 4, $dstr_parts);
-			break;
-		}
-	}
-	if (!isset($duration) OR $duration < 0) {
-		$duration = 0;
-	}
-	return $duration;
-}
-
-function podpress_strtomilliseconds_core($startindex=0, $max_nr_parts=4, $dstr_parts=array()){
-	$duration = $j = 0;
-	if (!empty($dstr_parts)) {
-		for ($i=$startindex; $i < ($max_nr_parts+$startindex); $i++) {
-			switch ($i) {
-				case 0 : // hours
-					$duration += 3600000 * intval(substr($dstr_parts[$j], 0, 2));
-					$j++;
 				break;
-				case 1 : // minutes
-					$duration += 60000 * intval(substr($dstr_parts[$j], 0, 2));
-					$j++;
+				case 3 :
+					// h:m:s
+					$duration = podpress_strtomilliseconds_core(0, 3, $dstr_parts);
+					if ($durationstr != podpress_millisecondstostring($duration)) {
+						// m:s:ms
+						$duration = podpress_strtomilliseconds_core(1, 3, $dstr_parts);
+					}
 				break;
-				case 2 : // seconds
-					$duration += 1000 * intval(substr($dstr_parts[$j], 0, 2));
-					$j++;
+				case 4 :
+					$duration = podpress_strtomilliseconds_core(0, 4, $dstr_parts);
 				break;
-				case 3 : // milliseconds
-					$duration += intval(substr($dstr_parts[$j], 0, 2));
-					$j++;
-				break;
 			}
 		}
+		if (!isset($duration) OR $duration < 0) {
+			$duration = 0;
+		}
+		return $duration;
 	}
-	return $duration;
-}
 
-function podpress_millisecondstostring($duration) {
-// This function gives the milliseconds value back in the format H:M:S:MS or if the H:M:S if the milliseconds part is zero.
-// If the leading parts is zero then the return string will not contain this part.
-	$hours = intval($duration / (3600000));
-	$minutes = intval($duration / (60000) % 60);
-	$seconds = intval($duration / (1000) % 60);
-	$mseconds = intval($duration % 1000);
-	$duration_array = array($hours, $minutes, $seconds, $mseconds);
-	$dur_str ="";
-	$j=0;
-	foreach($duration_array as $key => $dur_part) {
-		if ("" == $dur_str AND 0 == $dur_part) {
-		} else {
-			if (3 == $key AND  0 == $dur_part) {
+	function podpress_strtomilliseconds_core($startindex=0, $max_nr_parts=4, $dstr_parts=array()){
+		$duration = $j = 0;
+		if (!empty($dstr_parts)) {
+			for ($i=$startindex; $i < ($max_nr_parts+$startindex); $i++) {
+				switch ($i) {
+					case 0 : // hours
+						$duration += 3600000 * intval(substr($dstr_parts[$j], 0, 2));
+						$j++;
+					break;
+					case 1 : // minutes
+						$duration += 60000 * intval(substr($dstr_parts[$j], 0, 2));
+						$j++;
+					break;
+					case 2 : // seconds
+						$duration += 1000 * intval(substr($dstr_parts[$j], 0, 2));
+						$j++;
+					break;
+					case 3 : // milliseconds
+						$duration += intval(substr($dstr_parts[$j], 0, 2));
+						$j++;
+					break;
+				}
+			}
+		}
+		return $duration;
+	}
+
+	function podpress_millisecondstostring($duration) {
+		// This function gives the milliseconds value back in the format H:M:S:MS or if the H:M:S if the milliseconds part is zero.
+		// If the leading parts is zero then the return string will not contain this part.
+		$hours = intval($duration / (3600000));
+		$minutes = intval($duration / (60000) % 60);
+		$seconds = intval($duration / (1000) % 60);
+		$mseconds = intval($duration % 1000);
+		$duration_array = array($hours, $minutes, $seconds, $mseconds);
+		$dur_str ="";
+		$j=0;
+		foreach($duration_array as $key => $dur_part) {
+			if ("" == $dur_str AND 0 == $dur_part) {
 			} else {
-				if ($j > 0) { 
-					$dur_str .= ":".strval($dur_part);
+				if (3 == $key AND  0 == $dur_part) {
 				} else {
-					$dur_str .= strval($dur_part);
+					if ($j > 0) { 
+						$dur_str .= ":".strval($dur_part);
+					} else {
+						$dur_str .= strval($dur_part);
+					}
+					$j++;
 				}
-				$j++;
 			}
 		}
+		return $dur_str;
 	}
-	return $dur_str;
-}
 
 	function podPress_getiTunesCategoryTags() {
 		GLOBAL $podPress, $post;

