Created
March 2, 2018 13:49
-
-
Save Septdir/cbc6905586785a09b64619b8dce5ddf7 to your computer and use it in GitHub Desktop.
Site Directory Viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Site Directory Viewer | |
* @version 1.0 | |
* @author Igor Berdicheskiy - septdir.ru | |
* @copyright Copyright (c) 2013 - 2017 Igor Berdicheskiy. All rights reserved. | |
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html | |
*/ | |
$directory = ''; | |
if (!empty($_GET['dir'])) | |
{ | |
ini_set('max_execution_time', 0); | |
$directory = urldecode(trim($_GET['dir'], '/')); | |
} | |
$url = urldecode((isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); | |
if (!isset($_SERVER['HTTP_USER_AGENT']) || stripos($_SERVER['HTTP_USER_AGENT'], 'Speed Insights') === false) | |
{ | |
header("Pragma: no-cache"); | |
header("Cache: no-cache"); | |
header("Cache-Control: no-cache, must-revalidate"); | |
header("Expires: Mon, 9 Jul 1995 05:00:00 GMT"); | |
$optimize = false; | |
if (!empty($directory)) | |
{ | |
$ch = curl_init("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=" . urlencode($url) . '&tab=mobile'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$ruleResults = json_decode(curl_exec($ch), true)['formattedResults']['ruleResults']; | |
if (isset($ruleResults['MinifyCss']['urlBlocks'][1])) | |
{ | |
$optimize = true; | |
} | |
if (isset($ruleResults['MinifyJavaScript']['urlBlocks'][1])) | |
{ | |
$optimize = true; | |
} | |
if (isset($ruleResults['OptimizeImages']['urlBlocks'][1])) | |
{ | |
$optimize = true; | |
} | |
} | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="robots" content="noindex"/> | |
<meta name="robots" content="nofollow"/> | |
<meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT"> | |
<meta http-equiv="Pragma" content="no-cache"> | |
<title>Site Directory Viewer</title> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.26.2/css/uikit.almost-flat.min.css" rel="stylesheet" | |
type="text/css"/> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.26.2/js/uikit.min.js" | |
type="text/javascript"></script> | |
<?php if (!empty($directory)) : ?> | |
<script> | |
var second = 30; | |
function tiktak() { | |
if (second <= 9) { | |
second = '0' + second; | |
} | |
if (document.getElementById) { | |
timer.innerHTML = second; | |
} | |
if (second == 00) { | |
$('#pstimer').remove(); | |
return false; | |
} | |
second--; | |
setTimeout('tiktak()', 1000); | |
} | |
$(document).ready(function () { | |
tiktak(); | |
}); | |
</script> | |
<?php endif; ?> | |
</head> | |
<body> | |
<div class="uk-container uk-container-center uk-margin-top"> | |
<?php if (!empty($directory)) : ?> | |
<p id="pstimer" class="uk-alert uk-alert-danger"> | |
PageSpeed Insights cache time: <span id="timer"></span>sec. | |
</p> | |
<?php endif; ?> | |
<h1 class="uk-h2 uk-clearfix"> | |
Site Directory Viewer | |
<?php if ($optimize): ?> | |
<a class="uk-button uk-button-danger uk-button-large uk-float-right" | |
href="https://developers.google.com/speed/pagespeed/insights/optimizeContents?url=<?php echo urlencode($url); ?>&strategy=mobile"> | |
Download PageSpeed Insights optimized contents | |
</a> | |
<?php endif; ?> | |
</h1> | |
<form id="getToken" method="get" class="uk-form uk-form-horizontal"> | |
<div class="uk-form-row"> | |
<label class="uk-form-label"> | |
Directory <span class="uk-text-danger">*</span> | |
</label> | |
<div class="uk-form-controls"> | |
<input type="text" value="<?php echo $directory; ?>" name="dir" class="uk-form-width-large" | |
placeholder="directory/subdirectory"/> | |
<button type="submit" class="uk-button uk-button-success"> | |
GO | |
</button> | |
</div> | |
</div> | |
</form> | |
<?php if (!empty($directory)) : ?> | |
<div class="uk-margin-top"> | |
<?php foreach (glob($directory . '/*') as $path): | |
$file = pathinfo($path); | |
$file['path'] = $path; | |
$file['link'] = '/' . $file['path']; | |
if (!isset($file['extension'])) | |
{ | |
$file['extension'] = 'unknown'; | |
} | |
$file['extension'] = str_replace(' ', '', (mb_strtolower($file['extension']))); | |
?> | |
<div class="uk-margin-bottom uk-panel uk-panel-box"> | |
<dl class="uk-description-list-horizontal"> | |
<dt> | |
filename | |
</dt> | |
<dd> | |
<?php echo $file['filename']; ?> | |
</dd> | |
<dt> | |
extension | |
</dt> | |
<dd> | |
<?php echo $file['extension']; ?> | |
</dd> | |
<dt> | |
link | |
</dt> | |
<dd> | |
<a href="<?php echo $file['link']; ?>" target="_blank"> | |
<?php echo $file['link']; ?> | |
</a> | |
</dd> | |
</dl> | |
<?php if ($file['extension'] !== 'unknown'): ?> | |
<?php if (is_array(getimagesize($file['path']))): ?> | |
<img src="<?php echo $file['link']; ?>" alt="<?php echo $file['filename']; ?>" | |
class="uk-margin-small-top"> | |
<?php endif; ?> | |
<?php if ($file['extension'] == 'css'): ?> | |
<link href="<?php echo $file['link']; ?>" rel="stylesheet" type="text/css"/> | |
<?php endif; ?> | |
<?php if ($file['extension'] == 'js'): ?> | |
<script src="<?php echo $file['link']; ?>" type="text/javascript"></script> | |
<?php endif; ?> | |
<?php endif; ?> | |
</div> | |
<?php endforeach; ?> | |
</div> | |
<?php endif; ?> | |
</div> | |
</body> | |
</html> | |
<?php | |
} | |
else | |
{ | |
foreach (glob($directory . '/*') as $path) | |
{ | |
$file = pathinfo($path); | |
$file['path'] = $path; | |
$file['link'] = '/' . $file['path']; | |
$file['extension'] = str_replace(' ', '', (mb_strtolower($file['extension']))); | |
if (is_array(getimagesize($file['path']))) | |
{ | |
echo '<img src="' . $file['link'] . '" alt="' . $file['filename'] . '">'; | |
} | |
if ($file['extension'] == 'css') | |
{ | |
echo '<link href="' . $file['link'] . '" rel="stylesheet" type="text/css"/>'; | |
} | |
if ($file['extension'] == 'js') | |
{ | |
echo '<script src="' . $file['link'] . '" type="text/javascript"></script>'; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment