← All changes
|
includes/Core/Integration/Telegram/TelegramHandler.php
+27
-6
2.10.0
→
3.3.1
View file →
| @@ -6,10 +6,15 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace BitCode\BitForm\Core\Integration\Telegram; |
| 9 | 9 | |
| 10 | +if (!defined('ABSPATH')) { | |
| 11 | + exit; | |
| 12 | +} | |
| 13 | + | |
| 10 | 14 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 11 | 15 | use BitCode\BitForm\Core\Util\HttpHelper; |
| 16 | +use BitCode\BitForm\GlobalHelper; | |
| 12 | 17 | use WP_Error; |
| 13 | 18 | |
| 14 | 19 | /** |
| 15 | 20 | * Provide functionality for Telegram integration |
| @@ -44,11 +49,17 @@ | ||
| 44 | 49 | */ |
| 45 | 50 | public static function telegramAuthorize() |
| 46 | 51 | { |
| 47 | 52 | $authorizationHeader = null; |
| 48 | - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 49 | - $inputJSON = file_get_contents('php://input'); | |
| 50 | - $requestsParams = json_decode($inputJSON); | |
| 53 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 54 | + GlobalHelper::requirePostMethod(); | |
| 55 | + | |
| 56 | + try { | |
| 57 | + $requestsParams = GlobalHelper::formatRequestData(); | |
| 58 | + } catch (\InvalidArgumentException $e) { | |
| 59 | + wp_send_json_error($e->getMessage(), 400); | |
| 60 | + } | |
| 61 | + | |
| 51 | 62 | if ( |
| 52 | 63 | empty($requestsParams->bot_api_key) |
| 53 | 64 | ) { |
| 54 | 65 | wp_send_json_error( |
| @@ -101,11 +112,16 @@ | ||
| 101 | 112 | public static function refreshGetUpdates() |
| 102 | 113 | { |
| 103 | 114 | $authorizationHeader = null; |
| 104 | 115 | $response = null; |
| 105 | - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 106 | - $inputJSON = file_get_contents('php://input'); | |
| 107 | - $requestsParams = json_decode($inputJSON); | |
| 116 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 117 | + GlobalHelper::requirePostMethod(); | |
| 118 | + | |
| 119 | + try { | |
| 120 | + $requestsParams = GlobalHelper::formatRequestData(); | |
| 121 | + } catch (\InvalidArgumentException $e) { | |
| 122 | + wp_send_json_error($e->getMessage(), 400); | |
| 123 | + } | |
| 108 | 124 | if ( |
| 109 | 125 | empty($requestsParams->bot_api_key) |
| 110 | 126 | ) { |
| 111 | 127 | wp_send_json_error( |
| @@ -128,8 +144,13 @@ | ||
| 128 | 144 | if (!empty($list->my_chat_member->chat->title) && !empty($list->my_chat_member->chat->id)) { |
| 129 | 145 | $allList[$list->my_chat_member->chat->title] = (object) [ |
| 130 | 146 | 'id' => $list->my_chat_member->chat->id, |
| 131 | 147 | 'name' => $list->my_chat_member->chat->title, |
| 148 | + ]; | |
| 149 | + } elseif (isset($list->channel_post->chat->title, $list->channel_post->chat->id)) { | |
| 150 | + $allList[$list->channel_post->chat->title] = (object) [ | |
| 151 | + 'id' => $list->channel_post->chat->id, | |
| 152 | + 'name' => $list->channel_post->chat->title, | |
| 132 | 153 | ]; |
| 133 | 154 | } |
| 134 | 155 | } |
| 135 | 156 | uksort($allList, 'strnatcasecmp'); |