<?php if(!defined('master_script')) die();

/**
 * Include language files
 *
 * @param      string $key
 * @param      string $path Path to language files
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2011-12-02
 */
	
	function include_txt($key, $path) {
		global $user_data, $system_data;
		
		$paths = array(
			'system' => $path,
			'template' => str_replace($system_data['folder']['sources'], $system_data['folder']['templates'] . $user_data['frontend template'] . '/', $path),
		);
		
		if(is_dir($paths['system'])) {
			if(is_file($paths['system'] . language . '.php')) {
				require_once($paths['system'] . language . '.php');
			}
		}
		
		if(is_dir($paths['template'])) {
			if(is_file($paths['template'] . language . '.php')) {
				require_once($paths['template'] . language . '.php');
			}
		}
	}
	
/**
 * Translate string
 *
 * @param      string $key
 * @param      string $text Text to translate
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2011-12-02
 */

	function txt($key, $text = false) {
		global $system_data;
		
		return isset($system_data['txt'][$key][$text]) ? $system_data['txt'][$key][$text] : $text;
	}

/**
 * Cut text after x chars and add text
 *
 * @param      string $text
 * @param      int $limmit Number of chars
 * @param      string $replace String to add after cutted text
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-11-19
 */
	
	function limit_text($text, $limit, $replace = '', $word_cutting = true) {
		$string_length = strlen(htmlspecialchars_decode($text));
	    
	    if($string_length > $limit) {
	    	$text = substr($text, 0, $limit);
	    	if($word_cutting == false && strpos($text, ' ') > 0) $text = substr($text, 0, strrpos($text, ' '));
	    	$text .= $replace;
	    }
	    
	    return $text;
	}

/**
 * Create human readable file sizes
 *
 * @param      float $size File size in bytes
 * @param      bool $retstring
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	function format_filesize($size, $retstring = null) {
		$sizes = explode(',', txt('global', 'B,KB,MB,GB,TB,PB,EB,ZB,YB'));
		if($retstring === null) $retstring = '%01.2f %s';
		$lastsizestring = end($sizes);

		foreach($sizes as $sizestring) {
			if($size < 1024) break;
			if($sizestring != $lastsizestring) $size /= 1024;
		}
    	
    	if($sizestring == $sizes[0]) $retstring = '%01d %s';
    	return sprintf($retstring, $size, $sizestring);
	}

/**
 * Get file type by file extension
 *
 * @param      string $string File extension
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	function get_file_type($string) {
		switch($string) {
			case 'gif' : case 'jpg' : case 'jpeg' : case 'png' : case 'bmp' : $string = 'image'; break;
			case 'mov' : case 'avi' : case 'wmv' : case 'fla' : case 'asf' : case 'ram' : $string = 'video'; break;
			case 'mp3' : case 'wma' : case 'aiff' : case 'au' : case 'wav' : case 'ra' : $string = 'audio'; break;
		}
		
		return $string;
	}

/**
 * Transcribe a string
 *
 * @param      string $sString A field value or other user generated data
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2010-01-30
 */
	
	function transcribe($string, $is_dir = false) {
		$string = trim($string);
		$string = mb_strtolower(html_entity_decode($string));
		
		$search = array('/ß/', '/ä/', '/ö/', '/ü/', '/&/', '/–/', '/\'/', '/"/', $is_dir == false ? '([^a-z0-9._]+)' : '([^a-z0-9_]+)');
		$replace = array('ss', 'ae', 'oe', 'ue', 'and', '-', '', '', '-');
		
		$string = preg_replace($search, $replace, $string);
		$string = htmlentities($string);
		$string = preg_replace("/&(.)(uml);/", "$1e", $string);
		$string = preg_replace("/&(.)(acute|cedil|circ|ring|tilde|uml);/", "$1", $string);
		$string = preg_replace($is_dir == false ? "/([^a-z0-9._]+)/" : "/([^a-z0-9_]+)/", "-", html_entity_decode($string));

		return trim($string, "-");
	}

/**
 * Create random string
 *
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */
	
	function random_string() {
		$chars = "abcdefghijkmnopqrstuvwxyz023456789";
		srand((double)microtime() * 1000000);
		$i = 0;
		$string = '' ;
		
		while($i <= 7) {
			$num = rand() % 33;
			$tmp = substr($chars, $num, 1);
			$string = $string . $tmp;
			$i++;
		}
		
		return $string; 
	} 

/**
 * Custom strip_tags function
 *
 * @param      string $content Source string
 * @param      bool $php Strip PHP code
 * @param      bool $javascript Strip JavaScript code
 * @param      bool $style Strip CSS style tags
 * @param      bool $html Strip HTML code
 * @param      bool $comments Strip HTML comments
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	function strip_custom_tags($content, $php = true, $javascript = true, $style = true, $html = true, $comments = true) {
		$search = array();
		
		if($php == true) array_push($search, '@<[\?%].*[\?%]>@ms');
		if($javascript == true) array_push($search, '@<script[^>]*?>.*?</script>@si');
		if($style == true) array_push($search, '@<style[^>]*?>.*?</style>@siU');
		if($html == true) array_push($search, '@<[\/\!]*?[^<>]*?>@si');
		if($comments == true) array_push($search, '@<![\s\S]*?--[ \t\n\r]*>@');
		
		$content = preg_replace($search, '', $content);
		return trim($content);
	}

/**
 * Simple string cleaning
 *
 * @param      string $string
 * @param      bool $strip_tags Use strip_tags()
 * @param      bool $decode Use htmlspecialchars()
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	function clean_string($string, $strip_tags = false, $decode = true) {
		$string = stripslashes($string);
		if($strip_tags == true) $string = strip_tags($string);
		if($decode == true) $string = htmlspecialchars($string, ENT_QUOTES);
		$string = trim($string);
		return $string;
	}

/**
 * Return validated email address
 *
 * @param      string $email
 * @return     string
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	function is_email($email = null) {
		return preg_match("/^[\d\w\/+!=#|$?%{^&}*`'~-][\d\w\/\.+!=#|$?%{^&}*`'~-]*@[A-Z0-9][A-Z0-9.-]{1,61}[A-Z0-9]\.[A-Z]{2,6}$/ix", $email);
	}

/**
 * Get size of folder
 *
 * @param      string $path
 * @return     float
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-06-28
 */
    
	function dirsize($path) {
		if(!file_exists($path)) return 0;
		if(is_file($path)) return filesize($path);
		$self = __FUNCTION__;
		$return = 0;
		$glob = glob($path . "/*");
		if($glob) foreach($glob as $filename) $return += $self($filename);
		return $return;
	}

/**
 * Delete a folder recursive
 *
 * @param      string $path
 * @return     numeric
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	function rec_rmdir($path) {
	    if(!is_dir ($path)) return 1;
	    $dir = @opendir($path);
	    if(!$dir) return 2;
	
	    while($entry = @readdir($dir)) {
	    	if($entry == '.' || $entry == '..') continue;
	    	if(is_dir($path . '/' . $entry)) {
	    		$res = rec_rmdir($path . '/' . $entry);
	    		if($res == 1) { @closedir($dir); return 2; } else if($res == 2) { @closedir($dir); return 2; } else if($res == 3) { @closedir($dir); return 3; } else if($res != 0) { @closedir($dir); return 2; }
	    	} else if(is_file($path . '/' . $entry) || is_link($path . '/' . $entry)) {
	    		$res = @unlink($path . '/' . $entry);
	    		if(!$res) { @closedir ($dir); return 2; }
	    	} else {
	    		@closedir($dir);
	    		return 3;
	    	}
	    }
	
	    @closedir($dir);
	    $res = @rmdir($path);
	
	    if(!$res) return 2;
	    return 0;
	}
	
/**
 * Save user data vars to user settings file
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

    function save_user_data() {
    	global $system_data, $user_data;
    	
    	$open_user_config_file = fopen($system_data['folder']['settings'] . 'settings.php', 'wb');
    	fputs($open_user_config_file, '<?php' . "\n");
    	
    	foreach($user_data as $key => $value) {
   			if(is_string($value)) $value = '"' . $value . '"';
    		if(is_array($value)) $value = 'array("' . implode('", "', $value) . '")';
    		fputs($open_user_config_file, '	$user_data["' . $key . '"] = ' . $value . ';' . "\n");
		}
		
		fputs($open_user_config_file, '?>');
		fclose($open_user_config_file);
	}

/**
 * Display system error message
 *
 * @param      string $message
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-06-27
 */

	function stop_script($message) {
    	global $system_data, $user_data;
		
		if(isset($message)) include($system_data['folder']['backend']. $system_data['file']['error template index']);
		die();
	}

