예제 #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
            $left_content = $topic->get_parameter('midcom.helper.datamanager2', 'left_content');
            if ($topic->up == 0) {
                break;
            }
        }
    }
}
$topic = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_CONTENTTOPIC);
$left_navigation_hide = $topic->get_parameter('midcom.helper.datamanager2', 'left_navigation_hide');
$left_navigation_show = true;
if ($left_navigation_hide == 1) {
    $left_navigation_show = false;
} elseif ($left_navigation_hide != -1) {
    while (true) {
        $topic = new midcom_db_topic($topic->up);
        if ($topic->get_parameter('midcom.helper.datamanager2', 'left_navigation_hide')) {
            $left_navigation_show = false;
            break;
        }
        if ($topic->up == 0) {
            $left_navigation_show = true;
            break;
        }
    }
}
if ($left_navigation_show) {
    ?>
        <div id="left_top">
            <span class="left_content_top">&nbsp;</span>
            <div id="navigation_content">
                <(navi-content)>