open) return false; $this->open = true; $language = lang_base(Config::current()->locale); $feed = ''."\n"; $feed.= ''. "\n"; $feed.= ''.fix($title).''."\n"; if (!empty($subtitle)) $feed.= ''.fix($subtitle).''."\n"; $feed.= ''.fix(oneof($id, self_url())).''."\n"; $feed.= ''. when(DATE_ATOM, oneof($updated, time())). ''. "\n"; $feed.= ''. "\n"; $feed.= ''. CHYRP_IDENTITY. ''. "\n"; $this->xml = array( "feed" => $feed, "items" => array() ); return $this->open = true; } /** * Function: entry * Adds an individual feed entry. * * Parameters: * $title - Title for this entry. * $id - The unique ID. * $content - Content for this entry. * $link - The URL to the resource. * $published - Time of creation. * $updated - Time of update (optional). * $name - Name of the author (optional). * $uri - URI of the author (optional). * $email - Email address of the author (optional). * * Notes: * The entry remains open to allow triggered insertions. */ public function entry( $title, $id, $content, $link, $published, $updated = null, $name = "", $uri = "", $email = "" ): bool { if (!$this->open) return false; $this->count++; $entry = ''. fix($title, false, true). ''. "\n"; $entry.= ''.fix($id).''."\n"; $entry.= ''. when(DATE_ATOM, oneof($updated, $published)). ''. "\n"; $entry.= ''. when(DATE_ATOM, $published). ''. "\n"; $entry.= ''. "\n"; $entry.= ''."\n"; $entry.= ''. fix(oneof($name, __("Guest"))). ''. "\n"; if (!empty($uri) and is_url($uri)) $entry.= ''.fix($uri).''."\n"; if (!empty($email) and is_email($email)) $entry.= ''.fix($email).''."\n"; $entry.= ''."\n"; $entry.= ''. fix($content, false, true). ''. "\n"; $item = $this->count - 1; $this->xml["items"][$item] = $entry; return true; } /** * Function: category * Adds a category element for an entry or feed. * * Parameters: * $term - String that identifies the category. * $scheme - URI for the categorization scheme (optional). * $label - Human-readable label for the category (optional). */ public function category( $term, $scheme = "", $label = "" ): bool { if (!$this->open) return false; $category = 'count) { $this->xml["feed"].= $category; } else { $item = $this->count - 1; $this->xml["items"][$item].= $category; } return true; } /** * Function: rights * Adds a rights element for an entry or feed. * * Parameters: * $text - Human-readable licensing information. */ public function rights( $text ): bool { if (!$this->open) return false; $rights = ''. fix($text, false, true). ''. "\n"; if (!$this->count) { $this->xml["feed"].= $rights; } else { $item = $this->count - 1; $this->xml["items"][$item].= $rights; } return true; } /** * Function: enclosure * Adds a link element for a resource that is potentially large in size. * * Parameters: * $link - The URL to the resource. * $length - Size in bytes of the resource (optional). * $type - The media type of the resource (optional). * $title - Title for the resource (optional). */ public function enclosure( $link, $length = null, $type = "", $title = "" ): bool { if (!$this->open) return false; $enclosure = 'count) { $this->xml["feed"].= $enclosure; } else { $item = $this->count - 1; $this->xml["items"][$item].= $enclosure; } return true; } /** * Function: related * Adds a link element for a resource related to an entry or feed. * * Parameters: * $link - The URL to the resource. */ public function related( $link ): bool { if (!$this->open) return false; if (empty($link) or !is_url($link)) return false; $related = ''. "\n"; if (!$this->count) { $this->xml["feed"].= $related; } else { $item = $this->count - 1; $this->xml["items"][$item].= $related; } return true; } /** * Function: feed * Returns the generated feed. */ public function feed(): string { $feed = $this->xml["feed"]; $items = $this->xml["items"]; foreach ($items as $item) { $feed.= ''."\n". $item. ''."\n"; } $feed.= ''."\n"; return $feed; } /** * Function: output * Displays the generated feed. */ public function display(): bool { if (headers_sent()) return false; header("Content-Type: ".self::type()."; charset=UTF-8"); echo $this->feed(); return true; } }