state system fixed - empty variables are removed from the query string, including ${*} placeholders, system.css, system.js lang switcher included(simple)
This commit is contained in:
parent
49e18f1c3c
commit
9b30021029
0
files/sys/system.css
Normal file
0
files/sys/system.css
Normal file
@ -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;
|
||||
};
|
||||
@ -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'));}
|
||||
|
||||
@ -1,21 +1,24 @@
|
||||
<?php
|
||||
namespace SYSTEM\PAGE;
|
||||
class replace
|
||||
{
|
||||
public static function replace($text, $vars){
|
||||
if(!$vars){
|
||||
$vars = array();}
|
||||
$search = array();
|
||||
$replace = array();
|
||||
class replace {
|
||||
public static function replace($text, $vars){
|
||||
if(!$vars){
|
||||
$vars = array();}
|
||||
$search = array();
|
||||
$replace = array();
|
||||
|
||||
foreach($vars as $key=>$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);}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user