Пример #1
1
 function get_all_taxa()
 {
     require_library('connectors/INBioAPI');
     $func = new INBioAPI();
     $paths = $func->extract_archive_file($this->dwca_file, "meta.xml");
     $archive_path = $paths['archive_path'];
     $temp_dir = $paths['temp_dir'];
     $harvester = new ContentArchiveReader(NULL, $archive_path);
     $tables = $harvester->tables;
     if (!($this->fields["taxa"] = $tables["http://rs.tdwg.org/dwc/terms/taxon"][0]->fields)) {
         debug("Invalid archive file. Program will terminate.");
         return false;
     }
     self::build_taxa_rank_array($harvester->process_row_type('http://rs.tdwg.org/dwc/terms/Taxon'));
     self::create_instances_from_taxon_object($harvester->process_row_type('http://rs.tdwg.org/dwc/terms/Taxon'));
     self::get_objects($harvester->process_row_type('http://eol.org/schema/media/Document'));
     self::get_references($harvester->process_row_type('http://rs.gbif.org/terms/1.0/Reference'));
     self::get_agents($harvester->process_row_type('http://eol.org/schema/agent/Agent'));
     self::get_vernaculars($harvester->process_row_type('http://rs.gbif.org/terms/1.0/VernacularName'));
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     recursive_rmdir($temp_dir);
     echo "\n temporary directory removed: " . $temp_dir;
     print_r($this->debug);
 }
Пример #2
0
 function get_all_taxa($taxa_list_text_file = NULL)
 {
     $this->TEMP_FILE_PATH = create_temp_dir() . "/";
     if ($taxa_list_text_file) {
         if ($contents = Functions::lookup_with_cache($taxa_list_text_file, $this->download_options)) {
             self::save_to_taxa_text_file($contents);
         }
     } else {
         self::generate_taxa_list();
     }
     /* debug: stop operation here if you only want to generate taxa list */
     //return;
     self::save_data_to_text();
     /* debug: stop operation here if you only want to generate processed text files */
     //return;
     if ($taxa_list_text_file) {
         echo "\n\n finished processing: [{$taxa_list_text_file}]\n\n";
         return;
         // you need to consolidate the processed text files before proceeding.
     }
     self::process_text_file();
     $this->archive_builder->finalize(true);
     // remove temp dir
     recursive_rmdir($this->TEMP_FILE_PATH);
     echo "\n temporary directory removed: " . $this->TEMP_FILE_PATH;
 }
