davvalent commited on 2023-03-13 22:16:49
Showing 1 changed files, with 30 additions and 14 deletions.
| ... | ... |
@@ -1,9 +1,19 @@ |
| 1 | 1 |
<?php |
| 2 | 2 |
|
| 3 |
-// URL rewriting |
|
| 4 |
-// http://127.0.0.1/~david/dev-web/qdmtl-triple-store/Batiment/1373-1377-de-la-Gauchetiere-Est |
|
| 5 |
-// http://127\.0\.0\.1/~david/dev\-web/qdmtl\-triple\-store/([A-Z][a-z]+/.+) |
|
| 6 |
- |
|
| 3 |
+/** |
|
| 4 |
+ * Négociation de contenu pour data.qdmtl.ca : .htaccess + PHP |
|
| 5 |
+ * |
|
| 6 |
+ * 1. URL rewriting pour générer le paramètre d'URL "path" passé à ce script |
|
| 7 |
+ * 2. Traitement avec gestion des URI bilingues |
|
| 8 |
+ * |
|
| 9 |
+ * Local URL rewriting |
|
| 10 |
+ * http://127.0.0.1/~david/dev-web/qdmtl-triple-store/Batiment/1373-1377-de-la-Gauchetiere-Est |
|
| 11 |
+ * http://127\.0\.0\.1/~david/dev\-web/qdmtl\-triple\-store/([A-Z][a-z]+/.+) |
|
| 12 |
+ * |
|
| 13 |
+ * Prod URL rewriting : voir .htaccess |
|
| 14 |
+ */ |
|
| 15 |
+ |
|
| 16 |
+ /** Redirection si paramètre path absent */ |
|
| 7 | 17 |
if (!isset($_GET['path'])) {
|
| 8 | 18 |
header('Location: ./');
|
| 9 | 19 |
header('HTTP/1.1 301 Moved Permanently');
|
| ... | ... |
@@ -13,8 +23,11 @@ |
| 13 | 23 |
require 'parse-ini.php'; |
| 14 | 24 |
require 'vendor/autoload.php'; |
| 15 | 25 |
|
| 16 |
- //Trois arguments : |
|
| 17 |
- // requête, store, true pour var_dump() si debug nécessaire |
|
| 26 |
+ /** |
|
| 27 |
+ * fonction use_path_to_query |
|
| 28 |
+ * Trois arguments : |
|
| 29 |
+ * requête, store, true pour var_dump() si debug nécessaire |
|
| 30 |
+ */ |
|
| 18 | 31 |
function use_path_to_query($q, $s, $vd = false) {
|
| 19 | 32 |
$rs = $s->query($q); |
| 20 | 33 |
|
| ... | ... |
@@ -29,8 +42,10 @@ |
| 29 | 42 |
? $rs |
| 30 | 43 |
: $rs['result']['rows']; |
| 31 | 44 |
|
| 32 |
- if ($vd) |
|
| 45 |
+ if ($vd) {
|
|
| 33 | 46 |
var_dump($result); |
| 47 |
+ exit(); |
|
| 48 |
+ } |
|
| 34 | 49 |
|
| 35 | 50 |
return $result; |
| 36 | 51 |
|
| ... | ... |
@@ -57,7 +72,7 @@ |
| 57 | 72 |
'store_write_buffer' => 40000 |
| 58 | 73 |
); |
| 59 | 74 |
|
| 60 |
- /* namespace prefixes */ |
|
| 75 |
+ /** namespace prefixes */ |
|
| 61 | 76 |
$ns = array( |
| 62 | 77 |
'dcterms' => 'http://purl.org/dc/terms/', |
| 63 | 78 |
'ecrm' => 'http://erlangen-crm.org/current/', |
| ... | ... |
@@ -70,9 +85,9 @@ |
| 70 | 85 |
); |
| 71 | 86 |
$ns_config = array('ns' => $ns);
|
| 72 | 87 |
|
| 73 |
- /* instantiation */ |
|
| 88 |
+ /** instantiation */ |
|
| 74 | 89 |
$store = ARC2::getStore($config); |
| 75 |
- $ser = ARC2::getRDFXMLSerializer($ns_config); |
|
| 90 |
+ $rdf_xml_serializer = ARC2::getRDFXMLSerializer($ns_config); |
|
| 76 | 91 |
|
| 77 | 92 |
// $store->createDBCon(); |
| 78 | 93 |
|
| ... | ... |
@@ -82,7 +97,7 @@ |
| 82 | 97 |
|
| 83 | 98 |
$path = $_GET["path"]; |
| 84 | 99 |
|
| 85 |
- // vérifier si objet de owl:sameAs pour traduction |
|
| 100 |
+ // vérifier si objet de la prop owl:sameAs pour traduction |
|
| 86 | 101 |
$q = ' |
| 87 | 102 |
PREFIX owl: <http://www.w3.org/2002/07/owl#> |
| 88 | 103 |
PREFIX qdmtld: <http://data.qdmtl.ca/> |
| ... | ... |
@@ -91,6 +106,7 @@ |
| 91 | 106 |
?s owl:sameAs qdmtld:' . $path . ' . |
| 92 | 107 |
} |
| 93 | 108 |
'; |
| 109 |
+ |
|
| 94 | 110 |
$has_sameAs = use_path_to_query($q, $store); |
| 95 | 111 |
|
| 96 | 112 |
preg_match('/[A-Z][a-z]+\/(.+)/', $path, $chunked_path);
|
| ... | ... |
@@ -103,10 +119,10 @@ |
| 103 | 119 |
|
| 104 | 120 |
$q = ' |
| 105 | 121 |
PREFIX qdmtld: <http://data.qdmtl.ca/> |
| 106 |
- DESCRIBE qdmtld:' . $path |
|
| 107 |
- ; |
|
| 122 |
+ DESCRIBE qdmtld:' . $path; |
|
| 123 |
+ |
|
| 108 | 124 |
$triples = use_path_to_query($q, $store); |
| 109 |
- $doc = $ser->getSerializedIndex($triples['result']); |
|
| 125 |
+ |
|
| 110 | 126 |
|
| 111 | 127 |
header('Content-type: text/xml');
|
| 112 | 128 |
echo $doc; |
| 113 | 129 |