xml_encode($urlPrefix . $urlHost . $urlRequest); $extraInfos = $this->getExtraInfos(); $title = $this->xml_encode($extraInfos['name']); $icon = $extraInfos['icon']; if(!empty($extraInfos['uri'])) { $uri = $this->xml_encode($extraInfos['uri']); } else { $uri = REPOSITORY; } $items = ''; foreach($this->getItems() as $item) { $itemTimestamp = $item->getTimestamp(); $itemTitle = $this->xml_encode($item->getTitle()); $itemUri = $this->xml_encode($item->getURI()); $itemContent = $this->xml_encode($this->sanitizeHtml($item->getContent())); $entryID = $item->getUid(); $isPermaLink = 'false'; if (empty($entryID) && !empty($itemUri)) { // Fallback to provided URI $entryID = $itemUri; $isPermaLink = 'true'; } if (empty($entryID)) // Fallback to title and content $entryID = hash('sha1', $itemTitle . $itemContent); $entryTitle = ''; if (!empty($itemTitle)) $entryTitle = '' . $itemTitle . ''; $entryLink = ''; if (!empty($itemUri)) $entryLink = '' . $itemUri . ''; $entryPublished = ''; if (!empty($itemTimestamp)) { $entryPublished = '' . $this->xml_encode(gmdate(DATE_RFC2822, $itemTimestamp)) . ''; } $entryDescription = ''; if (!empty($itemContent)) $entryDescription = '' . $itemContent . ''; $entryEnclosures = ''; foreach($item->getEnclosures() as $enclosure) { $entryEnclosures .= '' . PHP_EOL; } $entryCategories = ''; foreach($item->getCategories() as $category) { $entryCategories .= '' . $category . '' . PHP_EOL; } $items .= << {$entryTitle} {$entryLink} {$entryID} {$entryPublished} {$entryDescription} {$entryEnclosures} {$entryCategories} EOD; } $charset = $this->getCharset(); $feedImage = ''; if (!empty($icon) && in_array(substr($icon, -4), self::ALLOWED_IMAGE_EXT)) { $feedImage .= << {$icon} {$title} {$uri} EOD; } /* Data are prepared, now let's begin the "MAGIE !!!" */ $toReturn = << {$title} {$uri} {$title} {$feedImage} {$items} EOD; // Remove invalid non-UTF8 characters ini_set('mbstring.substitute_character', 'none'); $toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8'); return $toReturn; } public function display(){ $this ->setContentType(self::MIME_TYPE . '; charset=' . $this->getCharset()) ->callContentType(); return parent::display(); } private function xml_encode($text){ return htmlspecialchars($text, ENT_XML1); } }