jargon

Roe Web Builder - Vars

Oct 20th, 2021
947
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. echo listvars();
  4.  
  5. function listvars( $vars = 'vars' )
  6. {
  7.     $vars = minus_reserved( dumpvars( $vars ) );
  8.    
  9.     $pagerow = '<p>{{key}} (x{{value}})</p>';
  10.     $pagedata = '';
  11.    
  12.     foreach($vars as $key => $value )
  13.     {
  14.         $pagedata.= str_replace( '{{value}}', $value, str_replace( '{{key}}', $key, $pagerow ) );
  15.     }
  16.    
  17.     return $pagedata;
  18. }
  19.  
  20. function dumpvars( $filename = 'vars' )
  21. {
  22.     $nen = nen_ini();
  23.    
  24.     $subject = file_get_contents( $nen[ 'root' ]. $filename. '.dat' );
  25.  
  26.     $v = array();
  27.    
  28.     $pattern = '/(?<var>(?<prefix>\$|)(?<name>[A-Za-z][A-Za-z0-9]*)(?<ext>[%&!#$]|))/m';
  29.    
  30.     if( preg_match_all( $pattern, $subject, $matches, PREG_UNMATCHED_AS_NULL ) )
  31.     {
  32.         foreach($matches as $group )
  33.         {
  34.             if( isset( $group[ 'var' ] ) )
  35.             {
  36.                 trk_echo2('group',$group);
  37.                 if( !isset( $v[ $group[ 'var' ] ] ) )
  38.                 {
  39.                     $v[ $group[ 'var' ] ] = 0;
  40.                 }
  41.                 $v[ $group[ 'var' ] ]++;
  42.             }
  43.         }
  44.     }
  45.     return $v;
  46. }
  47.  
  48. function minus_reserved( $vars = array(), $reserved = null)
  49. {  
  50.     if( is_null( $reserved ) )
  51.     {
  52.         $reserved = 'reserved';
  53.     }
  54.  
  55.     if( is_string( $reserved ) )
  56.     {
  57.         $reserved = dumpvars( $reserved );
  58.     }
  59.    
  60.     if( !is_array( $reserved ) )
  61.     {
  62.         $reserved = array();
  63.     }
  64.    
  65.     foreach( $reserved as $key => $value )
  66.     {
  67.         if( isset( $vars[ $key ] ) )
  68.         {
  69.             unset( $vars[ $key ] );
  70.         }
  71.     }
  72.     return $vars;
  73. }
  74.  
  75. ?>
RAW Paste Data