mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Template/Update (Part 10)
* convert language switcher
This commit is contained in:
27
endpoints/locale/locale.php
Normal file
27
endpoints/locale/locale.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Aowow;
|
||||||
|
|
||||||
|
if (!defined('AOWOW_REVISION'))
|
||||||
|
die('illegal access');
|
||||||
|
|
||||||
|
|
||||||
|
class LocaleBaseResponse extends TextResponse
|
||||||
|
{
|
||||||
|
protected array $expectedGET = array(
|
||||||
|
'locale' => ['filter' => FILTER_CALLBACK, 'options' => [Locale::class, 'tryFrom']]
|
||||||
|
);
|
||||||
|
|
||||||
|
protected function generate() : void
|
||||||
|
{
|
||||||
|
if ($this->_get['locale']?->validate())
|
||||||
|
{
|
||||||
|
User::$preferedLoc = $this->_get['locale'];
|
||||||
|
User::save(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->redirectTo = $_SERVER['HTTP_REFERER'] ?? '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Aowow;
|
|
||||||
|
|
||||||
if (!defined('AOWOW_REVISION'))
|
|
||||||
die('illegal access');
|
|
||||||
|
|
||||||
class AjaxLocale extends AjaxHandler
|
|
||||||
{
|
|
||||||
protected $_get = array(
|
|
||||||
'locale' => ['filter' => FILTER_CALLBACK, 'options' => 'Aowow\Locale::tryFrom']
|
|
||||||
);
|
|
||||||
|
|
||||||
public function __construct(array $params)
|
|
||||||
{
|
|
||||||
parent::__construct($params);
|
|
||||||
|
|
||||||
// always this one
|
|
||||||
$this->handler = 'handleLocale';
|
|
||||||
$this->doRedirect = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* responses
|
|
||||||
header()
|
|
||||||
*/
|
|
||||||
protected function handleLocale() : string
|
|
||||||
{
|
|
||||||
if ($this->_get['locale']?->validate())
|
|
||||||
{
|
|
||||||
User::$preferedLoc = $this->_get['locale'];
|
|
||||||
User::save(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
Reference in New Issue
Block a user