Get the html node for this element

@param \DOMElement $node
@param \AppShed\Remote\XML\DOMDocument $xml
@param \AppShed\Remote\HTML\Settings $settings
@param CSSDocument $css
@param array $javascripts
480685
protected function getHTMLNodeBase($node, $xml, $settings, $css, &$javascripts)
    {
        $node->setAttribute('data-screentype', static::TYPE);
        if ($this->secure) {
            $xml->addClass($node, 'secured');
        }
        $this->getCSS($css, $settings);

        if ($this->tabs === 'float') {
            $node->setAttribute('data-tabs', 'float');
        } else {
            if (!$this->tabs) {
                $node->setAttribute('data-tabs', 'hide');
            }
        }

        if ($this->header === 'float') {
            $xml->addClass($node, 'float-header');
        } else {
            if (!$this->header) {
                $xml->addClass($node, 'hide-header');
            }
        }

        if ($this->statusBarStyle === 'float') {
            $node->setAttribute('data-status', 'float');
        } else {
            if ($this->statusBarStyle === 'black') {
                $node->setAttribute('data-status', 'black');
            }
        }

        if ($this->tab) {
            $node->setAttribute('data-tab', $this->tab);
        }

        if ($settings->getFetchId()) {
            $node->setAttribute('data-fetch-id', $settings->getPrefix() . $settings->getFetchId());
        }

        if ($settings->getFetchUrl()) {
            $node->setAttribute('data-fetch-url', $settings->getFetchUrl());
        }

        if ($settings->getDirect()) {
            $node->setAttribute('data-fetch-direct', 'direct');
        }

        $node->appendChild($navbar = $xml->createElement('div', 'header'));
        $navbar->setAttribute('x-blackberry-focusable', 'true');
        $navbar->appendChild($xml->createElement('div', 'background'));
        if ($this->back !== false) {
            $navbar->appendChild(
                $back = $xml->createElement(
                    'div',
                    ['class' => 'back', 'data-linktype' => 'back', 'text' => 'Back']
                )
            );
            if ($this->back instanceof Screen) {
                $this->back->getHTMLNode($xml, $settings);
                $back->setAttribute('data-href', $settings->getPrefix() . $this->back->getId());
            } else {
                if ($this->back !== true) {
                    $back->setAttribute('data-href', $settings->getPrefix() . $this->back);
                }
            }
            $back->setAttribute('x-blackberry-focusable', 'true');
        }
        $navbar->appendChild($title = $xml->createElement('div', 'title'));

        $title->appendChild($xml->createElement('span', ['text' => $this->title]));

        $items = $xml->createElement('div', 'items' . ($this->scroll ? ' scrolling' : ''));
        $node->appendChild($items);
        $headButtons = $this->addHTMLChildren($items, $xml, $settings, $css, $javascripts);
        foreach ($headButtons as $b) {
            $c = $b->getHTMLNode($xml, $settings);
            if ($c) {
                $navbar->appendChild($c);
            }
        }

        if ($this->isRefreshable()) {
            $navbar->appendChild($refreshButton = $xml->createElement('div', ['data-linktype' => 'refresh', 'class' => 'refresh item headerbutton']));
            $refreshButton->appendChild($xml->createElement('div', ['class' => 'button', '']));
        }
    }
1077722
public static function getChildElements($node)
    {
        $ret = array();
        $nodes = $node->childNodes;
        foreach ($nodes as $node) {
            if ($node instanceof DOMElement) {
                array_push($ret, $node);
            }
        }
        return $ret;
    }
1281323
public function html_first($css)
    {
        if ($nodes = $this->_document->getQuery()->css($css, $this->_node)) {
            $node = $nodes->item(0);
            return $node->ownerDocument->saveHTML($node);
        } else {
            return null;
        }
    }
915872
protected function applyLinkToNode(DOMDocument $xml, \DOMElement $node, Settings $settings)
    {
        switch ($this->linktype) {
            case LinkConstants::LINK_JAVASCRIPT:
                $node->setAttribute('data-linktype', LinkConstants::LINK_JAVASCRIPT);
                $node->setAttribute('data-href', $this->getIdType() . $settings->getPrefix() . $this->getId());
                break;
            case LinkConstants::LINK_APP:
                $node->setAttribute('data-linktype', LinkConstants::LINK_APP);
                if ($this->screen instanceof App) {
                    $this->app->getHTMLNode($xml, $settings);
                    $node->setAttribute('data-href', $settings->getPrefix() . $this->app->getId());
                } else {
                    $node->setAttribute('data-href', $settings->getPrefix() . $this->app);
                }
                break;
            case LinkConstants::LINK_SCREEN:
                $node->setAttribute('data-linktype', LinkConstants::LINK_SCREEN);
                if ($this->screen instanceof Screen) {
                    $this->screen->getHTMLNode($xml, $settings);
                    $node->setAttribute('data-href', $settings->getPrefix() . $this->screen->getId());
                } elseif ($this->appshedLink) {
                    $node->setAttribute('data-href', $this->screen);
                    $node->setAttribute('data-appshed', 'appshed');
                } else {
                    $node->setAttribute('data-href', $settings->getPrefix() . $this->screen);
                }
                if (!empty($this->elementId)) {
                    $node->setAttribute('data-element', $this->elementId);
                }
                break;
            case LinkConstants::LINK_TAB:
                $node->setAttribute('data-linktype', LinkConstants::LINK_TAB);
                if ($this->tab instanceof Tab) {
                    $node->setAttribute('data-href', $settings->getPrefix() . $this->tab->getId());
                } elseif ($this->appshedLink) {
                    $node->setAttribute('data-href', $this->tab);
                    $node->setAttribute('data-appshed', 'appshed');
                } else {
                    $node->setAttribute('data-href', $settings->getPrefix() . $this->tab);
                }
                break;
            case LinkConstants::LINK_FILE:
                $node->setAttribute('data-linktype', LinkConstants::LINK_FILE);
                $node->setAttribute('data-href', $this->fileUrl);
                if ($this->fileName) {
                    $node->setAttribute('data-filename', $this->fileName);
                }
                break;
            case LinkConstants::LINK_SOUND:
                $node->setAttribute('data-linktype', LinkConstants::LINK_SOUND);
                $node->setAttribute('data-href', $this->soundUrl);
                if ($this->soundName) {
                    $node->setAttribute('data-filename', $this->soundName);
                }
                break;
            case LinkConstants::LINK_WEB:
                $node->setAttribute('data-linktype', LinkConstants::LINK_WEB);
                $node->setAttribute('data-href', $this->applyVariablesToUrl($this->webUrl));
                $node->setAttribute('data-weblinktype', $this->webType);
                break;
            case LinkConstants::LINK_REMOTE:
                $node->setAttribute('data-linktype', LinkConstants::LINK_REMOTE);
                $node->setAttribute('data-href', $this->applyVariablesToUrl($this->remoteUrl));
                $node->setAttribute('data-direct', 'direct');
                break;
            case LinkConstants::LINK_LOGIN:
                $node->setAttribute('data-linktype', LinkConstants::LINK_LOGIN);
                $node->setAttribute('data-href', $this->loginId);
                break;
            case LinkConstants::LINK_REGISTER:
                $node->setAttribute('data-linktype', LinkConstants::LINK_REGISTER);
                $node->setAttribute('data-href', $this->registerId);
                break;
            case LinkConstants::LINK_YOUTUBE:
                $node->setAttribute('data-linktype', LinkConstants::LINK_YOUTUBE);
                $node->setAttribute('data-href', $this->youTubeUrl);
                break;
            case LinkConstants::LINK_VIMEO:
                $node->setAttribute('data-linktype', LinkConstants::LINK_VIMEO);
                $node->setAttribute('data-href', $this->vimeoUrl);
                break;
            case LinkConstants::LINK_VIDEO:
                $node->setAttribute('data-linktype', LinkConstants::LINK_VIDEO);
                $node->setAttribute('data-href', $this->videoUrl);
                break;
            case LinkConstants::LINK_FACEBOOK:
                $node->setAttribute('data-linktype', LinkConstants::LINK_FACEBOOK);
                $node->setAttribute('data-href', $this->facebookUrl);
                break;
            case LinkConstants::LINK_TWITTER:
                $node->setAttribute('data-linktype', LinkConstants::LINK_TWITTER);
                $node->setAttribute('data-href', $this->twitterScreenName);
                break;
            case LinkConstants::LINK_BBM:
                $node->setAttribute('data-linktype', LinkConstants::LINK_BBM);
                break;
            case LinkConstants::LINK_REFRESH:
                $node->setAttribute('data-linktype', LinkConstants::LINK_REFRESH);
                break;
            case LinkConstants::LINK_EMAIL:
                if ($settings->getEmailPreview()) {
                    $screen = new Screen('Email');
                    $screen->setId('email' . $this->getId());
                    $screen->setEditable(false);
                    $screen->setBack($settings->getCurrentScreen());

                    $screen->addChild(new Input('email_to', 'To', $this->emailTo));
                    $screen->addChild(new Input('email_subject', 'Subject', $this->emailSubject));
                    $screen->addChild(new TextArea('email_body', 'Message', $this->emailBody));

                    $send = new Button('Send');
                    $send->setWebLink(
                        'mailto:{email_to}?subject={email_subject}&body={email_body}',
                        LinkConstants::WEBLINK_EXTERNAL
                    );
                    $screen->addChild($send);
                    $screen->getHTMLNode($xml, $settings);
                    $node->setAttribute('data-linktype', LinkConstants::LINK_SCREEN);
                    $node->setAttribute('data-href', $settings->getPrefix() . $screen->getId());
                } else {
                    $node->setAttribute('data-linktype', LinkConstants::LINK_WEB);
                    $node->setAttribute(
                        'data-href',
                        'mailto:' . $this->emailTo . '?' . http_build_query(
                            [
                                'subject' => $this->emailSubject,
                                'body' => $this->emailBody
                            ]
                        )
                    );
                    $node->setAttribute('data-weblinktype', LinkConstants::WEBLINK_EXTERNAL);
                }
                break;
            case LinkConstants::LINK_PHONE:
                if ($settings->getPhonePreview()) {
                    $screen = new Screen('Phone');
                    $screen->setId('phone' . $this->getId());
                    $screen->setScroll(false);
                    $screen->setEditable(false);
                    $screen->setBack($settings->getCurrentScreen());
                    $screen->addClass('phone-screen');
                    $screen->setHeader(false);
                    $screen->setTabs(false);

                    $top = new LinkElement($this->phoneNumber);
                    $top->addClass('top');
                    $screen->addChild($top);

                    $end = new LinkElement('End');
                    $end->addClass('bottom');
                    $end->setBackLink();
                    $screen->addChild($end);

                    $screen->getHTMLNode($xml, $settings);
                    $node->setAttribute('data-linktype', LinkConstants::LINK_SCREEN);
                    $node->setAttribute('data-href', $settings->getPrefix() . $screen->getId());
                } else {
                    $node->setAttribute('data-linktype', 'web');
                    $node->setAttribute('data-href', 'tel:' . $this->phoneNumber);
                    $node->setAttribute('data-weblinktype', LinkConstants::WEBLINK_CONFIRM);
                    $node->setAttribute('data-confirm-message', 'Click to make a call to ' . $this->phoneNumber);
                    $node->setAttribute('data-okbtn', 'Call');
                }
                break;
            case LinkConstants::LINK_BACK:
                $node->setAttribute('data-linktype', LinkConstants::LINK_BACK);
                if ($this->backScreenId) {
                    $node->setAttribute('data-href', $this->backScreenId);
                }
                break;
            case LinkConstants::LINK_IOT:
                $node->setAttribute('data-linktype', LinkConstants::LINK_IOT);
                $node->setAttribute('data-href', $this->iotPinName);
                $node->setAttribute('data-value', $this->iotValue);
                break;
        }
        if ($node->hasAttribute('data-linktype')) {
            $xml->addClass($node, 'link');
            if ($this->linkArrow === true) {
                $node->appendChild($xml->createElement('div', 'link-arrow'));
            } else {
                if ($this->linkArrow === false) {
                    $xml->addClass($node, 'link-no-arrow');
                }
            }
            $node->setAttribute('x-blackberry-focusable', 'true');
        }
    }
373134
public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) {
		if ( ! DOM::has_class( $textnode, $this->classes_to_avoid ) ) {
			$this->apply_internal( $textnode, $settings, $is_title );
		}
	}
496121
protected function getCustomTemplateContent(DOMNode $node)
    {
        $innerDoc = new DOMDocument();

        $rootNode = $innerDoc->createElementNS('http://docbook.org/ns/docbook', 'section');
        $innerDoc->appendChild($rootNode);

        /** @var \DOMNode $child */
        foreach ($node->childNodes as $child) {
            $newNode = $innerDoc->importNode($child, true);
            if ($newNode === false) {
                $this->logger->warning(
                    "Failed to import Custom Style content of node '{$child->getNodePath()}'"
                );
            }

            $rootNode->appendChild($newNode);
        }

        return trim($this->richTextConverter->convert($innerDoc)->saveHTML());
    }
1239458
protected function getHTMLNodeInner($node, $xml, $settings)
    {
        $css = new CSSDocument();
        $idSelector = $css->getIdSelector($this->getIdType() . $settings->getPrefix() . $this->getId());
        if ($this->customCSS) {
            $css->addCSSText($this->customCSS, $idSelector);
        }
        $this->getCSS($css, $settings);
        if ($this->splash) {
            $this->splash->toCSS($css, $idSelector . $css->getClassSelector('splash'));
        }

        if ($this->name) {
            $node->setAttribute('data-name', $this->name);
        }

        if ($this->description) {
            $node->setAttribute('data-description', $this->description);
        }

        if ($this->flag) {
            $node->setAttribute('data-flag', $this->flag);
        }

        if ($this->previewUrl) {
            $node->setAttribute('data-preview-url', $this->previewUrl);
        }

        if ($this->webviewUrl) {
            $node->setAttribute('data-webview-url', $this->webviewUrl);
        }

        if ($this->disableIos7) {
            $node->setAttribute('data-disable-ios7', 'data-disable-ios7');
        }

        if ($this->disableMasking) {
            $node->setAttribute('data-disable-masking', 'data-disable-masking');
        }

        if ($this->icon) {
            $node->setAttribute('data-icon', $this->icon->getUrl());
            $idSelector = $css->getIdSelector($this->getIdType() . $settings->getPrefix() . $this->getId());
            $css->addRule(
                [".android .phone-navigator $idSelector.app .app-navigator .screen .header .back"],
                'background-image',
                $css->getURLValue($this->icon->getUrl())
            );
            $css->addRule(
                [".blackberry .phone-navigator $idSelector.app .app-navigator .screen .header"],
                'background-image',
                $css->getURLValue($this->icon->getUrl())
            );
        }

        if ($settings->getFetchUrl()) {
            $node->setAttribute('data-fetch-url', $settings->getFetchUrl());
        }

        $node->appendChild($navigator = $xml->createElement('div', 'app-navigator'));
        $navigator->appendChild($navinner = $xml->createElement('div', 'app-navigator-inner'));
        $navinner->appendChild($xml->createElement('div', 'app-navigator-inner-sides'));
        $navinner->appendChild($xml->createElement('div', 'app-navigator-inner-sides'));

        if ($this->ads) {
            $xml->addClass($navigator, 'ads');
            $node->appendChild($xml->createElement('div', 'ad-holder'));
        }

        $node->appendChild(($tabbarOuter = $xml->createElement('div', 'tab-bar')));
        $tabbarOuter->appendChild(($tabbar = $xml->createElement('table')));
        $tabbar->appendChild(($tabbarinner = $xml->createElement('tr', 'tar-bar-inner')));

        foreach ($this->children as $tab) {
            $tabbarinner->appendChild($tab->getHTMLNode($xml, $settings));
            $tab->getCSS($css, $settings);
        }

        $settings->addApp(
            $this->getId(),
            $xml->saveXML($node),
            $css,
            $this->splash ? "<style scoped>" . $css->toSplashString(
                ) . "</style><div class=\"splash\" id=\"app" . $this->getId() . "\"></div>" : null,
            $this->updated === true ? new \DateTime() : $this->updated,
            ['login' => null, 'register' => null],
            $this->js
        );
    }
891305
protected function getHTMLNodeInner($node, $xml, $settings)
    {
        $node->appendChild($htmlNode = $xml->createElement('div', 'html'));
        $html = $this->html;

        if ($html != '') {
            $fragDoc = new \DOMDocument();
            $libxml_previous_state = libxml_use_internal_errors(true);
            $fragDoc->loadHTML(
                '<?xml version="1.0" encoding="utf-8" standalone="yes"?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/ loose.dtd"><html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body>' . $html . '</body></html>'
            );
            libxml_clear_errors();
            libxml_use_internal_errors($libxml_previous_state);
            if ($fragDoc->hasChildNodes()) {
                $body = $fragDoc->getElementsByTagName('body')->item(0);
                if ($body->hasChildNodes()) {
                    for ($i = 0; $i < $body->childNodes->length; $i++) {
                        $iNode = $body->childNodes->item($i);
                        $importedNode = $xml->importNode($iNode, true);
                        $htmlNode->appendChild($importedNode);
                    }

                    $this->checkNode($xml, $htmlNode);
                }
            }
        }
    }
417406
protected function getHTMLNodeInner($node, $xml, $settings)
    {
        $node->appendChild($xml->createElement('div', ['class' => 'title', 'text' => $this->title]));
        $node->appendChild($xml->createElement('div', ['class' => 'text', 'text' => $this->subtitle]));
        $this->applyLinkToNode($xml, $node, $settings);
    }
682712
private function addEditorSection(ArrayNodeDefinition $node)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $node
            ->children()
                ->arrayNode('editor')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->scalarNode('template')->defaultValue('@EkynaCms/Editor/content.html.twig')->end()
                        ->scalarNode('css_path')->defaultValue('/bundles/ekynacms/css/editor-document.css')->end()
                        ->arrayNode('viewports')
                            ->defaultValue(Editor::getDefaultViewportsConfig())
                            ->requiresAtLeastOneElement()
                            ->useAttributeAsKey('name')
                            ->prototype('array')
                                ->children()
                                    ->integerNode('width')->isRequired()->min(0)->defaultValue(0)->end()
                                    ->integerNode('height')->isRequired()->min(0)->defaultValue(0)->end()
                                    ->scalarNode('icon')->isRequired()->cannotBeEmpty()->end()
                                    ->scalarNode('title')->isRequired()->cannotBeEmpty()->end()
                                    ->booleanNode('active')->defaultFalse()->end()
                                ->end()
                            ->end()
                            ->validate()
                            ->ifTrue(function($classes) {
                                if (0 < count(array_diff(Editor::getViewportsKeys(), (array) $classes))) {
                                    return true;
                                }
                                return false;
                            })
                            ->thenInvalid('Unexpected key(s) in editor classes configuration.')
                            ->end()
                        ->end()
                        ->arrayNode('layout')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->scalarNode('adapter')
                                    ->defaultValue(Bootstrap3Adapter::class)
                                    ->isRequired()->cannotBeEmpty()
                                ->end()
                            ->end()
                        ->end()
                        ->arrayNode('plugins')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->arrayNode('block')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->scalarNode('default')
                                            ->defaultValue('ekyna_block_tinymce')
                                        ->end()
                                        ->integerNode('min_size')
                                            ->min(1)->max(12)
                                            ->defaultValue(2)
                                        ->end()
                                        ->arrayNode('tinymce')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->scalarNode('default_content')
                                                    ->defaultValue('<p>Default content.</p>')
                                                ->end()
                                            ->end()
                                        ->end()
                                        ->arrayNode('image')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->scalarNode('default_path')
                                                    ->defaultValue('/bundles/ekynacms/img/default-image.gif')
                                                ->end()
                                                ->scalarNode('default_alt')
                                                    ->defaultValue('Default image')
                                                ->end()
                                                ->scalarNode('filter')->defaultValue('cms_block_image')->end()
                                                ->arrayNode('themes')
                                                    ->useAttributeAsKey('name')
                                                    ->prototype('scalar')->end()
                                                    ->defaultValue(PropertyDefaults::getDefaultThemeChoices())
                                                ->end()
                                                ->arrayNode('styles')
                                                    ->useAttributeAsKey('name')
                                                    ->prototype('scalar')->end()
                                                    ->defaultValue(PropertyDefaults::getDefaultStyleChoices())
                                                ->end()
                                                ->arrayNode('animations')
                                                    ->useAttributeAsKey('name')
                                                    ->prototype('scalar')->end()
                                                    ->defaultValue(PropertyDefaults::getDefaultAnimationChoices())
                                                ->end()
                                            ->end()
                                        ->end()
                                        ->arrayNode('video')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->scalarNode('default_poster')
                                                    ->defaultValue('/bundles/ekynacms/img/default-image.gif')
                                                ->end()
                                            ->end()
                                        ->end()
                                        ->arrayNode('feature')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->scalarNode('image_filter')->defaultValue('cms_block_feature')->end()
                                                ->arrayNode('animations')
                                                    ->useAttributeAsKey('name')
                                                    ->prototype('scalar')->end()
                                                    ->defaultValue(PropertyDefaults::getDefaultAnimationChoices())
                                                ->end()
                                            ->end()
                                        ->end()
                                        ->arrayNode('template')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->arrayNode('templates')
                                                    ->defaultValue([])
                                                    ->useAttributeAsKey('name')
                                                    ->prototype('array')
                                                        ->children()
                                                            ->scalarNode('title')->isRequired()->cannotBeEmpty()->end()
                                                            ->scalarNode('path')->isRequired()->cannotBeEmpty()->end()
                                                        ->end()
                                                    ->end()
                                                ->end()
                                            ->end()
                                        ->end()
                                        ->arrayNode('tabs')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->arrayNode('themes')
                                                    ->useAttributeAsKey('name')
                                                    ->prototype('scalar')->end()
                                                    ->defaultValue(PropertyDefaults::getDefaultThemeChoices())
                                                ->end()
                                            ->end()
                                        ->end()
                                    ->end()
                                ->end()
                                ->arrayNode('container')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->scalarNode('default')->defaultValue('ekyna_container_background')->end()
                                        ->arrayNode('background')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->scalarNode('filter')->defaultValue('cms_container_background')->end()
                                                ->scalarNode('default_color')->defaultValue('')->end()
                                                ->arrayNode('themes')
                                                    ->useAttributeAsKey('name')
                                                    ->prototype('scalar')->end()
                                                    ->defaultValue(PropertyDefaults::getDefaultThemeChoices())
                                                ->end()
                                            ->end()
                                        ->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;
    }
