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 _mystreams(&$vars) { // index controller returns // a Collection of recent entries extract($vars); $Blog =& $db->model('Blog'); $Blog->set_param('find_by', array('entries.person_id' => get_person_id())); $collection = new Collection('blogs'); return vars(array(&$collection, &$profile), get_defined_vars()); }
function post(&$vars) { extract($vars); $g = $Group->base(); $fields = $Group->fields_from_request($request); foreach ($fields['groups'] as $field => $type) { $g->set_value($field, $request->params['group'][$field]); } $g->save_changes(); $g->set_etag(get_person_id()); $subscribers = explode("\n", $request->subscribers); foreach ($subscribers as $addr) { $p = false; $i = false; $a = trim($addr); $i = $Identity->find_by('email_value', $a); if (is_email($a) && $i) { $p = $i->FirstChild('people'); } elseif (is_email($a)) { $p = $Person->base(); $p->save(); $i = $Identity->base(); $i->set_value('url', $a); $i->set_value('email_value', $a); $i->set_value('given_name', ''); $i->set_value('label', 'profile 1'); $token = make_token($p->id); $i->set_value('token', $token); $i->set_value('person_id', $p->id); $i->save_changes(); $i->set_etag($p->id); do_invite_email($a, $token, $g); } if (is_email($a) && $p) { $m = $Membership->base(); $m->set_value('group_id', $g->id); $m->set_value('person_id', $p->id); $m->save_changes(); } } header('Status: 201 Created'); redirect_to('groups'); }
public function report($post_id) { $this->load->model('report_model'); $person_id = get_person_id($this); $this->report_model->add_report($person_id, $post_id); $this->session->set_flashdata('alert', 'Successfully reported post ID#' . $post_id); redirect($this->input->get('return')); }
<?php # Given a postcode, return a person ID include_once 'min-init.php'; include_once INCLUDESPATH . 'easyparliament/member.php'; $pc = $_GET['pc']; $pc = preg_replace('#[^a-z0-9 ]#i', '', $pc); if (validate_postcode($pc)) { $constituency = postcode_to_constituency($pc); if ($constituency == 'CONNECTION_TIMED_OUT') { error('Connection timed out'); } elseif ($constituency) { $pid = get_person_id($constituency); echo 'pid,', $pid; } else { error('Unknown postcode'); } } else { error('Invalid postcode'); } function error($s) { echo 'error,', $s; } function get_person_id($c) { $db = new ParlDB(); if ($c == '') { return false; } if ($c == 'Orkney ') {
function is_person($id) { $CI =& get_instance(); if ($id == get_person_id($CI)) { return true; } return false; }
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()); }
/** * Set Etag * * if it's empty, set a valid Etag in the entries table * * @author Brian Hendrickson <*****@*****.**> * @access public * @return string[] */ function set_etag($person_id = NULL) { global $db; $Entry =& $db->get_table('entries'); $atomentry = $Entry->find_by(array('resource' => $this->table, 'record_id' => $this->id), $this->id); if ($atomentry) { return true; } $atomentry = $Entry->base(); if ($person_id == NULL) { $person_id = get_person_id(); } if ($atomentry) { $id = $this->primary_key; $atomentry->set_value('etag', getEtag($this->{$id})); $atomentry->set_value('resource', $this->table); $atomentry->set_value('record_id', $this->{$id}); $atomentry->set_value('content_type', 'text/html'); $atomentry->set_value('last_modified', timestamp()); $atomentry->set_value('person_id', $person_id); $aresult = $atomentry->save_changes(); if ($aresult && array_key_exists('entry_id', $this->attributes)) { $this->set_value('entry_id', $atomentry->id); $this->save_changes(); } } }
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()); }
/** * get_profile * * get the Identity of a person * * @access public * @return integer */ function get_profile($id = NULL) { global $db, $response; if (!($id == NULL)) { $Identity =& $db->get_table('identities'); return $Identity->find($id); } elseif (isset($response->named_vars['profile'])) { $profile =& $response->named_vars['profile']; if ($profile->id > 0) { return $profile; } } $pid = get_person_id(); if (!$pid) { return false; } $Person =& $db->get_table('people'); $p = $Person->find($pid); if ($p) { $i = $p->FirstChild('identities'); if ($i) { $response->named_vars['profile'] = $i; } if ($i) { return $i; } } return false; }
function delete_from_post(&$req) { 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']; } else { $recid = $req->id; } $rec = $this->find($recid); 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); }
<?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'];
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 oauth_authorize(&$vars) { extract($vars); if (!(environment('openid_version') > 1) || (!$db->has_table('oauth_consumers') || !$db->has_table('oauth_tokens'))) { $db->create_openid_tables(); } wp_plugin_include(array('wp-oauth')); global $wpdb; global $userdata; if (!$_GET['oauth_token'] && !$_POST['authorize']) { trigger_error('Sorry, the remote service did not send a subscription token. The error has been recorded, you may go back and try the subscription again.', E_USER_ERROR); } $NO_oauth = true; //require_once dirname(__FILE__).'/common.inc.php'; $store = new OAuthWordpressStore(); if (!$_POST['authorize']) { $token = $wpdb->escape($_GET['oauth_token']); $consumer_key = $store->lookup_token('', 'request', $token); //verify token if (!$consumer_key) { die('Invalid token passed'); } } //end if ! POST authorize get_currentuserinfo(); if (!$userdata->ID) { redirect_to($request->url_for('openid_login')); } //end if ! userdata->ID $xrds = get_remote_xrds(trim(urldecode($_GET['omb_listenee_profile']))); if (is_array($xrds)) { $localid = $xrds[0]; $endpoints = $xrds[1]; } else { trigger_error('unable to fetch remote XRDS document', E_USER_ERROR); } $postNotice = $endpoints[OMB_VERSION . '/postNotice']; $updateProfile = $endpoints[OMB_VERSION . '/updateProfile']; $listenee_params = array('omb_listenee_fullname' => 'fullname', 'omb_listenee_profile' => 'profile_url', 'omb_listenee_nickname' => 'nickname', 'omb_listenee_license' => 'license', 'omb_listenee' => 'url', 'omb_listenee_homepage' => 'homepage', 'omb_listenee_bio' => 'bio', 'omb_listenee_location' => 'locality', 'omb_listenee_avatar' => 'avatar'); $Identity =& $db->get_table('identities'); $Person =& $db->get_table('people'); $Subscription =& $db->model('Subscription'); $prof = urldecode($_GET['omb_listenee']); $i = $Identity->find_by('profile', $prof); if (!$i) { // need to create the identity (and person?) because it was not found $p = $Person->base(); $p->save(); // CREATE USER $i = $Identity->base(); $i->set_value('profile', $prof); $i->set_value('label', 'profile 1'); $i->set_value('person_id', $p->id); foreach ($listenee_params as $k => $v) { if (isset($_GET[$k])) { $i->set_value($v, urldecode($_GET[$k])); } } if ("/" == substr($i->attributes['url'], -1)) { $i->attributes['url'] = substr($i->attributes['url'], 0, -1); } if (empty($i->attributes['url']) || !$Identity->is_unique_value($i->attributes['url'], 'url')) { $i->set_value('url', $i->attributes['profile_url']); } $i->set_value('update_profile', $updateProfile); $i->set_value('post_notice', $postNotice); $i->save_changes(); $i->set_etag($p->id); } $_SESSION['listenee_id'] = $i->id; if ($_POST['authorize']) { session_start(); $_GET['oauth_callback'] = $_SESSION['oauth_callback']; unset($_SESSION['oauth_callback']); $token = $_SESSION['oauth_token']; unset($_SESSION['oauth_token']); $consumer_key = $_SESSION['oauth_consumer_key']; unset($_SESSION['oauth_consumer_key']); if ($_POST['authorize'] != 'Ok') { if ($_GET['oauth_callback']) { header('Location: ' . urldecode($_GET['oauth_callback']), true, 303); } else { //get_header(); echo '<h2 class="omb-center">You chose to cancel authorization. You may now close this window.</h2>'; //get_footer(); } //end if-else callback exit; } //cancel authorize $consumers = $userdata->oauth_consumers ? $userdata->oauth_consumers : array(); $services = get_option('oauth_services'); $yeservices = array(); foreach ($services as $k => $v) { if (in_array($k, array_keys($_GET['services']))) { $yeservices[$k] = $v; } } $consumers[$consumer_key] = array_merge(array('authorized' => true), $yeservices); //it's an array so that more granular data about permissions could go in here $userdata->oauth_consumers = $consumers; update_usermeta($userdata->ID, 'oauth_consumers', $consumers); } //end if authorize if ($userdata->oauth_consumers && in_array($consumer_key, array_keys($userdata->oauth_consumers))) { $store->authorize_request_token($consumer_key, $token, $userdata->ID); if ($_GET['oauth_callback']) { $Subscription =& $db->model('Subscription'); $sub = $Subscription->find_by(array('subscribed' => $_SESSION['listenee_id'], 'subscriber' => get_profile_id())); if (!$sub) { $s = $Subscription->base(); $s->set_value('subscriber', get_profile_id()); $s->set_value('subscribed', $_SESSION['listenee_id']); $s->save_changes(); $s->set_etag(get_person_id()); } // response to omb remote service $i = get_profile(); if (!empty($i->profile_url)) { $profile_url = $i->profile_url; } else { $profile_url = $i->profile; } $omb_subscriber = array('omb_version' => OMB_VERSION, 'omb_listener_profile' => $profile_url, 'omb_listener_nickname' => $i->nickname, 'omb_listener_license' => $i->license, 'omb_listener_fullname' => $i->fullname, 'omb_listener_homepage' => $i->homepage, 'omb_listener_bio' => $i->bio, 'omb_listener_location' => $i->locality, 'omb_listener_avatar' => $i->avatar); if (strpos($_GET['oauth_callback'], '?') === false) { $profileparams = "?"; } else { $profileparams = "&"; } foreach ($omb_subscriber as $key => $item) { $profileparams .= $key . "=" . urlencode($item) . '&'; } $profileparams .= "oauth_token=" . $token; header('Location: ' . urldecode($_GET['oauth_callback']) . $profileparams, true, 303); } else { //get_header(); echo '<h2 class="omb-center">Authorized! You may now close this window.</h2>'; //get_footer(); } //end if-else callback exit; } else { session_start(); //use a session to prevent the consumer from tricking the user into posting the Yes answer $_SESSION['oauth_token'] = $token; $_SESSION['oauth_callback'] = $_GET['oauth_callback']; $_SESSION['oauth_consumer_key'] = $consumer_key; //get_header(); $description = $store->lookup_consumer_description($consumer_key); if ($description) { $description = 'Allow ' . $description . ' to post notices to your account?'; } else { $description = 'Click "allow" to authorize messages from the remote site.'; } ?> <div class="omb-center"> <h2><?php echo $description; ?> </h2> <form method="post" action=""><div> <div id="omb-desc"> <ul class="omb-ul"> <?php $services = get_option('oauth_services'); //foreach($services as $k => $v) // echo '<li><input type="checkbox" checked="checked" name="services['.htmlentities($k).']" /> '.$k.'</li>'; ?> </ul> <br /> <input type="submit" name="authorize" value="Cancel" /> <input type="submit" name="authorize" value="Ok" /> </div> </div></form> </div> <?php //get_footer(); exit; } //end if user has authorized this consumer }