Mikolaj Zalewski : refactor some common functions

Alexandre Julliard julliard at winehq.org
Fri Jun 19 08:36:17 CDT 2009


Module: tools
Branch: master
Commit: 51d572561e614d94f59c9181ac9064d66dea4d21
URL:    http://source.winehq.org/git/tools.git/?a=commit;h=51d572561e614d94f59c9181ac9064d66dea4d21

Author: Mikolaj Zalewski <mikolajz at tygrys.dom>
Date:   Wed Feb 13 19:02:45 2008 +0100

refactor some common functions

---

 php/lang.php     |   11 +++++------
 php/lib.php      |   22 ++++++++++++++++++++++
 php/resfile.php  |    7 +++----
 php/resource.php |    7 +++----
 4 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/php/lang.php b/php/lang.php
index ab0394f..c16aab7 100644
--- a/php/lang.php
+++ b/php/lang.php
@@ -1,10 +1,9 @@
 <?php
 include_once("config.php") ;
+include_once("lib.php");
+
+$lang = validate_lang($_REQUEST['lang']);
 
-$lang = preg_replace("/[^0-9a-f:]/", "-", $_REQUEST['lang']);
-if (!file_exists("$DATAROOT/langs/$lang"))
-    die("Invalid lang parameter");
-    
 $file = fopen("$DATAROOT/langs/$lang", "r");
 $transl = array();
 $notransl = array();
@@ -56,7 +55,7 @@ function dump_table($table)
 }
 
 ?>
-<h1><?php echo "Language: ".file_get_contents("$DATAROOT/conf/$lang") ?></h1>
+<h1><?php echo "Language: ".get_lang_name($lang) ?></h1>
 <h2>Partialy translanted files</h2>
 <?php dump_table($partial) ?>
 
@@ -66,4 +65,4 @@ function dump_table($table)
 <h2>Fully translated files</h2>
 <?php dump_table($transl) ?>
 
-</html>
\ No newline at end of file
+</html>
diff --git a/php/lib.php b/php/lib.php
new file mode 100644
index 0000000..e5e68b7
--- /dev/null
+++ b/php/lib.php
@@ -0,0 +1,22 @@
+<?php
+
+$MASTER_LANGUAGE = "009:01";
+
+function validate_lang($id)
+{
+    global $DATAROOT;
+    
+    $lang = preg_replace("/[^0-9a-f:]/", "-", $_REQUEST['lang']);
+    if (!file_exists("$DATAROOT/conf/$lang") || !file_exists("$DATAROOT/langs/$lang"))
+        die("Invalid lang parameter");
+    return $lang;
+}
+
+function get_lang_name($id)
+{
+    global $DATAROOT;
+
+    return file_get_contents("$DATAROOT/conf/$id");
+}
+
+?>
diff --git a/php/resfile.php b/php/resfile.php
index 35f693f..6685c50 100644
--- a/php/resfile.php
+++ b/php/resfile.php
@@ -1,16 +1,15 @@
 <?php
 include("config.php");
+include("lib.php");
 
-$lang = preg_replace("/[^0-9a-f:]/", "-", $_REQUEST['lang']);
+$lang = validate_lang($_REQUEST['lang']);
 $resfile = $_REQUEST['resfile'];
-if (!file_exists("$DATAROOT/langs/$lang"))
-    die("Invalid lang parameter");
     
 $file = fopen("$DATAROOT/langs/$lang", "r");
 $msgs = array();
 ?>
 <html>
-<h1>File <?php echo $resfile?> - <?php echo file_get_contents("$DATAROOT/conf/$lang") ?> language</h1>
+<h1>File <?php echo $resfile?> - <?php echo get_lang_name($lang) ?> language</h1>
 
 <?php
 while ($line = fgets($file, 4096))
diff --git a/php/resource.php b/php/resource.php
index a3361d0..5c7cbba 100644
--- a/php/resource.php
+++ b/php/resource.php
@@ -1,12 +1,11 @@
 <?php
 include("config.php");
+include("lib.php");
 
-$lang = $_REQUEST['lang'];
+$lang = validate_lang($_REQUEST['lang']);
 $resfile = $_REQUEST['resfile'];
 $type = $_REQUEST['type'];
 $id = $_REQUEST['id'];
-if (!file_exists("$DATAROOT/langs/$lang"))
-    die("Invalid lang parameter");
     
 $norm_fn = preg_replace("/[^A-Za-z0-9]/", "-", $resfile);
 $file = fopen("$DATAROOT/dumps/$norm_fn/$lang-$type-$id", "r");
@@ -14,7 +13,7 @@ $msgs = array();
 ?>
 <html>
 <body>
-<h1>File <?php echo $resfile?> - <?php echo file_get_contents("$DATAROOT/conf/$lang") ?> language - Resource <?php echo "$id ($type)"?></h1>
+<h1>File <?php echo $resfile?> - <?php echo get_lang_name($lang) ?> language - Resource <?php echo "$id ($type)"?></h1>
 
 <table style="background-color: #f8f8ff">
 <tr style="background-color: #f0f0ff"><th colspan="2">String table #<?php echo $id?></th></tr>




More information about the wine-cvs mailing list