Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: anwiki/_override/contentclasses/contentclass_menu/contentclass_menu.tpl.php

Issue 9148089: Less hacky implementation of the language selection (Closed)
Patch Set: Created Jan. 9, 2013, 1:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 $pages = $currentPage->getPageGroup()->getPages();
90 $translationThreshold = AnwComponent::globalCfgViewUntranslatedMinpercent();
91 foreach ($pages as $page)
92 {
93 if ($page->isActionAllowed('view'))
94 {
95 $current = ($page->getName() == $currentPageName);
96 $online = ($page->getTranslatedPercent() >= $translationThreshold);
97 $linkStyle = ($online ? '' : ' style="text-decoration:line-through;"');
98 $lang = $this->xQuote($page->getLang());
99 $text = $this->xText(self::g_('lang_' . $lang, array(),
100 AnwAction::getActionLang()));
101 $entry = array("lang" => $lang, "linkStyle" => $linkStyle,
102 "text" => $text);
103 if ($current)
104 array_unshift($languages, $entry);
105 else
106 {
107 $params = $_GET;
108 unset($params[AnwActionPage::GET_PAGENAME]); //avoid loop
109 unset($params['browser']);
110 $url = AnwUtils::link($page, "view", $params);
111 $entry['url'] = $this->xQuote($url);
112 array_push($languages, $entry);
113 }
114 }
115 }
116
117 return $languages;
118 }
119
37 function mainItem($sTitle, $sUrl, $sTarget, $sRenderedSubItems=false) 120 function mainItem($sTitle, $sUrl, $sTarget, $sRenderedSubItems=false)
38 { 121 {
39 if ($this->firstItem) 122 if ($this->firstItem)
40 { 123 {
41 $classAttribute = ' class="first"'; 124 $classAttribute = ' class="first"';
42 $this->firstItem = false; 125 $this->firstItem = false;
43 } 126 }
44 else 127 else
45 $classAttribute = ''; 128 $classAttribute = '';
46 129
47 if ($sUrl == "/search/") 130 if ($sUrl == "/search/")
48 return $this->renderSearch($sTitle, $classAttribute); 131 return $this->renderSearch($sTitle, $classAttribute);
132 else if ($sUrl == "/languages/")
133 return $this->renderLanguages();
49 134
50 # Anything with a link relative to site root must be in English 135 # Anything with a link relative to site root must be in English
51 $sHrefLang = (preg_match('!^/!', $sUrl) ? ' hreflang="en"' : ''); 136 $sHrefLang = (preg_match('!^/!', $sUrl) ? ' hreflang="en"' : '');
52 137
53 $HTML = <<<EOF 138 $HTML = <<<EOF
54 139
55 <li$classAttribute><a href="$sUrl"$sHrefLang>$sTitle</a></li> 140 <li$classAttribute><a href="$sUrl"$sHrefLang>$sTitle</a></li>
56 EOF; 141 EOF;
57 142
58 return $HTML; 143 return $HTML;
(...skipping 23 matching lines...) Expand all
82 function closeMenu() 167 function closeMenu()
83 { 168 {
84 $HTML = <<<EOF 169 $HTML = <<<EOF
85 </ul> 170 </ul>
86 EOF; 171 EOF;
87 return $HTML; 172 return $HTML;
88 } 173 }
89 } 174 }
90 175
91 ?> 176 ?>
OLDNEW

Powered by Google App Engine
This is Rietveld