Skip to content

Instantly share code, notes, and snippets.

@ennjoy
Last active June 10, 2019 07:44
Show Gist options
  • Save ennjoy/7582ef29b5b2d49b08b6f26fee4f0baf to your computer and use it in GitHub Desktop.
Save ennjoy/7582ef29b5b2d49b08b6f26fee4f0baf to your computer and use it in GitHub Desktop.
wall.get
<?php
$owner_id = isset($_REQUEST['owner_id']) ? clean($_REQUEST['owner_id']) : false;
$count = isset($_REQUEST['count']) ? intval($_REQUEST['count']) : false;
$offset = isset($_REQUEST['offset']) ? intval($_REQUEST['offset']) : false;
$access_token = check_token();
if($count <= 0) $count = 10;
if($count > 100) $count = 100;
if($offset <= 0) $offset = 0;
$count += $offset;
if (!$offset) $offset = 1;
if (!$owner_id) $owner_id = $access_token['user_id'];
$result = array();
$attachments = array();
if ($owner_id{0} == '-') {
$page_id = substr($owner_id, 1);
$row_wall = mysqli_query($sqlConnect, "SELECT * FROM ". T_POSTS ." WHERE page_id = '$page_id' ORDER BY id DESC LIMIT $count ");
} else if ($owner_id{0} == ':') {
$group_id = substr($owner_id, 1);
$row_wall = mysqli_query($sqlConnect, "SELECT * FROM ". T_POSTS ." WHERE group_id = '$group_id' ORDER BY id DESC LIMIT $count ");
} else if (intval($owner_id)) {
$user_id = intval($owner_id);
$row_wall = mysqli_query($sqlConnect, "SELECT * FROM ". T_POSTS ." WHERE user_id = '$user_id' ORDER BY id DESC LIMIT $count ");
}
if(!$owner_id) {
error(2, 'not found owner_id');
} else if ($owner_id) {
if ($row_wall) {
foreach ($row_wall as $row) {
$row_like = mysqli_query($sqlConnect, "SELECT * FROM ". T_REACTIONS ." WHERE post_id = '$row[post_id]' ");
if ($row['postText']) {
$replace = array('#[1]', '#[6]', '#[7]', '#[8]', '#[10]', '#[15]', '#[34]', '#[45]', '#[54]', '#[60]', '#[66]', '[a]', '[/a]', '<br>');
$text = str_replace($replace, '', $row['postText']);
} else {
$text = '';
}
while ($like = mysqli_fetch_assoc($row_like)) {
$reaction[] = $like;
}
if (!empty($row_like)) {
$attachments['likes'] = $reaction;
}
$result[] = array(
'post_id' => $row['post_id'],
'owner_id' => $owner_id,
'text' => $text,
'attachments' => $attachments,
'time' => $row['time']
);
}
$response = array(
'response' => array(
'count' => $row_wall->num_rows,
'items' => $result
)
);
json_encode_cyr($response);
} else {
error(3, 'owner_id - '.$owner_id.' is incorrect');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment