//1kĻU<Ģ81kĻU`Y1kĻUF91kĻU>ąå0kĻU'(kP   ‘R(1kĻU @ °‘j1kĻU°ā‘+!å0kĻU ā’6Ļ1kĻUā°ā’7ė1kĻUā ā’7ų1kĻU0Ā ļ’p//1kĻUĀ’<€1kĻUāĀā’7ė1kĻUā ā’7Ļ1kĻUā°ā’7ā1kĻUā` Ð’8Ąų0kĻU`ÐJ’™þ0kĻU0 Č0“D1kĻU`P“B 01kĻUL“<qų0kĻUp0M“ų1kĻUpРДp 01kĻUN”< õ0kĻUÐp•MĄ41kĻUp@€ā•NĄų0kĻUP€Q•ų1kĻUpP ā–p1kĻUPP–B1kĻU@`–B 01kĻUR–<Č1kĻU@ĸĸĸ•*Ģ81kĻUp•ų1kĻUp° ð˜p//1kĻU°˜<Ģ81kĻU`˜Y1kĻU˜F91kĻU°˜>Č1kĻU€˜*ų1kĻU ›p†)1kĻU P›t 01kĻUT›<Č1kĻU`ōĸĸw*Ģ81kĻU`wų1kĻU  žp†)1kĻU  Pžt 01kĻUUž<Y1kĻUŸF ö0kĻUPŸ>™þ0kĻU0 āĒD1kĻUPPĒB 01kĻUWĒ<qų0kĻU0āXĒų1kĻU0Ð(Ģpīó0kĻU€Ð8ĶR)1kĻU` ĶQu1kĻU  0ĶQž1kĻU0@ĶG1kĻU@PĶt//1kĻUPĶ<•1kĻUP`Ķj1kĻU``Ķ+Y1kĻUĐF ö0kĻUPĐ>ų1kĻU0ĀPŦp =1kĻUŦd„ó0kĻU€ p`Ŧ^Šį0kĻUp`€Ŧ]Fė0kĻU€pŦ]1kĻUPŦđ1kĻUp`ŦB 01kĻUbŦ<ų1kĻU0xŽp//1kĻU°Ž<Y1kĻUŽF91kĻU°Ž>Y1kĻUŊF ö0kĻUPŊ>Y1kĻUŊF<ð0kĻU@ĸĸĸĸą> `AðLAðb AðLAðb AĮጎ"A˜DAX°AĻþAāþA`™AðAðLAXfAĸAĸAøAøAĀDAX)Ah)A`ÔA`ÔAЅAЅAPA€jUkĻUPAPA .A`ÔA`ÔAĸAĸAXd A`vA`vAĀDAЅAЅAPA€jUkĻUPAPAð A0 A(qA`_ A0 AĻþAāþAĸAĸA`A`AX)Aā(AX)A)AhĸAhĸAX)Ah)Að AhĸAhĸA0 A`_ A0 AĻþAāþAĸAĸA`A`AhĸAhĸAxØAxØAĀDA`vA`vAĀDAĻþAāþAĸAĸAðLAXfAXd A`A`AðLAX°AhĸAhĸA[] Server paths of source images. */ public function skip_converted_paths( array $source_paths, ?array $allowed_output_formats = null, bool $force_convert_modified = false ): array { $plugin_settings = $this->plugin_data->get_plugin_settings(); $allowed_output_formats = $allowed_output_formats ?: $plugin_settings[ OutputFormatsOption::OPTION_NAME ]; $force_convert_deleted = ( ! in_array( ExtraFeaturesOption::OPTION_VALUE_ONLY_SMALLER, $plugin_settings[ ExtraFeaturesOption::OPTION_NAME ] ) ); foreach ( $source_paths as $path_index => $source_path ) { $is_converted = true; foreach ( $allowed_output_formats as $output_format ) { $output_path = $this->output_path->get_path( $source_path, false, $output_format ); if ( $output_path && ! $this->is_converted_file( $source_path, $output_path, $force_convert_deleted, false, $force_convert_modified ) ) { $is_converted = false; break; } } if ( $is_converted ) { unset( $source_paths[ $path_index ] ); } } return $source_paths; } /** * @param mixed[] $source_dirs Server paths of source images. * @param bool $skip_converted Skip converted images? * @param string[]|null $allowed_output_formats List of extensions or use selected in plugin settings. * * @return mixed[] Server paths of source images. */ private function skip_converted_paths_chunks( array $source_dirs, bool $skip_converted, ?array $allowed_output_formats = null ): array { $plugin_settings = $this->plugin_data->get_plugin_settings(); $allowed_output_formats = $allowed_output_formats ?: $plugin_settings[ OutputFormatsOption::OPTION_NAME ]; $force_convert_deleted = ( ! in_array( ExtraFeaturesOption::OPTION_VALUE_ONLY_SMALLER, $plugin_settings[ ExtraFeaturesOption::OPTION_NAME ] ) ); $force_convert_crashed = ( $plugin_settings[ ServiceModeOption::OPTION_NAME ] === 'yes' ); foreach ( $source_dirs as $dir_name => $dir_data ) { foreach ( $dir_data['files'] as $path_index => $source_file ) { $source_path = $dir_data['path'] . '/' . $source_file; $is_converted = true; foreach ( $allowed_output_formats as $output_format ) { $output_path = $this->output_path->get_path( $source_path, false, $output_format ); if ( $output_path && ( ! $skip_converted || ! $this->is_converted_file( $source_path, $output_path, $force_convert_deleted, $force_convert_crashed ) ) ) { $is_converted = false; break; } } if ( $is_converted ) { unset( $source_dirs[ $dir_name ]['files'][ $path_index ] ); } } } return $source_dirs; } /** * Returns list of server paths of source images to be converted. * * @return mixed[] { * @type string $path Directory path. * @type string[] $files Files paths. * } */ private function find_source_paths(): array { $settings = $this->plugin_data->get_plugin_settings(); $source_dirs = []; foreach ( $settings[ SupportedDirectoriesOption::OPTION_NAME ] as $dir_name ) { $source_dirs[ $dir_name ] = apply_filters( 'webpc_dir_path', '', $dir_name ); } $list = []; foreach ( $source_dirs as $dir_name => $dir_path ) { $list[ $dir_name ] = [ 'path' => $dir_path, 'files' => $this->files_finder->get_files_by_directory( $dir_path ), ]; } return $list; } /** * @param string $source_path . * @param string $output_path . * @param bool $force_convert_deleted Skip .deleted files. * @param bool $force_convert_crashed Skip .crashed files. * @param bool $force_convert_modified . * * @return bool */ private function is_converted_file( string $source_path, string $output_path, bool $force_convert_deleted, bool $force_convert_crashed, bool $force_convert_modified = false ): bool { if ( file_exists( $output_path ) ) { return ( $force_convert_modified ) ? ( filemtime( $source_path ) <= filemtime( $output_path ) ) : true; } elseif ( ! $force_convert_deleted && file_exists( $output_path . '.' . LargerFilesOperator::DELETED_FILE_EXTENSION ) ) { return true; } elseif ( ! $force_convert_crashed && file_exists( $output_path . '.' . CrashedFilesOperator::CRASHED_FILE_EXTENSION ) ) { return true; } return false; } /** * @param int $paths_count . * * @return int<1, max> */ private function get_paths_chunk_size( int $paths_count ): int { $settings = $this->plugin_data->get_plugin_settings(); if ( $settings[ ConversionMethodOption::OPTION_NAME ] !== RemoteMethod::METHOD_NAME ) { return self::PATHS_PER_REQUEST_LOCAL; } if ( $settings[ ServiceModeOption::OPTION_NAME ] === 'yes' ) { return self::PATHS_PER_REQUEST_REMOTE_LARGE; } $output_formats = count( $settings[ OutputFormatsOption::OPTION_NAME ] ) ?: 1; $images_count = $paths_count * $output_formats; $images_limit = $this->token_repository->get_token()->get_images_limit(); $images_to_conversion = min( $images_count, $images_limit ); if ( $images_to_conversion <= 10000 ) { return self::PATHS_PER_REQUEST_REMOTE_SMALL; } elseif ( $images_to_conversion <= 120000 ) { return self::PATHS_PER_REQUEST_REMOTE_MEDIUM; } else { return self::PATHS_PER_REQUEST_REMOTE_LARGE; } } }