/**
  * @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['msazureaccname'] = $_POST['msazureaccname'];
         $args['msazurekey'] = $_POST['msazurekey'];
         $args['msazureselected'] = $_POST['msazureselected'];
         $ajax = TRUE;
     }
     echo '<span id="msazurecontainererror" style="color:red;">';
     if (!empty($args['msazureaccname']) && !empty($args['msazurekey'])) {
         try {
             set_include_path(get_include_path() . PATH_SEPARATOR . BackWPup::get_plugin_data('plugindir') . '/vendor/PEAR/');
             $blobRestProxy = WindowsAzure\Common\ServicesBuilder::getInstance()->createBlobService('DefaultEndpointsProtocol=https;AccountName=' . $args['msazureaccname'] . ';AccountKey=' . BackWPup_Encryption::decrypt($args['msazurekey']));
             $containers = $blobRestProxy->listContainers()->getContainers();
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (empty($args['msazureaccname'])) {
         _e('Missing account name!', 'backwpup');
     } elseif (empty($args['msazurekey'])) {
         _e('Missing access key!', 'backwpup');
     } elseif (!empty($error)) {
         echo esc_html($error);
     } elseif (empty($containers)) {
         _e('No container found!', 'backwpup');
     }
     echo '</span>';
     if (!empty($containers)) {
         echo '<select name="msazurecontainer" id="msazurecontainer">';
         foreach ($containers as $container) {
             echo "<option " . selected(strtolower($args['msazureselected']), strtolower($container->getName()), FALSE) . ">" . $container->getName() . "</option>";
         }
         echo '</select>';
     }
     if ($ajax) {
         die;
     } else {
         return;
     }
 }
Esempio n. 2
0
 public function storeBlobInAzure($filePath, $blobName)
 {
     $connectionString = 'DefaultEndpointsProtocol=http;AccountName=licenta;AccountKey=kIldSIWX1maxG1xj+yw+SgBk+9DN6/oexbu+PwiwINIX6eySp4GMVXPrYDSDWon2mAdluWEThF/rmvMwKKuA4g==';
     $blobRestProxy = WindowsAzure\Common\ServicesBuilder::getInstance()->createBlobService($connectionString);
     $createContainerOptions = new WindowsAzure\Blob\Models\CreateContainerOptions();
     $createContainerOptions->setPublicAccess(WindowsAzure\Blob\Models\PublicAccessType::CONTAINER_AND_BLOBS);
     try {
         $fileContent = fopen($filePath, 'r');
         $storingOptions = new \WindowsAzure\Blob\Models\CreateBlobOptions();
         $storingOptions->setContentType('audio/mpeg');
         $blobRestProxy->createBlockBlob('uploads', $blobName, $fileContent, $storingOptions);
     } catch (Exception $e) {
         $code = $e->getCode();
         $error_message = $e->getMessage();
         echo $code . ": " . $error_message . "<br />";
     }
 }