示例#1
0
function broadcast_email_notice(&$model, &$rec)
{
    if (!isset($rec->title)) {
        return;
    }
    global $request, $db;
    $i = owner_of($rec);
    $sent_to = array();
    $Subscription = $db->model('Subscription');
    $Subscription->has_one('subscriber:identity');
    $where = array('subscriptions.subscribed' => $i->id);
    $Subscription->set_param('find_by', $where);
    $Subscription->find();
    while ($sub = $Subscription->MoveNext()) {
        $sid = $sub->FirstChild('identities');
        if (!in_array($sid->id, $sent_to) && $sub->email) {
            $html = false;
            // this is the body of the e-mail if ($html == false)
            $text = $rec->title;
            $subject = $i->nickname . " posted a notice";
            send_email($sid->email_value, $subject, $text, environment('email_from'), environment('email_name'), $html);
            $sent_to[] = $sid->id;
        }
    }
}
示例#2
0
function broadcast_sms_notice(&$model, &$rec)
{
    $smskey = environment('zeepAccessKey');
    if (empty($smskey)) {
        return;
    }
    if (!isset($rec->title)) {
        return;
    }
    global $request, $db;
    $i = owner_of($rec);
    $notice_content = substr($rec->title, 0, 100);
    $sent_to = array();
    $Subscription = $db->model('Subscription');
    $Subscription->has_one('subscriber:identity');
    $where = array('subscriptions.subscribed' => $i->id);
    $Subscription->set_param('find_by', $where);
    $Subscription->find();
    while ($sub = $Subscription->MoveNext()) {
        $sid = $sub->FirstChild('identities');
        if (!in_array($sid->id, $sent_to) && $sub->sms) {
            $sent_to[] = $sid->id;
            $apiurl = environment('zeepUrl');
            $secret = environment('zeepSecretKey');
            $apikey = environment('zeepAccessKey');
            $http_date = gmdate(DATE_RFC822);
            $parameters = "user_id=" . $sid->id . "&body=" . urlencode($notice_content);
            $canonical_string = $apikey . $http_date . $parameters;
            $b64_mac = base64_encode(hash_hmac("sha1", $canonical_string, $secret, TRUE));
            $authentication = "Zeep {$apikey}:{$b64_mac}";
            $header = array("Authorization: " . $authentication, "Date: " . $http_date, "Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strval(strlen($parameters)));
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $apiurl);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
            $response = curl_exec($ch);
            //echo $response; exit;
            curl_close($ch);
        }
    }
}
示例#3
0
function post_as_notice(&$vars)
{
    extract($vars);
    $Member = $Auction->find($request->id);
    $o = owner_of($Member);
    if (!($o->id == get_profile_id())) {
        trigger_error('your profile id does not match the owner of the auction', E_USER_ERROR);
    }
    $adsrc = '
  
  <div style="background-color:#ddd; padding:15px; margin:15px;">

  <p>' . $Member->headline . '</p>

  <p>' . $Member->body . '</p>

  <ul style="list-style: square; margin-left: 20px; margin-top: 0px;">';
    while ($bullet = $Member->NextChild("auction_bullets")) {
        $adsrc .= '  <li>' . $bullet->bullet . '</li>';
    }
    $adsrc .= '</ul>

  <p>
    ' . $Member->close . '
  </p>';
    while ($photo = $Member->NextChild("auction_photos")) {
        $adsrc .= '  <img src="' . $request->url_for(array("resource" => "auction_photos", "id" => $photo->id, "action" => "photo.jpg")) . '" border="0" />';
    }
    $adsrc .= '</div>';
    $p = $Post->base();
    $p->set_value('profile_id', $o->id);
    $p->set_value('parent_id', 0);
    $p->set_value('title', $Member->headline);
    $p->set_value('body', $adsrc);
    $p->save_changes();
    $p->set_etag();
    header_status('200 OK');
    redirect_to($request->base);
}
示例#4
0
function broadcast_omb_notice(&$model, &$rec)
{
    if (!isset($rec->title) || !isset($rec->uri)) {
        return;
    }
    global $request, $db;
    if (empty($rec->uri)) {
        $rec->set_value('uri', $request->url_for(array('resource' => '__' . $rec->id)));
        $rec->save_changes();
    }
    wp_plugin_include(array('wp-oauth'));
    $i = owner_of($rec);
    $listenee_uri = $i->profile;
    $notice_uri = $rec->uri;
    $notice_content = substr($rec->title, 0, 140);
    $notice_url = $notice_uri;
    $license = $i->license;
    $sent_to = array();
    $Subscription = $db->model('Subscription');
    $Subscription->has_one('subscriber:identity');
    $where = array('subscriptions.subscribed' => $i->id);
    $Subscription->set_param('find_by', $where);
    $Subscription->find();
    while ($sub = $Subscription->MoveNext()) {
        $sub_token = trim($sub->token);
        $sub_secret = trim($sub->secret);
        $sid = $sub->FirstChild('identities');
        $url = $sid->post_notice;
        if (!in_array($url, $sent_to) && !empty($url) && !strstr($url, $request->base)) {
            $sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
            $wp_plugins = "wp-plugins" . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "enabled";
            $path = plugin_path() . $wp_plugins . DIRECTORY_SEPARATOR . 'wp-openid' . DIRECTORY_SEPARATOR;
            add_include_path($path);
            require_once "Auth/Yadis/Yadis.php";
            $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
            //for ($i=0;$i<5;$i++) {
            $consumer = new OAuthConsumer($request->base, '');
            $token = new OAuthToken($sub_token, $sub_secret);
            $parsed = parse_url($url);
            $params = array();
            parse_str($parsed['query'], $params);
            $req = OAuthRequest::from_consumer_and_token($consumer, $token, "POST", $url, $params);
            $req->set_parameter('omb_version', OMB_VERSION);
            $req->set_parameter('omb_listenee', $listenee_uri);
            $req->set_parameter('omb_notice', $notice_uri);
            $req->set_parameter('omb_notice_content', $notice_content);
            $req->set_parameter('omb_notice_url', $notice_url);
            $req->set_parameter('omb_notice_license', $license);
            $req->sign_request($sha1_method, $consumer, $token);
            $result = $fetcher->post($req->get_normalized_http_url(), $req->to_postdata());
            if ($result->status == 403) {
                $db->delete_record($sub);
            } else {
                parse_str($result->body, $return);
                if (is_array($return) && $return['omb_version'] == OMB_VERSION) {
                    $sent_to[] = $url;
                } else {
                    admin_alert('failed to post' . "\n\n" . $url . "\n\n" . $result->body . "\n\n" . $notice_content);
                }
            }
            //}
            // this is the old CURL version of omb_notice
            //$curl = curl_init($url);
            //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
            //curl_setopt($curl, CURLOPT_HEADER, false);
            //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            //curl_setopt($curl, CURLOPT_POST, true);
            //curl_setopt($curl, CURLOPT_POSTFIELDS, $req->to_postdata());
            //curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            //$result = curl_exec($curl);
            //curl_close($curl);
        }
    }
}
示例#5
0
function send_email_notice(&$model, &$rec)
{
    global $db;
    global $request;
    if (!(get_profile_id() && $request->resource == 'groups')) {
        return;
    }
    // get data modesl for 3 tables
    $Entry =& $db->get_table('entries');
    $Group =& $db->get_table('groups');
    $Person =& $db->get_table('people');
    // load the first 20 records from the groups table
    $Group->find();
    // keep a list of people we have notified
    $sent_to = array();
    // get the name of the table from the data model reference we received
    $notify_table = $model->table;
    // get the primary key value of the record reference we received
    $notify_id = $rec->id;
    // if the table that was modified is a metadata table (comments, reviews)
    // notify about the "target" table being modified
    if (array_key_exists('target_id', $model->field_array)) {
        $e = $Entry->find($rec->attributes['target_id']);
        if ($e) {
            $notify_table = $e->resource;
            $notify_id = $e->record_id;
        }
    }
    // get the data model we are notifying about
    $datamodel =& $db->get_table($notify_table);
    // get the profile data for the current user
    $profile = owner_of($rec);
    // loop over each group
    while ($g = $Group->MoveNext()) {
        if (in_array($g->name, array('administrators', 'everyone', 'members'))) {
            continue;
        }
        // if the GROUP has READ or CREATE then do notify its members
        if ($rec->id && (in_array($g->name, $datamodel->access_list['read']['id']) || in_array($g->name, $datamodel->access_list['create'][$notify_table]))) {
            // loop over each member in the group
            while ($m = $g->NextChild('memberships')) {
                // get a person activerecord object for the member's person_id
                $p = $Person->find($m->person_id);
                if ($p) {
                    $action = $request->action;
                    $notify = "notify_" . $action;
                    // get an identities activerecord object for the person's first identity
                    // this is an example of traversing the result dataset without re-querying
                    $i = $p->FirstChild('identities');
                    // if we haven't already sent this person a message
                    if (isset($m->{$notify}) && $m->{$notify} && is_email($i->email_value) && !in_array($i->email_value, $sent_to)) {
                        // a token may be set to allow the notify-ee to "EXPRESS" register as a new site user
                        // it fills in some of the "new user" form info such as e-mail address for them
                        if (isset($i->token) && strlen($i->token) > 0) {
                            $addr = $request->url_for(array('resource' => $notify_table, 'id' => $notify_id, 'ident' => $i->token));
                        } else {
                            $addr = $request->url_for(array('resource' => $notify_table, 'id' => $notify_id));
                        }
                        // this is the HTML content of the e-mail
                        $html = ' 
            <!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.0 Transitional//EN\\"> 
            <html> 
            <body> 
            <br /> 
            <b><u><i>Click on this link:</i></u></b><br /> 
            <br />
            <font color="red"><a href="' . $addr . '">' . $addr . '</a></font> 
            </body> 
            </html>';
                        // oh wait, we are not going to send the HTML it is just wasting space for now
                        // comment this out to try the HTML yourself
                        $html = false;
                        // this is the body of the e-mail if ($html == false)
                        $text = 'Content was updated at the following location:' . "\r\n\r\n" . $addr . "\r\n\r\n";
                        // change the e-mail subject line depending on what action took place
                        if ($action == 'post') {
                            $actionmessage = " created a new ";
                        } elseif ($action == 'put') {
                            $actionmessage = " updated a ";
                        } elseif ($action == 'delete') {
                            $actionmessage = " deleted a ";
                        }
                        // set the e-mail subject to the current user's first name
                        // classify() converts a table name "nerds" to "Nerd"
                        // the converse is tableize()
                        $subject = $profile->given_name . $actionmessage . classify($request->resource);
                        // this sends e-mail using the xpertmailer package
                        // the environment() function reads a value from the config.yml file
                        send_email($i->email_value, $subject, $text, environment('email_from'), environment('email_name'), $html);
                        // add a new entry to the list of successful (more like woeful) recipients
                        $sent_to[] = $i->email_value;
                    }
                }
            }
        }
    }
}
示例#6
0
function send_ping(&$model, &$rec)
{
    if (!PING) {
        return;
    }
    global $db;
    global $request;
    $req =& $request;
    $Entry =& $db->get_table('entries');
    $notify_table = $model->table;
    $recid = $rec->id;
    if (!empty($db->prefix)) {
        $chan = $db->prefix;
    } else {
        $chan = "chan";
    }
    if (REALTIME_HOST) {
        $o = owner_of($rec);
        $payload = array();
        if (environment('threaded') && isset($rec->parent_id) && $rec->parent_id > 0) {
            // push a P2 comment
            $par = $db->get_record('posts', $rec->parent_id);
            $tweet = render_comment($rec, $o, $par);
            $payload['html'] = $tweet;
            if ($rec->parent_id > 0) {
                $payload['in_reply_to'] = "#commentcontent-" . $rec->parent_id;
            } else {
                $payload['in_reply_to'] = "#content-" . $rec->parent_id;
            }
        } else {
            // push a P2 tweet
            $o = owner_of($rec);
            $tweet = '<hr />' . "\n";
            $tweet .= '<h4>' . "\n";
            $tweet .= '<span class="meta"> <span class="actions"> <a href="' . $request->url_for(array('resource' => $notify_table, 'id' => $recid)) . '" class="thepermalink">Permalink</a> | <a href="' . $request->url_for(array('resource' => $notify_table, 'id' => $recid)) . '" class="post-reply-link" rel="' . $recid . '">Reply</a> <br />' . "\n";
            $tweet .= '</span> <br />' . "\n";
            $tweet .= '<img alt="" src="' . $o->avatar . '" class="avatar avatar-48" height="48" width="48" /> <a class="nick" href="' . $o->profile . '" title="Posts by ' . $o->nickname . '">' . $o->nickname . '</a> ' . laconica_time($rec->created) . ' | <a href="">0</a> </span>' . "\n";
            $tweet .= '</h4>' . "\n";
            $tweet .= '<div class="postcontent" id="content-<?php echo $recid; ">' . "\n";
            $tweet .= '<p>' . "\n";
            $tweet .= render_notice($rec->title, $rec, $o);
            $tweet .= '</p>' . "\n";
            $tweet .= '</div>' . "\n";
            $tweet .= '<!-- // postcontent -->' . "\n";
            $tweet .= '<div class="bottom_of_entry">' . "\n";
            $tweet .= '&nbsp;' . "\n";
            $tweet .= '</div>' . "\n";
            $tweet .= '<div class="commentlist">' . "\n";
            $tweet .= '</div>' . "\n";
            $oldstyle = false;
            if ($oldstyle) {
                $tweet = '';
                $tweet .= '<li id="prologue-' . $rec->id . '" class="user_id_' . $o->id . '">';
                $tweet .= '<img alt=\'\' src=\'' . $o->avatar . '\' class=\'avatar avatar-48\' height=\'48\' width=\'48\' />';
                $tweet .= '<h4>';
                $tweet .= '<a href="' . $o->profile . '" title="Posts by ' . $o->nickname . '">' . $o->nickname . '</a>    <span class="meta">' . date("g:i A", strtotime($rec->created)) . '<em>on</em> ' . date(get_settings('date_format'), strtotime($rec->created)) . ' |';
                $tweet .= '        <span class="actions">';
                $tweet .= '    <a href="' . $request->url_for(array('resource' => $notify_table, 'action' => 'entry.html', 'id' => $recid)) . '" class="thepermalink">Permalink</a>';
                $tweet .= '                  </span>';
                $tweet .= '  <br />';
                $tweet .= '          </span>';
                $tweet .= '  </h4>';
                $tweet .= '  <div class="postcontent" id="content-' . $rec->id . '"><p>' . render_notice($rec->title, $rec, $o) . '</p></div>';
                $tweet .= '    <div class="bottom_of_entry">&nbsp;</div>';
                $tweet .= '   <ul class="commentlist">';
                //      $tweet .= '   <ul id="comments" class="commentlist">';
                $tweet .= '  </ul>';
                $tweet .= '</li>';
            }
            $payload['html'] = $tweet;
            $payload['in_reply_to'] = 0;
        }
        if (!class_exists('Services_JSON')) {
            lib_include('json');
        }
        $json = new Services_JSON();
        $load = $json->encode($payload);
        $curl = curl_init("http://" . REALTIME_HOST . ":" . REALTIME_PORT);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 1);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'ADDMESSAGE ' . $chan . ' ' . addslashes($load));
        $output = curl_exec($curl);
    }
    if (!get_profile_id()) {
        return;
    }
    if (array_key_exists('target_id', $model->field_array)) {
        $e = $Entry->find($rec->attributes['target_id']);
        if ($e) {
            $notify_table = $e->resource;
            $recid = $e->record_id;
        }
    }
    $url = environment('ping_server');
    if (empty($url)) {
        return;
    }
    $url .= "=" . $request->url_for(array('resource' => $notify_table, 'action' => 'entry.html', 'id' => $recid));
    $curl = curl_init($url);
    $method = "GET";
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_HTTPGET, $method == "GET");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
}
示例#7
0
function the_post()
{
    global $wpmode;
    global $wphaved;
    if ($wpmode == 'other') {
        if (!$wphaved) {
            $wphaved = true;
            return true;
        }
        return false;
    }
    global $the_post, $response, $the_author, $the_entry, $request;
    $the_post = $response->collection->MoveNext();
    if (isset($the_post->profile_id) && $the_post->table == 'posts') {
        $the_author = get_profile($the_post->profile_id);
    } else {
        global $db;
        $Identity =& $db->model('Identity');
        if ($the_post) {
            $the_entry = $the_post->FirstChild('entries');
            if ($the_entry && $the_entry->person_id) {
                $the_author = owner_of($the_post);
            } else {
                $the_author = $Identity->base();
            }
        } else {
            $Post =& $db->model('Post');
            $the_post = $Post->base();
            $the_author = $Identity->base();
        }
    }
    if (!empty($the_author->profile_url)) {
        $the_author->profile = $the_author->profile_url;
    }
    global $comment_author;
    global $comment_author_email;
    global $comment_author_url;
    $comment_author = $the_author->nickname;
    $comment_author_email = $the_author->email_value;
    $comment_author_url = $the_author->url;
    // show pretty URLs if not a Remote user
    if (empty($the_author->post_notice)) {
        $the_author->profile = $request->url_for(array('resource' => $the_author->nickname));
    }
    return "";
}
示例#8
0
function _oembed(&$vars)
{
    extract($vars);
    $width = $_GET['maxWidth'];
    $height = $_GET['maxHeight'];
    $id = array_pop(split("\\/", $_GET['url']));
    $version = '1.0';
    $p = $Post->find($id);
    $e = $p->FirstChild('entries');
    $title = $p->title;
    $o = owner_of($p);
    if (extension_for($e->content_type) == 'mp3') {
        $type = 'rich';
        // photo video link rich
        $url = $request->url_for(array('resource' => 'posts', 'id' => $id, 'action' => 'attachment.mp3'));
    } elseif (extension_for($e->content_type) == 'jpg') {
        $type = 'photo';
        $url = $request->url_for(array('resource' => 'posts', 'id' => $id, 'action' => 'preview'));
    } elseif (extension_for($e->content_type) == 'mov') {
        $type = 'video';
        $url = $request->url_for(array('resource' => 'posts', 'id' => $id, 'action' => 'attachment.mov'));
    } elseif (extension_for($e->content_type) == 'avi') {
        $type = 'video';
        $url = $request->url_for(array('resource' => 'posts', 'id' => $id, 'action' => 'attachment.avi'));
    } else {
        exit;
    }
    $author_name = $o->nickname;
    $author_url = $o->profile;
    $cache_age = 3600;
    $provider_name = "myphotos";
    $provider_url = $request->base;
    $thumbnail_url = 0;
    $thumbnail_width = 0;
    $thumbnail_height = 0;
    return vars(array(&$version, &$type, &$title, &$author_name, &$author_url, &$cache_age, &$provider_name, &$provider_url, &$width, &$height, &$thumbnail_url, &$thumbnail_width, &$thumbnail_height, &$url), get_defined_vars());
}