| @@ -4,11 +4,19 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class WPBotGCDownload |
| 7 | 7 | { |
| 8 | - private $download_url = 'https://github.com/qcloud/gc/raw/master/wpbotgc.zip'; | |
| 9 | 8 | private $filename = 'wpbotgc.zip'; |
| 10 | 9 | |
| 10 | + /** | |
| 11 | + * Path to the bundled Google Client zip inside the plugin. | |
| 12 | + * | |
| 13 | + * @return string | |
| 14 | + */ | |
| 15 | + private function get_bundled_zip_path() { | |
| 16 | + return plugin_dir_path( __FILE__ ) . 'assets/' . $this->filename; | |
| 17 | + } | |
| 18 | + | |
| 11 | 19 | public function __construct() { |
| 12 | 20 | add_action( 'wp_ajax_qcld_wp_chatbot_gc_client_download', array( $this, 'downloadgc' ) ); |
| 13 | 21 | add_action( 'wp_ajax_qcld_wp_chatbot_gc_client_extract', array( $this, 'extractgc' ) ); |
| 14 | 22 | } |
| @@ -75,23 +83,17 @@ | ||
| 75 | 83 | wp_die(); |
| 76 | 84 | } |
| 77 | 85 | |
| 78 | 86 | $zip_file = $gcdirectory . '/' . $this->filename; |
| 87 | + $bundled = $this->get_bundled_zip_path(); | |
| 79 | 88 | |
| 80 | - $remote_response = wp_remote_get( $this->download_url, array( | |
| 81 | - 'timeout' => 60, | |
| 82 | - 'stream' => true, | |
| 83 | - 'filename' => $zip_file, | |
| 84 | - ) ); | |
| 85 | - | |
| 86 | - if ( is_wp_error( $remote_response ) ) { | |
| 87 | - wp_send_json( array( 'status' => 'error', 'content' => esc_html( $remote_response->get_error_message() ) ) ); | |
| 89 | + if ( ! $fs->exists( $bundled ) ) { | |
| 90 | + wp_send_json( array( 'status' => 'error', 'content' => esc_html__( 'Bundled Google Client package not found. Please install it manually using the instructions above.', 'chatbot' ) ) ); | |
| 88 | 91 | wp_die(); |
| 89 | 92 | } |
| 90 | 93 | |
| 91 | - $http_code = wp_remote_retrieve_response_code( $remote_response ); | |
| 92 | - if ( 200 !== $http_code ) { | |
| 93 | - wp_send_json( array( 'status' => 'error', 'content' => esc_html__( 'Remote server returned an unexpected response.', 'chatbot' ) ) ); | |
| 94 | + if ( ! $fs->copy( $bundled, $zip_file, true, FS_CHMOD_FILE ) ) { | |
| 95 | + wp_send_json( array( 'status' => 'error', 'content' => esc_html__( 'Could not copy the Google Client package.', 'chatbot' ) ) ); | |
| 94 | 96 | wp_die(); |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | wp_send_json( array( 'status' => 'success', 'content' => esc_html__( 'File downloaded successfully.', 'chatbot' ) ) ); |