322397
private function copyUninlineableCssToStyleNode(\DOMXPath $xPath, array $cssRules)
    {
        $cssRulesRelevantForDocument = \array_filter(
            $cssRules,
            function (array $cssRule) use ($xPath) {
                $selector = $cssRule['selector'];
                if ($cssRule['hasUnmatchablePseudo']) {
                    $selector = $this->removeUnmatchablePseudoComponents($selector);
                }
                return $this->existsMatchForCssSelector($xPath, $selector);
            }
        );

        if ($cssRulesRelevantForDocument === []) {
            // avoid adding empty style element (or including unneeded class dependency)
            return;
        }

        $cssConcatenator = new CssConcatenator();
        foreach ($cssRulesRelevantForDocument as $cssRule) {
            $cssConcatenator->append([$cssRule['selector']], $cssRule['declarationsBlock'], $cssRule['media']);
        }

        $this->addStyleElementToDocument($cssConcatenator->getCss());
    }
1295199
private function parseXml(\DOMNode $node, array $context = [])
    {
        $data = $this->parseXmlAttributes($node, $context);

        $value = $this->parseXmlValue($node, $context);

        if (!\count($data)) {
            return $value;
        }

        if (!\is_array($value)) {
            $data['#'] = $value;

            return $data;
        }

        if (1 === \count($value) && key($value)) {
            $data[key($value)] = current($value);

            return $data;
        }

        foreach ($value as $key => $val) {
            $data[$key] = $val;
        }

        return $data;
    }
1354474
public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) {
		if ( empty( $settings['smartDashes'] ) ) {
			return;
		}

		// Various special characters and regular expressions.
		$s = $settings->dash_style();

		// Cache textnode content.
		$node_data = $textnode->data;

		$node_data = \str_replace( '---', U::EM_DASH, $node_data );
		$node_data = \preg_replace( self::PARENTHETICAL_DOUBLE_DASH, "\$1{$s->parenthetical_dash()}\$2", $node_data );
		$node_data = \str_replace( '--', U::EN_DASH, $node_data );
		$node_data = \preg_replace( self::PARENTHETICAL_SINGLE_DASH, "\$1{$s->parenthetical_dash()}\$2", $node_data );

		$node_data = \preg_replace( self::EN_DASH_WORDS ,        '$1' . U::EN_DASH . '$2',         $node_data );
		$node_data = \preg_replace( self::EN_DASH_NUMBERS,       "\$1{$s->interval_dash()}\$3",    $node_data );
		$node_data = \preg_replace( self::EN_DASH_PHONE_NUMBERS, '$1' . U::NO_BREAK_HYPHEN . '$2', $node_data ); // phone numbers.
		$node_data = \str_replace( 'xn' . U::EN_DASH,            'xn--',                           $node_data ); // revert messed-up punycode.

		// Revert dates back to original formats
		// YYYY-MM-DD.
		$node_data = \preg_replace( self::DATE_YYYY_MM_DD, '$1-$2-$3',     $node_data );
		// MM-DD-YYYY or DD-MM-YYYY.
		$node_data = \preg_replace( self::DATE_MM_DD_YYYY, '$1$3-$2$4-$5', $node_data );
		// YYYY-MM or YYYY-DDDD next.
		$node_data = \preg_replace( self::DATE_YYYY_MM,    '$1-$2',        $node_data );

		// Restore textnode content.
		$textnode->data = $node_data;
	}
182821
protected function appendNode(DOMNode $node, $xquery = null)
    {
      // Determine parent node
      if(!is_null($xquery))
        $parentNode = $this->getNode($xquery);
      else if(!is_null($this->node))
        $parentNode = $this->node;
      else
        $parentNode = $this->document;

      $parentNode->appendChild($node);
    }
