Passed
Pull Request — master (#1323)
by Michael
05:22
created

langDropdown()   C

Complexity

Conditions 12
Paths 5

Size

Total Lines 43
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 32
nc 5
nop 0
dl 0
loc 43
rs 6.9666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 *  Xoopsmlcontent plugin for tinymce
4
 *
5
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
6
 * @license             GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
7
 * @package             class / xoopseditor
8
 * @subpackage          tinymce / xoops plugins
9
 * @since               2.3.0
10
 * @author              ralf57
11
 * @author              luciorota <[email protected]>
12
 * @author              Laurent JEN <[email protected]>
13
 */
14
15
// load mainfile.php - start
16
$current_path = __DIR__;
17
if (DIRECTORY_SEPARATOR !== '/') {
18
    $current_path = str_replace(DIRECTORY_SEPARATOR, '/', $current_path);
19
}
20
$xoops_root_path = substr($current_path, 0, strpos(strtolower($current_path), '/class/xoopseditor/tinymce/'));
21
include_once $xoops_root_path . '/mainfile.php';
22
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
23
// load mainfile.php - end
24
25
function langDropdown()
26
{
27
    $content = '';
28
29
    $time = time();
30
    if (!isset($_SESSION['XoopsMLcontent']) && (isset($_SESSION['XoopsMLcontent_expire']) && $_SESSION['XoopsMLcontent_expire'] < $time)) {
31
        include_once XOOPS_ROOT_PATH . '/kernel/module.php';
32
        $xlanguage = XoopsModule::getByDirname('xlanguage');
33
        if (is_object($xlanguage) && $xlanguage->getVar('isactive')) {
34
            include_once(XOOPS_ROOT_PATH . '/modules/xlanguage/include/vars.php');
35
            include_once(XOOPS_ROOT_PATH . '/modules/xlanguage/include/functions.php');
36
            $xlanguage_handler = xoops_getModuleHandler('language', 'xlanguage');
37
            $xlanguage_handler->loadConfig();
0 ignored issues
show
Bug introduced by
The method loadConfig() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            $xlanguage_handler->/** @scrutinizer ignore-call */ 
38
                                loadConfig();
Loading history...
38
            $lang_list =& $xlanguage_handler->getAllList();
0 ignored issues
show
Bug introduced by
The method getAllList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
            $lang_list =& $xlanguage_handler->/** @scrutinizer ignore-call */ getAllList();
Loading history...
39
40
            $content .= '<select name="mlanguages" id="mlanguages">';
41
            $content .= '<option value="">{#xoopsmlcontent_dlg.sellang}</option>';
42
            if (is_array($lang_list) && count($lang_list) > 0) {
43
                foreach (array_keys($lang_list) as $lang_name) {
44
                    $lang =& $lang_list[$lang_name];
45
                    $content .= '<option value="' . $lang['base']->getVar('lang_code') . '">' . $lang['base']->getVar('lang_name') . '</option>';
46
                }
47
            }
48
            $content .= '</select>';
49
        } elseif (defined('EASIESTML_LANGS') && defined('EASIESTML_LANGNAMES')) {
50
            $easiestml_langs = explode(',', EASIESTML_LANGS);
0 ignored issues
show
Bug introduced by
The constant EASIESTML_LANGS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
51
            $langnames       = explode(',', EASIESTML_LANGNAMES);
0 ignored issues
show
Bug introduced by
The constant EASIESTML_LANGNAMES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
52
            $lang_options    = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $lang_options is dead and can be removed.
Loading history...
53
54
            $content .= '<select name="mlanguages" id="mlanguages">';
55
            $content .= '<option value="">{#xoopsmlcontent_dlg.sellang}</option>';
56
            foreach ($easiestml_langs as $l => $lang) {
57
                $content .= '<option value="' . $lang . '">' . $langnames[$l] . '</option>';
58
            }
59
            $content .= '</select>';
60
        } else {
61
            $content .= '<input type="text" name="mlanguages" />';
62
        }
63
        $_SESSION['XoopsMLcontent']        = $content;
64
        $_SESSION['XoopsMLcontent_expire'] = $time + 300;
65
    }
66
67
    echo $_SESSION['XoopsMLcontent'];
68
}
69
70
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
71
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . '">';
72
echo '<head>';
73
echo '<meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" />';
74
echo '<meta http-equiv="content-language" content="' . _LANGCODE . '" />';
75
?>
76
<title>{#xoopsmlcontent_dlg.title}</title>
77
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
78
<script type="text/javascript" src="../../utils/mctabs.js"></script>
79
<script type="text/javascript" src="../../utils/form_utils.js"></script>
80
<script type="text/javascript" src="../../utils/validate.js"></script>
81
<script type="text/javascript" src="js/xoopsmlcontent.js"></script>
82
<link href="<?php echo xoops_getcss($xoopsConfig['theme_set']); ?>" rel="stylesheet" type="text/css"/>
83
<link href="css/xoopsmlcontent.css" rel="stylesheet" type="text/css"/>
84
<base target="_self"/>
85
</head>
86
<body>
87
<form>
88
    <div class="tabs">
89
        <ul>
90
            <li id="tab_mlcontent" class="current"><span><a href="javascript:mcTabs.displayTab('tab_mlcontent','mlcontent_panel');"
91
                                                            onmousedown="return false;">{#xoopsmlcontent_dlg.title}</a></span></li>
92
        </ul>
93
    </div>
94
95
    <div class="panel_wrapper">
96
        <div id="mlcontent_panel" class="panel current" style="overflow:auto;">
97
            <table border="0" cellspacing="1" width="100%">
98
                <tr>
99
                    <th>{#xoopsmlcontent_dlg.subtitle}</th>
100
                </tr>
101
102
                <tr>
103
                    <td class="even">
104
                    <?php langDropdown(); ?></td>
105
                </tr>
106
107
                <tr>
108
                    <td nowrap="nowrap">
109
                        <textarea type="text" id="mltext" name="mltext" value="" onkeyup="XoopsmlcontentDialog.onkeyupMLC(this);"></textarea>
110
                    </td>
111
                </tr>
112
                <tr>
113
                    <td class="foot bold">
114
                        <div id="mltext_msg">
115
                            <script type="text/javascript">XoopsmlcontentDialog.onkeyupMLC(this);</script>
116
                        </div>
117
                    </td>
118
                </tr>
119
            </table>
120
121
            <div class="mceActionPanel floatright">
122
                <input type="submit" id="insert" name="insert" value="{#insert}" onclick="XoopsmlcontentDialog.insertMLC();return false;"/>
123
                <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();"/>
124
            </div>
125
        </div>
126
    </div>
127
</form>
128
</body>
129
</html>
130