Example #1
0
	function friend_request($toEntity, $msgtype = 'friend_request')
	{
    $fr = new HubbubMessage($msgtype);
    $fr->to($toEntity->ds);
    $fr->from(object('user')->entity);
    $res = $fr->sendToUrl($toEntity->ds['server']);
		return($res);
	}
Example #2
0
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();
}
Example #3
0
 function pollFeed($serverObj, $time)
 {
   $pollMsg = new HubbubMessage('feed_poll');
   $pollMsg->author(HubbubServer::localEntity());
   $pollMsg->data['last'] = $time;
   $pollMsg->sendToUrl($serverObj->ds['s_url']);
   return($pollMsg->responseData);
 }
Example #4
0
function post_receive_single(&$data, &$msg)
{
    // we're receiving this message because the sender(=owner) has published something on their profile
    WriteToFile('log/activity.log', $data['msgid'] . ':' . $msg->authorEntity->key() . ':' . $msg->ownerEntity->key() . ' received' . chr(10));
    // if this was created from a foreign message
    if ($data['rel']['foreign'] != '') {
        // let's check if the foreign message can be deleted
        $fods = new HubbubMessage();
        $fods->load(array('id' => $data['rel']['foreign'], 'field' => 'm_id'));
        if ($fods->data['type'] == 'foreign_post' && $fods->ownerEntity->key() == $msg->ownerEntity->key()) {
            $fods->delete();
        }
    }
    $msg->save();
    $msg->ok();
}
Example #5
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;
}
Example #6
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();
}
Example #7
0
<?

$ds = DB_GetDataset('messages', $_REQUEST['id']);
$data = HubbubMessage::unpackData($ds);

$data['created'] = $data['created'].' ('.gmdate('Y-m-d H:i:s', $data['created']).')';
$data['changed'] = $data['changed'].' ('.gmdate('Y-m-d H:i:s', $data['changed']).')';

?>
<h2>Inspect Message <?php 
echo $_REQUEST['id'];
?>
</h2>
<pre><?
  print('Message Data '); print_r($data);
  $ds['m_data'] = strlen($ds['m_data']).' bytes';
  print('Local Storage '); print_r($ds);
  ?></pre>
Example #8
0
  $mds = DB_GetDataset('messages', $post->ds['m_key']);
  $textData = HubbubMessage::unpackData($mds);
  tlog($mds['m_deleted'] == 'Y', 'm_deleted in DB', 'OK (#'.$mds['m_key'].')', 'fail');  
  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.')');
Example #9
0
	function Post($p)
	{
		// posts and comments have the same basic structure: author, owner and text
		// if the author is also the owner, we do not need to send a foreign_post message
		if($p['author']['_key'] == $p['owner']['_key'])
		{
			$msg = $this->makePostMessage('post', $p);
			$msg->broadcast();
		}
		else
		{
      $msg = $this->makePostMessage('foreign_post', $p);
      WriteToFile('log/activity.log', $type.' sending: '.$msg->data['msgid'].' '.dumpArray($msg->data).chr(10));
      $res = $msg->sendToOwner();
      // if the post was accepted right away:
      if(sizeof($res['post']) > 0)
      {
        $msg->delete();
        $msg = new HubbubMessage();
        $msg->receive_single($res['post']);
      }
		}
		return($msg->ds);
	}  
Example #10
0
 function msg_trust_sendkey1()
 {
     // make a trust_sendkey1 message
     $msg = new HubbubMessage('trust_sendkey1');
     $msg->to($this->entity());
     $msg->data['author'] = $this->localEntity();
     $this->save();
     // make new key if there is none
     $this->ds['s_key_in'] = getDefault($this->ds['s_key_in'], randomHashId());
     if ($this->ds['s_url'] != '') {
         DB_UpdateField('servers', $this->ds['s_key'], 's_key_in', $this->ds['s_key_in']);
     }
     $msg->data['mykey'] = $this->ds['s_key_in'];
     // we need to save at this point because the other server will try to make a trust_sendkey2-request in the meantime
     // send message to other server
     $responseData = $msg->sendToUrl($this->ds['s_url']);
     if ($responseData['result'] == 'OK') {
         $this->ds['s_status'] = 'OK';
         $ret = result_ok();
     } else {
         $this->ds['s_status'] = 'fail';
         $this->ds['s_key_in'] = '';
         logError('notrace', '[OUT] trust_sendkey1 failed, server ' . $this->ds['s_url'] . ' says: ' . getDefault($responseData['reason'], $responseData['result']));
         $ret = result_fail('trust_sendkey1 failed: ' . getDefault($responseData['reason'], $responseData['result']));
     }
     return $ret;
 }
Example #11
0
  quickConnect($u[0]['id'], $u[1]['id']);
  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']), 
Example #12
0
function tmpl_commentlist($postDS, &$comments, $withContainer = false)
{
  if($withContainer) print('<div class="comment_list" id="comments_'.$postDS['m_key'].'">');

  if($comments['count'] > 3 && sizeof($comments['list'])==3)
	{
		?><div class="comment_item smalltext">&nbsp; <a onclick="loadThread(<?php 
echo $postDS['m_key'];
?>
)">▼ Show entire conversation</a> (<?php 
echo $comments['count'];
?>
)</div><?
	}

  if(sizeof($comments['votes']) > 0)
  {
  	foreach($comments['votes'] as $voteDS)
		{
			$vData = HubbubMessage::unpackData($voteDS);
      ?><div class="comment_item smalltext">&nbsp; <?php 
echo htmlspecialchars(substr($vData['text'], 1));
?>
 (<?php 
echo $voteDS['votecount'];
?>
)</div><?
		}
  }

  if(sizeof($comments['list'])) foreach($comments['list'] as $comment)
	{
    $data = HubbubMessage::unpackData($comment);
	  $metaElements = array(
	    ageToString($comment['m_created']));
    if(object('user')->entity == $comment['m_owner'] || object('user')->entity == $comment['m_author']) $metaElements[] = '<a onclick="deleteComment('.$comment['m_key'].')">Delete</a>';
		?><div id="comment_item_<?php 
echo $comment['m_key'];
?>
" class="comment_item comment_entry">
				<div class="comment_img"><img src="img/anonymous.png" width="32"/></div>
				<div class="comment_text"><?php 
echo HubbubEntity::linkFromId($comment['m_author']);
?>
				  <?php 
echo h2_post_excerpt($data['text'], $comment['m_key']);
?>
	
				  <div class="comment_meta"><?php 
echo implode(' · ', $metaElements);
?>
</div></div>
		</div><?
	}

  if($withContainer) { ?></div><? }
}