Mikolaj Zalewski : php: add navigation menu, refactor link generation code

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


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

Author: Mikolaj Zalewski <mikolajz at tygrys.dom>
Date:   Tue Feb 19 20:20:15 2008 +0100

php: add navigation menu, refactor link generation code

---

 php/index.php    |    2 +-
 php/lang.php     |    3 +-
 php/lib.php      |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 php/resfile.php  |   13 +++++-----
 php/resource.php |   10 +++++---
 5 files changed, 78 insertions(+), 17 deletions(-)

diff --git a/php/index.php b/php/index.php
index 05e2693..47366fc 100644
--- a/php/index.php
+++ b/php/index.php
@@ -63,7 +63,7 @@ for ($i = 0; $i < count($transl); $i++)
         echo "<td rowspan=\"$serial\" style=\"text-align: center\">$nr";
         echo "</td>";
     }
-    echo "<td><a href=\"lang.php?lang=$langid\">".get_lang_name($langid)."</a></td>";
+    echo "<td>".gen_lang_a($langid).get_lang_name($langid)."</a></td>";
     printf("<td>%d (%.1f%%)</td>", $value, ($value*100)/$sum);
     echo "<td>".$missing[$langid]."</td><td>".$errors[$langid]."</td>\n";
     draw_bar($value, $errors[$langid], $sum);
diff --git a/php/lang.php b/php/lang.php
index 6f9e950..fd212a7 100644
--- a/php/lang.php
+++ b/php/lang.php
@@ -49,7 +49,7 @@ function dump_table($table)
     echo "<tr><th>File name</th><th>translated</th><th>missing</th><th>errors</th></tr>\n";
     foreach ($table as $key => $value)
     {
-        echo "<tr><td><a href=\"resfile.php?lang=$lang&resfile=".urlencode($value[3])."\">".$key."</a></td>";
+        echo "<tr><td>".gen_resfile_a($lang, $value[3]).$key."</a></td>";
         echo "<td>".$value[0]."</td>";
         echo "<td>".$value[1]."</td>";
         echo "<td>".$value[2]."</td>";
@@ -59,6 +59,7 @@ function dump_table($table)
 }
 
 ?>
+<p><?php dump_menu_root() ?> &gt; <?php dump_menu_lang($lang, FALSE)?> </p>
 <h1><?php echo "Language: ".get_lang_name($lang) ?></h1>
 <h2>Partialy translanted files</h2>
 <?php dump_table($partial) ?>
diff --git a/php/lib.php b/php/lib.php
index 8aede15..e11ef5e 100644
--- a/php/lib.php
+++ b/php/lib.php
@@ -31,7 +31,7 @@ function validate_resfile($resfile)
 function validate_id($id)
 {
     if (!preg_match("/^[a-zA-Z0-9_]+$/", $id))
-        die("Invalid resource file");
+        die("Invalid resource id");
     return $id;
 }
 
@@ -82,12 +82,26 @@ function get_locale_name($localeid)
     return $LOCALE_NAMES[$localeid];
 }
 
-function get_res_path($respath)
+function get_res_path($resfile)
 {
     global $DATAROOT;
 
-    $respath = preg_replace("/\\.rc(#.*)?$/", "", $respath);
-    return "$DATAROOT/dumps/res/".preg_replace("/[^a-zA-Z0-9]/", "-", $respath).".res";
+    $resfile = preg_replace("/\\.rc(#.*)?$/", "", $resfile);
+    return "$DATAROOT/dumps/res/".preg_replace("/[^a-zA-Z0-9]/", "-", $resfile).".res";
+}
+
+function get_resfile_name($resfile)
+{
+    if (preg_match("*^([a-zA-Z0-9/.-_]+)#locale([0-9a-f]{3}:[0-9a-f]{2})$*", $resfile, $m))
+    {
+        return "Locale data for: ".get_locale_name($m[2])." (".$m[1].")";
+    }
+    return $resfile;
+}
+
+function get_resource_name($type, $name)
+{
+    return "Resource ".$type." ".$name;
 }
 
 function update_lang_from_resfile($lang, $resfile)
@@ -97,4 +111,49 @@ function update_lang_from_resfile($lang, $resfile)
     return $lang;
 }
 
