XoopsCaptchaImage::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Image Creation class for CAPTCHA
5
 *
6
 * D.J.
7
 */
8
class XoopsCaptchaImage
9
{
10
    public $config = [];
11
12
    /**
13
     * XoopsCaptchaImage constructor.
14
     */
15
    public function __construct()
16
    {
17
        //$this->name = md5( session_id() );
18
    }
19
20
    /**
21
     * @return XoopsCaptchaImage
22
     */
23
    public static function getInstance()
24
    {
25
        static $instance;
26
        if (null === $instance) {
27
            $instance = new static();
28
        }
29
30
        return $instance;
31
    }
32
33
    /**
34
     * Loading configs from CAPTCHA class
35
     * @param array $config
36
     */
37
    public function loadConfig($config = [])
38
    {
39
        // Loading default preferences
40
        $this->config = $config;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function render()
47
    {
48
        $form = "<input type='text' name='" . $this->config['name'] . "' id='" . $this->config['name'] . "' size='" . $this->config['num_chars'] . "' maxlength='" . $this->config['num_chars'] . "' value=''> &nbsp; " . $this->loadImage();
49
        $rule = htmlspecialchars(XOOPS_CAPTCHA_REFRESH, ENT_QUOTES);
50
        if ($this->config['maxattempt']) {
51
            $rule .= ' | ' . sprintf(constant('XOOPS_CAPTCHA_MAXATTEMPTS'), $this->config['maxattempt']);
52
        }
53
        $form .= "&nbsp;&nbsp;<small>{$rule}</small>";
54
55
        return $form;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function loadImage()
62
    {
63
        $rule = $this->config['casesensitive'] ? constant('XOOPS_CAPTCHA_RULE_CASESENSITIVE') : constant('XOOPS_CAPTCHA_RULE_CASEINSENSITIVE');
64
        $ret  = "<img id='captcha' src='" . XOOPS_URL . '/' . $this->config['imageurl'] . "' onclick=\"this.src='" . XOOPS_URL . '/' . $this->config['imageurl'] . "?refresh='+Math.random()" . "\" align='absmiddle'  style='cursor: pointer;' alt='" . htmlspecialchars($rule, ENT_QUOTES) . "'>";
65
66
        return $ret;
67
    }
68
}
69