HtmlFormat.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Html
  4. * Documentation Source http://en.wikipedia.org/wiki/Atom_%28standard%29 and http://tools.ietf.org/html/rfc4287
  5. *
  6. * @name Html
  7. */
  8. class HtmlFormat extends FormatAbstract{
  9. public function stringify(){
  10. /* Datas preparation */
  11. $extraInfos = $this->getExtraInfos();
  12. $title = htmlspecialchars($extraInfos['name']);
  13. $uri = htmlspecialchars($extraInfos['uri']);
  14. $atomquery = str_replace('format=HtmlFormat', 'format=AtomFormat', htmlentities($_SERVER['QUERY_STRING']));
  15. $entries = '';
  16. foreach($this->getDatas() as $data){
  17. $entryUri = is_null($data->uri) ? $uri : $data->uri;
  18. $entryTitle = is_null($data->title) ? '' : $this->sanitizeHtml(strip_tags($data->title));
  19. $entryTimestamp = is_null($data->timestamp) ? '' : '<small><time datetime="' . date(DATE_ATOM, $data->timestamp) . '">' . date(DATE_ATOM, $data->timestamp) . '</time></small>';
  20. $entryAuthor = is_null($data->author) ? '' : '<br><small>by: ' . $data->author . '</small>';
  21. $entryContent = is_null($data->content) ? '' : '<p>' . $this->sanitizeHtml($data->content). '</p>';
  22. $entries .= <<<EOD
  23. <div class="feeditem">
  24. <h2><a href="{$entryUri}">{$entryTitle}</a></h2>
  25. {$entryTimestamp}
  26. {$entryAuthor}
  27. {$entryContent}
  28. </div>
  29. EOD;
  30. }
  31. $styleCss = <<<'EOD'
  32. body{
  33. font-family:"Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;
  34. font-size:10pt;
  35. background-color:#aaa;
  36. background-image:linear-gradient(#eee, #aaa);
  37. background-attachment:fixed;
  38. }
  39. div.feeditem{border:1px solid black;padding:1em;margin:1em;background-color:#fff;}
  40. div.feeditem:hover { background-color:#ebf7ff; }
  41. h1 {border-bottom:dotted #bbb;margin:0 1em 1em 1em;}
  42. h2 {margin:0;}
  43. h2 a {color:black;text-decoration:none;}
  44. h2 a:hover {text-decoration:underline;}
  45. span.menu {margin-left:1em;}
  46. span.menu img {vertical-align:middle;}
  47. span.menu a { color:black; text-decoration:none; padding:0.4em; }
  48. span.menu a:hover { background-color:white; }
  49. EOD;
  50. /* Data are prepared, now let's begin the "MAGIE !!!" */
  51. $toReturn = <<<EOD
  52. <!DOCTYPE html>
  53. <html>
  54. <head>
  55. <meta charset="UTF-8">
  56. <title>{$title}</title>
  57. <style type="text/css">{$styleCss}</style>
  58. <meta name="robots" content="noindex, follow">
  59. </head>
  60. <body>
  61. <h1>{$title}</h1>
  62. <span class="menu"><a href="./" onclick="window.history.back()">← back to rss-bridge</a> <a title="Get the ATOM feed" href="./?{$atomquery}"><img alt="feed" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZAgMAAAC5h23wAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJUExURf+cCv/8+P/OhD2VurcAAAABdFJOU/4a4wd9AAAAbklEQVQI13XOMQ6AIAwFUGzCgLtHYPEUHMHBTwgTRyFOXoDdUT2ltCKbXV6b/iZV6qcMYmY1EJtw3MwFQRJU/Bfl6VaEzENQxbHIUxKTrY4Xgk4ct0EvcrYa9iTPGrxqbE3XHWSfRfIk1trp6O8+R38aBYbaAE4AAAAASUVORK5CYII="></a></span>
  63. {$entries}
  64. </body>
  65. </html>
  66. EOD;
  67. return $toReturn;
  68. }
  69. public function display() {
  70. $this
  71. ->setContentType('text/html; charset=' . $this->getCharset())
  72. ->callContentType();
  73. return parent::display();
  74. }
  75. }