+function gen_lang_a($lang)
+{
+    return "<a href=\"lang.php?lang=".urlencode($lang)."\">";
+}
+
+function gen_resfile_a($lang, $resfile)
+{
+    return "<a href=\"resfile.php?lang=".urlencode($lang)."&resfile=".urlencode($resfile)."\">";
+}
+
+function gen_resource_a($lang, $resfile, $type, $id, $compare=FALSE)
+{
+    if ($compare)
+        $extra = "&compare=";
+    else
+        $extra = "";
+    return "<a href=\"resource.php?lang=".urlencode($lang)."&resfile=".urlencode($resfile)."&type=".urlencode($type)."&id=".urlencode($id)."$extra\">";
+}
+
+function dump_menu_root()
+{
+    echo "<a href=\"index.php\">Wine translations</a>";
+}
+
+function dump_menu_lang($lang, $link = TRUE)
+{
+    if ($link)
+        echo gen_lang_a($lang);
+    echo get_lang_name($lang);
+    echo "</a>";
+}
+
+function dump_menu_resfile($lang, $resfile, $link = TRUE)
+{
+    if ($link)
+        echo gen_resfile_a($lang, $resfile);
+    echo get_resfile_name($resfile);
+    echo "</a>";
+}
+
+function dump_menu_resource($lang, $resfile, $type, $id)
+{
+    echo get_resource_name($type, $id);
+}
+
 ?>
diff --git a/php/resfile.php b/php/resfile.php
index 12079b4..3a80e83 100644
--- a/php/resfile.php
+++ b/php/resfile.php
@@ -4,12 +4,14 @@ include("lib.php");
 
 $lang = validate_lang($_REQUEST['lang']);
 $resfile = validate_resfile($_REQUEST['resfile']);
-    
+
 $file = fopen("$DATAROOT/langs/$lang", "r");
 $msgs = array();
 ?>
 <html>
-<h1>File <?php echo $resfile?> - <?php echo get_lang_name($lang) ?> language</h1>
+<?php dump_menu_root() ?> &gt <?php dump_menu_lang($lang) ?> &gt <?php dump_menu_resfile($lang, $resfile, FALSE) ?>
+
+<h1>File <?php echo $resfile?></h1>
 
 <?php
 while ($line = fgets($file, 4096))
@@ -50,12 +52,9 @@ foreach ($msgs as $value)
         }
         else
         {
-            if (strpos($value, "Error: ") === 0)
-                $extra = "&compare=";
-            else
-                $extra = "";
+            $error = (strpos($value, "Error: ") === 0);
             $value = preg_replace("/STRINGTABLE ([0-9]+)/",
-                "<a href=\"resource.php?lang=$lang&resfile=".urlencode($resfile)."&type=6&id=".$m[1]."$extra\">".
+                gen_resource_a($lang, $resfile, 6, $m[1], $error).
                 "STRINGTABLE #".$m[1]." (strings $id0..$id1)</a>",
                 $value);
         }
diff --git a/php/resource.php b/php/resource.php
index 5388ced..4e0da68 100644
--- a/php/resource.php
+++ b/php/resource.php
@@ -21,7 +21,9 @@ $compare = isset($_REQUEST['compare']);
     </style>
 </head>
 <body>
-<h1>File <?php echo $resfile?> - <?php echo get_lang_name($lang) ?> language - Resource <?php echo "$id ($type)"?></h1>
+<?php dump_menu_root() ?> &gt <?php dump_menu_lang($lang) ?> &gt <?php dump_menu_resfile($lang, $resfile) ?> &gt
+<?php dump_menu_resource($lang, $resfile, $type, $id) ?>
+<h1>Resource <?php echo "$id ($type)"?></h1>
 
 <?php
 
@@ -62,14 +64,14 @@ function dump_unicode_or_empty($uni_str)
 if (!$compare)
 {
     echo "<tr style=\"background-color: #e8e8ff\"><td colspan=\"2\" style=\"text-align: right\">";
-    echo "<small><a href=\"resource.php?lang=".urlencode($lang)."&resfile=".urlencode($resfile)."&type=".urlencode($type)."&id=".urlencode($id)."&compare=\">";
+    echo "<small>".gen_resource_a($lang, $resfile, $type, $id, TRUE);
     echo "Compare with ".$MASTER_LANGUAGE_NAME." &gt;&gt;</a></small>";
     echo "</td></tr>";
 }
 else
 {
     echo "<tr style=\"background-color: #e8e8ff\"><td colspan=\"3\" style=\"text-align: right\">";
-    echo "<small><a href=\"resource.php?lang=".urlencode($lang)."&resfile=".urlencode($resfile)."&type=".urlencode($type)."&id=".urlencode($id)."\">";
+    echo "<small>".gen_resource_a($lang, $resfile, $type, $id, FALSE);
     echo "&lt;&lt; Hide compare with ".get_lang_name($MASTER_LANGUAGE)."</a></small>";
     echo "</td></tr>";
 
@@ -102,4 +104,4 @@ for ($i=0; $i<16; $i++) {
 ?>
 </table>
 </body>
-</html>
\ No newline at end of file
+</html>




More information about the wine-cvs mailing list