[ | [ | ...] ] // Embeds an external file in the source code as a gzipped and base64-encoded string; // optional filter functions can be "piped" at the end of the line; // multiple files can be specified with glob syntax. E.g., classes/*.php // // # INCLUDE [ | [ | ...] ] // Includes code from another php file; expects the first line of the file to // start with ' // Assigns a variable using the current value in the build script; // will generate a valid and indented line of php code. E.g. // $myvar = array('key'=>'value','otherkey'=>'othervalue'); // // ###identifier### // Is replaced with the value of $build_data['identifier']; if the array // element is not defined, the string will be left untouched. // // # REMOVE_FROM_BUILD ... # END REMOVE_FROM_BUILD // Anything between the two directive will be removed from the final code. // // # other build comments // Any remaining lines starting with a # will be removed. // // === build script configuration === $inputfile = 'phpliteadmin-build-template.php'; $outputfile = 'phpliteadmin.php'; date_default_timezone_set('UTC'); // === identifiers recognized in EXPORT and ###something### directives === $build_data = array( // used for resource embedding 'resources' => array(), 'resourcesize' => 0, // custom variables 'build_date' => date('Y-m-d'), 'build_year' => date('Y'), ); ?> phpLiteAdmin build script Building phpLiteAdmin
    "; // load the build template only this file will be parsed for build directives echo "
  1. Loading template: {$inputfile}"; $output .= file_get_contents($inputfile); // parse EMBED echo "
  2. Embedding resources
      "; $output = preg_replace_callback('@(\r?\n?)^#\s*EMBED\s+(?P\S+)\s*(?P(\|\s*\w+\s*)+|)\r?\n?$@m', 'replace_embed', $output); echo "
    "; // parse INCLUDE echo "
  3. Including files
      "; $output = preg_replace_callback('@^#\s*INCLUDE\s+(?P\S+)\s*(?P(\|\s*\w+\s*)+|)$@m', 'replace_include', $output); echo "
    "; // parse EXPORT echo "
  4. Replacing variables
      "; $output = preg_replace_callback('@^(?P\s*)#\s*EXPORT\s+\$?(?P\w+)\s*$@m', 'replace_export', $output); // parse ###identifier### $output = preg_replace_callback('@###(?P\w+)###@', 'replace_value', $output); echo "
    "; // parse REMOVE_FROM_BUILD echo "
  5. Removing ignored code"; $output = preg_replace('@(\r?\n?)^#\s*REMOVE_FROM_BUILD.*?^#\s*END\s+REMOVE_FROM_BUILD\s*$@ms', '', $output); // remove other comments starting with '#' echo "
  6. Removing build comments"; $output = preg_replace('@\r?\n#[^\r\n]*@m', "", $output); // save result script to file echo "
  7. Saving code to {$outputfile}"; file_put_contents($outputfile, $output); // ===== end of main code, support functions follow ===== ?>
{$filename}"; // read file and remove first '{$filename} - cannot read file"; } } } else { echo "
  • {$m['pattern']} - no files matching"; } return $source; } function replace_embed($m) { if ($m['filters']) { $filters = array_map('trim', preg_split('@\s*\|\s*@', trim($m['filters'], ' |'))); } else { $filters = array(); } $result = ''; global $build_data; $matching_files = glob($m['pattern']); if ($matching_files) { foreach ($matching_files as $filename) { if (is_file($filename) && is_readable($filename)) { echo "
  • {$filename}"; $data = file_get_contents($filename); // pipe $data through filter functions foreach ($filters as $function) { $data = call_user_func($function, $data); } // encode filtered data, // $data = base64_encode(gzencode($data)); // disabled after #197 $result .= $data; // evaluate size and position relative to __COMPILER_HALT_OFFSET__ $size = strlen($data); $build_data['resources'][$filename] = array($build_data['resourcesize'], $size); $build_data['resourcesize'] += $size; } else { echo "
  • {$filename} - cannot read file"; } } } else { echo "
  • {$m['pattern']} - no files matching"; } return $result; } function replace_export($m) { global $build_data; $variable = $m['identifier']; if (isset($build_data[$variable])) { echo "
  • \${$variable} = " . gettype($build_data[$variable]); return $m['indent'] . '$' . $variable . ' = ' . preg_replace('/\s+/','', var_export($build_data[$variable], true)) . ';' . PHP_EOL; } // remove line if variabile is not defined echo "
  • \${$variable} - variable not defined"; return ''; } function replace_value($m) { global $build_data; $variable = $m['identifier']; if (isset($build_data[$variable])) { echo "
  • \${$variable} = " . gettype($build_data[$variable]); return $build_data[$variable]; } // leave the string if the variable is not defined echo "
  • \${$variable} - variable not defined"; return $m[0]; } // end of build script