Ticket #1074: podpress_feed_functions_885b3.2.diff
| File podpress_feed_functions_885b3.2.diff, 16.5 KB (added by ntm, 2 years ago) |
|---|
-
podpress_feed_functions.php
19 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-107 USA 20 20 */ 21 21 /*************************************************************/ 22 /* feed generation functions */22 /* feed generation functions */ 23 23 /*************************************************************/ 24 24 25 25 function podPress_feedSafeContent($input, $aggressive = false) { 26 26 GLOBAL $podPress; 27 /* 28 // if the feed should not be protect agressively (option in the backend) then return immediately 29 if ( ('no' == strtolower($podPress->settings['protectFeed']) OR FALSE === $podPress->settings['protectFeed']) AND FALSE === $aggressive) { 30 return $input; 31 } 32 */ 27 33 28 // replace the relevant characters with their HTML entities 34 29 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 35 30 if (TRUE === version_compare(PHP_VERSION, '5.2.3', '>=')) { … … 152 147 $rss_category = $podPress->settings['rss_category']; 153 148 } 154 149 155 $data['rss_ttl'] = get_option('rss_ttl');156 if(!empty($data['rss_ttl']) && $data['rss_ttl'] < 1440) {157 $data['rss_ttl'] = 1440;158 }159 150 echo '<!-- podcast_generator="podPress/'.PODPRESS_VERSION.'" - maintenance_release="'.PODPRESS_MAINTENANCE_VERSION.'" -->'."\n"; 151 160 152 if (empty($data['rss_copyright'])) { 161 153 echo ' <copyright>'.podPress_feedSafeContent(__('Copyright', 'podpress').' © '. date('Y',time())).' '.get_bloginfo('blogname').' '.$podPress->settings['rss_license_url'].'</copyright>'."\n"; 162 154 } else { 163 155 echo ' <copyright>'.podPress_feedSafeContent($data['rss_copyright']).' '.$podPress->settings['rss_license_url'].'</copyright>'."\n"; 164 156 } 165 if($data['new-feed-url'] == 'Enable') { 166 if(!empty($data['podcastFeedURL']) && !strpos(strtolower($data['podcastFeedURL']), 'phobos.apple.com') && !strpos(strtolower($data['podcastFeedURL']), 'itpc://')) { 167 echo ' <itunes:new-feed-url>'.podPress_feedSafeContent($data['podcastFeedURL']).'</itunes:new-feed-url>'."\n"; 157 158 if (FALSE !== $data['admin_email'] AND FALSE === empty($data['admin_email'])) { 159 if ('' != trim($data['author'])) { 160 $admin_name = ' ('.podPress_feedSafeContent($data['author']).')'; 161 } else { 162 $admin_name = ''; 168 163 } 164 echo ' <managingEditor>'.podPress_feedSafeContent($data['admin_email']).$admin_name.'</managingEditor>'."\n"; 165 echo ' <webMaster>'.podPress_feedSafeContent($data['admin_email']).$admin_name.'</webMaster>'."\n"; 169 166 } 170 echo ' <managingEditor>'.podPress_feedSafeContent(stripslashes(get_option('admin_email'))).' ('.podPress_feedSafeContent($data['author']).')</managingEditor>'."\n"; 171 echo ' <webMaster>'.podPress_feedSafeContent(get_option('admin_email')).' ('.podPress_feedSafeContent($data['author']).')</webMaster>'."\n"; 167 172 168 echo ' <category>'.podPress_feedSafeContent($rss_category).'</category>'."\n"; 169 170 $data['rss_ttl'] = get_option('rss_ttl'); 171 if(!empty($data['rss_ttl']) && $data['rss_ttl'] < 1440) { 172 $data['rss_ttl'] = 1440; 173 } 173 174 if(!empty($data['rss_ttl'])) { 174 175 echo ' <ttl>'.$data['rss_ttl'].'</ttl>'."\n"; 175 176 } 176 echo ' <itunes:keywords>'.podPress_stringLimiter(podPress_feedSafeContent($data['keywords']), 255).'</itunes:keywords>'."\n"; 177 178 if ('' != trim($data['rss_image'])) { 179 echo ' <image>'."\n"; 180 echo ' <url>'.$data['rss_image'].'</url>'."\n"; 181 echo ' <title>'.podPress_feedSafeContent(get_bloginfo('blogname')).'</title>'."\n"; 182 echo ' <link>'.get_bloginfo('siteurl').'</link>'."\n"; 183 echo ' <width>144</width>'."\n"; 184 echo ' <height>144</height>'."\n"; 185 echo ' </image>'."\n"; 186 } 187 188 // iTunes - tags for the channnel: 189 if($data['new-feed-url'] == 'Enable') { 190 if(!empty($data['podcastFeedURL']) && !strpos(strtolower($data['podcastFeedURL']), 'phobos.apple.com') && !strpos(strtolower($data['podcastFeedURL']), 'itpc://')) { 191 echo ' <itunes:new-feed-url>'.podPress_feedSafeContent($data['podcastFeedURL']).'</itunes:new-feed-url>'."\n"; 192 } 193 } 177 194 echo ' <itunes:subtitle>'.podPress_stringLimiter(podPress_feedSafeContent($data['subtitle']), 255).'</itunes:subtitle>'."\n"; 178 195 echo ' <itunes:summary>'.podPress_stringLimiter(podPress_feedSafeContent($data['summary']), 4000).'</itunes:summary>'."\n"; 196 echo ' <itunes:keywords>'.podPress_stringLimiter(podPress_feedSafeContent($data['keywords']), 255).'</itunes:keywords>'."\n"; 197 echo podPress_getiTunesCategoryTags(); 179 198 echo ' <itunes:author>'.podPress_feedSafeContent($data['author']).'</itunes:author>'."\n"; 180 echo podPress_getiTunesCategoryTags();181 199 echo ' <itunes:owner>'."\n"; 182 200 echo ' <itunes:name>'.stripslashes(podPress_feedSafeContent($data['author'])).'</itunes:name>'."\n"; 183 201 echo ' <itunes:email>'.podPress_feedSafeContent($data['admin_email']).'</itunes:email>'."\n"; 184 202 echo ' </itunes:owner>'."\n"; 185 if(empty($data['block'])) { 186 $data['block'] = 'No'; 203 if ('yes' == strtolower($data['block']) OR 'no' == strtolower($data['block'])) { 204 echo ' <itunes:block>'.strtolower($data['block']).'</itunes:block>'."\n"; 205 } else { 206 echo ' <itunes:block>no</itunes:block>'."\n"; 187 207 } 188 echo ' <itunes:block>'.$data['block'].'</itunes:block>'."\n";189 208 echo ' <itunes:explicit>'.podPress_feedSafeContent(strtolower($data['explicit'])).'</itunes:explicit>'."\n"; 190 echo ' <itunes:image href="'.$data['image'].'" />'."\n"; 191 echo ' <image>'."\n"; 192 echo ' <url>'.$data['rss_image'].'</url>'."\n"; 193 echo ' <title>'.podPress_feedSafeContent(get_bloginfo('blogname')).'</title>'."\n"; 194 echo ' <link>'.get_bloginfo('siteurl').'</link>'."\n"; 195 echo ' <width>144</width>'."\n"; 196 echo ' <height>144</height>'."\n"; 197 echo ' </image>'."\n"; 209 if ('' != trim($data['image'])) { 210 echo ' <itunes:image href="'.$data['image'].'" />'."\n"; 211 } 198 212 } 199 213 200 214 function podPress_rss2_item() { … … 253 267 } 254 268 echo ' <itunes:author>'.podPress_feedSafeContent($post->podPressPostSpecific['itunes:author']).'</itunes:author>'."\n"; 255 269 256 if ($post->podPressPostSpecific['itunes:explicit'] == 'Default') {270 if ($post->podPressPostSpecific['itunes:explicit'] == 'Default') { 257 271 $post->podPressPostSpecific['itunes:explicit'] = $podPress->settings['iTunes']['explicit']; 258 if(empty($post->podPressPostSpecific['itunes:explicit'])) {259 $post->podPressPostSpecific['itunes:explicit'] = 'No';260 }261 272 } 273 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'])) ) { 274 $post->podPressPostSpecific['itunes:explicit'] = 'No'; 275 } 262 276 echo ' <itunes:explicit>'.podPress_feedSafeContent(strtolower($post->podPressPostSpecific['itunes:explicit'])).'</itunes:explicit>'."\n"; 263 277 264 if ($post->podPressPostSpecific['itunes:block'] == 'Default') {278 if ($post->podPressPostSpecific['itunes:block'] == 'Default') { 265 279 $post->podPressPostSpecific['itunes:block'] = $podPress->settings['iTunes']['block']; 266 if(empty($post->podPressPostSpecific['itunes:block'])) {267 $post->podPressPostSpecific['itunes:block'] = 'No';268 }269 280 } 270 if (empty($post->podPressPostSpecific['itunes:block'])) {281 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'])) ) { 271 282 $post->podPressPostSpecific['itunes:block'] = 'No'; 272 283 } 273 echo ' <itunes:block>'.podPress_feedSafeContent( $post->podPressPostSpecific['itunes:block']).'</itunes:block>'."\n";284 echo ' <itunes:block>'.podPress_feedSafeContent(strtolower($post->podPressPostSpecific['itunes:block'])).'</itunes:block>'."\n"; 274 285 //echo '<comments>'. get_comments_link() .'</comments>'."\n"; 286 287 $episodeLicenseTags = podPress_getEpisodeLicenseTags(); 288 if ($episodeLicenseTags != '') 289 { 290 echo $episodeLicenseTags; 291 } 275 292 } 276 $episodeLicenseTags = podPress_getEpisodeLicenseTags(); 277 if ($episodeLicenseTags != '') 278 { 279 echo $episodeLicenseTags; 280 } 281 if(isset($post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold'])) { 293 if (isset($post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold'])) { 282 294 $post_meta_cache[$blog_id][$post->ID]['enclosure'] = $post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold']; 283 295 unset($post_meta_cache[$blog_id][$post->ID]['enclosure_podPressHold']); 284 296 } 285 297 } 286 298 287 288 299 function podPress_atom_head() { 289 300 GLOBAL $podPress; 290 301 if(!isset($podPress->settings['category_data'])) { … … 308 319 309 320 function podPress_atom_entry() { 310 321 $enclosureTag = podPress_getEnclosureTags('atom'); 311 if ($enclosureTag != '') // if no enclosure tag, no need for iTunes tags 312 { 322 if ($enclosureTag != '') { // if no enclosure tag, no need for iTunes tags 313 323 echo $enclosureTag; 324 325 $episodeLicenseTags = podPress_getEpisodeLicenseTags('atom'); 326 if ($episodeLicenseTags != '') { 327 echo $episodeLicenseTags; 328 } 314 329 } 315 $episodeLicenseTags = podPress_getEpisodeLicenseTags('atom');316 if ($episodeLicenseTags != '')317 {318 echo $episodeLicenseTags;319 }320 330 } 321 331 322 332 function podPress_xspf_playlist() { … … 525 535 return $exists; 526 536 } 527 537 528 function podpress_strtomilliseconds($durationstr) { 529 $dstr_parts=explode(':', $durationstr); 530 $nr_dstr_parts=count($dstr_parts); 531 if (1 < $nr_dstr_parts AND 5 > $nr_dstr_parts) { 532 switch ($nr_dstr_parts) { 533 case 2 : 534 // this method is only good if the input data which consist of two parts is most likely in the format m:s because 535 // m:s 536 $duration = podpress_strtomilliseconds_core(1, 2, $dstr_parts); 537 if ($durationstr != podpress_millisecondstostring($duration)) { 538 // h:m 539 $duration = podpress_strtomilliseconds_core(0, 2, $dstr_parts); 538 function podpress_strtomilliseconds($durationstr) { 539 // This function converts a string which is parted by at least one double point into a milliseconds value. 540 // 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. 541 // 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. 542 // Better ideas are welcome! Write a ticket http://plugins.trac.wordpress.org/ or post to the forum: http://wordpress.org/support/forum/10 543 $dstr_parts=explode(':', $durationstr); 544 $nr_dstr_parts=count($dstr_parts); 545 if (1 < $nr_dstr_parts AND 5 > $nr_dstr_parts) { 546 switch ($nr_dstr_parts) { 547 case 2 : 548 // this method is only good if the input data which consist of two parts is most likely in the format m:s because 549 // m:s 550 $duration = podpress_strtomilliseconds_core(1, 2, $dstr_parts); 540 551 if ($durationstr != podpress_millisecondstostring($duration)) { 541 // s:ms 542 $duration = podpress_strtomilliseconds_core(2, 2, $dstr_parts); 552 // h:m 553 $duration = podpress_strtomilliseconds_core(0, 2, $dstr_parts); 554 if ($durationstr != podpress_millisecondstostring($duration)) { 555 // s:ms 556 $duration = podpress_strtomilliseconds_core(2, 2, $dstr_parts); 557 } 543 558 } 544 }545 break;546 case 3 :547 // h:m:s548 $duration = podpress_strtomilliseconds_core(0, 3, $dstr_parts);549 if ($durationstr != podpress_millisecondstostring($duration)) {550 // m:s:ms551 $duration = podpress_strtomilliseconds_core(1, 3, $dstr_parts);552 }553 break;554 case 4 :555 $duration = podpress_strtomilliseconds_core(0, 4, $dstr_parts);556 break;557 }558 }559 if (!isset($duration) OR $duration < 0) {560 $duration = 0;561 }562 return $duration;563 }564 565 function podpress_strtomilliseconds_core($startindex=0, $max_nr_parts=4, $dstr_parts=array()){566 $duration = $j = 0;567 if (!empty($dstr_parts)) {568 for ($i=$startindex; $i < ($max_nr_parts+$startindex); $i++) {569 switch ($i) {570 case 0 : // hours571 $duration += 3600000 * intval(substr($dstr_parts[$j], 0, 2));572 $j++;573 559 break; 574 case 1 : // minutes 575 $duration += 60000 * intval(substr($dstr_parts[$j], 0, 2)); 576 $j++; 560 case 3 : 561 // h:m:s 562 $duration = podpress_strtomilliseconds_core(0, 3, $dstr_parts); 563 if ($durationstr != podpress_millisecondstostring($duration)) { 564 // m:s:ms 565 $duration = podpress_strtomilliseconds_core(1, 3, $dstr_parts); 566 } 577 567 break; 578 case 2 : // seconds 579 $duration += 1000 * intval(substr($dstr_parts[$j], 0, 2)); 580 $j++; 568 case 4 : 569 $duration = podpress_strtomilliseconds_core(0, 4, $dstr_parts); 581 570 break; 582 case 3 : // milliseconds583 $duration += intval(substr($dstr_parts[$j], 0, 2));584 $j++;585 break;586 571 } 587 572 } 573 if (!isset($duration) OR $duration < 0) { 574 $duration = 0; 575 } 576 return $duration; 588 577 } 589 return $duration;590 }591 578 592 function podpress_millisecondstostring($duration) { 593 // 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. 594 // If the leading parts is zero then the return string will not contain this part. 595 $hours = intval($duration / (3600000)); 596 $minutes = intval($duration / (60000) % 60); 597 $seconds = intval($duration / (1000) % 60); 598 $mseconds = intval($duration % 1000); 599 $duration_array = array($hours, $minutes, $seconds, $mseconds); 600 $dur_str =""; 601 $j=0; 602 foreach($duration_array as $key => $dur_part) { 603 if ("" == $dur_str AND 0 == $dur_part) { 604 } else { 605 if (3 == $key AND 0 == $dur_part) { 579 function podpress_strtomilliseconds_core($startindex=0, $max_nr_parts=4, $dstr_parts=array()){ 580 $duration = $j = 0; 581 if (!empty($dstr_parts)) { 582 for ($i=$startindex; $i < ($max_nr_parts+$startindex); $i++) { 583 switch ($i) { 584 case 0 : // hours 585 $duration += 3600000 * intval(substr($dstr_parts[$j], 0, 2)); 586 $j++; 587 break; 588 case 1 : // minutes 589 $duration += 60000 * intval(substr($dstr_parts[$j], 0, 2)); 590 $j++; 591 break; 592 case 2 : // seconds 593 $duration += 1000 * intval(substr($dstr_parts[$j], 0, 2)); 594 $j++; 595 break; 596 case 3 : // milliseconds 597 $duration += intval(substr($dstr_parts[$j], 0, 2)); 598 $j++; 599 break; 600 } 601 } 602 } 603 return $duration; 604 } 605 606 function podpress_millisecondstostring($duration) { 607 // This function converts a milliseconds value into duration string in the format H:M:S:MS or H:M:S (if the MS part would be zero). 608 // If the leading part is zero then the return string will not contain this part. 609 $hours = intval($duration / (3600000)); 610 $minutes = intval($duration / (60000) % 60); 611 $seconds = intval($duration / (1000) % 60); 612 $mseconds = intval($duration % 1000); 613 $duration_array = array($hours, $minutes, $seconds, $mseconds); 614 $dur_str =""; 615 $j=0; 616 foreach($duration_array as $key => $dur_part) { 617 if ("" == $dur_str AND 0 == $dur_part) { 606 618 } else { 607 if ($j > 0) { 608 $dur_str .= ":".strval($dur_part); 619 if (3 == $key AND 0 == $dur_part) { 609 620 } else { 610 $dur_str .= strval($dur_part); 621 if ($j > 0) { 622 $dur_str .= ":".strval($dur_part); 623 } else { 624 $dur_str .= strval($dur_part); 625 } 626 $j++; 611 627 } 612 $j++;613 628 } 614 629 } 630 return $dur_str; 615 631 } 616 return $dur_str;617 }618 632 619 633 function podPress_getiTunesCategoryTags() { 620 634 GLOBAL $podPress, $post; … … 638 652 foreach($data as $thiscat) { 639 653 if (strstr($thiscat, ':')) { 640 654 list($cat, $subcat) = explode(":", $thiscat); 641 $result .= "\t".'<itunes:category text="'. str_replace('&', '&',$cat).'">'."\n";642 $result .= "\t\t".'<itunes:category text="'. str_replace('&', '&',$subcat).'" />'."\n";655 $result .= "\t".'<itunes:category text="'.podPress_feedSafeContent($cat).'">'."\n"; 656 $result .= "\t\t".'<itunes:category text="'.podPress_feedSafeContent($subcat).'" />'."\n"; 643 657 $result .= "\t".'</itunes:category>'."\n"; 644 658 } elseif (!empty($thiscat) AND '[ '.__('nothing', 'podpress').' ]' != $thiscat ) { 645 $result .= "\t".'<itunes:category text="'. str_replace('&', '&',$thiscat).'" />'."\n";659 $result .= "\t".'<itunes:category text="'.podPress_feedSafeContent($thiscat).'" />'."\n"; 646 660 } 647 661 } 648 662 }
