HtmlFormat.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. class HtmlFormat extends FormatAbstract {
  3. public function stringify(){
  4. $extraInfos = $this->getExtraInfos();
  5. $title = htmlspecialchars($extraInfos['name']);
  6. $uri = htmlspecialchars($extraInfos['uri']);
  7. $atomquery = str_replace('format=Html', 'format=Atom', htmlentities($_SERVER['QUERY_STRING']));
  8. $mrssquery = str_replace('format=Html', 'format=Mrss', htmlentities($_SERVER['QUERY_STRING']));
  9. $entries = '';
  10. foreach($this->getItems() as $item){
  11. $entryAuthor = isset($item['author']) ? '<br /><p class="author">by: ' . $item['author'] . '</p>' : '';
  12. $entryTitle = isset($item['title']) ? $this->sanitizeHtml(strip_tags($item['title'])) : '';
  13. $entryUri = isset($item['uri']) ? $item['uri'] : $uri;
  14. $entryTimestamp = '';
  15. if(isset($item['timestamp'])){
  16. $entryTimestamp = '<time datetime="'
  17. . date(DATE_ATOM, $item['timestamp'])
  18. . '">'
  19. . date(DATE_ATOM, $item['timestamp'])
  20. . '</time>';
  21. }
  22. $entryContent = '';
  23. if(isset($item['content'])){
  24. $entryContent = '<div class="content">'
  25. . $this->sanitizeHtml($item['content'])
  26. . '</div>';
  27. }
  28. $entries .= <<<EOD
  29. <section class="feeditem">
  30. <h2><a class="itemtitle" href="{$entryUri}">{$entryTitle}</a></h2>
  31. {$entryTimestamp}
  32. {$entryAuthor}
  33. {$entryContent}
  34. </section>
  35. EOD;
  36. }
  37. $charset = $this->getCharset();
  38. /* Data are prepared, now let's begin the "MAGIE !!!" */
  39. $toReturn = <<<EOD
  40. <!DOCTYPE html>
  41. <html>
  42. <head>
  43. <meta charset="{$charset}">
  44. <title>{$title}</title>
  45. <link href="css/HtmlFormat.css" rel="stylesheet">
  46. <meta name="robots" content="noindex, follow">
  47. </head>
  48. <body>
  49. <h1 class="pagetitle"><a href="{$uri}" target="_blank">{$title}</a></h1>
  50. <div class="buttons">
  51. <a href="./#bridge-{$_GET['bridge']}"><button class="backbutton">← back to rss-bridge</button></a>
  52. <a href="./?{$atomquery}"><button class="rss-feed">RSS feed (ATOM)</button></a>
  53. <a href="./?{$mrssquery}"><button class="rss-feed">RSS feed (MRSS)</button></a>
  54. </div>
  55. {$entries}
  56. </body>
  57. </html>
  58. EOD;
  59. // Remove invalid characters
  60. ini_set('mbstring.substitute_character', 'none');
  61. $toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
  62. return $toReturn;
  63. }
  64. public function display() {
  65. $this
  66. ->setContentType('text/html; charset=' . $this->getCharset())
  67. ->callContentType();
  68. return parent::display();
  69. }
  70. }