Пример #3
0
function recursive_rmdir($directory, $empty = false)
{
    $directory = preg_replace('@[\\/]$@', '', $directory);
    if (!file_exists($directory) || !is_dir($directory)) {
        return false;
    } elseif (!is_readable($directory)) {
        return false;
    } else {
        $handle = opendir($directory);
        while (false !== ($item = readdir($handle))) {
            if ($item != '.' && $item != '..') {
                $path = $directory . DIRECTORY_SEPARATOR . $item;
                if (is_dir($path)) {
                    recursive_rmdir($path);
                } elseif (unlink($path)) {
                    echo $path . "\n";
                }
            }
        }
        closedir($handle);
        if ($empty == false) {
            if (rmdir($directory)) {
                echo $directory . "\n";
            } else {
                return false;
            }
        }
        return true;
    }
}
 function get_all_taxa()
 {
     $this->institution_uris = self::get_institution_uris();
     self::load_zip_contents();
     print_r($this->text_path);
     require_library('connectors/FishBaseAPI');
     $func = new FishBaseAPI();
     $fields = array("lngSpeciesSenior_ID", "lngSpecies_ID", "lngRepository_ID", "strCatNr", "lngPrepMeth_ID", "lngPersPrep_ID", "lngPersID2_ID", "lngPersID3_ID", "bytCountPrep", "lngDocuTypeSpecimen", "lngPrep_ID", "txtPrepNotes", "lngSpecimen_ID", "strTypeStat", "lngLoc_ID", "strLocName", "txtLocDescr", "sngElevation", "sngLatitudeWGS84", "sngLongitudeWGS84", "lngMacrohabitat_ID", "lngPermanency_ID", "strDepth", "lngGeology_ID", "lngSpecLocal_ID");
     $records_specimen = $func->make_array($this->text_path["sd_specimen"], $fields, "", array());
     array_shift($records_specimen);
     $fields = array("lngPersIdent_ID", "lngSpecimen_ID");
     $records_specimen_identifier = $func->make_array($this->text_path["sd_specimen_identifier"], $fields, "", array());
     array_shift($records_specimen_identifier);
     $fields = array("lngSpeciesSenior_ID", "lngMacroMicro_ID", "lngSpecies_ID");
     $records_habitat = $func->make_array($this->text_path["sd_macro_locality"], $fields, "", array());
     array_shift($records_habitat);
     /*
     $fields = array("lngLoc_ID", "strLocName", "txtLocDescr", "sngElevation", "sngLatitudeWGS84", "sngLongitudeWGS84", "lngMacrohabitat_ID", "lngPermanency_ID", "strDepth", "lngGeology_ID", "lngSpecLocal_ID", "lngSpecimen_ID", "lngSpeciesSenior_ID", "lngSpecies_ID");
     $records_locality = $func->make_array($this->text_path["sd_locality"], $fields, "", array());
     array_shift($records_locality);
     */
     $this->assemble_identified_by($records_specimen_identifier);
     $this->create_instances_from_taxon_object($records_specimen, "specimen");
     // $this->create_instances_from_taxon_object($records_locality, "locality");
     $this->create_instances_from_taxon_object($records_habitat, "habitat");
     $this->create_archive();
     // remove temp dir
     $path = $this->text_path["sd_specimen"];
     $parts = pathinfo($path);
     $parts["dirname"] = str_ireplace("/type_specimen", "", $parts["dirname"]);
     recursive_rmdir($parts["dirname"]);
     debug("\n temporary directory removed: " . $parts["dirname"]);
 }
 function get_all_taxa()
 {
     /*
     $id = "100001";
     $arr = array("distribution", "chromosome", "taxon_name", "taxonomy", "synonyms", "taxon_ref", "images");
     foreach($arr as $type)
     {
         if($type == "taxon_name") $url = TROPICOS_API_SERVICE . $id . "?format=json&apikey=" . TROPICOS_API_KEY;
         elseif($type == "taxonomy") $url = TROPICOS_API_SERVICE . $id . "/HigherTaxa?format=xml&apikey=" . TROPICOS_API_KEY;
         elseif($type == "synonyms") $url = TROPICOS_API_SERVICE . $id . "/Synonyms?format=xml&apikey=" . TROPICOS_API_KEY;
         elseif($type == "taxon_ref") $url = TROPICOS_API_SERVICE . $id . "/References?format=xml&apikey=" . TROPICOS_API_KEY;
         elseif($type == "distribution") $url = TROPICOS_API_SERVICE . $id . "/Distributions?format=xml&apikey=" . TROPICOS_API_KEY;
         elseif($type == "images") $url = TROPICOS_API_SERVICE . $id . "/Images?format=xml&apikey=" . TROPICOS_API_KEY;
         elseif($type == "chromosome") $url = TROPICOS_API_SERVICE . $id . "/ChromosomeCounts?format=xml&apikey=" . TROPICOS_API_KEY;
         echo "\n $type: [$url]";
     }
     exit;
     */
     self::assemble_id_list();
     exit;
     self::process_taxa();
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     recursive_rmdir($this->TEMP_DIR);
     echo "\n temporary directory removed: " . $this->TEMP_DIR;
 }
Пример #6
0
 function export_gbif_to_eol($params)
 {
     require_library('connectors/INBioAPI');
     $func = new INBioAPI();
     $paths = $func->extract_archive_file($params["dwca_file"], "meta.xml");
     $archive_path = $paths['archive_path'];
     $temp_dir = $paths['temp_dir'];
     $harvester = new ContentArchiveReader(NULL, $archive_path);
     $tables = $harvester->tables;
     if (!($this->fields["occurrence"] = $tables["http://rs.tdwg.org/dwc/terms/occurrence"][0]->fields)) {
         debug("Invalid archive file. Program will terminate.");
         return false;
     }
     /*
         $harvester->process_row_type() -  this will convert rows into array.
     */
     // $r = $harvester->process_row_type('http://rs.tdwg.org/dwc/terms/occurrence');
     // $r = $harvester->process_row_type('http://rs.gbif.org/terms/1.0/Multimedia');
     // print_r($r); exit;
     self::create_instances_from_taxon_object($harvester->process_row_type('http://rs.tdwg.org/dwc/terms/occurrence'));
     self::get_media_objects($harvester->process_row_type('http://rs.gbif.org/terms/1.0/Multimedia'));
     // self::get_objects($harvester->process_row_type('http://eol.org/schema/media/Document'));
     // self::get_references($harvester->process_row_type('http://rs.gbif.org/terms/1.0/Reference'));
     // self::get_agents($harvester->process_row_type('http://eol.org/schema/agent/Agent'));
     // self::get_vernaculars($harvester->process_row_type('http://rs.gbif.org/terms/1.0/VernacularName'));
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     recursive_rmdir($temp_dir);
     echo "\n temporary directory removed: " . $temp_dir;
 }
Пример #7
0
 function get_all_taxa()
 {
     self::initialize_dump_file();
     $this->agent_ids = self::get_object_agents($this->agents);
     // /* normal operation
     $this->save_data_to_text();
     $this->access_dump_file(false, "synonyms");
     $this->access_dump_file(false, "objects");
     $this->process_taxa();
     // */
     /* use this if the dump file has already been created - works okay!
        $dump_file = DOC_ROOT . "tmp/turbellarian_dump/turbellarian_dump.txt";
        $this->access_dump_file($dump_file, "synonyms");
        $this->access_dump_file($dump_file, "objects");
        $this->process_taxa($dump_file);
        */
     /* manually adding Bilateria */
     $rec = array();
     $rec["sciname"] = "Bilateria";
     $rec["taxon_id"] = "Bilateria";
     $rec["authorship"] = "";
     $rec["parent_id"] = "";
     $rec["status"] = "";
     $this->create_instances_from_taxon_object($rec);
     $this->create_archive();
     /* remove temp dir */
     recursive_rmdir($this->TEMP_DIR);
     echo "\n temporary directory removed: " . $this->TEMP_DIR;
 }
 function generate_EnvEOL_data()
 {
     require_library('connectors/IUCNRedlistDataConnector');
     $func = new IUCNRedlistDataConnector();
     $basenames = array("eol_env_annotations_noParentTerms");
     // list of needed basenames
     $options = $this->download_options;
     $options['expire_seconds'] = 2592000 * 3;
     // 3 months before cache expires
     $text_path = $func->load_zip_contents($this->species_list_export, $options, $basenames, ".tsv");
     print_r($text_path);
     self::csv_to_array($text_path[$basenames[0]]);
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     $parts = pathinfo($text_path[$basenames[0]]);
     recursive_rmdir($parts["dirname"]);
     debug("\n temporary directory removed: " . $parts["dirname"]);
     recursive_rmdir($this->TEMP_DIR);
     // comment this if u want to check "need_to_check_tc_id.txt"
     /* run problematic tc_ids with cache=0 --- a utility
        $tc_ids = self::get_dump();
        foreach($tc_ids as $tc_id)
        {
            $rec['taxon_id'] = $tc_id;
            self::prepare_taxon($rec);
        }
        exit("\n-exit-\n");
        */
 }
 function load_xml_string()
 {
     $file_contents = "";
     debug("Please wait, downloading resource document...");
     if (preg_match("/^(.*)\\.(gz|gzip)\$/", $this->xml_path, $arr)) {
         $path_parts = pathinfo($this->xml_path);
         $filename = $path_parts['basename'];
         $temp_dir = create_temp_dir() . "/";
         debug("temp file path: " . $temp_dir);
         if ($file_contents = Functions::get_remote_file($this->xml_path, array('timeout' => 172800))) {
             $temp_file_path = $temp_dir . "/" . $filename;
             $TMP = fopen($temp_file_path, "w");
             fwrite($TMP, $file_contents);
             fclose($TMP);
             shell_exec("gunzip -f {$temp_file_path}");
             $this->xml_path = $temp_dir . str_ireplace(".gz", "", $filename);
             debug("xml path: " . $this->xml_path);
         } else {
             debug("Connector terminated. Remote files are not ready.");
             return false;
         }
         echo "\n {$temp_dir} \n";
         $file_contents = Functions::get_remote_file($this->xml_path, array('timeout' => 172800));
         recursive_rmdir($temp_dir);
         // remove temp dir
         echo "\n temporary directory removed: [{$temp_dir}]\n";
     }
     return $file_contents;
 }
Пример #10
0
 function export_gbif_to_eol($params)
 {
     $this->uris = self::get_uris($params);
     require_library('connectors/INBioAPI');
     $func = new INBioAPI();
     $paths = $func->extract_archive_file($params["dwca_file"], "meta.xml", array("timeout" => 7200, "expire_seconds" => false));
     // "expire_seconds" -- false => won't expire; 0 => expires now
     $archive_path = $paths['archive_path'];
     $temp_dir = $paths['temp_dir'];
     $this->harvester = new ContentArchiveReader(NULL, $archive_path);
     if (!@$this->harvester->tables["http://rs.tdwg.org/dwc/terms/occurrence"][0]->fields) {
         debug("Invalid archive file. Program will terminate.");
         return false;
     }
     if ($params["dataset"] == "NMNH") {
         self::process_row_type($params);
     } elseif ($params["dataset"] == "NHM") {
         self::process_row_type_from_NHM($temp_dir . "/" . $params['location']);
     }
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     recursive_rmdir($temp_dir);
     echo "\n temporary directory removed: " . $temp_dir;
     print_r($this->debug);
 }
Пример #11
0
 public function uninstall()
 {
     recursive_rmdir(DATA_DIR . '/Base_Theme/templates/default/images');
     Variable::delete('default_theme');
     Variable::delete('preload_image_cache_default');
     Variable::delete('preload_image_cache_selected');
     return true;
 }
Пример #12
0
 function get_all_taxa()
 {
     if (self::process_text_files()) {
         $this->create_archive();
         // remove temp dir
         $parts = pathinfo($this->text_path["1"]);
         recursive_rmdir($parts["dirname"]);
         debug("\n temporary directory removed: " . $parts["dirname"]);
     }
 }
Пример #13
0
 function get_all_taxa()
 {
     self::process_text_files();
     // remove temp dir
     $path = $this->text_path["species"];
     $parts = pathinfo($path);
     $parts["dirname"] = str_ireplace("/rotifers", "", $parts["dirname"]);
     recursive_rmdir($parts["dirname"]);
     debug("\n temporary directory removed: " . $parts["dirname"]);
 }
Пример #14
0
 function export_lifedesk_to_eol($params)
 {
     require_library('connectors/LifeDeskToScratchpadAPI');
     $func = new LifeDeskToScratchpadAPI();
     if ($this->text_path = $func->load_zip_contents($params["lifedesk"])) {
         self::update_eol_xml("LD_" . $params["name"]);
     }
     // remove temp dir
     $parts = pathinfo($this->text_path["eol_xml"]);
     recursive_rmdir($parts["dirname"]);
     debug("\n temporary directory removed: " . $parts["dirname"]);
 }
Пример #15
0
 function get_all_taxa()
 {
     $this->stored_offline_urls = $this->get_rows_from_dump_file($this->stored_offline_urls_dump_file);
     $this->create_reference();
     $urls = self::get_urls_to_process();
     $this->process_urls($urls);
     $this->manuall_add_taxon();
     $this->archive_builder->finalize(TRUE);
     recursive_rmdir($this->TEMP_DIR);
     // comment this line to check offline_urls.txt
     debug("\n temporary directory removed: " . $this->TEMP_DIR);
 }
 public function begin()
 {
     $this->path_to_archive_directory = CONTENT_RESOURCE_LOCAL_PATH . '/' . $this->resource_id . '_working/';
     $this->archive_builder = new \eol_schema\ContentArchiveBuilder(array('directory_path' => $this->path_to_archive_directory));
     $this->prepare_files();
     $this->process_export();
     $this->archive_builder->finalize(true);
     //remove temp dir
     $parts = pathinfo($this->source_file_path);
     recursive_rmdir($parts["dirname"]);
     debug("\n temporary directory removed: " . $parts["dirname"]);
 }
 function get_all_taxa($resource_id)
 {
     $this->uris = self::get_uris();
     // print_r($this->uris); exit;
     /*
     $str = "bathydemersal; marine; depth range 549 - 1202 m (Ref. 97189)";
     $str = "benthopelagic; potamodromous (Ref. 51243); freshwater; brackish; pH range: 7.0 - 7.5; dH range: 15; depth range 1 - ? m (Ref. 9696)";
     $str = "depth range 220 - 457 m, usually 274 - 402 m";
     $str = "reef-associated; non-migratory; marine; depth range 6 - 80 m (Ref. 9334), usually 6 - 20 m (Ref. 6852)";
     $str = "demersal; freshwater; pH range: 6.6 - 36,751.0; depth range 0 - 1 m (Ref. 58018)";
     
     $parts = self::get_description_parts($str, false); 
     print_r($parts); 
     $a = self::process_habitat_data($parts);
     print_r($a);
     exit;
     */
     /*
     $str = "33.7 cm SL (male/unsexed; (Ref. 93606)); max. reported age: 33 years (Ref. 93630)";
     $str = "69.0 cm TL (male/unsexed; (Ref. 5578))";
     $str = "4.7 cm SL (male/unsexed; (Ref. 4696)); 3.9 cm SL (female); max. reported age: 1 years (Ref. 232)";
     $str = "61.0 cm TL (male/unsexed; (Ref. 58426)); 
     42.9 cm SL (female); 
     max. published weight: 9,500 g (Ref. 4701); 
     max. published weight: 5,000.0 g; 
     max. reported age: 13 years (Ref. 54207)";
     $str = "50.0 cm TL (male/unsexed; (Ref. 3506)); 
             133 cm TL (female); 
             max. published weight: 6,599 g (Ref. 39903); 
             max. published weight: 2,850.0 g; 
             max. reported age: 88 years (Ref. 72468)";
     
     $str = str_ireplace("unsexed;", "unsexed", $str);
     $parts = self::get_description_parts($str, false);
     print_r($parts); 
     $a = self::process_size_data($parts);
     print_r($a);
     exit;
     */
     self::prepare_data();
     // remove tmp dir
     $this->TEMP_FILE_PATH = str_ireplace("/fishbase", "", $this->TEMP_FILE_PATH);
     // if($this->TEMP_FILE_PATH) shell_exec("rm -fr $this->TEMP_FILE_PATH");
     recursive_rmdir($this->TEMP_FILE_PATH);
     // debug uncomment in real operation
     echo "\n temporary directory removed: " . $this->TEMP_FILE_PATH;
     if ($this->test_run) {
         return $all_taxa;
     }
     //used in testing
 }
 public function __construct()
 {
     $this->mysqli =& $GLOBALS['db_connection'];
     if ($GLOBALS['ENV_NAME'] == 'production' && environment_defined('slave')) {
         $this->mysqli_slave = load_mysql_environment('slave');
     } else {
         $this->mysqli_slave =& $this->mysqli;
     }
     $this->output_directory = DOC_ROOT . "temp/eol_names_and_ranks_to_family_archive/";
     recursive_rmdir($this->output_directory);
     $this->archive_builder = new \eol_schema\ContentArchiveBuilder(array('directory_path' => $this->output_directory));
     $this->load_all_ranks();
     $this->load_all_hierarchies();
 }
Пример #19
0
 public function build_archive()
 {
     $this->path_to_archive_directory = CONTENT_RESOURCE_LOCAL_PATH . "/{$this->resource_id}/";
     $this->archive_builder = new \eol_schema\ContentArchiveBuilder(array('directory_path' => $this->path_to_archive_directory));
     if ($download_directory = ContentManager::download_temp_file_and_assign_extension(self::DUMP_URL)) {
         if (is_dir($download_directory) && file_exists($download_directory . "/names.dmp")) {
             $this->download_directory = $download_directory;
             $this->get_names();
             $this->get_nodes();
             recursive_rmdir($download_directory);
         }
     }
     $this->archive_builder->finalize(true);
 }
Пример #20
0
 function process_xml($params)
 {
     $all_taxa = self::get_taxa_list_from_biogeodb();
     $this->taxa_id_list = array_merge($all_taxa, self::get_taxa_list_from_myspecies());
     require_library('connectors/INBioAPI');
     $func = new INBioAPI();
     $paths = $func->extract_archive_file($params["eol_xml_file"], $params["filename"], array("timeout" => 7200, "expire_seconds" => false));
     print_r($paths);
     $params["path"] = $paths["temp_dir"];
     $xml = self::update_xml($params);
     recursive_rmdir($paths["temp_dir"]);
     // remove temp dir
     return $xml;
 }
 function generate_IUCN_data()
 {
     $basename = $this->export_basename;
     $text_path = self::load_zip_contents($this->species_list_export, $this->download_options, array($basename), ".csv");
     print_r($text_path);
     self::csv_to_array($text_path[$basename]);
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     $path = $text_path[$basename];
     $parts = pathinfo($path);
     $parts["dirname"] = str_ireplace($basename, "", $parts["dirname"]);
     recursive_rmdir($parts["dirname"]);
     debug("\n temporary directory removed: " . $parts["dirname"]);
     print_r($this->debug);
 }
Пример #22
0
 function get_all_taxa()
 {
     require_library('connectors/INBioAPI');
     $func = new INBioAPI();
     $paths = $func->extract_archive_file($this->dwca_file, "meta.xml");
     $archive_path = $paths['archive_path'];
     $harvester = new ContentArchiveReader(NULL, $archive_path);
     $tables = $harvester->tables;
     if (!($this->fields["taxa"] = $tables["http://rs.tdwg.org/dwc/terms/taxon"][0]->fields)) {
         debug("Invalid archive file. Program will terminate.");
         return false;
     }
     if ($records = $harvester->process_row_type('http://rs.gbif.org/terms/1.0/Reference')) {
         self::get_references($records);
     }
     if ($records = $harvester->process_row_type('http://rs.tdwg.org/dwc/terms/Taxon')) {
         $taxa_id_list = self::get_taxa_id_list($records);
         self::create_instances_from_taxon_object($records, $taxa_id_list);
     }
     if ($this->params["process occurrence"]) {
         echo "\nProcessed OCCURRENCE\n";
         if ($records = $harvester->process_row_type('http://rs.tdwg.org/dwc/terms/Occurrence')) {
             $this->uris = self::get_uris();
             self::get_occurrences($records);
         }
     }
     if ($records = $harvester->process_row_type('http://rs.gbif.org/terms/1.0/Distribution')) {
         self::get_distributions($records);
     }
     if ($records = $harvester->process_row_type('http://rs.gbif.org/terms/1.0/Image')) {
         self::get_images($records);
     }
     //http://eol.org/content_partners/159/resources/345
     if ($records = $harvester->process_row_type('http://rs.gbif.org/terms/1.0/Description')) {
         self::get_descriptions($records);
     }
     //http://eol.org/content_partners/159/resources/332
     if ($records = $harvester->process_row_type('http://rs.gbif.org/terms/1.0/VernacularName')) {
         self::get_vernaculars($records);
     }
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     recursive_rmdir($paths['temp_dir']);
     echo "\n temporary directory removed: " . $paths['temp_dir'];
     print_r($this->debug);
 }
