Permalink
Browse files

Merge branch 'master' of git.nexgenta.com:projects/eregansu

  • Loading branch information...
2 parents acb22f0 + b869716 commit 93cdf8a9ee8ff5a7621056385c52a4d1d17669c0 @nevali nevali committed Apr 8, 2012
Showing with 36 additions and 3 deletions.
  1. +28 −3 lib/rdf.php
  2. +8 −0 lib/rdf/redland.php
View
@@ -152,11 +152,29 @@ public static function documentFromURL($location, $curl = null)
{
$location = strval($location);
$ct = null;
- $doc = self::fetch($location, $ct, 'application/rdf+xml', $curl);
+ if(defined('EREGANSU_DEBUG'))
+ {
+ error_log('RDF::documentFromURL(): Fetching ' . $location);
+ }
+ $doc = self::fetch($location, $ct, RDFDocument::$parseableTypes, $curl);
if($doc === null)
{
+ error_log('RDF::documentFromURL(): Failed to fetch ' . $location);
return null;
}
+ if(defined('EREGANSU_DEBUG'))
+ {
+ error_log('RDF::documentFromURL(): Fetched ' . $location . ' with content type ' . $ct);
+ }
+ if(in_array($ct, RDFDocument::$parseableTypes))
+ {
+ $d = new RDFDocument($location);
+ if($d->parse($ct, $doc))
+ {
+ return $d;
+ }
+ error_log('RDF::documentFromURL(): RDFDocument::parse() failed for ' . $location . ' with type '. $ct);
+ }
if(self::isHTML($doc, $ct))
{
return self::documentFromHTML($doc, $location, $curl);
@@ -165,6 +183,7 @@ public static function documentFromURL($location, $curl = null)
{
return self::documentFromXMLString($doc, $location, $curl);
}
+ error_log('RDF::documentFromURL(): Unable to parse ' . $location . ' with type ' . $ct);
return null;
}
@@ -279,7 +298,8 @@ protected static function documentFromHTML($doc, $location, $curl = null)
}
$href .= '.rdf';
}
- $doc = self::fetch($href, $ct, 'application/rdf+xml', $curl);
+ /* XXX This should obtain the list of acceptable types from RDFDocument */
+ $doc = self::fetch($href, $ct, RDFDocument::$parseableTypes, $curl);
if(self::isXML($doc, $ct))
{
return self::documentFromXMLString($doc, $href);
@@ -328,14 +348,19 @@ protected static function fetch($url, &$contentType, $accept = null, &$curl)
$accept = array();
}
}
- $accept[] = '*/*';
+ $accept[] = '*/*;q=0.5';
$curl->headers['Accept'] = implode(',', $accept);
$buf = $curl->exec();
$info = $curl->info;
$curl->headers = $headers;
if(intval($info['http_code']) > 399)
{
+ error_log('RDF::fetch(): Fetching ' . $url . ': HTTP status ' . $info['http_code']);
+/* echo '<pre>';
+ print_r($curl);
+ echo '</pre>';
echo "RDF::fetch(): HTTP status " . $info['http_code'] . "\n";
+ throw new Exception($curl->receivedHeaders['status'], $info['http_code']); */
return null;
}
$c = explode(';', $info['content_type']);
View
@@ -253,6 +253,14 @@ public function __construct($name = 'rdfxml', $mime = null, $type = null, $world
}
}
+class RedlandTurtleParser extends RedlandParser
+{
+ public function __construct($name = 'turtle', $mime = null, $type = null, $world = null)
+ {
+ parent::__construct($name, $mime, $type, $world);
+ }
+}
+
class RedlandNode extends RedlandBase
{
public static function blank($world = null)

0 comments on commit 93cdf8a

Please sign in to comment.