HtmlFormat.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. $entries = '';
  15. foreach($this->getDatas() as $data){
  16. $entryUri = is_null($data->uri) ? $uri : $data->uri;
  17. $entryTitle = is_null($data->title) ? '' : htmlspecialchars(strip_tags($data->title));
  18. $entryTimestamp = is_null($data->timestamp) ? '' : '<small>' . date(DATE_ATOM, $data->timestamp) . '</small>';
  19. $entryContent = is_null($data->content) ? '' : '<p>' . $data->content . '</p>';
  20. $entries .= <<<EOD
  21. <div class="rssitem">
  22. <h2><a href="{$entryUri}">{$entryTitle}</a></h2>
  23. {$entryTimestamp}
  24. {$entryContent}
  25. </div>
  26. EOD;
  27. }
  28. $styleCss = <<<'EOD'
  29. body{font-family:"Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;font-size:10pt;background-color:#aaa;}div.rssitem{border:1px solid black;padding:5px;margin:10px;background-color:#fff;}
  30. EOD;
  31. /* Data are prepared, now let's begin the "MAGIE !!!" */
  32. $toReturn = <<<EOD
  33. <html>
  34. <head>
  35. <title>{$title}</title>
  36. <style type="text/css">{$styleCss}</style>
  37. </head>
  38. <body>
  39. <h1>{$title}</h1>
  40. {$entries}
  41. </body>
  42. </html>
  43. EOD;
  44. return $toReturn;
  45. }
  46. public function display(){
  47. $this
  48. ->setContentType('text/html; charset=' . $this->getCharset())
  49. ->callContentType();
  50. return parent::display();
  51. }
  52. }