Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$nen = nen_ini();
- echo main();
- function nen_ini()
- {
- $nen['me'] = me_shorthand($_SERVER['SCRIPT_NAME']);
- $nen[ 'src' ] = 'R11-SRC';
- $nen[ 'emojis' ] = 'emojis/';
- // assign domain root
- $nen['domain']='Roe XAMPP Builder';
- // assign host mode (local)
- $nen[ 'host' ] = 'local';
- // assign host mode (online)
- //$nen[ 'host' ] = 'online';
- // switch http host vars
- switch( $_SERVER[ 'HTTP_HOST' ] )
- {
- case 'localhost':
- // domain local
- $nen[ 'root' ] = $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $nen[ 'domain' ] . '/';
- break;
- default:
- // domain host
- $nen[ 'root' ] = $_SERVER[ 'DOCUMENT_ROOT' ] . '/';
- break;
- }
- return $nen;
- }
- // configure cascading stylesheet
- function nen_css()
- {
- $nen = nen_ini();
- // load stylesheet into memory
- return file_get_contents( $nen[ 'root' ]. 'css/stylesheet.css');
- }
- // include Tim Keal's token library
- function trk_strippath( $filename = '' )
- {
- trk_stripchars( $filename, '\\', '/', $file );
- trk_tok( $file, '/', $tok );
- return strtoupper( $tok[ count( $tok ) - 1 ] );
- }
- function trk_fastfiles( $path = '', $Exts = array(), &$files = array() )
- {
- $nen = nen_ini();
- $files[ null ] = $path;
- if ( is_dir( $nen['root'] . '/' . $path . '/' ) )
- {
- if ( $handle = opendir( $nen['root'] . '/' . $files[ null ] . '/' ) )
- {
- while ( false !== ( $entry = readdir( $handle ) ) )
- {
- if( is_file( $nen['root'] . '/' . $files[ null ] . '/' . $entry ) )
- {
- if ( ( $entry !== '.' ) && ( $entry !== '..' ) )
- {
- foreach( $Exts as $Ext )
- {
- if ( substr( $entry, -strlen( '.'.$Ext ), strlen( '.'.$Ext ) ) === '.'.$Ext )
- {
- $files[ $entry ] = null;
- }
- }
- }
- }
- }
- }
- closedir($handle);
- }
- jensort($files);
- }
- function trk_cleancfg( &$config = array() )
- {
- $config_temp = $config;
- $config = array();
- foreach( $config_temp as $k => $v )
- {
- if( is_integer( $k ) )
- {
- _e if( is_array( $v ) )
- {
- foreach( $v as $k2 => $v2 )
- {
- $config[ $k2 ] = $v2;
- }
- }
- elseif( is_string( $v ) )
- {
- $config[ $v ] = '';
- }
- }
- }
- unset( $config_temp );
- }
- function trk_fastini( $cfgfile = '', &$ini = array() )
- {
- trk_loadcfg( $cfgfile, $config );
- trk_cleancfg( $config );
- $ini = array();
- foreach( $config as $k => $empty )
- {
- $ini[ $k ] = jpp_build( $k );
- }
- }
- function trk_loadcfg($filename = '', &$config = array() )
- {
- $nen = nen_ini();
- $crlf = "\r\n";
- $comma = ",";
- $colon = ":";
- $quot = "\"";
- $buffer = '';
- if( file_exists($nen['root'].$filename ) ? is_file($nen['root'].$filename) : false )
- {
- trk_fastload( $filename, $buffer );
- }
- else
- {
- $buffer = '';
- }
- trk_fastcfg( $buffer, $config );
- }
- function trk_fastcfg( $buffer = '', &$config = array() )
- {
- $config = array();
- $crlf = "\r\n";
- $colon = ":";
- $comma = ",";
- $quot = "\"";
- $ct = 0;
- if( strlen( $buffer ) === 0 )
- {
- return;
- }
- elseif ( strpos( $buffer, $crlf ) !== false )
- {
- trk_tok( $buffer, $crlf, $lines );
- unset( $lines[ 0 ] );
- foreach($lines as $line)
- {
- trk_fastcfg( $line, $config[] );
- }
- return;
- }
- elseif ( strpos( $buffer, $colon ) !== false )
- {
- $prefix = substr( $buffer, 0, strpos( $buffer, $colon ) );
- $suffix = substr( $buffer, strpos( $buffer, $colon ) + 1 );
- $config[ $prefix ] = $suffix;
- return;
- }
- elseif ( strpos( $buffer, $comma ) !== false )
- {
- trk_tok( $buffer, $comma, $parts );
- unset( $parts[ 0 ] );
- foreach($parts as $part)
- {
- $config[] = $part;
- }
- return;
- }
- else
- {
- $config = $buffer;
- return;
- }
- }
- function trk_fastload( $filename = '', &$buffer = '')
- {
- if( is_file( $filename ) )
- {
- $buffer = file_get_contents($filename);
- }
- else
- {
- $buffer = '';
- }
- }
- function trk_tok( $subject = '', $delimiter = ',', &$tok = array() )
- {
- $tok = explode( $delimiter, $delimiter.$subject );
- $tok[0] = $subject;
- }
- function trk_implode( $tok = array(), $delimiter = ',', &$buffer = '' )
- {
- if( isset( $tok[0] ) )
- {
- unset( $tok[0] );
- }
- $buffer = implode( $delimiter, $tok);
- }
- function trk_stripchars ($subject = '', $ws = ' ',$replace = '', &$buffer = '' )
- {
- $buffer = str_replace( $ws, $replace, $subject );
- }
- function trk_striptok ( $subject='', $delimiter=',', $skip = '', &$buffer = '')
- {
- $tok=array();
- trk_tok( $subject, $delimiter, $tok() );
- $token_index = 0; $buffer_index = 0;
- if( count( tok ) < 1 )
- {
- return;
- }
- $buffer = '';
- foreach( $tok as $tok_index => $tok_dat)
- {
- if( !( $tok[ $token_index ] === 0 ) )
- {
- if( !( $tok[ $token_index ] === $skip ) )
- {
- if( strlen( $buffer ) > 0 )
- {
- $buffer .= $delimiter;
- }
- $buffer .= $tok[ token_index ];
- }
- }
- }
- }
- function trk_debug( $color = 'red', $subject = '' )
- {
- return '<span style="color:'.$color.';">'.$subject.'</span>';
- }
- function trk_fastlog( $caption, $filename )
- {
- return '<h1>'.htmlentities( strtoupper( $caption ) ).':'.trk_fastdump( jpp_build( $filename ) ).'</h1>';
- }
- const DESIGNATIONS = ['array' => 'red', 'string' => 'orange', 'integer' => 'orange', 'float' => 'orange', 'bool' => 'orange', 'object' => 'brown', 'null' => 'yellow', 'unknown' => 'purple'];
- function trk_styles(string $designation):string {
- return DESIGNATIONS[$designation] ?? '';
- }
- // include Tim Keal's memory trace library
- function trk_emoji( $buffer )
- {
- $nen = nen_ini();
- return '<img src="./emojis/stop-sign.png" style="width:50px;height:50px;">'. strtoupper( $buffer );
- }
- function trk_echo2($header = '', $buffer = '')
- {
- echo '<h1>' . trk_emoji($header) . '[' . trk_fastdump($buffer) . ']</h1>';
- }
- function trk_fastdump( $subject = array() )
- {
- $ret = '';
- switch( true )
- {
- case is_array( $subject ):
- $type = 'array';
- break;
- case is_string( $subject ):
- $type = 'string';
- break;
- case is_integer( $subject ):
- $type = 'integer';
- break;
- case is_float( $subject ):
- $type = 'float';
- break;
- case is_bool( $subject ):
- $type = 'bool';
- break;
- case is_object( $subject ):
- $type = 'object';
- break;
- case is_null( $subject ):
- $type = 'null';
- break;
- default:
- $type = 'unknown';
- break;
- }
- switch( $type )
- {
- case 'array':
- $ret.=
- trk_debug('red','array{');
- $ct=0;
- foreach( $subject as $key => $value )
- {
- $ct++;
- if( $ct > 0 )
- {
- $ret.= trk_debug( trk_styles( 'array' ), '[' ).trk_fastdump($key).trk_debug( trk_styles( 'array' ), ']');
- $ret.= trk_debug( trk_styles( 'array' ), ' => ');
- $ret.= trk_fastdump( $value );
- if( $ct < count( $subject ) )
- {
- $ret.= trk_debug( trk_styles( 'array' ), ',');
- }
- }
- }
- $ret.= trk_debug('red','}');
- break;
- case 'string':
- $ret.=
- 'string('.strlen($subject).')'.
- ' '.
- '"'.htmlentities($subject).'"';
- break;
- case 'integer':
- $ret.=
- trk_debug( trk_styles( $type ), $type.'[').
- htmlentities($subject).
- trk_debug( trk_styles( $type ),']');
- break;
- case 'float':
- $ret.=
- trk_debug( trk_styles( $type ), $type.'[').
- htmlentities($subject).
- trk_debug( trk_styles( $type ),']');
- break;
- case 'bool':
- $ret.=
- trk_debug( trk_styles( $type ), $type.'[').
- htmlentities($subject===true?'True':'False').
- trk_debug( trk_styles( $type ),']');
- break;
- case 'null':
- $ret.=
- trk_debug( trk_styles( $type ), $type.'[').
- htmlentities('NULL').
- trk_debug( trk_styles( $type ),']');
- break;
- case 'object':
- case 'unknown':
- default:
- $ret.=
- trk_debug( trk_styles( $type ),$type.'[').
- htmlentities( strtoupper( $type ) ).
- trk_debug( trk_styles( $type ),']');
- break;
- }
- return $ret;
- }
- // include Tim Keal's table of contents library
- function fasttoc( $path = '', $ext = array() )
- {
- $nen = nen_ini();
- if( is_string( $ext ) )
- {
- $ext = array( 0 => $ext );
- }
- $buffer = ( is_dir( $nen['root'] . $path ) ? array_diff( scandir( $nen['root'] . $path, SCANDIR_SORT_ASCENDING ), array('..', '.' ) ) : array() );
- $toc = array();
- foreach( $buffer as $entry )
- {
- $hit = 0;
- foreach( $ext as $test )
- {
- if( strtolower( substr( $entry, -strlen( $test ), strlen( $test ) ) ) === strtolower( $test ) )
- {
- $hit++;
- break;
- }
- }
- if( $hit > 0 )
- {
- $toc[ count( $toc ) ] = $entry;
- }
- }
- return $toc;
- }
- function me_shorthand()
- {
- $pattern = '/(mk)(11|45|71)([A-Z]+)(\.php)/';
- if( preg_match($pattern, $_SERVER['SCRIPT_NAME'], $matches) )
- {
- return array( 'mk' => $matches[ 2 ], 'me'=> $matches[ 3 ] );
- }
- else
- {
- return null;
- }
- }
- function main()
- {
- $nen = nen_ini();
- $pagedata = '';
- // top of page (title)
- $pagedata .= '<html><head><title>Roe XAMPP Builder (mk'.
- ( !is_null( $nen['me'] ) ? ' '. $nen['me']['mk'] : '').
- ( !is_null( $nen['me'] ) ? ' '. $nen['me']['me'] : '').
- ')</title><link rel="stylesheet" href="./css/stylesheet.css"></head><body>';
- // copyright header
- $pagedata .= '<table style="width:100%;text-align:top;"><tr><th colspan="2"><span style="alignment:center center;font-size:170%;">Roe Collector Card Game</span><br><span style="alignment:center center;font-size:120%;">Copyright 1997, 2021 Tim Keal</span><br><span style="alignment:center center;font-size:100%;">mk'. $nen['me']['mk']. $nen['me']['me']. '</span></th></tr>';
- $pagedata .= '<tr><td>'. regex_toc(). '</td></tr>';
- // bottom of page
- $pagedata .= '</table></body></html>';
- return $pagedata;
- }
- function regex_toc()
- {
- $nen = nen_ini();
- // table of contents filename pattern
- $toc_index = 0;
- $toc_pattern = '/(?<prefix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<suffix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<ext>\.bmp)/';
- $toc = fasttoc( 'tiles src data/rgb', array( '.bmp' ) );
- trk_echo2('toc',$toc);
- $toc_result = '';
- $tiles_replace = "$0\n";
- $toc_lines = array();
- $result = '';
- // loop through toc
- while(
- ($toc_index > count( $toc ) - 1)?false:preg_match(
- $toc_pattern,
- $toc[ $toc_index ],
- $toc_matches
- )
- )
- {
- /*
- // echo current toc filename
- $result .= '<h3>'. htmlentities( $toc[ $toc_index ] ). '</h3>';
- */
- // load current image document by toc index into page memory
- $image['rgb'] = imagecreatefrombmp($nen[ 'root' ]. 'tiles src data/rgb/'. $toc[ $toc_index ] );
- $image['mask'] = imagecreatefrombmp($nen[ 'root' ]. 'tiles src data/mask/'. $toc[ $toc_index ] );
- $result .= adhere_tiles( $image );
- // increment one table of contents file higher
- $toc_index++;
- }
- return $result;
- }
- function adhere_tiles( $image = array() )
- {
- $nen = nen_ini();
- $result = '';
- //load tiles regular expression
- /*
- $tiles_pattern ='/sub (?<tilesname>do[a-z]+[a-z0-9]*)/m';
- $tiles_pattern2 = file_get_contents( $nen[ 'root' ]. 'pcre/tiles.pattern.pcre' );
- if( $tiles_pattern !== $tiles_pattern2 )
- {
- $tiles_pattern = $tiles_pattern2;
- }
- unset( $tiles_pattern2 );
- */
- //load tiles single layer png
- $width['rgb'] = imagesx(image['rgb']);
- $height['rgb'] = imagesy(image['rgb']);
- $width['mask'] = imagesx(image['mask']);
- $height['mask'] = imagesy(image['mask']);
- $width['combo'] = $width['rgb'];
- $height['combo'] = $height['rgb'];
- $image['combo'] = imagecreate($width['combo'], $height['combo']);
- // assign replacement (unused)
- //$tiles_replace = "$0\n";
- // create desination folder if it does not exist
- if( !is_dir( $nen[ 'root' ]. 'tiles out data' ) )
- {
- mkdir ( $nen[ 'root' ]. 'tiles out data' );
- }
- if( !is_dir( $nen[ 'root' ]. 'tiles out data/combo' ) )
- {
- mkdir ( $nen[ 'root' ]. 'tiles out data/combo' );
- }
- $col = 0;
- $row = 0;
- while($row < $height['combo'])
- {
- while($col < $width['combo'])
- {
- $pix['rgb']=imagegetcolorat($image['rgb'], $col, $row);
- $pix['mask']=imagegetcolorat($image['mask'], $col, $row);
- $pix['combo']=rand(0, 255);
- imagesetpixel($image['combo'], $col, $row, $pix['combo']);
- $col++;
- }
- $row++;
- }
- file_put_contents( $nen[ 'root' ]. 'tiles out data/combo/'. $tiles_matches[ 'tilesname' ][ $tiles_index ]. '.png', imagepng( $image['combo'] ) );
- return $result;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement