', '>', $str); if ($attr) $str = str_replace('"', '"', $str); return $str; } } class AtomFeed extends AtomBase { // public: // (string) Feed title var $title; // (string) Feed subtitle [optional] var $subtitle; // (array) List of links [optional] // Link: (array) href: URI, rel: Relation type [opt], type: Media type [opt], title: Title [opt] // Relations: alternate, related, self (the only interesting one), enclosure, via var $links; // (int) Updated timestamp var $updated; // (string) Author's name [optional] // (array) name: Author's name, email: E-mail address [opt], uri: Website [opt] var $author; // (string) Unique identifier var $category; // (string) Category var $id; // (string) Feed logo image [optional] var $logo; // (string) URI base [optional] var $base; // (string) Language [optional] var $lang; // (array) List of AtomEntry objects var $entries; // (bool) Add the feed generator's tag var $_showgenerator = true; var $_name = 'Unclassified AtomFeed Creator'; var $_version = '0.1'; var $_uri = 'http://unclassified.software'; // public: function AtomFeed() { $this->links = array(); $this->entries = array(); } function SendHTTPHeader() { header('Content-Type: application/atom+xml'); #header('Content-Type: text/xml'); #header('Content-Disposition: Inline; filename="unclassified-beta-news.atom"'); } function SendFeed() { echo $this->ToXML(); } function ToXML() { $xml = ''; $xml .= '' . "\n"; $base = ''; if ($this->base) $base = ' xml:base="' . trim($this->quote($this->base, true)) . '"'; $lang = ''; if ($this->lang) $lang = ' xml:lang="' . trim($this->quote($this->lang, true)) . '"'; $xml .= '' . "\n"; $xml .= ' ' . trim($this->quote($this->title)) . '' . "\n"; if ($this->subtitle) { if (is_array($this->subtitle)) { $type = ''; if ($this->subtitle['type']) $type = ' type="' . trim($this->quote($this->subtitle['type'], true)) . '"'; $xml .= ' ' . trim($this->quote($this->subtitle)) . '' . "\n"; } else { $xml .= ' ' . trim($this->quote($this->subtitle)) . '' . "\n"; } } if (is_array($this->links)) foreach ($this->links as $link) { $rel = ''; if ($link['rel']) $rel = ' rel="' . trim($this->quote($link['rel'], true)) . '"'; $type = ''; if ($link['type']) $type = ' type="' . trim($this->quote($link['type'], true)) . '"'; $title = ''; if ($link['title']) $title = ' title="' . trim($this->quote($link['title'], true)) . '"'; $xml .= ' ' . "\n"; } $updated = $this->updated; if (is_int($updated)) $updated = gmdate('Y-m-d\TH:i:s\Z', $updated); $xml .= ' ' . trim($this->quote($updated)) . '' . "\n"; // TODO: (see draft-ietf-atompub-format-11#4.2.2) // TODO: (see draft-ietf-atompub-format-11#4.2.10) if ($this->logo) // TODO $xml .= ' ' . "\n"; if ($this->author) { $xml .= ' ' . "\n"; if (is_array($this->author)) { $xml .= ' ' . trim($this->quote($this->author['name'])) . '' . "\n"; if ($this->author['email']) $xml .= ' ' . trim($this->quote($this->author['email'])) . '' . "\n"; if ($this->author['uri']) $xml .= ' ' . trim($this->quote($this->author['uri'])) . '' . "\n"; } else $xml .= ' ' . trim($this->quote($this->author)) . '' . "\n"; $xml .= ' ' . "\n"; } if ($this->category) { $xml .= ' ' . trim($this->quote($this->category)) . '' . "\n"; } $xml .= ' ' . trim($this->quote($this->id)) . '' . "\n"; if ($this->_showgenerator) $xml .= ' ' . trim($this->quote($this->_name)) . '' . "\n"; if (is_array($this->entries)) foreach ($this->entries as $entry) { $xml .= $entry->ToXML(); } $xml .= '' . "\n"; return $xml; } } class AtomEntry extends AtomBase { // public: // (string) Entry title var $title; // (array) List of links [optional] // Link: (array) href: URI, rel: Relation type [opt], type: Media type [opt], title: Title [opt] // Relations: alternate, related, self (the only interesting one), enclosure, via var $links; // (string) Author's name [optional] // (array) name: Author's name, email: E-mail address [opt], uri: Website [opt] var $author; // (int) Published timestamp [optional] var $published; // (int) Updated timestamp var $updated; // (string) Unique identifier var $id; // (string) Entry summary [optional] var $summary; // (array) type: Content type [opt], base: URI base [opt], lang: Language [opt], data: Actual data [optional] // Content types: text [default], html, xhtml var $content; // public: function AtomEntry() { $this->links = array(); } function ToXML() { $xml = ' ' . "\n"; $xml .= ' ' . trim($this->quote($this->title)) . '' . "\n"; if (is_array($this->links)) foreach ($this->links as $link) { $rel = ''; if ($link['rel']) $rel = ' rel="' . trim($this->quote($link['rel'], true)) . '"'; $type = ''; if ($link['type']) $type = ' type="' . trim($this->quote($link['type'], true)) . '"'; $title = ''; if ($link['title']) $title = ' title="' . trim($this->quote($link['title'], true)) . '"'; $xml .= ' ' . "\n"; } if ($this->author) { $xml .= ' ' . "\n"; if (is_array($this->author)) { $xml .= ' ' . trim($this->quote($this->author['name'])) . '' . "\n"; if ($this->author['email']) $xml .= ' ' . trim($this->quote($this->author['email'])) . '' . "\n"; if ($this->author['uri']) $xml .= ' ' . trim($this->quote($this->author['uri'])) . '' . "\n"; } else $xml .= ' ' . trim($this->quote($this->author)) . '' . "\n"; $xml .= ' ' . "\n"; } // TODO: if ($this->published) { $published = $this->published; if (is_int($published)) $published = gmdate('Y-m-d\TH:i:s\Z', $published); $xml .= ' ' . trim($this->quote($published)) . '' . "\n"; } $updated = $this->updated; if (is_int($updated)) $updated = gmdate('Y-m-d\TH:i:s\Z', $updated); $xml .= ' ' . trim($this->quote($updated)) . '' . "\n"; $xml .= ' ' . trim($this->quote($this->id)) . '' . "\n"; if ($this->summary) $xml .= ' ' . trim($this->quote($this->summary)) . '' . "\n"; if ($this->content) { $content = ''; if ($this->content['type'] == 'html') $content = trim($this->quote($this->content['data'])); elseif ($this->content['type'] == 'xhtml') $content = '
' . trim($this->content['data']) . '
'; else { $content = trim($this->quote($this->content['data'])); $this->content['type'] = 'text'; } $type = ''; if ($this->content['type']) $type = ' type="' . trim($this->quote($this->content['type'], true)) . '"'; $lang = ''; if ($this->content['lang']) $lang = ' xml:lang="' . trim($this->quote($this->content['lang'], true)) . '"'; $base = ''; if ($this->content['base']) $base = ' xml:base="' . trim($this->quote($this->content['base'], true)) . '"'; $xml .= ' ' . $content . '' . "\n"; } $xml .= '
' . "\n"; return $xml; } } ?>