@param \SimpleXMLElement $nodes

@return PortfolioWidget[]
978001
private function extractTextWidgets(\SimpleXMLElement $nodes, Portfolio $portfolio)
    {
        $portfolioWidgets = [];
        $textWidgetNodes = $nodes->xpath("//entry[rdf:type/@rdf:resource='leap2:entry']");

        foreach ($textWidgetNodes as $textWidgetNode) {
            $portfolioWidget = $this->widgetsManager->getNewPortfolioWidget($portfolio, 'text');
            $textWidget = new TextWidget();
            $portfolioWidget->setWidget($textWidget);
            $textWidget->setUser($portfolio->getUser());

            $textWidget
                ->setLabel((string) $textWidgetNode->title)
                ->setText((string) $textWidgetNode->content);

            $portfolioWidgets[] = $portfolioWidget;
        }

        return $portfolioWidgets;
    }
254996
private function replaceGroupUseStatements(array $nodes): array
    {
        foreach ($nodes as $node) {
            if (false === ($node instanceof Namespace_)) {
                continue;
            }

            /** @var Namespace_ $node */
            $statements = $node->stmts;

            $newStatements = [];

            foreach ($statements as $statement) {
                if ($statement instanceof GroupUse) {
                    $uses_ = $this->createUses_($statement);

                    array_splice($newStatements, count($newStatements), 0, $uses_);
                } else {
                    $newStatements[] = $statement;
                }
            }

            $node->stmts = $newStatements;
        }

        return $nodes;
    }
1066815
protected function getChilds(SimpleXMLElement $element)
    {
        parent::getChilds($element);
        
        $this->getChildsAsCDATAFromList($element, array(
            'nb_site_target_attributes' => 'attributes'
        ), false);
    }
720024
public function retrievePortfolioFromXml(\SimpleXMLElement $xml, User $user)
    {
        $portfolioTitleNodes = $xml->xpath('/feed/title');

        if (0 === count($portfolioTitleNodes)) {
            throw new \Exception("Missing portfolio's title");
        }

        $portfolio = new Portfolio();
        $portfolio
            ->setTitle((string) $portfolioTitleNodes[0])
            ->setUser($user)
            ->setPortfolioWidgets($this->retrieveWidgets($xml, $portfolio));

        return $portfolio;
    }
40267
public function replaceWith($nodes) {
    $first = TRUE;
    foreach ($this->nodes as $node) {
      if (!$first) {
        if (is_array($nodes)) {
          $nodes = new NodeCollection($nodes, FALSE);
        }
        $nodes = clone $nodes;
      }
      $node->replaceWith($nodes);
      $first = FALSE;
    }
    return $this;
  }
583401
protected function computeRoutePattern(array $nodes)
    {
        $routePattern = array();
        foreach ($nodes as $node) {
            if (isset($node['nodeId']) && isset($node['routePattern']) && isset($node['parentId'])) {
                $routePattern[$node['nodeId']] = $node;
            }
        }

        return $routePattern;
    }
282090
protected function getNodes(array $nodeTypes, ContentContext $context)
    {
        $nodes = [];
        $siteNode = $context->getCurrentSiteNode();
        foreach ($this->nodeDataRepository->findByParentAndNodeTypeRecursively($siteNode->getPath(), implode(',', $nodeTypes), $context->getWorkspace()) as $nodeData) {
            $nodes[] = $this->nodeFactory->createFromNodeData($nodeData, $context);
        }
        return $nodes;
    }
681607
protected function renderChildren(ElementCollection $children)
    {
        $attributes = [];

        $children->forAll(function (ElementInterface $child) use (&$attributes) {
            $attributes[] = $this->renderElement($child);
        });

        return $attributes;
    }
1302146
public function beforeTraverse(array $nodes)
    {
        $keyedNodes = [];

        foreach ($nodes as $node) {
            $hashFunc = $node->getType().'Hash';

            if ( ! method_exists($this, $hashFunc)) {
                $keyedNodes[] = $node;

                continue;
            }

            $keyedNodes[$this->$hashFunc($node)] = $node;
        }

        return $keyedNodes;
    }
1327163
private function getNodes($node)
    {
        $this->logger->info('[Get Nodes] Retrieving nodes...');

        $stripUnlikelyCandidates = $this->configuration->getStripUnlikelyCandidates();

        $elementsToScore = [];

        /*
         * First, node prepping. Trash nodes that look cruddy (like ones with the
         * class name "comment", etc), and turn divs into P tags where they have been
         * used inappropriately (as in, where they contain no other block level elements.)
         */

        while ($node) {
            // Remove DOMComments nodes as we don't need them and mess up children counting
            if ($node->nodeType === XML_COMMENT_NODE) {
                $this->logger->debug(sprintf('[Get Nodes] Found comment node, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id');

            if (!$node->isProbablyVisible()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing hidden node... Match string was: \'%s\'', $matchString));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Check to see if this node is a byline, and remove it if it is.
            if ($this->checkByline($node, $matchString)) {
                $this->logger->debug(sprintf('[Get Nodes] Found byline, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Remove unlikely candidates
            if ($stripUnlikelyCandidates) {
                if (
                    preg_match(NodeUtility::$regexps['unlikelyCandidates'], $matchString) &&
                    !preg_match(NodeUtility::$regexps['okMaybeItsACandidate'], $matchString) &&
                    $node->nodeName !== 'body' &&
                    $node->nodeName !== 'a'
                ) {
                    $this->logger->debug(sprintf('[Get Nodes] Removing unlikely candidate. Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::removeAndGetNext($node);
                    continue;
                }
            }

            // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe).
            if (($node->nodeName === 'div' || $node->nodeName === 'section' || $node->nodeName === 'header' ||
                    $node->nodeName === 'h1' || $node->nodeName === 'h2' || $node->nodeName === 'h3' ||
                    $node->nodeName === 'h4' || $node->nodeName === 'h5' || $node->nodeName === 'h6' ||
                    $node->nodeName === 'p') &&
                $node->isElementWithoutContent()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing empty \'%s\' node.', $node->nodeName));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            if (in_array(strtolower($node->nodeName), $this->defaultTagsToScore)) {
                $this->logger->debug(sprintf('[Get Nodes] Adding node to score list, node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                $elementsToScore[] = $node;
            }

            // Turn all divs that don't have children block level elements into p's
            if ($node->nodeName === 'div') {
                // Put phrasing content into paragraphs.
                $p = null;
                $childNode = $node->firstChild;
                while ($childNode) {
                    $nextSibling = $childNode->nextSibling;
                    if ($childNode->isPhrasingContent()) {
                        if ($p !== null) {
                            $p->appendChild($childNode);
                        } elseif (!$childNode->isWhitespace()) {
                            $p = $this->dom->createElement('p');
                            $node->replaceChild($p, $childNode);
                            $p->appendChild($childNode);
                        }
                    } elseif ($p !== null) {
                        while ($p->lastChild && $p->lastChild->isWhitespace()) {
                            $p->removeChild($p->lastChild);
                        }
                        $p = null;
                    }
                    $childNode = $nextSibling;
                }

                /*
                 * Sites like http://mobile.slate.com encloses each paragraph with a DIV
                 * element. DIVs with only a P element inside and no text content can be
                 * safely converted into plain P elements to avoid confusing the scoring
                 * algorithm with DIVs with are, in practice, paragraphs.
                 */
                if ($node->hasSingleTagInsideElement('p') && $node->getLinkDensity() < 0.25) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single P node, removing DIV. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $pNode = $node->getChildren(true)[0];
                    $node->parentNode->replaceChild($pNode, $node);
                    $node = $pNode;
                    $elementsToScore[] = $node;
                } elseif (!$node->hasSingleChildBlockElement()) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single child block element, converting to a P node. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::setNodeTag($node, 'p');
                    $elementsToScore[] = $node;
                }
            }

            $node = NodeUtility::getNextNode($node);
        }

        return $elementsToScore;
    }
53130
public static function findClassLikeNodes(array $nodes): array
    {
        $collectedNodes = [];

        foreach ($nodes as $node) {
            if ($node instanceof Node\Stmt\ClassLike) {
                $collectedNodes[] = $node;
            } elseif ($node instanceof Use_) {
                continue;
            } elseif (is_array($node)) {
                $collectedNodes = array_merge(
                    static::findClassLikeNodes($node),
                    $collectedNodes
                );
            } elseif ($node instanceof Node) {
                $collectedNodes = array_merge(
                    static::findClassLikeNodes(static::getSubNodes($node)),
                    $collectedNodes
                );
            }
        }

        return $collectedNodes;
    }
1222429
protected function optimizeNodes(ChildrenNodeCollection $nodes)
    {
        $optimizedNodes = [];

        foreach ($nodes->getChildren() as $key => $node) {
            $optimizedNodes[$key] = $this->optimizeNode($node);
        }

        $optimizedNodes = new ChildrenNodeCollection($optimizedNodes);

        $optimizedNodes = $this->moveCommonMatchersToParentNode($optimizedNodes);

        return $optimizedNodes;
    }
871718
protected function getHTMLNodeInner($node, $xml, $settings)
    {
        $css = new CSSDocument();
        if ($this->customCSS) {
            $idSelector = $css->getIdSelector($this->getIdType() . $settings->getPrefix() . $this->getId());
            $css->addCSSText($this->customCSS, $idSelector);
        }
        $javascripts = [];
        $this->getHTMLNodeBase($node, $xml, $settings, $css, $javascripts);
        if ($this->secure) {
            $node->setAttribute('data-secured', 'secure');
        }
        $settings->addScreen(
            $this->getId(),
            $xml->saveXML($node),
            $css,
            $this->updated === true ? new \DateTime() : $this->updated,
            $this->secure,
            $javascripts
        );
    }
885902
protected function renderNodes($nodes)
    {
        $lines = [];

        if (!empty($nodes)) {

            $nodesOptions = $this->nodesOptions;
            $tag = ArrayHelper::remove($nodesOptions, 'tag', 'ol');
            $lines[] =  Html::beginTag($tag, $nodesOptions);

            foreach ($nodes as $node) {
                if (isset($node['visible']) && !$node['visible']) {
                    continue;
                }
                $lines[] = $this->renderNode($node);
            }

            $lines[] =  Html::endTag($tag); 
        }

        return implode("\n", $lines);
    }
813929
protected function parseOptions(\SimpleXMLElement $nodes)
    {
        $options = [];

        foreach ($nodes as $node) {
            if (\count($node) > 0) {
                if (\count($node->value) > 0) {
                    $value = $this->parseValues($node->value);
                } elseif (\count($node->constraint) > 0) {
                    $value = $this->parseConstraints($node->constraint);
                } else {
                    $value = [];
                }
            } else {
                $value = XmlUtils::phpize($node);
                if (\is_string($value)) {
                    $value = trim($value);
                }
            }

            $options[(string) $node['name']] = $value;
        }

        return $options;
    }
960176
private function createNodeRenderers(): array
    {
        return [
            new NodeRenderer\AssetHyperlink(),
            new NodeRenderer\Blockquote(),
            new NodeRenderer\Document(),
            new NodeRenderer\EmbeddedAssetBlock(),
            new NodeRenderer\EmbeddedAssetInline(),
            new NodeRenderer\EmbeddedEntryBlock(),
            new NodeRenderer\EmbeddedEntryInline(),
            new NodeRenderer\EntryHyperlink(),
            new NodeRenderer\Heading1(),
            new NodeRenderer\Heading2(),
            new NodeRenderer\Heading3(),
            new NodeRenderer\Heading4(),
            new NodeRenderer\Heading5(),
            new NodeRenderer\Heading6(),
            new NodeRenderer\Hr(),
            new NodeRenderer\Hyperlink(),
            new NodeRenderer\ListItem(),
            new NodeRenderer\Nothing(),
            new NodeRenderer\OrderedList(),
            new NodeRenderer\Paragraph(),
            new NodeRenderer\Text(),
            new NodeRenderer\UnorderedList(),
        ];
    }
520938
public function getPortfolioWidgetsForWidgetPicker(Portfolio $portfolio, User $user, $widgetType)
    {
        $portfolioWidgets = [];

        $widgets = $this->getWidgets($user, $widgetType);

        foreach ($widgets as $widget) {
            $portfolioWidget = new PortfolioWidget();
            $portfolioWidget
                ->setPortfolio($portfolio)
                ->setWidget($widget)
                ->setWidgetType($widgetType)
                ->setSize($this->getWidgetSizeByType($widgetType))
            ;
            $portfolioWidgets[] = $portfolioWidget;
        }

        return $portfolioWidgets;
    }