| | 12 | /* private $itunesCategory = array( |
| | 13 | 'Arts' => array( 'Design', 'Fashion & Beauty', 'Food', 'Literature', 'Performing Arts', 'Visual Arts' ), |
| | 14 | 'Business' => array( 'Business News', 'Careers', 'Investing', 'Management & Marketing', 'Shopping' ), |
| | 15 | 'Comedy', |
| | 16 | 'Education' => array( 'Education Technology', 'Higher Education', 'K-12', 'Language Courses', 'Training' ), |
| | 17 | 'Games & Hobbies' => array( 'Automotive', 'Aviation', 'Hobbies', 'Other Games', 'Video Games' ), |
| | 18 | 'Government & Organizations' => array( 'Local', 'National', 'Non-Profit', 'Regional' ), |
| | 19 | 'Health' => array( 'Alternative Health', 'Fitness & Nutrition', 'Self-Help', 'Sexuality' ), |
| | 20 | 'Kids & Family', |
| | 21 | 'Music', |
| | 22 | 'News & Politics', |
| | 23 | 'Religion & Spirituality' => array( 'Buddhism', 'Christianity', 'Hinduism', 'Islam', 'Judaism', 'Other', 'Spirituality' ), |
| | 24 | 'Science & Medicine' => array( 'Medicine', 'Natural Sciences', 'Social Sciences' ), |
| | 25 | 'Society & Culture' => array( 'History', 'Personal Journals', 'Philosophy', 'Places & Travel' ), |
| | 26 | 'Sports & Recreation' => array( 'Amateur', 'College & High School', 'Outdoor', 'Professional' ), |
| | 27 | 'Technology' => array( 'Gadgets', 'Tech News', 'Podcasting', 'Software How-To' ), |
| | 28 | 'TV & Film', |
| | 29 | ); |
| | 30 | */ |
| 212 | | public function produce_rss($feed_name) |
| 213 | | { |
| 214 | | echo <<< RSS |
| 215 | | RSS goes here. |
| 216 | | RSS; |
| | 265 | public function produce_rss( $feed_name ) |
| | 266 | { |
| | 267 | $xml = $this->create_rss_wrapper( $feed_name ); |
| | 268 | $posts= Posts::get( array( 'status' => Post::status( 'published' ), 'content_type' => Post::type( 'podcast' ), array( 'info' => $feed_name ) ) ); |
| | 269 | $xml = $this->add_posts( $xml, $posts, $feed_name ); |
| | 270 | Plugins::act( 'podcast_rss_collection', $xml, $posts, $feed_name ); |
| | 271 | ob_clean(); |
| | 272 | |
| | 273 | header( 'Content-Type: application/xml' ); |
| | 274 | echo $xml->asXML(); |
| | 275 | exit; |
| | 276 | } |
| | 277 | |
| | 278 | /** |
| | 279 | * Creates a basic RSS-format XML structure with channel and items elements |
| | 280 | * @return SimpleXMLElement The requested RSS document |
| | 281 | */ |
| | 282 | public function create_rss_wrapper( $feed_name ) |
| | 283 | { |
| | 284 | $xml= new SimpleXMLElement( '<?xml version="1.0" encoding="UTF-8" ?><rss></rss>' ); |
| | 285 | $xml->addAttribute( 'xmlns:xmlns:itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd' ); |
| | 286 | $xml->addAttribute( 'version', '2.0' ); |
| | 287 | $channel= $xml->addChild( 'channel' ); |
| | 288 | $title= $channel->addChild( 'title', htmlspecialchars( Options::get('title') ) ); |
| | 289 | $link= $channel->addChild( 'link', Site::get_url('habari') ); |
| | 290 | if ( $tagline= Options::get( 'tagline' ) ) { |
| | 291 | $description= $channel->addChild( 'description', htmlspecialchars( $tagline ) ); |
| | 292 | } |
| | 293 | $pubDate= $channel->addChild( 'lastBuildDate', date( DATE_RFC822, strtotime( Post::get()->pubdate ) ) ); |
| | 294 | $generator= $channel->addChild( 'generator', 'Habari ' . Version::get_habariversion() . ' http://habariproject.org/' ); |
| | 295 | |
| | 296 | $itunes_author = $channel->addChild( 'xmlns:itunes:author', 'nothing' ); |
| | 297 | $itunes_subtitle = $channel->addChild( 'xmlns:itunes:subtitle', 'nothing' ); |
| | 298 | $itunes_summary = $channel->addChild( 'xmlns:itunes:summary', 'nothing' ); |
| | 299 | $itunes_owner = $channel->addChild( 'xmlns:itunes:owner' ); |
| | 300 | $itunes_owner_name = $itunes_owner->addChild( 'xmlns:itunes:name', 'nothing' ); |
| | 301 | $itunes_owner_email = $itunes_owner->addChild( 'xmlns:itunes:email', 'nothing' ); |
| | 302 | $itunes_explicit = $channel->addChild( 'xmlns:itunes:explicit', 'no' ); |
| | 303 | $itunes_image = $channel->addChild( 'xmlns:itunes:image', 'nothing' ); |
| | 304 | $itunes_image->addAttribute( 'href', 'nothing' ); |
| | 305 | $itunes_category = $channel->addChild( 'xmlns:itunes:category' ); |
| | 306 | $itunes_category->addAttribute( 'text', 'nothing' ); |
| | 307 | |
| | 308 | Plugins::act( 'podcast_create_wrapper', $xml ); |
| | 309 | return $xml; |
| | 310 | } |
| | 311 | |
| | 312 | /** |
| | 313 | * Add posts as items in the provided xml structure |
| | 314 | * @param SimpleXMLElement $xml The document to add to |
| | 315 | * @param array $posts An array of Posts to add to the XML |
| | 316 | * @return SimpleXMLElement The resultant XML with added posts |
| | 317 | */ |
| | 318 | public function add_posts($xml, $posts, $feed_name ) |
| | 319 | { |
| | 320 | $items = $xml->channel; |
| | 321 | foreach ( $posts as $post ) { |
| | 322 | if ($post instanceof Post) { |
| | 323 | $item= $items->addChild( 'item' ); |
| | 324 | $title= $item->addChild( 'title', htmlspecialchars( $post->title ) ); |
| | 325 | $link= $item->addChild( 'link', $post->permalink ); |
| | 326 | $description= $item->addChild( 'description', htmlspecialchars( $post->content ) ); |
| | 327 | $pubdate= $item->addChild ( 'pubDate', date( DATE_RFC822, strtotime( $post->pubdate ) ) ); |
| | 328 | $guid= $item->addChild( 'guid', $post->guid ); |
| | 329 | $guid->addAttribute( 'isPermaLink', 'false' ); |
| | 330 | $enclosure = $item->addChild( 'enclosure' ); |
| | 331 | $enclosure->addAttribute( 'url', $post->info->feed ); |
| | 332 | $enclosure->addAttribute( 'length', filesize( $post->info->feed ) ); |
| | 333 | $enclosure->addAttribute( 'type', 'audio/mpeg' ); |
| | 334 | $category = $item->addChild( 'Category', '' ); |
| | 335 | |
| | 336 | $itunes_author = $item->addChild( 'xmlns:itunes:author', $post->author->displayname ); |
| | 337 | $itunes_explicit = $item->addChild( 'xmlns:itunes:explicit', 'Clean' ); |
| | 338 | $itunes_subtitle = $item->addChild( 'xmlns:itunes:subtitle', '' ); |
| | 339 | $itunes_summary = $item->addChild( 'xmlns:itunes:summary', '' ); |
| | 340 | $itunes_duration = $item->addChild( 'xmlns:itunes:duration', '' ); |
| | 341 | $itunes_keywords = $item->addChild( 'xmlns:itunes:keywords', '' ); |
| | 342 | |
| | 343 | Plugins::act( 'podcast_add_post', $item, $post ); |
| | 344 | } |
| | 345 | } |
| | 346 | return $xml; |