From 181b0cd0d07ca36cefc105409204dc64410c2ca4 Mon Sep 17 00:00:00 2001 From: Adelbert Silla Date: Mon, 29 Apr 2013 08:50:17 +0800 Subject: [PATCH 1/7] Added text_color option. --- DependencyInjection/Configuration.php | 1 + Generator/CaptchaGenerator.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index bac834d..cf87657 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -43,6 +43,7 @@ class Configuration implements ConfigurationInterface ->scalarNode('max_behind_lines')->defaultValue(null)->end() ->scalarNode('interpolation')->defaultValue(true)->end() ->arrayNode('background_color')->prototype('scalar')->end() + ->arrayNode('text_color')->prototype('scalar')->end() ->end() ; diff --git a/Generator/CaptchaGenerator.php b/Generator/CaptchaGenerator.php index e419580..08cde2d 100644 --- a/Generator/CaptchaGenerator.php +++ b/Generator/CaptchaGenerator.php @@ -98,6 +98,15 @@ class CaptchaGenerator $this->builder->setMaxFrontLines($options['max_front_lines']); $this->builder->setMaxBehindLines($options['max_behind_lines']); + if ($options['text_color'] != array()) { + if (count($options['text_color'])!=3) { + throw new \RuntimeException('text_color should be an array of r, g and b'); + } + + $color = $options['text_color']; + $this->builder->setTextColor($color[0], $color[1], $color[2]); + } + if ($options['background_color'] != array()) { if (count($options['background_color'])!=3) { throw new \RuntimeException('background_color should be an array of r, g and b'); From 1881d292b89192d609fe2a534f5d3a63ac5263d4 Mon Sep 17 00:00:00 2001 From: Adelbert Silla Date: Mon, 29 Apr 2013 10:13:58 +0800 Subject: [PATCH 2/7] Fixed text_color and background_color validation exception. --- Generator/CaptchaGenerator.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Generator/CaptchaGenerator.php b/Generator/CaptchaGenerator.php index 08cde2d..a588a54 100644 --- a/Generator/CaptchaGenerator.php +++ b/Generator/CaptchaGenerator.php @@ -98,17 +98,18 @@ class CaptchaGenerator $this->builder->setMaxFrontLines($options['max_front_lines']); $this->builder->setMaxBehindLines($options['max_behind_lines']); - if ($options['text_color'] != array()) { - if (count($options['text_color'])!=3) { - throw new \RuntimeException('text_color should be an array of r, g and b'); + + if (isset($options['text_color'])) { + if (count($options['text_color']) !== 3) { + throw new \RuntimeException('text_color should be an array of r, g and b'); } $color = $options['text_color']; $this->builder->setTextColor($color[0], $color[1], $color[2]); } - if ($options['background_color'] != array()) { - if (count($options['background_color'])!=3) { + if (isset($options['background_color'])) { + if (count($options['background_color']) !== 3) { throw new \RuntimeException('background_color should be an array of r, g and b'); } From daec205870f1e05d78a03cb773265bf5ed5cbcb3 Mon Sep 17 00:00:00 2001 From: Adelbert Silla Date: Mon, 29 Apr 2013 10:17:04 +0800 Subject: [PATCH 3/7] Adjust text_color execption line indention. --- Generator/CaptchaGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Generator/CaptchaGenerator.php b/Generator/CaptchaGenerator.php index a588a54..d4440fa 100644 --- a/Generator/CaptchaGenerator.php +++ b/Generator/CaptchaGenerator.php @@ -101,7 +101,7 @@ class CaptchaGenerator if (isset($options['text_color'])) { if (count($options['text_color']) !== 3) { - throw new \RuntimeException('text_color should be an array of r, g and b'); + throw new \RuntimeException('text_color should be an array of r, g and b'); } $color = $options['text_color']; From 7f30646c68d821fbd1105a94c8365b0a4396e4f0 Mon Sep 17 00:00:00 2001 From: Gregwar Date: Wed, 7 Aug 2013 10:56:49 +0200 Subject: [PATCH 4/7] Moving the "reload without as_url" exception to catch more cases (see --- DependencyInjection/GregwarCaptchaExtension.php | 4 ---- Type/CaptchaType.php | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/GregwarCaptchaExtension.php b/DependencyInjection/GregwarCaptchaExtension.php index 75b7246..83f4ddb 100755 --- a/DependencyInjection/GregwarCaptchaExtension.php +++ b/DependencyInjection/GregwarCaptchaExtension.php @@ -33,10 +33,6 @@ class GregwarCaptchaExtension extends Extension $container->setParameter('gregwar_captcha.config.expiration', $config['expiration']); $container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']); - if ($config['reload'] && !$config['as_url']) { - throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'); - } - $resources = $container->getParameter('twig.form.resources'); $container->setParameter('twig.form.resources', array_merge(array('GregwarCaptchaBundle::captcha.html.twig'), $resources)); } diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index 2a90ed7..2b10374 100644 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -90,6 +90,10 @@ class CaptchaType extends AbstractType { $isHuman = false; + if ($options['reload'] && !$options['as_url']) { + throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'); + } + if ($options['humanity'] > 0) { $humanityKey = $this->key.'_humanity'; if ($this->session->get($humanityKey, 0) > 0) { From 3f64e064d3a86d4e5b13304777ca4454c098769b Mon Sep 17 00:00:00 2001 From: Gregwar Date: Wed, 7 Aug 2013 11:18:16 +0200 Subject: [PATCH 5/7] Mergin & fixing text_color & background_color (fixes #57) --- DependencyInjection/Configuration.php | 4 ++-- Generator/CaptchaGenerator.php | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index cf87657..9f9fbd5 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -42,8 +42,8 @@ class Configuration implements ConfigurationInterface ->scalarNode('max_front_lines')->defaultValue(null)->end() ->scalarNode('max_behind_lines')->defaultValue(null)->end() ->scalarNode('interpolation')->defaultValue(true)->end() - ->arrayNode('background_color')->prototype('scalar')->end() - ->arrayNode('text_color')->prototype('scalar')->end() + ->arrayNode('text_color')->prototype('scalar')->end()->end() + ->arrayNode('background_color')->prototype('scalar')->end()->end() ->end() ; diff --git a/Generator/CaptchaGenerator.php b/Generator/CaptchaGenerator.php index d4440fa..60db59b 100644 --- a/Generator/CaptchaGenerator.php +++ b/Generator/CaptchaGenerator.php @@ -98,8 +98,7 @@ class CaptchaGenerator $this->builder->setMaxFrontLines($options['max_front_lines']); $this->builder->setMaxBehindLines($options['max_behind_lines']); - - if (isset($options['text_color'])) { + if (isset($options['text_color']) && $options['text_color']) { if (count($options['text_color']) !== 3) { throw new \RuntimeException('text_color should be an array of r, g and b'); } @@ -108,7 +107,7 @@ class CaptchaGenerator $this->builder->setTextColor($color[0], $color[1], $color[2]); } - if (isset($options['background_color'])) { + if (isset($options['background_color']) && $options['background_color']) { if (count($options['background_color']) !== 3) { throw new \RuntimeException('background_color should be an array of r, g and b'); } From 0b08b38cb03aee70c01703bc1cb823adefdbfa9e Mon Sep 17 00:00:00 2001 From: Gregwar Date: Wed, 7 Aug 2013 15:46:23 +0200 Subject: [PATCH 6/7] Enhancing documentation about font option (fixes #66) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33ee8fa..9a81582 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ You can define the following configuration options globally or on the CaptchaTyp * **length**: the length of the captcha (number of chars, default 5) * **quality**: jpeg quality of captchas (default=15) * **charset**: the charset used for code generation (default=abcdefhjkmnprstuvwxyz23456789) -* **font**: the font to use (default=Generator/Font/captcha.ttf) +* **font**: the font to use (default is random among some pre-provided fonts), this should be an absolute path * **keep_value**: the value will be the same until the form is posted, even if the page is refreshed (default=true) * **as_file**: if set to true an image file will be created instead of embedding to please IE6/7 (default=false) * **as_url**: if set to true, a URL will be used in the image tag and will handle captcha generation. This can be used in a multiple-server environment and support IE6/7 (default=false) From ddab3ef0058d784511ccc5b5f17b8dedeef34024 Mon Sep 17 00:00:00 2001 From: Sergey Lunev Date: Thu, 8 Aug 2013 16:31:34 +0400 Subject: [PATCH 7/7] Add translation to russian. --- Resources/translations/gregwar_captcha.ru.yml | 1 + Resources/translations/validators.ru.yml | 1 + 2 files changed, 2 insertions(+) create mode 100644 Resources/translations/gregwar_captcha.ru.yml create mode 100644 Resources/translations/validators.ru.yml diff --git a/Resources/translations/gregwar_captcha.ru.yml b/Resources/translations/gregwar_captcha.ru.yml new file mode 100644 index 0000000..a311cfa --- /dev/null +++ b/Resources/translations/gregwar_captcha.ru.yml @@ -0,0 +1 @@ +Renew: Обновить \ No newline at end of file diff --git a/Resources/translations/validators.ru.yml b/Resources/translations/validators.ru.yml new file mode 100644 index 0000000..dd4b7fa --- /dev/null +++ b/Resources/translations/validators.ru.yml @@ -0,0 +1 @@ +Bad code value: Неправильный код