1 | <?php |
||
61 | class Captcha extends InputWidget |
||
62 | { |
||
63 | /** |
||
64 | * @var string|array the route of the action that generates the CAPTCHA images. |
||
65 | * The action represented by this route must be an action of [[CaptchaAction]]. |
||
66 | * Please refer to [[\yii\helpers\Url::toRoute()]] for acceptable formats. |
||
67 | */ |
||
68 | public $captchaAction = 'site/captcha'; |
||
69 | /** |
||
70 | * @var array HTML attributes to be applied to the CAPTCHA image tag. |
||
71 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
72 | */ |
||
73 | public $imageOptions = []; |
||
74 | /** |
||
75 | * @var string the template for arranging the CAPTCHA image tag and the text input tag. |
||
76 | * In this template, the token `{image}` will be replaced with the actual image tag, |
||
77 | * while `{input}` will be replaced with the text input tag. |
||
78 | */ |
||
79 | public $template = '{image} {input}'; |
||
80 | /** |
||
81 | * @var array the HTML attributes for the input tag. |
||
82 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
83 | */ |
||
84 | public $options = ['class' => 'form-control']; |
||
85 | |||
86 | |||
87 | /** |
||
88 | * Initializes the widget. |
||
89 | */ |
||
90 | 1 | public function init() |
|
91 | { |
||
92 | 1 | parent::init(); |
|
93 | |||
94 | 1 | static::checkRequirements(); |
|
95 | |||
96 | if (!isset($this->imageOptions['id'])) { |
||
97 | $this->imageOptions['id'] = $this->options['id'] . '-image'; |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Renders the widget. |
||
103 | */ |
||
104 | public function run() |
||
124 | |||
125 | /** |
||
126 | * Registers the needed JavaScript. |
||
127 | */ |
||
128 | public function registerClientScript() |
||
137 | |||
138 | /** |
||
139 | * Returns the options for the captcha JS widget. |
||
140 | * @return array the options |
||
141 | */ |
||
142 | protected function getClientOptions() |
||
158 | |||
159 | /** |
||
160 | * Checks if there is graphic extension available to generate CAPTCHA images. |
||
161 | * This method will check the existence of ImageMagick and GD extensions. |
||
162 | * @return string the name of the graphic extension, either "imagick" or "gd". |
||
163 | * @throws InvalidConfigException if neither ImageMagick nor GD is installed. |
||
164 | */ |
||
165 | 1 | public static function checkRequirements() |
|
181 | } |
||
182 |