Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Bump PHP version requirement to 7.2 and remove wfio extension support
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklul committed May 10, 2020
1 parent b20d4e8 commit 242ce7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 61 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ Removed services:

#### Windows

Package comes with compiled **PHP 5.6 library** (x86 Non Thread Safe) and all required extensions
Package comes with compiled **PHP 7.2 library** (x86 Non Thread Safe) and all required extensions.

You will need **Visual C++ 2012 Redistributable (x86)** for it to run - https://www.microsoft.com/en-us/download/details.aspx?id=30679
You will need **Visual C++ 2015 Redistributable (x86)** for it to run - https://www.microsoft.com/en-us/download/details.aspx?id=52685

#### Linux

Install **PHP library** (>=5.6), cURL, GD and zip extensions - `sudo apt-get install php-cli php-curl php-gd php-zip`
Install **PHP library** (>=7.2), cURL, GD and zip extensions - `sudo apt-get install php-cli php-curl php-gd php-zip`

#### Warning about PHP version

While the script will still work with PHP >=5.6 it won't be able to work with some special characters that can be in the file names, PHP 7.2+ is recommended.

## Usage:
- Put images into 'images' folder
Expand All @@ -35,7 +39,6 @@ Install **PHP library** (>=5.6), cURL, GD and zip extensions - `sudo apt-get ins
- `E621_LOGIN` - your e621 username
- `E621_API_KEY` - obtained from `e621 -> Account -> Manage API Access`


## Advanced
- You can pass any directory as an argument to the run script (on Windows you can move a directory over `run.bat`)
- Rename `config.cfg.example` to `config.cfg` to make the script use it, configure it how you want
Expand Down
74 changes: 17 additions & 57 deletions src/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class App
*
* @var string
*/
private $VERSION = '1.7.3';
private $VERSION = '1.8.0';

/**
* App update URL
Expand Down Expand Up @@ -123,15 +123,6 @@ class App
*/
private $REVERSE_SEARCH = true;

/**
* Use php-wfio extension or not
* This is required for UTF-8 filename support on Windows
* (see https://github.com/kenjiuno/php-wfio)
*
* @var bool
*/
private $USE_PHPWFIO = true;

/**
* Convert image into JPEG with '90' quality before uploading
*
Expand Down Expand Up @@ -570,10 +561,6 @@ public function readConfig($file)
die("No search method set, check config!\n\n");
}

if (isset($config['USE_PHPWFIO'])) {
$this->USE_PHPWFIO = (bool)$config['USE_PHPWFIO'];
}

if (isset($config['USE_CONVERSION'])) {
$this->USE_CONVERSION = (bool)$config['USE_CONVERSION'];
}
Expand Down Expand Up @@ -683,22 +670,7 @@ public function run()
$this->printout("\n");

if ($this->CUSTOM_PATH) {
$this->printout("Using path: " . str_replace("wfio://", "", $this->PATH_IMAGES) . "\n\n");
}

if (!$this->IS_LINUX) {
if (!extension_loaded("wfio") && $this->USE_PHPWFIO) {
$this->printout("WARNING: 'php_wfio.dll' extension not loaded - UTF-8 filename support will be disabled!\n\n");
$this->USE_PHPWFIO = false;
}

if ($this->USE_PHPWFIO) {
$this->PATH_IMAGES = "wfio://" . $this->PATH_IMAGES;
$this->PATH_IMAGES_FOUND = "wfio://" . $this->PATH_IMAGES_FOUND;
$this->PATH_IMAGES_NOT_FOUND = "wfio://" . $this->PATH_IMAGES_NOT_FOUND;
}
} else {
$this->USE_PHPWFIO = false;
$this->printout("Using path: " . $this->PATH_IMAGES . "\n\n");
}

$this->main();
Expand Down Expand Up @@ -747,7 +719,7 @@ private function main()
$file_size = filesize($this->PATH_IMAGES . '/' . $entry);
$image_size = getimagesize($this->PATH_IMAGES . '/' . $entry);

if (urlencode($entry) != $entry && !$this->USE_PHPWFIO && !$this->IS_LINUX) {
if (urlencode($entry) != $entry && (float)PHP_VERSION < 7.2) {
$files_error['encoding'] = true;
} elseif (!in_array(strtolower(pathinfo($entry, PATHINFO_EXTENSION)), ['jpg', 'jpeg', 'png', 'gif'])) {
$files_error['file_type'] = true;
Expand All @@ -770,7 +742,7 @@ private function main()
}

if (isset($files_error['encoding'])) {
$this->printout("WARNING: Some files contained non-standard characters in their names and were ignored!\n");
$this->printout("WARNING: Some files contained UTF-8 characters in their names and were ignored, please use at least PHP 7.2 to support them!\n");
}

if (isset($files_error['file_type'])) {
Expand Down Expand Up @@ -837,7 +809,7 @@ private function main()
foreach ($files as $entry) {
if ($this->IS_RUNNING) {
$files_count++;
$this->printout('[' . ($files_count) . "/$files_total] Searching '" . (($this->USE_PHPWFIO) ? utf8_decode($entry) : $entry) . "':\n");
$this->printout('[' . ($files_count) . "/$files_total] Searching '" . $entry . "':\n");

$results = null;
if ($this->MD5_SEARCH) {
Expand Down Expand Up @@ -1230,14 +1202,10 @@ private function reverseSearch($file)

$post_data = [];

if ($this->USE_PHPWFIO || $this->USE_CONVERSION) {
if ($this->USE_CONVERSION) {
$contents = $this->convertImage($file);
if (is_array($contents) && isset($contents['error'])) {
return $contents;
}
} else {
$contents = file_get_contents($file);
if ($this->USE_CONVERSION) {
$contents = $this->convertImage($file);
if (is_array($contents) && isset($contents['error'])) {
return $contents;
}

$file_data['file'] = $contents;
Expand Down Expand Up @@ -1437,14 +1405,10 @@ private function reverseSearchSaucenao($file)
{
$post_data = [];

if ($this->USE_PHPWFIO || $this->USE_CONVERSION) {
if ($this->USE_CONVERSION) {
$contents = $this->convertImage($file);
if (is_array($contents) && isset($contents['error'])) {
return $contents;
}
} else {
$contents = file_get_contents($file);
if ($this->USE_CONVERSION) {
$contents = $this->convertImage($file);
if (is_array($contents) && isset($contents['error'])) {
return $contents;
}

$file_data['file'] = $contents;
Expand Down Expand Up @@ -1642,14 +1606,10 @@ private function reverseSearchHarryLu($file)
{
$post_data = [];

if ($this->USE_PHPWFIO || $this->USE_CONVERSION) {
if ($this->USE_CONVERSION) {
$contents = $this->convertImage($file);
if (is_array($contents) && isset($contents['error'])) {
return $contents;
}
} else {
$contents = file_get_contents($file);
if ($this->USE_CONVERSION) {
$contents = $this->convertImage($file);
if (is_array($contents) && isset($contents['error'])) {
return $contents;
}

$file_data['file'] = $contents;
Expand Down

0 comments on commit 242ce7b

Please sign in to comment.