Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Shared :: "linedancerClass.php"
- class linedancerClass {
- public $scriptMatch;
- public $history = [];
- public $hashMatch = "";
- public $depth = 0;
- public $shortName = "";
- public $release = "";
- public $game = "";
- public $extensions = [];
- public $package = "";
- public $pagedata = "";
- public function __construct($release, $game) {
- include_once("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/regex/scriptMatches.php");
- $this->scriptMatch = new scriptMatchClass();
- $this->package = "";
- $this->extensions = implode("|", explode("\r\n", file_get_contents("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/csv/extensions.csv")));
- $this->release = $release;
- $this->game = $game;
- $this->history = [];
- $this->depth = 0;
- }
- public function iText($text) {
- if (is_array($text)) {
- $text = implode("\r\n", $text);
- }
- if (!is_string($text)) {
- $text = (string)$text;
- }
- return $text;
- }
- public function xText($text) {
- $text = $this->iText($text);
- $text = str_replace("\r\n", "\n", $text);
- $text = str_replace("\n", "\r\n", $text);
- return explode("\r\n", $text);
- }
- public function loader($pagedata) {
- global $queries, $swaps;
- $this->pagedata = $pagedata;
- $this->depth++;
- // Swap out placeholder variables with actual content
- foreach ($swaps as $swapOut => $swapIn) {
- $this->pagedata = str_replace($swapOut, $swapIn, $this->pagedata);
- }
- $pageLines = $this->xText($this->pagedata);
- for ($index = 0; $index < count($pageLines); $index++) {
- $line = $pageLines[$index];
- foreach($this->scriptMatch->regex as $key => $pattern){
- if (preg_match_all($pattern, trim($line, " \t"), $matches, PREG_SET_ORDER)) {
- $Matches[$key] = $this->jRmNumeric($matches);
- } else {
- $Matches[$key] = [];
- }
- }
- $MatchParts = [];
- foreach(['short','full'] as $key){
- if(isset($Matches[$key][0])){
- $MatchParts[$key]=$Matches[$key][0];
- $MatchParts[$key]=$this->jRmNumeric($MatchParts[$key]);
- }
- }
- $MatchNames = $this->scriptMatch->genNames($MatchParts);
- // echo "MatchNames: ".print_r($MatchNames)."\r\n\r\n";
- if(!isset($MatchNames['full'])){
- if(isset($MatchNames['short'])){
- // echo "<!-- BOGUS: {$MatchNames['short']} -->";
- }
- continue;
- }else{
- // echo "<!-- MATCH: {$MatchNames['full']} -->";
- }
- $fileData = null;
- if(is_file("{$_SERVER['DOCUMENT_ROOT']}{$MatchNames['full']}")){
- $fileData = file_get_contents("{$_SERVER['DOCUMENT_ROOT']}{$MatchNames['full']}");
- }else{
- continue;
- }
- // echo "<!-- Found: \"{$MatchNames['full']}\" in: \"".htmlentities($line)."\" -->\r\n";
- if ($fileData !== null) {
- $pageLines = $this->remove($pageLines, $index, 1);
- $pgData = "\r\n" . implode("\r\n", $this->commentEntrance($MatchNames['full'], $this->depth));
- $pgData .= "\r\n" . $this->loader($this->xText($fileData));
- $pgData .= "\r\n" . implode("\r\n", $this->commentExit($MatchNames['full'], $this->depth - 1));
- $pgData = explode("\r\n", $pgData);
- $pageLines = $this->insert($pageLines, $index, $pgData);
- }
- $this->depth--;
- }
- return $this->iText($pageLines);
- }
- public function getFileData($filePath, $mode = null, $var = null) {
- $data = null;
- if (in_array($filePath, $this->history)) {
- return $data;
- }
- $this->history[] = $filePath;
- $ext = "." . pathinfo($filePath, PATHINFO_EXTENSION);
- if (in_array($ext, ['.css', '.js', '.meta', '.html'])) {
- $data = file_get_contents($filePath);
- } elseif (in_array($ext, ['.json']) && in_array($mode, ['const', 'var', 'let'])) {
- if ($var !== null) {
- $data = "$mode $var = " . file_get_contents($filePath) . ";";
- }
- }
- return $data;
- }
- public function insert($array, $index, $value) {
- if (!is_array($array)) {
- $array = explode("\r\n", $array);
- }
- if (!is_array($value)) {
- $value = explode("\r\n", $value);
- }
- array_splice($array, $index, 0, $value);
- return $array;
- }
- public function remove($array, $index, $count) {
- if (!is_array($array)) {
- $array = explode("\r\n", $array);
- }
- array_splice($array, $index, $count);
- return $array;
- }
- public function commentEntrance($filePath, $depth) {
- $results = [];
- /*
- foreach ((array)$filePath as $path) {
- $results[] = json_decode(file_get_contents("http://{$_SERVER['HTTP_HOST']}/Shared/php/nameConverter.php?name=".urlencode($path)), true);
- }
- */
- $comments = [];
- foreach ($results as $result) {
- $ext = "." . pathinfo($result['short'], PATHINFO_EXTENSION);
- switch ($ext) {
- case '.css':
- case '.js':
- $comments[] = "/* Processed: \"{$result['short']}\" (Entrance Depth: {$depth}) */";
- break;
- case '.meta':
- case '.html':
- $comments[] = "<!-- Processed: \"{$result['short']}\" (Entrance Depth: {$depth}) -->";
- break;
- case '.json':
- $comments[] = "/* Processed: \"{$result['short']}\" (Entrance Depth: {$depth}) */";
- break;
- default:
- break;
- }
- if ($ext === '.js') {
- $comments[] = "console.log('Processed: \"{$result['short']}\" (Entrance Depth: {$depth})');";
- }
- }
- return $comments;
- }
- public function commentExit($filePath, $depth) {
- $results = [];
- /*
- foreach ((array)$filePath as $path) {
- $results[] = json_decode(file_get_contents("http://{$_SERVER['HTTP_HOST']}/Shared/php/nameConverter.php?name=".urlencode($path)), true);
- }
- */
- $comments = [];
- foreach ($results as $result) {
- $ext = "." . pathinfo($result['short'], PATHINFO_EXTENSION);
- switch ($ext) {
- case '.css':
- case '.js':
- $comments[] = "/* Processed: \"{$result['short']}\" (Exit Depth: {$depth}) */";
- break;
- case '.meta':
- case '.html':
- $comments[] = "<!-- Processed: \"{$result['short']}\" (Exit Depth: {$depth}) -->";
- break;
- case '.json':
- $comments[] = "/* Processed: \"{$result['short']}\" (Exit Depth: {$depth}) */";
- break;
- default:
- break;
- }
- if ($ext === '.js') {
- $comments[] = "console.log('Processed: \"{$result['short']}\" (Exit Depth: {$depth})');";
- }
- }
- return $comments;
- }
- public function jRmNumeric($m = false) {
- if (!is_array($m)) {
- return;
- }
- foreach ($m as $key => $value) {
- if ($key == 0) {
- continue;
- }
- if (is_numeric($key)) {
- unset($m[$key]);
- }
- if (is_numeric($value)) {
- $m[$key] = intval($m[$key]);
- }
- if ($value === null) {
- $m[$key] = "";
- }
- }
- return $m;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement