function telegram_download_file($telegram_user_id, $file_id, $directory = '') { $url = telegram_geturl() . 'getFile?file_id=' . $file_id; $response = file_get_contents($url); if (!$response) { return; } $data = (array) json_decode($response, TRUE); $plugin_post_id = telegram_getid($telegram_user_id); $remote_url = 'https://api.telegram.org/file/bot' . telegram_option('token') . '/' . $data['result']['file_path']; $local_dir = $local_url = ABSPATH . 'wp-content/uploads/telegram-bot/' . $plugin_post_id . $directory; $ext = pathinfo($remote_url, PATHINFO_EXTENSION); $file_name = time() . '.' . $ext; $local_url = $local_dir . '/' . $file_name; if (!copy($remote_url, $local_url)) { mkdir($local_dir, 0755, true); if (!copy($remote_url, $local_url)) { telegram_log('', $telegram_user_id, 'Cannot write file image from ' . $remove_url . ' to ' . $local_url); return false; } else { telegram_log('', $telegram_user_id, 'Directory created for incoming image'); return false; } } else { telegram_log('', $telegram_user_id, 'Received and saved image'); return get_site_url() . '/wp-content/uploads/telegram-bot/' . $plugin_post_id . '/' . $file_name; } }
<div class="wrap"> <h2>Settings </h2> <form method="post" action="options.php"> <?php settings_fields('wp_telegram_options'); $options = get_option('wp_telegram'); if (isset($_GET['settings-updated'])) { $url = telegram_geturl() . 'setWebhook?url='; if (telegram_option('mode')) { $url .= 'https://wptele.ga/?key=' . get_option('wp_telegram_apikey'); } else { $url .= telegram_getapiurl(); } json_decode(file_get_contents($url), true); telegram_log('####', __('"WebHook" updated', 'telegram-bot'), $url); } ?> <table class="form-table"> <tr valign="top"> <th scope="row"> <label for="apikey">Plugin Api Key </label> </th> <td> <input disabled id="apikey" type="text" name="wp_telegram_apikey" value="<?php echo get_option('wp_telegram_apikey'); ?> " size="55" /> <br> <small>This is the unique key generated for your website.