1185858
public function addNode($node) {
		$src=false;
		// find src
		if (array_key_exists('src',$node))
			$src = $node['src'];
		elseif (array_key_exists('href',$node))
			$src = $node['href'];
		if ($src) {
			// find type
			if (!isset($node['type'])) {
				if (preg_match('/.*\.(css|js)(?=[?#].*|$)/i',$src,$match))
					$node['type'] = $match[1];
				elseif (array_key_exists('src',$node))
					$node['type'] = 'js';
				elseif (array_key_exists('href',$node))
					$node['type'] = 'css';
				elseif(empty($type))
					// unknown file type
					return "";
			}
			$type = $node['type'];
			// default slot is based on the type
			if (!isset($node['group']))
				$node['group'] = ($node['type'] == 'js')
					? 'footer' : 'head';
			if (!isset($node['priority']))
				$node['priority'] = 5;
			if (!isset($node['slot']))
				$node['slot'] = null;
			$group = $node['group'];
			$prio = $node['priority'];
			$slot = $node['slot'];
			unset($node['priority'],$node['src'],$node['href'],
				$node['group'],$node['type'],$node['slot']);
			$this->add($src,$type,$group,$prio,$slot,$node);
		}
	}
333145
protected function htmlFromNode($node)
    {
        $domDocument = new \DOMDocument();
        $newNode = $domDocument->importNode($node, true);
        $domDocument->appendChild($newNode);

        return $domDocument->saveHTML();
    }
