View difference between Paste ID: zj8ZnuTK and RF1kXVGX
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
$convert_toSpace = true;	// true if script should convert _ in folder names to spaces
4
$upperCaseWords = true;	// true if script should convert lowercase to initial caps
5
$topLevelName = "HOME";		// name of home/root directory
6
$separator = " &gt; ";		// characters(s) to separate links in hierarchy (default is a > with 2 spaces on either side)
7
8
// find index page in directory...
9
function MPBCDirIndex($dir) {
10
	$index = '';
11
	@$dir_handle = opendir($dir);
12
	if ($dir_handle) {
13
		while ($file = readdir($dir_handle)) {
14
			$test = substr(strtolower($file), 0, 6);
15
			if ($test == 'index.') {
16
				$index = $file;
17
				break;
18
				}
19
			}
20
		}
21
	return $index;
22
	}
23
24
// make clean array (trim entries and remove blanks)...
25
function MPBCTrimArray($array) {
26
	$clean = array();
27
	for ($n=0; $n<count($array); $n++) {
28
		$entry = trim($array[$n]);
29
		if ($entry != '') $clean[] = $entry;
30
		}
31
	return $clean;
32
	}
33
34
// function to prep string folder names if needed...
35
function MPBCFixNames($string) {
36
	global $convert_toSpace;
37
	global $upperCaseWords;
38
	if ($convert_toSpace) $string = str_replace('_', ' ', $string);
39
	if ($upperCaseWords) $string = ucwords($string);
40
	return $string;
41
	}
42
43
$server = (isset($_SERVER)) ? $_SERVER : $HTTP_SERVER_VARS;
44
45
$htmlRoot = (isset($server['DOCUMENT_ROOT'])) ? $server['DOCUMENT_ROOT'] : '';
46
if ($htmlRoot == '') $htmlRoot = (isset($server['SITE_HTMLROOT'])) ? $server['SITE_HTMLROOT'] : '';
47
48
$pagePath = (isset($server['SCRIPT_FILENAME'])) ? $server['SCRIPT_FILENAME'] : '';
49
if ($pagePath == '') $pagePath = (isset($server['SCRIPT_FILENAME'])) ? $server['SCRIPT_FILENAME'] : '';
50
51
$httpPath = ($htmlRoot != '/') ? str_replace($htmlRoot, '', $pagePath) : $pathPath;
52
53
$dirArray = explode('/', $httpPath);
54
if (!is_dir($htmlRoot.$httpPath)) $dirArray = array_slice($dirArray, 0, count($dirArray) - 1);
55
56
$linkArray = array();
57
$thisDir = '';
58
$baseDir = ($htmlRoot == '') ? '' : $htmlRoot;
59
for ($n=0; $n<count($dirArray); $n++) {
60
	$thisDir .= $dirArray[$n].'/';
61
	$thisIndex = MPBCDirIndex($htmlRoot.$thisDir);
62
	$thisText = ($n == 0) ? $topLevelName : MPBCFixNames($dirArray[$n]);
63
	$thisLink = ($thisIndex != '') ? '<a href="'.$thisDir.$thisIndex.'">'.$thisText.'</a>' : $thisText;
64
	if ($thisLink != '') $linkArray[] = $thisLink;
65
	}
66
67
$results = (count($linkArray) > 0) ? implode($separator, $linkArray) : '';
68
if ($results != '') print('<div class="backlinks">'.$results.'</div>');
69
70
?>