Add template doc, fixup rendering locale select

This commit is contained in:
Vojtěch Sajdl 2018-01-07 20:43:04 +01:00
parent 61f563c9b0
commit 5dd9a2a1bd
No known key found for this signature in database
GPG Key ID: 5D4EB1361A272390
3 changed files with 65 additions and 50 deletions

View File

@ -14,12 +14,13 @@ class LocaleNegotiator
*/
function __construct($default_language)
{
$tmp = glob(__DIR__ . '/locale/*' , GLOB_ONLYDIR);
$tmp = glob(__DIR__ . '/../locale/*' , GLOB_ONLYDIR);
$this->default_language = $default_language;
//Works only if the server supports the locale
//This basically means $accepted_langs[<lang_code>] = "<lang name>";
foreach ($accepted_langs as $key => $value) {
$this->accepted_langs[basename($value)] = self::mb_ucfirst(locale_get_display_language($lang, $lang));
foreach ($tmp as $key => $value) {
$lang = basename($value);
$this->accepted_langs[$lang] = self::mb_ucfirst(locale_get_display_language($lang, $lang));
}
}

View File

@ -11,10 +11,11 @@ define("DEFAULT_LANGUAGE", "en_GB");
require("classes/locale-negotiator.php");
$negotiator = new LocaleNegotiator(DEFAULT_LANGUAGE);
if (!isset($_SESSION['locale'])||isset($_GET['lang']))
{
$override = ((isset($_GET['lang']))?$_GET['lang']:null);
$negotiator = new LocaleNegotiator(DEFAULT_LANGUAGE);
$best_match = $negotiator->negotiate($override);
$_SESSION['locale'] = $best_match;
setlocale(LC_ALL, $_SESSION['locale'].".UTF-8");

View File

@ -1,5 +1,13 @@
<?php
class Template(){
/**
* Class that encapsulates methods to render header and footer
*/
class Template{
/**
* Renders header
* @param String $page_name name of the page to be displayed as title
* @param Boolean $admin decides whether to show admin menu
*/
public static function render_header($page_name, $admin = false){
if (!$admin)
{
@ -73,52 +81,57 @@ class Template(){
</div>
</div>
<div id="wrapper" class="center admin">
<?php
}
}
<?php
}
}
public static function render_footer($admin = false)
{
global $lang_names;
?>
</div>
<div id="footerwrap">
<div class="container">
<div class="row centered">
<div class="col-md-4 text-left">Copyright © <?php echo date("Y");?> Vojtěch Sajdl</div>
<div class="col-md-4 text-center">
<div class="btn-group dropup">
<button type="button" class="btn btn-primary"><?php echo '<img src="'.WEB_URL.'/locale/'.$_SESSION['locale'].'/flag.png" alt="'.$lang_names[$_SESSION['locale']].'">'.$lang_names[$_SESSION['locale']];?></button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only"><?php echo _("Toggle Dropdown");?></span>
</button>
<ul class="dropdown-menu">
<?php
foreach ($lang_names as $key => $value) {
echo '<a href="?lang='.$key.'"><img src="'.WEB_URL.'/locale/'.$key.'/flag.png" alt="'.$value.'">'.$value.'</a>';
}
?>
<hr role="separator" class="divider">
<a href="https://poeditor.com/join/project/37SpmJtyOm"><?php echo _("Help with translation!");?></a>
</ul>
</div>
/**
* Renders footer
* @param Boolean $admin decides whether to load admin scripts
*/
public static function render_footer($admin = false)
{
global $negotiator;
$lang_names = $negotiator->get_accepted_langs();
?>
</div>
<div id="footerwrap">
<div class="container">
<div class="row centered">
<div class="col-md-4 text-left">Copyright © <?php echo date("Y");?> Vojtěch Sajdl</div>
<div class="col-md-4 text-center">
<div class="btn-group dropup">
<button type="button" class="btn btn-primary"><?php echo '<img src="'.WEB_URL.'/locale/'.$_SESSION['locale'].'/flag.png" alt="'.$lang_names[$_SESSION['locale']].'">'.$lang_names[$_SESSION['locale']];?></button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only"><?php echo _("Toggle Dropdown");?></span>
</button>
<ul class="dropdown-menu">
<?php
foreach ($lang_names as $key => $value) {
echo '<a href="?lang='.$key.'"><img src="'.WEB_URL.'/locale/'.$key.'/flag.png" alt="'.$value.'">'.$value.'</a>';
}
?>
<hr role="separator" class="divider">
<a href="https://poeditor.com/join/project/37SpmJtyOm"><?php echo _("Help with translation!");?></a>
</ul>
</div>
<div class="col-md-4 text-right"><a href="https://github.com/Pryx/server-status/" target="_blank"><i class="fa fa-github" aria-hidden="true"></i></a></div>
</div><!--/row -->
</div><!--/container -->
</div>
<script src="/js/vendor/jquery-1.11.2.min.js"></script>
<script src="/js/vendor/jquery.timeago.js"></script>
<?php if ($admin){?>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script src="/js/admin.js"></script>
<script src="/js/vendor/jquery.growl.js"></script>
<? }?>
<script src="/js/vendor/bootstrap.min.js"></script>
<script src="/js/main.js"></script>
</body>
</html>
<?
</div>
<div class="col-md-4 text-right"><a href="https://github.com/Pryx/server-status/" target="_blank"><i class="fa fa-github" aria-hidden="true"></i></a></div>
</div><!--/row -->
</div><!--/container -->
</div>
<script src="/js/vendor/jquery-1.11.2.min.js"></script>
<script src="/js/vendor/jquery.timeago.js"></script>
<?php if ($admin){?>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script src="/js/admin.js"></script>
<script src="/js/vendor/jquery.growl.js"></script>
<? }?>
<script src="/js/vendor/bootstrap.min.js"></script>
<script src="/js/main.js"></script>
</body>
</html>
<?
}
}