Example #1
0
function get_repo_list($ged_id)
{
    $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom FROM `##other` WHERE o_type='REPO' AND o_file=?")->execute(array($ged_id))->fetchAll();
    $list = array();
    foreach ($rows as $row) {
        $list[] = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
    }
    usort($list, array('WT_GedcomRecord', 'compare'));
    return $list;
}
Example #2
0
 protected function _canShowByType($access_level)
 {
     // Hide sources if they are attached to private repositories ...
     preg_match_all('/\\n1 REPO @(.+)@/', $this->gedcom, $matches);
     foreach ($matches[1] as $match) {
         $repo = WT_Repository::getInstance($match);
         if ($repo && !$repo->canShow($access_level)) {
             return false;
         }
     }
     // ... otherwise apply default behaviour
     return parent::_canShowByType($access_level);
 }
Example #3
0
 public function __construct()
 {
     $xref = WT_Filter::get('rid', WT_REGEX_XREF);
     $this->record = WT_Repository::getInstance($xref);
     parent::__construct();
 }
/**
 * print a repository record
 *
 * find and print repository information attached to a source
 *
 * @param $xref the Gedcom Xref ID of the repository to print
 */
function print_repository_record($xref)
{
    $repository = WT_Repository::getInstance($xref);
    if ($repository && $repository->canShow()) {
        echo '<a class="field" href="', $repository->getHtmlUrl(), '">', $repository->getFullName(), '</a><br>';
        echo '<br>';
        echo print_fact_notes($repository->getGedcom(), 1);
    }
}
Example #5
0
function create_edit_form(WT_GedcomRecord $record, WT_Fact $fact)
{
    global $ADVANCED_PLAC_FACTS, $date_and_time, $FULL_SOURCES, $tags;
    $pid = $record->getXref();
    $tags = array();
    $gedlines = explode("\n", $fact->getGedcom());
    $linenum = 0;
    $fields = explode(' ', $gedlines[$linenum]);
    $glevel = $fields[0];
    $level = $glevel;
    $type = $fact->getTag();
    $parent = $fact->getParent();
    $level0type = $parent::RECORD_TYPE;
    $level1type = $type;
    $i = $linenum;
    $inSource = false;
    $levelSource = 0;
    $add_date = true;
    // List of tags we would expect at the next level
    // NB add_missing_subtags() already takes care of the simple cases
    // where a level 1 tag is missing a level 2 tag.  Here we only need to
    // handle the more complicated cases.
    $expected_subtags = array('SOUR' => array('PAGE', 'DATA'), 'DATA' => array('TEXT'), 'PLAC' => array('MAP'), 'MAP' => array('LATI', 'LONG'));
    if ($FULL_SOURCES) {
        $expected_subtags['SOUR'][] = 'QUAY';
        $expected_subtags['DATA'][] = 'DATE';
    }
    if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $ADVANCED_PLAC_FACTS, $match)) {
        $expected_subtags['PLAC'] = array_merge($match[1], $expected_subtags['PLAC']);
    }
    $stack = array(0 => $level0type);
    // Loop on existing tags :
    while (true) {
        // Keep track of our hierarchy, e.g. 1=>BIRT, 2=>PLAC, 3=>FONE
        $stack[(int) $level] = $type;
        // Merge them together, e.g. BIRT:PLAC:FONE
        $label = implode(':', array_slice($stack, 1, $level));
        $text = '';
        for ($j = 2; $j < count($fields); $j++) {
            if ($j > 2) {
                $text .= ' ';
            }
            $text .= $fields[$j];
        }
        $text = rtrim($text);
        while ($i + 1 < count($gedlines) && preg_match("/" . ($level + 1) . " CONT ?(.*)/", $gedlines[$i + 1], $cmatch) > 0) {
            $text .= "\n" . $cmatch[1];
            $i++;
        }
        if ($type == "SOUR") {
            $inSource = true;
            $levelSource = $level;
        } elseif ($levelSource >= $level) {
            $inSource = false;
        }
        if ($type != "DATA" && $type != "CONT") {
            $tags[] = $type;
            $person = WT_Individual::getInstance($pid);
            $subrecord = $level . ' ' . $type . ' ' . $text;
            if ($inSource && $type == "DATE") {
                add_simple_tag($subrecord, '', WT_Gedcom_Tag::getLabel($label, $person));
            } elseif (!$inSource && $type == "DATE") {
                add_simple_tag($subrecord, $level1type, WT_Gedcom_Tag::getLabel($label, $person));
                $add_date = false;
            } elseif ($type == 'STAT') {
                add_simple_tag($subrecord, $level1type, WT_Gedcom_Tag::getLabel($label, $person));
            } elseif ($level0type == 'REPO') {
                $repo = WT_Repository::getInstance($pid);
                add_simple_tag($subrecord, $level0type, WT_Gedcom_Tag::getLabel($label, $repo));
            } else {
                add_simple_tag($subrecord, $level0type, WT_Gedcom_Tag::getLabel($label, $person));
            }
        }
        // Get a list of tags present at the next level
        $subtags = array();
        for ($ii = $i + 1; isset($gedlines[$ii]) && preg_match('/^\\s*(\\d+)\\s+(\\S+)/', $gedlines[$ii], $mm) && $mm[1] > $level; ++$ii) {
            if ($mm[1] == $level + 1) {
                $subtags[] = $mm[2];
            }
        }
        // Insert missing tags
        if (!empty($expected_subtags[$type])) {
            foreach ($expected_subtags[$type] as $subtag) {
                if (!in_array($subtag, $subtags)) {
                    if (!$inSource || $subtag != "DATA") {
                        add_simple_tag($level + 1 . ' ' . $subtag, '', WT_Gedcom_Tag::getLabel("{$label}:{$subtag}"));
                    }
                    if (!empty($expected_subtags[$subtag])) {
                        foreach ($expected_subtags[$subtag] as $subsubtag) {
                            add_simple_tag($level + 2 . ' ' . $subsubtag, '', WT_Gedcom_Tag::getLabel("{$label}:{$subtag}:{$subsubtag}"));
                        }
                    }
                }
            }
        }
        // Awkward special cases
        if ($level == 2 && $type == 'DATE' && in_array($level1type, $date_and_time) && !in_array('TIME', $subtags)) {
            add_simple_tag("3 TIME");
            // TIME is NOT a valid 5.5.1 tag
        }
        if ($level == 2 && $type == 'STAT' && WT_Gedcom_Code_Temp::isTagLDS($level1type) && !in_array('DATE', $subtags)) {
            add_simple_tag("3 DATE", '', WT_Gedcom_Tag::getLabel('STAT:DATE'));
        }
        $i++;
        if (isset($gedlines[$i])) {
            $fields = explode(' ', $gedlines[$i]);
            $level = $fields[0];
            if (isset($fields[1])) {
                $type = trim($fields[1]);
            } else {
                $level = 0;
            }
        } else {
            $level = 0;
        }
        if ($level <= $glevel) {
            break;
        }
    }
    if ($level1type != '_PRIM') {
        insert_missing_subtags($level1type, $add_date);
    }
    return $level1type;
}
Example #6
0
 public function getTarget()
 {
     $xref = trim($this->getValue(), '@');
     switch ($this->tag) {
         case 'FAMC':
         case 'FAMS':
             return WT_Family::getInstance($xref, $this->getParent()->getGedcomId());
         case 'HUSB':
         case 'WIFE':
         case 'CHIL':
             return WT_Individual::getInstance($xref, $this->getParent()->getGedcomId());
         case 'SOUR':
             return WT_Source::getInstance($xref, $this->getParent()->getGedcomId());
         case 'OBJE':
             return WT_Media::getInstance($xref, $this->getParent()->getGedcomId());
         case 'REPO':
             return WT_Repository::getInstance($xref, $this->getParent()->getGedcomId());
         case 'NOTE':
             return WT_Note::getInstance($xref, $this->getParent()->getGedcomId());
         default:
             return WT_GedcomRecord::getInstance($xref, $this->getParent()->getGedcomId());
     }
 }
Example #7
0
 private static function fetchGedcomRecord($xref, $gedcom_id)
 {
     static $statement = null;
     // We don't know what type of object this is.  Try each one in turn.
     $data = WT_Individual::fetchGedcomRecord($xref, $gedcom_id);
     if ($data) {
         return $data;
     }
     $data = WT_Family::fetchGedcomRecord($xref, $gedcom_id);
     if ($data) {
         return $data;
     }
     $data = WT_Source::fetchGedcomRecord($xref, $gedcom_id);
     if ($data) {
         return $data;
     }
     $data = WT_Repository::fetchGedcomRecord($xref, $gedcom_id);
     if ($data) {
         return $data;
     }
     $data = WT_Media::fetchGedcomRecord($xref, $gedcom_id);
     if ($data) {
         return $data;
     }
     $data = WT_Note::fetchGedcomRecord($xref, $gedcom_id);
     if ($data) {
         return $data;
     }
     // Some other type of record...
     if (is_null($statement)) {
         $statement = WT_DB::prepare("SELECT o_gedcom FROM `##other` WHERE o_id=? AND o_file=?");
     }
     return $statement->execute(array($xref, $gedcom_id))->fetchOne();
 }
Example #8
0
     echo '<td  class="optionbox wrap">';
     if ($linktoid == "") {
         echo '<input class="pedigree_form" type="text" name="linktoid" id="linktosid" size="3" value="', $linktoid, '"> ';
         echo print_findsource_link('linktosid');
     } else {
         $record = WT_Source::getInstance($linktoid);
         echo $record->format_list('span', false, $record->getFullName());
     }
 }
 if ($linkto == "repository") {
     echo WT_I18N::translate('Repository'), "</td>";
     echo '<td  class="optionbox wrap">';
     if ($linktoid == "") {
         echo '<input class="pedigree_form" type="text" name="linktoid" id="linktorid" size="3" value="', $linktoid, '">';
     } else {
         $record = WT_Repository::getInstance($linktoid);
         echo $record->format_list('span', false, $record->getFullName());
     }
 }
 if ($linkto == "note") {
     echo WT_I18N::translate('Shared note'), "</td>";
     echo '<td  class="optionbox wrap">';
     if ($linktoid == "") {
         echo '<input class="pedigree_form" type="text" name="linktoid" id="linktonid" size="3" value="', $linktoid, '">';
     } else {
         $record = WT_Note::getInstance($linktoid);
         echo $record->format_list('span', false, $record->getFullName());
     }
 }
 echo '</td></tr>';
 echo '<tr><td class="topbottombar" colspan="2"><input type="submit" value="', WT_I18N::translate('Set link'), '"></td></tr>';
