[freeciv-i18n] Re: Manual translation and updates
[Top] [All Lists]
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
 
On Wed, Jan 22, 2003 at 08:41:48PM +0100, Christian Knoke wrote:
> 
> -- Binary/unsupported file stripped by Ecartis --
> -- Type: application/x-httpd-php
Ok, then:
manual.phtml
-------------------------------------------------------
<?php
// serves manual pages, corrects links, and inserts IMG attributes
// Accepted arguments: section and tiles
// No Doctype header, this will be inserted from the *.html file
  // include the php-code finder
  ini_set("include_path",
        ini_get("include_path") . ':' . $_SERVER['DOCUMENT_ROOT']
  );
  include_once("php_code/php_code_find.php");
  // includes for support routines
   include_once(php_code_find("fallback_find_file.php"));
   include_once(php_code_find("shared_variables.php"));
  function fallback_glob($pattern, $reldir = ".") {
    // search files both local and global, replace global with local files
    // if they do exist. Returns keyed array(filename => /path/to/filename)
    $arglobal = glob ($_SERVER['DOCUMENT_ROOT'] . "/$pattern");
    $arlocal = glob (dirname($_SERVER['SCRIPT_FILENAME']) . 
"/$reldir/$pattern");
    foreach ($arglobal as $path) { $ar[basename($path)] = $path;}
    foreach ($arlocal as $path) { $ar[basename($path)] = $path;}
    return $ar;
  }
  function man_error($what_error) {
    global $webmaster;
    echo "<table border=\"1\" style=\"font-size:xx-small\">\n";
    echo "<tr><th>$what_error</th><tr><td>";
    echo "Please contact the maintainer";
    if ($webmaster != "") {
      echo ", $webmaster";
    }
    echo ".</td></tr></table></font>\n";
  }
  function createTag ($part1, $pngname) {
    global $pngsize, $tiles;
    return $part1 . "src=\"{$tiles}/{$pngname}\" " . $pngsize[$pngname] . ">";
  }
  function createLink ($part1, $sect, $internal) {
    global $self, $tiles;
    return "{$part1}\"{$self}?section={$sect}&tiles={$tiles}{$internal}\">";
  }
  // initialize variables
  $self = basename($_SERVER["SCRIPT_NAME"]);
  $tilesets = array ("trident", "hires", "isotrident");
  $section = $_GET['section'];
  $tiles = $_GET['tiles'];
  if ($section == "") {$section = "over";}
  if ($tiles == "") {$tiles = "trident";}
  // valid url?
  if (!file_exists(fallback_find_file("manual/html/game-{$section}.html","..")) 
|| 
      !in_array ($tiles, $tilesets)) {
    // Bad URI's in the *.html files, bad (user manipulated?) links
    man_error("The requested manual section is not available.");
    exit;
  }
  
  // create files array with relative pathnames, local files have precedence
  $pngarray = fallback_glob("manual/$tiles/*.png", "..");
  // check for up to date *local* pngsize.spec
  $spec_valid = file_exists("$tiles/pngsize.spec");
  if ($spec_valid) {
    $stat = stat ("$tiles/pngsize.spec");
    $mtime = $stat[10];
    foreach ($pngarray as $filename => $path) {
      $stat = stat ($path);
      if ($stat[10] > $mtime) {
        $spec_valid = FALSE;
        break;
      }
    }
  }
  // read valid spec or create new one
  if ($spec_valid) {
    // read pngsize.spec and check
    $fd = fopen ("$tiles/pngsize.spec", "r");
    while (!feof ($fd)) {
      fscanf ($fd, "%s => %s %s\n", &$path, &$size1, &$size2);
      $filename = basename($path);
      $pngsize[$filename] = "$size1 $size2";
      if ($pngarray[$filename] != $path) { 
        $spec_valid = FALSE; 
        break;
      }
    }
    fclose ($fd);
    $spec_valid = $spec_valid && (count ($pngsize) == count ($pngarray));
    if (!$spec_valid) {
      // This should happen very rarely
      // If reload doesn't help, there is something essential wrong
      unlink ("$tiles/pngsize.spec");
      man_error("An Error has occured creating the manual page.<br>" . 
                "Please reload the page from the server.<br>" .
                "If this doesn't help:<br>");
      exit;
    }
  } else {
    // create pngsize data
    $pngsize = NULL;
    foreach ($pngarray as $filename => $path) {
      $size = GetImageSize ($path);
      $pngsize[$filename] = $size[3];
    }
    // write pngsize.spec
    $fd = fopen ("$tiles/pngsize.spec", "w");
    foreach ($pngsize as $filename => $sizestring) {
      fwrite ($fd, "$pngarray[$filename] => $sizestring\n");
    }
    if (!fclose ($fd)) { 
      // This means write errors
      man_error("Failed to create pngsize.spec file");
      exit;
    }
  }
  // read real manual section and replace links and img tags
  $htmlstr = file_get_contents(fallback_find_file(
             "manual/html/game-{$section}.html", ".."));
  // target looks like this: <img align="right" src="citywork.png">
  $htmlstr = preg_replace ('/(<img.+?)src=\s*"(.+?)"\s*>/e', 
             'createTag ("$1", "$2")', $htmlstr);
  // target looks like this: <a href="game-units.html#unit%3Asettlers">
  $htmlstr = preg_replace ('/(<a\s*href=\s*)"game-(\w+?)\.html([^"]*)">/e',
             'createLink ("$1", "$2", "$3")', $htmlstr);
  // output manual page
  print ($htmlstr);
?>
---------------------------------------------------------------
manphp.sh
--------------------------------------------------------------
#!/bin/bash
# run from /manual/ directory
# trident, isotrident, and hires directories need write permission for httpd
# also in website_l10n/de/.. they need to exist and have wr perm
mkdir html
mv trident/*.html trident/style.css html/
cd html
for i in *.html ; do
sed 's% height=".*" width=".*">%>%g' < $i > $i.new
mv $i.new $i
sed 's/href="game.html/href="game-over.html/g' < $i > $i.new
mv $i.new $i
sed 's%="style.css"%="html/style.css"%g' < $i > $i.new
mv $i.new $i
sed 's%href="/manual/"%href="./"%g' < $i > $i.new
mv $i.new $i
done
mv game.html game-over.html
---------------------------------------------------------------
manual.phtml.locale
-------------------------------------------------------------
<?php include($_SERVER["DOCUMENT_ROOT"] . "/mymanual/manual.phtml"); ?>
---------------------------------------------------------------
-- 
Christian Knoke     * * *      http://www.enter.de/~c.knoke/
* * * * * * * * *  Ceterum censeo Microsoft esse dividendum.
 
 
 | 
 |