Completed
Branch master (616741)
by Michael
03:30 queued 01:05
created

XoopsGTicket::renderRepostForm()   C

Complexity

Conditions 8
Paths 17

Size

Total Lines 48
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 35
nc 17
nop 1
dl 0
loc 48
rs 5.9322
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 31 and the first side effect is on line 416.

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
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
// GIJOE's Ticket Class (based on Marijuana's Oreteki XOOPS)
24
// nobunobu's suggestions are applied
25
26
if (!class_exists('XoopsGTicket')) {
27
28
    /**
29
     * Class XoopsGTicket
30
     */
31
    class XoopsGTicket
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
32
    {
33
        public $_errors       = array();
34
        public $_latest_token = '';
35
        public $messages      = array();
36
37
        /**
38
         * XoopsGTicket constructor.
39
         */
40
        public function __construct()
41
        {
42
            global $xoopsConfig;
43
44
            // language file
45
            if (defined('XOOPS_ROOT_PATH') && !empty($xoopsConfig['language'])
46
                && false === strpos($xoopsConfig['language'], '/')
47
            ) {
48
                if (file_exists(dirname(__DIR__) . '/language/' . $xoopsConfig['language'] . '/gticket_messages.phtml')) {
49
                    include dirname(__DIR__) . '/language/' . $xoopsConfig['language'] . '/gticket_messages.phtml';
50
                }
51
            }
52
53
            // default messages
54
            if (empty($this->messages)) {
55
                $this->messages = array(
56
                    'err_general'       => 'GTicket Error',
57
                    'err_nostubs'       => 'No stubs found',
58
                    'err_noticket'      => 'No ticket found',
59
                    'err_nopair'        => 'No valid ticket-stub pair found',
60
                    'err_timeout'       => 'Time out',
61
                    'err_areaorref'     => 'Invalid area or referer',
62
                    'fmt_prompt4repost' => 'error(s) found:<br><span style="background-color:red;font-weight:bold;color:white;">%s</span><br>Confirm it.<br>And do you want to post again?',
63
                    'btn_repost'        => 'repost'
64
                );
65
            }
66
        }
67
68
        // render form as plain html
69
        /**
70
         * @param string $salt
71
         * @param int    $timeout
72
         * @param string $area
73
         *
74
         * @return string
75
         */
76
        public function getTicketHtml($salt = '', $timeout = 1800, $area = '')
77
        {
78
            return '<input type="hidden" name="XOOPS_G_TICKET" value="' . $this->issue($salt, $timeout, $area) . '" />';
79
        }
80
81
        // returns an object of XoopsFormHidden including theh ticket
82
        /**
83
         * @param string $salt
84
         * @param int    $timeout
85
         * @param string $area
86
         *
87
         * @return XoopsFormHidden
88
         */
89
        public function getTicketXoopsForm($salt = '', $timeout = 1800, $area = '')
90
        {
91
            return new XoopsFormHidden('XOOPS_G_TICKET', $this->issue($salt, $timeout, $area));
92
        }
93
94
        // add a ticket as Hidden Element into XoopsForm
95
        /**
96
         * @param        $form
97
         * @param string $salt
98
         * @param int    $timeout
99
         * @param string $area
100
         */
101
        public function addTicketXoopsFormElement(&$form, $salt = '', $timeout = 1800, $area = '')
102
        {
103
            $form->addElement(new XoopsFormHidden('XOOPS_G_TICKET', $this->issue($salt, $timeout, $area)));
104
        }
105
106
        // returns an array for xoops_confirm() ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
107
        /**
108
         * @param string $salt
109
         * @param int    $timeout
110
         * @param string $area
111
         *
112
         * @return array
113
         */
114
        public function getTicketArray($salt = '', $timeout = 1800, $area = '')
115
        {
116
            return array('XOOPS_G_TICKET' => $this->issue($salt, $timeout, $area));
117
        }
118
119
        // return GET parameter string.
120
        /**
121
         * @param string $salt
122
         * @param bool   $noamp
123
         * @param int    $timeout
124
         * @param string $area
125
         *
126
         * @return string
127
         */
128
        public function getTicketParamString($salt = '', $noamp = false, $timeout = 1800, $area = '')
129
        {
130
            return ($noamp ? '' : '&amp;') . 'XOOPS_G_TICKET=' . $this->issue($salt, $timeout, $area);
131
        }
132
133
        // issue a ticket
134
        /**
135
         * @param string $salt
136
         * @param int    $timeout
137
         * @param string $area
138
         *
139
         * @return string
140
         */
141
        public function issue($salt = '', $timeout = 1800, $area = '')
0 ignored issues
show
Coding Style introduced by
issue uses the super-global variable $_SERVER 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...
Coding Style introduced by
issue uses the super-global variable $_SESSION 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 $xoopsModule;
144
145
            // create a token
146
            list($usec, $sec) = explode(' ', microtime());
147
            $appendix_salt       = empty($_SERVER['PATH']) ? XOOPS_DB_NAME : $_SERVER['PATH'];
148
            $token               = crypt($salt . $usec . $appendix_salt . $sec, $salt);
149
            $this->_latest_token = $token;
150
151
            if (empty($_SESSION['XOOPS_G_STUBS'])) {
152
                $_SESSION['XOOPS_G_STUBS'] = array();
153
            }
154
155
            // limit max stubs 10
156
            if (count($_SESSION['XOOPS_G_STUBS']) > 10) {
157
                $_SESSION['XOOPS_G_STUBS'] = array_slice($_SESSION['XOOPS_G_STUBS'], -10);
158
            }
159
160
            // record referer if browser send it
161
            $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['REQUEST_URI'];
162
163
            // area as module's dirname
164
            if (!$area && is_object(@$xoopsModule)) {
165
                $area = $xoopsModule->getVar('dirname');
166
            }
167
168
            // store stub
169
            $_SESSION['XOOPS_G_STUBS'][] = array(
170
                'expire'  => time() + $timeout,
171
                'referer' => $referer,
172
                'area'    => $area,
173
                'token'   => $token
174
            );
175
176
            // paid md5ed token as a ticket
177
            return md5($token . XOOPS_DB_PREFIX);
178
        }
179
180
        // check a ticket
181
        /**
182
         * @param bool   $post
183
         * @param string $area
184
         * @param bool   $allow_repost
185
         *
186
         * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be null|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
187
         */
188
        public function check($post = true, $area = '', $allow_repost = true)
0 ignored issues
show
Coding Style introduced by
check uses the super-global variable $_SESSION 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...
Coding Style introduced by
check uses the super-global variable $_SERVER 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...
189
        {
190
            global $xoopsModule;
191
192
            $this->_errors = array();
193
194
            // CHECK: stubs are not stored in session
195
            if (!is_array(@$_SESSION['XOOPS_G_STUBS'])) {
196
                $this->_errors[]           = $this->messages['err_nostubs'];
197
                $_SESSION['XOOPS_G_STUBS'] = array();
198
            }
199
200
            // get key&val of the ticket from a user's query
201
            $ticket = $post ? @Request::getString('XOOPS_G_TICKET', '', 'POST') : @Request::getString('XOOPS_G_TICKET', '', 'GET') ;
202
203
            // CHECK: no tickets found
204
            if (empty($ticket)) {
205
                $this->_errors[] = $this->messages['err_noticket'];
206
            }
207
208
            // gargage collection & find a right stub
209
            $stubs_tmp                 = $_SESSION['XOOPS_G_STUBS'];
210
            $_SESSION['XOOPS_G_STUBS'] = array();
211
            foreach ($stubs_tmp as $stub) {
212
                // default lifetime 30min
213
                if ($stub['expire'] >= time()) {
214
                    if (md5($stub['token'] . XOOPS_DB_PREFIX) === $ticket) {
215
                        $found_stub = $stub;
216
                    } else {
217
                        // store the other valid stubs into session
218
                        $_SESSION['XOOPS_G_STUBS'][] = $stub;
219
                    }
220
                } else {
221
                    if (md5($stub['token'] . XOOPS_DB_PREFIX) === $ticket) {
222
                        // not CSRF but Time-Out
223
                        $timeout_flag = true;
224
                    }
225
                }
226
            }
227
228
            // CHECK: the right stub found or not
229
            if (empty($found_stub)) {
230
                if (empty($timeout_flag)) {
231
                    $this->_errors[] = $this->messages['err_nopair'];
232
                } else {
233
                    $this->_errors[] = $this->messages['err_timeout'];
234
                }
235
            } else {
236
237
                // set area if necessary
238
                // area as module's dirname
239
                if (!$area && is_object(@$xoopsModule)) {
240
                    $area = $xoopsModule->getVar('dirname');
241
                }
242
243
                // check area or referer
244
                if (@$found_stub['area'] == $area) {
245
                    $area_check = true;
246
                }
247
                if (!empty($found_stub['referer'])
248
                    && true === strpos(@$_SERVER['HTTP_REFERER'], $found_stub['referer'])
249
                ) {
250
                    $referer_check = true;
251
                }
252
253
                if (empty($area_check) && empty($referer_check)) { // loose
254
                    $this->_errors[] = $this->messages['err_areaorref'];
255
                }
256
            }
257
258
            if (!empty($this->_errors)) {
259
                if ($allow_repost) {
260
                    // repost form
261
                    $this->renderRepostForm($area);
262
                    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method check() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
263
                } else {
264
                    // failed
265
                    $this->clear();
266
267
                    return false;
268
                }
269
            } else {
270
                // all green
271
                return true;
272
            }
273
        }
274
275
        // draw form for repost
276
        /**
277
         * @param string $area
278
         */
279
        public function renderRepostForm($area = '')
0 ignored issues
show
Coding Style introduced by
renderRepostForm uses the super-global variable $_SERVER 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...
Coding Style introduced by
renderRepostForm uses the super-global variable $_POST 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...
280
        {
281
            // Notify which file is broken
282
            if (headers_sent()) {
283
                restore_error_handler();
284
                set_error_handler('GTicket_ErrorHandler4FindOutput');
285
                header('Dummy: for warning');
286
                restore_error_handler();
287
                exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method renderRepostForm() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
288
            }
289
290
            error_reporting(0);
291
            while (ob_get_level()) {
292
                ob_end_clean();
293
            }
294
295
            $table = '<table>';
296
            $form  = '<form action="?' . htmlspecialchars(@$_SERVER['QUERY_STRING'], ENT_QUOTES) . '" method="post" >';
297
            foreach ($_POST as $key => $val) {
298
                if ($key === 'XOOPS_G_TICKET') {
299
                    continue;
300
                }
301
                if (get_magic_quotes_gpc()) {
302
                    $key = stripslashes($key);
303
                }
304
                if (is_array($val)) {
305
                    list($tmp_table, $tmp_form) = $this->extractPostRecursive(htmlspecialchars($key, ENT_QUOTES), $val);
306
                    $table .= $tmp_table;
307
                    $form .= $tmp_form;
308
                } else {
309
                    if (get_magic_quotes_gpc()) {
310
                        $val = stripslashes($val);
311
                    }
312
                    $table .= '<tr><th>' . htmlspecialchars($key, ENT_QUOTES) . '</th><td>' . htmlspecialchars($val, ENT_QUOTES) . '</td></tr>' . "\n";
313
                    $form .= '<input type="hidden" name="' . htmlspecialchars($key, ENT_QUOTES) . '" value="' . htmlspecialchars($val, ENT_QUOTES) . '" />' . "\n";
314
                }
315
            }
316
            $table .= '</table>';
317
            $form .= $this->getTicketHtml(__LINE__, 300, $area) . '<input type="submit" value="' . $this->messages['btn_repost'] . '" /></form>';
318
319
            echo '<html><head><title>'
320
                 . $this->messages['err_general']
321
                 . '</title><style>table,td,th {border:solid black 1px; border-collapse:collapse;}</style></head><body>'
322
                 . sprintf($this->messages['fmt_prompt4repost'], $this->getErrors())
323
                 . $table
324
                 . $form
325
                 . '</body></html>';
326
        }
327
328
        /**
329
         * @param $key_name
330
         * @param $tmp_array
331
         *
332
         * @return array
333
         */
334
        public function extractPostRecursive($key_name, $tmp_array)
335
        {
336
            $table = '';
337
            $form  = '';
338
            foreach ($tmp_array as $key => $val) {
339
                if (get_magic_quotes_gpc()) {
340
                    $key = stripslashes($key);
341
                }
342
                if (is_array($val)) {
343
                    list($tmp_table, $tmp_form) = $this->extractPostRecursive($key_name . '[' . htmlspecialchars($key, ENT_QUOTES) . ']', $val);
344
                    $table .= $tmp_table;
345
                    $form .= $tmp_form;
346
                } else {
347
                    if (get_magic_quotes_gpc()) {
348
                        $val = stripslashes($val);
349
                    }
350
                    $table .= '<tr><th>' . $key_name . '[' . htmlspecialchars($key, ENT_QUOTES) . ']</th><td>' . htmlspecialchars($val, ENT_QUOTES) . '</td></tr>' . "\n";
351
                    $form .= '<input type="hidden" name="' . $key_name . '[' . htmlspecialchars($key, ENT_QUOTES) . ']" value="' . htmlspecialchars($val, ENT_QUOTES) . '" />' . "\n";
352
                }
353
            }
354
355
            return array($table, $form);
356
        }
357
358
        // clear all stubs
359
        public function clear()
0 ignored issues
show
Coding Style introduced by
clear uses the super-global variable $_SESSION 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...
360
        {
361
            $_SESSION['XOOPS_G_STUBS'] = array();
362
        }
363
364
        // Ticket Using
365
        /**
366
         * @return bool
367
         */
368
        public function using()
0 ignored issues
show
Coding Style introduced by
using uses the super-global variable $_SESSION 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...
369
        {
370
            if (!empty($_SESSION['XOOPS_G_STUBS'])) {
371
                return true;
372
            } else {
373
                return false;
374
            }
375
        }
376
377
        // return errors
378
        /**
379
         * @param bool $ashtml
380
         *
381
         * @return array|string
382
         */
383
        public function getErrors($ashtml = true)
384
        {
385
            if ($ashtml) {
386
                $ret = '';
387
                foreach ($this->_errors as $msg) {
388
                    $ret .= "$msg<br>\n";
389
                }
390
            } else {
391
                $ret = $this->_errors;
392
            }
393
394
            return $ret;
395
        }
396
397
        // end of class
398
    }
399
400
    /**
401
     * @param $errNo
402
     * @param $errStr
403
     * @param $errFile
404
     * @param $errLine
405
     */
406
    function GTicket_ErrorHandler4FindOutput($errNo, $errStr, $errFile, $errLine)
0 ignored issues
show
Unused Code introduced by
The parameter $errNo is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errFile is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errLine is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
407
    {
408
        if (preg_match('?' . preg_quote(XOOPS_ROOT_PATH) . '([^:]+)\:(\d+)?', $errStr, $regs)) {
409
            echo 'Irregular output! check the file ' . htmlspecialchars($regs[1]) . ' line ' . htmlspecialchars($regs[2]);
410
        } else {
411
            echo 'Irregular output! check language files etc.';
412
        }
413
    }
414
415
    // create a instance in global scope
416
    $GLOBALS['xoopsGTicket'] = new XoopsGTicket();
417
}
418
419
if (!function_exists('admin_refcheck')) {
420
421
    //Admin Referer Check By Marijuana(Rev.011)
422
    /**
423
     * @param string $chkref
424
     *
425
     * @return bool
426
     */
427
    function admin_refcheck($chkref = '')
0 ignored issues
show
Coding Style introduced by
admin_refcheck uses the super-global variable $_SERVER 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...
428
    {
429
        if (empty($_SERVER['HTTP_REFERER'])) {
430
            return true;
431
        } else {
432
            $ref = $_SERVER['HTTP_REFERER'];
433
        }
434
        $cr = XOOPS_URL;
435
        if ($chkref != '') {
436
            $cr .= $chkref;
437
        }
438
        if (strpos($ref, $cr) !== 0) {
439
            return false;
440
        }
441
442
        return true;
443
    }
444
}
445