Skip to content

Commit 133d2fc

Browse files
committed
2016-07-23 AC: Merge branch '1.8.9' into stable.
2 parents a06abb8 + 42436fe commit 133d2fc

File tree

133 files changed

+19079
-2729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+19079
-2729
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ MAINTAINERS.txt export-ignore
3434
INSTALL*.txt export-ignore
3535
# tests
3636
test export-ignore
37+
# docs
38+
docs export-ignore
3739
# scripts
3840
createpack.sh export-ignore

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ matrix:
1212
- php: 5.4
1313
- php: 5.5
1414
- php: 5.6
15+
env:
16+
- CS_CHECK=true
1517
- php: 7
1618
- php: hhvm
1719
allow_failures:

CAPTCHA.php

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* Text_CAPTCHA - creates a CAPTCHA for Turing tests
55
*
66
* Class to create a Turing test for websites by
7-
* creating an image, ASCII art or something else
8-
* with some (obfuscated) characters
7+
* creating an image, ASCII art or something else
8+
* with some (obfuscated) characters
9+
*
910
*
10-
*
1111
* @package Text_CAPTCHA
1212
* @license BSD License
1313
* @author Christian Wenz <wenz@php.net>
@@ -33,13 +33,13 @@
3333
* Text_CAPTCHA - creates a CAPTCHA for Turing tests
3434
*
3535
* Class to create a Turing test for websites by
36-
* creating an image, ASCII art or something else
37-
* with some (obfuscated) characters
36+
* creating an image, ASCII art or something else
37+
* with some (obfuscated) characters
3838
*
3939
* @package Text_CAPTCHA
4040
*/
41-
42-
/*
41+
42+
/*
4343
// This is a simple example script
4444
4545
<?php
@@ -52,7 +52,7 @@ public function file_put_contents($filename, $content) {
5252
fclose($file);
5353
return $n ? $n : false;
5454
}
55-
}
55+
}
5656
5757
// Start PHP session support
5858
session_start();
@@ -73,16 +73,16 @@ public function file_put_contents($filename, $content) {
7373
$msg = 'Please try again!';
7474
}
7575
76-
unlink(sha1(session_id()) . '.png');
76+
unlink(sha1(session_id()) . '.png');
7777
7878
}
7979
8080
print "<p>$msg</p>";
8181
8282
if (!$ok) {
83-
83+
8484
require_once 'Text/CAPTCHA.php';
85-
85+
8686
// Set CAPTCHA image options (font must exist!)
8787
$imageOptions = array(
8888
'font_size' => 24,
@@ -109,10 +109,10 @@ public function file_put_contents($filename, $content) {
109109
$retval->getMessage());
110110
exit;
111111
}
112-
112+
113113
// Get CAPTCHA secret passphrase
114114
$_SESSION['phrase'] = $c->getPhrase();
115-
115+
116116
// Get CAPTCHA image (as PNG)
117117
$png = $c->getCAPTCHA();
118118
if (PEAR::isError($png)) {
@@ -121,16 +121,17 @@ public function file_put_contents($filename, $content) {
121121
exit;
122122
}
123123
file_put_contents(sha1(session_id()) . '.png', $png);
124-
125-
echo '<form method="post">' .
126-
'<img src="' . sha1(session_id()) . '.png?' . time() . '" />' .
124+
125+
echo '<form method="post">' .
126+
'<img src="' . sha1(session_id()) . '.png?' . time() . '" />' .
127127
'<input type="text" name="phrase" />' .
128128
'<input type="submit" /></form>';
129129
}
130130
?>
131131
*/
132-
133-
class Text_CAPTCHA {
132+
133+
class Text_CAPTCHA
134+
{
134135

135136
/**
136137
* Version number
@@ -208,12 +209,12 @@ public function getPhrase()
208209
/**
209210
* Sets secret CAPTCHA phrase
210211
*
211-
* This method sets the CAPTCHA phrase
212+
* This method sets the CAPTCHA phrase
212213
* (use null for a random phrase)
213214
*
214215
* @access public
215216
* @param string $phrase the (new) phrase
216-
* @void
217+
* @void
217218
*/
218219
public function setPhrase($phrase = null)
219220
{
@@ -226,12 +227,13 @@ public function setPhrase($phrase = null)
226227

227228
/**
228229
* Place holder for the real init() method
229-
* used by extended classes to initialize CAPTCHA
230+
* used by extended classes to initialize CAPTCHA
230231
*
231232
* @access private
232233
* @return PEAR_Error
233234
*/
234-
public function init() {
235+
public function init()
236+
{
235237
return PEAR::raiseError('CAPTCHA type not selected', true);
236238
}
237239

@@ -242,21 +244,21 @@ public function init() {
242244
* @access private
243245
* @return PEAR_Error
244246
*/
245-
public function _createCAPTCHA() {
247+
public function _createCAPTCHA()
248+
{
246249
return PEAR::raiseError('CAPTCHA type not selected', true);
247250
}
248251

249252
/**
250253
* Place holder for the real getCAPTCHA() method
251-
* used by extended classes to return the generated CAPTCHA
254+
* used by extended classes to return the generated CAPTCHA
252255
* (as an image resource, as an ASCII text, ...)
253256
*
254257
* @access private
255258
* @return PEAR_Error
256259
*/
257-
public function getCAPTCHA() {
260+
public function getCAPTCHA()
261+
{
258262
return PEAR::raiseError('CAPTCHA type not selected', true);
259263
}
260-
261264
}
262-
?>

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 1.8.9 (2016-07-23)
4+
5+
- Fixes issue #2 - Confirmation messages when uploading more than one file.
6+
- Fixes issue #12 - File uploaded in spite of wrong captcha.
7+
38
## 1.8.8 (2016-07-04)
49

510
- Fixes issue #1 - Error messages are displayed to the user when leaving

Image.php

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/**
55
*
6-
* Require Image_Text class for generating the text.
6+
* Require ImageText class for generating the text.
77
*
88
*/
99
require_once 'CAPTCHA.php';
@@ -12,13 +12,13 @@
1212
/**
1313
* Text_CAPTCHA_Driver_Image - Text_CAPTCHA driver graphical CAPTCHAs
1414
*
15-
* Class to create a graphical Turing test
15+
* Class to create a graphical Turing test
16+
*
1617
*
17-
*
1818
* @license BSD License
1919
* @author Christian Wenz <wenz@php.net>
2020
* @todo refine the obfuscation algorithm :-)
21-
* @todo consider removing Image_Text dependency
21+
* @todo consider removing ImageText dependency
2222
*/
2323

2424
class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
@@ -33,7 +33,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
3333
public $_im;
3434

3535
/**
36-
* Image_Text object
36+
* ImageText object
3737
*
3838
* @access private
3939
* @public resource
@@ -59,7 +59,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
5959
/**
6060
* Phrase length of CAPTCHA
6161
*
62-
* @access public static
62+
* @access public static
6363
* @public int
6464
*/
6565
public static $_phraseLength;
@@ -73,7 +73,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
7373
public $_output;
7474

7575
/**
76-
* Further options (here: for Image_Text)
76+
* Further options (here: for ImageText)
7777
*
7878
* @access private
7979
* @public array
@@ -85,7 +85,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
8585
'text_color' => '#000000',
8686
'lines_color' => '#CACACA',
8787
'background_color' => '#555555');
88-
88+
8989
/**
9090
* Whether the immage resource has been created
9191
*
@@ -115,17 +115,17 @@ public function init($options = array())
115115
{
116116
if (!is_array($options)) {
117117
// Compatibility mode ... in future versions, these two
118-
// lines of code will be used:
118+
// lines of code will be used:
119119
// $this->_error = PEAR::raiseError('You need to provide a set of CAPTCHA options!');
120-
// return $this->_error;
120+
// return $this->_error;
121121
$o = array();
122122
$args = func_get_args();
123123
if (isset($args[0])) {
124124
$o['width'] = $args[0];
125-
}
125+
}
126126
if (isset($args[1])) {
127127
$o['height'] = $args[1];
128-
}
128+
}
129129
if (isset($args[2]) && $args[2] != null) {
130130
$o['phrase'] = $args[2];
131131
}
@@ -134,16 +134,16 @@ public function init($options = array())
134134
}
135135
$options = $o;
136136
}
137-
if (is_array($options)) {
137+
if (is_array($options)) {
138138
if (isset($options['width']) && is_int($options['width'])) {
139-
$this->_width = $options['width'];
139+
$this->_width = $options['width'];
140140
} else {
141-
$this->_width = 200;
141+
$this->_width = 200;
142142
}
143143
if (isset($options['height']) && is_int($options['height'])) {
144-
$this->_height = $options['height'];
144+
$this->_height = $options['height'];
145145
} else {
146-
$this->_height = 80;
146+
$this->_height = 80;
147147
}
148148
if (!isset($options['phrase']) || empty($options['phrase'])) {
149149
$phraseoptions = (isset($options['phraseOptions']) && is_array($options['phraseOptions'])) ? $options['phraseOptions'] : array();
@@ -155,9 +155,9 @@ public function init($options = array())
155155
$this->_output = 'resource';
156156
} else {
157157
$this->_output = $options['output'];
158-
}
158+
}
159159
if (isset($options['imageOptions']) && is_array($options['imageOptions']) && count($options['imageOptions']) > 0) {
160-
$this->_imageOptions = array_merge($this->_imageOptions, $options['imageOptions']);
160+
$this->_imageOptions = array_merge($this->_imageOptions, $options['imageOptions']);
161161
}
162162
return true;
163163
}
@@ -172,11 +172,11 @@ public function init($options = array())
172172
*/
173173
public function _createPhrase($options = array())
174174
{
175-
if (isset(self::$_phraseLength)) {
176-
$len = intval(min(self::$_phraseLength, $this->_width / 25));
177-
} else {
178-
$len = intval(min(8, $this->_width / 25));
179-
}
175+
if (isset(self::$_phraseLength)) {
176+
$len = intval(min(self::$_phraseLength, $this->_width / 25));
177+
} else {
178+
$len = intval(min(8, $this->_width / 25));
179+
}
180180
if (!is_array($options) || count($options) === 0) {
181181
$this->_phrase = Text_Password::create($len);
182182
} else {
@@ -208,11 +208,11 @@ public function _createCAPTCHA()
208208
$options['canvas'] = array(
209209
'width' => $this->_width,
210210
'height' => $this->_height
211-
);
211+
);
212212
$options['width'] = $this->_width - 20;
213-
$options['height'] = $this->_height - 20;
213+
$options['height'] = $this->_height - 20;
214214
$options['cx'] = ceil(($this->_width) / 2 + 10);
215-
$options['cy'] = ceil(($this->_height) / 2 + 10);
215+
$options['cy'] = ceil(($this->_height) / 2 + 10);
216216
$options['angle'] = rand(0, 30) - 15;
217217
$options['font_size'] = $this->_imageOptions['font_size'];
218218
$options['font_path'] = $this->_imageOptions['font_path'];
@@ -222,26 +222,29 @@ public function _createCAPTCHA()
222222
$options['max_lines'] = 1;
223223
$options['mode'] = 'auto';
224224
do {
225-
$this->_imt = new Image_Text(
225+
$this->_imt = new ImageText(
226226
$this->_phrase,
227227
$options
228228
);
229229
if (PEAR::isError($e = $this->_imt->init())) {
230230
$this->_error = PEAR::raiseError(
231-
sprintf('Error initializing Image_Text (%s)',
232-
$e->getMessage()));
231+
sprintf(
232+
'Error initializing ImageText (%s)',
233+
$e->getMessage()
234+
)
235+
);
233236
return $this->_error;
234237
} else {
235-
$this->_created = true;
238+
$this->_created = true;
236239
}
237240
$result = $this->_imt->measurize();
238241
} while ($result === false && --$options['font_size'] > 0);
239242
if ($result === false) {
240243
$this->_error = PEAR::raiseError('The text provided does not fit in the image dimensions');
241244
return $this->_error;
242245
}
243-
$this->_imt->render();
244-
$this->_im =& $this->_imt->getImg();
246+
$this->_imt->render();
247+
$this->_im =& $this->_imt->getImg();
245248
$colors = $this->_imt->_convertString2RGB($this->_imageOptions['lines_color']);
246249
$lines_color = imagecolorallocate($this->_im, $colors['r'], $colors['g'], $colors['b']);
247250
//some obfuscation
@@ -277,7 +280,7 @@ public function getCAPTCHA()
277280
if (PEAR::isError($retval)) {
278281
return PEAR::raiseError($retval->getMessage());
279282
}
280-
283+
281284
if ($this->_output == 'gif' && !function_exists('imagegif')) {
282285
$this->_output = 'png';
283286
}
@@ -286,7 +289,7 @@ public function getCAPTCHA()
286289
case 'png':
287290
return $this->getCAPTCHAAsPNG();
288291
break;
289-
case 'jpg':
292+
case 'jpg':
290293
case 'jpeg':
291294
return $this->getCAPTCHAAsJPEG();
292295
break;
@@ -386,5 +389,5 @@ public function getCAPTCHAAsGIF()
386389
public function __wakeup()
387390
{
388391
$this->_created = false;
389-
}
392+
}
390393
}

0 commit comments

Comments
 (0)