Exemplo n.º 1
0
 public static function updatePersonLink($tag, $oldTitle, $newTitle, &$pd, $familyTag, &$text, &$textChanged)
 {
     if ($newTitle) {
         $new = Person::getPropagatedElement($tag, $newTitle, $pd, $familyTag);
     } else {
         $new = '';
     }
     $old = "<{$tag}[^>]*? title=\"" . StructuredData::protectRegexSearch(StructuredData::escapeXml($oldTitle)) . "\".*?/>\n";
     $found = false;
     if (preg_match('$' . $old . '$', $text)) {
         $found = true;
     } else {
         if ($tag == 'husband' || $tag == 'wife') {
             // check the other tag just in case
             $old = '<' . ($tag == 'husband' ? 'wife' : 'husband') . '[^>]*? title="' . StructuredData::protectRegexSearch(StructuredData::escapeXml($oldTitle)) . "\".*?/>\n";
             if (preg_match('$' . $old . '$', $text)) {
                 $found = true;
             }
         }
     }
     if (!$found) {
         $old = ESINHandler::findRelationshipInsertionPointTag($tag, $text);
         $new .= $old;
     }
     // limit to 1 replacement, sine there could be multiple <child tags and we don't want to insert the new child more than once
     $result = preg_replace('$' . $old . '$', StructuredData::protectRegexReplace($new), $text, 1);
     // keep children sorted
     if ($tag == 'child') {
         $childBegin = mb_strpos($result, '<child ');
         if ($childBegin !== false) {
             $childEnd = $childBegin;
             while (mb_substr($result, $childEnd, strlen('<child ')) == '<child ') {
                 $childEnd = mb_strpos($result, "/>\n", $childEnd) + strlen("/>\n");
             }
             $children = mb_substr($result, $childBegin, $childEnd - $childBegin);
             ESINHandler::sortChildren($children);
             $result = mb_substr($result, 0, $childBegin) . $children . mb_substr($result, $childEnd);
         }
     }
     if ($result != $text) {
         $text = $result;
         $textChanged = true;
     }
 }
Exemplo n.º 2
0
 public static function updateFamilyLink($tag, $oldTitle, $newTitle, &$text, &$textChanged)
 {
     if ($newTitle) {
         $new = Family::getPropagatedElement($tag, $newTitle, $pd);
     } else {
         $new = '';
     }
     $old = "<{$tag} title=\"" . StructuredData::protectRegexSearch(StructuredData::escapeXml($oldTitle)) . "\"/>\n";
     if (!preg_match('$' . $old . '$', $text)) {
         $old = ESINHandler::findRelationshipInsertionPointTag($tag, $text);
         $new .= $old;
     }
     $result = preg_replace('$' . $old . '$', StructuredData::protectRegexReplace($new), $text, 1);
     if ($result != $text) {
         $text = $result;
         $textChanged = true;
     }
 }