// First name $firstname = $profile->get('foaf:givenName') != null ? $profile->get('foaf:givenName') : ''; // Lastname $familyname = $profile->get('foaf:familyName') != null ? $profile->get('foaf:familyName') : ''; // Picture $picture = $_SESSION['myprofile']->get_picture(); // Nickname $nick = $profile->get('foaf:nick') != null ? $profile->get('foaf:nick') : ''; // Pingback endpoint $pingback = $profile->get('pingback:to') != null ? $profile->get('pingback:to') : ''; // Multiple values // Email addresses $emails = ''; if ($profile->get('foaf:mbox') != null) { foreach ($profile->all('foaf:mbox') as $email) { $emails .= "<tr><td>Email: </td><td id=\"mbox\"><input type=\"text\" size=\"50\" maxlength=\"64\" value=\"" . clean_mail($email) . "\" name=\"foaf:mbox[]\"><a href=\"#\"><img src=\"img/wac.png\" class=\"mywac\" /></a></td></tr>\n"; } } else { // Should still display the email field by default $emails .= "<tr><td>Email: </td><td><input type=\"text\" size=\"50\" maxlength=\"64\" value=\"\" name=\"foaf:mbox[]\"></td></tr>\n"; } // SHA1 sums $sha1sums = ''; if ($profile->get('foaf:mbox_sha1sum') != null) { foreach ($profile->all('foaf:mbox_sha1sum') as $sha1) { $sha1sums .= "<tr><td>Email SHA1SUM: </td><td id=\"mbox_sha1sum\"><input type=\"text\" size=\"50\" maxlength=\"64\" value=\"" . $sha1 . "\" name=\"foaf:mbox_sha1sum[]\"><a href=\"#\"><img src=\"img/wac.png\" class=\"mywac\" /></a></td></tr>\n"; } } // sameAs $sameAs = ''; if ($profile->get('owl:sameAs') != null) {
// Database error, return a proper HTTP response code with error $ret .= header("HTTP/1.1 500 Internal Error"); $ret .= header("Status: 500 Internal Error"); $ret .= "<html><body>\n"; $ret .= "Internal error: could not deliver the ping (database error).\n"; $ret .= "</body></html>\n"; } else { mysql_free_result($result); // Send a mail too if the receiving user allows it if (is_subscribed_email($to)) { $person = new MyProfile(trim($_POST['target']), BASE_URI, SPARQL_ENDPOINT); $person->load(); $to_name = $person->get_name(); $to_email = $person->get_email(); $from = 'MyProfile Notification System <' . SMTP_USERNAME . '>'; $to = '"' . $to_name . '" <' . clean_mail($to_email) . '>'; $subject = 'You have received a new personal message!'; $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array('host' => SMTP_SERVER, 'auth' => SMTP_AUTHENTICATION, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD)); $message = '<html><body>'; $message .= '<p>Hello ' . $to_name . ',</p>'; $message .= '<p>You have just received a new message from ' . $name . '! '; $message .= '<a href="' . BASE_URI . '/messages">Click here</a> to see it.</p>'; $message .= '<br/><p><small>You are receiving this email because you enabled Semantic Pingback notification '; $message .= '(with email as notification mechanism) for your Personal Profile on <a href="' . BASE_URI . '">' . BASE_URI . '</a>. '; $message .= 'If you would like to stop receiving email notifications, please check your '; $message .= ' <a href="' . BASE_URI . '/subscription.php">subscription settings</a>.</small></p>'; $message .= '<p><small>You do not need to respond to this automated email.</small></p>'; $message .= '</body></html>'; $crlf = "\n"; $mime = new Mail_Mime(array('eol' => $crlf));
// First name $firstname = $profile->get('foaf:givenName') != null ? $profile->get('foaf:givenName') : ''; // Lastname $familyname = $profile->get('foaf:familyName') != null ? $profile->get('foaf:familyName') : ''; // Picture $picture = $_SESSION['myprofile']->get_picture(); // Nickname $nick = $profile->get('foaf:nick') != null ? $profile->get('foaf:nick') : ''; // Pingback endpoint $pingback = $profile->get('pingback:to') != null ? $profile->get('pingback:to') : ''; // Multiple values // Email addresses $emails = ''; if ($profile->get('foaf:mbox') != null) { foreach ($profile->all('foaf:mbox') as $email) { $emails .= "<tr><td>Email: </td><td><input type=\"text\" size=\"50\" maxlength=\"64\" value=\"" . clean_mail($email) . "\" name=\"foaf:mbox[]\"></td></tr>\n"; } } else { // Should still display the email field by default $emails .= "<tr><td>Email: </td><td><input type=\"text\" size=\"50\" maxlength=\"64\" value=\"\" name=\"foaf:mbox[]\"></td></tr>\n"; } // SHA1 sums $sha1sums = ''; if ($profile->get('foaf:mbox_sha1sum') != null) { foreach ($profile->all('foaf:mbox_sha1sum') as $sha1) { $sha1sums .= "<tr><td>Email SHA1SUM: </td><td><input type=\"text\" size=\"50\" maxlength=\"64\" value=\"" . $sha1 . "\" name=\"foaf:mbox_sha1sum[]\"></td></tr>\n"; } } // sameAs $sameAs = ''; if ($profile->get('owl:sameAs') != null) {
function viewProfile($graph, $profile, $webid, $base_uri) { // main table with one row which holds data in the left cell, and pics in the right cell $ret = ""; $ret .= "<table align=\"center\" border=\"0\">\n"; $ret .= "<tr><td>"; $ret .= "<table border=\"0\">"; // identity $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Identity: </h3>"; $ret .= "<a href=\"" . $webid . "\">{$webid}</a>"; $ret .= "</td>"; $ret .= "</tr>\n"; // name $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Full name: </h3>"; $ret .= ""; if ($profile->get("foaf:name") != null) { $ret .= $profile->get("foaf:name"); } else { $first = $profile->get('foaf:givenName'); $last = $profile->get('foaf:familyName'); $name = ''; if ($first != null) { $name .= $first . ' '; } if ($last != null) { $name .= $last; } if (strlen($name) == 0) { $ret .= $name; } else { $ret .= 'Anonymous'; } } $ret .= ""; $ret .= "</td>"; $ret .= "</tr>\n"; // nickname if ($profile->get("foaf:nick") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Nickname: </h3>"; $ret .= "<dd>" . $profile->get("foaf:nick") . "</dd>"; $ret .= "</td>"; $ret .= "</tr>\n"; } // b-day if ($profile->get("foaf:birthday") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Birthday: </h3>"; $ret .= "<dd>" . $profile->get("foaf:birthday") . "</dd>"; $ret .= "</td>"; $ret .= "</tr>\n"; } // contact info if ($profile->get("http://www.w3.org/2000/10/swap/pim/contact#home") != null) { $ret .= "<tr valign=\"top\">"; foreach ($profile->all('http://www.w3.org/2000/10/swap/pim/contact#home') as $cont) { $ret .= "<td><h3 class=\"profileHeaders\">Contact info: </h3>"; $contres = $graph->resource($cont); $address = $graph->resource($contres->get('http://www.w3.org/2000/10/swap/pim/contact#address')); $ret .= "<dd><h3 class=\"profileHeaders\">Street</h3> " . $address->get('http://www.w3.org/2000/10/swap/pim/contact#street') . "</dd>\n"; $ret .= "<dd><h3 class=\"profileHeaders\">City</h3> " . $address->get('http://www.w3.org/2000/10/swap/pim/contact#city') . "</dd>\n"; $ret .= "<dd><h3 class=\"profileHeaders\">Zip code</h3> " . $address->get('http://www.w3.org/2000/10/swap/pim/contact#postalCode') . "</dd>\n"; $ret .= "<dd><h3 class=\"profileHeaders\">Country</h3> " . $address->get('http://www.w3.org/2000/10/swap/pim/contact#country') . "</dd>\n"; $ret .= "</td>"; } $ret .= "</tr>\n"; } // email if ($profile->get("foaf:mbox") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Email: </h3>"; foreach ($profile->all("foaf:mbox") as $mail) { $ret .= "<dd>" . clean_mail($mail) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // mbox_sha1 if ($profile->get("foaf:mbox_sha1sum") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">mbox sha1sum: </h3>"; $ret .= "<dd>" . $profile->join("foaf:mbox_sha1sum", "<br>") . "</dd>"; $ret .= "</td>"; $ret .= "</tr>\n"; } // sameAs if ($profile->get("owl:sameAs") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Additional profiles: </h3>"; foreach ($profile->all("owl:sameAs") as $sameAs) { $ret .= "<dd>" . $graph->resource($sameAs) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // homepage if ($profile->get("foaf:homepage") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Homepage: </h3>"; foreach ($profile->all("foaf:homepage") as $homepage) { $ret .= "<dd>" . $graph->resource($homepage) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // blogs if ($profile->get("foaf:weblog") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Blog: </h3>"; foreach ($profile->all("foaf:weblog") as $blog) { $ret .= "<dd>" . $graph->resource($blog) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // workplaceHomepage if ($profile->get("foaf:workplaceHomepage") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Workplace Homepage: </h3>"; foreach ($profile->all("foaf:workplaceHomepage") as $workpage) { $ret .= "<dd>" . $graph->resource($workpage) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // schoolHomepage if ($profile->get("foaf:schoolHomepage") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">School Homepage: </h3>"; foreach ($profile->all("foaf:schoolHomepage") as $schoolpage) { $ret .= "<dd>" . $graph->resource($schoolpage) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // current proj if ($profile->get("foaf:currentProject") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Current projects: </h3>"; foreach ($profile->all("foaf:currentProject") as $currproj) { $ret .= "<dd>" . $graph->resource($currproj) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // past proj if ($profile->get("foaf:pastProject") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Past projects: </h3>"; foreach ($profile->all("foaf:pastProject") as $pastproj) { $ret .= "<dd>" . $graph->resource($pastproj) . "</dd>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // rss feeds if ($profile->get("foaf:rssFeed") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">RSS feeds: </h3>"; foreach ($profile->all('foaf:rssFeed') as $rss) { // each feed is a separate resource $contres = $graph->resource($rss); if ($contres->get('http://purl.org/rss/1.0/title') != null) { $ret .= "<dd><h3 class=\"profileHeaders\">Title</h3> " . $contres->get('http://purl.org/rss/1.0/title') . "</dd>\n"; } if ($contres->get('http://purl.org/rss/1.0/link') != null) { $ret .= "<dd><h3 class=\"profileHeaders\">Link</h3> <a href=\"" . $contres->get('http://purl.org/rss/1.0/link') . "\">" . $contres->get('http://purl.org/rss/1.0/link') . "</a></dd>\n"; } if ($contres->get('http://purl.org/rss/1.0/description') != null) { $ret .= "<dd><h3 class=\"profileHeaders\">Description</h3> " . $contres->get('http://purl.org/rss/1.0/description') . "</dd>\n"; } $ret .= "<br/>\n"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // holds account if ($profile->get("foaf:holdsAccount") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Holds account: </h3>"; foreach ($profile->all('foaf:holdsAccount') as $accounts) { // each account is a separate resource $account = $graph->resource($accounts); if ($account->get("rdfs:label") != null) { $ret .= "<dd>" . $account->get("rdfs:label") . "</dd>"; } if ($account->get("foaf:accountProfilePage") != null) { $ret .= "<dd>" . $account->get("foaf:accountProfilePage") . "</dd>\n"; } if ($account->get("foaf:accountServiceHomepage") != null) { $ret .= "<dd>" . $account->get("foaf:accountServiceHomepage") . "</dd>"; } $ret .= "<br/>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // interests if ($profile->get("foaf:interest") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Interests: </h3>"; foreach ($profile->all('foaf:interest') as $interests) { // each interest is a separate resource $interest = $graph->resource($interests); $label = $interest->label() == null ? $interest->toString() : $interest->label(); $ret .= "<dd><a href=\"" . $interest->toString() . "\">" . $label . "</a></dd>\n"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // foaf:knows if ($profile->get("foaf:knows") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td align=\"left\"><h3 class=\"profileHeaders\">Knows: </h3></td>"; $ret .= "</tr>\n"; $ret .= "<tr>\n"; $ret .= "<td id=\"knows\">\n"; $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]; $("#knows").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 .= "You do not have any friends.\n"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // public keys if ($profile->get("wot:hasKey") != null) { $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Public key: </h3>"; foreach ($profile->all('wot:hasKey') as $keys) { // each key is a separate resource $key = $graph->resource($keys); if ($key->get("wot:fingerprint") != null) { $ret .= "<dd><h3 class=\"profileHeaders\">Fingerprint:</h3></dd><dd>" . $key->get("wot:fingerprint") . "</dd>\n"; } if ($key->get("wot:hex_id") != null) { $ret .= "<dd><h3 class=\"profileHeaders\">Hex ID:</h3></dd><dd>" . $key->get("wot:hex_id") . "</dd>"; } $ret .= "<br/>"; } $ret .= "</td>"; $ret .= "</tr>\n"; } // certificates $ret .= "<tr valign=\"top\">"; $ret .= "<td><h3 class=\"profileHeaders\">Certificates: </h3>"; foreach ($graph->allOfType('http://www.w3.org/ns/auth/cert#RSAPublicKey') as $cert) { // get corresponding resources for modulus and exponent if ($cert->isBnode() == true) { $bnode = $graph->resource($cert); $hex = $bnode->getLiteral('http://www.w3.org/ns/auth/cert#modulus'); $exp = $bnode->getLiteral('http://www.w3.org/ns/auth/cert#exponent'); } else { $hex = $cert->get('http://www.w3.org/ns/auth/cert#modulus'); $exp = $cert->get('http://www.w3.org/ns/auth/cert#exponent'); } $ret .= "<dd><h3 class=\"profileHeaders\">Modulus:</h3></dd><dd>" . wordwrap($hex, 70, "<br />\n", 1) . "</dd><br/>\n"; $ret .= "<dd><h3 class=\"profileHeaders\">Public exponent:</h3></dd><dd>" . $exp . "</dd>\n"; $ret .= "<br/>\n"; } $ret .= "</tr>\n"; $ret .= "</table>\n"; // load all pictures $ret .= "</td>"; $ret .= "<td valign=\"top\">"; foreach ($profile->all("foaf:img") as $picture) { $ret .= "<img width=\"200\" src=\"" . $picture . "\"></img>\n"; $ret .= "<br/><br/>\n"; } foreach ($profile->all("foaf:depiction") as $picture) { $ret .= "<img width=\"200\" src=\"" . $picture . "\"></img>\n"; $ret .= "<br/><br/>\n"; } foreach ($profile->all("foaf:logo") as $logo) { $ret .= "<img width=\"200\" src=\"" . $logo . "\"></img>\n"; $ret .= "<br/><br/>\n"; } $ret .= "</td>\n"; $ret .= "</tr>\n"; $ret .= "</table>\n"; return $ret; }
function recover($webid) { // hexa string of 20 chars $hash = sha1(trim($webid) . uniqid(microtime(true), true)); $webid = trim($webid); // find if a recovery email exists or not for the given WebID $query = "SELECT email FROM recovery WHERE webid='" . mysql_real_escape_string($webid) . "'"; $result = mysql_query($query); if (!$result) { die('Unable to connect to the database!'); } else { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $email = $row['email']; mysql_free_result($result); // set the hash $query = "UPDATE recovery SET " . "recovery_hash='" . $hash . "' " . "WHERE webid='" . mysql_real_escape_string($webid) . "'"; $result = mysql_query($query); if (!$result) { return error('Unable to connect to the database!'); } else { // send the email $person = new MyProfile(trim($webid), BASE_URI, SPARQL_ENDPOINT); $person->load(); $to_name = $person->get_name(); $from = 'MyProfile Recovery System <' . SMTP_USERNAME . '>'; $to = '"' . $to_name . '" <' . clean_mail($email) . '>'; $subject = 'Instructions to recover your account on ' . BASE_URI . '.'; $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array('host' => SMTP_SERVER, 'auth' => SMTP_AUTHENTICATION, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD)); $message = '<html><body>'; $message .= '<p>Hello ' . $to_name . ',</p>'; $message .= '<p>You have requested to recover your personal account on ' . BASE_URI . '. '; $message .= 'Please click <a href="' . BASE_URI . '/recovery?recovery_code=' . $hash . '">' . BASE_URI . '/recovery?recovery_code=' . $hash . '</a> to proceed.</p>'; $message .= '<p>Alternatively, you can recover your account by visiting this page: <a href="' . BASE_URI . '/recovery">' . BASE_URI . '/recovery</a> and typing or pasting the following recovery code:</p>'; $message .= '<p>'; $message .= '<strong>' . $hash . '</strong> '; $message .= '</p>'; $message .= '<p>Important! Do not forget that once you are logged in, you can obtain a new certificate by going to your <a href="https://my-profile.eu/view">profile page</a> and then clicking on the "Certificate" icon under "Actions for this profile".</p>'; $message .= '<br /><p><hr /></p>'; $message .= '<p><small>This is an automated email generate by <a href="https://my-profile.eu/">MyProfile</a> and you do not need to respond to it.</small></p>'; $message .= '</body></html>'; $crlf = "\n"; $mime = new Mail_Mime(array('eol' => $crlf)); $mime->setHTMLBody($message); $mimeparams = array(); $mimeparams['html_charset'] = "UTF-8"; $mimeparams['head_charset'] = "UTF-8"; $headers = $mime->headers($headers); $body = $mime->get($mimeparams); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { $ret .= error('Sendmail: ' . $mail->getMessage()); } return success('An email has been sent to the recovery address you have specified.'); } } else { return error('You did not provide a recovery email address!'); } } }