new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Filesystem;
|
||||
|
||||
class Delete extends MLExtends
|
||||
{
|
||||
/**
|
||||
* Delete langauge key
|
||||
*
|
||||
* @param string $app
|
||||
* @param mixed $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function do(string $app, $key) : bool
|
||||
{
|
||||
$datas = [];
|
||||
|
||||
$createFile = $this->_langFile($app);
|
||||
|
||||
if( is_file($createFile) )
|
||||
{
|
||||
$datas = json_decode(file_get_contents($createFile), true);
|
||||
}
|
||||
|
||||
if( ! empty($datas) )
|
||||
{
|
||||
$json = $datas;
|
||||
}
|
||||
|
||||
if( ! is_array($key) )
|
||||
{
|
||||
unset($json[$key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($key as $v)
|
||||
{
|
||||
unset($json[$v]);
|
||||
}
|
||||
}
|
||||
|
||||
Properties::$select = NULL;
|
||||
|
||||
return file_put_contents($createFile, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all langauges keys
|
||||
*
|
||||
* @param string $app
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function all($app = NULL) : bool
|
||||
{
|
||||
Properties::$select = NULL;
|
||||
|
||||
if( ! is_string($app) )
|
||||
{
|
||||
if( $app === NULL )
|
||||
{
|
||||
$MLFiles = Filesystem::getFiles($this->appdir, 'ml');
|
||||
}
|
||||
elseif( is_array($app) )
|
||||
{
|
||||
$MLFiles = $app;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$allMLFiles = [];
|
||||
|
||||
if( ! empty($MLFiles) ) foreach( $MLFiles as $file )
|
||||
{
|
||||
$removeExtension = str_replace($this->extension ?? '', '', $file);
|
||||
$this->all($removeExtension);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$createFile = $this->_langFile($app);
|
||||
|
||||
if( is_file($createFile) )
|
||||
{
|
||||
return unlink($createFile);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Lang;
|
||||
use ZN\Hypertext;
|
||||
use ZN\Singleton;
|
||||
use ZN\Request\URI;
|
||||
use ZN\Request\Method;
|
||||
|
||||
class Grid extends MLExtends
|
||||
{
|
||||
/**
|
||||
* Keeps limit
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $limit = 10;
|
||||
|
||||
/**
|
||||
* Keeps url
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = NULL;
|
||||
|
||||
/**
|
||||
* Keeps lang
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $getLang;
|
||||
|
||||
/**
|
||||
* Magic Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->getLang = Lang::default('ZN\Language\GridDefaultLanguage')
|
||||
::select('ViewObjects:mlgrid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set URL
|
||||
*
|
||||
* @param string $url = NULL
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
public function url(?string $url = NULL)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Limit
|
||||
*
|
||||
* @param int $limit = NULL
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
public function limit(?int $limit = NULL)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates table
|
||||
*
|
||||
* @param mixed $app = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function create($app = NULL) : string
|
||||
{
|
||||
$searchWord = '';
|
||||
|
||||
if( Method::post() )
|
||||
{
|
||||
$keyword = Method::post('ML_UPDATE_KEYWORD_HIDDEN');
|
||||
$languages = explode(',', Method::post('ML_LANGUAGES'));
|
||||
$words = Method::post('ML_UPDATE_WORDS');
|
||||
|
||||
// SEARCH
|
||||
if( Method::post('ML_SEARCH_SUBMIT') )
|
||||
{
|
||||
$searchWord = Method::post('ML_SEARCH');
|
||||
}
|
||||
|
||||
// ADD LANGUAGE
|
||||
if( Method::post('ML_ADD_ALL_LANGUAGE_SUBMIT') )
|
||||
{
|
||||
(new Insert)->do(Method::post('ML_ADD_LANGUAGE'), 'example', 'Example');
|
||||
}
|
||||
|
||||
// ALL DELETE
|
||||
if( Method::post('ML_ALL_DELETE_SUBMIT') )
|
||||
{
|
||||
$allDelete = Method::post('ML_ALL_DELETE_HIDDEN');
|
||||
(new Delete)->all($allDelete);
|
||||
}
|
||||
|
||||
// ADD
|
||||
if( Method::post('ML_ADD_KEYWORD_SUBMIT') )
|
||||
{
|
||||
$addWords = Method::post('ML_ADD_WORDS');
|
||||
$addKeyword = Method::post('ML_ADD_KEYWORD');
|
||||
|
||||
if( is_numeric($addKeyword) )
|
||||
{
|
||||
$addKeyword = 'Wrong Keyword! Only String.';
|
||||
}
|
||||
|
||||
if( ! empty($languages) ) foreach( $languages as $key => $lang )
|
||||
{
|
||||
(new Insert)->do($lang, $addKeyword, $addWords[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
if( Method::post('ML_UPDATE_KEYWORD_SUBMIT') )
|
||||
{
|
||||
if( ! empty($languages) ) foreach( $languages as $key => $lang )
|
||||
{
|
||||
(new Update)->do($lang, $keyword, $words[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE
|
||||
if( Method::post('ML_DELETE_SUBMIT') )
|
||||
{
|
||||
if( ! empty($languages) ) foreach( $languages as $key => $lang )
|
||||
{
|
||||
(new Delete)->do($lang, $keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$config = $this->gridConfig;
|
||||
|
||||
$attributes = $config['attributes'];
|
||||
$pagcon = $config['pagination'];
|
||||
$title = $this->getLang['ml:titleLabel'];
|
||||
$confirmMessage = $this->getLang['ml:confirmLabel'];
|
||||
$process = $this->getLang['ml:processLabel'];
|
||||
$keywords = $this->getLang['ml:keywordsLabel'];
|
||||
|
||||
$confirmBox = ' onsubmit="return confirm(\''.$confirmMessage.'\');"';
|
||||
|
||||
$data = (new Select)->all($app);
|
||||
|
||||
$languageCount = count($data);
|
||||
|
||||
$formClass = Singleton::class('ZN\Hypertext\Form');
|
||||
|
||||
$table = $this->_styleElement();
|
||||
$table .= '<table id="ML_TABLE"'.Hypertext::attributes($attributes['table']).'>';
|
||||
$table .= '<thead>';
|
||||
$table .= '<tr><th colspan="'.($languageCount + 4).'">'.$title.'</th></tr>';
|
||||
$table .= '<tr><th>S/L</th>';
|
||||
$table .= '<td colspan="'.($languageCount + 3).'">';
|
||||
$table .= '<form name="ML_SEARCH_ADD_LANGUAGE_FORM" method="post">';
|
||||
$table .= $formClass->attr($attributes['textbox'])->placeholder($this->getLang['ml:searchPlaceHolder'])->text('ML_SEARCH');
|
||||
$table .= $formClass->attr($attributes['add'])->submit('ML_SEARCH_SUBMIT', $this->getLang['ml:searchButton']);
|
||||
$table .= $formClass->attr($attributes['textbox'])->placeholder($this->getLang['ml:addLanguagePlaceHolder'])->text('ML_ADD_LANGUAGE');
|
||||
$table .= $formClass->attr($attributes['add'])->submit('ML_ADD_ALL_LANGUAGE_SUBMIT', $this->getLang['ml:addButton']).'</td>';
|
||||
$table .= '</form>';
|
||||
$table .= '</tr>';
|
||||
$table .= '<tr><th>#</th><td><strong>'.$keywords.'</strong></td>';
|
||||
|
||||
$words = [];
|
||||
$formObjects = '';
|
||||
|
||||
$languages = implode(',', $arrayKeys = array_keys($data));
|
||||
$mlLanguages = (string) $formClass->hidden('ML_LANGUAGES', $languages);
|
||||
|
||||
foreach( $data as $lang => $values )
|
||||
{
|
||||
$upperLang = strtoupper($lang);
|
||||
|
||||
$table .= '<form name="ML_TOP_FORM_'.$upperLang.'" method="post"'.$confirmBox.'>';
|
||||
$table .= '<td><strong>'.$upperLang.$formClass->hidden('ML_ALL_DELETE_HIDDEN', $lang).$formClass->attr($attributes['delete'])->submit('ML_ALL_DELETE_SUBMIT', $this->getLang['ml:deleteButton']).'</strong></td>';
|
||||
$table .= '</form>';
|
||||
|
||||
foreach( $values as $key => $val )
|
||||
{
|
||||
$words[$key][$lang] = $val;
|
||||
}
|
||||
|
||||
$formObjects .= '<td>'.$formClass->attr($attributes['textbox'])->placeholder($upperLang)->text('ML_ADD_WORDS[]').'</td>';
|
||||
}
|
||||
|
||||
$table .= '<td><strong>'.$process.'</strong></td>';
|
||||
$table .= '</tr>';
|
||||
$table .= '</thead>';
|
||||
$table .= '<tbody>';
|
||||
$table .= '<tr>';
|
||||
$table .= '<form name="ML_TOP_FORM" method="post">';
|
||||
$table .= '<th>N</th>';
|
||||
$table .= '<td>'.$mlLanguages.$formClass->attr($attributes['textbox'])->placeholder($this->getLang['ml:keywordPlaceHolder'])->text('ML_ADD_KEYWORD').'</td>';
|
||||
$table .= $formObjects;
|
||||
$table .= '<td>'.$formClass->attr($attributes['add'])->submit('ML_ADD_KEYWORD_SUBMIT', $this->getLang['ml:addButton']).' '.$formClass->attr($attributes['clear'])->reset('ML_ADD_KEYWORD_RESET', $this->getLang['ml:clearButton']).'</td>';
|
||||
$table .= '</form>';
|
||||
$table .= '</tr>';
|
||||
|
||||
$limit = $this->limit;
|
||||
$start = (int) URI::segment(-1);
|
||||
$totalRows = count($words);
|
||||
$index = 1;
|
||||
|
||||
if( ! empty($searchWord) )
|
||||
{
|
||||
$newWords = [];
|
||||
|
||||
foreach( $words as $key => $val )
|
||||
{
|
||||
if( stristr($key, $searchWord) )
|
||||
{
|
||||
$newWords[$key] = $val; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
$newValues = [];
|
||||
|
||||
foreach( $val as $k => $v )
|
||||
{
|
||||
if( stristr($v, $searchWord) )
|
||||
{
|
||||
$newValues = array_merge($newValues, $val); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty($newValues) )
|
||||
{
|
||||
$newWords[$key] = $newValues; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$words = $newWords;
|
||||
}
|
||||
|
||||
if( empty($searchWord) )
|
||||
{
|
||||
$words = array_slice($words, $start, $limit);
|
||||
}
|
||||
|
||||
foreach( $words as $key => $val )
|
||||
{
|
||||
$table .= '<tr>';
|
||||
$table .= '<form name="ML_'.strtoupper($key).'_FORM" method="post"'.$confirmBox.'>';
|
||||
$table .= '<th>'.$index++.'</th>';
|
||||
$table .= '<td>'.$formClass->hidden('ML_UPDATE_KEYWORD_HIDDEN', $key).$key.'</td>';
|
||||
|
||||
foreach( $arrayKeys as $i )
|
||||
{
|
||||
$table .= '<td>'.$formClass->attr($attributes['textbox'])->text('ML_UPDATE_WORDS[]', ( ! empty($val[$i]) ? $val[$i] : '' )).'</td>';
|
||||
}
|
||||
|
||||
$table .= '<td>'.$mlLanguages.$formClass->attr($attributes['update'])->submit('ML_UPDATE_KEYWORD_SUBMIT', $this->getLang['ml:updateButton']);
|
||||
$table .= ' ';
|
||||
$table .= $formClass->attr($attributes['delete'])->submit('ML_DELETE_SUBMIT', $this->getLang['ml:deleteButton']).'</td>';
|
||||
$table .= '</form>';
|
||||
$table .= '</tr>';
|
||||
}
|
||||
|
||||
if( empty($this->url) )
|
||||
{
|
||||
$paginationUrl = CURRENT_CFPATH;
|
||||
}
|
||||
else
|
||||
{
|
||||
$paginationUrl = $this->url;
|
||||
}
|
||||
|
||||
if( empty($searchWord) )
|
||||
{
|
||||
$pagination = Singleton::class('ZN\Pagination\Paginator')
|
||||
->style($pagcon['style'])
|
||||
->css($pagcon['class'])
|
||||
->start($start)
|
||||
->totalRows($totalRows)
|
||||
->limit($limit)
|
||||
->url($paginationUrl)
|
||||
->create();
|
||||
}
|
||||
else
|
||||
{
|
||||
$pagination = NULL;
|
||||
}
|
||||
|
||||
if( ! empty($pagination) && ! empty($totalRows) )
|
||||
{
|
||||
$table .= '<tr><th>P</th><td colspan="'.($languageCount + 3).'">'.$pagination.'</td></tr>'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$table .= '</tbody>';
|
||||
$table .= '</table>';
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Style Element
|
||||
*/
|
||||
protected function _styleElement()
|
||||
{
|
||||
$styleElementConfig = $this->gridConfig['styleElement'] ?? NULL;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if( ! empty($styleElementConfig) )
|
||||
{
|
||||
$attributes = '';
|
||||
|
||||
$sheet = Singleton::class('ZN\Hypertext\Sheet');
|
||||
$style = Singleton::class('ZN\Hypertext\Style');
|
||||
|
||||
foreach( $styleElementConfig as $selector => $attr )
|
||||
{
|
||||
$attributes .= $sheet->selector($selector)->attr($attr)->create();
|
||||
}
|
||||
|
||||
return $style->open().$attributes.$style->close();
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default Configuration
|
||||
*
|
||||
* Enabled when the configuration file can not be accessed.
|
||||
*/
|
||||
class GridDefaultConfiguration
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ML Grid
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| It edits the table created by the ML::table() method.
|
||||
|
|
||||
| styleElement: Used to give built-in style to the table.
|
||||
| attributes : Used to add attributes to objects in the table.
|
||||
| pagination : It arranges the pagination bar on the table.
|
||||
|
|
||||
*/
|
||||
|
||||
public $styleElement =
|
||||
[
|
||||
#'#ML_TABLE tr:nth-child(even)' => ['background' => '#E6F9FF'],
|
||||
#'#ML_TABLE tr:nth-child(odd)' => ['background' => '#FFF']
|
||||
];
|
||||
|
||||
public $attributes =
|
||||
[
|
||||
'table' => ['class' => 'table table-bordered table-hover table-striped'],
|
||||
'add' => ['style' => 'height:30px; color:#0085B2; background:none; border:solid 1px #ccc; cursor:pointer; border-radius:4px'],
|
||||
'update' => ['style' => 'height:30px; color:#0085B2; background:none; border:solid 1px #ccc; cursor:pointer; border-radius:4px'],
|
||||
'delete' => ['style' => 'height:30px; color:#0085B2; background:none; border:solid 1px #ccc; cursor:pointer; border-radius:4px'],
|
||||
'clear' => ['style' => 'height:30px; color:#0085B2; background:none; border:solid 1px #ccc; cursor:pointer; border-radius:4px'],
|
||||
'textbox' => ['style' => 'height:30px; color:#0085B2; border:solid 1px #ccc; text-indent:10px; border-radius:4px']
|
||||
];
|
||||
|
||||
public $pagination =
|
||||
[
|
||||
'style' =>
|
||||
[
|
||||
'links' => 'color:#0085B2; width:30px; height:30px; text-align:center; padding-top:4px;
|
||||
display:inline-block; background:white; border:solid 1px #ddd; border-radius: 4px;
|
||||
-webkit-border-radius: 4px; -moz-border-radius: 4px;text-decoration:none;',
|
||||
|
||||
'current' => 'font-weight:bold;'
|
||||
],
|
||||
'class' => []
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default Configuration
|
||||
*
|
||||
* Enabled when the language file can not be accessed.
|
||||
*/
|
||||
class GridDefaultLanguage
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ML
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The language of the ML library.
|
||||
|
|
||||
*/
|
||||
|
||||
public $en =
|
||||
[
|
||||
'ml:addButton' => 'New Add',
|
||||
'ml:updateButton' => 'Update',
|
||||
'ml:deleteButton' => 'Delete',
|
||||
'ml:clearButton' => 'Clear',
|
||||
'ml:searchButton' => 'Search',
|
||||
'ml:titleLabel' => 'Multi Language Data Table',
|
||||
'ml:confirmLabel' => 'Are you sure you want to do this operation?',
|
||||
'ml:keywordsLabel' => 'Keywords',
|
||||
'ml:processLabel' => 'Process',
|
||||
'ml:addLanguagePlaceHolder' => 'Add Language',
|
||||
'ml:keywordPlaceHolder' => 'New Keyword',
|
||||
'ml:searchPlaceHolder' => 'Search Word'
|
||||
];
|
||||
|
||||
public $tr =
|
||||
[
|
||||
'ml:addButton' => 'Yeni Ekle',
|
||||
'ml:updateButton' => 'Güncelle',
|
||||
'ml:deleteButton' => 'Sil',
|
||||
'ml:clearButton' => 'Temizle',
|
||||
'ml:searchButton' => 'Ara',
|
||||
'ml:titleLabel' => 'Çoklu Dil Veri Tablosu',
|
||||
'ml:confirmLabel' => 'Bu işlemi yapmak istediğinizden emin misiniz?',
|
||||
'ml:keywordsLabel' => 'Anahtar Kelimeler',
|
||||
'ml:processLabel' => 'İşlemler',
|
||||
'ml:addLanguagePlaceHolder' => 'Dil Ekle',
|
||||
'ml:keywordPlaceHolder' => 'Yeni Anahtar',
|
||||
'ml:searchPlaceHolder' => 'Kelime Ara'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Insert extends MLExtends
|
||||
{
|
||||
/**
|
||||
* Insert language key
|
||||
*
|
||||
* @param string $app = NULL
|
||||
* @param mixed $key
|
||||
* @param string $data = NULL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function do(string $app, $key, ?string $data = NULL) : bool
|
||||
{
|
||||
$datas = [];
|
||||
|
||||
$createFile = $this->_langFile($app);
|
||||
|
||||
if( ! is_file($createFile) )
|
||||
{
|
||||
file_put_contents($createFile, json_encode([]));
|
||||
}
|
||||
|
||||
$datas = json_decode(file_get_contents($createFile), true);
|
||||
|
||||
if( ! empty($datas) )
|
||||
{
|
||||
$json = $datas;
|
||||
}
|
||||
|
||||
if( ! is_array($key) )
|
||||
{
|
||||
$json[$key] = $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( $key as $k => $v )
|
||||
{
|
||||
$json[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if( $json !== $datas )
|
||||
{
|
||||
Properties::$select = NULL;
|
||||
|
||||
return file_put_contents($createFile, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Lang;
|
||||
use ZN\Controller\Factory;
|
||||
|
||||
class ML extends Factory
|
||||
{
|
||||
const factory =
|
||||
[
|
||||
'methods' =>
|
||||
[
|
||||
'select' => 'Select::do',
|
||||
'selectall' => 'Select::all',
|
||||
'keys' => 'Select::keys',
|
||||
'langs' => 'Select::langs',
|
||||
'insert' => 'Insert::do',
|
||||
'update' => 'Update::do',
|
||||
'delete' => 'Delete::do',
|
||||
'deleteall' => 'Delete::all',
|
||||
'grid' => 'Grid::create',
|
||||
'table' => 'Grid::create',
|
||||
'limit' => 'Grid::limit:this',
|
||||
'url' => 'Grid::url:this'
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Set language
|
||||
*
|
||||
* @param string $lang = 'tr'
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function lang(string $lang = 'tr') : bool
|
||||
{
|
||||
Properties::$select = NULL;
|
||||
|
||||
return Lang::set($lang);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Lang;
|
||||
use ZN\Config;
|
||||
|
||||
class MLExtends
|
||||
{
|
||||
/**
|
||||
* Keeps MLGrid config
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $gridConfig;
|
||||
|
||||
/**
|
||||
* Keeps language file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $appdir;
|
||||
|
||||
/**
|
||||
* Keeps external language file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $externalAppdir;
|
||||
|
||||
/**
|
||||
* Keeps file extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $extension = '.ml';
|
||||
|
||||
/**
|
||||
* Keeps directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory = 'ml/';
|
||||
|
||||
/**
|
||||
* Keeps external language path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $externalLang;
|
||||
|
||||
/**
|
||||
* Magic constructor
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->gridConfig = Config::default('ZN\Language\GridDefaultConfiguration')
|
||||
::get('ViewObjects', 'mlgrid');
|
||||
|
||||
$mlDir = $this->directory;
|
||||
|
||||
$this->appdir = LANGUAGES_DIR . $mlDir;
|
||||
$this->externalAppdir = EXTERNAL_LANGUAGES_DIR . $mlDir;
|
||||
|
||||
if( ! is_dir($this->appdir) )
|
||||
{
|
||||
mkdir($this->appdir, 0755); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$getLang = Lang::get();
|
||||
|
||||
$this->externalLang = $this->externalAppdir.$getLang.$this->extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* protected get file path
|
||||
*/
|
||||
protected function getFilePath()
|
||||
{
|
||||
return $this->appdir . Lang::get(). $this->extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* protected lang file
|
||||
*
|
||||
* @param string $app
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _langFile($app)
|
||||
{
|
||||
return $this->appdir . $app . $this->extension;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Properties
|
||||
{
|
||||
/**
|
||||
* Get select lang.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $select = NULL;
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
* @since 2011
|
||||
*/
|
||||
|
||||
use ZN\Lang;
|
||||
use ZN\Filesystem;
|
||||
|
||||
class Select extends MLExtends
|
||||
{
|
||||
/**
|
||||
* Select word.
|
||||
*
|
||||
* @param string $key = NULL
|
||||
* @param mixed $convert = NULL
|
||||
*/
|
||||
public function do(?string $key = NULL, $convert = NULL)
|
||||
{
|
||||
if( Properties::$select === NULL )
|
||||
{
|
||||
if( is_file($this->getFilePath()) )
|
||||
{
|
||||
$read = file_get_contents($this->getFilePath());
|
||||
}
|
||||
|
||||
if( is_file($this->externalLang) )
|
||||
{
|
||||
$eread = file_get_contents($this->externalLang); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$read = json_decode($read ?? '', true);
|
||||
$eread = json_decode($eread ?? '', true);
|
||||
Properties::$select = array_merge((array) $eread, (array) $read);
|
||||
}
|
||||
|
||||
if( $key === NULL )
|
||||
{
|
||||
return Properties::$select;
|
||||
}
|
||||
|
||||
if( isset(Properties::$select[$key]) )
|
||||
{
|
||||
if( is_array($convert) )
|
||||
{
|
||||
$return = str_replace(array_keys($convert), array_values($convert), Properties::$select[$key] ?? '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = str_replace('%', $convert ?? '', Properties::$select[$key] ?? '');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = $key;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select all languages
|
||||
*
|
||||
* @param mixed $app = NULL
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all($app = NULL) : array
|
||||
{
|
||||
if( ! is_string($app) )
|
||||
{
|
||||
if( $app === NULL )
|
||||
{
|
||||
$MLFiles = $this->getMLFiles();
|
||||
}
|
||||
elseif( is_array($app) )
|
||||
{
|
||||
$MLFiles = $app;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$allMLFiles = [];
|
||||
|
||||
if( ! empty($MLFiles) ) foreach( $MLFiles as $file )
|
||||
{
|
||||
$removeExtension = $this->removeExtension($file);
|
||||
$allMLFiles[$removeExtension] = $this->all($removeExtension);
|
||||
}
|
||||
|
||||
return $allMLFiles;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( is_file($createFile = $this->_langFile($app)) )
|
||||
{
|
||||
$read = file_get_contents($createFile);
|
||||
|
||||
return json_decode($read, true);
|
||||
}
|
||||
|
||||
return []; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keys and values of the selected language from the object type.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function keys()
|
||||
{
|
||||
return (object) $this->all(Lang::get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get langs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function langs()
|
||||
{
|
||||
$langs = [];
|
||||
$files = $this->getMLFiles();
|
||||
|
||||
foreach( $files as $file )
|
||||
{
|
||||
$langs[] = $this->removeExtension($file);
|
||||
}
|
||||
|
||||
return $langs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get ml files
|
||||
*/
|
||||
protected function getMLFiles()
|
||||
{
|
||||
return Filesystem::getFiles($this->appdir, 'ml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected remove extension
|
||||
*/
|
||||
protected function removeExtension($file)
|
||||
{
|
||||
return str_replace($this->extension, '', $file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php namespace ZN\Language;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Update
|
||||
{
|
||||
/**
|
||||
* Updates language key
|
||||
*
|
||||
* @param string $app = NULL
|
||||
* @param mixed $key
|
||||
* @param string $data = NULL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function do(?string $app = NULL, $key, ?string $data = NULL) : bool
|
||||
{
|
||||
return (new Insert)->do($app, $key, $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user