HtmlFormat.php 2.3 KB

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