BLAserv: Blosxom-Like Article Serv
<?php
# version 0.01a
/******** CONFIGURATION ********/
$datadir = '/full/path/to/installation';
// Full path
$extension = 'inc';
// No leading dot! Your data file extension
$space_char = '_';
// Character in dir/file names displayed as a space
/****** END CONFIGURATION ******/
/******** MAIN PROGRAM ********/
$thisdir = $_SERVER['QUERY_STRING'];
$getdir = $datadir.
'/'.
$thisdir;
if(is_file($getdir.
".$extension")) {
render($getdir.
".$extension",0
);
if(is_dir($getdir)) {
get_folders($getdir);
$j = 0;
foreach($dirnames as $dir) {
get_files($dir,
$extension);
$j++;
}
$path = $thisdir;
echo('<h2 class="toc">'.
$title[0
].
"</h2>\n");
toc($filenames,
$datadir,
$path,
$extension,
$space_char);
}
else {
echo('<h2>'.
$title[0
].
"</h2>\n");
}
echo($story[0
].
$filenames[0
].
'<hr>');
}
else {
if(is_dir($getdir)) {
$thedir = $getdir;
}
else {
$thedir = $datadir;
}
get_folders($thedir);
$j = 0;
foreach($dirnames as $dir) {
get_files($dir,
$extension);
$j++;
}
// Directories only show up in the TOC if they have a descriptor file
// (i.e. /foo/bar is described by /foo/bar.inc
toc($filenames,
$datadir,
'',
$extension,
$space_char);
/* I'm keeping this routine for now. It's the "blog display" routine
$j = 0; foreach($filenames as $file) {
render($file,$j);
$j++;
}
$j = 0; foreach($title as $title) {
echo('<h2>'.$title."</h2>\n");
echo($story[$j].$filenames[$j].'<hr>');
$j++;
}
*/
}
/****** END MAIN PROGRAM ******/
/************* TOC *************/
function toc($dirarray,
$datadir,
$path,
$extension,
$space_char) {
echo("\n<ul class='toc'>\n");
// Start the TOC UL
foreach($dirarray as $item) {
// Create the anchortext by removing fullpath and extension
$anchor_item = ereg_replace("\.$extension",
'',
ereg_replace($datadir.
'/*',
'',
$item));
// Pretty up the display item (insert spaces and remove categories
$display_item = ereg_replace($space_char,
' ',
ereg_replace($path.
'/',
'',
$anchor_item));
// And of course, write linked list items
echo("<li class='toc'><a href='?$anchor_item' class='toc'>$display_item</a></li>\n");
}
echo("</ul>\n\n");
// Close up list
}
/*********** END TOC ***********/
/********* GET FOLDERS *********/
function get_folders($datadir) {
global $dirnames;
$dirnames[] = $datadir;
// Allows top-level and request-level files to be used
$handle = opendir($datadir);
$file = readdir($handle);
// while(($file = readdir($handle)) !== false ) { // Don't want to display a bunch
if($file !== '..' &&
$file !== '.' &&
is_dir($datadir.
'/'.
$file)) {
$dirnames[] = $datadir.
'/'.
$file;
$dir_varname = $datadir.
$file;
$$dir_varname = $datadir.
'/'.
$file;
get_folders($$dir_varname);
// }
}
}
/******* END GET FOLDERS *******/
/********* GET FILES **********/
function get_files($directory,
$extension) {
global $filenames;
$handle = opendir($directory);
$file = readdir($handle);
while(($file = readdir($handle)) !== false
) {
if(substr(strrchr($file,
"."), 1
) == $extension) {
$filenames[] = $directory.
'/'.
$file;
}
}
}
/******* END GET FILES ********/
function GetFile($basedir) {
if(is_dir($basedir)) {
$basedirhandle = opendir($basedir);
while(($file = readdir($basedirhandle)) !== false
) {
if($file !== '.' &&
$file !== '..') {
if(is_dir($basedir.
'/'.
$file)) {
GetFile($basedir.
'/'.
$file);
}
}
}
}
else {
$currentstorylimit = $currentstorylimit +1;
if($currentstorylimit <
= $storylimit) {
array_push($filename,
$basedir.
'/'.
$file);
$str = file_get_contents($basedir.
'/'.
$file);
array_push($filecontents,
$str);
}
}
}
function ReadFilesAndDirectories($basedirectoryname,
$file,
$filename,
$filecontents,
$directorydepth,
$currentdepth,
$storylimit,
$currentstorylimit,
$extension) {
$currentdepth = $currentdepth +1;
if (is_dir($basedirectoryname)) {
$basedirectoryhandle = opendir($basedirectoryname);
while (($file = readdir($basedirectoryhandle)) !== false
) {
if ($file !== '.' &&
$file !== '..') {
if (is_dir($basedirectoryname .
'/' .
$file)) {
if ($currentdepth <
= $directorydepth ||
$directorydepth == -1
) {
ReadFilesAndDirectories($basedirectoryname .
'/' .
$file,
$file, &
$filename, &
$filecontents,
$directorydepth,
$currentdepth, &
$storylimit,
$currentstorylimit,
$extension);
}
}
else {
if (substr($file,
strlen($file)-4, 4
) == $extension) {
$currentstorylimit = $currentstorylimit +1;
if ($currentstorylimit <
= $storylimit ||
$storylimit == -1
) {
array_push($filename,
$basedirectoryname.
'/'.
$file);
$str = file_get_contents($basedirectoryname.
'/'.
$file);
array_push($filecontents,
$str);
}
}
}
}
}
}
}
/******** RENDER *********/
function render($renderfile,
$i) {
// The function must be passed a file and a story id (incremental and unique)
global $title;
global $story;
$theFile = file($renderfile);
foreach($theFile as $line) {
unset($postarray);
// I'm not sure I need to do this, but it seemed safer
// Process Metadata
// Metadata can be placed in a story as "meta_varname: vardata" lines.
//
// Metadata is available to the page generation routines as $meta_varname[$i],
// where $i is the story number in the sequence of the individual run.
if(preg_match("/^meta_/",
$line)) {
$metaArray = explode(": ",
$line);
// Parse metadata
global $$metaArray[0
];
// Make sure the meta can get out
$$metaArray[0
] = array($i =>
$metaArray[1
]);
// Populate $meta_ arrays
unset($line);
// Remove meta information from story
}
if($line &&
$line !== "\n") { // Discount blank lines
$postArray[] = $line;
// Place the post lines in an array
}
}
$title[$i] = $postArray[0
];
// Set title variable
unset($postArray[0
]);
// Remove title line from story
foreach($postArray as $para) { // Walk the post array to compile the story
if($meta_block[$i] = true
) { // Is the text not pre-html'd?
if(!preg_match("/<ul/",
$para) &&
!preg_match("/<ol/",
$para) &&
!preg_match("/<li/",
$para) &&
!preg_match("/<\/ul/",
$para) &&
!preg_match("/<\/ol/",
$para)) { // Allow lists in block-processed stories
$buildstory .
= '<p>'.
$para.
"</p>\n\n";
// Add paragraph tags
}
else {
$buildstory .
= $para;
// For list lines, use raw line
}
}
else { // Just pretty up the source if blocking is not specified
$buildstory .
= $para.
"\n\n";
}
}
$story[$i] = $buildstory.
"\n\n";
// Get the story out
unset($buildstory);
// Prep for another run
}
/****** END RENDER *******/
?>
Generated by GNU enscript 1.6.1 and enscriptclean.
BLAserv | Download Source | View Source