PHP Classes

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Richard Lucas  >  ABC_RSS  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Case
Class: ABC_RSS
Compose and generate RSS 2.0 feeds
Author: By
Last change: Added support for multiple category elements in channels and items
Date: 5 years ago
Size: 3,917 bytes


Class file image Download
require_once( 'ABC_RSS.php' );

$destination_file ='rss.xml';

$rss = new ABC_RSS();

try {

// All possible channel elements
$channel =array();
$channel['title'] ='News.dom';
$channel['link'] ='';
$channel['description'] ='All the News You Can Stand';
$channel['language'] ='en-us';
$channel['copyright'] ='Copyright 2010-2012, News.dom';
$channel['managingEditor'] ='editor@news.dom (John Smith)';
$channel['webMaster'] ='webmaster@news.dom (Jane Doe)';
$channel['pubDate'] =date( DATE_RSS );
$channel['lastBuildDate'] =date( DATE_RSS );
$channel['category'] =array();
$channel['category'][] =array( 'content' =>'news', 'domain' =>'local,regional,national,world' );
$channel['category'][] =array( 'content' =>'sports', 'domain' =>'local,regional,national' );
$channel['category'][] =array( 'content' =>'entertainment', 'domain' =>'local,regional,national' );
$channel['generator'] ='ABC_RSS PHP Class';
$channel['docs'] ='';
$channel['cloud'] = array();
$channel['cloud']['domain'] ='';
$channel['cloud']['port'] ='80';
$channel['cloud']['path'] ='/RPC2';
$channel['cloud']['registerProcedure'] ='pingMe';
$channel['cloud']['protocol'] ='soap';
$channel['ttl'] = '60';
$channel['image'] =array();
$channel['image']['url'] ='';
$channel['image']['title'] ='News.dom';
$channel['image']['link'] ='';
$channel['image']['width'] ='88';
$channel['image']['height'] ='31';
$channel['rating'] ='(PICS-1.1 "" '.
'l r (suds 0.5 density 0 color/hue 1) '.
'r (subject 2 density 1 color/hue 1))';
$channel['textInput'] =array();
$channel['textInput']['title'] ='Search';
$channel['textInput']['description'] ='Find an article on News.dom';
$channel['textInput']['name'] ='q';
$channel['textInput']['link'] ='';
$channel['skipHours'] ='0,1,2,3';
$channel['skipDays'] ='Saturday';
    if ( !
$rss->set_channel( $channel ))
$errors =&$rss->errors;
        throw new
Exception( 'Unable to set the RSS channel.' );
// All possible item elements
$item =array();
$item['title'] ='New Water Park Makes Big Splash in Local Economy';
$item['description'] ='Reporter Peter Griffin talks to Bob Smith, the owner-operator '.
'of Quahog\'s new water recreation park, Wetworld.';
$item['link'] ='';
$item['author'] ='Peter Griffin';
$item['category'] =array();
$item['category'][] =array( 'content' =>'news', 'domain' =>'local' );
$item['category'][] =array( 'content' =>'entertainment', 'domain' =>'local' );
$item['comments'] ='';
$item['enclosure'] =array();
$item['enclosure']['url'] ='';
$item['enclosure']['length'] ='12216320';
$item['enclosure']['type'] ='video/quicktime';
$item['guid'] =array();
$item['guid']['isPermaLink'] ='true';
$item['guid']['content'] ='';
$item['pubDate'] ='Sun, 19 May 2002 15:21:36 GMT';
    if ( !
$rss->set_item( $item ))
$errors =&$rss->errors;
        throw new
Exception( 'Unable to set the RSS item.' );
    if ( !
$rss->export( 'write', $destination_file ))
$errors =&$rss->errors;
        throw new
Exception( 'Unable to write the RSS file.' );

catch (
Exception $e ) { $errors[] =$e->getMessage(); }

if ( !empty(
$errors ))
    foreach (
$errors as $error )
printf( "<p>%s</p>", $error );
'<p>The RSS was created without errors.</p>';