Filter:   InfoImg
download strings.php
Language: PHP
LOC: 110
Project Info
Virtual Photo Album(vphotoalb)
Server: SourceForge
Type: cvs
...alb\vphotoalb\html\include\
   .htaccess
   antispam.php
   constants.php
   db.php
   db_my.php
   db_pg.php
   db_schema.php
   faq_strings.php
   form.php
   functions.php
   globals.php
   html.php
   html_verifier.php
   ImageProcessing.php
   input.php
   mime.php
   originals.php
   PictureFinder.php
   queries.php
   read_exif_data.php
   read_tiff_data.php
   SearchParameters.php
   security.php
   strings.en.php
   strings.fr.php
   strings.php
   tables.php

<?php
/* Global strings for all languages.
 *
 * Written by: Chris Studholme
 * Copyright:  GPL (http://www.fsf.org/copyleft/gpl.html)
 * $Id: strings.php,v 1.16 2002/11/08 23:24:54 cstudhol Exp $
 */


/* List of supported languages.
 */
$supported_lang=array("en"=>"English",
		      "fr"=>"Fran&ccedil;ais");

/* Local strings.  These are set in individual pages if necessary.
 */
$strings_local = array();

/* Global strings.  These are set in strings.*.php.
 */
$strings_global = array();

/* For security reasons, $strings is initialized here.  Use get_strings()
 * to set $strings where needed.
 */
$strings = false;
$lang = false;

// language input
function input_lang($str="lang",$usedefault=true) {
    global $HTTP_GET_VARS, $HTTP_POST_VARS;
    global $supported_lang,$default_lang;
    if ($supported_lang[$HTTP_POST_VARS[$str]])
	return $HTTP_POST_VARS[$str];
    if ($supported_lang[$HTTP_GET_VARS[$str]])
	return $HTTP_GET_VARS[$str];
    return $usedefault ? $default_lang : "";
}

/* Make sure the string is valid language.
 */
function check_lang($lang,$usedefault=true) {
    global $supported_lang,$default_lang;
    if ($supported_lang[$lang])
	return $lang;
    if ($usedefault)
	return $default_lang;
    return "";
}

/* Find most appropriate version of string.  $a can be one of the following:
 *   - a simple string (it's returned)
 *   - a string representing a serialized associative array with lang as key
 *   - an associative array with lang as key
 * The most appropriate string available given the current values of $lang, 
 * $cookie_record, $config, and $default_lang is returned.
 */
function best_lang($a) {
  global $lang,$cookie_record,$config,$default_lang;

  // check if $a is a serialized array
  if (is_string($a)) {
    $serialized=false;
    if (ereg("^a:([0-9]+):\{(.*)\}$",$a,$regs)) {
      $c = (int)$regs[1];
      if ($c>0) {
	$s = $regs[2];
	$serialized=true;
	for ($c*=2; $c>0; --$c) {
	  if (ereg("^s:([0-9]+):\"(.*)$",$s,$regs)) {
	    if (substr($regs[2],$regs[1],2)!="\";") {
	      $serialized=false;
	      break;
	    }
	    $s = substr($regs[2],2+$regs[1]);
	  }
	  else {
	    $serialized=false;
	    break;
	  }
	}
	if (strlen($s)>0) {
	  $serialized=false;
	  break;
	}
      }
    }
    if ($serialized)
      $a = unserialize($a);
    else 
      return $a;
  }

  // make sure $a is an array
  if (!is_array($a))
    return strval($a);

  // find most appropriate string (language) from $a
  if ($a[$lang])
    return $a[$lang];
  if ($a[$cookie_record["lang"]])
    return $a[$cookie_record["lang"]];
  if ($a[$config["default_lang"]])
    return $a[$config["default_lang"]];
  if ($a[$default_lang])
    return $a[$default_lang];
  reset($a);
  return current($a);
}


/* Get array of strings for use on this page.  The strings will be a merge
 * of $strings_global and $strings_local, with $strings_local taking
 * precidence.  If $page is false or invalid, it will be determined from
 * the name of the page (ie. SCRIPT_NAME).  The page name is used to figure
 * out appropriate titles for the page.
 * Globals $lang and $default_lang will also be set by this function.
 */
function get_strings($page=false, $preferred_lang=false) {
  global $HTTP_GET_VARS, $HTTP_POST_VARS;
  global $default_lang,$config,$cookie_record;
  global $supported_lang,$strings_global,$strings_local;
  global $strings, $lang;

  // set default_lang
  if ($supported_lang[$cookie_record["lang"]])
    $default_lang=$cookie_record["lang"];
  else if ($supported_lang[$config["default_lang"]])
    $default_lang=$config["default_lang"];

  // figure out what language we want
  $newlang = $preferred_lang;
  if (!$supported_lang[$newlang])
    $newlang = $lang;
  if (!$supported_lang[$newlang])
    $newlang = $HTTP_POST_VARS["lang"];
  if (!$supported_lang[$newlang])
    $newlang = $HTTP_GET_VARS["lang"];
  if (!$supported_lang[$newlang])
    $newlang = $default_lang;

  // return early if strings is already set
  if (is_array($strings)&&($lang==$newlang))
    return $strings;

  if (!$strings_global[$newlang])
    require("include/strings.".$newlang.".php");

  $lang = $newlang;
  $strings = array_merge($strings_global[$lang],$strings_local[$lang]);

  if (!$page||!$strings["title"][$page]) {
    // figure out what page this is
    if (ereg("/([^/]*)[.]php$",getenv("SCRIPT_NAME"),$regs))
      $page = $regs[1];
    else
      $page=false;
  }
  if ($strings["title"][$page]) {
    reset($strings["title"][$page]);
    while (list($t,$s)=each($strings["title"][$page])) {
      if (!$strings["title_".$t])
	$strings["title_".$t] = $s;
    }
  }
  return $strings;
}

?>