Source for file StrictBlockquote.php

Documentation is available at StrictBlockquote.php

  1. <?php
  2.  
  3. /**
  4.  * Takes the contents of blockquote when in strict and reformats for validation.
  5.  */
  6. {
  7.     protected $real_elements;
  8.     protected $fake_elements;
  9.     public $allow_empty = true;
  10.     public $type = 'strictblockquote';
  11.     protected $init = false;
  12.     public function validateChildren($tokens_of_children$config$context{
  13.         
  14.         $def $config->getHTMLDefinition();
  15.         if (!$this->init{
  16.             // allow all inline elements
  17.             $this->real_elements = $this->elements;
  18.             $this->fake_elements = $def->info_content_sets['Flow'];
  19.             $this->fake_elements['#PCDATA'true;
  20.             $this->init = true;
  21.         }
  22.         
  23.         // trick the parent class into thinking it allows more
  24.         $this->elements = $this->fake_elements;
  25.         $result parent::validateChildren($tokens_of_children$config$context);
  26.         $this->elements = $this->real_elements;
  27.         
  28.         if ($result === falsereturn array();
  29.         if ($result === true$result $tokens_of_children;
  30.         
  31.         $block_wrap_start new HTMLPurifier_Token_Start($def->info_block_wrapper);
  32.         $block_wrap_end   new HTMLPurifier_Token_End(  $def->info_block_wrapper);
  33.         $is_inline false;
  34.         $depth 0;
  35.         $ret array();
  36.         
  37.         // assuming that there are no comment tokens
  38.         foreach ($result as $i => $token{
  39.             $token $result[$i];
  40.             // ifs are nested for readability
  41.             if (!$is_inline{
  42.                 if (!$depth{
  43.                      if (
  44.                         ($token instanceof HTMLPurifier_Token_Text && !$token->is_whitespace||
  45.                         (!$token instanceof HTMLPurifier_Token_Text && !isset($this->elements[$token->name]))
  46.                      {
  47.                         $is_inline true;
  48.                         $ret[$block_wrap_start;
  49.                      }
  50.                 }
  51.             else {
  52.                 if (!$depth{
  53.                     // starting tokens have been inline text / empty
  54.                     if ($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty{
  55.                         if (isset($this->elements[$token->name])) {
  56.                             // ended
  57.                             $ret[$block_wrap_end;
  58.                             $is_inline false;
  59.                         }
  60.                     }
  61.                 }
  62.             }
  63.             $ret[$token;
  64.             if ($token instanceof HTMLPurifier_Token_Start$depth++;
  65.             if ($token instanceof HTMLPurifier_Token_End)   $depth--;
  66.         }
  67.         if ($is_inline$ret[$block_wrap_end;
  68.         return $ret;
  69.     }
  70. }

Documentation generated on Thu, 19 Jun 2008 18:50:21 -0400 by phpDocumentor 1.4.2