Passed
Push — master ( 11a5c5...26a351 )
by Goffy
04:01
created

getUserDefinedConstants()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
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
13
/**
14
 * modulebuilder module.
15
 *
16
 * @copyright       XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.5
20
 *
21
 * @author          Txmod Xoops <[email protected]>
22
 *
23
 */
24
25
use Xmf\Request;
26
use XoopsModules\Modulebuilder\Devtools;
27
28
$moduleDirName      = \basename(\dirname(__DIR__));
29
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
30
31
// Define main template
32
$templateMain = $moduleDirName . '_devtools.tpl';
33
34
include __DIR__ . '/header.php';
35
// Recovered value of argument op in the URL $
36
$op    = Request::getString('op', 'list');
37
38
switch ($op) {
39
    case 'fq':
40
        $fqModule = Request::getString('fq_module');
41
        $src_path = XOOPS_ROOT_PATH . '/modules/' . $fqModule;
42
        $dst_path = TDMC_UPLOAD_PATH . '/devtools/fq/' . $fqModule;
43
44
        $patKeys = [];
45
        $patValues = [];
46
        //Devtools::cloneFileFolder($src_path, $dst_path, $patKeys, $patValues);
47
        Devtools::function_qualifier($src_path, $dst_path, $fqModule);
48
        \redirect_header('devtools.php', 3, _AM_MODULEBUILDER_DEVTOOLS_FQ_SUCCESS);
49
        break;
50
    case 'check_lang':
51
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('devtools.php'));
52
        $clModuleName = Request::getString('cl_module');
53
        $clModuleNameUpper = \mb_strtoupper($clModuleName);
54
55
        //scan language files
56
        $src_path = XOOPS_ROOT_PATH . '/modules/' . $clModuleName . '/language/english/';
57
        $langfiles = [];
58
        foreach (scandir($src_path) as $scan) {
59
            if (is_file($src_path . $scan) && 'index.html' !== $scan && 'common.php' !== $scan) {
60
                $langfiles[] = $src_path . $scan;
61
            }
62
        }
63
        $moduleConstants = [];
64
        if (file_exists($src_path . 'common.php')) {
65
            // include common.php first
66
            $constantsBeforeInclude = getUserDefinedConstants();
67
            include_once($src_path . 'common.php');
68
            $constantsAfterInclude = getUserDefinedConstants();
69
            $moduleConstants[$src_path . 'common.php'] = array_diff_assoc($constantsAfterInclude, $constantsBeforeInclude);
70
        }
71
        foreach ($langfiles as $langfile) {
72
            $constantsBeforeInclude = getUserDefinedConstants();
73
            include_once($langfile);
74
            $constantsAfterInclude = getUserDefinedConstants();
75
            $moduleConstants[$langfile] = array_diff_assoc($constantsAfterInclude, $constantsBeforeInclude);
76
        }
77
78
        //get all php and tpl files from module
79
        $check_path = XOOPS_ROOT_PATH . '/modules/' . $clModuleName;
80
        $Directory = new RecursiveDirectoryIterator($check_path);
81
        $Iterator = new RecursiveIteratorIterator($Directory);
82
        $regexFiles = new RegexIterator($Iterator, '/^.+\.(php|tpl)$/i', RecursiveRegexIterator::GET_MATCH);
83
        //$files = new RegexIterator($flattened, '#^(?:[A-Z]:)?(?:/(?!\.Trash)[^/]+)+/[^/]+\.(?:php|html)$#Di');
84
        $modfiles = [];
85
        foreach($regexFiles as $regexFiles) {
86
            $file = str_replace('\\', '/', $regexFiles[0]);
87
            if (!\in_array($file, $langfiles)) {
88
                $modfiles[] = $file;
89
            }
90
        }
91
92
        //check all constants in all files
93
        $resultsList = [];
94
        foreach ($moduleConstants as $keyFile => $constFile) { 
95
            $resultCheck = [];
96
            foreach ($constFile as $constKey => $constValue) {
97
                $found = 0;
98
                $first = '';
99
                //search for complete string
100
                foreach($modfiles as $modfile) {
101
                    if( strpos(file_get_contents($modfile),$constKey) !== false) {
102
                        $found = 1;
103
                        $first = $modfile;
104
                        break;
105
                    }
106
                }
107
                if (0 == $found) {
108
                    //search for concatenated string
109
                    $needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_' . '", $constKey);
110
                    foreach($modfiles as $modfile) {
111
                        if( strpos(file_get_contents($modfile),$needle) !== false) {
112
                            $found = 1;
113
                            $first = $modfile;
114
                            break;
115
                        }
116
                    }
117
                }
118
                $resultCheck[] = ['define' => $constKey, 'found' => $found, 'first' => $first];
119
            }
120
            $resultsList[] = ['file' => $keyFile, 'result' => $resultCheck];
121
        }
122
123
        $GLOBALS['xoopsTpl']->assign('clresults', $resultsList);
124
        $GLOBALS['xoopsTpl']->assign('modPathIcon16', TDMC_URL . '/' . $modPathIcon16);
125
126
        break;
127
    case 'list':
128
    default:
129
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('devtools.php'));
130
        $dst_path = TDMC_UPLOAD_PATH . '/devtools/fq/';
131
        $GLOBALS['xoopsTpl']->assign('fq_desc',\str_replace('%s', $dst_path, _AM_MODULEBUILDER_DEVTOOLS_FQ_DESC));
132
        $fq_form = Devtools::getFormModulesFq();
133
        $GLOBALS['xoopsTpl']->assign('fq_form', $fq_form->render());
134
        $cl_form = Devtools::getFormModulesCl();
135
        $GLOBALS['xoopsTpl']->assign('cl_form', $cl_form->render());
136
        $GLOBALS['xoopsTpl']->assign('devtools_list',true);
137
138
        break;
139
}
140
141
function getUserDefinedConstants() {
142
    $constants = get_defined_constants(true);
143
    return (isset($constants['user']) ? $constants['user'] : array());
144
}
145
146
include __DIR__ . '/footer.php';
147
148
149
150
151