Example #1
0
 $result = mysql_query($query);
 if (!$result) {
     // 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>';
Example #2
0
function sendPing($to, $message, $base_uri, $verbose = false)
{
    $ret = "<br/>\n";
    $to = trim($to);
    // fetch the user's profile
    $person = new MyProfile($to, $base_uri, SPARQL_ENDPOINT);
    $person->load();
    $profile = $person->get_profile();
    $to_name = $person->get_name();
    $to_email = $person->get_email();
    $pingback_service = $profile->get("pingback:to");
    // set form data
    $source = $_SESSION['webid'];
    // parse the pingback form
    $config = array('auto_extract' => 0);
    $parser = ARC2::getSemHTMLParser($config);
    $parser->parse($pingback_service);
    $parser->extractRDF('rdfa');
    // load triples
    $triples = $parser->getTriples();
    // proceed only if the user has defined a pingback:to relation
    if ($pingback_service != null) {
        if (sizeof($triples) > 0) {
            //echo "<pre>" . print_r($triples, true) . "</pre>\n";
            foreach ($triples as $triple) {
                // proceed only if we have a valid pingback resource
                if ($triple['o'] == 'http://purl.org/net/pingback/Container') {
                    $fields = array('source' => $source, 'target' => $to, 'comment' => $message);
                    // Should really replace curl with an ajax call
                    //open connection to pingback service
                    $ch = curl_init();
                    //set the url, number of POST vars, POST data
                    curl_setopt($ch, CURLOPT_URL, $pingback_service);
                    curl_setopt($ch, CURLOPT_POST, count($fields));
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    //execute post
                    $return = curl_exec($ch);
                    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                    //close connection
                    curl_close($ch);
                    if ($httpCode == '201' || $httpCode == '202') {
                        $ret .= success('Message delivered!');
                    } else {
                        $ret .= error('Something happened and I couldn\'t deliver the message!');
                        $ret .= "<p>Details:</p>\n";
                        $ret .= "</p>" . $return . "</p>\n";
                    }
                    break;
                }
            }
        } else {
            $ret .= "   <p>{$pingback_service} does not comply with semantic pingback standards! Showing the pingback service page instead.</p>\n";
            // show frame
            $ret .= "   <iframe src=\"{$pingback_service}\" width=\"100%\" height=\"300\">\n";
            $ret .= "   <p>Your browser does not support iframes.</p>\n";
            $ret .= "   </iframe>\n";
        }
    } else {
        // no valid pingback service found, fallback to AKSW
        $ret .= "   <p>Could not find a pingback service for the given WebID. Here is a generic pingback service provided by http://pingback.aksw.org/.</p>\n";
        $ret .= "   <iframe src=\"http://pingback.aksw.org/\" width=\"100%\" height=\"300\">\n";
        $ret .= "   <p>Your browser does not support iframes.</p>\n";
        $ret .= "   </iframe>\n";
    }
    if ($verbose) {
        return $ret;
    }
}