Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created May 23, 2014 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/c4671b6a1aaa0955f710 to your computer and use it in GitHub Desktop.
Save walterdavis/c4671b6a1aaa0955f710 to your computer and use it in GitHub Desktop.
<?php
// Inlay template/page finder.
ini_set('display_errors', 1);
if(preg_match('/scan_folder\.php/', $_SERVER['REQUEST_URI']) || !isset($_POST['inlay_key']) || empty($_POST['inlay_key']) || ($_POST['inlay_key'] != '2f96deba74feb435ecf7f94f83f34c2c2')){
header("Status: 404 Not Found", true, 404);
print 'Missing. Move along.';
exit;
}
$base = dirname(__FILE__);
$pages = array();
$templates = array();
$partials = array();
function list_directory($dir) {
$file_list = array();
$stack[] = $dir;
while ($stack) {
$current_dir = array_pop($stack);
if ($dh = opendir($current_dir)) {
while (($file = readdir($dh)) !== false) {
if ($file !== '.' AND $file !== '..') {
$current_file = "{$current_dir}/{$file}";
if (is_file($current_file) && preg_match('/\.html$/i', $file)) {
$file_list[] = "{$current_dir}/{$file}";
} elseif (is_dir($current_file)) {
$stack[] = $current_file;
$file_list[] = "{$current_dir}/{$file}/";
}
}
}
}
}
return $file_list;
}
$candidates = list_directory($base);
header('Content-type: text/plain; charset=utf-8');
foreach($candidates as $candidate){
if(is_file($candidate)){
$uri = str_replace($base, '', $candidate);
$content = file_get_contents($candidate);
if(false !== stristr($content, 'data-inlay-source="')){
if(preg_match('/\/_/', $candidate)){
$partials[] = $uri;
}else{
$templates[] = $uri;
}
}else{
$pages[] = $uri;
}
}
}
$remote = @file_get_contents('http://inlay.io/test.txt');
if(empty($remote)) $remote = 'Boo! Could not connect to Inlay.io';
$server = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
print_r(array('base' => $server, 'remote' => $remote, 'pages' => $pages, 'templates' => $templates, 'partials' => $partials));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment