GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 2.8 ( 651d2c...3866ce )
by Thorsten
18:13
created

PMF_Link::isInternalReference()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Link management - Functions and Classes
4
 *
5
 * PHP Version 5.3
6
 *
7
 * This Source Code Form is subject to the terms of the Mozilla Public License,
8
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
 * obtain one at http://mozilla.org/MPL/2.0/.
10
 *
11
 * @category  phpMyFAQ
12
 * @package   PMF_Link  
13
 * @author    Matteo Scaramuccia <[email protected]>
14
 * @author    Thorsten Rinne <[email protected]>
15
 * @copyright 2005-2016 phpMyFAQ Team
16
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
17
 * @link      http://www.phpmyfaq.de
18
 * @since     2005-11-02
19
 */
20
21
if (!defined('IS_VALID_PHPMYFAQ')) {
22
    exit();
23
}
24
25
/**
26
 * PMF_Link Class
27
 *
28
 * This class wrap the needs for managing an HTML anchor
29
 * taking into account also the HTML anchor creation
30
 * with specific handling for mod_rewrite PMF native support
31
 *
32
 * @category  phpMyFAQ
33
 * @package   PMF_Link  
34
 * @author    Matteo Scaramuccia <[email protected]>
35
 * @author    Thorsten Rinne <[email protected]>
36
 * @copyright 2005-2016 phpMyFAQ Team
37
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
38
 * @link      http://www.phpmyfaq.de
39
 * @since     2005-11-02
40
 */
41
class PMF_Link
42
{
43
    /**
44
     * class constants
45
     *
46
     */
47
    const PMF_LINK_AMPERSAND = '&amp;';
48
    const PMF_LINK_CATEGORY = 'category/';
49
    const PMF_LINK_CONTENT = 'content/';
50
    const PMF_LINK_EQUAL = '=';
51
    const PMF_LINK_FRAGMENT_SEPARATOR = '#';
52
    const PMF_LINK_HTML_MINUS = '-';
53
    const PMF_LINK_HTML_UNDERSCORE = '_';
54
    const PMF_LINK_HTML_SLASH = '/';
55
    const PMF_LINK_HTML_TARGET_BLANK = '_blank';
56
    const PMF_LINK_HTML_TARGET_PARENT = '_parent';
57
    const PMF_LINK_HTML_TARGET_SELF = '_self';
58
    const PMF_LINK_HTML_TARGET_TOP = '_top';
59
    const PMF_LINK_NEWS = 'news/';
60
    const PMF_LINK_SITEMAP = 'sitemap/';
61
    const PMF_LINK_SLASH = '/';
62
    const PMF_LINK_SEARCHPART_SEPARATOR = '?';
63
    const PMF_LINK_TAGS = 'tags/';
64
    
65
    const PMF_LINK_INDEX_ADMIN = '/admin/index.php';
66
    const PMF_LINK_INDEX_HOME = '/index.php';
67
    
68
    const PMF_LINK_GET_ACTION = 'action';
69
    const PMF_LINK_GET_ARTLANG = 'artlang';
70
    const PMF_LINK_GET_CATEGORY = 'cat';
71
    const PMF_LINK_GET_HIGHLIGHT = 'highlight';
72
    const PMF_LINK_GET_ID = 'id';
73
    const PMF_LINK_GET_LANG = 'lang';
74
    const PMF_LINK_GET_LETTER = 'letter';
75
    const PMF_LINK_GET_NEWS_ID = 'newsid';
76
    const PMF_LINK_GET_NEWS_LANG = 'newslang';
77
    const PMF_LINK_GET_PAGE = 'seite';
78
    const PMF_LINK_GET_SIDS = 'SIDS';
79
    const PMF_LINK_GET_TAGGING_ID = 'tagging_id';
80
    const PMF_LINK_GET_LANGS = 'langs';
81
    
82
    const PMF_LINK_GET_ACTION_ADD = 'add';
83
    const PMF_LINK_GET_ACTION_ARTIKEL = 'artikel';
84
    const PMF_LINK_GET_ACTION_ASK = 'ask';
85
    const PMF_LINK_GET_ACTION_CONTACT = 'contact';
86
    const PMF_LINK_GET_ACTION_GLOSSARY = 'glossary';
87
    const PMF_LINK_GET_ACTION_HELP = 'help';
88
    const PMF_LINK_GET_ACTION_LOGIN = 'login';
89
    const PMF_LINK_GET_ACTION_NEWS = 'news';
90
    const PMF_LINK_GET_ACTION_OPEN = 'open';
91
    const PMF_LINK_GET_ACTION_PASSWORD = 'password';
92
    const PMF_LINK_GET_ACTION_REGISTER = 'register';
93
    const PMF_LINK_GET_ACTION_SEARCH = 'search';
94
    const PMF_LINK_GET_ACTION_SITEMAP = 'sitemap';
95
    const PMF_LINK_GET_ACTION_SHOW = 'show';
96
    
97
    const PMF_LINK_HTML_CATEGORY = 'category';
98
    const PMF_LINK_HTML_EXTENSION = '.html';
99
    const PMF_LINK_HTML_SITEMAP = 'sitemap';
100
    
101
    const PMF_LINK_HTML_ADDCONTENT = 'addcontent.html';
102
    const PMF_LINK_HTML_ASK = 'ask.html';
103
    const PMF_LINK_HTML_CONTACT = 'contact.html';
104
    const PMF_LINK_HTML_GLOSSARY = 'glossary.html';
105
    const PMF_LINK_HTML_HELP = 'help.html';
106
    const PMF_LINK_HTML_LOGIN = 'login.html';
107
    const PMF_LINK_HTML_OPEN = 'open.html';
108
    const PMF_LINK_HTML_PASSWORD = 'password.html';
109
    const PMF_LINK_HTML_REGISTER = 'register.html';
110
    const PMF_LINK_HTML_SEARCH = 'search.html';
111
    const PMF_LINK_HTML_SHOWCAT = 'showcat.html';
112
113
    /**
114
     * URL
115
     *
116
     * @var string
117
     */
118
    public $url = '';
119
    
120
    /**
121
     * CSS class
122
     *
123
     * @var string
124
     */
125
    public $class = '';
126
    
127
    /**
128
     * Linktext
129
     *
130
     * @var string
131
     */
132
    public $text = '';
133
    
134
    /**
135
     * Tooltip
136
     *
137
     * @var string
138
     */
139
    public $tooltip = '';
140
    
141
    /**
142
     * Target
143
     *
144
     * @var string
145
     */
146
    public $target = '';
147
    
148
    /**
149
     * Name selector
150
     *
151
     * @var string
152
     */
153
    public $name = '';
154
    
155
    /**
156
     * property specific to the SEO/SEF URLs
157
     *
158
     * @var string
159
     */
160
    public $itemTitle = '';
161
162
    /**
163
     * Item property for HTML5 microdata
164
     *
165
     * @var string
166
     */
167
    protected $itemprop = '';
168
169
    /**
170
     * rel property
171
     *
172
     * @var string
173
     */
174
    protected $rel = '';
175
176
    /**
177
     * id selector
178
     *
179
     * @var string
180
     */
181
    public $id = '';
182
183
    /**
184
     * @var PMF_Configuration
185
     */
186
    private $_config = null;
187
188
    /**
189
     * Constructor
190
     *
191
     * @param string            $url    URL
192
     * @param PMF_Configuration $config
193
     *
194
     * @return PMF_Link
195
     */
196
    public function __construct($url, PMF_Configuration $config)
197
    {
198
        $this->url     = $url;
199
        $this->_config = $config;
200
    }
201
202
    /**
203
     * Checks if webserver is an IIS Server
204
     *
205
     * @return boolean
206
     */
207
    public static function isIISServer()
208
    {
209
        return (isset($_SERVER['ALL_HTTP']) || isset($_SERVER['COMPUTERNAME']) || isset($_SERVER['APP_POOL_ID']));
210
    }
211
212
    /**
213
     * Checks if the the current URL is the main index.php file
214
     *
215
     * @return boolean
216
     */
217
    protected function isHomeIndex()
218
    {
219
        if (!$this->isSystemLink()) {
220
            return false;
221
        }
222
223
        return !(false === strpos($this->url, self::PMF_LINK_INDEX_HOME));
224
    }
225
226
    /**
227
     * Checks if URL is an internal reference
228
     *
229
     * @return boolean
230
     */
231
    protected function isInternalReference()
232
    {
233
        if ($this->isRelativeSystemLink()) {
234
            return true;
235
        }
236
        if (false === strpos($this->url, '#')) {
237
            return false;
238
        }
239
240
        return (strpos($this->url, '#') == 0);
241
    }
242
243
    /**
244
     * Checks if URL is a relative system link
245
     *
246
     * @return boolean
247
     */
248
    protected function isRelativeSystemLink()
249
    {
250
        $slashIdx = strpos($this->url, self::PMF_LINK_SLASH);
251
        if (false === $slashIdx) {
252
            return false;
253
        }
254
255
        return ($slashIdx == 0);
256
    }
257
258
    /**
259
     * Checks if URL is a system link
260
     *
261
     * @return boolean
262
     */
263
    protected function isSystemLink()
264
    {
265
        // a. Is the url relative, starting with '/'?
266
        // b. Is the url related to the current running PMF system?
267
        if ($this->isRelativeSystemLink()) {
268
            return true;
269
        }
270
        // $_SERVER['HTTP_HOST'] is the name of the website or virtual host name
271
        return !(false === strpos($this->url, $_SERVER['HTTP_HOST']));
272
    }
273
274
    /**
275
     * @param string $itemprop Item property
276
     *
277
     * @return void
278
     */
279
    public function setItemProperty($itemprop)
280
    {
281
        $this->itemprop = $itemprop;
282
    }
283
284
    /**
285
     * @param string $rel rel property
286
     *
287
     * @return void
288
     */
289
    public function setRelation($rel)
290
    {
291
        $this->rel = $rel;
292
    }
293
294
    /**
295
     * Checks if URL contains a scheme
296
     *
297
     * @return boolean
298
     */
299
    protected function hasScheme()
300
    {
301
        $parsed = parse_url($this->url);
302
303
        return (!empty($parsed['scheme']));
304
    }
305
306
    /**
307
     * Returns a search engine optimized title
308
     *
309
     * @param string $title
310
     *
311
     * @return string
312
     */
313
    public function getSEOItemTitle($title = '')
314
    {
315
        if ('' === $title) {
316
            $title = $this->itemTitle;
317
        }
318
319
        $itemTitle = trim($title);
320
        // Lower the case (aesthetic)
321
        $itemTitle = PMF_String::strtolower($itemTitle);
322
        // Use '_' for some other characters for:
323
        // 1. avoiding regexp match break;
324
        // 2. improving the reading.
325
        $itemTitle = str_replace(array('-', "'", '/', '&#39'), '_', $itemTitle);
326
        // 1. Remove any CR LF sequence
327
        // 2. Use a '-' for the words separation
328
        $itemTitle = PMF_String::preg_replace('/\s/m', '-', $itemTitle);
329
        // Hack: remove some chars for having a better readable title
330
        $itemTitle = str_replace(
331
            array('+', ',', ';', ':', '.', '?', '!', '"', '(', ')', '[', ']', '{', '}', '<', '>'),
332
            '',
333
            $itemTitle
334
        );
335
        // Hack: move some chars to "similar" but plain ASCII chars
336
        $itemTitle = str_replace(
337
            array(
338
                'à', 'è', 'é', 'ì', 'ò', 'ù', 'ä', 'ö', 'ü', 'ß', 'Ä', 'Ö', 'Ü',
339
                'č', 'ę', 'ė', 'į', 'š', 'ų', 'ū', 'ž'
340
                ),
341
            array(
342
                'a', 'e', 'e', 'i', 'o', 'u', 'ae', 'oe', 'ue', 'ss', 'Ae', 'Oe', 'Ue',
343
                'c', 'e', 'e', 'i', 's', 'u', 'u', 'z'
344
            ),
345
            $itemTitle
346
        );
347
        // Clean up
348
        $itemTitle = PMF_String::preg_replace('/-[\-]+/m', '-', $itemTitle);
349
350
        return $itemTitle;
351
    }
352
353
    /**
354
     * Returns the HTTP GET parameters
355
     *
356
     * @return array
357
     */
358
    protected function getHttpGetParameters()
359
    {
360
        $query      = $this->getQuery();
361
        $parameters = array();
362
363
        if (!empty($query)) {
364
            // Check fragment
365
            if (isset($query['fragment']) ) {
366
                $parameters[self::PMF_LINK_FRAGMENT_SEPARATOR] = urldecode($query['fragment']);
367
            }
368
            // Check if query string contains &amp;
369
            if (!strpos($query['main'], '&amp;')) {
370
                $query['main'] = str_replace('&', '&amp;', $query['main']);
371
            }
372
            $params = explode(self::PMF_LINK_AMPERSAND, $query['main']);
373
            foreach ($params as $param) {
374
                if (!empty($param)) {
375
                    $couple           = explode(self::PMF_LINK_EQUAL, $param);
376
                    list($key, $val)  = $couple;
377
                    $parameters[$key] = urldecode($val);
378
                }
379
            }
380
        }
381
382
        return $parameters;
383
    }
384
385
    /**
386
     * Returns the Query of an URL
387
     *
388
     * @return string
389
     */
390
    protected function getQuery()
391
    {
392
        $query = '';
393
        
394
        if (!empty($this->url)) {
395
            $parsed = parse_url($this->url);
396
397 View Code Duplication
            if (isset($parsed['query'])) {
398
                $query['main'] = filter_var($parsed['query'], FILTER_SANITIZE_STRIPPED); 
399
            }
400 View Code Duplication
            if (isset($parsed['fragment'])) {
401
                $query['fragment'] = filter_var($parsed['fragment'], FILTER_SANITIZE_STRIPPED);
402
            }
403
        }
404
405
        return $query;
406
    }
407
408
    /**
409
     * Returns the default scheme
410
     *
411
     * @return string
412
     */
413
    protected function getDefaultScheme()
414
    {
415
        $scheme = 'http://';
416
        if ($this->isSystemLink()) {
417
            $scheme = $this->getSystemScheme();
418
        }
419
420
        return $scheme;
421
    }
422
423
    /**
424
     * Returns the system scheme, http or https
425
     *
426
     * @return string
427
     */
428
    public function getSystemScheme()
429
    {
430
        if ($this->_config->get('security.useSslOnly')) {
431
            return 'https://';
432
        }
433
434
        if (!PMF_Link::isIISServer()) {
435
            // Apache, nginx, lighttpd
436
            if (isset($_SERVER['HTTPS']) && 'on' === strtolower($_SERVER['HTTPS'])) {
437
                return 'https://';
438
            } else {
439
                return 'http://';
440
            }
441
        } else {
442
            // IIS Server
443
            if ('on' === strtolower($_SERVER['HTTPS'])) {
444
                return 'https://';
445
            } else {
446
                return 'http://';
447
            }
448
        }
449
    }
450
451
    /**
452
     * Returns the relative URI
453
     *
454
     * @param string $path
455
     *
456
     * @return string
457
     */
458
    public static function getSystemRelativeUri($path = null)
459
    {
460
        if (isset($path)) {
461
            return str_replace($path, '', $_SERVER['SCRIPT_NAME']);
462
        }
463
        
464
        return str_replace('/inc/Link.php', '', $_SERVER['SCRIPT_NAME']);
465
    }
466
467
    /**
468
     * Returns the system URI
469
     *
470
     * @param string $path
471
     *
472
     * @return string
473
     */
474
    public function getSystemUri($path = null)
475
    {
476
        // $_SERVER['HTTP_HOST'] is the name of the website or virtual host name (HTTP/1.1)
477
        // Precisely, it contains what the user has written in the Host request-header, see below.
478
        // RFC 2616: The Host request-header field specifies the Internet host and port number of the resource
479
        //           being requested, as obtained from the original URI given by the user or referring resource
480
481
        // Remove any ref to standard ports 80 and 443.
482
        $pattern[0] = '/:80$/';   // HTTP: port 80
483
        $pattern[1] = '/:443$/'; // HTTPS: port 443
484
        $sysUri = $this->getSystemScheme() . preg_replace($pattern, '', $_SERVER['HTTP_HOST']);
485
486
        return $sysUri . PMF_link::getSystemRelativeUri($path);
487
    }
488
489
    /**
490
     * Builds a HTML anchor
491
     *
492
     * @return string
493
     */
494
    public function toHtmlAnchor()
495
    {
496
        // Sanitize the provided url
497
        $url = $this->toString();
498
        // Prepare HTML anchor element
499
        $htmlAnchor = '<a';
500
        if (!empty($this->class)) {
501
            $htmlAnchor .= sprintf(' class="%s"', $this->class);
502
        }
503
        if (!empty($this->id)) {
504
            $htmlAnchor .= ' id="'.$this->id.'"';
505
        }
506
        if (!empty($this->tooltip)) {
507
            $htmlAnchor .= sprintf(' title="%s"', addslashes($this->tooltip));
508
        }
509
        if (!empty($this->name)) {
510
                $htmlAnchor .= sprintf(' name="%s"', $this->name);
511
        } else {
512
            if (!empty($this->url)) {
513
                $htmlAnchor .= sprintf(' href="%s"', $url);
514
            }
515
            if (!empty($this->target)) {
516
                $htmlAnchor .= sprintf(' target="%s"', $this->target);
517
            }
518
        }
519
        if (!empty($this->itemprop)) {
520
            $htmlAnchor .= sprintf(' itemprop="%s"', $this->itemprop);
521
        }
522
        if (!empty($this->rel)) {
523
            $htmlAnchor .= sprintf(' rel="%s"', $this->rel);
524
        }
525
        $htmlAnchor .= '>';
526
        if (('0' == $this->text) || (!empty($this->text))) {
527
            $htmlAnchor .= $this->text;
528
        } else {
529
            if (!empty($this->name)) {
530
                $htmlAnchor .= $this->name;
531
            } else {
532
                $htmlAnchor .= $url;
533
            }
534
        }
535
        $htmlAnchor .= '</a>';
536
537
        return $htmlAnchor;
538
    }
539
540
    /**
541
     * Appends the session id
542
     *
543
     * @param string  $url  URL
544
     * @param integer $sids Session Id
545
     *
546
     * @return string
547
     */
548
    protected function appendSids($url, $sids)
549
    {
550
        $separator = (false === strpos($url, self::PMF_LINK_SEARCHPART_SEPARATOR)) 
551
                     ? 
552
                     self::PMF_LINK_SEARCHPART_SEPARATOR 
553
                     : 
554
                     self::PMF_LINK_AMPERSAND;
555
        return $url . $separator . self::PMF_LINK_GET_SIDS . self::PMF_LINK_EQUAL . $sids;
556
    }
557
    
558
    /**
559
     * Rewrites a URL string
560
     *
561
     * @param boolean $forceNoModrewriteSupport Force no rewrite support
562
     *
563
     * @return string
564
     */
565
    public function toString($forceNoModrewriteSupport = false)
566
    {
567
        $url = $this->toUri();
568
        // Check mod_rewrite support and 'rewrite' the passed (system) uri
569
        // according to the rewrite rules written in .htaccess
570
        if ((!$forceNoModrewriteSupport) && ($this->_config->get('main.enableRewriteRules'))) {
571
572
            if ($this->isHomeIndex()) {
573
574
                $getParams = $this->getHttpGetParameters();
575
                if (isset($getParams[self::PMF_LINK_GET_ACTION])) {
576
                    // Get the part of the url 'till the '/' just before the pattern
577
                    $url = substr($url, 0, strpos($url, self::PMF_LINK_INDEX_HOME) + 1);
578
                    // Build the Url according to .htaccess rules
579
                    switch ($getParams[self::PMF_LINK_GET_ACTION]) {
580
                        
581
                        case self::PMF_LINK_GET_ACTION_ADD:
582
                            $url .= self::PMF_LINK_HTML_ADDCONTENT;
583
                            break;
584
                            
585
                        case self::PMF_LINK_GET_ACTION_ARTIKEL:
586
                            $url .= self::PMF_LINK_CONTENT . 
587
                                    $getParams[self::PMF_LINK_GET_CATEGORY] . 
588
                                    self::PMF_LINK_HTML_SLASH . 
589
                                    $getParams[self::PMF_LINK_GET_ID] . 
590
                                    self::PMF_LINK_HTML_SLASH . 
591
                                    $getParams[self::PMF_LINK_GET_ARTLANG] . 
592
                                    self::PMF_LINK_SLASH . 
593
                                    $this->getSEOItemTitle() . 
594
                                    self::PMF_LINK_HTML_EXTENSION;
595 View Code Duplication
                            if (isset($getParams[self::PMF_LINK_GET_HIGHLIGHT])) {
596
                                $url .= self::PMF_LINK_SEARCHPART_SEPARATOR . 
597
                                        self::PMF_LINK_GET_HIGHLIGHT . '=' . 
598
                                        $getParams[self::PMF_LINK_GET_HIGHLIGHT];
599
                            }
600
                            if (isset($getParams[self::PMF_LINK_FRAGMENT_SEPARATOR])) {
601
                                $url .= self::PMF_LINK_FRAGMENT_SEPARATOR . 
602
                                        $getParams[self::PMF_LINK_FRAGMENT_SEPARATOR];
603
                            }
604
                            break;
605
                            
606
                        case self::PMF_LINK_GET_ACTION_ASK:
607
                            $url .= self::PMF_LINK_HTML_ASK;
608
                            break;
609
                            
610
                        case self::PMF_LINK_GET_ACTION_CONTACT:
611
                            $url .= self::PMF_LINK_HTML_CONTACT;
612
                            break;
613
614
                        case self::PMF_LINK_GET_ACTION_GLOSSARY:
615
                            $url .= self::PMF_LINK_HTML_GLOSSARY;
616
                            break;
617
618
                        case self::PMF_LINK_GET_ACTION_HELP:
619
                            $url .= self::PMF_LINK_HTML_HELP;
620
                            break;
621
                            
622
                        case self::PMF_LINK_GET_ACTION_OPEN:
623
                            $url .= self::PMF_LINK_HTML_OPEN;
624
                            break;
625
                            
626
                        case self::PMF_LINK_GET_ACTION_SEARCH:
627
                            if (!isset($getParams[self::PMF_LINK_GET_ACTION_SEARCH]) && 
628
                                isset($getParams[self::PMF_LINK_GET_TAGGING_ID])) {
629
                                $url .= self::PMF_LINK_TAGS.$getParams[self::PMF_LINK_GET_TAGGING_ID];
630
                                if (isset($getParams[self::PMF_LINK_GET_PAGE])) {
631
                                    $url .= self::PMF_LINK_HTML_SLASH.$getParams[self::PMF_LINK_GET_PAGE];
632
                                }
633
                                $url .= self::PMF_LINK_SLASH . 
634
                                        $this->getSEOItemTitle() . 
635
                                        self::PMF_LINK_HTML_EXTENSION; 
636
                            } elseif (isset($getParams[self::PMF_LINK_GET_ACTION_SEARCH])) {
637
                                $url .= self::PMF_LINK_HTML_SEARCH;
638
                                $url .= self::PMF_LINK_SEARCHPART_SEPARATOR . 
639
                                        self::PMF_LINK_GET_ACTION_SEARCH . '=' . 
640
                                        $getParams[self::PMF_LINK_GET_ACTION_SEARCH];
641 View Code Duplication
                                if (isset($getParams[self::PMF_LINK_GET_PAGE])) {
642
                                    $url .= self::PMF_LINK_AMPERSAND.self::PMF_LINK_GET_PAGE . '=' . 
643
                                            $getParams[self::PMF_LINK_GET_PAGE];
644
                                }
645
                            }
646 View Code Duplication
                            if (isset($getParams[self::PMF_LINK_GET_LANGS])) {
647
                                $url .= self::PMF_LINK_AMPERSAND . 
648
                                        self::PMF_LINK_GET_LANGS . '=' . 
649
                                        $getParams[self::PMF_LINK_GET_LANGS];
650
                            }
651
                            break;
652
                            
653
                        case self::PMF_LINK_GET_ACTION_SITEMAP:
654
                            if (isset($getParams[self::PMF_LINK_GET_LETTER])) {
655
                                $url .= self::PMF_LINK_SITEMAP . 
656
                                        $getParams[self::PMF_LINK_GET_LETTER] . 
657
                                        self::PMF_LINK_HTML_SLASH . 
658
                                        $getParams[self::PMF_LINK_GET_LANG] . 
659
                                        self::PMF_LINK_HTML_EXTENSION;
660
                            } else {
661
                                $url .= self::PMF_LINK_SITEMAP . 'A' . 
662
                                        self::PMF_LINK_HTML_SLASH . 
663
                                        $getParams[self::PMF_LINK_GET_LANG] . 
664
                                        self::PMF_LINK_HTML_EXTENSION;
665
                            }
666
                            break;
667
                            
668
                        case self::PMF_LINK_GET_ACTION_SHOW:
669
                            if (!isset($getParams[self::PMF_LINK_GET_CATEGORY]) || 
670
                                (isset($getParams[self::PMF_LINK_GET_CATEGORY]) && 
671
                                (0 == $getParams[self::PMF_LINK_GET_CATEGORY]))) {
672
                                $url .= self::PMF_LINK_HTML_SHOWCAT;
673
                            } else {
674
                                $url .= self::PMF_LINK_CATEGORY . 
675
                                        $getParams[self::PMF_LINK_GET_CATEGORY];
676
                                if (isset($getParams[self::PMF_LINK_GET_PAGE])) {
677
                                    $url .= self::PMF_LINK_HTML_SLASH . 
678
                                            $getParams[self::PMF_LINK_GET_PAGE];
679
                                }
680
                                $url .= self::PMF_LINK_HTML_SLASH . 
681
                                        $this->getSEOItemTitle() .
682
                                        self::PMF_LINK_HTML_EXTENSION;
683
                            }
684
                            break;
685
                            
686
                        case self::PMF_LINK_GET_ACTION_NEWS:
687
                            $url .= self::PMF_LINK_NEWS . 
688
                                    $getParams[self::PMF_LINK_GET_NEWS_ID] . 
689
                                    self::PMF_LINK_HTML_SLASH .
690
                                    $getParams[self::PMF_LINK_GET_NEWS_LANG] .
691
                                    self::PMF_LINK_SLASH .
692
                                    $this->getSEOItemTitle() .
693
                                    self::PMF_LINK_HTML_EXTENSION;
694
                            break;
695
                    }
696
                    
697
                    if (isset($getParams[self::PMF_LINK_GET_SIDS])) {
698
                        $url = $this->appendSids($url, $getParams[self::PMF_LINK_GET_SIDS]);
699
                    }
700
                    
701
                    if (isset($getParams['fragment'])) {
702
                        $url .= self::PMF_LINK_FRAGMENT_SEPARATOR.$getParams['fragment'];
703
                    }
704
                }
705
            }
706
        }
707
708
        return $url;
709
    }
710
711
    /**
712
     * Transforms a URI
713
     *
714
     * @return string
715
     */
716
    public function toUri()
717
    {
718
        $url = $this->url;
719
        if (!empty($this->url)) {
720
            if ((!$this->hasScheme()) && (!$this->isInternalReference())) {
721
                $url = $this->getDefaultScheme() . $this->url;
722
            }
723
        }
724
725
        return $url;
726
    }
727
728
    /**
729
     * Returns the current URL
730
     *
731
     * @return string
732
     */
733
    public function getCurrentUrl()
734
    {
735
        if (!empty($_SERVER['HTTPS'])) {
736
            return 'https://' . $_SERVER['SERVER_NAME'] . PMF_String::htmlentities($_SERVER['REQUEST_URI']);
737
        } else {
738
            return 'http://' . $_SERVER['SERVER_NAME'] . PMF_String::htmlentities($_SERVER['REQUEST_URI']);
739
        }
740
    }
741
    
742
    /**
743
     * Static method to generate simple HTML anchors
744
     *
745
     * @static
746
     * @param string $url    URL
747
     * @param string $text   Text
748
     * @param bool   $active Add CSS class named "active"?
749
     *
750
     * @return string
751
     */
752
    public static function renderNavigationLink($url, $text, $active = false)
753
    {
754
        return printf(
755
            '<a %s href="%s">%s</a>',
756
            (true === $active ? 'class="active"' : ''),
757
            $url,
758
            $text
759
        );
760
    }
761
}