Changeset 1070 in ExiteCMS


Ignore:
Timestamp:
11/06/07 15:39:37 (4 years ago)
Author:
root
Message:

update to add the locales table
added the locales cache directory
created the locale_load() function

Location:
trunk
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/administration/db_backup.php

    r954 r1070  
    5252            } else { 
    5353                gzwrite($fp, "#----------------------------------------------------------".$crlf); 
    54                 gzwrite($fp, "# PHP-Fusion SQL Data Dump".$crlf); 
     54                gzwrite($fp, "# ExiteCMS SQL Data Dump".$crlf); 
    5555                gzwrite($fp, "# Database Name: `".$db_name."`".$crlf); 
    5656                gzwrite($fp, "# Table Prefix: `".$db_prefix."`".$crlf); 
  • trunk/includes/locale_functions.php

    r1069 r1070  
    1111+----------------------------------------------------*/ 
    1212if (eregi("locale_functions.php", $_SERVER['PHP_SELF']) || !defined('INIT_CMS_OK')) die(); 
    13  
    14 // locale defines (no longer needed once we moved to the new locale system 
    15  
    16 define("PATH_LOCALE", PATH_ROOT."locale/"); 
    1713 
    1814// locale detection - step 1 - check if there's a locale cookie set 
     
    5854} 
    5955 
     56// locale defines (no longer needed once we moved to the new locale system!) 
     57 
     58define("PATH_LOCALE", PATH_ROOT."locale/"); 
     59 
    6060// locale detection - step 3 - use the website's default 
    6161if (!defined('LOCALESET')) { 
     
    6767 
    6868// Load the global language file 
    69 include PATH_LOCALE.LOCALESET."global.php"; 
     69locale_load("main.global"); 
    7070 
     71/*----------------------------------------------------+ 
     72| locale_functions include - general functions below  | 
     73+----------------------------------------------------*/ 
     74function locale_load($locale_name) { 
     75 
     76    global $settings, $locale; 
     77     
     78    // assemble the locale filename 
     79    $locales_file = PATH_ROOT."files/".$locale['locale'].".".$locale_name.".php"; 
     80 
     81    // check if we need to recompile from the database 
     82    if (dbtable_exists($prefix."locales")) { 
     83 
     84        // get the last update date from the locale strings table 
     85        $result = dbquery("SELECT MAX(locales_datestamp) as last_update FROM ".$db_prefix." WHERE locales_locale = '".$settings['locale']."' AND locales_name = '".$locale_name."'"); 
     86 
     87        // if found... 
     88        if ($data = dbarray($result)) { 
     89 
     90            // if the locales cache does not exist or is out of date... 
     91            if (!file_exists($locales_file) || filemtime($locales_file) < $data['last_update']) { 
     92 
     93                // compile the locales cache file from the locales table 
     94                if ($handle = fopen($locales_file, 'w')) { 
     95 
     96                    // get the locale records for the selected locale and this locale_name 
     97                    $result = dbquery("SELECT * FROM ".$db_prefix." WHERE locales_locale = '".$settings['locale']."' AND locales_name = '".$locale_name."' ORDER BY locales_key"); 
     98                    if (dbrows($result)) { 
     99                        fwrite($handle, "<?php"."\n"); 
     100                        fwrite($handle, "// ----------------------------------------------------------"."\n"); 
     101                        fwrite($handle, "// locale : ".$locale['locale']."\n"); 
     102                        fwrite($handle, "// name   : ".$locale_name."\n"); 
     103                        fwrite($handle, "// date   : ".date("D M j Y, G:i:s T")."\n"); 
     104                        fwrite($handle, "// ----------------------------------------------------------"."\n"); 
     105                    } 
     106                    while ($data = dbarray($result)) { 
     107                        fwrite($handle, "\$locale['".$data['locales_key']."'] = \"".$data['locales_value']."\"".";\n"); 
     108                    } 
     109                    fwrite($handle, "?>"."\n"); 
     110                    fclose($handle); 
     111                } 
     112            } 
     113        } 
     114    } 
     115 
     116    // if the locale file could not be found or generated, check if a static file exists in the 'old' location 
     117    if (!file_exists($locales_file)) { 
     118 
     119        // split the locale_name to determine the location of the file on disk 
     120        // name is in the form: moduletype.modulename, p.e. main.setup, or admin.articles, or modules.some_panel 
     121        $nameparts = explode(".", strtolower($locale_name)); 
     122 
     123        switch ($nameparts[0]) { 
     124 
     125            case "admin":   // admin modules 
     126                $locales_file = PATH_LOCALE.$settings['locale']."/admin/".$nameparts[1].".php"; 
     127                break; 
     128 
     129            case "main":    // main modules 
     130                $locales_file = PATH_LOCALE.$settings['locale']."/".$nameparts[1].".php"; 
     131                break; 
     132 
     133            case "modules": // installable modules & plugins 
     134                $locales_file = PATH_MODULES.$nameparts[1]."/locale/".$settings['locale'].".php"; 
     135                break; 
     136 
     137            case "tools":   // webmaster tools 
     138                $locales_file = PATH_ADMIN."tools/locale/".$nameparts[1].".php"; 
     139                break; 
     140 
     141            default: 
     142                // unknown module type 
     143        }        
     144    } 
     145     
     146    // if a locales file could be assembled, and it exists, load it 
     147    if (!empty($locales_file) && file_exists($locales_file)) { 
     148        include $locales_file; 
     149    } 
     150 
     151} 
    71152?> 
Note: See TracChangeset for help on using the changeset viewer.