Advertisement
jargon

mk11TILES.php DEESIGNATIONS error

Oct 9th, 2021
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.23 KB | None | 0 0
  1. <?php
  2.  
  3. //$nen = nen_ini();
  4. echo main();
  5.  
  6. function nen_ini()
  7. {  
  8.     $nen['me'] = me_shorthand($_SERVER['SCRIPT_NAME']);
  9.  
  10.     $nen[ 'src' ] = 'R11-SRC';
  11.     $nen[ 'emojis' ] = 'emojis/';
  12.  
  13.     // assign domain root
  14.     $nen['domain']='Roe XAMPP Builder';
  15.    
  16.     // assign host mode (local)
  17.     $nen[ 'host' ] = 'local';
  18.    
  19.     // assign host mode (online)
  20.     //$nen[ 'host' ] = 'online';
  21.    
  22.     // switch http host vars
  23.     switch( $_SERVER[ 'HTTP_HOST' ] )
  24.     {
  25.        
  26.     case 'localhost':
  27.         // domain local
  28.         $nen[ 'root' ] = $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $nen[ 'domain' ] . '/';
  29.         break;
  30.  
  31.     default:
  32.         // domain host
  33.         $nen[ 'root' ] = $_SERVER[ 'DOCUMENT_ROOT' ] . '/';
  34.         break;     
  35.     }
  36.    
  37.     return $nen;
  38. }
  39.  
  40. // configure cascading stylesheet
  41. function nen_css()
  42. {
  43.     $nen = nen_ini();
  44.     // load stylesheet into memory 
  45.     return file_get_contents( $nen[ 'root' ]. 'css/stylesheet.css');
  46. }
  47.  
  48.  
  49. // include Tim Keal's token library
  50. function trk_strippath( $filename = '' )
  51. {
  52.     trk_stripchars( $filename, '\\', '/', $file );
  53.     trk_tok( $file, '/', $tok );
  54.     return strtoupper( $tok[ count( $tok ) - 1 ] );
  55. }
  56.  
  57. function trk_fastfiles( $path = '', $Exts = array(), &$files = array() )
  58. {
  59.     $nen = nen_ini();
  60.  
  61.     $files[ null ] = $path;
  62.    
  63.     if ( is_dir( $nen['root'] . '/' . $path . '/' ) )
  64.     {
  65.         if ( $handle = opendir( $nen['root'] . '/' . $files[ null ] . '/' ) )
  66.         {
  67.             while ( false !== ( $entry = readdir( $handle ) ) )
  68.             {
  69.                 if( is_file( $nen['root'] . '/' . $files[ null ] . '/' . $entry ) )
  70.                 {
  71.                     if ( ( $entry !== '.' ) && ( $entry !== '..' ) )
  72.                     {
  73.                         foreach( $Exts as $Ext )
  74.                         {
  75.                             if ( substr( $entry, -strlen( '.'.$Ext ), strlen( '.'.$Ext ) ) === '.'.$Ext )
  76.                             {
  77.                                 $files[ $entry ] = null;
  78.                             }
  79.                         }
  80.                     }
  81.                 }
  82.             }
  83.         }
  84.        
  85.         closedir($handle);
  86.     }
  87.     jensort($files);
  88. }
  89.  
  90. function trk_cleancfg( &$config = array() )
  91. {
  92.     $config_temp = $config;
  93.     $config = array();
  94.    
  95.     foreach( $config_temp as $k => $v )
  96.     {
  97.         if( is_integer( $k ) )
  98.         {
  99.             if( is_array( $v ) )
  100.             {
  101.                 foreach( $v as $k2 => $v2 )
  102.                 {
  103.                     $config[ $k2 ] = $v2;
  104.                 }
  105.             }
  106.             elseif( is_string( $v ) )
  107.             {
  108.                 $config[ $v ] = '';
  109.             }
  110.         }
  111.     }
  112.        
  113.     unset( $config_temp );
  114. }
  115.  
  116. function trk_fastini( $cfgfile = '', &$ini = array() )
  117. {
  118.     trk_loadcfg( $cfgfile, $config );
  119.     trk_cleancfg( $config );
  120.  
  121.     $ini = array();
  122.     foreach( $config as $k => $empty )
  123.     {
  124.         $ini[ $k ] = jpp_build( $k );
  125.     }
  126. }
  127.  
  128. function trk_loadcfg($filename = '', &$config = array() )
  129. {
  130.     $nen = nen_ini();
  131.    
  132.     $crlf = "\r\n";
  133.     $comma = ",";
  134.     $colon = ":";
  135.     $quot = "\"";
  136.    
  137.     $buffer = '';
  138.    
  139.     if( file_exists($nen['root'].$filename ) ? is_file($nen['root'].$filename) : false )
  140.     {
  141.         trk_fastload( $filename, $buffer );
  142.     }
  143.     else
  144.     {
  145.         $buffer = '';
  146.     }
  147.    
  148.     trk_fastcfg( $buffer, $config );
  149. }
  150.  
  151. function trk_fastcfg( $buffer = '', &$config = array() )
  152. {
  153.     $config = array();
  154.    
  155.     $crlf   =   "\r\n";
  156.     $colon  =   ":";
  157.     $comma  =   ",";
  158.     $quot   =   "\"";
  159.  
  160.     $ct = 0;
  161.     if( strlen( $buffer ) === 0 )
  162.     {
  163.         return;
  164.     }
  165.     elseif ( strpos( $buffer, $crlf ) !== false )
  166.     {  
  167.         trk_tok( $buffer, $crlf, $lines );
  168.         unset( $lines[ 0 ] );
  169.        
  170.         foreach($lines as $line)
  171.         {
  172.             trk_fastcfg( $line, $config[] );
  173.         }
  174.        
  175.         return;
  176.     }
  177.     elseif ( strpos( $buffer, $colon ) !== false )
  178.     {
  179.         $prefix = substr( $buffer, 0, strpos( $buffer, $colon ) );
  180.         $suffix = substr( $buffer, strpos( $buffer, $colon ) + 1 );
  181.        
  182.         $config[ $prefix ] = $suffix;
  183.        
  184.         return;
  185.     }
  186.     elseif ( strpos( $buffer, $comma ) !== false )
  187.     {  
  188.         trk_tok( $buffer, $comma, $parts );
  189.         unset( $parts[ 0 ] );
  190.                
  191.         foreach($parts as $part)
  192.         {
  193.             $config[] = $part;
  194.         }
  195.        
  196.         return;
  197.     }
  198.     else
  199.     {
  200.         $config = $buffer;
  201.         return;
  202.     }
  203.        
  204. }
  205.  
  206. function trk_fastload( $filename = '', &$buffer = '')
  207. {
  208.     if( is_file( $filename ) )
  209.     {
  210.         $buffer = file_get_contents($filename);
  211.     }
  212.     else
  213.     {
  214.         $buffer = '';
  215.     }
  216. }
  217.  
  218.  
  219. function trk_tok( $subject = '', $delimiter = ',', &$tok = array() )
  220. {
  221.     $tok = explode( $delimiter, $delimiter.$subject );
  222.     $tok[0] = $subject;
  223. }
  224.  
  225. function trk_implode( $tok = array(), $delimiter = ',', &$buffer = '' )
  226. {
  227.     if( isset( $tok[0] ) )
  228.     {
  229.         unset( $tok[0] );
  230.     }
  231.     $buffer = implode( $delimiter, $tok);
  232. }
  233.  
  234. function trk_stripchars ($subject = '', $ws = ' ',$replace = '', &$buffer = '' )
  235. {
  236.     $buffer = str_replace( $ws, $replace, $subject );
  237. }
  238.  
  239. function trk_striptok ( $subject='', $delimiter=',', $skip = '', &$buffer = '')
  240. {
  241.     $tok=array();
  242.     trk_tok( $subject, $delimiter, $tok() );
  243.     $token_index = 0; $buffer_index = 0;
  244.    
  245.     if( count( tok ) < 1 )
  246.     {
  247.         return;
  248.     }
  249.    
  250.     $buffer = '';
  251.    
  252.     foreach( $tok as $tok_index => $tok_dat)
  253.     {
  254.         if( !( $tok[ $token_index ] === 0 ) )
  255.         {
  256.             if( !( $tok[ $token_index ] === $skip ) )
  257.             {
  258.                 if( strlen( $buffer ) > 0 )
  259.                 {
  260.                     $buffer .= $delimiter;
  261.                 }
  262.                 $buffer .= $tok[ token_index ];
  263.             }
  264.         }
  265.     }
  266.  
  267. }
  268.  
  269. function trk_debug( $color = 'red', $subject = '' )
  270. {
  271.     return '<span style="color:'.$color.';">'.$subject.'</span>';
  272. }
  273.  
  274. function trk_fastlog( $caption, $filename )
  275. {
  276.     return '<h1>'.htmlentities( strtoupper( $caption ) ).':'.trk_fastdump( jpp_build( $filename ) ).'</h1>';
  277. }
  278.  
  279. const DESIGNATIONS = ['array' => 'red', 'string' => 'orange', 'integer' => 'orange', 'float' => 'orange', 'bool' => 'orange', 'object' => 'brown', 'null' => 'yellow', 'unknown' => 'purple'];
  280.  
  281. function trk_styles(string $designation):string {
  282.     return DESIGNATIONS[$designation] ?? '';
  283. }
  284.  
  285. // include Tim Keal's memory trace library
  286. function trk_emoji( $buffer )
  287. {
  288.     $nen = nen_ini();
  289.  
  290.     return '<img src="./emojis/stop-sign.png" style="width:50px;height:50px;">'. strtoupper( $buffer );
  291. }
  292.  
  293. function trk_echo2($header = '', $buffer = '')
  294. {
  295.     echo '<h1>' . trk_emoji($header) . '[' . trk_fastdump($buffer) . ']</h1>';
  296. }
  297.  
  298. function trk_fastdump( $subject = array() )
  299. {
  300.     $ret = '';
  301.    
  302.     switch( true )
  303.     {
  304.     case is_array( $subject ):
  305.         $type = 'array';
  306.         break;
  307.     case is_string( $subject ):
  308.         $type = 'string';
  309.         break;
  310.     case is_integer( $subject ):
  311.         $type = 'integer';
  312.         break;
  313.     case is_float( $subject ):
  314.         $type = 'float';
  315.         break;
  316.     case is_bool( $subject ):
  317.         $type = 'bool';
  318.         break;
  319.     case is_object( $subject ):
  320.         $type = 'object';
  321.         break;
  322.     case is_null( $subject ):
  323.         $type = 'null';
  324.         break;
  325.     default:
  326.         $type = 'unknown';
  327.         break;
  328.     }
  329.    
  330.     switch( $type )
  331.     {
  332.     case 'array':
  333.        
  334.         $ret.=
  335.         trk_debug('red','array{');
  336.         $ct=0;
  337.         foreach( $subject as $key => $value )
  338.         {
  339.             $ct++;
  340.             if( $ct > 0 )
  341.             {
  342.                 $ret.= trk_debug( trk_styles( 'array' ), '[' ).trk_fastdump($key).trk_debug( trk_styles( 'array' ), ']');
  343.  
  344.                 $ret.= trk_debug( trk_styles( 'array' ), ' => ');
  345.                
  346.                 $ret.= trk_fastdump( $value );
  347.                
  348.                 if( $ct < count( $subject ) )
  349.                 {  
  350.                     $ret.= trk_debug( trk_styles( 'array' ), ',');
  351.                 }
  352.             }
  353.         }
  354.         $ret.= trk_debug('red','}');
  355.  
  356.         break;
  357.    
  358.     case 'string':
  359.         $ret.=
  360.             'string('.strlen($subject).')'.
  361.             ' '.
  362.             '"'.htmlentities($subject).'"';
  363.         break;
  364.     case 'integer':
  365.         $ret.=
  366.             trk_debug( trk_styles( $type ), $type.'[').
  367.             htmlentities($subject).
  368.             trk_debug( trk_styles( $type ),']');
  369.         break;
  370.     case 'float':
  371.         $ret.=
  372.             trk_debug( trk_styles( $type ), $type.'[').
  373.             htmlentities($subject).
  374.             trk_debug( trk_styles( $type ),']');
  375.         break;
  376.     case 'bool':
  377.         $ret.=
  378.             trk_debug( trk_styles( $type ), $type.'[').
  379.             htmlentities($subject===true?'True':'False').
  380.             trk_debug( trk_styles( $type ),']');
  381.         break;
  382.  
  383.     case 'null':
  384.         $ret.=
  385.             trk_debug( trk_styles( $type ), $type.'[').
  386.             htmlentities('NULL').
  387.             trk_debug( trk_styles( $type ),']');
  388.         break;
  389.     case 'object':
  390.     case 'unknown':
  391.     default:
  392.  
  393.         $ret.=
  394.             trk_debug( trk_styles( $type ),$type.'[').
  395.             htmlentities( strtoupper( $type ) ).
  396.             trk_debug( trk_styles( $type ),']');
  397.         break;     
  398.     }
  399.     return $ret;
  400. }
  401.  
  402. // include Tim Keal's table of contents library
  403.  
  404. function fasttoc( $path = '', $ext = array() )
  405. {
  406.     $nen = nen_ini();
  407.  
  408.     if( is_string( $ext ) )
  409.     {
  410.         $ext = array( 0 => $ext );
  411.     }
  412.    
  413.     $buffer = ( is_dir( $nen['root'] . $path ) ? array_diff( scandir( $nen['root'] . $path, SCANDIR_SORT_ASCENDING ), array('..', '.' ) ) : array() );
  414.    
  415.     $toc = array();
  416.    
  417.     foreach( $buffer as $entry )
  418.     {
  419.         $hit = 0;
  420.         foreach( $ext as $test )
  421.         {
  422.        
  423.             if( strtolower( substr( $entry, -strlen( $test ), strlen( $test ) ) ) === strtolower( $test ) )
  424.             {
  425.                 $hit++;
  426.                 break;
  427.             }
  428.         }
  429.         if( $hit > 0 )
  430.         {
  431.             $toc[ count( $toc ) ] = $entry;
  432.         }
  433.     }
  434.        
  435.     return $toc;
  436. }
  437.  
  438. function me_shorthand()
  439. {
  440.     $pattern = '/(mk)(11|45|71)([A-Z]+)(\.php)/';
  441.     if( preg_match($pattern, $_SERVER['SCRIPT_NAME'], $matches) )
  442.     {
  443.         return array( 'mk' => $matches[ 2 ], 'me'=> $matches[ 3 ] );
  444.     }
  445.     else
  446.     {
  447.         return null;
  448.     }
  449. }
  450.  
  451. function main()
  452. {
  453.     $nen = nen_ini();
  454.     $pagedata = '';
  455.  
  456.     // top of page (title)
  457.     $pagedata .= '<html><head><title>Roe XAMPP Builder (mk'.
  458.     ( !is_null( $nen['me'] ) ? ' '. $nen['me']['mk'] : '').
  459.     ( !is_null( $nen['me'] ) ? ' '. $nen['me']['me'] : '').
  460.     ')</title><link rel="stylesheet" href="./css/stylesheet.css"></head><body>';
  461.  
  462.  
  463.     // copyright header
  464.     $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>';
  465.  
  466.     $pagedata .= '<tr><td>'. regex_toc(). '</td></tr>';
  467.  
  468.     // bottom of page
  469.     $pagedata .= '</table></body></html>';
  470.    
  471.     return $pagedata;
  472. }
  473.    
  474. function regex_toc()
  475. {
  476.     $nen = nen_ini();
  477.    
  478.     // table of contents filename pattern
  479.     $toc_index = 0;
  480.     $toc_pattern = '/(?<prefix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<suffix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<ext>\.bmp)/';
  481.    
  482.     $toc = fasttoc( 'tiles src data/rgb', array( '.bmp' ) );
  483.  
  484.     trk_echo2( 'toc', $toc );
  485.  
  486.     $toc_result = '';
  487.  
  488.     $tiles_replace = "$0\n";
  489.    
  490.     $toc_lines = array();
  491.    
  492.     $result = '';
  493.    
  494.     // loop through toc
  495.     while(
  496.         ($toc_index > count( $toc ) - 1)?false:preg_match(
  497.         $toc_pattern,
  498.         $toc[ $toc_index ],
  499.         $toc_matches
  500.         )
  501.     )
  502.     {      
  503.         /*
  504.         // echo current toc filename
  505.         $result .= '<h3>'. htmlentities( $toc[ $toc_index ] ). '</h3>';
  506.         */
  507.        
  508.         // load current image document by toc index into page memory
  509.        
  510.         $image['rgb'] = imagecreatefrombmp($nen[ 'root' ]. 'tiles src data/rgb/'. $toc[ $toc_index ] );
  511.        
  512.         $image['mask'] = imagecreatefrombmp($nen[ 'root' ]. 'tiles src data/mask/'. $toc[ $toc_index ] );
  513.                
  514.         $result .= adhere_tiles( $image );
  515.        
  516.         // increment one table of contents file higher
  517.         $toc_index++;      
  518.        
  519.     }
  520.    
  521.     return $result;
  522.    
  523. }
  524.  
  525. function adhere_tiles( $image = array() )
  526. {
  527.     $nen = nen_ini();
  528.     $result = '';
  529.    
  530.     //load tiles regular expression
  531.     /*
  532.     $tiles_pattern ='/sub (?<tilesname>do[a-z]+[a-z0-9]*)/m';
  533.     $tiles_pattern2 = file_get_contents( $nen[ 'root' ]. 'pcre/tiles.pattern.pcre' );
  534.     if( $tiles_pattern !== $tiles_pattern2 )
  535.     {
  536.         $tiles_pattern = $tiles_pattern2;
  537.     }
  538.     unset( $tiles_pattern2 );
  539.     */
  540.  
  541.     //load tiles single layer png
  542.    
  543.     $width['rgb']  = imagesx(image['rgb']);
  544.     $height['rgb']  = imagesy(image['rgb']);
  545.  
  546.     $width['mask']  = imagesx(image['mask']);
  547.     $height['mask']  = imagesy(image['mask']);
  548.  
  549.     $width['combo']  = $width['rgb'];
  550.     $height['combo']  = $height['rgb'];
  551.    
  552.     $image['combo'] = imagecreate($width['combo'], $height['combo']);
  553.      
  554.     // assign replacement (unused)
  555.     //$tiles_replace = "$0\n";
  556.    
  557.     // create desination folder if it does not exist
  558.  
  559.     if( !is_dir( $nen[ 'root' ]. 'tiles out data' ) )
  560.     {
  561.         mkdir ( $nen[ 'root' ]. 'tiles out data' );
  562.     }
  563.  
  564.     if( !is_dir( $nen[ 'root' ]. 'tiles out data/combo' ) )
  565.     {
  566.         mkdir ( $nen[ 'root' ]. 'tiles out data/combo' );
  567.     }
  568.    
  569.     $col = 0;
  570.     $row = 0;
  571.     while($row < $height['combo'])
  572.     {
  573.         while($col < $width['combo'])
  574.         {
  575.             $pix['rgb']=imagegetcolorat($image['rgb'], $col, $row);
  576.            
  577.             $pix['mask']=imagegetcolorat($image['mask'], $col, $row);
  578.            
  579.             $pix['combo']=rand(0, 255);
  580.            
  581.             imagesetpixel($image['combo'], $col, $row, $pix['combo']);
  582.             $col++;
  583.         }
  584.         $row++;
  585.     }
  586.        
  587.     file_put_contents( $nen[ 'root' ]. 'tiles out data/combo/'. $tiles_matches[ 'tilesname' ][ $tiles_index ]. '.png', imagepng( $image['combo'] ) );
  588.    
  589.     return $result;
  590.    
  591. }
  592.  
  593.  
  594. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement