newbbTrackbackResponse()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 18
nc 4
nop 2
dl 0
loc 23
rs 9.6666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * NewBB,  the forum module for XOOPS project
4
 *
5
 * @copyright      XOOPS Project (https://xoops.org)
6
 * @license        GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
7
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
8
 * @since          4.00
9
 */
10
defined('NEWBB_FUNCTIONS_INI') || require __DIR__ . '/functions.ini.php';
11
define('NEWBB_FUNCTIONS_RPC_LOADED', true);
12
13
if (!defined('NEWBB_FUNCTIONS_RPC')) {
14
    define('NEWBB_FUNCTIONS_RPC', 1);
15
16
    /**
17
     * Function to respond to a trackback
18
     * @param int    $error
19
     * @param string $error_message
20
     */
21
    function newbbTrackbackResponse(int $error = 0, string $error_message = ''): void
22
    {
23
        $moduleConfig = newbbLoadConfig();
24
25
        if (!empty($moduleConfig['rss_utf8'])) {
26
            $charset       = 'utf-8';
27
            $error_message = xoops_utf8_encode($error_message);
0 ignored issues
show
Unused Code introduced by
The assignment to $error_message is dead and can be removed.
Loading history...
28
        } else {
29
            $charset = _CHARSET;
30
        }
31
        header('Content-Type: text/xml; charset="' . $charset . '"');
32
        if ($error) {
33
            echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n";
34
            echo '<response>\n';
35
            echo '<error>1</error>\n';
36
            echo '<message>$error_message</message>\n';
37
            echo '</response>';
38
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
39
        }
40
        echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n";
41
        echo '<response>\n';
42
        echo '<error>0</error>\n';
43
        echo '</response>';
44
    }
45
}
46