'.$title[0]."\n");
toc($filenames,$datadir,$path,$extension,$space_char);
}
else {
echo('
'.$title[0]."
\n");
}
echo($story[0].$filenames[0].'
');
}
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(''.$title."
\n");
echo($story[$j].$filenames[$j].'
');
$j++;
}
*/
}
/****** END MAIN PROGRAM ******/
/************* TOC *************/
function toc($dirarray,$datadir,$path,$extension,$space_char) {
echo("\n\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("- $display_item
\n");
}
echo("
\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("/\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 *******/
?>