} //echo(" now equals $url\n"); return $url; } // end transform_url // get/update the cache file. // true return means new copy if (get_weblogs_updatedfile()) { //echo('<pre>'); // pre-load the links preload_links(); // Create an XML parser $xml_parser = xml_parser_create(); // Set the functions to handle opening and closing tags xml_set_element_handler($xml_parser, "startElement", "endElement"); // Open the XML file for reading $fp = fopen(ABSPATH . get_settings('weblogs_cache_file'), "r") or die("Error reading XML data."); // Read the XML file 16KB at a time while ($data = fread($fp, 16384)) { // Parse each 4KB chunk with the XML parser created above xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } // Close the XML file fclose($fp); // Free up memory used by the XML parser xml_parser_free($xml_parser); // now update the db with latest times update_links(); //echo('</pre>'); } // end if updated cache file
/** * import record into database * * this function will parse the given gedcom record and add it to the database * @param string $gedrec the raw gedcom record to parse * @param boolean $update whether or not this is an updated record that has been accepted */ function import_record($gedrec, $update) { global $xtype, $TBLPREFIX, $GEDCOM_FILE, $FILE, $pgv_lang, $USE_RIN; global $place_id, $WORD_WRAPPED_NOTES, $GEDCOMS, $MAX_IDS, $fpnewged, $GEDCOM, $GENERATE_UIDS; global $gBitDb, $gGedcom; $FILE = $gGedcom->mGedcomName; // Escaped @ signs (only if importing from file) if (!$update) { $gedrec = str_replace('@@', '@', $gedrec); } // Standardise gedcom format $gedrec = reformat_record_import($gedrec); // import different types of records if (preg_match('/^0 @(' . PGV_REGEX_XREF . ')@ (' . PGV_REGEX_TAG . ')/', $gedrec, $match) > 0) { list(, $gid, $type) = $match; // check for a _UID, if the record doesn't have one, add one if ($GENERATE_UIDS && !strpos($gedrec, "\n1 _UID ")) { $gedrec .= "\n1 _UID " . uuid(); } } elseif (preg_match('/0 (' . PGV_REGEX_TAG . ')/', $gedrec, $match)) { $gid = $match[1]; $type = $match[1]; } else { echo $pgv_lang['invalid_gedformat'], '<br /><pre>', $gedrec, '</pre>'; return; } // keep track of the max id for each type as they are imported if (!isset($MAX_IDS)) { $MAX_IDS = array(); } if (preg_match('/(\\d+)/', $gid, $match)) { $idnum = (int) $match[1]; } else { $idnum = 0; } if (isset($MAX_IDS[$type])) { $MAX_IDS[$type] = max($MAX_IDS[$type], $idnum); } else { $MAX_IDS[$type] = $idnum; } $newrec = update_media($gid, $gedrec, $update); if ($newrec != $gedrec) { $gedrec = $newrec; // make sure we have the correct media id if (preg_match('/0 @(' . PGV_REGEX_XREF . ')@ (' . PGV_REGEX_TAG . ')/', $gedrec, $match)) { list(, $gid, $type) = $match; } else { echo $pgv_lang['invalid_gedformat'], '<br /><pre>', $gedrec, '</pre>'; return; } } switch ($type) { case 'INDI': $record = new Person($gedrec); break; case 'FAM': $record = new Family($gedrec); break; case 'SOUR': $record = new Source($gedrec); break; case 'REPO': $record = new Repository($gedrec); break; case 'OBJE': $record = new Media($gedrec); break; default: $record = new GedcomRecord($gedrec); $type = $record->getType(); break; } // Just in case the admin has blocked themself from seeing names! $record->disp = true; $record->dispname = true; // Update the cross-reference/index tables. $ged_id = $gGedcom->mGEDCOMId; $xref = $gid; update_places($xref, $ged_id, $gedrec); update_dates($xref, $ged_id, $gedrec); update_links($xref, $ged_id, $gedrec); update_rlinks($xref, $ged_id, $gedrec); update_names($xref, $ged_id, $record); switch ($type) { case 'INDI': if ($USE_RIN && preg_match('/\\n1 RIN (.+)/', $gedrec, $match)) { $rin = $match[1]; } else { $rin = $xref; } $param = array($xref, $ged_id, $rin, is_dead($gedrec, '', true), $record->getSex(), $gedrec); $gBitDb->query("INSERT INTO {$TBLPREFIX}individuals (i_id, i_file, i_rin, i_isdead, i_sex, i_gedcom) VALUES (?,?,?,?,?,?)", $param); break; case 'FAM': if (preg_match('/\\n1 HUSB @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) { $husb = $match[1]; } else { $husb = ''; } if (preg_match('/\\n1 WIFE @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) { $wife = $match[1]; } else { $wife = ''; } if ($nchi = preg_match_all('/\\n1 CHIL @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) { $chil = implode(';', $match[1]) . ';'; } else { $chil = ''; } if (preg_match('/\\n1 NCHI (\\d+)/', $gedrec, $match)) { $nchi = max($nchi, $match[1]); } $param = array($xref, $ged_id, $husb, $wife, $chil, $gedrec, $nchi); $gBitDb->query("INSERT INTO {$TBLPREFIX}families (f_id, f_file, f_husb, f_wife, f_chil, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?,?)", $param); break; case 'SOUR': if (preg_match('/\\n1 TITL (.+)/', $gedrec, $match)) { $name = $match[1]; } elseif (preg_match('/\\n1 ABBR (.+)/', $gedrec, $match)) { $name = $match[1]; } else { $name = $gid; } if (strpos($gedrec, "\n1 _DBID")) { $_dbid = 'Y'; } else { $_dbid = null; } $gBitDb->query("INSERT INTO {$TBLPREFIX}sources (s_id, s_file, s_name, s_gedcom, s_dbid) VALUES (?,?,?,?,?)", array($xref, $ged_id, $name, $gedrec, $_dbid)); break; case 'OBJE': // OBJE records are imported by update_media function break; case 'HEAD': if (!strpos($gedrec, "\n1 DATE ")) { $gedrec .= "\n1 DATE " . date('j M Y'); } // no break // no break default: if (substr($type, 0, 1) != '_') { $gBitDb->query("INSERT INTO {$TBLPREFIX}other (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)", array($xref, $ged_id, $type, $gedrec)); } break; } // if this is not an update then write it to the new gedcom file if (!$update && !empty($fpnewged)) { fwrite($fpnewged, reformat_record_export($gedrec)); } $xtype = $type; // Pass value back to uploadgedcom.php }
/** * import record into database * * this function will parse the given gedcom record and add it to the database * * @param string $gedrec the raw gedcom record to parse * @param integer $ged_id import the record into this gedcom * @param boolean $update whether or not this is an updated record that has been accepted */ function import_record($gedrec, $ged_id, $update) { global $USE_RIN, $GENERATE_UIDS, $keep_media; static $sql_insert_indi = null; static $sql_insert_fam = null; static $sql_insert_sour = null; static $sql_insert_media = null; static $sql_insert_other = null; if (!$sql_insert_indi) { $sql_insert_indi = WT_DB::prepare("INSERT INTO `##individuals` (i_id, i_file, i_rin, i_sex, i_gedcom) VALUES (?,?,?,?,?)"); $sql_insert_fam = WT_DB::prepare("INSERT INTO `##families` (f_id, f_file, f_husb, f_wife, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?)"); $sql_insert_sour = WT_DB::prepare("INSERT INTO `##sources` (s_id, s_file, s_name, s_gedcom) VALUES (?,?,?,?)"); $sql_insert_media = WT_DB::prepare("INSERT INTO `##media` (m_id, m_ext, m_type, m_titl, m_filename, m_file, m_gedcom) VALUES (?, ?, ?, ?, ?, ?, ?)"); $sql_insert_other = WT_DB::prepare("INSERT INTO `##other` (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)"); } // Escaped @ signs (only if importing from file) if (!$update) { $gedrec = str_replace('@@', '@', $gedrec); } // Standardise gedcom format $gedrec = reformat_record_import($gedrec); // import different types of records if (preg_match('/^0 @(' . WT_REGEX_XREF . ')@ (' . WT_REGEX_TAG . ')/', $gedrec, $match)) { list(, $xref, $type) = $match; // check for a _UID, if the record doesn't have one, add one if ($GENERATE_UIDS && !strpos($gedrec, "\n1 _UID ")) { $gedrec .= "\n1 _UID " . WT_Gedcom_Tag::createUid(); } } elseif (preg_match('/0 (HEAD|TRLR)/', $gedrec, $match)) { $type = $match[1]; $xref = $type; // For HEAD/TRLR, use type as pseudo XREF. } else { echo WT_I18N::translate('Invalid GEDCOM format'), '<br><pre>', $gedrec, '</pre>'; return; } // If the user has downloaded their GEDCOM data (containing media objects) and edited it // using an application which does not support (and deletes) media objects, then add them // back in. if ($keep_media && $xref) { $old_linked_media = WT_DB::prepare("SELECT l_to FROM `##link` WHERE l_from=? AND l_file=? AND l_type='OBJE'")->execute(array($xref, $ged_id))->fetchOneColumn(); foreach ($old_linked_media as $media_id) { $gedrec .= "\n1 OBJE @" . $media_id . "@"; } } switch ($type) { case 'INDI': // Convert inline media into media objects $gedrec = convert_inline_media($ged_id, $gedrec); $record = new WT_Individual($xref, $gedrec, null, $ged_id); if ($USE_RIN && preg_match('/\\n1 RIN (.+)/', $gedrec, $match)) { $rin = $match[1]; } else { $rin = $xref; } $sql_insert_indi->execute(array($xref, $ged_id, $rin, $record->getSex(), $gedrec)); // Update the cross-reference/index tables. update_places($xref, $ged_id, $gedrec); update_dates($xref, $ged_id, $gedrec); update_links($xref, $ged_id, $gedrec); update_names($xref, $ged_id, $record); break; case 'FAM': // Convert inline media into media objects $gedrec = convert_inline_media($ged_id, $gedrec); if (preg_match('/\\n1 HUSB @(' . WT_REGEX_XREF . ')@/', $gedrec, $match)) { $husb = $match[1]; } else { $husb = ''; } if (preg_match('/\\n1 WIFE @(' . WT_REGEX_XREF . ')@/', $gedrec, $match)) { $wife = $match[1]; } else { $wife = ''; } $nchi = preg_match_all('/\\n1 CHIL @(' . WT_REGEX_XREF . ')@/', $gedrec, $match); if (preg_match('/\\n1 NCHI (\\d+)/', $gedrec, $match)) { $nchi = max($nchi, $match[1]); } $sql_insert_fam->execute(array($xref, $ged_id, $husb, $wife, $gedrec, $nchi)); // Update the cross-reference/index tables. update_places($xref, $ged_id, $gedrec); update_dates($xref, $ged_id, $gedrec); update_links($xref, $ged_id, $gedrec); break; case 'SOUR': // Convert inline media into media objects $gedrec = convert_inline_media($ged_id, $gedrec); $record = new WT_Source($xref, $gedrec, null, $ged_id); if (preg_match('/\\n1 TITL (.+)/', $gedrec, $match)) { $name = $match[1]; } elseif (preg_match('/\\n1 ABBR (.+)/', $gedrec, $match)) { $name = $match[1]; } else { $name = $xref; } $sql_insert_sour->execute(array($xref, $ged_id, $name, $gedrec)); // Update the cross-reference/index tables. update_links($xref, $ged_id, $gedrec); update_names($xref, $ged_id, $record); break; case 'REPO': // Convert inline media into media objects $gedrec = convert_inline_media($ged_id, $gedrec); $record = new WT_Repository($xref, $gedrec, null, $ged_id); $sql_insert_other->execute(array($xref, $ged_id, $type, $gedrec)); // Update the cross-reference/index tables. update_links($xref, $ged_id, $gedrec); update_names($xref, $ged_id, $record); break; case 'NOTE': $record = new WT_Note($xref, $gedrec, null, $ged_id); $sql_insert_other->execute(array($xref, $ged_id, $type, $gedrec)); // Update the cross-reference/index tables. update_links($xref, $ged_id, $gedrec); update_names($xref, $ged_id, $record); break; case 'OBJE': $record = new WT_Media($xref, $gedrec, null, $ged_id); $sql_insert_media->execute(array($xref, $record->extension(), $record->getMediaType(), $record->title, $record->file, $ged_id, $gedrec)); // Update the cross-reference/index tables. update_links($xref, $ged_id, $gedrec); update_names($xref, $ged_id, $record); break; case 'HEAD': // Force HEAD records to have a creation date. if (!strpos($gedrec, "\n1 DATE ")) { $gedrec .= "\n1 DATE " . date('j M Y'); } // No break; // No break; case 'TRLR': case 'SUBM': case 'SUBN': $sql_insert_other->execute(array($xref, $ged_id, $type, $gedrec)); // Update the cross-reference/index tables. update_links($xref, $ged_id, $gedrec); break; default: $record = new WT_GedcomRecord($xref, $gedrec, null, $ged_id); $sql_insert_other->execute(array($xref, $ged_id, $type, $gedrec)); // Update the cross-reference/index tables. update_links($xref, $ged_id, $gedrec); update_names($xref, $ged_id, $record); break; } }
public static function addLinks($to_print) { parse_str($_SERVER['QUERY_STRING'], $vars); $new_vars = array(); if (array_key_exists('debug', $vars)) { $new_vars['debug'] = $vars['debug']; } if (array_key_exists('nocache', $vars)) { $new_vars['nocache'] = $vars['nocache']; } if (array_key_exists('recache', $vars)) { $new_vars['recache'] = $vars['recache']; } /*if (array_key_exists('mode', $vars)) { $new_vars['mode'] = $vars['mode']; }*/ $to_print = update_links($to_print, $new_vars); return $to_print; }