Пример #23
0
 function generate_traits_for_taxa($params)
 {
     $this->temp_dir = create_temp_dir() . "/";
     $taxa = self::access_spreadsheet($params, 0);
     $this->traits = self::access_spreadsheet($params, 1);
     self::process_taxa($taxa, "get_measurement_fields");
     self::initialize_text_files();
     self::process_taxa($taxa, "process_taxa");
     self::delete_blank_text_files();
     // compress text files, delete temp dir
     $trait_request_dir_path = DOC_ROOT . "/public/tmp/trait_request/";
     if (!is_dir($trait_request_dir_path)) {
         mkdir($trait_request_dir_path);
     }
     $command_line = "tar -czf " . $trait_request_dir_path . $params["name"] . ".tar.gz --directory=" . $this->temp_dir . " .";
     $output = shell_exec($command_line);
     recursive_rmdir($this->temp_dir);
 }
Пример #24
0
 function get_all_taxa($resource_id)
 {
     $this->uris = self::get_uris();
     $this->bibliographic_citation = self::get_fishbase_remote_citation();
     /*
     $str = "Circumglobal in coastal warm temperate and tropical seas (Ref. 13562). Western Atlantic: North Carolina, USA to Uruguay, including the Gulf of Mexico and Caribbean. Eastern Atlantic: Mediterranean and Morocco to Senegal. Indo-Pacific: throughout the Indian Ocean; Ryukyu Islands to New Caledonia and French Polynesia. Eastern Pacific: southern Baja California, Mexico to Peru. Highly migratory species, Annex I of the 1982 Convention on the Law of the Sea (Ref. 26139).";
     $str = "Western Atlantic: o River basin (Ref. 3498, 40587, 81627), but also in Ogowe River, Kouilou-Niari River and Loeme River (Ref. 3498, 40587, 81627, Ref. 2)Panama to southern Brazil and Uruguay (Ref. 58839) (Ref. 5663, 89864) bvhgbhghty hbgj nh b hgv (Ref. 2921, Ref. 3515).";
     $texts = self::process_distribution_text($str);
     print_r($texts); exit;
     */
     /*
     $str = "bathydemersal; marine; depth range 549 - 1202 m (Ref. 97189)";
     $str = "benthopelagic; potamodromous (Ref. 51243); freshwater; brackish; pH range: 7.0 - 7.5; dH range: 15; depth range 1 - ? m (Ref. 9696)";
     $str = "depth range 220 - 457 m, usually 274 - 402 m";
     $str = "reef-associated; non-migratory; marine; depth range 6 - 80 m (Ref. 9334), usually 6 - 20 m (Ref. 6852)";
     $str = "non-migratory; freshwater; anadromous; pH range: 6.6 - 36,751.0; depth range 0 - 1 m (Ref. 58018)";
     $str = "pH range: 6.6; depth range 220 - 457 m, usually 274 - 402 m";
     $str = "depth range 220 - 457 m; benthopelagic; freshwater, usually ? - 10 m (Ref. 5595)";
     $str = "demersal; amphidromous? (Ref. 51243); freshwater; brackish; marine; depth range ? - 5 m (Ref. 6733)";
     $parts = self::get_description_parts($str, false); print_r($parts); 
     $a = self::process_habitat_data($parts); print_r($a); exit;
     */
     /*
     $str = "33.7 cm SL (male/unsexed; (Ref. 93606)); max. reported age: 33 years (Ref. 93630)";
     $str = "69.0 cm TL (male/unsexed; (Ref. 5578))";
     $str = "4.7 cm SL (male/unsexed; (Ref. 4696)); 3.9 cm SL (female); max. reported age: 1 years (Ref. 232)";
     $str = "61.0 cm TL (male/unsexed; (Ref. 58426)); 42.9 cm SL (female); max. published weight: 9,500 g (Ref. 4701); max. published weight: 5,000.0 g; max. reported age: 13 years (Ref. 54207)";
     $str = "50.0 cm TL (male/unsexed; (Ref. 3506)); 133 cm TL (female); max. published weight: 6,599 g (Ref. 39903); max. published weight: 2,850.0 g; max. reported age: 88 years (Ref. 72468)";
     $str = str_ireplace("unsexed;", "unsexed", $str);
     $parts = self::get_description_parts($str, false); print_r($parts); 
     $a = self::process_size_data($parts); print_r($a); exit;
     */
     self::prepare_data();
     // remove tmp dir
     $this->TEMP_FILE_PATH = str_ireplace("/fishbase", "", $this->TEMP_FILE_PATH);
     // if($this->TEMP_FILE_PATH) shell_exec("rm -fr $this->TEMP_FILE_PATH");
     recursive_rmdir($this->TEMP_FILE_PATH);
     // debug uncomment in real operation
     echo "\n temporary directory removed: " . $this->TEMP_FILE_PATH;
     if ($this->test_run) {
         return $all_taxa;
     }
     //used in testing
 }
Пример #25
0
 function generate_FEIS_data()
 {
     $basenames = array_keys($this->export_basenames);
     $text_path = self::load_zip_contents($this->species_list_export, array('timeout' => 3600, 'download_attempts' => 1, 'delay_in_minutes' => 1), $basenames, ".csv");
     foreach ($this->export_basenames as $type => $uri) {
         self::csv_to_array($text_path[$type], $type, $uri);
     }
     $this->archive_builder->finalize(TRUE);
     // remove temp dir
     $basename = $basenames[0];
     $path = $text_path[$basename];
     $parts = pathinfo($path);
     $parts["dirname"] = str_ireplace($basename, "", $parts["dirname"]);
     recursive_rmdir($parts["dirname"]);
     debug("\n temporary directory removed: " . $parts["dirname"]);
     if ($val = $this->debug) {
         print_r($val);
     }
 }
 function get_all_taxa()
 {
     if (!self::load_zip_contents()) {
         return FALSE;
     }
     self::assign_name_and_id();
     self::process_files("species");
     self::process_genera_files();
     self::add_higher_level_taxa_to_archive();
     $this->create_archive();
     // remove temp dir
     recursive_rmdir($this->TEMP_FILE_PATH);
     echo "\n temporary directory removed: " . $this->TEMP_FILE_PATH;
     // some stats
     echo "\n count not numeric: " . $this->not_numeric_id;
     echo "\n synonyms count: " . $this->syn_count;
     echo "\n wrong data: " . $this->no_rank;
     // print_r($this->debug); //to list the unique habitat values
 }
Пример #27
0
 function clean_media_extension($resource_id, $dwca_file)
 {
     require_library('connectors/INBioAPI');
     $func = new INBioAPI();
     if ($paths = $func->extract_archive_file($dwca_file, "meta.xml")) {
         print_r($paths);
         if ($contents = Functions::get_remote_file($paths['archive_path'] . "media.txt", array('timeout' => 172800))) {
             $contents = str_ireplace('<a title=""', '<a title="', $contents);
             $contents = str_ireplace('"" href=""', '" href="', $contents);
             $contents = str_ireplace('"">', '">', $contents);
             //saving new media.txt
             if (!($WRITE = fopen($paths['archive_path'] . "media.txt", "w"))) {
                 debug(__CLASS__ . ":" . __LINE__ . ": Couldn't open file: " . $paths['archive_path'] . "media.txt");
                 return;
             }
             fwrite($WRITE, $contents);
             fclose($WRITE);
             // remove the archive file e.g. plazi.zip
             $info = pathinfo($dwca_file);
             unlink($paths['archive_path'] . $info["basename"]);
             // creating the archive file
             $command_line = "tar -czf " . CONTENT_RESOURCE_LOCAL_PATH . $resource_id . ".tar.gz --directory=" . $paths['archive_path'] . " .";
             $output = shell_exec($command_line);
             // moving files to /resources/
             recursive_rmdir(CONTENT_RESOURCE_LOCAL_PATH . $resource_id);
             if (!file_exists(CONTENT_RESOURCE_LOCAL_PATH . $resource_id)) {
                 mkdir(CONTENT_RESOURCE_LOCAL_PATH . $resource_id);
             }
             $src = $paths['archive_path'];
             $dst = CONTENT_RESOURCE_LOCAL_PATH . $resource_id . "/";
             $files = glob($paths['archive_path'] . "*.*");
             foreach ($files as $file) {
                 $file_to_go = str_replace($src, $dst, $file);
                 copy($file, $file_to_go);
             }
         }
         // remove temp dir
         recursive_rmdir($paths['archive_path']);
         echo "\n temporary directory removed: " . $paths['archive_path'];
     }
 }
Пример #28
0
 public function __construct()
 {
     $this->mysqli =& $GLOBALS['db_connection'];
     if ($GLOBALS['ENV_NAME'] == 'production' && environment_defined('slave')) {
         $this->mysqli_slave = load_mysql_environment('slave');
     } else {
         $this->mysqli_slave =& $this->mysqli;
     }
     $this->output_directory = DOC_ROOT . "temp/eol_archive_objects/";
     recursive_rmdir($this->output_directory);
     $this->archive_builder = new \eol_schema\ContentArchiveBuilder(array('directory_path' => $this->output_directory));
     $this->load_all_ranks();
     $this->load_all_hierarchies();
     $this->load_all_data_types();
     $this->load_all_mime_types();
     $this->load_all_languages();
     $this->load_all_licenses();
     $this->load_all_curated_object_associations();
     $this->load_all_user_object_associations();
     $this->load_all_resources();
     $this->initital_object_associations = array_merge($this->curated_data_objects_taxa, $this->user_data_objects_taxa);
 }
 function export_gbif_to_eol($params)
 {
     $this->uris = self::get_uris($params, $params["uri_file"]);
     $params["uri_type"] = "citation";
     if ($file = @$params["citation_file"]) {
         $this->citations = self::get_uris($params, $file);
     }
     require_library('connectors/INBioAPI');
     $func = new INBioAPI();
     $paths = $func->extract_archive_file($params["dwca_file"], "meta.xml", array("timeout" => 7200, "expire_seconds" => 0));
     $archive_path = $paths['archive_path'];
     $temp_dir = $paths['temp_dir'];
     $this->harvester = new ContentArchiveReader(NULL, $archive_path);
     if (!@$this->harvester->tables["http://rs.tdwg.org/dwc/terms/occurrence"][0]->fields) {
         echo "\nInvalid archive file. Program will terminate.\n";
         return false;
     }
     if ($params["dataset"] == "GBIF") {
         $params["row_type"] = "http://rs.tdwg.org/dwc/terms/occurrence";
         $params["location"] = "occurrence.txt";
         self::process_row_type($params);
     } elseif ($params["dataset"] == "iDigBio") {
         $params["row_type"] = "http://rs.tdwg.org/dwc/terms/occurrence";
         $params["location"] = "occurrence.txt";
         self::process_row_type($params);
     }
     /* old ways
        self::process_row_type(array("row_type" => 'http://rs.gbif.org/terms/1.0/Multimedia', "location" => "multimedia.txt"));
        self::create_instances_from_taxon_object($harvester->process_row_type('http://rs.tdwg.org/dwc/terms/occurrence'));
        self::get_media_objects($harvester->process_row_type('http://rs.gbif.org/terms/1.0/Multimedia'));
        self::get_objects($harvester->process_row_type('http://eol.org/schema/media/Document'));
        self::get_references($harvester->process_row_type('http://rs.gbif.org/terms/1.0/Reference'));
        */
     $this->archive_builder->finalize(TRUE);
     recursive_rmdir($temp_dir);
     // remove temp dir
     print_r($this->debug);
 }
Пример #30
0
 function export_xml_to_archive($params, $xml_file_YN = false)
 {
     if (!$xml_file_YN) {
         require_library('connectors/INBioAPI');
         $func = new INBioAPI();
         $paths = $func->extract_archive_file($params["eol_xml_file"], $params["filename"], array("timeout" => 7200, "expire_seconds" => 0));
         // "expire_seconds" -- false => won't expire; 0 => expires now //debug
         print_r($paths);
         $params["path"] = $paths["temp_dir"];
         self::convert_xml($params);
         $this->archive_builder->finalize(TRUE);
         recursive_rmdir($paths["temp_dir"]);
         // remove temp dir
     } else {
         $params['path'] = DOC_ROOT . "tmp/";
         $local_xml_file = Functions::save_remote_file_to_local($params['eol_xml_file'], array('file_extension' => "xml", 'cache' => 0, "timeout" => 7200, "download_attempts" => 2, "delay_in_minutes" => 2));
         //debug - cache should be 0 zero in normal operation
         $params['filename'] = pathinfo($local_xml_file, PATHINFO_BASENAME);
         self::convert_xml($params);
         $this->archive_builder->finalize(TRUE);
         unlink($local_xml_file);
     }
 }