Permalink
Browse files

remove getCaptchaHtml, move code to renderQuestion

  • Loading branch information...
1 parent 36882c1 commit f3ccb927ecd173a31640f686c735e7220b2321c6 @cweiske cweiske committed Mar 14, 2013
Showing with 24 additions and 29 deletions.
  1. +24 −29 HTML/QuickForm2/Element/Captcha/Image.php
@@ -148,45 +148,36 @@ protected function generateCaptcha()
$this->adapter->getCAPTCHA()
);
- // Clean up old images
- if (mt_rand(1, 10) == 1) {
- $this->garbageCollection();
- }
+ $this->garbageCollection();
return true;
}
/**
- * Returns the HTML for the captcha question and answer.
- *
- * Used in __toString() and to be used when $data['captchaRender']
- * is set to false.
- *
- * @uses $data['captchaHtmlAttributes'].
+ * Renders the CAPTCHA question in HTML and returns it.
+ * Returns empty string when "captchaRender" option is false.
*
- * @return string HTML code
+ * @return string HTML
*/
- public function getCaptchaHtml()
+ protected function renderQuestion()
{
- $prefix = '';
-
- if ($this->data['captchaRender']) {
- $prefix = '<div'
- . self::getAttributesString(
- $this->data['captchaHtmlAttributes']
- ) . '>'
- . '<img width="' . intval($this->getSession()->imageWidth) . '"'
- . ' height="' . intval($this->getSession()->imageHeight) . '"'
- . ' alt="CAPTCHA"'
- . ' src="' . htmlspecialchars(
- $this->imageDirUrl . $this->getSession()->question
- . '?ts=' . time()
- ) . '"'
- . '/>'
- . '</div>';
+ if (!$this->data['captchaRender']) {
+ return '';
}
- return $prefix . '<input' . $this->getAttributes(true) . ' />';
+ return '<div'
+ . self::getAttributesString(
+ $this->data['captchaHtmlAttributes']
+ ) . '>'
+ . '<img width="' . intval($this->getSession()->imageWidth) . '"'
+ . ' height="' . intval($this->getSession()->imageHeight) . '"'
+ . ' alt="CAPTCHA"'
+ . ' src="' . htmlspecialchars(
+ $this->imageDirUrl . $this->getSession()->question
+ . '?ts=' . time()
+ ) . '"'
+ . '/>'
+ . '</div>';
}
/**
@@ -196,6 +187,10 @@ public function getCaptchaHtml()
*/
protected function garbageCollection()
{
+ // Clean up old images
+ if (mt_rand(1, 10) != 1) {
+ return;
+ }
if (!$this->imageDir || (strlen($this->imageDir) < 2)) {
return;
}

0 comments on commit f3ccb92

Please sign in to comment.