XoopsCaptchaImage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstance() 0 9 2
A loadConfig() 0 5 1
A render() 0 11 2
A loadImage() 0 7 2
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