Completed
Push — master ( ed35ab...871ad1 )
by Michael
05:54
created

xoopsmlcontent.php ➔ langDropdown()   C

Complexity

Conditions 11
Paths 5

Size

Total Lines 44
Code Lines 33

Duplication

Lines 44
Ratio 100 %

Importance

Changes 0
Metric Value
cc 11
eloc 33
nc 5
nop 0
dl 44
loc 44
rs 5.2653
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
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 26 and the first side effect is on line 17.

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
 *  Xoopsmlcontent plugin for tinymce
4
 *
5
 * @copyright       (c) 2000-2014 XOOPS Project (www.xoops.org)
6
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
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
 * @version         $Id: xoopsmlcontent.php 12745 2014-08-27 03:30:37Z beckmi $
14
 */
15
16
// load mainfile.php - start
17
$current_path = __DIR__;
18
if (DIRECTORY_SEPARATOR != "/") {
19
    $current_path = str_replace( DIRECTORY_SEPARATOR, "/", $current_path);
20
}
21
$xoops_root_path = substr($current_path, 0, strpos(strtolower($current_path), "/class/xoopseditor/tinymce/"));
22
include_once $xoops_root_path . "/mainfile.php";
23
if (!defined("XOOPS_ROOT_PATH")) { die("XOOPS root path not defined"); }
24
// load mainfile.php - end
25
26 View Code Duplication
function langDropdown() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
langDropdown 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...
27
    $content = '';
28
29
    $time = time();
30
    if ( !isset( $_SESSION['XoopsMLcontent'] ) && @$_SESSION['XoopsMLcontent_expire'] < $time ) {
31
32
        include_once XOOPS_ROOT_PATH."/class/xoopsmodule.php";
33
        $xlanguage =& XoopsModule::getByDirname("xlanguage");
34
        if ( is_object($xlanguage) && $xlanguage->getVar('isactive') ) {
35
            include_once(XOOPS_ROOT_PATH.'/modules/xlanguage/include/vars.php');
36
            include_once(XOOPS_ROOT_PATH.'/modules/xlanguage/include/functions.php');
37
            $xlanguage_handler =& xoops_getmodulehandler('language', 'xlanguage');
38
            $xlanguage_handler->loadConfig();
39
            $lang_list =& $xlanguage_handler->getAllList();
40
41
            $content .= '<select name="mlanguages" id="mlanguages">';
42
            $content .= '<option value="">{#xoopsmlcontent_dlg.sellang}</option>';
43
            if ( is_array($lang_list)&&count( $lang_list ) > 0 ) {
44
                foreach ( array_keys($lang_list) as $lang_name ) {
45
                    $lang =& $lang_list[$lang_name];
46
                    $content .= '<option value="' . $lang['base']->getVar('lang_code') . '">' . $lang['base']->getVar('lang_name') . '</option>';
47
                }
48
            }
49
            $content .=  '</select>';
50
        } elseif ( defined('EASIESTML_LANGS') && defined('EASIESTML_LANGNAMES') ) {
51
            $easiestml_langs = explode( ',' , EASIESTML_LANGS ) ;
52
            $langnames = explode( ',' , EASIESTML_LANGNAMES ) ;
53
            $lang_options = '' ;
0 ignored issues
show
Unused Code introduced by
$lang_options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
55
            $content .= '<select name="mlanguages" id="mlanguages">';
56
            $content .= '<option value="">{#xoopsmlcontent_dlg.sellang}</option>';
57
            foreach ($easiestml_langs as $l => $lang) {
58
                $content .= '<option value="'.$lang.'">'.$langnames[$l].'</option>' ;
59
            }
60
            $content .= '</select>';
61
        } else {
62
            $content .= '<input type="text" name="mlanguages" />';
63
        }
64
        $_SESSION['XoopsMLcontent'] = $content;
65
        $_SESSION['XoopsMLcontent_expire'] = $time + 300;
66
    }
67
68
    echo $_SESSION['XoopsMLcontent'];
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');" onmousedown="return false;">{#xoopsmlcontent_dlg.title}</a></span></li>
91
        </ul>
92
    </div>
93
94
    <div class="panel_wrapper">
95
        <div id="mlcontent_panel" class="panel current" style="overflow:auto;">
96
            <table border="0" cellspacing="1" width="100%">
97
                <tr>
98
                    <th>{#xoopsmlcontent_dlg.subtitle}</th>
99
                </tr>
100
101
                <tr>
102
                    <td class="even"><?php langDropdown(); ?></th>
103
                </tr>
104
105
                <tr>
106
                    <td nowrap="nowrap">
107
                    <textarea type="text" id="mltext" name="mltext" value="" onkeyup="XoopsmlcontentDialog.onkeyupMLC(this);"></textarea>
108
                    </td>
109
                </tr>
110
                <tr>
111
                    <td class="foot bold">
112
                    <div id="mltext_msg"><script type="text/javascript">XoopsmlcontentDialog.onkeyupMLC(this);</script></div>
113
                    </td>
114
                </tr>
115
            </table>
116
117
            <div class="mceActionPanel floatright">
118
                <input type="submit" id="insert" name="insert" value="{#insert}" onclick="XoopsmlcontentDialog.insertMLC();return false;"/>
119
                <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
120
            </div>
121
        </div>
122
    </div>
123
</form>
124
</body>
125
</html>
126