$config['spam_noticer']['base_url'], 'http_errors' => false ]); } class SpamNoticerResult { public $result_json = NULL; public $noticed = false; public $succeeded = false; public $reason = NULL; public $client = NULL; } function checkWithSpamNoticer($config, $post, $boardname) { $client = _createClient($config); $attachments = []; foreach ($post['files'] as $key => $file) { $attachments[] = array( 'filename' => $file['filename'], 'mimetype' => $file['type'] ? $file['type'] : mime_content_type($file['tmp_name']), 'md5_hash' => $file['hash'], 'thumbnail_url' => $config['spam_noticer']['imageboard_root'] . $file['thumb'] ); } $json_payload = [ 'attachments' => $attachments, 'body' => $post['raw_body'], 'time_stamp' => time(), 'website_name' => $config['spam_noticer']['website_name'], 'board_name' => $boardname, 'thread_id' => array_key_exists('thread', $post) ? $post['thread'] : NULL ]; $result = new SpamNoticerResult(); try { $multipart = array(); $multipart[] = [ 'name' => 'json', 'contents' => json_encode($json_payload) ]; foreach ($post['files'] as $key => $file) { $multipart[] = array( 'name' => 'attachments', 'contents' => GuzzleHttp\Psr7\Utils::tryFopen($file['tmp_name'], 'r') ); } $response = $client->request('POST', '', [ 'multipart' => $multipart ]); $status_code = $response->getStatusCode(); if ($status_code >= 200 && $status_code < 300) { $result->succeeded = true; $result->result_json = json_decode($response->getBody(), true); $result->noticed = $result->result_json['noticed'] == true; if ($result->noticed) { $result->reason = (string) $response->getBody(); } } else { $result->reason = (string) $response->getBody(); } print_err("strbody:\n" . $result->reason); print_err("status_code: " . $response->getStatusCode()); $result->client = $client; return $result; } catch (GuzzleHttp\Exception\ConnectException $e) { $result->reason = $e->getMessage(); } return $result; }