Completed
Push — master ( 98eeb4...22887c )
by Michael
11s
created

blocks/xlanguage_blocks.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * xLanguage module (eXtensible Language Management For XOOPS)
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright    XOOPS Project (https://xoops.org)
13
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
14
 * @package      xlanguage
15
 * @since        2.0
16
 * @author       D.J.(phppp) [email protected]
17
 * @param $options
18
 * @return array
19
 */
20
21
function b_xlanguage_select_show($options)
22
{
23
    global $xlanguage;
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...
24
25
    $block = array();
26
27
    /** @var \XlanguageLanguageHandler $xlanguageHandler */
28
    $xlanguageHandler = xoops_getModuleHandler('language', 'xlanguage');
29
    $xlanguageHandler->loadConfig();
30
    $lang_list = $xlanguageHandler->getAllList();
31
    if (!is_array($lang_list) || count($lang_list) < 1) {
32
        return $block;
33
    }
34
35
    $languages = array();
36
    foreach ($lang_list as $lang_name => $lang) {
37
        if (!isset($lang['base'])) {
38
            continue;
39
        }
40
        $languages[$lang_name]['name']  = $lang_name;
41
        $languages[$lang_name]['desc']  = $lang['base']->getVar('lang_desc');
42
        $languages[$lang_name]['image'] = XOOPS_URL . '/modules/xlanguage/assets/images/' . $lang['base']->getVar('lang_image');
43
        if (!isset($lang['ext']) || count($lang['ext']) < 1) {
44
            continue;
45
        }
46
        foreach ($lang['ext'] as $ext) {
47
            $languages[$ext->getVar('lang_name')]['name']  = $ext->getVar('lang_name');
48
            $languages[$ext->getVar('lang_name')]['desc']  = $ext->getVar('lang_desc');
49
            $languages[$ext->getVar('lang_name')]['image'] = XOOPS_URL . '/modules/xlanguage/assets/images/' . $ext->getVar('lang_image');
50
        }
51
    }
52
53
    $QUERY_STRING_array = array_filter(explode('&', xoops_getenv('QUERY_STRING')));
54
    $QUERY_STRING_new   = array();
55
    foreach ($QUERY_STRING_array as $QUERY) {
56
        if (0 !== strpos($QUERY, XLANGUAGE_LANG_TAG . '=')) {
57
            $vals = explode('=', $QUERY);
58
            foreach (array_keys($vals) as $key) {
59
                if (preg_match('/^a-z0-9$/i', $vals[$key])) {
60
                    $vals[$key] = urlencode($vals[$key]);
61
                }
62
            }
63
            $QUERY_STRING_new[] = implode('=', $vals);
64
        }
65
    }
66
67
    $block['display']   = $options[0];
68
    $block['delimitor'] = $options[1];
69
    $block['number']    = $options[2];
70
    $block['selected']  = $xlanguage['lang'];
71
    if ($options[0] === 'images' || $options[0] === 'text') {
72
        $query_string = htmlspecialchars(implode('&', $QUERY_STRING_new));
73
        $query_string .= empty($query_string) ? '' : '&amp;';
74
    } else {
75
        $query_string = implode('&', array_map('htmlspecialchars', $QUERY_STRING_new));
76
        $query_string .= empty($query_string) ? '' : '&';
77
    }
78
    $block['url']       = xoops_getenv('PHP_SELF') . '?' . $query_string . XLANGUAGE_LANG_TAG . '=';
79
    $block['languages'] =& $languages;
80
81
    return $block;
82
}
83
84
/**
85
 * @param $options
86
 * @return string
87
 */
88
function b_xlanguage_select_edit($options)
89
{
90
    $form = _MB_XLANGUAGE_DISPLAY_METHOD . "&nbsp;<select name='options[]'>";
91
    $form .= "<option value='images'";
92
    if ($options[0] === 'images') {
93
        $form .= ' selected';
94
    }
95
    $form .= '>' . _MB_XLANGUAGE_DISPLAY_FLAGLIST . "</option>\n";
96
    $form .= "<option value='text'";
97
    if ($options[0] === 'text') {
98
        $form .= ' selected';
99
    }
100
    $form .= '>' . _MB_XLANGUAGE_DISPLAY_TEXTLIST . "</option>\n";
101
    $form .= "<option value='dropdown'";
102
    if ($options[0] === 'dropdown') {
103
        $form .= ' selected';
104
    }
105
    $form .= '>' . _MB_XLANGUAGE_DISPLAY_DROPDOWNLIST . "</option>\n";
106
    $form .= "</select>\n";
107
    $form .= '<br>' . _MB_XLANGUAGE_IMAGE_SEPARATOR . ' (' . _MB_XLANGUAGE_OPTIONAL . "):&nbsp;<input type='text' name='options[]' value='" . $options[1] . "'>";
108
    $form .= '<br>' . _MB_XLANGUAGE_IMAGE_PERROW . ' (' . _MB_XLANGUAGE_OPTIONAL . "):&nbsp;<input type='text' name='options[]' value='" . $options[2] . "'>";
109
110
    return $form;
111
}
112