public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_local_send_to_s3_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     $this->queue = new WPAdm_Queue($this->id);
     WPAdm_Core::log('Start copy files to Amazon S3');
     $this->queue->clear();
     $files = $this->params['files'];
     //$this->getResult()->setData($files);
     $dir = isset($ad['dir']) ? $ad['dir'] : '/';
     //$dir = trim($dir, '/') . '/' . $this->name;
     foreach ($files as $file) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'local_send_to_s3')->addParam('file', ABSPATH . $file)->addParam('bucket', $this->params['bucket'])->addParam('AccessKeyId', $this->params['AccessKeyId'])->addParam('SecretAccessKey', $this->params['SecretAccessKey']);
         if (isset($this->params['dir']) && !empty($this->params['dir'])) {
             $commandContext->addParam('dir', $this->params['dir']);
         }
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     $res = $this->queue->save()->execute();
     if (!$res) {
         WPAdm_Core::log('S3: ' . $this->queue->getError());
         $errors[] = 'S3: ' . $this->queue->getError();
     }
     WPAdm_Core::log('End copy files to Amazon S3');
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     ini_set("memory_limit", "256M");
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
     $af = $this->getArchiveName($context->get('to_file'));
     ini_set("memory_limit", "256M");
     $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
     $archive->setRemovePath($context->get('remove_path'));
     $files = $context->get('files');
     if (!file_exists($af)) {
         WPAdm_Core::log(langWPADM::get('Create part ', false) . basename($af));
     }
     if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
         $af = $this->getNextArchiveName($context->get('to_file'));
         unset($archive);
         if (!file_exists($af)) {
             WPAdm_Core::log(langWPADM::get('Create part ', false) . basename($af));
         }
         $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
         $archive->setRemovePath($context->get('remove_path'));
     }
     $files_str = implode(',', $files);
     $files_archive = WPAdm_Running::getCommandResultData('archive');
     if (!in_array($files_str, $files_archive)) {
         $archive->add($files_str);
         $files_archive = WPAdm_Running::getCommandResultData('archive');
         $files_archive[] = $files_str;
         if (!empty($files_archive)) {
             WPAdm_Running::setCommandResultData('archive', $files_archive);
         }
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     @session_start();
     require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
     WPAdm_Core::log(langWPADM::get('Send to dropbox files', false));
     $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
     if (!$dropbox->isAuth()) {
         $context->setError(langWPADM::get('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"', false, array('%d', '%k', '%s'), array(SITE_HOME, $context->get('key'), $context->get('secret'))));
         return false;
     }
     $files = $context->get('files');
     $file = explode("/", $files);
     $file_name = array_pop($file);
     $folder_project_temp = $context->get('folder_project');
     $folder_project = "";
     if (!empty($folder_project_temp)) {
         $folder_project = $folder_project_temp . "/";
         $dropbox->createDir($folder_project_temp);
         $dropbox->createDir($folder_project . $context->get('folder'));
     } else {
         $dropbox->createDir($context->get('folder'));
     }
     $fromFile = str_replace('//', '/', $files);
     $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
     $res = $dropbox->uploadFile($fromFile, $toFile);
     if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
         $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $res['text'] . '"');
         return false;
     }
     if (isset($res['size']) && isset($res['client_mtime'])) {
         WPAdm_Core::log(langWPADM::get('File upload: ', false) . basename($files) . langWPADM::get(' size: ', false) . $res['size']);
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/aws-autoloader.php';
     $credentials = new Aws\Common\Credentials\Credentials($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     $client = Aws\S3\S3Client::factory(array('credentials' => $credentials));
     $dir = $context->get('dir') ? $context->get('dir') . "/" : '';
     try {
         if (!empty($dir)) {
             $logs = $client->putObject(array('Bucket' => $context->get('bucket'), 'Key' => $dir, 'Body' => ''));
             WPAdm_Core::log('Create folder ' . $dir);
         }
         $filePath = preg_replace('#[/\\\\]+#', '/', $context->get('file'));
         $key = $dir ? $dir . '/' . basename($filePath) : basename($filePath);
         $key = ltrim(preg_replace('#[/\\\\]+#', '/', $key), '/');
         //if first will be '/', file not will be uploaded, but result will be ok
         $putRes = $client->putObject(array("Bucket" => $context->get('bucket'), 'Key' => $key, 'Body' => fopen($filePath, 'r+')));
         if ((int) $putRes == 1) {
             WPAdm_Core::log("File({$key}) Upload successfully to Amazon S3");
         }
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     } catch (S3Exception $e) {
         WPAdm_Core::log('error send file ' . $e->getMessage());
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }
 public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_send_to_dropbox_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     $this->queue = new WPAdm_Queue($this->id);
     $ad = $this->params['access_details'];
     WPAdm_Core::log(langWPADM::get('Start copy to Dropbox Cloud', false));
     $this->queue->clear();
     $files = $this->params['files'];
     //$this->getResult()->setData($files);
     $dir = isset($ad['dir']) ? $ad['dir'] : '/';
     //$dir = trim($dir, '/') . '/' . $this->name;
     if (is_array($files)) {
         foreach ($files as $file) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $ad['key'])->addParam('secret', $ad['secret'])->addParam('token', $ad['token'])->addParam('folder_project', $ad['folder'])->addParam('folder', $dir)->addParam('files', ABSPATH . $file);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
     }
     $res = $this->queue->save()->execute();
     if (!$res) {
         WPAdm_Core::log(langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError());
         $errors[] = langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError();
     }
     WPAdm_Core::log(langWPADM::get('End Copy Files to Dropbox', false));
     if (count($errors) > 0) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function getResult()
 {
     WPAdm_Core::log("start widget method", __CLASS__);
     $this->result->setData('not result');
     wpadm_wp_stat::on_activate();
     if (isset($this->params['side'])) {
         $this->deleteWidget();
         $this->addWidget($this->params['side']);
     }
     $this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
     return $this->result;
 }
 private function unpack($f, $to)
 {
     if (strpos($to, ABSPATH) === false) {
         $to = ABSPATH . $to;
     }
     require_once WPAdm_Core::getPluginDir() . '/modules/pclzip.lib.php';
     $this->archive = new PclZip($f);
     $res = $this->archive->extract(PCLZIP_OPT_PATH, WPAdm_Core::getPluginDir(), PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_REMOVE_PATH, WPAdm_Core::$plugin_name);
     WPAdm_Core::log($this->archive->errorInfo(true));
     if ($res) {
         return true;
     }
     return false;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     if (file_exists($context->get('zip_file'))) {
         require_once WPAdm_Core::getPluginDir() . '/modules/pclzip.lib.php';
         $this->archive = new PclZip($context->get('zip_file'));
         $file = $context->get('file');
         $is_dump = $file && strpos($file, "mysqldump.sql");
         WPAdm_Core::log("Decompression Archive " . basename($context->get('zip_file')));
         if ($is_dump !== false) {
             $inzip = str_replace(ABSPATH, "", $file);
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_BY_NAME, $inzip);
         } else {
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_REPLACE_NEWER);
         }
         if ($file_in_zip == 0) {
             WPAdm_Core::log("ERROR Archived: " . $this->archive->errorInfo(true));
             $context->setError("ERROR Archived: " . $this->archive->errorInfo(true));
             return false;
         }
         //WPAdm_Core::log(print_r($file_in_zip, 1));
         if ($is_dump !== false) {
             $db_host = $context->get('db_host');
             if ($db_host !== false) {
                 require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
                 $mysqldump = new WPAdm_Mysqldump();
                 $mysqldump->host = $context->get('db_host');
                 $mysqldump->user = $context->get('db_user');
                 $mysqldump->password = $context->get('db_password');
                 try {
                     $mysqldump->restore($context->get('db_name'), $file);
                 } catch (Exception $e) {
                     $context->setError($e->getMessage());
                     return false;
                 }
             }
         }
     } else {
         $context->setError("File Archive Not Exist " . $context->get('zip_file'));
         WPAdm_Core::log("File Archive Not Exist " . $context->get('zip_file'));
         return false;
     }
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     if (file_exists($context->get('zip_file'))) {
         require_once WPAdm_Core::getPluginDir() . '/modules/pclzip.lib.php';
         $this->archive = new PclZip($context->get('zip_file'));
         $file = $context->get('file');
         $is_dump = $file && strpos($file, "mysqldump.sql");
         WPAdm_Core::log("Data decompression " . basename($context->get('zip_file')));
         if ($is_dump !== false) {
             $inzip = str_replace(ABSPATH, "", $file);
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_BY_NAME, $inzip);
         } else {
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_REPLACE_NEWER);
         }
         if ($file_in_zip == 0) {
             WPAdm_Core::log(langWPADM::get("Website \"%d\" returned an error during archive extracting: ", false, "%d", SITE_HOME) . $this->archive->errorInfo(true));
             $context->setError(langWPADM::get("Website \"%d\" returned an error during archive extracting: ", false, "%d", SITE_HOME) . $this->archive->errorInfo(true));
             return false;
         }
         //WPAdm_Core::log(print_r($file_in_zip, 1));
         if ($is_dump !== false) {
             $db_host = $context->get('db_host');
             if ($db_host !== false) {
                 require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
                 $mysqldump = new WPAdm_Mysqldump();
                 $mysqldump->host = $context->get('db_host');
                 $mysqldump->user = $context->get('db_user');
                 $mysqldump->password = $context->get('db_password');
                 try {
                     $mysqldump->restore($context->get('db_name'), $file);
                 } catch (Exception $e) {
                     $context->setError($e->getMessage());
                     return false;
                 }
             }
         }
     } else {
         $context->setError(langWPADM::get("Website \"%d\" returned an error: The necessary file of archive \"%f\" wasn't found ", false, array('%d', '%f'), array(SITE_HOME, $context->get('zip_file'))));
         WPAdm_Core::log(langWPADM::get("Website \"%d\" returned an error: The necessary file of archive \"%f\" wasn't found ", false, array('%d', '%f'), array(SITE_HOME, $context->get('zip_file'))));
         return false;
     }
     return true;
 }
 public function execute()
 {
     $url = get_option('siteurl');
     $pu = parse_url($url);
     $host = $pu['host'];
     $path = isset($pu['path']) ? $pu['path'] . "/" : "/";
     //WPAdm_Core::log('execute on host ' . $host);
     $data = array('method' => 'queue_controller', 'params' => array('id' => $this->id), 'sign' => '');
     if (function_exists('fsockopen')) {
         $socket = @fsockopen($host, 80, $errno, $errstr, 30);
         $dp = explode(DIRECTORY_SEPARATOR, WPAdm_Core::$pl_dir);
         $pl = array_pop($dp) . '_';
         $data = $pl . 'request=' . base64_encode(serialize($data));
         if (!$socket) {
             WPAdm_Core::log("{$errstr} ({$errno}) ", "socket");
             $curl = curl_init($url . "/");
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($curl, CURLOPT_POST, true);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
             curl_setopt($curl, CURLOPT_TIMEOUT, 10);
             $res = curl_exec($curl);
             curl_close($curl);
             return $this->wait_result();
         }
         fwrite($socket, "POST {$path} HTTP/1.1\r\n");
         fwrite($socket, "Host: {$host}\r\n");
         fwrite($socket, "Content-type: application/x-www-form-urlencoded\r\n");
         fwrite($socket, "Content-length:" . strlen($data) . "\r\n");
         fwrite($socket, "Accept:*/*\r\n");
         fwrite($socket, "User-agent:Opera 10.00\r\n");
         fwrite($socket, "Connection:Close\r\n");
         fwrite($socket, "\r\n");
         fwrite($socket, "{$data}\r\n");
         fwrite($socket, "\r\n");
         @sleep(1);
         fclose($socket);
     }
     return $this->wait_result();
 }
 public function getResult()
 {
     if ($this->restore) {
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
         $this->result->setError('');
         WPAdm_Core::log('Start Restore process');
         $n = count($this->md5_info);
         if (in_array('db', $this->params['types'])) {
         }
         if (in_array('files', $this->params['types'])) {
             foreach ($this->files_resotre as $key => $file) {
                 if (file_exists($file)) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'restore_backup')->addParam('zip_file', $file);
                     $this->queue->clear()->add($commandContext)->save()->execute();
                     unset($commandContext);
                 }
             }
         }
         if (in_array('db', $this->params['types'])) {
             $this->getWpMysqlParams();
             for ($i = 0; $i < $n; $i++) {
                 if (strpos($this->md5_info[$i], "mysqldump.sql") !== false) {
                     $data = explode("\t", $this->md5_info[$i]);
                     if (isset($this->files_resotre[$data[2]]) && file_exists($this->files_resotre[$data[2]])) {
                         $commandContext = new WPAdm_Command_Context();
                         $commandContext->addParam('command', 'restore_backup')->addParam('file', $data[0])->addParam('zip_file', $this->files_resotre[$data[2]]);
                         $commandContext->addParam('db_password', $this->db_data['password'])->addParam('db_name', $this->db_data['db'])->addParam('db_user', $this->db_data['user'])->addParam('db_host', $this->db_data['host']);
                         $this->queue->clear()->add($commandContext)->save()->execute();
                         unset($commandContext);
                     } else {
                         $this->setError('File(' . $data[2] . ') not Exist');
                         WPAdm_Core::log('File(' . $data[2] . ') not Exist');
                         break;
                     }
                 }
             }
         }
     } else {
         WPAdm_Core::log('Files to restore is empty');
     }
     return $this->result;
 }
 /**
  * @param string $error
  */
 public function setError($error)
 {
     WPAdm_Core::log($error);
     $this->error = $error;
 }
Example #13
0
 public function restore($db, $file)
 {
     $link = $this->connect($db);
     WPAdm_Core::log(langWPADM::get('Restore Database was started', false));
     $fo = fopen($file, "r");
     if (!$fo) {
         WPAdm_Core::log(langWPADM::get('Error in open file dump', false));
         $this->setError(langWPADM::get('Error in open file dump', false));
         return false;
     }
     $sql = "";
     while (false !== ($char = fgetc($fo))) {
         $sql .= $char;
         if ($char == ";") {
             $char_new = fgetc($fo);
             if ($char_new !== false && $char_new != "\n") {
                 $sql .= $char_new;
             } else {
                 $ress = $link->query($sql);
                 if (!empty($link->last_error) && $n > 0) {
                     $this->setError($link->last_error);
                     WPAdm_Core::log(langWPADM::get('MySQL Error: ', false) . $link->last_error);
                     break;
                 }
                 $sql = "";
             }
         }
     }
     WPAdm_Core::log(langWPADM::get('Restore Database was finished', false));
 }
 public function execute(WPAdm_Command_Context $context)
 {
     @session_start();
     require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
     WPAdm_Core::log(langWPADM::get('Send to dropbox files', false));
     $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
     if (!$dropbox->isAuth()) {
         $context->setError(langWPADM::get('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"', false, array('%d', '%k', '%s'), array(SITE_HOME, $context->get('key'), $context->get('secret'))));
         return false;
     }
     $files = $context->get('files');
     $file = explode("/", $files);
     $file_name = array_pop($file);
     $folder_project_temp = $context->get('folder_project');
     $folder_project = "";
     if (!empty($folder_project_temp)) {
         $folder_project = $folder_project_temp . "/";
         $dropbox->createDir($folder_project_temp);
         $dropbox->createDir($folder_project . $context->get('folder'));
     } else {
         $dropbox->createDir($context->get('folder'));
     }
     $fromFile = str_replace('//', '/', $files);
     $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
     $local = $context->get('local');
     $file_dropbox = $dropbox->listing($folder_project . $context->get('folder') . '/' . $file_name);
     $send = true;
     if (!isset($file_dropbox['error'])) {
         if ($file_dropbox['bytes'] != filesize($fromFile)) {
             $delete_file = $dropbox->deleteFile($folder_project . $context->get('folder') . '/' . $file_name);
             if (isset($delete_file['error'])) {
                 $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $delete_file['text'] . '"');
                 return false;
             }
             $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
             if (isset($data_command[$fromFile])) {
                 $data_error_command[$fromFile]['count'] += 1;
             } else {
                 $data_error_command[$fromFile] = array();
                 $data_error_command[$fromFile]['count'] = 1;
             }
             WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
         } else {
             $send = false;
         }
     }
     if ($local) {
         $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
         if (empty($data_command) || !in_array($fromFile, $data_command)) {
             if ($send) {
                 $res = $dropbox->uploadFile($fromFile, $toFile, true);
             } else {
                 $this->saveDataCommand($fromFile);
             }
         }
     } else {
         $res = $dropbox->uploadFile($fromFile, $toFile, true);
     }
     if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
         $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $res['text'] . '"');
         return false;
     }
     if (isset($res['size']) && isset($res['client_mtime'])) {
         WPAdm_Core::log(langWPADM::get('File upload: ', false) . basename($files) . langWPADM::get(' size: ', false) . $res['size']);
         $this->saveDataCommand($fromFile);
     }
     return true;
 }
 public function getResult()
 {
     if ($this->restore) {
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
         $this->result->setError('');
         WPAdm_Core::log(langWPADM::get('Start Restore process', false));
         $n = count($this->md5_info);
         if (in_array('files', $this->params['types'])) {
             foreach ($this->files_resotre as $key => $file) {
                 if (file_exists($file)) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'restore_backup')->addParam('zip_file', $file);
                     $this->queue->clear()->add($commandContext)->save()->execute();
                     unset($commandContext);
                 }
             }
         }
         if (in_array('db', $this->params['types'])) {
             $this->getWpMysqlParams();
             for ($i = 0; $i < $n; $i++) {
                 if (strpos($this->md5_info[$i], "mysqldump.sql") !== false) {
                     $data = explode("\t", $this->md5_info[$i]);
                     if (isset($this->files_resotre[$data[2]]) && file_exists($this->files_resotre[$data[2]])) {
                         $commandContext = new WPAdm_Command_Context();
                         $commandContext->addParam('command', 'restore_backup')->addParam('file', $data[0])->addParam('zip_file', $this->files_resotre[$data[2]]);
                         $commandContext->addParam('db_password', $this->db_data['password'])->addParam('db_name', $this->db_data['db'])->addParam('db_user', $this->db_data['user'])->addParam('db_host', $this->db_data['host']);
                         $this->queue->clear()->add($commandContext)->save()->execute();
                         unset($commandContext);
                     } else {
                         $log = langWPADM::get('Website "%d" returned an error during backup restoration: Part Backup is not exist "%s" ', false, array('%d', '%s'), array(SITE_HOME, $data[2]));
                         $this->setError($log);
                         WPAdm_Core::log($log);
                         break;
                     }
                 }
             }
         }
     } else {
         WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during restore backup: Files for restore is not exist, check permission your backup data or You can send to us support request using "Help" button on plugin page.', false, array('%d'), array(SITE_HOME)));
     }
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_send_to_dropbox_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     if (isset($this->params['local']) && $this->params['local']) {
         $params_data_cron = WPAdm_Running::getCommandResultData('local_backup');
         $this->params['files'] = $params_data_cron['data'];
         $this->params['access_details']['dir'] = $params_data_cron['name'];
         WPAdm_Core::log(langWPADM::get('', false));
     }
     $this->queue = new WPAdm_Queue($this->id);
     $ad = $this->params['access_details'];
     $this->queue->clear();
     $files = $this->params['files'];
     //$this->getResult()->setData($files);
     $dir = isset($ad['dir']) ? $ad['dir'] : '/';
     //$dir = trim($dir, '/') . '/' . $this->name;
     if (is_array($files)) {
         $send = false;
         foreach ($files as $file) {
             if (isset($this->params['local']) && $this->params['local']) {
                 $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
                 $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
                 if (isset($data_error_command[ABSPATH . $file]) && $data_error_command[ABSPATH . $file]['count'] > WPADM_COUNT_LIMIT_SEND_TO_DROPBOX) {
                     $msg = langWPADM::get('Not perhaps sending file: "%file%". If you wish make upload file, increase execution time code or speed internet provider is small for upload file.', false, '%file%', $file);
                     WPAdm_Core::log($msg);
                     $errors[] = $msg;
                     break;
                 }
                 if (!empty($data_command) && in_array(ABSPATH . $file, $data_command)) {
                     continue;
                 }
             }
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $ad['key'])->addParam('secret', $ad['secret'])->addParam('token', $ad['token'])->addParam('folder_project', $ad['folder'])->addParam('folder', $dir)->addParam('files', ABSPATH . $file);
             if (isset($this->params['local']) && $this->params['local']) {
                 $commandContext->addParam('local', true);
             }
             $this->queue->add($commandContext);
             unset($commandContext);
             $send = true;
         }
     }
     if ($send) {
         WPAdm_Core::log(langWPADM::get('Start copy to Dropbox Cloud', false));
         $res = $this->queue->save()->execute();
         WPAdm_Core::log(langWPADM::get('End Copy Files to Dropbox', false));
     }
     if (isset($res) && !$res) {
         WPAdm_Core::log(langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError());
         $errors[] = langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError();
     }
     if (count($errors) > 0) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     } else {
         if (class_exists('wpadm_wp_full_backup_dropbox') && !file_exists(WPAdm_Core::getTmpDir() . "/notice-star")) {
             wpadm_wp_full_backup_dropbox::setFlagToTmp('notice-star', time() . "_1d");
         }
         if (isset($this->params['local']) && $this->params['local'] && isset($params_data_cron)) {
             $this->result->setData($this->params['files']);
             $this->result->setSize($params_data_cron['size']);
             $this->result->setValue('md5_data', md5(print_r($this->result->toArray(), 1)));
             $this->result->setValue('name', $params_data_cron['name']);
             $this->result->setValue('time', $params_data_cron['time']);
             $this->result->setValue('type', 'dropbox');
             $this->result->setValue('counts', $params_data_cron['counts']);
             WPAdm_Core::rmdir(DROPBOX_BACKUP_DIR_BACKUP . "/{$params_data_cron['name']}");
         }
     }
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log('Start backup');
     WPAdm_Core::mkdir(ABSPATH . 'wpadm_backup');
     $mysql_dump_file = ABSPATH . 'wpadm_backup/mysqldump.sql';
     if (file_exists($mysql_dump_file)) {
         unlink($mysql_dump_file);
     }
     $wp_mysql_params = $this->getWpMysqlParams();
     if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
         WPAdm_Core::log('Optimize database tables');
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
         $this->queue->clear()->add($commandContext);
         unset($commandContext);
     }
     $commandContext = new WPAdm_Command_Context();
     $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
     $res = $this->queue->add($commandContext)->save()->execute();
     if (!$res) {
         WPAdm_Core::log('Database dump was not created(' . $this->queue->getError() . ')');
         $errors[] = 'MySQL error: ' . $this->queue->getError();
     } elseif (0 == (int) filesize($mysql_dump_file)) {
         $errors[] = 'MySQL error: empty dump-file';
         WPAdm_Core::log('Database dump was not created(empty file)');
     } else {
         WPAdm_Core::log('Database dump created(' . filesize($mysql_dump_file) . 'b):' . $mysql_dump_file);
     }
     unset($commandContext);
     WPAdm_Core::log('Start preparing a list of files');
     $files = array();
     if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = 'Empty list files';
     }
     // Divide the list of files on the lists from 170 kbytes to break one big task into smaller
     $files2 = array();
     $files2[0] = array();
     $i = 0;
     $size = 0;
     foreach ($files as $f) {
         if ($size > 170000) {
             //~170kbyte
             $i++;
             $size = 0;
             $files2[$i] = array();
         }
         $f_size = (int) filesize($f);
         if ($f_size == 0 || $f_size > 1000000) {
             WPAdm_Core::log('file ' . $f . ' size ' . $f_size);
         }
         $size += $f_size;
         $files2[$i][] = $f;
     }
     WPAdm_Core::log('List of files prepared');
     $this->queue->clear();
     foreach ($files2 as $files) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     WPAdm_Core::log('Getting back up files');
     $this->queue->save()->execute();
     WPAdm_Core::log('Ended up files');
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     $totalSize = 0;
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
         $totalSize += @intval(filesize($file));
     }
     $this->result->setData($urls);
     $this->result->setSize($totalSize);
     $remove_from_server = 0;
     if (isset($this->params['storage'])) {
         foreach ($this->params['storage'] as $storage) {
             if ($storage['type'] == 's3') {
                 WPAdm_Core::log('Begin coping files to S3');
                 $this->queue->clear();
                 $files = glob($this->dir . '/' . $this->name . '*');
                 //$this->getResult()->setData($files);
                 $ad = $storage['access_details'];
                 $dir = isset($ad['dir']) ? $ad['dir'] : '/';
                 $dir = trim($dir, '/') . '/' . $this->name;
                 foreach ($files as $file) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'send_to_s3')->addParam('file', $file)->addParam('bucket', $ad['bucket'])->addParam('AccessKeyId', $ad['AccessKeyId'])->addParam('SecretAccessKey', $ad['SecretAccessKey'])->addParam('SessionToken', $ad['SessionToken']);
                     if (isset($ad['mkdir_for_backup']) && $ad['mkdir_for_backup'] == 1) {
                         $commandContext->addParam('dir', $this->name);
                     }
                     $this->queue->add($commandContext);
                     unset($commandContext);
                 }
                 $res = $this->queue->save()->execute();
                 if (!$res) {
                     WPAdm_Core::log('S3: ' . $this->queue->getError());
                     $errors[] = 'S3: ' . $this->queue->getError();
                 }
                 WPAdm_Core::log('Finished copying files to S3');
                 if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1) {
                     $remove_from_server = $storage['remove_from_server'];
                 }
             }
         }
         if ($remove_from_server) {
             // удаляем файлы на сервере
             WPAdm_Core::log('Remove the backup server');
             WPAdm_Core::rmdir($this->dir);
         }
     }
     # delete tmpf-files
     WPAdm_Core::rmdir(ABSPATH . 'wpadm_backup');
     #Remove old archives (over limit)
     WPAdm_Core::log('Start removing old files');
     if ($this->params['limit'] != 0) {
         $files = glob(ABSPATH . 'wpadm_backups/*');
         if (count($files) > $this->params['limit']) {
             $files2 = array();
             foreach ($files as $f) {
                 $fa = explode('-', $f);
                 if (count($fa) != 3) {
                     continue;
                 }
                 $files2[$fa[2]] = $f;
             }
             ksort($files2);
             $d = count($files2) - $this->params['limit'];
             $del = array_slice($files2, 0, $d);
             foreach ($del as $d) {
                 WPAdm_Core::rmdir($d);
             }
         }
     }
     WPAdm_Core::log('Finished delete the old files');
     WPAdm_Core::log('backup completed');
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 private function directoryToArray($directory, $recursive)
 {
     $array_items = array();
     $d = str_replace(ABSPATH . '/', '', $directory);
     // пропускаем ненужные директории
     if (in_array($d, $this->params['minus-path'])) {
         WPAdm_Core::log('Пропускаем папку ' . $directory);
         return array();
     }
     if ($handle = opendir($directory)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 if (is_dir($directory . "/" . $file)) {
                     if ($recursive) {
                         $array_items = array_merge($array_items, $this->directoryToArray($directory . "/" . $file, $recursive));
                     }
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH . '/', '', $ff);
                         // пропускаем ненужные директории
                         if (!in_array($f, $this->params['minus-path'])) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log('Пропускаем файл ' . $ff);
                         }
                     }
                 } else {
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH . '/', '', $ff);
                         // пропускаем ненужные директории
                         if (!in_array($f, $this->params['minus-path'])) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log('Пропускаем файл ' . $ff);
                         }
                     }
                 }
             }
         }
         closedir($handle);
     }
     return $array_items;
 }
 public static function restore_backup()
 {
     require_once dirname(__FILE__) . "/class-wpadm-core.php";
     @session_write_close();
     $log = new WPAdm_Core(array('method' => "local"), 'db_backup_s3', dirname(__FILE__));
     if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
         unlink(WPAdm_Core::getTmpDir() . "/logs2");
     }
     if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
         unlink(WPAdm_Core::getTmpDir() . "/log.log");
     }
     $res['error'] = 'Error';
     $res['result'] = 'error';
     parent::$type = 'db';
     if (isset($_POST['type'])) {
         $name_backup = isset($_POST['name']) ? trim($_POST['name']) : "";
         $dir = ABSPATH . 'wpadm_backups/' . $name_backup;
         if ($_POST['type'] == 'local') {
             $backup = new WPAdm_Core(array('method' => "local_restore", 'params' => array('types' => array('db'), 'name_backup' => $name_backup)), 'db_backup_s3', dirname(__FILE__));
             $res = $backup->getResult()->toArray();
         } elseif ($_POST['type'] == 's3') {
             $amazon_option = self::getAmazonOptions();
             if ($amazon_option) {
                 require_once dirname(__FILE__) . '/modules/aws-autoloader.php';
                 try {
                     $credentials = new Aws\Common\Credentials\Credentials($amazon_option['access_key_id'], $amazon_option['secret_access_key']);
                     $client = Aws\S3\S3Client::factory(array('credentials' => $credentials));
                     $project = self::getNameProject();
                     WPAdm_Core::log("Get Files for Resore Backup");
                     $keys = $client->listObjects(array('Bucket' => $amazon_option['bucket'], 'Prefix' => $name_backup))->getIterator();
                     //->getPath('Contents/*/Key');
                     if (isset($keys['Contents'])) {
                         $n = count($keys['Contents']);
                         WPAdm_Core::mkdir($dir);
                         WPAdm_Core::log("Start Downloads files with Amazon S3");
                         for ($i = 0; $i < $n; $i++) {
                             $path = explode("/", $keys['Contents'][$i]['Key']);
                             if (isset($path[0]) && isset($path[1]) && !empty($path[1])) {
                                 $result = $client->getObject(array('Bucket' => $amazon_option['bucket'], 'Key' => $keys['Contents'][$i]['Key'], 'SaveAs' => ABSPATH . 'wpadm_backups/' . $keys['Contents'][$i]['Key']));
                                 WPAdm_Core::log("Download file - {$keys['Contents'][$i]['Key']}");
                             }
                         }
                         WPAdm_Core::log("End downloads files with Amazon S3");
                         $restore = new WPAdm_Core(array('method' => "local_restore", 'params' => array('log-delete' => 0, 'types' => array('db'), 'name_backup' => $name_backup)), 'db_backup_s3', dirname(__FILE__));
                         $res = $restore->getResult()->toArray();
                         if (is_dir($dir)) {
                             WPAdm_Core::rmdir($dir);
                         }
                     } else {
                         $res['error'] = "Error, in downloads with Amazon S3";
                         $res['result'] = 'error';
                     }
                 } catch (Exception $e) {
                     $res['error'] = $e->getMessage();
                     $res['result'] = 'error';
                 } catch (S3Exception $e) {
                     $res['error'] = $e->getMessage();
                     $res['result'] = 'error';
                 }
             } else {
                 $res['error'] = 'Error: Data is not exist for send backup files to Amazon S3. Please type your Data in the Settings form';
                 $res['result'] = 'error';
             }
         }
     }
     @session_start();
     echo json_encode($res);
     wp_die();
 }
 private function directoryToArray($directory, $recursive)
 {
     $array_items = array();
     $d = str_replace(ABSPATH, '', $directory);
     // Skip dirs
     if (isset($this->params['minus-path'])) {
         $minus_path = explode(",", $this->params['minus-path']);
         if (in_array($d, $minus_path)) {
             WPAdm_Core::log(langWPADM::get('Skip of Folder ', false) . $directory);
             return array();
         }
     } else {
         $minus_path = array();
     }
     $d = str_replace('\\', '/', $d);
     $tmp = explode('/', $d);
     $d1 = mb_strtolower($tmp[0]);
     unset($tmp[0]);
     $d2 = mb_strtolower(implode('/', $tmp));
     if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes'))) {
         WPAdm_Core::log(langWPADM::get('Skip of Cache-Folder ', false) . $directory);
         return array();
     }
     if (strpos($directory, 'wpadm_backups') !== false) {
         return array();
     }
     if ($handle = opendir($directory)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 if (is_dir($directory . "/" . $file)) {
                     if ($recursive) {
                         $array_items = array_merge($array_items, $this->directoryToArray($directory . "/" . $file, $recursive));
                     }
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH, '', $ff);
                         // skip "minus" dirs
                         if (!in_array($f, $minus_path)) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log(langWPADM::get('Skip of File ', false) . $ff);
                         }
                     }
                 } else {
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH, '', $ff);
                         // skip "minus" dirs
                         if (!in_array($f, $minus_path)) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log(langWPADM::get('Skip of Folder ', false) . $ff);
                         }
                     }
                 }
             }
         }
         closedir($handle);
     }
     return $array_items;
 }
 public function restore($db, $file)
 {
     $link = $this->connect($db);
     WPAdm_Core::log("Restore Database was started");
     $fo = fopen($file, "r");
     if (!$fo) {
         WPAdm_Core::log("Error in open file dump");
         $this->setError("Error in open file dump");
         return false;
     }
     $sql = "";
     while (false !== ($char = fgetc($fo))) {
         $sql .= $char;
         if ($char == ";") {
             $char_new = fgetc($fo);
             if ($char_new !== false && $char_new != "\n") {
                 $sql .= $char_new;
             } else {
                 $ress = mysqli_query($link, $sql);
                 if (!$ress) {
                     $this->setError(mysqli_error($link));
                     WPAdm_Core::log("MySQL Error: " . mysqli_error($link));
                     break;
                 }
                 $sql = "";
             }
         }
     }
     WPAdm_Core::log("Restore Database was finished");
 }
 public static function dropbox_backup_create()
 {
     require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
     @session_write_close();
     $log = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
     if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
         @unlink(WPAdm_Core::getTmpDir() . "/logs2");
     }
     if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
         file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
     }
     if (WPAdm_Core::dir_writeble(DROPBOX_BACKUP_DIR_BACKUP) && !file_exists(WPAdm_Core::getTmpDir() . "/create-backup")) {
         file_put_contents(WPAdm_Core::getTmpDir() . "/create-backup", 1);
         $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
         $send_to_dropbox = true;
         if ($dropbox_options) {
             $dropbox_options = unserialize(base64_decode($dropbox_options));
             if (!isset($dropbox_options['app_key'])) {
                 WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "App Key" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME));
                 $send_to_dropbox = false;
             }
             if (!isset($dropbox_options['app_secret'])) {
                 WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "App Secret" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME));
                 $send_to_dropbox = false;
             }
             if (!isset($dropbox_options['oauth_token'])) {
                 WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during file sending to Dropbox: "Auth Token not exist. Files cannot be sent to Dropbox cloud. Please, check your Dropbox settings."', false, '%d', SITE_HOME));
                 $send_to_dropbox = false;
             }
         } else {
             WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "app key" and "app secret" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME));
             $res['type'] = 'local';
             $send_to_dropbox = false;
         }
         if ($send_to_dropbox) {
             parent::$type = 'full';
             WPAdm_Running::init_params_default();
             WPAdm_Running::delCommandResultData("local_backup");
             $dropbox_options = self::getSettings();
             $optimization = isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1 || !isset($dropbox_options['is_optimization']) ? 1 : 0;
             $backup_local = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files'))), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
             $res = array();
             if (WPAdm_Core::$cron === false) {
                 $res = $backup->getResult()->toArray();
                 $res['md5_data'] = md5(print_r($res, 1));
                 $res['name'] = $backup->name;
                 $res['time'] = $backup->time;
                 $res['type'] = 'dropbox';
                 $res['counts'] = count($res['data']);
             }
             unset($backup_local);
             $folder_project = self::getNameProject();
             WPAdm_Running::delCommandResultData("send-to-dropbox");
             $backup = new WPAdm_Core(array('method' => "send-to-dropbox", 'params' => array('files' => isset($res['data']) ? $res['data'] : '', 'local' => true, 'access_details' => array('key' => $dropbox_options['app_key'], 'secret' => $dropbox_options['app_secret'], 'token' => $dropbox_options['auth_token_secret'], 'dir' => isset($res['name']) ? $res['name'] : '', 'folder' => $folder_project))), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
             if (WPAdm_Core::$cron === false) {
                 $result_send = $backup->getResult()->toArray();
                 if ($result_send['result'] == 'error') {
                     $res = array();
                     $res['error'] = $result_send['error'];
                     $res['result'] = 'error';
                     @rename(WPAdm_Core::getTmpDir() . "/logs2", WPAdm_Core::getTmpDir() . "/logs_error_" . $backup_local->time);
                 }
                 WPAdm_Core::rmdir(DROPBOX_BACKUP_DIR_BACKUP . "/{$res['name']}");
             } else {
                 set_transient('running_command', 'send-to-dropbox', 0);
                 $res['result'] = 'work';
                 $res['error'] = '';
                 $res['data'] = array();
                 $res['size'] = 0;
             }
             if (file_exists(WPAdm_Core::getTmpDir() . "/create-backup")) {
                 @unlink(WPAdm_Core::getTmpDir() . "/create-backup");
             }
         }
     } else {
         $res['result'] = 'error';
         $res['error'] = langWPADM::get('Website "%domain" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir-backup".', false, array('%domain', '%dir-backup'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP));
         $res['data'] = array();
         $res['size'] = 0;
     }
     @session_start();
     echo json_encode($res);
     wp_die();
 }
 private function directoryToArray($directory, $recursive)
 {
     $array_items = array();
     $d = str_replace(ABSPATH . '/', '', $directory);
     // пропускаем ненужные директории
     if (in_array($d, $this->params['minus-path'])) {
         WPAdm_Core::log('Пропускаем папку ' . $directory);
         return array();
     }
     $d = str_replace('\\', '/', $d);
     $tmp = explode('/', $d);
     $d1 = mb_strtolower($tmp[0]);
     unset($tmp[0]);
     $d2 = mb_strtolower(implode('/', $tmp));
     //        if (strpos($d1, 'cache') !== false || ($d1 == 'wp-includes' && strpos($d2, 'cache') !== false)) {
     //        if (($d1 == 'wp-includes' && strpos($d2, 'cache') !== false)
     //           || ($d1 == 'wp-content' || !in_array($tmp[0], array('plugins', 'themes')))
     if (strpos($d2, 'cache') !== false && !in_array($tmp[0], array('plugins', 'themes'))) {
         WPAdm_Core::log('Пропускаем папку(cache) ' . $directory);
         return array();
     }
     if (strpos($directory, 'wpadm_backups') !== false) {
         return array();
     }
     if ($handle = opendir($directory)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 if (is_dir($directory . "/" . $file)) {
                     if ($recursive) {
                         $array_items = array_merge($array_items, $this->directoryToArray($directory . "/" . $file, $recursive));
                     }
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH . '/', '', $ff);
                         // пропускаем ненужные директории
                         if (!in_array($f, $this->params['minus-path'])) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log('Пропускаем файл ' . $ff);
                         }
                     }
                 } else {
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH . '/', '', $ff);
                         // пропускаем ненужные директории
                         if (!in_array($f, $this->params['minus-path'])) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log('Пропускаем файл ' . $ff);
                         }
                     }
                 }
             }
         }
         closedir($handle);
     }
     return $array_items;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/S3.php';
     $s3 = new S3($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     //new S3Wrapper();
     //S3::setAuth($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     /*(array(
       'key'    => $context->get('AccessKeyId'),
       'secret' => $context->get('SecretAccessKey'),
       'token'  => $context->get('SessionToken')
       ));   */
     // $s3->setTimeCorrectionOffset(60);
     $dir = $context->get('dir') ? $context->get('dir') : '';
     if ($dir) {
         //$s3->mkdir('s3://' . $context->get('bucket') . '/' . $dir);
         $logs = $s3->putObject($dir, $context->get('bucket'), $dir . "/", s3::ACL_PUBLIC_READ);
         //$logs = $s3->putObjectString($dir, $context->get('bucket'), $context->get('bucket') . '/' . $dir, s3::ACL_PUBLIC_READ_WRITE);
         WPAdm_Core::log('create folder logs ' . serialize($logs));
         /*$s3->registerStreamWrapper("s3");
           @mkdir('s3://'.$context->get('bucket').'/'.$dir);*/
     }
     try {
         $filePath = preg_replace('#[/\\\\]+#', '/', $context->get('file'));
         $key = $dir ? $dir . '/' . basename($filePath) : basename($filePath);
         $key = ltrim(preg_replace('#[/\\\\]+#', '/', $key), '/');
         //if first will be '/', file not will be uploaded, but result will be ok
         $putRes = $s3->putObjectFile($filePath, $context->get('bucket'), $key, s3::ACL_PUBLIC_READ_WRITE);
         WPAdm_Core::log('putObjectFile ' . $filePath . ' == ' . $context->get('bucket') . " == " . $key . ' == ' . (int) $putRes);
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     } catch (S3Exception $e) {
         WPAdm_Core::log('error send file ' . $e->getMessage());
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }