コード例 #1
0
 /**
  * Prepare components (set classes to nodes etc.)
  * @param ComponentAbstract $component
  * @param \simple_html_dom_node $node
  */
 protected function beforeHandle(ComponentAbstract $component, \simple_html_dom_node $node)
 {
     $this->attachAngularApp();
     if ($class = $component->getOption('class')) {
         if (is_array($class)) {
             $class = implode(' ', $class);
         } elseif (is_callable($class)) {
             $class = $class();
         }
         if (is_string($class)) {
             $node->setAttribute('class', $class);
         }
     }
     $id = $component->getOption('id');
     if (!$id) {
         $id = $node->getAttribute('id');
     }
     if (!$id) {
         $id = $this->getId($node->getAttribute('data-component'));
     }
     if ($node->getAttribute('data-component') === 'likeGate') {
         $node->setAttribute('ng-init', 'likeGateEnabled = 1');
         $node->setAttribute('ng-show', 'likeGateEnabled');
         $header = $node->find('#likeGate-header', 0);
         $message = $node->find('#likeGate-message', 0);
         if ($header) {
             $header->setAttribute('ng-bind', 'likeGateHeader');
         }
         if ($message) {
             $message->setAttribute('ng-bind', 'likeGateMessage');
         }
         $node->setAttribute('ng-model', 'pageData.' . $id);
     }
 }
コード例 #2
0
 /**
  * Возвращает максимальное числовое значение в ячейках строки
  * @param \simple_html_dom_node $tr
  * @return float
  */
 private function findTdWithLargestValue(\simple_html_dom_node $tr)
 {
     $floatValues = [];
     foreach ($tr->find('td') as $td) {
         if (preg_match("/^[\\s]*([\\d.]+)[\\s]*\$/", $td->innertext, $matches)) {
             $floatValues[] = (double) $matches[1];
         }
     }
     return max($floatValues);
 }
コード例 #3
0
 /**
  * Manipulate node
  * @param DomNode $node
  * @return mixed
  */
 public function handleNode(DomNode $node)
 {
     if ($this->getOption('editMode')) {
         $data = $this->getValue();
         $id = $node->getAttribute('id');
         if (is_array($data)) {
             $sessionHelper = get_instance()->container->get('core.service.theme.session.helper');
             foreach (array('original', 'cropped') as $type) {
                 if (isset($data[$type])) {
                     //set current images to session
                     if (file_exists($data[$type]['path'])) {
                         $data[$type]['exist'] = true;
                         $sessionHelper->addTemplateImage($id, $data[$type], $type);
                     }
                 }
             }
         }
         if (isset($data['original']['exist'])) {
             $this->setOption('value', $data['original']['url']);
             $node->setAttribute('data-source-url', $data['original']['url']);
             if (isset($data['crop_params']['selection'])) {
                 $node->setAttribute('data-selection', str_replace('"', "'", json_encode($data['crop_params']['selection'])));
             }
             if (isset($data['crop_params']['scales'])) {
                 $node->setAttribute('data-scale', str_replace('"', "'", json_encode($data['crop_params']['scales'])));
             }
         }
     }
     parent::handleNode($node);
 }
コード例 #4
0
 /**
  * Manipulate node
  * @param DomNode $node
  * @return mixed
  */
 public function handleNode(DomNode $node)
 {
     if (!$this->isLikeGateEnabled()) {
         //no need to like gate be showed - remove node
         $node->outertext = '';
     } else {
         $data = $this->getValue();
         $header = $node->find('#likeGate-header', 0);
         $message = $node->find('#likeGate-message', 0);
         if (isset($data['header'])) {
             $header->innertext = $data['header'];
         }
         if (isset($data['message'])) {
             $message->innertext = $data['message'];
         }
         if (isset($data['enabled'])) {
             $node->setAttribute('ng-init', "likeGateEnabled = " . $data['enabled']);
         }
         $header->setAttribute('ng-init', "likeGateHeader = '" . $header->innertext . "'");
         $message->setAttribute('ng-init', "likeGateMessage = '" . $message->innertext . "'");
     }
 }
コード例 #5
0
 function lastChild()
 {
     return $this->root->last_child();
 }
コード例 #6
0
ファイル: ImportCourse.php プロジェクト: BePsvPT/CCU-Plus
 /**
  * 取得欄位資料.
  *
  * @param \simple_html_dom_node $row
  * @param string $department
  * @return array
  */
 protected function getColumns($row, $department)
 {
     static $name = ['domain', 'grade', 'code', 'class', 'name', 'professors', 'hours', 'credit', 'type', 'time', 'location', 'limit'];
     // I001:通識
     $i = 'I001' === $department ? 0 : 1;
     foreach ($row->children() as $node) {
         if ($i >= 12) {
             break;
         }
         $result[$name[$i++]] = trim($node->plaintext);
     }
     return $result ?? [];
 }
