summaryrefslogtreecommitdiffstats
path: root/modules/admin.inc.php
diff options
context:
space:
mode:
authorraul2014-07-15 21:06:07 +0200
committerraul2014-07-15 21:06:07 +0200
commitbd9cdadb71b9cb46e7c8c629739997d2a0c1388e (patch)
tree2c8084c0132b581f6e2eb850248eddee69a77b7a /modules/admin.inc.php
parent[i18n] Updated the translations (diff)
downloadslx-admin-bd9cdadb71b9cb46e7c8c629739997d2a0c1388e.tar.gz
slx-admin-bd9cdadb71b9cb46e7c8c629739997d2a0c1388e.tar.xz
slx-admin-bd9cdadb71b9cb46e7c8c629739997d2a0c1388e.zip
[i18n] Added administration interface for the i18n system
Diffstat (limited to 'modules/admin.inc.php')
-rw-r--r--modules/admin.inc.php160
1 files changed, 160 insertions, 0 deletions
diff --git a/modules/admin.inc.php b/modules/admin.inc.php
new file mode 100644
index 00000000..b74b5ef5
--- /dev/null
+++ b/modules/admin.inc.php
@@ -0,0 +1,160 @@
+<?php
+
+class Page_Admin extends Page
+{
+
+ private $template = false;
+ private $files = false;
+ private $table = false;
+ private $tags = false;
+
+ /**
+ * Implementation of the abstract doPreprocess function
+ *
+ * Checks if the user is logged in and processes any
+ * action if one was specified in the request.
+ *
+ */
+ protected function doPreprocess()
+ {
+ // load user, we will need it later
+ User::load();
+
+ // only admins should be able to access the administration page
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=Main');
+ }
+
+ if(Request::any('template')){
+ $this->template = Request::any('template');
+ }
+
+ }
+
+ /**
+ * Implementation of the abstract doRender function
+ *
+ * Fetch the list of news from the database and paginate it.
+ *
+ */
+ protected function doRender()
+ {
+ if(!$this->template || !$this->templateAnalysis($this->template)){
+ $this->initTable();
+ Render::addTemplate('administration/_page', array(
+ 'token' => Session::get('token'),
+ 'adminMessage' => $this->message,
+ 'table' => $this->table
+ ));
+ }else{
+ Render::addTemplate('administration/template', array(
+ 'template' => $this->template,
+ 'tags' => $this->tags
+ ));
+ }
+
+
+ }
+
+ private function initTable(){
+ $this->listTemplates();
+ $de = $this->listJson('de/');
+ $en = $this->listJson('en/');
+ $pt = $this->listJson('pt/');
+
+ foreach($this->files as $key => $value){
+
+ $this->table[] = array(
+ 'template' => $value,
+ 'link' => $key,
+ 'de' => $this->checkJson($de[$key],'de'),
+ 'en' => $this->checkJson($en[$key],'en'),
+ 'pt' => $this->checkJson($pt[$key],'pt')
+ );
+ }
+
+ }
+
+ private function listTemplates(){
+ $this->files = array();
+ $dir = 'templates/';
+ $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
+ foreach($objects as $name => $object){
+ if(array_pop(explode('.',$name)) === 'html'){
+ $key = str_replace($dir, '', $name);
+ $key = str_replace('.html', '', $key);
+ $this->files[$key] = $name;
+ }
+ }
+ }
+
+ private function listJson($lang){
+ $json = array();
+ $dir = 'lang/' . $lang;
+ $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
+ foreach($objects as $name => $object){
+ if(array_pop(explode('.',$name)) === 'json'){
+ $key = str_replace($dir, '', $name);
+ $key = str_replace('.json', '', $key);
+ $json[$key] = $key;
+ }
+ }
+ return $json;
+ }
+
+ private function checkJson($path,$lang){
+ if($path){
+ $htmlTemplate = file_get_contents('templates/' . $path . '.html');
+ $json = Dictionary::getArrayTemplate($path,$lang);
+ $htmlCount = substr_count($htmlTemplate, 'lang_');
+ $matchCount = 0;
+
+ foreach($json as $key => $value){
+ if($key != 'lang'){
+ $key = $key . '}}';
+ $matchCount += substr_count($htmlTemplate, $key);
+ }
+ }
+
+ $diff = $htmlCount - $matchCount;
+
+ //allright
+ if($diff == 0) return "OK";
+ if($diff > 0) return $diff . " JSON tag(s) are missing";
+ if($diff < 0) return ($diff * -1) . " extra JSON tag(s)";
+ }else{
+ return "JSON file is missing";
+ }
+
+ }
+
+ private function templateAnalysis($path){
+ if(!file_exists('templates/' . $path . '.html')){
+ Message::addError('invalid-template');
+ return false;
+ }
+ $htmlTemplate = file_get_contents('templates/' . $path . '.html');
+ preg_match_all('/{{lang_(.*?)}}/s', $htmlTemplate, $matches);
+
+ $tags = $matches[1];
+
+ foreach($tags as $tag){
+ $this->tags[] = array(
+ 'tag' => 'lang_' . $tag,
+ 'de' => $this->checkJsonTag($path,$tag,'de/'),
+ 'en' => $this->checkJsonTag($path,$tag,'en/'),
+ 'pt' => $this->checkJsonTag($path,$tag,'pt/')
+ );
+ }
+
+ return true;
+ }
+
+ private function checkJsonTag($path,$tag,$lang){
+ if($json = Dictionary::getArrayTemplate($path,$lang)){
+ return $json['lang_' . $tag];
+ }
+ return '';
+ }
+}