Update composer dependencies
This commit is contained in:
1
vendor/gregwar/captcha/.gitignore
vendored
1
vendor/gregwar/captcha/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
demo/*.jpg
|
||||
demo/*.pgm
|
||||
demo/temp/
|
||||
vendor/
|
||||
|
||||
4
vendor/gregwar/captcha/.travis.yml
vendored
4
vendor/gregwar/captcha/.travis.yml
vendored
@@ -6,6 +6,10 @@ php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- hhvm
|
||||
|
||||
script:
|
||||
- composer install
|
||||
|
||||
2
vendor/gregwar/captcha/LICENSE
vendored
2
vendor/gregwar/captcha/LICENSE
vendored
@@ -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
|
||||
|
||||
34
vendor/gregwar/captcha/PhraseBuilder.php
vendored
34
vendor/gregwar/captcha/PhraseBuilder.php
vendored
@@ -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');
|
||||
}
|
||||
}
|
||||
34
vendor/gregwar/captcha/README.md
vendored
34
vendor/gregwar/captcha/README.md
vendored
@@ -2,6 +2,7 @@ Captcha
|
||||
=======
|
||||
|
||||

|
||||
[](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
|
||||
=======
|
||||
|
||||
|
||||
16
vendor/gregwar/captcha/autoload.php
vendored
16
vendor/gregwar/captcha/autoload.php
vendored
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
9
vendor/gregwar/captcha/composer.json
vendored
9
vendor/gregwar/captcha/composer.json
vendored
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
5
vendor/gregwar/captcha/demo/demo.php
vendored
5
vendor/gregwar/captcha/demo/demo.php
vendored
@@ -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;
|
||||
|
||||
|
||||
5
vendor/gregwar/captcha/demo/fingerprint.php
vendored
5
vendor/gregwar/captcha/demo/fingerprint.php
vendored
@@ -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;
|
||||
|
||||
|
||||
5
vendor/gregwar/captcha/demo/ocr.php
vendored
5
vendor/gregwar/captcha/demo/ocr.php
vendored
@@ -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;
|
||||
|
||||
|
||||
5
vendor/gregwar/captcha/demo/output.php
vendored
5
vendor/gregwar/captcha/demo/output.php
vendored
@@ -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;
|
||||
|
||||
|
||||
15
vendor/gregwar/captcha/phpunit.xml.dist
vendored
Normal file
15
vendor/gregwar/captcha/phpunit.xml.dist
vendored
Normal file
@@ -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>
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -27,4 +27,3 @@ interface CaptchaBuilderInterface
|
||||
*/
|
||||
public function output($quality);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
59
vendor/gregwar/captcha/src/Gregwar/Captcha/PhraseBuilder.php
vendored
Normal file
59
vendor/gregwar/captcha/src/Gregwar/Captcha/PhraseBuilder.php
vendored
Normal file
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
30
vendor/gregwar/captcha/tests/CaptchaBuilderTest.php
vendored
Normal file
30
vendor/gregwar/captcha/tests/CaptchaBuilderTest.php
vendored
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user