"Fossies" - the Fresh Open Source Software Archive

Member "betterawstats/core/language.inc.php" (17 Mar 2008, 5600 Bytes) of package /linux/www/old/betterawstats-1.0.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * betterawstats - an alternative display for awstats data
    4  *
    5  * @author      Oliver Spiesshofer, support at betterawstats dot com
    6  * @copyright   2008 Oliver Spiesshofer
    7  * @version     1.0
    8  * @link        http://betterawstats.com
    9 
   10  * Based on the GPL AWStats Totals script by:
   11  * Jeroen de Jong <jeroen@telartis.nl>
   12  * copyright   2004-2006 Telartis
   13  * version 1.13 (http://www.telartis.nl/xcms/awstats)
   14  *
   15  * This program is free software; you can redistribute it and/or
   16  * modify it under the terms of the GNU General Public License
   17  * as published by the Free Software Foundation; either version 2
   18  * of the License, or (at your option) any later version.
   19  *
   20  * This program is distributed in the hope that it will be useful,
   21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23  * GNU General Public License for more details.
   24  *
   25  * You should have received a copy of the GNU General Public License
   26  * along with this program; if not, write to the Free Software
   27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   28  */
   29 
   30 /**
   31  * File contents:
   32  *
   33  * This file coordinates the complete language-file processing.
   34  */
   35 
   36 
   37 // this is the main function that should coordinate reading all language ressources
   38 function baw_language() {
   39 // find out what our language is
   40 baw_detect_language();
   41 // include the AWSTATS language file
   42 baw_set_language();
   43 // include the BAW language file
   44 baw_select_internal_language();
   45 // read the AWSTATS tooltips
   46 // baw_get_tooltips();
   47 
   48 }
   49 
   50 function baw_set_language() {
   51     global $BAW_CONF, $BAW_MES;
   52 
   53     $path = $BAW_CONF['path_lang']."/awstats-{$BAW_CONF['lang']}.txt";
   54     if (!file_exists($path)) {
   55         // lets get an error-free error message
   56         $BAW_MES[58] = '';
   57         $BAW_MES['e'] = 'UTF-8';
   58         include_once($BAW_CONF['site_path'].'/language/lang_en.inc.php');
   59         echo baw_raise_error('languagefile', array($path));
   60         exit;
   61     } else {
   62         $alternative = $BAW_CONF['path_lang']."/awstats-en.txt";
   63         baw_read_lng_data($path, $alternative);
   64     }
   65 }
   66 
   67 // this is detecting the required language if not set to auto by config.
   68 // this is called only by baw_set_language()
   69 function baw_detect_language() {
   70     global $BAW_CONF;
   71     $lang = '';
   72     if ($BAW_CONF['lang_setting'] == 'auto') {
   73         baw_debug('dbg_detect_language');
   74         $acc_lang = explode(',', @$_SERVER['HTTP_ACCEPT_LANGUAGE']);
   75         foreach ($acc_lang as $lang) {
   76             $lang = strtolower(substr($lang, 0, 2));
   77             if (file_exists($BAW_CONF['path_lang'] . "/awstats-$lang.txt")) {
   78                 break;
   79             } else {
   80                 $lang = '';
   81             }
   82         }
   83         if (!$lang) {
   84             $lang = 'en';
   85         }
   86     } else {
   87         $lang = $BAW_CONF['lang_setting'];
   88     }
   89     $BAW_CONF['lang'] = $lang;
   90     baw_debug('dbg_detected_language', $lang);
   91 }
   92 
   93 // we assume that awstats has more translations than betterawstats
   94 // so we check if the one selected is available, otherwise include
   95 /// english.
   96 function baw_select_internal_language() {
   97     global $BAW_CONF;
   98     $lang = $BAW_CONF['lang'];
   99     $path = "{$BAW_CONF['site_path']}/language/lang_$lang.inc.php";
  100     if (file_exists($path)) {
  101         include_once($path);
  102     } else {
  103         $path = "{$BAW_CONF['site_path']}/language/lang_en.inc.php";
  104         include_once($path);
  105     }
  106 }
  107 
  108 // this function gets the file and returns the array
  109 // that is then added to the language file.
  110 function baw_read_lng_data($file, $alternative) {
  111     global $BAW_MES;
  112     $r = array();
  113     baw_debug("reading language data: $file");
  114     $lines = file($file);
  115     $encode_str = false;
  116     foreach ($lines as $line) {
  117         if (substr($line, 0, 7) == 'message') {
  118             $match = explode('=', $line);
  119             $match[0] = substr($match[0], 7);
  120             $r[$match[0]] = trim($match[1]);
  121         } else if (substr($line, 0, 8) == 'PageCode') {
  122             $encode_str = substr($line, 9);
  123             $r['e'] = $encode_str;
  124         }
  125     }
  126     // check that we have the whole file
  127     if (count($r) < 173) {
  128         baw_debug(
  129             "The language file is incomplete, only " . count($r)
  130             . "entries. Filling the rest with english"
  131         );
  132         $lines = file($alternative);
  133         foreach ($lines as $line) {
  134             if (substr($line, 0, 7) == 'message') {
  135                 $match = explode('=', $line);
  136                 $match[0] = substr($match[0], 7);
  137                 if (!isset($r[$match[0]])) {
  138                     $r[$match[0]] = trim($match[1]);
  139                 }
  140             }
  141         }
  142     }
  143     baw_debug("finished reading language data");
  144     $BAW_MES += $r;
  145 }
  146 
  147 function baw_get_tooltips() {
  148     global $BAW_CONF, $BAW_MES;
  149     $path = $BAW_CONF['path_lang']."/tooltips_w/awstats-tt-{$BAW_CONF['lang']}.txt";
  150     if (!file_exists($path)) {
  151         echo baw_raise_error('languagefile', array($path));
  152         $file_text = array();
  153     } else {
  154         $file_text = file_get_contents($path);
  155     }
  156     $search = array(
  157         "\n",
  158         "\r",
  159         "</div>",
  160         "<br />"
  161     );
  162     $replace = array(
  163         "",
  164         "",
  165         "",
  166         ""
  167     );
  168     $file_text = str_replace($search, $replace,$file_text);
  169     $file_text = explode('<div class="CTooltip" ', $file_text);
  170     array_shift($file_text);
  171     $pattern = '/id=\"tt(\d{1,3})\">(.*)/';
  172     foreach ($file_text as $line) {
  173         preg_match($pattern, $line, $match);
  174         $BAW_MES['tooltip'][$match[1]] = "<span>{$match[2]}</span>";
  175     }
  176 }
  177 ?>