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); } } }
function render_partial(&$request, $template) { trigger_before('render_partial', $this, $this); // content_for_layout() passes the $request->action as $template $ext = $this->pick_template_extension($request, $template); $view = $request->get_template_path($ext, $template); if ($template == 'get') { $template = 'index'; } if (file_exists($view)) { $action = "_" . $template; } else { $action = $template; } global $db; if (file_exists($view) && function_exists($action)) { trigger_before($request->action, $request, $db); $result = $action(array_merge($this->named_vars, $db->get_resource())); trigger_after($request->action, $request, $db); if (is_array($result)) { extract($result); } if (!$this->header_sent) { $content_type = 'Content-Type: ' . $this->pick_content_type($ext); if ($this->pick_content_charset($ext)) { $content_type .= '; charset=' . $this->pick_content_charset($ext); } header($content_type); $this->header_sent = true; } include $view; } else { // no template, check for blobcall if (in_array(type_of($ext), mime_types()) && !$this->header_sent) { $model =& $db->get_table($request->resource); if (isset($model->blob)) { $template = $model->blob; } trigger_before($request->action, $request, $db); $Member = $this->collection->MoveFirst(); render_blob($Member->{$template}, $ext); } else { if (strpos($request->uri, 'robots') === false || strpos($request->uri, 'crawl') === false) { admin_alert($request->uri . " {$view} {$action} " . $_SERVER[REMOTE_HOST]); } } } }
function set_categories(&$rec, &$req, &$atomentry) { global $db; $req->set_param('id', $rec->id); $req->id = $rec->id; $Category =& $db->model('Category'); $Entry =& $db->model('Entry'); foreach ($req->params as $cname => $catval) { if (substr($cname, 0, 8) == 'category') { $added = array(); if (!in_array($req->{$cname}, $added)) { $join =& $db->get_table($Entry->join_table_for('categories', 'entries')); $j = $join->base(); $j->set_value('entry_id', $atomentry->id); $c = $Category->find_by('term', $req->{$cname}); if ($c) { $j->set_value('category_id', $c->id); $j->save_changes(); $added[] = $req->{$cname}; } elseif (!empty($req->{$cname})) { if (isset_admin_email()) { $c = $Category->base(); $c->set_value('name', strtolower($req->{$cname})); $c->set_value('term', strtolower($req->{$cname})); $c->save(); $j->set_value('category_id', $c->id); $j->save_changes(); $added[] = $req->{$cname}; admin_alert("created a new category: " . $req->{$cname} . " at " . $req->base); } else { trigger_error("Sorry, I could not create the new Category because the administrator e-mail address has not been set.", E_USER_ERROR); } } } } } }
function _edit(&$vars) { // bring controller vars into scope extract($vars); if ($request->error) { $Member = session_restore($db->models['groups']); } else { $Member = $Group->find($request->id); } $Entry = $Member->FirstChild("entries"); if (empty($Entry->etag)) { $Member->set_etag(); $Member = $Group->find($request->id); $Entry = $Member->FirstChild("entries"); } $subscribers = ""; $arr = resource_group_members($Member->id); $avatars = array(); foreach ($arr as $member_ident) { $subscribers .= htmlentities($member_ident->email_value) . "\n"; $avatars[$member_ident->person_id] = $member_ident->avatar; } // custom controller adds $group_perms named variable $group_perms = array(); foreach ($db->models as $model) { foreach ($model->access_list as $permission => $values) { foreach ($values as $fieldname => $listofgroups) { if (in_array($Member->name, $listofgroups)) { if (!is_array($group_perms[$model->table])) { $group_perms[$model->table] = array(); } if (empty($model->table)) { admin_alert("table name not set for object " . get_class($model)); } $group_perms[$model->table][$permission] = $values; break; } } } } return vars(array(&$avatars, &$Member, &$Entry, &$group_perms, &$subscribers), get_defined_vars()); }
// http://abrah.am lib_include('twitteroauth'); global $db; $TwitterUser =& $db->model('TwitterUser'); $tu = $TwitterUser->find($tuid); if ($tu) { $latest = false; $key = $tu->oauth_key; $secret = $tu->oauth_secret; $consumer_key = environment('twitterKey'); $consumer_secret = environment('twitterSecret'); $to = new TwitterOAuth($consumer_key, $consumer_secret, $tu->oauth_key, $tu->oauth_secret); $timelineurl = 'https://twitter.com/statuses/friends_timeline.atom'; if ($options[1]['last_id']) { $timelineurl .= '?since_id=' . $options[1]['last_id'] . '&count=200'; admin_alert('starting from ' . $options[1]['last_id'] . ' for ' . $tu->screen_name); } $data = $to->OAuthRequest($timelineurl, array(), 'GET'); $xmlarray = array(); $xmlarray = xml2array($data, $get_attributes = 1, $priority = 'value'); if (count($xmlarray)) { $sincespl = split(":", $xmlarray['feed']['entry'][0]['id']['value']); $sincespl2 = split("/", $sincespl[3]); if (isset($sincespl2[5]) && $sincespl2[5] > 0) { $latest = $sincespl2[5]; if (isset($xmlarray['feed']['entry'])) { foreach ($xmlarray['feed']['entry'] as $entry) { global $request, $db; $Post =& $db->model('Post'); if (isset($entry['title']['value'])) { $u = add_tweet_user($entry);
$Feed->set_limit(1000); $Feed->find(); if ('' == get_option('cloud_domain')) { set_default_omb_cloud_options(); } while ($f = $Feed->MoveNext()) { $dow = date("w", time()); if ($dow != $f->day_of_sub && !empty($f->cloud_domain)) { $f->set_value('day_of_sub', $dow); $f->save_changes(); $subscribe_url = "http://" . $f->cloud_domain . ":" . $f->cloud_port . "" . $f->cloud_path . ""; $params = array('notifyProcedure' => get_option('cloud_function'), 'port' => get_option('cloud_port'), 'path' => '/api/rsscloud/callback', 'protocol' => get_option('cloud_protocol'), 'url1' => $f->xref, 'domain' => get_option('cloud_domain')); require_once ABSPATH . WPINC . '/class-snoopy.php'; $snoop = new Snoopy(); $snoop->submit($subscribe_url, $params); admin_alert("rssCloud renew: " . $f->title); } } exit; //[id] => 544591116 // [url] => http://www.facebook.com/Timoreilly // [name] => Tim O'Reilly // [pic_square] => http://profile.ak.fbcdn.net/v52/52/103/q544591116_1716.jpg // [type] => user function add_facebook_user($data) { global $db; $Identity =& $db->model('Identity'); $Person =& $db->model('Person'); $FacebookUser =& $db->model('FacebookUser'); $faceuser = $FacebookUser->find_by('facebook_id', $_SESSION['fb_userid']);