HtmlFormat.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. $entryEnclosures = '';
  29. if(isset($item['enclosures'])) {
  30. $entryEnclosures = '<div class="attachments"><p>Attachments:</p>';
  31. foreach($item['enclosures'] as $enclosure) {
  32. $url = $this->sanitizeHtml($enclosure);
  33. $entryEnclosures .= '<li class="enclosure"><a href="'
  34. . $url
  35. . '">'
  36. . substr($url, strrpos($url, '/') + 1)
  37. . '</a></li>';
  38. }
  39. $entryEnclosures .= '</div>';
  40. }
  41. $entryCategories = '';
  42. if(isset($item['categories']) && count($item['categories']) > 0) {
  43. $entryCategories = '<div class="categories"><p>Categories:</p>';
  44. foreach($item['categories'] as $category) {
  45. $entryCategories .= '<li class="category">'
  46. . $this->sanitizeHtml($category)
  47. . '</li>';
  48. }
  49. $entryCategories .= '</div>';
  50. }
  51. $entries .= <<<EOD
  52. <section class="feeditem">
  53. <h2><a class="itemtitle" href="{$entryUri}">{$entryTitle}</a></h2>
  54. {$entryTimestamp}
  55. {$entryAuthor}
  56. {$entryContent}
  57. {$entryEnclosures}
  58. {$entryCategories}
  59. </section>
  60. EOD;
  61. }
  62. $charset = $this->getCharset();
  63. /* Data are prepared, now let's begin the "MAGIE !!!" */
  64. $toReturn = <<<EOD
  65. <!DOCTYPE html>
  66. <html>
  67. <head>
  68. <meta charset="{$charset}">
  69. <title>{$title}</title>
  70. <link href="static/HtmlFormat.css" rel="stylesheet">
  71. <meta name="robots" content="noindex, follow">
  72. </head>
  73. <body>
  74. <h1 class="pagetitle"><a href="{$uri}" target="_blank">{$title}</a></h1>
  75. <div class="buttons">
  76. <a href="./#bridge-{$_GET['bridge']}"><button class="backbutton">← back to rss-bridge</button></a>
  77. <a href="./?{$atomquery}"><button class="rss-feed">RSS feed (ATOM)</button></a>
  78. <a href="./?{$mrssquery}"><button class="rss-feed">RSS feed (MRSS)</button></a>
  79. </div>
  80. {$entries}
  81. </body>
  82. </html>
  83. EOD;
  84. // Remove invalid characters
  85. ini_set('mbstring.substitute_character', 'none');
  86. $toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
  87. return $toReturn;
  88. }
  89. public function display() {
  90. $this
  91. ->setContentType('text/html; charset=' . $this->getCharset())
  92. ->callContentType();
  93. return parent::display();
  94. }
  95. }