HTMLTag.php
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | |
| 4 | class IRP_HTMLTag { |
| 5 | var $tags; |
| 6 | var $tag; |
| 7 | var $openTag; |
| 8 | var $closeTag; |
| 9 | |
| 10 | public function __construct() { |
| 11 | $this->tags = array(); |
| 12 | $this->tag=''; |
| 13 | $this->openTag=''; |
| 14 | $this->closeTag=''; |
| 15 | } |
| 16 | |
| 17 | public function hasTagContent() { |
| 18 | return TRUE; |
| 19 | } |
| 20 | public function pushTag(IRP_HTMLTag $child) { |
| 21 | if(count($this->tags)>0) { |
| 22 | //replace the TextContent tag that only contains \r\n with NewLineText |
| 23 | //due to now we use the substrln is impossible that we enter here |
| 24 | $last=$this->tags[count($this->tags)-1]; |
| 25 | if(isset($last->body)) { |
| 26 | $newline=TRUE; |
| 27 | if($last->body=="\n" || $last->body=="\r\n") { |
| 28 | //we dont have to do nothing... sure this is a newlinetext! |
| 29 | } else { |
| 30 | for($i=0; $i<strlen($last->body); $i++) { |
| 31 | $c=substr($last->body, $i, 1); |
| 32 | if($c!="\n" && $c!="\n") { |
| 33 | $newline=FALSE; |
| 34 | break; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if($newline) { |
| 40 | $tag=new IRP_NewLineText(); |
| 41 | $tag->body=$last->body; |
| 42 | $this->tags[count($this->tags)-1]=$tag; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | $this->tags[] = $child; |
| 47 | } |
| 48 | |
| 49 | public function write(IRP_HTMLContext $context) { |
| 50 | $context->write($this->openTag); |
| 51 | foreach($this->tags as $tag) { |
| 52 | $tag->write($context); |
| 53 | } |
| 54 | $context->write($this->closeTag); |
| 55 | } |
| 56 | public function analyseText(IRP_HTMLContext $context) { |
| 57 | foreach ($this->tags as $tag) { |
| 58 | $tag->analyseText($context); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 |