11 require_once(
"XMLDocument.php");
13 define(
'ATOM_XMLNS',
'http://www.w3.org/2005/Atom');
14 define(
'XHTML_XMLNS',
'http://www.w3.org/1999/xhtml');
29 private $content_string;
31 function __construct($xhtml) {
32 $this->content_string = $xhtml;
35 function Render( $ignore1, $ignore2, $ignore3 ) {
36 return $this->content_string .
"\n";
61 function __construct(
$id, $title, $published, $updated ) {
62 $this->nodes = array(
'id',
'title',
'updated' );
65 public function setId( $new_value ) {
66 $this->
id =
new XMLElement(
'id', rtrim($new_value,
"\r\n"));
70 public function setTitle( $new_value, $type =
'text' ) {
71 $this->title =
new XMLElement(
'title', $new_value, array(
'type' => $type ));
75 public static function setDate( $tagname, $epoch ) {
77 return new XMLElement($tagname, date(
'Y-m-d\TH:i:sP',$epoch));
80 public function setDateModified( $epoch ) {
81 $this->updated = self::setDate(
'updated', $epoch);
82 return $this->updated;
85 public function setDateCreated( $epoch ) {
86 $node = self::setDate(
'published', $epoch);
87 $this->nodes[] = $node;
91 public function setLink( $new_value, $type=
"text/calendar", $rel=
'alternate' ) {
92 return $this->addNode(
'link', $new_value, array(
'rel' => $rel,
'type' => $type ) );
95 public function addAuthor( $new_value ) {
96 if ( is_array($new_value) && isset($new_value[
'name']) ) {
97 $author = $this->addNode(
'author' );
98 foreach( $new_value AS $k => $v ) {
99 $author->NewElement($k, $v);
103 throw new Exception(
"AtomFeed::addAuthor(\$new_value) the \$new_value MUST be an array with at least a 'name' element. RFC4287-3.2");
107 public function addCategory( $new_value ) {
108 if ( is_array($new_value) && isset($new_value[
'term']) ) {
109 $category = $this->addNode(
'category', null, $new_value );
112 throw new Exception(
"AtomFeed::addCategory(\$new_value) the \$new_value MUST be an array with at least a 'term' element, and potentially a 'scheme' and a 'label' element. RFC4287-4.2.2");
116 public function setDescription( $new_value, $type =
'text' ) {
117 return $this->addNode(
'summary', $new_value, array(
'type' => $type ) );
120 public function setContent( $new_value, $type =
'xhtml' ) {
121 $content = $this->addNode(
'content', null, array(
'type' => $type ) );
122 if ( $type ==
'xhtml' ) {
123 $content->NewElement(
'div', array(
new AtomXHTMLContent($new_value) ), array(
'xmlns' => XHTML_XMLNS));
126 $content->SetContent($new_value);
131 public function addNode( $in_tag, $content=
false, $attributes=
false, $xmlns=null ) {
132 $node =
new XMLElement($in_tag,$content,$attributes,$xmlns);
133 if ( !isset($node) )
return null;
134 $this->nodes[] = $node;
138 public function getXML() {
140 $this->nodes[1] = $this->title;
141 $this->nodes[2] = $this->updated;
154 public function __construct() {
156 parent::__construct( array( ATOM_XMLNS => null, XHTML_XMLNS =>
'xhtml' ) );
157 $this->title =
'DAViCal Atom Feed';
158 $this->nodes = array(
'id',
'title',
'updated',
159 new XMLElement(
'generator',
'DAViCal', array(
'uri' =>
'https://www.davical.org/',
'version' => $c->version_string ) )
177 public function setId( $new_value ) {
178 $this->
id = $this->NewXMLElement(
'id', $new_value);
182 public function setTitle( $new_value, $type =
'text' ) {
183 $this->title = $this->NewXMLElement(
'title', $new_value, array(
'type' => $type ));
187 public function setDateModified( $epoch ) {
188 $this->updated = AtomEntry::setDate(
'updated', $epoch);
189 return $this->updated;
192 public function setLink( $new_value, $type=
"text/calendar", $rel=
'alternate' ) {
193 return $this->addNode(
'link', $new_value, array(
'rel' => $rel,
'type' => $type ) );
205 $this->setId($new_value);
206 return $this->setLink($new_value ,
'application/atom+xml',
'self' );
209 public function addAuthor( $new_value ) {
210 if ( is_array($new_value) && isset($new_value[
'name']) ) {
211 $author = $this->addNode(
'author' );
212 foreach( $new_value AS $k => $v ) {
213 $this->NSElement($author, $k, $v);
217 throw new Exception(
"AtomFeed::addAuthor(\$new_value) the \$new_value MUST be an array with at leas a 'name' element. RFC4287-3.2");
221 public function setDescription( $new_value, $type =
'text' ) {
222 return $this->addNode(
'subtitle', $new_value, array(
'type' => $type ) );
225 public function addNode( $in_tag, $content=
false, $attributes=
false, $xmlns=null ) {
226 $node = $this->NewXMLElement($in_tag,$content,$attributes,$xmlns);
227 if ( !isset($node) )
return null;
228 $this->nodes[] = $node;
232 public function addEntry( $new_entry ) {
233 if ( !isset($new_entry) )
return;
234 $this->nodes[] =
new XMLElement(
'entry', $new_entry->getXML() );
237 public function createEntry( $id=null, $title=null, $published=null, $updated=null ) {
238 return new AtomEntry($id,$title,$published,$updated);
241 public function export( $format=
'atom' ) {
242 if ( $format !=
'atom' )
throw new Exception(
"AtomFeed class only supports creation of Atom 1.0 format feeds.");
243 $this->nodes[0] = $this->id;
244 $this->nodes[1] = $this->title;
245 $this->nodes[2] = $this->updated;
246 return $this->Render(
'feed', $this->nodes );
setFeedLink($new_value, $type=null)