blob: f8a473423895961144007c85e9e13259234fcf39 [file] [log] [blame]
<?php
/**
* THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE (http://www.eclipse.org/legal/epl-v10.html).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
*
*/
/**
*
*/
/*
* Created on 15/12/2005
*
* Eduardo A. Romero Gomez
* eromero@openmex.com
* http://www.openmex.com
*/
require_once($_SERVER['DOCUMENT_ROOT'] . "/projects/common/xmlwrapper.class.php");
/**
* The Blog object models a RSS v2.0 or ATOM v1.0 <b>blog</b>
*
* see http://www.tbray.org/atom/RSS-and-Atom#specs for more information
*
* As any blog out there it has a <b>name</b> and an <b>url</b>, description, date, image and copyrigth are also avaliable
*
* @license http://www.eclipse.org/legal/epl-v10.html Eclipse Public License - v 1.0
* @author Eduardo A. Romero
*/
class Blog {
var $name="";
var $url="";
/* xml feed */
var $xml;
var $xmlsource;
var $serialized = 0;
var $xmlArray = array();
var $errors = array();
var $description = "";
var $copyright = "";
var $image = "";
var $thedate = "";
/* type of feed 1 == RSS 2 == ATOM */
var $feedType = 0;
/**
* Constructor,
*
* Creates a new Blog object, if no name is given the URL will be used
* as the name.
*
* @param string $name The name of the Blog, defaults to the URL
* @param string $url The URL of the Blog, defaults to the empty string
*
* @return Blog The brand new blog
*
*/
function Blog($url= "",$name="") {
$this->url = $url;
if(strlen($name) == 0)
$name = $url;
$this->name = $name;
}
/**
* Sets the name of the Blog
*
* @access public
* @param string The <i>name</i> of the blog
*/
function setName($name)
{
$this->name = $name;
}
/**
* Sets the URL where the Blog can be found
*
* @access public
* @param string The <i>url</i> of the blog
*/
function setURL($url)
{
$this->url = $url;
}
/**
* Returns the name of the Blog
*
* @access public
* @return string The name of the blog
*/
function getName()
{
if($this->serialized == 0)
$this->parseToArray();
return $this->name;
}
/**
* Returns the URL where the Blog can be found
*
* @access public
* @return string The URL of the Blog
*/
function getURL()
{
return $this->url;
}
/**
* Returns the XML feed of the Blog
*
* @access public
* @return string The URL XML Feed of the Blog
*/
function getXMLFeed()
{
return $this->xmlsource;
}
/**
* Returns the Date of the Blog
*
* @access public
* @return string The Date of the blog
*/
function getDate()
{
if($this->serialized == 0)
$this->parseToArray();
return $this->thedate;
}
/**
* Returns the Description of the Blog
*
* @access public
* @return string The Description of the blog
*/
function getDescription()
{
if($this->serialized == 0)
$this->parseToArray();
return $this->description;
}
/**
* Returns the Copyright of the Blog
*
* @access public
* @return string The copyright notice of the blog
*/
function getCopyright()
{
if($this->serialized == 0)
$this->parseToArray();
return $this->copyright;
}
/**
* Returns the URL of the Image of the Blog
*
* @access public
* @return string The URL of the image of the blog
*/
function getImage()
{
if($this->serialized == 0)
$this->parseToArray();
return $this->image;
}
/**
* Retrieves the XML from the XML Feed given on the constructor
*
* @access private
*/
function getXML()
{
$source = $this->url;
if(isset($_REQUEST['debug']))
echo "xmlsource $source <br>";
$xml = "";
if(strlen($source))
{
$xml = @file($source);
if(is_array($xml) && count($xml) > 0)
$xml = implode('',$xml);
$this->xmlsource = $source;
}
if(strlen($xml) <= 0)
{
/* no xml found */
} else {
$this->xml = $xml;
$this->xml = preg_replace( "/\<\!--.*?--\>/s", "", $this->xml );
}
}
/**
* Parses the XML Feed given on the constructor
*
* @access private
*/
function parseToArray()
{
$this->getXML();
if($this->serialized == 0)
{
$this->serialized = 1;
$this->xmlArray= XML_unserialize($this->xml);
}
else
$this->xmlArray= array();
if(count($this->xmlArray)>0)
{
// El XML esta en el arreglo. a procesar se ha dicho!
// es RSS o ATOM?
if(isset($this->xmlArray['rss']))
$this->feedType = 1;
elseif(isset($this->xmlArray['feed']))
$this->feedType = 2;
elseif(isset($this->xmlArray['rdf:RDF']))
{
$this->feedType = 1;
$this->xmlArray['rss'] = $this->xmlArray['rdf:RDF'];
}
if($this->feedType == 1)
{
/* RSS Channel information */
if(isset($this->xmlArray['rss']['channel']))
{
if(isset($this->xmlArray['rss']['channel']['title']))
$this->name = $this->xmlArray['rss']['channel']['title'];
if(isset($this->xmlArray['rss']['channel']['description']))
$this->description = $this->xmlArray['rss']['channel']['description'];
if(isset($this->xmlArray['rss']['channel']['copyright']))
$this->copyright = $this->xmlArray['rss']['channel']['copyright'];
if(isset($this->xmlArray['rss']['channel']['image']['url']))
$this->image = $this->xmlArray['rss']['channel']['image']['url'];
if(isset($this->xmlArray['rss']['channel']['lastBuildDate']))
$this->thedate = $this->xmlArray['rss']['channel']['lastBuildDate'];
if(isset($this->xmlArray['rss']['channel']['link']))
$this->url = $this->xmlArray['rss']['channel']['link'];
}
else
$this->errors[] = "No channel found";
}
elseif($this->feedType == 2)
{
/* Atom feed information */
if(isset($this->xmlArray['feed']['title']))
$this->name = $this->xmlArray['feed']['title'];
if(isset($this->xmlArray['feed']['subtitle']))
$this->desription = $this->xmlArray['feed']['subtitle'];
if(isset($this->xmlArray['feed']['rights']))
$this->copyright = $this->xmlArray['feed']['rights'];
if(isset($this->xmlArray['feed']['logo']))
$this->image = $this->xmlArray['feed']['logo'];
if(isset($this->xmlArray['feed']['updated']))
$this->thedate = $this->xmlArray['feed']['updated'];
}
else
{
//$error = "No Project Found";
$this->serialized = -2;
}
}
else
{
//$error = "No se pudo Serializar el XML";
$this->errors[] = "Couldn't parse XML";
$this->serialized = -1;
}
}
}
?>