-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLink.php
64 lines (62 loc) · 1.67 KB
/
Link.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @file framework/html/link.php
*
* depage html module
*
*
* copyright (c) 2012 Frank Hellenkamp [[email protected]]
*
* @author Frank Hellenkamp [[email protected]]
*/
namespace depage\html;
class link {
protected $link = null;
protected $protocol = null;
protected $locale = null;
// {{{ constructor
/**
* builds a localized link
*
* @param $link (string) page to link to
* @param $protocol (string) protocol to use for the link
* @param $locale (string) locale to link to
*/
public function __construct($link, $protocol = null, $locale = null) {
$this->link = $link;
$this->protocol = $protocol;
$this->locale = $locale;
}
// }}}
// {{{ __toString
/**
* builds a localized link
*
* @param $link (string) page to link to
* @param $protocol (string) protocol to use for the link
* @param $locale (string) locale to link to
*/
public function __toString() {
if (is_null($this->locale)) {
$lang = DEPAGE_LANG;
} else {
$lang = \Locale::getPrimaryLanguage($this->locale);
}
if (!is_null($this->protocol)) {
if ($this->protocol == "auto") {
$base = DEPAGE_BASE;
} else {
$base = preg_replace("/.*:\/\//", $this->protocol . "://", DEPAGE_BASE);
}
} else {
$base = "";
}
if (DEPAGE_URL_HAS_LOCALE) {
return $base . $lang . '/' . $this->link;
} else {
return $base . $this->link;
}
}
// }}}
}
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */