예제 #1
1
 public function show($segments)
 {
     extract($_POST);
     if (!isset($username)) {
         $username = $segments[1];
     }
     $entry = DB::query('select id,username,title,location,bio,avatar from users where username = \'' . $username . '\'', 1);
     $entry['activity'] = DB::query('select count(*) as activity from feed where user_id = \'' . $entry['id'] . '\'', 2, 'activity');
     if (!is_file(PATH_UPLOAD . 'profile/' . $entry['avatar'])) {
         $entry['avatar'] = 'default.png';
     }
     $feed = array();
     $feedraw = DB::query('select * from feed where user_id = ' . $entry['id'] . ' and privacy_id = 1 order by id desc limit 20', 0);
     foreach ($feedraw as $i => $row) {
         $feed[$i] = $row;
         $feed[$i]['status'] = Feed::parse_status($row['status']);
         $feed[$i]['files'] = Feed::get_files($row['id'], 'th');
         if (isset($row['created_ts'])) {
             $feed[$i]['timespan'] = timespan($row['created_ts']);
         }
     }
     $follow_btn = "";
     if ($entry['id'] != $_SESSION['user_id']) {
         $following = DB::query('select id from follows where user_id = ' . $_SESSION['user_id'] . ' and user2_id = ' . $entry['id'], 1);
         if ($following) {
             $follow_btn = '<button class="btn btn-success follow" data-id="' . $entry['id'] . '"><i class="ion-checkmark-round"></i> ' . _l('Following') . ' </button>';
         } else {
             $follow_btn = '<button class="btn btn-info follow" data-id="' . $entry['id'] . '"><i class="ion-ios-bolt"></i> ' . _l('Follow') . ' </button>';
         }
     }
     return array('view' => "account", 'follow_btn' => $follow_btn, 'entry' => $entry, 'feed' => $feed);
 }
예제 #2
0
    public function connect()
    {
        $j = 0;
        $feed = array();
        $online = array();
        $feed_ids = array();
        extract($_POST);
        $connect_user = $segments[1];
        if (strlen($connect_user)) {
            $connect_id = DB::query('select id from users where username = \'' . $connect_user . '\'', 2, 'id');
        }
        if (!$connect_id) {
            return false;
        }
        $user_id = $_SESSION['user_id'];
        if (!isset($limit_ts)) {
            $limit_ts = time() - 3600 * 24 * 30;
            // when read first time, update for online timestamp
            DB::write('update users set updated_ts = ' . time() . ' where id = ' . $user_id);
        }
        IController::keep_online();
        $follows = DB::query('select user2_id from follows where user_id = ' . $user_id, 4, 'user2_id');
        $follows[] = $user_id;
        $feedraw = DB::query('select feed.*, users.username, users.title as user, users.avatar 
			from mentions  
			left join feed on feed.id = mentions.feed_id 
			left join users on users.id = feed.user_id 
			where mentions.user_id in(' . implode(',', array($user_id, $connect_id)) . ') 
			group by mentions.feed_id
			order by feed.created_ts desc 
			limit 20', 0);
        $onlineraw = DB::query('select users.username, users.title, users.lastlogin_ts, users.last_ts    
			from follows  
			inner join users on users.id = follows.user2_id 
			where follows.user_id = ' . $_SESSION['user_id'] . ' 
			group by follows.user2_id', 0);
        if (count($follows)) {
            $feed_ids = DB::query('select feed.id 
				from feed 
				left join users on users.id = feed.user_id 
				where feed.user_id in(' . implode(',', $follows) . ') 
				order by feed.created_ts desc 
				limit 20', 4, 'id');
        }
        foreach ($feedraw as $i => $row) {
            // mark as read
            $feed[$j] = $row;
            if (!is_file(PATH_UPLOAD . 'profile/' . $row['avatar'])) {
                $feed[$j]['avatar'] = 'default.png';
            }
            $feed[$j]['status'] = Feed::parse_status($row['status']);
            $feed[$j]['files'] = Feed::get_files($row['id'], 'th');
            if (isset($row['created_ts'])) {
                $feed[$j]['timespan'] = timespan($row['created_ts']);
            }
            $j++;
        }
        foreach ($onlineraw as $i => $row) {
            $status = "offline";
            if ($row['last_ts'] > time() - 20) {
                // n + 2
                $status = "online";
            }
            $online[$i]['unread'] = 0;
            $online[$i] = $row;
            $online[$i]['timespan'] = timespan($row['lastlogin_ts']);
            $online[$i]['unread'] = DB::query('select count(*) as total from feed where id in(' . implode(',', $feed_ids) . ') and read_ts = 0', 2, 'total');
            $online[$i]['total'] = DB::query('select count(*) as total from mentions where user2_id = ' . $user_id, 2, 'total');
            $online[$i]['status'] = $status;
            $online[$i]['show_as'] = 'mention';
            if ($feed_ids) {
                $online[$i]['unread'] = DB::query('select count(*) as total from feed where id in (' . implode(',', $feed_ids) . ') and read_ts = 0', 2, 'total');
            }
        }
        DB::write('update feed set read_ts = ' . time() . ' where id in (' . implode(',', $feed_ids) . ')');
        return array('feed' => $feed, 'online' => $online);
    }