| Conditions | 118 |
| Paths | > 20000 |
| Total Lines | 433 |
| Code Lines | 302 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 57 | public static function printFact(Fact $fact, GedcomRecord $record) |
||
| 58 | { |
||
| 59 | static $n_chil = 0, $n_gchi = 0; |
||
| 60 | |||
| 61 | $parent = $fact->getParent(); |
||
| 62 | |||
| 63 | // Some facts don't get printed here ... |
||
| 64 | switch ($fact->getTag()) { |
||
| 65 | case 'NOTE': |
||
| 66 | self::printMainNotes($fact, 1); |
||
| 67 | |||
| 68 | return; |
||
| 69 | case 'SOUR': |
||
| 70 | self::printMainSources($fact, 1); |
||
| 71 | |||
| 72 | return; |
||
| 73 | case 'OBJE': |
||
| 74 | self::printMainMedia($fact, 1); |
||
| 75 | |||
| 76 | return; |
||
| 77 | case 'FAMC': |
||
| 78 | case 'FAMS': |
||
| 79 | case 'CHIL': |
||
| 80 | case 'HUSB': |
||
| 81 | case 'WIFE': |
||
| 82 | // These are internal links, not facts |
||
| 83 | return; |
||
| 84 | case '_WT_OBJE_SORT': |
||
| 85 | // These links are used internally to record the sort order. |
||
| 86 | return; |
||
| 87 | default: |
||
| 88 | // Hide unrecognized/custom tags? |
||
| 89 | if ($fact->getParent()->getTree()->getPreference('HIDE_GEDCOM_ERRORS') === '0' && !GedcomTag::isTag($fact->getTag())) { |
||
| 90 | return; |
||
| 91 | } |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | |||
| 95 | // Who is this fact about? Need it to translate fact label correctly |
||
| 96 | if ($parent instanceof Family && $record instanceof Individual) { |
||
| 97 | // Family event |
||
| 98 | $label_person = $fact->getParent()->getSpouse($record); |
||
|
|
|||
| 99 | } else { |
||
| 100 | // Individual event |
||
| 101 | $label_person = $parent; |
||
| 102 | } |
||
| 103 | |||
| 104 | // New or deleted facts need different styling |
||
| 105 | $styleadd = ''; |
||
| 106 | if ($fact->isPendingAddition()) { |
||
| 107 | $styleadd = 'new'; |
||
| 108 | } |
||
| 109 | if ($fact->isPendingDeletion()) { |
||
| 110 | $styleadd = 'old'; |
||
| 111 | } |
||
| 112 | |||
| 113 | // Event of close relative |
||
| 114 | if (preg_match('/^_[A-Z_]{3,5}_[A-Z0-9]{4}$/', $fact->getTag())) { |
||
| 115 | $styleadd = trim($styleadd . ' rela'); |
||
| 116 | } |
||
| 117 | |||
| 118 | // Event of close associates |
||
| 119 | if ($fact->getFactId() == 'asso') { |
||
| 120 | $styleadd = trim($styleadd . ' rela'); |
||
| 121 | } |
||
| 122 | |||
| 123 | // historical facts |
||
| 124 | if ($fact->getFactId() == 'histo') { |
||
| 125 | $styleadd = trim($styleadd . ' histo'); |
||
| 126 | } |
||
| 127 | |||
| 128 | // Does this fact have a type? |
||
| 129 | if (preg_match('/\n2 TYPE (.+)/', $fact->getGedcom(), $match)) { |
||
| 130 | $type = $match[1]; |
||
| 131 | } else { |
||
| 132 | $type = ''; |
||
| 133 | } |
||
| 134 | |||
| 135 | switch ($fact->getTag()) { |
||
| 136 | case 'EVEN': |
||
| 137 | case 'FACT': |
||
| 138 | if (GedcomTag::isTag($type)) { |
||
| 139 | // Some users (just Meliza?) use "1 EVEN/2 TYPE BIRT". Translate the TYPE. |
||
| 140 | $label = GedcomTag::getLabel($type, $label_person); |
||
| 141 | $type = ''; // Do not print this again |
||
| 142 | } elseif ($type) { |
||
| 143 | // We don't have a translation for $type - but a custom translation might exist. |
||
| 144 | $label = I18N::translate(Filter::escapeHtml($type)); |
||
| 145 | $type = ''; // Do not print this again |
||
| 146 | } else { |
||
| 147 | // An unspecified fact/event |
||
| 148 | $label = $fact->getLabel(); |
||
| 149 | } |
||
| 150 | break; |
||
| 151 | case 'MARR': |
||
| 152 | // This is a hack for a proprietory extension. Is it still used/needed? |
||
| 153 | $utype = strtoupper($type); |
||
| 154 | if ($utype == 'CIVIL' || $utype == 'PARTNERS' || $utype == 'RELIGIOUS') { |
||
| 155 | $label = GedcomTag::getLabel('MARR_' . $utype, $label_person); |
||
| 156 | $type = ''; // Do not print this again |
||
| 157 | } else { |
||
| 158 | $label = $fact->getLabel(); |
||
| 159 | } |
||
| 160 | break; |
||
| 161 | default: |
||
| 162 | // Normal fact/event |
||
| 163 | $label = $fact->getLabel(); |
||
| 164 | break; |
||
| 165 | } |
||
| 166 | |||
| 167 | echo '<tr class="', $styleadd, '">'; |
||
| 168 | echo '<td class="descriptionbox width20">'; |
||
| 169 | |||
| 170 | if ($fact->getParent()->getTree()->getPreference('SHOW_FACT_ICONS')) { |
||
| 171 | echo Theme::theme()->icon($fact), ' '; |
||
| 172 | } |
||
| 173 | |||
| 174 | if ($fact->getFactId() != 'histo' && $fact->canEdit()) { |
||
| 175 | ?> |
||
| 176 | <a |
||
| 177 | href="#" |
||
| 178 | title="<?php echo I18N::translate('Edit'); ?>" |
||
| 179 | onclick="return edit_record('<?php echo $parent->getXref(); ?>', '<?php echo $fact->getFactId(); ?>');" |
||
| 180 | ><?php echo $label; ?></a> |
||
| 181 | <div class="editfacts"> |
||
| 182 | <div class="editlink"> |
||
| 183 | <a |
||
| 184 | href="#" |
||
| 185 | title="<?php echo I18N::translate('Edit'); ?>" |
||
| 186 | class="editicon" |
||
| 187 | onclick="return edit_record('<?php echo $parent->getXref(); ?>', '<?php echo $fact->getFactId(); ?>');" |
||
| 188 | ><span class="link_text"><?php echo I18N::translate('Edit'); ?></span></a> |
||
| 189 | </div> |
||
| 190 | <div class="copylink"> |
||
| 191 | <a |
||
| 192 | href="#" |
||
| 193 | title="<?php echo I18N::translate('Copy'); ?>" |
||
| 194 | class="copyicon" |
||
| 195 | onclick="return copy_fact('<?php echo $parent->getXref(); ?>', '<?php echo $fact->getFactId(); ?>');" |
||
| 196 | ><span class="link_text"><?php echo I18N::translate('Copy'); ?></span></a> |
||
| 197 | </div> |
||
| 198 | <div class="deletelink"> |
||
| 199 | <a |
||
| 200 | href="#" |
||
| 201 | title="<?php echo I18N::translate('Delete'); ?>" |
||
| 202 | class="deleteicon" |
||
| 203 | onclick="return delete_fact('<?php echo I18N::translate('Are you sure you want to delete this fact?'); ?>', '<?php echo $parent->getXref(); ?>', '<?php echo $fact->getFactId(); ?>');" |
||
| 204 | ><span class="link_text"><?php echo I18N::translate('Delete'); ?></span></a> |
||
| 205 | </div> |
||
| 206 | </div> |
||
| 207 | <?php |
||
| 208 | } else { |
||
| 209 | echo $label; |
||
| 210 | } |
||
| 211 | |||
| 212 | switch ($fact->getTag()) { |
||
| 213 | case '_BIRT_CHIL': |
||
| 214 | echo '<br>', /* I18N: Abbreviation for "number %s" */ |
||
| 215 | I18N::translate('#%s', ++$n_chil); |
||
| 216 | break; |
||
| 217 | case '_BIRT_GCHI': |
||
| 218 | case '_BIRT_GCH1': |
||
| 219 | case '_BIRT_GCH2': |
||
| 220 | echo '<br>', I18N::translate('#%s', ++$n_gchi); |
||
| 221 | break; |
||
| 222 | } |
||
| 223 | |||
| 224 | echo '</td><td class="optionbox ', $styleadd, ' wrap">'; |
||
| 225 | |||
| 226 | // Event from another record? |
||
| 227 | if ($parent !== $record) { |
||
| 228 | if ($parent instanceof Family) { |
||
| 229 | foreach ($parent->getSpouses() as $spouse) { |
||
| 230 | if ($record !== $spouse) { |
||
| 231 | echo '<a href="', $spouse->getHtmlUrl(), '">', $spouse->getFullName(), '</a> — '; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | echo '<a href="', $parent->getHtmlUrl(), '">', I18N::translate('View this family'), '</a><br>'; |
||
| 235 | } elseif ($parent instanceof Individual) { |
||
| 236 | echo '<a href="', $parent->getHtmlUrl(), '">', $parent->getFullName(), '</a><br>'; |
||
| 237 | } |
||
| 238 | } |
||
| 239 | |||
| 240 | // Print the value of this fact/event |
||
| 241 | switch ($fact->getTag()) { |
||
| 242 | case 'ADDR': |
||
| 243 | echo Filter::escapeUrl($fact->getValue()); |
||
| 244 | break; |
||
| 245 | case 'AFN': |
||
| 246 | echo '<div class="field"><a href="https://familysearch.org/search/tree/results#count=20&query=afn:', Filter::escapeUrl($fact->getValue()), '">', Filter::escapeHtml($fact->getValue()), '</a></div>'; |
||
| 247 | break; |
||
| 248 | case 'ASSO': |
||
| 249 | // we handle this later, in format_asso_rela_record() |
||
| 250 | break; |
||
| 251 | case 'EMAIL': |
||
| 252 | case 'EMAI': |
||
| 253 | case '_EMAIL': |
||
| 254 | echo '<div class="field"><a href="mailto:', Filter::escapeHtml($fact->getValue()), '">', Filter::escapeHtml($fact->getValue()), '</a></div>'; |
||
| 255 | break; |
||
| 256 | case 'FILE': |
||
| 257 | if (Auth::isEditor($fact->getParent()->getTree())) { |
||
| 258 | echo '<div class="field">', Filter::escapeHtml($fact->getValue()), '</div>'; |
||
| 259 | } |
||
| 260 | break; |
||
| 261 | case 'RESN': |
||
| 262 | echo '<div class="field">'; |
||
| 263 | switch ($fact->getValue()) { |
||
| 264 | case 'none': |
||
| 265 | // Note: "1 RESN none" is not valid gedcom. |
||
| 266 | // However, webtrees privacy rules will interpret it as "show an otherwise private record to public". |
||
| 267 | echo '<i class="icon-resn-none"></i> ', I18N::translate('Show to visitors'); |
||
| 268 | break; |
||
| 269 | case 'privacy': |
||
| 270 | echo '<i class="icon-class-none"></i> ', I18N::translate('Show to members'); |
||
| 271 | break; |
||
| 272 | case 'confidential': |
||
| 273 | echo '<i class="icon-confidential-none"></i> ', I18N::translate('Show to managers'); |
||
| 274 | break; |
||
| 275 | case 'locked': |
||
| 276 | echo '<i class="icon-locked-none"></i> ', I18N::translate('Only managers can edit'); |
||
| 277 | break; |
||
| 278 | default: |
||
| 279 | echo Filter::escapeHtml($fact->getValue()); |
||
| 280 | break; |
||
| 281 | } |
||
| 282 | echo '</div>'; |
||
| 283 | break; |
||
| 284 | case 'PUBL': // Publication details might contain URLs. |
||
| 285 | echo '<div class="field">', Filter::expandUrls($fact->getValue()), '</div>'; |
||
| 286 | break; |
||
| 287 | case 'REPO': |
||
| 288 | if (preg_match('/^@(' . WT_REGEX_XREF . ')@$/', $fact->getValue(), $match)) { |
||
| 289 | self::printRepositoryRecord($match[1]); |
||
| 290 | } else { |
||
| 291 | echo '<div class="error">', Filter::escapeHtml($fact->getValue()), '</div>'; |
||
| 292 | } |
||
| 293 | break; |
||
| 294 | case 'URL': |
||
| 295 | case '_URL': |
||
| 296 | case 'WWW': |
||
| 297 | echo '<div class="field"><a href="', Filter::escapeHtml($fact->getValue()), '">', Filter::escapeHtml($fact->getValue()), '</a></div>'; |
||
| 298 | break; |
||
| 299 | case 'TEXT': // 0 SOUR / 1 TEXT |
||
| 300 | echo '<div class="field">', nl2br(Filter::escapeHtml($fact->getValue()), false), '</div>'; |
||
| 301 | break; |
||
| 302 | default: |
||
| 303 | // Display the value for all other facts/events |
||
| 304 | switch ($fact->getValue()) { |
||
| 305 | case '': |
||
| 306 | // Nothing to display |
||
| 307 | break; |
||
| 308 | case 'N': |
||
| 309 | // Not valid GEDCOM |
||
| 310 | echo '<div class="field">', I18N::translate('No'), '</div>'; |
||
| 311 | break; |
||
| 312 | case 'Y': |
||
| 313 | // Do not display "Yes". |
||
| 314 | break; |
||
| 315 | default: |
||
| 316 | if (preg_match('/^@(' . WT_REGEX_XREF . ')@$/', $fact->getValue(), $match)) { |
||
| 317 | $target = GedcomRecord::getInstance($match[1], $fact->getParent()->getTree()); |
||
| 318 | if ($target) { |
||
| 319 | echo '<div><a href="', $target->getHtmlUrl(), '">', $target->getFullName(), '</a></div>'; |
||
| 320 | } else { |
||
| 321 | echo '<div class="error">', Filter::escapeHtml($fact->getValue()), '</div>'; |
||
| 322 | } |
||
| 323 | } else { |
||
| 324 | echo '<div class="field"><span dir="auto">', Filter::escapeHtml($fact->getValue()), '</span></div>'; |
||
| 325 | } |
||
| 326 | break; |
||
| 327 | } |
||
| 328 | break; |
||
| 329 | } |
||
| 330 | |||
| 331 | // Print the type of this fact/event |
||
| 332 | if ($type) { |
||
| 333 | $utype = strtoupper($type); |
||
| 334 | // Events of close relatives, e.g. _MARR_CHIL |
||
| 335 | if (substr($fact->getTag(), 0, 6) == '_MARR_' && ($utype == 'CIVIL' || $utype == 'PARTNERS' || $utype == 'RELIGIOUS')) { |
||
| 336 | // Translate MARR/TYPE using the code that supports MARR_CIVIL, etc. tags |
||
| 337 | $type = GedcomTag::getLabel('MARR_' . $utype); |
||
| 338 | } else { |
||
| 339 | // Allow (custom) translations for other types |
||
| 340 | $type = I18N::translate($type); |
||
| 341 | } |
||
| 342 | echo GedcomTag::getLabelValue('TYPE', Filter::escapeHtml($type)); |
||
| 343 | } |
||
| 344 | |||
| 345 | // Print the date of this fact/event |
||
| 346 | echo FunctionsPrint::formatFactDate($fact, $record, true, true); |
||
| 347 | |||
| 348 | // Print the place of this fact/event |
||
| 349 | echo '<div class="place">', FunctionsPrint::formatFactPlace($fact, true, true, true), '</div>'; |
||
| 350 | // A blank line between the primary attributes (value, date, place) and the secondary ones |
||
| 351 | echo '<br>'; |
||
| 352 | |||
| 353 | $addr = $fact->getAttribute('ADDR'); |
||
| 354 | if ($addr) { |
||
| 355 | echo GedcomTag::getLabelValue('ADDR', $addr); |
||
| 356 | } |
||
| 357 | |||
| 358 | // Print the associates of this fact/event |
||
| 359 | if ($fact->getFactId() !== 'asso') { |
||
| 360 | echo self::formatAssociateRelationship($fact); |
||
| 361 | } |
||
| 362 | |||
| 363 | // Print any other "2 XXXX" attributes, in the order in which they appear. |
||
| 364 | preg_match_all('/\n2 (' . WT_REGEX_TAG . ') (.+)/', $fact->getGedcom(), $matches, PREG_SET_ORDER); |
||
| 365 | foreach ($matches as $match) { |
||
| 366 | switch ($match[1]) { |
||
| 367 | case 'DATE': |
||
| 368 | case 'TIME': |
||
| 369 | case 'AGE': |
||
| 370 | case 'PLAC': |
||
| 371 | case 'ADDR': |
||
| 372 | case 'ALIA': |
||
| 373 | case 'ASSO': |
||
| 374 | case '_ASSO': |
||
| 375 | case 'DESC': |
||
| 376 | case 'RELA': |
||
| 377 | case 'STAT': |
||
| 378 | case 'TEMP': |
||
| 379 | case 'TYPE': |
||
| 380 | case 'FAMS': |
||
| 381 | case 'CONT': |
||
| 382 | // These were already shown at the beginning |
||
| 383 | break; |
||
| 384 | case 'NOTE': |
||
| 385 | case 'OBJE': |
||
| 386 | case 'SOUR': |
||
| 387 | // These will be shown at the end |
||
| 388 | break; |
||
| 389 | case '_UID': |
||
| 390 | case 'RIN': |
||
| 391 | // These don't belong at level 2, so do not display them. |
||
| 392 | // They are only shown when editing. |
||
| 393 | break; |
||
| 394 | case 'EVEN': // 0 SOUR / 1 DATA / 2 EVEN / 3 DATE / 3 PLAC |
||
| 395 | $events = array(); |
||
| 396 | foreach (preg_split('/ *, */', $match[2]) as $event) { |
||
| 397 | $events[] = GedcomTag::getLabel($event); |
||
| 398 | } |
||
| 399 | if (count($events) == 1) { |
||
| 400 | echo GedcomTag::getLabelValue('EVEN', $event); |
||
| 401 | } else { |
||
| 402 | echo GedcomTag::getLabelValue('EVEN', implode(I18N::$list_separator, $events)); |
||
| 403 | } |
||
| 404 | if (preg_match('/\n3 DATE (.+)/', $fact->getGedcom(), $date_match)) { |
||
| 405 | $date = new Date($date_match[1]); |
||
| 406 | echo GedcomTag::getLabelValue('DATE', $date->display()); |
||
| 407 | } |
||
| 408 | if (preg_match('/\n3 PLAC (.+)/', $fact->getGedcom(), $plac_match)) { |
||
| 409 | echo GedcomTag::getLabelValue('PLAC', $plac_match[1]); |
||
| 410 | } |
||
| 411 | break; |
||
| 412 | case 'FAMC': // 0 INDI / 1 ADOP / 2 FAMC / 3 ADOP |
||
| 413 | $family = Family::getInstance(str_replace('@', '', $match[2]), $fact->getParent()->getTree()); |
||
| 414 | if ($family) { |
||
| 415 | echo GedcomTag::getLabelValue('FAM', '<a href="' . $family->getHtmlUrl() . '">' . $family->getFullName() . '</a>'); |
||
| 416 | if (preg_match('/\n3 ADOP (HUSB|WIFE|BOTH)/', $fact->getGedcom(), $match)) { |
||
| 417 | echo GedcomTag::getLabelValue('ADOP', GedcomCodeAdop::getValue($match[1], $label_person)); |
||
| 418 | } |
||
| 419 | } else { |
||
| 420 | echo GedcomTag::getLabelValue('FAM', '<span class="error">' . $match[2] . '</span>'); |
||
| 421 | } |
||
| 422 | break; |
||
| 423 | case '_WT_USER': |
||
| 424 | $user = User::findByIdentifier($match[2]); // may not exist |
||
| 425 | if ($user) { |
||
| 426 | echo GedcomTag::getLabelValue('_WT_USER', $user->getRealNameHtml()); |
||
| 427 | } else { |
||
| 428 | echo GedcomTag::getLabelValue('_WT_USER', Filter::escapeHtml($match[2])); |
||
| 429 | } |
||
| 430 | break; |
||
| 431 | case 'RESN': |
||
| 432 | switch ($match[2]) { |
||
| 433 | case 'none': |
||
| 434 | // Note: "2 RESN none" is not valid gedcom. |
||
| 435 | // However, webtrees privacy rules will interpret it as "show an otherwise private fact to public". |
||
| 436 | echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-none"></i> ' . I18N::translate('Show to visitors')); |
||
| 437 | break; |
||
| 438 | case 'privacy': |
||
| 439 | echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-privacy"></i> ' . I18N::translate('Show to members')); |
||
| 440 | break; |
||
| 441 | case 'confidential': |
||
| 442 | echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-confidential"></i> ' . I18N::translate('Show to managers')); |
||
| 443 | break; |
||
| 444 | case 'locked': |
||
| 445 | echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-locked"></i> ' . I18N::translate('Only managers can edit')); |
||
| 446 | break; |
||
| 447 | default: |
||
| 448 | echo GedcomTag::getLabelValue('RESN', Filter::escapeHtml($match[2])); |
||
| 449 | break; |
||
| 450 | } |
||
| 451 | break; |
||
| 452 | case 'CALN': |
||
| 453 | echo GedcomTag::getLabelValue('CALN', Filter::expandUrls($match[2])); |
||
| 454 | break; |
||
| 455 | case 'FORM': // 0 OBJE / 1 FILE / 2 FORM / 3 TYPE |
||
| 456 | echo GedcomTag::getLabelValue('FORM', $match[2]); |
||
| 457 | if (preg_match('/\n3 TYPE (.+)/', $fact->getGedcom(), $type_match)) { |
||
| 458 | echo GedcomTag::getLabelValue('TYPE', GedcomTag::getFileFormTypeValue($type_match[1])); |
||
| 459 | } |
||
| 460 | break; |
||
| 461 | case 'URL': |
||
| 462 | case '_URL': |
||
| 463 | case 'WWW': |
||
| 464 | $link = '<a href="' . Filter::escapeHtml($match[2]) . '">' . Filter::escapeHtml($match[2]) . '</a>'; |
||
| 465 | echo GedcomTag::getLabelValue($fact->getTag() . ':' . $match[1], $link); |
||
| 466 | break; |
||
| 467 | default: |
||
| 468 | if ($fact->getParent()->getTree()->getPreference('HIDE_GEDCOM_ERRORS') === '1' || GedcomTag::isTag($match[1])) { |
||
| 469 | if (preg_match('/^@(' . WT_REGEX_XREF . ')@$/', $match[2], $xmatch)) { |
||
| 470 | // Links |
||
| 471 | $linked_record = GedcomRecord::getInstance($xmatch[1], $fact->getParent()->getTree()); |
||
| 472 | if ($linked_record) { |
||
| 473 | $link = '<a href="' . $linked_record->getHtmlUrl() . '">' . $linked_record->getFullName() . '</a>'; |
||
| 474 | echo GedcomTag::getLabelValue($fact->getTag() . ':' . $match[1], $link); |
||
| 475 | } else { |
||
| 476 | echo GedcomTag::getLabelValue($fact->getTag() . ':' . $match[1], Filter::escapeHtml($match[2])); |
||
| 477 | } |
||
| 478 | } else { |
||
| 479 | // Non links |
||
| 480 | echo GedcomTag::getLabelValue($fact->getTag() . ':' . $match[1], Filter::escapeHtml($match[2])); |
||
| 481 | } |
||
| 482 | } |
||
| 483 | break; |
||
| 484 | } |
||
| 485 | } |
||
| 486 | echo self::printFactSources($fact->getGedcom(), 2); |
||
| 487 | echo FunctionsPrint::printFactNotes($fact->getGedcom(), 2); |
||
| 488 | self::printMediaLinks($fact->getGedcom(), 2); |
||
| 489 | echo '</td></tr>'; |
||
| 490 | } |
||
| 1238 |