/[web]/nav/lib.php
ViewVC logotype

Contents of /nav/lib.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1096 - (show annotations) (download)
Tue May 15 17:27:45 2012 UTC (11 years, 11 months ago) by rda
File size: 2990 byte(s)
first import; adapted copy of www/_nav/
1 <?php
2 // definition
3
4 class l10n
5 {
6 public static $t;
7
8 /**
9 * Load langs/$lang.lang into global $_t array.
10 *
11 * @param string $lang
12 *
13 * @return void
14 */
15 function load($lang) {
16 $lang_file = __DIR__ . '/langs/' . $lang . '.lang';
17 if (file_exists($lang_file)) {
18 global $_t;
19 $f = file($lang_file);
20 foreach ($f as $k => $v) {
21 if (substr($v, 0, 1) == ';' && !empty($f[$k+1])) {
22 $_t[trim(substr($v, 1))] = trim($f[$k+1]);
23 }
24 }
25 }
26 }
27
28 /**
29 * Get value for key $s in global array $_t.
30 *
31 * @param string $s
32 *
33 * @return string
34 */
35 function _t($s) {
36 if (trim($s) == '')
37 return '';
38
39 global $_t;
40
41 return array_key_exists($s, $_t) ? $_t[$s] : $s;
42 }
43 }
44
45 /**
46 * Produce navigation HTML code.
47 *
48 * @param boolean $wrap = false should it be wrapped in a <header id="nav" /> element?
49 * @param string $lang = 'en'
50 * @param string $inject = null
51 * @param string $vhost = '//www.mageia.org'
52 *
53 * @return string HTML code
54 */
55 function _mgnav_html($wrap = false, $lang = 'en', $inject = null, $vhost = '//www.mageia.org')
56 {
57 l10n::load($lang);
58
59 $tn = array(
60 array('mageia', '$S/$L/map/', 'Mageia', l10n::_t('Go to mageia.org site map.')),
61 array('about', '$S/$L/about/', l10n::_t('About&nbsp;us', $_t), l10n::_t('Learn more about Mageia.')),
62 array('downloads', '$S/$L/downloads/', l10n::_t('Downloads', $_t), l10n::_t('Download Mageia ISO and updates.')),
63 array('support', '$S/$L/support/', l10n::_t('Support', $_t), l10n::_t('Get support from Mageia community.')),
64 array('community', '$S/$L/community/', l10n::_t('Community', $_t), l10n::_t('')),
65 array('contribute', '$S/$L/contribute/', l10n::_t('Contribute', $_t), l10n::_t('You too can build Mageia with us!')),
66 array('you', '//identity.mageia.org/', l10n::_t('You', $_t), l10n::_t('Your Mageia online account.'))
67 // <search>
68 );
69
70 $s = array();
71 foreach ($tn as $i) {
72 $s[] = sprintf('<li><a href="%s" class="%s" title="%s">%s</a></li>',
73 str_replace(
74 array('$L', '$S'),
75 array($lang, $vhost),
76 $i[1]
77 ),
78 $i[0],
79 $i[3],
80 $i[2]
81 );
82 }
83
84 if (!is_null($inject))
85 $s[] = sprintf('<li>%s</li>', $inject);
86
87 $s = implode($s);
88 $h = sprintf('<nav id="mgnav"><ul id="nav">%s</ul></nav>', $s);
89
90 if ($wrap)
91 $h = sprintf('<header id="hmgn">%s</header>', $h);
92
93 return $h;
94 }
95
96 /**
97 * Returns CSS definition ready to be inserted into a HTML document.
98 *
99 * @return string
100 */
101 function _mgnav_style()
102 {
103 return '<style>' . file_get_contents(__DIR__ . '/css/source.css') . '</style>';
104 }

  ViewVC Help
Powered by ViewVC 1.1.30