Пример #1
0
// GNU General Public License for more details.
//
// See <http://www.gnu.org/licenses/> for a description of this license.
require 'include.php';
$ret = "";
// Process request and deliver pingback
if (isset($_POST['source'])) {
    // fetch the user's profile
    $profile = new MyProfile(trim($_POST['source']), $base_uri, SPARQL_ENDPOINT);
    $profile->load();
    // Prepare data to be inserted into the database
    $from = mysql_real_escape_string(trim($_POST['source']));
    $to = mysql_real_escape_string(trim($_POST['target']));
    $msg = mysql_real_escape_string(trim($_POST['comment']));
    $name = mysql_real_escape_string(trim($profile->get_name()));
    $pic = mysql_real_escape_string(trim($profile->get_picture()));
    // Return HTTP 400 (bad request)
    if (!isset($_POST['target'])) {
        // No destination user, return a proper HTTP response code with error
        $ret .= header("HTTP/1.1 400 Bad request");
        $ret .= header("Status: 400 Bad request");
        $ret .= "<html><body>\n";
        $ret .= "Bad request: you did not specify the destination user.\n";
        $ret .= "</body></html>\n";
    } else {
        if (!isset($_POST['comment'])) {
            // No message, return a proper HTTP response code with error
            $ret .= header("HTTP/1.1 400 Bad request");
            $ret .= header("Status: 400 Bad request");
            $ret .= "<html><body>\n";
            $ret .= "Bad request: you did not provide a message.\n";
Пример #2
0
function viewShortInfo($webid, $me, $base_uri, $endpoint)
{
    // fetch info for webid
    $ret = '';
    $person = new MyProfile($webid, $base_uri, $endpoint);
    $person->load();
    $profile = $person->get_profile();
    // find if he has me in his list of foaf:knows!
    $has_me = false;
    if (in_array($me, $profile->all('foaf:knows'))) {
        $has_me = true;
    }
    // check if the user has subscribed to local messages
    $is_subscribed = strlen($person->get_hash()) > 0 ? true : false;
    // start populating array
    $friend = array('webid' => (string) $webid, 'img' => (string) $person->get_picture(), 'name' => (string) $profile->get("foaf:name"), 'nick' => (string) $profile->get("foaf:nick"), 'email' => (string) $profile->get("foaf:mbox"), 'blog' => (string) $profile->get("foaf:weblog"), 'pingback' => (string) $profile->get("http://purl.org/net/pingback/to"), 'hash' => $person->get_hash(), 'hasme' => $has_me);
    if (isset($new)) {
        $friend['new'] = $new;
    }
    $ret .= "<table>\n";
    $ret .= "<tr bgcolor=\"\"><td>\n";
    $ret .= "<table><tr>\n";
    $ret .= "<td width=\"70\" style=\"vertical-align: top; padding: 10px;\">\n";
    $ret .= "<div align=\"left\"><a href=\"view.php?webid=" . urlencode($friend['webid']) . "\" target=\"_blank\">";
    $ret .= "<img title=\"" . $friend['name'] . "\" alt=\"" . $friend['name'] . ".\" width=\"64\" src=\"" . $friend['img'] . "\" />";
    $ret .= "</a></div>\n";
    $ret .= "</td>\n";
    $ret .= "<td><table>\n";
    if ($friend['name'] != null) {
        $ret .= "<tr><td><strong>" . $friend['name'] . "</strong>\n";
    } else {
        $ret .= "<tr><td><strong>Anonymous</strong>\n";
    }
    if ($friend['nick'] != null) {
        $ret .= "''" . $friend['nick'] . "''";
    }
    $ret .= "</td></tr>\n";
    if ($friend['hasme'] == true) {
        $ret .= "<tr><td><div style=\"color:#60be60;\">Has you as friend.</div></td></tr>\n";
    }
    //$ret .= "<tr><td>&nbsp;</td></tr>\n";
    if ($friend['email'] != null) {
        $ret .= "<tr><td>Email: <a href=\"" . $friend['email'] . "\">" . clean_mail($friend['email']) . "</a></td></tr>\n";
    }
    if ($friend['blog'] != null) {
        $ret .= "<tr><td>Blog:<a href=\"" . $friend['blog'] . "\">" . $friend['blog'] . "</a></td></tr>\n";
    }
    $ret .= "<tr><td>WebID: <a href=\"view.php?webid=" . urlencode($friend['webid']) . "\">" . $friend['webid'] . "</a></td></tr>\n";
    $ret .= "</table>\n";
    $ret .= "<br/><table>\n";
    $ret .= "<tr>\n";
    // add or remove friends if we have them in our list
    if (isset($_SESSION['webid']) && webid_is_local($_SESSION['webid'])) {
        if ($_SESSION['myprofile']->is_friend($webid)) {
            // remove friend
            $ret .= "<td style=\"padding-right: 10px; float: left;\"><form action=\"friends.php\" method=\"POST\">\n";
            $ret .= "<input type=\"hidden\" name=\"action\" value=\"delfriend\">\n";
            $ret .= "<input type=\"hidden\" name=\"uri\" value=\"" . $friend['webid'] . "\">\n";
            $ret .= "<input src=\"img/actions/remove.png\" type=\"image\" title=\"Remove friend\" name=\"submit\" value=\" Remove \">\n";
            $ret .= "</form></td>\n";
        } else {
            // add friend
            $ret .= "<td style=\"padding-right: 10px; float: left;\"><form action=\"friends.php\" method=\"POST\">\n";
            $ret .= "<input type=\"hidden\" name=\"action\" value=\"addfriend\">\n";
            $ret .= "<input type=\"hidden\" name=\"uri\" value=\"" . $friend['webid'] . "\">\n";
            $ret .= "<input src=\"img/actions/add.png\" type=\"image\" title=\"Add friend\" name=\"submit\" value=\" Add \">\n";
            $ret .= "</form></td>\n";
        }
    }
    // send messages using the pingback protocol
    if ($friend['pingback'] != null) {
        $ret .= "<td style=\"padding-right: 10px; float: left;\"><form action=\"messages.php\" method=\"POST\">\n";
        $ret .= "<input type=\"hidden\" name=\"new\" value=\"true\">\n";
        $ret .= "<input type=\"hidden\" name=\"to\" value=\"" . $friend['webid'] . "\">\n";
        $ret .= "<input src=\"img/actions/message.png\" type=\"image\" title=\"Send a message\" name=\"submit\" value=\" Message \" onclick=\"this.form.target='_blank';return true;\">\n";
        $ret .= "</form></td>\n";
    }
    // more functions if the user has previously subscribed to the local services
    if ($is_subscribed) {
        // Post on the user's wall
        $ret .= "<td style=\"padding-right: 10px; float: left;\"><form action=\"wall.php\" method=\"POST\">\n";
        $ret .= "<input type=\"hidden\" name=\"user\" value=\"" . $friend['hash'] . "\">\n";
        $ret .= "<input src=\"img/actions/wall.png\" type=\"image\" title=\"View posts\" name=\"submit\" value=\" Wall \" onclick=\"this.form.target='_blank';return true;\">\n";
        $ret .= "</form></td>\n";
    }
    $ret .= "<td style=\"padding-right: 10px; float: left;\"><form action=\"friends.php\" method=\"GET\">\n";
    $ret .= "<input type=\"hidden\" name=\"webid\" value=\"" . $friend['webid'] . "\">\n";
    $ret .= "<input type=\"hidden\" name=\"me\" value=\"" . $me . "\">\n";
    $ret .= "<input src=\"img/actions/friends.png\" type=\"image\" title=\"View friends\" name=\"submit\" value=\" Friends \">\n";
    $ret .= "</form></td>\n";
    $ret .= "</tr></table></p>\n";
    $ret .= "</td>\n";
    $ret .= "</tr></table>\n";
    $ret .= "</td></tr>\n";
    $ret .= "</table>\n";
    return $ret;
}