mirror of
https://github.com/Chouchen/ShikiryuRSS.git
synced 2024-11-22 07:48:51 +01:00
Better doc
This commit is contained in:
parent
3825c11863
commit
919c67018c
116
srss.php
116
srss.php
@ -1,9 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
TODO textinput a 4 sous enfant
|
* TODO textinput a 4 sous enfant
|
||||||
TODO language
|
* TODO language
|
||||||
TODO CDATA ?
|
* TODO CDATA ?
|
||||||
*/
|
* @property string generator
|
||||||
|
* @property null|string image
|
||||||
|
* @property null|string cloud
|
||||||
|
* @property null|string title
|
||||||
|
* @property null|string link
|
||||||
|
* @property null|string description
|
||||||
|
*/
|
||||||
class SRSS extends DomDocument implements Iterator
|
class SRSS extends DomDocument implements Iterator
|
||||||
{
|
{
|
||||||
protected $xpath; // xpath engine
|
protected $xpath; // xpath engine
|
||||||
@ -63,13 +70,14 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $link url of the rss
|
* @param $link string url of the rss
|
||||||
|
* @throws SRSSException
|
||||||
* @return SRSS
|
* @return SRSS
|
||||||
*/
|
*/
|
||||||
public static function read($link)
|
public static function read($link)
|
||||||
{
|
{
|
||||||
$doc = new SRSS;
|
$doc = new SRSS;
|
||||||
if(@$doc->load($link)) // We don't want the warning in case of bad XML. Let's manage it.
|
if(@$doc->load($link)) // We don't want the warning in case of bad XML. Let's manage it with an exception.
|
||||||
{
|
{
|
||||||
$channel = $doc->getElementsByTagName('channel');
|
$channel = $doc->getElementsByTagName('channel');
|
||||||
if($channel->length == 1){ // Good URL and good RSS
|
if($channel->length == 1){ // Good URL and good RSS
|
||||||
@ -101,7 +109,7 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
$doc->appendChild($root);
|
$doc->appendChild($root);
|
||||||
$doc->encoding = "UTF-8";
|
$doc->encoding = "UTF-8";
|
||||||
$doc->generator = 'Shikiryu RSS';
|
$doc->generator = 'Shikiryu RSS';
|
||||||
$docs = 'http://www.scriptol.fr/rss/RSS-2.0.html';
|
// $docs = 'http://www.scriptol.fr/rss/RSS-2.0.html';
|
||||||
return $doc;
|
return $doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +122,7 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
if(func_num_args() == 0) $args[0] = 'url';
|
if(func_num_args() == 0) $args[0] = 'url';
|
||||||
$img = $this->xpath->query('//channel/image');
|
$img = $this->xpath->query('//channel/image');
|
||||||
if($img->length != 1) return; // <image> is not in channel
|
if($img->length != 1) return null; // <image> is not in channel
|
||||||
$img = $img->item(0);
|
$img = $img->item(0);
|
||||||
$r = array();
|
$r = array();
|
||||||
foreach($img->childNodes as $child)
|
foreach($img->childNodes as $child)
|
||||||
@ -129,12 +137,12 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setter of "image"'s channel attributes
|
* setter of "image"'s channel attributes
|
||||||
* @param $url picture's url
|
* @param $url string picture's url
|
||||||
* @param $title picture's title
|
* @param $title string picture's title
|
||||||
* @param $link link on the picture
|
* @param $link string link on the picture
|
||||||
* @param $width width
|
* @param $width int width
|
||||||
* @param $height height
|
* @param $height int height
|
||||||
* @param $description description
|
* @param $description string description
|
||||||
*/
|
*/
|
||||||
public function setImage($url, $title, $link, $width = 0, $height = 0, $description = '')
|
public function setImage($url, $title, $link, $width = 0, $height = 0, $description = '')
|
||||||
{
|
{
|
||||||
@ -192,11 +200,11 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setter of "cloud"'s channel attributes
|
* setter of "cloud"'s channel attributes
|
||||||
* @param $domain domain
|
* @param $domain string domain
|
||||||
* @param $port port
|
* @param $port int port
|
||||||
* @param $path path
|
* @param $path string path
|
||||||
* @param $registerProcedure register procedure
|
* @param $registerProcedure string register procedure
|
||||||
* @param $protocol protocol
|
* @param $protocol string protocol
|
||||||
*/
|
*/
|
||||||
public function setCloud($domain, $port, $path, $registerProcedure, $protocol)
|
public function setCloud($domain, $port, $path, $registerProcedure, $protocol)
|
||||||
{
|
{
|
||||||
@ -244,9 +252,11 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
}
|
}
|
||||||
return ($valid && $this->title != null && $this->link != null && $this->description != null);
|
return ($valid && $this->title != null && $this->link != null && $this->description != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getter of current RSS channel
|
* getter of current RSS channel
|
||||||
|
* @return DOMElement
|
||||||
|
* @throws SRSSException
|
||||||
*/
|
*/
|
||||||
private function _getChannel()
|
private function _getChannel()
|
||||||
{
|
{
|
||||||
@ -254,9 +264,12 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
if($channel->length != 1) throw new SRSSException('channel node not created, or too many channel nodes');
|
if($channel->length != 1) throw new SRSSException('channel node not created, or too many channel nodes');
|
||||||
return $channel->item(0);
|
return $channel->item(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setter of others attributes
|
* setter of others attributes
|
||||||
|
* @param $name
|
||||||
|
* @param $val
|
||||||
|
* @throws SRSSException
|
||||||
*/
|
*/
|
||||||
public function __set($name, $val)
|
public function __set($name, $val)
|
||||||
{
|
{
|
||||||
@ -275,18 +288,21 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
throw new SRSSException($name.' is not a possible item');
|
throw new SRSSException($name.' is not a possible item');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getter of others attributes
|
* getter of others attributes
|
||||||
|
* @param $name
|
||||||
|
* @return null|string
|
||||||
|
* @throws SRSSException
|
||||||
*/
|
*/
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
if(isset($this->attr[$name]))
|
if(isset($this->attr[$name]))
|
||||||
return $this->attr[$name];
|
return $this->attr[$name];
|
||||||
$channel = $this->_getChannel();
|
// $channel = $this->_getChannel();
|
||||||
if(array_key_exists($name, $this->possibleAttr)){
|
if(array_key_exists($name, $this->possibleAttr)){
|
||||||
$tmp = $this->xpath->query('//channel/'.$name);
|
$tmp = $this->xpath->query('//channel/'.$name);
|
||||||
if($tmp->length != 1) return;
|
if($tmp->length != 1) return null;
|
||||||
return $tmp->item(0)->nodeValue;
|
return $tmp->item(0)->nodeValue;
|
||||||
}else{
|
}else{
|
||||||
throw new SRSSException($name.' is not a possible value.');
|
throw new SRSSException($name.' is not a possible value.');
|
||||||
@ -387,17 +403,18 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
$i--;
|
$i--;
|
||||||
return isset($this->items[$i]) ? $this->items[$i] : null;
|
return isset($this->items[$i]) ? $this->items[$i] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getter of all items
|
* getter of all items
|
||||||
* @return array of SRSSItem
|
* @return SRSSItem[]
|
||||||
|
* @throws SRSSException
|
||||||
*/
|
*/
|
||||||
public function getItems()
|
public function getItems()
|
||||||
{
|
{
|
||||||
$channel = $this->_getChannel();
|
$channel = $this->_getChannel();
|
||||||
$item = $channel->getElementsByTagName('item');
|
$item = $channel->getElementsByTagName('item');
|
||||||
$length = $item->length;
|
$length = $item->length;
|
||||||
$items = array();
|
$this->items = array();
|
||||||
if($length > 0){
|
if($length > 0){
|
||||||
for($i = 0; $i < $length; $i++)
|
for($i = 0; $i < $length; $i++)
|
||||||
{
|
{
|
||||||
@ -459,9 +476,16 @@ class SRSS extends DomDocument implements Iterator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property null|string enclosure
|
||||||
|
* @property null|string description
|
||||||
|
*/
|
||||||
class SRSSItem extends DomDocument
|
class SRSSItem extends DomDocument
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DOMElement
|
||||||
|
*/
|
||||||
protected $node; // item node
|
protected $node; // item node
|
||||||
protected $attr; // item's properties
|
protected $attr; // item's properties
|
||||||
|
|
||||||
@ -481,7 +505,7 @@ class SRSSItem extends DomDocument
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param DomElement $node
|
* @param DomNode $node
|
||||||
*/
|
*/
|
||||||
public function __construct($node = null)
|
public function __construct($node = null)
|
||||||
{
|
{
|
||||||
@ -548,9 +572,12 @@ class SRSSItem extends DomDocument
|
|||||||
{
|
{
|
||||||
return $this->description != null ? true : false;
|
return $this->description != null ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main setter for properties
|
* main setter for properties
|
||||||
|
* @param $name
|
||||||
|
* @param $val
|
||||||
|
* @throws SRSSException
|
||||||
*/
|
*/
|
||||||
public function __set($name, $val)
|
public function __set($name, $val)
|
||||||
{
|
{
|
||||||
@ -571,9 +598,12 @@ class SRSSItem extends DomDocument
|
|||||||
throw New SRSSException($name.' is not a possible item : '.print_r($this->possibilities));
|
throw New SRSSException($name.' is not a possible item : '.print_r($this->possibilities));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main getter for properties
|
* main getter for properties
|
||||||
|
* @param $name
|
||||||
|
* @return null|string
|
||||||
|
* @throws SRSSException
|
||||||
*/
|
*/
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
@ -582,7 +612,7 @@ class SRSSItem extends DomDocument
|
|||||||
if(array_key_exists($name, $this->possibilities))
|
if(array_key_exists($name, $this->possibilities))
|
||||||
{
|
{
|
||||||
$tmp = $this->node->getElementsByTagName($name);
|
$tmp = $this->node->getElementsByTagName($name);
|
||||||
if($tmp->length != 1) return;
|
if($tmp->length != 1) return null;
|
||||||
return $tmp->item(0)->nodeValue;
|
return $tmp->item(0)->nodeValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -673,16 +703,18 @@ class SRSSTools
|
|||||||
* format the RSS to the wanted format
|
* format the RSS to the wanted format
|
||||||
* @param $format string wanted format
|
* @param $format string wanted format
|
||||||
* @param $date string RSS date
|
* @param $date string RSS date
|
||||||
* @return date
|
* @return string date
|
||||||
*/
|
*/
|
||||||
public static function formatDate($format, $date)
|
public static function formatDate($format, $date)
|
||||||
{
|
{
|
||||||
return date($format, strtotime($date));
|
return date($format, strtotime($date));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* format a date for RSS format
|
* format a date for RSS format
|
||||||
* @param $date string date to format
|
* @param string $date date to format
|
||||||
|
* @param string $format
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getRSSDate($date, $format='')
|
public static function getRSSDate($date, $format='')
|
||||||
{
|
{
|
||||||
@ -711,7 +743,7 @@ class SRSSTools
|
|||||||
/**
|
/**
|
||||||
* check if it's an url
|
* check if it's an url
|
||||||
* @param $check string to check
|
* @param $check string to check
|
||||||
* @return the filtered data, or FALSE if the filter fails.
|
* @return string|boolean the filtered data, or FALSE if the filter fails.
|
||||||
*/
|
*/
|
||||||
public static function checkLink($check)
|
public static function checkLink($check)
|
||||||
{
|
{
|
||||||
@ -721,7 +753,7 @@ class SRSSTools
|
|||||||
/**
|
/**
|
||||||
* make a string XML-compatible
|
* make a string XML-compatible
|
||||||
* @param $check string to format
|
* @param $check string to format
|
||||||
* @return formated string
|
* @return string formatted string
|
||||||
* TODO CDATA ?
|
* TODO CDATA ?
|
||||||
*/
|
*/
|
||||||
public static function HTML4XML($check)
|
public static function HTML4XML($check)
|
||||||
@ -732,7 +764,7 @@ class SRSSTools
|
|||||||
/**
|
/**
|
||||||
* delete html tags
|
* delete html tags
|
||||||
* @param $check string to format
|
* @param $check string to format
|
||||||
* @return formated string
|
* @return string formatted string
|
||||||
*/
|
*/
|
||||||
public static function noHTML($check)
|
public static function noHTML($check)
|
||||||
{
|
{
|
||||||
@ -742,7 +774,7 @@ class SRSSTools
|
|||||||
/**
|
/**
|
||||||
* check if it's a day (in RSS terms)
|
* check if it's a day (in RSS terms)
|
||||||
* @param $check string to check
|
* @param $check string to check
|
||||||
* @return theday, or empty string
|
* @return string the day, or empty string
|
||||||
*/
|
*/
|
||||||
public static function checkDay($check)
|
public static function checkDay($check)
|
||||||
{
|
{
|
||||||
@ -753,7 +785,7 @@ class SRSSTools
|
|||||||
/**
|
/**
|
||||||
* check if it's an email
|
* check if it's an email
|
||||||
* @param $check string to check
|
* @param $check string to check
|
||||||
* @return the filtered data, or FALSE if the filter fails.
|
* @return string|boolean the filtered data, or FALSE if the filter fails.
|
||||||
*/
|
*/
|
||||||
public static function checkEmail($check)
|
public static function checkEmail($check)
|
||||||
{
|
{
|
||||||
@ -763,7 +795,7 @@ class SRSSTools
|
|||||||
/**
|
/**
|
||||||
* check if it's an hour (in RSS terms)
|
* check if it's an hour (in RSS terms)
|
||||||
* @param $check string to check
|
* @param $check string to check
|
||||||
* @return the filtered data, or FALSE if the filter fails.
|
* @return string|boolean the filtered data, or FALSE if the filter fails.
|
||||||
*/
|
*/
|
||||||
public static function checkHour($check)
|
public static function checkHour($check)
|
||||||
{
|
{
|
||||||
@ -780,7 +812,7 @@ class SRSSTools
|
|||||||
/**
|
/**
|
||||||
* check if it's an int
|
* check if it's an int
|
||||||
* @param $check int to check
|
* @param $check int to check
|
||||||
* @return the filtered data, or FALSE if the filter fails.
|
* @return int|boolean the filtered data, or FALSE if the filter fails.
|
||||||
*/
|
*/
|
||||||
public static function checkInt($check)
|
public static function checkInt($check)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user