text() 공개 메소드

get dom node's plain text
public text ( )
 /**
  * @param Listing $listing
  * @param string $type
  * @param string $basis
  * @param \DateTime $dateStart
  * @param \DateTime $dateEnd
  * @param string $currency
  * @param \simple_html_dom_node|array $priceDom
  * @param \simple_html_dom_node|array $priceNotes
  *
  * @throws \UnexpectedValueException
  */
 protected function parsePriceByType(Listing $listing, $type, $basis, \DateTime $dateStart, \DateTime $dateEnd, $currency, $priceDom, $priceNotes)
 {
     if (!isset($priceDom)) {
         return;
     }
     $price = '';
     foreach ($priceDom->nodes as $node) {
         if ($node->tag == 'text') {
             $price .= trim($node->text());
         }
     }
     if (empty($price)) {
         return;
     }
     $price = str_replace(array('$', ','), '', trim($price));
     if (!is_numeric($price)) {
         throw new \UnexpectedValueException(sprintf('Price ammount not found in "%s"', trim($priceDom->text())));
     }
     $priceNotes = trim($priceNotes->text());
     $listingPrice = $listing->getPrice($type, $dateStart, $dateEnd);
     if (!isset($listingPrice)) {
         $listingPrice = new ListingPrice();
         $listing->addPrice($listingPrice);
     }
     $listingPrice->setType($type)->setBasis($basis)->setDateStart($dateStart)->setDateEnd($dateEnd)->setPrice($price)->setCurrency($currency)->setNotes($priceNotes);
 }
예제 #2
0
 public function text($sText = null)
 {
     if (func_num_args()) {
         $this->plaintext = $sText;
         return $this;
     } else {
         return parent::text();
     }
 }
 function __get($name)
 {
     switch ($name) {
         case 'outertext':
             return $this->root->innertext();
         case 'innertext':
             return $this->root->innertext();
         case 'plaintext':
             return $this->root->text();
         case 'charset':
             return $this->_charset;
         case 'target_charset':
             return $this->_target_charset;
     }
 }
예제 #4
0
 /**
  * Transforms Riot expressions into PHP on a tag object
  *
  * @param object $node simple_html_dom_node
  * @return void
  */
 public function transformExpressions(\simple_html_dom_node &$node)
 {
     if ($node->nodetype === 3) {
         $node->innertext = $this->phpifyExpression($node->text());
         return;
     }
     $attrs_to_delete = [];
     foreach ($node->nodes as $i => $child) {
         $this->transformExpressions($child);
         $surround = [];
         foreach ($child->attr as $child_attr => $child_attr_value) {
             // Remove on{event} attributes
             if (preg_match('|on\\w+|', $child_attr)) {
                 $attrs_to_delete[] = $child_attr;
             }
             // Find control attributes
             foreach (['each', 'if'] as $ctrl) {
                 if (strstr($child_attr, $ctrl)) {
                     $surround[$ctrl] = $child_attr_value;
                     $attrs_to_delete[] = $child_attr;
                 }
             }
             if (!in_array($child_attr, ['show', 'hide', 'each', 'if']) && strstr($child_attr_value, $this->settings['brackets'][0])) {
                 $child->attr[$child_attr] = $this->phpifyExpression($child_attr_value);
             }
         }
         $display = [];
         foreach (['show', 'hide'] as $ctrl) {
             if (isset($child->{$ctrl})) {
                 // Only last one should matter in case somebody puts both show and hide controls on a tag
                 $display = ['action' => $ctrl === 'show' ? true : false, 'expression' => $child->{$ctrl}];
                 $attrs_to_delete[] = $ctrl;
             }
         }
         if (!empty($display)) {
             $style = isset($child->style) ? $child->style : '';
             if (!preg_match('|\\bdisplay\\b\\s*:|', $style, $m)) {
                 $style = 'display: initial;';
             }
             /**/
             $style = preg_replace('|(\\bdisplay\\b\\s*:)[^;]*(;?)|', '$1 <?php if (' . $this->phpifyExpression($display['expression'], 'if') . ') { ?>' . ($display['action'] ? 'initial' : 'none') . '<?php } ?>$2', $style);
             /**/
             $style = trim(str_replace('display: initial', '', $style), ' ;');
             if (!empty($style)) {
                 $child->style = $style;
             }
         }
         foreach ($attrs_to_delete as $attr) {
             $child->removeAttribute($attr);
         }
         if (!empty($surround)) {
             foreach ($surround as $ctrl => $expression) {
                 switch ($ctrl) {
                     case 'each':
                         $child->outertext = "\n" . '<?php foreach (' . $this->phpifyExpression($expression, $ctrl) . ') { ?>' . "\n" . $child . "\n" . '<?php } ?>' . "\n";
                         break;
                     case 'if':
                         $child->outertext = "\n" . '<?php if (' . $this->phpifyExpression($expression, $ctrl) . ') { ?>' . "\n" . $child . "\n" . '<?php } ?>' . "\n";
                         break;
                 }
             }
         }
     }
 }