forked from MyProfile/myprofile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shorthandle.php
42 lines (34 loc) · 1.37 KB
/
shorthandle.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
<?php
require_once ("include.php");
$sparql = sparql_connect(SPARQL_ENDPOINT);
$input = $_REQUEST["term"];
$data = array();
// query the triple store looking for a match to $input
$query = 'SELECT DISTINCT ?webid, ?name, ?img WHERE {
?webid foaf:name ?name .
?webid foaf:nick ?nick .
?webid foaf:img ?img .
FILTER (regex(?name, "' . $input . '", "i") || regex(?nick, "' . $input . '", "i") || regex(?webid, "' . $input . '", "i"))
MINUS { ?webid a foaf:Person .
FILTER (regex(?webid, "nodeID", "i")) }
} LIMIT 10';
$result = $sparql->query($query);
if(!$result)
die(sparql_errno() . ": " . sparql_error());
while ($row = sparql_fetch_array($result)) {
$json = array();
$json['webid'] = $row['webid'];
$json['name'] = $row['name'];
$json['img'] = $row['img'];
$json['label'] = '<table><tr>';
$json['label'] .= '<td><img width="30" src="' . $row['img'] . '"/></td>';
$json['label'] .= '<td><strong>' . $row['name'] . '</strong><br/>' . $row['webid'] . '</td>';
$json['label'] .= '</tr></table>';
$json['value'] = '<'. strtolower($row['webid']) . '>';
$data[] = $json;
}
// return data
header("Content-type: application/json");
echo json_encode($data);
//echo $data;
?>