Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class pathClass {
- public $root = "";
- public $path = "";
- public function __construct(){
- $this->root = $_SERVER["DOCUMENT_ROOT"];
- $this->host = "http://".$_SERVER["HTTP_HOST"];
- }
- }
- $path = new pathClass();
- $formats = json_decode(file_get_contents($path->root."/test dictionary/scripts/json/includes/formats.json"),true, 512, JSON_THROW_ON_ERROR);
- include_once($path->root."/test dictionary/scripts/php/prettyClass.php");
- include_once($path->root."/test dictionary/scripts/php/phlegmClass.php");
- $pretty = new prettyClass();
- $phlegm = new phlegmClass();
- include_once($path->root."/Classes/mapCsv2JsonClass.php");
- $pagedata = file_get_contents($path->root."/test dictionary/scripts/html/main.html");
- $pagedata = str_replace ( "{{ host }}", $path->host, $pagedata );
- $pagedata = $pretty->favIconRender($pagedata);
- $pagedata = str_replace("{{ fav icon }}", "{{ host }}/Sprites/icon/crescent-onion-dome.png", $pagedata);
- $prettyHost = str_replace ( " ",".", ucwords(str_replace ( "."," ",str_replace('http://','',$path->host))));
- $prettyName = str_replace ( " ",".", ucwords(str_replace ( "."," ",basename(__FILE__,".php"))));
- $pagedata = str_replace("{{ title }}", "Keal's Roe2Js $prettyName @ $prettyHost", $pagedata);
- $pagedata = str_replace("{{ tray }}", "", $pagedata);
- $pagedata = str_replace("{{ menu }}", "", $pagedata);
- $eventLog = "";
- $buffet = "";
- loader ( $pagedata );
- $pagedata = str_replace ("{{ table }}","<textarea>$eventLog</textarea>",$pagedata);
- $pagedata = str_replace ("{{ host }}",$path->host,$pagedata);
- header("Content-Type: text/html");
- echo $pagedata;
- exit;
- function loader ( &$pagedata ) {
- global $path, $pretty;
- global $eventLog, $formats;
- global $lines;
- foreach($formats as $ext => $tag){
- $lines = [];
- switch($ext) {
- case "js":
- case "css":
- $pagedata = str_replace ("{{ ${tag} }}","<${tag}></${tag}>",$pagedata);
- $line = "/* {{ #/test dictionary/scripts/json/includes/${ext} includes.csv }} */";
- insert($lines, count($lines), $line);
- $row = 0;
- while($row < count($lines)){
- LineChef ( $row );
- $row++;
- }
- $pagedata = str_replace("</${tag}>",implode("\r\n",$lines)."</${tag}>",$pagedata);
- break;
- case "json":
- case "csv":
- break;
- }
- }
- $pagedata = str_replace("</textarea>","${eventLog}</textarea>",$pagedata);
- }
- function Linedancer ( &$row ) {
- global $path, $pretty;
- global $eventLog, $formats;
- global $lines;
- $line = $lines[$row];
- if(preg_match_all(Cookbook(),$line,$matches,PREG_SET_ORDER ) > 0 ) {
- foreach($matches as $match){
- $pretty->jRmNumeric($match);
- $words = [];
- foreach(["op","var","path","file","ext"] as $key ) {
- $words[$key] = $match[$key];
- }
- }
- }else{
- remove($lines,$row,1);
- insert($lines,$row,$line);
- return;
- }
- if ($words['op'] !== "#"){
- remove($lines,$row,1);
- insert($lines,$row,$line);
- return;
- }
- $hit = array_search(substr("${words['ext']}",1), $formats);
- if ( $hit === false ) {
- remove($lines,$row,1);
- insert($lines,$row,$line);
- return;
- }
- if(!is_file($path->root."${words['path']}${words['file']}${words['ext']}")) {
- remove($lines,$row,1);
- insert($lines,$row,$line);
- return;
- }
- switch( substr("${words['ext']}",1) ){
- case 'js':
- case 'css':
- case 'csv':
- remove($lines,$row,1);
- insert($lines,$row,file_get_contents($path->root."${words['path']}${words['file']}${words['ext']}"));
- return;
- case "json":
- if($words['var'] === ""){
- remove($lines,$row,1);
- insert($lines,$row,$line);
- return;
- }
- remove($lines,$row,1);
- insert($lines,$row,"var ${words['var']} = ".file_get_contents($path->root."${words['path']}${words['file']}${words['ext']}"));
- return;
- }
- remove($lines,$row,1);
- insert($lines,$row,$line);
- return;
- }
- function LineChef( &$row ){
- global $lines;
- $row = 0;
- while($row < count($lines)){
- Linedancer ( $row );
- $row++;
- }
- return;
- }
- function Cookbook(){
- return '/\/\* {{ (?<op>#)(?<pad>(?<var>[A-Za-z][A-Za-z0-9_]*)=|)(?<path>\/[\/A-Za-z0-9\-_ ]*\/)(?<file>[A-Za-z0-9\-_ ^\/]+)(?<ext>\.[A-Za-z0-9\-_]+) }} \*\//m';
- }
- function insert(&$array, $index, $value) {
- if (!is_array($value)) {
- $value = explode("\r\n", $value);
- }
- $row = 0;
- foreach ($value as $item) {
- array_splice($array, $index + $row, 0, $item);
- $row++;
- }
- }
- function remove(&$array, $index, $count) {
- if(is_array($count)){
- $count = count($count);
- }
- array_splice($array, $index, $count);
- }
Add Comment
Please, Sign In to add comment