OLD | NEW |
1 <?php | 1 <?php |
2 | 2 |
3 class AnwTemplateOverride_contentclass_menu extends AnwTemplateDefault_contentcl
ass_menu | 3 class AnwTemplateOverride_contentclass_menu extends AnwTemplateDefault_contentcl
ass_menu |
4 { | 4 { |
5 private $firstItem; | 5 private $firstItem; |
6 | 6 |
7 function openMenu() | 7 function openMenu() |
8 { | 8 { |
9 $this->firstItem = true; | 9 $this->firstItem = true; |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 <input id="search-field" name="q" type="search" /> | 27 <input id="search-field" name="q" type="search" /> |
28 <label id="search-field-label-button" for="search-field"> | 28 <label id="search-field-label-button" for="search-field"> |
29 <button id="search-button" type="submit">$sTitle</button> | 29 <button id="search-button" type="submit">$sTitle</button> |
30 </label> | 30 </label> |
31 </form> | 31 </form> |
32 </li> | 32 </li> |
33 EOF; | 33 EOF; |
34 return $HTML; | 34 return $HTML; |
35 } | 35 } |
36 | 36 |
| 37 function renderLanguages() |
| 38 { |
| 39 $languages = $this->getLanguages($aoTranslations); |
| 40 if (count($languages) == 0) |
| 41 return ""; |
| 42 |
| 43 $currentLanguage = array_shift($languages); |
| 44 $currentLang = $currentLanguage['lang']; |
| 45 $currentText = $currentLanguage['text']; |
| 46 |
| 47 $HTML = <<<EOF |
| 48 |
| 49 <li id="language"> |
| 50 <div id="current-language"> |
| 51 <div id="flag-$currentLang" class="flag sprite"></div><span>$currentText</sp
an> |
| 52 <span id="language-arrow" class="sprite"></span> |
| 53 </div> |
| 54 <ul id="language-selector"> |
| 55 EOF; |
| 56 |
| 57 foreach ($languages as $language) |
| 58 { |
| 59 $url = $language['url']; |
| 60 $linkStyle = $language['linkStyle']; |
| 61 $lang = $language['lang']; |
| 62 $text = $language['text']; |
| 63 |
| 64 # Note: The space before URL is required because otherwise Anwiki will |
| 65 # automatically replace the URL based on current language. |
| 66 $HTML .= <<<EOF |
| 67 |
| 68 <li class="language-entry"><a href=" $url"$linkStyle><div id="flag-$lang" cl
ass="flag sprite"></div>$text</a></li> |
| 69 EOF; |
| 70 } |
| 71 |
| 72 $HTML .= <<<EOF |
| 73 |
| 74 </ul> |
| 75 </li> |
| 76 EOF; |
| 77 return $HTML; |
| 78 } |
| 79 |
| 80 private function getLanguages() |
| 81 { |
| 82 $languages = array(); |
| 83 |
| 84 $currentPageName = AnwActionPage::getCurrentPageName(); |
| 85 if (!AnwPage::isValidPageName($currentPageName)) |
| 86 return $languages; |
| 87 |
| 88 $currentPage = new AnwPageByName($currentPageName); |
| 89 if (!$currentPage->exists()) |
| 90 return $languages; |
| 91 |
| 92 $pages = $currentPage->getPageGroup()->getPages(); |
| 93 $translationThreshold = AnwComponent::globalCfgViewUntranslatedMinpercent(); |
| 94 foreach ($pages as $page) |
| 95 { |
| 96 if ($page->isActionAllowed('view')) |
| 97 { |
| 98 $current = ($page->getName() == $currentPageName); |
| 99 $online = ($page->getTranslatedPercent() >= $translationThreshold); |
| 100 $linkStyle = ($online ? '' : ' style="text-decoration:line-through;"'); |
| 101 $lang = $this->xQuote($page->getLang()); |
| 102 $text = $this->xText(self::g_('lang_' . $lang, array(), |
| 103 AnwAction::getActionLang())); |
| 104 $entry = array("lang" => $lang, "linkStyle" => $linkStyle, |
| 105 "text" => $text); |
| 106 if ($current) |
| 107 array_unshift($languages, $entry); |
| 108 else |
| 109 { |
| 110 $params = $_GET; |
| 111 unset($params[AnwActionPage::GET_PAGENAME]); //avoid loop |
| 112 unset($params['browser']); |
| 113 $url = AnwUtils::link($page, "view", $params); |
| 114 $entry['url'] = $this->xQuote($url); |
| 115 array_push($languages, $entry); |
| 116 } |
| 117 } |
| 118 } |
| 119 |
| 120 return $languages; |
| 121 } |
| 122 |
37 function mainItem($sTitle, $sUrl, $sTarget, $sRenderedSubItems=false) | 123 function mainItem($sTitle, $sUrl, $sTarget, $sRenderedSubItems=false) |
38 { | 124 { |
39 if ($this->firstItem) | 125 if ($this->firstItem) |
40 { | 126 { |
41 $classAttribute = ' class="first"'; | 127 $classAttribute = ' class="first"'; |
42 $this->firstItem = false; | 128 $this->firstItem = false; |
43 } | 129 } |
44 else | 130 else |
45 $classAttribute = ''; | 131 $classAttribute = ''; |
46 | 132 |
47 if ($sUrl == "/search/") | 133 if ($sUrl == "/search/") |
48 return $this->renderSearch($sTitle, $classAttribute); | 134 return $this->renderSearch($sTitle, $classAttribute); |
| 135 else if ($sUrl == "/languages/") |
| 136 return $this->renderLanguages(); |
49 | 137 |
50 # Anything with a link relative to site root must be in English | 138 # Anything with a link relative to site root must be in English |
51 $sHrefLang = (preg_match('!^/!', $sUrl) ? ' hreflang="en"' : ''); | 139 $sHrefLang = (preg_match('!^/!', $sUrl) ? ' hreflang="en"' : ''); |
52 | 140 |
53 $HTML = <<<EOF | 141 $HTML = <<<EOF |
54 | 142 |
55 <li$classAttribute><a href="$sUrl"$sHrefLang>$sTitle</a></li> | 143 <li$classAttribute><a href="$sUrl"$sHrefLang>$sTitle</a></li> |
56 EOF; | 144 EOF; |
57 | 145 |
58 return $HTML; | 146 return $HTML; |
(...skipping 23 matching lines...) Expand all Loading... |
82 function closeMenu() | 170 function closeMenu() |
83 { | 171 { |
84 $HTML = <<<EOF | 172 $HTML = <<<EOF |
85 </ul> | 173 </ul> |
86 EOF; | 174 EOF; |
87 return $HTML; | 175 return $HTML; |
88 } | 176 } |
89 } | 177 } |
90 | 178 |
91 ?> | 179 ?> |
OLD | NEW |