Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Shared :: "Linedancer 2/Parse Comments.php"
- // Define the regular expressions for path and short containers
- $pathPattern = '/(\/\*)?(\<\!\-\-)? \{\{ \#(?<capture>[^\r\n]+) \}\} (?(1)\*\/|(?(2)\-\-\>|(*F)))/';
- $shortPattern = '/(\/\*)?(\<\!\-\-)? \{\{ \#(?<capture>\/\/ [^\r\n]+ :: [^\r\n]+\([^\r\n]+\)\.(css|csv|html|js|json|meta|php|regex)) \}\} (?(1)\*\/|(?(2)\-\-\>|(*F)))/';
- $filePattern = '/(?<release_root>\/(?<release_name>[^\/]+))(?<project_root>\/(?<project_name>[^\/]+)|)\/(?<sub>scripts)\/(?<format>css|csv|html|js|json|meta|php|regex)\/(?<file>[^\.]+)\.(?<extension>(?!\.|\/|\n|$)[\w]+)/m';
- $release = $_GET['release'] ?? false;
- $game = $_GET['game'] ?? false;
- // Debugging output for release and game
- // echo "Release: " . htmlspecialchars($release) . "<br>";
- // echo "Game: " . htmlspecialchars($game) . "<br>";
- // Blacklist for releases and games
- $releaseBlacklist = ['Shared', 'cgi-bin', 'Junk'];
- $gameBlacklist = ['Shared', 'Junk']; // Example of blacklisted games
- // Initial placeholders for Linedancer's embed state
- $placeholders = [
- '{{ release root }}' => rtrim("/" . ltrim($release, '/'), '/'), // Ensure single leading slash
- '{{ project root }}' => rtrim("/" . ltrim($game, '/'), '/'), // Ensure single leading slash
- '{{ release name }}' => $release, // Example release name
- '{{ project name }}' => $game, // Example project name
- '{{ title }}' => fancyTitle($release,$game), // Placeholder for title to be dynamically generated
- '{{ fav icon }}' => fancyIcon($release,$game), // Placeholder for base64 icon URL
- ];
- $validReleases = [];
- $validGames = [];
- // Reset valid games for each release to avoid duplication
- validation($validReleases, $validGames, $releaseBlacklist, $gameBlacklist);
- function validation(&$validReleases, &$validGames, $releaseBlacklist, $gameBlacklist) {
- // Get all valid releases from the document root
- $validReleases = array_filter(array_map('basename', glob("{$_SERVER['DOCUMENT_ROOT']}/*", GLOB_ONLYDIR)), function($release) use ($releaseBlacklist) {
- // Filter out blacklisted releases
- return !in_array($release, $releaseBlacklist);
- });
- // Loop through each valid release and get valid games
- foreach ($validReleases as $validRelease) {
- $validGames[$validRelease] = array_filter(array_map('basename', glob("{$_SERVER['DOCUMENT_ROOT']}/{$validRelease}/*", GLOB_ONLYDIR)), function($game) use ($gameBlacklist) {
- // Filter out blacklisted games
- return !in_array($game, $gameBlacklist);
- });
- }
- }
- // Define the isValidCombo function to check valid release/game combinations
- function isValidCombo($release, $game, $validReleases, $validGames) {
- // Check if release and game are valid
- return isset($validGames[$release]) && in_array($game, $validGames[$release]);
- }
- // Check if the release and game combination is valid
- if (!isValidCombo($release, $game, $validReleases, $validGames)) {
- // Display menu for invalid combo
- echo displayMenu($validReleases, $validGames);
- exit;
- }
- // Continue with the rest of the script for valid combo...
- // Generate title with fancy project/release names and host
- // Parse and embed referenced files recursively
- function processLines(&$lines, &$index, $depth) {
- global $pathPattern, $shortPattern, $filePattern, $placeholders;
- $depth++; // Increase depth for each recursion
- while ($index < count($lines)) {
- $lines[$index] = swapPlaceholders($lines[$index], $placeholders);
- $file = null;
- $matches = [];
- if (preg_match_all($pathPattern, $lines[$index], $matches, PREG_SET_ORDER) > 0) {
- foreach($matches as $match){
- $file = $match['capture'] ?? null; // Use first match, access by named group if available
- }
- } elseif (preg_match_all($shortPattern, $lines[$index], $matches, PREG_SET_ORDER) > 0) {
- foreach($matches as $match){
- $file = $match['capture'] ?? null; // Use first match, access by named group if available
- }
- } else {
- $index++;
- continue;
- }
- // If $file was successfully captured, proceed to process it
- if ($file === null){
- $index++;
- continue;
- }
- if(!is_file("{$_SERVER['DOCUMENT_ROOT']}{$file}")){
- notification($file, $extension, $base, $in, $out, $bad, $depth);
- array_splice(
- $lines,
- $index,
- 1,
- explode("\r\n", $bad)
- );
- $index++;
- continue;
- }
- // $index++;
- notification($file, $extension, $base, $in, $out, $bad, $depth);
- // Insert the included file's contents
- array_splice(
- $lines,
- $index,
- 1,
- explode("\r\n", "{$in}\r\n" . file_get_contents("{$_SERVER['DOCUMENT_ROOT']}{$file}") . "\r\n{$out}")
- );
- // Recursively process the included file, increasing the index to continue past the inserted content
- processLines($lines, $index, $depth);
- $index++;
- }
- }
- function notification($file,&$extension,&$base,&$in,&$out,&$bad,$depth){
- global $filePattern;
- $fileShort = "{$file}";
- if(preg_match_all($filePattern,$file,$matches,PREG_SET_ORDER)>0){
- foreach($matches as $match){
- // LabDemo2Js (Beta 3 A) :: "Fade Audio.js"
- $fileShort = "// ";
- $fileShort .= convertNumbersToRoman($match['project_name']);
- $fileShort .= " (";
- $fileShort .= convertNumbersToRoman($match['release_name']);
- $fileShort .= ") :: \"";
- $fileShort .= $match['file'];
- $fileShort .= ".";
- $fileShort .= $match['extension'];
- $fileShort .= "\"";
- }
- }
- $extension = pathinfo($file, PATHINFO_EXTENSION);
- $base = basename($file, $extension);
- $template = "{{ open }} {{ build }}: {{ file }} (Depth: {{ depth }}) {{ close }}";
- $in = $template;
- $out = $template;
- $bad = $template;
- $in = str_replace("{{ build }}","Included",$in);
- $out = str_replace("{{ build }}","Concluded",$out);
- $bad = str_replace("{{ build }}","Invalid",$bad);
- $in = str_replace("{{ depth }}","{$depth}",$in);
- $out = str_replace("{{ depth }}","{$depth}",$out);
- $bad = str_replace("{{ depth }}","{$depth}",$bad);
- $in = str_replace("{{ file }}","{$fileShort}",$in);
- $out = str_replace("{{ file }}","{$fileShort}",$out);
- $bad = str_replace("{{ file }}","{$fileShort}",$bad);
- switch($extension){
- case '.css':
- case '.js':
- $in = str_replace("{{ open }}","/*",$in);
- $out = str_replace("{{ open }}","/*",$out);
- $bad = str_replace("{{ open }}","/*",$bad);
- $in = str_replace("{{ close }}","*/",$in);
- $out = str_replace("{{ close }}","*/",$out);
- $bad = str_replace("{{ close }}","*/",$bad);
- break;
- case '.meta':
- case '.html':
- default:
- $in = str_replace("{{ open }}","<!--",$in);
- $out = str_replace("{{ open }}","<!--",$out);
- $bad = str_replace("{{ open }}","<!--",$bad);
- $in = str_replace("{{ close }}","-->",$in);
- $out = str_replace("{{ close }}","-->",$out);
- $bad = str_replace("{{ close }}","-->",$bad);
- break;
- }
- }
- // Swap placeholders in content
- function swapPlaceholders($content, &$placeholders) {
- foreach ($placeholders as $placeholder => $replacement) {
- // Normalize slashes to avoid double slashes (//)
- $replacement = rtrim($replacement, '/'); // Remove trailing slashes from replacement
- $content = str_replace($placeholder, $replacement, $content);
- }
- return $content;
- }
- // Initialize title and fav icon
- $rawtext = ($release!==null?"{$release}":"").($game!==null?"/{$game}":"");
- if(strpos($rawtext,"/")){
- $release = explode("/",$rawtext)[0];
- $game = explode("/",$rawtext)[1];
- }else{
- $release = $rawtext;
- $game = "";
- }
- $placeholders['{{ title }}'] = fancyTitle($release,$game);
- $placeholders['{{ fav icon }}'] = fancyIcon($release,$game);
- $placeholders['{{ release name }}'] = $release;
- $placeholders['{{ project name }}'] = $game;
- $placeholders['{{ release root }}'] = "/{$release}";
- $placeholders['{{ project root }}'] = "/{$game}";
- $scriptContent = "<!-- {{ #{{ release root }}/Shared/scripts/html/main.html }} -->";
- // Array to track already embedded files
- $embeddedFiles = [];
- // Call parser to embed files and replace placeholders
- $lines = explode("\r\n",$scriptContent);
- $index = 0;
- $depth = 0;
- processLines($lines, $index, $depth);
- $processedContent = implode("\r\n",$lines);
- // Output the processed content
- // echo $processedContent;
- echo $processedContent;
- ?>
Add Comment
Please, Sign In to add comment