[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/parser/ -> xhtmlsummary.php (source)

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