コード例 #1
0
ファイル: fetch.php プロジェクト: nemein/openpsa
 /**
  * Imports an item as an event
  */
 private function import_event($item)
 {
     // Check that we're trying to import item suitable to be an event
     if (!isset($item['xcal']) && !isset($item['gd']['when@'])) {
         // Not an event
         return false;
     }
     // Get start and end times
     $start = null;
     $end = null;
     if (isset($item['xcal']['dtstart'])) {
         // xCal RSS feed, for example Upcoming or Last.fm
         $start = strtotime($item['xcal']['dtstart']);
     } elseif (isset($item['gd']['when@starttime'])) {
         // gData Atom feed, for example Dopplr
         $start = strtotime($item['gd']['when@starttime']);
     }
     if (isset($item['xcal']['dtend'])) {
         $end = strtotime($item['xcal']['dtend']);
     } elseif (isset($item['gd']['when@starttime'])) {
         $end = strtotime($item['gd']['when@endtime']);
     }
     if (!$start || !$end) {
         return false;
     }
     if (!$this->_datamanager) {
         $schemadb = midcom_helper_datamanager2_schema::load_database($this->_node_config->get('schemadb'));
         $this->_datamanager = new midcom_helper_datamanager2_datamanager($schemadb);
     }
     // TODO: Move to real geocoded stuff
     $location_parts = array();
     if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-venue-name'])) {
         $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-venue-name'];
     }
     if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-street'])) {
         $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-street'];
     }
     if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-city'])) {
         $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-city'];
     }
     if (isset($item['gd']['where@valuestring'])) {
         $wherevalues = explode(' ', $item['gd']['where@valuestring']);
         foreach ($wherevalues as $val) {
             $location_parts[] = $val;
         }
     }
     $qb = net_nemein_calendar_event_dba::new_query_builder();
     $qb->add_constraint('node', '=', $this->_feed->node);
     $qb->add_constraint('extra', '=', md5($item['guid']));
     $events = $qb->execute();
     if (count($events) > 0) {
         // This item has been imported already earlier. Update
         $event = $events[0];
         $event->_activitystream_verb = 'http://community-equity.org/schema/1.0/clone';
         $event->_rcs_message = sprintf(midcom::get('i18n')->get_string('%s was imported from %s', 'net.nemein.rss'), $event->title, $this->_feed->title);
         $event->allow_name_catenate = true;
         if (empty($event->name)) {
             $resolver = new midcom_helper_reflector_nameresolver($event);
             // To prevent validation errors in case the auto-catenate is not allowed in the urlname datatype
             $event->name = $resolver->generate_unique_name();
         }
     } else {
         $node = new midcom_db_topic($this->_feed->node);
         $node_lang_code = $node->get_parameter('net.nemein.calendar', 'language');
         // This is a new item
         $event = new net_nemein_calendar_event_dba();
         $event->start = $start;
         $event->end = $end;
         $event->extra = md5($item['guid']);
         $event->node = $this->_feed->node;
         if ($node->get_parameter('net.nemein.calendar', 'symlink_topic') != '') {
             try {
                 $symlink_topic = new midcom_db_topic($node->get_parameter('net.nemein.calendar', 'symlink_topic'));
                 $event->node = $symlink_topic->id;
             } catch (midcom_error $e) {
                 $e->log();
             }
         }
         if ($node_lang_code != '') {
             $lang_id = midcom::get('i18n')->code_to_id($node_lang_code);
             $event->lang = $lang_id;
         }
         $event->allow_name_catenate = true;
         $event->title = (string) $item['title'];
         $event->_activitystream_verb = 'http://community-equity.org/schema/1.0/clone';
         $event->_rcs_message = sprintf(midcom::get('i18n')->get_string('%s was imported from %s', 'net.nemein.rss'), $event->title, $this->_feed->title);
         $resolver = new midcom_helper_reflector_nameresolver($event);
         $event->name = $resolver->generate_unique_name();
         if (!$event->create()) {
             return false;
         }
     }
     $this->_datamanager->autoset_storage($event);
     $this->_datamanager->types['start']->value = new DateTime(strftime('%Y-%m-%d %H:%M:%S', $start));
     $this->_datamanager->types['end']->value = new DateTime(strftime('%Y-%m-%d %H:%M:%S', $end));
     if (is_a($this->_datamanager->types['location'], 'midcom_helper_datamanager2_type_position')) {
         // Position type, give all values we got, assume order "Street, City, Country"
         $location_parts = array_reverse($location_parts);
         if (count($location_parts) > 0) {
             $country = org_routamc_positioning_country_dba::get_by_name($location_parts[0]);
             if ($country && $country->code) {
                 $this->_datamanager->types['location']->location->county = $country->code;
             }
         }
         if (count($location_parts) > 1) {
             $city = org_routamc_positioning_city_dba::get_by_name($location_parts[1]);
             if ($city && $city->id) {
                 $this->_datamanager->types['location']->location->city = $city->id;
             }
         }
         if (count($location_parts) > 2) {
             $this->_datamanager->types['location']->location->street = $location_parts[2];
         }
         if (isset($item['gml'])) {
             $gml_parts = explode(' ', $item['gml']['where_point_pos']);
             if (count($gml_parts) == 2) {
                 $this->_datamanager->types['location']->location->latitude = (double) $gml_parts[0];
                 $this->_datamanager->types['location']->location->longitude = (double) $gml_parts[1];
             }
         }
     } else {
         // Just give the location string we got
         $this->_datamanager->types['location']->value = implode(', ', $location_parts);
     }
     foreach ($item as $key => $value) {
         if (isset($this->_datamanager->types[$key])) {
             $this->_datamanager->types[$key]->value = $value;
         }
     }
     if (!$this->_datamanager->save()) {
         return false;
     }
     // This should be unnecessary but left in place just to be sure
     if (strlen($this->_datamanager->storage->object->name) == 0) {
         // Generate something to avoid empty "/" links in case of failures
         $this->_datamanager->storage->object->name = time();
         $this->_datamanager->storage->object->update();
     }
     $this->parse_tags($event, $item, 'description');
     $this->parse_parameters($event, $item);
     return $event->guid;
 }
コード例 #2
0
ファイル: widget.php プロジェクト: nemein/openpsa
 function _get_city_by_name($city_name, $results = array())
 {
     if (empty($city_name)) {
         return 0;
     }
     $city_id = 0;
     $city = org_routamc_positioning_city_dba::get_by_name($city_name);
     if ($city && $city->id) {
         $city_id = $city->id;
     } else {
         if (!empty($results)) {
             $city = new org_routamc_positioning_city_dba();
             $city->city = $city_name;
             if (isset($results["{$this->_element_id}_input_place_country"]) && $results["{$this->_element_id}_input_place_country"]) {
                 $city->country = $results["{$this->_element_id}_input_place_country"];
             }
             if (isset($results["{$this->_element_id}_input_place_region"])) {
                 $city->region = $results["{$this->_element_id}_input_place_region"];
             }
             if (isset($results["{$this->_element_id}_input_coordinates_latitude"]) && $results["{$this->_element_id}_input_coordinates_latitude"] != '') {
                 $city->latitude = $results["{$this->_element_id}_input_coordinates_latitude"];
             }
             if (isset($results["{$this->_element_id}_input_coordinates_longitude"]) && $results["{$this->_element_id}_input_coordinates_longitude"] != '') {
                 $city->longitude = $results["{$this->_element_id}_input_coordinates_longitude"];
             }
             if (!$city->create()) {
                 debug_add("Cannot save new city '{$city_name}'");
             }
             $city_id = $city->id;
         }
     }
     return $city_id;
 }
コード例 #3
0
ファイル: import-countries.php プロジェクト: nemein/openpsa
<?php

midcom::get('auth')->require_admin_user();
$http_request = new org_openpsa_httplib();
$xml = $http_request->get('http://ws.geonames.org/countryInfo?lang=' . midcom::get('i18n')->get_current_language());
$simplexml = simplexml_load_string($xml);
foreach ($simplexml->country as $id => $countryinfo) {
    echo "<br />Importing {$countryinfo->countryName}...\n";
    $country = new org_routamc_positioning_country_dba();
    $country->code = (string) $countryinfo->countryCode;
    $country->name = (string) $countryinfo->countryName;
    $country->codenumeric = (string) $countryinfo->isoNumeric;
    $country->code3 = (string) $countryinfo->isoAlpha3;
    $country->fips = (string) $countryinfo->fipsCode;
    $country->continent = (string) $countryinfo->continent;
    $country->area = (double) $countryinfo->areaInSqKm;
    $country->population = (int) $countryinfo->population;
    $country->currency = (string) $countryinfo->currencyCode;
    $country->bboxwest = (double) $countryinfo->bBoxWest;
    $country->bboxnorth = (double) $countryinfo->bBoxNorth;
    $country->bboxeast = (double) $countryinfo->bBoxEast;
    $country->bboxsouth = (double) $countryinfo->bBoxSouth;
    $capital = org_routamc_positioning_city_dba::get_by_name((string) $countryinfo->capital);
    if ($capital) {
        $country->capital = $capital->id;
    }
    $country->create();
    echo midcom_connection::get_error_string();
}