1<?php 2 3/** 4 * AtomCreator03 is a FeedCreator that implements the atom specification, 5 * as in http://www.intertwingly.net/wiki/pie/FrontPage. 6 * Please note that just by using AtomCreator03 you won't automatically 7 * produce valid atom files. For example, you have to specify either an editor 8 * for the feed or an author for every single feed item. 9 * Some elements have not been implemented yet. These are (incomplete list): 10 * author URL, item author's email and URL, item contents, alternate links, 11 * other link content types than text/html. Some of them may be created with 12 * AtomCreator03::additionalElements. 13 * 14 * @see FeedCreator#additionalElements 15 * @since 1.6 16 * @author Kai Blankenhorn <kaib@bitfolge.de>, Scott Reynen <scott@randomchaos.com> 17 * @package de.bitfolge.feedcreator 18 */ 19class AtomCreator03 extends FeedCreator 20{ 21 22 /** 23 * AtomCreator03 constructor. 24 */ 25 public function __construct() 26 { 27 $this->contentType = "application/atom+xml"; 28 $this->encoding = "utf-8"; 29 } 30 31 /** @inheritdoc */ 32 public function createFeed() 33 { 34 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; 35 $feed .= $this->_createGeneratorComment(); 36 $feed .= $this->_createStylesheetReferences(); 37 $feed .= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\""; 38 if ($this->format == 'TOOLBAR') { 39 $feed .= " xmlns:gtb=\"http://toolbar.google.com/custombuttons/\""; 40 } 41 if ($this->language != "") { 42 $feed .= " xml:lang=\"".$this->language."\""; 43 } 44 $feed .= ">\n"; 45 $feed .= " <title>".htmlspecialchars($this->title)."</title>\n"; 46 $feed .= " <tagline>".htmlspecialchars($this->description)."</tagline>\n"; 47 $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n"; 48 $feed .= " <id>".htmlspecialchars($this->link)."</id>\n"; 49 $now = new FeedDate(); 50 $feed .= " <modified>".htmlspecialchars($now->iso8601())."</modified>\n"; 51 if ($this->editor != "") { 52 $feed .= " <author>\n"; 53 $feed .= " <name>".$this->editor."</name>\n"; 54 if ($this->editorEmail != "") { 55 $feed .= " <email>".$this->editorEmail."</email>\n"; 56 } 57 $feed .= " </author>\n"; 58 } 59 $feed .= " <generator>".FEEDCREATOR_VERSION."</generator>\n"; 60 $feed .= $this->_createAdditionalElements($this->additionalElements, " "); 61 for ($i = 0; $i < count($this->items); $i++) { 62 $feed .= " <entry>\n"; 63 $feed .= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n"; 64 $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars( 65 $this->items[$i]->link 66 )."\"/>\n"; 67 if ($this->items[$i]->date == "") { 68 $this->items[$i]->date = time(); 69 } 70 $itemDate = new FeedDate($this->items[$i]->date); 71 $feed .= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n"; 72 $feed .= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n"; 73 $feed .= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n"; 74 $feed .= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n"; 75 $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); 76 if ($this->items[$i]->author != "") { 77 $feed .= " <author>\n"; 78 $feed .= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n"; 79 $feed .= " </author>\n"; 80 } 81 if ($this->items[$i]->description != "") { 82 $feed .= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n"; 83 } 84 if (isset($this->items[$i]->thumbdata)) { 85 $feed .= " <gtb:icon mode=\"base64\" type=\"image/jpeg\">\n"; 86 $feed .= chunk_split(base64_encode($this->items[$i]->thumbdata))."\n"; 87 $feed .= " </gtb:icon>\n"; 88 } 89 $feed .= " </entry>\n"; 90 } 91 $feed .= "</feed>\n"; 92 93 return $feed; 94 } 95} 96