コード例 #7
0
 /**
  * Process a tag.
  * @param $tag string
  * @param \simple_html_dom_node $rootNode
  * @return void
  */
 protected function processTag($tag, \simple_html_dom_node $rootNode)
 {
     $closure = static::$tags[$tag];
     foreach ((array) $rootNode->find($tag) as $node) {
         $closure($node, $this);
     }
 }
コード例 #8
0
 /**
  * @param \simple_html_dom_node $item
  *
  * @return array
  * [
  *    'text'
  *    'href'
  * ]
  */
 private function getTd($item)
 {
     $data = ['text' => trim(explode(':', trim($item->plaintext))[1])];
     $a = $item->find('a');
     if (count($a) > 0) {
         $href = $a[0]->attr['href'];
         $href = str_replace('http://yourhumandesign.ru', '', $href);
         $data['href'] = $href;
     }
     return $data;
 }
コード例 #9
0
 function outertext()
 {
     if ($this->tag === HDOM_ROOT_PSEUDOTAG) {
         return $this->innertext();
     }
     return parent::outertext();
 }
コード例 #10
0
 /**
  * @param Listing $listing
  * @param string $name
  * @param \simple_html_dom_node $domRow
  */
 protected function parseAmenityByType(Listing $listing, $name, $domRow)
 {
     foreach ($domRow->find('div ul li') as $domValue) {
         /** @var \simple_html_dom_node $domValue */
         $value = trim($domValue->text());
         if (!empty($value)) {
             $amenity = new ListingAmenity();
             $amenity->setName($name)->setValue($value);
             $listing->addAmenity($amenity);
         }
     }
 }
コード例 #11
0
ファイル: ListDiffLines.php プロジェクト: caxy/php-htmldiff
 /**
  * @param \simple_html_dom_node $node
  * @param string                $class
  */
 protected function addClassToNode($node, $class)
 {
     $node->setAttribute('class', trim(sprintf('%s %s', $node->getAttribute('class'), $class)));
 }
コード例 #12
0
 /**
  * At least three views create a table of TplanElements.
  * (Tplans.edit,  Tplans.view, and TplanElements.index)
  * This table must be tested. Factor that testing into this method.
  * @param \simple_html_dom_node $html parsed dom that contains the TplanElementsTable
  * @param \App\Test\Fixture\TplanElementsFixture $tplan_elementsFixture
  * @return int $aTagsFoundCnt The number of aTagsFound.
  */
 public function tstTplanElementsTable($html, $tplan_elementsFixture)
 {
     // 1. Ensure that there is a suitably named table to display the results.
     $this->table = $html->find('table#TplanElementsTable', 0);
     $this->assertNotNull($this->table);
     // 2. Ensure that said table's thead element contains the correct
     //    headings, in the correct order, and nothing else.
     $this->thead = $this->table->find('thead', 0);
     $thead_ths = $this->thead->find('tr th');
     $this->assertEquals($thead_ths[0]->id, 'col1');
     $this->assertEquals($thead_ths[1]->id, 'col2');
     $this->assertEquals($thead_ths[2]->id, 'actions');
     $column_count = count($thead_ths);
     $this->assertEquals($column_count, 3);
     // no other columns
     // 3. Ensure that the tbody section has the same
     //    quantity of rows as the count of tplan_elements records in the fixture.
     $this->tbody = $this->table->find('tbody', 0);
     $tbody_rows = $this->tbody->find('tr');
     $this->assertEquals(count($tbody_rows), count($tplan_elementsFixture->records));
     // 4. Ensure that the values displayed in each row, match the values from
     //    the fixture.  The values should be presented in a particular order
     //    with nothing else thereafter.
     $iterator = new \MultipleIterator();
     $iterator->attachIterator(new \ArrayIterator($tplan_elementsFixture->records));
     $iterator->attachIterator(new \ArrayIterator($tbody_rows));
     $aTagsFoundCnt = 0;
     foreach ($iterator as $values) {
         $fixtureRecord = $values[0];
         $this->htmlRow = $values[1];
         $htmlColumns = $this->htmlRow->find('td');
         // 4.0 col1
         $this->assertEquals($fixtureRecord['col1'], $htmlColumns[0]->plaintext);
         // 4.1 col2
         $this->assertEquals($fixtureRecord['col2'], $htmlColumns[1]->plaintext);
         // 4.2 Now examine the action links
         $this->td = $htmlColumns[2];
         $actionLinks = $this->td->find('a');
         $this->assertEquals('TplanElementView', $actionLinks[0]->name);
         $aTagsFoundCnt++;
         $this->assertEquals('TplanElementEdit', $actionLinks[1]->name);
         $aTagsFoundCnt++;
         $this->assertEquals('TplanElementDelete', $actionLinks[2]->name);
         $aTagsFoundCnt++;
         // 4.9 No other columns
         $this->assertEquals(count($htmlColumns), $column_count);
     }
     return $aTagsFoundCnt;
 }
コード例 #13
0
ファイル: Eromon.php プロジェクト: kknet/AdultMidnight
 /**
  * 動画urlの指定されたa要素を取得する
  *
  * @param  simple_html_dom_node $el
  * @return simple_html_dom_node
  **/
 private function _fetchMovieLinkElement($el)
 {
     $next_el = $el->nextSibling();
     if (is_null($next_el)) {
         return $next_el;
     }
     return $next_el->nextSibling();
 }
コード例 #14
0
 /**
  * @param simple_html_dom_node $node
  *
  * @return simple_html_dom_node
  */
 public function appendChild(simple_html_dom_node $node)
 {
     $node->parent($this);
     return $node;
 }
コード例 #15
0
 /**
  * @deprecated use selectCheckerA
  * Look for a particular select input and ensure that:
  * The selection is what is expected and that the selection control
  * has the correct quantity of choices.  If the control passes, return true, else fail.
  *
  * @param \simple_html_dom_node $form the form that contains the select
  * @param string $selectID the html id of the select of interest
  * @param string $vvName the name of the view var that contains the into to populate the select
  * @return boolean
  */
 protected function lookForSelect($form, $selectID, $vvName)
 {
     $option = $form->find('select#' . $selectID . ' option[selected]', 0);
     $this->assertNull($option);
     $option_cnt = count($form->find('select#' . $selectID . ' option'));
     $record_cnt = $this->viewVariable($vvName)->count();
     $this->assertEquals($record_cnt + 1, $option_cnt);
     return true;
 }
コード例 #16
0
ファイル: Compiler.php プロジェクト: attitude/riotphp-tags
 /**
  * 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;
                 }
             }
         }
     }
 }
コード例 #17
0
ファイル: DOMParser.php プロジェクト: algolia/php-dom-parser
 /**
  * @param \simple_html_dom_node $node
  */
 private function emptyNodeContent(\simple_html_dom_node $node)
 {
     $node->innertext = '';
     foreach ($node->children() as $child) {
         $this->emptyNodeContent($child);
     }
 }
コード例 #18
0
/**
 * @param simple_html_dom_node $child
 * @param string $tmpBuffer
 * @return string
 */
function elementHandler($child, $tmpBuffer, $depth = 0, $break = true)
{
    //foreach ($childsHtml->children as $child) {
    /** @var simple_html_dom_node $child */
    if ($child->tag == 'ul') {
        foreach ($child->children as $grandchild) {
            $tmpBuffer = elementHandler($grandchild, $tmpBuffer, $depth + 1);
        }
        return $tmpBuffer;
    }
    $inner = $child->innertext();
    $break2 = true;
    if ($child->tag == 'li') {
        //$tmpBuffer.='*';
        for ($i = 0; $i < $depth; $i++) {
            $tmpBuffer .= '*';
        }
        if ($inner == '') {
            $break2 = false;
        } else {
            $tmpBuffer .= $inner;
        }
    } else {
        if ($child->tag == 'p') {
            $inner = str_replace("\t", '', $inner);
            $inner = str_replace("\n", ' ', $inner);
            //$tmpBuffer .= $inner;
            $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
        } else {
            if ($child->tag == 'b') {
                $tmpBuffer .= '===';
                $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
                //$tmpBuffer .= $inner;
                $tmpBuffer .= "===";
            } else {
                if ($child->tag == 'u') {
                    $tmpBuffer .= '<u>';
                    $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
                    //$tmpBuffer .= $inner;
                    $tmpBuffer .= '</u>';
                } else {
                    if ($child->tag == 'i') {
                        $tmpBuffer .= '\'\'';
                        $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
                        //$tmpBuffer .= $inner;
                        $tmpBuffer .= '\'\'';
                    } else {
                        if ($child->tag == 'text') {
                            $tmpBuffer .= $inner;
                        } else {
                            if ($child->tag == 'font') {
                                $tmpBuffer .= $inner;
                            }
                        }
                    }
                }
            }
        }
    }
    if ($break && $break2) {
        $tmpBuffer .= "\n";
    }
    //}
    return $tmpBuffer;
}
コード例 #19
0
 /**
  * At least three views create a table of Clazzes.
  * (Sections.edit,  Sections.view, and Clazzes.index)
  * This table must be tested. Factor that testing into this method.
  * @param \simple_html_dom_node $html parsed dom that contains the ClazzesTable
  * @param \App\Model\Table\ClazzesTable $clazzes
  * @param \App\Test\Fixture\ClazzesFixture $clazzesFixture
  * @param \App\Model\Table\SectionsTable $sections
  * @param int $sectionId If $sectionId=null, the test will expect to see all the records from
  * the fixture. Else the test will only expect to nersee fixture records with the given $sectionId.
  * @return int $aTagsFoundCnt The number of aTagsFound.
  */
 public function tstClazzesTable($html, $clazzes, $clazzesFixture, $sections, $section_id = null)
 {
     // 1. Ensure that there is a suitably named table to display the results.
     $this->table = $html->find('table#ClazzesTable', 0);
     $this->assertNotNull($this->table);
     // 2. Ensure that said table's thead element contains the correct
     //    headings, in the correct order, and nothing else.
     $this->thead = $this->table->find('thead', 0);
     $thead_ths = $this->thead->find('tr th');
     $this->assertEquals($thead_ths[0]->id, 'event_datetime');
     $this->assertEquals($thead_ths[1]->id, 'comments');
     $this->assertEquals($thead_ths[2]->id, 'attend');
     $this->assertEquals($thead_ths[3]->id, 'participate');
     $this->assertEquals($thead_ths[4]->id, 'actions');
     $column_count = count($thead_ths);
     $this->assertEquals($column_count, 5);
     // no other columns
     // 3. Ensure that the tbody section has the correct quantity of rows.
     // This should be done using a very similar query as used by the controller.
     $this->tbody = $this->table->find('tbody', 0);
     $this->tbody_rows = $this->tbody->find('tr');
     //if(!is_null($sectionId))
     //$clazzesFixture->filterBySectionId($sectionId);
     //$this->assertEquals(count($tbody_rows), count($clazzesFixture->records));
     //$connection = ConnectionManager::get('default');
     // This query should be essentially the same as the query in SectionsController.view
     //$query = "select students.sort, students.sid, students.id as student_id, students.giv_name, students.fam_name, students.phonetic_name, cohorts.id, sections.id, clazzes.id
     //from students
     //left join cohorts on students.cohort_id = cohorts.id
     //left join sections on sections.cohort_id = cohorts.id
     //left join clazzes on clazzes.section_id = sections.id
     //left join interactions on interactions.clazz_id=clazzes.id and interactions.student_id=students.id and interactions.itype_id=".ItypesController::ATTEND." where clazzes.id=".$clazz_id.
     //" order by sort";
     //$studentsResults = $connection->execute($query)->fetchAll('assoc');
     //$s1=count($this->tbody_rows);
     //$s2=count($studentsResults);
     //$this->assertEquals($s1,$s2);
     // Now get the classes associated with this section
     $query = $clazzes->find()->order(['event_datetime' => 'asc']);
     if (!is_null($section_id)) {
         $query->where(['section_id' => $section_id]);
     }
     $q = $query->execute()->fetchAll('assoc');
     // 4. Ensure that the values displayed in each row, match the values from
     //    the fixture.  The values should be presented in a particular order
     //    with nothing else thereafter.
     $iterator = new \MultipleIterator();
     $iterator->attachIterator(new \ArrayIterator($q));
     //$iterator->attachIterator(new \ArrayIterator($clazzesFixture->records));
     $iterator->attachIterator(new \ArrayIterator($this->tbody_rows));
     $aTagsFoundCnt = 0;
     foreach ($iterator as $values) {
         $fixtureRecord = $values[0];
         $this->htmlRow = $values[1];
         $htmlColumns = $this->htmlRow->find('td');
         // 8.0 event_datetime
         $this->assertEquals($fixtureRecord['Clazzes__event_datetime'], $htmlColumns[0]->plaintext);
         // 8.1 comments
         $this->assertEquals($fixtureRecord['Clazzes__comments'], $htmlColumns[1]->plaintext);
         // 8.2 attend
         // 8.3 participate
         // 8.4 Now examine the action links
         $this->td = $htmlColumns[4];
         $actionLinks = $this->td->find('a');
         $this->assertEquals('ClazzAttend', $actionLinks[0]->name);
         $aTagsFoundCnt++;
         $this->assertEquals('ClazzParticipate', $actionLinks[1]->name);
         $aTagsFoundCnt++;
         $this->assertEquals('ClazzView', $actionLinks[2]->name);
         $aTagsFoundCnt++;
         $this->assertEquals('ClazzEdit', $actionLinks[3]->name);
         $aTagsFoundCnt++;
         $this->assertEquals('ClazzDelete', $actionLinks[4]->name);
         $aTagsFoundCnt++;
         // 8.9 No other columns
         $this->assertEquals(count($htmlColumns), $column_count);
     }
     return $aTagsFoundCnt;
 }