Passed
Push — master ( 04fa92...8e4306 )
by Michael
03:48
created

newbbDisplayTarea()   A

Complexity

Conditions 6
Paths 24

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
nc 24
nop 6
dl 0
loc 30
rs 9.0777
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * NewBB 5.0x,  the forum module for XOOPS project
5
 *
6
 * @copyright      XOOPS Project (https://xoops.org)
7
 * @license        GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
8
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
9
 * @since          4.00
10
 */
11
12
use XoopsModules\Newbb\IconHandler;
13
14
/** @var IconHandler $iconHandler */
15
defined('NEWBB_FUNCTIONS_INI') || require __DIR__ . '/functions.ini.php';
16
define('NEWBB_FUNCTIONS_RENDER_LOADED', true);
17
18
if (!defined('NEWBB_FUNCTIONS_RENDER')) {
19
    define('NEWBB_FUNCTIONS_RENDER', 1);
20
21
    /*
22
     * Sorry, we have to use the stupid solution unless there is an option in MyTextSanitizer:: htmlspecialchars();
23
     */
24
    /**
25
     * @param $text
26
     * @return array|string|string[]|null
27
     */
28
    function newbbhtmlspecialchars($text)
29
    {
30
        return preg_replace(['/&amp;/i', '/&nbsp;/i'], ['&', '&amp;nbsp;'], htmlspecialchars((string)$text, ENT_QUOTES | ENT_HTML5));
31
    }
32
33
    /**
34
     * @param mixed $text
35
     * @param int   $html
36
     * @param int   $smiley
37
     * @param int   $xcode
38
     * @param int   $image
39
     * @param int   $br
40
     * @return mixed
41
     */
42
    function &newbbDisplayTarea(&$text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1)
43
    {
44
        global $myts;
45
46
        if (1 !== $html) {
47
            // html not allowed
48
            $text = newbbhtmlspecialchars($text);
49
        }
50
        $text = $myts->codePreConv($text, $xcode); // Ryuji_edit(2003-11-18)
51
        $text = $myts->makeClickable($text);
52
        if (0 !== $smiley) {
53
            // process smiley
54
            $text = $myts->smiley($text);
55
        }
56
        if (0 !== $xcode) {
57
            // decode xcode
58
            if (0 !== $image) {
59
                // image allowed
60
                $text = $myts->xoopsCodeDecode($text);
61
            } else {
62
                // image not allowed
63
                $text = $myts->xoopsCodeDecode($text, 0);
64
            }
65
        }
66
        if (0 !== $br) {
67
            $text = $myts->nl2Br($text);
68
        }
69
        $text = $myts->codeConv($text, $xcode, $image);    // Ryuji_edit(2003-11-18)
70
71
        return $text;
72
    }
73
74
    /**
75
     * @param $document
76
     * @return string
77
     */
78
    function newbbHtml2text($document)
79
    {
80
        $text = strip_tags($document);
81
82
        return $text;
83
    }
84
85
    /**
86
     * Display forrum button
87
     *
88
     * @param          $link
89
     * @param          $button
90
     * @param string   $alt     alt message
91
     * @param bool     $asImage true for image mode; false for text mode
92
     * @param string   $extra   extra attribute for the button
93
     * @return string
94
     * @internal param string $image image/button name, without extension
95
     */
96
    function newbbGetButton($link, $button, $alt = '', $asImage = true, $extra = "class='forum_button'")
97
    {
98
        $button = "<input type='button' name='{$button}' {$extra} value='{$alt}' onclick='window.location.href={$link}' >";
99
        if (empty($asImage)) {
100
            $button = "<a href='{$link}' title='{$alt}' {$extra}>" . newbbDisplayImage($button, $alt, true) . '</a>';
101
        }
102
103
        return $button;
104
    }
105
106
    /**
107
     * Display forrum images
108
     *
109
     * @param string $image   image name, without extension
110
     * @param string $alt     alt message
111
     * @param bool   $display true for return image anchor; faulse for assign to $xoopsTpl
112
     * @param string $extra   extra attribute for the image
113
     * @return mixed
114
     */
115
    function newbbDisplayImage($image, $alt = '', $display = true, $extra = "class='forum_icon'")
116
    {
117
        $iconHandler = newbbGetIconHandler();
118
        // START hacked by irmtfan
119
        // to show text links instead of buttons - func_num_args()==2 => only when $image, $alt is set and optional $display not set
120
121
        if (2 == func_num_args()) {
122
            // overall setting
123
            if (!empty($GLOBALS['xoopsModuleConfig']['display_text_links'])) {
124
                $display = false;
125
            }
126
            // if set for each link => overwrite $display
127
            if (isset($GLOBALS['xoopsModuleConfig']['display_text_each_link'][$image])) {
128
                $display = empty($GLOBALS['xoopsModuleConfig']['display_text_each_link'][$image]);
129
            }
130
        }
131
        // END hacked by irmtfan
132
        if (empty($display)) {
133
            return $iconHandler->assignImage($image, $alt, $extra);
134
        }
135
136
        return $iconHandler->getImage($image, $alt, $extra);
137
    }
138
139
    /**
140
     * @return IconHandler
141
     */
142
    function newbbGetIconHandler()
143
    {
144
        global $xoTheme;
145
        static $iconHandler;
146
147
        if (null !== $iconHandler) {
148
            return $iconHandler;
149
        }
150
151
        //        if (!class_exists('IconHandler')) {
152
        //            require_once \dirname(__DIR__) . '/class/icon.php';
153
        //        }
154
155
        $iconHandler           = IconHandler::getInstance();
156
        $iconHandler->template = $xoTheme->template;
157
        $iconHandler->init($GLOBALS['xoopsConfig']['language']);
158
159
        return $iconHandler;
160
    }
161
}
162