コード例 #1
0
function print_main_media(WT_Fact $fact, $level)
{
    $factrec = $fact->getGedcom();
    $parent = $fact->getParent();
    if ($fact->isNew()) {
        $styleadd = 'new';
        $can_edit = $level == 1 && $fact->canEdit();
    } elseif ($fact->isOld()) {
        $styleadd = 'old';
        $can_edit = false;
    } else {
        $styleadd = '';
        $can_edit = $level == 1 && $fact->canEdit();
    }
    // -- find source for each fact
    preg_match_all('/(?:^|\\n)' . $level . ' OBJE @(.*)@/', $factrec, $matches);
    foreach ($matches[1] as $xref) {
        $media = WT_Media::getInstance($xref);
        // Allow access to "1 OBJE @non_existent_source@", so it can be corrected/deleted
        if (!$media || $media->canShow()) {
            if ($level > 1) {
                echo '<tr class="row_obje2">';
            } else {
                echo '<tr>';
            }
            echo '<td class="descriptionbox';
            if ($level > 1) {
                echo ' rela';
            }
            echo ' ', $styleadd, ' width20">';
            preg_match("/^\\d (\\w*)/", $factrec, $factname);
            $factlines = explode("\n", $factrec);
            // 1 BIRT Y\n2 SOUR ...
            $factwords = explode(" ", $factlines[0]);
            // 1 BIRT Y
            $factname = $factwords[1];
            // BIRT
            if ($factname == 'EVEN' || $factname == 'FACT') {
                // Add ' EVEN' to provide sensible output for an event with an empty TYPE record
                $ct = preg_match("/2 TYPE (.*)/", $factrec, $ematch);
                if ($ct > 0) {
                    $factname = $ematch[1];
                    echo $factname;
                } else {
                    echo WT_Gedcom_Tag::getLabel($factname, $parent);
                }
            } else {
                if ($can_edit) {
                    echo '<a onclick="window.open(\'addmedia.php?action=editmedia&amp;pid=', $media->getXref(), '\', \'_blank\', edit_window_specs); return false;" href="#" title="', WT_I18N::translate('Edit'), '">';
                    echo WT_Gedcom_Tag::getLabel($factname, $parent), '</a>';
                    echo '<div class="editfacts">';
                    echo '<div class="editlink"><a class="editicon" onclick="window.open(\'addmedia.php?action=editmedia&amp;pid=', $media->getXref(), '\', \'_blank\', edit_window_specs); return false;" href="#" title="', WT_I18N::translate('Edit'), '"><span class="link_text">', WT_I18N::translate('Edit'), '</span></a></div>';
                    echo '<div class="copylink"><a class="copyicon" href="#" onclick="jQuery.post(\'action.php\',{action:\'copy-fact\', type:\'\', factgedcom:\'' . rawurlencode($factrec) . '\'},function(){location.reload();})" title="' . WT_I18N::translate('Copy') . '"><span class="link_text">' . WT_I18N::translate('Copy') . '</span></a></div>';
                    echo '<div class="deletelink"><a class="deleteicon" onclick="return delete_fact(\'', WT_I18N::translate('Are you sure you want to delete this fact?'), '\', \'', $parent->getXref(), '\', \'', $fact->getFactId(), '\');" href="#" title="', WT_I18N::translate('Delete'), '"><span class="link_text">', WT_I18N::translate('Delete'), '</span></a></div>';
                    echo '</div>';
                } else {
                    echo WT_Gedcom_Tag::getLabel($factname, $parent);
                }
            }
            echo '</td>';
            echo '<td class="optionbox ', $styleadd, ' wrap">';
            if ($media) {
                echo '<span class="field">';
                echo $media->displayImage();
                if (empty($SEARCH_SPIDER)) {
                    echo '<a href="' . $media->getHtmlUrl() . '">';
                }
                echo '<em>';
                foreach ($media->getAllNames() as $name) {
                    if ($name['type'] != 'TITL') {
                        echo '<br>';
                    }
                    echo $name['full'];
                }
                echo '</em>';
                if (empty($SEARCH_SPIDER)) {
                    echo '</a>';
                }
                echo '</span>';
                echo WT_Gedcom_Tag::getLabelValue('FORM', $media->mimeType());
                $imgsize = $media->getImageAttributes('main');
                if (!empty($imgsize['WxH'])) {
                    echo WT_Gedcom_Tag::getLabelValue('__IMAGE_SIZE__', $imgsize['WxH']);
                }
                if ($media->getFilesizeraw() > 0) {
                    echo WT_Gedcom_Tag::getLabelValue('__FILE_SIZE__', $media->getFilesize());
                }
                $mediatype = $media->getMediaType();
                if ($mediatype) {
                    echo WT_Gedcom_Tag::getLabelValue('TYPE', WT_Gedcom_Tag::getFileFormTypeValue($mediatype));
                }
                switch ($media->isPrimary()) {
                    case 'Y':
                        echo WT_Gedcom_Tag::getLabelValue('_PRIM', WT_I18N::translate('yes'));
                        break;
                    case 'N':
                        echo WT_Gedcom_Tag::getLabelValue('_PRIM', WT_I18N::translate('no'));
                        break;
                }
                echo print_fact_notes($media->getGedcom(), 1);
                echo print_fact_sources($media->getGedcom(), 1);
            } else {
                echo $xref;
            }
            echo '</td></tr>';
        }
    }
}
コード例 #2
0
function format_fact_date(WT_Fact $event, WT_GedcomRecord $record, $anchor = false, $time = false)
{
    global $pid, $SEARCH_SPIDER, $SHOW_PARENTS_AGE;
    $factrec = $event->getGedcom();
    $html = '';
    // Recorded age
    if (preg_match('/\\n2 AGE (.+)/', $factrec, $match)) {
        $fact_age = $match[1];
    } else {
        $fact_age = '';
    }
    if (preg_match('/\\n2 HUSB\\n3 AGE (.+)/', $factrec, $match)) {
        $husb_age = $match[1];
    } else {
        $husb_age = '';
    }
    if (preg_match('/\\n2 WIFE\\n3 AGE (.+)/', $factrec, $match)) {
        $wife_age = $match[1];
    } else {
        $wife_age = '';
    }
    // Calculated age
    if (preg_match('/2 DATE (.+)/', $factrec, $match)) {
        $date = new WT_Date($match[1]);
        $html .= ' ' . $date->Display($anchor && !$SEARCH_SPIDER);
        // time
        if ($time) {
            $timerec = get_sub_record(2, '2 TIME', $factrec);
            if ($timerec == '') {
                $timerec = get_sub_record(2, '2 DATE', $factrec);
            }
            if (preg_match('/[2-3] TIME (.*)/', $timerec, $tmatch)) {
                $html .= '<span class="date"> - ' . $tmatch[1] . '</span>';
            }
        }
        $fact = $event->getTag();
        if ($record instanceof WT_Individual) {
            // age of parents at child birth
            if ($fact == 'BIRT' && $SHOW_PARENTS_AGE) {
                $html .= format_parents_age($record, $date);
            } else {
                if ($fact != 'CHAN' && $fact != '_TODO') {
                    $birth_date = $record->getBirthDate();
                    // Can't use getDeathDate(), as this also gives BURI/CREM events, which
                    // wouldn't give the correct "days after death" result for people with
                    // no DEAT.
                    $death_event = $record->getFirstFact('DEAT');
                    if ($death_event) {
                        $death_date = $death_event->getDate();
                    } else {
                        $death_date = new WT_Date('');
                    }
                    $ageText = '';
                    if (WT_Date::Compare($date, $death_date) <= 0 || !$record->isDead() || $fact == 'DEAT') {
                        // Before death, print age
                        $age = WT_Date::GetAgeGedcom($birth_date, $date);
                        // Only show calculated age if it differs from recorded age
                        if ($age != '') {
                            if ($fact_age != '' && $fact_age != $age || $fact_age == '' && $husb_age == '' && $wife_age == '' || $husb_age != '' && $record->getSex() == 'M' && $husb_age != $age || $wife_age != '' && $record->getSex() == 'F' && $wife_age != $age) {
                                if ($age != "0d") {
                                    $ageText = '(' . WT_I18N::translate('Age') . ' ' . get_age_at_event($age, false) . ')';
                                }
                            }
                        }
                    }
                    if ($fact != 'DEAT' && WT_Date::Compare($date, $death_date) >= 0) {
                        // After death, print time since death
                        $age = get_age_at_event(WT_Date::GetAgeGedcom($death_date, $date), true);
                        if ($age != '') {
                            if (WT_Date::GetAgeGedcom($death_date, $date) == "0d") {
                                $ageText = '(' . WT_I18N::translate('on the date of death') . ')';
                            } else {
                                $ageText = '(' . $age . ' ' . WT_I18N::translate('after death') . ')';
                                // Family events which occur after death are probably errors
                                if ($event->getParent() instanceof WT_Family) {
                                    $ageText .= '<i class="icon-warning"></i>';
                                }
                            }
                        }
                    }
                    if ($ageText) {
                        $html .= ' <span class="age">' . $ageText . '</span>';
                    }
                }
            }
        } elseif ($record instanceof WT_Family) {
            $indi = WT_Individual::getInstance($pid);
            if ($indi) {
                $birth_date = $indi->getBirthDate();
                $death_date = $indi->getDeathDate();
                $ageText = '';
                if (WT_Date::Compare($date, $death_date) <= 0) {
                    $age = WT_Date::GetAgeGedcom($birth_date, $date);
                    // Only show calculated age if it differs from recorded age
                    if ($age != '' && $age > 0) {
                        if ($fact_age != '' && $fact_age != $age || $fact_age == '' && $husb_age == '' && $wife_age == '' || $husb_age != '' && $indi->getSex() == 'M' && $husb_age != $age || $wife_age != '' && $indi->getSex() == 'F' && $wife_age != $age) {
                            $ageText = '(' . WT_I18N::translate('Age') . ' ' . get_age_at_event($age, false) . ')';
                        }
                    }
                }
                if ($ageText) {
                    $html .= ' <span class="age">' . $ageText . '</span>';
                }
            }
        }
    } else {
        // 1 DEAT Y with no DATE => print YES
        // 1 BIRT 2 SOUR @S1@ => print YES
        // 1 DEAT N is not allowed
        // It is not proper GEDCOM form to use a N(o) value with an event tag to infer that it did not happen.
        $factdetail = explode(' ', trim($factrec));
        if (isset($factdetail) && (count($factdetail) == 3 && strtoupper($factdetail[2]) == 'Y') || count($factdetail) == 4 && $factdetail[2] == 'SOUR') {
            $html .= WT_I18N::translate('yes');
        }
    }
    // print gedcom ages
    foreach (array(WT_Gedcom_Tag::getLabel('AGE') => $fact_age, WT_Gedcom_Tag::getLabel('HUSB') => $husb_age, WT_Gedcom_Tag::getLabel('WIFE') => $wife_age) as $label => $age) {
        if ($age != '') {
            $html .= ' <span class="label">' . $label . ':</span> <span class="age">' . get_age_at_event($age, false) . '</span>';
        }
    }
    return $html;
}
コード例 #3
0
ファイル: Timeline.php プロジェクト: sadr110/webtrees
 function print_time_fact(WT_Fact $event)
 {
     global $basexoffset, $baseyoffset, $factcount, $TEXT_DIRECTION, $WT_IMAGES, $placements;
     $desc = $event->getValue();
     // check if this is a family fact
     $gdate = $event->getDate();
     $date = $gdate->MinDate();
     $date = $date->convert_to_cal('gregorian');
     $year = $date->y;
     $month = max(1, $date->m);
     $day = max(1, $date->d);
     $xoffset = $basexoffset + 22;
     $yoffset = $baseyoffset + ($year - $this->baseyear) * $this->scale - $this->scale;
     $yoffset = $yoffset + $month / 12 * $this->scale;
     $yoffset = $yoffset + $day / 30 * ($this->scale / 12);
     $yoffset = (int) $yoffset;
     $place = (int) ($yoffset / $this->bheight);
     $i = 1;
     $j = 0;
     $tyoffset = 0;
     while (isset($placements[$place])) {
         if ($i == $j) {
             $tyoffset = $this->bheight * $i;
             $i++;
         } else {
             $tyoffset = -1 * $this->bheight * $j;
             $j++;
         }
         $place = (int) (($yoffset + $tyoffset) / $this->bheight);
     }
     $yoffset += $tyoffset;
     $xoffset += abs($tyoffset);
     $placements[$place] = $yoffset;
     echo "<div id=\"fact{$factcount}\" style=\"position:absolute; " . ($TEXT_DIRECTION == "ltr" ? "left: " . $xoffset : "right: " . $xoffset) . "px; top:" . $yoffset . "px; font-size: 8pt; height: " . $this->bheight . "px;\" onmousedown=\"factMouseDown(this, '" . $factcount . "', " . ($yoffset - $tyoffset) . ");\">";
     echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"cursor: hand;\"><tr><td>";
     echo "<img src=\"" . $WT_IMAGES["hline"] . "\" name=\"boxline{$factcount}\" id=\"boxline{$factcount}\" height=\"3\" align=\"left\" width=\"10\" alt=\"\" style=\"padding-";
     if ($TEXT_DIRECTION == "ltr") {
         echo "left";
     } else {
         echo "right";
     }
     echo ": 3px;\">";
     $col = $event->temp % 6;
     echo "</td><td valign=\"top\" class=\"person" . $col . "\">";
     if (count($this->pids) > 6) {
         echo $event->getParent()->getFullName() . ' — ';
     }
     $record = $event->getParent();
     echo $event->getLabel();
     echo ' — ';
     if ($record instanceof WT_Individual) {
         echo format_fact_date($event, $record, false, false);
     } elseif ($record instanceof WT_Family) {
         echo $gdate->Display(false);
         if ($record->getHusband() && $record->getHusband()->getBirthDate()->isOK()) {
             $ageh = get_age_at_event(WT_Date::GetAgeGedcom($record->getHusband()->getBirthDate(), $gdate), false);
         } else {
             $ageh = null;
         }
         if ($record->getWife() && $record->getWife()->getBirthDate()->isOK()) {
             $agew = get_age_at_event(WT_Date::GetAgeGedcom($record->getWife()->getBirthDate(), $gdate), false);
         } else {
             $agew = null;
         }
         if ($ageh && $agew) {
             echo '<span class="age"> ', WT_I18N::translate('Husband’s age'), ' ', $ageh, ' ', WT_I18N::translate('Wife’s age'), ' ', $agew, '</span>';
         } elseif ($ageh) {
             echo '<span class="age"> ', WT_I18N::translate('Age'), ' ', $ageh, '</span>';
         } elseif ($agew) {
             echo '<span class="age"> ', WT_I18N::translate('Age'), ' ', $ageh, '</span>';
         }
     }
     echo ' ' . WT_Filter::escapeHtml($desc);
     if (!$event->getPlace()->isEmpty()) {
         echo ' — ' . $event->getPlace()->getShortName();
     }
     // print spouse name for marriage events
     if (isset($event->spouse)) {
         $spouse = $event->spouse;
     } else {
         $spouse = null;
     }
     if ($spouse) {
         for ($p = 0; $p < count($this->pids); $p++) {
             if ($this->pids[$p] == $spouse->getXref()) {
                 break;
             }
         }
         if ($p == count($this->pids)) {
             $p = $event->temp;
         }
         if ($spouse->getXref() != $this->pids[$p]) {
             echo ' <a href="', $spouse->getHtmlUrl(), '">', $spouse->getFullName(), '</a>';
         } else {
             echo ' <a href="', $event->getParent()->getHtmlUrl(), '">', $event->getParent()->getFullName(), '</a>';
         }
     }
     echo "</td></tr></table>";
     echo "</div>";
     if ($TEXT_DIRECTION == 'ltr') {
         $img = "dline2";
         $ypos = "0%";
     } else {
         $img = "dline";
         $ypos = "100%";
     }
     $dyoffset = $yoffset - $tyoffset + $this->bheight / 3;
     if ($tyoffset < 0) {
         $dyoffset = $yoffset + $this->bheight / 3;
         if ($TEXT_DIRECTION == 'ltr') {
             $img = "dline";
             $ypos = "100%";
         } else {
             $img = "dline2";
             $ypos = "0%";
         }
     }
     // print the diagnal line
     echo "<div id=\"dbox{$factcount}\" style=\"position:absolute; " . ($TEXT_DIRECTION == "ltr" ? "left: " . ($basexoffset + 25) : "right: " . ($basexoffset + 25)) . "px; top:" . $dyoffset . "px; font-size: 8pt; height: " . abs($tyoffset) . "px; width: " . abs($tyoffset) . "px;";
     echo " background-image: url('" . $WT_IMAGES[$img] . "');";
     echo " background-position: 0% {$ypos};\">";
     echo "</div>";
 }
