예제 #1
0
// .3 seconds wait time
include_once dirname(__FILE__) . "/../../config/environment.php";
$resource_id = 15;
if (!Functions::can_this_connector_run($resource_id)) {
    return;
}
require_library('FlickrAPI');
$GLOBALS['ENV_DEBUG'] = false;
$auth_token = NULL;
if (FlickrAPI::valid_auth_token(FLICKR_AUTH_TOKEN)) {
    $auth_token = FLICKR_AUTH_TOKEN;
}
// create new _temp file
if (!($resource_file = Functions::file_open(CONTENT_RESOURCE_LOCAL_PATH . $resource_id . "_temp.xml", "w+"))) {
    return;
}
// start the resource file with the XML header
fwrite($resource_file, \SchemaDocument::xml_header());
// query Flickr and write results to file
FlickrAPI::get_all_eol_photos($auth_token, $resource_file);
// write the resource footer
fwrite($resource_file, \SchemaDocument::xml_footer());
fclose($resource_file);
// cache the previous version and make this new version the current version
@unlink(CONTENT_RESOURCE_LOCAL_PATH . $resource_id . "_previous.xml");
Functions::file_rename(CONTENT_RESOURCE_LOCAL_PATH . $resource_id . ".xml", CONTENT_RESOURCE_LOCAL_PATH . $resource_id . "_previous.xml");
Functions::file_rename(CONTENT_RESOURCE_LOCAL_PATH . $resource_id . "_temp.xml", CONTENT_RESOURCE_LOCAL_PATH . $resource_id . ".xml");
// set Flickr to force harvest
if (filesize(CONTENT_RESOURCE_LOCAL_PATH . $resource_id . ".xml") > 600) {
    Functions::set_resource_status_to_force_harvest($resource_id);
}
예제 #2
0
 function prepare_resource()
 {
     if (!($resource_file = fopen(CONTENT_RESOURCE_LOCAL_PATH . $this->resource_id . "_temp.xml", "w+"))) {
         debug(__CLASS__ . ":" . __LINE__ . ": Couldn't open file: " . CONTENT_RESOURCE_LOCAL_PATH . $this->resource_id . "_temp.xml");
         return;
     }
     fwrite($resource_file, \SchemaDocument::xml_header());
     $language_iso_codes = self::language_iso_codes();
     $avibaseids_added = array();
     foreach ($this->names_in_families as $taxon_name => $metadata) {
         $taxon_parameters = array();
         $taxon_parameters['identifier'] = $metadata['avibaseid'];
         if (isset($avibaseids_added[$metadata['avibaseid']])) {
             continue;
         }
         $avibaseids_added[$metadata['avibaseid']] = 1;
         $taxon_parameters['kingdom'] = "Animalia";
         $taxon_parameters['phylum'] = "Chordata";
         $taxon_parameters['class'] = "Aves";
         $taxon_parameters['order'] = @$this->family_orders[$metadata['family']];
         $taxon_parameters['family'] = @$metadata['family'];
         $taxon_parameters['scientificName'] = $metadata['taxon_name'];
         $taxon_parameters['source'] = self::AVIBASE_SOURCE_URL . $metadata['avibaseid'];
         if (preg_match("/^([a-z][^ ]+) /i", $metadata['taxon_name'], $arr)) {
             $taxon_parameters['genus'] = $arr[1];
         }
         if (!$taxon_parameters['scientificName']) {
             continue;
         }
         $taxon_parameters['common_names'] = array();
         if (isset($metadata['common_names'])) {
             foreach ($metadata['common_names'] as $language => $common_names) {
                 if ($language_iso_code = @$language_iso_codes[$language]) {
                     foreach ($common_names as $common_name => $value) {
                         $taxon_parameters['commonNames'][] = new \SchemaCommonName(array("name" => $common_name, "language" => $language_iso_code));
                     }
                 } else {
                     debug("No iso code for: {$language} \n");
                 }
             }
         }
         $taxon_parameters['synonyms'] = array();
         if (isset($metadata['synonyms'])) {
             foreach ($metadata['synonyms'] as $synonym => $value) {
                 if ($synonym == $metadata['taxon_name']) {
                     continue;
                 }
                 $taxon_parameters['synonyms'][] = new \SchemaSynonym(array("synonym" => $synonym, "relationship" => 'synonym'));
             }
         }
         $taxon = new \SchemaTaxon($taxon_parameters);
         fwrite($resource_file, $taxon->__toXML());
     }
     fwrite($resource_file, \SchemaDocument::xml_footer());
     fclose($resource_file);
     // cache the previous version and make this new version the current version
     @unlink(CONTENT_RESOURCE_LOCAL_PATH . $this->resource_id . "_previous.xml");
     @rename(CONTENT_RESOURCE_LOCAL_PATH . $this->resource_id . ".xml", CONTENT_RESOURCE_LOCAL_PATH . $this->resource_id . "_previous.xml");
     rename(CONTENT_RESOURCE_LOCAL_PATH . $this->resource_id . "_temp.xml", CONTENT_RESOURCE_LOCAL_PATH . $this->resource_id . ".xml");
     // returning the last taxon
     return $taxon;
 }