1
0

HtmlFormat.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. $entries .= <<<EOD
  42. <section class="feeditem">
  43. <h2><a class="itemtitle" href="{$entryUri}">{$entryTitle}</a></h2>
  44. {$entryTimestamp}
  45. {$entryAuthor}
  46. {$entryContent}
  47. {$entryEnclosures}
  48. </section>
  49. EOD;
  50. }
  51. $charset = $this->getCharset();
  52. /* Data are prepared, now let's begin the "MAGIE !!!" */
  53. $toReturn = <<<EOD
  54. <!DOCTYPE html>
  55. <html>
  56. <head>
  57. <meta charset="{$charset}">
  58. <title>{$title}</title>
  59. <link href="css/HtmlFormat.css" rel="stylesheet">
  60. <meta name="robots" content="noindex, follow">
  61. </head>
  62. <body>
  63. <h1 class="pagetitle"><a href="{$uri}" target="_blank">{$title}</a></h1>
  64. <div class="buttons">
  65. <a href="./#bridge-{$_GET['bridge']}"><button class="backbutton">← back to rss-bridge</button></a>
  66. <a href="./?{$atomquery}"><button class="rss-feed">RSS feed (ATOM)</button></a>
  67. <a href="./?{$mrssquery}"><button class="rss-feed">RSS feed (MRSS)</button></a>
  68. </div>
  69. {$entries}
  70. </body>
  71. </html>
  72. EOD;
  73. // Remove invalid characters
  74. ini_set('mbstring.substitute_character', 'none');
  75. $toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
  76. return $toReturn;
  77. }
  78. public function display() {
  79. $this
  80. ->setContentType('text/html; charset=' . $this->getCharset())
  81. ->callContentType();
  82. return parent::display();
  83. }
  84. }