!/usr/bin/php
<?php
/**
* This file is part of the Pollux.casa cockpit
*
* Source is available here: https://codeberg.org/pollux.casa/cockpit
*
* @license GNU/AGPLv3 https://www.gnu.org/licenses/agpl-3.0.html
* see joined LICENSE file
*
* @author Adële <gemini://adele.work/>
*
**/
require_once('config.php');
require_once('phpgmi/phpgmi.inc.php');
class member_index extends phpgmiPage
{
// array of User Info
private $UserInfo;
private $favicon;
private $badtz = false;
function init()
{
// Ensure user is browsing with a known certificate
$this->requireAuth();
// load known UserInfo parameters
$this->UserInfo = $this->getWorkingData("UserInfo");
// default value
if(!isset($this->UserInfo['lang']))
$this->UserInfo['lang'] = '';
if(!isset($this->UserInfo['country']))
$this->UserInfo['country'] = '';
if(!isset($this->UserInfo['timezone']))
$this->UserInfo['timezone'] = 'UTC';
$this->favicon = mb_substr(@file_get_contents($this->getCapsulePath().'/favicon.txt'),0,1);
if(empty($this->favicon))
$this->favicon = "🚀";
}
// manage actions
function actionDone($action, $name, $value, $parameters)
{
// Update UserInfo
if($action=='input' && $name=='lang')
$this->UserInfo[$name] = trim($value);
if($action=='input' && $name=='country')
$this->UserInfo[$name] = trim($value);
if($action=='input' && $name=='timezone')
{
if(in_array($value, timezone_identifiers_list()))
$this->UserInfo[$name] = trim($value);
else
$this->badtz = true;
}
if($action=='input' && $name=='favicon')
$this->favicon = mb_substr(trim($value),0,1);
}
// Build page
function build()
{
$this->add("# Hello ".$this->getUser());
$this->addLinkRequestInput('favicon', "Change your favicon emoji: ".$this->favicon);
$this->addLinkRequestInput('timezone', "Change your timezone: ".$this->UserInfo['timezone']);
$this->addLink("tinylog/", "Manage your Tinylog");
if($this->badtz)
{
$this->add("");
$this->add("## Timezone must be in this list :");
foreach(timezone_identifiers_list() as $tz)
$this->add("* ".$tz);
}
}
// Save data
function save()
{
if(!empty($this->getUser()))
{
$this->saveWorkingData('UserInfo', $this->UserInfo);
@file_put_contents($this->getCapsulePath().'/favicon.txt', $this->favicon);
}
}
}
$page = new member_index();