コード例 #4
0
ファイル: functions_edit.php プロジェクト: jacoline/webtrees
function create_edit_form(WT_GedcomRecord $record, WT_Fact $fact)
{
    global $ADVANCED_PLAC_FACTS, $date_and_time, $FULL_SOURCES, $tags;
    $pid = $record->getXref();
    $tags = array();
    $gedlines = explode("\n", $fact->getGedcom());
    $linenum = 0;
    $fields = explode(' ', $gedlines[$linenum]);
    $glevel = $fields[0];
    $level = $glevel;
    $type = $fact->getTag();
    $parent = $fact->getParent();
    $level0type = $parent::RECORD_TYPE;
    $level1type = $type;
    $i = $linenum;
    $inSource = false;
    $levelSource = 0;
    $add_date = true;
    // List of tags we would expect at the next level
    // NB add_missing_subtags() already takes care of the simple cases
    // where a level 1 tag is missing a level 2 tag.  Here we only need to
    // handle the more complicated cases.
    $expected_subtags = array('SOUR' => array('PAGE', 'DATA'), 'DATA' => array('TEXT'), 'PLAC' => array('MAP'), 'MAP' => array('LATI', 'LONG'));
    if ($FULL_SOURCES) {
        $expected_subtags['SOUR'][] = 'QUAY';
        $expected_subtags['DATA'][] = 'DATE';
    }
    if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $ADVANCED_PLAC_FACTS, $match)) {
        $expected_subtags['PLAC'] = array_merge($match[1], $expected_subtags['PLAC']);
    }
    $stack = array(0 => $level0type);
    // Loop on existing tags :
    while (true) {
        // Keep track of our hierarchy, e.g. 1=>BIRT, 2=>PLAC, 3=>FONE
        $stack[(int) $level] = $type;
        // Merge them together, e.g. BIRT:PLAC:FONE
        $label = implode(':', array_slice($stack, 1, $level));
        $text = '';
        for ($j = 2; $j < count($fields); $j++) {
            if ($j > 2) {
                $text .= ' ';
            }
            $text .= $fields[$j];
        }
        $text = rtrim($text);
        while ($i + 1 < count($gedlines) && preg_match("/" . ($level + 1) . " CONT ?(.*)/", $gedlines[$i + 1], $cmatch) > 0) {
            $text .= "\n" . $cmatch[1];
            $i++;
        }
        if ($type == "SOUR") {
            $inSource = true;
            $levelSource = $level;
        } elseif ($levelSource >= $level) {
            $inSource = false;
        }
        if ($type != "DATA" && $type != "CONT") {
            $tags[] = $type;
            $person = WT_Individual::getInstance($pid);
            $subrecord = $level . ' ' . $type . ' ' . $text;
            if ($inSource && $type == "DATE") {
                add_simple_tag($subrecord, '', WT_Gedcom_Tag::getLabel($label, $person));
            } elseif (!$inSource && $type == "DATE") {
                add_simple_tag($subrecord, $level1type, WT_Gedcom_Tag::getLabel($label, $person));
                $add_date = false;
            } elseif ($type == 'STAT') {
                add_simple_tag($subrecord, $level1type, WT_Gedcom_Tag::getLabel($label, $person));
            } elseif ($level0type == 'REPO') {
                $repo = WT_Repository::getInstance($pid);
                add_simple_tag($subrecord, $level0type, WT_Gedcom_Tag::getLabel($label, $repo));
            } else {
                add_simple_tag($subrecord, $level0type, WT_Gedcom_Tag::getLabel($label, $person));
            }
        }
        // Get a list of tags present at the next level
        $subtags = array();
        for ($ii = $i + 1; isset($gedlines[$ii]) && preg_match('/^\\s*(\\d+)\\s+(\\S+)/', $gedlines[$ii], $mm) && $mm[1] > $level; ++$ii) {
            if ($mm[1] == $level + 1) {
                $subtags[] = $mm[2];
            }
        }
        // Insert missing tags
        if (!empty($expected_subtags[$type])) {
            foreach ($expected_subtags[$type] as $subtag) {
                if (!in_array($subtag, $subtags)) {
                    if (!$inSource || $subtag != "DATA") {
                        add_simple_tag($level + 1 . ' ' . $subtag, '', WT_Gedcom_Tag::getLabel("{$label}:{$subtag}"));
                    }
                    if (!empty($expected_subtags[$subtag])) {
                        foreach ($expected_subtags[$subtag] as $subsubtag) {
                            add_simple_tag($level + 2 . ' ' . $subsubtag, '', WT_Gedcom_Tag::getLabel("{$label}:{$subtag}:{$subsubtag}"));
                        }
                    }
                }
            }
        }
        // Awkward special cases
        if ($level == 2 && $type == 'DATE' && in_array($level1type, $date_and_time) && !in_array('TIME', $subtags)) {
            add_simple_tag("3 TIME");
            // TIME is NOT a valid 5.5.1 tag
        }
        if ($level == 2 && $type == 'STAT' && WT_Gedcom_Code_Temp::isTagLDS($level1type) && !in_array('DATE', $subtags)) {
            add_simple_tag("3 DATE", '', WT_Gedcom_Tag::getLabel('STAT:DATE'));
        }
        $i++;
        if (isset($gedlines[$i])) {
            $fields = explode(' ', $gedlines[$i]);
            $level = $fields[0];
            if (isset($fields[1])) {
                $type = trim($fields[1]);
            } else {
                $level = 0;
            }
        } else {
            $level = 0;
        }
        if ($level <= $glevel) {
            break;
        }
    }
    if ($level1type != '_PRIM') {
        insert_missing_subtags($level1type, $add_date);
    }
    return $level1type;
}