mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
🎨 Apply PSR2
This commit is contained in:
parent
ab7887ce84
commit
db51375185
@ -125,7 +125,8 @@ class Email extends TransportAbstract
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getMimeType($file) {
|
public static function getMimeType($file)
|
||||||
|
{
|
||||||
if (function_exists('finfo_open')) {
|
if (function_exists('finfo_open')) {
|
||||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
$type = (string) finfo_file($finfo, $file);
|
$type = (string) finfo_file($finfo, $file);
|
||||||
@ -135,17 +136,19 @@ class Email extends TransportAbstract
|
|||||||
return mime_content_type($file);
|
return mime_content_type($file);
|
||||||
} else {
|
} else {
|
||||||
$ext = strtolower(array_pop(explode('.', $file)));
|
$ext = strtolower(array_pop(explode('.', $file)));
|
||||||
if (array_key_exists($ext, self::$mimeTypes))
|
if (array_key_exists($ext, self::$mimeTypes)) {
|
||||||
return self::$mimeTypes[$ext];
|
return self::$mimeTypes[$ext];
|
||||||
else
|
} else {
|
||||||
return 'application/octet-stream';
|
return 'application/octet-stream';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param BackupAbstract $backup
|
* @param BackupAbstract $backup
|
||||||
*/
|
*/
|
||||||
public function __construct(BackupAbstract $backup, array $config) {
|
public function __construct(BackupAbstract $backup, array $config)
|
||||||
|
{
|
||||||
parent::__construct($backup, $config);
|
parent::__construct($backup, $config);
|
||||||
$this->setFiles($this->backup->getFilesTobackup());
|
$this->setFiles($this->backup->getFilesTobackup());
|
||||||
$this->setStreams($this->backup->getStreamsTobackup());
|
$this->setStreams($this->backup->getStreamsTobackup());
|
||||||
@ -198,10 +201,9 @@ class Email extends TransportAbstract
|
|||||||
// Checking files are selected
|
// Checking files are selected
|
||||||
$zip = new \ZipArchive(); // Load zip library
|
$zip = new \ZipArchive(); // Load zip library
|
||||||
$zip_name = time().".zip"; // Zip name
|
$zip_name = time().".zip"; // Zip name
|
||||||
if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==TRUE) {
|
if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==true) {
|
||||||
if (!empty($this->files)) {
|
if (!empty($this->files)) {
|
||||||
foreach($this->files as $file => $name)
|
foreach ($this->files as $file => $name) {
|
||||||
{
|
|
||||||
$zip->addFile($file, $name); // Adding files into zip
|
$zip->addFile($file, $name); // Adding files into zip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,7 +225,7 @@ Content-Transfer-Encoding: 8bit
|
|||||||
|
|
||||||
" . $this->message . "\r\n";
|
" . $this->message . "\r\n";
|
||||||
|
|
||||||
if(!empty($this->files))
|
if (!empty($this->files)) {
|
||||||
foreach ($this->files as $file => $name) {
|
foreach ($this->files as $file => $name) {
|
||||||
$output .= "
|
$output .= "
|
||||||
--$random_hash
|
--$random_hash
|
||||||
@ -233,10 +235,13 @@ 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))
|
if (!empty($this->streams)) {
|
||||||
foreach ($this->streams as $name => $stream) {
|
foreach ($this->streams as $name => $stream) {
|
||||||
if(count(explode('.',$name))<2) $name = 'backup'.$name.'.txt';
|
if (count(explode('.', $name))<2) {
|
||||||
|
$name = 'backup'.$name.'.txt';
|
||||||
|
}
|
||||||
$output .= "
|
$output .= "
|
||||||
--$random_hash
|
--$random_hash
|
||||||
Content-Type: text/plain; name=" . $name . "
|
Content-Type: text/plain; name=" . $name . "
|
||||||
@ -245,8 +250,8 @@ Content-Disposition: attachment; filename=" . $name . "
|
|||||||
|
|
||||||
" . chunk_split(base64_encode($stream));
|
" . chunk_split(base64_encode($stream));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$output.="--$random_hash--";
|
$output.="--$random_hash--";
|
||||||
return mail($this->email_to, $this->subject, $output, $headers);
|
return mail($this->email_to, $this->subject, $output, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ abstract class BackupAbstract
|
|||||||
*
|
*
|
||||||
* @param array $config array of options and parameters
|
* @param array $config array of options and parameters
|
||||||
*/
|
*/
|
||||||
function __construct($config = array())
|
public function __construct($config = array())
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->options = !empty($config['options']) ? $config['options'] : [];
|
$this->options = !empty($config['options']) ? $config['options'] : [];
|
||||||
@ -174,7 +174,7 @@ abstract class BackupAbstract
|
|||||||
if (touch(TEMP_DIR . $zip_name) === false) {
|
if (touch(TEMP_DIR . $zip_name) === false) {
|
||||||
throw new \Exception('Backup::Zip::Permission denied.');
|
throw new \Exception('Backup::Zip::Permission denied.');
|
||||||
}
|
}
|
||||||
if ($zip->open(TEMP_DIR . $zip_name, \ZipArchive::OVERWRITE) == TRUE) {
|
if ($zip->open(TEMP_DIR . $zip_name, \ZipArchive::OVERWRITE) == true) {
|
||||||
foreach ($this->files_to_backup as $file => $name) {
|
foreach ($this->files_to_backup as $file => $name) {
|
||||||
$zip->addFile($file, $name); // Adding files into zip
|
$zip->addFile($file, $name); // Adding files into zip
|
||||||
}
|
}
|
||||||
@ -270,5 +270,4 @@ abstract class BackupAbstract
|
|||||||
throw new \Exception('name option is for zip only.');
|
throw new \Exception('name option is for zip only.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,4 +64,3 @@ class Files extends BackupAbstract
|
|||||||
// TODO: Implement build() method.
|
// TODO: Implement build() method.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user