212 lines
4.8 KiB
PHP
212 lines
4.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* DomFramework
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework;
|
|
|
|
/**
|
|
* This class manage one RSS Item
|
|
*
|
|
* Called by Rss
|
|
*/
|
|
class RssItem
|
|
{
|
|
/**
|
|
* The title of the item
|
|
*/
|
|
private $title;
|
|
|
|
/**
|
|
* The URL of the item
|
|
*/
|
|
private $link;
|
|
|
|
/**
|
|
* The item synopsis
|
|
*/
|
|
private $description;
|
|
|
|
/**
|
|
* Email address of the author of the item
|
|
*/
|
|
private $author;
|
|
|
|
/**
|
|
* URL of a page for comments relating to the item
|
|
*/
|
|
private $comments;
|
|
|
|
/**
|
|
* A string that uniquely identifies the item
|
|
*/
|
|
private $guid;
|
|
|
|
/**
|
|
* Indicates when the item was published
|
|
*/
|
|
private $pubDate;
|
|
|
|
/**
|
|
* Get/Set the value
|
|
* @param string|null $title The title to get/set
|
|
*/
|
|
public function title($title = null)
|
|
{
|
|
if ($title === null) {
|
|
return $this->title;
|
|
}
|
|
if (! is_string($title)) {
|
|
throw new \Exception("Title provided to RSS Item is not a string", 500);
|
|
}
|
|
if ($title === "") {
|
|
$title = null;
|
|
}
|
|
$this->title = $title;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get/Set the value
|
|
* @param string|null $link The link to get/set
|
|
*/
|
|
public function link($link = null)
|
|
{
|
|
if ($link === null) {
|
|
return $this->link;
|
|
}
|
|
if (! is_string($link)) {
|
|
throw new \Exception("Link provided to RSS Item is not a string", 500);
|
|
}
|
|
$verify = new Verify();
|
|
if (! $verify->is_URL($link)) {
|
|
throw new \Exception("Link provided to RSS Item is not an URL", 500);
|
|
}
|
|
if ($link === "") {
|
|
$link = null;
|
|
}
|
|
$this->link = $link;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get/Set the value
|
|
* @param string|null $description The description to get/set
|
|
*/
|
|
public function description($description = null)
|
|
{
|
|
if ($description === null) {
|
|
return $this->description;
|
|
}
|
|
if (! is_string($description)) {
|
|
throw new \Exception(
|
|
"Description provided to RSS Item is not a string",
|
|
500
|
|
);
|
|
}
|
|
if ($description === "") {
|
|
$description = null;
|
|
}
|
|
$this->description = $description;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get/Set the value
|
|
* @param string|null $author The author to get/set
|
|
*/
|
|
public function author($author = null)
|
|
{
|
|
if ($author === null) {
|
|
return $this->author;
|
|
}
|
|
if (! is_string($author)) {
|
|
throw new \Exception("Author provided to RSS Item is not a string", 500);
|
|
}
|
|
if ($author === "") {
|
|
$author = null;
|
|
}
|
|
$this->author = $author;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get/Set the value
|
|
* @param string|null $comments The comments to get/set
|
|
*/
|
|
public function comments($comments = null)
|
|
{
|
|
if ($comments === null) {
|
|
return $this->comments;
|
|
}
|
|
if (! is_string($comments)) {
|
|
throw new \Exception(
|
|
"Comments provided to RSS Item is not a string",
|
|
500
|
|
);
|
|
}
|
|
if ($comments === "") {
|
|
$comments = null;
|
|
}
|
|
$this->comments = $comments;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get/Set the value
|
|
* @param string|null $guid The guid to get/set
|
|
*/
|
|
public function guid($guid = null)
|
|
{
|
|
if ($guid === null) {
|
|
return $this->guid;
|
|
}
|
|
if (! is_string($guid)) {
|
|
throw new \Exception("GUID provided to RSS Item is not a string", 500);
|
|
}
|
|
if ($guid === "") {
|
|
$guid = null;
|
|
}
|
|
$this->guid = $guid;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get/Set the value
|
|
* @param string|null $pubDate The pubDate to get/set
|
|
*/
|
|
public function pubDate($pubDate = null)
|
|
{
|
|
if ($pubDate === null) {
|
|
return $this->pubDate;
|
|
}
|
|
if (! is_string($pubDate)) {
|
|
throw new \Exception(
|
|
"pubDate provided to RSS Item is not a string",
|
|
500
|
|
);
|
|
}
|
|
if (! Verify::staticIs_datetimeSQL($pubDate)) {
|
|
throw new \Exception(
|
|
"pubDate provided to RSS Item is not a valid date",
|
|
500
|
|
);
|
|
}
|
|
if ($pubDate === "") {
|
|
$pubDate = null;
|
|
} else {
|
|
$pubDate = Convert::convertDate(
|
|
$pubDate,
|
|
"Y-m-d H:i:s",
|
|
\DateTime::RFC2822
|
|
);
|
|
}
|
|
$this->pubDate = $pubDate;
|
|
return $this;
|
|
}
|
|
}
|