mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
🎨 Reformat some code
This commit is contained in:
@@ -30,21 +30,25 @@ class Dropbox extends TransportAbstract
|
||||
public function send()
|
||||
{
|
||||
$sent = true;
|
||||
$files = $this->backup->getFilesTobackup();
|
||||
$files = $this->backup->getFilesToBackup();
|
||||
foreach ($files as $file => $name) {
|
||||
$file = fopen($file, 'r');
|
||||
$file = fopen($file, 'rb');
|
||||
$upload = $this->dropbox->uploadFile($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $file);
|
||||
if (!$upload) {
|
||||
$sent = false;
|
||||
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||||
}
|
||||
}
|
||||
$streams = $this->backup->getStreamsTobackup();
|
||||
$streams = $this->backup->getStreamsToBackup();
|
||||
foreach ($streams as $stream => $name) {
|
||||
$upload = $this->dropbox->uploadFileFromString($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $stream);
|
||||
$upload = $this->dropbox->uploadFileFromString(
|
||||
$this->folder . '/' . $name,
|
||||
\Dropbox\WriteMode::force(),
|
||||
$stream
|
||||
);
|
||||
if (!$upload) {
|
||||
$sent = false;
|
||||
echo 'DROPBOX upload manqu<EFBFBD>e de '.$file.' vers '.$this->folder.$name;
|
||||
echo 'DROPBOX upload manquée de ' . $file . ' vers '.$this->folder.$name;
|
||||
}
|
||||
}
|
||||
return $sent;
|
||||
|
||||
@@ -132,16 +132,19 @@ class Email extends TransportAbstract
|
||||
$type = (string) finfo_file($finfo, $file);
|
||||
finfo_close($finfo);
|
||||
return $type;
|
||||
} else if (function_exists('mime_content_type')) {
|
||||
return mime_content_type($file);
|
||||
} else {
|
||||
$ext = strtolower(array_pop(explode('.', $file)));
|
||||
if (array_key_exists($ext, self::$mimeTypes)) {
|
||||
return self::$mimeTypes[$ext];
|
||||
} else {
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('mime_content_type')) {
|
||||
return mime_content_type($file);
|
||||
}
|
||||
|
||||
$file_info = explode('.', $file);
|
||||
$ext = strtolower(array_pop($file_info));
|
||||
if (array_key_exists($ext, self::$mimeTypes)) {
|
||||
return self::$mimeTypes[$ext];
|
||||
}
|
||||
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,8 +153,8 @@ class Email extends TransportAbstract
|
||||
public function __construct(BackupAbstract $backup, array $config)
|
||||
{
|
||||
parent::__construct($backup, $config);
|
||||
$this->setFiles($this->backup->getFilesTobackup());
|
||||
$this->setStreams($this->backup->getStreamsTobackup());
|
||||
$this->setFiles($this->backup->getFilesToBackup());
|
||||
$this->setStreams($this->backup->getStreamsToBackup());
|
||||
$this->email_to = $this->config['to'];
|
||||
$this->email_from = $this->config['from'];
|
||||
$this->encoding = $this->config['encoding'];
|
||||
@@ -200,8 +203,8 @@ class Email extends TransportAbstract
|
||||
|
||||
// Checking files are selected
|
||||
$zip = new \ZipArchive(); // Load zip library
|
||||
$zip_name = time().".zip"; // Zip name
|
||||
if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==true) {
|
||||
$zip_name = time(). '.zip'; // Zip name
|
||||
if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)===true) {
|
||||
if (!empty($this->files)) {
|
||||
foreach ($this->files as $file => $name) {
|
||||
$zip->addFile($file, $name); // Adding files into zip
|
||||
@@ -214,9 +217,9 @@ class Email extends TransportAbstract
|
||||
|
||||
$this->files = array(TEMP_DIR.$zip_name=>$zip_name);
|
||||
|
||||
$random_hash = md5(date('r', time()));
|
||||
$headers = "From: " . $this->email_from . "\r\nReply-To: " . $this->email_from;
|
||||
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"" . $random_hash . "\"";
|
||||
$random_hash = md5(date('r'));
|
||||
$headers = 'From: ' . $this->email_from . "\r\nReply-To: " . $this->email_from;
|
||||
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"" . $random_hash . '"';
|
||||
$output = "
|
||||
|
||||
--$random_hash
|
||||
@@ -229,26 +232,26 @@ Content-Transfer-Encoding: 8bit
|
||||
foreach ($this->files as $file => $name) {
|
||||
$output .= "
|
||||
--$random_hash
|
||||
Content-Type: " . self::getMimeType($file) . "; name=" . $name . "
|
||||
Content-Type: " . self::getMimeType($file) . '; name=' . $name . '
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Disposition: attachment; filename=" . $name . "
|
||||
Content-Disposition: attachment; filename=' . $name . '
|
||||
|
||||
" . chunk_split(base64_encode(file_get_contents($file)));
|
||||
' . chunk_split(base64_encode(file_get_contents($file)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->streams)) {
|
||||
foreach ($this->streams as $name => $stream) {
|
||||
if (count(explode('.', $name))<2) {
|
||||
if (substr_count($name, '.') + 1 <2) {
|
||||
$name = 'backup'.$name.'.txt';
|
||||
}
|
||||
$output .= "
|
||||
--$random_hash
|
||||
Content-Type: text/plain; name=" . $name . "
|
||||
Content-Type: text/plain; name=" . $name . '
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Disposition: attachment; filename=" . $name . "
|
||||
Content-Disposition: attachment; filename=' . $name . '
|
||||
|
||||
" . chunk_split(base64_encode($stream));
|
||||
' . chunk_split(base64_encode($stream));
|
||||
}
|
||||
}
|
||||
$output.="--$random_hash--";
|
||||
|
||||
@@ -25,7 +25,7 @@ class Ftp extends TransportAbstract
|
||||
}
|
||||
|
||||
$this->connection = ftp_connect($this->host);
|
||||
if ($this->connection == false) {
|
||||
if ($this->connection === false) {
|
||||
throw new \Exception(sprintf('I can\'t connect to the FTP %s', $this->host));
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ class Ftp extends TransportAbstract
|
||||
throw new \Exception($msg);
|
||||
}
|
||||
|
||||
$this->setFiles($this->backup->getFilesTobackup());
|
||||
$this->setStreams($this->backup->getStreamsTobackup());
|
||||
$this->setFiles($this->backup->getFilesToBackup());
|
||||
$this->setStreams($this->backup->getStreamsToBackup());
|
||||
}
|
||||
|
||||
private function setFiles($files = array())
|
||||
@@ -57,6 +57,7 @@ class Ftp extends TransportAbstract
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
@@ -74,7 +75,7 @@ class Ftp extends TransportAbstract
|
||||
|
||||
if (!empty($this->streams)) {
|
||||
foreach ($this->streams as $name => $stream) {
|
||||
if (count(explode('.', $name)) < 2) {
|
||||
if (substr_count($name, '.') + 1 < 2) {
|
||||
$name = 'backup' . $name . '.txt';
|
||||
}
|
||||
file_put_contents($name, $stream);
|
||||
|
||||
@@ -29,13 +29,13 @@ class Folder extends TransportAbstract
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
foreach ($this->backup->getFilesTobackup() as $file => $name) {
|
||||
foreach ($this->backup->getFilesToBackup() as $file => $name) {
|
||||
if (copy($file, $this->folder . $name) === false) {
|
||||
throw new \Exception(sprintf('Copy of %s in %s failed', $name, $this->folder));
|
||||
};
|
||||
}
|
||||
foreach ($this->backup->getStreamsTobackup() as $name => $file) {
|
||||
if (count(explode('.', $name)) < 2) {
|
||||
foreach ($this->backup->getStreamsToBackup() as $name => $file) {
|
||||
if (substr_count($name, '.') + 1 < 2) {
|
||||
$name = 'backup' . $name . '.txt';
|
||||
}
|
||||
if (file_put_contents($this->folder . $name, $file) === false) {
|
||||
|
||||
@@ -42,7 +42,7 @@ class Sftp extends TransportAbstract
|
||||
public function send()
|
||||
{
|
||||
$sent = true;
|
||||
$files = $this->backup->getFilesTobackup();
|
||||
$files = $this->backup->getFilesToBackup();
|
||||
if (!empty($files)) {
|
||||
foreach ($files as $file => $name) {
|
||||
$upload = $this->connection->put($this->folder.'/'.$name, $file, LibSFTP::SOURCE_LOCAL_FILE);
|
||||
@@ -53,12 +53,12 @@ class Sftp extends TransportAbstract
|
||||
}
|
||||
}
|
||||
|
||||
$streams = $this->backup->getStreamsTobackup();
|
||||
$streams = $this->backup->getStreamsToBackup();
|
||||
if (!empty($streams)) {
|
||||
foreach ($streams as $name => $stream) {
|
||||
$upload = $this->connection->put($this->folder.'/'.$name, $stream);
|
||||
if (!$upload) {
|
||||
echo 'SFTP upload manqu<EFBFBD>e de '.$name.' vers '.$this->folder.$name;
|
||||
echo 'SFTP upload manquée de '.$name.' vers '.$this->folder.$name;
|
||||
$sent = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user