@param TreeNodeInterface $treeNode
@param int               $version
@param string            $language

@return string
352006
public function hashNode(TreeNodeInterface $treeNode, $version, $language)
    {
        $identifier = "{$treeNode->getId()}__{$version}__{$language}";

        if (isset($this->hashes[$identifier])) {
            return $this->hashes[$identifier];
        }

        $values = $this->createHashValuesByTreeNode($treeNode, $version, $language);
        $hash = $this->hashValues($values);

        $this->hashes[$identifier] = $hash;

        return $hash;
    }
734855
public function getChildrenQueryBuilder(Node $parent, $lang = null)
    {
        return $this->getNodeTranslationsQueryBuilder($lang)
            ->andWhere('n.parent = :parent')
            ->setParameter('parent', $parent);
    }
659774
public static function NodeLang( $testLang, $node )
	{
		if ( $node instanceof Undefined )
		{
			return false;
		}

		if ( ! $node instanceof XPathNavigator )
		{
		    throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::XPTY0004,
				array(
					SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $node ), XmlTypeCardinality::ZeroOrOne ),
					"$node()? in fn:lang()"
				)
			);
		}

	    /**
	     * @var XPathNavigator $nav
	     */
		$nav = $node;

		$xmlLang = $nav->getXmlLang();
		if ( $xmlLang == "" )
		{
			return false;
		}

		$lang = ( $testLang instanceof Undefined )
			? ""
			: $testLang . "";

		if ( strcasecmp( $xmlLang, $lang ) == 0 )
		{
			return true;
		}

		$index = strpos( $xmlLang, '-' );

		return $index
			? strcasecmp( substr( $xmlLang, 0, $index ), $lang ) == 0
			: false;
	}
511349
public function deleteTranslationFromVersionFields(VersionInfo $versionInfo, $languageCode)
    {
        $fieldTypeIdsMap = $this->contentGateway->getFieldIdsByType(
            $versionInfo->contentInfo->id,
            $versionInfo->versionNo,
            $languageCode
        );
        foreach ($fieldTypeIdsMap as $fieldType => $ids) {
            $this->storageHandler->deleteFieldData($fieldType, $versionInfo, $ids);
        }
        $this->contentGateway->deleteTranslatedFields(
            $languageCode,
            $versionInfo->contentInfo->id,
            $versionInfo->versionNo
        );
    }
227652
public function load(ElementVersion $elementVersion, $defaultLanguage = null)
    {
        $element = $elementVersion->getElement();

        $identifier = $element->getEid().'_'.$elementVersion->getVersion();

        if (isset($this->map[$identifier])) {
            return $this->map[$identifier];
        }

        $source = $elementVersion->getElementSource();

        $elementtype = $this->xmlParser->parseString($source->getXml());
        $elementtypeStructure = $elementtype->getStructure();

        $structureRows = $this->queryStructures($elementVersion);
        $dataRows = $this->queryValues($elementVersion->getElement()->getEid(), $elementVersion->getVersion());

        $structures = [
            null => $rootStructure = new ElementStructure(),
        ];

        $rootId = null;
        $rootStructure->setDefaultLanguage($defaultLanguage);

        if (!$structureRows && !$dataRows) {
            return $rootStructure;
        }

        if (isset($structureRows[null])) {
            foreach ($structureRows[null] as $row) {
                if ($row['type'] === 'root') {
                    $rootId = $row['id'];
                    $rootStructure
                        ->setDefaultLanguage($defaultLanguage)
                        ->setId($row['id'])
                        ->setDataId($row['data_id'])
                        ->setDsId($row['ds_id'])
                        ->setType($row['type'])
                        ->setName($row['name']);
                    continue;
                }
                $myNode = $elementtypeStructure->getNode($row['ds_id']);
                if (!$myNode) {
                    continue;
                }
                $myParentNode = $myNode;
                do {
                    $myParentNode = $elementtypeStructure->getNode($myParentNode->getParentDsId());
                } while (in_array($myParentNode->getType(), ['reference', 'referenceroot']));

                $structure = new ElementStructure();
                $structure
                    ->setDefaultLanguage($defaultLanguage)
                    ->setId($row['id'])
                    ->setDataId($row['data_id'])
                    ->setDsId($row['ds_id'])
                    ->setType($row['type'])
                    ->setName($myNode->getName()) // $row['name'])
                    ->setParentName($myParentNode->getName());
                $rootStructure->addStructure($structure);
                $structures[$row['id']] = $structure;
                if (isset($dataRows[$row['id']])) {
                    foreach ($dataRows[$row['id']] as $dataRow) {
                        $structure->setValue($this->createValue($dataRow, $elementtypeStructure));
                    }
                }
            }
        }

        if (isset($dataRows[$rootId])) {
            foreach ($dataRows[$rootId] as $dataRow) {
                $rootStructure->setValue($this->createValue($dataRow, $elementtypeStructure));
            }
        }

        $rii = new \RecursiveIteratorIterator($elementtypeStructure->getIterator(), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($rii as $node) {
            /* @var $node ElementtypeStructureNode */
            if ($node->isRepeatable() || $node->isOptional()) {
                if (isset($structureRows[$node->getDsId()])) {
                    foreach ($structureRows[$node->getDsId()] as $row) {
                        $myNode = $elementtypeStructure->getNode($row['ds_id']);
                        if (!$myNode) {
                            continue;
                        }
                        $myParentNode = $myNode;
                        do {
                            $myParentNode = $elementtypeStructure->getNode($myParentNode->getParentDsId());
                        } while (in_array($myParentNode->getType(), ['reference', 'referenceroot']));

                        $structure = new ElementStructure();
                        $structure
                            ->setDefaultLanguage($defaultLanguage)
                            ->setId($row['id'])
                            ->setDataId($row['data_id'])
                            ->setDsId($row['ds_id'])
                            ->setType($row['type'])
                            ->setName($myNode->getName()) // $row['name'])
                            ->setParentName($myParentNode->getName());

                        if (!isset($structures[$row['parent_id']])) {
                            continue;
                        }

                        /* @var $parentStructure ElementStructure */
                        $parentStructure = $structures[$row['parent_id']];
                        $parentStructure->addStructure($structure);

                        $structures[$row['id']] = $structure;

                        if (isset($dataRows[$row['id']])) {
                            foreach ($dataRows[$row['id']] as $dataRow) {
                                $structure->setValue($this->createValue($dataRow, $elementtypeStructure));
                            }
                        }
                    }
                }
            }
        }

        $this->map[$identifier] = $rootStructure;

        return $rootStructure;
    }
306983
public function createNewLanguageNode(NodeInterface $node, $language)
    {
        $newNode = clone $node;
        $newNode->setVersion($this->uniqueIdGenerator->generateUniqueId());
        $status = $this->statusRepository->findOneByTranslationState();

        $newNode->setStatus($status);
        $newNode = $this->duplicateArea($node, $newNode, false);

        $newNode->setLanguage($language);
        $newNode->setSeoTitle(null);
        $newNode->setMetaDescription(null);
        $newNode->setMetaIndex(false);
        $newNode->setMetaFollow(false);
        $newNode->setSitemapChangefreq(null);
        $newNode->setSitemapPriority(null);
        $newNode->initializeKeywords();

        $this->eventDispatcher->dispatch(NodeEvents::NODE_ADD_LANGUAGE, new NodeEvent($node));

        return $newNode;
    }
228935
public function getXML( $version = '1.0', $encoding = 'UTF-8', $willFormatOutput = true )
    {
        if (is_null( self::$instance )) {
            self::$instance               = new \DOMDocument( $version, $encoding );
            self::$instance->formatOutput = $willFormatOutput;
        }

        return self::$instance;
    }
13566
protected function printPendingVersion(Version $version, $style)
    {
        /** @var Version $version */
        $id = $version->getId();
        $reflectionClass = new \ReflectionClass($version->getMigration());
        $absolutePath = $reflectionClass->getFileName();
        $fileName = $absolutePath ? $this->getRelativePath(getcwd(), $absolutePath) : '';
        $this->output->writeln("\t<$style>[$id] $fileName</$style>");
    }
1068557
public function createNewErrorNode($nodeId, $name, $parentId, $siteId, $language, $template)
    {
        $node = $this->initializeNode(NodeInterface::ROOT_NODE_ID, $language, $siteId);
        $node->setNodeId($nodeId);
        $node->setParentId($parentId);
        $node->setNodeType(ReadNodeInterface::TYPE_ERROR);
        $node->setName($name);
        $node->setInFooter(false);
        $node->setInMenu(false);
        $node->setTemplate($template);
        $node->setOrder(-1);
        $node = $this->setVersionName($node);

        $this->eventDispatcher->dispatch(NodeEvents::NODE_CREATION, new NodeEvent($node));

        return $node;
    }
803767
public function getLogEntriesRoot($entity, $rootVersion = null)
    {
        $q = $this->getLogEntriesQueryRoot($entity, $rootVersion);

        return $q->getResult();
    }
894076
public function getAdminEditAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $this->layout = 'layouts/administration';

        $block_id = (int) $request->get('block_id');

        if ($block_id === 0) {
            // Creating a new story
            $individual  = Individual::getInstance($request->get('xref', ''), $tree);
            $story_title = '';
            $story_body  = '';
            $languages   = [];

            $title = I18N::translate('Add a story') . ' — ' . e($tree->title());
        } else {
            // Editing an existing story
            $xref = (string) DB::table('block')
                ->where('block_id', '=', $block_id)
                ->value('xref');

            $individual  = Individual::getInstance($xref, $tree);
            $story_title = $this->getBlockSetting($block_id, 'title', '');
            $story_body  = $this->getBlockSetting($block_id, 'story_body', '');
            $languages   = explode(',', $this->getBlockSetting($block_id, 'languages'));

            $title = I18N::translate('Edit the story') . ' — ' . e($tree->title());
        }

        return $this->viewResponse('modules/stories/edit', [
            'block_id'    => $block_id,
            'languages'   => $languages,
            'story_body'  => $story_body,
            'story_title' => $story_title,
            'title'       => $title,
            'tree'        => $tree,
            'individual'  => $individual,
        ]);
    }
1089392
public static function markdown(string $text, Tree $tree): string
    {
        $environment = Environment::createCommonMarkEnvironment();
        $environment->mergeConfig(['html_input' => 'escape']);
        $environment->addExtension(new TableExtension());
        $environment->addExtension(new CensusTableExtension());
        $environment->addExtension(new XrefExtension($tree));

        $converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));

        try {
            return $converter->convertToHtml($text);
        } catch (Throwable $ex) {
            // See issue #1824
            return $text;
        }
    }
630873
public function hasParentNodeTranslationsForLanguage(
        NodeTranslation $nodeTranslation,
        $language
    ) {
        $parentNode = $nodeTranslation->getNode()->getParent();
        if ($parentNode !== null) {
            $parentNodeTranslation = $parentNode->getNodeTranslation(
                $language,
                true
            );
            if ($parentNodeTranslation !== null) {
                return $this->hasParentNodeTranslationsForLanguage(
                    $parentNodeTranslation,
                    $language
                );
            } else {
                return false;
            }
        }

        return true;
    }
3934
public function addChild(TreeNodeInterface $node): void
    {
        $this->children[] = $node;
        $this->isLeaf = false;
    }
866388
public function serializeNodes(array $nodes, $language, TokenInterface $token)
    {
        $return = [];

        foreach ($nodes as $node) {
            $nodeData = $this->serializeNode($node, $language, $token);

            if ($nodeData) {
                $return[] = $nodeData;
            }
        }

        return $return;
    }
275382
public function getShowListAction(Tree $tree): ResponseInterface
    {
        $stories = DB::table('block')
            ->where('module_name', '=', $this->name())
            ->where('gedcom_id', '=', $tree->id())
            ->get()
            ->map(function (stdClass $story) use ($tree): stdClass {
                $block_id = (int) $story->block_id;

                $story->individual = Individual::getInstance($story->xref, $tree);
                $story->title      = $this->getBlockSetting($block_id, 'title');
                $story->languages  = $this->getBlockSetting($block_id, 'languages');

                return $story;
            })->filter(static function (stdClass $story): bool {
                // Filter non-existant and private individuals.
                return $story->individual instanceof Individual && $story->individual->canShow();
            })->filter(static function (stdClass $story): bool {
                // Filter foreign languages.
                return $story->languages === '' || in_array(WT_LOCALE, explode(',', $story->languages), true);
            });

        return $this->viewResponse('modules/stories/list', [
            'stories' => $stories,
            'title'   => $this->title(),
        ]);
    }
1311775
public function getNodeRef($nodeId, $lang = null)
    {
        $this->initNodeVersions();

        $lang = $lang ?: $this->currentLocale->getCurrentLocale();

        return isset($this->nodeRefs[$lang][$nodeId]) ? $this->nodeRefs[$lang][$nodeId] : null;
    }