HtmlFormat.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $entryContent = is_null($data->content) ? '' : '<p>' . $this->sanitizeHtml($data->content). '</p>';
  21. $entries .= <<<EOD
  22. <div class="feeditem">
  23. <h2><a href="{$entryUri}">{$entryTitle}</a></h2>
  24. {$entryTimestamp}
  25. {$entryContent}
  26. </div>
  27. EOD;
  28. }
  29. $styleCss = <<<'EOD'
  30. body{
  31. font-family:"Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;
  32. font-size:10pt;
  33. background-color:#aaa;
  34. background-image:linear-gradient(#eee, #aaa);
  35. background-attachment:fixed;
  36. }
  37. div.feeditem{border:1px solid black;padding:1em;margin:1em;background-color:#fff;}
  38. div.feeditem:hover { background-color:#ebf7ff; }
  39. h1 {border-bottom:dotted #bbb;margin:0 1em 1em 1em;}
  40. h2 {margin:0;}
  41. h2 a {color:black;text-decoration:none;}
  42. h2 a:hover {text-decoration:underline;}
  43. span.menu {margin-left:1em;}
  44. span.menu img {vertical-align:middle;}
  45. span.menu a { color:black; text-decoration:none; padding:0.4em; }
  46. span.menu a:hover { background-color:white; }
  47. EOD;
  48. /* Data are prepared, now let's begin the "MAGIE !!!" */
  49. $toReturn = <<<EOD
  50. <!DOCTYPE html>
  51. <html>
  52. <head>
  53. <meta charset="UTF-8">
  54. <title>{$title}</title>
  55. <style type="text/css">{$styleCss}</style>
  56. <meta name="robots" content="noindex, follow">
  57. </head>
  58. <body>
  59. <h1>{$title}</h1>
  60. <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>
  61. {$entries}
  62. </body>
  63. </html>
  64. EOD;
  65. return $toReturn;
  66. }
  67. public function display() {
  68. $this
  69. ->setContentType('text/html; charset=' . $this->getCharset())
  70. ->callContentType();
  71. return parent::display();
  72. }
  73. }