HtmlFormat.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /* Data are prepared, now let's begin the "MAGIE !!!" */
  38. $toReturn = <<<EOD
  39. <!DOCTYPE html>
  40. <html>
  41. <head>
  42. <meta charset="UTF-8">
  43. <title>{$title}</title>
  44. <link href="css/HtmlFormat.css" rel="stylesheet">
  45. <meta name="robots" content="noindex, follow">
  46. </head>
  47. <body>
  48. <h1 class="pagetitle"><a href="{$uri}" target="_blank">{$title}</a></h1>
  49. <div class="buttons">
  50. <a href="./#bridge-{$_GET['bridge']}"><button class="backbutton">← back to rss-bridge</button></a>
  51. <a href="./?{$atomquery}"><button class="rss-feed">RSS feed (ATOM)</button></a>
  52. <a href="./?{$mrssquery}"><button class="rss-feed">RSS feed (MRSS)</button></a>
  53. </div>
  54. {$entries}
  55. </body>
  56. </html>
  57. EOD;
  58. return $toReturn;
  59. }
  60. public function display() {
  61. $this
  62. ->setContentType('text/html; charset=' . $this->getCharset())
  63. ->callContentType();
  64. return parent::display();
  65. }
  66. }