ChatID(); $result = $telegram->getData(); $received = $result['message']['text']; $callback = $result['callback_query']; if(startsWith($received, "/start")) { $text = "ID: " . $chat_id; $content = array('chat_id' => $chat_id, 'text' => $text); $telegram->sendMessage($content); } else if(isset($callback)) { $firstname = $callback["from"]["first_name"]; $update_id = $callback["message"]["message_id"]; $response_data = $callback["data"]; $vote = preg_split('/\s+/', $response_data)[0]; $id = preg_split('/\s+/', $response_data)[1]; if($vote === "approve") { $vote_str = "✅ aprovou a foto (ID: " . $id . ")"; $vote_value = 1; } else if($vote === "reject") { $vote_str = "❎ rejeitou a foto (ID: " . $id . ")"; $vote_value = -1; } else if($vote === "ban") { $vote_str = "🚫 baniu"; $vote_value = -2; } // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { error_log($conn->connect_error); return; } $stmt = $conn->prepare("UPDATE posts SET enabled=? WHERE id=?"); $stmt->bind_param("ii", $vote_value,$id); $stmt->execute(); $stmt->close(); if($vote_value == -2) { $results = $conn->query("SELECT author FROM cardapio.posts WHERE id=" . $id); $value = $results->fetch_assoc(); $userid = $value["author"]; error_log("banning " . $userid); $stmt = $conn->prepare("INSERT INTO bans (uuid) VALUES (?)"); $stmt->bind_param("s", $userid); $stmt->execute(); $stmt->close(); $vote_str .= " o usuário [" . $userid . "] e a foto ID: " . $id; } $content = array('message_id' => $update_id, 'chat_id' => $group_chat_id, 'caption' => $firstname . " " . $vote_str); $telegram->editMessageCaption($content); //$id = preg_replace('/approve ', '', $received); //TODO: send approve to backend //$content = array('chat_id' => $chat_id, 'text' => $text); } //error_log(json_encode($result)); //error_log($received); function startsWith($haystack, $needle) { // search backwards starting from haystack length characters from the end return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; } function endsWith($haystack, $needle) { // search forward starting from end minus needle length characters return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE); } function clean($string) { $string = str_replace('', '-', $string); // Replaces all spaces with hyphens. return preg_replace('/[^A-Za-z0-9\-\s\.\']/', '', $string); // Removes special chars. } function sendDocument($chat_id, $file) { global $_BOT_TOKEN; global $_API_URL; $url = $_API_URL . "sendDocument"; error_log("curl -s -X POST -o /dev/null -w \"%{http_code}\" " . $url . " -F chat_id=" . $chat_id . " -F document=\"@" . $file . "\""); $code = shell_exec("curl -s -X POST -o /dev/null -w \"%{http_code}\" " . $url . " -F chat_id=" . $chat_id . " -F document=\"@" . $file . "\""); } function sendPhoto($chat_id, $file) { global $_BOT_TOKEN; global $_API_URL; $url = $_API_URL . "sendPhoto"; $code = shell_exec('curl -s -X POST -o /dev/null -w "%{http_code}" ' . $url . ' -F chat_id=' . $chat_id . ' -F photo="@' . $file . '"'); return $code; } ?>