Source Code Index
<?php
 
/* INC/PAGES.PHP - This is to read/write records as files in 'pagedir'.
 
The use of 'db' for the function names is only to be similar to the other, 
related functions to read/write MYSQL records.
 
A version of "pages" might be created that use posts with a "page:" header.
 
See also dbfilerecord() is module RECORD.
 
*/
 
function makepagesdir() {
 
	$dir = config('pagedir');
	return @mkdir($dir);
}
 
function dblistpages($id = NULL, $dir = NULL) {
 
	if (!$dir)
		$dir = config('pagedir');
 
	if (!is_dir($dir))
		return FALSE;
 
	if ($id)
		return (is_file($dir.$id.'.txt')) ? $id : 0;
 
	$ids = glob($dir.'*.txt');
	foreach ($ids as $k => $v) {
		$v = str_replace($dir,'',$v);
		$ids[$k] = str_replace('.txt','',$v);
	}
	natsort($ids);
	return $ids;	// will be array() if no files found
}
 
function dbreadpage($id, $dir = NULL) {
 
	if (!$dir)
		$dir = config('pagedir');
 
	if (!($rec = @file_get_contents($dir.$id.'.txt')))
		return $rec;
 
	$record = stringtorecord($rec);
	$record['id'] = $id;
	return $record;
}
 
function dbgetpage($id, $dir = NULL) {
 
	if (!$dir)
		$dir = config('pagedir');
 
	return file_get_contents($dir.$id.'.txt');
}
 
function dbnewpage($data, $id = '', $dir = NULL) {
 
	if (!$dir)
		$dir = config('pagedir');
 
	if ($id === '') {
		$files = glob($dir.'*.txt');
		natsort($files);
		foreach ($files as $f) {
			$f = str_replace('.txt','',$f);
			$f = str_replace($dir,'',$f);
			if (is_numeric($f))
				$id = (int)$f;
		}
		$id++;
	}
 
	return dbputpage($id,$data);
}
 
function dbputpage($id, $data, $dir = NULL) {
 
	if (!$dir)
		$dir = config('pagedir');
 
	if (strpos($id,'.txt') === FALSE)
		$id = $id.'.txt';
 
	return file_put_contents($dir.$id,$data);
}
 
function dbdelpage($id, $dir = NULL) {
 
	if (!$dir)
		$dir = config('pagedir');
 
	return @unlink($dir.$id.'.txt');
}
 
?>
 
THIS source compiler