function send_to_identica(&$model, &$rec) { if (!get_profile_id()) { return; } // if the Record does not have a title or uri, bail out if (!isset($rec->title) || !isset($rec->uri)) { return; } if (get_option('identica_status') != 'enabled') { return; } // truncate the tweet at 140 chars $notice_content = substr($rec->title, 0, 140); // activate Twitter Tools $_GET['activate'] = true; // trip the init() function aktt_init(); // get the Twitter Tools object global $aktt; // make a new tweet object $tweet = new aktt_tweet(); // set the tweetbody $tweet->tw_text = stripslashes($notice_content); // send the dent to Identica global $db; $aktt->twitter_username = get_option('aktt_identica_username'); $aktt->twitter_password = md5_decrypt(stripslashes(get_option('aktt_identica_password')), $db->dbname); do_dent($tweet); }
function View() { $this->named_vars = array(); $this->header_sent = false; global $db; global $request; $env =& environment(); if (isset($request->resource)) { $this->collection = new Collection($request->resource); } else { $this->collection = new Collection(null); } $this->named_vars['db'] =& $db; $this->named_vars['request'] =& $request; $this->named_vars['collection'] =& $this->collection; $this->named_vars['response'] =& $this; if (get_profile_id()) { $this->named_vars['profile'] =& get_profile(); } else { $this->named_vars['profile'] = false; } if (isset($request->resource) && $request->resource != 'introspection') { $this->named_vars['resource'] =& $db->get_table($request->resource); } else { $this->named_vars['resource'] = false; } $this->named_vars['prefix'] = $db->prefix; $this->controller = $request->controller; load_apps(); $controller_path = controller_path(); // check for a controller file in controllers/[resource].php if (isset($request->resource)) { $cont = $controller_path . $request->resource . ".php"; if (file_exists($cont)) { $this->controller = $request->resource . ".php"; } elseif (isset($request->templates_resource[$request->resource]) && file_exists($controller_path . $request->templates_resource[$request->resource] . ".php")) { $this->controller = $request->templates_resource[$request->resource] . ".php"; } else { if (isset($GLOBALS['PATH']['apps'])) { foreach ($GLOBALS['PATH']['apps'] as $k => $v) { if (file_exists($v['controller_path'] . $request->resource . ".php")) { $this->controller = $request->resource . ".php"; $controller_path = $v['controller_path']; } } } } } if (is_file($controller_path . $this->controller)) { require_once $controller_path . $this->controller; } else { trigger_error('Sorry, the controller was not found at ' . $controller_path . $this->controller, E_USER_ERROR); } if (!isset($env['content_types'])) { trigger_error('Sorry, the content_types array was not found in the configuration file', E_USER_ERROR); } $this->negotiator = HTTP_Negotiate::choose($env['content_types']); }
function _edit(&$vars) { extract($vars); $password = $Setting->find_by(array('name' => 'aktt_identica_password', 'profile_id' => get_profile_id())); if (!$password) { $password = $Setting->base(); $password->set_value('profile_id', get_profile_id()); $password->set_value('person_id', get_person_id()); $password->set_value('name', 'aktt_identica_password'); $password->save_changes(); $password->set_etag(); $password = $Setting->find($password->id); $pword = ""; } if (!empty($password->value)) { $pword = "******"; } // get the one-to-one-related child-record from "entries" $pEntry =& $password->FirstChild('entries'); $passurl = $request->url_for(array('resource' => 'settings', 'id' => $password->id, 'action' => 'put')); $username = $Setting->find_by(array('name' => 'aktt_identica_username', 'profile_id' => get_profile_id())); if (!$username) { $username = $Setting->base(); $username->set_value('profile_id', get_profile_id()); $username->set_value('person_id', get_person_id()); $username->set_value('name', 'aktt_identica_username'); $username->save_changes(); $username->set_etag(); $username = $Setting->find($username->id); } // get the one-to-one-related child-record from "entries" $uEntry =& $username->FirstChild('entries'); $userurl = $request->url_for(array('resource' => 'settings', 'id' => $username->id, 'action' => 'put')); $stat = $Setting->find_by(array('name' => 'identica_status', 'profile_id' => get_profile_id())); if (!$stat) { $stat = $Setting->base(); $stat->set_value('profile_id', get_profile_id()); $stat->set_value('person_id', get_person_id()); $stat->set_value('name', 'identica_status'); $stat->set_value('value', 'enabled'); $stat->save_changes(); $stat->set_etag(); $stat = $Setting->find($stat->id); } // get the one-to-one-related child-record from "entries" $sEntry =& $stat->FirstChild('entries'); $staturl = $request->url_for(array('resource' => 'settings', 'id' => $stat->id, 'action' => 'put')); $status = $stat->value; $akidentica_tw_text_options = array('disabled' => 'disabled', 'enabled' => 'enabled'); $RemoteServer =& $db->model('RemoteServer'); $RemoteServer->find(); $servers = array(); while ($r = $RemoteServer->MoveNext()) { $servers[] = $r; } return vars(array(&$servers, &$akidentica_tw_text_options, &$status, &$staturl, &$pword, &$userurl, &$passurl, &$password, &$sEntry, &$username, &$uEntry, &$pEntry, &$profile), get_defined_vars()); }
function delete(&$vars) { extract($vars); $s = $collection->MoveFirst(); if (!$s || $s->profile_id != get_profile_id()) { trigger_error('Sorry, the setting could not be deleted', E_USER_ERROR); } $resource->delete_from_post($request); header_status('200 OK'); redirect_to($request->resource); }
function broadcast_notifixious_notice(&$model, &$rec) { $notifixkey = ''; $login = '******'; $pass = ''; $notifixurl = 'notifixio.us'; if (!isset($rec->title)) { return; } if (!get_profile_id()) { return; } $installed = environment('installed'); if (!in_array('notifixious', $installed)) { return; } if (!class_exists('Services_JSON')) { lib_include('json'); } $url = "http://" . $notifixurl . "/sources/find.json"; $params = "url=" . urlencode(get_bloginfo('rss2_url')); $results = notifixious_http_request($url . "?" . $params, "GET"); $jsonobj = json_decode($results[1]); $source_id = $jsonobj->sources->source->permalink; if ($source_id != "") { update_option('notifixiousSourceId', '' . $source_id . '', '', 'no'); update_option('notifixiousRegistered', '1', '', 'no'); update_option('notifixiousClaimed', '0', '', 'yes'); } else { update_option('notifixiousSourceId', '0', '', 'no'); update_option('notifixiousRegistered', '0', '', 'no'); } $post = get_post($rec); $title = urlencode($post->post_title); $text = urlencode($post->post_content); $link = urlencode($post->guid); $url = "http://" . urlencode($login) . ":" . urlencode($pass) . "@" . $notifixurl . "/sources/" . $source_id . "/events.json?" . "event[title]=" . $title . "&event[text]=" . $text . "&event[link]=" . $link; echo $url; exit; //http://:@?event[title]=&event[text]=&event[link]= $arr = notifixious_http_request($url, "POST"); print_r($arr); exit; }
function send_to_twitter(&$model, &$rec) { if (!get_profile_id()) { return; } // if the Record does not have a title or uri, bail out if (!isset($rec->title) || !isset($rec->uri)) { return; } if (get_option('twitter_status') != 'enabled') { return; } global $db, $prefix; $sql = "SELECT oauth_key,oauth_secret FROM " . $prefix . "twitter_users WHERE profile_id = " . get_profile_id(); $result = $db->get_result($sql); if ($db->num_rows($result) == 1) { // http://abrah.am lib_include('twitteroauth'); $key = $db->result_value($result, 0, 'oauth_key'); $secret = $db->result_value($result, 0, 'oauth_secret'); $consumer_key = environment('twitterKey'); $consumer_secret = environment('twitterSecret'); $to = new TwitterOAuth($consumer_key, $consumer_secret, $key, $secret); $notice_content = substr($rec->title, 0, 140); $content = $to->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => $notice_content), 'POST'); } else { wp_plugin_include('twitter-tools'); // set a flag on aktt global $aktt; $aktt->tweet_from_sidebar = false; // truncate the tweet at 140 chars $notice_content = substr($rec->title, 0, 140); // activate Twitter Tools $_GET['activate'] = true; // trip the init() function aktt_init(); // make a new tweet object $tweet = new aktt_tweet(); // set the tweetbody $tweet->tw_text = stripslashes($notice_content); // send the tweet to Twitter $aktt->do_tweet($tweet); } }
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); }
function dynamic_sidebar() { global $request; global $sidebar_done; if (isset($request->params['nickname'])) { if ($request->action == 'index' && $request->byid == get_profile_id()) { render_partial('apps'); } echo '<script type="text/javascript" src="' . $request->url_for(array('resource' => 'pages', 'action' => 'block.js')) . '"></script>'; $sidebar_done = true; return true; } if (!$sidebar_done && get_profile_id() && $request->resource == 'identities' && in_array($request->action, array('edit', 'entry'))) { if ($request->id == get_profile_id()) { render_partial('admin'); } $sidebar_done = true; return true; } $blocks = environment('blocks'); if (environment('categories') && !empty($blocks) && !$sidebar_done && $request->resource == 'posts') { foreach ($blocks as $b) { // if it's the prologue theme, don't show PAGES in sidebar if (!($b == 'pages' && is_microblog_theme())) { //$renderpartial = true; if (isset($renderpartial)) { // this would be better/faster, but not working yet echo '<script type="text/javascript">'; render_partial(array('resource' => $b, 'action' => 'block.js')); echo '</script>'; } else { // doing a call back to the server for each block. not cool XXX echo '<script type="text/javascript" src="' . $request->url_for(array('resource' => $b, 'action' => 'block.js')) . '"></script>'; } } } $sidebar_done = true; } if (environment('theme') == 'prologue-theme') { echo '<a href="http://openmicroblogger.org"><img src="http://openmicroblogger.org/omb.gif" style="border:none;" alt="openmicroblogger.org" /></a>' . "\n"; } return true; }
function update_my_tweets() { $profile_id = get_profile_id(); if (!$profile_id) { return; } // activate Twitter Tools $_GET['activate'] = true; // trip the init() function aktt_init(); // get the Twitter Tools object global $wpdb, $aktt, $db; if (empty($aktt->twitter_username) || empty($aktt->twitter_password)) { return; } // make a new tweet object $tweet = new aktt_tweet(); // let the last update run for 5 minutes if (time() - intval(get_option('aktt_doing_tweet_download')) < 300) { return; } update_option('aktt_doing_tweet_download', time()); if (empty($aktt->twitter_username) || empty($aktt->twitter_password)) { update_option('aktt_doing_tweet_download', '0'); die; } require_once ABSPATH . WPINC . '/class-snoopy.php'; $snoop = new Snoopy(); $snoop->agent = 'Twitter Tools http://alexking.org/projects/wordpress'; $snoop->user = $aktt->twitter_username; $snoop->pass = $aktt->twitter_password; $snoop->fetch('http://tweetpass.com/statuses/friends_timeline.json'); if (!strpos($snoop->response_code, '200')) { update_option('aktt_doing_tweet_download', '0'); return; } $data = $snoop->results; $hash = md5($data); if ($hash == get_option('aktt_update_hash')) { update_option('aktt_doing_tweet_download', '0'); return; } $json = new Services_JSON(); $tweets = $json->decode($data); if (is_array($tweets) && count($tweets) > 0) { $tweet_ids = array(); foreach ($tweets as $tweet) { $tweet_ids[] = $wpdb->escape($tweet->id); } $existing_ids = $wpdb->get_col("\n SELECT tw_id\n FROM {$wpdb->aktt}\n WHERE tw_id\n IN ('" . implode("', '", $tweet_ids) . "')\n "); $new_tweets = array(); foreach ($tweets as $tw_data) { if (!$existing_ids || !in_array($tw_data->id, $existing_ids)) { $tweet = new aktt_tweet($tw_data->id, $tw_data->text); $tweet->tw_created_at = $tweet->twdate_to_time($tw_data->created_at); $new_tweets[] = $tweet; } } foreach ($new_tweets as $tweet) { $AkTwitter =& $db->get_table('ak_twitter'); $Entry =& $db->get_table('entries'); $t = $AkTwitter->find_by('tw_id', $tweet->tw_id); if (!$t) { $tweet->add(); $created = date("Y-m-d H:i:s", $tweet->tw_created_at - 8 * 3600); $t = $AkTwitter->find($db->last_insert_id($AkTwitter)); if ($t) { $t->set_etag(); } $atomentry = $Entry->find_by(array('resource' => 'ak_twitter', 'record_id' => $t->id), $t->id); if ($atomentry) { $result = $db->get_result("UPDATE entries SET last_modified = '{$created}' WHERE id = " . $atomentry->id); } $user = new Snoopy(); $user->agent = 'Twitter Tools http://alexking.org/projects/wordpress'; $user->user = $aktt->twitter_username; $user->pass = $aktt->twitter_password; $user->fetch('http://tweetpass.com/statuses/show/' . $tweet->tw_id . '.json'); $data = $user->results; $json = new Services_JSON(); $notice = $json->decode($data); $uarr = $notice->user; $TwitterUser =& $db->model('TwitterUser'); $twuser = $TwitterUser->find_by('twitter_id', $uarr->id); if (!$twuser) { $twuser = $TwitterUser->base(); $twuser->set_value('description', $uarr->description); $twuser->set_value('screen_name', $uarr->screen_name); $twuser->set_value('url', $uarr->url); $twuser->set_value('name', $uarr->name); $twuser->set_value('protected', $uarr->protected); $twuser->set_value('followers_count', $uarr->followers_count); $twuser->set_value('profile_image_url', $uarr->profile_image_url); $twuser->set_value('location', $uarr->location); $twuser->set_value('twitter_id', $uarr->id); $twuser->save_changes(); } $t->set_value('profile_id', $twuser->twitter_id); $t->save_changes(); } $AkTwitter->has_and_belongs_to_many('identities'); $join =& $db->get_table($Entry->join_table_for('ak_twitter', 'identities')); $j = $join->base(); $j->set_value('aktwitter_id', $t->id); $j->set_value('identity_id', get_profile_id()); $j->save_changes(); } } update_option('aktt_update_hash', $hash); update_option('aktt_last_tweet_download', time()); update_option('aktt_doing_tweet_download', '0'); }
function _sources(&$vars) { extract($vars); if (!member_of('administrators')) { trigger_error('sorry you must be an administrator to do that', E_USER_ERROR); } $aktwitter_tw_text_options = array('0' => 'false', '1' => 'true'); $Setting =& $db->model('Setting'); $returnvars = array(); $TwitterUser =& $db->model('TwitterUser'); $TwitterUser->find_by(array('eq' => 'not like', 'oauth_key' => ''), 1); $i = 1; while ($tu = $TwitterUser->MoveNext()) { $modevar = 'n' . $i . 'mode'; $urlvar = 'n' . $i . 'url'; $entryvar = 'n' . $i . 'entry'; $nickvar = 'n' . $i . 'nick'; $i++; ${$nickvar} = $tu->screen_name; ${$modevar} = $Setting->find_by('name', 'config.env.importtwitter_' . $tu->id); if (!${$modevar}) { ${$modevar} = $Setting->base(); ${$modevar}->set_value('profile_id', get_profile_id()); ${$modevar}->set_value('person_id', get_person_id()); ${$modevar}->set_value('name', 'config.env.importtwitter_' . $tu->id); ${$modevar}->set_value('value', 0); ${$modevar}->save_changes(); ${$modevar}->set_etag(); ${$modevar} = $Setting->find(${$modevar}->id); } ${$urlvar} = $request->url_for(array('resource' => 'settings', 'id' => ${$modevar}->id, 'action' => 'put')); ${$entryvar} = ${$modevar}->FirstChild('entries'); $returnvars[] =& ${$modevar}; $returnvars[] =& ${$urlvar}; $returnvars[] =& ${$entryvar}; $returnvars[] =& ${$nickvar}; } $returnvars[] =& $collection; $returnvars[] =& $profile; $returnvars[] =& $aktwitter_tw_text_options; $listvars = array(1 => 'friends_timeline', 0 => 'disabled'); $returnvars[] =& $listvars; $returnvars[] =& $i; return vars($returnvars, get_defined_vars()); }
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 .= ' ' . "\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"> </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); }
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; } } } } } }
function get_admin_oauth($username_user, $password_user, $device) { if (isset($username_user) && isset($password_user) && isset($device)) { $secret = check_admin($username_user); if ($secret != 'false') { $device = json_encode($device); $profile_id = get_profile_id($username_user, $password_user); $oauth_key = check_oauth($profile_id, $device); $status = "failure"; //$device_name = 'device_'.uniqid(rand(), true); include 'sql.php'; if ($profile_id != null && $oauth_key == null) { /* * generate and write the oauth key to db */ $token = md5(uniqid(rand(), true)); $date = date_create(); date_timestamp_set($date, time() + 2 * 24 * 60 * 60); $dtm = date_format($date, "Y-m-d H:i:s"); $sql = "insert into " . $dbname . ".oauth(oauth_key,oauth_expiry,device,profile_id) value ('{$token}','{$dtm}','{$device}',{$profile_id})"; $result = $conn->query($sql); $oauth_key = $token; header($_SERVER["SERVER_PROTOCOL"] . " " . $GLOBALS['status_found']); header('Oauth: ' . $oauth_key); $res = get_userdata($profile_id); $result_array = array('status' => 'Success', 'message' => 'User found', 'number_of_devices_logged_in' => get_users_logged_in($profile_id), 'secret_key' => $secret, 'user_data' => $res); // /* // * write to logs // */ // date_default_timezone_set('Asia/Calcutta'); // $date = date_create(); // date_timestamp_set($date, time()); // $dtm = date_format($date, "Y-m-d H:i:s"); // //echo $dtm; // //exit; // $sql = "insert into " . $dbname . ".logs(profile_id,state,mytime,oauth_key,device) value ($profile_id,'login','$dtm','$oauth_key','$device')"; // $result = $conn->query($sql); $conn->close(); } else { if ($oauth_key != null) { $res = get_userdata($profile_id); header($_SERVER["SERVER_PROTOCOL"] . " " . $GLOBALS['status_found']); header('oauth: ' . $oauth_key); $status = "Sucess"; $result_array = array('status' => 'Success', 'message' => 'User found', 'number_of_devices_logged_in' => get_users_logged_in($profile_id), 'secret_key' => $secret, 'user_data' => $res); /* * write to logs */ date_default_timezone_set('Asia/Calcutta'); $date = date_create(); date_timestamp_set($date, time()); $dtm = date_format($date, "Y-m-d H:i:s"); $sql = "insert into " . $dbname . ".logs(profile_id,state,mytime,oauth_key,device) value ({$profile_id},'login','{$dtm}','{$oauth_key}','{$device}')"; $result = $conn->query($sql); } else { header($_SERVER["SERVER_PROTOCOL"] . " " . $GLOBALS['status_notfound']); // header('oauth: ' . $oauth_key); $result_array = array('status' => 'Failure', 'message' => 'User not found'); } } print_r(json_encode($result_array)); } else { header($_SERVER["SERVER_PROTOCOL"] . " " . $GLOBALS['status_notfound']); $result_array = array('status' => 'Failure', 'message' => 'Admin access denied'); } } }
function _edit(&$vars) { extract($vars); if (!class_exists('Services_JSON')) { lib_include('json'); } $TwitterUser =& $db->model('TwitterUser'); $tu = $TwitterUser->find_by(array('profile_id' => get_profile_id()), 1); if ($tu) { $method = 'oauth'; } else { $method = 'password'; $password = $Setting->find_by(array('name' => 'aktt_twitter_password', 'profile_id' => get_profile_id())); if (!$password) { $password = $Setting->base(); $password->set_value('profile_id', get_profile_id()); $password->set_value('person_id', get_person_id()); $password->set_value('name', 'aktt_twitter_password'); $password->save_changes(); $password->set_etag(); $password = $Setting->find($password->id); $pword = ""; } if (!empty($password->value)) { $pword = "******"; } // get the one-to-one-related child-record from "entries" $pEntry =& $password->FirstChild('entries'); $passurl = $request->url_for(array('resource' => 'settings', 'id' => $password->id, 'action' => 'put')); $username = $Setting->find_by(array('name' => 'aktt_twitter_username', 'profile_id' => get_profile_id())); if (!$username) { $username = $Setting->base(); $username->set_value('profile_id', get_profile_id()); $username->set_value('person_id', get_person_id()); $username->set_value('name', 'aktt_twitter_username'); $username->save_changes(); $username->set_etag(); $username = $Setting->find($username->id); } // get the one-to-one-related child-record from "entries" $uEntry =& $username->FirstChild('entries'); $userurl = $request->url_for(array('resource' => 'settings', 'id' => $username->id, 'action' => 'put')); } $stat = $Setting->find_by(array('name' => 'twitter_status', 'profile_id' => get_profile_id())); if (!$stat) { $stat = $Setting->base(); $stat->set_value('profile_id', get_profile_id()); $stat->set_value('person_id', get_person_id()); $stat->set_value('name', 'twitter_status'); $stat->set_value('value', 'enabled'); $stat->save_changes(); $stat->set_etag(); $stat = $Setting->find($stat->id); } // get the one-to-one-related child-record from "entries" $sEntry =& $stat->FirstChild('entries'); $staturl = $request->url_for(array('resource' => 'settings', 'id' => $stat->id, 'action' => 'put')); $status = $stat->value; $aktwitter_tw_text_options = array('disabled' => 'disabled', 'enabled' => 'enabled'); if ($method == 'password') { return vars(array(&$aktwitter_tw_text_options, &$status, &$staturl, &$pword, &$userurl, &$passurl, &$password, &$sEntry, &$username, &$uEntry, &$pEntry, &$profile, &$method), get_defined_vars()); } if ($method == 'oauth') { return vars(array(&$aktwitter_tw_text_options, &$status, &$staturl, &$sEntry, &$profile, &$method), get_defined_vars()); } }
function _background(&$vars) { extract($vars); $settingvalue = $Setting->find_by(array('name' => 'background_image', 'profile_id' => get_profile_id())); if (!$settingvalue) { $settingvalue = $Setting->base(); $settingvalue->set_value('profile_id', get_profile_id()); $settingvalue->set_value('person_id', get_person_id()); $settingvalue->set_value('name', 'background_image'); $settingvalue->save_changes(); $settingvalue->set_etag(); $settingvalue = $Setting->find($settingvalue->id); } // get the one-to-one-related child-record from "entries" $Entry =& $settingvalue->FirstChild('entries'); $settingurl = $request->url_for(array('resource' => 'settings', 'id' => $settingvalue->id, 'action' => 'put')); $setting_name = 'background_tile'; $boolean_options = array('0' => 'false', '1' => 'true'); $setting_list = $boolean_options; $setting_mode = $Setting->find_by(array('name' => $setting_name, 'profile_id' => get_profile_id())); if (!$setting_mode) { $setting_mode = $Setting->base(); $setting_mode->set_value('profile_id', get_profile_id()); $setting_mode->set_value('person_id', get_person_id()); $setting_mode->set_value('name', $setting_name); $setting_mode->set_value('value', '0'); $setting_mode->save_changes(); $setting_mode->set_etag(); $setting_mode = $Setting->find($setting_mode->id); } $setting_url = $request->url_for(array('resource' => 'settings', 'id' => $setting_mode->id, 'action' => 'put')); $setting_entry = $setting_mode->FirstChild('entries'); return vars(array(&$setting_mode, &$setting_url, &$setting_entry, &$setting_list, &$Member, &$Entry, &$profile, &$settingurl, &$settingvalue, &$boolean_options), get_defined_vars()); }
function delete_from_post(&$req, $revision = false) { trigger_before('delete_from_post', $this, $req); global $db; if ($this->has_metadata && !isset($req->params['entry']['etag'])) { trigger_error("Sorry, the etag was not submitted with the database entry", E_USER_ERROR); } $fields = $this->fields_from_request($req); if ($this->has_metadata) { $atomentry = $db->models['entries']->find_by('etag', $req->params['entry']['etag']); $recid = $atomentry->attributes['record_id']; if (!$req->id) { $req->set_param('id', $recid); } } else { $recid = $req->id; } $rec = $this->find($recid); if ($revision) { // save a revision $Revision =& $db->model('Revision'); $r = $Revision->base(); $r->set_value('data', serialize($rec)); $r->set_value('profile_id', get_profile_id()); $r->set_value('target_id', $rec->entry_id); $r->save(); } if ($this->has_metadata) { $Person =& $db->model('Person'); $Group =& $db->model('Group'); $p = $Person->find(get_person_id()); if (!($p->id == $atomentry->attributes['person_id']) && !$this->can_superuser($req->resource)) { trigger_error("Sorry, your id does not match the owner of the database entry", E_USER_ERROR); } } $coll = environment('collection_cache'); if ($this->has_metadata && isset($coll[$req->resource]) && $coll[$req->resource]['location'] == 'aws') { $ext = extension_for($atomentry->content_type); $pkname = $rec->primary_key; global $prefix; $aws_file = $prefix . $rec->table . $rec->{$pkname} . "." . $ext; lib_include('S3'); $s3 = new S3(environment('awsAccessKey'), environment('awsSecretKey')); if (!$s3) { trigger_error('Sorry, there was a problem connecting to Amazon Web Services', E_USER_ERROR); } if ($s3->getBucket(environment('awsBucket')) && $s3->getObject(environment('awsBucket'), urlencode($aws_file))) { $result = $s3->deleteObject(environment('awsBucket'), urlencode($aws_file)); if (!$result) { trigger_error('Sorry, there was a problem deleting the file from Amazon Web Services', E_USER_ERROR); } } } $result = $db->delete_record($rec); trigger_after('delete_from_post', $this, $req); }
function setting($name) { if (!signed_in()) { return false; } global $db; global $ombsettings; if (!is_array($ombsettings)) { $ombsettings = array(); } if (isset($ombsettings[$name])) { return $ombsettings[$name]; } $Setting =& $db->model('Setting'); $sett = $Setting->find_by(array('name' => $name, 'profile_id' => get_profile_id())); if ($sett) { $ombsettings[$name] = $sett->value; return $ombsettings[$name]; } $ombsettings[$name] = false; return false; }
include 'wp-content/language/lang_chooser.php'; //Loads the language-file ?> <?php global $request; ?> <?php if (get_app_id()) { ?> <?php $profile = get_profile(get_app_id()); if ($profile->id == get_profile_id()) { if (in_array('settings', $request->activeroute->patterns)) { render_partial('admin'); } } // echo '<script type="text/javascript" src="'.$request->url_for(array('resource'=>'pages','action'=>'block.js')).'"></script>'; } ?> <?php if (!in_array('settings', $request->activeroute->patterns)) { ?> <?php if (isset($request->params['nickname'])) { ?>
function _apps(&$vars) { extract($vars); $Identity =& $db->model('Identity'); global $submenu, $current_user; trigger_before('admin_menu', $current_user, $current_user); $menuitems = array(); $apps_list = array(); global $env; if (is_array($env['apps'])) { $apps_list = $env['apps']; } $i = $Identity->find(get_profile_id()); while ($s = $i->NextChild('settings')) { $s = $Setting->find($s->id); $e = $s->FirstChild('entries'); $apps_list[] = $s->value; } $menuitems[$request->url_for(array('resource' => 'identities', 'id' => get_profile_id(), 'action' => 'edit')) . '/partial'] = 'Settings'; $menuitems[$request->url_for(array('resource' => 'identities', 'id' => get_profile_id(), 'action' => 'subs')) . '/partial'] = 'Friends'; //$menuitems[$request->url_for(array( // 'resource'=>'identities', // 'id'=>get_profile_id(), // 'action'=>'apps' // )).'/partial'] = 'Apps'; foreach ($submenu as $arr) { if (in_array($arr[0][0], $apps_list)) { $menuitems[$arr[0][4]] = $arr[0][3]; } } return vars(array(&$menuitems), get_defined_vars()); }
<?php if (isset($_POST['ozh_yourls'])) { if (!signed_in()) { return; } $setting_name = 'ozh_yourls'; $setting_value = serialize(base64_encode($_POST['ozh_yourls'])); global $db, $request; $Setting =& $db->model('Setting'); $sett = $Setting->find_by(array('name' => $setting_name, 'profile_id' => get_profile_id())); if (!$sett) { $s = $Setting->base(); $s->set_value('profile_id', get_profile_id()); $s->set_value('person_id', get_person_id()); $s->set_value('name', $setting_name); $s->set_value('value', $setting_value); $s->save_changes(); $s->set_etag(); } else { $sett->set_value('value', $setting_value); $sett->save_changes(); } $profile = get_profile(); redirect_to($request->url_for(array("resource" => $profile->nickname)) . "/settings"); } if (isset($_POST['ajax_shorten'])) { if (!signed_in()) { return; } $url = $_POST['ajax_shorten'];
if (REALTIME_HOST) { ?> <?php global $db; if (!empty($db->prefix)) { $chan = $db->prefix; } else { $chan = "chan"; } ?> <script type="text/javascript"> // <![CDATA[ Meteor.hostid = '<?php echo get_profile_id(); ?> '; Meteor.host = "<?php echo REALTIME_HOST; ?> "; Meteor.registerEventCallback("process", test); Meteor.joinChannel("<?php echo $chan; ?> ", 0); Meteor.mode = 'stream'; Meteor.connect(); function test(data) { data = data.substring(0,(data.length - 10));
function handle_posted_file($filename = "", $att, $profile) { global $db, $request, $response; $response->set_var('profile', $profile); load_apps(); if (isset($_FILES['media']['tmp_name'])) { $table = 'uploads'; } else { $table = 'posts'; } $modelvar = classify($table); $_FILES = array(strtolower($modelvar) => array('name' => array('attachment' => $filename), 'tmp_name' => array('attachment' => $att))); $Post =& $db->model('Post'); $Upload =& $db->model('Upload'); $field = 'attachment'; $request->set_param('resource', $table); $request->set_param(array(strtolower(classify($table)), $field), $att); trigger_before('insert_from_post', ${$modelvar}, $request); $content_type = 'text/html'; $rec = ${$modelvar}->base(); $content_type = type_of($filename); $rec->set_value('profile_id', get_profile_id()); $rec->set_value('parent_id', 0); if (isset($request->params['message'])) { $rec->set_value('title', $request->params['message']); } else { $rec->set_value('title', ''); } if ($table == 'uploads') { $rec->set_value('tmp_name', 'new'); } $upload_types = environment('upload_types'); if (!$upload_types) { $upload_types = array('jpg', 'jpeg', 'png', 'gif'); } $ext = extension_for(type_of($filename)); if (!in_array($ext, $upload_types)) { trigger_error('Sorry, this site only allows the following file types: ' . implode(',', $upload_types), E_USER_ERROR); } $rec->set_value($field, $att); $rec->save_changes(); $tmp = $att; if (is_jpg($tmp)) { $thumbsize = environment('max_pixels'); $Thumbnail =& $db->model('Thumbnail'); $t = $Thumbnail->base(); $newthumb = tempnam("/tmp", "new" . $rec->id . ".jpg"); resize_jpeg($tmp, $newthumb, $thumbsize); $t->set_value('target_id', $atomentry->id); $t->save_changes(); update_uploadsfile('thumbnails', $t->id, $newthumb); $t->set_etag(); } $atomentry = ${$modelvar}->set_metadata($rec, $content_type, $table, 'id'); ${$modelvar}->set_categories($rec, $request, $atomentry); $url = $request->url_for(array('resource' => $table, 'id' => $rec->id)); // $title = substr($rec->title,0,140); // $over = ((strlen($title) + strlen($url) + 1) - 140); // if ($over > 0) // $rec->set_value('title',substr($title,0,-$over)." ".$url); // else // $rec->set_value('title',$title." ".$url); // $rec->save_changes(); trigger_after('insert_from_post', ${$modelvar}, $rec); return true; }
function local_unsubscribe(&$vars) { extract($vars); $Subscription =& $db->model('Subscription'); $sub = $Subscription->find_by(array('subscribed' => $request->listenee_id, 'subscriber' => get_profile_id())); if ($sub) { $db->delete_record($sub); } redirect_to(array('resource' => $request->listenee_nick)); }