Example #9
0
 static function getLatestRecord($xref, $type)
 {
     switch ($type) {
         case 'INDI':
             return WT_Individual::getInstance($xref)->getGedcom();
         case 'FAM':
             return WT_Family::getInstance($xref)->getGedcom();
         case 'SOUR':
             return WT_Source::getInstance($xref)->getGedcom();
         case 'REPO':
             return WT_Repository::getInstance($xref)->getGedcom();
         case 'OBJE':
             return WT_Media::getInstance($xref)->getGedcom();
         case 'NOTE':
             return WT_Note::getInstance($xref)->getGedcom();
         default:
             return WT_GedcomRecord::getInstance($xref)->getGedcom();
     }
 }
Example #10
0
     }
 }
 // Fetch all data, regardless of privacy
 $rows = get_SOUR_rows($term);
 // Filter for privacy
 foreach ($rows as $row) {
     $source = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
     if ($source->canShowName()) {
         $data[] = array('value' => $source->getXref(), 'label' => $source->getFullName());
     }
 }
 // Fetch all data, regardless of privacy
 $rows = get_REPO_rows($term);
 // Filter for privacy
 foreach ($rows as $row) {
     $repository = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
     if ($repository->canShowName()) {
         $data[] = array('value' => $repository->getXref(), 'label' => $repository->getFullName());
     }
 }
 // Fetch all data, regardless of privacy
 $rows = get_OBJE_rows($term);
 // Filter for privacy
 foreach ($rows as $row) {
     $media = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
     if ($media->canShowName()) {
         $data[] = array('value' => $media->getXref(), 'label' => '<img src="' . $media->getHtmlUrlDirect() . '" width="25"> ' . $media->getFullName());
     }
 }
 // Fetch all data, regardless of privacy
 $rows = get_FAM_rows($term);
Example #11
0
 private function generate_file($ged_id, $rec_type, $volume)
 {
     // Check the cache
     $timestamp = get_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.timestamp');
     if ($timestamp > WT_TIMESTAMP - self::CACHE_LIFE && !WT_USER_ID) {
         $data = get_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.xml');
     } else {
         $tree = WT_Tree::get($ged_id);
         $data = '<url><loc>' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ctype=gedcom&amp;ged=' . $tree->tree_name_url . '</loc></url>' . PHP_EOL;
         $records = array();
         switch ($rec_type) {
             case 'i':
                 $rows = WT_DB::prepare("SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals`" . " WHERE i_file=?" . " ORDER BY i_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 's':
                 $rows = WT_DB::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources`" . " WHERE s_file=?" . " ORDER BY s_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 'r':
                 $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other`" . " WHERE o_file=? AND o_type='REPO'" . " ORDER BY o_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 'n':
                 $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other`" . " WHERE o_file=? AND o_type='NOTE'" . " ORDER BY o_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 'm':
                 $rows = WT_DB::prepare("SELECT m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media`" . " WHERE m_file=?" . " ORDER BY m_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
         }
         foreach ($records as $record) {
             if ($record->canShowName()) {
                 $data .= '<url>';
                 $data .= '<loc>' . WT_SERVER_NAME . WT_SCRIPT_PATH . $record->getHtmlUrl() . '</loc>';
                 $chan = $record->getFirstFact('CHAN');
                 if ($chan) {
                     $date = $chan->getDate();
                     if ($date->isOK()) {
                         $data .= '<lastmod>' . $date->minDate()->Format('%Y-%m-%d') . '</lastmod>';
                     }
                 }
                 $data .= '</url>' . PHP_EOL;
             }
         }
         $data = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL . $data . '</urlset>' . PHP_EOL;
         // Cache this data - but only for visitors, as we don’t want
         // visitors to see data created by logged-in users.
         if (!WT_USER_ID) {
             set_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.xml', $data);
             set_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.timestamp', WT_TIMESTAMP);
         }
     }
     header('Content-Type: application/xml');
     header('Content-Length: ' . strlen($data));
     echo $data;
 }
Example #12
0
function export_gedcom($gedcom, $gedout, $exportOptions)
{
    global $GEDCOM;
    // Temporarily switch to the specified GEDCOM
    $oldGEDCOM = $GEDCOM;
    $GEDCOM = $gedcom;
    $ged_id = get_id_from_gedcom($gedcom);
    switch ($exportOptions['privatize']) {
        case 'gedadmin':
            $access_level = WT_PRIV_NONE;
            break;
        case 'user':
            $access_level = WT_PRIV_USER;
            break;
        case 'visitor':
            $access_level = WT_PRIV_PUBLIC;
            break;
        case 'none':
            $access_level = WT_PRIV_HIDE;
            break;
    }
    $head = gedcom_header($gedcom);
    if ($exportOptions['toANSI'] == 'yes') {
        $head = str_replace('UTF-8', 'ANSI', $head);
        $head = utf8_decode($head);
    }
    $head = reformat_record_export($head);
    fwrite($gedout, $head);
    // Buffer the output.  Lots of small fwrite() calls can be very slow when writing large gedcoms.
    $buffer = '';
    // Generate the OBJE/SOUR/REPO/NOTE records first, as their privacy calcualations involve
    // database queries, and we wish to avoid large gaps between queries due to MySQL connection timeouts.
    $tmp_gedcom = '';
    $rows = WT_DB::prepare("SELECT 'OBJE' AS type, m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media` WHERE m_file=? ORDER BY m_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        $rec = convert_media_path($rec, $exportOptions['path']);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $tmp_gedcom .= reformat_record_export($rec);
    }
    $rows = WT_DB::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources` WHERE s_file=? ORDER BY s_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $tmp_gedcom .= reformat_record_export($rec);
    }
    $rows = WT_DB::prepare("SELECT o_type AS type, o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other` WHERE o_file=? AND o_type!='HEAD' AND o_type!='TRLR' ORDER BY o_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        switch ($row->type) {
            case 'NOTE':
                $record = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                break;
            case 'REPO':
                $record = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                break;
            default:
                $record = WT_GedcomRecord::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                break;
        }
        $rec = $record->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $tmp_gedcom .= reformat_record_export($rec);
    }
    $rows = WT_DB::prepare("SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals` WHERE i_file=? ORDER BY i_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $buffer .= reformat_record_export($rec);
        if (strlen($buffer) > 65536) {
            fwrite($gedout, $buffer);
            $buffer = '';
        }
    }
    $rows = WT_DB::prepare("SELECT f_id AS xref, f_file AS gedcom_id, f_gedcom AS gedcom" . " FROM `##families` WHERE f_file=? ORDER BY f_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Family::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $buffer .= reformat_record_export($rec);
        if (strlen($buffer) > 65536) {
            fwrite($gedout, $buffer);
            $buffer = '';
        }
    }
    fwrite($gedout, $buffer);
    fwrite($gedout, $tmp_gedcom);
    fwrite($gedout, '0 TRLR' . WT_EOL);
    $GEDCOM = $oldGEDCOM;
}