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
Pull Request — master (#1192)
by
unknown
14:48
created

PMF_Link::renderNavigationLink()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 1
nop 3
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Link management - Functions and Classes
4
 *
5
 * PHP Version 5.4
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-2014 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-2014 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 rawurlencode($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 = [];
362
363
        if (!empty($query)) {
364
            if (isset($query['fragment']) ) {
365
                $parameters[self::PMF_LINK_FRAGMENT_SEPARATOR] = urldecode($query['fragment']);
366
            }
367
            $params = explode(self::PMF_LINK_AMPERSAND, $query['main']);
368
            foreach ($params as $param) {
369
                if (!empty($param)) {
370
                    $couple           = explode(self::PMF_LINK_EQUAL, $param);
371
                    list($key, $val)  = $couple;
372
                    $parameters[$key] = urldecode($val);
373
                }
374
            }
375
        }
376
377
        return $parameters;
378
    }
379
380
    /**
381
     * Returns the Query of an URL
382
     *
383
     * @return string
384
     */
385
    protected function getQuery()
386
    {
387
        $query = '';
388
        
389
        if (!empty($this->url)) {
390
            $parsed = parse_url($this->url);
391
392 View Code Duplication
            if (isset($parsed['query'])) {
393
                $query['main'] = filter_var($parsed['query'], FILTER_SANITIZE_STRIPPED); 
394
            }
395 View Code Duplication
            if (isset($parsed['fragment'])) {
396
                $query['fragment'] = filter_var($parsed['fragment'], FILTER_SANITIZE_STRIPPED);
397
            }
398
        }
399
400
        return $query;
401
    }
402
403
    /**
404
     * Returns the default scheme
405
     *
406
     * @return string
407
     */
408
    protected function getDefaultScheme()
409
    {
410
        $scheme = 'http://';
411
        if ($this->isSystemLink()) {
412
            $scheme = $this->getSystemScheme();
413
        }
414
415
        return $scheme;
416
    }
417
418
    /**
419
     * Returns the system scheme, http or https
420
     *
421
     * @return string
422
     */
423
    public function getSystemScheme()
424
    {
425
        if ($this->_config->get('security.useSslOnly')) {
426
            return 'https://';
427
        }
428
        
429
        $scheme = 'http' . (((!PMF_Link::isIISServer()) && isset($_SERVER['HTTPS'])) || 
430
                           ((PMF_Link::isIISServer()) && ('on' == strtolower($_SERVER['HTTPS']))) ? 's' : '') . '://';
431
432
        return $scheme;
433
    }
434
435
    /**
436
     * Returns the relative URI
437
     *
438
     * @param string $path
439
     *
440
     * @return string
441
     */
442
    public static function getSystemRelativeUri($path = null)
443
    {
444
        if (isset($path)) {
445
            return str_replace($path, '', $_SERVER['SCRIPT_NAME']);
446
        }
447
        
448
        return str_replace('/inc/Link.php', '', $_SERVER['SCRIPT_NAME']);
449
    }
450
451
    /**
452
     * Returns the system URI
453
     *
454
     * @param string $path
455
     *
456
     * @return string
457
     */
458
    public function getSystemUri($path = null)
459
    {
460
        // $_SERVER['HTTP_HOST'] is the name of the website or virtual host name (HTTP/1.1)
461
        // Precisely, it contains what the user has written in the Host request-header, see below.
462
        // RFC 2616: The Host request-header field specifies the Internet host and port number of the resource
463
        //           being requested, as obtained from the original URI given by the user or referring resource
464
465
        // Remove any ref to standard ports 80 and 443.
466
        $pattern[0] = '/:80$/';   // HTTP: port 80
467
        $pattern[1] = '/:443$/'; // HTTPS: port 443
468
        $sysUri = $this->getSystemScheme() . preg_replace($pattern, '', $_SERVER['HTTP_HOST']);
469
470
        return $sysUri . PMF_link::getSystemRelativeUri($path);
471
    }
472
473
    /**
474
     * Builds a HTML anchor
475
     *
476
     * @return string
477
     */
478
    public function toHtmlAnchor()
479
    {
480
        // Sanitize the provided url
481
        $url = $this->toString();
482
        // Prepare HTML anchor element
483
        $htmlAnchor = '<a';
484
        if (!empty($this->class)) {
485
            $htmlAnchor .= sprintf(' class="%s"', $this->class);
486
        }
487
        if (!empty($this->id)) {
488
            $htmlAnchor .= ' id="'.$this->id.'"';
489
        }
490
        if (!empty($this->tooltip)) {
491
            $htmlAnchor .= sprintf(' title="%s"', addslashes($this->tooltip));
492
        }
493
        if (!empty($this->name)) {
494
                $htmlAnchor .= sprintf(' name="%s"', $this->name);
495
        } else {
496
            if (!empty($this->url)) {
497
                $htmlAnchor .= sprintf(' href="%s"', $url);
498
            }
499
            if (!empty($this->target)) {
500
                $htmlAnchor .= sprintf(' target="%s"', $this->target);
501
            }
502
        }
503
        if (!empty($this->itemprop)) {
504
            $htmlAnchor .= sprintf(' itemprop="%s"', $this->itemprop);
505
        }
506
        if (!empty($this->rel)) {
507
            $htmlAnchor .= sprintf(' rel="%s"', $this->rel);
508
        }
509
        $htmlAnchor .= '>';
510
        if (('0' == $this->text) || (!empty($this->text))) {
511
            $htmlAnchor .= $this->text;
512
        } else {
513
            if (!empty($this->name)) {
514
                $htmlAnchor .= $this->name;
515
            } else {
516
                $htmlAnchor .= $url;
517
            }
518
        }
519
        $htmlAnchor .= '</a>';
520
521
        return $htmlAnchor;
522
    }
523
524
    /**
525
     * Appends the session id
526
     *
527
     * @param string  $url  URL
528
     * @param integer $sids Session Id
529
     *
530
     * @return string
531
     */
532
    protected function appendSids($url, $sids)
533
    {
534
        $separator = (false === strpos($url, self::PMF_LINK_SEARCHPART_SEPARATOR)) 
535
                     ? 
536
                     self::PMF_LINK_SEARCHPART_SEPARATOR 
537
                     : 
538
                     self::PMF_LINK_AMPERSAND;
539
        return $url . $separator . self::PMF_LINK_GET_SIDS . self::PMF_LINK_EQUAL . $sids;
540
    }
541
    
542
    /**
543
     * Rewrites a URL string
544
     *
545
     * @param boolean $forceNoModrewriteSupport Force no rewrite support
546
     *
547
     * @return string
548
     */
549
    public function toString($forceNoModrewriteSupport = false)
550
    {
551
        $url = $this->toUri();
552
        // Check mod_rewrite support and 'rewrite' the passed (system) uri
553
        // according to the rewrite rules written in .htaccess
554
        if ((!$forceNoModrewriteSupport) && ($this->_config->get('main.enableRewriteRules'))) {
555
556
            if ($this->isHomeIndex()) {
557
558
                $getParams = $this->getHttpGetParameters();
559
                if (isset($getParams[self::PMF_LINK_GET_ACTION])) {
560
                    // Get the part of the url 'till the '/' just before the pattern
561
                    $url = substr($url, 0, strpos($url, self::PMF_LINK_INDEX_HOME) + 1);
562
                    // Build the Url according to .htaccess rules
563
                    switch ($getParams[self::PMF_LINK_GET_ACTION]) {
564
                        
565
                        case self::PMF_LINK_GET_ACTION_ADD:
566
                            $url .= self::PMF_LINK_HTML_ADDCONTENT;
567
                            break;
568
                            
569
                        case self::PMF_LINK_GET_ACTION_ARTIKEL:
570
                            $url .= self::PMF_LINK_CONTENT . 
571
                                    $getParams[self::PMF_LINK_GET_CATEGORY] . 
572
                                    self::PMF_LINK_HTML_SLASH . 
573
                                    $getParams[self::PMF_LINK_GET_ID] . 
574
                                    self::PMF_LINK_HTML_SLASH . 
575
                                    $getParams[self::PMF_LINK_GET_ARTLANG] . 
576
                                    self::PMF_LINK_SLASH . 
577
                                    $this->getSEOItemTitle() . 
578
                                    self::PMF_LINK_HTML_EXTENSION;
579 View Code Duplication
                            if (isset($getParams[self::PMF_LINK_GET_HIGHLIGHT])) {
580
                                $url .= self::PMF_LINK_SEARCHPART_SEPARATOR . 
581
                                        self::PMF_LINK_GET_HIGHLIGHT . '=' . 
582
                                        $getParams[self::PMF_LINK_GET_HIGHLIGHT];
583
                            }
584
                            if (isset($getParams[self::PMF_LINK_FRAGMENT_SEPARATOR])) {
585
                                $url .= self::PMF_LINK_FRAGMENT_SEPARATOR . 
586
                                        $getParams[self::PMF_LINK_FRAGMENT_SEPARATOR];
587
                            }
588
                            break;
589
                            
590
                        case self::PMF_LINK_GET_ACTION_ASK:
591
                            $url .= self::PMF_LINK_HTML_ASK;
592
                            break;
593
                            
594
                        case self::PMF_LINK_GET_ACTION_CONTACT:
595
                            $url .= self::PMF_LINK_HTML_CONTACT;
596
                            break;
597
598
                        case self::PMF_LINK_GET_ACTION_GLOSSARY:
599
                            $url .= self::PMF_LINK_HTML_GLOSSARY;
600
                            break;
601
602
                        case self::PMF_LINK_GET_ACTION_HELP:
603
                            $url .= self::PMF_LINK_HTML_HELP;
604
                            break;
605
                            
606
                        case self::PMF_LINK_GET_ACTION_OPEN:
607
                            $url .= self::PMF_LINK_HTML_OPEN;
608
                            break;
609
                            
610
                        case self::PMF_LINK_GET_ACTION_SEARCH:
611
                            if (!isset($getParams[self::PMF_LINK_GET_ACTION_SEARCH]) && 
612
                                isset($getParams[self::PMF_LINK_GET_TAGGING_ID])) {
613
                                $url .= self::PMF_LINK_TAGS.$getParams[self::PMF_LINK_GET_TAGGING_ID];
614
                                if (isset($getParams[self::PMF_LINK_GET_PAGE])) {
615
                                    $url .= self::PMF_LINK_HTML_SLASH.$getParams[self::PMF_LINK_GET_PAGE];
616
                                }
617
                                $url .= self::PMF_LINK_SLASH . 
618
                                        $this->getSEOItemTitle() . 
619
                                        self::PMF_LINK_HTML_EXTENSION; 
620
                            } elseif (isset($getParams[self::PMF_LINK_GET_ACTION_SEARCH])) {
621
                                $url .= self::PMF_LINK_HTML_SEARCH;
622
                                $url .= self::PMF_LINK_SEARCHPART_SEPARATOR . 
623
                                        self::PMF_LINK_GET_ACTION_SEARCH . '=' . 
624
                                        $getParams[self::PMF_LINK_GET_ACTION_SEARCH];
625 View Code Duplication
                                if (isset($getParams[self::PMF_LINK_GET_PAGE])) {
626
                                    $url .= self::PMF_LINK_AMPERSAND.self::PMF_LINK_GET_PAGE . '=' . 
627
                                            $getParams[self::PMF_LINK_GET_PAGE];
628
                                }
629
                            }
630 View Code Duplication
                            if (isset($getParams[self::PMF_LINK_GET_LANGS])) {
631
                                $url .= self::PMF_LINK_AMPERSAND . 
632
                                        self::PMF_LINK_GET_LANGS . '=' . 
633
                                        $getParams[self::PMF_LINK_GET_LANGS];
634
                            }
635
                            break;
636
                            
637
                        case self::PMF_LINK_GET_ACTION_SITEMAP:
638
                            if (isset($getParams[self::PMF_LINK_GET_LETTER])) {
639
                                $url .= self::PMF_LINK_SITEMAP . 
640
                                        $getParams[self::PMF_LINK_GET_LETTER] . 
641
                                        self::PMF_LINK_HTML_SLASH . 
642
                                        $getParams[self::PMF_LINK_GET_LANG] . 
643
                                        self::PMF_LINK_HTML_EXTENSION;
644
                            } else {
645
                                $url .= self::PMF_LINK_SITEMAP . 'A' . 
646
                                        self::PMF_LINK_HTML_SLASH . 
647
                                        $getParams[self::PMF_LINK_GET_LANG] . 
648
                                        self::PMF_LINK_HTML_EXTENSION;
649
                            }
650
                            break;
651
                            
652
                        case self::PMF_LINK_GET_ACTION_SHOW:
653
                            if (!isset($getParams[self::PMF_LINK_GET_CATEGORY]) || 
654
                                (isset($getParams[self::PMF_LINK_GET_CATEGORY]) && 
655
                                (0 == $getParams[self::PMF_LINK_GET_CATEGORY]))) {
656
                                $url .= self::PMF_LINK_HTML_SHOWCAT;
657
                            } else {
658
                                $url .= self::PMF_LINK_CATEGORY . 
659
                                        $getParams[self::PMF_LINK_GET_CATEGORY];
660
                                if (isset($getParams[self::PMF_LINK_GET_PAGE])) {
661
                                    $url .= self::PMF_LINK_HTML_SLASH . 
662
                                            $getParams[self::PMF_LINK_GET_PAGE];
663
                                }
664
                                $url .= self::PMF_LINK_HTML_SLASH . 
665
                                        $this->getSEOItemTitle() .
666
                                        self::PMF_LINK_HTML_EXTENSION;
667
                            }
668
                            break;
669
                            
670
                        case self::PMF_LINK_GET_ACTION_NEWS:
671
                            $url .= self::PMF_LINK_NEWS . 
672
                                    $getParams[self::PMF_LINK_GET_NEWS_ID] . 
673
                                    self::PMF_LINK_HTML_SLASH .
674
                                    $getParams[self::PMF_LINK_GET_NEWS_LANG] .
675
                                    self::PMF_LINK_SLASH .
676
                                    $this->getSEOItemTitle() .
677
                                    self::PMF_LINK_HTML_EXTENSION;
678
                            break;
679
                    }
680
                    
681
                    if (isset($getParams[self::PMF_LINK_GET_SIDS])) {
682
                        $url = $this->appendSids($url, $getParams[self::PMF_LINK_GET_SIDS]);
683
                    }
684
                    
685
                    if (isset($getParams['fragment'])) {
686
                        $url .= self::PMF_LINK_FRAGMENT_SEPARATOR.$getParams['fragment'];
687
                    }
688
                }
689
            }
690
        }
691
692
        return $url;
693
    }
694
695
    /**
696
     * Transforms a URI
697
     *
698
     * @return string
699
     */
700
    public function toUri()
701
    {
702
        $url = $this->url;
703
        if (!empty($this->url)) {
704
            if ((!$this->hasScheme()) && (!$this->isInternalReference())) {
705
                $url = $this->getDefaultScheme() . $this->url;
706
            }
707
        }
708
709
        return $url;
710
    }
711
712
    /**
713
     * Returns the current URL
714
     *
715
     * @return string
716
     */
717
    public function getCurrentUrl()
718
    {
719
        if (!empty($_SERVER['HTTPS'])) {
720
            return 'https://' . $_SERVER['SERVER_NAME'] . PMF_String::htmlentities($_SERVER['REQUEST_URI']);
721
        } else {
722
            return 'http://' . $_SERVER['SERVER_NAME'] . PMF_String::htmlentities($_SERVER['REQUEST_URI']);
723
        }
724
    }
725
    
726
    /**
727
     * Static method to generate simple HTML anchors
728
     *
729
     * @static
730
     * @param string $url    URL
731
     * @param string $text   Text
732
     * @param bool   $active Add CSS class named "active"?
733
     *
734
     * @return string
735
     */
736
    public static function renderNavigationLink($url, $text, $active = false)
737
    {
738
        return printf(
739
            '<a %s href="%s">%s</a>',
740
            (true === $active ? 'class="active"' : ''),
741
            $url,
742
            $text
743
        );
744
    }
745
}