xhtmlsummary.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * The summary XHTML form selects either up to the first two paragraphs
  4. * it find in a page or the first section (whichever comes first)
  5. * It strips out the table of contents if one exists
  6. * Section divs are not used - everything should be nested in a single
  7. * div with CSS class "page"
  8. * Headings have their a name link removed and section editing links
  9. * removed
  10. * It also attempts to capture the first heading in a page for
  11. * use as the title of the page.
  12. *
  13. *
  14. * @author Harry Fuecks <hfuecks@gmail.com>
  15. * @todo Is this currently used anywhere? Should it?
  16. */
  17. class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml {
  18. // Namespace these variables to
  19. // avoid clashes with parent classes
  20. protected $sum_paragraphs = 0;
  21. protected $sum_capture = true;
  22. protected $sum_inSection = false;
  23. protected $sum_summary = '';
  24. protected $sum_pageTitle = false;
  25. /** @inheritdoc */
  26. public function document_start() {
  27. $this->doc .= DOKU_LF.'<div>'.DOKU_LF;
  28. }
  29. /** @inheritdoc */
  30. public function document_end() {
  31. $this->doc = $this->sum_summary;
  32. $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
  33. }
  34. /** @inheritdoc */
  35. public function header($text, $level, $pos) {
  36. if ( !$this->sum_pageTitle ) {
  37. $this->info['sum_pagetitle'] = $text;
  38. $this->sum_pageTitle = true;
  39. }
  40. $this->doc .= DOKU_LF.'<h'.$level.'>';
  41. $this->doc .= $this->_xmlEntities($text);
  42. $this->doc .= "</h$level>".DOKU_LF;
  43. }
  44. /** @inheritdoc */
  45. public function section_open($level) {
  46. if ( $this->sum_capture ) {
  47. $this->sum_inSection = true;
  48. }
  49. }
  50. /** @inheritdoc */
  51. public function section_close() {
  52. if ( $this->sum_capture && $this->sum_inSection ) {
  53. $this->sum_summary .= $this->doc;
  54. $this->sum_capture = false;
  55. }
  56. }
  57. /** @inheritdoc */
  58. public function p_open() {
  59. if ( $this->sum_capture && $this->sum_paragraphs < 2 ) {
  60. $this->sum_paragraphs++;
  61. }
  62. parent :: p_open();
  63. }
  64. /** @inheritdoc */
  65. public function p_close() {
  66. parent :: p_close();
  67. if ( $this->sum_capture && $this->sum_paragraphs >= 2 ) {
  68. $this->sum_summary .= $this->doc;
  69. $this->sum_capture = false;
  70. }
  71. }
  72. }
  73. //Setup VIM: ex: et ts=2 :