コード例 #1
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;
 }
コード例 #2
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";
コード例 #3
0
ファイル: fetch.php プロジェクト: nemein/openpsa
 /**
  * Parses rel-tag links in article content and tags the object based on them
  *
  * @param midgard_article $article Imported article
  * @param Array $item Feed item as provided by MagpieRSS
  * @return boolean
  */
 function parse_tags($article, $item, $field = 'content')
 {
     $html_tags = org_openpsa_httplib_helpers::get_anchor_values($article->{$field}, 'tag');
     $tags = array();
     if (count($html_tags) > 0) {
         foreach ($html_tags as $html_tag) {
             if (!$html_tag['value']) {
                 // No actual tag specified, skip
                 continue;
             }
             $tag = strtolower(strip_tags($html_tag['value']));
             $tags[$tag] = $html_tag['href'];
         }
         midcom::get('componentloader')->load_library('net.nemein.tag');
         return net_nemein_tag_handler::tag_object($article, $tags);
     }
     return true;
 }
コード例 #4
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;
 }