Completed
Push — master ( 004fa5...9844ae )
by Alexey
06:55
created

View::customAsset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
1
<?php
2
3
/**
4
 * View module
5
 *
6
 * Rendering pages, contents and widgets
7
 *
8
 * @author Alexey Krupskiy <[email protected]>
9
 * @link http://inji.ru/
10
 * @copyright 2015 Alexey Krupskiy
11
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
12
 */
13
class View extends \Module
14
{
15
    public $title = 'No title';
16
    public $template = null;
17
    public $libAssets = ['css' => [], 'js' => []];
18
    public $dynAssets = ['css' => [], 'js' => []];
19
    public $dynMetas = [];
20
    public $viewedContent = '';
21
    public $contentData = [];
22
    public $templatesPath = '';
23
    public $loadedCss = [];
24
    public $loadedJs = [];
25
26
    public function init()
27
    {
28
        if (!empty($this->app->config['site']['name'])) {
29
            $this->title = $this->app->config['site']['name'];
30
        }
31
        $this->resolveTemplate();
32
    }
33
34
    public function resolveTemplate()
35
    {
36
        $templateName = 'default';
37
        if (!empty($this->config[$this->app->type]['current'])) {
38
            $templateName = $this->config[$this->app->type]['current'];
39
            if (!empty($this->config[$this->app->type]['installed'][$templateName]['location'])) {
40
                $this->templatesPath = App::$primary->path . "/templates";
41
            }
42
        }
43
        if (!$this->templatesPath) {
44
            $this->templatesPath = $this->app->path . "/templates";
45
        }
46
        $this->template = \View\Template::get($templateName, $this->app, $this->templatesPath);
47
        if (!$this->template) {
48
            $this->template = new \View\Template([
49
                'name' => 'default',
50
                'path' => $this->templatesPath . '/default',
51
                'app' => $this->app
52
            ]);
53
        }
54
    }
55
56
    public function page($params = [])
57
    {
58
        $this->paramsParse($params);
59
        if (file_exists($this->template->pagePath)) {
60
            $source = file_get_contents($this->template->pagePath);
61
            if (strpos($source, 'BODYEND') === false) {
62
                $source = str_replace('</body>', '{BODYEND}</body>', $source);
63
            }
64
            $this->parseSource($source);
65
        } else {
66
            $this->content();
67
        }
68
    }
69
70
    public function paramsParse($params)
71
    {
72
        // set template
73
        if (!empty($params['template']) && $params['template'] != 'current') {
74
            $this->template = \View\Template::get($params['template']);
75
        }
76
        //set page
77
        if (!empty($params['page']) && $params['page'] != 'current') {
78
            $this->template->setPage($params['page']);
79
        }
80
        //set module
81
        if (!empty($params['module'])) {
82
            $this->template->setModule($params['module']);
83
        }
84
        //set content
85
        if (!empty($params['content'])) {
86
            $this->template->setContent($params['content']);
87
        } elseif (!$this->template->contentPath) {
88
            $this->template->setContent();
89
        }
90
        //set data
91
        if (!empty($params['data'])) {
92
            $this->contentData = array_merge($this->contentData, $params['data']);
93
        }
94
    }
95
96
    public function content($params = [])
97
    {
98
99
        $this->paramsParse($params);
100
101
        if (empty($this->template->config['noSysMsgAutoShow'])) {
102
            Msg::show(true);
0 ignored issues
show
Unused Code introduced by
The call to Msg::show() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
103
        }
104
        if (!file_exists($this->template->contentPath)) {
105
            echo 'Content not found';
106
        } else {
107
            extract($this->contentData);
108
            include $this->template->contentPath;
109
        }
110
    }
111
112
    public function parentContent($contentName = '')
113
    {
114
        if (!$contentName) {
115
            $contentName = $this->template->content;
116
        }
117
118
        $paths = $this->template->getContentPaths($contentName);
119
120
        $data = [];
121
        $exist = false;
122
        foreach ($paths as $type => $path) {
123
            if (substr($path, 0, strrpos($path, '/')) == substr($this->template->contentPath, 0, strrpos($this->template->contentPath, '/'))) {
124
                $exist = true;
125
                continue;
126
            }
127
            if (file_exists($path) && $exist) {
128
                $data['contentPath'] = $path;
129
                $data['content'] = $contentName;
130
                break;
131
            }
132
        }
133
        if (!$data) {
134
            echo 'Content not found';
135
        } else {
136
            extract($this->contentData);
137
            include $data['contentPath'];
138
        }
139
    }
140
141
    private function parseRaw($source)
142
    {
143
        if (!$source)
144
            return [];
145
146
        preg_match_all("|{([^}]+)}|", $source, $result);
147
        return $result[1];
148
    }
149
150
    public function parseSource($source)
151
    {
152
        $tags = $this->parseRaw($source);
153
        foreach ($tags as $rawTag) {
154
            $tag = explode(':', $rawTag);
155
            switch ($tag[0]) {
156
                case 'CONTENT':
157
                    $source = $this->cutTag($source, $rawTag);
158
                    $this->content();
159
                    break;
160
                case 'TITLE':
161
                    $source = $this->cutTag($source, $rawTag);
162
                    echo $this->title;
163
                    break;
164
                case 'WIDGET':
165
                    $source = $this->cutTag($source, $rawTag);
166
                    $params = array_slice($tag, 2);
167
                    $this->widget($tag[1], ['params' => $params], ':' . implode(':', $params));
168
                    break;
169
                case 'HEAD':
170
                    $source = $this->cutTag($source, $rawTag);
171
                    $this->head();
172
                    break;
173
                case 'PAGE':
174
                    $source = $this->cutTag($source, $rawTag);
175
                    $this->page(['page' => $tag[1]]);
176
                    break;
177
                case 'BODYEND':
178
                    $source = $this->cutTag($source, $rawTag);
179
                    $this->bodyEnd();
180
                    break;
181
            }
182
        }
183
        echo $source;
184
    }
185
186
    public function cutTag($source, $rawTag)
187
    {
188
        $pos = strpos($source, $rawTag) - 1;
189
        echo substr($source, 0, $pos);
190
        return substr($source, ( $pos + strlen($rawTag) + 2));
191
    }
192
193
    public function getHref($type, $params)
194
    {
195
        $href = '';
196
        if (is_string($params)) {
197
            $href = ($this->app->type != 'app' ? '/' . $this->app->name : '' ) . $params;
198
        } elseif (empty($params['template']) && !empty($params['file'])) {
199
            $href = ($this->app->type != 'app' ? '/' . $this->app->name : '' ) . $params['file'];
200
        } elseif (!empty($params['template']) && !empty($params['file'])) {
201
            $href = $this->app->templatesPath . "/{$this->template->name}/{$type}/{$params['file']}";
202
        }
203
        return $href;
204
    }
205
206
    public function checkNeedLibs()
207
    {
208
        if (!empty($this->template->config['libs'])) {
209
            foreach ($this->template->config['libs'] as $libName => $libOptions) {
210
                if (!is_array($libOptions)) {
211
                    $libName = $libOptions;
212
                    $libOptions = [];
213
                }
214
                $this->app->libs->loadLib($libName, $libOptions);
215
            }
216
        }
217 View Code Duplication
        foreach ($this->dynAssets['js'] as $asset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
218
            if (is_array($asset) && !empty($asset['libs'])) {
219
                foreach ($asset['libs'] as $libName) {
220
                    $this->app->libs->loadLib($libName);
221
                }
222
            }
223
        }
224 View Code Duplication
        foreach ($this->libAssets['js'] as $asset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
225
            if (is_array($asset) && !empty($asset['libs'])) {
226
                foreach ($asset['libs'] as $libName) {
227
                    $this->app->libs->loadLib($libName);
228
                }
229
            }
230
        }
231
    }
232
233
    public function head()
234
    {
235
236
        echo "<title>{$this->title}</title>\n";
237
238
        if (!empty($this->template->config['favicon']) && file_exists($this->template->path . "/{$this->template->config['favicon']}")) {
239
            echo "        <link rel='shortcut icon' href='/templates/{$this->template->name}/{$this->template->config['favicon']}' />";
240
        } elseif (!empty($this->template->config['favicon']) && file_exists($this->app->path . "/static/images/{$this->template->config['favicon']}")) {
241
            echo "        <link rel='shortcut icon' href='/static/images/{$this->template->config['favicon']}' />";
242
        } elseif (file_exists($this->app->path . '/static/images/favicon.ico')) {
243
            echo "        <link rel='shortcut icon' href='/static/images/favicon.ico' />";
244
        }
245
246
        foreach ($this->getMetaTags() as $meta) {
247
            echo "\n        " . Html::el('meta', $meta, '', null);
248
        }
249
250
        if (!empty(Inji::$config['assets']['js'])) {
251
            foreach (Inji::$config['assets']['js'] as $js) {
252
                $this->customAsset('js', $js);
253
            }
254
        }
255
256
        $this->checkNeedLibs();
257
        $this->parseCss();
258
        echo "\n        <script src='" . Statics::file(($this->app->type != 'app' ? '/' . $this->app->name : '' ) . "/static/system/js/Inji.js") . "'></script>";
259
    }
260
261
    public function parseCss()
262
    {
263
        $css = $this->getCss();
264
        $urls = [];
265
        $timeStr = '';
266
        $cssAll = '';
267
        $exclude = ['^http:', '^https:', '^//'];
268
        foreach ($css as $href) {
269
            if (!empty($this->loadedCss[$href])) {
270
                continue;
271
            }
272
            foreach ($exclude as $item) {
273
                if (preg_match("!{$item}!", $href)) {
274
                    echo "\n        <link href='{$href}' rel='stylesheet' type='text/css' />";
275
                    continue;
276
                }
277
            }
278
            $path = $this->app->staticLoader->parsePath($href);
279
            if (file_exists($path)) {
280
                $this->loadedCss[$href] = $href;
281
                $urls[$href] = $path;
282
                $timeStr.=filemtime($path);
283
            } else {
284
                echo "\n        <link href='{$href}' rel='stylesheet' type='text/css' />";
285
            }
286
        }
287
        $timeMd5 = md5($timeStr);
288
        $cacheDir = Cache::getDir();
289
        if (!file_exists($cacheDir . '/all' . $timeMd5 . '.css')) {
290
            foreach ($urls as $primaryUrl => $url) {
291
                $source = file_get_contents($url);
292
                $matches = [];
0 ignored issues
show
Unused Code introduced by
$matches 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...
293
                $rootPath = substr($primaryUrl, 0, strrpos($primaryUrl, '/'));
294
                $levelUpPath = substr($rootPath, 0, strrpos($rootPath, '/'));
295
                $source = preg_replace('!url\((\'?"?)[\.]{2}!isU', 'url($1' . $levelUpPath, $source);
296
                $source = preg_replace('!url\((\'?"?)[\.]{1}!isU', 'url($1' . $rootPath, $source);
297
                $source = preg_replace('#url\(([\'"]){1}(?!http|https|/|data\:)([^/])#isU', 'url($1' . $rootPath . '/$2', $source);
298
                $source = preg_replace('#url\((?!http|https|/|data\:|\'|")([^/])#isU', 'url(' . $rootPath . '/$1$2', $source);
299
                $cssAll .= $source;
300
            }
301
            file_put_contents($cacheDir . '/all' . $timeMd5 . '.css', $cssAll);
302
        }
303
        echo "\n        <link href='/{$cacheDir}/all{$timeMd5}.css' rel='stylesheet' type='text/css' />";
304
    }
305
306 View Code Duplication
    public function getCss()
307
    {
308
        $css = [];
309
        if (!empty($this->libAssets['css'])) {
310
            $this->ResolveCssHref($this->libAssets['css'], 'libs', $css);
311
        }
312
        if (!empty($this->template->config['css'])) {
313
            $this->ResolveCssHref($this->template->config['css'], 'template', $css);
314
        }
315
        if (!empty($this->dynAssets['css'])) {
316
            $this->ResolveCssHref($this->dynAssets['css'], 'custom', $css);
317
        }
318
        return $css;
319
    }
320
321
    public function ResolveCssHref($cssArray, $type = 'custom', &$hrefs)
322
    {
323
        switch ($type) {
324 View Code Duplication
            case'libs':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
325
                foreach ($cssArray as $css) {
326
                    if (is_array($css)) {
327
                        $this->ResolveCssHref($css, $type, $hrefs);
328
                        continue;
329
                    }
330
                    if (strpos($css, '//') !== false)
331
                        $href = $css;
332
                    else
333
                        $href = ($this->app->type != 'app' ? '/' . $this->app->name : '' ) . $css;
334
                    $hrefs[$href] = $href;
335
                }
336
                break;
337 View Code Duplication
            case'template':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
338
                foreach ($cssArray as $css) {
339
                    if (is_array($css)) {
340
                        $this->ResolveCssHref($css, $type, $hrefs);
341
                        continue;
342
                    }
343
                    if (strpos($css, '://') !== false)
344
                        $href = $css;
345
                    else
346
                        $href = $this->app->templatesPath . "/{$this->template->name}/css/{$css}";
347
                    $hrefs[$href] = $href;
348
                }
349
                break;
350 View Code Duplication
            case 'custom':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
351
                foreach ($cssArray as $css) {
352
                    if (is_array($css)) {
353
                        $this->ResolveCssHref($css, $type, $hrefs);
354
                        continue;
355
                    }
356
                    if (strpos($css, '//') !== false)
357
                        $href = $css;
358
                    else
359
                        $href = ($this->app->type != 'app' ? '/' . $this->app->name : '' ) . $css;
360
                    $hrefs[$href] = $href;
361
                }
362
                break;
363
        }
364
    }
365
366
    public function getMetaTags()
367
    {
368
        $metas = [];
369
370 View Code Duplication
        if (!empty($this->app->config['site']['keywords'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
371
            $metas['metaName:keywords'] = ['name' => 'keywords', 'content' => $this->app->config['site']['keywords']];
372
        }
373 View Code Duplication
        if (!empty($this->app->config['site']['description'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
374
            $metas['metaName:description'] = ['name' => 'description', 'content' => $this->app->config['site']['description']];
375
        }
376
        if (!empty($this->app->config['site']['metatags'])) {
377
            foreach ($this->app->config['site']['metatags'] as $meta) {
378
                if (!empty($meta['name'])) {
379
                    $metas['metaName:' . $meta['name']] = $meta;
380
                } elseif (!empty($meta['property'])) {
381
                    $metas['metaProperty:' . $meta['property']] = $meta;
382
                }
383
            }
384
        }
385
        if ($this->dynMetas) {
386
            $metas = array_merge($metas, $this->dynMetas);
387
        }
388
        return $metas;
389
    }
390
391
    public function addMetaTag($meta)
392
    {
393
        if (!empty($meta['name'])) {
394
            $this->dynMetas['metaName:' . $meta['name']] = $meta;
395
        } elseif (!empty($meta['property'])) {
396
            $this->dynMetas['metaProperty:' . $meta['property']] = $meta;
397
        }
398
    }
399
400
    public function bodyEnd()
401
    {
402
        $this->checkNeedLibs();
403
        $this->parseCss();
404
        $scripts = $this->getScripts();
405
        $onLoadModules = [];
406
        $scriptAll = '';
407
        $urls = [];
408
        $nativeUrl = [];
409
        $timeStr = '';
410
        $noParsedScripts = [];
411
        foreach ($scripts as $script) {
412
            if (is_string($script)) {
413
                if (!empty($urls[$script]))
414
                    continue;
415
416
                $path = $this->app->staticLoader->parsePath($script);
417
                if (file_exists($path)) {
418
                    $nativeUrl[$script] = $script;
419
                    $urls[$script] = $path;
420
                    $timeStr.=filemtime($path);
421
                } else {
422
                    $noParsedScripts[$script] = $script;
423
                }
424
            } elseif (!empty($script['file'])) {
425
                if (!empty($urls[$script['file']]))
426
                    continue;
427
428
                $path = $this->app->staticLoader->parsePath($script['file']);
429
                if (file_exists($path)) {
430
                    $nativeUrl[$script['file']] = $script['file'];
431
                    $urls[$script['file']] = $path;
432
                    if (!empty($script['name'])) {
433
                        $onLoadModules[$script['name']] = $script['name'];
434
                    }
435
                    $timeStr.=filemtime($path);
436
                } else {
437
                    $noParsedScripts[$script] = $script;
438
                }
439
            }
440
        }
441
442
        $timeMd5 = md5($timeStr);
443
        $cacheDir = Cache::getDir();
444
        if (!file_exists($cacheDir . '/all' . $timeMd5 . '.js')) {
445
            foreach ($urls as $url) {
446
                $scriptAll .= ';' . file_get_contents($url);
447
            }
448
            file_put_contents($cacheDir . '/all' . $timeMd5 . '.js', $scriptAll);
449
        }
450
        $options = [
451
            'scripts' => array_values($noParsedScripts),
452
            'compresedScripts' => $nativeUrl,
453
            'styles' => [],
454
            'appRoot' => $this->app->type == 'app' ? '/' : '/' . $this->app->name . '/',
455
            'onLoadModules' => $onLoadModules
456
        ];
457
        $options['scripts'][] = '/' . $cacheDir . '/all' . $timeMd5 . '.js';
458
        $this->widget('View\bodyEnd', compact('options'));
459
    }
460
461 View Code Duplication
    public function getScripts()
462
    {
463
        $scripts = [];
464
        if (!empty($this->libAssets['js'])) {
465
            $this->genScriptArray($this->libAssets['js'], 'libs', $scripts);
466
        }
467
        if (!empty($this->dynAssets['js'])) {
468
            $this->genScriptArray($this->dynAssets['js'], 'custom', $scripts);
469
        }
470
        if (!empty($this->template->config['js'])) {
471
            $this->genScriptArray($this->template->config['js'], 'template', $scripts);
472
        }
473
        return $scripts;
474
    }
475
476
    public function genScriptArray($jsArray, $type = 'custom', &$resultArray)
477
    {
478
        switch ($type) {
479
            case 'libs':
480
                foreach ($jsArray as $js) {
481
                    if (is_array($js)) {
482
                        $this->genScriptArray($js, $type, $resultArray);
483
                        continue;
484
                    }
485
                    if (strpos($js, '//') !== false)
486
                        $href = $js;
487
                    else
488
                        $href = $this->getHref('js', $js);
489
                    if (!$href)
490
                        continue;
491
492
                    $resultArray[] = $href;
493
                }
494
                break;
495 View Code Duplication
            case'template':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
496
                foreach ($jsArray as $js) {
497
                    if (is_array($js)) {
498
                        $this->genScriptArray($js, $type, $resultArray);
499
                        continue;
500
                    }
501
                    if (strpos($js, '//') !== false)
502
                        $href = $js;
503
                    else
504
                        $href = $this->app->templatesPath . "/{$this->template->name}/js/{$js}";
505
                    $resultArray[] = $href;
506
                }
507
                break;
508
            case 'custom':
509
                foreach ($jsArray as $js) {
510
                    if (is_array($js)) {
511
                        if (!empty($js[0]) && is_array($js[0])) {
512
                            $this->genScriptArray($js, $type, $resultArray);
513
                            continue;
514
                        }
515
                        $asset = $js;
516
                    } else {
517
                        $asset = [];
518
                    }
519
                    $asset['file'] = $this->getHref('js', $js);
520
                    if (!$asset['file'])
521
                        continue;
522
                    $resultArray[] = $asset;
523
                }
524
                break;
525
        }
526
    }
527
528
    public function customAsset($type, $asset, $lib = false)
529
    {
530
        if (!$lib) {
531
            $this->dynAssets[$type][] = $asset;
532
        } else {
533
            $this->libAssets[$type][$lib][] = $asset;
534
        }
535
    }
536
537
    public function setTitle($title, $add = true)
538
    {
539
        if ($add && !empty($this->app->config['site']['name'])) {
540
            $this->title = $title . ' - ' . $this->app->config['site']['name'];
541
        } else {
542
            $this->title = $title;
543
        }
544
    }
545
546
    public function widget($_widgetName, $_params = [], $lineParams = null)
547
    {
548
        $_paths = $this->getWidgetPaths($_widgetName);
549
        $find = false;
550
        foreach ($_paths as $_path) {
551
            if (file_exists($_path)) {
552
                $find = true;
553
                break;
554
            }
555
        }
556
        if ($lineParams === null) {
557
            $lineParams = '';
558
            if ($_params) {
559
                $paramArray = false;
560
                foreach ($_params as $param) {
561
                    if (is_array($param) || is_object($param)) {
562
                        $paramArray = true;
563
                    }
564
                }
565
                if (!$paramArray)
566
                    $lineParams = ':' . implode(':', $_params);
567
            }
568
        }
569
        echo "<!--start:{WIDGET:{$_widgetName}{$lineParams}}-->\n";
570
        if ($find) {
571
            if ($_params && is_array($_params)) {
572
                extract($_params);
573
            }
574
            include $_path;
575
        }
576
        echo "<!--end:{WIDGET:{$_widgetName}{$lineParams}}-->\n";
577
    }
578
579
    public function getWidgetPaths($widgetName)
580
    {
581
        $paths = [];
582
        if (strpos($widgetName, '\\')) {
583
            $widgetName = explode('\\', $widgetName);
584
585
            $paths['templatePath_widgetDir'] = $this->templatesPath . '/' . $this->template->name . '/widgets/' . $widgetName[0] . '/' . $widgetName[1] . '/' . $widgetName[1] . '.php';
586
            $paths['templatePath'] = $this->templatesPath . '/' . $this->template->name . '/widgets/' . $widgetName[0] . '/' . $widgetName[1] . '.php';
587
            App::$cur->$widgetName[0];
588
            $modulePaths = Module::getModulePaths(ucfirst($widgetName[0]));
589
            foreach ($modulePaths as $pathName => $path) {
590
                $paths[$pathName . '_widgetDir'] = $path . '/widgets/' . $widgetName[1] . '/' . $widgetName[1] . '.php';
591
                $paths[$pathName] = $path . '/widgets/' . $widgetName[1] . '.php';
592
            }
593
            return $paths;
594
        } else {
595
            $paths['templatePath_widgetDir'] = $this->templatesPath . '/' . $this->template->name . '/widgets/' . $widgetName . '/' . $widgetName . '.php';
596
            $paths['templatePath'] = $this->templatesPath . '/' . $this->template->name . '/widgets/' . $widgetName . '.php';
597
598
            $paths['curAppPath_widgetDir'] = $this->app->path . '/widgets/' . $widgetName . '/' . $widgetName . '.php';
599
            $paths['curAppPath'] = $this->app->path . '/widgets/' . $widgetName . '.php';
600
601
            $paths['systemPath_widgetDir'] = INJI_SYSTEM_DIR . '/widgets/' . $widgetName . '/' . $widgetName . '.php';
602
            $paths['systemPath'] = INJI_SYSTEM_DIR . '/widgets/' . $widgetName . '.php';
603
        }
604
        return $paths;
605
    }
606
607
}
608