Skip to content

Commit 9279d46

Browse files
committed
Added private profile form
1 parent e7a17a5 commit 9279d46

21 files changed

+967
-20
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*~
2+
lib/arc/*
3+
lib/xmlrpc/*
4+
js/jquery.form.js
5+
js/jquery-dynamic-form.js
6+
js/dbpedia-spotlight-0.2.js
7+
js/dbpedia-spotlight-0.1.js
8+
test_data/*

.htaccess

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ RewriteRule ^sparql(.*)$ index.php?t=sparql [L,QSA]
3131

3232
RewriteRule ^callback(.*)$ index.php?t=callback [L,QSA]
3333
RewriteRule ^callbackrdf(.*)$ index.php?t=callbackrdf [L,QSA]
34+
#RewriteRule ^me/private(.*)$ lib/smob/SMOBPrivacyTemplate.php [L,QSA]
35+
RewriteRule ^private/edit(.*)$ index.php?t=private&a=edit [L,QSA]
36+
RewriteRule ^private(.*)$ index.php?t=private [L,QSA]
37+
RewriteRule ^logout(.*)$ index.php?t=logout [L,QSA]
3438

3539
RewriteRule ^feedrdf$ sparql?query=CONSTRUCT\%20\%7B\%20?s\%20?p\%20?o\%20.\%20\%7D\%20WHERE\%20\%7B\%20GRAPH\%20?g\%20\%7B\%20?s\%20?p\%20?o\%20.\%20\%7D\%7D
3640

ajax/private.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
4+
require_once(dirname(__FILE__)."/../lib/smob/SMOBTools.php");
5+
require_once(dirname(__FILE__)."/../lib/smob/SMOBStore.php");
6+
require_once(dirname(__FILE__)."/../config/config.php");
7+
8+
$triples = $_POST['triples'];
9+
error_log($triples,0);
10+
error_log(SMOB_ROOT,0);
11+
$query = "DELETE FROM <".SMOB_ROOT."me> ";
12+
$res = SMOBStore::query($query);
13+
#error_log(var_dump($res, 1), 0);
14+
$query = "INSERT INTO <".SMOB_ROOT."me> { $triples }";
15+
$res = SMOBStore::query($query);
16+
#error_log(var_dump($res, 1), 0);
17+
print "Your private profile has been stored...\n";
18+
error_log("private profile stored");

ajax/suggestions.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
//$json = json_encode($dbpediaentities, true);
3+
//$json = json_decode($dbpediaentities, true);
4+
//foreach ($json as $label=>$uri) {
5+
// $options .= "<option value='".$rel."' >".$label."</option>";
6+
//};
7+
//return $rels;
8+
9+
10+
//require_once(dirname(__FILE__)."/../lib/smob/wrappers/tag/dbpedia.php");
11+
//$x = new DBPediaTagWrapper($term);
12+
//$uris = $x->get_uris();
13+
14+
require_once(dirname(__FILE__).'/../lib/smob/SMOB.php');
15+
require_once(dirname(__FILE__)."/../config/config.php");
16+
17+
function get_wrappers($type) {
18+
if ($handle = opendir(dirname(__FILE__)."/../lib/smob/wrappers/$type")) {
19+
while (false !== ($file = readdir($handle))) {
20+
if (substr($file, 0, 1) != '.') {
21+
$services[] = substr($file, 0, -4);
22+
require_once(dirname(__FILE__)."/../lib/smob/wrappers/$type/$file");
23+
}
24+
}
25+
closedir($handle);
26+
}
27+
return $services;
28+
}
29+
30+
function find_uris($wrapper, $term, $type) {
31+
$w = ucfirst($wrapper).ucfirst($type).'Wrapper';
32+
$x = new $w($term);
33+
return $x->get_uris();
34+
}
35+
36+
$type = $_GET['type'];
37+
$term = $_GET['term'];
38+
39+
40+
// URIs from wrappers
41+
$wrappers = get_wrappers($type);
42+
//$ht = "<div id='suggestions'>";
43+
$ht = "";
44+
$i = 0;
45+
foreach($wrappers as $wrapper) {
46+
$ht .= "<fieldset><legend>Via $wrapper</legend>";
47+
$uris = find_uris($wrapper, $term, $type);
48+
if($uris) {
49+
foreach($uris as $name=>$uri) {
50+
$ht .= "<input id='suggestion$i' type='radio' name='suggestion' value='$uri'/><label for='suggestion$i'>$name</label> ($uri)<br/>";
51+
$i++;
52+
}
53+
} else {
54+
$ht .= "Nothing retrieved from this service<br/>";
55+
}
56+
$ht .= "</fieldset>";
57+
}
58+
//$ht .= "</div>";
59+
print $ht;

auth/.htaccess

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
# shoud work. If note, please read
33
# http://foaf.me/Enabling_SSL_Client_Certificates_on_Apache.php
44

5-
#SSLVerifyClient optional_no_ca
6-
#SSLVerifyDepth 1
7-
#SSLOptions +StdEnvVars
8-
#SSLOptions +ExportCertData
5+
SSLVerifyClient optional_no_ca
6+
SSLVerifyDepth 1
7+
SSLOptions +StdEnvVars
8+
SSLOptions +ExportCertData
99

1010
# If you don't want basic HTTP authentication, comment the following
1111
# lines. Otherwise, uncoment them and create a corresponding .htpasswd file,
1212
# containing login:pass
1313
# See http://www.htaccesstools.com/htpasswd-generator/ for generation
1414
# Or use the example auth/.htpasswd provided for user admin and password admin
1515

16-
AuthUserFile /path/to/.htpasswd
17-
AuthGroupFile /dev/null
18-
AuthName "Restricted area !"
19-
AuthType Basic
20-
<Limit GET>
21-
require valid-user
22-
</Limit>
16+
#AuthUserFile /path/to/.htpasswd
17+
#AuthGroupFile /dev/null
18+
#AuthName "Restricted area !"
19+
#AuthType Basic
20+
#<Limit GET>
21+
#require valid-user
22+
#</Limit>

auth/index.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55
require_once(dirname(__FILE__).'/../lib/smob/SMOBTools.php');
66
require_once(dirname(__FILE__).'/../config/config.php');
77

8+
error_log("going to authenticate");
89
SMOBAuth::grant();
10+
error_log("authentication done");
911

10-
header("Location: ".SMOB_ROOT);
12+
if($_SESSION['grant'] && isset($_REQUEST['referer'])){
13+
error_log("has been authenticated and came from other page, going to the initial page");
14+
header("Location: ".$_REQUEST['referer']);
15+
//if ($_SESSION['grant'] && $_GET["redirect"]) {
16+
// error_log("has been authenticated and came from other page, going to the initial page");
17+
// header("Location: ".SMOB_ROOT.$_GET["redirect"]);
18+
} else {
19+
error_log("has no been authenticated or did not come from other page, going to the main page");
20+
header("Location: ".SMOB_ROOT);
21+
}
1122

1223
?>

index.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,31 @@
220220
$post_data = file_get_contents("php://input");
221221
error_log("DEBUG: received PUT with content: $post_data",0);
222222
}
223-
} else {
223+
} elseif($t == 'private') {
224+
// TODO: The private profile graph is the same as the profile graph, privacy preferences will decide what is visible
225+
// TODO: Authorize depending on the WebID URI
226+
if(!SMOBAuth::check()) {
227+
error_log("not authenticated");
228+
//if($a && $a == 'edit'){
229+
// header( 'Location: '.SMOB_ROOT.'auth?redirect=private/edit' ) ;
230+
//} else {
231+
// header( 'Location: '.SMOB_ROOT.'auth?redirect=private' ) ;
232+
//};
233+
header( 'Location: '.SMOB_ROOT.'auth' ) ;
234+
} else {
235+
error_log("authenticated");
236+
if($a && $a == 'edit'){
237+
echo PrivateProfile::view_private_profile_form();
238+
} else {
239+
echo PrivateProfile::view_private_profile();
240+
exit();
241+
};
242+
};
243+
} elseif($t == 'logout'){
244+
session_start();
245+
session_destroy();
246+
echo 'bye';
247+
} else {
224248
$smob = new SMOB($t, $u, $p);
225249
$smob->reply_of($r);
226250
$smob->go();

js/dbpedia-spotlight-0.1.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* If you use this script, please give credit to DBpedia Spotlight by:
3+
* - adding "powered by DBpedia Spotlight" somewhere in the page.
4+
* - add a link to http://spotlight.dbpedia.org.
5+
*
6+
* @author pablomendes
7+
*
8+
*/
9+
10+
(function( $ ){
11+
12+
$.fn.annotate = function( options ) {
13+
14+
var powered_by = "<div style='font-size: 9px; float: right'><a href='http://spotlight.dbpedia.org'>Powered by DBpedia Spotlight</a></div>";
15+
16+
var settings = {
17+
'endpoint' : 'http://spotlight.dbpedia.org/rest/annotate',
18+
'confidence' : 0.4,
19+
'support' : 20,
20+
'powered_by': 'yes'
21+
};
22+
23+
function update(response) {
24+
var content = $(response).find("div"); //the div with the annotated text
25+
26+
if (settings.powered_by == 'yes') {
27+
$(content).append($(powered_by));
28+
};
29+
30+
var entities = $(content).find("a/[about]")
31+
32+
$(this).replaceWith(content);
33+
34+
}
35+
36+
37+
return this.each(function() {
38+
39+
// If options exist, lets merge them with our default settings
40+
if ( options ) {
41+
$.extend( settings, options );
42+
}
43+
44+
var params = {'text': this.innerHTML, 'confidence': settings.confidence, 'support': settings.support };
45+
46+
$.ajax({ 'url': settings.endpoint,
47+
'data': params,
48+
'context': this,
49+
'headers': {'Accept': 'application/xhtml+xml'},
50+
'success': update
51+
});
52+
53+
});
54+
55+
};
56+
})( jQuery );

js/dbpedia-spotlight-0.2.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* If you use this script, please give credit to DBpedia Spotlight by:
3+
* - adding "powered by DBpedia Spotlight" somewhere in the page.
4+
* - add a link to http://spotlight.dbpedia.org.
5+
*
6+
* TODO people can also want to change the boundaries of the spotting
7+
* TODO showScores = [ list of score names ]
8+
*
9+
* @author pablomendes
10+
*
11+
*/
12+
13+
(function( $ ){
14+
15+
var powered_by = "<div style='font-size: 9px; float: right'><a href='http://spotlight.dbpedia.org'>Powered by DBpedia Spotlight</a></div>";
16+
17+
var settings = {
18+
'endpoint' : 'http://spotlight.dbpedia.org/dev/rest',
19+
'confidence' : 0.4,
20+
'support' : 20,
21+
'powered_by': 'yes'
22+
};
23+
24+
var methods = {
25+
init : function( options ) {
26+
// If options exist, lets merge them with our default settings
27+
if ( options ) {
28+
$.extend( settings, options );
29+
}
30+
},
31+
annotate: function( options ) {
32+
function update(response) {
33+
var content = $(response).find("div"); //the div with the annotated text
34+
if (settings.powered_by == 'yes') {
35+
$(content).append($(powered_by));
36+
};
37+
//var entities = $(content).find("a/[about]");
38+
$(this).html(content.html());
39+
}
40+
41+
return this.each(function() {
42+
var params = {'text': $.quoteString($(this).text()), 'confidence': settings.confidence, 'support': settings.support };
43+
$.ajax({ 'url': settings.endpoint+"/annotate",
44+
'data': params,
45+
'context': this,
46+
'headers': {'Accept': 'application/xhtml+xml'},
47+
'success': update
48+
});
49+
});
50+
},
51+
candidates: function( options ) {
52+
function getSelectBox(resources) {
53+
var snippet = "<select class='candidates'>";
54+
//console.log(resources);
55+
var options = ""; $.each(resources, function(i, r) {
56+
options += "<option value='" + r["@uri"] + "'>" + r["@label"];
57+
//TODO settings.showScores = ["finalScore"] foreach showscores, add k=v
58+
if (settings.showScores == 'yes') options += " (" + parseFloat(r["@finalScore"]).toPrecision(3) +")";
59+
options += "</option>";
60+
});
61+
snippet += options;
62+
snippet += "</select>"
63+
return snippet;
64+
}
65+
66+
67+
function parseCandidates(json) {
68+
var text = json.annotation["@text"];
69+
var start = 0;
70+
var annotatedText = json.annotation.surfaceForm.map(function(e) {
71+
var name = e["@name"];
72+
var offset = parseInt(e["@offset"]);
73+
var sfLength = parseInt(name.length);
74+
var snippet = text.substring(start, offset)
75+
var surfaceForm = text.substring(offset,offset+sfLength);
76+
start = offset+sfLength;
77+
snippet += "<div id='"+(name+offset)+"' class='annotation'>";
78+
//TODO instead of showing directly the select box, it would be cuter to just show a span, and onClick on that span, build the select box.
79+
snippet += getSelectBox($(e.resource));
80+
snippet += "</div>";
81+
return snippet;
82+
}).join("");
83+
//snippet after last surface form
84+
annotatedText += text.substring(start, text.length);
85+
//console.log(annotatedText);
86+
return annotatedText;
87+
}
88+
89+
function update(response) {
90+
//console.log(response);
91+
var content = parseCandidates(response);
92+
if (settings.powered_by == 'yes') {
93+
$(content).append($(powered_by));
94+
};
95+
$(this).html(content);
96+
}
97+
98+
return this.each(function() {
99+
var params = {'text': $(this).val(), 'confidence': settings.confidence, 'support': settings.support };
100+
$.ajax({ 'url': settings.endpoint+"/candidates",
101+
'data': params,
102+
'context': this,
103+
'headers': {'Accept': 'application/json'},
104+
'success': update
105+
});
106+
});
107+
}
108+
109+
};
110+
111+
$.fn.runDBpediaSpotlight = function(method) {
112+
// Method calling logic
113+
if ( methods[method] ) {
114+
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
115+
} else if ( typeof method === 'object' || ! method ) {
116+
return methods.init.apply( this, arguments );
117+
} else {
118+
$.error( 'Method ' + method + ' does not exist on jQuery.spotlight' );
119+
}
120+
};
121+
122+
})( jQuery );

0 commit comments

Comments
 (0)