', ' '), array('', ' '), str_replace(array("\r\n", "\r"), "\n", $g_sContent)); // Remove code and first span $g_sContent = substr($g_sContent, 36, -15); // Convert color to class foreach (array ( 'default', 'comment', 'html', 'keyword', 'string', ) as $g_sClass) { // Replace $g_sContent = str_replace('', '', $g_sContent); } // Link include $g_sContent = preg_replace('/(include\(<\/span>\')([^<]+)(\'<\/span>\);)/', '\1\2\3', $g_sContent); // Previous block $g_sBlock = null; // Code begin $g_sOutput = '
    '.PHP_EOL; // Loop through content line list foreach (explode("\n", $g_sContent) as $g_sLine) { // Check split block if ('' === substr($g_sLine, 0, 7)) { // Remove split block $g_sLine = substr($g_sLine, 7); // Clear pending block $g_sBlock = null; } // Check pending block if (null !== $g_sBlock) { // Reopen split block $g_sLine = $g_sBlock.$g_sLine; // Clear pending block $g_sBlock = null; } // Count block begin and end $g_iBlockBegin = substr_count($g_sLine, ''); // Compare block begin and end if ($g_iBlockEnd < $g_iBlockBegin) { // Close last block $g_sLine .= ''; // Get last block $g_sBlock = substr($g_sLine, strrpos($g_sLine, ')( +)/', '\2\1', $g_sLine); // Remove empty blocks $g_sLine = preg_replace('/<\/span>/', '', $g_sLine); // Allow line break and preserve spaces $g_sLine = str_replace(array(' ', '[', ']', '(', ')', ' '.$g_sBreak, $g_sBreak.' '), array('  ', $g_sBreak.'[', ']'.$g_sBreak, $g_sBreak.'(', ')'.$g_sBreak, ' ', ' '), $g_sLine); // Check line if ('' === $g_sLine) { // Display empty line $g_sOutput .= '
  1. '.PHP_EOL; } else { // Display line $g_sOutput .= '
  2. '.$g_sLine.'
  3. '.PHP_EOL; } } // Code end $g_sOutput .= '
