diff options
Diffstat (limited to 'vendor/gregwar')
24 files changed, 165 insertions, 82 deletions
diff --git a/vendor/gregwar/captcha/.gitignore b/vendor/gregwar/captcha/.gitignore index 5a275919..5b9939b3 100644 --- a/vendor/gregwar/captcha/.gitignore +++ b/vendor/gregwar/captcha/.gitignore @@ -1,3 +1,4 @@ demo/*.jpg demo/*.pgm demo/temp/ +vendor/ diff --git a/vendor/gregwar/captcha/.travis.yml b/vendor/gregwar/captcha/.travis.yml index 9c4b7049..5d2dbf97 100644 --- a/vendor/gregwar/captcha/.travis.yml +++ b/vendor/gregwar/captcha/.travis.yml @@ -6,6 +6,10 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 + - 7.1 + - 7.2 + - hhvm script: - composer install diff --git a/vendor/gregwar/captcha/LICENSE b/vendor/gregwar/captcha/LICENSE index 7db6ad8e..62f991a6 100644 --- a/vendor/gregwar/captcha/LICENSE +++ b/vendor/gregwar/captcha/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) <2012-2015> Grégoire Passault +Copyright (c) <2012-2017> Grégoire Passault Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/gregwar/captcha/PhraseBuilder.php b/vendor/gregwar/captcha/PhraseBuilder.php deleted file mode 100644 index b94bd61c..00000000 --- a/vendor/gregwar/captcha/PhraseBuilder.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -namespace Gregwar\Captcha; - -/** - * Generates random phrase - * - * @author Gregwar <g.passault@gmail.com> - */ -class PhraseBuilder implements PhraseBuilderInterface -{ - /** - * Generates random phrase of given length with given charset - */ - public function build($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789') - { - $phrase = ''; - $chars = str_split($charset); - - for ($i = 0; $i < $length; $i++) { - $phrase .= $chars[array_rand($chars)]; - } - - return $phrase; - } - - /** - * "Niceize" a code - */ - public function niceize($str) - { - return strtr(strtolower($str), '01', 'ol'); - } -} diff --git a/vendor/gregwar/captcha/README.md b/vendor/gregwar/captcha/README.md index 9f6c17a9..9f4d94b1 100644 --- a/vendor/gregwar/captcha/README.md +++ b/vendor/gregwar/captcha/README.md @@ -2,6 +2,7 @@ Captcha ======= ![Captchas examples](http://gregwar.com/captchas.png) +[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YUXRLWHQSWS6L) Installation ============ @@ -96,12 +97,43 @@ You can use theses functions : * **setMaxBehindLines($lines)**, sets the maximum number of lines behind the code * **setMaxFrontLines($lines)**, sets the maximum number of lines on the front of the code -Symfony 2 Bundle +If you want to change the number of character, you can call the phrase builder directly using +extra parameters: + +```php +use Gregwar\Captcha\CaptchaBuilder; +use Gregwar\Captcha\PhraseBuilder; + +// Will build phrases of 3 characters +$phraseBuilder = new PhraseBuilder(4) + +// Will build phrases of 5 characters, only digits +$phraseBuilder = new PhraseBuilder(5, '0123456789'); + +// Pass it as first argument of CaptchaBuilder, passing it the phrase +// builder +$captcha = new CaptchaBuilder(null, $phraseBuilder); +``` + +You can also pass directly the wanted phrase to the builder: + +```php +// Building a Captcha with the "hello" phrase +$captcha = new CaptchaBuilder('hello'); +``` + +Symfony Bundle ================ You can have a look at the following repository to enjoy the Symfony 2 bundle packaging this captcha generator : https://github.com/Gregwar/CaptchaBundle +Yii2 Extension +=============== + +You can use the following extension for integrating with Yii2 Framework : +https://github.com/juliardi/yii2-captcha + License ======= diff --git a/vendor/gregwar/captcha/autoload.php b/vendor/gregwar/captcha/autoload.php deleted file mode 100644 index 8b3fa392..00000000 --- a/vendor/gregwar/captcha/autoload.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -/** -* Registers an autoload for all the classes in Gregwar\Captcha -*/ -spl_autoload_register(function ($className) { - $namespace = 'Gregwar\\Captcha'; - - if (strpos($className, $namespace) === 0) { - $className = str_replace($namespace, '', $className); - $fileName = __DIR__ . '/' . str_replace('\\', '/', $className) . '.php'; - if (file_exists($fileName)) { - require($fileName); - } - } -}); diff --git a/vendor/gregwar/captcha/composer.json b/vendor/gregwar/captcha/composer.json index ef79423b..e225720e 100644 --- a/vendor/gregwar/captcha/composer.json +++ b/vendor/gregwar/captcha/composer.json @@ -18,11 +18,16 @@ ], "require": { "php": ">=5.3.0", - "ext-gd": "*" + "ext-gd": "*", + "ext-mbstring": "*", + "symfony/finder": "~3.0" }, "autoload": { "psr-4": { - "Gregwar\\Captcha\\": "/" + "Gregwar\\": "src/Gregwar" } + }, + "require-dev": { + "phpunit/phpunit": "^6.4" } } diff --git a/vendor/gregwar/captcha/demo/demo.php b/vendor/gregwar/captcha/demo/demo.php index 7852745f..87116cd7 100644 --- a/vendor/gregwar/captcha/demo/demo.php +++ b/vendor/gregwar/captcha/demo/demo.php @@ -1,9 +1,6 @@ <?php -include(__DIR__.'/../CaptchaBuilderInterface.php'); -include(__DIR__.'/../PhraseBuilderInterface.php'); -include(__DIR__.'/../CaptchaBuilder.php'); -include(__DIR__.'/../PhraseBuilder.php'); +require_once __DIR__.'/../vendor/autoload.php'; use Gregwar\Captcha\CaptchaBuilder; diff --git a/vendor/gregwar/captcha/demo/fingerprint.php b/vendor/gregwar/captcha/demo/fingerprint.php index ce30d991..d5319c7d 100644 --- a/vendor/gregwar/captcha/demo/fingerprint.php +++ b/vendor/gregwar/captcha/demo/fingerprint.php @@ -1,9 +1,6 @@ <?php -include(__DIR__.'/../CaptchaBuilderInterface.php'); -include(__DIR__.'/../PhraseBuilderInterface.php'); -include(__DIR__.'/../CaptchaBuilder.php'); -include(__DIR__.'/../PhraseBuilder.php'); +require_once __DIR__.'/../vendor/autoload.php'; use Gregwar\Captcha\CaptchaBuilder; diff --git a/vendor/gregwar/captcha/demo/ocr.php b/vendor/gregwar/captcha/demo/ocr.php index 3d745f65..0b0807d7 100644 --- a/vendor/gregwar/captcha/demo/ocr.php +++ b/vendor/gregwar/captcha/demo/ocr.php @@ -1,9 +1,6 @@ <?php -include(__DIR__.'/../CaptchaBuilderInterface.php'); -include(__DIR__.'/../PhraseBuilderInterface.php'); -include(__DIR__.'/../CaptchaBuilder.php'); -include(__DIR__.'/../PhraseBuilder.php'); +require_once __DIR__.'/../vendor/autoload.php'; use Gregwar\Captcha\CaptchaBuilder; diff --git a/vendor/gregwar/captcha/demo/output.php b/vendor/gregwar/captcha/demo/output.php index 2a4f3303..9223bf69 100644 --- a/vendor/gregwar/captcha/demo/output.php +++ b/vendor/gregwar/captcha/demo/output.php @@ -1,9 +1,6 @@ <?php -include(__DIR__.'/../CaptchaBuilderInterface.php'); -include(__DIR__.'/../PhraseBuilderInterface.php'); -include(__DIR__.'/../CaptchaBuilder.php'); -include(__DIR__.'/../PhraseBuilder.php'); +require_once __DIR__.'/../vendor/autoload.php'; use Gregwar\Captcha\CaptchaBuilder; diff --git a/vendor/gregwar/captcha/phpunit.xml.dist b/vendor/gregwar/captcha/phpunit.xml.dist new file mode 100644 index 00000000..f17e3b4d --- /dev/null +++ b/vendor/gregwar/captcha/phpunit.xml.dist @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit colors="true" bootstrap="vendor/autoload.php"> + <testsuites> + <testsuite name="KnpMenu Test Suite"> + <directory suffix="Test.php">./tests/</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist> + <directory>./src</directory> + </whitelist> + </filter> +</phpunit> diff --git a/vendor/gregwar/captcha/CaptchaBuilder.php b/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php index bc6173fe..6db2f2c3 100644 --- a/vendor/gregwar/captcha/CaptchaBuilder.php +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php @@ -317,33 +317,34 @@ class CaptchaBuilder implements CaptchaBuilderInterface */ protected function writePhrase($image, $phrase, $font, $width, $height) { - $length = strlen($phrase); + $length = mb_strlen($phrase); if ($length === 0) { - return imagecolorallocate($image, 0, 0, 0); + return \imagecolorallocate($image, 0, 0, 0); } // Gets the text size and start position $size = $width / $length - $this->rand(0, 3) - 1; - $box = imagettfbbox($size, 0, $font, $phrase); + $box = \imagettfbbox($size, 0, $font, $phrase); $textWidth = $box[2] - $box[0]; $textHeight = $box[1] - $box[7]; $x = ($width - $textWidth) / 2; $y = ($height - $textHeight) / 2 + $size; - if (!count($this->textColor)) { + if (!$this->textColor) { $textColor = array($this->rand(0, 150), $this->rand(0, 150), $this->rand(0, 150)); } else { $textColor = $this->textColor; } - $col = imagecolorallocate($image, $textColor[0], $textColor[1], $textColor[2]); + $col = \imagecolorallocate($image, $textColor[0], $textColor[1], $textColor[2]); // Write the letters one by one, with random angle for ($i=0; $i<$length; $i++) { - $box = imagettfbbox($size, 0, $font, $phrase[$i]); + $symbol = mb_substr($phrase, $i, 1); + $box = \imagettfbbox($size, 0, $font, $symbol); $w = $box[2] - $box[0]; $angle = $this->rand(-$this->maxAngle, $this->maxAngle); $offset = $this->rand(-$this->maxOffset, $this->maxOffset); - imagettftext($image, $size, $angle, $x, $y + $offset, $col, $font, $phrase[$i]); + \imagettftext($image, $size, $angle, $x, $y + $offset, $col, $font, $symbol); $x += $w; } @@ -682,7 +683,7 @@ class CaptchaBuilder implements CaptchaBuilderInterface $imageType = finfo_file($finfo, $backgroundImage); finfo_close($finfo); - if (!in_array ($imageType, $this->allowedBackgroundImageTypes)) { + if (!in_array($imageType, $this->allowedBackgroundImageTypes)) { throw new Exception('Invalid background image type! Allowed types are: ' . join(', ', $this->allowedBackgroundImageTypes)); } diff --git a/vendor/gregwar/captcha/CaptchaBuilderInterface.php b/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilderInterface.php index bdebf38f..bebd0704 100644 --- a/vendor/gregwar/captcha/CaptchaBuilderInterface.php +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilderInterface.php @@ -27,4 +27,3 @@ interface CaptchaBuilderInterface */ public function output($quality); } - diff --git a/vendor/gregwar/captcha/Font/captcha0.ttf b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha0.ttf Binary files differindex 139f0b43..139f0b43 100644 --- a/vendor/gregwar/captcha/Font/captcha0.ttf +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha0.ttf diff --git a/vendor/gregwar/captcha/Font/captcha1.ttf b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha1.ttf Binary files differindex bb1abf6b..bb1abf6b 100644 --- a/vendor/gregwar/captcha/Font/captcha1.ttf +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha1.ttf diff --git a/vendor/gregwar/captcha/Font/captcha2.ttf b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha2.ttf Binary files differindex 8d1f31e8..8d1f31e8 100644 --- a/vendor/gregwar/captcha/Font/captcha2.ttf +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha2.ttf diff --git a/vendor/gregwar/captcha/Font/captcha3.ttf b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha3.ttf Binary files differindex d232902c..d232902c 100644 --- a/vendor/gregwar/captcha/Font/captcha3.ttf +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha3.ttf diff --git a/vendor/gregwar/captcha/Font/captcha4.ttf b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha4.ttf Binary files differindex ab154440..ab154440 100644 --- a/vendor/gregwar/captcha/Font/captcha4.ttf +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha4.ttf diff --git a/vendor/gregwar/captcha/Font/captcha5.ttf b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha5.ttf Binary files differindex f7cd9986..f7cd9986 100644 --- a/vendor/gregwar/captcha/Font/captcha5.ttf +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/Font/captcha5.ttf diff --git a/vendor/gregwar/captcha/ImageFileHandler.php b/vendor/gregwar/captcha/src/Gregwar/Captcha/ImageFileHandler.php index 6b6bdb87..dd20fcb2 100644 --- a/vendor/gregwar/captcha/ImageFileHandler.php +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/ImageFileHandler.php @@ -86,7 +86,7 @@ class ImageFileHandler $finder->in($this->webPath . '/' . $this->imageFolder) ->date($criteria); - foreach($finder->files() as $file) { + foreach ($finder->files() as $file) { unlink($file->getPathname()); } @@ -103,4 +103,3 @@ class ImageFileHandler } } } - diff --git a/vendor/gregwar/captcha/src/Gregwar/Captcha/PhraseBuilder.php b/vendor/gregwar/captcha/src/Gregwar/Captcha/PhraseBuilder.php new file mode 100644 index 00000000..5cc938b6 --- /dev/null +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/PhraseBuilder.php @@ -0,0 +1,59 @@ +<?php + +namespace Gregwar\Captcha; + +/** + * Generates random phrase + * + * @author Gregwar <g.passault@gmail.com> + */ +class PhraseBuilder implements PhraseBuilderInterface +{ + /** + * @var int + */ + public $length; + + /** + * @var string + */ + public $charset; + /** + * Constructs a PhraseBuilder with given parameters + */ + public function __construct($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789') + { + $this->length = $length; + $this->charset = $charset; + } + + /** + * Generates random phrase of given length with given charset + */ + public function build($length = null, $charset = null) + { + if ($length !== null) { + $this->length = $length; + } + if ($charset !== null) { + $this->charset = $charset; + } + + $phrase = ''; + $chars = str_split($this->charset); + + for ($i = 0; $i < $this->length; $i++) { + $phrase .= $chars[array_rand($chars)]; + } + + return $phrase; + } + + /** + * "Niceize" a code + */ + public function niceize($str) + { + return strtr(strtolower($str), '01', 'ol'); + } +} diff --git a/vendor/gregwar/captcha/PhraseBuilderInterface.php b/vendor/gregwar/captcha/src/Gregwar/Captcha/PhraseBuilderInterface.php index 0a4f5361..62ec4b08 100644 --- a/vendor/gregwar/captcha/PhraseBuilderInterface.php +++ b/vendor/gregwar/captcha/src/Gregwar/Captcha/PhraseBuilderInterface.php @@ -12,7 +12,7 @@ interface PhraseBuilderInterface /** * Generates random phrase of given length with given charset */ - public function build($length, $charset); + public function build(); /** * "Niceize" a code diff --git a/vendor/gregwar/captcha/tests/CaptchaBuilderTest.php b/vendor/gregwar/captcha/tests/CaptchaBuilderTest.php new file mode 100644 index 00000000..5325a9c1 --- /dev/null +++ b/vendor/gregwar/captcha/tests/CaptchaBuilderTest.php @@ -0,0 +1,30 @@ +<?php + +namespace Test; + +use Gregwar\Captcha\CaptchaBuilder; +use PHPUnit\Framework\TestCase; + +class CaptchaBuilderTest extends TestCase +{ + public function testDemo() + { + $captcha = new CaptchaBuilder(); + $captcha + ->build() + ->save('out.jpg') + ; + + $this->assertTrue(file_exists(__DIR__.'/../out.jpg')); + } + + public function testFingerPrint() + { + $int = count(CaptchaBuilder::create() + ->build() + ->getFingerprint() + ); + + $this->assertTrue(is_int($int)); + } +}
\ No newline at end of file |