Commit 97db8863 authored by M.Nowocyn's avatar M.Nowocyn

Minor changes.

parent f71135ee
This diff is collapsed.
......@@ -6,14 +6,11 @@
* Time: 23:38
*/
namespace Iko\Language;
namespace Iko;
use Iko\Core;
use Iko\Event\Handler;
use Iko\Lib\Multiton\Cache\Mixed;
use Iko\log;
use Iko\User;
use Iko\User\iUser;
use PDO;
......
......@@ -10,6 +10,7 @@
* the LICENSE file.
*
*/
/**
* Created by PhpStorm.
* User: Marcel
......@@ -22,21 +23,23 @@ namespace Iko\Language;
use Iko\Config;
use Iko\Core;
use Iko\iLanguage;
use Iko\Language;
use Iko\Lib\Singleton\Instance;
use Iko\Session;
use Iko\User;
class System extends Instance implements iSystem
{
const DEFAULT = "english";
const TABLE = "{prefix}translation";
const LANG_TABLE = "{prefix}languages";
const LANG_NAME = "language";
const NAME = "translation_key";
const FIXED = array (
"german",
"english" );
protected static $instance = NULL;
const DEFAULT = "english";
const TABLE = "{prefix}translation";
const LANG_TABLE = "{prefix}languages";
const LANG_NAME = "language";
const NAME = "translation_key";
const FIXED = array (
"german",
"english");
protected static $instance = null;
protected static $args = null;
public static function getInstance ($args = null, $reload = false, $property = true): iSystem
......@@ -46,150 +49,155 @@ class System extends Instance implements iSystem
$reload,
$property
);
}
}
private $config = NULL;
private $current = NULL;
private $languages = array ();
private $config = null;
private $current = null;
private $languages = array ();
protected function __construct ($args)
{
if ($args !== NULL && Language::exist($args)) {
if ($args !== null && Language::exist($args)) {
$lang = $args;
}
else {
$lang = null;
if (Session::isLoggedIn()) {
$lang = User::getSession()->getLanguage();
if (isset($_GET['lang']) && Language::exist($_GET['lang'])) {
$lang = htmlspecialchars($_GET['lang']);
}
else {
if (Session::isLoggedIn()) {
$lang = User::getSession()->getLanguage();
}
if ($lang == null || $lang == "") {
$this->config = Config::load(
"pdo",
"language"
);
$lang = $this->config->default_language ?? self::DEFAULT;
}
}
if ($lang == null || $lang == "") {
$this->config = Config::load(
"pdo",
"language"
}
$this->current = Language::get($lang);
$sql = "SHOW COLUMNS FROM " . self::TABLE;
$statement = Core::PDO()->query($sql);
$fetch_all = $statement->fetchAll();
foreach ($fetch_all as $item) {
if ($item["Field"] != self::NAME) {
array_push(
$this->languages,
Language::get($item["Field"])
);
$lang = $this->config->default_language ?? self::DEFAULT;
}
}
$this->current = Language::get( $lang );
$sql = "SHOW COLUMNS FROM " . self::TABLE;
$statement = Core::PDO()->query( $sql );
$fetch_all = $statement->fetchAll();
foreach ( $fetch_all as $item ) {
if ( $item["Field"] != self::NAME ) {
array_push(
$this->languages,
Language::get( $item["Field"] )
);
}
}
}
public function getCurrent (): iLanguage
{
return $this->current;
}
public function isSupportedLanguage ( $lang ): bool
{
if ( !( $lang instanceof iLanguage ) ) {
$lang = Language::get( $lang );
}
if ( array_search(
$lang,
$this->languages
) !== FALSE
) {
return TRUE;
}
else {
return FALSE;
}
}
public function getLanguages (): array
{
return $this->languages;
}
private function change ( string $func, $name ): bool
{
if ( $name instanceof iLanguage ) {
$name = $name->getName();
}
$name = strtolower( $name );
if ( ( $func == "add" && !$this->isSupportedLanguage(
$name
) ) || ( $func == "remove" && $this->isSupportedLanguage( $name ) && array_search(
$name,
self::FIXED,
TRUE
) === FALSE )
) {
if ( User::getSession()->hasPermission( "iko.language." . $func . ".lang" ) ) {
if ( $func == "add" ) {
$sql = "ALTER TABLE " . self::TABLE . " ADD :lang TEXT";
$sql_update = "INSERT INTO " . Language::TABLE . " ( " . Language::NAME . ",status) VALUE(:lang, '" . $this->config->default_status . "')";
}
else {
$sql_update = "DELETE FROM " . Language::TABLE . " WHERE " . Language::NAME . " = :lang";
$sql = "ALTER TABLE " . self::TABLE . " DROP :lang";
}
$statement = Core::PDO()->prepare( $sql );
$statement->bindParam(
":lang",
$name
);
$statement->execute();
if ( $statement > 0 ) {
$statement_update = Core::PDO()->prepare( $sql_update );
$statement_update->bindParam(
":lang",
$name
);
$statement_update->execute();
if ( $statement_update > 0 ) {
if ( $func == "add" ) {
array_push(
$this->languages,
Language::get(
$name,
TRUE
)
);
}
else {
unset(
$this->languages[ array_search(
$name,
$this->languages,
TRUE
) ]
);
}
return TRUE;
}
}
}
}
return FALSE;
}
public function add ( $name ): bool
{
return $this->change(
__FUNCTION__,
$name
);
}
public function remove ( $name ): bool
{
return $this->change(
__FUNCTION__,
$name
);
}
}
public function getCurrent (): iLanguage
{
return $this->current;
}
public function isSupportedLanguage ($lang): bool
{
if (!($lang instanceof iLanguage)) {
$lang = Language::get($lang);
}
if (array_search(
$lang,
$this->languages
) !== false) {
return true;
}
else {
return false;
}
}
public function getLanguages (): array
{
return $this->languages;
}
private function change (string $func, $name): bool
{
if ($name instanceof iLanguage) {
$name = $name->getName();
}
$name = strtolower($name);
if (($func == "add" && !$this->isSupportedLanguage(
$name
)) || ($func == "remove" && $this->isSupportedLanguage($name) && array_search(
$name,
self::FIXED,
true
) === false)) {
if (User::getSession()->hasPermission("iko.language." . $func . ".lang")) {
if ($func == "add") {
$sql = "ALTER TABLE " . self::TABLE . " ADD :lang TEXT";
$sql_update = "INSERT INTO " . Language::TABLE . " ( " . Language::NAME . ",status) VALUE(:lang, '" . $this->config->default_status . "')";
}
else {
$sql_update = "DELETE FROM " . Language::TABLE . " WHERE " . Language::NAME . " = :lang";
$sql = "ALTER TABLE " . self::TABLE . " DROP :lang";
}
$statement = Core::PDO()->prepare($sql);
$statement->bindParam(
":lang",
$name
);
$statement->execute();
if ($statement > 0) {
$statement_update = Core::PDO()->prepare($sql_update);
$statement_update->bindParam(
":lang",
$name
);
$statement_update->execute();
if ($statement_update > 0) {
if ($func == "add") {
array_push(
$this->languages,
Language::get(
$name,
true
)
);
}
else {
unset(
$this->languages[ array_search(
$name,
$this->languages,
true
) ]
);
}
return true;
}
}
}
}
return false;
}
public function add ($name): bool
{
return $this->change(
__FUNCTION__,
$name
);
}
public function remove ($name): bool
{
return $this->change(
__FUNCTION__,
$name
);
}
}
\ No newline at end of file
......@@ -23,7 +23,9 @@ interface iKey
{
public function getKey (): string;
public function getLang ( $lang = "" ): string;
public function getLang ($lang = "", $includeParam = true): string;
public function addParam (string $string);
public function getLangAll (): array;
......
......@@ -6,7 +6,7 @@
* Time: 23:38
*/
namespace Iko\Language;
namespace Iko;
interface iLanguage
......
......@@ -18,15 +18,18 @@
*/
namespace Iko\Language;
use Iko\iLanguage;
interface iSystem
{
public function isSupportedLanguage ( $lang ): bool;
public function isSupportedLanguage ($lang ): bool;
public function getCurrent (): iLanguage;
public function getCurrent (): iLanguage;
public function getLanguages (): array;
public function getLanguages (): array;
public function add ( $name ): bool;
public function add ($name ): bool;
public function remove ( $name ): bool;
public function remove ($name ): bool;
}
\ No newline at end of file
......@@ -15,9 +15,9 @@ namespace Iko\Language;
class Loader extends \Iko\Module\Loader
{
public function __construct ($modul)
{
parent::__construct($modul);
public function __construct ($module)
{
parent::__construct($module);
}
protected function preCheckPDOTables ()
......
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.login.success', 'Login erfolgreich', 'Login success');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('redirect', 'Du wirst in wenigen Sekunden weitergeleitet', 'You will be redirected in a few seconds');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.login.fail', 'Login fehlgeschlagen', 'Login failed');
UPDATE `iko_translation` SET `translation_key` = 'iko.user.login' WHERE (`translation_key` = 'login');
UPDATE `iko_translation` SET `translation_key` = 'iko.user.logout' WHERE (`translation_key` = 'logout');
UPDATE `iko_translation` SET `translation_key` = 'iko.user.password' WHERE (`translation_key` = 'password');
UPDATE `iko_translation` SET `translation_key` = 'iko.user.register.since' WHERE (`translation_key` = 'regist_since');
UPDATE `iko_translation` SET `translation_key` = 'iko.forum.create.thread' WHERE (`translation_key` = 'create_thread');
UPDATE `iko_translation` SET `translation_key` = 'iko.user' WHERE (`translation_key` = 'user');
UPDATE `iko_translation` SET `translation_key` = 'iko.user.list' WHERE (`translation_key` = 'user_list');
UPDATE `iko_translation` SET `translation_key` = 'iko.user.name' WHERE (`translation_key` = 'user_name');
UPDATE `iko_translation` SET `translation_key` = 'iko.user.own.profil' WHERE (`translation_key` = 'user_own_profile');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group', 'Gruppe', 'Group');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.groups', 'Gruppen', 'Groups');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.parent', 'Elterngruppe', 'Parentgroup');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.parents', 'Elterngruppen', 'Parentgroups');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.child', 'Untergruppe', 'Childgroup');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.childs', 'Untergruppen', 'Childgroups');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.permission', 'Berechtigung', 'Permission');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.permissions', 'Berechtigungen', 'Permissions');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('displayname', 'Anzeigename', 'Displayname');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.name.first', 'Vorname', 'Firstname');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.name.last', 'Nachname', 'Lastname');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.name.nick', 'Spitzname', 'Nickname');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.admin.sitename', 'Seitentitel', 'Sitetitle');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.admin.rewriteurl', 'URL Umschreiben', 'Rewrite URL');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('example', 'Beispiel', 'Example');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.own.profil.edit.link', 'Profil bearbeiten', 'Edit profil');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('german', 'Deutsch', 'german');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('english', 'Englisch', 'english');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.register', 'Registrieren', 'regist');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.status', 'Status', 'Status');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.status.online', 'Online', 'Online');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.status.offline', 'Offline', 'Offline');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.post', 'Beitrag', 'Post');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.posts', 'Beiträge', 'Posts');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('success', 'Erfolgreich', 'Success');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('fail', 'Fehler', 'Fail');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('failed', 'Fehlgeschlagen', 'Failed');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.email', 'Email', 'Email');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.password.confirm', 'Bestätige Kennwort', 'Confirm password');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.password.repeat', 'Wiederhole Kennwort', 'Repeat password');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.acp.create', 'Erstelle Benutzer', 'Create User');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.acp.all', 'Alle Benutzer', 'All User');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.acp.create', 'Erstelle Gruppe', 'Create Group');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.acp.all', 'Alle Gruppen', 'All Groups');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.login.last', 'Letzter Login', 'Last login');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.groups.list', 'Gruppenliste', 'Group list');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.member', 'Mitglied', 'Member');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('edit', 'Bearbeiten', 'Edit');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('save', 'Speichern', 'Save');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('create', 'Erstellen', 'Create');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.edit', 'Bearbeite Gruppe', 'Edit Group');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.name', 'Gruppenname', 'Groupname');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('back', 'Zurück', 'Back');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.group.create', 'Erstelle Gruppe', 'Create Group');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.edit', 'Bearbeite Benutzer', 'Edit User');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.password.new', 'Neues Kennwort', 'New Password');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.password.actual', 'Aktuelles Kennwort', 'Actual Password');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.register.failed.general', 'Ein Fehler ist aufgetreten. Bitte wenden Sie sich an den Administrator.', 'An error has occurred. Please contact an Administrator.');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.register.failed.exists', 'Es existiert bereits ein Benutzer mit dem Benutzernamen bzw. der Email.', 'An User already exists with this Username or rather with this Mail.');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.register.failed.event', 'Ihre Registrierung wurde durch eine Erweiterung abgelehnt.', 'Your registration was rejected by an extension.');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES ('iko.user.register.failed.sql', 'Ein Fehler in der Datenbank ist aufgetreten. Bitte wenden Sie sich an den Administrator.', 'An error in the database has occurred. Please contact an Administrator.');
INSERT INTO `iko_translation` (`translation_key`, `german`, `english`) VALUES
('create_thread', 'Thread erstellen', 'Create thread'),
('home', 'Home', 'Home'),
('iko.user.activation', 'Benutzer Aktivierung', 'User activation'),
('login', 'Anmelden', 'Login'),
('logout', 'Abmelden', 'Logout'),
('password', 'Kennwort', 'password'),
('regist_since', 'Registriert seit:', 'Registered since:'),
('reply', 'Antworten', 'Reply'),
('user', 'Benutzer', 'User'),
('user_list', 'Benutzerliste', 'User list'),
('user_name', 'Benutzername', 'username'),
('user_own_profile', 'Eigenes Benutzerprofil', 'Own User profile');
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment