Format a name record

@param Tree $tree
@param int  $n
@param Fact $fact

@return string
547592
private function formatNameRecord(Tree $tree, $n, Fact $fact): string
    {
        $individual = $fact->record();

        // Create a dummy record, so we can extract the formatted NAME value from it.
        $dummy = new Individual(
            'xref',
            "0 @xref@ INDI\n1 DEAT Y\n" . $fact->gedcom(),
            null,
            $individual->tree()
        );
        $dummy->setPrimaryName(0); // Make sure we use the name from "1 NAME"

        $container_class = 'card';
        $content_class   = 'collapse';
        $aria            = 'false';

        if ($n === 0) {
            $content_class = 'collapse show';
            $aria          = 'true';
        }
        if ($fact->isPendingDeletion()) {
            $container_class .= ' old';
        } elseif ($fact->isPendingAddition()) {
            $container_class .= ' new';
        }

        ob_start();
        echo '<dl><dt class="label">', I18N::translate('Name'), '</dt>';
        echo '<dd class="field">', $dummy->fullName(), '</dd>';
        $ct = preg_match_all('/\n2 (\w+) (.*)/', $fact->gedcom(), $nmatch, PREG_SET_ORDER);
        for ($i = 0; $i < $ct; $i++) {
            $tag = $nmatch[$i][1];
            if ($tag !== 'SOUR' && $tag !== 'NOTE' && $tag !== 'SPFX') {
                echo '<dt class="label">', GedcomTag::getLabel($tag, $individual), '</dt>';
                echo '<dd class="field">'; // Before using dir="auto" on this field, note that Gecko treats this as an inline element but WebKit treats it as a block element
                if (isset($nmatch[$i][2])) {
                    $name = e($nmatch[$i][2]);
                    $name = str_replace('/', '', $name);
                    $name = preg_replace('/(\S*)\*/', '<span class="starredname">\\1</span>', $name);
                    switch ($tag) {
                        case 'TYPE':
                            echo GedcomCodeName::getValue($name, $individual);
                            break;
                        case 'SURN':
                            // The SURN field is not necessarily the surname.
                            // Where it is not a substring of the real surname, show it after the real surname.
                            $surname = e($dummy->getAllNames()[0]['surname']);
                            $surns   = preg_replace('/, */', ' ', $nmatch[$i][2]);
                            if (strpos($dummy->getAllNames()[0]['surname'], $surns) !== false) {
                                echo '<span dir="auto">' . $surname . '</span>';
                            } else {
                                echo I18N::translate('%1$s (%2$s)', '<span dir="auto">' . $surname . '</span>', '<span dir="auto">' . $name . '</span>');
                            }
                            break;
                        default:
                            echo '<span dir="auto">' . $name . '</span>';
                            break;
                    }
                }
                echo '</dd>';
                echo '</dl>';
            }
        }
        if (strpos($fact->gedcom(), "\n2 SOUR") !== false) {
            echo '<div id="indi_sour" class="clearfix">', FunctionsPrintFacts::printFactSources($tree, $fact->gedcom(), 2), '</div>';
        }
        if (strpos($fact->gedcom(), "\n2 NOTE") !== false) {
            echo '<div id="indi_note" class="clearfix">', FunctionsPrint::printFactNotes($tree, $fact->gedcom(), 2), '</div>';
        }
        $content = ob_get_clean();

        if ($fact->canEdit()) {
            $edit_links =
                '<a class="btn btn-link" href="#" data-confirm="' . I18N::translate('Are you sure you want to delete this fact?') . '" onclick="return delete_fact(this.dataset.confirm, \'' . e($individual->tree()->name()) . '\', \'' . e($individual->xref()) . '\', \'' . $fact->id() . '\');" title="' . I18N::translate('Delete this name') . '">' . view('icons/delete') . '<span class="sr-only">' . I18N::translate('Delete this name') . '</span></a>' .
                '<a class="btn btn-link" href="' . e(route('edit-name', ['xref' => $individual->xref(), 'fact_id' => $fact->id(), 'ged' => $individual->tree()->name()])) . '" title="' . I18N::translate('Edit the name') . '">' . view('icons/edit') . '<span class="sr-only">' . I18N::translate('Edit the name') . '</span></a>';
        } else {
            $edit_links = '';
        }

        return '
			<div class="' . $container_class . '">
        <div class="card-header" role="tab" id="name-header-' . $n . '">
		        <a data-toggle="collapse" data-parent="#individual-names" href="#name-content-' . $n . '" aria-expanded="' . $aria . '" aria-controls="name-content-' . $n . '">' . $dummy->fullName() . '</a>
		      ' . $edit_links . '
        </div>
		    <div id="name-content-' . $n . '" class="' . $content_class . '" role="tabpanel" aria-labelledby="name-header-' . $n . '">
		      <div class="card-body">' . $content . '</div>
        </div>
      </div>';
    }
