private function getSortKey($eventFact, &$prevKey) { $date = (string) $eventFact['date']; $type = (string) $eventFact['type']; $key = ''; if (!$date) { if ($type == 'Death') { $key = 29999998; } else { if ($type == 'Burial') { $key = 29999999; } } } else { $k = StructuredData::getDateKey($date, true); if ($k) { $key = $k; $prevKey = $key; } } if (!$key) { $key = $prevKey; } // if no date, assume same as previous return $key; }
public static function standardizeValues($label, $values) { $stdValues = array(); if (is_array(@$values)) { foreach ($values as $value) { $stdValue = ''; if (strpos($label, 'Surname') !== false || strpos($label, 'Given') !== false) { $pieces = explode(' ', $value); $sdxValue = ''; foreach ($pieces as $piece) { $lowerPiece = mb_strtolower($piece); if ($piece && $lowerPiece != 'unknown' && $lowerPiece != '?' && $lowerPiece != 'fnu' && $lowerPiece != 'lnu' && $lowerPiece != 'nn' && $lowerPiece != 'n.n.') { if ($stdValue) { $stdValue .= ' '; $sdxValue .= ' '; } $stdValue .= $lowerPiece; $sdxValue .= soundex($piece); } } $stdValue .= '|' . $sdxValue; } else { if (strpos($label, 'date') !== false) { $stdValue = StructuredData::getDateKey($value); } else { if (strpos($label, 'place') !== false) { $stdValue = StructuredData::getPlaceKey($value); $pos = mb_strpos($stdValue, ', united states'); if ($pos !== false) { $stdValue = mb_substr($stdValue, 0, $pos); // remove united states for ,-check in scoreMatch below } } else { if (strpos($label, 'ParentFamilyTitle') !== false || strpos($label, 'SpouseFamilyTitle') !== false) { $pos = mb_strpos($value, '('); if ($pos !== false) { $stdValue = mb_substr($value, 0, $pos); } else { $stdValue = $value; } $stdValue = trim(mb_convert_case($stdValue, MB_CASE_LOWER)); } else { $stdValue = $value; } } } } if ($stdValue) { $stdValues[] = $stdValue; } } } else { if ($label == 'childGedcomMatchTitle' && @$values) { // keep this for matching $stdValues[] = $values; } } return $stdValues; }
private function cleanDate($str) { return StructuredData::getDateKey($str); // if($str == 'UNKNOWN') // return ''; // $str = preg_replace('/abt\.?\s*/i', '', $str); // $date = date_create($str); // function new in PHP 5.2 // return @date_format($date, DATE_ISO8601); // $matches = array(); // $pattern = '/abt\.?\s+([0-9]{4})'; // preg_match($pattern, $str, $matches); // if(isset($matches[1])) // return $matches[1]; // $pattern = '([0-9]{1,2}\s+(\w+)\s+' }
private function getMapData($n, &$result) { $family = @$this->families[$n]; // calculate color index numbers list($familyNumber, $husbandNumber, $wifeNumber, $selfNumber, $spouseNumber) = ShowPedigree::getColorIndexes($n); if (@$family['exists']) { $endpoints = array(); // get marriage $this->addEvent($family, 'marriage', $husbandNumber, $result); $this->addEndpoint($family, 'marriage', $endpoints); // get childbirths if (isset($family['children'])) { foreach ($family['children'] as $child) { // get birth for children $this->addEvent($child, 'birth', $familyNumber, $result); $this->addEndpoint($child, 'birth', $endpoints); } } // calculate which spouse dies first $husbandDeath = StructuredData::getDateKey(@$family['husband']['deathdate']); $wifeDeath = StructuredData::getDateKey(@$family['wife']['deathdate']); if ($husbandDeath && $wifeDeath) { if ($husbandDeath < $wifeDeath) { $firstDeathTag = 'husband'; $secondDeathTag = 'wife'; $secondDeathNumber = $wifeNumber; } else { $firstDeathTag = 'wife'; $secondDeathTag = 'husband'; $secondDeathNumber = $husbandNumber; } } else { if ($n >= ShowPedigree::SPOUSE_FAMILY_BASE && $n < ShowPedigree::SPOUSE_FAMILY_BASE + $this->numSpouseFamilies - 1) { $firstDeathTag = $this->spouseTag; $secondDeathTag = $this->selfTag; $secondDeathNumber = $selfNumber; } else { $firstDeathTag = 'husband'; $secondDeathTag = 'wife'; $secondDeathNumber = $wifeNumber; } } // include endpoint of first spouse to die in family endpoints $this->addEndpoint(@$family[$firstDeathTag], 'death', $endpoints); // generate edges from endpoints sort($endpoints, SORT_STRING); $firstFamilyEndpoint = count($endpoints) > 0 ? $endpoints[0] : null; $lastFamilyEndpoint = count($endpoints) > 0 ? $endpoints[count($endpoints) - 1] : null; $result .= $this->generateEdges($endpoints, $husbandNumber, $wifeNumber); // get death edge for last spouse to die (self's death on last spouse-family only) if ($lastFamilyEndpoint && ($secondDeathTag != $this->selfTag || $n <= ShowPedigree::MAX_FAMILIES || $n == ShowPedigree::SPOUSE_FAMILY_BASE + $this->numSpouseFamilies - 1)) { $endpoints = array($lastFamilyEndpoint); $this->addEndpoint(@$family[$secondDeathTag], 'death', $endpoints); $result .= $this->generateEdges($endpoints, $secondDeathNumber); } // get death info (self's death on last spouse-family only) if ($n >= ShowPedigree::SPOUSE_FAMILY_BASE) { $this->addEvent(@$family[$this->spouseTag], 'death', $spouseNumber, $result); if ($n == ShowPedigree::SPOUSE_FAMILY_BASE + $this->numSpouseFamilies - 1) { // last spouse family $this->addEvent(@$family[$this->selfTag], 'death', $selfNumber, $result); } } else { $this->addEvent(@$family['husband'], 'death', $husbandNumber, $result); $this->addEvent(@$family['wife'], 'death', $wifeNumber, $result); } // get birth for self-spouses and anyone who doesn't appear in a parent-family if ($n >= ShowPedigree::SPOUSE_FAMILY_BASE) { $this->addEvent(@$family[$this->spouseTag], 'birth', $spouseNumber, $result); if ($n == ShowPedigree::SPOUSE_FAMILY_BASE && @(!$this->families[1]['exists'])) { // first family, and parent family doesn't exist $this->addEvent(@$family[$this->selfTag], 'birth', $selfNumber, $result); } // add edges from spouse and self to first family event (but don't do this for self for 2nd and later families) if ($firstFamilyEndpoint) { $endpoints = array($firstFamilyEndpoint); $this->addEndpoint(@$family[$this->spouseTag], 'birth', $endpoints); $result .= $this->generateEdges($endpoints, $spouseNumber); if ($n == ShowPedigree::SPOUSE_FAMILY_BASE) { // first family for self $endpoints = array($firstFamilyEndpoint); $this->addEndpoint(@$family[$this->selfTag], 'birth', $endpoints); $result .= $this->generateEdges($endpoints, $selfNumber); } else { if ($this->prevLastFamilyEndpoint) { // second or later family for self $endpoints = array($this->prevLastFamilyEndpoint, $firstFamilyEndpoint); $result .= $this->generateEdges($endpoints, $selfNumber); } } } } else { if (@(!$this->families[$n * 2]['exists'])) { $this->addEvent(@$family['husband'], 'birth', $husbandNumber, $result); } if (@(!$this->families[$n * 2 + 1]['exists'])) { $this->addEvent(@$family['wife'], 'birth', $wifeNumber, $result); } if ($firstFamilyEndpoint) { $endpoints = array($firstFamilyEndpoint); $this->addEndpoint(@$family['husband'], 'birth', $endpoints); $result .= $this->generateEdges($endpoints, $husbandNumber); $endpoints = array($firstFamilyEndpoint); $this->addEndpoint(@$family['wife'], 'birth', $endpoints); $result .= $this->generateEdges($endpoints, $wifeNumber); } } $this->prevLastFamilyEndpoint = $lastFamilyEndpoint; } // just in case there are no spouse-families and we're not doing a pedigree for a family, we still need to get info on self if ($this->numSpouseFamilies == 0 && $n == 1 && $this->selfTag) { $endpoints = array(); if (@(!$this->families[1]['exists'])) { $this->addEvent(@$this->families[ShowPedigree::SPOUSE_FAMILY_BASE][$this->selfTag], 'birth', $selfNumber, $result); } $this->addEndpoint(@$this->families[ShowPedigree::SPOUSE_FAMILY_BASE][$this->selfTag], 'birth', $endpoints); $this->addEvent(@$this->families[ShowPedigree::SPOUSE_FAMILY_BASE][$this->selfTag], 'death', $selfNumber, $result); $this->addEndpoint(@$this->families[ShowPedigree::SPOUSE_FAMILY_BASE][$this->selfTag], 'death', $endpoints); $result .= $this->generateEdges($endpoints, $selfNumber); } }
private function getEventData($xml, $eventTypes) { $eventTypeIndex = 0; foreach ($eventTypes as $type) { foreach ($xml->event_fact as $event_fact) { if ((string) $event_fact['type'] == $type) { $eventDate = (string) $event_fact['date']; $eventYear = substr(StructuredData::getDateKey($eventDate), 0, 4); $eventPlace = ''; // $eventPlaceUrl = ''; $place = (string) $event_fact['place']; if ($place) { $pos = mb_strpos($place, '|'); if ($pos !== false) { $eventPlace = mb_substr($place, $pos + 1); // $placeTitle = mb_substr($place, 0, $pos); } else { $eventPlace = $place; // $placeTitle = $place; } // $t = Title::newFromText($placeTitle, NS_PLACE); // if ($t) { // $eventPlaceUrl = $t->getFullURL(); // } } return array($eventYear, $eventDate, $eventPlace, $eventTypeIndex); } } $eventTypeIndex++; } return array('', '', '', -1); }
private static function readEvents($xml) { $events = array(); foreach ($xml->event_fact as $o) { $type = (string) $o['type']; $stdType = MergeForm::getStdType($type); $date = (string) $o['date']; $stdDate = (string) StructuredData::getDateKey($date); $place = (string) $o['place']; $stdPlace = StructuredData::getPlaceKey($place); $desc = (string) $o['desc']; // sometimes people put the references in the wrong fields, so gather them all together list($sources, $images, $notes) = MergeForm::readSourcesImagesNotes((string) $o['sources'], (string) $o['images'], (string) $o['notes']); $key = 'EVENT|' . $type . '|' . $date . '|' . $place . '|' . $desc . '|' . $sources . '|' . $notes . '|' . $images; $events[] = array('type' => $type, 'stdtype' => $stdType, 'date' => $date, 'stddate' => $stdDate, 'place' => $place, 'stdplace' => $stdPlace, 'description' => $desc, 'sources' => $sources, 'notes' => $notes, 'images' => $images, 'key' => $key); } return $events; }
private function getRange($date, $range) { if ($range) { $year = substr(StructuredData::getDateKey($date), 0, 4); if ($year && $range <= 5) { return '[' . ($year - $range) . ' TO ' . ($year + $range) . ']'; } } return $this->addQuotes($date); }
protected function getFamilyBadge($family, $isParentsSiblings, $gender, $parentFamilies, &$marriageEvents) { global $wrHostName; $marriageKey = 0; $title = (string) $family['title']; $warning = ''; $subtitle = ''; if ($isParentsSiblings) { $label = "Parents and Siblings"; $husbandLabel = 'F'; $wifeLabel = 'M'; $childLabel = 'S'; $class = "wr-infobox-parentssiblings"; if (count($parentFamilies) > 1) { $pfs = array(); foreach ($parentFamilies as $pf) { $t = Title::newFromText($pf, NS_FAMILY); $pfs[] = wfUrlencode($t->getDBkey()); } $warning = "Duplicate parents - <span class=\"plainlinks\">[http://{$wrHostName}/wiki/Special:Compare?ns=Family&compare=" . join('|', $pfs) . " compare]</span>"; } } else { $label = "Spouse and Children"; $husbandLabel = 'H'; $wifeLabel = 'W'; $childLabel = 'C'; $class = "wr-infobox-spousechildren"; } $spouses = ''; $marriage = ''; $children = ''; $spouseLinks = array(); if ($this->isGedcomPage) { if (mb_strpos($title, ' - Excluded (') > 0) { $label .= ' - Excluded'; } $spouses = "<li>[[Family:{$title}|View family members]]<br><span style=\"font-size:75%\">family members not shown in gedcom review</span></li>"; } else { $familyObject = new Family($title); $familyXml = $familyObject->getPageXml(true); if (isset($familyXml)) { if (isset($familyXml->husband)) { foreach ($familyXml->husband as $spouse) { $spouses .= $this->getFamilyMember($spouse, $husbandLabel, !$isParentsSiblings && $gender == 'F', $spouseLinks); } } else { list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($title); if ($hg || $hs) { $spouses .= $this->getFamilyMember(null, $husbandLabel, !$isParentsSiblings && $gender == 'F', $spouseLinks, "{$hg} {$hs}", 'M', $title); } } if (isset($familyXml->wife)) { foreach ($familyXml->wife as $spouse) { $spouses .= $this->getFamilyMember($spouse, $wifeLabel, !$isParentsSiblings && $gender == 'M', $spouseLinks); } } else { list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($title); if ($wg || $ws) { $spouses .= $this->getFamilyMember(null, $wifeLabel, !$isParentsSiblings && $gender == 'M', $spouseLinks, "{$wg} {$ws}", 'F', $title); } } if (isset($familyXml->event_fact)) { foreach ($familyXml->event_fact as $eventFact) { if ((string) $eventFact['type'] == 'Marriage') { $marriageDate = (string) $eventFact['date']; $marriageKey = StructuredData::getDateKey($marriageDate, true); $marriage = "<div class=\"wr-infobox-event\">m. <span class=\"wr-infobox-date\">{$marriageDate}</span></div>"; } if (!$isParentsSiblings) { $marriageDesc = (string) $eventFact['desc']; if ($marriageDesc) { $marriageDesc .= '<br/>'; } // sometimes event type is "Reference Number" -- I don't know why $conjunction = @Family::$EVENT_CONJUNCTIONS[(string) $eventFact['type']]; $marriageDesc .= $conjunction . ' ' . join(' or ', $spouseLinks); $marriageEvents[] = array('type' => (string) $eventFact['type'], 'date' => (string) $eventFact['date'], 'place' => (string) $eventFact['place'], 'desc' => $marriageDesc, 'srcs' => (string) $eventFact['sources'], 'no_citation_needed' => true); } } } foreach ($familyXml->child as $child) { $children .= $this->getFamilyMember($child, $childLabel, false, $spouseLinks); } if ($children) { $children = "<ol>{$children}</ol>"; } } else { list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($title); if ($hg || $hs) { $spouses .= $this->getFamilyMember(null, $husbandLabel, false, $spouseLinks, "{$hg} {$hs}", 'M', $title); } if ($wg || $ws) { $spouses .= $this->getFamilyMember(null, $wifeLabel, false, $spouseLinks, "{$wg} {$ws}", 'F', $title); } } $t = Title::makeTitleSafe(NS_FAMILY, $title); $subtitle = "<div class=\"wr-infobox-editlink\"><span class=\"plainlinks\">([" . $t->getFullURL('action=edit') . " edit])</span></div>"; } if ($warning) { $subtitle = "<div class=\"wr-infobox-warning\">{$warning}</div>"; } $result = <<<END <div class="wr-infobox wr-infobox-familybadge {$class}"> <div class="wr-infobox-heading">[[Family:{$title}|{$label}]]</div>{$subtitle}<ul>{$spouses}</ul>{$marriage}{$children} </div> END; return array($marriageKey, $result); }
private function getAllEventPlaces($xml) { $events = array(); foreach ($xml->event_fact as $event_fact) { list($eventPlace, $eventPlaceText) = $this->getEventPlace($event_fact); $eventDate = (string) StructuredData::getDateKey((string) $event_fact['date'], true); if ($eventPlace) { $events[] = $eventDate . '|' . $eventPlace; } } foreach ($xml->spouse_of_family as $spouseFamily) { $titleText = (string) $spouseFamily['title']; $family = @$this->families[$titleText]; if ($family && $family['xml']) { foreach ($family['xml']->event_fact as $event_fact) { list($eventPlace, $eventPlaceText) = $this->getEventPlace($event_fact); $eventDate = (string) StructuredData::getDateKey((string) $event_fact['date'], true); if ($eventPlace) { $events[] = $eventDate . '|' . $eventPlace; } } } } // sort events by date sort($events); $result = array(); foreach ($events as $event) { $pos = mb_strpos($event, '|'); $place = mb_substr($event, $pos + 1); if (!in_array($place, $result)) { $result[] = $place; } } return $result; }