/
friends.php
100 lines (83 loc) · 3.87 KB
/
friends.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* Copyright (C) 2012 MyProfile Project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
require_once 'include.php';
$title = 'Friends';
$friends_on = 'friends-on';
// load a specific webid instead of the logged user
if (isset($_REQUEST['webid'])) {
$person = new MyProfile(urldecode($_REQUEST['webid']), BASE_URI, SPARQL_ENDPOINT);
$person->load();
$profile = $person->get_profile();
} else {
// verify if we're logged in or not, so we get the user's list of contacts
check_auth(IDP, $page_uri);
$profile = $_SESSION['myprofile']->get_profile();
}
$user = $profile->get("foaf:name");
$search = (isset($_REQUEST['search'])) ? $_REQUEST['search'] : '';
$form = "<div id=\"friends\" class=\"content relative shadow clearfix main\">";
$form .= "<div>\n";
$form .= "<form action=\"lookup\" method=\"GET\">\n";
$form .= "<input type=\"search\" name=\"search\" onfocus=\"this.value=(this.value=='name, nickname or WebID') ? '' : this.value;\" onblur=\"this.value=(this.value=='') ? 'name, nickname or WebID' : this.value;\" value=\"name, nickname or WebID\" />\n";
$form .= "<input class=\"btn btn-primary\" type=\"submit\" name=\"submit\" value=\" Search \">\n";
$form .= "</form></div>\n";
$ret = '';
$ret .= "<div class=\"clear\"></div>\n";
$ret .= "<p><font style=\"font-size: 2em; text-shadow: 0 1px 1px #cccccc;\">" . $user . "'s Friends</font></p>\n";
$ret .= "<p><small>This page may take a while to finish loading...<small></p>\n";
// display confirmation message here
if (isset($confirmation)) {
$ret .= $confirmation;
}
// call ajax script here to load each friend's data
$friends = implode(',', $profile->all('foaf:knows'));
// show something if there are friends for this webid
if (strlen($friends) > 0) {
$ret .= '<script type="text/javascript">
var list = "' . (string)$friends . '";
var uris = list.split(",");
// Create placeholders for each contact info
for (i = 0; i < uris.length; i++) {
var webid = uris[i];
$("#friends").append("<div id=\"person_"+i+"\"></div>");
}
</script>';
$ret .= '<script type="text/javascript">
var list = "' . (string)$friends . '";
var uris = list.split(",");
if (list.length > 0) {
for (i = 0; i < uris.length; i++) {
var webid = uris[i];
//var hash = webid.slice(webid.indexOf("#"));
// script URI that we will call for each user
var addr = "load.php?webid="+encodeURIComponent(webid)+"&me="+encodeURIComponent("' . $_SESSION['webid'] . '");
$("#person_"+i).load(addr);
}
}
</script>';
} else {
$ret .= "The user does not have any friends.<br/>\n";
}
$ret .= "</div>\n";
include 'header.php';
echo $form;
echo $ret;
include 'footer.php';
?>