diff --git a/AVE-PHP.iss b/AVE-PHP.iss index 1f1dc3f..896f5bf 100644 --- a/AVE-PHP.iss +++ b/AVE-PHP.iss @@ -1,5 +1,5 @@ #define MyAppName "AVE-PHP" -#define MyAppVersion "2.0.1" +#define MyAppVersion "2.1.0" #define MyAppPublisher "Abyss Morgan" #define MyAppURL "https://github.com/AbyssMorgan" #define MyAppExeName "AVE-PHP.cmd" @@ -41,9 +41,7 @@ Source: "{#SourcePath}\commands\*"; DestDir: "{app}\commands"; Flags: ignorevers Source: "{#SourcePath}\AVE-PHP.cmd"; DestDir: "{app}"; Flags: ignoreversion Source: "{#SourcePath}\LICENSE"; DestDir: "{app}"; Flags: ignoreversion Source: "{#SourcePath}\ave-php.ico"; DestDir: "{app}"; Flags: ignoreversion -Source: "{#SourcePath}\ave-php.png"; DestDir: "{app}"; Flags: ignoreversion Source: "{#SourcePath}\Changelog.txt"; DestDir: "{app}"; Flags: ignoreversion -Source: "{#SourcePath}\example.ave-php"; DestDir: "{app}"; Flags: ignoreversion Source: "{#SourcePath}\composer.json"; DestDir: "{app}"; Flags: ignoreversion [Icons] diff --git a/Changelog.txt b/Changelog.txt index 6522043..d14901b 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,13 @@ +v2.1.0: +- Added tool: Media Tools > Ident mime type: Images +- Added tool: Directory Names Editor > Escape directory name (WWW) +- Added tool: Directory Names Editor > Pretty directory name +- Added tool: Directory Names Editor > Add directory name prefix/suffix +- Added tool: Directory Names Editor > Remove keywords from directory name +- Added tool: Directory Names Editor > Insert string into directory name +- Added tool: Directory Names Editor > Replace keywords in directory name +- Rebuild AveCore and separated libraries that can be used without AVE-PHP + v2.0.1: - Improved tool: File Functions > Anti Duplicates (added mode a3 and b3 - detect duplicates and write logs only) - Improved tool: Media Tools > Video: Fetch media info (added FPS and codec) diff --git a/includes/AVE.php b/includes/AVE.php index 1e91cc4..14394f5 100644 --- a/includes/AVE.php +++ b/includes/AVE.php @@ -2,31 +2,32 @@ declare(strict_types=1); -use App\Services\IniFile; -use App\Services\AveCore; -use App\Services\AppBuffer; +use AveCore\Core; +use AveCore\IniFile; +use AveCore\AppBuffer; -use App\Tools\AveSettings; +use App\Tools\AdmFileConverter; use App\Tools\AveConsole; -use App\Tools\FileNamesEditor; +use App\Tools\AveSettings; +use App\Tools\CheckFileIntegrity; +use App\Tools\DirectoryFunctions; +use App\Tools\DirectoryNamesEditor; +use App\Tools\FileEditor; use App\Tools\FileFunctions; +use App\Tools\FileNamesEditor; +use App\Tools\FtpTools; use App\Tools\MediaSorter; -use App\Tools\DirectoryFunctions; use App\Tools\MediaTools; -use App\Tools\CheckFileIntegrity; use App\Tools\MySQLTools; -use App\Tools\FileEditor; -use App\Tools\FtpTools; -use App\Tools\AdmFileConverter; -class AVE extends AveCore { +class AVE extends Core { public IniFile $mkvmerge; public AppBuffer $app_buffer; public string $app_data; public bool $abort = false; public string $app_name = "AVE-PHP"; - public string $version = "2.0.1"; + public string $version = "2.1.0"; private array $folders_to_scan = [ 'bin', @@ -40,6 +41,7 @@ public function __construct(array $arguments){ $config_default = new IniFile($this->get_file_path("$this->path/includes/config/default.ini"), true); if($this->windows){ dl('php_imagick.dll'); + dl('php_exif.dll'); $config_default_system = new IniFile($this->get_file_path("$this->path/includes/config/windows.ini"), true); $old_app_data = $this->get_file_path($this->get_variable("%LOCALAPPDATA%")."/AVE"); $this->app_data = $this->get_file_path($this->get_variable("%LOCALAPPDATA%")."/AVE-PHP"); @@ -57,7 +59,7 @@ public function __construct(array $arguments){ $config_default_system->set('AVE_OPEN_FILE_BINARY', $open_file_binary); } - $config_default->update($config_default_system->getAll()); + $config_default->update($config_default_system->get_all()); $this->logo = "\r\n $this->app_name Toolkit v$this->version by Abyss Morgan\r\n"; $changed = false; @@ -80,15 +82,15 @@ public function __construct(array $arguments){ $this->config->unset(['AVE_DATA_FOLDER','AVE_LOG_FOLDER']); } - foreach($config_default->getAll() as $key => $value){ - if(!$this->config->isSet($key)){ + foreach($config_default->get_all() as $key => $value){ + if(!$this->config->is_set($key)){ $this->config->set($key, $value); $changed = true; } } - foreach($this->config->allExcept(['APP_NEXT_CHECK_FOR_UPDATE', 'APP_VERSION']) as $key => $value){ - if(!$config_default->isSet($key)){ + foreach($this->config->all_except(['APP_NEXT_CHECK_FOR_UPDATE', 'APP_VERSION']) as $key => $value){ + if(!$config_default->is_set($key)){ $this->config->unset($key); $changed = true; } @@ -195,17 +197,18 @@ public function select_tool() : bool { $this->tool_name = ''; $options = [ ' Tools:', - ' 0 - File Names Editor', - ' 1 - File Functions', - ' 2 - Media Sorter', - ' 3 - Directory Functions', - ' 4 - Media Tools', - ' 5 - Check File Integrity', - ' 6 - MySQL Tools', - ' 7 - File Editor', - ' 8 - FTP Tools', - ' 9 - ADM File Converter', - ' H - Help', + ' 0 - File Names Editor', + ' 1 - File Functions', + ' 2 - Media Sorter', + ' 3 - Directory Functions', + ' 4 - Media Tools', + ' 5 - Check File Integrity', + ' 6 - MySQL Tools', + ' 7 - File Editor', + ' 8 - FTP Tools', + ' 9 - ADM File Converter', + ' 10 - Directory Names Editor', + ' H - Help', ]; if(!$this->windows) array_push($options, ' # - Close program'); $this->print_help($options); @@ -253,12 +256,16 @@ public function select_tool() : bool { $this->tool = new AdmFileConverter($this); break; } + case '10': { + $this->tool = new DirectoryNamesEditor($this); + break; + } case 'H': { $this->tool = new AveSettings($this); break; } case '#': { - if($this->can_exit) return true; + if($this->can_exit || !$this->windows) return true; } } if(!$this->abort && !is_null($this->tool)){ diff --git a/includes/services/AppBuffer.php b/includes/avecore/AppBuffer.php similarity index 89% rename from includes/services/AppBuffer.php rename to includes/avecore/AppBuffer.php index 5c598cb..60dbc39 100644 --- a/includes/services/AppBuffer.php +++ b/includes/avecore/AppBuffer.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Services; +namespace AveCore; use Exception; @@ -10,24 +10,22 @@ class AppBuffer { protected string $path; - public int $version = 10000; - function __construct(string $path){ $this->path = $path; if(!file_exists($this->path)) mkdir($this->path, 0755, true); } - public function getPath() : string { + public function get_path() : string { return $this->path; } - public function getFile(string $key) : string { + public function get_file(string $key) : string { $key = hash('sha256', $key); return $this->path.DIRECTORY_SEPARATOR."$key.json"; } public function get(string $key, int|bool|string|array|float|null $default = null) : mixed { - $file = $this->getFile($key); + $file = $this->get_file($key); if(!file_exists($file)) return $default; $buffer = json_decode(file_get_contents($file), true); if(!isset($buffer['expire']) || !isset($buffer['type'])) return $default; @@ -44,7 +42,7 @@ public function get(string $key, int|bool|string|array|float|null $default = nul } public function set(string $key, int|bool|string|array|float|null $value, int $expire = -1) : void { - $file = $this->getFile($key); + $file = $this->get_file($key); if($expire > 0) $expire = time() + $expire; $type = strtolower(gettype($value)); switch($type){ @@ -75,10 +73,10 @@ public function set(string $key, int|bool|string|array|float|null $value, int $e } public function forget(string $key) : void { - $this->delete($this->getFile($key)); + $this->delete($this->get_file($key)); } - public function clearExpired() : void { + public function clear_expired() : void { $files = scandir($this->path); foreach($files as $file){ $buffer = json_decode(file_get_contents($this->path.DIRECTORY_SEPARATOR.$file), true); diff --git a/includes/avecore/BinaryFile.php b/includes/avecore/BinaryFile.php new file mode 100644 index 0000000..c8fe892 --- /dev/null +++ b/includes/avecore/BinaryFile.php @@ -0,0 +1,71 @@ +path = $path; + if(!is_null($path)) $this->open($path, $allocate); + } + + public function create(string $path, ?int $allocate = null) : bool { + if(file_exists($path)) return false; + $folder = pathinfo($path, PATHINFO_DIRNAME); + if(!file_exists($folder) && !@mkdir($folder, 0755, true)) return false; + $file = @fopen($path, "wb"); + if(!$file) return false; + if(!is_null($allocate) && $allocate > 0){ + fseek($file, $allocate - 1); + fwrite($file, "\0"); + } else { + fwrite($file, ""); + } + fclose($file); + return file_exists($path); + } + + public function open(string $path, ?int $allocate = null) : bool { + if(!is_null($this->file)) return false; + if(!file_exists($path) && !$this->create($path, $allocate)) return false; + $this->file = fopen($path, "r+b"); + if(!$this->file) return false; + $this->path = $path; + return true; + } + + public function close() : bool { + if(is_null($this->file)) return false; + fclose($this->file); + $this->file = null; + $this->path = null; + return true; + } + + public function read(int $offset = 0, ?int $length = null) : string|false { + if(is_null($this->file)) return false; + fseek($this->file, $offset); + if(is_null($length)) $length = filesize($this->path) - $offset; + if($length <= 0) return ""; + return fread($this->file, $length); + } + + public function write(string $data, int $offset = 0, ?int $length = null) : int|false { + if(is_null($this->file)) return false; + fseek($this->file, $offset); + return fwrite($this->file, $data, $length); + } + + public function size() : int|false { + if(is_null($this->file)) return false; + return filesize($this->path); + } + +} + +?> diff --git a/includes/avecore/BitArray.php b/includes/avecore/BitArray.php new file mode 100644 index 0000000..28ffa33 --- /dev/null +++ b/includes/avecore/BitArray.php @@ -0,0 +1,149 @@ +bits = new BitFunctions(); + $this->max_bits = $this->bits->get_max_bits(); + } + + public function get_config_address(int $id) : int { + return (int)floor(intval($id) / $this->max_bits); + } + + public function get_config_bit(int $id) : int { + return (int)intval($id) % $this->max_bits; + } + + public function get_config_size(int $max_items) : int { + return (int)floor(intval($max_items) / $this->max_bits) + 1; + } + + public function get_config_used_size() : int { + $size = 0; + foreach($this->original as $key => $value) $size = max($size, $key); + return (int)($size + 1); + } + + public function get_config(int $id) : bool { + $address = $this->get_config_address($id); + return $this->bits->get_bit_Value($this->original[$address] ?? 0, $this->get_config_bit($id)); + } + + public function set_config(int $id, bool $state) : void { + $address = $this->get_config_address($id); + if(!isset($this->original[$address])) $this->original[$address] = 0; + $this->bits->set_bit_Value($this->original[$address], $this->get_config_bit($id), $state); + } + + public function from_array(array $array) : void { + $this->original = $array; + } + + public function from_assoc(array $assoc, array $keys) : void { + $this->original = []; + foreach($keys as $id => $key){ + $this->set_config($id, ($assoc[$key] ?? false)); + } + } + + public function from_json(string $json) : void { + $this->from_array(json_decode($json, true)); + } + + public function from_binary(string $binary, int $length) : void { + $this->original = []; + $address = 0; + for($offset = 0; $offset < $length; $offset += 4){ + $this->original[$address] = $this->bits->merge_value(ord($binary[$offset] ?? 0), ord($binary[$offset+1] ?? 0), ord($binary[$offset+2] ?? 0), ord($binary[$offset+3] ?? 0)); + $address++; + } + } + + public function from_hex(string $hex) : void { + $this->from_binary(hex2bin($hex), strlen($hex) * 2); + } + + public function from_file(string $path) : bool { + if(!file_exists($path)) return false; + $file = fopen($path, "rb"); + if(!$file) return false; + $length = filesize($path); + $this->from_binary(fread($file, $length), $length); + fclose($file); + return true; + } + + public function to_array() : array { + return $this->original; + } + + public function to_assoc(array $keys) : array { + $data = []; + $id = 0; + $max_address = $this->get_config_used_size(); + for($address = 0; $address < $max_address; $address++){ + for($bitid = 0; $bitid < $this->max_bits; $bitid++){ + if(isset($keys[$id])){ + $data[$keys[$id]] = $this->get_config($id); + } + $id++; + } + } + return $data; + } + + public function to_json() : string { + return json_encode($this->to_array()); + } + + public function to_binary(int &$length = 0) : string { + $data = ''; + $length = 0; + $int1 = 0; + $int2 = 0; + $int3 = 0; + $int4 = 0; + $max_address = $this->get_config_used_size(); + for($address = 0; $address < $max_address; $address++){ + $this->bits->extract_value($this->original[$address] ?? 0, $int1, $int2, $int3, $int4); + $data .= chr($int1); + $data .= chr($int2); + $data .= chr($int3); + $data .= chr($int4); + $length += 4; + } + return $data; + } + + public function to_hex() : string { + return bin2hex($this->to_binary()); + } + + public function to_file(string $path) : bool { + if(file_exists($path)){ + unlink($path); + if(file_exists($path)) return false; + } + $file = fopen($path, "wb"); + if(!$file) return false; + $length = 0; + $data = $this->to_binary($length); + fwrite($file, $data, $length); + fclose($file); + return true; + } + +} + +?> diff --git a/includes/avecore/BitFunctions.php b/includes/avecore/BitFunctions.php new file mode 100644 index 0000000..68a7ad1 --- /dev/null +++ b/includes/avecore/BitFunctions.php @@ -0,0 +1,184 @@ +max_bits = 64; + } else { + $this->max_bits = 32; + } + } + + public function get_max_bits() : int { + return $this->max_bits; + } + + public function get_bit_Value(int $value, int $bitid) : bool { + return (bool)(($value >> $bitid) & 0x01); + } + + public function set_bit_Value(int &$value, int $bitid, bool $state) : void { + $value = (($value & ~(0x01 << $bitid)) | ((0x01 << $bitid)*($state ? 1 : 0))); + } + + public function get_bit(int $bitid) : bool { + return $this->get_bit_Value($this->original, $bitid); + } + + public function set_bit(int $bitid, bool $state) : void { + $this->set_bit_Value($this->original, $bitid, $state); + } + + public function from_int(int $int) : void { + $this->original = $int; + } + + public function from_array(array $array) : void { + $this->original = 0; + for($bitid = 0; $bitid < $this->max_bits; $bitid++){ + $this->set_bit($bitid, ($array[$bitid] ?? false)); + } + } + + public function from_assoc(array $assoc, array $keys) : void { + $this->original = 0; + foreach($keys as $bitid => $key){ + $this->set_bit($bitid, ($assoc[$key] ?? false)); + } + } + + public function from_string(string $string) : void { + $this->original = bindec($string); + } + + public function from_json(string $json) : void { + $this->from_array(json_decode($json, true)); + } + + public function to_int() : int { + return $this->original; + } + + public function to_array() : array { + $data = []; + for($bitid = 0; $bitid < $this->max_bits; $bitid++){ + $data[$bitid] = $this->get_bit($bitid); + } + return $data; + } + + public function to_assoc(array $keys) : array { + $data = []; + for($bitid = 0; $bitid < $this->max_bits; $bitid++){ + if(isset($keys[$bitid])) $data[$keys[$bitid]] = $this->get_bit($bitid); + } + return $data; + } + + public function to_string(bool $full_string = false) : string { + $string = ''; + for($bitid = 0; $bitid < $this->max_bits; $bitid++){ + $string .= $this->get_bit($bitid) ? '1' : '0'; + } + $string = strrev($string); + if(!$full_string){ + $pos = strpos($string, "1", 0); + if($pos === false){ + return "0"; + } else { + return substr($string, $pos); + } + } + return $string; + } + + public function to_json() : string { + return json_encode($this->to_array()); + } + + public function invert(bool $full_string = false) : void { + $this->from_string(str_replace("X", "0", str_replace("0", "1", str_replace("1", "X", $this->to_string($full_string))))); + } + + public function invert_full() : void { + if($this->max_bits == 64){ + $this->original ^= 0x7FFFFFFFFFFFFFFF; + } else { + $this->original ^= 0xFFFFFFFF; + } + $this->set_bit($this->max_bits - 1, !$this->get_bit($this->max_bits - 1)); + } + + public function compare_value(int $value, int $mask) : bool { + return ($value & $mask) == $mask; + } + + public function compare(int $mask) : bool { + return $this->compare_value($this->original, $mask); + } + + public function extract_value(int $value, ?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4) : void { + $int1 = (int)($value >> 24) & 0xFF; + $int2 = (int)($value >> 16) & 0xFF; + $int3 = (int)($value >> 8) & 0xFF; + $int4 = (int)($value) & 0xFF; + } + + public function merge_value(int $int1, int $int2, int $int3, int $int4) : int { + return (int)((($int1 & 0xFF) << 24) | (($int2 & 0xFF) << 16) | (($int3 & 0xFF) << 8) | ($int4 & 0xFF)); + } + + public function extract_value_64(int $value, ?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4, ?int &$int5, ?int &$int6, ?int &$int7, ?int &$int8) : void { + $int1 = (int)($value >> 56) & 0xFF; + $int2 = (int)($value >> 48) & 0xFF; + $int3 = (int)($value >> 40) & 0xFF; + $int4 = (int)($value >> 32) & 0xFF; + $int5 = (int)($value >> 24) & 0xFF; + $int6 = (int)($value >> 16) & 0xFF; + $int7 = (int)($value >> 8) & 0xFF; + $int8 = (int)($value) & 0xFF; + } + + public function merge_value_64(int $int1, int $int2, int $int3, int $int4, int $int5, int $int6, int $int7, int $int8) : int { + return ((($int1 & 0xFF) << 56) | (($int2 & 0xFF) << 48) | (($int3 & 0xFF) << 40) | (($int4 & 0xFF) << 32) | (($int5 & 0xFF) << 24) | (($int6 & 0xFF) << 16) | (($int7 & 0xFF) << 8) | ($int8 & 0xFF)); + } + + public function extract(?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4) : void { + $this->extract_value($this->original, $int1, $int2, $int3, $int4); + } + + public function merge(int $int1, int $int2, int $int3, int $int4) : void { + $this->original = $this->merge_value($int1, $int2, $int3, $int4); + } + + public function extract_64(?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4, ?int &$int5, ?int &$int6, ?int &$int7, ?int &$int8) : void { + $this->extract_value_64($this->original, $int1, $int2, $int3, $int4, $int5, $int6, $int7, $int8); + } + + public function merge_64(int $int1, int $int2, int $int3, int $int4, int $int5, int $int6, int $int7, int $int8) : void { + $this->original = $this->merge_value_64($int1, $int2, $int3, $int4, $int5, $int6, $int7, $int8); + } + + public function bin64_to_float(int $value) : float { + $sign = ($value >> 63) & 0x1; + $exponent = ($value >> 52) & 0x7FF; + $fraction = ($value & 0xFFFFFFFFFFFFF); + $this->max_bits = 64; + $this->from_int($fraction); + $e = 1.0; + for($i = 1; $i <= 52; $i++) $e += ($this->get_bit(52-$i) ? 1 : 0) * pow(2.0, -$i); + return pow(-1.0, $sign) * ($e) * pow(2.0, ($exponent-1023)); + } + +} + +?> diff --git a/includes/services/AveCore.php b/includes/avecore/Core.php similarity index 97% rename from includes/services/AveCore.php rename to includes/avecore/Core.php index 3fd73dc..318f645 100644 --- a/includes/services/AveCore.php +++ b/includes/avecore/Core.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Services; +namespace AveCore; use IntlTimeZone; use RecursiveIteratorIterator; @@ -10,9 +10,9 @@ use FilesystemIterator; use DirectoryIterator; -class AveCore { +class Core { - public int $core_version = 8; + public int $core_version = 9; public IniFile $config; @@ -122,7 +122,7 @@ public function setup_folders(array $folders) : void { } public function set_folder_done(string $folder) : void { - $this->folders_state[$folder] = '[DONE]'; + $this->folders_state[$folder] = file_exists($folder) ? '[DONE]' : '[NOT EXISTS]'; $this->print_folders_state(); } @@ -263,14 +263,14 @@ public function filter(string $search, array $filters) : bool { return false; } - public function get_folders(string $path) : array { + public function get_folders(string $path, bool $with_parrent = false) : array { if(!file_exists($path)) return []; $data = []; $files = new DirectoryIterator($path); - array_push($data, $path); + if($with_parrent) array_push($data, $path); foreach($files as $file){ if($file->isDir() && !$file->isDot()){ - $data = array_merge($data, $this->get_folders($file->getRealPath())); + $data = array_merge($data, $this->get_folders($file->getRealPath(), true)); } } return $data; @@ -317,14 +317,14 @@ public function open_logs(bool $open_event = false, bool $init = true) : void { $this->log_event->close(); $this->log_error->close(); $this->log_data->close(); - if($this->config->get('AVE_OPEN_LOG_EVENT', true) && $open_event && file_exists($this->log_event->getPath())){ - $this->open_file($this->log_event->getPath()); + if($this->config->get('AVE_OPEN_LOG_EVENT', true) && $open_event && file_exists($this->log_event->get_path())){ + $this->open_file($this->log_event->get_path()); } - if(file_exists($this->log_data->getPath())){ - $this->open_file($this->log_data->getPath()); + if(file_exists($this->log_data->get_path())){ + $this->open_file($this->log_data->get_path()); } - if(file_exists($this->log_error->getPath())){ - $this->open_file($this->log_error->getPath()); + if(file_exists($this->log_error->get_path())){ + $this->open_file($this->log_error->get_path()); } if($init) $this->init_logs(); } @@ -391,7 +391,7 @@ public function delete(string $path, bool $log = true) : bool { if($log) $this->write_log("DELETE \"$path\""); return true; } else { - if($log) $this->write_error("FAILED UNLINK \"$path\""); + if($log) $this->write_error("FAILED DELETE \"$path\""); return false; } } @@ -770,15 +770,6 @@ public function windows_only() : bool { return false; } - /** - * @deprecated "Use delete instead" - * - * @return $this - */ - public function unlink(...$args) : bool { - return $this->delete(...$args); - } - } ?> diff --git a/includes/services/AveFtp.php b/includes/avecore/FtpService.php similarity index 97% rename from includes/services/AveFtp.php rename to includes/avecore/FtpService.php index e5356b5..150c33b 100644 --- a/includes/services/AveFtp.php +++ b/includes/avecore/FtpService.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace App\Services; +namespace AveCore; use FtpClient\FtpClient; -class AveFtp { +class FtpService { private FtpClient $ftp; @@ -85,7 +85,7 @@ public function get_folders(string $path) : array { return $data; } - public function hasFiles(string $path) : bool { + public function has_files(string $path) : bool { $files = $this->ftp->rawlist($path); foreach($files as $file){ $chunks = preg_split("/\s+/", $file); diff --git a/includes/services/IniFile.php b/includes/avecore/IniFile.php similarity index 70% rename from includes/services/IniFile.php rename to includes/avecore/IniFile.php index 2a898ea..a7e38d5 100644 --- a/includes/services/IniFile.php +++ b/includes/avecore/IniFile.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Services; +namespace AveCore; use Exception; @@ -14,14 +14,19 @@ class IniFile { protected bool $sort; protected array $original; protected bool $compressed; - public int $version = 20500; + protected ?object $encoder = null; - function __construct(?string $path = null, bool $sort = false, bool $compressed = false){ + function __construct(?string $path = null, bool $sort = false, bool $compressed = false, ?object $encoder = null){ $this->path = $path; $this->data = []; $this->original = []; $this->sort = $sort; $this->compressed = $compressed; + if(!is_null($encoder)){ + if(method_exists($encoder, 'encrypt') && method_exists($encoder, 'decrypt') && method_exists($encoder, 'get_header')){ + $this->encoder = $encoder; + } + } if(is_null($this->path)){ $this->valid = false; } else { @@ -63,18 +68,27 @@ public function read() : bool { if(!$file) return false; $this->data = []; $content = file_get_contents($this->path); - if(substr($content, 0, 11) == 'ADM_GZ_INI:'){ - $content = str_replace(["\r\n", "\r"], "\n", gzuncompress(substr($content, 11))); - $lines = explode("\n", $content); - foreach($lines as $line){ - if($this->parse_line($line, $key, $data)){ - $this->data[$key] = $data; + if(strlen($content) > 0){ + if(!is_null($this->encoder)){ + $header_length = strlen($this->encoder->get_header()); + if(substr($content, 0, $header_length) == $this->encoder->get_header()){ + $content = $this->encoder->decrypt(substr($content, $header_length)); + if(is_null($content)) return false; } } - } else { - while(($line = fgets($file)) !== false){ - if($this->parse_line($line, $key, $data)){ - $this->data[$key] = $data; + if(substr($content, 0, 11) == 'ADM_GZ_INI:'){ + $content = str_replace(["\r\n", "\r"], "\n", gzuncompress(substr($content, 11))); + $lines = explode("\n", $content); + foreach($lines as $line){ + if($this->parse_line($line, $key, $data)){ + $this->data[$key] = $data; + } + } + } else { + while(($line = fgets($file)) !== false){ + if($this->parse_line($line, $key, $data)){ + $this->data[$key] = $data; + } } } } @@ -119,13 +133,13 @@ public function parse_line(string $line, &$key, int|bool|string|array|float|null return true; } - public function isChanged() : bool { - return (json_encode($this->getOriginalAll()) != json_encode($this->getAll())); + public function is_changed() : bool { + return (json_encode($this->get_original_all()) != json_encode($this->get_all())); } - public function isValueChanged(string $key) : bool { + public function is_value_changed(string $key) : bool { $value = $this->get($key); - $original = $this->getOriginal($key); + $original = $this->get_original($key); if(gettype($value) != gettype($original)) return false; if(gettype($value) == 'array'){ return json_encode($value) != json_encode($original); @@ -134,15 +148,15 @@ public function isValueChanged(string $key) : bool { } } - public function getOriginalAll() : array { + public function get_original_all() : array { return $this->original; } - public function getAll() : array { + public function get_all() : array { return $this->data; } - public function getSorted() : array { + public function get_sorted() : array { $data = $this->data; ksort($data); return $data; @@ -152,7 +166,7 @@ public function sort() : void { ksort($this->data); } - public function setAll(array $data, bool $save = false) : void { + public function set_all(array $data, bool $save = false) : void { $this->data = $data; if($save) $this->save(); } @@ -168,19 +182,19 @@ public function get(string $key, int|bool|string|array|float|null $default = nul return $this->data[$key] ?? $default; } - public function getString(string $key, int|bool|string|array|float|null $default = null) : string { + public function get_string(string $key, int|bool|string|array|float|null $default = null) : string { return strval($this->data[$key] ?? $default); } - public function getOriginal(string $key, int|bool|string|array|float|null $default = null) : mixed { + public function get_original(string $key, int|bool|string|array|float|null $default = null) : mixed { return $this->original[$key] ?? $default; } public function set(string $key, int|bool|string|array|float|null $value) : void { - $this->data[$key] = $this->cleanValue($value); + $this->data[$key] = $this->clean_value($value); } - public function cleanValue(int|bool|string|array|float|null $value) : mixed { + public function clean_value(int|bool|string|array|float|null $value) : mixed { if(gettype($value) == 'string'){ if(strtolower($value) == 'true'){ return true; @@ -199,7 +213,7 @@ public function rename(string $key1, string $key2) : void { public function unset(string|array $keys) : void { if(gettype($keys) == 'string') $keys = [$keys]; foreach($keys as $key){ - if($this->isSet($key)){ + if($this->is_set($key)){ unset($this->data[$key]); } } @@ -208,14 +222,14 @@ public function unset(string|array $keys) : void { public function reset(string|array $keys, int|bool|string|array|float|null $value = null) : void { if(gettype($keys) == 'string') $keys = [$keys]; foreach($keys as $key){ - if($this->isSet($key)){ + if($this->is_set($key)){ $this->set($key, $value); } } } public function save() : bool { - if(!$this->isValid()) return false; + if(!$this->is_valid()) return false; if($this->sort) ksort($this->data); $content = "\xEF\xBB\xBF"; foreach($this->data as $key => $value){ @@ -237,6 +251,11 @@ public function save() : bool { } try { if($this->compressed) $content = "ADM_GZ_INI:".gzcompress($content, 9); + if(!is_null($this->encoder)){ + $content = $this->encoder->encrypt($content); + if(is_null($content)) return false; + $content = $this->encoder->get_header().$content; + } file_put_contents($this->path, $content); } catch(Exception $e){ @@ -245,11 +264,11 @@ public function save() : bool { return true; } - public function isValid() : bool { + public function is_valid() : bool { return $this->valid; } - public function toggleSort(bool $sort) : void { + public function toggle_sort(bool $sort) : void { $this->sort = $sort; } @@ -257,35 +276,35 @@ public function keys() : array { return array_keys($this->data); } - public function isSet(string $key) : bool { + public function is_set(string $key) : bool { return array_key_exists($key, $this->data); } - public function getSize() : int { - if(!$this->isValid()) return 0; + public function get_size() : int { + if(!$this->is_valid()) return 0; $size = filesize($this->path); if(!$size) return 0; return $size; } - public function getModificationDate() : string { - if(!$this->isValid()) return '0000-00-00 00:00:00'; + public function get_modification_date() : string { + if(!$this->is_valid()) return '0000-00-00 00:00:00'; return date("Y-m-d H:i:s", filemtime($this->path)); } - public function toJson() : string|false { + public function to_json() : string|false { return json_encode($this->data); } - public function fromJson(string $json, bool $merge = false, bool $save = false) : void { + public function from_json(string $json, bool $merge = false, bool $save = false) : void { if($merge){ $this->update(json_decode($json, true), $save); } else { - $this->setAll(json_decode($json, true), $save); + $this->set_all(json_decode($json, true), $save); } } - public function fromAssoc(array $assoc, bool $merge = false, bool $save = false) : void { + public function from_assoc(array $assoc, bool $merge = false, bool $save = false) : void { if(!$merge) $this->data = []; foreach($assoc as $key => $value){ $this->set($key, $value); @@ -304,7 +323,7 @@ public function search(string $search) : array { return $results; } - public function searchPrefix(string $search) : array { + public function search_prefix(string $search) : array { $results = []; $keys = $this->keys(); foreach($keys as $key){ @@ -315,7 +334,7 @@ public function searchPrefix(string $search) : array { return $results; } - public function searchSuffix(string $search) : array { + public function search_suffix(string $search) : array { $results = []; $keys = $this->keys(); foreach($keys as $key){ @@ -326,8 +345,8 @@ public function searchSuffix(string $search) : array { return $results; } - public function setChanged(string $key, int|bool|string|array|float|null $value, int|bool|string|array|float|null $default = null) : void { - if($this->cleanValue($value) != $default){ + public function set_changed(string $key, int|bool|string|array|float|null $value, int|bool|string|array|float|null $default = null) : void { + if($this->clean_value($value) != $default){ $this->set($key, $value); } else { $this->unset($key); @@ -343,7 +362,7 @@ public function only(string|array $keys) : array { return $data; } - public function allExcept(string|array $keys) : array { + public function all_except(string|array $keys) : array { if(gettype($keys) == 'string') $keys = [$keys]; $data = []; foreach($this->keys() as $key){ diff --git a/includes/services/JournalService.php b/includes/avecore/JournalService.php similarity index 80% rename from includes/services/JournalService.php rename to includes/avecore/JournalService.php index 8bac1ff..4c08bec 100644 --- a/includes/services/JournalService.php +++ b/includes/avecore/JournalService.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Services; +namespace AveCore; class JournalService { @@ -30,7 +30,7 @@ protected function length(string $data) : int { return strlen(bin2hex($data)) / 2; } - protected function writeString(string $line) : bool { + protected function write_string(string $line) : bool { $fp = fopen($this->path, "a"); if(!$fp) return false; $int1 = 0; @@ -39,13 +39,13 @@ protected function writeString(string $line) : bool { $int4 = 0; $raw = gzcompress($line, 9); $length = $this->length($raw); - $this->bits->extractValue($length, $int1, $int2, $int3, $int4); + $this->bits->extract_value($length, $int1, $int2, $int3, $int4); fwrite($fp, chr($int1).chr($int2).chr($int3).chr($int4).$raw); fclose($fp); return true; } - protected function writeArray(array $lines) : bool { + protected function write_array(array $lines) : bool { $fp = fopen($this->path, "a"); if(!$fp) return false; $int1 = 0; @@ -55,7 +55,7 @@ protected function writeArray(array $lines) : bool { foreach($lines as $line){ $raw = gzcompress($line, 9); $length = $this->length($raw); - $this->bits->extractValue($length, $int1, $int2, $int3, $int4); + $this->bits->extract_value($length, $int1, $int2, $int3, $int4); fwrite($fp, chr($int1).chr($int2).chr($int3).chr($int4).$raw); } fclose($fp); @@ -67,8 +67,8 @@ public function write(string|array $content) : bool { if(!file_exists($this->path)){ if(!$this->create()) return false; } - if(gettype($content) == "array") return $this->writeArray($content); - return $this->writeString($content); + if(gettype($content) == "array") return $this->write_array($content); + return $this->write_string($content); } public function read(bool $json = false) : ?array { @@ -82,7 +82,7 @@ public function read(bool $json = false) : ?array { while(!feof($fp)){ $l = fread($fp, 4); if(!isset($l[0])) break; - $length = $this->bits->mergeValue(ord($l[0]), ord($l[1]), ord($l[2]), ord($l[3])); + $length = $this->bits->merge_value(ord($l[0]), ord($l[1]), ord($l[2]), ord($l[3])); $string = gzuncompress(fread($fp, $length)); if($json) $string = json_decode($string, true); array_push($data, $string); diff --git a/includes/services/Logs.php b/includes/avecore/Logs.php similarity index 82% rename from includes/services/Logs.php rename to includes/avecore/Logs.php index 01eeed6..35155ed 100644 --- a/includes/services/Logs.php +++ b/includes/avecore/Logs.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Services; +namespace AveCore; class Logs { @@ -11,8 +11,6 @@ class Logs { private bool $hold_open; private $file; - public int $version = 10100; - function __construct(string $path, bool $timestamp = true, bool $hold_open = false){ $this->path = $path; $this->timestamp = $timestamp; @@ -30,7 +28,7 @@ protected function create() : bool { return file_exists($this->path); } - protected function writeString(string $line) : bool { + protected function write_string(string $line) : bool { if(!$this->file) $this->file = fopen($this->path, "a"); if(!$this->file) return false; if($this->timestamp) fwrite($this->file, "[".date("Y-m-d H:i:s")."] "); @@ -39,7 +37,7 @@ protected function writeString(string $line) : bool { return true; } - protected function writeArray(array $lines) : bool { + protected function write_array(array $lines) : bool { if(!$this->file) $this->file = fopen($this->path, "a"); if(!$this->file) return false; foreach($lines as $line){ @@ -55,11 +53,11 @@ public function write(string|array $content) : bool { if(!file_exists($this->path)){ if(!$this->create()) return false; } - if(gettype($content) == "array") return $this->writeArray($content); - return $this->writeString($content); + if(gettype($content) == "array") return $this->write_array($content); + return $this->write_string($content); } - public function getPath() : string { + public function get_path() : string { return $this->path; } diff --git a/includes/services/DataBase.php b/includes/avecore/MySQL.php similarity index 87% rename from includes/services/DataBase.php rename to includes/avecore/MySQL.php index ea7b207..5d382aa 100644 --- a/includes/services/DataBase.php +++ b/includes/avecore/MySQL.php @@ -2,20 +2,20 @@ declare(strict_types=1); -namespace App\Services; +namespace AveCore; use PDO; use PDOException; use PDOStatement; -class DataBase { +class MySQL { public ?PDO $db; function __construct(){ } - + public function connect(string $host, string $user, string $password, string $dbname, int $port = 3306) : bool { $options = [ PDO::ATTR_EMULATE_PREPARES => true, @@ -37,11 +37,11 @@ public function disconnect() : void { $this->db = null; } - public function getConnection() : ?PDO { + public function get_connection() : ?PDO { return $this->db; } - public function getDataBase() : ?string { + public function get_data_base() : ?string { $sth = $this->query("SELECT DATABASE() as `name`;"); $result = $sth->fetch(PDO::FETCH_OBJ); return $result->name ?? null; @@ -57,7 +57,7 @@ public function query(string $query, ?int $fetchMode = null) : PDOStatement|fals return $this->db->query($query, $fetchMode); } - public function resultsToString(array $results, string $separator = '|') : string { + public function results_to_string(array $results, string $separator = '|') : string { $data = " ".implode($separator, array_keys($results[0]))."\r\n"; foreach($results as $result){ $data .= " ".implode($separator, $result)."\r\n"; diff --git a/includes/avecore/Request.php b/includes/avecore/Request.php new file mode 100644 index 0000000..805b9ec --- /dev/null +++ b/includes/avecore/Request.php @@ -0,0 +1,130 @@ +json = $json; + $this->cookies = false; + $this->cookie_file = 'AVE-COOKIE.txt'; + $this->header = $header; + if(is_null($options)){ + $this->options = [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 120, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_USERAGENT => 'AVE-PHP', + ]; + } else { + $this->options = $options; + } + } + + public function toggle_cookie(bool $toggle, string $file = 'AVE-COOKIE.txt') : void { + $this->cookies = $toggle; + $this->cookie_file = $file; + } + + public function get_cookie_file() : string { + return $this->cookie_file; + } + + public function set_header(array $header) : void { + $this->header = $header; + } + + public function set_options(array $options) : void { + $this->options = $options; + } + + public function set_option(int $option, mixed $value) : void { + $this->options[$option] = $value; + } + + public function get(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'GET', $data, $follow); + } + + public function head(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'HEAD', $data, $follow); + } + + public function post(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'POST', $data, $follow); + } + + public function put(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'PUT', $data, $follow); + } + + public function delete(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'DELETE', $data, $follow); + } + + public function connect(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'CONNECT', $data, $follow); + } + + public function options(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'OPTIONS', $data, $follow); + } + + public function trace(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'TRACE', $data, $follow); + } + + public function patch(string $url, array $data = [], bool $follow = false) : array { + return $this->request($url, 'PATCH', $data, $follow); + } + + private function request(string $url, string $method, array $data, bool $follow) : array { + $options = $this->options; + $options[CURLOPT_FOLLOWLOCATION] = $follow; + $options[CURLOPT_CUSTOMREQUEST] = $method; + if(!empty($data)){ + if($method == 'POST'){ + $options[CURLOPT_POSTFIELDS] = $this->json ? json_encode($data) : urldecode(http_build_query($data)); + } else { + $params = "?".urldecode(http_build_query($data)); + } + } + $curl = curl_init($url.($params ?? '')); + $options[CURLOPT_HTTPHEADER] = $this->header; + if($this->json){ + array_push($options[CURLOPT_HTTPHEADER], 'Content-Type: application/json'); + } + if($this->cookies){ + $options[CURLOPT_COOKIEFILE] = $this->cookie_file; + $options[CURLOPT_COOKIEJAR] = $this->cookie_file; + } + curl_setopt_array($curl, $options); + $response = curl_exec($curl); + curl_close($curl); + if(!$response){ + return [ + 'code' => curl_getinfo($curl, CURLINFO_HTTP_CODE), + 'data' => [] + ]; + } + return [ + 'code' => curl_getinfo($curl, CURLINFO_HTTP_CODE), + 'data' => $this->json ? json_decode($response, true) : $response + ]; + } + +} + +?> diff --git a/includes/main.php b/includes/main.php index 5830bee..7258d48 100644 --- a/includes/main.php +++ b/includes/main.php @@ -14,35 +14,41 @@ require __DIR__.'/../vendor/autoload.php'; $includes_path = __DIR__; - require_once("$includes_path/services/Logs.php"); - require_once("$includes_path/services/IniFile.php"); - require_once("$includes_path/services/AveCore.php"); + + require_once("$includes_path/avecore/Logs.php"); + require_once("$includes_path/avecore/IniFile.php"); + require_once("$includes_path/avecore/Core.php"); + require_once("$includes_path/avecore/MySQL.php"); + require_once("$includes_path/avecore/Request.php"); + require_once("$includes_path/avecore/FtpService.php"); + require_once("$includes_path/avecore/BitFunctions.php"); + require_once("$includes_path/avecore/BitArray.php"); + require_once("$includes_path/avecore/JournalService.php"); + require_once("$includes_path/avecore/AppBuffer.php"); + require_once("$includes_path/avecore/BinaryFile.php"); + require_once("$includes_path/services/GuardPattern.php"); require_once("$includes_path/services/GuardDriver.php"); require_once("$includes_path/services/FaceDetector.php"); - require_once("$includes_path/services/DataBase.php"); require_once("$includes_path/services/DataBaseBackup.php"); - require_once("$includes_path/services/Request.php"); require_once("$includes_path/services/MediaFunctions.php"); require_once("$includes_path/services/StringConverter.php"); - require_once("$includes_path/services/AveFtp.php"); - require_once("$includes_path/services/BitFunctions.php"); - require_once("$includes_path/services/BitArray.php"); - require_once("$includes_path/services/JournalService.php"); - require_once("$includes_path/services/AppBuffer.php"); + require_once("$includes_path/AVE.php"); - require_once("$includes_path/tools/AveSettings.php"); + + require_once("$includes_path/tools/AdmFileConverter.php"); require_once("$includes_path/tools/AveConsole.php"); - require_once("$includes_path/tools/FileNamesEditor.php"); + require_once("$includes_path/tools/AveSettings.php"); + require_once("$includes_path/tools/CheckFileIntegrity.php"); + require_once("$includes_path/tools/DirectoryFunctions.php"); + require_once("$includes_path/tools/DirectoryNamesEditor.php"); + require_once("$includes_path/tools/FileEditor.php"); require_once("$includes_path/tools/FileFunctions.php"); + require_once("$includes_path/tools/FileNamesEditor.php"); + require_once("$includes_path/tools/FtpTools.php"); require_once("$includes_path/tools/MediaSorter.php"); - require_once("$includes_path/tools/DirectoryFunctions.php"); require_once("$includes_path/tools/MediaTools.php"); - require_once("$includes_path/tools/CheckFileIntegrity.php"); require_once("$includes_path/tools/MySQLTools.php"); - require_once("$includes_path/tools/FileEditor.php"); - require_once("$includes_path/tools/FtpTools.php"); - require_once("$includes_path/tools/AdmFileConverter.php"); $ave = new AVE($argv); if(!$ave->abort) $ave->execute(); diff --git a/includes/services/BitArray.php b/includes/services/BitArray.php deleted file mode 100644 index 5ab2a58..0000000 --- a/includes/services/BitArray.php +++ /dev/null @@ -1,149 +0,0 @@ -bits = new BitFunctions(); - $this->max_bits = $this->bits->getMaxBits(); - } - - public function getConfigAddress(int $id) : int { - return (int)floor(intval($id) / $this->max_bits); - } - - public function getConfigBit(int $id) : int { - return (int)intval($id) % $this->max_bits; - } - - public function getConfigSize(int $max_items) : int { - return (int)floor(intval($max_items) / $this->max_bits) + 1; - } - - public function getConfigUsedSize() : int { - $size = 0; - foreach($this->original as $key => $value) $size = max($size,$key); - return (int)($size + 1); - } - - public function getConfig(int $id) : bool { - $address = $this->getConfigAddress($id); - return $this->bits->getBitValue($this->original[$address] ?? 0, $this->getConfigBit($id)); - } - - public function setConfig(int $id, bool $state) : void { - $address = $this->getConfigAddress($id); - if(!isset($this->original[$address])) $this->original[$address] = 0; - $this->bits->setBitValue($this->original[$address], $this->getConfigBit($id), $state); - } - - public function fromArray(array $array) : void { - $this->original = $array; - } - - public function fromAssoc(array $assoc, array $keys) : void { - $this->original = []; - foreach($keys as $id => $key){ - $this->setConfig($id,($assoc[$key] ?? false)); - } - } - - public function fromJson(string $json) : void { - $this->fromArray(json_decode($json,true)); - } - - public function fromBinary(string $binary, int $length) : void { - $this->original = []; - $address = 0; - for($offset = 0; $offset < $length; $offset += 4){ - $this->original[$address] = $this->bits->mergeValue(ord($binary[$offset] ?? 0),ord($binary[$offset+1] ?? 0),ord($binary[$offset+2] ?? 0),ord($binary[$offset+3] ?? 0)); - $address++; - } - } - - public function fromHex(string $hex) : void { - $this->fromBinary(hex2bin($hex), strlen($hex) * 2); - } - - public function fromFile(string $path) : bool { - if(!file_exists($path)) return false; - $file = fopen($path,"rb"); - if(!$file) return false; - $length = filesize($path); - $this->fromBinary(fread($file,$length),$length); - fclose($file); - return true; - } - - public function toArray() : array { - return $this->original; - } - - public function toAssoc(array $keys) : array { - $data = []; - $id = 0; - $max_address = $this->getConfigUsedSize(); - for($address = 0; $address < $max_address; $address++){ - for($bitid = 0; $bitid < $this->max_bits; $bitid++){ - if(isset($keys[$id])){ - $data[$keys[$id]] = $this->getConfig($id); - } - $id++; - } - } - return $data; - } - - public function toJson() : string { - return json_encode($this->toArray()); - } - - public function toBinary(int &$length = 0) : string { - $data = ''; - $length = 0; - $int1 = 0; - $int2 = 0; - $int3 = 0; - $int4 = 0; - $max_address = $this->getConfigUsedSize(); - for($address = 0; $address < $max_address; $address++){ - $this->bits->extractValue($this->original[$address] ?? 0, $int1, $int2, $int3, $int4); - $data .= chr($int1); - $data .= chr($int2); - $data .= chr($int3); - $data .= chr($int4); - $length += 4; - } - return $data; - } - - public function toHex() : string { - return bin2hex($this->toBinary()); - } - - public function toFile(string $path) : bool { - if(file_exists($path)){ - unlink($path); - if(file_exists($path)) return false; - } - $file = fopen($path,"wb"); - if(!$file) return false; - $length = 0; - $data = $this->toBinary($length); - fwrite($file,$data,$length); - fclose($file); - return true; - } - -} - -?> diff --git a/includes/services/BitFunctions.php b/includes/services/BitFunctions.php deleted file mode 100644 index 5f7436b..0000000 --- a/includes/services/BitFunctions.php +++ /dev/null @@ -1,184 +0,0 @@ -max_bits = 64; - } else { - $this->max_bits = 32; - } - } - - public function getMaxBits() : int { - return $this->max_bits; - } - - public function getBitValue(int $value, int $bitid) : bool { - return (bool)(($value >> $bitid) & 0x01); - } - - public function setBitValue(int &$value, int $bitid, bool $state) : void { - $value = (($value & ~(0x01 << $bitid)) | ((0x01 << $bitid)*($state ? 1 : 0))); - } - - public function getBit(int $bitid) : bool { - return $this->getBitValue($this->original, $bitid); - } - - public function setBit(int $bitid, bool $state) : void { - $this->setBitValue($this->original, $bitid, $state); - } - - public function fromInt(int $int) : void { - $this->original = $int; - } - - public function fromArray(array $array) : void { - $this->original = 0; - for($bitid = 0; $bitid < $this->max_bits; $bitid++){ - $this->setBit($bitid, ($array[$bitid] ?? false)); - } - } - - public function fromAssoc(array $assoc, array $keys) : void { - $this->original = 0; - foreach($keys as $bitid => $key){ - $this->setBit($bitid, ($assoc[$key] ?? false)); - } - } - - public function fromString(string $string) : void { - $this->original = bindec($string); - } - - public function fromJson(string $json) : void { - $this->fromArray(json_decode($json, true)); - } - - public function toInt() : int { - return $this->original; - } - - public function toArray() : array { - $data = []; - for($bitid = 0; $bitid < $this->max_bits; $bitid++){ - $data[$bitid] = $this->getBit($bitid); - } - return $data; - } - - public function toAssoc(array $keys) : array { - $data = []; - for($bitid = 0; $bitid < $this->max_bits; $bitid++){ - if(isset($keys[$bitid])) $data[$keys[$bitid]] = $this->getBit($bitid); - } - return $data; - } - - public function toString(bool $full_string = false) : string { - $string = ''; - for($bitid = 0; $bitid < $this->max_bits; $bitid++){ - $string .= $this->getBit($bitid) ? '1' : '0'; - } - $string = strrev($string); - if(!$full_string){ - $pos = strpos($string, "1", 0); - if($pos === false){ - return "0"; - } else { - return substr($string, $pos); - } - } - return $string; - } - - public function toJson() : string { - return json_encode($this->toArray()); - } - - public function invert(bool $full_string = false) : void { - $this->fromString(str_replace("X", "0", str_replace("0", "1", str_replace("1", "X", $this->toString($full_string))))); - } - - public function invertFull() : void { - if($this->max_bits == 64){ - $this->original ^= 0x7FFFFFFFFFFFFFFF; - } else { - $this->original ^= 0xFFFFFFFF; - } - $this->setBit($this->max_bits - 1, !$this->getBit($this->max_bits - 1)); - } - - public function compareValue(int $value, int $mask) : bool { - return ($value & $mask) == $mask; - } - - public function compare(int $mask) : bool { - return $this->compareValue($this->original, $mask); - } - - public function extractValue(int $value, ?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4) : void { - $int1 = (int)($value >> 24) & 0xFF; - $int2 = (int)($value >> 16) & 0xFF; - $int3 = (int)($value >> 8) & 0xFF; - $int4 = (int)($value) & 0xFF; - } - - public function mergeValue(int $int1, int $int2, int $int3, int $int4) : int { - return (int)((($int1 & 0xFF) << 24) | (($int2 & 0xFF) << 16) | (($int3 & 0xFF) << 8) | ($int4 & 0xFF)); - } - - public function extractValue64(int $value, ?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4, ?int &$int5, ?int &$int6, ?int &$int7, ?int &$int8) : void { - $int1 = (int)($value >> 56) & 0xFF; - $int2 = (int)($value >> 48) & 0xFF; - $int3 = (int)($value >> 40) & 0xFF; - $int4 = (int)($value >> 32) & 0xFF; - $int5 = (int)($value >> 24) & 0xFF; - $int6 = (int)($value >> 16) & 0xFF; - $int7 = (int)($value >> 8) & 0xFF; - $int8 = (int)($value) & 0xFF; - } - - public function mergeValue64(int $int1, int $int2, int $int3, int $int4, int $int5, int $int6, int $int7, int $int8) : int { - return ((($int1 & 0xFF) << 56) | (($int2 & 0xFF) << 48) | (($int3 & 0xFF) << 40) | (($int4 & 0xFF) << 32) | (($int5 & 0xFF) << 24) | (($int6 & 0xFF) << 16) | (($int7 & 0xFF) << 8) | ($int8 & 0xFF)); - } - - public function extract(?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4) : void { - $this->extractValue($this->original, $int1, $int2, $int3, $int4); - } - - public function merge(int $int1, int $int2, int $int3, int $int4) : void { - $this->original = $this->mergeValue($int1, $int2, $int3, $int4); - } - - public function extract64(?int &$int1, ?int &$int2, ?int &$int3, ?int &$int4, ?int &$int5, ?int &$int6, ?int &$int7, ?int &$int8) : void { - $this->extractValue64($this->original, $int1, $int2, $int3, $int4, $int5, $int6, $int7, $int8); - } - - public function merge64(int $int1, int $int2, int $int3, int $int4, int $int5, int $int6, int $int7, int $int8) : void { - $this->original = $this->mergeValue64($int1, $int2, $int3, $int4, $int5, $int6, $int7, $int8); - } - - public function Bin64ToFloat(int $value) : float { - $sign = ($value >> 63) & 0x1; - $exponent = ($value >> 52) & 0x7FF; - $fraction = ($value & 0xFFFFFFFFFFFFF); - $this->max_bits = 64; - $this->fromInt($fraction); - $e = 1.0; - for($i = 1; $i <= 52; $i++) $e += ($this->getBit(52-$i) ? 1 : 0) * pow(2.0, -$i); - return pow(-1.0, $sign) * ($e) * pow(2.0, ($exponent-1023)); - } - -} - -?> diff --git a/includes/services/DataBaseBackup.php b/includes/services/DataBaseBackup.php index 137dc65..9c9cd6c 100644 --- a/includes/services/DataBaseBackup.php +++ b/includes/services/DataBaseBackup.php @@ -12,7 +12,6 @@ class DataBaseBackup { protected ?PDO $source; protected ?PDO $destination; protected string $database; - private ?string $path; private string $alters; private bool $lock_tables = false; @@ -43,21 +42,21 @@ public function __construct(?string $path = null, int $query_limit = 50000, int $this->alters = ''; } - public function getAlters() : string { + public function get_alters() : string { return $this->alters; } - public function resetAlters() : void { + public function reset_alters() : void { $this->alters = ''; } - public function getOutput(?string $folder = null) : string { + public function get_output(?string $folder = null) : string { $path = $this->path.DIRECTORY_SEPARATOR."{$this->database}_{$this->date}"; if(!is_null($folder)) $path .= DIRECTORY_SEPARATOR.$folder; return $path; } - public function toggleLockTables(bool $toggle) : void { + public function toggle_lock_tables(bool $toggle) : void { $this->lock_tables = $toggle; } @@ -96,11 +95,11 @@ public function connect_destination(string $host, string $user, string $password return true; } - public function getSource() : ?PDO { + public function get_source() : ?PDO { return $this->source; } - public function getDestination() : ?PDO { + public function get_destination() : ?PDO { return $this->destination; } @@ -112,7 +111,7 @@ public function disconnect_destination() : void { $this->destination = null; } - public function setDataBase(string $dbname) : void { + public function set_data_base(string $dbname) : void { $this->database = $dbname; } @@ -122,12 +121,12 @@ public function escape(mixed $string) : string { return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $string); } - public function isDestinationEmpty() : bool { + public function is_destination_empty() : bool { $items = $this->destination->query('SHOW TABLES', PDO::FETCH_OBJ); return $items->rowCount() == 0; } - public function getTables() : array { + public function get_tables() : array { $data = []; $items = $this->source->query("SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'BASE TABLE'", PDO::FETCH_OBJ); foreach($items as $item){ @@ -136,7 +135,7 @@ public function getTables() : array { return $data; } - public function getViews() : array { + public function get_views() : array { $data = []; $items = $this->source->query("SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'", PDO::FETCH_OBJ); foreach($items as $item){ @@ -145,7 +144,7 @@ public function getViews() : array { return $data; } - public function getFunctions() : array { + public function get_functions() : array { $data = []; $items = $this->source->query("SHOW FUNCTION STATUS WHERE `Db` = '$this->database' AND `Type` = 'FUNCTION'", PDO::FETCH_OBJ); foreach($items as $item){ @@ -154,7 +153,7 @@ public function getFunctions() : array { return $data; } - public function getProcedures() : array { + public function get_procedures() : array { $data = []; $items = $this->source->query("SHOW PROCEDURE STATUS WHERE `Db` = '$this->database' AND `Type` = 'PROCEDURE'", PDO::FETCH_OBJ); foreach($items as $item){ @@ -163,7 +162,7 @@ public function getProcedures() : array { return $data; } - public function getEvents() : array { + public function get_events() : array { $data = []; $items = $this->source->query("SHOW EVENTS", PDO::FETCH_OBJ); foreach($items as $item){ @@ -172,7 +171,7 @@ public function getEvents() : array { return $data; } - public function getTriggers() : array { + public function get_triggers() : array { $data = []; $items = $this->source->query("SHOW TRIGGERS", PDO::FETCH_OBJ); foreach($items as $item){ @@ -181,7 +180,7 @@ public function getTriggers() : array { return $data; } - public function getColumns(string $name) : array { + public function get_columns(string $name) : array { $data = []; $columns = $this->source->query("SELECT `COLUMN_NAME`, `DATA_TYPE` FROM INFORMATION_SCHEMA.COLUMNS WHERE `TABLE_SCHEMA` = '$this->database' AND `TABLE_NAME` = '$name'", PDO::FETCH_OBJ); foreach($columns as $column){ @@ -190,7 +189,7 @@ public function getColumns(string $name) : array { return $data; } - public function getTableCreation(string $name) : array { + public function get_table_creation(string $name) : array { $creation = $this->source->query("SHOW CREATE TABLE `$name`", PDO::FETCH_OBJ); $data = $creation->fetch(PDO::FETCH_OBJ); $query = str_replace(["\r\n", "\r"], "\n", $data->{'Create Table'}.';'); @@ -213,69 +212,69 @@ public function getTableCreation(string $name) : array { ]; } - public function getViewCreation(string $name) : string { + public function get_view_creation(string $name) : string { $creation = $this->source->query("SHOW CREATE VIEW `$name`", PDO::FETCH_OBJ); $data = $creation->fetch(PDO::FETCH_OBJ); return $data->{'Create View'}.';'; } - public function getFunctionCreation(string $name) : string { + public function get_function_creation(string $name) : string { $creation = $this->source->query("SHOW CREATE FUNCTION `$name`", PDO::FETCH_OBJ); $data = $creation->fetch(PDO::FETCH_OBJ); return "DELIMITER $$\n".$data->{'Create Function'}."$$\nDELIMITER ;\n"; } - public function getProcedureCreation(string $name) : string { + public function get_procedure_creation(string $name) : string { $creation = $this->source->query("SHOW CREATE PROCEDURE `$name`", PDO::FETCH_OBJ); $data = $creation->fetch(PDO::FETCH_OBJ); return "DELIMITER $$\n".$data->{'Create Procedure'}."$$\nDELIMITER ;\n"; } - public function getEventCreation(string $name) : string { + public function get_event_creation(string $name) : string { $creation = $this->source->query("SHOW CREATE EVENT `$name`", PDO::FETCH_OBJ); $data = $creation->fetch(PDO::FETCH_OBJ); return "DELIMITER $$\n".$data->{'Create Event'}."$$\nDELIMITER ;\n"; } - public function getTriggerCreation(string $name) : string { + public function get_triger_creation(string $name) : string { $creation = $this->source->query("SHOW CREATE TRIGGER `$name`", PDO::FETCH_OBJ); $data = $creation->fetch(PDO::FETCH_OBJ); return "DELIMITER $$\n".$data->{'SQL Original Statement'}."$$\nDELIMITER ;\n"; } - public function getTableDrop(string $name) : string { + public function get_table_drop(string $name) : string { return "DROP TABLE IF EXISTS `$name`;"; } - public function getViewDrop(string $name) : string { + public function get_view_drop(string $name) : string { return "DROP VIEW IF EXISTS `$name`;"; } - public function getFunctionDrop(string $name) : string { + public function get_function_drop(string $name) : string { return "DROP FUNCTION IF EXISTS `$name`;"; } - public function getProcedureDrop(string $name) : string { + public function get_procedure_drop(string $name) : string { return "DROP PROCEDURE IF EXISTS `$name`;"; } - public function getEventDrop(string $name) : string { + public function get_event_drop(string $name) : string { return "DROP EVENT IF EXISTS `$name`;"; } - public function getTriggerDrop(string $name) : string { + public function get_trigger_drop(string $name) : string { return "DROP TRIGGER IF EXISTS `$name`;"; } - public function getHeader() : string { + public function get_header() : string { return $this->header; } - public function getFooter() : string { + public function get_footer() : string { return $this->footer; } - public function getInsert(string $table, array $columns) : string { + public function get_insert(string $table, array $columns) : string { $columns_string = ''; foreach($columns as $column){ $columns_string .= "`$column`,"; @@ -284,19 +283,19 @@ public function getInsert(string $table, array $columns) : string { return "INSERT INTO `$table` ($columns_string)"; } - public function backupTableStructure(string $table) : array { - if(!file_exists($this->getOutput("structure"))) mkdir($this->getOutput("structure"), 0755, true); + public function backup_table_structure(string $table) : array { + if(!file_exists($this->get_output("structure"))) mkdir($this->get_output("structure"), 0755, true); $errors = []; - $file_path = $this->getOutput("structure").DIRECTORY_SEPARATOR."$table.sql"; + $file_path = $this->get_output("structure").DIRECTORY_SEPARATOR."$table.sql"; if(file_exists($file_path)) unlink($file_path); $file = fopen($file_path, "a"); try { - $creation = $this->getTableCreation($table); + $creation = $this->get_table_creation($table); fwrite($file, "-- やあ --\n\n"); - fwrite($file, $this->getHeader()."\n\n"); - fwrite($file, $this->getTableDrop($table)."\n\n"); + fwrite($file, $this->get_header()."\n\n"); + fwrite($file, $this->get_table_drop($table)."\n\n"); fwrite($file, $creation['query']."\n\n"); - fwrite($file, "\n".$this->getFooter()."\n"); + fwrite($file, "\n".$this->get_footer()."\n"); echo " Table structure: `$this->database`.`$table` Progress: 100.00 % \r\n"; } catch(PDOException $e){ @@ -306,8 +305,8 @@ public function backupTableStructure(string $table) : array { } fclose($file); if(!empty($creation['alters'])){ - if(!file_exists($this->getOutput("alters"))) mkdir($this->getOutput("alters"), 0755, true); - $file_path = $this->getOutput("alters").DIRECTORY_SEPARATOR."$table.sql"; + if(!file_exists($this->get_output("alters"))) mkdir($this->get_output("alters"), 0755, true); + $file_path = $this->get_output("alters").DIRECTORY_SEPARATOR."$table.sql"; if(file_exists($file_path)) unlink($file_path); $file = fopen($file_path, "a"); fwrite($file, $creation['alters']."\n\n"); @@ -316,15 +315,15 @@ public function backupTableStructure(string $table) : array { return $errors; } - public function cloneTableStructure(string $table) : array { + public function clone_table_structure(string $table) : array { $errors = []; try { - $creation = $this->getTableCreation($table); - $this->destination->query($this->getHeader()); - $this->destination->query($this->getTableDrop($table)); + $creation = $this->get_table_creation($table); + $this->destination->query($this->get_header()); + $this->destination->query($this->get_table_drop($table)); $this->destination->query($creation['query']); $this->alters .= $creation['alters']."\n"; - $this->destination->query($this->getFooter()); + $this->destination->query($this->get_footer()); echo " Table structure: `$this->database`.`$table` Progress: 100.00 % \r\n"; } catch(PDOException $e){ @@ -335,20 +334,20 @@ public function cloneTableStructure(string $table) : array { return $errors; } - public function backupTableData(string $table) : array { - if(!file_exists($this->getOutput("data"))) mkdir($this->getOutput("data"), 0755, true); + public function backup_table_data(string $table) : array { + if(!file_exists($this->get_output("data"))) mkdir($this->get_output("data"), 0755, true); $errors = []; - $file_path = $this->getOutput("data").DIRECTORY_SEPARATOR."$table.sql"; + $file_path = $this->get_output("data").DIRECTORY_SEPARATOR."$table.sql"; if(file_exists($file_path)) unlink($file_path); $file = fopen($file_path, "a"); try { $offset = 0; - $columns = $this->getColumns($table); + $columns = $this->get_columns($table); fwrite($file, "-- やあ --\n\n"); - fwrite($file, $this->getHeader()."\n\n"); + fwrite($file, $this->get_header()."\n\n"); fwrite($file, "SET foreign_key_checks = 0;\n\n"); echo " Table data: `$this->database`.`$table` Progress: 0.00 % \r"; - $insert = $this->getInsert($table, array_keys($columns))." VALUES\n"; + $insert = $this->get_insert($table, array_keys($columns))." VALUES\n"; if($this->lock_tables) $this->source->query("LOCK TABLE `$table` WRITE"); $results = $this->source->query("SELECT count(*) AS cnt FROM `$table`"); $row = $results->fetch(PDO::FETCH_OBJ); @@ -412,7 +411,7 @@ public function backupTableData(string $table) : array { } if($this->lock_tables) $this->source->query("UNLOCK TABLES"); fwrite($file, "SET foreign_key_checks = 1;\n\n"); - fwrite($file, "\n".$this->getFooter()."\n"); + fwrite($file, "\n".$this->get_footer()."\n"); echo " Table data: `$this->database`.`$table` Progress: 100.00 % \r\n"; } catch(PDOException $e){ @@ -430,15 +429,15 @@ public function backupTableData(string $table) : array { return $errors; } - public function cloneTableData(string $table) : array { + public function clone_table_data(string $table) : array { $errors = []; $offset = 0; try { - $columns = $this->getColumns($table); - $this->destination->query($this->getHeader()); + $columns = $this->get_columns($table); + $this->destination->query($this->get_header()); $this->destination->query("SET foreign_key_checks = 0;"); echo " Table: `$this->database`.`$table` Progress: 0.00 % \r"; - $insert = $this->getInsert($table, array_keys($columns))." VALUES\n"; + $insert = $this->get_insert($table, array_keys($columns))." VALUES\n"; if($this->lock_tables) $this->source->query("LOCK TABLE `$table` WRITE"); $results = $this->source->query("SELECT count(*) AS cnt FROM `$table`"); $row = $results->fetch(PDO::FETCH_OBJ); @@ -502,7 +501,7 @@ public function cloneTableData(string $table) : array { } if($this->lock_tables) $this->source->query("UNLOCK TABLES"); $this->destination->query("SET foreign_key_checks = 1;"); - $this->destination->query($this->getFooter()); + $this->destination->query($this->get_footer()); echo " Table: `$this->database`.`$table` Progress: 100.00 % \r\n"; } catch(PDOException $e){ @@ -519,18 +518,18 @@ public function cloneTableData(string $table) : array { return $errors; } - public function backupView(string $table) : array { - if(!file_exists($this->getOutput("views"))) mkdir($this->getOutput("views"), 0755, true); + public function backup_view(string $table) : array { + if(!file_exists($this->get_output("views"))) mkdir($this->get_output("views"), 0755, true); $errors = []; - $file_path = $this->getOutput("views").DIRECTORY_SEPARATOR."$table.sql"; + $file_path = $this->get_output("views").DIRECTORY_SEPARATOR."$table.sql"; if(file_exists($file_path)) unlink($file_path); $file = fopen($file_path, "a"); try { fwrite($file, "-- やあ --\n\n"); - fwrite($file, $this->getHeader()."\n\n"); - fwrite($file, $this->getViewDrop($table)."\n\n"); - fwrite($file, $this->getViewCreation($table)."\n\n"); - fwrite($file, "\n".$this->getFooter()."\n"); + fwrite($file, $this->get_header()."\n\n"); + fwrite($file, $this->get_view_drop($table)."\n\n"); + fwrite($file, $this->get_view_creation($table)."\n\n"); + fwrite($file, "\n".$this->get_footer()."\n"); echo " View: `$this->database`.`$table` Progress: 100.00 % \r\n"; } catch(PDOException $e){ @@ -542,13 +541,13 @@ public function backupView(string $table) : array { return $errors; } - public function cloneView(string $table) : array { + public function clone_view(string $table) : array { $errors = []; try { - $this->destination->query($this->getHeader()); - $this->destination->query($this->getViewDrop($table)); - $this->destination->query($this->getViewCreation($table)); - $this->destination->query($this->getFooter()); + $this->destination->query($this->get_header()); + $this->destination->query($this->get_view_drop($table)); + $this->destination->query($this->get_view_creation($table)); + $this->destination->query($this->get_footer()); } catch(PDOException $e){ echo " Failed clone view $table skipping\r\n"; @@ -559,18 +558,18 @@ public function cloneView(string $table) : array { return $errors; } - public function backupFunction(string $table) : array { - if(!file_exists($this->getOutput("functions"))) mkdir($this->getOutput("functions"), 0755, true); + public function backup_function(string $table) : array { + if(!file_exists($this->get_output("functions"))) mkdir($this->get_output("functions"), 0755, true); $errors = []; - $file_path = $this->getOutput("functions").DIRECTORY_SEPARATOR."$table.sql"; + $file_path = $this->get_output("functions").DIRECTORY_SEPARATOR."$table.sql"; if(file_exists($file_path)) unlink($file_path); $file = fopen($file_path, "a"); fwrite($file, "-- やあ --\n\n"); try { - fwrite($file, $this->getHeader()."\n\n"); - fwrite($file, $this->getFunctionDrop($table)."\n\n"); - fwrite($file, $this->getFunctionCreation($table)."\n\n"); - fwrite($file, "\n".$this->getFooter()."\n"); + fwrite($file, $this->get_header()."\n\n"); + fwrite($file, $this->get_function_drop($table)."\n\n"); + fwrite($file, $this->get_function_creation($table)."\n\n"); + fwrite($file, "\n".$this->get_footer()."\n"); } catch(PDOException $e){ echo " Failed clone function $table skipping\r\n"; @@ -582,13 +581,13 @@ public function backupFunction(string $table) : array { return $errors; } - public function cloneFunction(string $table) : array { + public function clone_function(string $table) : array { $errors = []; try { - $this->destination->query($this->getHeader()); - $this->destination->query($this->getFunctionDrop($table)); - $this->destination->query($this->getFunctionCreation($table)); - $this->destination->query($this->getFooter()); + $this->destination->query($this->get_header()); + $this->destination->query($this->get_function_drop($table)); + $this->destination->query($this->get_function_creation($table)); + $this->destination->query($this->get_footer()); } catch(PDOException $e){ echo " Failed clone function $table skipping\r\n"; @@ -599,18 +598,18 @@ public function cloneFunction(string $table) : array { return $errors; } - public function backupProcedure(string $table) : array { - if(!file_exists($this->getOutput("procedures"))) mkdir($this->getOutput("procedures"), 0755, true); + public function backup_procedure(string $table) : array { + if(!file_exists($this->get_output("procedures"))) mkdir($this->get_output("procedures"), 0755, true); $errors = []; - $file_path = $this->getOutput("procedures").DIRECTORY_SEPARATOR."$table.sql"; + $file_path = $this->get_output("procedures").DIRECTORY_SEPARATOR."$table.sql"; if(file_exists($file_path)) unlink($file_path); $file = fopen($file_path, "a"); fwrite($file, "-- やあ --\n\n"); try { - fwrite($file, $this->getHeader()."\n\n"); - fwrite($file, $this->getProcedureDrop($table)."\n\n"); - fwrite($file, $this->getProcedureCreation($table)."\n\n"); - fwrite($file, "\n".$this->getFooter()."\n"); + fwrite($file, $this->get_header()."\n\n"); + fwrite($file, $this->get_procedure_drop($table)."\n\n"); + fwrite($file, $this->get_procedure_creation($table)."\n\n"); + fwrite($file, "\n".$this->get_footer()."\n"); } catch(PDOException $e){ echo " Failed clone procedure $table skipping\r\n"; @@ -622,13 +621,13 @@ public function backupProcedure(string $table) : array { return $errors; } - public function cloneProcedure(string $table) : array { + public function clone_procedure(string $table) : array { $errors = []; try { - $this->destination->query($this->getHeader()); - $this->destination->query($this->getProcedureDrop($table)); - $this->destination->query($this->getProcedureCreation($table)); - $this->destination->query($this->getFooter()); + $this->destination->query($this->get_header()); + $this->destination->query($this->get_procedure_drop($table)); + $this->destination->query($this->get_procedure_creation($table)); + $this->destination->query($this->get_footer()); } catch(PDOException $e){ echo " Failed clone procedure $table skipping\r\n"; @@ -639,18 +638,18 @@ public function cloneProcedure(string $table) : array { return $errors; } - public function backupEvent(string $table) : array { - if(!file_exists($this->getOutput("events"))) mkdir($this->getOutput("events"), 0755, true); + public function backup_event(string $table) : array { + if(!file_exists($this->get_output("events"))) mkdir($this->get_output("events"), 0755, true); $errors = []; - $file_path = $this->getOutput("events").DIRECTORY_SEPARATOR."$table.sql"; + $file_path = $this->get_output("events").DIRECTORY_SEPARATOR."$table.sql"; if(file_exists($file_path)) unlink($file_path); $file = fopen($file_path, "a"); fwrite($file, "-- やあ --\n\n"); try { - fwrite($file, $this->getHeader()."\n\n"); - fwrite($file, $this->getEventDrop($table)."\n\n"); - fwrite($file, $this->getEventCreation($table)."\n\n"); - fwrite($file, "\n".$this->getFooter()."\n"); + fwrite($file, $this->get_header()."\n\n"); + fwrite($file, $this->get_event_drop($table)."\n\n"); + fwrite($file, $this->get_event_creation($table)."\n\n"); + fwrite($file, "\n".$this->get_footer()."\n"); } catch(PDOException $e){ echo " Failed clone event $table skipping\r\n"; @@ -662,13 +661,13 @@ public function backupEvent(string $table) : array { return $errors; } - public function cloneEvent(string $table) : array { + public function clone_event(string $table) : array { $errors = []; try { - $this->destination->query($this->getHeader()); - $this->destination->query($this->getEventDrop($table)); - $this->destination->query($this->getEventCreation($table)); - $this->destination->query($this->getFooter()); + $this->destination->query($this->get_header()); + $this->destination->query($this->get_event_drop($table)); + $this->destination->query($this->get_event_creation($table)); + $this->destination->query($this->get_footer()); } catch(PDOException $e){ echo " Failed clone event $table skipping\r\n"; @@ -679,7 +678,7 @@ public function cloneEvent(string $table) : array { return $errors; } - public function backupTrigger(string $table) : array { + public function backup_trigger(string $table) : array { if(!file_exists($this->path.DIRECTORY_SEPARATOR."triggers")) mkdir($this->path.DIRECTORY_SEPARATOR."triggers", 0755, true); $errors = []; $file_path = $this->path.DIRECTORY_SEPARATOR."triggers".DIRECTORY_SEPARATOR."$table.sql"; @@ -687,10 +686,10 @@ public function backupTrigger(string $table) : array { $file = fopen($file_path, "a"); fwrite($file, "-- やあ --\n\n"); try { - fwrite($file, $this->getHeader()."\n\n"); - fwrite($file, $this->getTriggerDrop($table)."\n\n"); - fwrite($file, $this->getTriggerCreation($table)."\n\n"); - fwrite($file, "\n".$this->getFooter()."\n"); + fwrite($file, $this->get_header()."\n\n"); + fwrite($file, $this->get_trigger_drop($table)."\n\n"); + fwrite($file, $this->get_triger_creation($table)."\n\n"); + fwrite($file, "\n".$this->get_footer()."\n"); } catch(PDOException $e){ echo " Failed clone trigger $table skipping\r\n"; @@ -702,13 +701,13 @@ public function backupTrigger(string $table) : array { return $errors; } - public function cloneTrigger(string $table) : array { + public function clone_trigger(string $table) : array { $errors = []; try { - $this->destination->query($this->getHeader()); - $this->destination->query($this->getTriggerDrop($table)); - $this->destination->query($this->getTriggerCreation($table)); - $this->destination->query($this->getFooter()); + $this->destination->query($this->get_header()); + $this->destination->query($this->get_trigger_drop($table)); + $this->destination->query($this->get_triger_creation($table)); + $this->destination->query($this->get_footer()); } catch(PDOException $e){ echo " Failed clone trigger $table skipping\r\n"; @@ -719,66 +718,66 @@ public function cloneTrigger(string $table) : array { return $errors; } - public function backupAll(bool $backup_structure = true, bool $backup_data = true) : array { + public function backup_all(bool $backup_structure = true, bool $backup_data = true) : array { $errors = []; - $items = $this->getTables(); + $items = $this->get_tables(); foreach($items as $item){ - array_merge($errors, $this->backupTableStructure($item)); - array_merge($errors, $this->backupTableData($item)); + array_merge($errors, $this->backup_table_structure($item)); + array_merge($errors, $this->backup_table_data($item)); } - $items = $this->getViews(); + $items = $this->get_views(); foreach($items as $item){ - array_merge($errors, $this->backupView($item)); + array_merge($errors, $this->backup_view($item)); } - $items = $this->getFunctions(); + $items = $this->get_functions(); foreach($items as $item){ - array_merge($errors, $this->backupFunction($item)); + array_merge($errors, $this->backup_function($item)); } - $items = $this->getProcedures(); + $items = $this->get_procedures(); foreach($items as $item){ - array_merge($errors, $this->backupProcedure($item)); + array_merge($errors, $this->backup_procedure($item)); } - $items = $this->getEvents(); + $items = $this->get_events(); foreach($items as $item){ - array_merge($errors, $this->backupEvent($item)); + array_merge($errors, $this->backup_event($item)); } - $items = $this->getTriggers(); + $items = $this->get_triggers(); foreach($items as $item){ - array_merge($errors, $this->backupTrigger($item)); + array_merge($errors, $this->backup_trigger($item)); } return $errors; } - public function cloneAll() : array { - $this->resetAlters(); + public function clone_all() : array { + $this->reset_alters(); $errors = []; - $items = $this->getTables(); + $items = $this->get_tables(); foreach($items as $item){ - array_merge($errors, $this->cloneTableStructure($item)); + array_merge($errors, $this->clone_table_structure($item)); } - $this->destination->query($this->getAlters()); + $this->destination->query($this->get_alters()); foreach($items as $item){ - array_merge($errors, $this->cloneTableData($item)); + array_merge($errors, $this->clone_table_data($item)); } - $items = $this->getViews(); + $items = $this->get_views(); foreach($items as $item){ - array_merge($errors, $this->cloneView($item)); + array_merge($errors, $this->clone_view($item)); } - $items = $this->getFunctions(); + $items = $this->get_functions(); foreach($items as $item){ - array_merge($errors, $this->cloneFunction($item)); + array_merge($errors, $this->clone_function($item)); } - $items = $this->getProcedures(); + $items = $this->get_procedures(); foreach($items as $item){ - array_merge($errors, $this->cloneProcedure($item)); + array_merge($errors, $this->clone_procedure($item)); } - $items = $this->getEvents(); + $items = $this->get_events(); foreach($items as $item){ - array_merge($errors, $this->cloneEvent($item)); + array_merge($errors, $this->clone_event($item)); } - $items = $this->getTriggers(); + $items = $this->get_triggers(); foreach($items as $item){ - array_merge($errors, $this->cloneTrigger($item)); + array_merge($errors, $this->clone_trigger($item)); } return $errors; } diff --git a/includes/services/FaceDetector.php b/includes/services/FaceDetector.php index edb03e4..6b2e8e7 100644 --- a/includes/services/FaceDetector.php +++ b/includes/services/FaceDetector.php @@ -34,7 +34,7 @@ public function __construct(string $detection_data){ $this->detection_data = unserialize(file_get_contents($detection_data)); } - private function getVariantRectangle(float $multiplier = 1.0) : array { + private function get_variant_rectangle(float $multiplier = 1.0) : array { $sw = $this->face['w']; $nw = $this->face['w'] * $multiplier; return [ @@ -45,8 +45,8 @@ private function getVariantRectangle(float $multiplier = 1.0) : array { ]; } - public function saveVariantImage(float $multiplier, string $input, string $output, int $size) : bool { - $rect = $this->getVariantRectangle($multiplier); + public function save_variant_image(float $multiplier, string $input, string $output, int $size) : bool { + $rect = $this->get_variant_rectangle($multiplier); $image = new Imagick(); $image->readImage($input); $image->cropImage((int)$rect['width'], (int)$rect['height'], (int)$rect['x'], (int)$rect['y']); @@ -57,7 +57,7 @@ public function saveVariantImage(float $multiplier, string $input, string $outpu return true; } - public function faceDetect(GdImage $image) : bool { + public function face_detect(GdImage $image) : bool { $this->canvas = $image; $im_width = imagesx($this->canvas); $im_height = imagesy($this->canvas); @@ -71,8 +71,8 @@ public function faceDetect(GdImage $image) : bool { if($ratio != 0){ $this->reduced_canvas = imagecreatetruecolor((int)($im_width / $ratio), (int)($im_height / $ratio)); imagecopyresampled($this->reduced_canvas, $this->canvas, 0, 0, 0, 0, (int)($im_width / $ratio), (int)($im_height / $ratio), $im_width, $im_height); - $stats = $this->getImgStats($this->reduced_canvas); - $this->face = $this->doDetectGreedyBigToSmall($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']); + $stats = $this->get_img_stats($this->reduced_canvas); + $this->face = $this->do_detect_greedy_big_to_small($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']); if(!is_null($this->face)){ if($this->face['w'] > 0){ $this->face['x'] *= $ratio; @@ -81,17 +81,17 @@ public function faceDetect(GdImage $image) : bool { } } } else { - $stats = $this->getImgStats($this->canvas); - $this->face = $this->doDetectGreedyBigToSmall($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']); + $stats = $this->get_img_stats($this->canvas); + $this->face = $this->do_detect_greedy_big_to_small($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']); } if(is_null($this->face)) return false; return ($this->face['w'] > 0); } - private function getImgStats(GdImage $canvas) : array { + private function get_img_stats(GdImage $canvas) : array { $image_width = imagesx($canvas); $image_height = imagesy($canvas); - $iis = $this->computeII($canvas, $image_width, $image_height); + $iis = $this->compute_ii($canvas, $image_width, $image_height); return [ 'width' => $image_width, 'height' => $image_height, @@ -100,7 +100,7 @@ private function getImgStats(GdImage $canvas) : array { ]; } - private function computeII(GdImage $canvas, int $image_width, int $image_height) : array { + private function compute_ii(GdImage $canvas, int $image_width, int $image_height) : array { $ii_w = $image_width+1; $ii_h = $image_height+1; $ii = []; @@ -131,7 +131,7 @@ private function computeII(GdImage $canvas, int $image_width, int $image_height) return ['ii' => $ii, 'ii2' => $ii2]; } - private function doDetectGreedyBigToSmall(array $ii, array $ii2, int $width, int $height) : array|null { + private function do_detect_greedy_big_to_small(array $ii, array $ii2, int $width, int $height) : array|null { $s_w = $width/20.0; $s_h = $height/20.0; $start_scale = $s_h < $s_w ? $s_h : $s_w; @@ -144,7 +144,7 @@ private function doDetectGreedyBigToSmall(array $ii, array $ii2, int $width, int $inv_area = 1 / ($w*$w); for($y = 0; $y < $endy; $y += $step){ for($x = 0; $x < $endx; $x += $step){ - $passed = $this->detectOnSubImage($x, $y, $scale, $ii, $ii2, $w, $width+1, $inv_area); + $passed = $this->detect_on_sub_image($x, $y, $scale, $ii, $ii2, $w, $width+1, $inv_area); if($passed){ return ['x' => $x, 'y' => $y, 'w' => $w]; } @@ -154,7 +154,7 @@ private function doDetectGreedyBigToSmall(array $ii, array $ii2, int $width, int return null; } - private function detectOnSubImage(int $x, int $y, float $scale, array $ii, array $ii2, int $w, int $iiw, float $inv_area) : bool { + private function detect_on_sub_image(int $x, int $y, float $scale, array $ii, array $ii2, int $w, int $iiw, float $inv_area) : bool { $mean = ($ii[($y+$w)*$iiw + $x + $w] + $ii[$y*$iiw+$x] - $ii[($y+$w)*$iiw+$x] - $ii[$y*$iiw+$x+$w])*$inv_area; $vnorm = ($ii2[($y+$w)*$iiw + $x + $w] + $ii2[$y*$iiw+$x] - $ii2[($y+$w)*$iiw+$x] - $ii2[$y*$iiw+$x+$w])*$inv_area - ($mean*$mean); $vnorm = $vnorm > 1 ? sqrt($vnorm) : 1; diff --git a/includes/services/GuardDriver.php b/includes/services/GuardDriver.php index 5e013f7..39cec83 100644 --- a/includes/services/GuardDriver.php +++ b/includes/services/GuardDriver.php @@ -8,6 +8,7 @@ use RecursiveIteratorIterator; use FilesystemIterator; use Exception; +use AveCore\IniFile; class GuardDriver { @@ -27,35 +28,35 @@ public function __construct(string $file, array $folders_to_scan = [], array $fi $this->files_to_scan = $files_to_scan; } - public function addFolders(array|string $folders) : void { + public function add_folders(array|string $folders) : void { if(gettype($folders) == 'string') $folders = [$folders]; $this->folders_to_scan = array_unique(array_merge($this->folders_to_scan, $folders)); } - public function setFolders(array|string $folders) : void { + public function set_folders(array|string $folders) : void { if(gettype($folders) == 'string') $folders = [$folders]; $this->folders_to_scan = $folders; } - public function getFolders() : array { + public function get_folders() : array { return $this->folders_to_scan; } - public function addFiles(array|string $files) : void { + public function add_files(array|string $files) : void { if(gettype($files) == 'string') $files = [$files]; $this->files_to_scan = array_unique(array_merge($this->files_to_scan, $files)); } - public function setFiles(array|string $files) : void { + public function set_files(array|string $files) : void { if(gettype($files) == 'string') $files = [$files]; $this->files_to_scan = $files; } - public function getFiles() : array { + public function get_files() : array { return $this->files_to_scan; } - public function resetCache() : void { + public function reset_cache() : void { $this->file_list = []; $this->data = []; $this->keys = []; @@ -63,7 +64,7 @@ public function resetCache() : void { } public function load(IniFile $guard) : void { - $this->data = $guard->allExcept(['files', 'keys', 'files_to_scan', 'folders_to_scan']); + $this->data = $guard->all_except(['files', 'keys', 'files_to_scan', 'folders_to_scan']); $this->file_list = $guard->get('files'); $this->keys = $guard->get('keys'); $this->files_to_scan = $guard->get('files_to_scan'); @@ -71,7 +72,7 @@ public function load(IniFile $guard) : void { $this->errors = []; } - public function scanFolder(string $folder) : void { + public function scan_folder(string $folder) : void { $files = new RecursiveDirectoryIterator($folder, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS); foreach(new RecursiveIteratorIterator($files) as $file){ if($file->isDir() || $file->isLink()) continue; @@ -84,7 +85,7 @@ public function scanFolder(string $folder) : void { } } - public function scanFile(string $file, bool $update = false) : void { + public function scan_file(string $file, bool $update = false) : void { $key = strtoupper(hash('md5', str_replace(["\\", "/"], ":", pathinfo($file, PATHINFO_DIRNAME)))); if(!isset($data[$key])) $data[$key] = []; $this->data[$key][pathinfo($file, PATHINFO_BASENAME)] = strtoupper(hash_file('md5', $file)); @@ -92,7 +93,7 @@ public function scanFile(string $file, bool $update = false) : void { $this->keys[$key] = str_replace("\\", "/", pathinfo($file, PATHINFO_DIRNAME)); } - public function validateFolder(string $folder) : bool { + public function validate_folder(string $folder) : bool { if(!file_exists($folder)) return false; $files = new RecursiveDirectoryIterator($folder, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS); foreach(new RecursiveIteratorIterator($files) as $file){ @@ -123,9 +124,9 @@ public function validateFolder(string $folder) : bool { } public function scan() : void { - $this->resetCache(); - foreach($this->folders_to_scan as $folder) $this->scanFolder($folder); - foreach($this->files_to_scan as $file) $this->scanFile($file); + $this->reset_cache(); + foreach($this->folders_to_scan as $folder) $this->scan_folder($folder); + foreach($this->files_to_scan as $file) $this->scan_file($file); } public function get() : array { @@ -136,7 +137,7 @@ public function get() : array { return $this->data; } - public function validateFile(string $file) : bool { + public function validate_file(string $file) : bool { if(!file_exists($file)) return false; $key = strtoupper(hash('md5', str_replace(["\\", "/"], ":", pathinfo($file, PATHINFO_DIRNAME)))); $file_name = pathinfo($file, PATHINFO_BASENAME); @@ -160,7 +161,7 @@ public function validateFile(string $file) : bool { return true; } - public function validateExist() : void { + public function validate_exists() : void { if(isset($this->data['files'])){ foreach($this->data['files'] as $file){ if(!file_exists($file)){ @@ -172,34 +173,34 @@ public function validateExist() : void { public function validate(array $flags = ['damaged' => true, 'unknown' => true, 'missing' => true]) : array { $guard = new IniFile($this->file, true); - $this->resetCache(); - $this->data = $guard->getAll(); + $this->reset_cache(); + $this->data = $guard->get_all(); $this->flags = $flags; - foreach($this->folders_to_scan as $folder) $this->validateFolder($folder); - foreach($this->files_to_scan as $file) $this->validateFile($file); - $this->validateExist(); + foreach($this->folders_to_scan as $folder) $this->validate_folder($folder); + foreach($this->files_to_scan as $file) $this->validate_file($file); + $this->validate_exists(); return $this->errors; } public function generate() : void { $guard = new IniFile($this->file, true, true); $this->scan(); - $guard->setAll($this->get(), true); + $guard->set_all($this->get(), true); } - public function getTree() : array { + public function get_tree() : array { $guard = new IniFile($this->file, true); $data = []; foreach($guard->get('keys', []) as $key => $value){ $guard->rename($key, $value); $guard->extract_path($data, $value); } - $guard->setAll($data); + $guard->set_all($data); foreach($guard->get('.', []) as $key => $value){ $guard->set($key, $value); } $guard->unset('.'); - return $guard->getAll(); + return $guard->get_all(); } } diff --git a/includes/services/GuardPattern.php b/includes/services/GuardPattern.php index 2dcafe9..97121be 100644 --- a/includes/services/GuardPattern.php +++ b/includes/services/GuardPattern.php @@ -17,48 +17,48 @@ public function __construct(array $folders = [], array $files = []){ $this->input = ''; } - public function addFolders(array|string $folders) : void { + public function add_folders(array|string $folders) : void { if(gettype($folders) == 'string') $folders = [$folders]; $this->folders = array_unique(array_merge($this->folders, $folders)); } - public function setFolders(array|string $folders) : void { + public function set_folders(array|string $folders) : void { if(gettype($folders) == 'string') $folders = [$folders]; $this->folders = $folders; } - public function getFolders() : array { + public function get_folders() : array { return $this->folders; } - public function addFiles(array|string $files) : void { + public function add_files(array|string $files) : void { if(gettype($files) == 'string') $files = [$files]; $this->files = array_unique(array_merge($this->files, $files)); } - public function setFiles(array|string $files) : void { + public function set_files(array|string $files) : void { if(gettype($files) == 'string') $files = [$files]; $this->files = $files; } - public function getFiles() : array { + public function get_files() : array { return $this->files; } - public function getInput() : string { + public function get_input() : string { return rtrim($this->input, "\\/"); } - public function setInput(string $input) : void { + public function set_input(string $input) : void { $this->input = $input; } public function get() : string { - $data = ['input:'.$this->getInput()]; - foreach($this->getFolders() as $folder){ + $data = ['input:'.$this->get_input()]; + foreach($this->get_folders() as $folder){ array_push($data, "folder:$folder"); } - foreach($this->getFiles() as $file){ + foreach($this->get_files() as $file){ array_push($data, "file:$file"); } return implode("\r\n", $data); @@ -74,11 +74,11 @@ public function load(string $pattern) : void { } else if(substr($pat, 0, 5) == 'file:'){ array_push($files, substr($pat, 5)); } else if(substr($pat, 0, 6) == 'input:'){ - $this->setInput(substr($pat, 6)); + $this->set_input(substr($pat, 6)); } } - $this->setFolders($folders); - $this->setFiles($files); + $this->set_folders($folders); + $this->set_files($files); } } diff --git a/includes/services/MediaFunctions.php b/includes/services/MediaFunctions.php index dfb4774..ccf2246 100644 --- a/includes/services/MediaFunctions.php +++ b/includes/services/MediaFunctions.php @@ -13,6 +13,8 @@ class MediaFunctions { public AVE $ave; + public array $vr_tags = ['_180', '_360', '_FISHEYE', '_FISHEYE190', '_RF52', '_MKX200', '_VRCA220']; + const MEDIA_ORIENTATION_HORIZONTAL = 0; const MEDIA_ORIENTATION_VERTICAL = 1; const MEDIA_ORIENTATION_SQUARE = 2; @@ -21,7 +23,7 @@ public function __construct(AVE $ave){ $this->ave = $ave; } - public function getImageFromPath(string $path) : GdImage|bool|null { + public function get_image_from_path(string $path) : GdImage|bool|null { if(!file_exists($path)) return null; switch(strtolower(pathinfo($path, PATHINFO_EXTENSION))){ case 'bmp': return @imagecreatefrombmp($path); @@ -43,8 +45,8 @@ public function getImageFromPath(string $path) : GdImage|bool|null { return null; } - public function getImageResolution(string $path) : string { - $image = $this->getImageFromPath($path); + public function get_image_resolution(string $path) : string { + $image = $this->get_image_from_path($path); if(!$image){ try { $image = new Imagick($path); @@ -54,7 +56,7 @@ public function getImageResolution(string $path) : string { return $w."x".$h; } catch(Exception $e){ - return $this->getVideoResolution($path); + return $this->get_video_resolution($path); } } $w = imagesx($image); @@ -63,7 +65,7 @@ public function getImageResolution(string $path) : string { return $w."x".$h; } - public function isGifAnimated(string $path) : bool { + public function is_gif_animated(string $path) : bool { if(!($fh = @fopen($path, 'rb'))) return false; $count = 0; while(!feof($fh) && $count < 2){ @@ -74,23 +76,28 @@ public function isGifAnimated(string $path) : bool { return $count > 1; } - public function getVideoFPS(string $path) : float { + public function get_video_fps(string $path) : float { $this->ave->exec("ffprobe", "-v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate \"$path\" 2>nul", $output); eval('$fps = '.trim(preg_replace('/[^0-9.\/]+/', "", $output[0])).';'); return $fps; } - public function getVideoCodec(string $path) : string { - $this->ave->exec("ffprobe", "-v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 \"$path\" 2>nul", $output); + public function get_video_codec(string $path) : string { + $this->ave->exec("ffprobe", "-v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 \"$path\" 2>nul", $output); return trim($output[0]); } - public function getVideoResolution(string $path) : string { + public function get_video_resolution(string $path) : string { $this->ave->exec("ffprobe", "-v error -select_streams v:0 -show_entries stream^=width^,height -of csv^=s^=x:p^=0 \"$path\" 2>nul", $output); return rtrim($output[0] ?? '0x0', 'x'); } - public function getVideoDuration(string $path) : string { + public function get_video_color_primaries(string $path): string { + $this->ave->exec("ffprobe","-v error -select_streams v:0 -show_entries stream^=color_primaries -of default=noprint_wrappers=1:nokey=1 \"$path\" 2>nul", $output); + return trim($output[0] ?? ''); + } + + public function get_video_duration(string $path) : string { $this->ave->exec("ffprobe", "-i \"$path\" -show_entries format=duration -v quiet -of csv=\"p=0\" -sexagesimal 2>nul", $output); $file_duration = trim($output[0]); $h = $m = $s = 0; @@ -98,7 +105,7 @@ public function getVideoDuration(string $path) : string { return sprintf("%02d:%02d:%02d", $h, $m, $s); } - public function getVideoDurationSeconds(string $path) : int { + public function get_video_duration_seconds(string $path) : int { $this->ave->exec("ffprobe", "-i \"$path\" -show_entries format=duration -v quiet -of csv=\"p=0\" -sexagesimal 2>nul", $output); $file_duration = trim($output[0]); $h = $m = $s = 0; @@ -106,7 +113,7 @@ public function getVideoDurationSeconds(string $path) : int { return (intval($h) * 3600) + (intval($m) * 60) + intval($s); } - public function getVideoLanguages(string $path) : array { + public function get_video_languages(string $path) : array { $this->ave->exec("ffprobe", "-i \"$path\" -show_entries stream=index:stream_tags=language -select_streams a -of compact=p=0:nk=1 2> nul", $output); $data = []; foreach($output as $language){ @@ -116,7 +123,33 @@ public function getVideoLanguages(string $path) : array { return $data; } - public function SecToTime(int $s) : string { + public function get_extension_by_mime_type(string $path) : string|false { + if(!file_exists($path)) return false; + switch(exif_imagetype($path)){ + case IMAGETYPE_GIF: return 'gif'; + case IMAGETYPE_JPEG: return 'jpg'; + case IMAGETYPE_PNG: return 'png'; + case IMAGETYPE_SWF: return 'swf'; + case IMAGETYPE_PSD: return 'psd'; + case IMAGETYPE_BMP: return 'bmp'; + case IMAGETYPE_TIFF_II: return 'tiff'; + case IMAGETYPE_TIFF_MM: return 'tiff'; + case IMAGETYPE_JPC: return 'jpc'; + case IMAGETYPE_JP2: return 'jp2'; + case IMAGETYPE_JPX: return 'jpx'; + case IMAGETYPE_JB2: return 'jb2'; + case IMAGETYPE_SWC: return 'swc'; + case IMAGETYPE_IFF: return 'iff'; + case IMAGETYPE_WBMP: return 'wbmp'; + case IMAGETYPE_XBM: return 'xbm'; + case IMAGETYPE_ICO: return 'ico'; + case IMAGETYPE_WEBP: return 'webp'; + case IMAGETYPE_AVIF: return 'avif'; + default: return false; + } + } + + public function sec_to_time(int $s) : string { $d = intval(floor($s / 86400)); $s -= ($d * 86400); $h = intval(floor($s / 3600)); @@ -132,7 +165,7 @@ public function SecToTime(int $s) : string { } } - public function getVideoThumbnail(string $path, string $output, int $w, int $r, int $c) : bool { + public function get_video_thumbnail(string $path, string $output, int $w, int $r, int $c) : bool { if(!$this->ave->windows && !file_exists("/usr/bin/mtn")) return false; $input_file = $this->ave->get_file_path("$output/".pathinfo($path, PATHINFO_FILENAME)."_s.jpg"); $output_file = $this->ave->get_file_path("$output/".pathinfo($path, PATHINFO_BASENAME).".webp"); @@ -148,7 +181,7 @@ public function getVideoThumbnail(string $path, string $output, int $w, int $r, return file_exists($output_file); } - public function getMediaOrientation(int $width, int $height) : int { + public function get_media_orientation(int $width, int $height) : int { if($width > $height){ return self::MEDIA_ORIENTATION_HORIZONTAL; } else if($height > $width){ @@ -158,7 +191,7 @@ public function getMediaOrientation(int $width, int $height) : int { } } - public function getMediaOrientationName(int $orientation) : string { + public function get_media_orientation_name(int $orientation) : string { switch($orientation){ case self::MEDIA_ORIENTATION_HORIZONTAL: return 'Horizontal'; case self::MEDIA_ORIENTATION_VERTICAL: return 'Vertical'; @@ -167,7 +200,7 @@ public function getMediaOrientationName(int $orientation) : string { return 'Unknown'; } - public function getMediaQuality(int $width, int $height, bool $is_video = false) : string { + public function get_media_quality(int $width, int $height, bool $is_video = false) : string { $w = max($width, $height); $h = min($width, $height); if($is_video && $w / $h == 2) return strval($h); @@ -200,13 +233,13 @@ public function getMediaQuality(int $width, int $height, bool $is_video = false) } } - public function getImageColorCount(string $path) : int|null { + public function get_image_color_count(string $path) : int|null { $image = new Imagick($path); if(!$image->valid()) return null; return $image->getImageColors(); } - public function getImageColorGroup(int $colors) : string { + public function get_image_color_group(int $colors) : string { if($colors > 500000){ return '500001 - 999999'; } else if($colors > 400000 && $colors <= 500000){ @@ -243,6 +276,22 @@ public function format_episode(int $episode, int $digits, int $max) : string { return str_repeat("0", $digits - strlen($ep)).$ep; } + public function is_vr_video(string $path) : bool { + $name = strtoupper(pathinfo($path, PATHINFO_FILENAME)); + foreach($this->vr_tags as $tag){ + if(strpos("$name#", "$tag#") !== false) return true; + } + return false; + } + + public function is_ar_video(string $path) : bool { + $name = strtoupper(pathinfo($path, PATHINFO_FILENAME)); + foreach($this->vr_tags as $tag){ + if(strpos("$name#", "{$tag}_ALPHA#") !== false) return true; + } + return false; + } + } ?> diff --git a/includes/services/Request.php b/includes/services/Request.php deleted file mode 100644 index 2945cb9..0000000 --- a/includes/services/Request.php +++ /dev/null @@ -1,81 +0,0 @@ -json = $json; - $this->cookies = $cookies; - $this->header = $header; - $this->options = [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 120, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_SSL_VERIFYHOST => false, - CURLOPT_SSL_VERIFYPEER => false, - ]; - } - - public function setHeader(array $header) : void { - $this->header = $header; - } - - public function setOptions(array $options) : void { - $this->options = $options; - } - - public function setOption(int $option, mixed $value) : void { - $this->options[$option] = $value; - } - - public function get(string $url, array $data = [], bool $follow = false) : array { - return $this->request($url, 'GET', $data, $follow); - } - - public function post(string $url, array $data = [], bool $follow = false) : array { - return $this->request($url, 'POST', $data, $follow); - } - - private function request(string $url, string $method, array $data, bool $follow) : array { - $options = $this->options; - $options[CURLOPT_FOLLOWLOCATION] = $follow; - $options[CURLOPT_CUSTOMREQUEST] = $method; - if(!empty($data)){ - if($method == 'POST'){ - $options[CURLOPT_POSTFIELDS] = $this->json ? json_encode($data) : urldecode(http_build_query($data)); - } else { - $params = "?".urldecode(http_build_query($data)); - } - } - $curl = curl_init($url.($params ?? '')); - $options[CURLOPT_HTTPHEADER] = $this->header; - if($this->json) array_push($options[CURLOPT_HTTPHEADER], 'Content-Type: application/json'); - if($this->cookies){ - $options[CURLOPT_COOKIEFILE] = 'AVE-COOKIE.txt'; - $options[CURLOPT_COOKIEJAR] = 'AVE-COOKIE.txt'; - } - curl_setopt_array($curl, $options); - $response = curl_exec($curl); - curl_close($curl); - if(!$response) return ['code' => curl_getinfo($curl, CURLINFO_HTTP_CODE), 'data' => []]; - return [ - 'code' => curl_getinfo($curl, CURLINFO_HTTP_CODE), - 'data' => $this->json ? json_decode($response, true) : $response - ]; - } - -} - -?> diff --git a/includes/services/StringConverter.php b/includes/services/StringConverter.php index 2c3c70c..29a3a1f 100644 --- a/includes/services/StringConverter.php +++ b/includes/services/StringConverter.php @@ -4,6 +4,8 @@ namespace App\Services; +use AveCore\IniFile; + class StringConverter { public array $replace = []; @@ -21,16 +23,16 @@ public function __construct(){ ]; } - public function importPinYin(string $path) : void { + public function import_pin_yin(string $path) : void { if(empty($this->pinyin)){ $ini = new IniFile($path); - $this->pinyin = $ini->getAll(); + $this->pinyin = $ini->get_all(); } } - public function importReplacement(string $path) : void { + public function import_replacement(string $path) : void { $ini = new IniFile($path); - foreach($ini->getAll() as $key => $value){ + foreach($ini->get_all() as $key => $value){ $this->replace[$key] = $value; } } @@ -50,13 +52,13 @@ public function remove_double_spaces(string $string) : string { return trim($string, ' '); } - public function stringToPinYin(string $string) : string { + public function string_to_pin_yin(string $string) : string { $string = preg_replace("/\s/is", "_", $string); $pinyin = ""; $string = iconv('UTF-8', 'GBK//TRANSLIT', $string); for($i = 0; $i < strlen($string); $i++){ if(ord($string[$i]) > 128){ - $char = $this->asc2ToPinYin(ord($string[$i]) + ord($string[$i+1]) * 256); + $char = $this->asc2_to_pin_yin(ord($string[$i]) + ord($string[$i+1]) * 256); if(!is_null($char)){ $pinyin .= $char; } else { @@ -70,7 +72,7 @@ public function stringToPinYin(string $string) : string { return str_replace('_', ' ', $pinyin); } - private function asc2ToPinYin(int $asc2) : ?string { + private function asc2_to_pin_yin(int $asc2) : ?string { foreach($this->pinyin as $key => $value){ if(array_search($asc2, $value) !== false){ return $key; diff --git a/includes/tools/AdmFileConverter.php b/includes/tools/AdmFileConverter.php index c341351..9f338b2 100644 --- a/includes/tools/AdmFileConverter.php +++ b/includes/tools/AdmFileConverter.php @@ -6,13 +6,12 @@ use AVE; use Exception; -use App\Services\IniFile; -use App\Services\JournalService; +use AveCore\IniFile; +use AveCore\JournalService; class AdmFileConverter { private string $name = "ADM File Converter"; - private array $params = []; private string $action; private AVE $ave; @@ -84,7 +83,7 @@ public function ToolIniConverter() : bool { } if($this->params['mode'] == '2'){ - $this->ave->write_data(print_r($ini->getAll(), true)); + $this->ave->write_data(print_r($ini->get_all(), true)); $this->ave->open_logs(); } else { set_output: @@ -107,7 +106,7 @@ public function ToolIniConverter() : bool { $ini->save(); } else { $new = new IniFile($output, true, $this->params['mode'] == '0'); - $new->setAll($ini->getAll()); + $new->set_all($ini->get_all()); $new->save(); } } diff --git a/includes/tools/AveConsole.php b/includes/tools/AveConsole.php index 1269cc5..fcd9aff 100644 --- a/includes/tools/AveConsole.php +++ b/includes/tools/AveConsole.php @@ -8,10 +8,7 @@ class AveConsole { - private string $name = "Ave Console"; - private AVE $ave; - public string $script; public string $path; diff --git a/includes/tools/AveSettings.php b/includes/tools/AveSettings.php index 5da1f81..b7bcfef 100644 --- a/includes/tools/AveSettings.php +++ b/includes/tools/AveSettings.php @@ -5,13 +5,12 @@ namespace App\Tools; use AVE; -use App\Services\Request; -use App\Services\IniFile; +use AveCore\Request; +use AveCore\IniFile; class AveSettings { private string $name = "Ave Settings"; - private array $params = []; private string $action; private AVE $ave; @@ -106,8 +105,8 @@ public function ToolRestoreDefaultSettings() : bool { } else { $config_default_system = new IniFile($this->ave->get_file_path($this->ave->path."/includes/config/linux.ini"), true); } - $config_default->update($config_default_system->getAll()); - $this->ave->config->update($config_default->getAll(), true); + $config_default->update($config_default_system->get_all()); + $this->ave->config->update($config_default->get_all(), true); $this->ave->echo(" Settings have been reset"); } else { $this->ave->echo(" Settings reset has been cancelled"); diff --git a/includes/tools/CheckFileIntegrity.php b/includes/tools/CheckFileIntegrity.php index 7cbbf83..7b84701 100644 --- a/includes/tools/CheckFileIntegrity.php +++ b/includes/tools/CheckFileIntegrity.php @@ -7,12 +7,11 @@ use AVE; use App\Services\GuardPattern; use App\Services\GuardDriver; -use App\Services\IniFile; +use AveCore\IniFile; class CheckFileIntegrity { private string $name = "Check File Integrity"; - private array $params = []; private string $action; private AVE $ave; @@ -89,13 +88,13 @@ public function ToolCreatePattern() : bool { $pattern_file = preg_replace('/[^A-Za-z0-9_\-]/', '_', $pattern_file[0]).".ave-pat"; $pattern = new GuardPattern(); - $pattern->setInput($input); + $pattern->set_input($input); set_folders: $line = $this->ave->get_input(" Folders: "); if($line == '#') return false; foreach($this->ave->get_input_folders($line) as $folder){ - $pattern->addFolders(str_replace([$input.DIRECTORY_SEPARATOR, $input], "", $folder)); + $pattern->add_folders(str_replace([$input.DIRECTORY_SEPARATOR, $input], "", $folder)); } if(!empty($line)){ @@ -106,7 +105,7 @@ public function ToolCreatePattern() : bool { $line = $this->ave->get_input(" Files: "); if($line == '#') return false; foreach($this->ave->get_input_folders($line) as $file){ - $pattern->addFiles(str_replace([$input.DIRECTORY_SEPARATOR, $input], "", $file)); + $pattern->add_files(str_replace([$input.DIRECTORY_SEPARATOR, $input], "", $file)); } if(!empty($line)){ @@ -141,14 +140,14 @@ public function ToolGuardGenerate() : bool { $pattern = new GuardPattern(); $pattern->load(file_get_contents($pattern_file)); - $input = $pattern->getInput(); + $input = $pattern->get_input(); if(!file_exists($input) || !is_dir($input) || empty($input)){ $this->ave->echo(" Invalid input folder: \"$input\""); goto set_pattern; } - $files = count($pattern->getFiles()); - $folders = count($pattern->getFolders()); + $files = count($pattern->get_files()); + $folders = count($pattern->get_folders()); $this->ave->echo(" Loaded $folders folders and $files files"); $guard_file = str_replace(chr(0x5C).chr(0x5C), chr(0x5C), $this->ave->get_file_path("$input/".pathinfo($pattern_file, PATHINFO_FILENAME).".ave-guard")); @@ -156,7 +155,7 @@ public function ToolGuardGenerate() : bool { $cwd = getcwd(); chdir($input); $this->ave->echo(" Generate $guard_file"); - $guard = new GuardDriver($guard_file, $pattern->getFolders(), $pattern->getFiles()); + $guard = new GuardDriver($guard_file, $pattern->get_folders(), $pattern->get_files()); $guard->generate(); chdir($cwd); @@ -264,7 +263,7 @@ public function ToolGetFilesTree() : bool { $guard = new GuardDriver($guard_file); $tree_file = "$guard_file.txt"; - file_put_contents($tree_file, print_r($guard->getTree(), true)); + file_put_contents($tree_file, print_r($guard->get_tree(), true)); $this->ave->open_file($tree_file); @@ -355,12 +354,12 @@ public function ToolGuardUpdate(string $guard_file, array $params) : void { switch($error['type']){ case 'unknown': { $this->ave->write_log("ADD FILE \"$file\""); - $guard->scanFile($file); + $guard->scan_file($file); break; } case 'damaged': { $this->ave->write_log("UPDATE FILE \"$file\""); - $guard->scanFile($file, true); + $guard->scan_file($file, true); break; } case 'missing': { @@ -380,7 +379,7 @@ public function ToolGuardUpdate(string $guard_file, array $params) : void { } } - $ini->setAll($guard->get(), true); + $ini->set_all($guard->get(), true); chdir($cwd); } diff --git a/includes/tools/DirectoryFunctions.php b/includes/tools/DirectoryFunctions.php index f760157..1236f57 100644 --- a/includes/tools/DirectoryFunctions.php +++ b/includes/tools/DirectoryFunctions.php @@ -10,7 +10,6 @@ class DirectoryFunctions { private string $name = "Directory Functions"; - private array $params = []; private string $action; private AVE $ave; @@ -219,7 +218,7 @@ public function ToolCloneFolderStructure() : bool { $this->ave->pause(" Operation done, press any key to back to menu"); return false; } - + } ?> diff --git a/includes/tools/DirectoryNamesEditor.php b/includes/tools/DirectoryNamesEditor.php new file mode 100644 index 0000000..79080ed --- /dev/null +++ b/includes/tools/DirectoryNamesEditor.php @@ -0,0 +1,511 @@ +ave = $ave; + $this->ave->set_tool($this->name); + } + + public function help() : void { + $this->ave->print_help([ + ' Actions:', + ' 0 - Escape directory name (WWW)', + ' 1 - Pretty directory name', + ' 2 - Add directory name prefix/suffix', + ' 3 - Remove keywords from directory name', + ' 4 - Insert string into directory name', + ' 5 - Replace keywords in directory name', + ]); + } + + public function action(string $action) : bool { + $this->params = []; + $this->action = $action; + switch($this->action){ + case '0': return $this->ToolEscapeDirectoryNameWWW(); + case '1': return $this->ToolPrettyDirectoryName(); + case '2': return $this->ToolAddDirectoryNamePrefixSuffix(); + case '3': return $this->ToolRemoveKeywordsFromDirectoryName(); + case '4': return $this->ToolInsertStringIntoDirectoryName(); + case '5': return $this->ToolReplaceKeywordsInDirectoryName(); + } + return false; + } + + public function ToolEscapeDirectoryNameWWW() : bool { + $this->ave->clear(); + $this->ave->set_subtool("Escape directory name WWW"); + $this->ave->print_help([ + " Double spaces reduce", + " Characters after escape: A-Z a-z 0-9 _ - .", + " Be careful to prevent use on Japanese, Chinese, Korean, etc. directory names", + ]); + $line = $this->ave->get_input(" Folders: "); + if($line == '#') return false; + $folders = $this->ave->get_input_folders($line); + $this->ave->setup_folders($folders); + $errors = 0; + $this->ave->set_errors($errors); + foreach($folders as $folder){ + if(!file_exists($folder)) continue; + $files = $this->ave->get_folders($folder); + $items = 0; + $total = count($files); + foreach($files as $file){ + $items++; + if(!file_exists($file)) continue 1; + $escaped_name = pathinfo($file, PATHINFO_BASENAME); + while(strpos($escaped_name, ' ') !== false){ + $escaped_name = str_replace(' ', ' ', $escaped_name); + } + $escaped_name = trim(preg_replace('/[^A-Za-z0-9_\-.]/', '', str_replace(' ', '_', $escaped_name)), ' '); + if(empty($escaped_name)){ + $this->ave->write_error("ESCAPED NAME IS EMPTY \"$file\""); + $errors++; + } else { + $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/$escaped_name"); + if(file_exists($new_name) && strtoupper($new_name) != strtoupper($file)){ + $this->ave->write_error("DUPLICATE \"$file\" AS \"$new_name\""); + $errors++; + } else { + if(!$this->ave->rename($file, $new_name)){ + $errors++; + } + } + } + + $this->ave->progress($items, $total); + $this->ave->set_errors($errors); + } + $this->ave->progress($items, $total); + unset($files); + $this->ave->set_folder_done($folder); + } + + $this->ave->open_logs(true); + $this->ave->pause(" Operation done, press any key to back to menu"); + return false; + } + + public function ToolPrettyDirectoryName() : bool { + $this->ave->clear(); + $this->ave->set_subtool("Pretty directory name"); + + set_mode: + $this->ave->clear(); + $this->ave->print_help([ + ' Flags (type in one line, default BC):', + ' B - Basic replacement', + ' C - Basic remove', + ' L - Replace language characters', + ' 0 - Chinese to PinYin', + ' 1 - Hiragama to Romaji', + ' 2 - Katakana to Romaji', + ' + - To upper case', + ' - - To lower case', + ]); + + $line = strtoupper($this->ave->get_input(" Flags: ")); + if($line == '#') return false; + if(empty($line)) $line = 'BC'; + if(str_replace(['B', 'C', 'L', '0', '1', '2', '+', '-'], '', $line) != '') goto set_mode; + $flags = (object)[ + 'basic_replace' => (strpos($line, 'B') !== false), + 'basic_remove' => (strpos($line, 'C') !== false), + 'language_replace' => (strpos($line, 'L') !== false), + 'ChineseToPinYin' => (strpos($line, '0') !== false), + 'HiragamaToRomaji' => (strpos($line, '1') !== false), + 'KatakanaToRomaji' => (strpos($line, '2') !== false), + 'UpperCase' => (strpos($line, '+') !== false), + 'LowerCase' => (strpos($line, '-') !== false), + ]; + $converter = new StringConverter(); + if($flags->language_replace){ + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/LanguageReplacement.ini")); + } + if($flags->ChineseToPinYin){ + $converter->import_pin_yin($this->ave->get_file_path($this->ave->path."/includes/data/PinYin.ini")); + } + if($flags->HiragamaToRomaji){ + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/Hiragama.ini")); + } + if($flags->KatakanaToRomaji){ + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/Katakana.ini")); + } + $this->ave->clear(); + + $line = $this->ave->get_input(" Folders: "); + if($line == '#') return false; + $folders = $this->ave->get_input_folders($line); + $this->ave->setup_folders($folders); + + $errors = 0; + $this->ave->set_errors($errors); + foreach($folders as $folder){ + if(!file_exists($folder)) continue; + $files = $this->ave->get_folders($folder); + $items = 0; + $total = count($files); + foreach($files as $file){ + $items++; + if(!file_exists($file)) continue 1; + $escaped_name = pathinfo($file, PATHINFO_BASENAME); + if($flags->basic_replace || $flags->language_replace || $flags->HiragamaToRomaji || $flags->KatakanaToRomaji){ + $escaped_name = $converter->convert($escaped_name); + } + if($flags->basic_remove){ + $escaped_name = $converter->clean($escaped_name); + } + if($flags->ChineseToPinYin){ + $escaped_name = $converter->string_to_pin_yin($escaped_name); + } + if($flags->UpperCase){ + $escaped_name = mb_strtoupper($escaped_name); + } else if($flags->LowerCase){ + $escaped_name = mb_strtolower($escaped_name); + } + $escaped_name = $converter->remove_double_spaces(str_replace(',', ', ', $escaped_name)); + if(empty($escaped_name)){ + $this->ave->write_error("ESCAPED NAME IS EMPTY \"$file\""); + $errors++; + } else { + $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/$escaped_name"); + if(file_exists($new_name) && strtoupper($new_name) != strtoupper($file)){ + $this->ave->write_error("DUPLICATE \"$file\" AS \"$new_name\""); + $errors++; + } else { + if(!$this->ave->rename_case($file, $new_name)){ + $errors++; + } + } + } + + $this->ave->progress($items, $total); + $this->ave->set_errors($errors); + } + $this->ave->progress($items, $total); + unset($files); + $this->ave->set_folder_done($folder); + } + + $this->ave->open_logs(true); + $this->ave->pause(" Operation done, press any key to back to menu"); + return false; + } + + public function ToolAddDirectoryNamePrefixSuffix() : bool { + $this->ave->clear(); + $this->ave->set_subtool("Add directory name prefix/suffix"); + + $line = $this->ave->get_input(" Folders: "); + if($line == '#') return false; + $folders = $this->ave->get_input_folders($line); + + $prefix = $this->ave->get_input_no_trim(" Prefix (may be empty): "); + if($prefix == '#') return false; + $prefix = str_replace(['<', '>', ':', '"', '/', '\\', '|', '?', '*'], '', $prefix); + + $suffix = $this->ave->get_input_no_trim(" Suffix (may be empty): "); + if($suffix == '#') return false; + $suffix = str_replace(['<', '>', ':', '"', '/', '\\', '|', '?', '*'], '', $suffix); + + $this->ave->setup_folders($folders); + $errors = 0; + $this->ave->set_errors($errors); + foreach($folders as $folder){ + if(!file_exists($folder)) continue; + $files = $this->ave->get_folders($folder); + $items = 0; + $total = count($files); + foreach($files as $file){ + $items++; + if(!file_exists($file)) continue 1; + $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/$prefix".pathinfo($file, PATHINFO_BASENAME).$suffix); + if(file_exists($new_name) && strtoupper($new_name) != strtoupper($file)){ + $this->ave->write_error("DUPLICATE \"$file\" AS \"$new_name\""); + $errors++; + } else { + if(!$this->ave->rename($file, $new_name)){ + $errors++; + } + } + $this->ave->progress($items, $total); + $this->ave->set_errors($errors); + } + $this->ave->progress($items, $total); + $this->ave->set_folder_done($folder); + } + + $this->ave->open_logs(true); + $this->ave->pause(" Operation done, press any key to back to menu"); + return false; + } + + public function ToolRemoveKeywordsFromDirectoryName() : bool { + $this->ave->clear(); + $this->ave->set_subtool("Remove keywords from directory name"); + + set_mode: + $this->ave->clear(); + $this->ave->print_help([ + ' Modes:', + ' 0 - Type keywords', + ' 1 - Load from file (new line every keyword)', + ]); + + $line = $this->ave->get_input(" Mode: "); + if($line == '#') return false; + + $this->params = [ + 'mode' => strtolower($line[0] ?? '?'), + ]; + + if(!in_array($this->params['mode'], ['0', '1'])) goto set_mode; + + $this->ave->clear(); + $line = $this->ave->get_input(" Folders: "); + if($line == '#') return false; + $folders = $this->ave->get_input_folders($line); + + $keywords = []; + if($this->params['mode'] == '0'){ + $this->ave->echo(" Put numbers how much keywords you want remove"); + + $quantity = $this->ave->get_input_integer(" Quantity: "); + if(!$quantity) return false; + + for($i = 0; $i < $quantity; $i++){ + $keywords[$i] = $this->ave->get_input_no_trim(" Keyword ".($i+1).": "); + } + } else if($this->params['mode'] == '1'){ + set_keyword_file: + $line = $this->ave->get_input(" Keywords file: "); + if($line == '#') return false; + $line = $this->ave->get_input_folders($line); + if(!isset($line[0])) goto set_keyword_file; + $input = $line[0]; + + if(!file_exists($input) || is_dir($input)){ + $this->ave->echo(" Invalid keywords file"); + goto set_keyword_file; + } + + $fp = fopen($input, 'r'); + if(!$fp){ + $this->ave->echo(" Failed open keywords file"); + goto set_keyword_file; + } + while(($line = fgets($fp)) !== false){ + $line = str_replace(["\n", "\r", "\xEF\xBB\xBF"], "", $line); + if(empty(trim($line))) continue; + array_push($keywords, $line); + } + fclose($fp); + } + + $this->ave->setup_folders($folders); + $errors = 0; + $this->ave->set_errors($errors); + foreach($folders as $folder){ + if(!file_exists($folder)) continue; + $files = $this->ave->get_folders($folder); + $items = 0; + $total = count($files); + foreach($files as $file){ + $items++; + if(!file_exists($file)) continue 1; + $name = trim(str_replace($keywords, '', pathinfo($file, PATHINFO_BASENAME))); + $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/$name"); + if(empty($new_name)){ + $this->ave->write_error("ESCAPED NAME IS EMPTY \"$file\""); + $errors++; + } else if(file_exists($new_name) && strtoupper($new_name) != strtoupper($file)){ + $this->ave->write_error("DUPLICATE \"$file\" AS \"$new_name\""); + $errors++; + } else { + if(!$this->ave->rename($file, $new_name)){ + $errors++; + } + } + $this->ave->progress($items, $total); + $this->ave->set_errors($errors); + } + $this->ave->progress($items, $total); + $this->ave->set_folder_done($folder); + } + + $this->ave->open_logs(true); + $this->ave->pause(" Operation done, press any key to back to menu"); + return false; + } + + public function ToolInsertStringIntoDirectoryName() : bool { + $this->ave->set_subtool("Insert string into directory name"); + + set_offset: + $this->ave->clear(); + $this->ave->print_help([ + ' Specify the string offset where you want insert into directory name', + ' Offset = 0 - means the beginning, i.e. the string will be inserted before the directory name (prefix)', + ' Offset > 0 - means that the string will be inserted after skipping N characters', + ' Offset < 0 - means that the string will be inserted after skipping N characters from the end', + ]); + $line = $this->ave->get_input(" Offset: "); + if($line == '#') return false; + $offset = preg_replace("/[^0-9\-]/", '', $line); + if($offset == '') goto set_offset; + $offset = intval($offset); + + $this->ave->print_help([ + ' Specify the string you want to inject the file name, may contain spaces', + ]); + $insert_string = $this->ave->get_input_no_trim(" String: "); + + $this->ave->clear(); + $line = $this->ave->get_input(" Folders: "); + if($line == '#') return false; + $folders = $this->ave->get_input_folders($line); + + $this->ave->setup_folders($folders); + $errors = 0; + $this->ave->set_errors($errors); + foreach($folders as $folder){ + if(!file_exists($folder)) continue; + $files = $this->ave->get_folders($folder); + $items = 0; + $total = count($files); + foreach($files as $file){ + $items++; + if(!file_exists($file)) continue 1; + $name = pathinfo($file, PATHINFO_BASENAME); + if(abs($offset) > strlen($name)){ + $this->ave->write_error("ILLEGAL OFFSET FOR FILE NAME \"$file\""); + $errors++; + } else { + if($offset > 0){ + $name = substr($name, 0, $offset).$insert_string.substr($name, $offset); + } else if($offset < 0){ + $name = substr($name, 0, strlen($name) + $offset).$insert_string.substr($name, $offset); + } else { + $name = $insert_string.$name; + } + $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/$name"); + if(file_exists($new_name) && strtoupper($new_name) != strtoupper($file)){ + $this->ave->write_error("DUPLICATE \"$file\" AS \"$new_name\""); + $errors++; + } else { + if(!$this->ave->rename($file, $new_name)){ + $errors++; + } + } + } + $this->ave->progress($items, $total); + $this->ave->set_errors($errors); + } + $this->ave->progress($items, $total); + $this->ave->set_folder_done($folder); + } + + $this->ave->open_logs(true); + $this->ave->pause(" Operation done, press any key to back to menu"); + return false; + } + + public function ToolReplaceKeywordsInDirectoryName() : bool { + $this->ave->clear(); + $this->ave->set_subtool("Replace keywords in directory name"); + + $line = $this->ave->get_input(" Folders: "); + if($line == '#') return false; + $folders = $this->ave->get_input_folders($line); + + set_keyword_file: + $replacements = []; + $line = $this->ave->get_input(" Keywords file: "); + if($line == '#') return false; + $line = $this->ave->get_input_folders($line); + if(!isset($line[0])) goto set_keyword_file; + $input = $line[0]; + + if(!file_exists($input) || is_dir($input)){ + $this->ave->echo(" Invalid keywords file"); + goto set_keyword_file; + } + + $fp = fopen($input, 'r'); + if(!$fp){ + $this->ave->echo(" Failed open keywords file"); + goto set_keyword_file; + } + $i = 0; + $errors = 0; + while(($line = fgets($fp)) !== false){ + $i++; + $line = str_replace(["\n", "\r", "\xEF\xBB\xBF"], "", $line); + if(empty(trim($line))) continue; + $replace = $this->ave->get_input_folders($line, false); + if(!isset($replace[0]) || !isset($replace[1]) || isset($replace[2])){ + $this->ave->echo(" Failed parse replacement in line $i content: '$line'"); + $errors++; + } else { + $replacements[$replace[0]] = $replace[1]; + } + } + fclose($fp); + + if($errors > 0){ + if(!$this->ave->get_confirm(" Errors detected, continue with valid replacement (Y/N): ")) goto set_keyword_file; + } + + $this->ave->setup_folders($folders); + $errors = 0; + $this->ave->set_errors($errors); + foreach($folders as $folder){ + if(!file_exists($folder)) continue; + $files = $this->ave->get_folders($folder); + $items = 0; + $total = count($files); + foreach($files as $file){ + $items++; + if(!file_exists($file)) continue 1; + $name = trim(str_replace(array_keys($replacements), $replacements, pathinfo($file, PATHINFO_BASENAME))); + $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/$name"); + if(empty($new_name)){ + $this->ave->write_error("ESCAPED NAME IS EMPTY \"$file\""); + $errors++; + } else if(file_exists($new_name) && strtoupper($new_name) != strtoupper($file)){ + $this->ave->write_error("DUPLICATE \"$file\" AS \"$new_name\""); + $errors++; + } else { + if(!$this->ave->rename($file, $new_name)){ + $errors++; + } + } + $this->ave->progress($items, $total); + $this->ave->set_errors($errors); + } + $this->ave->progress($items, $total); + $this->ave->set_folder_done($folder); + } + + $this->ave->open_logs(true); + $this->ave->pause(" Operation done, press any key to back to menu"); + return false; + } + +} + +?> diff --git a/includes/tools/FileEditor.php b/includes/tools/FileEditor.php index dc7bd6b..d67c202 100644 --- a/includes/tools/FileEditor.php +++ b/includes/tools/FileEditor.php @@ -11,7 +11,6 @@ class FileEditor { private string $name = "File Editor"; - private array $params = []; private string $action; private AVE $ave; @@ -510,16 +509,16 @@ public function ToolPrettyFileContent() : bool { ]; $converter = new StringConverter(); if($flags->language_replace){ - $converter->importReplacement($this->ave->get_file_path($this->ave->path."/includes/data/LanguageReplacement.ini")); + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/LanguageReplacement.ini")); } if($flags->ChineseToPinYin){ - $converter->importPinYin($this->ave->get_file_path($this->ave->path."/includes/data/PinYin.ini")); + $converter->import_pin_yin($this->ave->get_file_path($this->ave->path."/includes/data/PinYin.ini")); } if($flags->HiragamaToRomaji){ - $converter->importReplacement($this->ave->get_file_path($this->ave->path."/includes/data/Hiragama.ini")); + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/Hiragama.ini")); } if($flags->KatakanaToRomaji){ - $converter->importReplacement($this->ave->get_file_path($this->ave->path."/includes/data/Katakana.ini")); + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/Katakana.ini")); } $this->ave->clear(); @@ -565,7 +564,7 @@ public function ToolPrettyFileContent() : bool { $content = $converter->clean($content); } if($flags->ChineseToPinYin){ - $content = $converter->stringToPinYin($content); + $content = $converter->string_to_pin_yin($content); } if($flags->UpperCase){ $content = mb_strtoupper($content); diff --git a/includes/tools/FileFunctions.php b/includes/tools/FileFunctions.php index 8ce8d00..ffc435a 100644 --- a/includes/tools/FileFunctions.php +++ b/includes/tools/FileFunctions.php @@ -9,7 +9,6 @@ class FileFunctions { private string $name = "File Functions"; - private array $params = []; private string $action; private AVE $ave; @@ -48,7 +47,7 @@ public function action(string $action) : bool { } public function ToolAntiDuplicates() : bool { - $this->ave->set_subtool("AntiDuplicates"); + $this->ave->set_subtool("Anti duplicates"); set_mode: $this->ave->clear(); @@ -137,7 +136,7 @@ public function ToolAntiDuplicates() : bool { } public function ToolValidateCheckSum() : bool { - $this->ave->set_subtool("ValidateCheckSum"); + $this->ave->set_subtool("Validate checksum"); set_mode: $this->ave->clear(); @@ -237,7 +236,7 @@ public function ToolValidateCheckSum() : bool { } public function ToolRandomFileGenerator() : bool { - $this->ave->set_subtool("RandomFileGenerator"); + $this->ave->set_subtool("Random file generator"); $write_buffer = $this->ave->get_write_buffer(); if(!$write_buffer) return false; @@ -365,7 +364,7 @@ public function ToolRandomFileGenerator() : bool { public function ToolOverwriteFoldersContent() : bool { $this->ave->clear(); - $this->ave->set_subtool("OverwriteFoldersContent"); + $this->ave->set_subtool("Overwrite folders content"); $write_buffer = $this->ave->get_write_buffer(); if(!$write_buffer) return false; @@ -430,7 +429,7 @@ public function ToolOverwriteFoldersContent() : bool { public function ToolMoveFilesWithStructure() : bool { $this->ave->clear(); - $this->ave->set_subtool("MoveFilesWithStructure"); + $this->ave->set_subtool("Move files with structure"); set_input: $line = $this->ave->get_input(" Input: "); @@ -509,7 +508,7 @@ public function ToolMoveFilesWithStructure() : bool { public function ToolCopyFilesWithStructure() : bool { $this->ave->clear(); - $this->ave->set_subtool("CopyFilesWithStructure"); + $this->ave->set_subtool("Copy files with structure"); set_input: $line = $this->ave->get_input(" Input: "); @@ -587,7 +586,7 @@ public function ToolCopyFilesWithStructure() : bool { } public function ToolCloneFilesWithStructure() : bool { - $this->ave->set_subtool("CloneFilesWithStructure"); + $this->ave->set_subtool("Clone files with structure"); set_mode: $this->ave->clear(); diff --git a/includes/tools/FileNamesEditor.php b/includes/tools/FileNamesEditor.php index 20702d5..a1781b9 100644 --- a/includes/tools/FileNamesEditor.php +++ b/includes/tools/FileNamesEditor.php @@ -11,7 +11,6 @@ class FileNamesEditor { private string $name = "File Names Editor"; - private array $params = []; private string $action; private AVE $ave; @@ -62,7 +61,7 @@ public function action(string $action) : bool { } public function ToolCheckSum() : bool { - $this->ave->set_subtool("CheckSum"); + $this->ave->set_subtool("Checksum"); set_mode: $this->ave->clear(); @@ -326,7 +325,7 @@ public function ToolNumberActionGroup() : bool { } public function ToolVideoGenerator() : bool { - $this->ave->set_subtool("VideoGenerator"); + $this->ave->set_subtool("Video generator"); set_mode: $this->ave->clear(); @@ -389,7 +388,7 @@ public function ToolVideoGenerator() : bool { $hash = null; } if($this->params['resolution'] && in_array($extension, $video_extensions)){ - $resolution = $media->getVideoResolution($file); + $resolution = $media->get_video_resolution($file); if($resolution == '0x0'){ $this->ave->write_error("FAILED GET MEDIA RESOLUTION \"$file\""); $errors++; @@ -400,7 +399,7 @@ public function ToolVideoGenerator() : bool { } } if($this->params['thumbnail'] && in_array($extension, $video_extensions)){ - $thumbnail = $media->getVideoThumbnail($file, $directory, $this->ave->config->get('AVE_THUMBNAIL_WIDTH'), $this->ave->config->get('AVE_THUMBNAIL_ROWS'), $this->ave->config->get('AVE_THUMBNAIL_COLUMN')); + $thumbnail = $media->get_video_thumbnail($file, $directory, $this->ave->config->get('AVE_THUMBNAIL_WIDTH'), $this->ave->config->get('AVE_THUMBNAIL_ROWS'), $this->ave->config->get('AVE_THUMBNAIL_COLUMN')); if($thumbnail){ $this->ave->write_log("GENERATE THUMBNAIL \"$file.webp\""); } else { @@ -460,7 +459,7 @@ public function ToolVideoGenerator() : bool { public function ToolGenerateSeriesName() : bool { $this->ave->clear(); - $this->ave->set_subtool("GenerateSeriesName"); + $this->ave->set_subtool("Generate series name"); $line = $this->ave->get_input(" Folders: "); if($line == '#') return false; $folders = $this->ave->get_input_folders($line); @@ -523,7 +522,7 @@ public function ToolGenerateSeriesName() : bool { public function ToolEscapeFileNameWWW() : bool { $this->ave->clear(); - $this->ave->set_subtool("EscapeFileNameWWW"); + $this->ave->set_subtool("Escape file name WWW"); $this->ave->print_help([ " Double spaces reduce", " Characters after escape: A-Z a-z 0-9 _ - .", @@ -548,7 +547,6 @@ public function ToolEscapeFileNameWWW() : bool { $escaped_name = str_replace(' ', ' ', $escaped_name); } $escaped_name = trim(preg_replace('/[^A-Za-z0-9_\-.]/', '', str_replace(' ', '_', $escaped_name)), ' '); - if(empty($escaped_name)){ $this->ave->write_error("ESCAPED NAME IS EMPTY \"$file\""); $errors++; @@ -579,7 +577,7 @@ public function ToolEscapeFileNameWWW() : bool { public function ToolPrettyFileName() : bool { $this->ave->clear(); - $this->ave->set_subtool("PrettyFileName"); + $this->ave->set_subtool("Pretty file name"); set_mode: $this->ave->clear(); @@ -611,16 +609,16 @@ public function ToolPrettyFileName() : bool { ]; $converter = new StringConverter(); if($flags->language_replace){ - $converter->importReplacement($this->ave->get_file_path($this->ave->path."/includes/data/LanguageReplacement.ini")); + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/LanguageReplacement.ini")); } if($flags->ChineseToPinYin){ - $converter->importPinYin($this->ave->get_file_path($this->ave->path."/includes/data/PinYin.ini")); + $converter->import_pin_yin($this->ave->get_file_path($this->ave->path."/includes/data/PinYin.ini")); } if($flags->HiragamaToRomaji){ - $converter->importReplacement($this->ave->get_file_path($this->ave->path."/includes/data/Hiragama.ini")); + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/Hiragama.ini")); } if($flags->KatakanaToRomaji){ - $converter->importReplacement($this->ave->get_file_path($this->ave->path."/includes/data/Katakana.ini")); + $converter->import_replacement($this->ave->get_file_path($this->ave->path."/includes/data/Katakana.ini")); } $this->ave->clear(); @@ -665,7 +663,7 @@ public function ToolPrettyFileName() : bool { $escaped_name = $converter->clean($escaped_name); } if($flags->ChineseToPinYin){ - $escaped_name = $converter->stringToPinYin($escaped_name); + $escaped_name = $converter->string_to_pin_yin($escaped_name); } if($flags->UpperCase){ $escaped_name = mb_strtoupper($escaped_name); @@ -703,7 +701,7 @@ public function ToolPrettyFileName() : bool { public function ToolRemoveYouTubeQualityTag() : bool { $this->ave->clear(); - $this->ave->set_subtool("RemoveYouTubeQualityTag"); + $this->ave->set_subtool("Remove YouTube quality tag"); $line = $this->ave->get_input(" Folders: "); if($line == '#') return false; $folders = $this->ave->get_input_folders($line); @@ -770,7 +768,7 @@ public function ToolRemoveYouTubeQualityTag() : bool { } public function ToolSeriesEpisodeEditor() : bool { - $this->ave->set_subtool("SeriesEpisodeEditor"); + $this->ave->set_subtool("Series episode editor"); set_mode: $this->ave->clear(); @@ -797,11 +795,11 @@ public function ToolSeriesEpisodeEditor() : bool { public function ToolSeriesEpisodeEditorActionSeason() : bool { $this->ave->clear(); - $this->ave->set_subtool("SeriesEpisodeEditor > ChangeSeason"); + $this->ave->set_subtool("Series episode editor > Change season"); set_input: $this->ave->print_help([ - " Attention filename must begin with the season and episode number in the format:", + " Attention file name must begin with the season and episode number in the format:", " \"S00E00{whatever}.{extension}\"", " \"S00E000{whatever}.{extension}\"", ]); @@ -876,11 +874,11 @@ public function ToolSeriesEpisodeEditorActionSeason() : bool { public function ToolSeriesEpisodeEditorActionEpisode() : bool { $this->ave->clear(); - $this->ave->set_subtool("SeriesEpisodeEditor > ChangeEpisodeNumbers"); + $this->ave->set_subtool("Series episode editor > Change episode"); set_input: $this->ave->print_help([ - " Attention filename must begin with the season and episode number in the format:", + " Attention file name must begin with the season and episode number in the format:", " \"S00E00{whatever}.{extension}\"", " \"S00E000{whatever}.{extension}\"", ]); @@ -993,7 +991,7 @@ public function ToolSeriesEpisodeEditorActionEpisode() : bool { public function ToolAddFileNamePrefixSuffix() : bool { $this->ave->clear(); - $this->ave->set_subtool("AddFileNamePrefixSuffix"); + $this->ave->set_subtool("Add file name prefix/suffix"); $line = $this->ave->get_input(" Folders: "); if($line == '#') return false; @@ -1050,7 +1048,7 @@ public function ToolAddFileNamePrefixSuffix() : bool { public function ToolRemoveKeywordsFromFileName() : bool { $this->ave->clear(); - $this->ave->set_subtool("RemoveKeywordsFromFileName"); + $this->ave->set_subtool("Remove keywords from file name"); set_mode: $this->ave->clear(); @@ -1067,7 +1065,7 @@ public function ToolRemoveKeywordsFromFileName() : bool { 'mode' => strtolower($line[0] ?? '?'), ]; - if(!in_array($this->params['mode'],['0','1'])) goto set_mode; + if(!in_array($this->params['mode'], ['0', '1'])) goto set_mode; $this->ave->clear(); $line = $this->ave->get_input(" Folders: "); @@ -1156,12 +1154,12 @@ public function ToolRemoveKeywordsFromFileName() : bool { } public function ToolInsertStringIntoFileName() : bool { - $this->ave->set_subtool("InsertStringIntoFileName"); + $this->ave->set_subtool("Insert string into file name"); set_offset: $this->ave->clear(); $this->ave->print_help([ - ' Specify the string offset where you want insert into filename', + ' Specify the string offset where you want insert into file name', ' Offset = 0 - means the beginning, i.e. the string will be inserted before the file name (prefix)', ' Offset > 0 - means that the string will be inserted after skipping N characters', ' Offset < 0 - means that the string will be inserted after skipping N characters from the end', @@ -1173,7 +1171,7 @@ public function ToolInsertStringIntoFileName() : bool { $offset = intval($offset); $this->ave->print_help([ - ' Specify the string you want to inject the filename, may contain spaces', + ' Specify the string you want to inject the file name, may contain spaces', ]); $insert_string = $this->ave->get_input_no_trim(" String: "); @@ -1238,7 +1236,7 @@ public function ToolInsertStringIntoFileName() : bool { public function ToolReplaceKeywordsInFileName() : bool { $this->ave->clear(); - $this->ave->set_subtool("ReplaceKeywordsInFileName"); + $this->ave->set_subtool("Replace keywords in file name"); $line = $this->ave->get_input(" Folders: "); if($line == '#') return false; @@ -1329,12 +1327,11 @@ public function ToolReplaceKeywordsInFileName() : bool { public function ToolExtensionChange() : bool { $this->ave->clear(); - $this->ave->set_subtool("ExtensionChange"); + $this->ave->set_subtool("Extension change"); $line = $this->ave->get_input(" Folders: "); if($line == '#') return false; $folders = $this->ave->get_input_folders($line); - set_extension_old: $extension_old = strtolower($this->ave->get_input(" Extension old: ")); if($extension_old == '#') return false; diff --git a/includes/tools/FtpTools.php b/includes/tools/FtpTools.php index 52742d7..9e64c44 100644 --- a/includes/tools/FtpTools.php +++ b/includes/tools/FtpTools.php @@ -5,16 +5,15 @@ namespace App\Tools; use AVE; -use App\Services\Logs; -use App\Services\IniFile; -use App\Services\AveFtp; +use AveCore\Logs; +use AveCore\IniFile; +use AveCore\FtpService; use FtpClient\FtpClient; use FtpClient\FtpException; class FtpTools { private string $name = "Ftp Tools"; - private array $params = []; private string $action; private string $path; @@ -67,7 +66,7 @@ public function action(string $action) : bool { return false; } - public function getSelectLabel() : void { + public function get_select_label() : void { $this->select_label = []; $i = 0; $files = scandir($this->path); @@ -86,12 +85,12 @@ public function getSelectLabel() : void { } } - public function getConfigPath(string $label) : string { + public function get_config_path(string $label) : string { return $this->ave->get_file_path("$this->path/$label.ini"); } - public function getConfig(string $label) : IniFile { - $config = new IniFile($this->getConfigPath($label), true); + public function get_config(string $label) : IniFile { + $config = new IniFile($this->get_config_path($label), true); return $config; } @@ -112,7 +111,7 @@ public function ToolConfigureConnection() : bool { goto set_label; } - if(file_exists($this->getConfigPath($label))){ + if(file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" already in use"); if(!$this->ave->get_confirm(" Overwrite (Y/N): ")) goto set_label; } @@ -160,7 +159,7 @@ public function ToolConfigureConnection() : bool { } $ftp->close(); - $ini = $this->getConfig($label); + $ini = $this->get_config($label); $ini->update([ 'FTP_HOST' => $auth['host'], 'FTP_USER' => $auth['user'], @@ -179,7 +178,7 @@ public function ToolRemoveConnection() : bool { $this->ave->clear(); $this->ave->set_subtool("RemoveConnection"); - $this->getSelectLabel(); + $this->get_select_label(); set_label: $label = $this->ave->get_input(" Label / ID: "); if($label == '#') return false; @@ -189,7 +188,7 @@ public function ToolRemoveConnection() : bool { goto set_label; } - $path = $this->getConfigPath($label); + $path = $this->get_config_path($label); if(!file_exists($path)){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; @@ -216,7 +215,7 @@ public function ToolShowConnections() : bool { $files = $this->ave->get_files($this->path, ['ini']); foreach($files as $file){ $ini = new IniFile($file); - if($ini->isValid() && $ini->isSet('FTP_HOST')){ + if($ini->is_valid() && $ini->is_set('FTP_HOST')){ $label = pathinfo($file, PATHINFO_FILENAME); $this->ave->echo(" $label".str_repeat(" ",32-strlen($label))." ".$ini->get('FTP_HOST').":".$ini->get('FTP_PORT')."@".$ini->get('FTP_USER')); $cnt++; @@ -235,10 +234,10 @@ public function ToolGetFileList() : bool { $this->ave->clear(); $this->ave->set_subtool("GetFileList"); - $ftp = $this->SetupFTP(" Label / ID: "); + $ftp = $this->setup_ftp(" Label / ID: "); if(!$ftp) return false; - $remote = new AveFtp($ftp); + $remote = new FtpService($ftp); set_output: $line = $this->ave->get_input(" Output: "); @@ -317,7 +316,7 @@ public function ToolGetFileList() : bool { $csv->write(implode($this->ave->config->get('AVE_CSV_SEPARATOR'), $meta)); } } - $this->ave->echo(" Saved results into ".$csv->getPath()); + $this->ave->echo(" Saved results into ".$csv->get_path()); $csv->close(); $ftp->close(); @@ -330,10 +329,10 @@ public function ToolDownloadFiles() : bool { $this->ave->clear(); $this->ave->set_subtool("DownloadFiles"); - $ftp = $this->SetupFTP(" Label / ID: "); + $ftp = $this->setup_ftp(" Label / ID: "); if(!$ftp) return false; - $remote = new AveFtp($ftp); + $remote = new FtpService($ftp); set_input: $input = $this->ave->get_input(" FTP folder: "); @@ -421,10 +420,10 @@ public function ToolUploadFiles() : bool { $this->ave->clear(); $this->ave->set_subtool("UploadFiles"); - $ftp = $this->SetupFTP(" Label / ID: "); + $ftp = $this->setup_ftp(" Label / ID: "); if(!$ftp) return false; - $remote = new AveFtp($ftp); + $remote = new FtpService($ftp); set_input: $line = $this->ave->get_input(" Input: "); @@ -532,10 +531,10 @@ public function ToolDeleteFiles() : bool { $this->ave->clear(); $this->ave->set_subtool("DeleteFiles"); - $ftp = $this->SetupFTP(" Label / ID: "); + $ftp = $this->setup_ftp(" Label / ID: "); if(!$ftp) return false; - $remote = new AveFtp($ftp); + $remote = new FtpService($ftp); set_input: $input = $this->ave->get_input(" FTP folder: "); @@ -604,10 +603,10 @@ public function ToolDeleteEmptyFolders() : bool { $this->ave->clear(); $this->ave->set_subtool("DeleteEmptyFolders"); - $ftp = $this->SetupFTP(" Label / ID: "); + $ftp = $this->setup_ftp(" Label / ID: "); if(!$ftp) return false; - $remote = new AveFtp($ftp); + $remote = new FtpService($ftp); set_input: $input = $this->ave->get_input(" FTP folder: "); @@ -632,7 +631,7 @@ public function ToolDeleteEmptyFolders() : bool { $this->ave->set_errors($errors); foreach($files as $file){ $items++; - if(!$remote->hasFiles($file)){ + if(!$remote->has_files($file)){ if($ftp->rmdir($file, false)){ $this->ave->write_log("DELETE \"$file\""); } else { @@ -654,10 +653,10 @@ public function ToolDeleteStructure() : bool { $this->ave->clear(); $this->ave->set_subtool("DeleteStructure"); - $ftp = $this->SetupFTP(" Label / ID: "); + $ftp = $this->setup_ftp(" Label / ID: "); if(!$ftp) return false; - $remote = new AveFtp($ftp); + $remote = new FtpService($ftp); set_input: $input = $this->ave->get_input(" FTP folder: "); @@ -701,7 +700,7 @@ public function ToolDeleteStructure() : bool { $this->ave->set_errors($errors); foreach($files as $file){ $items++; - if(!$remote->hasFiles($file)){ + if(!$remote->has_files($file)){ if($ftp->rmdir($file, false)){ $this->ave->write_log("DELETE \"$file\""); } else { @@ -723,17 +722,17 @@ public function ToolCopyFilesFromFTPToFTP() : bool { $this->ave->clear(); $this->ave->set_subtool("CopyFilesFromFTPToFTP"); - $ftp_source = $this->SetupFTP(" Source label / ID: "); + $ftp_source = $this->setup_ftp(" Source label / ID: "); if(!$ftp_source) return false; - $ftp_destination = $this->SetupFTP(" Destination label / ID: ", false); + $ftp_destination = $this->setup_ftp(" Destination label / ID: ", false); if(!$ftp_destination){ $ftp_source->close(); return false; } - $remote_source = new AveFtp($ftp_source); - $remote_destination = new AveFtp($ftp_destination); + $remote_source = new FtpService($ftp_source); + $remote_destination = new FtpService($ftp_destination); set_input: $input = $this->ave->get_input(" FTP input: "); @@ -918,7 +917,7 @@ public function ToolImportFileZillaXML() : bool { $label = substr(preg_replace("/[^A-Za-z0-9_\-]/", '', str_replace(" ", "_", trim($server['Name']))), 0, 32); if(strlen($label) < 3) substr($label."___", 0, 3); if($this->ave->is_valid_label($label)){ - $ini = $this->getConfig($label); + $ini = $this->get_config($label); $ini->update([ 'FTP_HOST' => $server['Host'], 'FTP_USER' => $server['User'], @@ -939,8 +938,8 @@ public function ToolImportFileZillaXML() : bool { return false; } - public function SetupFTP(string $name, bool $print = true) : FtpClient|bool { - if($print) $this->getSelectLabel(); + public function setup_ftp(string $name, bool $print = true) : FtpClient|bool { + if($print) $this->get_select_label(); set_label: $label = $this->ave->get_input($name); if($label == '#') return false; @@ -950,12 +949,12 @@ public function SetupFTP(string $name, bool $print = true) : FtpClient|bool { goto set_label; } - if(!file_exists($this->getConfigPath($label))){ + if(!file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; } - $ini = $this->getConfig($label); + $ini = $this->get_config($label); $ftp = new FtpClient(); try { diff --git a/includes/tools/MediaSorter.php b/includes/tools/MediaSorter.php index bde19f3..074585d 100644 --- a/includes/tools/MediaSorter.php +++ b/includes/tools/MediaSorter.php @@ -10,7 +10,6 @@ class MediaSorter { private string $name = "Media Sorter"; - private array $params = []; private string $action; private AVE $ave; @@ -129,9 +128,9 @@ public function ToolSortMediaQuality() : bool { if(!file_exists($file)) continue 1; $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if(in_array($extension, $image_extensions)){ - $resolution = $media->getImageResolution($file); + $resolution = $media->get_image_resolution($file); } else { - $resolution = $media->getVideoResolution($file); + $resolution = $media->get_video_resolution($file); } if($resolution == '0x0'){ $this->ave->write_error("FAILED GET MEDIA RESOLUTION \"$file\""); @@ -140,8 +139,8 @@ public function ToolSortMediaQuality() : bool { continue 1; } $size = explode("x", $resolution); - $quality = $media->getMediaQuality(intval($size[0]), intval($size[1]), in_array($extension, $video_extensions)).$this->ave->config->get('AVE_QUALITY_SUFFIX'); - $orientation_name = $media->getMediaOrientationName($media->getMediaOrientation(intval($size[0]), intval($size[1]))); + $quality = $media->get_media_quality(intval($size[0]), intval($size[1]), in_array($extension, $video_extensions)).$this->ave->config->get('AVE_QUALITY_SUFFIX'); + $orientation_name = $media->get_media_orientation_name($media->get_media_orientation(intval($size[0]), intval($size[1]))); if($this->params['resolution'] && $this->params['quality']){ $directory = "$folder/$orientation_name/$quality"; } else if($this->params['resolution']){ @@ -186,7 +185,7 @@ public function ToolSortGifAnimated() : bool { foreach($files as $file){ $items++; if(!file_exists($file)) continue 1; - if($media->isGifAnimated($file)){ + if($media->is_gif_animated($file)){ $directory = "$folder/Animated"; } else { $directory = "$folder/NotAnimated"; @@ -323,11 +322,11 @@ public function ToolSortImagesColor() : bool { foreach($files as $file){ $items++; if(!file_exists($file)) continue 1; - $colors = $media->getImageColorCount($file); + $colors = $media->get_image_color_count($file); if(is_null($colors)){ $group = 'Unknown'; } else { - $group = $media->getImageColorGroup($colors); + $group = $media->get_image_color_group($colors); } $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/$group/".pathinfo($file, PATHINFO_BASENAME)); if(!$this->ave->rename($file, $new_name)){ @@ -448,14 +447,14 @@ public function ToolSortMediaDuration() : bool { foreach($files as $file){ $items++; if(!file_exists($file)) continue 1; - $duration = $media->getVideoDurationSeconds($file); + $duration = $media->get_video_duration_seconds($file); $multiplier = floor($duration / $interval); if($multiplier == 0){ $start = '00_00'; } else { - $start = str_replace(":", "_", $media->SecToTime(intval($interval * $multiplier) + 1)); + $start = str_replace(":", "_", $media->sec_to_time(intval($interval * $multiplier) + 1)); } - $end = str_replace(":", "_", $media->SecToTime(intval($interval * ($multiplier + 1)))); + $end = str_replace(":", "_", $media->sec_to_time(intval($interval * ($multiplier + 1)))); $directory = "$folder/$start - $end"; $new_name = $this->ave->get_file_path("$directory/".pathinfo($file, PATHINFO_BASENAME)); if($this->ave->rename($file, $new_name)){ diff --git a/includes/tools/MediaTools.php b/includes/tools/MediaTools.php index cb35ad5..336f7d5 100644 --- a/includes/tools/MediaTools.php +++ b/includes/tools/MediaTools.php @@ -7,15 +7,14 @@ use AVE; use Imagick; use Exception; -use App\Services\Logs; -use App\Services\IniFile; +use AveCore\Logs; +use AveCore\IniFile; use App\Services\MediaFunctions; use App\Services\FaceDetector; class MediaTools { private string $name = "Media Tools"; - private array $params = []; private string $action; private AVE $ave; @@ -32,7 +31,8 @@ public function help() : void { ' 1 - Merge: Video + SRT', ' 2 - Avatar generator', ' 3 - Video: Fetch media info', - ' 4 - Image converter' + ' 4 - Image converter', + ' 5 - Ident mime type: Images', ]); } @@ -45,6 +45,7 @@ public function action(string $action) : bool { case '2': return $this->ToolAvatarGenerator(); case '3': return $this->ToolVideoFetchMediaInfo(); case '4': return $this->ToolImageConverter(); + case '5': return $this->ToolIdentMimeType(); } return false; } @@ -274,19 +275,19 @@ public function ToolAvatarGenerator() : bool { } } if(file_exists($directory)){ - $image = $media->getImageFromPath($file); + $image = $media->get_image_from_path($file); if(is_null($image)){ $this->ave->write_error("FAILED LOAD IMAGE \"$file\""); $errors++; } else { - $face = $detector->faceDetect($image); + $face = $detector->face_detect($image); if(!$face){ $this->ave->write_error("FAILED GET FACE \"$file\""); $errors++; } else { foreach($variants as $variant){ $new_name = $this->ave->get_file_path("$directory/".pathinfo($file, PATHINFO_FILENAME)."@$variant.".pathinfo($file, PATHINFO_EXTENSION)); - if($detector->saveVariantImage(floatval($variant), $file, $new_name, $size)){ + if($detector->save_variant_image(floatval($variant), $file, $new_name, $size)){ $this->ave->write_log("WRITE VARIANT $variant FOR \"$file\""); } } @@ -351,7 +352,7 @@ public function ToolVideoFetchMediaInfo() : bool { $this->ave->set_errors($errors); if(!file_exists($file)) continue; $key = hash('md5', str_ireplace($input, '', $file)); - if($cache->isSet($key)){ + if($cache->is_set($key)){ $media_info = $cache->get($key); $resolution = $media_info['resolution']; $quality = $media_info['quality']; @@ -367,20 +368,20 @@ public function ToolVideoFetchMediaInfo() : bool { } } else { $new++; - $resolution = $media->getVideoResolution($file); + $resolution = $media->get_video_resolution($file); if($resolution == '0x0'){ $this->ave->write_error("FAILED GET MEDIA RESOLUTION \"$file\""); $errors++; continue; } $size = explode('x', $resolution); - $orientation = $media->getMediaOrientation(intval($size[0]), intval($size[1])); - $quality = $media->getMediaQuality(intval($size[0]), intval($size[1]), true).$this->ave->config->get('AVE_QUALITY_SUFFIX'); - $duration = $media->getVideoDuration($file); + $orientation = $media->get_media_orientation(intval($size[0]), intval($size[1])); + $quality = $media->get_media_quality(intval($size[0]), intval($size[1]), true).$this->ave->config->get('AVE_QUALITY_SUFFIX'); + $duration = $media->get_video_duration($file); $file_size = $this->ave->format_bytes(filesize($file)); - $orientation_name = $media->getMediaOrientationName($orientation); - $fps = $media->getVideoFPS($file); - $codec = $media->getVideoCodec($file); + $orientation_name = $media->get_media_orientation_name($orientation); + $fps = $media->get_video_fps($file); + $codec = $media->get_video_codec($file); if(file_exists("$file.md5")){ $checksum = file_get_contents("$file.md5"); } else if($generate_checksum){ @@ -422,9 +423,9 @@ public function ToolVideoFetchMediaInfo() : bool { } $this->ave->progress($items, $total); $this->ave->set_errors($errors); - $this->ave->echo(" Saved results into ".$csv->getPath()); + $this->ave->echo(" Saved results into ".$csv->get_path()); $csv->close(); - $cache->setAll($cache->only($keys)); + $cache->set_all($cache->only($keys)); $cache->update(['.LAST_UPDATE' => date('Y-m-d H:i:s')], true); $cache->close(); @@ -575,6 +576,56 @@ public function ToolImageConverter() : bool { return false; } + public function ToolIdentMimeType() : bool { + $this->ave->clear(); + $this->ave->set_subtool("Ident mime type"); + if(!$this->ave->windows) return $this->ave->windows_only(); + + $line = $this->ave->get_input(" Folders: "); + if($line == '#') return false; + $folders = $this->ave->get_input_folders($line); + $this->ave->setup_folders($folders); + + $errors = 0; + $this->ave->set_errors($errors); + $image_extensions = explode(" ", $this->ave->config->get('AVE_EXTENSIONS_PHOTO')); + array_push($image_extensions, ''); + $media = new MediaFunctions($this->ave); + foreach($folders as $folder){ + if(!file_exists($folder)) continue; + $files = $this->ave->get_files($folder, $image_extensions); + $items = 0; + $total = count($files); + foreach($files as $file){ + $items++; + if(!file_exists($file)) continue 1; + $extension_current = strtolower(pathinfo($file, PATHINFO_EXTENSION)); + $extension_detected = $media->get_extension_by_mime_type($file); + if(!$extension_detected){ + $this->ave->write_error("FAILED DETECT IMAGE TYPE \"$new_name\""); + $errors++; + continue 1; + } + if($extension_current != $extension_detected){ + $new_name = $this->ave->get_file_path(pathinfo($file, PATHINFO_DIRNAME)."/".pathinfo($file, PATHINFO_FILENAME).".".$extension_detected); + if(!$this->ave->rename($file, $new_name)){ + $errors++; + } + } + $this->ave->progress($items, $total); + $this->ave->set_errors($errors); + } + $this->ave->progress($items, $total); + unset($files); + $this->ave->set_folder_done($folder); + } + + + $this->ave->open_logs(true); + $this->ave->pause(" Operation done, press any key to back to menu"); + return false; + } + } ?> diff --git a/includes/tools/MySQLTools.php b/includes/tools/MySQLTools.php index cf15b70..f2716e7 100644 --- a/includes/tools/MySQLTools.php +++ b/includes/tools/MySQLTools.php @@ -7,20 +7,18 @@ use AVE; use PDO; use PDOException; -use App\Services\IniFile; +use AveCore\IniFile; +use AveCore\Request; +use AveCore\MySQL; use App\Services\DataBaseBackup; -use App\Services\DataBase; -use App\Services\Request; class MySQLTools { private string $name = "MySQL Tools"; - private array $params = []; private string $action; private string $path; private AVE $ave; - private $select_label = []; public function __construct(AVE $ave){ @@ -78,7 +76,7 @@ public function action(string $action) : bool { return false; } - public function getSelectLabel() : void { + public function get_select_label() : void { $this->select_label = []; $i = 0; $files = scandir($this->path); @@ -97,12 +95,12 @@ public function getSelectLabel() : void { } } - public function getConfigPath(string $label) : string { + public function get_config_path(string $label) : string { return $this->ave->get_file_path("$this->path/$label.ini"); } - public function getConfig(string $label) : IniFile { - $config = new IniFile($this->getConfigPath($label), true); + public function get_config(string $label) : IniFile { + $config = new IniFile($this->get_config_path($label), true); $this->checkConfig($config); return $config; } @@ -124,7 +122,7 @@ private function SelectDataBase(PDO $connection, ?DataBaseBackup $backup = null) if($database == '#') return false; if(!isset($options[$database])) goto select_database; $connection->query("USE ".$options[$database]); - if(!is_null($backup)) $backup->setDataBase($options[$database]); + if(!is_null($backup)) $backup->set_data_base($options[$database]); return true; } @@ -151,7 +149,7 @@ public function ToolConfigureConnection() : bool { goto set_label; } - if(file_exists($this->getConfigPath($label))){ + if(file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" already in use"); if(!$this->ave->get_confirm(" Overwrite (Y/N): ")) goto set_label; } @@ -214,7 +212,7 @@ public function ToolConfigureConnection() : bool { $backup['compress'] = $this->ave->get_confirm(" Compress after backup (Y/N): "); $backup['lock_tables'] = $this->ave->get_confirm(" Lock tables during background backup (Y/N): "); - $ini = $this->getConfig($label); + $ini = $this->get_config($label); $ini->update([ 'DB_HOST' => $db['host'], 'DB_USER' => $db['user'], @@ -241,7 +239,7 @@ public function ToolRemoveConnection() : bool { $this->ave->clear(); $this->ave->set_subtool("RemoveConnection"); - $this->getSelectLabel(); + $this->get_select_label(); set_label: $label = $this->ave->get_input(" Label / ID: "); if($label == '#') return false; @@ -251,7 +249,7 @@ public function ToolRemoveConnection() : bool { goto set_label; } - $path = $this->getConfigPath($label); + $path = $this->get_config_path($label); if(!file_exists($path)){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; @@ -278,7 +276,7 @@ public function ToolShowConnections() : bool { $files = $this->ave->get_files($this->path, ['ini']); foreach($files as $file){ $ini = new IniFile($file); - if($ini->isValid() && $ini->isSet('DB_HOST')){ + if($ini->is_valid() && $ini->is_set('DB_HOST')){ $label = pathinfo($file, PATHINFO_FILENAME); $this->ave->echo(" $label".str_repeat(" ",32-strlen($label))." ".$ini->get('DB_HOST').":".$ini->get('DB_PORT')."@".$ini->get('DB_USER')); $cnt++; @@ -297,7 +295,7 @@ public function ToolMakeBackup() : bool { $this->ave->clear(); $this->ave->set_subtool("MakeBackup"); - $this->getSelectLabel(); + $this->get_select_label(); set_label: $label = $this->ave->get_input(" Label / ID: "); if($label == '#') return false; @@ -307,12 +305,12 @@ public function ToolMakeBackup() : bool { goto set_label; } - if(!file_exists($this->getConfigPath($label))){ + if(!file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; } - $ini = $this->getConfig($label); + $ini = $this->get_config($label); if($ini->get('BACKUP_ADD_LABEL_TO_PATH')){ $path = $this->ave->get_file_path($ini->get('BACKUP_PATH')."/$label"); } else { @@ -337,15 +335,15 @@ public function ToolMakeBackup() : bool { $this->ave->write_log("Initialize backup for \"$label\""); $this->ave->echo(" Initialize backup service"); $backup = new DataBaseBackup($path, $ini->get('BACKUP_QUERY_LIMIT'), $ini->get('BACKUP_INSERT_LIMIT'), $ini->get('FOLDER_DATE_FORMAT')); - $backup->toggleLockTables($lock_tables); + $backup->toggle_lock_tables($lock_tables); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_START'], true); $this->ave->echo(" Connecting to: ".$ini->get('DB_HOST').":".$ini->get('DB_PORT')."@".$ini->get('DB_USER')); if(!$backup->connect($ini->get('DB_HOST'), $ini->get('DB_USER'), $ini->get('DB_PASSWORD'), $ini->get('DB_NAME'), $ini->get('DB_PORT'))) goto set_label; - if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->getSource(), $backup)) return false; + if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->get_source(), $backup)) return false; $this->ave->echo(" Create backup"); - $items = $backup->getTables(); + $items = $backup->get_tables(); $progress = 0; $total = count($items); $this->ave->set_progress_ex('Table', $progress, $total); @@ -354,10 +352,10 @@ public function ToolMakeBackup() : bool { $this->ave->write_log("Create backup for table $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "table:$item"], true); if($ini->get('BACKUP_TYPE_STRUCTURE')){ - $errors_structure = $backup->backupTableStructure($item); + $errors_structure = $backup->backup_table_structure($item); } if($ini->get('BACKUP_TYPE_DATA')){ - $errors_data = $backup->backupTableData($item); + $errors_data = $backup->backup_table_data($item); } $errors = array_merge($errors_structure ?? [], $errors_data ?? []); if(!empty($errors)){ @@ -375,7 +373,7 @@ public function ToolMakeBackup() : bool { } try { - $items = $backup->getViews(); + $items = $backup->get_views(); } catch(PDOException $e){ $items = []; @@ -388,7 +386,7 @@ public function ToolMakeBackup() : bool { $progress++; $this->ave->write_log("Create backup for view $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "view:$item"], true); - $errors = $backup->backupView($item); + $errors = $backup->backup_view($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -404,7 +402,7 @@ public function ToolMakeBackup() : bool { } try { - $items = $backup->getFunctions(); + $items = $backup->get_functions(); } catch(PDOException $e){ $items = []; @@ -417,7 +415,7 @@ public function ToolMakeBackup() : bool { $progress++; $this->ave->write_log("Create backup for function $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "function:$item"], true); - $errors = $backup->backupFunction($item); + $errors = $backup->backup_function($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -433,7 +431,7 @@ public function ToolMakeBackup() : bool { } try { - $items = $backup->getProcedures(); + $items = $backup->get_procedures(); } catch(PDOException $e){ $items = []; @@ -446,7 +444,7 @@ public function ToolMakeBackup() : bool { $progress++; $this->ave->write_log("Create backup for procedure $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "procedure:$item"], true); - $errors = $backup->backupProcedure($item); + $errors = $backup->backup_procedure($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -462,7 +460,7 @@ public function ToolMakeBackup() : bool { } try { - $items = $backup->getEvents(); + $items = $backup->get_events(); } catch(PDOException $e){ $items = []; @@ -475,7 +473,7 @@ public function ToolMakeBackup() : bool { $progress++; $this->ave->write_log("Create backup for event $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "event:$item"], true); - $errors = $backup->backupEvent($item); + $errors = $backup->backup_event($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -491,7 +489,7 @@ public function ToolMakeBackup() : bool { } try { - $items = $backup->getTriggers(); + $items = $backup->get_triggers(); } catch(PDOException $e){ $items = []; @@ -504,7 +502,7 @@ public function ToolMakeBackup() : bool { $progress++; $this->ave->write_log("Create backup for trigger $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "trigger:$item"], true); - $errors = $backup->backupTrigger($item); + $errors = $backup->backup_trigger($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -524,7 +522,7 @@ public function ToolMakeBackup() : bool { if(!is_null($callback)) $request->get($callback, ['maintenance' => false, 'state' => 'BACKUP_END'], true); $backup->disconnect(); - $output = $backup->getOutput(); + $output = $backup->get_output(); if($ini->get('BACKUP_COMPRESS', false)){ $this->compress($callback, $output, $ini->get('BACKUP_PATH'), $request); } else { @@ -541,7 +539,7 @@ public function ToolMakeClone() : bool { reset_connection: $this->ave->clear(); - $this->getSelectLabel(); + $this->get_select_label(); set_label_source: $source = $this->ave->get_input(" Source label / ID: "); if($source == '#') return false; @@ -551,12 +549,12 @@ public function ToolMakeClone() : bool { goto set_label_source; } - if(!file_exists($this->getConfigPath($source))){ + if(!file_exists($this->get_config_path($source))){ $this->ave->echo(" Source label \"$source\" not exists"); goto set_label_source; } - $ini_source = $this->getConfig($source); + $ini_source = $this->get_config($source); if($ini_source->get('BACKUP_ADD_LABEL_TO_PATH')){ $path = $this->ave->get_file_path($ini_source->get('BACKUP_PATH')."/$source"); } else { @@ -576,14 +574,14 @@ public function ToolMakeClone() : bool { $this->ave->write_log("Initialize backup for \"$source\""); $this->ave->echo(" Initialize backup service"); $backup = new DataBaseBackup($path, $ini_source->get('BACKUP_QUERY_LIMIT'), $ini_source->get('BACKUP_INSERT_LIMIT'), $ini_source->get('FOLDER_DATE_FORMAT')); - $backup->toggleLockTables($lock_tables); + $backup->toggle_lock_tables($lock_tables); $this->ave->echo(" Connecting to: ".$ini_source->get('DB_HOST').":".$ini_source->get('DB_PORT')."@".$ini_source->get('DB_USER')); if(!$backup->connect($ini_source->get('DB_HOST'), $ini_source->get('DB_USER'), $ini_source->get('DB_PASSWORD'), $ini_source->get('DB_NAME'), $ini_source->get('DB_PORT'))) goto set_label_source; - if($ini_source->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->getSource(), $backup)) return false; + if($ini_source->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->get_source(), $backup)) return false; $this->ave->clear(); - $this->getSelectLabel(); + $this->get_select_label(); set_label_destination: $destination = $this->ave->get_input(" Destination label: "); if($destination == '#') return false; @@ -593,19 +591,19 @@ public function ToolMakeClone() : bool { goto set_label_destination; } - if(!file_exists($this->getConfigPath($destination))){ + if(!file_exists($this->get_config_path($destination))){ $this->ave->echo(" Destination label \"$destination\" not exists"); goto set_label_destination; } - $ini_dest = $this->getConfig($destination); + $ini_dest = $this->get_config($destination); $this->ave->echo(" Connecting to: ".$ini_dest->get('DB_HOST').":".$ini_dest->get('DB_PORT')."@".$ini_dest->get('DB_USER')); if(!$backup->connect_destination($ini_dest->get('DB_HOST'), $ini_dest->get('DB_USER'), $ini_dest->get('DB_PASSWORD'), $ini_dest->get('DB_NAME'), $ini_dest->get('DB_PORT'))) goto set_label_destination; - if($ini_dest->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->getDestination())) return false; + if($ini_dest->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->get_destination())) return false; - $dbname_source = $this->getDataBase($backup->getSource()); - $dbname_destination = $this->getDataBase($backup->getDestination()); + $dbname_source = $this->getDataBase($backup->get_source()); + $dbname_destination = $this->getDataBase($backup->get_destination()); if($ini_source->get('DB_HOST') == $ini_dest->get('DB_HOST') && $ini_source->get('DB_USER') == $ini_dest->get('DB_USER') && $dbname_source == $dbname_destination && $ini_source->get('DB_PORT') == $ini_dest->get('DB_PORT')){ $backup->disconnect(); @@ -620,7 +618,7 @@ public function ToolMakeClone() : bool { return false; } - if(!$backup->isDestinationEmpty()){ + if(!$backup->is_destination_empty()){ if(!$this->ave->get_confirm(" Output database is not empty, continue (Y/N): ")){ $this->ave->pause(" Clone `$dbname_source` to `$dbname_destination` aborted, press any key to back to menu"); return false; @@ -630,7 +628,7 @@ public function ToolMakeClone() : bool { $this->ave->echo(" Clone `$dbname_source` to `$dbname_destination`"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_START'], true); - $items = $backup->getTables(); + $items = $backup->get_tables(); $progress = 0; $total = count($items); $this->ave->set_progress_ex('Table Structure', $progress, $total); @@ -638,7 +636,7 @@ public function ToolMakeClone() : bool { $progress++; $this->ave->write_log("Clone table Structure $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "table:$item"], true); - $errors = $backup->cloneTableStructure($item); + $errors = $backup->clone_table_structure($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini_source->get('BACKUP_CURL_SEND_ERRORS')){ @@ -660,7 +658,7 @@ public function ToolMakeClone() : bool { $progress++; $this->ave->write_log("Clone table data $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "table:$item"], true); - $errors = $backup->cloneTableData($item); + $errors = $backup->clone_table_data($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini_source->get('BACKUP_CURL_SEND_ERRORS')){ @@ -676,7 +674,7 @@ public function ToolMakeClone() : bool { } try { - $items = $backup->getViews(); + $items = $backup->get_views(); } catch(PDOException $e){ $items = []; @@ -689,7 +687,7 @@ public function ToolMakeClone() : bool { $progress++; $this->ave->write_log("Clone view $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "view:$item"], true); - $errors = $backup->cloneView($item); + $errors = $backup->clone_view($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini_source->get('BACKUP_CURL_SEND_ERRORS')){ @@ -705,7 +703,7 @@ public function ToolMakeClone() : bool { } try { - $items = $backup->getFunctions(); + $items = $backup->get_functions(); } catch(PDOException $e){ $items = []; @@ -718,7 +716,7 @@ public function ToolMakeClone() : bool { $progress++; $this->ave->write_log("Clone function $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "function:$item"], true); - $errors = $backup->cloneFunction($item); + $errors = $backup->clone_function($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini_source->get('BACKUP_CURL_SEND_ERRORS')){ @@ -734,7 +732,7 @@ public function ToolMakeClone() : bool { } try { - $items = $backup->getProcedures(); + $items = $backup->get_procedures(); } catch(PDOException $e){ $items = []; @@ -747,7 +745,7 @@ public function ToolMakeClone() : bool { $progress++; $this->ave->write_log("Clone procedure $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "procedure:$item"], true); - $errors = $backup->cloneProcedure($item); + $errors = $backup->clone_procedure($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini_source->get('BACKUP_CURL_SEND_ERRORS')){ @@ -763,7 +761,7 @@ public function ToolMakeClone() : bool { } try { - $items = $backup->getEvents(); + $items = $backup->get_events(); } catch(PDOException $e){ $items = []; @@ -776,7 +774,7 @@ public function ToolMakeClone() : bool { $progress++; $this->ave->write_log("Clone event $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "event:$item"], true); - $errors = $backup->cloneEvent($item); + $errors = $backup->clone_event($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini_source->get('BACKUP_CURL_SEND_ERRORS')){ @@ -792,7 +790,7 @@ public function ToolMakeClone() : bool { } try { - $items = $backup->getTriggers(); + $items = $backup->get_triggers(); } catch(PDOException $e){ $items = []; @@ -805,7 +803,7 @@ public function ToolMakeClone() : bool { $progress++; $this->ave->write_log("Clone trigger $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "trigger:$item"], true); - $errors = $backup->cloneTrigger($item); + $errors = $backup->clone_trigger($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini_source->get('BACKUP_CURL_SEND_ERRORS')){ @@ -837,12 +835,12 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool return false; } - if(!file_exists($this->getConfigPath($label))){ + if(!file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" not exists"); return false; } - $ini = $this->getConfig($label); + $ini = $this->get_config($label); if($ini->get('BACKUP_ADD_LABEL_TO_PATH')){ $path = $this->ave->get_file_path($ini->get('BACKUP_PATH')."/$label"); } else { @@ -864,7 +862,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool $this->ave->write_log("Initialize backup for \"$label\""); $this->ave->echo(" Initialize backup service"); $backup = new DataBaseBackup($path, $ini->get('BACKUP_QUERY_LIMIT'), $ini->get('BACKUP_INSERT_LIMIT'), $ini->get('FOLDER_DATE_FORMAT')); - $backup->toggleLockTables($ini->get('BACKUP_LOCK_TABLES')); + $backup->toggle_lock_tables($ini->get('BACKUP_LOCK_TABLES')); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_START'], true); $this->ave->echo(" Connecting to: ".$ini->get('DB_HOST').":".$ini->get('DB_PORT')."@".$ini->get('DB_USER')); @@ -872,19 +870,19 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool $this->ave->echo(" Failed connect to database"); return false; } - if($ini->get('DB_NAME') == "*") $backup->getSource()->query("USE $dbname"); + if($ini->get('DB_NAME') == "*") $backup->get_source()->query("USE $dbname"); $this->ave->echo(" Create backup"); - $items = $backup->getTables(); + $items = $backup->get_tables(); foreach($items as $item){ $this->ave->write_log("Create backup for table $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "table:$item"], true); if($ini->get('BACKUP_TYPE_STRUCTURE')){ - $errors_structure = $backup->backupTableStructure($item); + $errors_structure = $backup->backup_table_structure($item); } if($ini->get('BACKUP_TYPE_DATA')){ - $errors_data = $backup->backupTableData($item); + $errors_data = $backup->backup_table_data($item); } $errors = array_merge($errors_structure ?? [], $errors_data ?? []); if(!empty($errors)){ @@ -901,7 +899,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool } try { - $items = $backup->getViews(); + $items = $backup->get_views(); } catch(PDOException $e){ $items = []; @@ -910,7 +908,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool foreach($items as $item){ $this->ave->write_log("Create backup for view $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "view:$item"], true); - $errors = $backup->backupView($item); + $errors = $backup->backup_view($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -925,7 +923,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool } try { - $items = $backup->getFunctions(); + $items = $backup->get_functions(); } catch(PDOException $e){ $items = []; @@ -934,7 +932,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool foreach($items as $item){ $this->ave->write_log("Create backup for function $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "function:$item"], true); - $errors = $backup->backupFunction($item); + $errors = $backup->backup_function($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -949,7 +947,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool } try { - $items = $backup->getProcedures(); + $items = $backup->get_procedures(); } catch(PDOException $e){ $items = []; @@ -958,7 +956,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool foreach($items as $item){ $this->ave->write_log("Create backup for procedure $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "procedure:$item"], true); - $errors = $backup->backupProcedure($item); + $errors = $backup->backup_procedure($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -973,7 +971,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool } try { - $items = $backup->getEvents(); + $items = $backup->get_events(); } catch(PDOException $e){ $items = []; @@ -982,7 +980,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool foreach($items as $item){ $this->ave->write_log("Create backup for event $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "event:$item"], true); - $errors = $backup->backupEvent($item); + $errors = $backup->backup_event($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -997,7 +995,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool } try { - $items = $backup->getTriggers(); + $items = $backup->get_triggers(); } catch(PDOException $e){ $items = []; @@ -1006,7 +1004,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool foreach($items as $item){ $this->ave->write_log("Create backup for trigger $item"); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_TABLE_START', 'table' => "trigger:$item"], true); - $errors = $backup->backupTrigger($item); + $errors = $backup->backup_trigger($item); if(!empty($errors)){ $this->ave->write_error($errors); if($ini->get('BACKUP_CURL_SEND_ERRORS')){ @@ -1025,7 +1023,7 @@ public function ToolMakeBackupCMD(string $label, ?string $dbname = null) : bool if(!is_null($callback)) $request->get($callback, ['maintenance' => false, 'state' => 'BACKUP_END'], true); $backup->disconnect(); - $output = $backup->getOutput(); + $output = $backup->get_output(); if($ini->get('BACKUP_COMPRESS', false)){ $this->compress($callback, $output, $ini->get('BACKUP_PATH'), $request); } else { @@ -1041,7 +1039,7 @@ public function ToolOpenBackupFolder() : bool { $this->ave->clear(); $this->ave->set_subtool("OpenBackupFolder"); - $this->getSelectLabel(); + $this->get_select_label(); set_label: $label = $this->ave->get_input(" Label / ID: "); if($label == '#') return false; @@ -1051,13 +1049,13 @@ public function ToolOpenBackupFolder() : bool { goto set_label; } - $path = $this->getConfigPath($label); + $path = $this->get_config_path($label); if(!file_exists($path)){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; } - $config = $this->getConfig($label); + $config = $this->get_config($label); $this->ave->open_file($this->ave->get_file_path($config->get('BACKUP_PATH')."/$label"), ''); return false; @@ -1067,7 +1065,7 @@ public function ToolMySQLConsole() : bool { $this->ave->clear(); $this->ave->set_subtool("MySQLConsole"); - $this->getSelectLabel(); + $this->get_select_label(); set_label: $label = $this->ave->get_input(" Label / ID: "); if($label == '#') return false; @@ -1077,17 +1075,17 @@ public function ToolMySQLConsole() : bool { goto set_label; } - if(!file_exists($this->getConfigPath($label))){ + if(!file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; } - $ini = $this->getConfig($label); + $ini = $this->get_config($label); - $db = new DataBase(); + $db = new MySQL(); $this->ave->echo(" Connecting to: ".$ini->get('DB_HOST').":".$ini->get('DB_PORT')."@".$ini->get('DB_USER')); if(!$db->connect($ini->get('DB_HOST'), $ini->get('DB_USER'), $ini->get('DB_PASSWORD'), $ini->get('DB_NAME'), $ini->get('DB_PORT'))) goto set_label; - if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($db->getConnection())) return false; + if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($db->get_connection())) return false; $save_output = $this->ave->get_confirm(" Save query results in data file (Y/N): "); if($save_output){ @@ -1121,7 +1119,7 @@ public function ToolMySQLConsole() : bool { if($save_output) $this->ave->write_data([" ".$query, ""]); $sth = $db->query($query); $results = $sth->fetchAll(PDO::FETCH_ASSOC); - $last_insert_id = $db->getConnection()->lastInsertId(); + $last_insert_id = $db->get_connection()->lastInsertId(); if($last_insert_id){ $this->ave->echo(" Last insert id: $last_insert_id"); if($save_output) $this->ave->write_data(" Last insert id: $last_insert_id"); @@ -1134,7 +1132,7 @@ public function ToolMySQLConsole() : bool { if($save_output) $this->ave->write_data(" Done"); } } else { - $results = $db->resultsToString($results, $ini->get('SAVE_RESULTS_SEPARATOR')); + $results = $db->results_to_string($results, $ini->get('SAVE_RESULTS_SEPARATOR')); $this->ave->echo($results); if($save_output) $this->ave->write_data($results); } @@ -1182,18 +1180,18 @@ public function ToolBackupSelectedTriggers() : bool { } public function checkConfig(IniFile $config) : void { - if(!$config->isSet('BACKUP_ADD_LABEL_TO_PATH')) $config->set('BACKUP_ADD_LABEL_TO_PATH', true); - if(!$config->isSet('BACKUP_CURL_SEND_ERRORS')) $config->set('BACKUP_CURL_SEND_ERRORS', false); - if(!$config->isSet('BACKUP_CURL_CALLBACK')) $config->set('BACKUP_CURL_CALLBACK', null); - if(!$config->isSet('BACKUP_QUERY_LIMIT')) $config->set('BACKUP_QUERY_LIMIT', 50000); - if(!$config->isSet('BACKUP_INSERT_LIMIT')) $config->set('BACKUP_INSERT_LIMIT', 100); - if(!$config->isSet('BACKUP_TYPE_STRUCTURE')) $config->set('BACKUP_TYPE_STRUCTURE', true); - if(!$config->isSet('BACKUP_TYPE_DATA')) $config->set('BACKUP_TYPE_DATA', true); - if(!$config->isSet('BACKUP_COMPRESS')) $config->set('BACKUP_COMPRESS', true); - if(!$config->isSet('FOLDER_DATE_FORMAT')) $config->set('FOLDER_DATE_FORMAT', 'Y-m-d_His'); - if(!$config->isSet('SAVE_RESULTS_SEPARATOR')) $config->set('SAVE_RESULTS_SEPARATOR', '|'); - if(!$config->isSet('BACKUP_LOCK_TABLES')) $config->set('BACKUP_LOCK_TABLES', false); - if($config->isChanged()) $config->save(); + if(!$config->is_set('BACKUP_ADD_LABEL_TO_PATH')) $config->set('BACKUP_ADD_LABEL_TO_PATH', true); + if(!$config->is_set('BACKUP_CURL_SEND_ERRORS')) $config->set('BACKUP_CURL_SEND_ERRORS', false); + if(!$config->is_set('BACKUP_CURL_CALLBACK')) $config->set('BACKUP_CURL_CALLBACK', null); + if(!$config->is_set('BACKUP_QUERY_LIMIT')) $config->set('BACKUP_QUERY_LIMIT', 50000); + if(!$config->is_set('BACKUP_INSERT_LIMIT')) $config->set('BACKUP_INSERT_LIMIT', 100); + if(!$config->is_set('BACKUP_TYPE_STRUCTURE')) $config->set('BACKUP_TYPE_STRUCTURE', true); + if(!$config->is_set('BACKUP_TYPE_DATA')) $config->set('BACKUP_TYPE_DATA', true); + if(!$config->is_set('BACKUP_COMPRESS')) $config->set('BACKUP_COMPRESS', true); + if(!$config->is_set('FOLDER_DATE_FORMAT')) $config->set('FOLDER_DATE_FORMAT', 'Y-m-d_His'); + if(!$config->is_set('SAVE_RESULTS_SEPARATOR')) $config->set('SAVE_RESULTS_SEPARATOR', '|'); + if(!$config->is_set('BACKUP_LOCK_TABLES')) $config->set('BACKUP_LOCK_TABLES', false); + if($config->is_changed()) $config->save(); } public function compress(?string $callback, string $output, string $backup_path, Request $request) : void { @@ -1227,7 +1225,7 @@ public function BackupSelected(string $type, bool $need_lock) : bool { $this->ave->clear(); $this->ave->set_subtool("BackupSelected".$type); - $this->getSelectLabel(); + $this->get_select_label(); set_label: $label = $this->ave->get_input(" Label / ID: "); if($label == '#') return false; @@ -1237,12 +1235,12 @@ public function BackupSelected(string $type, bool $need_lock) : bool { goto set_label; } - if(!file_exists($this->getConfigPath($label))){ + if(!file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; } - $ini = $this->getConfig($label); + $ini = $this->get_config($label); if($ini->get('BACKUP_ADD_LABEL_TO_PATH')){ $path = $this->ave->get_file_path($ini->get('BACKUP_PATH')."/$label"); } else { @@ -1281,12 +1279,12 @@ public function BackupSelected(string $type, bool $need_lock) : bool { $this->ave->write_log("Initialize backup for \"$label\""); $this->ave->echo(" Initialize backup service"); $backup = new DataBaseBackup($path, $ini->get('BACKUP_QUERY_LIMIT'), $ini->get('BACKUP_INSERT_LIMIT'), $ini->get('FOLDER_DATE_FORMAT')); - $backup->toggleLockTables($lock_tables); + $backup->toggle_lock_tables($lock_tables); if(!is_null($callback)) $request->get($callback, ['maintenance' => true, 'state' => 'BACKUP_START'], true); $this->ave->echo(" Connecting to: ".$ini->get('DB_HOST').":".$ini->get('DB_PORT')."@".$ini->get('DB_USER')); if(!$backup->connect($ini->get('DB_HOST'), $ini->get('DB_USER'), $ini->get('DB_PASSWORD'), $ini->get('DB_NAME'), $ini->get('DB_PORT'))) goto set_label; - if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->getSource(), $backup)) return false; + if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($backup->get_source(), $backup)) return false; $this->ave->echo(" Create backup"); $func = "get".$ftype."s"; @@ -1323,7 +1321,7 @@ public function BackupSelected(string $type, bool $need_lock) : bool { if(!is_null($callback)) $request->get($callback, ['maintenance' => false, 'state' => 'BACKUP_END'], true); $backup->disconnect(); - $output = $backup->getOutput(); + $output = $backup->get_output(); if($compress){ $this->compress($callback, $output, $ini->get('BACKUP_PATH'), $request); } else { @@ -1339,7 +1337,7 @@ public function ToolFetchDataBaseInfo() : bool { $this->ave->clear(); $this->ave->set_subtool("FetchDataBaseInfo"); - $this->getSelectLabel(); + $this->get_select_label(); set_label: $label = $this->ave->get_input(" Label / ID: "); if($label == '#') return false; @@ -1349,22 +1347,22 @@ public function ToolFetchDataBaseInfo() : bool { goto set_label; } - if(!file_exists($this->getConfigPath($label))){ + if(!file_exists($this->get_config_path($label))){ $this->ave->echo(" Label \"$label\" not exists"); goto set_label; } - $ini = $this->getConfig($label); + $ini = $this->get_config($label); - $db = new DataBase(); + $db = new MySQL(); $this->ave->echo(" Connecting to: ".$ini->get('DB_HOST').":".$ini->get('DB_PORT')."@".$ini->get('DB_USER')); if(!$db->connect($ini->get('DB_HOST'), $ini->get('DB_USER'), $ini->get('DB_PASSWORD'), $ini->get('DB_NAME'), $ini->get('DB_PORT'))) goto set_label; - if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($db->getConnection())) return false; + if($ini->get('DB_NAME') == "*" && !$this->SelectDataBase($db->get_connection())) return false; $separator = $ini->get('SAVE_RESULTS_SEPARATOR'); $this->ave->write_data(str_replace("|", $separator, "Table|Engine|Collation|Rows|Data size|Data size (Bytes)|Index size|Index size (Bytes)|Row format")); - $db_name = $db->getDataBase(); + $db_name = $db->get_data_base(); $items = $db->query("SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'BASE TABLE'", PDO::FETCH_OBJ); foreach($items as $item){ @@ -1390,7 +1388,7 @@ public function ToolCompareDataBaseInfo() : bool { $this->ave->clear(); $this->ave->set_subtool("CompareDataBaseInfo"); - $this->getSelectLabel(); + $this->get_select_label(); set_label_source: $source = $this->ave->get_input(" Source label / ID: "); if($source == '#') return false; @@ -1400,16 +1398,16 @@ public function ToolCompareDataBaseInfo() : bool { goto set_label_source; } - if(!file_exists($this->getConfigPath($source))){ + if(!file_exists($this->get_config_path($source))){ $this->ave->echo(" Source label \"$source\" not exists"); goto set_label_source; } - $db_source = new DataBase(); - $ini_source = $this->getConfig($source); + $db_source = new MySQL(); + $ini_source = $this->get_config($source); $this->ave->echo(" Connecting to: ".$ini_source->get('DB_HOST').":".$ini_source->get('DB_PORT')."@".$ini_source->get('DB_USER')); if(!$db_source->connect($ini_source->get('DB_HOST'), $ini_source->get('DB_USER'), $ini_source->get('DB_PASSWORD'), $ini_source->get('DB_NAME'), $ini_source->get('DB_PORT'))) goto set_label_source; - if($ini_source->get('DB_NAME') == "*" && !$this->SelectDataBase($db_source->getConnection())) return false; + if($ini_source->get('DB_NAME') == "*" && !$this->SelectDataBase($db_source->get_connection())) return false; set_label_destination: $destination = $this->ave->get_input(" Destination label: "); @@ -1420,7 +1418,7 @@ public function ToolCompareDataBaseInfo() : bool { goto set_label_destination; } - if(!file_exists($this->getConfigPath($destination))){ + if(!file_exists($this->get_config_path($destination))){ $this->ave->echo(" Destination label \"$destination\" not exists"); goto set_label_destination; } @@ -1430,16 +1428,16 @@ public function ToolCompareDataBaseInfo() : bool { goto set_label_destination; } - $db_destination = new DataBase(); - $ini_destination = $this->getConfig($destination); + $db_destination = new MySQL(); + $ini_destination = $this->get_config($destination); $this->ave->echo(" Connecting to: ".$ini_destination->get('DB_HOST').":".$ini_destination->get('DB_PORT')."@".$ini_destination->get('DB_USER')); if(!$db_destination->connect($ini_destination->get('DB_HOST'), $ini_destination->get('DB_USER'), $ini_destination->get('DB_PASSWORD'), $ini_destination->get('DB_NAME'), $ini_destination->get('DB_PORT'))) goto set_label_destination; - if($ini_destination->get('DB_NAME') == "*" && !$this->SelectDataBase($db_destination->getConnection())) return false; + if($ini_destination->get('DB_NAME') == "*" && !$this->SelectDataBase($db_destination->get_connection())) return false; $info_source = []; $info_dest = []; - $db_name = $db_source->getDataBase(); + $db_name = $db_source->get_data_base(); $this->ave->echo(" Fetch data base info for \"$source\""); $items = $db_source->query("SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'BASE TABLE'", PDO::FETCH_OBJ); foreach($items as $item){ @@ -1457,7 +1455,7 @@ public function ToolCompareDataBaseInfo() : bool { } $db_source->disconnect(); - $db_name = $db_destination->getDataBase(); + $db_name = $db_destination->get_data_base(); $items = $db_destination->query("SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'BASE TABLE'", PDO::FETCH_OBJ); foreach($items as $item){ $table = $item->{"Tables_in_$db_name"}; diff --git a/version b/version index 10bf840..50aea0e 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.0.1 \ No newline at end of file +2.1.0 \ No newline at end of file