Imports atom data into the blog

@param string $workspace The workspace to work in
@param string $targetNode The target node (expressed as a FlowQuery find condition)
@param string $atomFile The atom file to import
@return void
350767
public function migrateCommand($workspace, $targetNode, $atomFile)
    {
        if (!class_exists(\SimplePie::class)) {
            $this->outputLine('The Atom import needs simplepie/simplepie, which you can install using composer.');
            $this->quit(1);
        }

        $context = $this->contentContextFactory->create(['workspaceName' => $workspace]);
        $q = new FlowQuery([$context->getRootNode()]);
        $this->blogNode = $q->find($targetNode)->get(0);
        if (!($this->blogNode instanceof NodeInterface)) {
            $this->outputLine('<error>Target node not found.</error>');
            $this->quit(1);
        }

        $parser = new \SimplePie();
        $parser->enable_order_by_date();
        $parser->enable_cache(false);

        $parser->set_raw_data(file_get_contents($atomFile));
        $parser->strip_attributes();
        $parser->strip_htmltags(array_merge($parser->strip_htmltags, ['span']));
        $parser->init();
        $items = $parser->get_items();

        $comments = [];
        /** @var $item \SimplePie_Item */
        foreach ($items as $item) {
            $categories = $item->get_categories();

            if (!is_array($categories)) {
                continue;
            }

            /** @var $category \SimplePie_Category */
            foreach ($categories as $category) {
                if ($category->get_term() === 'http://schemas.google.com/blogger/2008/kind#comment') {
                    $inReplyTo = current($item->get_item_tags('http://purl.org/syndication/thread/1.0', 'in-reply-to'));
                    $inReplyTo = current($inReplyTo['attribs']);
                    $comments[$inReplyTo['ref']][$item->get_date('U')] = $item;
                }
            }
        }

        $textNodeType = $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text');
        $commentNodeType = $this->nodeTypeManager->getNodeType('RobertLemke.Plugin.Blog:Comment');
        $counter = 0;
        foreach ($parser->get_items() as $item) {
            $categories = $item->get_categories();
            if (!is_array($categories)) {
                continue;
            }

            $tags = [];
            $itemIsPost = false;
            foreach ($categories as $category) {
                if ($category->get_term() === 'http://schemas.google.com/blogger/2008/kind#post') {
                    $itemIsPost = true;
                }
                if ($category->get_scheme() === 'http://www.blogger.com/atom/ns#') {
                    $tags[] = $category->get_term();
                }
            }
            if (!$itemIsPost) {
                continue;
            }

            $nodeTemplate = new NodeTemplate();
            $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('RobertLemke.Plugin.Blog:Post'));
            $nodeTemplate->setProperty('title', $item->get_title());
            $nodeTemplate->setProperty('author', $item->get_author()->get_name());
            $published = new \DateTime();
            $published->setTimestamp($item->get_date('U'));
            $nodeTemplate->setProperty('datePublished', $published);
            $nodeTemplate->setProperty('tags', $this->getTagNodes($tags));

            $slug = strtolower(str_replace([' ', ',', ':', 'ü', 'à', 'é', '?', '!', '[', ']', '.', '\''], ['-', '', '', 'u', 'a', 'e', '', '', '', '', '-', ''], $item->get_title()));
            /** @var NodeInterface $postNode */
            $postNode = $this->blogNode->createNodeFromTemplate($nodeTemplate, $slug);
            $postNode->getNode('main')->createNode(uniqid('node'), $textNodeType)->setProperty('text', $item->get_content());

            $postComments = isset($comments[$item->get_id()]) ? $comments[$item->get_id()] : [];
            if ($postComments !== []) {
                /** @var NodeInterface $commentsNode */
                $commentsNode = $postNode->getNode('comments');
                /** @var $postComment \SimplePie_Item */
                foreach ($postComments as $postComment) {
                    $commentNode = $commentsNode->createNode(uniqid('comment-'), $commentNodeType);
                    $commentNode->setProperty('author', html_entity_decode($postComment->get_author()->get_name(), ENT_QUOTES, 'utf-8'));
                    $commentNode->setProperty('emailAddress', $postComment->get_author()->get_email());
                    $commentNode->setProperty('uri', $postComment->get_author()->get_link());
                    $commentNode->setProperty('datePublished', new \DateTime($postComment->get_date()));
                    $commentText = preg_replace('/<br[ \/]*>/i', chr(10), $postComment->get_content());
                    $commentText = html_entity_decode($commentText, ENT_QUOTES, 'utf-8');
                    $commentNode->setProperty('text', $commentText);
                    $commentNode->setProperty('spam', false);
                    $previousCommentNode = $commentNode;
                    if ($previousCommentNode !== null) {
                        $commentNode->moveAfter($previousCommentNode);
                    }
                }
            }

            $counter++;
            $this->outputLine($postNode->getProperty('title') . ' by ' . $postNode->getProperty('author'));
        }

        $this->outputLine('Imported %s blog posts.', [$counter]);
    }
374822
public function import($page, $areaHandle, SimpleXMLElement $blockNode)
    {
        parent::import($page, $areaHandle, $blockNode);
    }
709598
private function addResolveTargetDocumentsSection(ArrayNodeDefinition $rootNode)
    {
        $rootNode
            ->fixXmlConfig('resolve_target_document')
            ->children()
                ->arrayNode('resolve_target_documents')
                    ->useAttributeAsKey('interface')
                    ->prototype('scalar')
                        ->cannotBeEmpty()
                    ->end()
                ->end()
            ->end();
    }
1241964
public static function convertJsonToIni( $sourceFile, $targetFile )
	{
		$data	= self::loadJson( $sourceFile );
		return self::saveIni( $targetFile, $data );
	}
230560
protected function removeNodeAndChildNodesInWorkspaceByPath($nodePath, $workspaceName)
    {
        /** @var QueryBuilder $queryBuilder */
        $queryBuilder = $this->entityManager->createQueryBuilder();

        $queryBuilder
            ->resetDQLParts()
            ->delete(NodeData::class, 'n')
            ->where('n.path LIKE :path')
            ->orWhere('n.path LIKE :subpath')
            ->andWhere('n.workspace = :workspace')
            ->setParameters(['path' => $nodePath, 'subpath' => $nodePath . '/%', 'workspace' => $workspaceName])
            ->getQuery()
            ->execute();
    }
789041
public function addChild(self $resourceNode)
    {
        if (!$this->children->contains($resourceNode)) {
            $this->children->add($resourceNode);
        }
    }
1246339
public function addOneToMany($name, $targetEntity, $mappedBy)
    {
        $builder = $this->createOneToMany($name, $targetEntity);
        $builder->mappedBy($mappedBy);

        return $builder->build();
    }
753271
public function package($targetFile, $force)
    {
        if (is_file($targetFile)) {
            if ($force) {
                unlink($targetFile);
            } else {
                throw new \RuntimeException("File {$targetFile} already exists");
            }
        }
        $curDir = getcwd();
        $buildFile = 'build.phar';
        $phar = new \Phar($buildFile);

        if ($static = $this->options['static']) {
            $stub = new Node\StaticStub(
                $phar,
                $this->options['app-name'],
                $this->options['app-version'],
                $this->options['static'],
                $this->options['static-plugin-paths']
            );
        } else {
            $stub = new Node\DynamicStub(
                $phar,
                $this->options['app-name'],
                $this->options['app-version'],
                $this->options['config-filename']
            );
        }
        $buffer = new Buffer();
        $buffer
            ->writeln('#!/usr/bin/env php')
            ->writeln('<?php')
            ->writeln(self::$HEADER)
        ;
        $stub->compile($buffer);

        chdir($this->srcRoot);
        $finder = new Finder();
        $files = $finder
            ->in(array('vendor', 'src'))
            ->ignoreVCS(true)
            // Finder is only used by the packager, not by Z itself.
            ->exclude(array('vendor/symfony/finder'))
            ->files();

        foreach ($files as $file) {
            $phar[$file->getPathname()] = file_get_contents($file->getPathname());
        }
        $phar['LICENSE'] = file_get_contents('LICENSE');
        chdir($curDir);

        $phar->setStub($buffer->getResult());
        rename($buildFile, $targetFile);
        chmod($targetFile, 0755);
        chdir($curDir);

        return realpath($targetFile);
    }
528971
function(node) {
        var atomAttrib = {};
        var value = null;
        var nodes = null;
        var attval = null;
        var atomns = this.namespaces.atom;
        
        // atomAuthor*
        this.parsePersonConstructs(node, "author", atomAttrib);
        
        // atomCategory*
        nodes = this.getElementsByTagNameNS(node, atomns, "category");
        if (nodes.length > 0) {
            atomAttrib.categories = [];
        }
        for (var i=0, ii=nodes.length; i<ii; i++) {
            value = {};
            value.term = nodes[i].getAttribute("term");
            attval = nodes[i].getAttribute("scheme");
            if (attval) { value.scheme = attval; }
            attval = nodes[i].getAttribute("label");
            if (attval) { value.label = attval; }
            atomAttrib.categories.push(value);
        }
        
        // atomContent?
        nodes = this.getElementsByTagNameNS(node, atomns, "content");
        if (nodes.length > 0) {
            value = {};
            attval = nodes[0].getAttribute("type");
            if (attval) {
                value.type = attval;
            }
            attval = nodes[0].getAttribute("src");
            if (attval) {
                value.src = attval;
            } else {
                if (value.type == "text" || 
                    value.type == "html" || 
                    value.type == null ) {
                    value.value = this.getFirstChildValue(
                                        node,
                                        atomns,
                                        "content",
                                        null
                                        );
                } else if (value.type == "xhtml" ||
                           value.type.match(/(\+|\/)xml$/)) {
                    value.value = this.getChildEl(nodes[0]);
                } else { // MUST be base64 encoded
                    value.value = this.getFirstChildValue(
                                        node,
                                        atomns,
                                        "content",
                                        null
                                        );
                }
                atomAttrib.content = value;
            }
        }
        
        // atomContributor*
        this.parsePersonConstructs(node, "contributor", atomAttrib);
        
        // atomId
        atomAttrib.id = this.getFirstChildValue(node, atomns, "id", null);
        
        // atomLink*
        nodes = this.getElementsByTagNameNS(node, atomns, "link");
        if (nodes.length > 0) {
            atomAttrib.links = new Array(nodes.length);
        }
        var oAtts = ["rel", "type", "hreflang", "title", "length"];
        for (var i=0, ii=nodes.length; i<ii; i++) {
            value = {};
            value.href = nodes[i].getAttribute("href");
            for (var j=0, jj=oAtts.length; j<jj; j++) {
                attval = nodes[i].getAttribute(oAtts[j]);
                if (attval) {
                    value[oAtts[j]] = attval;
                }
            }
            atomAttrib.links[i] = value;
        }
        
        // atomPublished?
        value = this.getFirstChildValue(node, atomns, "published", null);
        if (value) {
            atomAttrib.published = value;
        }
        
        // atomRights?
        value = this.getFirstChildValue(node, atomns, "rights", null);
        if (value) {
            atomAttrib.rights = value;
        }
        
        // atomSource? -- not implemented
        
        // atomSummary?
        value = this.getFirstChildValue(node, atomns, "summary", null);
        if (value) {
            atomAttrib.summary = value;
        }
        
        // atomTitle
        atomAttrib.title = this.getFirstChildValue(
                                node, atomns, "title", null
                                );
        
        // atomUpdated
        atomAttrib.updated = this.getFirstChildValue(
                                node, atomns, "updated", null
                                );
        
        var featureAttrib = {
            title: atomAttrib.title,
            description: atomAttrib.summary,
            atom: atomAttrib
        };
        var geometry = this.parseLocations(node)[0];
        var feature = new OpenLayers.Feature.Vector(geometry, featureAttrib);
        feature.fid = atomAttrib.id;
        return feature;
    }
1219721
private function loadExtensionData(NodeInterface $node, ExtensionInterface $extension, $webspaceKey, $locale)
    {
        $extension->setLanguageCode($locale, $this->namespaceRegistry->getPrefix('extension_localized'), '');
        $data = $extension->load(
            $node,
            $webspaceKey,
            $locale
        );

        return $extension->getContentData($data);
    }
1185415
def add_atom(self, key, atom):
        """"""
        self.graph.add_node(key, atom=atom)
1069182
protected function _mergeNodes($domElemTo, $domElemFrom, $xPathTo, $domDocTo, $queryStart)
    {
        foreach ($domElemFrom->childNodes as $fromNode) {
            if ($fromNode->nodeType === XML_ELEMENT_NODE) {
                $fromAttrName = $fromNode->getAttribute('id');
                $fromNodeName = $fromNode->tagName;

                // find current item
                $query = "{$queryStart}/{$fromNodeName}[@id='{$fromAttrName}']";
                $curNode = $xPathTo->query($query);

                // if not found - append
                if ($curNode->length == 0) {
                    $domElemTo->appendChild($domDocTo->importNode($fromNode, true));
                } else {
                    $curNode = $curNode->item(0);

                    // if found copy all attributes and check childnodes
                    $this->_copyAttributes($curNode, $fromNode);

                    if ($fromNode->childNodes->length) {
                        $this->_mergeNodes($curNode, $fromNode, $xPathTo, $domDocTo, $query);
                    }
                }
            }
        }
    }
845464
public static function import(\DOMElement $source, \DOMElement $target)
    {
        /* Prepare container */
        $container = $target->ownerDocument->createElement('xhtml:div');
        $container->setAttributeNS(Atom::XMLNS, 'xmlns:xhtml', Atom::XHTML);
        $target->appendChild($container);

        /* Prefix all source tags with "xhtml:" */
        $xmlFrom = $source->ownerDocument->saveXML($source);
        $xmlTo = '';
        $xhtmlNsSet = false;
        $parser = xml_parser_create('UTF-8');
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_set_element_handler(
            $parser,
            function ($parser, $name, array $attrs) use ($xmlFrom, &$xmlTo, &$xhtmlNsSet) {
                $selfClosing = '/>' === substr($xmlFrom, xml_get_current_byte_index($parser), 2);
                $xmlTo .= '<xhtml:' . $name;
                if (false === $xhtmlNsSet) {
                    $attrs['xmlns:xhtml'] = Atom::XHTML;
                    $xhtmlNsSet = true;
                }
                foreach ($attrs as $attr => $value) {
                    $xmlTo .= sprintf(
                        ' %s="%s"',
                        $attr,
                        htmlspecialchars($value, ENT_COMPAT | ENT_XML1)
                    );
                }
                $xmlTo .= $selfClosing ? '/>' : '>';
            },
            function ($parser, $name) use ($xmlFrom, &$xmlTo) {
                $selfClosing = '/>' ===
                    substr($xmlFrom, xml_get_current_byte_index($parser) - 2, 2);
                if ($selfClosing) {
                    return;
                }
                $xmlTo .= '</xhtml:' . $name . '>';
            }
        );
        xml_set_default_handler(
            $parser,
            function ($parser, $data) use (&$xmlTo) {
                $xmlTo .= $data;
            }
        );
        xml_parse($parser, $xmlFrom, true);
        xml_parser_free($parser);

        /* Import prefixed XML into container */
        $tmpDoc = new \DOMDocument('1.0', 'utf-8');
        $tmpDoc->loadXML($xmlTo);
        foreach ($tmpDoc->documentElement->childNodes as $node) {
            $container->appendChild($container->ownerDocument->importNode($node, true));
        }
    }
392299
public function preloadNode($ref, string $namespace = NcrPreloader::DEFAULT_NAMESPACE): void
    {
        $nodeRef = $this->toNodeRef($ref);
        if (!$nodeRef instanceof NodeRef) {
            return;
        }

        $this->ncrPreloader->addNodeRef($nodeRef, $namespace);
    }
531843
protected void parseWorkspaceElement(final Element element) throws ProponoException {
        final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT);
        setTitle(titleElem.getText());
        if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) {
            setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue());
        }
        final List<Element> collections = element.getChildren("collection", AtomService.ATOM_PROTOCOL);
        for (final Element e : collections) {
            addCollection(new Collection(e));
        }
    }
1286478
public function importXmlRdf($targetNameSpace, $fileLocation)
    {
        $returnValue = (bool) false;

        if(!file_exists($fileLocation) || !is_readable($fileLocation)){
            throw new common_Exception("Unable to load ontology : $fileLocation");
        }
        
	    if(!preg_match("/#$/", $targetNameSpace)){
			$targetNameSpace .= '#';
		}
		$modFactory = new core_kernel_api_ModelFactory();
		$returnValue = $modFactory->createModel($targetNameSpace, file_get_contents($fileLocation));
		


        return (bool) $returnValue;
    }
561230
private function setWorkflowStageOnNode(NodeInterface $node, $locale, $workflowStage, \DateTime $publishDate = null)
    {
        $node->setProperty(
            $this->propertyEncoder->localizedSystemName(self::WORKFLOW_STAGE_FIELD, $locale),
            $workflowStage
        );

        if ($publishDate) {
            $node->setProperty(
                $this->propertyEncoder->localizedSystemName(self::PUBLISHED_FIELD, $locale),
                $publishDate
            );
        }
    }