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.

*/

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 arraytorecord($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++;
    }

    if (
is_file($dir.$id.'.txt'))
        return -
1;

    return 
dbputpage($id,$data);
}

function 
dbputpage($id$data$dir NULL) {

    if (!
$dir)
        
$dir config('pagedir');

    return 
file_put_contents($dir.$id.'.txt',$data);
}

function 
dbdelpage($id$dir NULL) {

    if (!
$dir)
        
$dir config('pagedir');

    return @
unlink($dir.$id.'.txt');
}

?>