function print_fact(WT_Fact $fact, WT_GedcomRecord $record)
{
    global $HIDE_GEDCOM_ERRORS, $SHOW_FACT_ICONS;
    static $n_chil = 0, $n_gchi = 0;
    $parent = $fact->getParent();
    // Some facts don't get printed here ...
    switch ($fact->getTag()) {
        case 'NOTE':
            print_main_notes($fact, 1);
            return;
        case 'SOUR':
            print_main_sources($fact, 1);
            return;
        case 'OBJE':
            print_main_media($fact, 1);
            return;
        case 'FAMC':
        case 'FAMS':
        case 'CHIL':
        case 'HUSB':
        case 'WIFE':
            // These are internal links, not facts
            return;
        case '_WT_OBJE_SORT':
            // These links are used internally to record the sort order.
            return;
        default:
            // Hide unrecognized/custom tags?
            if ($HIDE_GEDCOM_ERRORS && !WT_Gedcom_Tag::isTag($fact->getTag())) {
                return;
            }
            break;
    }
    // Who is this fact about?  Need it to translate fact label correctly
    if ($parent instanceof WT_Family && $record instanceof WT_Individual) {
        // Family event
        $label_person = $fact->getParent()->getSpouse($record);
    } else {
        // Individual event
        $label_person = $parent;
    }
    // New or deleted facts need different styling
    $styleadd = '';
    if ($fact->isNew()) {
        $styleadd = 'new';
    }
    if ($fact->isOld()) {
        $styleadd = 'old';
    }
    // Event of close relative
    if (preg_match('/^_[A-Z_]{3,5}_[A-Z0-9]{4}$/', $fact->getTag())) {
        $styleadd = trim($styleadd . ' rela');
    }
    // Event of close associates
    if ($fact->getFactId() == 'asso') {
        $styleadd = trim($styleadd . ' rela');
    }
    // historical facts
    if ($fact->getFactId() == 'histo') {
        $styleadd = trim($styleadd . ' histo');
    }
    // Does this fact have a type?
    if (preg_match('/\\n2 TYPE (.+)/', $fact->getGedcom(), $match)) {
        $type = $match[1];
    } else {
        $type = '';
    }
    switch ($fact->getTag()) {
        case 'EVEN':
        case 'FACT':
            if (WT_Gedcom_Tag::isTag($type)) {
                // Some users (just Meliza?) use "1 EVEN/2 TYPE BIRT".  Translate the TYPE.
                $label = WT_Gedcom_Tag::getLabel($type, $label_person);
                $type = '';
                // Do not print this again
            } elseif ($type) {
                // We don't have a translation for $type - but a custom translation might exist.
                $label = WT_I18N::translate(WT_Filter::escapeHtml($type));
                $type = '';
                // Do not print this again
            } else {
                // An unspecified fact/event
                $label = $fact->getLabel();
            }
            break;
        case 'MARR':
            // This is a hack for a proprietory extension.  Is it still used/needed?
            $utype = strtoupper($type);
            if ($utype == 'CIVIL' || $utype == 'PARTNERS' || $utype == 'RELIGIOUS') {
                $label = WT_Gedcom_Tag::getLabel('MARR_' . $utype, $label_person);
                $type = '';
                // Do not print this again
            } else {
                $label = $fact->getLabel();
            }
            break;
        default:
            // Normal fact/event
            $label = $fact->getLabel();
            break;
    }
    echo '<tr class="', $styleadd, '">';
    echo '<td class="descriptionbox width20">';
    if ($SHOW_FACT_ICONS) {
        echo $fact->Icon(), ' ';
    }
    if ($fact->getFactId() != 'histo' && $fact->canEdit()) {
        ?>
		<a
			href="#"
			title="<?php 
        echo WT_I18N::translate('Edit');
        ?>
"
			onclick="return edit_record('<?php 
        echo $parent->getXref();
        ?>
', '<?php 
        echo $fact->getFactId();
        ?>
');"
		><?php 
        echo $label;
        ?>
</a>
		<div class="editfacts">
			<div class="editlink">
				<a
					href="#"
					title="<?php 
        echo WT_I18N::translate('Edit');
        ?>
"
					class="editicon"
					onclick="return edit_record('<?php 
        echo $parent->getXref();
        ?>
', '<?php 
        echo $fact->getFactId();
        ?>
');"
				><span class="link_text"><?php 
        echo WT_I18N::translate('Edit');
        ?>
</span></a>
			</div>
			<div class="copylink">
				<a
					href="#"
					title="<?php 
        echo WT_I18N::translate('Copy');
        ?>
"
					class="copyicon"
					onclick="return copy_fact('<?php 
        echo $parent->getXref();
        ?>
', '<?php 
        echo $fact->getFactId();
        ?>
');"
				><span class="link_text"><?php 
        echo WT_I18N::translate('Copy');
        ?>
</span></a>
			</div>
			<div class="deletelink">
				<a
					href="#"
					title="<?php 
        echo WT_I18N::translate('Delete');
        ?>
"
					class="deleteicon"
					onclick="return delete_fact('<?php 
        echo WT_I18N::translate('Are you sure you want to delete this fact?');
        ?>
', '<?php 
        echo $parent->getXref();
        ?>
', '<?php 
        echo $fact->getFactId();
        ?>
');"
				><span class="link_text"><?php 
        echo WT_I18N::translate('Delete');
        ?>
</span></a>
			</div>
		</div>
		<?php 
    } else {
        echo $label;
    }
    switch ($fact->getTag()) {
        case '_BIRT_CHIL':
            echo '<br>', WT_I18N::translate('#%s', ++$n_chil);
            break;
        case '_BIRT_GCHI':
        case '_BIRT_GCH1':
        case '_BIRT_GCH2':
            echo '<br>', WT_I18N::translate('#%s', ++$n_gchi);
            break;
    }
    echo '</td><td class="optionbox ', $styleadd, ' wrap">';
    // Event from another record?
    if ($parent !== $record) {
        if ($parent instanceof WT_Family) {
            foreach ($parent->getSpouses() as $spouse) {
                if ($record !== $spouse) {
                    echo '<a href="', $spouse->getHtmlUrl(), '">', $spouse->getFullName(), '</a> — ';
                }
            }
            echo '<a href="', $parent->getHtmlUrl(), '">', WT_I18N::translate('View family'), '</a><br>';
        } elseif ($parent instanceof WT_Individual) {
            echo '<a href="', $parent->getHtmlUrl(), '">', $parent->getFullName(), '</a><br>';
        }
    }
    // Print the value of this fact/event
    switch ($fact->getTag()) {
        case 'ADDR':
            echo $fact->getValue();
            break;
        case 'AFN':
            echo '<div class="field"><a href="https://familysearch.org/search/tree/results#count=20&query=afn:', rawurlencode($fact->getValue()), '" target="new">', WT_Filter::escapeHtml($fact->getValue()), '</a></div>';
            break;
        case 'ASSO':
            // we handle this later, in format_asso_rela_record()
            break;
        case 'EMAIL':
        case 'EMAI':
        case '_EMAIL':
            echo '<div class="field"><a href="mailto:', WT_Filter::escapeHtml($fact->getValue()), '">', WT_Filter::escapeHtml($fact->getValue()), '</a></div>';
            break;
        case 'FILE':
            if (WT_USER_CAN_EDIT || WT_USER_CAN_ACCEPT) {
                echo '<div class="field">', WT_Filter::escapeHtml($fact->getValue()), '</div>';
            }
            break;
        case 'RESN':
            echo '<div class="field">';
            switch ($fact->getValue()) {
                case 'none':
                    // Note: "1 RESN none" is not valid gedcom.
                    // However, webtrees privacy rules will interpret it as "show an otherwise private record to public".
                    echo '<i class="icon-resn-none"></i> ', WT_I18N::translate('Show to visitors');
                    break;
                case 'privacy':
                    echo '<i class="icon-class-none"></i> ', WT_I18N::translate('Show to members');
                    break;
                case 'confidential':
                    echo '<i class="icon-confidential-none"></i> ', WT_I18N::translate('Show to managers');
                    break;
                case 'locked':
                    echo '<i class="icon-locked-none"></i> ', WT_I18N::translate('Only managers can edit');
                    break;
                default:
                    echo WT_Filter::escapeHtml($fact->getValue());
                    break;
            }
            echo '</div>';
            break;
        case 'PUBL':
            // Publication details might contain URLs.
            echo '<div class="field">', WT_Filter::expandUrls($fact->getValue()), '</div>';
            break;
        case 'REPO':
            if (preg_match('/^@(' . WT_REGEX_XREF . ')@$/', $fact->getValue(), $match)) {
                print_repository_record($match[1]);
            } else {
                echo '<div class="error">', WT_Filter::escapeHtml($fact->getValue()), '</div>';
            }
            break;
        case 'URL':
        case '_URL':
        case 'WWW':
            echo '<div class="field"><a href="', WT_Filter::escapeHtml($fact->getValue()), '">', WT_Filter::escapeHtml($fact->getValue()), '</a></div>';
            break;
        case 'TEXT':
            // 0 SOUR / 1 TEXT
            echo '<div class="field">', nl2br(WT_Filter::escapeHtml($fact->getValue()), false), '</div>';
            break;
        default:
            // Display the value for all other facts/events
            switch ($fact->getValue()) {
                case '':
                    // Nothing to display
                    break;
                case 'N':
                    // Not valid GEDCOM
                    echo '<div class="field">', WT_I18N::translate('No'), '</div>';
                    break;
                case 'Y':
                    // Do not display "Yes".
                    break;
                default:
                    if (preg_match('/^@(' . WT_REGEX_XREF . ')@$/', $fact->getValue(), $match)) {
                        $target = WT_GedcomRecord::getInstance($match[1]);
                        if ($target) {
                            echo '<div><a href="', $target->getHtmlUrl(), '">', $target->getFullName(), '</a></div>';
                        } else {
                            echo '<div class="error">', WT_Filter::escapeHtml($fact->getValue()), '</div>';
                        }
                    } else {
                        echo '<div class="field"><span dir="auto">', WT_Filter::escapeHtml($fact->getValue()), '</span></div>';
                    }
                    break;
            }
            break;
    }
    // Print the type of this fact/event
    if ($type) {
        $utype = strtoupper($type);
        // Events of close relatives, e.g. _MARR_CHIL
        if (substr($fact->getTag(), 0, 6) == '_MARR_' && ($utype == 'CIVIL' || $utype == 'PARTNERS' || $utype == 'RELIGIOUS')) {
            // Translate MARR/TYPE using the code that supports MARR_CIVIL, etc. tags
            $type = WT_Gedcom_Tag::getLabel('MARR_' . $utype);
        } else {
            // Allow (custom) translations for other types
            $type = WT_I18N::translate($type);
        }
        echo WT_Gedcom_Tag::getLabelValue('TYPE', WT_Filter::escapeHtml($type));
    }
    // Print the date of this fact/event
    echo format_fact_date($fact, $record, true, true);
    // Print the place of this fact/event
    echo '<div class="place">', format_fact_place($fact, true, true, true), '</div>';
    // A blank line between the primary attributes (value, date, place) and the secondary ones
    echo '<br>';
    $addr = $fact->getAttribute('ADDR');
    if ($addr) {
        echo WT_Gedcom_Tag::getLabelValue('ADDR', $addr);
    }
    // Print the associates of this fact/event
    echo format_asso_rela_record($fact);
    // Print any other "2 XXXX" attributes, in the order in which they appear.
    preg_match_all('/\\n2 (' . WT_REGEX_TAG . ') (.+)/', $fact->getGedcom(), $matches, PREG_SET_ORDER);
    foreach ($matches as $match) {
        switch ($match[1]) {
            case 'DATE':
            case 'TIME':
            case 'AGE':
            case 'PLAC':
            case 'ADDR':
            case 'ALIA':
            case 'ASSO':
            case '_ASSO':
            case 'DESC':
            case 'RELA':
            case 'STAT':
            case 'TEMP':
            case 'TYPE':
            case 'FAMS':
            case 'CONT':
                // These were already shown at the beginning
                break;
            case 'NOTE':
            case 'OBJE':
            case 'SOUR':
                // These will be shown at the end
                break;
            case 'EVEN':
                // 0 SOUR / 1 DATA / 2 EVEN / 3 DATE / 3 PLAC
                $events = array();
                foreach (preg_split('/ *, */', $match[2]) as $event) {
                    $events[] = WT_Gedcom_Tag::getLabel($event);
                }
                if (count($events) == 1) {
                    echo WT_Gedcom_Tag::getLabelValue('EVEN', $event);
                } else {
                    echo WT_Gedcom_Tag::getLabelValue('EVEN', implode(WT_I18N::$list_separator, $events));
                }
                if (preg_match('/\\n3 DATE (.+)/', $fact->getGedcom(), $date_match)) {
                    $date = new WT_Date($date_match[1]);
                    echo WT_Gedcom_Tag::getLabelValue('DATE', $date->Display());
                }
                if (preg_match('/\\n3 PLAC (.+)/', $fact->getGedcom(), $plac_match)) {
                    echo WT_Gedcom_Tag::getLabelValue('PLAC', $plac_match[1]);
                }
                break;
            case 'FAMC':
                // 0 INDI / 1 ADOP / 2 FAMC / 3 ADOP
                $family = WT_Family::getInstance(str_replace('@', '', $match[2]));
                if ($family) {
                    // May be a pointer to a non-existant record
                    echo WT_Gedcom_Tag::getLabelValue('FAM', '<a href="' . $family->getHtmlUrl() . '">' . $family->getFullName() . '</a>');
                    if (preg_match('/\\n3 ADOP (HUSB|WIFE|BOTH)/', $fact->getGedcom(), $match)) {
                        echo WT_Gedcom_Tag::getLabelValue('ADOP', WT_Gedcom_Code_Adop::getValue($match[1], $label_person));
                    }
                } else {
                    echo WT_Gedcom_Tag::getLabelValue('FAM', '<span class="error">' . $match[2] . '</span>');
                }
                break;
            case '_WT_USER':
                $user = User::findByIdentifier($match[2]);
                // may not exist
                if ($user) {
                    echo WT_Gedcom_Tag::getLabelValue('_WT_USER', WT_Filter::escapeHtml($user->getRealName()));
                } else {
                    echo WT_Gedcom_Tag::getLabelValue('_WT_USER', WT_Filter::escapeHtml($match[2]));
                }
                break;
            case 'RESN':
                switch ($match[2]) {
                    case 'none':
                        // Note: "2 RESN none" is not valid gedcom.
                        // However, webtrees privacy rules will interpret it as "show an otherwise private fact to public".
                        echo WT_Gedcom_Tag::getLabelValue('RESN', '<i class="icon-resn-none"></i> ' . WT_I18N::translate('Show to visitors'));
                        break;
                    case 'privacy':
                        echo WT_Gedcom_Tag::getLabelValue('RESN', '<i class="icon-resn-privacy"></i> ' . WT_I18N::translate('Show to members'));
                        break;
                    case 'confidential':
                        echo WT_Gedcom_Tag::getLabelValue('RESN', '<i class="icon-resn-confidential"></i> ' . WT_I18N::translate('Show to managers'));
                        break;
                    case 'locked':
                        echo WT_Gedcom_Tag::getLabelValue('RESN', '<i class="icon-resn-locked"></i> ' . WT_I18N::translate('Only managers can edit'));
                        break;
                    default:
                        echo WT_Gedcom_Tag::getLabelValue('RESN', WT_Filter::escapeHtml($match[2]));
                        break;
                }
                break;
            case 'CALN':
                echo WT_Gedcom_Tag::getLabelValue('CALN', WT_Filter::expandUrls($match[2]));
                break;
            case 'FORM':
                // 0 OBJE / 1 FILE / 2 FORM / 3 TYPE
                echo WT_Gedcom_Tag::getLabelValue('FORM', $match[2]);
                if (preg_match('/\\n3 TYPE (.+)/', $fact->getGedcom(), $type_match)) {
                    echo WT_Gedcom_Tag::getLabelValue('TYPE', WT_Gedcom_Tag::getFileFormTypeValue($type_match[1]));
                }
                break;
            case 'URL':
            case '_URL':
            case 'WWW':
                $link = '<a href="' . WT_Filter::escapeHtml($match[2]) . '">' . WT_Filter::escapeHtml($match[2]) . '</a>';
                echo WT_Gedcom_Tag::getLabelValue($fact->getTag() . ':' . $match[1], $link);
                break;
            default:
                if (!$HIDE_GEDCOM_ERRORS || WT_Gedcom_Tag::isTag($match[1])) {
                    if (preg_match('/^@(' . WT_REGEX_XREF . ')@$/', $match[2], $xmatch)) {
                        // Links
                        $linked_record = WT_GedcomRecord::getInstance($xmatch[1]);
                        if ($linked_record) {
                            $link = '<a href="' . $linked_record->getHtmlUrl() . '">' . $linked_record->getFullName() . '</a>';
                            echo WT_Gedcom_Tag::getLabelValue($fact->getTag() . ':' . $match[1], $link);
                        } else {
                            echo WT_Gedcom_Tag::getLabelValue($fact->getTag() . ':' . $match[1], WT_Filter::escapeHtml($match[2]));
                        }
                    } else {
                        // Non links
                        echo WT_Gedcom_Tag::getLabelValue($fact->getTag() . ':' . $match[1], WT_Filter::escapeHtml($match[2]));
                    }
                }
                break;
        }
    }
    echo print_fact_sources($fact->getGedcom(), 2);
    echo print_fact_notes($fact->getGedcom(), 2);
    print_media_links($fact->getGedcom(), 2);
    echo '</td></tr>';
}
Beispiel #2
0
function edit_field_adop($name, $selected = '', $extra = '', WT_Individual $individual = null)
{
    return select_edit_control($name, WT_Gedcom_Code_Adop::getValues($individual), null, $selected, $extra);
}