538675
function handleNode( $node, &$sectionLevel, $isLastTag = false )
    {
        $xhtmlTextContent = "";
//    if ( $node->namespaceURI() == 'http://openoffice.org/2000/text' )
        {

            // If another tag than paragraph comes then terminate collapsing tags, if any
            if ( $node->localName != "p" and $this->CollapsingTagName != false )
            {
                $xhtmlTextContent .= '<paragraph>' . '<' . $this->CollapsingTagName . ' ' . $this->CollapsingTagAttribute . ' >' . $this->CollapsingTagContent . "</" . $this->CollapsingTagName . ">\n</paragraph>\n";
                $this->CollapsingTagContent = false;
                $this->CollapsingTagAttribute = false;
                $this->CollapsingTagName = false;
            }

            switch ( $node->localName )
            {
                case 'sequence-decls' :
                case 'forms' :
                {
                    // do nothing
                }break;


                case 'section' :
                {
                    foreach ( $node->childNodes as $childNode )
                    {
                        $xhtmlTextContent  .= self::handleNode( $childNode, $sectionLevel );
                    }
                }break;

                case 'h' :
                {
                    $level = $node->getAttributeNS( self::NAMESPACE_TEXT, 'outline-level' );

                    if ( $level > 6 )
                        $level = 6;

                    if ( $level >= 1 && $level <= 6 )
                    {
                        $levelDiff = $level - $sectionLevel;
                        $sectionLevel = $level;
                        $headerContent = "";

                        foreach ( $node->childNodes as $childNode )
                        {
                            // Alex 2008/04/21 - added initializations for $nextlineBreak and $prevlineBreak
                            $nextLineBreak = ( isset( $childNode->nextSibling ) &&
                                               $childNode->nextSibling->localName == 'line-break' );

                            $prevLineBreak = ( isset( $childNode->previousSibling ) &&
                                               $childNode->previousSibling->localName == 'line-break' );

                            $headerContent .= self::handleInlineNode( $childNode, $nextLineBreak, $prevLineBreak );
                        }
                        $sectionLevel = $level;

                        if ( $levelDiff > 0 )
                            $xhtmlTextContent .= str_repeat( "<section>", $levelDiff );

                        if ( $levelDiff < 0 )
                            $xhtmlTextContent .= str_repeat( "</section>", abs( $levelDiff ) );

                        $xhtmlTextContent .= "<header>" . $headerContent . "</header>\n";
                    }
                    else
                    {
                        eZDebug::writeError( "Unsupported header level $level<br>" . $node->textContent . "<br>" );
                    }
                }break;

                case 'p' :
                {
                    $styleName = $node->getAttributeNS( self::NAMESPACE_TEXT, 'style-name' );

                    $lastCollapsingTagName = $this->CollapsingTagName;

                    // Check for custom tags

                    if ( substr( $styleName, 0, 12 ) == "eZCustom_20_" )
                    {
                        $customName = substr( $styleName, 12, strlen( $styleName ) - 12 );
                        $this->CollapsingTagName = "custom";
                        $this->CollapsingTagAttribute = "name='$customName'";
                    }
                    else
                    {
                        switch ( $styleName )
                        {
                            case "Preformatted_20_Text" :
                            {
                                $this->CollapsingTagName = "literal";
                            }break;
                            default:
                            {
                                $this->CollapsingTagName = false;
                            }break;
                        }
                    }

                    // Check for bold and italic styles
                    // OOo does not have tags for these styles but set the style on the whole paragraph
                    $fontWeight = false;
                    $fontStyle = false;
                    $headerLevel = false;
                    foreach ( $this->AutomaticStyles as $style )
                    {
                        if ( $style->nodeType !== XML_ELEMENT_NODE )
                        {
                            continue;
                        }

                        $tmpStyleName = $style->getAttributeNS( self::NAMESPACE_STYLE, "name" );

                        if ( $styleName == $tmpStyleName )
                        {
                            foreach ( $style->childNodes as $styleChild )
                            {
                                $fontWeight = $styleChild->getAttributeNS( self::NAMESPACE_FO, 'font-weight' );
                                $fontStyle = $styleChild->getAttributeNS( self::NAMESPACE_FO, 'font-style' );
                            }

                            // Get the parent style name, it's used to see if it's a
                            // header which comes from Word conversion
                            $parentStyleName = $style->getAttributeNS( self::NAMESPACE_STYLE, "parent-style-name" );

                            // Check if we've got a header definition and which level Heading_20
                            // Header styles is either defined in style-name or parent-style-name when
                            // converting a Word document to OOo, here we check the parent-style-name
                            if ( substr( $parentStyleName, 0, 11 ) == "Heading_20_" )
                            {
                                $level = substr( $parentStyleName, 11, strlen( $parentStyleName )  );
                                if ( is_numeric( $level ) )
                                    $headerLevel = $level;
                            }

                        }
                    }

                    // Check if paragraph style is set to a header in the style-name
                    if ( substr( $styleName, 0, 11 ) == "Heading_20_" )
                    {
                        $level = substr( $styleName, 11, strlen( $styleName )  );
                        if ( is_numeric( $level ) )
                            $headerLevel = $level;
                    }

                    $preStyles = "";
                    if ( $fontWeight == "bold" )
                        $preStyles .= "<strong>";
                    if ( $fontStyle == "italic" )
                        $preStyles .= "<emphasize>";

                    $postStyles = "";
                    if ( $fontStyle == "italic" )
                        $postStyles .= "</emphasize>";
                    if ( $fontWeight == "bold" )
                        $postStyles .= "</strong>";

                    $paragraphContent = "";
                    foreach ( $node->childNodes as $childNode )
                    {
                        $nextLineBreak = ( isset( $childNode->nextSibling ) &&
                                           $childNode->nextSibling->localName == 'line-break' );

                        $prevLineBreak = ( isset( $childNode->previousSibling ) &&
                                           $childNode->previousSibling->localName == 'line-break' );

                        $paragraphContent .= self::handleInlineNode( $childNode, $nextLineBreak, $prevLineBreak );
                    }

                    // If current paragraph is actually a header, then skip sub-formatting
                    if ( $headerLevel !== false )
                    {
                        if ( $level > 6 )
                            $level = 6;

                        if ( $level >= 1 && $level <= 6 )
                        {
                            $levelDiff = $level - $sectionLevel;
                            $sectionLevel = $level;

                            if ( $levelDiff > 0 )
                                $xhtmlTextContent .= str_repeat( "<section>", $levelDiff );

                            if ( $levelDiff < 0 )
                                $xhtmlTextContent .= str_repeat( "</section>", abs( $levelDiff ) );

                            $xhtmlTextContent .= "<header>" . $paragraphContent . "</header>\n";
                        }
                    }
                    else
                    {
                        // Handle normal paragraphs

                        if ( $this->CollapsingTagName == false )
                        {
                            // Add collapsed tag, if beyond the last collapsing tag
                            if ( $lastCollapsingTagName !== false )
                            {
                                // Content should be quoted because it breaks the XML.
                                $tagContent = str_replace( "&", "&amp;", $this->CollapsingTagContent );
                                $tagContent = str_replace( ">", "&gt;", $tagContent );
                                $tagContent = str_replace( "<", "&lt;", $tagContent );
                                $tagContent = str_replace( "'", "&apos;", $tagContent );
                                $tagContent = str_replace( '"', "&quot;", $tagContent );

                                $collapsingTagAttrText = $this->CollapsingTagAttribute ? ' ' . $this->CollapsingTagAttribute : '';
                                $xhtmlTextContent .= '<paragraph>' . '<' . $lastCollapsingTagName . $collapsingTagAttrText . '>' . $tagContent . "</" . $lastCollapsingTagName . ">\n</paragraph>\n";
                                $this->CollapsingTagContent = false;
                                $this->CollapsingTagAttribute = false;
                            }

                            if ( trim( $paragraphContent ) != "" )
                            {
                                $xhtmlTextContent .= '<paragraph>' . $preStyles . $paragraphContent . $postStyles . "</paragraph>\n";
                            }
                        }
                        else
                        {
                            if ( $isLastTag == true )
                            {
                                if ( $this->CollapsingTagName != false )
                                    $lastCollapsingTagName = $this->CollapsingTagName;
                                $xhtmlTextContent .= '<paragraph>' . '<' . $lastCollapsingTagName . ' ' . $this->CollapsingTagAttribute . '>' . $paragraphContent . "</" . $lastCollapsingTagName . ">\n</paragraph>\n";
                                $this->CollapsingTagContent = false;
                                $this->CollapsingTagAttribute = false;
                                $this->CollapsingTagName = false;
                            }
                            else
                            {
                                if ( $this->CollapsingTagName == "custom" )
                                {
                                    if ( trim( $paragraphContent ) != "" )
                                    {
                                        $this->CollapsingTagContent .= '<paragraph>' . $preStyles . $paragraphContent . $postStyles . "</paragraph>\n";
                                    }
                                }
                                else
                                {
                                    $this->CollapsingTagContent .= $paragraphContent . "\n";
                                }
                            }
                        }

                    }
                }break;

                case 'numbered-paragraph' :
                {
                    $listContent = "";
                    foreach ( $node->childNodes as $itemNode )
                    {
                        if ( $itemNode->localName == 'p' )
                        {
                            $listContent .= "<li>" . strip_tags( self::handleNode( $itemNode, $sectionLevel ) ) . "</li>";
                        }
                    }

                    $xhtmlTextContent .= "<paragraph><ul>" . $listContent . "</ul></paragraph>\n";
                }break;

                case 'list' :
                {
                    $styleName = $node->getAttributeNS( self::NAMESPACE_TEXT, 'style-name' );

                    // Check list style for unordered/ordered list
                    $listType = false;
                    foreach ( $this->AutomaticStyles as $style )
                    {
                        if ( $style->nodeType !== XML_ELEMENT_NODE )
                        {
                            continue;
                        }

                        $tmpStyleName = $style->getAttributeNS( self::NAMESPACE_STYLE, "name" );

                        if ( $styleName == $tmpStyleName )
                        {
                            if ( $style->childNodes->length >= 1 )
                            {
                                $children = $style->childNodes;

                                switch ( $children->item( 0 )->localName )
                                {
                                    case "list-level-style-number":
                                    {
                                        $listType = "ordered";
                                        $this->InsideListType = "ordered";
                                    } break;

                                    case "list-level-style-bullet":
                                    {
                                        $listType = "unordered";
                                        $this->InsideListType = "unordered";
                                    } break;
                                }
                            }
                        }
                    }

                    if ( $listType == false )
                        $listType = $this->InsideListType;

                    $listItemCount = 0;
                    $listContent = "";

                    $isSubList = $this->IsSubList;
                    $this->IsSubList = true;
                    foreach ( $node->childNodes as $itemNode )
                    {
                        if ( $itemNode->localName == 'list-item' )
                        {
                            foreach ( $itemNode->childNodes as $childNode )
                            {
                                $listItemContent = self::handleNode( $childNode, $sectionLevel );

                                if ( substr( $listItemContent, 0, 4 ) == "<ol>" or
                                     substr( $listItemContent, 0, 4 ) == "<ul>" )
                                {
                                    $listContent .= $listItemContent;
                                }
                                else
                                {
                                    $endItemTag = "</li>";
                                    if ( $listItemCount == 0 )
                                        $endItemTag = "";
                                    $listContent .= "$endItemTag<li>" . $listItemContent;
                                }

                                $listItemCount++;
                            }
                        }
                    }

                    $this->IsSubList = $isSubList;

                    $paragraphPreTag = "<paragraph>";
                    $paragraphPostTag = "</paragraph>";

                    // If we are inside a list, ommit paragraph tag
                    if ( $this->IsSubList != false )
                    {
                        $paragraphPreTag = "";
                        $paragraphPostTag = "";
                    }

                    // Do not add empty lists
                    if ( $listItemCount > 0 )
                    {
                        if ( $listType == "ordered" )
                            $xhtmlTextContent .= "$paragraphPreTag<ol>" . $listContent . "</li></ol>$paragraphPostTag\n";
                        else
                        {
                            $xhtmlTextContent .= "$paragraphPreTag<ul>" . $listContent . "</li></ul>$paragraphPostTag\n";
                        }
                    }
                }break;

                case 'table' :
                {
                    $tableContent = "";
                    foreach ( $node->childNodes as $itemNode )
                    {
                        if ( $itemNode->localName == 'table-header-rows' )
                        {
                            foreach ( $itemNode->childNodes as $headerRow )
                            {
                                if ( $headerRow->localName == 'table-row' )
                                {
                                    $rowContent = "";
                                    foreach ( $headerRow->childNodes as $tableCell )
                                    {
                                        $colSpan = $tableCell->getAttributeNS( self::NAMESPACE_TABLE, 'number-columns-spanned' );

                                        if ( $tableCell->localName == 'table-cell' )
                                        {
                                            $cellContent = "";
                                            foreach ( $tableCell->childNodes as $tableContentNode )
                                            {
                                                $cellContent .= self::handleNode( $tableContentNode, $sectionLevel );
                                            }
                                            $colSpanXML = "";
                                            if ( is_numeric( $colSpan ) and $colSpan > 1 )
                                            {
                                                $colSpanXML = " xhtml:colspan='$colSpan' ";
                                            }
                                            $rowContent .= "<th $colSpanXML>" . $cellContent . "</th>";
                                        }
                                    }
                                    $tableContent .= "<tr>" . $rowContent . "</tr>";
                                }
                            }
                        }
                        else if ( $itemNode->localName == 'table-row' )
                        {
                            $rowContent = "";
                            foreach ( $itemNode->childNodes as $tableCell )
                            {
                                if ( $tableCell->localName == 'table-cell' )
                                {
                                    $cellContent = "";
                                    $colSpan = $tableCell->getAttributeNS( self::NAMESPACE_TABLE, 'number-columns-spanned' );
                                    foreach ( $tableCell->childNodes as $tableContentNode )
                                    {
                                        $cellContent .= self::handleNode( $tableContentNode, $sectionLevel );
                                    }
                                    $colSpanXML = "";
                                    if ( is_numeric( $colSpan ) and $colSpan > 1 )
                                    {
                                        $colSpanXML = " xhtml:colspan='$colSpan' ";
                                    }
                                    $rowContent .= "<td $colSpanXML>" . $cellContent . "</td>";
                                }
                            }
                            $tableContent .= "<tr>" . $rowContent . "</tr>";
                        }
                    }
                    $xhtmlTextContent .= "<paragraph><table width='100%'>" . $tableContent . "</table></paragraph>";
                }break;


                default:
                {
                    eZDebug::writeError( "Unsupported top node " . $node->localName . "<br/>" );
                }break;
            }
        }
        return $xhtmlTextContent;
    }