8000 Additions/fixes from rww.io · linkeddata/ldphp@da805ba · GitHub
[go: up one dir, main page]

Skip to content

Commit da805ba

Browse files
author
deiu
committed
Additions/fixes from rww.io
1 parent cdae89c commit da805ba

File tree

7 files changed

+53
-53
lines changed

7 files changed

+53
-53
lines changed

www/wildcard/GET.php

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,9 @@
1717
exit;
1818
}
1919

20+
// logout
2021
if ((basename($_filename) == 'logout') || (isset($_GET['logout']))) {
21-
foreach ($_SESSION as $k=>$v) {
22-
sess($k, null);
23-
}
24-
25-
if (isset($i_next)) {
26-
sess('next', $i_next);
27-
} elseif (isMethod('GET') && isset($_SERVER['HTTP_REFERER'])) {
28-
sess('next', $_SERVER['HTTP_REFERER']);
29-
}
30-
31-
if (isSess('next')) {
32-
$next = sess('next', null);
33-
$next = str_replace('https://', 'http://', $next);
34-
header('Location: '.$next);
35-
} else {
36-
header('Location: /');
37-
}
38-
exit;
22+
isset($i_next)?clearSession($i_next):clearSession();
3923
}
4024

4125
if (!in_array($_method, array('GET', 'HEAD')) && !isset($i_query))
@@ -85,6 +69,9 @@
8569
httpStatusExit(403, 'Forbidden');
8670
}
8771

72+
// add Vary header
73+
header("Vary: Accept, Origin, If-Modified-Since, If-None-Match");
74+
8875
// directory indexing
8976
if (is_dir($_filename) || substr($_filename,-1) == '/') {
9077
// add meta relation
@@ -140,7 +127,6 @@
140127
exit;
141128
} else {
142129
// always revalidate cache for RDF documents
143-
header("Vary: Accept, Origin, If-Modified-Since, ETag");
144130
header("Cache-Control: max-age=0", true);
145131
}
146132

@@ -172,16 +158,20 @@
172158
}
173159

174160
// add ETag and Last-Modified headers
175-
if (strlen($etag))
161+
if (strlen($etag)) {
176162
$etag = trim(array_shift(explode(' ', $etag)));
177-
header('ETag: "'.$etag.'"');
163+
header('ETag: "'.$etag.'"');
164+
}
165+
178166
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT', true, 200);
179167

180-
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
181-
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified ||
182-
str_replace('"', '', trim($_SERVER['HTTP_IF_NONE_MATCH'])) == $etag) {
183-
header("HTTP/1.1 304 Not Modified");
184-
exit;
168+
if (CACHING) {
169+
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
170+
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified ||
171+
str_replace('"', '', trim($_SERVER['HTTP_IF_NONE_MATCH'])) == $etag) {
172+
header("HTTP/1.1 304 Not Modified");
173+
exit;
174+
}
185175
}
186176
}
187177

@@ -231,14 +221,9 @@
231221
$g->reload();
232222
}
233223

234-
// ETag
235-
$etag = $g->etag();
236-
if ($etag)
237-
header('ETag: "'.$etag.'"');
238-
239224
// LDP type
240225
if (is_dir($_filename))
241-
header("Link: <http://www.w3.org/ns/ldp#Container>; rel=\"type\"", false);
226+
header("Link: <http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\"", false);
242227
else
243228
header("Link: <http://www.w3.org/ns/ldp#Resource>; rel=\"type\"", false);
244229

www/wildcard/MKCOL.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717

1818
// action
1919
@mkdir($_filename, 0777, true);
20+
header("Link: <".$_metabase.$_metaname.">; rel=meta", false);
21+
httpStatusExit(201, 'Created');

www/wildcard/PUT.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22
/* PUT.php
33
* service HTTP PUT controller
4+
*
45
*/
6+
57
require_once('runtime.php');
68

79
// permissions
@@ -31,7 +33,7 @@
3133
if ($_input == 'raw') {
3234
require_once('if-match.php');
3335
file_put_contents($_filename, $_data);
34-
exit;
36+
httpStatusExit(201, 'Created');
3537
}
3638

3739
$g = new Graph('', $_filename, '', $_base);
@@ -41,6 +43,7 @@
4143
if (!empty($_input) && $g->append($_input, $_data)) {
4244
librdf_php_last_log_level() && httpStatusExit(400, 'Bad Request', null, librdf_php_last_log_message());
4345
$g->save();
46+
httpStatusExit(201, 'Created');
4447
} else {
4548
librdf_php_last_log_level() && httpStatusExit(400, 'Bad Request', null, librdf_php_last_log_message());
4649
header('Accept-Post: '.implode(',', $_content_types));

www/wildcard/index.html.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
</form>
2929
</table>
3030

31-
<div id="editor" class="editor" style="display:none">
31+
<div id="editor" class="editor ui-widget-content" style="display:none">
3232
<input class="cleft left" style="margin: 0;" type="text" id="editorpath" placeholder="loading..." />
33-
<select id="editorType" class="left" onchange="cloud.edit($F('editorpath'))">
33+
<select id="editorType" class="left" style="margin: 0;" onchange="cloud.edit($F('editorpath'))">
3434
<option disabled="disabled"></option>
3535
<option>text/turtle</option>
3636
<option>text/rdf+xml</option>
@@ -44,11 +44,11 @@
4444
<option>text/javascript</option>
4545
</select>
4646
<textarea class="editor-content clear left" id="editorarea" disabled="disabled"></textarea><br/>
47-
<div class="right"><a href="#" class="button button-rounded button-flat-primary" onclick="cloud.save();"><i class="icon-save"></i> Save</a></div>
4847
<div class="right actions"><a href="#" class="button button-rounded button-flat-caution" onclick="$('editor').hide();"><i class="icon-remove"></i> Cancel</a></div>
48+
<div class="right"><a href="#" class="button button-rounded button-flat-primary" onclick="cloud.save();"><i class="icon-save"></i> Save</a></div>
4949
</div>
5050

51-
<div id="wac-editor" class="wac-editor" style="display: none;">
51+
<div id="wac-editor" class="wac-editor ui-widget-content" style="display: none;">
5252
<span id="wac-reqpath" name="wac-reqpath" style="display: none;"></span>
5353
<h3>Resource name: <b><span id="wac-path" name="wac-path"></span></b></h3>
5454
<input type="hidden" id="wac-exists" value="0" />
@@ -70,8 +70,8 @@
7070
</div>
7171
<textarea id="wac-users" name="users" cols="5" rows="5"></textarea>
7272
<br/>
73-
<div class="right"><a href="#" class="button button-rounded button-flat-primary" onclick="wac.save()"><i class="icon-save"></i> Save</a></div>
7473
<div class="right actions"><a href="#" class="button button-rounded button-flat-caution" onclick="wac.hide()"><i class="icon-remove"></i> Cancel</a></div>
74+
<div class="right"><a href="#" class="button button-rounded button-flat-primary" onclick="wac.save()"><i class="icon-save"></i> Save</a></div>
7575
</div>
7676
<?php } ?>
7777

@@ -115,7 +115,7 @@
115115
<table id="index" class="files center box-shadow">
116116
<thead>
117117
<tr>
118-
<th>Name</th>
118+
<th> Name</th>
119119
<th>Size</th>
120120
<th>Type</th>
121121
<th>Last Modified</th>
@@ -139,7 +139,7 @@
139139
$len = strlen($item);
140140
if (!$len)
141141
continue;
142-
if ($item == '.')
142+
if (($_request_path != '/' && $item == '.'))
143143
continue;
144144
if (($_request_path == '/' && $item == '..'))
145145
continue;
@@ -197,8 +197,7 @@
197197
}
198198
echo '</td>';
199199
echo '<td class="options">';
200-
if ($item != '..')
201-
echo '<a href="#" onclick="wac.edit(\''.$_request_path.'\', \''.$item_elt.'\');"><img class="actions" src="/common/images/22/acl.png" title="Access Control" /></a> ';
200+
echo '<a href="#" onclick="wac.edit(\''.$_request_path.'\', \''.$item_elt.'\');"><img class="actions" src="/common/images/22/acl.png" title="Access Control" /></a> ';
202201
echo '</td>';
203202
echo '<td class="options">';
204203
if ($_options->editui)
@@ -216,6 +215,9 @@
216215
</div>
217216

218217
<script type="text/javascript">
218+
jQuery('#editor').draggable();
219+
jQuery('#wac-editor').draggable();
220+
219221
function showWebID(e) {
220222
// get the mouse position
221223
var e = window.event || e;

www/wildcard/index.rdf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124

125125
// List LDPC info
126126
$ldpc = "@prefix ldp: <http://www.w3.org/ns/ldp#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix p: <http://www.w3.org/ns/posix/stat#> .".
127-
"<".$_base."> a ldp:Container, p:Directory ; ".
127+
"<".$_base."> a ldp:BasicContainer, p:Directory ; ".
128128
"p:mtime ".filemtime($_filename)." ;".
129129
"p:size ".filesize($_filename)." ;";
130130
$g->append('turtle', $ldpc);

www/wildcard/ldp.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
2-
/*
3-
* Linked Data Platform support
4-
*/
2+
53
$slug = (isset($_SERVER['HTTP_SLUG']))?trim($_SERVER['HTTP_SLUG']):'';
64
$got_resource = true;
75

@@ -10,11 +8,15 @@
108
$link_header = http_parse_link_header($_SERVER['HTTP_LINK']);
119

1210
// look for an ldp:Container in the Link header
13-
if (in_array('http://www.w3.org/ns/ldp#Container', $link_header)) {
11+
if in_array('http://www.w3.org/ns/ldp#BasicContainer', $link_header)) {
1412
if (strlen($slug) > 0) {
1513
$_dir = $slug;
1614
} else {
17-
$p = LDP_get_prefix($_metafile, $_metabase.$_metaname, 'http://ns.rww.io/ldpx#LDPCprefix');
15+
// try to find a dedicated LDPC prefix first
16+
$p = LDP_get_prefix($_metafile, $_metabase.$_metaname, 'http://ns.rww.io/ldpx#ldpcPrefix');
17+
// else, try to find a generic prefix
18+
if (!$p)
19+
$p = LDP_get_prefix($_metafile, $_metabase.$_metaname, 'http://ns.rww.io/ldpx#ldprPrefix');
1820
$prefix = ($p)?$p:LDPC_PREFIX;
1921
$c = count(glob($_filename.$prefix.'*'));
2022
$c++;
@@ -39,11 +41,17 @@
3941
$metafile = $slug;
4042
} else {
4143
// generate and autoincrement file ID
42-
$p = LDP_get_prefix($_metafile, $_metabase.$_metaname, 'http://ns.rww.io/ldpx#LDPRprefix');
44+
$p = LDP_get_prefix($_metafile, $_metabase.$_metaname, 'http://ns.rww.io/ldpx#ldprPrefix');
4345
$prefix = ($p)?$p:LDPR_PREFIX;
44-
$c = count(glob($_filename.$prefix.'*'));
45-
$c++;
46-
$metafile = $prefix.$c;
46+
$g = glob($_filename.$prefix.'*');
47+
$id = 0;
48+
foreach ($g as $f) {
49+
$i = substr($f, strlen($_filename.$prefix), strlen($_filename.$f));
50+
if ((int)$i > $id)
51+
$id = (int)$i;
52+
}
53+
$id++;
54+
$metafile = $prefix.$id;
4755
}
4856
$_filename = $_filename.$metafile;
4957
$ldp_location = $_base.$metafile;

www/wildcard/runtime.php

Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
$n = '*';
9898
}
9999
header('Access-Control-Allow-Origin: '.$n);
100-
header('Access-Control-Expose-Headers: User, Triples, Location, Link, Vary');
100+
header('Access-Control-Expose-Headers: User, Triples, Location, Link, Vary, Last-Modified');
101101
header('Access-Control-Allow-Credentials: true');
102102
}
103103

0 commit comments

Comments
 (0)
0