PHP Classes

File: build.php

Recommend this page to a friend!
  Classes of giuseppe lucarelli   reconfig   build.php   Download  
File: build.php
Role: Auxiliary script
Content type: text/plain
Description: build.php
Class: reconfig
Get configuration from files, pages and databases
Author: By
Last change: addes xml output format
Date: 8 years ago
Size: 17,577 bytes
 

Contents

Class file image Download
<?php /* * @$Header: /var/cvsroot/reconfig/build.php,v 1.5 2014/11/06 13:04:39 giuseppe Exp $ */ /* Copyright (C) 2014- Giuseppe Lucarelli <giu.lucarelli@gmail.com> This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ header('Content-type: text/html; charset=UTF-8'); ini_set('display_errors', 1); error_reporting(~0); require_once('class.reconfig.php'); class REConf extends REConfig { function Array2Xml(&$xml,&$item,$tag,$parent='') { if(!is_numeric($tag)) $xml.=(strlen($xml > 0) ? "\n" : '').'<'.$tag.">\n"; else $xml.=(strlen($xml > 0) ? "\n" : '').'<'.$parent.">\n"; foreach($item as $k=>$v) { if(is_array($v)) { $this->Array2Xml($xml,$v,$k,$tag); } else { if(strlen($v) > 0) $xml.="<$k>$v</$k>\n"; } } if(!is_numeric($tag)) $xml.='</'.$tag.">\n"; else $xml.='</'.$parent.">\n"; } function BuildXml(&$item) { $xml=''; $this->Array2Xml($xml,$item,'item'); $xml=preg_replace(array( '/\$/', '/(<regexp>)(?:[[:space:]]|)(<regexp>)/imsU', '/(<\/regexp>)(?:[[:space:]]|)(<\/regexp>)/imsU', '/(<out>)(?:[[:space:]]|)(<out>)/imsU', '/(<\/out>)(?:[[:space:]]|)(<\/out>)/imsU', '/(<pattern>)(?:[[:space:]]|)(<pattern>)/imsU', '/(<\/pattern>)(?:[[:space:]]|)(<\/pattern>)/imsU', '/(<pattern>)((?:[[:space:]]|).*)(<\/pattern>)/imsU' ),array('\\\$','\1','\1','\1','\1','\1','\1','\1<![CDATA[\2]]>\3'),$xml); return $xml; } function BuildHtml() { global $REC,$HTML; $item=array('type'=>$_POST['widgettype'],'name'=>$_POST['elname']); if(strlen($_POST['elcode']) > 0) { $item['code']=$_POST['elcode']; $item['in']=false; } if(strlen($_POST['elparms']) > 0) { $item['parms']=$_POST['elparms']; } if(strlen($_POST['ellabel']) > 0) $item['label']=$_POST['ellabel']; if(strlen($_POST['elattrs']) > 0) { $el=str_replace("\r",'',$_POST['elattrs']); $el=explode("\n",$el); foreach($el as $e) { $pos=strpos($e,':'); $key=substr($e,0,$pos); $val=substr($e,$pos+1); $item['attrs'][$key]=trim($val); } } if(strlen($_POST['ellowercase']) > 0 && strcasecmp('not set',$_POST['ellowercase'])) $item['lowercase']=filter_var($_POST['ellowercase'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['eluppercase']) > 0 && strcasecmp('not set',$_POST['eluppercase'])) $item['uppercase']=filter_var($_POST['eluppercase'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elencode']) > 0 && strcasecmp('not set',$_POST['elencode'])) $item['encode']=filter_var($_POST['elencode'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elvalue']) > 0 && strcasecmp('not set',$_POST['elvalue'])) $item['value']=$_POST['elvalue']; if(!strcasecmp('select',$_POST['widgettype']) || !strcasecmp('radio',$_POST['widgettype']) || !strcasecmp('checkbox',$_POST['widgettype'])) { if(strlen($_POST['elselbycode']) > 0 && strcasecmp('not set',$_POST['elselbycode'])) $item['selbycode']=filter_var($_POST['elselbycode'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['eldisplay']) > 0 && strcasecmp('not set',$_POST['eldisplay'])) $item['display']=$_POST['eldisplay']; } if(strlen($_POST['elevent']) > 0) { $event=array(); $el=str_replace("\r",'',$_POST['elevent']); $el=explode("\n",$el); foreach($el as $e) { $pos=strpos($e,':'); $key=substr($e,0,$pos); $val=substr($e,$pos+1); $item['event'][$key]=trim($val); } } if(isset($_POST['elvalues']) && !strcasecmp('show',$_POST['elvalues'])) { $values=array(); if(strlen($_POST['elvalues_list']) > 0) { $el=str_replace("\r",'',$_POST['elvalues_list']); $el=explode("\n",$el); foreach($el as $e) { $pos=strpos($e,':'); $key=substr($e,0,$pos); $val=substr($e,$pos+1); $item['values'][$key]=trim($val); } } } if(isset($_POST['elhtml']) && !strcasecmp('show',$_POST['elhtml'])) { $html=array(); if(strlen($_POST['elhtml_prepend']) > 0) $html['prepend']=$_POST['elhtml_prepend']; if(strlen($_POST['elhtml_append']) > 0) $html['append']=$_POST['elhtml_append']; $item['html']=$html; } if(isset($_POST['elin']) && !strcasecmp('show',$_POST['elin'])) { $in=array(); if(strlen($_POST['elin_group']) > 0) $in['group']=$_POST['elin_group']; if(strlen($_POST['elin_depth']) > 0) $in['depth']=$_POST['elin_depth']; if(strlen($_POST['elin_target']) > 0) $in['target']=$_POST['elin_target']; if(strlen($_POST['elin_func']) > 0) $in['func']=$_POST['elin_func']; if(strlen($_POST['elin_encode']) > 0 && strcasecmp('not set',$_POST['elin_encode'])) $in['encode']=filter_var($_POST['elin_encode'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elin_utf8_decode']) > 0 && strcasecmp('not set',$_POST['elin_utf8_decode'])) $in['utf8_decode']=filter_var($_POST['elin_utf8_decode'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elin_lowercase']) > 0 && strcasecmp('not set',$_POST['elin_lowercase'])) $in['lowercase']=filter_var($_POST['elin_lowercase'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elin_uppercase']) > 0 && strcasecmp('not set',$_POST['elin_uppercase'])) $in['uppercase']=filter_var($_POST['elin_uppercase'],FILTER_VALIDATE_BOOLEAN); if(isset($_POST['elin_type'])) { $in['type']=$_POST['elin_type']; if(!strcasecmp('file',$_POST['elin_type'])) { if(isset($_POST['elin_file_path']) && strlen($_POST['elin_file_path']) > 0) { $in['path']=$_POST['elin_file_path']; } } else { if(isset($_POST['elin_sql_driver']) && strlen($_POST['elin_sql_driver']) > 0) $in['driver']=$_POST['elin_sql_driver']; $in['dbhost']='localhost'; if(isset($_POST['elin_sql_host']) && strlen($_POST['elin_sql_host']) > 0) $in['dbhost']=$_POST['elin_sql_host']; if(isset($_POST['elin_sql_dbname']) && strlen($_POST['elin_sql_dbname']) > 0) $in['dbname']=$_POST['elin_sql_dbname']; if(isset($_POST['elin_sql_dbuser']) && strlen($_POST['elin_sql_dbuser']) > 0) $in['dbuser']=$_POST['elin_sql_dbuser']; $in['dbpass']=''; if(isset($_POST['elin_sql_dbpass']) && strlen($_POST['elin_sql_dbpass']) > 0) $in['dbpass']=$_POST['elin_sql_dbpass']; if(isset($_POST['elin_sql_query']) && strlen($_POST['elin_sql_query']) > 0) $in['query']=$_POST['elin_sql_query']; if(isset($_POST['elin_sql_column']) && strlen($_POST['elin_sql_column']) > 0) { if(preg_match('/(.*)=>(.*)/',$_POST['elin_sql_column'],$matches,PREG_OFFSET_CAPTURE)) { $in['column']=array($matches[1][0]=>$matches[2][0]); } else { $in['column']=$_POST['elin_sql_column']; } } if(strlen($_POST['elin_sql_rstype']) > 0 && strcasecmp('not set',$_POST['elin_sql_rstype'])) $in['rstype']=$_POST['elin_sql_rstype']; } } if(isset($_POST['elin_regexp']) && !strcasecmp('show',$_POST['elin_regexp'])) { $regexp=array(); if(isset($_POST['elin_regexp_key0']) && strlen($_POST['elin_regexp_key0']) > 0) $regexp['key']=$_POST['elin_regexp_key0']; if(isset($_POST['elin_regexp_pattern0']) && strlen($_POST['elin_regexp_pattern0']) > 0) $regexp['pattern']=$_POST['elin_regexp_pattern0']; if(isset($_POST['elin_regexp_func0']) && strlen($_POST['elin_regexp_func0']) > 0 && !strcasecmp('split',$_POST['elin_regexp_func0'])) $regexp['func']=$_POST['elin_regexp_func0']; $in['regexp']=array($regexp); $regexp=array(); if(isset($_POST['elin_regexp_key1']) && strlen($_POST['elin_regexp_key1']) > 0) $regexp['key']=$_POST['elin_regexp_key1']; if(isset($_POST['elin_regexp_pattern1']) && strlen($_POST['elin_regexp_pattern1']) > 0) $regexp['pattern']=$_POST['elin_regexp_pattern1']; if(isset($_POST['elin_regexp_func1']) && strlen($_POST['elin_regexp_func1']) > 0 && !strcasecmp('split',$_POST['elin_regexp_func1'])) $regexp['func']=$_POST['elin_regexp_func1']; if(isset($regexp['pattern'])) $in['regexp'][]=$regexp; $regexp=array(); if(isset($_POST['elin_regexp_key2']) && strlen($_POST['elin_regexp_key2']) > 0) $regexp['key']=$_POST['elin_regexp_key2']; if(isset($_POST['elin_regexp_pattern2']) && strlen($_POST['elin_regexp_pattern2']) > 0) $regexp['pattern']=$_POST['elin_regexp_pattern2']; if(isset($_POST['elin_regexp_func2']) && strlen($_POST['elin_regexp_func2']) > 0 && !strcasecmp('split',$_POST['elin_regexp_func2'])) $regexp['func']=$_POST['elin_regexp_func2']; if(isset($regexp['pattern'])) $in['regexp'][]=$regexp; } $item['in']=$in; } if(isset($_POST['elout']) && !strcasecmp('show',$_POST['elout']) && isset($_POST['elout_asin'])) { $out=array(); if(strlen($_POST['elout_group']) > 0) $out['group']=$_POST['elout_group']; if(strlen($_POST['elout_depth']) > 0) $out['depth']=$_POST['elout_depth']; if(strlen($_POST['elout_target']) > 0) $out['target']=$_POST['elout_target']; if(strlen($_POST['elout_func']) > 0) $out['func']=$_POST['elout_func']; if(strlen($_POST['elout_encode']) > 0 && strcasecmp('not set',$_POST['elout_encode'])) $out['encode']=filter_var($_POST['elout_encode'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elout_utf8_decode']) > 0 && strcasecmp('not set',$_POST['elout_utf8_decode'])) $out['utf8_decode']=filter_var($_POST['elout_utf8_decode'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elout_lowercase']) > 0 && strcasecmp('not set',$_POST['elout_lowercase'])) $out['lowercase']=filter_var($_POST['elout_lowercase'],FILTER_VALIDATE_BOOLEAN); if(strlen($_POST['elout_uppercase']) > 0 && strcasecmp('not set',$_POST['elout_uppercase'])) $out['uppercase']=filter_var($_POST['elout_uppercase'],FILTER_VALIDATE_BOOLEAN); if(isset($_POST['elout_type'])) { $out['type']=$_POST['elout_type']; if(!strcasecmp('file',$_POST['elout_type'])) { if(isset($_POST['elout_file_path']) && strlen($_POST['elout_file_path']) > 0) { $out['path']=$_POST['elout_file_path']; } } else { if(isset($_POST['elout_sql_driver']) && strlen($_POST['elout_sql_driver']) > 0) $out['driver']=$_POST['elout_sql_driver']; if(isset($_POST['elout_sql_host']) && strlen($_POST['elout_sql_host']) > 0) $out['dbhost']=$_POST['elout_sql_host']; if(isset($_POST['elout_sql_dbname']) && strlen($_POST['elout_sql_dbname']) > 0) $out['dbname']=$_POST['elout_sql_dbname']; if(isset($_POST['elout_sql_dbuser']) && strlen($_POST['elout_sql_dbuser']) > 0) $out['dbuser']=$_POST['elout_sql_dbuser']; $out['dbpass']=''; if(isset($_POST['elout_sql_dbpass']) && strlen($_POST['elout_sql_dbpass']) > 0) $out['dbpass']=$_POST['elout_sql_dbpass']; if(isset($_POST['elout_sql_query']) && strlen($_POST['elout_sql_query']) > 0) $out['query']=$_POST['elout_sql_query']; if(isset($_POST['elout_sql_column']) && strlen($_POST['elout_sql_column']) > 0) $out['column']=$_POST['elout_sql_column']; if(strlen($_POST['elout_sql_rstype']) > 0 && strcasecmp('not set',$_POST['elout_sql_rstype'])) $out['rstype']=$_POST['elout_sql_rstype']; } } if(isset($_POST['elout_regexp']) && !strcasecmp('show',$_POST['elout_regexp'])) { $regexp=array(); if(isset($_POST['elout_regexp_key0']) && strlen($_POST['elout_regexp_key0']) > 0) $regexp['key']=$_POST['elout_regexp_key0']; if(isset($_POST['elout_regexp_pattern0']) && strlen($_POST['elout_regexp_pattern0']) > 0) $regexp['pattern']=$_POST['elout_regexp_pattern0']; if(isset($_POST['elout_regexp_func0']) && strlen($_POST['elout_regexp_func0']) > 0 && !strcasecmp('split',$_POST['elout_regexp_func0'])) $regexp['func']=$_POST['elout_regexp_func0']; $out['regexp']=array($regexp); $regexp=array(); if(isset($_POST['elout_regexp_key1']) && strlen($_POST['elout_regexp_key1']) > 0) $regexp['key']=$_POST['elout_regexp_key1']; if(isset($_POST['elout_regexp_pattern1']) && strlen($_POST['elout_regexp_pattern1']) > 0) $regexp['pattern']=$_POST['elout_regexp_pattern1']; if(isset($_POST['elout_regexp_func1']) && strlen($_POST['elout_regexp_func1']) > 0 && !strcasecmp('split',$_POST['elout_regexp_func1'])) $regexp['func']=$_POST['elout_regexp_func1']; if(isset($regexp['pattern'])) $out['regexp'][]=$regexp; $regexp=array(); if(isset($_POST['elout_regexp_key2']) && strlen($_POST['elout_regexp_key2']) > 0) $regexp['key']=$_POST['elout_regexp_key2']; if(isset($_POST['elout_regexp_pattern2']) && strlen($_POST['elout_regexp_pattern2']) > 0) $regexp['pattern']=$_POST['elout_regexp_pattern2']; if(isset($_POST['elout_regexp_func2']) && strlen($_POST['elout_regexp_func2']) > 0 && !strcasecmp('split',$_POST['elout_regexp_func2'])) $regexp['func']=$_POST['elout_regexp_func2']; if(isset($regexp['pattern'])) $out['regexp'][]=$regexp; } $item['out']=$out; } if((isset($_POST['elin']) && !strcasecmp('show',$_POST['elin'])) && (!isset($_POST['elout']) || strcasecmp('show',$_POST['elout']))) { $item['out']=false; } $HTML=array('dright_show'=>array($item)); $HTML['dright_code']=(!strcasecmp('array',$_POST['out-format']) ? stripslashes(var_export($item,true)) : $this->BuildXml($item)); } }; $REC = new REConf(); if(!strcasecmp('none',$_POST['widgettype']) && strlen($_POST['dright_code_area']) > 0) { if(!strcasecmp('array',$_POST['out-format'])) { $HTML['dright_code']=str_replace("\\\$","\$", str_replace("\\\\","\\", var_export($REC->XmlConvert($_POST['dright_code_area']),true))); } else { eval('$xml='.$_POST['dright_code_area'].';'); $HTML['dright_code']=str_replace("\\\\","\\",$REC->BuildXml($xml)); } } else { $HTML = array(); $REC->BuildHtml(); if($REC->Init($HTML['dright_show'],'dright_show',true) === true) { } } echo json_encode($HTML);