/** * get edit menu */ public function getEditMenu() { if (!$this->record || $this->record->isPendingDeletion()) { return null; } // edit menu $menu = new Menu(I18N::translate('Edit'), '#', 'menu-record'); // edit raw if (Auth::isAdmin() || Auth::isEditor($this->record->getTree()) && $this->record->getTree()->getPreference('SHOW_GEDCOM_RECORD')) { $menu->addSubmenu(new Menu(I18N::translate('Edit raw GEDCOM'), '#', 'menu-record-editraw', array('onclick' => 'return edit_raw("' . $this->record->getXref() . '");'))); } // delete if (Auth::isEditor($this->record->getTree())) { $menu->addSubmenu(new Menu(I18N::translate('Delete'), '#', 'menu-record-del', array('onclick' => 'return delete_record("' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs(Filter::unescapeHtml($this->record->getFullName()))) . '", "' . $this->record->getXref() . '");'))); } // add to favorites if (Module::getModuleByName('user_favorites')) { $menu->addSubmenu(new Menu(I18N::translate('Add to favorites'), '#', 'menu-record-addfav', array('onclick' => 'jQuery.post("module.php?mod=user_favorites&mod_action=menu-add-favorite" ,{xref:"' . $this->record->getXref() . '"},function(){location.reload();})'))); } // Get the link for the first submenu and set it as the link for the main menu if ($menu->getSubmenus()) { $submenus = $menu->getSubmenus(); $menu->setLink($submenus[0]->getLink()); $menu->setAttrs($submenus[0]->getAttrs()); } return $menu; }
/** * Startup activity */ public function __construct() { // Automatically fix broken links if ($this->record && $this->record->canEdit()) { $broken_links = 0; foreach ($this->record->getFacts('HUSB|WIFE|CHIL|FAMS|FAMC|REPO') as $fact) { if (!$fact->isPendingDeletion() && $fact->getTarget() === null) { $this->record->deleteFact($fact->getFactId(), false); FlashMessages::addMessage(I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $this->record->getFullName(), $fact->getValue())); $broken_links = true; } } foreach ($this->record->getFacts('NOTE|SOUR|OBJE') as $fact) { // These can be links or inline. Only delete links. if (!$fact->isPendingDeletion() && $fact->getTarget() === null && preg_match('/^@.*@$/', $fact->getValue())) { $this->record->deleteFact($fact->getFactId(), false); FlashMessages::addMessage(I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $this->record->getFullName(), $fact->getValue())); $broken_links = true; } } if ($broken_links) { // Reload the updated family $this->record = GedcomRecord::getInstance($this->record->getXref(), $this->record->getTree()); } } parent::__construct(); // We want robots to index this page $this->setMetaRobots('index,follow'); // Set a page title if ($this->record) { if ($this->record->canShowName()) { // e.g. "John Doe" or "1881 Census of Wales" $this->setPageTitle($this->record->getFullName()); } else { // e.g. "Individual" or "Source" $record = $this->record; $this->setPageTitle(GedcomTag::getLabel($record::RECORD_TYPE)); } } else { // No such record $this->setPageTitle(I18N::translate('Private')); } }
/** * get edit menu */ public function getEditMenu() { if (!$this->record || $this->record->isPendingDeletion()) { return null; } // edit menu $menu = new Menu(I18N::translate('Edit'), '#', 'menu-record'); // edit raw if (Auth::isAdmin() || Auth::isEditor($this->record->getTree()) && $this->record->getTree()->getPreference('SHOW_GEDCOM_RECORD')) { $menu->addSubmenu(new Menu(I18N::translate('Edit the raw GEDCOM'), '#', 'menu-record-editraw', array('onclick' => 'return edit_raw("' . $this->record->getXref() . '");'))); } // delete if (Auth::isEditor($this->record->getTree())) { $menu->addSubmenu(new Menu(I18N::translate('Delete'), '#', 'menu-record-del', array('onclick' => 'return delete_record("' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs(Filter::unescapeHtml($this->record->getFullName()))) . '", "' . $this->record->getXref() . '");'))); } return $menu; }
/** * Convert custom markup into HTML * * @param Note $note * * @return string */ public static function formatCensusNote(Note $note) { global $WT_TREE; if (preg_match('/(.*)((?:\\n.*)*)\\n\\.start_formatted_area\\.\\n(.+)\\n(.+(?:\\n.+)*)\\n.end_formatted_area\\.((?:\\n.*)*)/', $note->getNote(), $match)) { // This looks like a census-assistant shared note $title = Filter::escapeHtml($match[1]); $preamble = Filter::escapeHtml($match[2]); $header = Filter::escapeHtml($match[3]); $data = Filter::escapeHtml($match[4]); $postamble = Filter::escapeHtml($match[5]); // Get the column headers for the census to which this note refers // requires the fact place & date to match the specific census // censusPlace() (Soundex match) and censusDate() functions $fmt_headers = array(); $linkedRecords = array_merge($note->linkedIndividuals('NOTE'), $note->linkedFamilies('NOTE')); $firstRecord = array_shift($linkedRecords); if ($firstRecord) { $countryCode = ''; $date = ''; foreach ($firstRecord->getFacts('CENS') as $fact) { if (trim($fact->getAttribute('NOTE'), '@') === $note->getXref()) { $date = $fact->getAttribute('DATE'); $place = explode(',', strip_tags($fact->getPlace()->getFullName())); $countryCode = Soundex::daitchMokotoff(array_pop($place)); break; } } foreach (Census::allCensusPlaces() as $censusPlace) { if (Soundex::compare($countryCode, Soundex::daitchMokotoff($censusPlace->censusPlace()))) { foreach ($censusPlace->allCensusDates() as $census) { if ($census->censusDate() == $date) { foreach ($census->columns() as $column) { $abbrev = $column->abbreviation(); if ($abbrev) { $description = $column->title() ? $column->title() : I18N::translate('Description unavailable'); $fmt_headers[$abbrev] = '<span title="' . $description . '">' . $abbrev . '</span>'; } } break 2; } } } } } // Substitute header labels and format as HTML $thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>'; $thead = str_replace('.b.', '', $thead); // Format data as HTML $tbody = ''; foreach (explode("\n", $data) as $row) { $tbody .= '<tr>'; foreach (explode('|', $row) as $column) { $tbody .= '<td>' . $column . '</td>'; } $tbody .= '</tr>'; } return $title . "\n" . '<div class="markdown">' . '<p>' . $preamble . '</p>' . '<table>' . '<thead>' . $thead . '</thead>' . '<tbody>' . $tbody . '</tbody>' . '</table>' . '<p>' . $postamble . '</p>' . '</div>'; } else { // Not a census-assistant shared note - apply default formatting return Filter::formatText($note->getNote(), $WT_TREE); } }