if($result->num_rows > 0){
$data = array();
while ($row = $result->fetch_assoc()){
$data[] = json_decode($row['data'], true);
}
}
$i = 0;
foreach ($data as $key => $value) {
if ($data[$key]['q1'] == 'a1') {
$i++;
}
}
echo $i;
$data = array();
if($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
$data[] = json_decode($row['data'], true);
}
}
function jsonCount($question, $answer){
global $data;
$i = 0;
foreach ($data as $key => $value) {
if ($data[$key][$question] == $answer) {
$i++;
}
}
return $i;
}
echo jsonCount('q1', 'a1');
echo '<br>';
echo jsonCount('q1', 'a2');
if ($result_wall_get['date'] == '1565458434') {
echo $result_wall_get['id']
}
<?php
define('BOT_TOKEN', 'ТУТ ТОКЕН БОТА');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
define('MY_ID', 'ТУТ ТВОЙ ИД');
define('WEBHOOK_URL', 'ПОЛНЫЙ АДРЕС ДО ФАЙЛА БОТА');
define('HELLO_TEXT', 'Просто напиши мне, и я передам все своему хозяину!');
define('DONE_TEXT', 'Сообщение отправлено!');
function apiRequestWebhook($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\n");
return false;
}
if (!$parameters) {
$parameters = array();
} else if (!is_array($parameters)) {
error_log("Parameters must be an array\n");
return false;
}
$parameters["method"] = $method;
header("Content-Type: application/json");
echo json_encode($parameters);
return true;
}
function exec_curl_request($handle) {
$response = curl_exec($handle);
if ($response === false) {
$errno = curl_errno($handle);
$error = curl_error($handle);
error_log("Curl returned error $errno: $error\n");
curl_close($handle);
return false;
}
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
curl_close($handle);
if ($http_code >= 500) {
sleep(10);
return false;
} else if ($http_code != 200) {
$response = json_decode($response, true);
error_log("Request has failed with error {$response['error_code']}: {$response['description']}\n");
if ($http_code == 401) {
throw new Exception('Invalid access token provided');
}
return false;
} else {
$response = json_decode($response, true);
if (isset($response['description'])) {
error_log("Request was successfull: {$response['description']}\n");
}
$response = $response['result'];
}
return $response;
}
function apiRequest($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\n");
return false;
}
if (!$parameters) {
$parameters = array();
} else if (!is_array($parameters)) {
error_log("Parameters must be an array\n");
return false;
}
foreach ($parameters as $key => &$val) {
if (!is_numeric($val) && !is_string($val)) {
$val = json_encode($val);
}
}
$url = API_URL.$method.'?'.http_build_query($parameters);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
return exec_curl_request($handle);
}
function apiRequestJson($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\n");
return false;
}
if (!$parameters) {
$parameters = array();
} else if (!is_array($parameters)) {
error_log("Parameters must be an array\n");
return false;
}
$parameters["method"] = $method;
$handle = curl_init(API_URL);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
return exec_curl_request($handle);
}
function processMessage($message) {
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
if (isset($message)) {
$text = $message['text'];
if (strpos($text, "/start") === 0) {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => HELLO_TEXT));
} else if (strpos($text, "/stop") === 0) {
} else {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => DONE_TEXT));
apiRequest("forwardMessage", array('chat_id' => MY_ID, 'from_chat_id' => $chat_id, 'message_id' => $message_id));
}
}
}
if (php_sapi_name() == 'cli') {
apiRequest('setWebhook', array('url' => isset($argv[1]) && $argv[1] == 'delete' ? '' : WEBHOOK_URL));
exit;
}
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update) {
exit;
}
if (isset($update["message"])) {
processMessage($update["message"]);
}
?>
<div class="row photos">
<?php
$apage = $_GET['page'];
if(isset($apage)){
$aoffset = $apage-1;
$aoffset = 16*$aoffset;
}
$fpt = file_get_contents('https://api.vk.com/method/photos.get?owner_id=-183487496&album_id=265483073&count=200&offset='.$aoffset.'&rev=1&access_token=a74&v=5.50');
$jjs = json_decode($fpt);
$jrnd = $jjs->response->count;
$apage = ceil($jrnd/16);
$x=-1;
while ($x<15)
{
$x++;
$pid = $jjs->response->items[$x]->photo_604;
echo '<div class="col-sm-6 col-md-4 col-lg-3 item"><a data-lightbox="photos" href="';
echo $pid;
echo '"><img class="img-fluid" src="';
echo $pid;
echo '"></a></div>';
}
?>
<ul class="pagination">
<?php
$z=0;
while ($z < $apage){
$z++;
echo '<li class="page-item"><a class="page-link"';
$bpage = 1;
if(isset($_GET['page'])){
$bpage = $_GET['page'];
}
if ($z != $bpage){
echo 'href="index.php?page=';
echo $z;
echo '"';
}
echo '>';
echo $z;
echo '</a></li>';
}
?>
</ul>
</div>
</div>
</div>
<?php
$i = $_GET['url'];
$dwnld_link = GetAllFiles($i);
$dwnld_link = (array) $dwnld_link[0];
$redirect = $dwnld_link['download_link'];
$file = $redirect;
if (ob_get_level()) {
ob_end_clean();
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($file);
exit;
class CMFile
{
public $name = "";
public $output = "";
public $link = "";
public $download_link = "";
function __construct($name, $output, $link, $download_link)
{
$this->name = $name;
$this->output = $output;
$this->link = $link;
$this->download_link = $download_link;
}
}
function GetAllFiles($link, $folder = "")
{
global $base_url, $id;
$page = get(pathcombine($link, $folder));
if ($page === false) { echo "Error $link\r\n"; return false; }
if (($mainfolder = GetMainFolder($page)) === false) { echo "Cannot get main folder $link\r\n"; return false; }
if (!$base_url) $base_url = GetBaseUrl($page);
if (!$id && preg_match('~\/public\/(.*)~', $link, $match)) $id = $match[1];
$cmfiles = array();
if ($mainfolder["name"] == "/") $mainfolder["name"] = "";
foreach ($mainfolder["list"] as $item)
{
if ($item["type"] == "folder")
{
$files_from_folder = GetAllFiles($link, pathcombine($folder, rawurlencode(basename($item["name"]))));
if (is_array($files_from_folder))
{
foreach ($files_from_folder as $file)
{
if ($mainfolder["name"] != "")
$file->output = $mainfolder["name"] . "/" . $file->output;
}
$cmfiles = array_merge($cmfiles, $files_from_folder);
}
}
else
{
$fileurl = pathcombine($folder, rawurlencode($item["name"]));
if (strpos($id, $fileurl) !== false) $fileurl = "";
$cmfiles[] = new CMFile($item["name"],
pathcombine($mainfolder["name"], $item["name"]),
pathcombine($link, $fileurl),
pathcombine($base_url, $id, $fileurl));
}
}
return $cmfiles;
}
function GetMainFolder($page)
{
if (preg_match('~"folder":\s+(\{.*?"id":\s+"[^"]+"\s+\})\s+}~s', $page, $match)) return json_decode($match[1], true);
else return false;
}
function GetBaseUrl($page)
{
if (preg_match('~"weblink_get":.*?"url":\s*"(https:[^"]+)~s', $page, $match)) return $match[1];
else return false;
}
function get($url)
{
$proxy = null;
$http["method"] = "GET";
if ($proxy) { $http["proxy"] = "tcp://" . $proxy; $http["request_fulluri"] = true; }
$options['http'] = $http;
$context = stream_context_create($options);
$body = @file_get_contents($url, NULL, $context);
return $body;
}
function pathcombine()
{
$result = "";
foreach (func_get_args() as $arg)
{
if ($arg !== '')
{
if ($result && substr($result, -1) != "/") $result .= "/";
$result .= $arg;
}
}
return $result;
}
?>