コード例 #1
0
ファイル: interfaces.php プロジェクト: nemein/opengov
 function _on_watched_dba_update($object)
 {
     // Note: the API key has to be defined in /etc/midgard/midcom.conf
     $apikey = $GLOBALS['midcom_config']['qaiku_apikey'];
     $_MIDCOM->load_library('org.openpsa.httplib');
     $message = array('channel' => 'opendata', 'source' => 'opengov.fi', 'lang' => 'fi', 'status' => '', 'external_url' => '');
     if ($object->get_parameter('fi.opengov.datacatalog', 'qaiku_id')) {
         // This is already on Qaiku, skip
         return;
     }
     if ($object instanceof midcom_baseclasses_database_article) {
         // Check that the article is a visible one
         $topic = new midcom_db_topic($object->topic);
         if ($topic->component != 'net.nehmer.blog') {
             return;
         }
         $message['status'] = "[blog] {$object->title}";
     } elseif ($object instanceof fi_opengov_datacatalog_dataset_dba) {
         // Check that the dataset is a published one
         if (!fi_opengov_datacatalog_dataset_dba::matching_license_type($object->guid, 'free')) {
             // We don't publicize closed datasets
             return;
         }
         $message['status'] = "[dataset] {$object->title}";
     } else {
         return;
     }
     $message['external_url'] = $_MIDCOM->permalinks->resolve_permalink($object->guid);
     $http = new org_openpsa_httplib();
     $json = $http->post("http://www.qaiku.com/api/statuses/update.json?apikey={$apikey}", $message);
     $qaiku = json_decode($json);
     if (is_object($qaiku) && isset($qaiku->id)) {
         $object->set_parameter('fi.opengov.datacatalog', 'qaiku_id', $qaiku->id);
     }
 }
コード例 #2
0
ファイル: geoplugin.php プロジェクト: nemein/openpsa
 /**
  * Try geocoding an IP address.
  *
  * @param array $location Parameters to geocode with, conforms to XEP-0080
  * @return org_routamc_positioning_spot containing geocoded information
  */
 public function geocode(array $location)
 {
     if (!isset($location['ip'])) {
         throw new InvalidArgumentException("No IP address provided");
     }
     // Check that we have a valid IP
     if (!filter_var($location['ip'], FILTER_VALIDATE_IP)) {
         throw new InvalidArgumentException("Invalid IP address provided");
     }
     $http_request = new org_openpsa_httplib();
     $json = $http_request->get("http://www.geoplugin.net/json.gp?ip={$location['ip']}");
     if (!$json) {
         throw new RuntimeException("GeoPlugin did not return data");
     }
     // Remove the geoPlugin() callback
     $json = substr($json, 10, -1);
     $geocoded = json_decode($json);
     if (!$geocoded->geoplugin_latitude || !$geocoded->geoplugin_longitude) {
         throw new RuntimeException("GeoPlugin did not return coordinates for IP");
     }
     $location = array('latitude' => (double) $geocoded->geoplugin_latitude, 'longitude' => (double) $geocoded->geoplugin_longitude);
     $location['accuracy'] = 80;
     $location['source'] = 'geoplugin';
     if (isset($geocoded->geoplugin_countryCode)) {
         $location['country'] = $geocoded->geoplugin_countryCode;
         $location['accuracy'] = 60;
     }
     if (isset($geocoded->geoplugin_city)) {
         $location['city'] = $geocoded->geoplugin_city;
         $location['accuracy'] = 30;
     }
     return $location;
 }
コード例 #3
0
ファイル: html.php プロジェクト: nemein/openpsa
 private function _fetch_icbm_position($url)
 {
     $client = new org_openpsa_httplib();
     $html = $client->get($url);
     $icbm = org_openpsa_httplib_helpers::get_meta_value($html, 'icbm');
     if (strstr($icbm, ',')) {
         $icbm_parts = explode(',', $icbm);
         if (count($icbm_parts) == 2) {
             $latitude = (double) $icbm_parts[0];
             if ($latitude > 90 || $latitude < -90) {
                 // This is no earth coordinate, my friend
                 $this->error = 'POSITIONING_HTML_INCORRECT_LATITUDE';
                 return null;
             }
             $longitude = (double) $icbm_parts[1];
             if ($longitude > 180 || $longitude < -180) {
                 // This is no earth coordinate, my friend
                 $this->error = 'POSITIONING_HTML_INCORRECT_LONGITUDE';
                 return null;
             }
             $position = array('latitude' => $latitude, 'longitude' => $longitude);
             return $position;
         }
     }
     $this->error = 'POSITIONING_HTML_CONNECTION_NORESULTS';
     return null;
 }
コード例 #4
0
ファイル: qaiku.php プロジェクト: nemein/openpsa
 private function _fetch_qaiku_positions($qaiku_apikey)
 {
     $positions = array();
     $client = new org_openpsa_httplib();
     $start_date = urlencode('2009-11-26 09:00:00');
     $json = $client->get("http://www.qaiku.com/api/statuses/user_timeline.json?apikey={$qaiku_apikey}&since={$start_date}");
     $statuses = json_decode($json);
     foreach ($statuses as $status) {
         if (!isset($status->geo->coordinates) || empty($status->geo->coordinates)) {
             // No location, skip
             continue;
         }
         $positions[] = array('qaiku' => $status->id, 'latitude' => (double) $status->geo->coordinates[1], 'longitude' => (double) $status->geo->coordinates[0], 'date' => strtotime($status->created_at));
     }
     return $positions;
 }
コード例 #5
0
ファイル: plazes.php プロジェクト: nemein/openpsa
 private function _fetch_plazes_positions($plazes_username, $plazes_password)
 {
     $positions = array();
     $client = new org_openpsa_httplib();
     $xml = $client->get("http://plazes.com/users/{$plazes_username}/past_activities.xml", 'User-agent: device: midgard', $plazes_username, $plazes_password);
     $simplexml = simplexml_load_string($xml);
     if (!isset($simplexml->activity)) {
         return null;
     }
     foreach ($simplexml->activity as $activity) {
         if (!isset($activity->plaze) || !isset($activity->plaze->latitude)) {
             // No location, skip
             continue;
         }
         $positions[] = array('plaze' => (int) $activity->plaze->id, 'latitude' => (double) $activity->plaze->latitude, 'longitude' => (double) $activity->plaze->longitude, 'country' => (string) $activity->plaze->country_code, 'city' => (string) $activity->plaze->city, 'date' => strtotime((string) $activity->scheduled_at));
     }
     return $positions;
 }
コード例 #6
0
ファイル: instamapper.php プロジェクト: nemein/openpsa
 private function _fetch_instamapper_positions($api_key)
 {
     $url = "http://www.instamapper.com/api?action=getPositions&key={$api_key}&num=10";
     $client = new org_openpsa_httplib();
     $csv = $client->get($url);
     if (!$csv) {
         $this->error = 'POSITIONING_INSTAMAPPER_CONNECTION_NORESULTS';
         return null;
     }
     $lines = explode("\n", $csv);
     $positions = array();
     foreach ($lines as $line) {
         if (strpos($line, ',') === false) {
             continue;
         }
         $position_data = explode(',', $line);
         $positions[] = array('device' => $position_data[0], 'device_label' => $position_data[1], 'time' => date('c', $position_data[2]), 'latitude' => $position_data[3], 'longitude' => $position_data[4], 'altitude' => (int) $position_data[5], 'speed' => $position_data[6], 'bearing' => $position_data[7]);
     }
     // Return latest first
     return array_reverse($positions);
 }
コード例 #7
0
ファイル: tiny.php プロジェクト: nemein/openpsa
 /**
  * Empty default implementation, this calls won't do much.
  *
  * @param Array $coordinates Contains latitude and longitude values
  * @return Array containing geocoded information
  */
 function reverse_geocode($coordinates)
 {
     if (!isset($coordinates['latitude']) && !isset($coordinates['longitude'])) {
         $this->error = 'POSITIONING_MISSING_ATTRIBUTES';
         return null;
     }
     $lat_str = str_replace(',', '.', (string) $coordinates['latitude']);
     $lon_str = str_replace(',', '.', (string) $coordinates['longitude']);
     $url = "http://tinygeocoder.com/create-api.php?g={$lat_str},{$lon_str}";
     $http_request = new org_openpsa_httplib();
     $response = $http_request->get($url);
     if (empty($response)) {
         $this->error = 'POSITIONING_SERVICE_NOT_AVAILABLE';
         return null;
     }
     // check for errors
     if (strpos($response, "couldn't get") !== false) {
         $this->error = 'POSITIONING_DETAILS_NOT_FOUND';
         return null;
     }
     $position = array();
     // Walk the reponse parts in reverse order putting to fields as specified by the response_fields below
     $response_parts = explode(',', $response);
     $response_parts = array_reverse($response_parts);
     $response_fields = array('country', 'postalcode', 'city', 'street');
     while (count($response_parts) > 0) {
         if (count($response_fields) > 0) {
             $field = array_pop($response_fields);
         }
         if (!isset($position[$field])) {
             $position[$field] = array_pop($response_parts);
         } else {
             //special case got more fields in response than we know how to handle, add them to the last field
             $position[$field] .= ' ' . array_pop($response_parts);
         }
     }
     return array($position);
 }
コード例 #8
0
ファイル: geonames.php プロジェクト: nemein/openpsa
 /**
  *
  * @param Array $coordinates Contains latitude and longitude values
  * @return Array containing geocoded information
  */
 function reverse_geocode($coordinates, $options = array())
 {
     $results = array();
     $parameters = array('radius' => 10, 'maxRows' => 20, 'style' => 'FULL');
     if (!empty($options)) {
         foreach ($options as $key => $value) {
             if (isset($parameters[$key])) {
                 $parameters[$key] = $value;
             }
         }
     }
     if (!isset($coordinates['latitude']) && !isset($coordinates['longitude'])) {
         $this->error = 'POSITIONING_MISSING_ATTRIBUTES';
         return null;
     }
     $params = array();
     $params[] = 'lat=' . urlencode($coordinates['latitude']);
     $params[] = 'lng=' . urlencode($coordinates['longitude']);
     foreach ($parameters as $key => $value) {
         if (!is_null($value)) {
             $params[] = "{$key}=" . urlencode($value);
         }
     }
     $http_request = new org_openpsa_httplib();
     $url = 'http://ws.geonames.org/findNearbyPlaceName?' . implode('&', $params);
     $response = $http_request->get($url);
     $simplexml = simplexml_load_string($response);
     if (!isset($simplexml->geoname) || count($simplexml->geoname) == 0) {
         $this->error = 'POSITIONING_DETAILS_NOT_FOUND';
         if (isset($simplexml->status)) {
             $constant_name = strtoupper(str_replace(" ", "_", $simplexml->status));
             $this->error = $constant_name;
         }
         return null;
     }
     for ($i = 0; $i < $parameters['maxRows']; $i++) {
         if (!isset($simplexml->geoname[$i])) {
             break;
         }
         $entry = $simplexml->geoname[$i];
         $entry_coordinates = array('latitude' => (double) $entry->lat, 'longitude' => (double) $entry->lng);
         $meters = round(org_routamc_positioning_utils::get_distance($coordinates, $entry_coordinates) * 1000);
         $entry_meters = round((double) $entry->distance * 1000);
         if ($entry_meters < $meters) {
             $meters = $entry_meters;
         }
         $position = array();
         $position['latitude'] = (double) $entry->lat;
         $position['longitude'] = (double) $entry->lng;
         $position['distance'] = array('meters' => $meters, 'bearing' => org_routamc_positioning_utils::get_bearing($coordinates, $entry_coordinates));
         $position['city'] = (string) $entry->name;
         $position['region'] = (string) $entry->adminName2;
         $position['country'] = (string) $entry->countryCode;
         $position['postalcode'] = (string) $entry->postalcode;
         $position['alternate_names'] = (string) $entry->alternateNames;
         $position['accuracy'] = ORG_ROUTAMC_POSITIONING_ACCURACY_GPS;
         $results[] = $position;
     }
     return $results;
 }
コード例 #9
0
ファイル: reindex.php プロジェクト: nemein/openpsa
$indexer = midcom::get('indexer');
// Use this to check that indexer is online (and hope the root topic isn't a gigantic wiki)
$root_node = $nap->get_node($nodeid);
$existing_documents = $indexer->query("__TOPIC_GUID:{$root_node[MIDCOM_NAV_OBJECT]->guid}");
if ($existing_documents === false) {
    $msg = "Query '__TOPIC_GUID:{$root_node[MIDCOM_NAV_OBJECT]->guid}' returned false, indicating problem with indexer";
    throw new midcom_error($msg);
}
unset($existing_documents, $root_node);
// Disable ob
while (@ob_end_flush()) {
}
echo "<pre>\n";
debug_dump_mem("Initial Memory Usage");
$reindex_topic_uri = str_replace('midcom-exec-midcom/reindex.php', 'midcom-exec-midcom/reindex_singlenode.php', $current_uri);
$http_client = new org_openpsa_httplib();
$http_client->set_param('timeout', 300);
if (isset($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && !empty($_SERVER['PHP_AUTH_PW'])) {
    $http_client->basicauth['user'] = $_SERVER['PHP_AUTH_USER'];
    $http_client->basicauth['password'] = $_SERVER['PHP_AUTH_PW'];
}
while (!is_null($nodeid)) {
    // Update script execution time
    // This should suffice for really large topics as well.
    set_time_limit(5000);
    // Reindex the node...
    $node = $nap->get_node($nodeid);
    echo "Processing node #{$nodeid}, {$node[MIDCOM_NAV_FULLURL]}: ";
    flush();
    //pass the node-id & the language
    $post_variables = array('nodeid' => $nodeid, 'language' => $language);
コード例 #10
0
ファイル: test_post.php プロジェクト: nemein/openpsa
if (!isset($_REQUEST['url'])) {
    ?>
<form method="post">
    <h2>address and data</h2>
    URL: <input name="url" value="" /><br/>
    Key => Value array (for eval())<br/>
    <textarea name="variables" rows=10 cols=40>'key' => 'value',
    </textarea>
    <h2>basic auth (optional)</h2>
    Username: <input name="username" value="" /><br/>
    Password: <input name="password" value="" /><br/>
    <input type="submit" value="post" />
</form>
<?php 
} else {
    $client = new org_openpsa_httplib();
    eval("\$vars = array({$_REQUEST['variables']});");
    if (isset($_REQUEST['username']) && !empty($_REQUEST['username']) && isset($_REQUEST['password']) && !empty($_REQUEST['password'])) {
        $client->basicauth['user'] = $_REQUEST['username'];
        $client->basicauth['password'] = $_REQUEST['password'];
    }
    if (!isset($vars)) {
        $display = "<h1>Error</h1>\n<p>Could not determine variables to post</p>";
    } else {
        $response = $client->post($_REQUEST['url'], $vars);
        if (!$response) {
            $display = "<h1>Error</h1>\n<p>Client error: {$client->error}</p>";
        } else {
            $display = "<h1>Success</h1>\n{$response}";
        }
    }
コード例 #11
0
ファイル: test.php プロジェクト: nemein/openpsa
<?php

$url = 'http://bergie.iki.fi/blog/';
$meta_name = 'icbm';
$link_relation = 'alternate';
$anchor_relation = 'tag';
$client = new org_openpsa_httplib();
$html = $client->get($url);
$meta_value = org_openpsa_httplib_helpers::get_meta_value($html, $meta_name);
$link_values = org_openpsa_httplib_helpers::get_link_values($html, $link_relation);
$anchor_values = org_openpsa_httplib_helpers::get_anchor_values($html, $anchor_relation);
echo "<p>\n";
echo "  url '{$url}'<br>\n";
echo "  value for meta tag {$meta_name}: {$meta_value}<br>\n";
echo "  values for link rel '{$link_relation}'<pre>\n";
print_r($link_values);
echo "  </pre>\n";
echo "  values for anchor rel '{$anchor_relation}'<pre>\n";
print_r($anchor_values);
echo "  </pre>\n";
echo "</p>\n";
コード例 #12
0
ファイル: fetch.php プロジェクト: nemein/openpsa
 /**
  * Normalizes items provided by different feed formats.
  *
  * @param Array $item Feed item as provided by MagpieRSS
  * @param Array Normalized feed item
  */
 function normalize_item($item)
 {
     if (!is_array($item)) {
         // Broken item, skip
         return false;
     }
     // Fix missing titles
     if (!isset($item['title']) || !$item['title']) {
         $item['title'] = midcom::get('i18n')->get_string('untitled', 'net.nemein.rss');
         $item_date = $item['date_timestamp'];
         // Check if this item is newer than the others
         if (isset($this)) {
             if ($item_date > $this->_feed_updated) {
                 $this->_feed_updated = $item_date;
             }
         }
         if (isset($item['description'])) {
             // Use 20 first characters from the description as title
             $item['title'] = substr(strip_tags($item['description']), 0, 20) . '...';
         } elseif ($item_date) {
             // Use publication date as title
             $item['title'] = strftime('%x', $item_date);
         }
     }
     // Fix missing links
     if (!isset($item['link']) || !$item['link']) {
         $item['link'] = '';
         if (isset($item['guid'])) {
             $item['link'] = $item['guid'];
         }
     }
     if (!array_key_exists('link', $item)) {
         // No link or GUID defined
         // TODO: Generate a "link" using channel URL
         $item['link'] = '';
     }
     // Fix missing GUIDs
     if (!isset($item['guid']) || !$item['guid']) {
         if (isset($item['link'])) {
             $item['guid'] = $item['link'];
         }
     }
     if (!isset($item['description']) || !$item['description']) {
         // Ensure description is always set
         $item['description'] = '';
     }
     if (isset($item['content']) && is_array($item['content']) && isset($item['content']['encoded'])) {
         // Some RSS feeds use "content:encoded" for storing HTML-formatted full item content,
         // so we prefer this instead of simpler description
         $item['description'] = $item['content']['encoded'];
     }
     if ($item['description'] == '') {
         // Empty description, fallbacks for some feed formats
         if (isset($item['dc']) && isset($item['dc']['description'])) {
             $item['description'] = $item['dc']['description'];
         } elseif (isset($item['atom_content'])) {
             // Atom 1.0 feeds store content in the atom_content field
             $item['description'] = $item['atom_content'];
         } elseif (strpos($item['link'], 'cws.huginonline.com') !== false) {
             // Deal with the funky RSS format provided by Hugin Online
             // Link points to actual news item in hexML format
             $http_client = new org_openpsa_httplib();
             $news_xml = $http_client->get($item['link']);
             $news = simplexml_load_string($news_xml);
             if (isset($news->body->press_releases->press_release->main)) {
                 $item['description'] = (string) $news->body->press_releases->press_release->main;
             }
         }
     }
     return $item;
 }
コード例 #13
0
ファイル: import-aerodromes.php プロジェクト: nemein/openpsa
<?php

midcom::get('auth')->require_admin_user();
midcom::get()->disable_limits();
$http_request = new org_openpsa_httplib();
$csv = $http_request->get('http://weather.gladstonefamily.net/cgi-bin/location.pl/pjsg_all_location.csv?csv=1');
$csv = str_replace('"', '', $csv);
$lines = explode("\n", $csv);
foreach ($lines as $line) {
    $aerodromeinfo = explode(',', $line);
    // Skip the non-ICAO ones
    if (empty($aerodromeinfo[0]) || strlen($aerodromeinfo[0]) != 4) {
        continue;
    }
    // Skip non-WMO ones
    if (empty($aerodromeinfo[1])) {
        continue;
    }
    echo "<br />Importing {$aerodromeinfo[0]} {$aerodromeinfo[2]}...\n";
    $aerodrome = new org_routamc_positioning_aerodrome_dba();
    $aerodrome->icao = $aerodromeinfo[0];
    $aerodrome->wmo = $aerodromeinfo[1];
    $aerodrome->name = $aerodromeinfo[2];
    $aerodrome->country = substr($aerodromeinfo[4], 0, 2);
    $aerodrome->latitude = (double) $aerodromeinfo[5];
    $aerodrome->longitude = (double) $aerodromeinfo[6];
    $aerodrome->altitude = (int) $aerodromeinfo[7];
    $aerodrome->create();
    echo midcom_connection::get_error_string();
    flush();
}
コード例 #14
0
ファイル: interfaces.php プロジェクト: nemein/openpsa
 private function _get_data_from_url($url)
 {
     //We have to hang on to the hKit object, because its configuration is done by require_once
     //and will thus only work for the first instantiation...
     static $hkit;
     if (is_null($hkit)) {
         require_once MIDCOM_ROOT . '/external/hkit.php';
         $hkit = new hKit();
     }
     $data = array();
     // TODO: Error handling
     $client = new org_openpsa_httplib();
     $html = $client->get($url);
     // Check for ICBM coordinate information
     $icbm = org_openpsa_httplib_helpers::get_meta_value($html, 'icbm');
     if ($icbm) {
         $data['icbm'] = $icbm;
     }
     // Check for RSS feed
     $rss_url = org_openpsa_httplib_helpers::get_link_values($html, 'alternate');
     if ($rss_url && count($rss_url) > 0) {
         $data['rss_url'] = $rss_url[0]['href'];
         // We have a feed URL, but we should check if it is GeoRSS as well
         midcom::get('componentloader')->load_library('net.nemein.rss');
         $rss_content = net_nemein_rss_fetch::raw_fetch($data['rss_url']);
         if (isset($rss_content->items) && count($rss_content->items) > 0) {
             if (array_key_exists('georss', $rss_content->items[0]) || array_key_exists('geo', $rss_content->items[0])) {
                 // This is a GeoRSS feed
                 $data['georss_url'] = $data['rss_url'];
             }
         }
     }
     $hcards = @$hkit->getByURL('hcard', $url);
     if (is_array($hcards) && count($hcards) > 0) {
         // We have found hCard data here
         $data['hcards'] = $hcards;
     }
     return $data;
 }
コード例 #15
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();
}