Beispiel #1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER, $exporter;
     $userid = $instance->get_view()->get('owner');
     if (!$userid) {
         // 'My Friends' doesn't make sense for group/site views
         return '';
     }
     $limit = isset($exporter) ? false : MAXFRIENDDISPLAY;
     $friends = get_friends($userid, $limit, 0);
     if ($friends['count']) {
         self::build_myfriends_html($friends, $userid, $instance);
     } else {
         $friends = false;
     }
     $smarty = smarty_core();
     $smarty->assign('friends', $friends);
     $smarty->assign('searchingforfriends', array('<a href="' . get_config('wwwroot') . 'user/find.php">', '</a>'));
     // If the user has no friends, try and display something useful, such
     // as a 'request friendship' button
     if (!$friends) {
         $loggedinid = $USER->get('id');
         $is_friend = is_friend($userid, $loggedinid);
         if ($is_friend) {
             $relationship = 'existingfriend';
         } else {
             if (record_exists('usr_friend_request', 'requester', $loggedinid, 'owner', $userid)) {
                 $relationship = 'requestedfriendship';
             } else {
                 $relationship = 'none';
                 $friendscontrol = get_account_preference($userid, 'friendscontrol');
                 if ($friendscontrol == 'auto') {
                     require_once 'pieforms/pieform.php';
                     $newfriendform = pieform(array('name' => 'myfriends_addfriend', 'successcallback' => 'addfriend_submit', 'autofocus' => false, 'renderer' => 'div', 'elements' => array('add' => array('type' => 'button', 'usebuttontag' => true, 'class' => 'btn-default', 'value' => '<span class="icon icon-user-plus icon-lg prs"></span>' . get_string('addtomyfriends', 'group')), 'id' => array('type' => 'hidden', 'value' => $userid))));
                     $smarty->assign('newfriendform', $newfriendform);
                 }
                 $smarty->assign('friendscontrol', $friendscontrol);
             }
         }
         $smarty->assign('relationship', $relationship);
     }
     $smarty->assign('loggedin', is_logged_in());
     $smarty->assign('lookingatownpage', $USER->get('id') == $userid);
     $smarty->assign('USERID', $userid);
     return $smarty->fetch('blocktype:myfriends:myfriends.tpl');
 }
Beispiel #2
0
function get_friends($screen_name, $cursor = -1)
{
    print "getting friends of {$screen_name}\n";
    global $twitter_keys, $current_key, $ratefree, $bin_name, $dbh;
    $ratefree--;
    if ($ratefree < 1 || $ratefree % 10 == 0) {
        $keyinfo = getRESTKey($current_key, 'friends', 'list');
        $current_key = $keyinfo['key'];
        $ratefree = $keyinfo['remaining'];
    }
    $tmhOAuth = new tmhOAuth(array('consumer_key' => $twitter_keys[$current_key]['twitter_consumer_key'], 'consumer_secret' => $twitter_keys[$current_key]['twitter_consumer_secret'], 'token' => $twitter_keys[$current_key]['twitter_user_token'], 'secret' => $twitter_keys[$current_key]['twitter_user_secret']));
    $params = array('cursor' => $cursor, 'skip_status' => true, 'count' => 200, 'include_user_entities' => false, 'screen_name' => $screen_name);
    $tmhOAuth->user_request(array('method' => 'GET', 'url' => $tmhOAuth->url('1.1/friends/list'), 'params' => $params));
    if ($tmhOAuth->response['code'] == 200) {
        $data = json_decode($tmhOAuth->response['response'], true);
        $observed_at = strftime("%Y-%m-%d %H-%M-%S", date('U'));
        $friends = $data['users'];
        $cursor = $data['next_cursor'];
        echo count($friends) . " users found\n";
        // store in db
        $tr = new TwitterRelations($screen_name, $friends, "friend", $observed_at);
        $tr->save($dbh, $bin_name);
        // continue if there are still things to do
        if (!empty($cursor) && $cursor != -1) {
            sleep(1);
            get_friends($screen_name, $cursor);
        }
    } else {
        $error_code = json_decode($tmhOAuth->response['response'])->errors[0]->code;
        if ($error_code == 130) {
            print "Twitter is over capacity, sleeping 5 seconds before retry\n";
            sleep(5);
            get_friends($screen_name, $cursor);
        } elseif ($error_code == 88) {
            print "API key rate limit exceeded, sleeping 60 seconds before retry\n";
            sleep(60);
            get_friends($screen_name, $cursor);
        } else {
            echo "\nAPI error: " . $tmhOAuth->response['response'] . "\n";
        }
    }
}
Beispiel #3
0
    return $queries;
}
// Comparison function based on mutual friend count
function cmp($a, $b)
{
    if ($a['count'] == $b['count']) {
        return 0;
    }
    return $a['count'] < $b['count'] ? 1 : -1;
}
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
        echo "<pre>";
        $response = get_friends();
        //array_splice($response, 50);
        $queries = get_queries($response);
        $BATCH_SIZE = 50;
        $batches = array_chunk($queries, $BATCH_SIZE);
        $i = 0;
        foreach ($batches as $batch) {
            try {
                $mutual = $facebook->api('/?batch=' . json_encode($batch), 'POST');
                foreach ($mutual as $idx => $dict) {
                    $body = $dict['body'];
                    $arr = json_decode($body);
                    $response[$i * $BATCH_SIZE + $idx]['count'] = count($arr);
                }
            } catch (FacebookApiException $e) {
                print_r($e);
Beispiel #4
0
 private function getFriendsList()
 {
     $list = array();
     $friends = get_friends($this->user->get('id'), 0, 0);
     if ($friends && array_key_exists('data', $friends) && is_array($friends['data'])) {
         foreach ($friends['data'] as $friend) {
             $list[] = $friend->id;
         }
     }
     return $list;
 }
Beispiel #5
0
                 ));
         $tmhOAuth->config['user_token'] = $_SESSION['access_token']['oauth_token'];
         $tmhOAuth->config['user_secret'] = $_SESSION['access_token']['oauth_token_secret'];

         //Twittear
         if ($_COOKIE['twitear'] != "no") {
            $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array(
                'status' => "Usando las Twit-Herramientas \"Test de reciprocidad\": Descubre gente a la que que sigues pero no te sigue a ti. " . KCY,
            ));
         }

         // Conseguir Followers
	get_followers();

         //Conseguir Firends
	get_friends();

//      if ($followers['num'] == 5000 || $friends['num'] == 5000) {
//        echo("<p align=\"center\">Atención: Tienes más de 5000 followers o sigues a más de 5000 personas.<br>
//            La operación se realizará con los 5000 más recientes.</p>");
//      }
         //Comparar
         foreach ($friends['ids'] as $hamijo) {
            if (!in_array($hamijo, $followers['ids'])) {
               $traidores[] = $hamijo;
            }
         }
         If (count($traidores) != 0) {

            $tmhOAuth->request('GET', $tmhOAuth->url('1/users/lookup'), array(
                'user_id' => implode(",", array_slice($traidores, 0, 100)),
Beispiel #6
0
 /**
  * 更新好友列表并返回好友信息。若参数为空,则返回存储的好友信息。
  * @param $params
  *  require    u          --  userid
  *             fids       --  好友平台id字符串,用逗号隔开
  *             t       -- update ,强制调用平台方法获取好友
  * @return
  *             s          --  OK,others fail
  *             infos      --  好友信息数组
  *             u          --  好友内部id数组 ? why? infos already have the id
  *             a          --  好友帐户信息数组 //why not use map ,dbid 
  */
 public function get($params)
 {
     $now = time();
     $uid = $params['u'];
     $upd = $params['t'];
     $tu = new TTUser($uid);
     $fids = $params['fids'];
     $infos = $tu->get('fr', false);
     if (!$fids) {
         $fids = $tu->getf(TT::FRIEND_STAT);
         if (!$fids || $upd == 'update') {
             //call from platform
             require_once WEB_ROOT . 'platform_tools.php';
             $fids = get_friends($uid);
             if ($fids) {
                 $tu->putf(TT::FRIEND_STAT, $fids);
             }
         }
     } else {
         $tu->putf(TT::FRIEND_STAT, $fids);
     }
     $fl = explode(',', $fids);
     $rinfos = array();
     $dup = array();
     $now = time();
     $dup['253382225'] = 1;
     $friend_count = 0;
     //记录好友个数
     foreach ($fl as $pid) {
         if ($dup[$pid]) {
             continue;
         }
         $dup[$pid] = 1;
         $finfos = TTGenid::getbypid($pid);
         //by tingkun
         $id = $finfos['id'];
         if ($id) {
             $fdid = $tu->getdid($id, 'fr');
             $fdata = json_decode($infos[$fdid], true);
             //if(!$fdata ||  $fdata['ut']<$now - 3600){
             if (!$fdata || $fdata['ut'] < $now - 3600) {
                 $ftu = new TTUser($finfos['id']);
                 $acc = $ftu->getdata(array('money', 'exp', 'gem'));
                 if (!$acc['exp']) {
                     continue;
                 }
                 $acc['name'] = $finfos['name'];
                 $acc['icon'] = $finfos['icon'];
                 $acc['pid'] = $pid;
                 $acc['ut'] = $now;
                 $acc['id'] = $fdid;
                 $acc['dbid'] = $id;
                 $tu->puto($acc);
                 $rinfos[] = $acc;
             } else {
                 $rinfos[] = $fdata;
             }
             unset($infos[$fdid]);
         }
         $friend_count++;
     }
     if ($friend_count > $tu->getf('friend_count')) {
         $tu->putf('friend_count', $friend_count);
     }
     //*
     $rinfos[] = array('name' => 'GM', 'icon' => 'http://hd45.xiaonei.com/photos/hd45/20080915/11/09/tiny_tDX1_3400c200150.jpg', 'pid' => '253382225', 'exp' => '10000', 'dbid' => 2, 'ht' => $now, 'help_car' => 1);
     //GM
     //*/
     $ret['infos'] =& $rinfos;
     $ret['s'] = 'OK';
     return $ret;
 }
Beispiel #7
0
            echo $post['post_title'];
            ?>
</a></h2>
			<?php 
        }
    }
} else {
    echo '<p>No hay ninguna entrada en el blog todavía.</p>';
}
?>
		</div>
		
		<div class="related-contacts">
			<h3 class="site-subtitle">Mis Contactos</h3>
			<?php 
$contacts = get_friends($_GET['id']);
if (count($contacts) == 0) {
    echo '<p>Todavía no tengo ningún contacto</p>';
} else {
    $result = "<ul>";
    foreach ($contacts as $contact_id => $rel) {
        $contact_data = get_userdata((int) $contact_id);
        $result .= '<li><img src="' . author_image_path($contact_id, $display = false) . '" width=25 height=25 /> <a href="?id=' . $contact_id . '">' . $contact_data->display_name . '</a>. -> ' . $rel . '</li>';
        if ($userdata->ID == $_GET['id']) {
            $result .= '<span class="elim"><a href="?id=' . $_GET['id'] . '&elim=' . $contact_id . '">Eliminar este contacto</a></span>';
        }
    }
    $result .= "</ul>";
    echo $result;
}
?>
 function handle($params)
 {
     require_once 'api.php';
     $query = Dataface_Application::getInstance()->getQuery();
     switch ($query['-do']) {
         case 'login':
             $token = login($query['username'], $query['password']);
             if (!$token) {
                 $this->output(array('code' => 400, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'token' => $token));
             }
             return;
         case 'logout':
             $token = logout($query['token']);
             if (!$token) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'register':
             $res = register($query['username'], $query['password']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'get_friends':
             $friends = get_friends($query['token']);
             if ($friends === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'friends' => $friends));
             }
             return;
         case 'find_users':
             $results = find_users($query['token'], $query['filter']);
             if ($results === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'results' => $results));
             }
             return;
         case 'get_pending_friend_requests':
             $requests = get_pending_friend_requests($query['token']);
             if ($requests === false) {
                 $this->output(array('code' => 500, 'message' => 'Failed to get friend requests'));
             } else {
                 $this->output(array('code' => 200, 'requests' => $requests));
             }
             return;
         case 'send_friend_request':
             $res = send_friend_request($query['token'], $query['friend']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'accept_friend_request':
             $res = accept_friend_request($query['token'], $query['friend']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'decline_friend_request':
             $res = decline_friend_request($query['token'], $query['friend']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'post':
             $file_path = null;
             $file_name = null;
             if (@$_FILES['photo']) {
                 $file_path = $_FILES['photo']['tmp_name'];
                 $file_name = $_FILES['photo']['name'];
             }
             $res = post($query['token'], $query['comment'], $file_path, $file_name);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'post_id' => $res));
             }
             return;
         case 'get_posts':
             $posts = get_posts($query['token'], @$query['username'], @$query['older_than']);
             if ($posts === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'posts' => $posts));
             }
             return;
         case 'get_feed':
             $posts = get_feed($query['token'], @$query['older_than']);
             if ($posts === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'posts' => $posts));
             }
             return;
         case 'get_profile':
             $profile = get_profile($query['token'], $query['username']);
             if ($profile === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'profile' => $profile));
             }
             return;
         case 'update_profile':
             $vals = array();
             if (@$query['screen_name']) {
                 $vals['screen_name'] = $query['screen_name'];
             }
             if (@$_FILES['avatar']) {
                 $vals['avatar'] = $_FILES['avatar']['tmp_name'];
             }
             $res = update_profile($query['token'], $vals);
             if ($res !== false) {
                 $this->output(array('code' => 200));
             } else {
                 $this->output(array('code' => 500, 'message' => error_message()));
             }
             return;
     }
 }
<?php

/**
 *
 * @package    mahara
 * @subpackage blocktype-myfriends
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */
define('INTERNAL', 1);
define('JSON', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
safe_require('blocktype', 'myfriends');
require_once 'user.php';
$offset = param_integer('offset');
$limit = param_integer('limit', MAXFRIENDDISPLAY);
$bi = new BlockInstance(param_integer('block'));
if (!can_view_view($bi->get('view'))) {
    json_reply(true, get_string('accessdenied', 'error'));
}
$userid = $bi->get_view()->get('owner');
$friends = get_friends($userid, $limit, $offset);
PluginBlocktypeMyfriends::build_myfriends_html($friends, $userid, $bi);
unset($friends['data']);
json_reply(false, array('data' => $friends));
Beispiel #10
0
function show_group_blog_form_options()
{
    global $current_user;
    $result = '';
    $friends = get_friends($current_user->ID);
    if (count($friends) != 0) {
        $i = 0;
        $results .= _e('Agrega si lo deseas a tus contactos como editores del nuevo blog: <br />');
        foreach ($friends as $id => $rel) {
            $i++;
            $friend = get_userdata((int) $id);
            $result .= '<img src="' . author_image_path($id, $display = false) . '" width=25 height=25 /> ' . $friend->display_name . ' <input type="checkbox" name="' . $i . '" value="' . $id . '" /> <br />';
        }
        $result .= '<input type="hidden" name="count_friends" value="' . $i . '">';
    }
    echo $result;
}
 public function GetResults()
 {
     $userID = $this->User['UserID'];
     return get_friends($userID);
 }