Пример #1
0
 /**
  * @param string $args
  */
 public function edit_ajax($args = '')
 {
     $error = '';
     if (is_array($args)) {
         $ajax = FALSE;
     } else {
         if (!current_user_can('backwpup_jobs_edit')) {
             wp_die(-1);
         }
         check_ajax_referer('backwpup_ajax_nonce');
         $args['s3accesskey'] = $_POST['s3accesskey'];
         $args['s3secretkey'] = $_POST['s3secretkey'];
         $args['s3bucketselected'] = $_POST['s3bucketselected'];
         $args['s3base_url'] = $_POST['s3base_url'];
         $args['s3region'] = $_POST['s3region'];
         $ajax = TRUE;
     }
     echo '<span id="s3bucketerror" style="color:red;">';
     if (!empty($args['s3accesskey']) && !empty($args['s3secretkey'])) {
         try {
             $s3 = new AmazonS3(array('key' => $args['s3accesskey'], 'secret' => BackWPup_Encryption::decrypt($args['s3secretkey']), 'certificate_authority' => TRUE));
             $base_url = $this->get_s3_base_url($args['s3region'], $args['s3base_url']);
             if (stristr($base_url, 'amazonaws.com')) {
                 $s3->set_region(str_replace(array('http://', 'https://'), '', $base_url));
             } else {
                 $s3->set_hostname(str_replace(array('http://', 'https://'), '', $base_url));
                 $s3->allow_hostname_override(FALSE);
                 if (substr($base_url, -1) == '/') {
                     $s3->enable_path_style(TRUE);
                 }
             }
             if (stristr($base_url, 'http://')) {
                 $s3->disable_ssl();
             }
             $buckets = $s3->list_buckets();
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (empty($args['s3accesskey'])) {
         _e('Missing access key!', 'backwpup');
     } elseif (empty($args['s3secretkey'])) {
         _e('Missing secret access key!', 'backwpup');
     } elseif (!empty($error) && $error == 'Access Denied') {
         echo '<input type="text" name="s3bucket" id="s3bucket" value="' . esc_attr($args['s3bucketselected']) . '" >';
     } elseif (!empty($error)) {
         echo esc_html($error);
     } elseif (!isset($buckets) || count($buckets->body->Buckets->Bucket) < 1) {
         _e('No bucket found!', 'backwpup');
     }
     echo '</span>';
     if (!empty($buckets->body->Buckets->Bucket)) {
         echo '<select name="s3bucket" id="s3bucket">';
         foreach ($buckets->body->Buckets->Bucket as $bucket) {
             echo "<option " . selected($args['s3bucketselected'], esc_attr($bucket->Name), FALSE) . ">" . esc_attr($bucket->Name) . "</option>";
         }
         echo '</select>';
     }
     if ($ajax) {
         die;
     }
 }
Пример #2
0
 public function connect()
 {
     $this->connection = new \AmazonS3($this->s3_options);
     $this->connection->set_region($this->region);
 }