示例#1
0
 private function correctPlaceTitle($place)
 {
     if ($place && mb_strpos($place, '|') === false) {
         $titles = array();
         $titles[] = $place;
         $correctedPlaces = PlaceSearcher::correctPlaceTitles($titles);
         $correctedPlace = @$correctedPlaces[$place];
         if ($correctedPlace) {
             $place = strcasecmp($place, $correctedPlace) == 0 ? $correctedPlace : $correctedPlace . '|' . $place;
         }
     }
     return $place;
 }
示例#2
0
 private static function correctPlaceTitles($request, $stdEventFacts)
 {
     $titles = array();
     for ($i = 0; $i < count($stdEventFacts) || $request->getVal("event_fact{$i}"); $i++) {
         $place = $request->getVal("place{$i}");
         if ($place && mb_strpos($place, '|') === false) {
             $titles[] = $place;
         }
     }
     return PlaceSearcher::correctPlaceTitles($titles);
 }
示例#3
0
 public static function getPageText($marriagedate, $marriageplace, $titleString, $pageids = NULL, $husbandTitle = '', $wifeTitle = '', $childTitle = '')
 {
     // standardize marriage place
     $placeTitles = array();
     if ($marriageplace && mb_strpos($marriageplace, '|') === false) {
         $placeTitles[] = $marriageplace;
     }
     if ($placeTitles) {
         $correctedTitles = PlaceSearcher::correctPlaceTitles($placeTitles);
         $correctedPlace = @$correctedTitles[$marriageplace];
         if ($correctedPlace) {
             $marriageplace = strcasecmp($marriageplace, $correctedPlace) == 0 ? $correctedPlace : $correctedPlace . '|' . $marriageplace;
         }
     }
     $result = "<family>\n";
     $db =& wfGetDB(DB_MASTER);
     // get latest version
     $imageId = 0;
     $husbands = '';
     $wives = '';
     $children = '';
     $images = '';
     if ($pageids) {
         foreach ($pageids as $pageid) {
             $revision = Revision::loadFromPageId($db, $pageid);
             if ($revision) {
                 if ($revision->getTitle()->getNamespace() == NS_PERSON) {
                     $text = $revision->getText();
                     $xml = StructuredData::getXml('person', $text);
                     if (isset($xml)) {
                         $personTitle = StructuredData::escapeXml($revision->getTitle()->getText());
                         $spouseTag = Person::getSpouseTagFromGender((string) $xml->gender);
                         foreach ($xml->spouse_of_family as $family) {
                             if ((string) $family['title'] == $titleString) {
                                 if ($spouseTag == 'husband') {
                                     $husbands .= "<husband title=\"" . $personTitle . "\"/>\n";
                                 } else {
                                     $wives .= "<wife title=\"" . $personTitle . "\"/>\n";
                                 }
                             }
                         }
                         foreach ($xml->child_of_family as $family) {
                             if ((string) $family['title'] == $titleString) {
                                 $children .= '<child title="' . $personTitle . "\"/>\n";
                             }
                         }
                     }
                 } else {
                     if ($revision->getTitle()->getNamespace() == NS_IMAGE) {
                         $text = $revision->getText();
                         $xml = StructuredData::getXml('image_data', $text);
                         if (isset($xml)) {
                             $imageTitle = StructuredData::escapeXml($revision->getTitle()->getText());
                             foreach ($xml->family as $family) {
                                 if ((string) $family['title'] == $titleString) {
                                     $imageId++;
                                     $images .= '<image id="I' . $imageId . '" filename="' . $imageTitle . "\"/>\n";
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($husbandTitle) {
         $husbands .= "<husband title=\"" . StructuredData::escapeXml($husbandTitle) . "\"/>\n";
     }
     if ($wifeTitle) {
         $wives .= "<husband title=\"" . StructuredData::escapeXml($wifeTitle) . "\"/>\n";
     }
     if ($childTitle) {
         $children .= "<husband title=\"" . StructuredData::escapeXml($childTitle) . "\"/>\n";
     }
     $result .= $husbands;
     $result .= $wives;
     $result .= $children;
     if ($marriagedate || $marriageplace) {
         $result .= '<event_fact type="Marriage" date="' . StructuredData::escapeXml($marriagedate) . '" place="' . StructuredData::escapeXml($marriageplace) . "\"/>\n";
     }
     $result .= $images;
     $result .= "</family>\n";
     return $result;
 }
示例#4
0
 private static function cleanSourcePlace($place)
 {
     $title = array();
     $title[] = $place;
     $stdTitle = PlaceSearcher::correctPlaceTitles($title);
     if (@$stdTitle[$place]) {
         $place = $stdTitle[$place];
     }
     return rtrim($place, ' .');
 }
示例#5
0
 public static function getPageText($givenname, $surname, $gender, $birthdate, $birthplace, $deathdate, $deathplace, $titleString, $pageids = NULL, $parentFamily = '', $spouseFamily = '', $chrdate = '', $chrplace = '', $burdate = '', $burplace = '')
 {
     // standardize places
     $placeTitles = array();
     if ($birthplace && mb_strpos($birthplace, '|') === false) {
         $placeTitles[] = $birthplace;
     }
     if ($deathplace && mb_strpos($deathplace, '|') === false) {
         $placeTitles[] = $deathplace;
     }
     if ($placeTitles) {
         $correctedTitles = PlaceSearcher::correctPlaceTitles($placeTitles);
         $correctedPlace = @$correctedTitles[$birthplace];
         if ($correctedPlace) {
             $birthplace = strcasecmp($birthplace, $correctedPlace) == 0 ? $correctedPlace : $correctedPlace . '|' . $birthplace;
         }
         $correctedPlace = @$correctedTitles[$deathplace];
         if ($correctedPlace) {
             $deathplace = strcasecmp($deathplace, $correctedPlace) == 0 ? $correctedPlace : $correctedPlace . '|' . $deathplace;
         }
     }
     $result = "<person>\n";
     if ($givenname || $surname) {
         $result .= '<name given="' . StructuredData::escapeXml(trim($givenname)) . '" surname="' . StructuredData::escapeXml(trim($surname)) . "\"/>\n";
     }
     $db =& wfGetDB(DB_MASTER);
     // make sure we get the most current version
     $spouseFamilies = '';
     $parentFamilies = '';
     $images = '';
     $imageId = 0;
     if ($pageids) {
         foreach ($pageids as $pageid) {
             $revision = Revision::loadFromPageId($db, $pageid);
             if ($revision) {
                 if ($revision->getTitle()->getNamespace() == NS_FAMILY) {
                     $text = $revision->getText();
                     $xml = StructuredData::getXml('family', $text);
                     if (isset($xml)) {
                         $familyTitle = StructuredData::escapeXml($revision->getTitle()->getText());
                         foreach ($xml->husband as $member) {
                             if ((string) $member['title'] == $titleString) {
                                 $spouseFamilies .= '<spouse_of_family title="' . $familyTitle . "\"/>\n";
                                 if (!$gender) {
                                     $gender = 'M';
                                 }
                             }
                         }
                         foreach ($xml->wife as $member) {
                             if ((string) $member['title'] == $titleString) {
                                 $spouseFamilies .= '<spouse_of_family title="' . $familyTitle . "\"/>\n";
                                 if (!$gender) {
                                     $gender = 'F';
                                 }
                             }
                         }
                         foreach ($xml->child as $member) {
                             if ((string) $member['title'] == $titleString) {
                                 $parentFamilies .= '<child_of_family title="' . $familyTitle . "\"/>\n";
                             }
                         }
                     }
                 } else {
                     if ($revision->getTitle()->getNamespace() == NS_IMAGE) {
                         $text = $revision->getText();
                         $xml = StructuredData::getXml('image_data', $text);
                         if (isset($xml)) {
                             $imageTitle = StructuredData::escapeXml($revision->getTitle()->getText());
                             foreach ($xml->person as $person) {
                                 if ((string) $person['title'] == $titleString) {
                                     $imageId++;
                                     $images .= '<image id="I' . $imageId . '" filename="' . $imageTitle . "\"/>\n";
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($parentFamily) {
         $parentFamilies .= '<child_of_family title="' . StructuredData::escapeXml($parentFamily) . "\"/>\n";
     }
     if ($spouseFamily) {
         $spouseFamilies .= '<spouse_of_family title="' . StructuredData::escapeXml($spouseFamily) . "\"/>\n";
     }
     if ($gender) {
         $result .= '<gender>' . StructuredData::escapeXml($gender) . "</gender>\n";
     }
     $result .= $parentFamilies;
     $result .= $spouseFamilies;
     if ($birthdate || $birthplace) {
         $result .= '<event_fact type="Birth" date="' . StructuredData::escapeXml($birthdate) . '" place="' . StructuredData::escapeXml($birthplace) . "\"/>\n";
     }
     if ($deathdate || $deathplace) {
         $result .= '<event_fact type="Death" date="' . StructuredData::escapeXml($deathdate) . '" place="' . StructuredData::escapeXml($deathplace) . "\"/>\n";
     }
     if ($chrdate || $chrplace) {
         $result .= '<event_fact type="Christening" date="' . StructuredData::escapeXml($chrdate) . '" place="' . StructuredData::escapeXml($chrplace) . "\"/>\n";
     }
     if ($burdate || $burplace) {
         $result .= '<event_fact type="Burial" date="' . StructuredData::escapeXml($burdate) . '" place="' . StructuredData::escapeXml($burplace) . "\"/>\n";
     }
     $result .= $images;
     $result .= "</person>\n";
     return $result;
 }
示例#6
0
 public static function correctPlaceTitlesMultiLine($text)
 {
     $text = trim(preg_replace('/ *\\r?\\n */', "\n", $text));
     $titles = preg_split('/[\\n]+/', $text, -1, PREG_SPLIT_NO_EMPTY);
     $lookupTitles = array();
     foreach ($titles as $title) {
         if (mb_strpos($title, '|') === false && !in_array($title, $lookupTitles)) {
             $lookupTitles[] = $title;
         }
     }
     return PlaceSearcher::correctPlaceTitles($lookupTitles);
 }
示例#7
0
 /**
  * Return xml elements from data in request
  * @param unknown $request
  */
 protected function fromEditFields($request)
 {
     $this->correctedPlaceTitles = PlaceSearcher::correctPlaceTitlesMultiLine($request->getVal('places', ''));
     $result = '';
     if ($this->isSubpage) {
         $result .= $this->addMultiLineFieldToXml($request->getVal('surnames', ''), 'formatSurname');
         $result .= $this->addMultiLineFieldToXml($request->getVal('places', ''), 'formatPlace');
         $result .= $this->addSingleLineFieldToXml($request->getVal('fromYear', ''), 'from_year');
         $result .= $this->addSingleLineFieldToXml($request->getVal('toYear', ''), 'to_year');
     } else {
         $placesToCorrect = array();
         for ($i = 0; $request->getVal("researching_id{$i}"); $i++) {
             $place = trim($request->getVal("researching_place{$i}"));
             if ($place && mb_strpos($place, '|') === false) {
                 $placesToCorrect[] = $place;
             }
         }
         $correctedPlaceTitles = PlaceSearcher::correctPlaceTitles($placesToCorrect);
         for ($i = 0; $request->getVal("researching_id{$i}"); $i++) {
             $surname = StructuredData::standardizeNameCase(trim($request->getVal("researching_surname{$i}")), false);
             $place = trim($request->getVal("researching_place{$i}"));
             if ($surname || $place) {
                 // if you change this, you must also change FamilyTreeAjaxFunctions
                 if ($place) {
                     $correctedPlace = @$correctedPlaceTitles[$place];
                     if ($correctedPlace) {
                         $place = $correctedPlace;
                     }
                 }
                 $result .= $this->addMultiAttrFieldToXml(array('surname' => $surname, 'place' => $place), 'researching');
             }
         }
     }
     return $result;
 }