Skip to content

Commit

Permalink
fixed openmicroblogger URI handling
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Aug 25, 2008
1 parent b5d1c87 commit 6e92520
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 56 deletions.
1 change: 1 addition & 0 deletions app/controllers/identities.php
Expand Up @@ -134,6 +134,7 @@ function put( &$vars ) {
$rec->set_value( 'avatar', '' );

$rec->set_value( 'profile', $request->url_for(array('resource'=>"_".$rec->id)));
$rec->set_value( 'profile_url', $request->url_for(array('resource'=>"".$rec->nickname)));
$rec->save_changes();
header_status( '200 OK' );
redirect_to( $request->url_for( array(
Expand Down
2 changes: 2 additions & 0 deletions app/models/Identity.php
Expand Up @@ -19,6 +19,8 @@ function Identity() {
$this->char_field( 'bio' );
$this->char_field( 'avatar' );
$this->char_field( 'profile' );
$this->char_field( 'profile_url' );
$this->char_field( 'homepage' );

$this->char_field( 'fullname' );
$this->char_field( 'family_name' );
Expand Down
160 changes: 109 additions & 51 deletions app/plugins/omb.php
Expand Up @@ -241,21 +241,29 @@ function wp_set_post_fields_after( &$model, &$rec ) {
after_filter('do_ajaxy_fileupload','routematch');

function do_ajaxy_fileupload(&$request,&$route) {

global $db;

if (!isset($_FILES['Filedata']['name']))
return;

if (!is_writable('cache'))
exit;
global $db;
$Upload =& $db->model('Upload');

$result = $db->get_result("DELETE FROM uploads WHERE name = '".$db->escape_string(urldecode($_FILES['Filedata']['name']))."'");
$tmp = 'cache'.DIRECTORY_SEPARATOR.make_token();
$tmp .= ".". extension_for(type_of($_FILES['Filedata']['name']));

$Upload =& $db->model('Upload');
$u = $Upload->base();
$tmp = 'cache/'.make_token().".". extension_for(type_of($_FILES['Filedata']['name']));
$u->set_value('name', urldecode($_FILES['Filedata']['name']));
$u->set_value('tmp_name', $tmp);
$u->save_changes();

move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmp);
echo "200 OK";
exit;

}


Expand Down Expand Up @@ -342,58 +350,28 @@ function omb_request_munger( &$request, &$route ) {
OMB_VERSION . '/postNotice',
OMB_VERSION . '/updateProfile'
);


function filter_MatchesAnyOMBType(&$service)
{
global $omb_services;

$uris = $service->getTypes();

foreach ($uris as $uri) {
if (in_array($uri, $omb_services)) {
return true;
}
}

return false;
}


// subscribe step 1 (remote service)

// a form on this site, submitted by a non-authenticated visitor

function oauth_omb_subscribe( &$vars ) {

extract($vars);

wp_plugin_include(array(
'wp-oauth'
));

$key = $request->base;
$secret = '';

function get_remote_xrds($at_url) {
global $request;
$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();
$yadis = Auth_Yadis_Yadis::discover($request->listener_url, $fetcher);

$yadis = Auth_Yadis_Yadis::discover($at_url, $fetcher);
if (!$yadis || $yadis->failed)
trigger_error("Sorry but the Yadis doc was not found at the profile URL", E_USER_ERROR);

$xrds =& Auth_Yadis_XRDS::parseXRDS($yadis->response_text);

if (!$xrds)
trigger_error("Sorry but the XRDS data was not found in the Yadis doc", E_USER_ERROR);

$yadis_services = $xrds->services(array('filter_MatchesAnyOMBType'));



foreach ($yadis_services as $service) {
$type_uris = $service->getTypes();
$uris = $service->getURIs();
Expand All @@ -420,6 +398,51 @@ function oauth_omb_subscribe( &$vars ) {
}
}

return array($localid,$endpoints);

}


function filter_MatchesAnyOMBType(&$service)
{
global $omb_services;

$uris = $service->getTypes();

foreach ($uris as $uri) {
if (in_array($uri, $omb_services)) {
return true;
}
}

return false;
}


// subscribe step 1 (remote service)

// a form on this site, submitted by a non-authenticated visitor

function oauth_omb_subscribe( &$vars ) {

extract($vars);

wp_plugin_include(array(
'wp-oauth'
));

$key = $request->base;
$secret = '';

$xrds = get_remote_xrds($request->listener_url);

if (is_array($xrds)) {
$localid = $xrds[0];
$endpoints = $xrds[1];
} else {
trigger_error('unable to fetch remote XRDS document', E_USER_ERROR );
}

$_SESSION['subscriber_request_token_url'] = $endpoints[OAUTH_VERSION . '/endpoint/request'];
$_SESSION['subscriber_access_token_url'] = $endpoints[OAUTH_VERSION . '/endpoint/access'];
$_SESSION['subscriber_authorize_url'] = $endpoints[OAUTH_VERSION . '/endpoint/authorize'];
Expand Down Expand Up @@ -506,12 +529,17 @@ function oauth_omb_subscribe( &$vars ) {

if (!(isset($i->nickname)))
trigger_error('the identity does not have a nickname', E_USER_ERROR);


if (!empty($i->profile_url))
$profile_url = $i->profile_url;
else
$profile_url = $i->profile;

$omb_subscribe = array(
'omb_version' => OMB_VERSION,
'omb_listener' => $_SESSION['listener_uri'],
'omb_listenee' => $i->profile,
'omb_listenee_profile' => $i->profile,
'omb_listenee_profile' => $profile_url,
'omb_listenee_nickname' => $i->nickname,
'omb_listenee_license' => $i->license,
'omb_listenee_avatar' => $i->avatar
Expand Down Expand Up @@ -566,13 +594,25 @@ function oauth_authorize( &$vars ) {
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',
'omb_listenee_profile' => 'profile_url',
'omb_listenee_nickname' => 'nickname',
'omb_listenee_license' => 'license',
'omb_listenee_homepage' => 'url',
'omb_listenee' => 'url',
'omb_listenee_homepage' => 'homepage',
'omb_listenee_bio' => 'bio',
'omb_listenee_location' => 'locality',
'omb_listenee_avatar' => 'avatar'
Expand All @@ -594,6 +634,7 @@ function oauth_authorize( &$vars ) {
// CREATE USER

$i = $Identity->base();
$i->set_value( 'profile', $prof );
$i->set_value( 'label', 'profile 1' );
$i->set_value( 'person_id', $p->id );

Expand All @@ -607,8 +648,11 @@ function oauth_authorize( &$vars ) {
$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'] );

$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);

Expand Down Expand Up @@ -665,13 +709,18 @@ function oauth_authorize( &$vars ) {

$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' => $i->profile,
'omb_listener_profile' => $profile_url,
'omb_listener_nickname' => $i->nickname,
'omb_listener_license' => $i->license,
'omb_listener_fullname' => $i->fullname,
'omb_listener_homepage' => $i->url,
'omb_listener_homepage' => $i->homepage,
'omb_listener_bio' => $i->bio,
'omb_listener_location' => $i->locality,
'omb_listener_avatar' => $i->avatar
Expand Down Expand Up @@ -749,9 +798,11 @@ function oauth_omb_finish_subscribe( &$vars ) {
trigger_error('Sorry the subscription failed', E_USER_ERROR);

$listener_params = array(
'omb_listener_profile' => 'profile_url',
'omb_listener_fullname' => 'fullname',
'omb_listener_license' => 'license',
'omb_listener_homepage' => 'url',
'omb_listener_nickname' => 'nickname',
'omb_listener_homepage' => 'homepage',
'omb_listener_bio' => 'bio',
'omb_listener_location' => 'locality',
'omb_listener_avatar' => 'avatar'
Expand All @@ -770,6 +821,7 @@ function oauth_omb_finish_subscribe( &$vars ) {
// CREATE USER

$i = $Identity->base();
$i->set_value( 'url', $_SESSION['listener_uri'] );
$i->set_value( 'profile', $_SESSION['listener_uri'] );
$i->set_value( 'label', 'profile 1' );
$i->set_value( 'person_id', $p->id );
Expand All @@ -784,7 +836,7 @@ function oauth_omb_finish_subscribe( &$vars ) {
$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'] );
$i->set_value( 'url', $i->attributes['profile_url'] );

$i->save_changes();
$i->set_etag($p->id);
Expand Down Expand Up @@ -846,7 +898,9 @@ function oauth_omb_finish_subscribe( &$vars ) {
$sub->save_changes();

redirect_to(array(
'resource'=>'_'.$_SESSION['listenee_id'] ));
'resource' => '_'.$_SESSION['listenee_id']
));

}


Expand Down Expand Up @@ -944,6 +998,8 @@ function oauth_omb_post( &$vars ) {
$sender = $Identity->find_by('profile',$listenee);

if (!($sender)) {
if (strpos($request->base, 'openmicroblogger') !== false)
send_email( 'brian@megapump.com', 'not found 403', 'listenee '.$listenee, environment('email_from'), environment('email_name'), false );
header( 'Status: 403 Forbidden' );
exit;
}
Expand All @@ -955,6 +1011,8 @@ function oauth_omb_post( &$vars ) {
));

if (!($sub)) {
if (strpos($request->base, 'openmicroblogger') !== false)
send_email( 'brian@megapump.com', 'no sub 403', 'listenee '.$listenee, environment('email_from'), environment('email_name'), false );
header( 'Status: 403 Forbidden' );
exit;
}
Expand Down
7 changes: 6 additions & 1 deletion app/plugins/omb_notice.php
Expand Up @@ -57,6 +57,11 @@ function broadcast_omb_notice( &$model, &$rec ) {
$parsed = parse_url($url);
$params = array();

//omb_version
//omb_listenee
//omb_notice
//omb_notice_content

parse_str($parsed['query'], $params);
$req = OAuthRequest::from_consumer_and_token($consumer, $token, "POST", $url, $params);
$req->set_parameter( 'omb_version', OMB_VERSION );
Expand Down Expand Up @@ -88,7 +93,7 @@ function broadcast_omb_notice( &$model, &$rec ) {
if ( $result->status == 403 ) {
if (strpos($request->base, 'openmicroblogger') !== false)
send_email( 'brian@megapump.com', 'delete subscription', 'listenee '.$listenee_uri, environment('email_from'), environment('email_name'), false );
$db->delete_record($sub);
//$db->delete_record($sub);
} else {
parse_str( $result->body, $return );
if ( is_array($return) && $return['omb_version'] == OMB_VERSION ) {
Expand Down
9 changes: 7 additions & 2 deletions app/plugins/wp.php
Expand Up @@ -218,8 +218,8 @@ function query($query) {
if ( preg_match("/^\\s*(delete) /i",$query) )
$query = str_replace("LIMIT 1","",$query);

//if ( preg_match("/^\\s*(replace into) /i",$query) )
// return;
if ( class_exists('PostgreSQL') && preg_match("/^\\s*(replace into) /i",$query) )
return;

$this->result = $db->get_result($query);
if ( preg_match("/^\\s*(insert|delete|update|replace) /i",$query) ) {
Expand Down Expand Up @@ -572,6 +572,9 @@ function wp_head() {
if (isset($request->resource) && $request->resource == 'identities' && $request->id > 0) {
echo '<meta http-equiv="X-XRDS-Location" content="'.$request->uri.'.xrds" />'."\n";
echo '<meta http-equiv="X-Yadis-Location" content="'.$request->uri.'.xrds" />'."\n";



}
echo '<link rel="stylesheet" type="text/css" href="'.$request->layout_path.'wp-themes/prologue-theme/menu.css" />'."\n";
echo '<script src="stuHover.js" type="text/javascript"></script>'."\n";
Expand Down Expand Up @@ -766,6 +769,8 @@ function the_post() {
$the_post = $Post->base();
}
}
if (!empty($the_author->profile_url)) $the_author->profile = $the_author->profile_url;

return "";
}
function get_links() {
Expand Down
4 changes: 2 additions & 2 deletions app/views/identities/_entry.html
Expand Up @@ -28,7 +28,7 @@ <h2><?php echo $Member->nickname; ?>'s subscribers</h2>
<?php if ($subscriber->subscribed == $Member->id) : ?>
<?php $subscribers[] = $subscriber->subscriber; ?>
<?php $si = $Identity->find( $subscriber->subscriber ); ?>
<a href="<?php echo $si->profile; ?>"><img style="border:none;width:48px;height:48px;" src="<?php echo $si->avatar; ?>"></a>
<a href="<?php if (!empty($si->profile_url)) echo $si->profile_url; else echo $si->profile; ?>"><img style="border:none;width:48px;height:48px;" src="<?php echo $si->avatar; ?>"></a>
<?php endif; ?>
<?php endwhile; ?>

Expand All @@ -41,7 +41,7 @@ <h2><?php echo $Member->nickname; ?>'s subscriptions</h2>
<?php while ($subscriber = $Subscription->MoveNext()) : ?>
<?php if ($subscriber->subscriber == $Member->id) : ?>
<?php $si = $Identity->find( $subscriber->subscribed ); ?>
<a href="<?php echo $si->profile; ?>"><img style="border:none;width:48px;height:48px;" src="<?php echo $si->avatar; ?>"></a>
<a href="<?php if (!empty($si->profile_url)) echo $si->profile_url; else echo $si->profile; ?>"><img style="border:none;width:48px;height:48px;" src="<?php echo $si->avatar; ?>"></a>
<?php endif; ?>
<?php endwhile; ?>

Expand Down
5 changes: 5 additions & 0 deletions app/views/wp-themes/prologue-theme/style.css
Expand Up @@ -64,6 +64,11 @@ blockquote {
float: left;
color: #555;
}
#sidebar table {
margin-left: 25px;
margin-bottom: 12px;
margin-top: 12px;
}
#sidebar ul li p {
font-size: 0.9em;
line-height: 1.4em;
Expand Down

0 comments on commit 6e92520

Please sign in to comment.