diff --git a/files/sys/system.css b/files/sys/system.css new file mode 100644 index 0000000..e69de29 diff --git a/files/sys/system.js b/files/sys/system.js index ee22a69..c02a0fa 100644 --- a/files/sys/system.js +++ b/files/sys/system.js @@ -14,13 +14,13 @@ function SYSTEM(endpoint, group,start_state){ this.start_state = start_state; this.go_state(start_state); - $(window).bind( 'hashchange', function( event ) { + $(window).bind('hashchange', function( event ) { system.go_state();}); } //internal function to handle pagestate results SYSTEM.prototype.handle_call_pages = function (data,id) { if(data['status']){ - system.log(system.LOG_INFO,'load pages: endpoint '+system.endpoint+':group '+system.group+':state '+id+' - success'); + system.log_info('load pages: endpoint '+system.endpoint+' group:'+system.group+' state:'+id+' - success'); if(id !== system.cur_state()){ window.history.pushState(null, "", '#!'+id);} data['result'].forEach(function(entry) { @@ -50,16 +50,16 @@ SYSTEM.prototype.handle_call_pages = function (data,id) { if(call_func && typeof fn === 'function'){ call_func = false; fn(); - system.log(system.LOG_INFO,'call func: '+entry['func']); + system.log_info('call func: '+entry['func']); } else { - system.log(system.LOG_ERROR,'call func: '+entry['func']+' - fail'); + system.log_error('call func: '+entry['func']+' - fail'); }} }); } }); } else { console.log(data); - system.log(system.LOG_INFO,'Problem with your Pages: '+data['result']['message']); + system.log_info('Problem with your Pages: '+data['result']['message']); } }; //send a call to the endpoint @@ -88,6 +88,10 @@ SYSTEM.prototype.log = function(type,msg){ } console.log(res+msg); }; +SYSTEM.prototype.log_info = function(msg){ + this.log(this.LOG_INFO,msg);} +SYSTEM.prototype.log_error = function(msg){ + this.log(this.LOG_ERROR,msg);} //get the pages and save em SYSTEM.prototype.load_page = function(){ result = false; @@ -126,9 +130,14 @@ SYSTEM.prototype.go_state = function(default_state){ }; SYSTEM.prototype.back = function(){ - window.history.back(); -}; - + window.history.back();}; SYSTEM.prototype.forwad = function(){ - window.history.forward(); + window.history.forward();}; + +SYSTEM.prototype.language = function(lang){ + this.log_info('change language to '+lang); + //preserve the old parameters + //var search = location.search ? location.search.substring(1).split("&") : []; + var search = '_lang='+lang; + window.location.href = '/?' + search + location.hash; }; \ No newline at end of file diff --git a/page/State.php b/page/State.php index b55ef79..e59cbba 100644 --- a/page/State.php +++ b/page/State.php @@ -11,6 +11,10 @@ class State { $res = \SYSTEM\DBD\SYS_PAGE_GROUP::QQ(array($group,$state[0])); while($row = $res->next()){ $row['url'] = \SYSTEM\PAGE\replace::replace($row['url'], $vars); + $row['url'] = \SYSTEM\PAGE\replace::clean($row['url']); + //clean url of empty variables + $row['url'] = preg_replace('/&.*?=(&|$)/', '&', $row['url']); + $row['url'] = preg_replace('/&$/', '', $row['url']); $row['css'] = $row['js'] = array(); if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){ $row['css'] = array_merge($row['css'], call_user_func($row['php_class'].'::css'));} diff --git a/page/replace.php b/page/replace.php index 4cd129c..ece66fc 100644 --- a/page/replace.php +++ b/page/replace.php @@ -1,21 +1,24 @@ $value){ - if(!is_array($value)){ - $search[] = '/\${'.$key.'}/'; - $replace[] = $value;} - } - return @preg_replace($search, $replace, $text); + foreach($vars as $key=>$value){ + if(!is_array($value)){ + $search[] = '/\${'.$key.'}/'; + $replace[] = $value;} } - public static function replaceFile($path, $vars){ - $buffer = file_get_contents($path); - return self::replace($buffer, $vars);} + return @preg_replace($search, $replace, $text); + } + public static function replaceFile($path, $vars){ + $buffer = file_get_contents($path); + return self::replace($buffer, $vars);} + + //removes all Variable Handles + public static function clean($text){ + return preg_replace('/\${.*?}/', '', $text);} } \ No newline at end of file