Jump to content

CMS from Scratch


graisbeck

Recommended Posts

Hi,

I have a CMS which uses includes. I want to alter a browser window script to allow files with pdf extensions to show, at the moment it only shows files that have a php extension.

 

This is the code:

<?PHP
require 'check-login.php' ;
require '../cmsfns.php' ;

/*
	Params:
		$_GET['dir']  - The directory we're currently browsing
		$_GET['type'] - Limit the file extensions to show (currently only supports one, only 'php' used)
*/

if (isset($_GET['dir'])) {
	// Strip off trailing slash if one exists
	define ("DIR", rtrim($_GET['dir'],'/')) ;
}
else {
	define ("DIR", '..') ;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Browse content - <?PHP echo stripslashes($_SESSION['CMS_Title']) ; ?></title>
<link href="styles.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" language="javascript" src="core.js"></script>
<script type="text/javascript">
<!--
	function selectPage(wotPage) {
		window.opener.sentLink(wotPage) ;
		window.close() ;
	}
// -->
</script>
<style type="text/css">
	body {padding:1em;}
	h1 {
		font-size:1.5em;
	}
</style>
</head>

<body class="">
<h1>Select page/file:</h1>
<div class="crumbNav">
<?PHP
	// Break down current location, linking to each folder..
	$folders = explode('/',DIR) ;
	$levels = sizeof($folders) ;
	$link = '' ;
	for ($fldr=0; $fldr<$levels; $fldr++) {
		$link .= $folders[$fldr] ;
		$link .= '/' ;
		if ($fldr < $levels-1) {
			echo '<a href="?dir=' . $link ;
			if (isSet($_GET['type'])) echo '&type=' . $_GET['type'] ;
			echo '">' ;
		}
		if ($folders[$fldr] == "..") $folders[$fldr] = "Home" ;
		echo ' ' . $folders[$fldr] ;
		if ($fldr < $levels-1) {
			echo '</a>' ;
		}
		echo ' /' ;
	}
?>
</div>

<?PHP
$handle = opendir(DIR) ;
$itemsFound = 0 ;
$outputHTML = '' ;
$outputDirs = '' ;
$outputFiles = '' ;
while (false !== ($file = readdir($handle))) {
	$previewFile = getPreviewFileFromLive(DIR.'/'.$file) ;
	if (strstr($file, 'phpthumb') || strstr($file, 'phpthumb') || !file_exists($previewFile)) {
		continue ;
	}
	if (
			(!in_array($file, $reserved_filenames) && !in_array('../'.$file, $reserved_filenames) )
			||
			($file == 'cmsfiles')
		) {
		$itemsFound++ ;
		if (is_dir(DIR.'/'.$file)) {
			// Directory
			$outputDirs .= "\n<li class=\"dir\">" ;
			$outputDirs .= '<a href="?dir=' . DIR .'/'. $file ;
			if (isSet($_GET['type'])) $outputDirs .= '&type=' . $_GET['type'] ;
			$outputDirs .= '" title="Browse ' . $file . '">' ;
			$outputDirs .= $file ;
			$outputDirs .= '</a></li>' ;
		}
		else if (isSet($_GET['type'])) {
			if ($_GET['type'] == 'php' && getFileExtension($file) == 'php') {
				// Page link
				$outputFiles .= "\n" . '<li class="file page"><a href="javascript:selectPage(\'' . DIR . '/' . $file . '\');" >' ;
				$outputFiles .= $file ;
				$outputFiles .= '</a>' ;
				$outputFiles .= "\n</li>" ;
			}
			else if ($_GET['type'] == getFileExtension($file) ) {
				// Other matching file
				$outputFiles .= "\n" . '<li class="file"><a href="javascript:selectPage(\'' . DIR . '/' . $file . '\');" >' ;
				$outputFiles .= $file ;
				$outputFiles .= '</a>' ;
				$outputFiles .= "\n</li>" ;
			}
		}
		else {
			// Unspecified (i.e. 'File' type link)
			$outputFiles .= "\n" . '<li class="file"><a href="javascript:selectPage(\'' . DIR . '/' . $file . '\');" >' ;
			$outputFiles .= $file ;
			$outputFiles .= '</a>' ;
			$outputFiles .= "\n</li>" ;
		}
	}
}
closedir($handle) ;

if ($itemsFound > 0) {
	$outputHTML = '<div class="bigLinks"><ul>' . $outputDirs . $outputFiles . '<!-- 3 --></ul></div>' ;
}
else {
	$outputHTML .= '<div><span class="info">No files or folders found</span></div>' ;
}

echo $outputHTML ;
?>



</body>
</html>

Thanks in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/268534-cms-from-scratch/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.