예제 #1
0
파일: events.php 프로젝트: hcopr/Hubbub
function friendlyui_user_new(&$entityDS, &$userDS)
{
  // create a welcome message for the new user's stream
  $welcome = new HubbubMessage('notice');
  $welcome->owner($entityDS);
  $welcome->data['notice_type'] = 'welcome';
  $welcome->save();
}
예제 #2
0
function foreign_post_receive(&$data, &$msg)
{
    if (!$msg->validateSignature()) {
        return true;
    }
    WriteToFile('log/activity.log', $data['msgid'] . ' foreign_post ' . $msg->ownerEntity->key() . ' to ' . $msg->authorEntity->key() . chr(10));
    $con = new HubbubConnection($msg->ownerEntity->key(), $msg->authorEntity->key());
    if ($con->status() != 'friend') {
        return $msg->fail('no connection');
    }
    $usr = new HubbubUser($msg->ownerEntity->key());
    if ($con->ds['c_auto_approve'] == 'Y') {
        // if we're gonna approve this anyway, there is no reason to store the message
        // let's just create a post out of this
        WriteToFile('log/activity.log', $data['msgid'] . ' foreign_post received, accepted' . chr(10));
        $post = new HubbubMessage('post');
        $npid = $post->data['msgid'];
        $post->data = $msg->data;
        $post->data['type'] = 'post';
        $post->data['msgid'] = $npid;
        $post->author($msg->authorEntity->ds);
        $post->owner($msg->ownerEntity->ds);
        $post->data['changed'] = time();
        $post->data['received'] = time();
        $post->data['rel']['foreign'] = $data['msgid'];
        $post->save();
        WriteToFile('log/activity.log', $post->data['msgid'] . ' created from foreign_post' . chr(10));
        $msg->response['post'] = $post->data;
        $msg->doSave = false;
        $usr->notify('fpost/new', $msg->authorEntity, $msg);
    } else {
        // if not, let's store this message for later approval
        $usr->notify('fpost/approve', $msg->authorEntity, $msg);
        $msg->vTag = 'A';
        $msg->save();
    }
    $msg->ok();
}
예제 #3
0
/**
 * On-receive event handler
 * 
 * Gets called when this server (A) receives a trust_sendkey1 message from another server (B).
 * Usually this means, server (B) wants to establish contact for the first time or it wants
 * to revoke its existing key. In both cases, the key can only be accepted when this server (A)
 * contacts server (B) to confirm the origin of the trust_sendkey1 message.
 * 
 * @param array $data
 * @param object $msg
 * @return boolean
 */
function trust_sendkey1_receive(&$data, &$msg)
{
    $data['mykey'] = trim($data['mykey']);
    $serverUrl = getDefault($data['author']['server']);
    if ($serverUrl == '') {
        $msg->fail('invalid server field in "author" array');
    }
    if ($data['mykey'] == '') {
        $msg->fail('"mykey" field missing');
    } else {
        // accept the new key (it's not confirmed yet)
        $server = new HubbubServer($serverUrl, true);
        $server->ds['s_newkey_out'] = $data['mykey'];
        $server->ds['s_key_in'] = getDefault($server->ds['s_key_in'], randomHashId());
        DB_UpdateField('servers', $server->ds['s_key'], 's_key_in', $server->ds['s_key_in']);
        logError('notrace', 'received temp outbound key: ' . $data['mykey'] . ' /// ' . dumpArray($server->ds));
        // now, get origin confirmation
        $confirmMsg = new HubbubMessage('trust_sendkey2');
        $confirmMsg->author($server->localEntity());
        $confirmMsg->owner($server->entity());
        $confirmMsg->data['mykey'] = $server->ds['s_key_in'];
        $responseData = $confirmMsg->sendtourl($server->ds['s_url'], $server->ds['s_newkey_out']);
        if ($responseData['result'] == 'OK') {
            /* we need to reload, because the server record might have changed in the meantime */
            $server = new HubbubServer($serverUrl, true);
            // okay, the remote server really sent the original message
            $server->ds['s_key_out'] = $server->ds['s_newkey_out'];
            $server->ds['s_status'] = 'OK';
            DB_UpdateField('servers', $server->ds['s_key'], 's_key_out', $data['mykey']);
            $msg->ok();
        } else {
            // this didn't work
            $server->ds['s_newkey_out'] = '';
            $msg->fail('unsuccessful trust_sendkey2: ' . $responseData['reason']);
        }
    }
    return true;
}
예제 #4
0
  tlog($textData['deleted'] == 'yes', 'deleted in record', 'OK (#'.$mds['m_key'].')', 'fail');  
  
	$streamPosts1 = $this->msg->getStream($ne2->key());
	$wallPosts1 = $this->msg->getPostList($ne1->key());
  $postFound9 = -1; $postFound10 = -1;
  foreach($streamPosts1['list'] as $pds)
    if($pds['m_id'] == $post->data['msgid']) $postFound9 = $pds['m_id']; 
  tlog($postFound9 == -1, 'Message gone from author stream', 'OK', 'fail (#'.$postFound9.')');
	foreach($wallPosts1['list'] as $pds)
	  if($pds['m_id'] == $post->data['msgid']) $postFound10 = $pds['m_id']; 
	tlog($postFound10 == -1, 'Message gone from owner profile', 'OK', 'fail ('.$postFound10.')');  

  $post = new HubbubMessage('post');
  $post->localUserEntity = $ne2->key();
  $post->author($ne2->ds);
  $post->owner($ne1->ds);
  $post->data['text'] = 'This is a message, it will be deleted. Umlauts like üöä should be preserved.';
  $post->save();

  $post->executeHandler('delete');
  tlog($post->data['deleted'] == 'yes', 'Author: "deleted" property set', 'OK', 'fail');  
  tlog($post->isDeleted, '"deleted" internal property set', 'OK', 'fail');  
	$streamPosts1 = $this->msg->getStream($ne2->key());
	$wallPosts1 = $this->msg->getPostList($ne1->key());
  $postFound9 = -1; $postFound10 = -1;
  foreach($streamPosts1['list'] as $pds)
    if($pds['m_id'] == $post->data['msgid']) $postFound9 = $pds['m_id']; 
  tlog($postFound9 == -1, 'Message gone from author stream', 'OK', 'fail (#'.$postFound9.')');
	foreach($wallPosts1['list'] as $pds)
	  if($pds['m_id'] == $post->data['msgid']) $postFound10 = $pds['m_id']; 
	tlog($postFound10 == -1, 'Message gone from owner profile', 'OK', 'fail ('.$postFound10.')');  
예제 #5
0
파일: test.vis.php 프로젝트: hcopr/Hubbub
  quickConnect($u[0]['id'], $u[2]['id']);
  quickConnect($u[1]['id'], $u[3]['id']);
  quickConnect($u[4]['id'], $u[3]['id']);

  foreach($u as $usr)
  {
    $isFriend[$usr['id']][$usr['id']] = true;
    $friends[$usr['id']] = getFriends($usr['id']);
    foreach($friends[$usr['id']] as $frid) $isFriend[$usr['id']][$frid] = true;
    $line = $usr['name'].' ('.$usr['id'].') Friends: '.implode(', ', $friends[$usr['id']]);
    tlog(true, 'Connections '.$line, 'OK', 'fail');
  }

  $post = new HubbubMessage('post');
	$post->localUserEntity = $u[0]['id'];
  $post->owner($u[0]['erec']);
  $post->data['text'] = 'This is a realtime message. Umlauts like üöä should be preserved.';
  $post->save();
  
  tlog($post->ds['m_key'] > 0, 'Message created by user ('.$u[0]['id'].')', 'OK (#'.$post->ds['m_key'].')', 'fail');

  // now let's see who has the message in their stream
  foreach($u as $usr)
  {
    if($isFriend[$u[0]['id']][$usr['id']])
      tlog(hasMessageInStream($this, $usr['id'], $post->ds['m_key']), 
        'User '.$usr['id'].' has message '.$post->ds['m_key'].' in stream', 'OK', 'fail'); 
    else
      tlog(!hasMessageInStream($this, $usr['id'], $post->ds['m_key']), 
        'User '.$usr['id'].' has message '.$post->ds['m_key'].' NOT in stream', 'OK', 'fail'); 
  }