header('HTTP/1.1 500 Internal Server Error'); } else { echo generate_error($api_session->format, 'Server error (Stage 1).', $_SERVER['REQUEST_URI'], $api_session->callback); } exit; } $followers = array_keys($info->followers); if (!count($followers)) { if (!isset($_GET['suppress_response_codes'])) { header('HTTP/1.1 304 Not Modified'); } else { echo generate_error($api_session->format, 'No followers found.', $_SERVER['REQUEST_URI'], $api_session->callback); } exit; } $num_rows = count($followers); $twitter_data = new TwitterData($api_session->format, $api_session->callback, $desired_user_id, TRUE); $answer = $twitter_data->data_header(); $answer .= $twitter_data->data_section('id_list', FALSE, FALSE, TRUE, ' type="array"'); $answer .= $twitter_data->data_section('ids'); foreach ($followers as $user_id) { $check = $num_rows - 1 > 0 ? true : false; $answer .= $twitter_data->data_field('id', $user_id, $check); $num_rows--; } $answer .= $twitter_data->data_section('ids', FALSE, TRUE); $answer .= $twitter_data->data_section('id_list', FALSE, TRUE, TRUE); $answer .= $twitter_data->data_bottom(); echo $answer; exit; }
if (!$res) { $error = TRUE; $errmsg = 'Inappropriate image file.'; } } if (!$error) { $old = $user->info->avatar; if ($old != $C->DEF_AVATAR_USER) { rm($C->IMG_DIR . 'avatars/' . $old); rm($C->IMG_DIR . 'avatars/thumbs1/' . $old); rm($C->IMG_DIR . 'avatars/thumbs2/' . $old); rm($C->IMG_DIR . 'avatars/thumbs3/' . $old); } $this->db2->query('UPDATE users SET avatar="' . $this->db2->escape($fn) . '" WHERE id="' . intval($this->db2->e($user->id)) . '" LIMIT 1'); $network->get_user_by_id($user->id, TRUE); $twitter_data = new TwitterData($api_session->format, $api_session->callback, $user->id); $answer = $twitter_data->data_header(); $answer .= $twitter_data->data_section('user'); $answer .= $twitter_data->print_user($user->id); $answer .= $api_session->format == 'json' ? ',' : ''; $answer .= $twitter_data->data_section('status', TRUE); $sid = $this->db2->fetch_field('SELECT id AS pid FROM posts WHERE user_id="' . intval($this->db2->e($user->id)) . '" AND api_id NOT IN(2,6) ORDER BY id DESC LIMIT 1'); $answer .= $twitter_data->print_status($sid); $answer .= $twitter_data->data_section('status', FALSE, TRUE); $answer .= $twitter_data->data_section('user', FALSE, TRUE); $answer .= $twitter_data->data_bottom(); echo $answer; exit; } else { if (!isset($_POST['suppress_response_codes'])) { header('HTTP/1.1 403 Forbidden');
$tmp2 = trim($tmp2); $tmp2 = ''; $in_sql[] = '(MATCH(p.message) AGAINST("' . $tmp2 . '" IN BOOLEAN MODE) OR p.message LIKE "%' . $tmp . '%")'; } else { $in_sql[] = 'p.message LIKE "%' . $tmp . '%"'; } $in_sql = implode(' AND ', $in_sql); $num_results = $this->db2->fetch_field('SELECT COUNT(id) FROM posts p WHERE ' . $in_sql); $num_pages = ceil($num_results / $num_per_page); $num_pages = !$num_pages ? 1 : $num_pages; $pg = min($pg, $num_pages); $from = ($pg - 1) * $num_per_page; $results = array(); $tmp = $this->db2->query('SELECT p.*, "public" AS `type` FROM posts p WHERE ' . $in_sql . ' ORDER BY p.id DESC LIMIT ' . $from . ', ' . $num_per_page); $num_rows = $this->db2->num_rows($tmp); $twitter_data = new TwitterData($api_session->format, $api_session->callback, $user->id, TRUE); $answer = $twitter_data->data_header(); $answer .= $twitter_data->data_section('results', FALSE, FALSE, TRUE, ' type="array"'); while ($obj = $this->db2->fetch_object($tmp)) { $answer .= $twitter_data->data_section('result', FALSE); $answer .= $twitter_data->data_field('to_user_id', $obj->id); $answer .= $twitter_data->data_field('to_user', $C->SITE_TITLE . ' API'); $answer .= $twitter_data->data_field('text', htmlspecialchars($obj->message), FALSE); $answer .= $twitter_data->data_section('result', FALSE, TRUE); $answer .= $api_session->format == 'json' && $num_rows - 1 > 0 ? ',' : ''; $num_rows--; } $answer .= $twitter_data->data_section('results', FALSE, TRUE, TRUE); $answer .= $twitter_data->data_bottom(); echo $answer; exit;
} } elseif (isset($_GET['page']) && !isset($_GET['count'])) { if (is_numeric($_GET['page'])) { $q .= ' LIMIT ' . 20 * (intval($_GET['page']) - 1) . ', ' . 20 * intval($_GET['page']); } } elseif (isset($_GET['page']) && isset($_GET['count'])) { if (is_numeric($_GET['page']) && is_numeric($_GET['count'])) { $q .= ' LIMIT ' . intval($_GET['count']) * (intval($_GET['page']) - 1) . ', ' . intval($_GET['count']) * intval($_GET['page']); } } else { $q .= ' LIMIT 20'; } $res = $this->db2->query($q); $num_rows = $this->db2->num_rows($res); if ($num_rows > 0) { $twitter_data = new TwitterData($api_session->format, $api_session->callback, $user->id, TRUE); $answer = $twitter_data->data_header(); if ($twitter_data->is_feed()) { while ($stat = $this->db2->fetch_object($res)) { $answer .= $twitter_data->print_status_simple($stat->pid, 'private'); } } else { $answer .= $twitter_data->data_section('direct-messages', FALSE, FALSE, TRUE, ' type="array"'); while ($message = $this->db2->fetch_object($res)) { $answer .= $twitter_data->data_section('direct_message'); $answer .= $twitter_data->data_field('id', $message->id); $answer .= $twitter_data->data_field('sender_id', $message->user_id); $answer .= $twitter_data->data_field('text', htmlspecialchars($message->message)); $answer .= $twitter_data->data_field('recipient_id', $message->to_user); $answer .= $twitter_data->data_field('created_at', gmdate('D M d H:i:s \\+0000 Y', $message->date)); $answer .= $twitter_data->data_field('sender_screen_name', 'none');
$result = new stdClass(); $result->trends = new stdClass(); $result->as_of = $dts; foreach ($data as $dt => $tgs) { if (!isset($result->trends->dt)) { $result->trends->dt = array(); } foreach ($tgs as $tg) { $result->trends->dt = (object) array('query' => '#' . $tg, 'name' => '#' . $tg, 'url' => $C->SITE_URL . 'search/tab:posts/s:%23' . urlencode($tg)); } } if (!isset($result->trends->dt)) { $result->trends->dt = array(); } $num_rows = count($result->trends->dt); $twitter_data = new TwitterData($api_session->format, $api_session->callback, -1, TRUE); $answer = $twitter_data->data_header(); $answer .= $twitter_data->data_section('trends', FALSE, FALSE, TRUE, ' type="array"'); foreach ($result->trends->dt as $tr) { $answer .= $twitter_data->data_section('trend', FALSE); $answer .= $twitter_data->data_field('name', $tr->name); $answer .= $twitter_data->data_field('query', $tr->query); $answer .= $twitter_data->data_field('url', $tr->url, FALSE); $answer .= $twitter_data->data_section('trend', FALSE, TRUE); $answer .= $api_session->format == 'json' && $num_rows - 1 > 0 ? ',' : ''; $num_rows--; } $answer .= $twitter_data->data_section('trends', FALSE, TRUE, TRUE); $answer .= $twitter_data->data_bottom(); echo $answer; exit;
header('HTTP/1.1 400 Bad Request'); } else { echo generate_error($api_session->format, 'Invalid request method.', $_SERVER['REQUEST_URI'], $api_session->callback); } exit; } elseif (!$api_session->oauth_status && !$api_session->bauth_status) { if (!isset($_POST['suppress_response_codes'])) { header('HTTP/1.1 401 Unauthorized'); } else { echo generate_error($api_session->format, 'OAuth otorization problem: ' . $api_session->oauth_error, $_SERVER['REQUEST_URI'], $api_session->callback); } exit; } $res = $this->db2->query('SELECT id, groupname FROM groups WHERE is_public=1'); $num_rows = $this->db2->num_rows($res); $twitter_data = new TwitterData($api_session->format, $api_session->callback, -1, TRUE); $answer = $twitter_data->data_header(); $answer .= $twitter_data->data_section('groups', FALSE, FALSE, TRUE, ' type="array"'); while ($obj = $this->db2->fetch_object($res)) { $answer .= $twitter_data->data_section('group'); $answer .= $twitter_data->data_field('id', $obj->id); $answer .= $twitter_data->data_field('name', $obj->groupname, FALSE); $answer .= $twitter_data->data_section('group', FALSE, TRUE); $answer .= $api_session->format == 'json' && $num_rows - 1 > 0 ? ',' : ''; $num_rows--; } $answer .= $twitter_data->data_section('groups', FALSE, TRUE, TRUE); $answer .= $twitter_data->data_bottom(); echo $answer; exit; }
if (!$user->info->is_network_admin) { $api_session->not_in_groups = array(); $api_session->not_in_groups = not_in_groups(); $api_session->not_in_groups = count($api_session->not_in_groups) > 0 ? 'AND posts.group_id NOT IN(' . implode(', ', $api_session->not_in_groups) . ')' : ''; $api_session->without_users = protected_users(); $api_session->without_users = count($api_session->without_users) > 0 ? ' AND (posts.group_id>0 OR posts.user_id NOT IN(' . implode(', ', $api_session->without_users) . ')) ' : ''; } if ($api_session->resource == 'comments') { $q = 'SELECT posts_comments.id AS cid, posts_comments.message AS mtext FROM posts_comments, posts WHERE posts.user_id=' . intval($user->id) . ' AND posts_comments.post_id=' . intval($_GET['post_id']) . ' ' . $api_session->not_in_groups . $api_session->without_users . ' GROUP BY posts_comments.id ORDER BY posts_comments.id DESC LIMIT 20'; } else { $q = 'SELECT posts_pr_comments.id AS cid, posts_pr_comments.message AS mtext FROM posts_pr_comments, posts_pr WHERE posts_pr.user_id=' . intval($user->id) . ' AND posts_pr.id=' . intval($_GET['post_id']) . ' ' . $api_session->not_in_groups . $api_session->without_users . ' GROUP BY posts_pr_comments.id ORDER BY posts_pr_comments.id DESC LIMIT 20'; } $res = $this->db2->query($q); $num_rows = $this->db2->num_rows($res); if ($num_rows > 0) { $twitter_data = new TwitterData($api_session->format, $api_session->callback, $user->id, TRUE); $answer = $twitter_data->data_header(); $answer .= $twitter_data->data_section('comments', FALSE, FALSE, TRUE, ' type="array"'); while ($stat = $this->db2->fetch_object($res)) { $answer .= $twitter_data->data_section('post'); $answer .= $twitter_data->data_field('id', $stat->cid); $answer .= $twitter_data->data_field('text', $stat->mtext, FALSE); $answer .= $twitter_data->data_section('post', FALSE, TRUE); $answer .= $api_session->format == 'json' && $num_rows - 1 > 0 ? ',' : ''; $num_rows--; } $answer .= $twitter_data->data_section('comments', FALSE, TRUE, TRUE); $answer .= $twitter_data->data_bottom(); echo $answer; exit; } else {
header('HTTP/1.1 400 Bad Request'); } else { echo generate_error($api_session->format, 'You have no available rate limits, try again later.', $_SERVER['REQUEST_URI'], $api_session->callback); } exit; } $q = 'SELECT post_id AS pid FROM post_favs WHERE user_id="' . intval($user->id) . '" AND post_type="public" ORDER BY date DESC'; if (isset($_GET['page']) && is_numeric($_GET['page'])) { $q .= ' LIMIT ' . 20 * (intval($_GET['page']) - 1) . ', ' . 20 * intval($_GET['page']); } else { $q .= ' LIMIT 20'; } $res = $this->db2->query($q); $num_rows = $this->db2->num_rows($res); if ($num_rows > 0) { $twitter_data = new TwitterData($api_session->format, $api_session->callback, $user->id, TRUE); $answer = $twitter_data->data_header(); if ($twitter_data->is_feed()) { while ($stat = $this->db2->fetch_object($res)) { $answer .= $twitter_data->print_status_simple($stat->pid, 'public'); } } else { $answer .= $twitter_data->data_section('statuses', FALSE, FALSE, TRUE, ' type="array"'); while ($stat = $this->db2->fetch_object($res)) { $answer .= $twitter_data->data_section('status'); $answer .= $twitter_data->print_status($stat->pid, TRUE); $answer .= $twitter_data->data_section('user', TRUE); $uid = $this->db2->fetch_field('SELECT user_id FROM posts WHERE id="' . $this->db2->e($stat->pid) . '" ORDER BY id DESC LIMIT 1'); $answer .= $twitter_data->print_user($uid); $answer .= $twitter_data->data_section('user', FALSE, TRUE); $answer .= $twitter_data->data_section('status', FALSE, TRUE);
$api_session->rate_status = true; } elseif (check_rate_limits($_SERVER['REMOTE_ADDR'])) { $api_session->rate_status = true; } if (!$api_session->rate_status) { if (!isset($_GET['suppress_response_codes'])) { header('HTTP/1.1 400 Bad Request'); } else { echo generate_error($api_session->format, 'You have no available rate limits, try again later.', $_SERVER['REQUEST_URI'], $api_session->callback); } exit; } $res = $this->db2->query('SELECT id, search_string, added_date FROM searches WHERE user_id="' . intval($this->db2->e($user->id)) . '" ORDER BY id DESC'); $num_rows = $this->db2->num_rows($res); if ($num_rows > 0) { $twitter_data = new TwitterData($api_session->format, $api_session->callback, $user->id, TRUE); $answer = $twitter_data->data_header(); if ($twitter_data->is_feed()) { while ($stat = $this->db2->fetch_object($res)) { $answer .= $twitter_data->print_status_simple($stat->pid); } } else { $answer .= $twitter_data->data_section('saved_searches', FALSE, FALSE, TRUE, ' type="array"'); while ($obj = $this->db2->fetch_object($res)) { $answer .= $twitter_data->data_section('saved_search'); $answer .= $twitter_data->data_field('id', $obj->id); $answer .= $twitter_data->data_field('query', stripslashes($obj->search_string)); $answer .= $twitter_data->data_field('created_at', gmstrftime('%a %b %d %H:%M:%S +0000 %Y', $obj->added_date), FALSE); $answer .= $twitter_data->data_section('saved_search', FALSE, TRUE); $answer .= $api_session->format == 'json' && $num_rows - 1 > 0 ? ',' : ''; $num_rows--;
echo generate_error($api_session->format, 'Invalid user id.', $_SERVER['REQUEST_URI'], $api_session->callback); } exit; } $user_result = new stdClass(); if ($stat = $this->db2->fetch_field('SELECT 1 FROM users_followed WHERE who="' . $this->db2->e($s_u->id) . '" AND whom="' . $this->db2->e($t_u->id) . '" LIMIT 1')) { $user_result->source_follow_target = 'true'; } else { $user_result->source_follow_target = 'false'; } if ($stat = $this->db2->fetch_field('SELECT 1 FROM users_followed WHERE who="' . $this->db2->e($t_u->id) . '" AND whom="' . $this->db2->e($s_u->id) . '" LIMIT 1')) { $user_result->target_follow_source = 'true'; } else { $user_result->target_follow_source = 'false'; } $twitter_data = new TwitterData($api_session->format, $api_session->callback, $s_u->id); $answer = $twitter_data->data_header(); $answer .= $api_session->format == 'json' ? '{' : ''; $answer .= $twitter_data->data_section('relationship', TRUE); $answer .= $twitter_data->data_section('source', TRUE); $answer .= $twitter_data->data_field('id', $source_id); $answer .= $twitter_data->data_field('screen_name', $s_u->username); $answer .= $twitter_data->data_field('following', $user_result->source_follow_target); $answer .= $twitter_data->data_field('followed_by', $user_result->target_follow_source, FALSE); $answer .= $twitter_data->data_section('source', FALSE, TRUE); $answer .= $api_session->format == 'json' ? ',' : ''; $answer .= $twitter_data->data_section('target', TRUE); $answer .= $twitter_data->data_field('id', $target_id); $answer .= $twitter_data->data_field('screen_name', $t_u->username); $answer .= $twitter_data->data_field('following', $user_result->target_follow_source); $answer .= $twitter_data->data_field('followed_by', $user_result->source_follow_target, FALSE);