/**
 * Include a page by name
 *
 * @param      string $page_name Without path
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-06-26
 */

    function include_page($page_name) {
    	global $system_data, $module_settings;
    	
    	$page_file = $system_data['folder']['pages'] . $page_name . '/' . $system_data['file']['index page'];
    	if(is_file($page_file)) include($page_file);
    	
    	connector('include_page');
    }

/**
 * Include a module by name
 *
 * @param      string $module_name
 * @param      bool $include_in_feeds If false just return the module path
 * @return     string Module path or false
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2010-02-05
 */

    // Include module
    function include_module($module_name, $include_in_feeds = true) {
    	global $simulate_feed_script, $user_data, $system_data, $module_settings;
    	
    	if(defined('feed_script') || $simulate_feed_script == 'true') {
    		if($include_in_feeds == false) return false;
    		$module_settings[$module_name]['language'] = '';
    	}

   		$module_path = $system_data['folder']['modules'] . $module_name . '/';
    	
    	$module_settings[$module_name]['language'] = isset($module_settings[$module_name]['language']) ? $module_settings[$module_name]['language'] : '';
    	if(!is_array($module_settings[$module_name]['language'])) $module_settings[$module_name]['language'] = explode(',', $module_settings[$module_name]['language']);
    	
    	if($module_settings[$module_name]['language'][0] == '' || in_array($_SESSION['language'], $module_settings[$module_name]['language'])) {
	   		if(file_exists($module_path . $system_data['file']['frontend module']))
	   			include($module_path . $system_data['file']['frontend module']);
    	}
    	
    	return $module_path;
    	
    	connector('include_module');
    }

/**
 * Get module path (without false return as in include_module)
 *
 * @param      string $module_name
 * @return     string Module path
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

    function get_module_path($module_name) {
    	global $user_data, $system_data;

   		$system_module_path = $system_data['folder']['modules'] . $module_name . '/';
   		$template_module_path = $system_data['folder']['templates'] . $user_data["frontend template"] . '/modules/' . $module_name . '/';
   		$module_path = file_exists($template_module_path) ? $template_module_path : $system_module_path;
		
   		return file_exists($module_path) ? $module_path : '';
    }

/**
 * Include Quick Help extension
 *
 * @param      string $text
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

    function quick_help($text) {
    	global $system_data, $user_data;
    	
    	$quick_help = $text;
    	$template_file = $system_data['folder']['extensions'] . 'quick-help/' . $system_data['file']['template index'];
    	
    	if($text != '' && file_exists($template_file)) include($template_file);
    }

/**
 * Generate PHP output and return as value
 *
 * @param      string $file Executeable file
 * @param      string $page_name Page name for simulating normal page output
 * @return     string Generated HTML source for file
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-07-16
 */

	function generate_content($file, $page_alias) {
		global $module_settings;
		$page_info = get_page_info($page_alias);
		
		if(is_file($file)) {
			ob_start();
			include($file);
			$content = '' . ob_get_contents();
			ob_end_clean();
			return $content;
		}
	}

/**
 * Include frontend template
 *
 * @param      string $module_name
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-18
 */

	function include_template($module_name) {
		global $system_data, $module_settings;
		
		$settings = $module_settings[$module_name];
		$tag_attributes = '';

		$margin_top = isset($settings["margin top"]) && $settings["margin top"] != '' ? $settings["margin top"] : 0;
		$margin_left = isset($settings["margin left"]) && $settings["margin left"] != '' ? $settings["margin left"] : 0;
		$tag_style = ' style="margin-top: ' . $margin_top . 'px; margin-left: ' . $margin_left . 'px"';
		if($margin_top == 0 && $margin_left == 0) $tag_style = '';
		
		if(isset($settings["css class"]) && $settings["css class"] != '') $tag_attributes .= ' class="' . $settings["css class"] . '"';
		if(isset($settings["css id"]) && $settings["css id"] != '') $tag_attributes .= ' id="' . $settings["css id"] . '"';
		
		$template_path = get_module_path($module_name) . 'frontend-template.tpl';
		$template_standard_path = $system_data['folder']['modules'] . $module_name . '/frontend-template.tpl';
		
		connector('include_template');
		
		if($tag_attributes != '' || $tag_style != '') echo '<div' . $tag_attributes . $tag_style . '>';

		if(file_exists($template_path)) include($template_path);
			elseif(file_exists($template_standard_path)) include($template_standard_path);

		if($tag_attributes != '' || $tag_style != '') echo '</div>';
	}

/**
 * Check valid RGB value
 *
 * @param      string $value
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	function is_rgb($value) {
		return preg_match("/^#([a-f]|\d){6}$/i", $value) ? true : false;
	}

/**
 * Make string valid for XML
 *
 * @param      string $value
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-03-24
 */

	function xml_string($value) {
		$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
		$value = preg_replace('/&\w+;/', '', $value); // strip all remaining unknown entities
		$value = preg_replace('/&(?!\w+;)/', '&amp;', $value); // Workaround for PHP &amp; bug
		return $value;
	}

/**
 * File list (subdirectories included)
 *
 * @param      string $dir
 * $return     array A simple file list dump.
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-05-29
 */

	function filelist($dir, $file_type = 'all', $hidden_dirs = array(), $hidden_files = array(), $nosubs = false) {
		if(!is_array($hidden_dirs)) $hidden_dirs = array();
		if(!is_array($hidden_files)) $hidden_files = array();
		
	    if(is_dir($dir)) {
	    	$dh = opendir($dir);
	    	$dir = trim($dir, '/');
	        $files = array();
	        $inner_files = array();
	
	        while($file = readdir($dh)) {
	            if($file != '.' && $file != '..' && $file[0] != '.') {
	            	$file_extension = strtolower(substr($file, strrpos($file, '.') + 1));
	            	
	                if(is_dir($dir . '/' . $file)) {
	                	if(!in_array($file, $hidden_dirs) && $nosubs == false) {
	                    	$inner_files = filelist($dir . '/' . $file, $file_type, $hidden_dirs, $hidden_files);
	                    	if(is_array($inner_files)) $files = array_merge($files, $inner_files);
	                    }
	                } else if(($file_type == 'all' || get_file_type($file_extension) == $file_type) && !in_array($file, $hidden_files)) {
                    	array_push($files, $dir . '/' . $file);
	                }
	            }
	        }
	
	        closedir($dh);
	        return $files;
	    } else
	    	return array();
	}

/**
 * Dir list (subdirectories included)
 *
 * @param      string $dir
 * $return     array A simple dir list dump.
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-03-30
 */

	function dirlist($dir, $hidden_dirs = array(), $nosubs = false) {
	    if(is_dir($dir)) {
	    	$dh = opendir($dir);
	    	$dir = trim($dir, '/');
	        $dirs = array();
	        $inner_dirs = array();
	
	        while($entry = readdir($dh)) {
	            if($entry != '.' && $entry != '..' && $entry[0] != '.') {
	                if(is_dir($dir . '/' . $entry)) {
	                	if(!in_array($entry, $hidden_dirs)) {
                			array_push($dirs, $dir . '/' . $entry);

	                		if($nosubs == false) {
	                    		$inner_dirs = dirlist($dir . '/' . $entry, $hidden_dirs);
	                    		$dirs = array_merge($dirs, $inner_dirs);
	                    	}
	                    }
	                }
	            }
	        }
	
	        closedir($dh);
	        return $dirs;
	    } else
	    	return array();
	}

/**
 * Connector function
 *
 * @param      string $id Hook ID (for example 'pages output before')
 * @param      string $callback Function name
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-19
 */

	function connector($id = '', $callback = '') {
		global $connectors;
		
		if($callback == '') {
			if(isset($connectors[$id])) {
				foreach($connectors[$id] as $user_function) {
					$tmp_output = call_user_func($user_function);
					array_splice($connectors[$id], 0, 1);
					connector($id);
					return $tmp_output;
				}
			}
		} else
			$connectors[$id][] = $callback;
	}

/**
 * Delete XML node
 * Workaround for PHP unset bug
 *
 * @param      object $object SimpleXML parent object
 * @param      object $node SimpleXML node object
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-03-29
 */

	function removeSimpleXMLnode($object, $node) {
		$object_string = $object->asXML();
		$node_string = $node->asXML();
		return simplexml_load_string(str_replace($node_string, '', $object_string));
	}

/**
 * Encode email addresses in text
 *
 * @param      string $string Text that contains email addresses
 * return      string Text with encoded email addresses
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-03
 */

	function encode_email($string) {
		$emails = array();
		preg_match_all('/\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,6}/i', $string, $emails);

		foreach((array) $emails[0] as $email) {
			$encoded_string = '';
			$arrCharacters = str_split($email);

			foreach ($arrCharacters as $strCharacter)
				$encoded_string .= sprintf('&#%s;', ord($strCharacter));

			$string = str_replace($email, $encoded_string, $string);
		}

		return str_replace('mailto:', '&#109;&#97;&#105;&#108;&#116;&#111;&#58;', $string);
	}

/**
 * Encode ascii text
 *
 * @param      string $string Text to encode
 * return      string Text encoded
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-04
 */

	function ascii_encode($string)  {
		$encoded = '';
		
		for ($i = 0; $i < strlen($string); $i++) {
			$encoded .= '&#' . ord(substr($string,$i)) . ';';    
		}
		
		return $encoded;
	}

/**
 * Parse text for output in input field
 *
 * @param      string $string Text to parse
 * return      string Parsed text
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-05
 */

	function clean_output($string)  {	
		return htmlspecialchars(trim(stripslashes(html_entity_decode($string))));
	}

/**
 * Recursive make dir
 *
 * @param      string $pathname Path with subdirectories
 * return      bool
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-11
 */

 	function rmkdir($path) {
    	is_dir(dirname($path)) || rmkdir(dirname($path));
    	return is_dir($path) || @mkdir($path);
	}

/**
 * Copy a file, or recursively copy a folder and its contents
 *
 * @author     Aidan Lister <aidan@php.net>
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version    1.0.2
 * @link       http://aidanlister.com/repos/v/function.copyr.php
 * @param      string   $source    Source path
 * @param      string   $dest      Destination path
 * @return     bool     Returns TRUE on success, FALSE on failure
 * @version	   2009-05-12
 */

	function rcopy($source, $dest) {
		if(!file_exists($source)) return false;
		if(is_link($source)) return symlink(readlink($source), $dest);
	    if(is_file($source)) return copy($source, $dest);
	    if(!is_dir($dest)) mkdir($dest);
	
	    $dir = dir($source);
	    
	    while(false !== $entry = $dir->read()) {
	    	if($entry == '.' || $entry == '..') continue;
	        rcopy("$source/$entry", "$dest/$entry");
	    }
	    
	    $dir->close();
	    return true;
	}

/**
 * Sort pagelist
 *
 * @param      string $key Sort array key
 * @param      string $type Sort array key type
 * @param      string $ascending Sort array key ascending (1) or not (0)
 * return      array
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-11
 */

	function sort_pagelist($key = 'alias', $ascending = 1) {
		global $pagelist;
		$pagelist_unsorted = array();
		$pagelist_presorted = array();
		$pagelist_sorted = array();
		
		foreach($pagelist as $category_entry) {
			foreach($category_entry['pages'] as $page_entry) {
				$page_entry->category = $category_entry['title'];
				$pagelist_unsorted[strval($page_entry->alias)] = $page_entry;
				$pagelist_presorted[strval($page_entry->alias)] = strval($page_entry->$key);
			}
		}
		
		($ascending == 1) ? asort($pagelist_presorted) : arsort($pagelist_presorted);
		
		while($value = current($pagelist_presorted)) {
			$pagelist_sorted[key($pagelist_presorted)] = $pagelist_unsorted[key($pagelist_presorted)];
			next($pagelist_presorted);
		}
		
		return $pagelist_sorted;
	}

/**
 * Get page info data
 *
 * @param      string $page Alias name of the page
 * return      object SimpleXML Object with page information
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-05-16
 */

	function get_page_info($page) {
		global $system_data;
		
		$page_info_file = $system_data['folder']['pages'] . $page . '/' . $system_data['file']['page info file'];
		$page_info_xml = ($page == '' || !is_file($page_info_file)) ? simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><page></page>') : simplexml_load_file($page_info_file);
		$page_info_xml->index = $system_data['folder']['pages'] . $page . '/' . $system_data['file']['index page'];
		$page_info_xml->href = $system_data['frontend']['href attribute'] . $page_info_xml->alias;
		
		return $page_info_xml;
	}

/**
 * Translate key words
 *
 * @param      string Key word
 * return      string Word
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-09-04
 */

	function translate_keyword($word) {
		$translated = $word;
		
		switch($word) {
			case 'module type: all' : $translated = txt('global', 'Frontend'); break;
			case 'module type: module' : $translated = txt('global', 'Backend'); break;
			case 'module type: protected' : $translated = txt('global', 'System'); break;
			
			case 'month: 01' : $translated = txt('global', 'Januar'); break;
			case 'month: 02' : $translated = txt('global', 'Februar'); break;
			case 'month: 03' : $translated = txt('global', 'März'); break;
			case 'month: 04' : $translated = txt('global', 'April'); break;
			case 'month: 05' : $translated = txt('global', 'Mai'); break;
			case 'month: 06' : $translated = txt('global', 'Juni'); break;
			case 'month: 07' : $translated = txt('global', 'Juli'); break;
			case 'month: 08' : $translated = txt('global', 'August'); break;
			case 'month: 09' : $translated = txt('global', 'September'); break;
			case 'month: 10' : $translated = txt('global', 'Oktober'); break;
			case 'month: 11' : $translated = txt('global', 'November'); break;
			case 'month: 12' : $translated = txt('global', 'Dezember'); break;
		}
		
		return $translated;
	}

/**
 * Search for value in XML nodes
 *
 * @param      string Searched value
 * @param      string Node name that should be checked
 * return      number Node position (-1 if not found)
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-05-17
 */

	function in_node($searched, $key, $node) {
		$i = 0;
		
		foreach($node->$key as $node_entry) {
			if(strval($node_entry) == $searched) { $found = $i; break; } else $i++;
		}
		
		return isset($found) ? $found : -1;
	}

/**
 * Get value vom GET var in URL string
 *
 * @param      string Var name
 * return      string Var value
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2010-08-08
 */

	function get_url_value($var) {
		$start = strpos(rtrim($_SERVER['REQUEST_URI'], '/') . '/', '/' . $var . '/');
		
		if($start !== false) {
			$value = substr(rtrim($_SERVER['REQUEST_URI'], '/'), $start + strlen($var) + 2);
			$end = strpos($value, '/');
			$value = ($end !== false && $end > 0) ? substr($value, 0, $end) : $value;
			return trim($value, '/ ');
		} else return false;
	}

/**
 * Return image size attributes for img tag
 *
 * @param      string file name
 * return      string width and height img tag attributes
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-07-15
 */

	function imagesize($file) {
		if(function_exists('getimagesize') && is_file($file)) {
			$image_data = getimagesize($file);
			return $image_data[3];
		} else
			return 'width="" height=""';
	}

/**
 * Is image?
 *
 * @param      string file name
 * return      bool
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-07-15
 */

	function is_image($file) {
		if(stristr(strtolower($file),'.png')) $is_image = 1;
		if(stristr(strtolower($file),'.gif')) $is_image = 1;
		if(stristr(strtolower($file),'.jpg')) $is_image = 1;
		if(stristr(strtolower($file),'.jpeg')) $is_image = 1;
		
		return isset($is_image) ? true : false;	
	}

/**
 * Insert tags
 *
 * @param      string Content with insert tags
 * return      string Converted content
 *
 * @category   Functions
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2010-05-19
 */

	function insert_tags($content) {
		if(strpos($content, '{{') !== false) {
		
			// Include file
			$content = preg_replace_callback("/\{\{include file:(.*)\}\}/U", create_function('$results', '
				$results[1] = trim($results[1]);
				if(is_file($results[1])) return generate_content($results[1], $results[1]);
			'), $content);
			
		}
		
		return $content;
	}

?>