'.PHP_EOL; } else { // Directory index $g_sTitle = 'Index of '; // Name comparison function gCompare($a_sFirst, $a_sSecond) { // Try case insensitive natural order $r_iResult = strnatcasecmp($a_sFirst, $a_sSecond); // Check order if (0 === $r_iResult) { // Try case sensitive natural order $r_iResult = strnatcasecmp($a_sFirst, $a_sSecond); } // Return order return $r_iResult; } // Accent list $g_a_sAccentList = array ( // Ordered accent 'acute', 'circ', 'grave', // Unordered accent 'cedil', 'orn', 'ring', 'slash', 'th', 'tilde', 'uml', ); // Directory map $g_h_sDirectoryMap = array(); // File map $g_h_sFileMap = array(); // Open directory $g_sDirectory = realpath(dirname(__FILE__).rawurldecode($_SERVER['REQUEST_URI'])).DIRECTORY_SEPARATOR; assert(is_dir($g_sDirectory)); $g_rDirectory = opendir($g_sDirectory); // Loop through directory while (false !== ($g_sName = readdir($g_rDirectory))) { // Check name if ('.' !== $g_sName[0]) { // Replace ligature $g_sNameAscii = preg_replace('/&([A-Za-z]{2})lig;/', '\1', htmlentities($g_sName, ENT_NOQUOTES, 'UTF-8')); $g_sNameOrder = $g_sNameAscii; // Replace accent $g_sNameAscii = preg_replace('/&([A-Za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);/', '\1', $g_sNameAscii); // Loop through accent list foreach ($g_a_sAccentList as $g_iOrder => $g_sAccent) { // Replace accent with ordered letter $g_sNameOrder = preg_replace('/&([A-Za-z])'.$g_sAccent.';/', '${1}{'.$g_iOrder.'}', $g_sNameOrder); } // Restore other $g_sNameAscii = html_entity_decode($g_sNameAscii, ENT_NOQUOTES, 'UTF-8'); $g_sNameOrder = preg_replace('/([A-Za-z])([^{]|$)/', '\1{}\2', $g_sNameOrder); // Sort key $g_sKey = $g_sNameOrder.' '.$g_sNameAscii.' '.$g_sName; // Check type if (is_dir($g_sDirectory.$g_sName)) { // Append to directory map $g_h_sDirectoryMap[$g_sName] = $g_sKey; } else { // Append to file map $g_h_sFileMap[$g_sName] = $g_sKey; } } } // Close directory closedir($g_rDirectory); // List begin $g_sOutput = ''.PHP_EOL. ' '.PHP_EOL; // Sort directory map uasort($g_h_sDirectoryMap, 'gCompare'); // Loop through directory map foreach ($g_h_sDirectoryMap as $g_sName => $g_sKey) { // Display directory $g_sOutput .= ' '.PHP_EOL. ' '.PHP_EOL. ' '.PHP_EOL. ' '.PHP_EOL; } // Sort file map uasort($g_h_sFileMap, 'gCompare'); // Unit suffit $g_a_sUnitList = array ( 'Kio', 'Mio', 'Gio', ); // Loop through file map foreach ($g_h_sFileMap as $g_sName => $g_sKey) { // Get path $g_sFile = $g_sDirectory.$g_sName; // Get size $g_iSize = filesize($g_sFile); $g_iUnit = (int)(floor(log($g_iSize, 2) / 10)); // Display file $g_sOutput .= ' '.PHP_EOL. ' '.PHP_EOL. ' '.PHP_EOL. ' '.PHP_EOL; // Check unit if (0 < $g_iUnit) { // Scaled size $g_sOutput .= ' '.PHP_EOL; } // File end $g_sOutput .= ' '.PHP_EOL; } // List end $g_sOutput .= ' '.PHP_EOL. '
 '.str_replace(array(' ', ' '), array(' ', '  '), $g_sName).'/  '.str_replace(' ', ' ', date('Y-m-d H:i:s', filemtime($g_sDirectory.$g_sName))).' 
 '.$g_sName.'  '.str_replace(' ', ' ', date('Y-m-d H:i:s', filemtime($g_sFile))).'  '.number_format($g_iSize, 0, '.', '\'').' octets ('.number_format($g_iSize / pow(1024, $g_iUnit), 1).' '.$g_a_sUnitList[$g_iUnit - 1].')
'.PHP_EOL; } // Display head echo '', PHP_EOL, '', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' '; // Get request $g_sRequest = htmlentities(rawurldecode($_SERVER['REQUEST_URI']), ENT_NOQUOTES | ENT_XHTML, 'UTF-8'); // Display title echo $g_sTitle, $g_sRequest, '', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, // Display foot ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, // Display content ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, ' ', PHP_EOL, '
', PHP_EOL, '

', $g_sTitle, ''; // Get element list $g_a_sElementList = explode('/', substr($g_sRequest, 1)); $g_iElementLast = count($g_a_sElementList) - 1; // Check last element if ('' === $g_a_sElementList[$g_iElementLast]) { // Handle trailing slash --$g_iElementLast; } // Loop through element list $g_sUrl = '/'; foreach ($g_a_sElementList as $g_iElement => $g_sElement) { // Display separator echo '/', $g_sBreak; // Check element if ($g_iElement !== $g_iElementLast) { // Update URL $g_sUrl .= $g_sElement.'/'; // Element link begin echo ''; } // Display element echo preg_replace('/[0-9a-f]{2,}/ei', 'implode($g_sBreak, str_split(\'\0\', 2))', $g_sElement); // Check element if ($g_iElement !== $g_iElementLast) { // Element link end echo ''; } } // Display server echo '

', PHP_EOL, '

'; if ('/' === $_SERVER['REQUEST_URI']) { echo $_SERVER['SERVER_NAME']; } else { echo '', $_SERVER['SERVER_NAME'], ''; } echo '

', PHP_EOL, '
Generated in ', round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000000), ' µs on ', date('Y-m-d H:i:s'), ' ', date_default_timezone_get(), '
', PHP_EOL, $g_sOutput, '
', PHP_EOL, ' ', PHP_EOL, '', PHP_EOL; ?>