Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /** NenGame PHP 0-044 List Module by Timothy Robert Keal 2016 **/
- $list_settings=null;
- $list_debug=null;
- list_initialization();
- function list_fix(&$list=null,$level=1) {
- $level=intval($level);
- if($level>=1) {
- if(!isset($list))
- $list['ct']=0;
- if($list===null)
- $list['ct']=0;
- if(!isset($list['ct']))
- $list['ct']=0;
- if(!($list['ct']>0))
- $list['ct']=0;
- }
- if($level>=2) {
- ksort($list);
- $temp['ct']=0;
- foreach($list as $key => $value)
- if(is_numeric($key)) {
- $temp[$temp['ct']]=$value;
- $temp['ct']++;
- }
- $list=$temp;
- unset($temp);
- }
- }
- function list_log_debug(&$list=null,$trace=null,$value='') {
- /*
- if($list===null) {
- global $list_debug;
- $list=$list_debug;
- }
- */
- list_fix($list);
- list_manip($list,'add',false,'<tr><td><font color="green" size="+3">'.$value.'</font></td></tr>');
- //echo $list[$list['ct']-1].'<br>';
- }
- function list_initialization() {
- global $list_settings;
- global $list_debug;
- $list_settings['debug']='false';
- list_fix($list_debug,2);
- }
- function list_manip(&$ret,$method,$index=false,$value=null,&$errorflag=false) {
- global $list_debug;
- //list_log_debug($debug,null,'list_manip open: "'.htmlentities(var_export($ret,true)).'" "'.htmlentities(var_export($method,true)).'" "'. htmlentities(var_export($index,true)).'" "'.htmlentities(var_export($value,true)).'" "'. htmlentities(var_export($errorflag,true)).'"');
- if(defined($errorflag))
- $errorflag=false;
- if(!is_array($ret)){
- $ret['lock']=true;
- $ret['ct']=0;
- $ret['lock']=false;
- }
- if(is_array($ret)){
- $ret['lock']=false;
- if($ret['ct']===null){
- $ret['lock']=true;
- $ret['ct']=0;
- $ret['lock']=false;
- }
- if($ret['ct']===null){
- $ret['lock']=true;
- $ret['ct']=0;
- $ret['lock']=false;
- }
- if($ret['ct']>=0){
- //list_log_debug($debug,null,'list_manip line: count greater than or equal to zero');
- /*if(defined($method)){
- list_log_debug($debug,null,'list_manip line: method defined');
- */ switch($method){
- case 'remove':
- //list_log_debug($debug,null,'list_manip line: method remove');
- //if(defined($index)){
- if(is_numeric($index)){
- list_log_debug($debug,null,'list_manip line: index numeric');
- if(index>=0){
- //list_log_debug($debug,null,'list_manip line: index greater than or equal to zero');
- $ret['lock']=true;
- for($i=$index;$i<$ret['ct'];$i++) {
- $ret[$i]=$ret[$i+1];
- }
- unset($ret[$i]);
- $ret['ct']--;
- $ret['lock']=false;
- }
- elseif(index<0){
- //list_log_debug($debug,null,'list_manip line: index less than zero');
- $ret['lock']=true;
- for($i=0;$i>$index;$i--) {
- unset($ret[$ret[ct]]);
- $ret['ct']--;
- }
- $ret['lock']=false;
- }
- }
- /*}
- else{
- //list_log_debug($debug,null,'list_manip line: index undefined');
- $ret['lock']=true;
- $i=$ret['ct'];
- unset($ret[$i]);
- $ret['ct']--;
- $ret['lock']=false;
- }*/
- case 'add':
- //list_log_debug($debug,null,'list_manip line: method add');
- //if(defined($value)){
- /*if(!defined($index)){
- //list_log_debug($debug,null,'list_manip line: index undefined');
- $ret['lock']=true;
- $ret[$ret['ct']]=$value;
- $ret['ct']++;
- $ret['lock']=false;
- }
- else*/
- if(is_numeric($index)){
- //list_log_debug($debug,null,'list_manip line: index numeric');
- if(($index>=0) && ($index<$ret['ct'])){
- $ret['lock']=true;
- $ret[$index]=$value;
- $ret['ct']++;
- $ret['lock']=false;
- }
- else{
- //if(defined($errorflag))
- $errorflag='index out of bounds';
- }
- }
- elseif($index===false){
- //list_log_debug($debug,null,'list_manip line: index false');
- $ret['lock']=true;
- $ret[$ret['ct']]=$value;
- $ret['ct']++;
- $ret['lock']=false;
- }
- //}
- // case 'insert':
- //list_log_debug($debug,null,'list_manip line: method insert');
- //if(defined($value)){
- /*if(!defined($index)){
- //list_log_debug($debug,null,'list_manip line: index undefined');
- $ret['lock']=true;
- $ret[$ret['ct']]=$value;
- $ret['ct']++;
- $ret['lock']=false;
- }
- else*/
- // if(is_numeric($index)){
- //list_log_debug($debug,null,'list_manip line: index numeric');
- // $ret['lock']=true;
- // for($i=$ret['ct'];$i>$index;$i++) {
- // $ret[$i]=$ret[$i-1];
- // }
- // $ret[$i]=$value;
- // $ret['ct']++;
- // $ret['lock']=false;
- /*}
- else{
- //if(defined($errorflag))
- $errorflag='index out of bounds';
- }*/
- // }
- // elseif($index===false){
- //list_log_debug($debug,null,'list_manip line: index false');
- // $ret['lock']=true;
- // $ret[$ret['ct']]=$value;
- // $ret['ct']++;
- // $ret['lock']=false;
- // }
- //}
- }
- //}
- }
- elseif($ret['ct']<0){
- //list_log_debug($debug,null,'list_manip line: count less than zero');
- $ret['lock']=true;
- $ret['ct']=0;
- $ret['lock']=false;
- }
- }
- else{
- $ret['lock']=true;
- $ret['ct']=0;
- $ret['lock']=false;
- }
- //list_log_debug($debug,null,'list_manip close: "'.htmlentities(var_export($ret,true)).'" "'.htmlentities(var_export($method,true)).'" "'. htmlentities(var_export($index,true)).'" "'.htmlentities(var_export($value,true)).'" "'. htmlentities(var_export($errorflag,true)).'"');
- return $ret;
- }
- function list_from_stream_contents($fn) {
- global $list_debug;
- global $list_settings;
- if($handle=$fopen($fn,'r')) {
- $dat=stream_get_contents($handle,-1);
- $ret['ct']=0;
- }
- else {
- $ret['ct']=0;
- }
- return $ret;
- }
- function string_shorten($source='',$sep='..',$max=30,$position=0.8){
- global $list_debug;
- $source=strval($source);
- if(strlen($source)===0)
- return '';
- $max=intval($max);
- if($max<1)
- $max=1;
- if(strlen($source)<=$max)
- return $source;
- if(strlen($sep)>=$max)
- return substr($source,0,$max);
- $position=floatval($position);
- if($position<0)
- $position=0;
- if($position>1)
- $position=1;
- $span[0]=intval(floor(floatval($max-1)*$position));
- $span[1]=$max-$span[0]-strlen($sep);
- if($span[1]<0){
- $span[0]=$max-strlen($sep);
- $span[1]=0;
- }
- return substr($source,0,$span[0]).$sep.substr($source,-$span[1],$span[1]);
- }
- function string_from_source($source='',$type='string'){
- global $list_debug;
- global $list_settings;
- $source=strval($source);
- switch($type){
- case 'string':
- if($list_settings['debug']==='true')
- list_log_debug($debug,null,'list.'.htmlentities($type).'.length="<font color="red"><tt>'.strlen($source).'</tt></font>"');
- $dat=$source;
- break;
- case 'file':
- if($list_settings['debug']==='true')
- if($list_settings['debug']==='true')
- list_log_debug($debug,null,'list.'.htmlentities($type).'.exists="<font color="red"><tt>'.is_file($source).'</tt></font>"');
- if(is_file($_SERVER['DOCUMENT_ROOT'].$source))
- $dat=file_get_contents($_SERVER['DOCUMENT_ROOT'].$source);
- else
- $dat='';
- break;
- case 'stream':
- if($handle=fopen($source,'r')) {
- if($list_settings['debug']==='true')
- list_log_debug($debug,null,'list.'.htmlentities($type).'.handle="<font color="red"><tt>'.$handle.'</tt></font>"');
- $dat=stream_get_contents($handle,-1);
- fclose($handle);
- }
- else {
- if($list_settings['debug']==='true')
- list_log_debug($debug,null,'list.'.htmlentities($type).'.failure');
- $dat='';
- }
- break;
- default:
- if($list_settings['debug']==='true')
- list_log_debug($debug,null,'list.'.htmlentities($type).'.invalid');
- $dat='';
- }
- if($list_settings['debug']==='true') {
- list_log_debug($debug,null,'list.'.$type.'.source="<font color="red"><tt>'.string_shorten(htmlentities($source)).'</tt></font>"');
- list_log_debug($debug,null,'list.'.$type.'.length="<font color="red"><tt>'.strlen($dat).'</tt></font>"');
- list_log_debug($debug,null,'list.'.$type.'.md5="<font color="red"><tt>'.md5($dat).'</tt></font>"');
- list_log_debug($debug,null,'list.'.$type.'.sha1="<font color="red"><tt>'.sha1($dat).'</tt></font>"');
- }
- return $dat;
- }
- function list_from_source($source='',$sep="\r\n",$type='string'){
- global $list_debug;
- $type=strval($type);
- $source=string_from_source($source,$type);
- $ret['ct']=0;
- while(strpos($source,$sep)!==false){
- list_manip($ret,'add',false,substr($source,0,strpos($source,$sep)));
- $source=substr($source,strpos($source,$sep)+strlen($sep));
- }
- if(strlen($source)>0)
- list_manip($ret,"add",false,$source);
- return $ret;
- }
- function list_from_file_contents($fn,$sep="\r\n",$type='file') {
- return list_from_source($fn,$sep,$type);
- }
- function list_regex_from_string_contents($arg,$prefix='/nengame/0-050/pcre/syntax.nengame.txt',$striphtml=false){
- global $list_debug;
- global $list_settings;
- $regex=list_ini_from_source($prefix,"\r\n",'string');
- $dat['original']=list_from_source($arg);
- $dat['result']['ct']=$dat['original']['ct'];
- for($ln=0;$ln<$dat['original']['ct'];$ln++){
- $dat['result'][$ln]=$dat['original'][$ln];
- foreach($regex as $key => $value){
- unset($markers);
- switch($key){
- case 'emotes':
- $emotes=list_ini_from_file_contents($value);
- $markers['pattern']['ct']=0;
- $markers['replace']['ct']=0;
- foreach($emotes as $emote => $emoji){
- $markers['pattern'][$markers['pattern']['ct']]='/([\\n ])'.$emote.'([ \\r])/';
- $markers['replace'][$markers['replace']['ct']]='$1[twitch.emote]v1/'.$emoji.'/2.0[/twitch.emote]$2';
- $markers['pattern']['ct']++;
- $markers['replace']['ct']++;
- }
- break;
- default:
- $markers['pattern']=list_from_file_contents($value.'pattern.txt');
- $markers['replace']=list_from_file_contents($value.'replace.txt');
- }
- for($marker=0;$marker<$markers['pattern']['ct'];$marker++)
- for($prior=false;$prior!==$dat['result'][$ln];){
- $prior=$dat['result'][$ln];
- $dat['result'][$ln]="\r\n".$dat['result'][$ln]."\r\n";
- $dat['result'][$ln]=preg_replace($markers['pattern'][$marker],$markers['replace'][$marker],$dat['result'][$ln],1);
- while(substr($dat['result'][$ln],0,strlen("\r\n"))==="\r\n")
- $dat['result'][$ln]=substr($dat['result'][$ln],strlen("\r\n"),strlen($dat['result'][$ln])-strlen("\r\n"));
- while(substr($dat['result'][$ln],strlen($dat['result'][$ln])-strlen("\r\n"),strlen("\r\n"))==="\r\n")
- $dat['result'][$ln]=substr($dat['result'][$ln],0,strlen($dat['result'][$ln])-strlen("\r\n"));
- }
- }
- }
- return $dat['result'];
- }
- function list_regex_from_file_contents($fn,$prefix='/nengame/0-050/pcre/syntax.nengame.txt',$striphtml=false){
- global $list_debug;
- global $list_settings;
- $regex=list_ini_from_file_contents($prefix);
- $dat['original']=list_from_file_contents($fn);
- $dat['result']['ct']=$dat['original']['ct'];
- for($ln=0;$ln<$dat['original']['ct'];$ln++){
- $dat['result'][$ln]=$dat['original'][$ln];
- foreach($regex as $key => $value){
- unset($markers);
- switch($key){
- case 'emotes':
- $emotes=list_ini_from_file_contents($value);
- $markers['pattern']['ct']=0;
- $markers['replace']['ct']=0;
- foreach($emotes as $emote => $emoji){
- $markers['pattern'][$markers['pattern']['ct']]='/([\\n ])'.$emote.'([ \\r])/';
- $markers['replace'][$markers['replace']['ct']]='$1[twitch.emote]v1/'.$emoji.'/2.0[/twitch.emote]$2';
- $markers['pattern']['ct']++;
- $markers['replace']['ct']++;
- }
- break;
- default:
- $markers['pattern']=list_from_file_contents($value.'pattern.txt');
- $markers['replace']=list_from_file_contents($value.'replace.txt');
- }
- for($marker=0;$marker<$markers['pattern']['ct'];$marker++)
- for($prior=false;$prior!==$dat['result'][$ln];){
- $prior=$dat['result'][$ln];
- $dat['result'][$ln]="\r\n".$dat['result'][$ln]."\r\n";
- $dat['result'][$ln]=preg_replace($markers['pattern'][$marker],$markers['replace'][$marker],$dat['result'][$ln],1);
- while(substr($dat['result'][$ln],0,strlen("\r\n"))==="\r\n")
- $dat['result'][$ln]=substr($dat['result'][$ln],strlen("\r\n"),strlen($dat['result'][$ln])-strlen("\r\n"));
- while(substr($dat['result'][$ln],strlen($dat['result'][$ln])-strlen("\r\n"),strlen("\r\n"))==="\r\n")
- $dat['result'][$ln]=substr($dat['result'][$ln],0,strlen($dat['result'][$ln])-strlen("\r\n"));
- }
- }
- }
- return $dat['result'];
- }
- function transliterateString($txt) {
- $transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'E', 'ё' => 'e', 'Ё' => 'E', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja');
- return str_replace(array_keys($transliterationTable), array_values($transliterationTable), $txt);
- }
- function list_markdown_from_string_contents($arg,$prefix='/nengame/0-050/pcre/syntax.nengame.txt',$striphtml=true,$count=1){
- $dat=list_regex_from_string_contents($arg,$prefix,$striphtml,$count);
- if($count>1){
- $ret['ct']=$count;
- for($i=0;$i<$dat['ct'];$i++){
- $ret[$i]='';
- for($ln=0;$ln<$dat[$i]['ct'];$ln++)
- $ret[$i].=$dat[$i][$ln].'<br>'."\r\n";
- }
- }
- else{
- $ret='';
- for($ln=0;$ln<$dat['ct'];$ln++)
- $ret.=$dat[$ln].'<br>'."\r\n";
- }
- return $ret;
- }
- function list_markdown_from_file_contents($fn,$prefix='/nengame/0-050/pcre/syntax.nengame.txt',$striphtml=true,$count=1){
- $dat=list_regex_from_file_contents($fn,$prefix,$striphtml,$count);
- if($count>1){
- $ret['ct']=$count;
- for($i=0;$i<$dat['ct'];$i++){
- $ret[$i]='';
- for($ln=0;$ln<$dat[$i]['ct'];$ln++)
- $ret[$i].=$dat[$i][$ln].'<br>'."\r\n";
- }
- }
- else{
- $ret='';
- for($ln=0;$ln<$dat['ct'];$ln++)
- $ret.=$dat[$ln].'<br>'."\r\n";
- }
- return $ret;
- }
- function list_ini_load($source='',$sep="\r\n",$type='file') {
- global $list_debug;
- $dat=list_from_source($source,$sep,$type);
- $local['pair']['pattern']='/\r\n"([^"]+?)"="([^"]+?)"\r\n/';
- $local['pair']['lead']='pair';
- $local['pair']['label']='$1';
- $local['pair']['value']='$2';
- $local['lead']['pattern']='/\r\n([\-\~\!\@\#\$\%\^\&\*\+\=\_\?\.\:])([^\-\"\ \~\!\@\#\$\%\^\&\*\+\=\?\.\:]+?) "([^"]+?)"\r\n/';
- $local['lead']['lead']='$1';
- $local['lead']['label']='$2';
- $local['lead']['value']='$3';
- $local['if']['pattern']='/\r\n([\-\~\!\@\#\$\%\^\&\*\+\=\_\?\.\:])if\(([^\-\"\ \~\!\@\#\$\%\^\&\*\+\=\?\.\:]+?)="([^"]+?)"\)\r\n/';
- $local['if']['lead']='$1';
- $local['if']['label']='$2';
- $local['if']['value']='$3';
- $ret=null;
- for($ln=0;$ln<$dat['ct'];$ln++) {
- list_log_debug($debug,null,'line[<font color="red">'.$ln.'</font>]=[<font color="red">'.$dat[$ln].'</font>]');
- unset($temp);
- foreach($local as $tier => $cast)
- foreach($cast as $key => $value)
- if($key !== 'pattern'){
- $temp[$tier][$key]=preg_replace($cast['pattern'],$value,"\r\n".$dat[$ln]."\r\n");
- if($temp[$tier][$key]==="\r\n".$dat[$ln]."\r\n")
- unset($temp[$tier][$key]);
- else
- list_log_debug($debug,null,htmlentities($tier).'[<font color="red">'.htmlentities($key).'</font>]="<font color="red">'.htmlentities($temp[$tier][$key]).'</font>" from "<font color="red">'.htmlentities($value).'</font>","<font color="red">'.htmlentities($dat[$ln]).'</font>"');
- }
- $method='comment';
- if(isset($temp['pair']['lead']))
- if($temp['pair']['lead'] === 'pair')
- $method='pair';
- if(isset($temp['if']['lead']))
- if(strlen($temp['if']['lead']) > 0)
- $method='if';
- if(isset($temp['lead']['lead']))
- if(strlen($temp['lead']['lead']) > 0)
- $method='lead';
- list_log_debug($debug,null,'method: <font color="red">'.htmlentities($method).'</font>');
- switch($method){
- case 'comment':
- list_log_debug($debug,null,'comment: <font color="red">'.htmlentities($dat[$ln]).'</font>');
- break;
- case 'pair':
- list_log_debug($debug,null,'pair[<font color="red">'.$temp[$method]['label'].'</font>]=[<font color="red">'.$temp[$method]['value'].'</font>]');
- $ret[$temp[$method]['label']]=$temp[$method]['value'];
- break;
- case 'lead':
- switch($temp[$method]['lead']){
- case '#':
- switch($temp[$method]['label']){
- case 'include':
- list_log_debug($debug,null,'include[<font color="red">'.htmlentities($method).'</font>]=[<font color="red">'.$temp[$method]['value'].'</font>]');
- $tempdat=list_from_source($temp[$method]['value'],$sep,'file');
- for($ln2=$ln+1;$ln2<$dat['ct'];$ln2++)
- $dat[$ln2+$tempdat['ct']]=$dat[$ln2];
- for($ln2=0;$ln2<$tempdat['ct'];$ln2++)
- $dat[$ln+$ln2+1]=$tempdat[$ln2];
- $dat['ct']+=$tempdat['ct'];
- ksort($dat);
- break;
- }
- break;
- case '@':
- switch($temp[$method]['label']){
- case 'include':
- list_log_debug($debug,null,'include[<font color="red">'.htmlentities($method).'</font>]=[<font color="red">'.$ret[$temp[$method]['value']].'</font>]');
- $tempdat=list_from_source($ret[$temp[$method]['value']],$sep,'file');
- for($ln2=$ln+1;$ln2<$dat['ct'];$ln2++)
- $dat[$ln2+$tempdat['ct']]=$dat[$ln2];
- for($ln2=0;$ln2<$tempdat['ct'];$ln2++)
- $dat[$ln+$ln2+1]=$tempdat[$ln2];
- $dat['ct']+=$tempdat['ct'];
- ksort($dat);
- break;
- }
- break;
- case '$':
- list_log_debug($debug,null,'eval: global $<font color="red">'.htmlentities($temp[$method]['label']).'</font>; <-- file:"<font color="red">'.$temp[$method]['value'].'</font>"');
- eval('global $'.$temp[$method]['label'].';');
- $tempdat=list_ini_load($temp[$method]['value'],$sep,$type);
- foreach($tempdat as $key => $value){
- eval('$'.$temp[$method]['label'].'[\''.$key.'\']=\''.addslashes($value).'\';');
- list_log_debug($debug,null,'load: $<font color="red">'.htmlentities($temp[$method]['label']).'</font>[\'<font color="red">'.htmlentities($key).'</font>\']=\'<font color="red">'.addslashes($value).'</font>\';');
- }
- break;
- case '~':
- $ret[$temp[$method]['label']]=$ret[$temp[$method]['value']].$ret[$temp[$method]['label']];
- break;
- case '.':
- $ret[$temp[$method]['label']].=$temp[$method]['value'];
- break;
- case '?':
- if(isset($_GET[$temp[$method]['value']]))
- $ret[$temp[$method]['label']]=$_GET[$temp[$method]['value']];
- else
- if(!isset($ret[$temp[$method]['label']]))
- $ret[$temp[$method]['label']]='';
- break;
- case '=':
- $ret[$temp[$method]['label']]=$ret[$temp[$method]['value']];
- break;
- }
- break;
- case 'if':
- switch($temp[$method]['lead']){
- case '#':
- if(!isset($ret[$temp[$method]['label']]))
- $ln++;
- elseif($ret[$temp[$method]['label']]!==$temp[$method]['value'])
- $ln++;
- break;
- case '@':
- if(!isset($ret[$temp[$method]['label']]))
- $ln++;
- if(!isset($ret[$temp[$method]['value']]))
- $ln++;
- elseif($ret[$temp[$method]['label']]!==$ret[$temp[$method]['value']])
- $ln++;
- break;
- }
- break;
- }
- }
- ksort($dat);
- return $ret;
- }
- function list_ini_from_source($source='',$sep="\r\n",$type='file') {
- $dat=list_from_source($source,$sep,$type);
- $pattern='/"([^"]+?)"="([^"]+?)"/';
- $ret=null;
- for($ln=0;$ln<$dat['ct'];$ln++)
- $ret[preg_replace($pattern,'$1',$dat[$ln])]=preg_replace($pattern,'$2',$dat[$ln]);
- return $ret;
- }
- function list_ini_from_file_contents($fn,$sep="\r\n",$type='file') {
- return list_ini_from_source($fn,$sep,$type);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement