⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 translation.class.php

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/** * File translation.class.php * * @package Translation */
/**
 * require dependencies
 */require_once 'PEAR.php';
require_once 'DB.php';

/**
 * Translation class
 *
 * Class allows storing and retrieving all the strings on multilingual site
 * in a database.
 * The class connects to any database using PEAR::DB extension - so it needs
 * PEAR to be installed to work correctly.
 * The object should be created for every page. While creation all the strings
 * connected with specific page and the strings connected with all the pages
 * on the site are loaded into variable, so accessing them is quite fast and
 * does not overload database server connection.
 * The class can reuse existing DB connections. To do so just pass to the
 * constructor the handle for the connection instead of DSN.
 *
 * @author Wojciech Zieli駍ki <voyteck@caffe.com.pl>
 * @version 1.2.3
 * @access public
 * @package Translation
 */
class Translation extends PEAR {

    /**
     * The translations are retrieved from this class object
     * @see Translation(), gstr(), getLangName(), getOtherLangs(), getMetaTags
     */

    /**
     * Strings of the given page array
     *
     * This one is for fast access to cached strings for specified page
     *
     * @var array string $Strings
     */
	var $Strings = array();

    /**
     * Page identifier
     *
     * @var string $PageName
     */
	var $PageName = '';

    /**
     * Language identifier
     *
     * @var string $LanguageID
     */
	var $LanguageID = '';

    /**
     * Connection to database
     *
     * @var object DB $db
     */
	var $db;

    /**
     * Is true if the connection was reused, not made from the class
     *
     * @var int $ConnectionReused
     */
	var $ConnectionReused;

    /**
     * The string that will be displayed, if no string has been found in the
     * DB for specified string_id
     * @var string $ErrorText
     */
	var $ErrorText;

    /**
     * The array with table and column names
     *
     * The table may have following items:
     *
     * 'langsavail' - table, in which all the information of the possible languages
     * is kept. This array item may be the string - then the structure of the table
     * remains as original, but the name is specified here; or the array with the
     * following items:
     * 'name' - the name of the table - default is 'tr_langsavail'
     * 'lang_id' - the column that stores the language identifier - default
     * is 'lang_id'
     * 'lang_name' - the column that stores the language name - default
     * is 'name'
     * 'metatags' - the column that stores meta tags for the pages in specified
     * language - default is 'metatags'
     * 'errortext' - the column that stores the text that will be displayed in case
     * if some text will not be found in the DB - default is 'errortext'
     *
     * 'strings_XX' - table, in which the strings of language "XX" (the
     * corresponding lang_id) are kept. This array item may be the string - then
     * the structure of the table remains as original, but the name is specified
     * here; or the array with the following items:
     * 'name' - the name of the table - default is 'tr_strings_XX'
     * 'page_id' - the page identifier - default is 'page_id'.
     * 'string_id' - the string indetifier - default is 'string_id'.
     * 'string' - the string itself - default is 'string'.
     *
     * This parameter in fact has impact only if the DB is used as the strings
     * repository. The defaults are set in the way that the method is compatible
     * with lower versions.
     *
     * @var array $CustomTables
     */
	var $TableDefinitions;

    /**
     * Class constructor
     *
     * @param string $PageName	the page identifier. It identifies
     * strings connected with specific page on the site
     * @param string $LanguageID language id. All the languages
     * are stored on the database on specific ID's.
     * @since version 1.2.1
     * @param string $pear_DSN	This might be 3 types: the PEAR DSN
     * string form making the connection; the PEAR DB connection handle;
     * the string has the following format:
     * gettext://LOCALE:LANG:BINDTXTDOMAIN:TXTDOMAINFILE:TXTDOMAIN:CFGFILE
     * for using the native PHP gettext support.
     * @param array $CustomTables				This is the array of the names of the tables and
     * optionally the names of columns. It contains the following elements:
     */
	function Translation($PageName, $LanguageID, $pear_DSN, $CustomTables = 0)
	{
		$this->PageName   = $PageName;
		$this->LanguageID = $LanguageID;
		if (!DB::isConnection($pear_DSN)) {
			$this->db = DB::connect($pear_DSN);
			$this->ConnectionReused = 0;
		} else {
			$this->db = $pear_DSN;
			$this->ConnectionReused = 1;
		}
		if (DB::isError($this->db)) {
			die ($this->db->getMessage());
		}

	    $this->TableDefinitions = array(
	            'langsavail' => array(
	                    'name'      => 'tr_langsavail',
	                    'lang_id'   => 'lang_id',
	                    'lang_name' => 'name',
	                    'metatags'  => 'metatags',
	                    'errortext' => 'errortext'
	            )
        );
		if (is_array($CustomTables['langsavail'])) {
			$this->TableDefinitions['langsavail']['name']      = isset($CustomTables['langsavail']['name'])      ? $CustomTables['langsavail']['name']      : 'tr_langsavail';
			$this->TableDefinitions['langsavail']['lang_id']   = isset($CustomTables['langsavail']['lang_id'])   ? $CustomTables['langsavail']['lang_id']   : 'lang_id';
			$this->TableDefinitions['langsavail']['lang_name'] = isset($CustomTables['langsavail']['lang_name']) ? $CustomTables['langsavail']['lang_name'] : 'lang_name';
			$this->TableDefinitions['langsavail']['metatags']  = isset($CustomTables['langsavail']['metatags'])  ? $CustomTables['langsavail']['metatags']  : 'metatags';
			$this->TableDefinitions['langsavail']['errortext'] = isset($CustomTables['langsavail']['errortext']) ? $CustomTables['langsavail']['errortext'] : 'errortext';
		} elseif (!empty($CustomTables['langsavail'])) {
			$this->TableDefinitions['langsavail']['name'] = $CustomTables['langsavail'];
		}
		$result = $this->db->query('SELECT ' . $this->TableDefinitions['langsavail']['lang_id'] . ' FROM ' . $this->TableDefinitions['langsavail']['name']);
		if (DB::isError($result)) {
			die ($result->getMessage());
		}
		while ($row = $result->fetchRow()) {
			$this->TableDefinitions['strings_'.$row[0]] = array(
			        'name'      => 'tr_strings_'.$row[0],
			        'page_id'   => 'page_id',
			        'string_id' => 'string_id',
			        'string'    => 'string'
			);
			if (is_array($CustomTables['strings_'.$row[0]])) {
				$this->TableDefinitions['strings_'.$row[0]]['name']      = isset($CustomTables['strings_'.$row[0]]['name'])      ? $CustomTables['strings_'.$row[0]]['name']      : 'strings_'.$row[0];
				$this->TableDefinitions['strings_'.$row[0]]['page_id']   = isset($CustomTables['strings_'.$row[0]]['page_id'])   ? $CustomTables['strings_'.$row[0]]['page_id']   : 'page_id';
				$this->TableDefinitions['strings_'.$row[0]]['string_id'] = isset($CustomTables['strings_'.$row[0]]['string_id']) ? $CustomTables['strings_'.$row[0]]['string_id'] : 'string_id';
				$this->TableDefinitions['strings_'.$row[0]]['string']    = isset($CustomTables['strings_'.$row[0]]['string'])    ? $CustomTables['strings_'.$row[0]]['string']    : 'string';
			} elseif (!empty($CustomTables['strings_'.$row[0]])) {
				$this->TableDefinitions['strings_'.$row[0]]['name'] = $CustomTables['strings_'.$row[0]];
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -