UrlProcessor::makeUrl()   F
last analyzed

Complexity

Conditions 23
Paths 3528

Size

Total Lines 87

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 23
nc 3528
nop 4
dl 0
loc 87
rs 0
c 0
b 0
f 0

How to fix   Long Method    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 namespace EvolutionCMS;
2
3
class UrlProcessor
4
{
5
    /**
6
     * @var Interfaces\CoreInterface
7
     */
8
    protected $core;
9
10
    public $aliasListing = [];
11
    public $documentListing = [];
12
    public $virtualDir = '';
13
14
    protected $aliases = [];
15
    protected $isfolder = [];
16
17
    protected $tagPattern = '!\[\~(\d+)\~\]!i';
18
19
    public function __construct(Interfaces\CoreInterface $core)
20
    {
21
        $this->core = $core;
22
        $this->documentListing = &$this->core->documentListing;
0 ignored issues
show
Bug introduced by
Accessing documentListing on the interface EvolutionCMS\Interfaces\CoreInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
23
        $this->aliasListing = &$this->core->aliasListing;
0 ignored issues
show
Bug introduced by
Accessing aliasListing on the interface EvolutionCMS\Interfaces\CoreInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
24
        $this->virtualDir = &$this->core->virtualDir;
0 ignored issues
show
Bug introduced by
Accessing virtualDir on the interface EvolutionCMS\Interfaces\CoreInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
25
26
        $this->build();
27
    }
28
29
    protected function build() : void
30
    {
31
        $this->aliases = [];
32
        $this->isfolder = [];
33
34
        if (\is_array($this->documentListing)) {
35
            foreach ($this->documentListing as $path => $docid) { // This is big Loop on large site!
36
                $this->aliases[$docid] = $path;
37
                $this->isfolder[$docid] = !empty($this->aliasListing[$docid]['isfolder']);
38
            }
39
        }
40
    }
41
42
    public function getAliases()
43
    {
44
        return $this->aliases;
45
    }
46
47
    public function getIsFolders()
48
    {
49
        return $this->isfolder;
50
    }
51
52
    /**
53
     * @desc Create an URL.
54
     *
55
     * @param string $pre Friendly URL Prefix. @required
56
     * @param string $suff Friendly URL Suffix. @required
57
     * @param string $alias Full document path. @required
58
     * @param bool $isfolder Is it a folder? Default: 0.
59
     * @param int $id Document id. Default: 0.
60
     * @return string Result URL.
61
     */
62
    public function makeFriendlyURL($pre, $suff, $alias, bool $isfolder = false, int $id = 0) : string
63
    {
64
        if ($id === $this->core->getConfig('site_start') && $this->core->getConfig('seostrict')) {
65
            $url = $this->core->getConfig('base_url');
66
        } else {
67
            $tmp = explode('/', $alias);
68
            $alias = array_pop($tmp);
69
            $dir = implode('/', $tmp);
70
            unset($tmp);
71
72
            if ($this->core->getConfig('make_folders') && $isfolder) {
73
                $suff = '/';
74
            }
75
76
            $url = ($dir !== '' ? $dir . '/' : '') . $pre . $alias . $suff;
77
        }
78
79
        $evtOut = $this->core->invokeEvent('OnMakeDocUrl', array(
80
            'id'  => $id,
81
            'url' => $url
82
        ));
83
84
        if (\is_array($evtOut) && \count($evtOut) > 0) {
85
            $url = array_pop($evtOut);
86
        }
87
88
        return $url;
89
    }
90
91
    /**
92
     * Convert URL tags [~...~] to URLs
93
     *
94
     * @param string $input
95
     * @return string
96
     */
97
    public function rewriteUrls($input)
98
    {
99
        // rewrite the urls
100
        if ($this->core->getConfig('friendly_urls')) {
101
            $aliases = $this->getAliases();
102
            $isFolder = $this->getIsFolders();
103
104
            if ($this->core->getConfig('aliaslistingfolder')) {
105
                preg_match_all($this->tagPattern, $input, $match);
106
                $this->generateAliasListingFolder($match['1'], $aliases, $isFolder);
107
            }
108
109
            $output = $this->replaceUrl($input, $aliases, $isFolder);
110
111
        } else {
112
            $output = $this->rewriteToNativeUrl($input);
113
        }
114
115
        return $output;
116
    }
117
118
    protected function replaceUrl(string $input, array $aliases, array $isFolder) : string
119
    {
120
        $isFriendly = $this->core->getConfig('friendly_alias_urls');
121
        $pref = $this->core->getConfig('friendly_url_prefix');
122
        $suffix = $this->core->getConfig('friendly_url_suffix');
123
        $seoStrict = $this->core->getConfig('seostrict');
124
125
        return preg_replace_callback(
126
            $this->tagPattern,
127
            function ($match) use ($aliases, $isFolder, $isFriendly, $seoStrict, $pref, $suffix) {
128
                if ($isFriendly && isset($aliases[$match[1]])) {
129
                    $out = $this->makeFriendlyURL(
130
                        $pref,
131
                        $suffix,
132
                        $aliases[$match[1]],
133
                        $isFolder[$match[1]],
134
                        $match[1]
135
                    );
136
137
                    //found friendly url
138
                    if ($seoStrict) {
139
                        $out = $this->toAlias($out);
140
                    }
141
                } else {
142
                    //not found friendly url
143
                    $out = $this->makeFriendlyURL($pref, $suffix, $match[1]);
144
                }
145
146
                return $out;
147
            },
148
            $input
149
        );
150
    }
151
    protected function generateAliasListingFolder(array $ids, &$aliases, &$isFolder) : void
152
    {
153
        $ids = array_unique($ids);
154
        if (empty($ids)) {
155
            return;
156
        }
157
158
        $useAliasPath = (bool)$this->core->getConfig('use_alias_path');
159
160
        $data = Models\SiteContent::whereIn('id', $ids)
161
            ->where('isfolder', '=', 0)
162
            ->get();
163
164
        foreach ($data as $row) {
165
            if ($useAliasPath && $row->parent > 0) {
166
                $parent = $row->parent;
167
                $path = $aliases[$parent];
168
169
                while (isset($this->aliasListing[$parent]) && (int)$this->aliasListing[$parent]['alias_visible'] === 0) {
170
                    $path = $this->aliasListing[$parent]['path'];
171
                    $parent = $this->aliasListing[$parent]['parent'];
172
                }
173
174
                $aliases[$row->getKey()] = $path . '/' . $row->alias;
175
            } else {
176
                $aliases[$row->getKey()] = $row->alias;
177
            }
178
            $isFolder[$row->getKey()] = '0';
179
        }
180
    }
181
182
    public function rewriteToNativeUrl(string $content) : string
183
    {
184
        return preg_replace($this->tagPattern, 'index.php?id=\1', $content);
185
    }
186
187
    /**
188
     * @param string $text
189
     * @return string mixed
190
     */
191
    public function toAlias(string $text) : string
192
    {
193
        $suffix = $this->core->getConfig('friendly_url_suffix');
194
        return str_replace(
195
            [
196
                '.xml' . $suffix,
197
                '.rss' . $suffix,
198
                '.js' . $suffix,
199
                '.css' . $suffix,
200
                '.txt' . $suffix,
201
                '.json' . $suffix,
202
                '.pdf' . $suffix
203
            ],
204
            [
205
                '.xml',
206
                '.rss',
207
                '.js',
208
                '.css',
209
                '.txt',
210
                '.json',
211
                '.pdf'
212
            ],
213
            $text
214
        );
215
    }
216
217
    public function getNotFoundPageId() : int
218
    {
219
        return $this->core->getConfig(
220
            $this->core->getConfig('error_page') ? 'error_page' : 'site_start',
221
            1
222
        );
223
    }
224
225
    public function getUnAuthorizedPageId() : int
226
    {
227
        if ($this->core->getConfig('unauthorized_page')) {
228
            $unauthorizedPage = $this->core->getConfig('unauthorized_page');
229
        } elseif ($this->core->getConfig('error_page')) {
230
            $unauthorizedPage = $this->core->getConfig('error_page');
231
        } else {
232
            $unauthorizedPage = $this->core->getConfig('site_start');
233
        }
234
235
        return $unauthorizedPage;
236
    }
237
238
    /**
239
     * Create a 'clean' document identifier with path information, friendly URL suffix and prefix.
240
     *
241
     * @param string $qOrig
242
     * @param string $documentMethod
243
     * @return string
244
     */
245
    public function cleanDocumentIdentifier($qOrig, &$documentMethod) : string
246
    {
247
        if (!$qOrig) {
248
            $qOrig = $this->core->getConfig('site_start');
249
        }
250
        $query = $qOrig;
251
252
        $pre = $this->core->getConfig('friendly_url_prefix');
253
        $suf = $this->core->getConfig('friendly_url_suffix');
254
        $pre = preg_quote($pre, '/');
255
        $suf = preg_quote($suf, '/');
256
        if ($pre && preg_match('@^' . $pre . '(.*)$@', $query, $matches)) {
257
            $query = $matches[1];
258
        }
259
        if ($suf && preg_match('@(.*)' . $suf . '$@', $query, $matches)) {
260
            $query = $matches[1];
261
        }
262
263
        /* First remove any / before or after */
264
        $query = trim($query, '/');
265
266
        /**
267
         * Save path if any
268
         * FS#476 and FS#308: only return virtualDir if friendly paths are enabled
269
         */
270
        if ($this->core->getConfig('use_alias_path')) {
271
            $matches = strrpos($query, '/');
272
            $this->virtualDir = $matches !== false ? substr($query, 0, $matches) : '';
273
            if ($matches !== false) {
274
                $query = preg_replace('@.*/@', '', $query);
275
            }
276
        } else {
277
            $this->virtualDir = '';
278
        }
279
280
        $documentMethod = 'alias';
281
        if (preg_match('@^[1-9]\d*$@', $query) && !isset($this->documentListing[$query])) {
282
            /**
283
             * we got an ID returned, check to make sure it's not an alias
284
             * FS#476 and FS#308: check that id is valid in terms of virtualDir structure
285
             */
286
            if ($this->core->getConfig('use_alias_path')) {
287
                if (//(
288
                        (
289
                            $this->virtualDir !== '' &&
290
                            !isset($this->documentListing[$this->virtualDir . '/' . $query])
291
                        ) || (
292
                            $this->virtualDir === '' && !isset($this->documentListing[$query])
293
                        )
294
                    //)
295
                    && (
296
                        (
297
                            $this->virtualDir !== '' &&
298
                            isset($this->documentListing[$this->virtualDir]) &&
299
                            \in_array($query, $this->core->getChildIds($this->documentListing[$this->virtualDir], 1))
300
                        ) ||
301
                        ($this->virtualDir === '' && in_array($query, $this->core->getChildIds(0, 1)))
302
                    )
303
                ) {
304
                    $documentMethod = 'id';
305
                }
306
            } else {
307
                $documentMethod = 'id';
308
            }
309
        } else {
310
            /** we didn't get an ID back, so instead we assume it's an alias */
311
            if (! (bool)$this->core->getConfig('friendly_alias_urls')) {
312
                $query = $qOrig;
313
            }
314
        }
315
316
        return $query;
317
    }
318
319
320
321
    /**
322
     * Get Clean Query String
323
     *
324
     * Fixes the issue where passing an array into the q get variable causes errors
325
     *
326
     * @param string|array $query
327
     * @return string
328
     */
329
    public function cleanQueryString($query) : string
330
    {
331
        $out = '';
332
333
        switch (true) {
334
            /** If we have a string, return it */
335
            case \is_string($query) && !empty($query):
336
                $out = $query;
337
                break;
338
            /** If we have an array, return the first element */
339
            case (\is_array($query) && isset($query[0]) && \is_scalar($query[0])):
340
                $out = $query[0];
341
                break;
342
        }
343
344
        /** Return null if the query doesn't exist */
345
        if (empty($query)) {
346
            $out = '';
347
        }
348
349
        return $out;
350
    }
351
352
    /**
353
     * @param $id
354
     * @return null|array
355
     */
356
    public function getAliasListing($id) : ?array
357
    {
358
        $out = null;
359
        if (isset($this->aliasListing[$id])) {
360
            $out = $this->aliasListing[$id];
361
        } else {
362
            /** @var Models\SiteContent|null $query */
363
            $query = Models\SiteContent::where('id', '=', (int)$id)->first();
364
            if ($query !== null) {
365
                $this->aliasListing[$id] = array(
366
                    'id'       => $query->getKey(),
367
                    'alias'    => $query->alias === '' ? $query->getKey() : $query->alias,
368
                    'parent'   => $query->parent,
369
                    'isfolder' => $query->isfolder,
370
                    'alias_visible' => $query->alias_visible,
371
                );
372
                if ($query->parent > 0) {
373
                    if ((bool)$this->core->getConfig('use_alias_path')) {
374
                        $tmp = $this->getAliasListing($query->parent);
375
                        if ($tmp['alias_visible']) {
376
                            $this->aliasListing[$id]['path'] = $tmp['path'] . (($tmp['parent'] > 0 && $tmp['path'] !== '') ? '/' : '') . $tmp['alias'];
377
                        } else {
378
                            $this->aliasListing[$id]['path'] = $tmp['path'];
379
                        }
380
                    } else {
381
                        $this->aliasListing[$id]['path'] = '';
382
                    }
383
                }
384
385
                $out = $this->aliasListing[$id];
386
            }
387
        }
388
389
        return $out;
390
    }
391
392
    /**
393
     * @param $alias
394
     * @return null|int
395
     */
396
    public function getIdFromAlias($alias)
397
    {
398
        if (isset($this->documentListing[$alias])) {
399
            return $this->documentListing[$alias];
400
        }
401
402
        if ($this->core->getConfig('use_alias_path')) {
403
            if ($alias === '.') {
404
                return 0;
405
            }
406
407
            if (strpos($alias, '/') !== false) {
408
                $aliases = explode('/', $alias);
409
            } else {
410
                $aliases = [$alias];
411
            }
412
            $id = 0;
413
414
            foreach ($aliases as $tmp) {
415
                if ($id === null) {
416
                    break;
417
                }
418
                /** @var Models\SiteContent $query */
419
                $query = Models\SiteContent::where('deleted', '=', 0)
420
                    ->where('parent', '=', $id)
421
                    ->where('alias', '=', $tmp)
422
                    ->first();
423
424
                if ($query === null) {
425
                    /** @var Models\SiteContent $query */
426
                    $query = Models\SiteContent::where('deleted', '=', 0)
427
                        ->where('parent', '=', $id)
428
                        ->where('id', '=', $tmp)
429
                        ->first();
430
                }
431
432
                $id = ($query === null) ? $this->getHiddenIdFromAlias($id, $tmp) : $query->getKey();
433
            }
434
        } else {
435
            /** @var Models\SiteContent $query */
436
            $query = Models\SiteContent::where('deleted', '=', 0)
437
                ->where('alias', '=', $alias)
438
                ->first();
439
440
            $id = ($query !== null) ? $query->getKey() : null;
441
        }
442
        return $id;
443
    }
444
445
    /**
446
     * @param int $parentid
447
     * @param string $alias
448
     * @return null|int
449
     */
450
    public function getHiddenIdFromAlias(int $parentid, string $alias) : ?int
451
    {
452
        $out = false;
453
        if ($alias !== '') {
454
            $table = $this->getFullTableName('site_content');
0 ignored issues
show
Bug introduced by
The method getFullTableName() does not seem to exist on object<EvolutionCMS\UrlProcessor>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
455
            $query = $this->db->query("SELECT 
0 ignored issues
show
Bug introduced by
The property db does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
456
                `sc`.`id` AS `hidden_id`,
457
                `children`.`id` AS `child_id`,
458
                children.alias AS `child_alias`,
459
                COUNT(`grandsons`.`id`) AS `grandsons_count`
460
              FROM " . $table ." AS `sc`
461
              JOIN " . $table . " AS `children` ON `children`.`parent` = `sc`.`id`
462
              LEFT JOIN " . $table . " AS `grandsons` ON `grandsons`.`parent` = `children`.`id`
463
              WHERE `sc`.`parent` = '" . (int)$parentid . "' AND `sc`.`alias_visible` = '0'
464
              GROUP BY `children`.`id`");
465
            while ($child = $this->db->getRow($query)) {
466
                if ($child['child_alias'] == $alias || $child['child_id'] == $alias) {
467
                    $out = $child['child_id'];
468
                    break;
469
                } else if ($child['grandsons_count'] > 0 && ($id = $this->getHiddenIdFromAlias($child['child_id'], $alias))) {
470
                    $out = $id;
471
                    break;
472
                }
473
            }
474
        }
475
        return $out;
476
    }
477
478
    /**
479
     * Create an URL for the given document identifier. The url prefix and postfix are used, when “friendly_url” is active.
480
     *
481
     * @param int $id The document identifier. @required
482
     * @param string $alias The alias name for the document. Default: ''.
483
     * @param string $args The paramaters to add to the URL. Default: ''.
484
     * @param string $scheme With full as valus, the site url configuration is used. Default: ''.
485
     * @return string Result URL.
486
     */
487
    public function makeUrl(int $id, string $alias = '', string $args = '', string $scheme = '') : string
488
    {
489
        $virtualDir = $this->core->getConfig('virtual_dir');
490
        $f_url_prefix = $this->core->getConfig('friendly_url_prefix');
491
        $f_url_suffix = $this->core->getConfig('friendly_url_suffix');
492
493
        if ($args !== '') {
494
            // add ? or & to $args if missing
495
            $args = ltrim($args, '?&');
496
            $_ = strpos($f_url_prefix, '?');
497
498
            if ($_ === false && $this->core->getConfig('friendly_urls')) {
499
                $args = "?{$args}";
500
            } else {
501
                $args = "&{$args}";
502
            }
503
        }
504
505
        if ($id !== $this->core->getConfig('site_start')) {
506
            if ($this->core->getConfig('friendly_urls') && $alias == '') {
507
                $alias = (string)$id;
508
                $alPath = '';
509
510
                if ($this->core->getConfig('friendly_alias_urls')) {
511
512
                    if ($this->core->getConfig('aliaslistingfolder')) {
513
                        $al = $this->getAliasListing($id);
514
                    } else {
515
                        $al = $this->aliasListing[$id] ?? null;
516
                    }
517
518
                    if(\is_array($al)) {
519
                        if ($al['isfolder'] === 1 && $this->core->getConfig('make_folders')) {
520
                            $f_url_suffix = '/';
521
                        }
522
                        $alPath = !empty($al['path']) ? $al['path'] . '/' : '';
523
524
                        if (isset($al['alias'])) {
525
                            $alias = $al['alias'];
526
                        }
527
                    }
528
                }
529
530
                $alias = $alPath . $f_url_prefix . $alias . $f_url_suffix;
531
                $url = "{$alias}{$args}";
532
            } else {
533
                $url = "index.php?id={$id}{$args}";
534
            }
535
        } else {
536
            $url = $args;
537
        }
538
539
        $host = $this->core->getConfig('base_url');
540
541
        // check if scheme argument has been set
542
        if ($scheme != '') {
543
            // for backward compatibility - check if the desired scheme is different than the current scheme
544
            if (is_numeric($scheme) && $scheme != $_SERVER['HTTPS']) {
545
                $scheme = ($_SERVER['HTTPS'] ? 'http' : 'https');
546
            }
547
548
            //TODO: check to make sure that $site_url incudes the url :port (e.g. :8080)
549
            $host = $scheme == 'full' ? $this->core->getConfig('site_url') : $scheme . '://' . $_SERVER['HTTP_HOST'] . $host;
550
        }
551
552
        //fix strictUrl by Bumkaka
553
        if ($this->core->getConfig('seostrict')) {
554
            $url = $this->toAlias($url);
555
        }
556
557
        if ($this->core->getConfig('xhtml_urls')) {
558
            $url = preg_replace("/&(?!amp;)/", "&amp;", $host . $virtualDir . $url);
559
        } else {
560
            $url = $host . $virtualDir . $url;
561
        }
562
563
        $evtOut = $this->core->invokeEvent('OnMakeDocUrl', array(
564
            'id'  => $id,
565
            'url' => $url
566
        ));
567
568
        if (is_array($evtOut) && count($evtOut) > 0) {
569
            $url = array_pop($evtOut);
570
        }
571
572
        return $url;
573
    }
574
575
    public function strictURI(string $query, int $id) :? string
576
    {
577
        $out = null;
578
        // FIX URLs
579
        if (empty($id) ||
580
            $this->core->getConfig('seostrict') === false ||
581
            $this->core->getConfig('friendly_urls') === false ||
582
            $this->core->getConfig('site_status') === false
583
        ) {
584
            return $out;
585
        }
586
587
        $scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
588
        $len_base_url = strlen($this->core->getConfig('base_url'));
589
590
        $url_path = $query;//LANG
591
592
        if (substr($url_path, 0, $len_base_url) === $this->core->getConfig('base_url')) {
593
            $url_path = substr($url_path, $len_base_url);
594
        }
595
596
        $strictURL = $this->makeUrl($id);
597
        $strictURL = $this->toAlias($strictURL);
598
599
        if (substr($strictURL, 0, $len_base_url) === $this->core->getConfig('base_url')) {
600
            $strictURL = substr($strictURL, $len_base_url);
601
        }
602
        $http_host = $_SERVER['HTTP_HOST'];
603
        $requestedURL = "{$scheme}://{$http_host}" . '/' . $query; //LANG
604
605
        $url_query_string = explode('?', $_SERVER['REQUEST_URI']);
606
        // Strip conflicting id/q from query string
607
        $qstring = !empty($url_query_string[1]) ? preg_replace("#(^|&)(q|id)=[^&]+#", '', $url_query_string[1]) : '';
608
609
        if ($id === (int)$this->core->getConfig('site_start')) {
610
            if ($requestedURL !== $this->core->getConfig('site_url')) {
611
                $url = $this->core->getConfig('site_url');
612
                if ($qstring) {
613
                     $url .= '?' . $qstring;
614
                }
615
616
                if ($this->core->getConfig('base_url') != $_SERVER['REQUEST_URI']) {
617
                    if (empty($_POST)) {
618
                        if (($this->core->getConfig('base_url') . '?' . $qstring) != $_SERVER['REQUEST_URI']) {
619
                            $out = $url;
620
                        }
621
                    }
622
                }
623
            }
624
        } elseif (preg_match('#/\?q\=' . $strictURL . '#i', $_SERVER['REQUEST_URI']) ||
625
            ($url_path != $strictURL && $id !== (int)$this->core->getConfig('error_page'))
626
        ) {
627
            if (!empty($qstring)) {
628
                $url = $this->core->getConfig('site_url') . $strictURL . '?' . $qstring;
629
            } else {
630
                $url = $this->core->getConfig('site_url') . $strictURL;
631
            }
632
            $out = $url;
633
        }
634
635
        return $out;
636
    }
637
}
638