Skip to content

Commit

Permalink
enhance language file loading to reduce dependency/errors from attemp…
Browse files Browse the repository at this point in the history
…ting to load files based on $_SESSION which may not be set; improve error reporting if xerte instance is unconfigured (suggest /setup if db is not working), reindent php files and remove references to database_library.php from everywhere but config.php

git-svn-id: https://xerteonlinetoolkits.googlecode.com/svn/branches/1.8@141 912cdd6b-5c7d-d5a7-a2ba-d0f0cdb91641
  • Loading branch information
Dave Goodwin committed Oct 18, 2011
1 parent 4f50144 commit da2ee5a
Show file tree
Hide file tree
Showing 116 changed files with 5,362 additions and 5,611 deletions.
37 changes: 25 additions & 12 deletions config.php
@@ -1,5 +1,4 @@
<?php

/**
*
* Config page, sets up the site variable from the database
Expand All @@ -21,7 +20,7 @@

// Change this to FALSE for production sites.
global $development;
$development = false;
$development = true;

ini_set('error_reporting', 0);
if($development) {
Expand All @@ -36,10 +35,23 @@ function _debug($string) {
}
}
}
if(!function_exists('_load_language_file')) {
function _load_language_file($file_path) {
if(isset($_SESSON['toolkits_language'])) {
$file_path = dirname(__FILE__) . '/languages/' . $_SESSION['toolkits_language'] . $file_path;
}
else {
// additional logic could use e.g. $_GET['language'] or $_COOKIE['language'] at this point... or something like Zend_Locale and HTTP accept headers...
// we'll just fall back to assuming en-gb if nothing else is specified here.
$file_path = dirname(__FILE__) . '/languages/en-gb/' . $file_path;
}
require_once($file_path);
return true;
}
}

if(!isset($xerte_toolkits_site)){


// create new generic object to hold all our config stuff in....
$xerte_toolkits_site = new StdClass();

Expand All @@ -51,9 +63,14 @@ function _debug($string) {
}

require_once("database.php");

require_once(dirname(__FILE__) . '/website_code/php/database_library.php');
if(!database_connect("","")) {
die("database.php isn't correctly configured; cannot connect to database; have you run /setup?");
}

$row = db_query_one("SELECT * FROM {$xerte_toolkits_site->database_table_prefix}sitedetails");

/**
* Access the database to get the variables
* @version 1.0
Expand Down Expand Up @@ -211,13 +228,9 @@ function _debug($string) {
array($session_handle,'xerte_session_clean'));
*/

session_start();

$_SESSION['toolkits_language'] = "en-gb";

$_SESSION['toolkits_sessionid'] = session_id();



session_start();
// fall back to en-gb if nothing is chosen elsewhere.
if(!isset($_SESSION['toolkits_language'])) {
$_SESSION['toolkits_language'] = "en-gb";
}
}

3 changes: 1 addition & 2 deletions data.php
Expand Up @@ -11,9 +11,8 @@

require_once("config.php");

require $xerte_toolkits_site->root_file_path . "languages/" . $_SESSION['toolkits_language'] . "/data.inc";
_load_language_file('data.inc');

require $xerte_toolkits_site->php_library_path . "database_library.php";
require $xerte_toolkits_site->php_library_path . "template_status.php";
require $xerte_toolkits_site->php_library_path . "display_library.php";

Expand Down
41 changes: 21 additions & 20 deletions database.php
@@ -1,36 +1,37 @@
<?PHP /**
*
* database page, has the settings for database connection
*
* @author Patrick Lockley
* @version 1.0
* @copyright Copyright (c) 2008,2009 University of Nottingham
* @package
*/
<?php
/**
*
* database page, has the settings for database connection
*
* @author Patrick Lockley
* @version 1.0
* @copyright Copyright (c) 2008,2009 University of Nottingham
* @package
*/

/*
* Host where database is
*/
* Host where database is
*/
$xerte_toolkits_site->database_host = "localhost";

/*
* Username for database
*/
* Username for database
*/
$xerte_toolkits_site->database_username ="root";

/*
* Password for database
*/
* Password for database
*/
$xerte_toolkits_site->database_password ="";

/*
* Database name
*/
* Database name
*/
$xerte_toolkits_site->database_name ="toolkits_data";

/*
* Database table prefix
*/
* Database table prefix
*/
$xerte_toolkits_site->database_table_prefix ="";

?>
?>

0 comments on commit da2ee5a

Please sign in to comment.