Passed
Push — master ( 856304...9f6f9b )
by Goffy
03:36
created

UserXoopsCode::getUserBreadcrumbs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\User;
4
5
use XoopsModules\Modulebuilder;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * modulebuilder module.
18
 *
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 *
22
 * @since           2.5.0
23
 *
24
 * @author          Txmod Xoops http://www.txmodxoops.org
25
 *
26
 */
27
28
/**
29
 * Class UserXoopsCode.
30
 */
31
class UserXoopsCode
32
{
33
    /**
34
     * @var string
35
     */
36
    private $xc = null;
37
38
    /**
39
     * @var string
40
     */
41
    private $pc = null;
42
43
    /**
44
     * @public function constructor
45
     * @param null
46
     */
47
    public function __construct()
48
    {
49
        $this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Modulebuild...oopsCode::getInstance() of type XoopsModules\Modulebuilder\Files\CreateXoopsCode is incompatible with the declared type string of property $xc.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
        $this->pc = Modulebuilder\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Modulebuild...ePhpCode::getInstance() of type XoopsModules\Modulebuilder\Files\CreatePhpCode is incompatible with the declared type string of property $pc.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
    }
52
53
    /*
54
    *  @static function getInstance
55
    *  @param null
56
    */
57
58
    /**
59
     * @return UserXoopsCode
60
     */
61
    public static function getInstance()
62
    {
63
        static $instance = false;
64
        if (!$instance) {
65
            $instance = new self();
66
        }
67
68
        return $instance;
69
    }
70
71
    /**
72
     * @public function getUserTplMain
73
     *
74
     * @param        $moduleDirname
75
     * @param string $tableName
76
     *
77
     * @return string
78
     */
79
    public function getUserTplMain($moduleDirname, $tableName = 'index')
80
    {
81
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
82
    }
83
84
    /**
85
     * @public function getUserAddMeta
86
     *
87
     * @param string $type
88
     * @param        $language
89
     * @param        $tableName
90
     *
91
     * @param string $t
92
     * @return string
93
     */
94
    public function getUserAddMeta($type, $language, $tableName, $t = '')
95
    {
96
        $stuTableName = mb_strtoupper($tableName);
97
        $stripTags    = $this->pc->getPhpCodeStripTags('', $language . $stuTableName, true);
98
99
        return "{$t}\$GLOBALS['xoTheme']->addMeta( 'meta', '{$type}', {$stripTags});\n";
100
    }
101
102
    /**
103
     * @public function getUserMetaKeywords
104
     *
105
     * @param $moduleDirname
106
     *
107
     * @return string
108
     */
109
    public function getUserMetaKeywords($moduleDirname)
110
    {
111
        $implode = $this->pc->getPhpCodeImplode(',', '$keywords');
112
113
        return "{$moduleDirname}MetaKeywords(\$helper->getConfig('keywords').', '. {$implode});\n";
114
    }
115
116
    /**
117
     * @public function getUserMetaDesc
118
     *
119
     * @param        $moduleDirname
120
     * @param        $language
121
     * @param string $file
122
     *
123
     * @return string
124
     */
125
    public function getUserMetaDesc($moduleDirname, $language, $file = 'INDEX')
126
    {
127
        return "{$moduleDirname}MetaDescription({$language}{$file}_DESC);\n";
128
    }
129
130
    /**
131
     * @public function getUserBreadcrumbs
132
     *
133
     * @param        $language
134
     * @param string $tableName
135
     * @param string $t
136
     *
137
     * @return string
138
     */
139
    public function getUserBreadcrumbs($language, $tableName = 'index', $t = '')
140
    {
141
        $stuTableName = mb_strtoupper($tableName);
142
        $title        = ["'title'" => "{$language}{$stuTableName}"];
143
144
        return $this->pc->getPhpCodeArray('xoBreadcrumbs[]', $title, false, $t);
145
    }
146
147
    /**
148
     * @public function getUserBreadcrumbs
149
     *
150
     * @param $moduleDirname
151
     *
152
     * @param $language
153
     * @return string
154
     */
155
    public function getUserBreadcrumbsHeaderFile($moduleDirname, $language)
156
    {
157
        $stuModuleDirname = mb_strtoupper($moduleDirname);
158
        $ret              = $this->pc->getPhpCodeCommentLine('Breadcrumbs');
159
        $ret              .= $this->pc->getPhpCodeArray('xoBreadcrumbs', null, false, '');
160
        $titleLink        = ["'title'" => $language . 'TITLE', "'link'" => "{$stuModuleDirname}_URL . '/'"];
161
        $ret              .= $this->pc->getPhpCodeArray('xoBreadcrumbs[]', $titleLink, false, '');
162
163
        return $ret;
164
    }
165
166
    /**
167
     * @public function getUserBreadcrumbs
168
     *
169
     * @return string
170
     */
171
    public function getUserBreadcrumbsFooterFile()
172
    {
173
        $cond = $this->xc->getXcXoopsTplAssign('xoBreadcrumbs', '$xoBreadcrumbs');
174
        $ret  = $this->pc->getPhpCodeConditions('count($xoBreadcrumbs)', ' > ', '1', $cond, false, "\t\t");
175
176
        return $ret;
177
    }
178
179
    /**
180
     * @public function getUserModVersionArray
181
     *
182
     * @param int    $eleArray
183
     * @param        $descriptions
184
     * @param null   $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
185
     * @param null   $index
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $index is correct as it would always require null to be passed?
Loading history...
186
     * @param bool   $num
187
     * @param string $t
188
     *
189
     * @return string
190
     */
191
    public function getUserModVersionArray($eleArray, $descriptions, $name = null, $index = null, $num = false, $t = '')
192
    {
193
        $ret = $t . '$modversion';
194
        $isArray = false;
195
        $n = '';
196
        if (!is_array($descriptions)) {
197
            $descs = [$descriptions];
198
        } else {
199
            $descs = $descriptions;
200
            $isArray = true;
201
            $n = "\n";
202
        }
203
        if (0 === $eleArray) {
204
            $ret .= " = ";
205
        } elseif (1 === $eleArray || 11 === $eleArray) {
206
            $ret .= "['{$name}'] = ";
207
        } elseif (2 === $eleArray) {
208
            $ret .= "['{$name}'][{$index}] = ";
209
        } elseif (3 === $eleArray) {
210
            $ret .= "['{$name}'][{$index}][{$num}] = ";
211
        }
212
        if ($isArray) {
213
            $ret .= "[";
214
        }
215
        $ret .= $n;
216
        //search for longest key
217
        $len = 0;
218
        foreach ($descs as $key => $desc) {
219
            $len = strlen($key) > $len ? strlen($key) : $len;
220
        }
221
222
        foreach ($descs as $key => $desc) {
223
            $space = str_repeat (  ' ' , $len - strlen($key));
224
            if ($eleArray < 4) {
225
                $ret .= $t . "\t'{$key}'{$space} => {$desc},{$n}";
226
            } elseif (11 === $eleArray) {
227
                if ('/' === substr($desc, 1, 1)) {
228
                    $ret .= $t . "\t{$desc}";
229
                } else {
230
                    $ret .= $t . "\t{$desc},{$n}";
231
                }
232
233
            } elseif (12 === $eleArray) {
234
                $ret .= $t . "\t{$desc}{$n}";
235
            }
236
        }
237
        $ret .= $t;
238
        if ($isArray) {
239
            $ret .= "]";
240
        }
241
        $ret .= ";\n";
242
        return $ret;
243
    }
244
245
    /**
246
     * @public function getUserModVersionText
247
     *
248
     * @param int $eleArray
249
     * @param $text
250
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
251
     * @param null $index
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $index is correct as it would always require null to be passed?
Loading history...
252
     * @param bool $num
253
     * @param string $t
254
     *
255
     * @return string
256
     */
257
    public function getUserModVersionText($eleArray, $text, $name = null, $index = null, $num = false, $t = '')
258
    {
259
        $ret = $t . '$modversion';
260
261
        if (0 === $eleArray) {
262
            $ret .= " = ";
263
        } elseif (1 === $eleArray) {
264
            $ret .= "['{$name}'] = ";
265
        } elseif (2 === $eleArray) {
266
            $ret .= "['{$name}'][{$index}] = ";
267
        } elseif (3 === $eleArray) {
268
            $ret .= "['{$name}'][{$index}][{$num}] = ";
269
        }
270
271
        $ret .= $t . "{$text};\n";
272
        return $ret;
273
    }
274
}
275