/source/unused/html/lang.php
PHP | 425 lines | 388 code | 23 blank | 14 comment | 45 complexity | e6c142e060dca974a4d42861eb2b58c0 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- include_once('define.php');
- include_once('filter.class.php');
- //edit value of constant
- if (isset($_POST['btn_edit']) && ($_POST['btn_edit']))
- {
- $key = $_POST['hidden_value_edit'];
- $file = $_POST['hidden_file_edit'];
- $en = $_POST['en'];
- $fr = $_POST['fr'];
- $de = $_POST['de'];
- $es = $_POST['es'];
- $it = $_POST['it'];
- $current_lang_group = '';
- $input = "";
- $lines = file("{$root}{$file}");
- foreach($lines as $key1 => $line) {
- if(preg_match("@^\[([en]+)\]$@U", $line, $out)) {
- $current_lang_group = 'en';
- }
- if(preg_match("@^\[([fr]+)\]$@U", $line, $out)) {
- $current_lang_group = 'fr';
- }
- if(preg_match("@^\[([de]+)\]$@U", $line, $out)) {
- $current_lang_group = 'de';
- }
- if(preg_match("@^\[([es]+)\]$@U", $line, $out)) {
- $current_lang_group = 'es';
- }
- if(preg_match("@^\[([it]+)\]$@U", $line, $out)) {
- $current_lang_group = 'it';
- }
- $line = trim($line);
- if(!preg_match("@(^{$key})( =|=)@U", $line) && $line != "") {
- $input .= "{$line}\n";
- }
- else {
- if($line != "")
- $input .= "{$key} = {$$current_lang_group}\n";
- }
- }
- $file = "{$root}{$file}";
- $fp = fopen($file, "w");
- fwrite($fp, $input);
- fclose($fp);
- echo json_encode(array("rep"=> "ok"));
- exit;
- }
- $filter = new filter();
- /*
- * cache file action.
- */
- if(isset($_POST['d'])) {
- $key = $_POST['d'];
- $files = $_POST['f'];
- foreach($files as $i => $file) {
- $input = ""; $cacheInput = "";
- $lines = file("{$root}{$file}");
- foreach($lines as $key1 => $line) {
- $line = trim($line);
- if(!preg_match("@(^{$key})( =|=)@U", $line) && $line != "") {
- $input .= "{$line}\n";
- } else {
- if($line != "")
- $cacheInput .= "{$line}\n";
- }
- if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $line, $out)) {
- $cacheInput .= "{$line}\n";
- }
- }
- $file = "{$root}{$file}";
- $fp = fopen($file, "w");
- fwrite($fp, $input);
- fclose($fp);
- // cache
- $cacheFile = str_replace('/', '-', $file);
- $cacheFileHandle = fopen("{$cache_lang_dir}{$cacheFile}", 'w');
- fwrite($cacheFileHandle, $cacheInput);
- fclose($cacheFileHandle);
- }
- echo json_encode(array("rep"=> "ok"));
- exit;
- }
- /*
- * restore cache action.
- */
- if(isset($_POST['r'])) {
- $key = $_POST['r'];
- $files = $_POST['f']; // <array>
- $contains = array();
- foreach($files as $i => $file) {
- $filename = str_replace($cache_lang_dir, '', $file);
- $lines = file($file); $lang = '';
- foreach($lines as $key => $line) {
- $line = trim($line);
- if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $line, $out)) {
- $lang = $out[1];
- continue;
- }
- if(empty($lang) || empty($line))
- continue;
- preg_match_all('/(.*)=(.*)/', $line, $data);
- if(!isset($data[1][0]) || !isset($data[2][0])) {
- continue;
- }
- $code = trim($data[1][0]);
- $detail = trim($data[2][0]);
- $contains[$filename][$lang] = array(
- 'key' => $code, 'value' => $detail
- );
- }
- // restore
- $fileuse = str_replace('-', '/', $filename);
- $ulines = file($fileuse);
- $input = '';
- foreach($ulines as $j => $uline) {
- $uline = trim($uline);
- if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $uline, $out)) {
- $input .= "$out[0]\n";
- $input .= "{$contains[$filename][$out[1]]['key']} = {$contains[$filename][$out[1]]['value']}\n";
- continue;
- }
- $input .= "{$uline}\n";
- }
- $fp = fopen($fileuse, "w");
- fwrite($fp, $input);
- fclose($fp);
- unlink($file);
- }
- echo json_encode(array('rep' => 'ok'));
- exit;
- }
- // lang key on disk
- $langfiles = $filter->dirfiles($view_dir, array('.svn'), array('ini'));
- $langkeys = $filter->getkeys($langfiles, $root);
- // key to use
- $useinifiles = $filter->dirfiles(
- "{$root}",
- array('.svn', 'config', 'files', 'language', 'logs', 'templates_pub'),
- array('html', 'php')
- );
- $contains = Array();
- foreach($useinifiles as $key => $file) {
- $info = pathinfo($file);
- $content = file_get_contents($file);
- $output = Array();
- if($info['extension'] == 'php') {
- preg_match_all("@({$prefix_lang})(.*)('|\")@U", $content, $out);
- if(count($out[0]) > 0) {
- $output = $out[0];
- }
- }
- if($info['extension'] == 'html') {
- preg_match_all("@#([A-Z0-9_]+)#@U", $content, $out);
- if(count($out[1]) > 0) {
- $output = $out[1];
- }
- }
- if(count($output) > 0) {
- foreach($output as $key => $value) {
- $value = str_replace("'", '', $value);
- $value = str_replace('"', '', $value);
- if (isset($contains[$value][$file][0]))
- {
- $appearance_time = $contains[$value][$file][0] + 1;
- }
- else
- {
- $appearance_time = 1;
- }
- $contains[$value][$file][0] = $appearance_time;
- $line_array = file($file);
- foreach($line_array as $i => $line)
- {
- if (strpos($line, $value))
- {
- $contains[$value][$file][1] = trim($line_array[$i]);
- break;
- }
- }
- }
- }
- }
- // cache file
- $cachekeys = Array();
- $cachefiles = $filter->files($cache_lang_dir, array('ini'));
- foreach($cachefiles as $key => $file) {
- $cachefiles[$key] = "{$cache_lang_dir}{$file}";
- }
- $cachekeys = $filter->getkeys($cachefiles, $root);
- ?>
- <html>
- <head>
- <title>Language unused</title>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $('.true').click(function(){
- var panel = $(this).next();
- if(panel.is(':hidden')) {
- panel.show();
- } else {
- panel.hide();
- }
- return false;
- });
- $('.delete').click(function(){
- var self = $(this);
- $.post(window.location.href, self.attr('href'), function(data){
- if(data.rep == 'ok') {
- window.location.reload();
- } else {
- alert("Error!");
- }
- }, 'json');
- return false;
- });
- $('.restore').click(function(){
- var self = $(this);
- $.post(window.location.href, self.attr('href'), function(data){
- if(data.rep == 'ok') {
- window.location.reload();
- } else {
- alert("Error!");
- }
- }, 'json');
- return false;
- });
- });
- function popup_exit()
- {
- var element = document.getElementById('popup');
- element.style.display = 'none';
- }
- function popup_show(key, file_name, en, fr, de, es, it)
- {
- var element = document.getElementById('popup');
- var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
- var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
- element.style.position = "absolute";
- element.style.display = "block";
- element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2)+'px';
- element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight)/2)+'px';
- document.getElementById('value_edit').innerHTML = 'EDIT: ' + key;
- document.getElementById('file_edit').innerHTML = 'FILE: ' + file_name;
- document.getElementById('en').value = en;
- document.getElementById('fr').value = fr;
- document.getElementById('de').value = de;
- document.getElementById('es').value = es;
- document.getElementById('it').value = it;
- document.getElementById('hidden_value_edit').value = key;
- document.getElementById('hidden_file_edit').value = file_name;
- }
- </script>
- <style type="text/css">
- .result {
- background-color:#f1f1f1;
- border:1px solid #ccc;
- padding:5px;
- margin:0px;
- margin-bottom:10px;
- color:#333
- }
- table {
- background-color:#eee;
- }
- .tr {
- text-transform: uppercase;
- font-weight:bold;
- background-color:#ccc;
- }
- .keys {
- }
- .keysuse {
- color:#060
- }
- .true {
- color:#060;cursor:pointer;font-weight:bold
- }
- .restore,
- .delete {
- color:#f00;font-weight:bold
- }
- .example {
- color:#090;
- }
- div.popup {
- z-index: 1;
- width: 1000px;
- border: 1px solid black;
- background-color: #216072;
- text-align: center;
- }
- </style>
- </head>
- <body>
- <?php
- if(count($cachekeys) > 0) {
- ?>
- <h1>Files delete</h1>
- <pre class="result">
- <?php
- foreach($cachekeys['en'] as $key => $files) {
- $paramfiles = ''; $cachefiles = '<div class="keysuse">';
- if(count($files) > 0) {
- foreach($files as $file => $value) {
- $paramfiles .= "&f[]={$file}";
- $cachefiles .= "\t{$file}\n";
- }
- }
- $cachefiles .= '</div>';
- echo "<div class=\"keys\">{$key} <a href=\"r={$key}{$paramfiles}\" class=\"restore\">restore</a>{$cachefiles}</div>";
- }
- ?>
- </pre>
- <?php
- }
- ?>
- <h1>Language unused</h1>
- <pre class="result">
- <?php
- //print_r($langkeys);
- foreach($langkeys['en'] as $key => $files) {
- $act = '';
- $key = str_replace($view_dir, "", $key);
- if(isset($contains[$key])) {
- $act .= '<a href="#" class="true">is use</a>';
- $act .= "<div>";
- $act .= "\t<strong>Files use</strong><div class=\"keysuse\">";
- foreach($contains[$key] as $keyuse => $value){
- $act .= "\t\t{$keyuse} ({$value[0]} times) <div class=\"example\">\t\t\t \"...".htmlentities($value[1])."...\" </div> \n";
- }
- $act .= '</div>';
- } else {
- $fileparams = '';
- if(count($files) > 0) {
- foreach($files as $file => $value) {
- $fileparams .= "&f[]={$file}";
- }
- }
- $act .= "<a href=\"d={$key}{$fileparams}\" class=\"delete\">delete</a>";
- $act .= '</div>';
- }
- $act .= "\t<strong>Language values</strong><table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">";
- $act .= "<tr class=\"tr\">";
- $act .= "<td width=\"30%\">file</td>";
- $act .= "<td>en</td>";
- $act .= "<td>fr</td>";
- $act .= "<td>de</td>";
- $act .= "<td>es</td>";
- $act .= "<td>it</td>";
- $act .= "<td width=\"5%\">Edit</td>";
- $act .= "</tr>";
- foreach($langkeys['en'][$key] as $key1 => $val1) {
- $edit_string = "'" . $key . "', '" . $key1;
- $act .= "<tr>";
- $act .= "<td>{$key1}</td>";
- foreach($defines['language_code'] as $key2 => $val2) {
- if (!isset($langkeys[$val2][$key][$key1])) $langkeys[$val2][$key][$key1] = '';
- {
- $val3 = $langkeys[$val2][$key][$key1];
- }
- $act .= "<td>" . $val3 . " </td>";
- $edit_string .= "', '" . $val3;
- }
- $edit_string .= "'";
- $act .= "<td><a href='#' onclick=\"popup_show(" . $edit_string . ");\" >edit</a></td>";
- $act .= "</tr>";
- }
- $act .= '</table></div>';
- echo "<div class=\"keys\">{$key} {$act}</div>";
- //popup to edit value of a constant
- echo "
- <div class='popup' id='popup' style='display: none;'>
- <div align='center'>
- <form id = 'form_edit' name = 'form_edit' method='post' action=''>
- <table width='950px'>
- <input type='hidden' name='hidden_value_edit' id='hidden_value_edit' />
- <input type='hidden' name='hidden_file_edit' id='hidden_file_edit' />
- <tr><th></th><td width='900px' align='center' id='value_edit'>EDIT VALUE</td></tr>
- <tr><th></th><td width='900px' align='center' id='file_edit'>file_name</td></tr>
- <tr><th>EN:</th><td width='900px'><input size='110' type='text' name='en' id='en' /></td></tr>
- <tr><th>FR:</th><td width='900px'><input size='110' type='text' name='fr' id='fr' /></td></tr>
- <tr><th>DE:</th><td width='900px'><input size='110' type='text' name='de' id='de' /></td></tr>
- <tr><th>ES:</th><td width='900px'><input size='110' type='text' name='es' id='es' /></td></tr>
- <tr><th>IT:</th><td width='900px'><input size='110' type='text' name='it' id='it' /></td></tr>
- <tr><th></th>
- <td>
- <input class='btn' type='submit' value='Edit' name='btn_edit' id='btn_edit' />
- <input class='btn' onclick=\"popup_exit();\" type='button' value='Cancel' />
- </td>
- </tr>
- </table>
- </form>
- </div>
- </div>
- ";
- }
- ?>
- </pre>
- </body>
- </html>