Completed
Branch master (9dda00)
by Michael
04:54 queued 02:33
created

functions.render.php ➔ newbb_displayTarea()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
nc 24
nop 6
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * NewBB 5.0x,  the forum module for XOOPS project
4
 *
5
 * @copyright      XOOPS Project (http://xoops.org)
6
 * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
7
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
8
 * @since          4.00
9
 * @package        module::newbb
10
 */
11
12
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
13
14
defined('NEWBB_FUNCTIONS_INI') || include __DIR__ . '/functions.ini.php';
15
define('NEWBB_FUNCTIONS_RENDER_LOADED', true);
16
17
if (!defined('NEWBB_FUNCTIONS_RENDER')) {
18
    define('NEWBB_FUNCTIONS_RENDER', 1);
19
20
    /*
21
     * Sorry, we have to use the stupid solution unless there is an option in MyTextSanitizer:: htmlspecialchars();
22
     */
23
    /**
24
     * @param $text
25
     * @return mixed
26
     */
27
    function newbbHtmlspecialchars(&$text)
28
    {
29
        return preg_replace(['/&amp;/i', '/&nbsp;/i'], ['&', '&amp;nbsp;'], htmlspecialchars($text));
30
    }
31
32
    /**
33
     * @param        $text
34
     * @param  int   $html
35
     * @param  int   $smiley
36
     * @param  int   $xcode
37
     * @param  int   $image
38
     * @param  int   $br
39
     * @return mixed
40
     */
41
    function &newbbDisplayTarea(&$text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1)
42
    {
43
        global $myts;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
44
45
        if ($html !== 1) {
46
            // html not allowed
47
            $text = newbbHtmlspecialchars($text);
48
        }
49
        $text = $myts->codePreConv($text, $xcode); // Ryuji_edit(2003-11-18)
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
        $text = $myts->makeClickable($text);
51
        if ($smiley !== 0) {
52
            // process smiley
53
            $text = $myts->smiley($text);
54
        }
55
        if ($xcode !== 0) {
56
            // decode xcode
57
            if ($image !== 0) {
58
                // image allowed
59
                $text = $myts->xoopsCodeDecode($text);
60
            } else {
61
                // image not allowed
62
                $text = $myts->xoopsCodeDecode($text, 0);
63
            }
64
        }
65
        if ($br !== 0) {
66
            $text = $myts->nl2Br($text);
67
        }
68
        $text = $myts->codeConv($text, $xcode, $image);    // Ryuji_edit(2003-11-18)
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
70
        return $text;
71
    }
72
73
    /**
74
     * @param $document
75
     * @return string
76
     */
77
    function newbbHtml2text($document)
78
    {
79
        $text = strip_tags($document);
80
81
        return $text;
82
    }
83
84
    /**
85
     * Display forrum button
86
     *
87
     * @param          $link
88
     * @param          $button
89
     * @param  string  $alt     alt message
90
     * @param  boolean $asImage true for image mode; false for text mode
91
     * @param  string  $extra   extra attribute for the button
92
     * @return mixed
93
     * @internal param string $image image/button name, without extension
94
     */
95
    function newbbGetButton($link, $button, $alt = '', $asImage = true, $extra = "class='forum_button'")
96
    {
97
        $button = "<input type='button' name='{$button}' {$extra} value='{$alt}' onclick='window.location.href={$link}' />";
98
        if (empty($asImage)) {
99
            $button = "<a href='{$link}' title='{$alt}' {$extra}>" . newbbDisplayImage($button, $alt, true) . '</a>';
100
        }
101
102
        return $button;
103
    }
104
105
    /**
106
     * Display forrum images
107
     *
108
     * @param  string  $image   image name, without extension
109
     * @param  string  $alt     alt message
110
     * @param  boolean $display true for return image anchor; faulse for assign to $xoopsTpl
111
     * @param  string  $extra   extra attribute for the image
112
     * @return mixed
113
     */
114
    function newbbDisplayImage($image, $alt = '', $display = true, $extra = "class='forum_icon'")
0 ignored issues
show
Coding Style introduced by
newbbDisplayImage uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
115
    {
116
        $iconHandler = newbbGetIconHandler();
117
        // START hacked by irmtfan
118
        // to show text links instead of buttons - func_num_args()==2 => only when $image, $alt is set and optional $display not set
119
120
        if (func_num_args() == 2) {
121
            // overall setting
122
            if (!empty($GLOBALS['xoopsModuleConfig']['display_text_links'])) {
123
                $display = false;
124
            }
125
            // if set for each link => overwrite $display
126
            if (isset($GLOBALS['xoopsModuleConfig']['display_text_each_link'][$image])) {
127
                $display = empty($GLOBALS['xoopsModuleConfig']['display_text_each_link'][$image]);
128
            }
129
        }
130
        // END hacked by irmtfan
131
        if (empty($display)) {
132
            return $iconHandler->assignImage($image, $alt, $extra);
133
        } else {
134
            return $iconHandler->getImage($image, $alt, $extra);
135
        }
136
    }
137
138
    /**
139
     * @return NewbbIconHandler
140
     */
141
    function newbbGetIconHandler()
0 ignored issues
show
Coding Style introduced by
newbbGetIconHandler uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
142
    {
143
        global $xoTheme;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
144
        static $iconHandler;
145
146
        if (isset($iconHandler)) {
147
            return $iconHandler;
148
        }
149
150
        if (!class_exists('NewbbIconHandler')) {
151
            require_once dirname(__DIR__) . '/class/icon.php';
152
        }
153
154
        $iconHandler           = NewbbIconHandler::getInstance();
155
        $iconHandler->template = $xoTheme->template;
156
        $iconHandler->init($GLOBALS['xoopsConfig']['language']);
157
158
        return $iconHandler;
159
    }
160
}
161