-
Notifications
You must be signed in to change notification settings - Fork 15
/
Queries.php
78 lines (70 loc) · 1.53 KB
/
Queries.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?
class Queries{
public static function uriExist($uri, $e){
$q = "SELECT * WHERE{
{<$uri> ?p1 ?o1}
UNION
{?s1 <$uri> ?o2}
UNION
{?s2 ?p2 <$uri>}
}LIMIT 1";
$r = $e->query($q);
if(sizeof($r['results']['bindings'])>0){
return true;
}
return false;
}
public static function getClass($uri, $e){
$q = "SELECT DISTINCT ?class WHERE{
<$uri> a ?class .
} LIMIT 1";
$r = $e->query($q);
if(sizeof($r['results']['bindings'])>0){
return $r['results']['bindings'][0]['class']['value'];
}
return NULL;
}
public static function getMetadata($uri, $format, $e){
global $conf;
$q = <<<QUERY
SELECT uri, doc, format FROM document WHERE
(uri = "$uri" AND format = "$format") OR doc = "$uri"
LIMIT 1
QUERY;
$r = $e->query($q);
if(sizeof($r) > 0){
$u = $r[0]['uri'];
$p = $r[0]['doc'];
$f = $r[0]['format'];
return array($u, $p, $f);
}else{
return NULL;
}
}
public static function createPage($uri, $contentType, $e){
global $conf;
$ext = 'html';
$inserts = "";
foreach($conf['http_accept'] as $extension => $f){
$page = $uri.".".$extension;
foreach($f as $v){
if($contentType == $v){
$returnPage = $uri.".".$extension;
}
if($inserts != ""){
$inserts .= "UNION ";
}
$inserts .= "SELECT '$uri', '$page', '$v' \n";
if($v == $contentType){
$ext = $extension;
}
}
}
$q = <<<QUERY
INSERT INTO document (uri, doc, format) $inserts
QUERY;
$r = $e->write($q);
return $returnPage;
}
}
?>