<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -132,7 +132,7 @@ function load_class($class = NULL, $path = NULL, $params = NULL, $instantiate =
 		return TRUE;
 	}
 
-	return $objects[$class] = new $class(($params ? $params : ''));
+	return $objects[$class] = new $class($params);
 }
 
 
@@ -177,14 +177,11 @@ function _error_handler($level='', $message='', $file='', $line='', $variables='
 	//Get Human-safe error title
 	$error = $error_levels[$level];
 
-	//If we only show simple error data
-	if(DEBUG_MODE == FALSE) {
+	if(DEBUG_MODE) {
 
 		//Create sentence
 		$line_info = 'On line '. $line. ' in '. $file;
 
-	} else {
-
 		//If the database class is loaded - get the queries run (if any)
 		if(class_exists('db')) {
 			$db = db::get_instance();
@@ -551,7 +548,7 @@ function pagination($options=null) {
  */
 function log_message($message = '') {
 
-	$filepath = LOG_PATH. 'log-'. date('Y-m-d'). '.php';
+	$filepath = LOG_PATH. DOMAIN. '_log-'. date('Y-m-d'). '.php';
 
 	//Add a exit header to the file
 	if ( ! file_exists($filepath)) {
@@ -573,3 +570,75 @@ function log_message($message = '') {
 	return TRUE;
 }
 
+
+/**
+ * Header redirection for both location and refresh types.
+ *
+ * @param	string	the URL
+ * @param	string	the method: location or redirect
+ * @return	void
+ */
+function redirect($uri = '', $method = 'location', $http_response_code = 302) {
+
+	//Do we need to add the site URL prefix?
+	$uri = strpos($uri, '://') !== FALSE ? $uri : 'http://'. DOMAIN. SITE_URL . $uri;
+
+	if($method == 'refresh') {
+		header(&quot;Refresh:0;url=&quot;. $uri);
+	} else {
+		header(&quot;Location: &quot;. $uri, TRUE, $http_response_code);
+	}
+	exit;
+}
+
+
+/**
+ * Return the site url prefixed to the uri path
+ * @param $uri
+ * @return unknown_type
+ */
+function site_url($uri = '') {
+	return SITE_URL. trim($uri, '/'). '/';
+}
+
+
+/**
+ * Fetch a $_POST value (or the default if not found)
+ * @param	string	$key
+ * @param	mixed	$value
+ * @return	mixed
+ */
+function post($key, $value = NULL) {
+	return isset($_POST[$key]) ? $_POST[$key] : $value;
+}
+
+
+/**
+ * Fetch the $_SESSION value (or default if not found)
+ * @param	string	$key
+ * @param	mixed	$value
+ * @return	mixed
+ */
+function session($key, $value = NULL) {
+	return isset($_SESSION[$key]) ? $_SESSION[$key] : $value;
+}
+
+
+/**
+ * Encode a string so it is safe to pass through the URI
+ * @param	string	$string
+ * @return	string
+ */
+function base64_url_encode($string=null){
+  return strtr(base64_encode($string), '+/=', '-_~');
+}
+
+
+/**
+ * Decode a string passed through the URI
+ * @param	string	$string
+ * @return	string
+ */
+function base64_url_decode($string=null) {
+  return base64_decode(strtr($string, '-_~','+/='));
+}
\ No newline at end of file</diff>
      <filename>functions/common.php</filename>
    </modified>
    <modified>
      <diff>@@ -280,18 +280,37 @@ function mime_type($type = NULL) {
  * @param	string	$ext
  * @return	void
  */
-function download_document($content = '', $ext = ''){
+function download_file($content = '', $ext = '', $filename = NULL){
 
 	//Try to get the mime type
 	if( ! $mime = mime_type($ext)) {
 		$mime = 'application/octet-stream';
 	}
 
-	//Send header data
-	header(&quot;Cache-Control: must-revalidate, post-check=0, pre-check=0&quot;);
-	header('Content-Disposition: attachment; filename='.time(). $ext);
-	header(&quot;Content-Length: &quot; . mb_strlen($content));
-	header(&quot;Content-Type: $mime&quot;);
+	//Create a random filename
+	if( ! $filename) {
+		$filename = time(). '.'. $ext;
+	}
+
+	// Generate the server headers
+	if (strstr($_SERVER['HTTP_USER_AGENT'], &quot;MSIE&quot;)) {
+		header('Content-Type: &quot;'.$mime.'&quot;');
+		header('Content-Disposition: attachment; filename=&quot;'.$filename.'&quot;');
+		header('Expires: 0');
+		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+		header(&quot;Content-Transfer-Encoding: binary&quot;);
+		header('Pragma: public');
+		header(&quot;Content-Length: &quot;.strlen($data));
+
+	} else {
+		header('Content-Type: &quot;'.$mime.'&quot;');
+		header('Content-Disposition: attachment; filename=&quot;'.$filename.'&quot;');
+		header(&quot;Content-Transfer-Encoding: binary&quot;);
+		header('Expires: 0');
+		header('Pragma: no-cache');
+		header(&quot;Content-Length: &quot;.strlen($data));
+	}
+
 
 	//Send file
 	exit($content);</diff>
      <filename>functions/mimes.php</filename>
    </modified>
    <modified>
      <diff>@@ -17,20 +17,22 @@
 class controller {
 
 	//Data for final site layout
-	public $views = array();
+	public $views	= array();
 	//Name of final site layout file
-	public $layout = 'layout';
+	public $layout	= 'layout';
 	//Singleton instance object
 	private static $instance;
 	//Config array
-	public $config = array();
+	public $config	= array();
+	//Language array
+	public $lang	= array();
 
 
 	/**
 	 * Setup some basic controller items on load
 	 * @param array $config
 	 */
-	public function __construct($config=null) {
+	public function __construct($config = null) {
 
 		//Set singleton instance
 		self::$instance =&amp; $this;
@@ -142,7 +144,9 @@ class controller {
 
 	/**
 	 * Load a config file
-	 * @param string $config
+	 * @param string $name
+	 * @param string $module
+	 * @return array
 	 */
 	public function load_config($name=null, $module = FALSE) {
 
@@ -167,6 +171,33 @@ class controller {
 
 
 	/**
+	 * Load a language file
+	 * @param string $name
+	 * @param string $module
+	 * @return array
+	 */
+	public function load_lang($name=null, $module = FALSE) {
+
+		//If this lang file was already loaded
+		if( ! empty($this-&gt;lang[$name])) {
+			return $this-&gt;lang[$name];
+		}
+
+		//Is this a module's config -or a site config?
+		$path = $module ? MODULE_PATH. $module. DS : SITE_PATH;
+
+		//Add the rest of the path
+		$path .= 'lang'. DS. $this-&gt;config['config']['language']. DS. $name. '.php';
+
+		//include the config
+		require($path);
+
+		//Set the values in our config array and return a copy too
+		return $this-&gt;lang[$name] = $lang;
+	}
+
+
+	/**
 	 * Load and initialize the database connection
 	 * @param array $config
 	 */</diff>
      <filename>libraries/controller.php</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@
 class validation {
 
 	//The Parent Controller Instance
-	public $instance		= NULL;
+	public $mvc				= NULL;
 	//An array of error messages
 	public $error_messages	= array();
 	//The array to hold form errors (if any)
@@ -25,14 +25,20 @@ class validation {
 	//The text to put before an error
 	public $error_prefix	= '&lt;p&gt;';
 	//The text to put after an error
-	public $error_sufix		= '&lt;/p&gt;';
+	public $error_suffix	= '&lt;/p&gt;';
 
 
 	/*
-	 * Get the Controller instance on load
+	 * Get the Controller mvc on load
 	 */
-	public function __construct() {
-		$this-&gt;instance = get_instance();
+	public function __construct($config = NULL) {
+
+		//Get the instance
+		$this-&gt;mvc = get_instance();
+
+		if($config) {
+			$this-&gt;setup($config);
+		}
 
 		//Set error messages
 		$this-&gt;error_messages = array(
@@ -52,6 +58,27 @@ class validation {
 	}
 
 
+	/**
+	 * Set the config for the validation run
+	 * @param	array	$config
+	 * @return	void
+	 */
+	public function setup($config) {
+		$this-&gt;config = $config;
+	}
+
+
+	/**
+	 * Add a field and the matching rules to our config
+	 * @param	string	$field
+	 * @param	string	$rules
+	 * @return	void
+	 */
+	public function set_rule($field = NULL, $rules = '') {
+		$this-&gt;config[$field] = $rules;
+	}
+
+
 	/*
 	 * Check and Filter the $_POST data submited to us.
 	 *
@@ -60,13 +87,18 @@ class validation {
 	 * first in the controller, then in this class, and
 	 * finally as just a function.
 	 */
-	public function run($config=null) {
+	public function run($config = NULL) {
 
 		//Reset error array
 		$this-&gt;errors = array();
 
+		//If the rules were not passed, then see if they are pre-set
+		if( ! $config) {
+			$config = $this-&gt;config;
+		}
+
 		//No rules?
-		if(! $config) {
+		if( ! $config) {
 			$this-&gt;errors['no_rules'] = $this-&gt;error_messages['no_rules'];
 			return FALSE;
 		}
@@ -131,8 +163,8 @@ class validation {
 				}
 
 				//Look for it in the current controller
-				if(method_exists($this-&gt;instance, $rule)) {
-					$result = $this-&gt;instance-&gt;$rule($field, $data, $params);
+				if(method_exists($this-&gt;mvc, $rule)) {
+					$result = $this-&gt;mvc-&gt;$rule($field, $data, $params);
 
 					//Look for it in this class
 				} elseif(method_exists($this, $rule)) {
@@ -193,7 +225,7 @@ class validation {
 		$output = '';
 		//Format each error
 		foreach($this-&gt;errors as $error) {
-			$output .= $this-&gt;error_prefix. $error. $this-&gt;error_sufix. &quot;\n\n&quot;;
+			$output .= $this-&gt;error_prefix. $error. $this-&gt;error_suffix. &quot;\n\n&quot;;
 		}
 
 		//Return the full errors string</diff>
      <filename>libraries/validation.php</filename>
    </modified>
    <modified>
      <diff>@@ -8,6 +8,8 @@ $config['default_controller'] = 'welcome';
 $config['default_method'] = 'index';
 //Characters to allow in the URI string ($_GET data)
 $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
+//Language
+$config['language'] = 'english';
 
 //Enable error reporting?
 //error_reporting(E_ALL|E_STRICT);</diff>
      <filename>localhost/config/config.php</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 /* PDO MySQL Database Config */
 $database= array(
 	'type'	=&gt; 'mysql',
-	'dns'	=&gt; 'host=127.0.0.1;dbname=pdo_test',
+	'dns'	=&gt; 'host=127.0.0.1;dbname=micromvc',
 	'port'	=&gt; '3306',
 	'name'	=&gt; '',
 	'user'	=&gt; 'root',</diff>
      <filename>localhost/config/database.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>785f5828f655d09cb23c6bf17ed97c877eb2262b</id>
    </parent>
  </parents>
  <author>
    <name>Xeoncross</name>
    <email>david@xeoncross.com</email>
  </author>
  <url>http://github.com/Xeoncross/micromvc/commit/0ddb2b69fdbf11e515b7335a12343d11d5d88406</url>
  <id>0ddb2b69fdbf11e515b7335a12343d11d5d88406</id>
  <committed-date>2009-07-16T12:04:01-07:00</committed-date>
  <authored-date>2009-07-16T12:04:01-07:00</authored-date>
  <message>Added the redirect(), post(), session(), site_url(), base64_url_(en/de)code() helper functions. Fixed the file name of log files. Added line &amp; file infomation to errors. Added language support to system. Added more config options for validation class.</message>
  <tree>bd43b85d7732b62cdd170f27a770046cddbd3576</tree>
  <committer>
    <name>Xeoncross</name>
    <email>david@xeoncross.com</email>
  </committer>
</commit>
