PageRenderTime 513ms CodeModel.GetById 150ms app.highlight 112ms RepoModel.GetById 140ms app.codeStats 0ms

/source/unused/html/lang.php

http://sharebooks.googlecode.com/
PHP | 425 lines | 388 code | 23 blank | 14 comment | 45 complexity | e6c142e060dca974a4d42861eb2b58c0 MD5 | raw file
  1<?php
  2
  3include_once('define.php');
  4include_once('filter.class.php');
  5
  6//edit value of constant
  7if (isset($_POST['btn_edit']) && ($_POST['btn_edit']))
  8{
  9	$key = $_POST['hidden_value_edit'];
 10	$file = $_POST['hidden_file_edit'];
 11	$en = $_POST['en'];
 12	$fr = $_POST['fr'];
 13	$de = $_POST['de'];
 14	$es = $_POST['es'];
 15	$it = $_POST['it'];
 16
 17	$current_lang_group = '';
 18
 19	$input = "";
 20	$lines = file("{$root}{$file}");
 21	foreach($lines as $key1 => $line) {
 22		if(preg_match("@^\[([en]+)\]$@U", $line, $out)) {
 23			$current_lang_group = 'en';
 24		}
 25		if(preg_match("@^\[([fr]+)\]$@U", $line, $out)) {
 26			$current_lang_group = 'fr';
 27		}
 28		if(preg_match("@^\[([de]+)\]$@U", $line, $out)) {
 29			$current_lang_group = 'de';
 30		}
 31		if(preg_match("@^\[([es]+)\]$@U", $line, $out)) {
 32			$current_lang_group = 'es';
 33		}
 34		if(preg_match("@^\[([it]+)\]$@U", $line, $out)) {
 35			$current_lang_group = 'it';
 36		}
 37
 38		$line = trim($line);
 39		if(!preg_match("@(^{$key})( =|=)@U", $line) && $line != "") {
 40			$input .= "{$line}\n";
 41		}
 42		else {
 43			if($line != "")
 44				$input .= "{$key} = {$$current_lang_group}\n";
 45		}
 46	}
 47	$file = "{$root}{$file}";
 48	$fp = fopen($file, "w");
 49	fwrite($fp, $input);
 50	fclose($fp);
 51
 52	echo json_encode(array("rep"=> "ok"));
 53	exit;
 54}
 55
 56$filter = new filter();
 57
 58/*
 59 * cache file action.
 60 */
 61if(isset($_POST['d'])) {
 62	$key = $_POST['d'];
 63	$files = $_POST['f'];
 64	foreach($files as $i => $file) {
 65		$input = ""; $cacheInput = "";
 66		$lines = file("{$root}{$file}");
 67		foreach($lines as $key1 => $line) {
 68			$line = trim($line);
 69			if(!preg_match("@(^{$key})( =|=)@U", $line) && $line != "") {
 70				$input .= "{$line}\n";
 71			} else {
 72				if($line != "")
 73					$cacheInput .= "{$line}\n";
 74			}
 75			if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $line, $out)) {
 76				$cacheInput .= "{$line}\n";
 77			}
 78
 79		}
 80		$file = "{$root}{$file}";
 81		$fp = fopen($file, "w");
 82		fwrite($fp, $input);
 83		fclose($fp);
 84		// cache
 85		$cacheFile = str_replace('/', '-', $file);
 86		$cacheFileHandle = fopen("{$cache_lang_dir}{$cacheFile}", 'w');
 87		fwrite($cacheFileHandle, $cacheInput);
 88		fclose($cacheFileHandle);
 89	}
 90	echo json_encode(array("rep"=> "ok"));
 91	exit;
 92}
 93/*
 94 * restore cache action.
 95 */
 96if(isset($_POST['r'])) {
 97	$key = $_POST['r'];
 98	$files = $_POST['f']; // <array>
 99	$contains = array();
100	foreach($files as $i => $file) {
101		$filename = str_replace($cache_lang_dir, '', $file);
102		$lines = file($file); $lang = '';
103		foreach($lines as $key => $line) {
104			$line = trim($line);
105			if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $line, $out)) {
106				$lang = $out[1];
107				continue;
108			}
109			if(empty($lang) || empty($line))
110				continue;
111			preg_match_all('/(.*)=(.*)/', $line, $data);
112			if(!isset($data[1][0]) || !isset($data[2][0])) {
113				continue;
114			}
115			$code = trim($data[1][0]);
116			$detail = trim($data[2][0]);
117
118			$contains[$filename][$lang] = array(
119				'key' => $code, 'value' => $detail
120			);
121		}
122		// restore
123		$fileuse = str_replace('-', '/', $filename);
124		$ulines = file($fileuse);
125		$input = '';
126		foreach($ulines as $j => $uline) {
127			$uline = trim($uline);
128			if(preg_match("@^\[([en|de|fr|es|it]+)\]$@U", $uline, $out)) {
129				$input .= "$out[0]\n";
130				$input .= "{$contains[$filename][$out[1]]['key']} = {$contains[$filename][$out[1]]['value']}\n";
131				continue;
132			}
133			$input .= "{$uline}\n";
134		}
135		$fp = fopen($fileuse, "w");
136		fwrite($fp, $input);
137		fclose($fp);
138		unlink($file);
139	}
140	echo json_encode(array('rep' => 'ok'));
141	exit;
142}
143
144// lang key on disk
145$langfiles = $filter->dirfiles($view_dir, array('.svn'), array('ini'));
146$langkeys = $filter->getkeys($langfiles, $root);
147
148// key to use
149$useinifiles = $filter->dirfiles(
150	"{$root}",
151	array('.svn', 'config', 'files', 'language', 'logs', 'templates_pub'),
152	array('html', 'php')
153);
154$contains = Array();
155foreach($useinifiles as $key => $file) {
156	$info = pathinfo($file);
157	$content = file_get_contents($file);
158	$output = Array();
159	if($info['extension'] == 'php') {
160		preg_match_all("@({$prefix_lang})(.*)('|\")@U", $content, $out);
161		if(count($out[0]) > 0) {
162			$output = $out[0];
163		}
164	}
165	if($info['extension'] == 'html') {
166		preg_match_all("@#([A-Z0-9_]+)#@U", $content, $out);
167		if(count($out[1]) > 0) {
168			$output = $out[1];
169		}
170	}
171	if(count($output) > 0) {
172		foreach($output as $key => $value) {
173			$value = str_replace("'", '', $value);
174			$value = str_replace('"', '', $value);
175			if (isset($contains[$value][$file][0]))
176			{
177				$appearance_time = $contains[$value][$file][0] + 1;
178			}
179			else
180			{
181				$appearance_time = 1;
182			}
183			$contains[$value][$file][0] = $appearance_time;
184
185			$line_array = file($file);
186			foreach($line_array as $i => $line)
187			{
188				if (strpos($line, $value))
189				{
190					$contains[$value][$file][1] = trim($line_array[$i]);
191					break;
192				}
193			}
194		}
195	}
196}
197// cache file
198$cachekeys = Array();
199$cachefiles = $filter->files($cache_lang_dir, array('ini'));
200foreach($cachefiles as $key => $file) {
201	$cachefiles[$key] = "{$cache_lang_dir}{$file}";
202}
203$cachekeys = $filter->getkeys($cachefiles, $root);
204?>
205
206<html>
207	<head>
208		<title>Language unused</title>
209		<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
210		<script type="text/javascript">
211			$(document).ready(function(){
212				$('.true').click(function(){
213		   			var panel = $(this).next();
214		   			if(panel.is(':hidden')) {
215		   				panel.show();
216	   				} else {
217	   					panel.hide();
218	   				}
219	   				return false;
220		   		});
221		   		$('.delete').click(function(){
222					var self = $(this);
223					$.post(window.location.href, self.attr('href'), function(data){
224						if(data.rep == 'ok') {
225							window.location.reload();
226						} else {
227							alert("Error!");
228						}
229					}, 'json');
230					return false;
231		   		});
232		   		$('.restore').click(function(){
233					var self = $(this);
234					$.post(window.location.href, self.attr('href'), function(data){
235						if(data.rep == 'ok') {
236							window.location.reload();
237						} else {
238							alert("Error!");
239						}
240					}, 'json');
241					return false;
242		   		});
243			});
244
245			function popup_exit()
246			{
247				var element = document.getElementById('popup');
248				element.style.display = 'none';
249			}
250
251			function popup_show(key, file_name, en, fr, de, es, it)
252			{
253				var element	  = document.getElementById('popup');
254
255				var width		= window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
256				var height	   = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
257
258				element.style.position = "absolute";
259				element.style.display  = "block";
260
261				element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2)+'px';
262				element.style.top  = (document.documentElement.scrollTop +(height-element.clientHeight)/2)+'px';
263				document.getElementById('value_edit').innerHTML = 'EDIT: ' + key;
264				document.getElementById('file_edit').innerHTML = 'FILE: ' + file_name;
265				document.getElementById('en').value = en;
266				document.getElementById('fr').value = fr;
267				document.getElementById('de').value = de;
268				document.getElementById('es').value = es;
269				document.getElementById('it').value = it;
270				document.getElementById('hidden_value_edit').value = key;
271				document.getElementById('hidden_file_edit').value = file_name;
272			}
273		</script>
274		<style type="text/css">
275			.result {
276				background-color:#f1f1f1;
277				border:1px solid #ccc;
278				padding:5px;
279				margin:0px;
280				margin-bottom:10px;
281				color:#333
282			}
283			table {
284				background-color:#eee;
285			}
286			.tr {
287				text-transform: uppercase;
288				font-weight:bold;
289				background-color:#ccc;
290			}
291			.keys {
292			}
293			.keysuse {
294				color:#060
295			}
296			.true {
297				color:#060;cursor:pointer;font-weight:bold
298			}
299			.restore,
300			.delete {
301				color:#f00;font-weight:bold
302			}
303			.example {
304				color:#090;
305			}
306			div.popup {
307				z-index: 1;
308				width: 1000px;
309				border: 1px solid black;
310				background-color: #216072;
311				text-align: center;
312			}
313
314		</style>
315	</head>
316	<body>
317<?php
318if(count($cachekeys) > 0) {
319?>
320<h1>Files delete</h1>
321<pre class="result">
322<?php
323foreach($cachekeys['en'] as $key => $files) {
324	$paramfiles = ''; $cachefiles = '<div class="keysuse">';
325	if(count($files) > 0) {
326		foreach($files as $file => $value) {
327			$paramfiles .= "&f[]={$file}";
328			$cachefiles .= "\t{$file}\n";
329		}
330	}
331	$cachefiles .= '</div>';
332	echo "<div class=\"keys\">{$key} <a href=\"r={$key}{$paramfiles}\" class=\"restore\">restore</a>{$cachefiles}</div>";
333}
334?>
335</pre>
336<?php
337}
338?>
339
340<h1>Language unused</h1>
341<pre class="result">
342<?php
343//print_r($langkeys);
344foreach($langkeys['en'] as $key => $files) {
345	$act = '';
346	$key = str_replace($view_dir, "", $key);
347	if(isset($contains[$key])) {
348		$act .= '<a href="#" class="true">is use</a>';
349		$act .= "<div>";
350		$act .= "\t<strong>Files use</strong><div class=\"keysuse\">";
351		foreach($contains[$key] as $keyuse => $value){
352			$act .= "\t\t{$keyuse} ({$value[0]} times) <div class=\"example\">\t\t\t \"...".htmlentities($value[1])."...\" </div> \n";
353		}
354		$act .= '</div>';
355	} else {
356		$fileparams = '';
357		if(count($files) > 0) {
358			foreach($files as $file => $value) {
359				$fileparams .= "&f[]={$file}";
360			}
361		}
362		$act .= "<a href=\"d={$key}{$fileparams}\" class=\"delete\">delete</a>";
363		$act .= '</div>';
364	}
365	$act .= "\t<strong>Language values</strong><table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">";
366	$act .= "<tr class=\"tr\">";
367	$act .= "<td width=\"30%\">file</td>";
368	$act .= "<td>en</td>";
369	$act .= "<td>fr</td>";
370	$act .= "<td>de</td>";
371	$act .= "<td>es</td>";
372	$act .= "<td>it</td>";
373	$act .= "<td width=\"5%\">Edit</td>";
374	$act .= "</tr>";
375	foreach($langkeys['en'][$key] as $key1 => $val1) {
376		$edit_string = "'" . $key . "', '" . $key1;
377		$act .= "<tr>";
378		$act .= "<td>{$key1}</td>";
379		foreach($defines['language_code'] as $key2 => $val2) {
380			if (!isset($langkeys[$val2][$key][$key1])) $langkeys[$val2][$key][$key1] = '';
381			{
382				$val3 = $langkeys[$val2][$key][$key1];
383			}
384			$act .= "<td>" . $val3 . "&nbsp;</td>";
385			$edit_string .= "', '" . $val3;
386		}
387		$edit_string .= "'";
388		$act .= "<td><a href='#' onclick=\"popup_show(" . $edit_string . ");\" >edit</a></td>";
389		$act .= "</tr>";
390	}
391	$act .= '</table></div>';
392	echo "<div class=\"keys\">{$key} {$act}</div>";
393
394	//popup to edit value of a constant
395	echo "
396		<div class='popup' id='popup' style='display: none;'>
397			<div align='center'>
398				<form id = 'form_edit' name = 'form_edit' method='post' action=''>
399					<table width='950px'>
400						<input type='hidden' name='hidden_value_edit' id='hidden_value_edit' />
401						<input type='hidden' name='hidden_file_edit' id='hidden_file_edit' />
402						<tr><th></th><td width='900px' align='center' id='value_edit'>EDIT VALUE</td></tr>
403						<tr><th></th><td width='900px' align='center' id='file_edit'>file_name</td></tr>
404						<tr><th>EN:</th><td width='900px'><input size='110' type='text' name='en' id='en' /></td></tr>
405						<tr><th>FR:</th><td width='900px'><input size='110' type='text' name='fr' id='fr' /></td></tr>
406						<tr><th>DE:</th><td width='900px'><input size='110' type='text' name='de' id='de' /></td></tr>
407						<tr><th>ES:</th><td width='900px'><input size='110' type='text' name='es' id='es' /></td></tr>
408						<tr><th>IT:</th><td width='900px'><input size='110' type='text' name='it' id='it' /></td></tr>
409						<tr><th></th>
410							<td>
411								<input class='btn' type='submit' value='Edit' name='btn_edit' id='btn_edit' />
412								<input class='btn' onclick=\"popup_exit();\" type='button' value='Cancel' />
413							</td>
414						</tr>
415					</table>
416				</form>
417			</div>
418		</div>
419	";
420}
421?>
422</pre>
423	</body>
424</html>
425