1345529
public static function formatResult($result, $decorate = true)
    {
        $name = isset(self::$stateNames[$result]) ? self::$stateNames[$result] : $result;

        return $decorate && $result === Activity::RESULT_FAILURE
            ? '<error>' . $name . '</error>'
            : $name;
    }
217275
public function updateFact(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref    = $request->get('xref', '');
        $fact_id = $request->get('fact_id', '');

        $record = GedcomRecord::getInstance($xref, $tree);
        Auth::checkRecordAccess($record, true);

        $keep_chan = (bool) $request->get('keep_chan');

        $this->glevels = $request->get('glevels', []);
        $this->tag     = $request->get('tag', []);
        $this->text    = $request->get('text', []);
        $this->islink  = $request->get('islink', []);

        // If the fact has a DATE or PLAC, then delete any value of Y
        if ($this->text[0] === 'Y') {
            foreach ($this->tag as $n => $value) {
                if ($this->glevels[$n] == 2 && ($value === 'DATE' || $value === 'PLAC') && $this->text[$n] !== '') {
                    $this->text[0] = '';
                    break;
                }
            }
        }

        $newged = '';
        if (!empty($_POST['NAME'])) {
            $newged     .= "\n1 NAME " . $_POST['NAME'];
            $name_facts = [
                'TYPE',
                'NPFX',
                'GIVN',
                'NICK',
                'SPFX',
                'SURN',
                'NSFX',
            ];
            foreach ($name_facts as $name_fact) {
                if (!empty($_POST[$name_fact])) {
                    $newged .= "\n2 " . $name_fact . ' ' . $_POST[$name_fact];
                }
            }
        }

        $newged = $this->handleUpdates($newged);

        // Add new names after existing names
        if (!empty($_POST['NAME'])) {
            preg_match_all('/[_0-9A-Z]+/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match);
            $name_facts = array_unique(array_merge(['_MARNM'], $match[0]));
            foreach ($name_facts as $name_fact) {
                // Ignore advanced facts that duplicate standard facts.
                if (!in_array($name_fact, [
                        'TYPE',
                        'NPFX',
                        'GIVN',
                        'NICK',
                        'SPFX',
                        'SURN',
                        'NSFX',
                    ]) && !empty($_POST[$name_fact])) {
                    $newged .= "\n2 " . $name_fact . ' ' . $_POST[$name_fact];
                }
            }
        }

        $newged = trim($newged); // Remove leading newline

        $census_assistant = $this->module_service->findByInterface(CensusAssistantModule::class)->first();
        if ($census_assistant instanceof CensusAssistantModule && $record instanceof Individual) {
            $newged = $census_assistant->updateCensusAssistant($request, $record, $fact_id, $newged, $keep_chan);
        }

        $record->updateFact($fact_id, $newged, !$keep_chan);

        // For the GEDFact_assistant module
        $pid_array = $request->get('pid_array', '');
        if ($pid_array) {
            foreach (explode(',', $pid_array) as $pid) {
                if ($pid !== $xref) {
                    $indi = Individual::getInstance($pid, $tree);
                    if ($indi && $indi->canEdit()) {
                        $indi->updateFact($fact_id, $newged, !$keep_chan);
                    }
                }
            }
        }

        return redirect($record->url());
    }
601732
public function editNameAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref = $request->get('xref', '');

        $individual = Individual::getInstance($xref, $tree);

        Auth::checkIndividualAccess($individual, true);

        // @TODO - Move the name-specific code to this function?
        return app(EditGedcomRecordController::class)->updateFact($request, $tree);
    }
547983
public function chartCommonSurnames(
        string $color_from = null,
        string $color_to = null,
        int $number_of_surnames = 10
    ): string {
        $tot_indi     = $this->totalIndividualsQuery();
        $all_surnames = $this->topSurnames($number_of_surnames, 0);

        if (empty($all_surnames)) {
            return I18N::translate('This information is not available.');
        }

        return (new ChartCommonSurname($this->tree))
            ->chartCommonSurnames($tot_indi, $all_surnames, $color_from, $color_to);
    }
147671
def get_node_fact_by_name(api_url=None, node_name=None, fact_name=None, verify=False, cert=list()):
    
    return utils._make_api_request(api_url, '/nodes/{0}/facts/{1}'.format(node_name,
        fact_name), verify, cert)
743377
public function deleteFact(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref    = $request->get('xref', '');
        $fact_id = $request->get('fact_id');

        $record = GedcomRecord::getInstance($xref, $tree);

        Auth::checkRecordAccess($record, true);

        foreach ($record->facts() as $fact) {
            if ($fact->id() == $fact_id && $fact->canShow() && $fact->canEdit()) {
                $record->deleteFact($fact_id, true);
                break;
            }
        }

        return response();
    }
1038744
public function pageTitle($name = 'default', $language = null, $treeNode = null, Siteroot $siteroot = null)
    {
        $request = $this->requestStack->getCurrentRequest();

        if ($siteroot === null) {
            $siteroot = $request->attributes->get('siterootUrl')->getSiteroot();
        }

        if ($treeNode instanceof ContentTreeContext) {
            $treeNode = $treeNode->getNode();
        }

        if (!($treeNode instanceof TreeNodeInterface)) {
            $treeNode = $request->get('contentDocument');
        }

        if ($language === null) {
            $language = $request->getLocale();
        }

        $title = $this->patternResolver->replace(
            $name,
            $siteroot,
            $treeNode->getTree()->getContent($treeNode),
            $language
        );

        return $title;
    }
491786
public function editName(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $fact_id = $request->get('fact_id', '');
        $xref    = $request->get('xref', '');

        $individual = Individual::getInstance($xref, $tree);

        Auth::checkIndividualAccess($individual, true);

        // Find the fact to edit
        foreach ($individual->facts() as $fact) {
            if ($fact->id() === $fact_id && $fact->canEdit()) {
                return $this->viewResponse('edit/new-individual', [
                    'tree'       => $tree,
                    'title'      => I18N::translate('Edit the name'),
                    'nextaction' => 'update',
                    'individual' => $individual,
                    'family'     => null,
                    'name_fact'  => $fact,
                    'famtag'     => '',
                    'gender'     => $individual->sex(),
                ]);
            }
        }

        throw new NotFoundHttpException();
    }
565762
function(fact) {
        var subject, predicate, object;

        /*if (fact.fromTriple !== undefined) {
            return fact.fromTriple;
        }*/

        if(fact.falseFact) {
            return '';
        }

        subject = this.parseStrEntityToTurtle(fact.subject);
        predicate = this.parseStrEntityToTurtle(fact.predicate);
        object = this.parseStrEntityToTurtle(fact.object);

        if (subject && predicate && object) {
            return subject + ' ' + predicate + ' ' + object + ' . ';
        } else {
            return '';
        }
    }
1372534
public function icon(Fact $fact): string
    {
        $asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png';
        if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
            return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">';
        }

        // Spacer image - for alignment - until we move to a sprite.
        $asset = 'public/css/' . $this->name() . '/images/facts/NULL.png';
        if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
            return '<img src="' . e(asset($asset)) . '">';
        }

        return '';
    }
332503
public function toQuery( $variableSet, $factVariableBinding )
	{
		$expressions = array();

		// Include the qnames if being called as part of a boolean filter or there are qname expressions
		if ( $this->inBoolean || $this->qnameExpressions )
		foreach ( $this->qnames as $qname )
		{
			$name = qname( $qname );
			$expressions[] = "(fn:node-name(..) eq fn:QName('{$name->namespaceURI}','{$name->localName}'))";
		}

		foreach ( $this->qnameExpressions as $qnameExpression )
		{
			$expressions[] = "(fn:node-name(..) eq {$qnameExpression})";
		}

		return implode( " or ", $expressions );
	}
766125
static private function generateName($ns, $node, $hash, $version) {
    $ns_fmt = self::detectFormat($ns);
    $field = self::convert($ns, $ns_fmt, self::FMT_FIELD);

    /* Swap byte order to keep it in big endian on all platforms */
    $field['time_low'] = self::swap32($field['time_low']);
    $field['time_mid'] = self::swap16($field['time_mid']);
    $field['time_hi'] = self::swap16($field['time_hi']);

    /* Convert the namespace to binary and concatenate node */
    $raw = self::convert($field, self::FMT_FIELD, self::FMT_BINARY);
    $raw .= $node;

    /* Hash the namespace and node and convert to a byte array */
    $val = $hash($raw, true);
    $tmp = unpack('C16', $val);
    foreach (array_keys($tmp) as $key)
      $byte[$key - 1] = $tmp[$key];

    /* Convert byte array to a field array */
    $field = self::conv_byte2field($byte);

    $field['time_low'] = self::swap32($field['time_low']);
    $field['time_mid'] = self::swap16($field['time_mid']);
    $field['time_hi'] = self::swap16($field['time_hi']);

    /* Apply version and constants */
    $field['clock_seq_hi'] &= 0x3f;
    $field['clock_seq_hi'] |= (1 << 7);
    $field['time_hi'] &= 0x0fff;
    $field['time_hi'] |= ($version << 12);

    return ($field);
  }
481558
public function getAddNoteAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref = $request->get('xref', '');

        $note = Note::getInstance($xref, $tree);

        if ($note === null) {
            throw new NoteNotFoundException();
        }

        $options = $this->noteOptions($note);

        $title = I18N::translate('Add %s to the clippings cart', $note->fullName());

        return $this->viewResponse('modules/clippings/add-options', [
            'options' => $options,
            'default' => key($options),
            'record'  => $note,
            'title'   => $title,
            'tree'    => $tree,
        ]);
    }
855853
public function toQuery( $variableSet, $factVariableBinding )
	{
		if ( ! $this->substitutionGroups )
		{
			return null;
		}

		$clauses = array();

		if ( isset( $this->substitutionGroups['qnames'] ) && $this->substitutionGroups['qnames'] )
		foreach ( $this->substitutionGroups['qnames'] as $qname )
		{
			$name = qname( $qname );
			$clauses[] = $this->strict
				? "fn:QName('{$name->namespaceURI}','{$name->localName}') eq (xfi:concept-substitutions(fn:node-name(.)))[1]"
				: "fn:QName('{$name->namespaceURI}','{$name->localName}') = xfi:concept-substitutions(fn:node-name(.))";
		}

		if ( isset( $this->substitutionGroups['qnameExpressions'] ) && $this->substitutionGroups['qnameExpressions'] )
		foreach ( $this->substitutionGroups['qnameExpressions'] as $qnameExpression )
		{
			$clauses[] = $this->strict
				? "{$qnameExpression} eq (xfi:concept-substitutions(fn:node-name(.)))[1]"
				: "{$qnameExpression} = xfi:concept-substitutions(fn:node-name(.))";
		}

		return implode( " or ", $clauses );

	}
1187739
public function editRawRecordAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref     = $request->get('xref', '');
        $facts    = (array) $request->get('fact');
        $fact_ids = (array) $request->get('fact_id');
        $record   = GedcomRecord::getInstance($xref, $tree);

        Auth::checkRecordAccess($record, true);

        $gedcom = '0 @' . $record->xref() . '@ ' . $record::RECORD_TYPE;

        // Retain any private facts
        foreach ($record->facts([], false, Auth::PRIV_HIDE) as $fact) {
            if (!in_array($fact->id(), $fact_ids, true) && !$fact->isPendingDeletion()) {
                $gedcom .= "\n" . $fact->gedcom();
            }
        }
        // Append the updated facts
        foreach ($facts as $fact) {
            $gedcom .= "\n" . $fact;
        }

        // Empty lines and MSDOS line endings.
        $gedcom = preg_replace('/[\r\n]+/', "\n", $gedcom);
        $gedcom = trim($gedcom);

        $record->updateRecord($gedcom, false);

        return redirect($record->url());
    }
633787
def _format_node_name(self, record, node, extra=None):
        
        line = ""
        if extra is not None:
            line = "%s(offset=%s, %s)" % (node.__class__.__name__, hex(node.offset() - record.offset()), extra)
        else:
            line = "%s(offset=%s)" % (node.__class__.__name__, hex(node.offset() - record.offset()))

        if isinstance(node, e_nodes.VariantTypeNode):
            line += " --> %s" % (node.string())
        if isinstance(node, e_nodes.OpenStartElementNode):
            line += " --> %s" % (node.tag_name())
        if isinstance(node, e_nodes.AttributeNode):
            line += " --> %s" % (node.attribute_name().string())
        return line