Commit 93027869 by Alexander Makarov

Fixes #5598: added ImageMagick with PNG and GD with FreeType checks to…

Fixes #5598: added ImageMagick with PNG and GD with FreeType checks to requirements of basic and advanced applications, used better Captcha exception message
parent 6e7cd9fd
...@@ -23,6 +23,28 @@ if (!is_dir($frameworkPath)) { ...@@ -23,6 +23,28 @@ if (!is_dir($frameworkPath)) {
require_once($frameworkPath . '/requirements/YiiRequirementChecker.php'); require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
$requirementsChecker = new YiiRequirementChecker(); $requirementsChecker = new YiiRequirementChecker();
$gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
$gdOK = $imagickOK = false;
if (extension_loaded('imagick')) {
$imagick = new Imagick();
$imagickFormats = $imagick->queryFormats('PNG');
if (in_array('PNG', $imagickFormats)) {
$imagickOK = true;
} else {
$imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
}
}
if (extension_loaded('gd')) {
$gdInfo = gd_info();
if (!empty($gdInfo['FreeType Support'])) {
$gdOK = true;
} else {
$gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
}
}
/** /**
* Adjust requirements according to your application specifics. * Adjust requirements according to your application specifics.
*/ */
...@@ -69,6 +91,21 @@ $requirements = array( ...@@ -69,6 +91,21 @@ $requirements = array(
'condition' => extension_loaded('apc'), 'condition' => extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>', 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>',
), ),
// CAPTCHA:
array(
'name' => 'GD PHP extension with FreeType support',
'mandatory' => false,
'condition' => $gdOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $gdMemo,
),
array(
'name' => 'ImageMagick PHP extension with PNG support',
'mandatory' => false,
'condition' => $imagickOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $imagickMemo,
),
// PHP ini : // PHP ini :
'phpSafeMode' => array( 'phpSafeMode' => array(
'name' => 'PHP safe mode', 'name' => 'PHP safe mode',
......
...@@ -23,6 +23,28 @@ if (!is_dir($frameworkPath)) { ...@@ -23,6 +23,28 @@ if (!is_dir($frameworkPath)) {
require_once($frameworkPath . '/requirements/YiiRequirementChecker.php'); require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
$requirementsChecker = new YiiRequirementChecker(); $requirementsChecker = new YiiRequirementChecker();
$gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
$gdOK = $imagickOK = false;
if (extension_loaded('imagick')) {
$imagick = new Imagick();
$imagickFormats = $imagick->queryFormats('PNG');
if (in_array('PNG', $imagickFormats)) {
$imagickOK = true;
} else {
$imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
}
}
if (extension_loaded('gd')) {
$gdInfo = gd_info();
if (!empty($gdInfo['FreeType Support'])) {
$gdOK = true;
} else {
$gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
}
}
/** /**
* Adjust requirements according to your application specifics. * Adjust requirements according to your application specifics.
*/ */
...@@ -69,6 +91,21 @@ $requirements = array( ...@@ -69,6 +91,21 @@ $requirements = array(
'condition' => extension_loaded('apc'), 'condition' => extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>', 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>',
), ),
// CAPTCHA:
array(
'name' => 'GD PHP extension with FreeType support',
'mandatory' => false,
'condition' => $gdOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $gdMemo,
),
array(
'name' => 'ImageMagick PHP extension with PNG support',
'mandatory' => false,
'condition' => $imagickOK,
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
'memo' => $imagickMemo,
),
// PHP ini : // PHP ini :
'phpSafeMode' => array( 'phpSafeMode' => array(
'name' => 'PHP safe mode', 'name' => 'PHP safe mode',
......
...@@ -151,6 +151,6 @@ class Captcha extends InputWidget ...@@ -151,6 +151,6 @@ class Captcha extends InputWidget
return 'gd'; return 'gd';
} }
} }
throw new InvalidConfigException('GD with FreeType or ImageMagick PHP extensions are required.'); throw new InvalidConfigException('Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required.');
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment