Exemple #1
0
function _post_save_vote(&$data, &$msg)
{
    $msg->voteHash = md5(strtolower(substr($data['text'], 1)));
    // but if this person already voted, we need to unregister these previous votes
    DB_Update('UPDATE ' . getTableName('messages') . ' SET m_votehash = "", m_deleted = "Y" WHERE m_parent = ? AND m_author = ?', array($msg->parentKey, $msg->authorEntity->key()));
    DB_Update('DELETE FROM ' . getTableName('votes') . ' WHERE v_msg = ?', array($msg->parentKey));
    // update the vote summary
    foreach (DB_GetList('SELECT COUNT(*) as votecount,m_data,m_id,m_votehash as count FROM ' . getTableName('messages') . '
    WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash != ""
    GROUP BY m_votehash') as $vds) {
        $msgData = HubbubMessage::unpackData($vds);
        // get the some exemplary votes for this
        $voterList = array();
        foreach (DB_GetList('SELECT m_author FROM ' . getTableName('messages') . ' WHERE m_parent = ? AND m_votehash = ? ORDER BY m_created DESC LIMIT 3', array($msg->parentKey, $vds['m_votehash'])) as $vex) {
            $voterList[] = $vex;
        }
        // if this is also what this message votes for, add it to the list
        if ($this->{$msg}->voteHash == $vds['m_votehash']) {
            $voterList[] = getDefault($msg->authorKey, $msg->ownerKey);
        }
        // make the vote summary dataset
        $voteDS = array('v_msg' => $msg->parentKey, 'v_choice' => $vds['m_votehash'], 'v_text' => $msgData['text'], 'v_voters' => implode(',', $voterList), 'v_count' => $vds['votecount']);
        DB_UpdateDataset('votes', $voteDS);
    }
}
Exemple #2
0
	function getFriends($filter = 'friend', $forUserEntity = null)
	{
		if($forUserEntity == null) $forUserEntity = object('user')->entity;
		return(DB_GetList('SELECT * FROM '.getTableName('connections').'
		  LEFT JOIN '.getTableName('entities').' ON (c_to = _key)
		  WHERE c_from=? AND c_status=?
		  ORDER BY `name` ASC', array($forUserEntity, $filter)));
	}
Exemple #3
0
 function getFriends($eid)
 {
   $result = array();
   foreach(DB_GetList('SELECT * FROM '.getTableName('connections').' WHERE c_from = ?', array($eid)) as $cds)
   {
     $result[] = $cds['c_to'];
   }
   return($result);
 }
Exemple #4
0
	function __init()
	{
    access_policy('auth');
    
		foreach(DB_GetList('SELECT c_status,COUNT(*) as count FROM '.getTableName('connections').'
		  WHERE c_from = ?
			GROUP BY c_status', array($this->user->entity)) as $item)
			$menuCount[$item['c_status']] = $item['count'];
		$countArray = array();
    if($menuCount['friend'] > 0) $countArray[] = ' ('.$menuCount['friend'].')'; else $countArray[] = '';
		$countArray[] = '';
    if($menuCount['req.rcv'] > 0) $countArray[] = ' ('.$menuCount['req.rcv'].')'; else $countArray[] = '';
    if($menuCount['req.sent'] > 0) $countArray[] = ' ('.$menuCount['req.sent'].')'; else $countArray[] = '';
    
    $this->menu = $this->makeMenu('index,add,ab,rcv', $countArray);
		$this->invokeModel();
    $this->myEntity = $this->user->selfEntity();
    $this->integrate('ab');
	}
Exemple #5
0
	function getComments($forPostKey, $getLimit = 3)
	{
		$countDS = DB_GetDatasetWQuery('SELECT COUNT(*) as count FROM '.getTableName('messages').'
        WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash = ""
        ', array($forPostKey));
		return(array(
		  'count' => $countDS['count'],
			'votes' => DB_GetList('SELECT COUNT(*) as votecount,m_data,m_id as count FROM '.getTableName('messages').'
        WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash != ""
        GROUP BY m_votehash
				ORDER BY votecount DESC, m_created ASC
				LIMIT 10
        ', array($forPostKey)),
		  'list' => array_reverse(DB_GetList('SELECT * FROM '.getTableName('messages').'
	      WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash = ""
	      ORDER BY m_created DESC
				LIMIT '.$getLimit, array($forPostKey))),
			));
	}
Exemple #6
0
function feed_poll_receive(&$data, &$msg)
{
    if (!$msg->validateSignature()) {
        return true;
    }
    $forServer = new HubbubServer($msg->authorEntity->ds['server']);
    $msg->response['listing_time'] = time();
    $msg->response['_listing_from_date'] = gmdate('Y-m-d H:i:s', $msg->data['last']);
    $msg->response['_listing_to_date'] = gmdate('Y-m-d H:i:s');
    $msg->response['_for_server'] = $msg->authorEntity->ds['server'] . ':' . $forServer->ds['s_key'];
    $serverKey = $forServer->ds['s_key'];
    // let's get a list of items
    $msg->response['feed'] = array();
    foreach (DB_GetList('SELECT * FROM ' . getTableName('messages') . ' LEFT JOIN ' . getTableName('connections') . ' ON (c_toserverkey = ' . $serverKey . ' AND (c_from = m_owner OR c_from = m_author)) ' . ' WHERE c_toserverkey > 0 AND m_publish="Y" AND m_changed >= "' . ($msg->data['last'] + 0) . '" ' . ' GROUP BY m_key ' . ' LIMIT ' . cfg('service/maxfeedsize', 200)) as $msgDS) {
        $resultCount++;
        $msg->response['feed'][] = json_decode(gzinflate($msgDS['m_data']), true);
    }
    $msg->response['_count'] = $resultCount;
    $msg->ok();
}
Exemple #7
0
    function GetClosestServers($entityId)
    {
        return DB_GetList('SELECT *,SUM(c_count_sent) as sent_count FROM ' . getTableName('connections') . ' 
	     LEFT JOIN ' . getTableName('servers') . ' ON (c_toserverkey = s_key)
	     WHERE c_from = "' . ($entityId + 0) . '" and c_status="friend" 
	     GROUP BY c_toserverkey
	     ORDER BY sent_count DESC
	     LIMIT ' . getDefault($GLOBALS['config']['service']['dmn_maxsize'], 10));
    }