Codice PHP:
<?php
defined( '_VALID_LM' ) or die( 'Direct Access to this location is not allowed.' );
/*
* WSI Flat Table Manager Read Table File functions
* (C)2003 WSI, ALL RIGHTS RESERVED. E-mail: support@webbstyle.com
* Version stable 0.1
*
* Flat File Database Engine
*********************************************************************************************/
if (!defined("DB_ERRORMSG_100")) { define ("DB_ERRORMSG_100", "ERROR 100 Could not open database directory."); }
if (!defined("DB_ERRORMSG_102")) { define ("DB_ERRORMSG_102", "ERROR 102 Could not open table schema, check table name and path."); }
function &_read_table(&$thiz, $table, $cols = '', $searchstr = '') {
$rs = false;
$tmp = '';
$idset = false;
$tsset = false;
// get table schema
if (!@include ($table.'/schema.php')) {
$thiz->ErrorMsg[] = DB_ERRORMSG_102;
} else {
if (isset ($columns) && is_array ($columns)) { $thiz->columns = $columns; }
$lcolumns = array_keys ($thiz->columns); // get column names from schema.php
// make search string
if (strlen ($searchstr) > 0) {
$searchstr = 'if ($'.$searchstr;
$search = array(" NOT ", " AND ", " && $(", " OR ", " || $(", "=", "> ==","<>", "< ==", "if ($(", " LIKE ");
$replace = array(" !", " && $", " && ($", " || $", " || ($", " == ", ">=","!=", "<=", "if (($", "~");
$searchstr = str_replace ($search, $replace, $searchstr);
$search = array ("/(\!)(\w+) /", "/= (\d+)/", "/([\(]*)(\S+)~(')*(%*\w+%*)(')*/", "/%/");
$replace = array ("\$2 \$1", "= '\$1'", "\$1preg_match(\"/^\$4$/i\", \$2)", "[\\w\\s]*");
$searchstr = preg_replace ($search, $replace, $searchstr).') { $f = true; } else { $f = false; }';
// check if perf cols are set
if (strpos ($searchstr, '$id')) { $idset = true; }
}
if($idset && preg_match("/id\s+==\s+(\d+)/",$searchstr,$matchid))
{
$item=str_replace(array("id","=="),array("\$item","="),$matchid[0]);
$item.=";";
eval($item);
// $item=$matchid[0];
if(is_file($table."/".$item.$thiz->ext)) // WE GOT DIRECT HIT
{
$first[0] = trim ($item);
$found = false;
$fp=fopen($table."/".$item.$thiz->ext,"r");
$tcontent=fread($fp,filesize( $table."/".$item.$thiz->ext));
fclose($fp);
$tcontent=str_replace("<?php die(); ?>\n",'',$tcontent);
$content = array_merge ($first,explode("\n",$tcontent,strlen($tcontent)));
$y = 0;$i = 0;
foreach ($lcolumns as $col) {
$$col = trim($content[$y++]);
if ($col == 'id' || $col == 'lastupd') { settype($$col, "integer"); }
if (is_array ($cols)) {
if (in_array ($col, $cols)) { $tmp[$col] = $$col; }
}
else {
$tmp[$col] = $$col;
}
}
if (is_array ($tmp)) {
if (is_array ($cols)) { // order selected columns as set in SQL-string
foreach ($cols as $col) { $tmp2[$col] = $tmp[$col]; }
$tmp = $tmp2;
}
if (strlen ($searchstr) > 0) { // run search string if exist
eval ($searchstr);
if ($f) { $rs[$i++] = $tmp; }
} else {
$rs[$i++] = $tmp;
}
}
}
}else if ($dh = @opendir ($table)) {
$i = 0;
while (($item = readdir ($dh)) !== false) {
if ($item != "." && $item != ".." && $item != "schema.php" ) {
// make recordset
$y = 0;
// make filename
$first[0] = str_replace($thiz->ext,'',trim ($item));
if($lcolumns[1]=='lastupd')$first[1]=0; // bug fix
if ((!$idset) || (($idset && $idset == $first[0]) ) ||
($idset && $idset == $first[0]) ) {
$fp=fopen($table."/".$item,"r");
$tcontent=fread($fp,filesize( $table."/".$item));
fclose($fp);
$tcontent=str_replace("<?php die(); ?>\n",'',$tcontent);
$content = array_merge ($first,explode("\n",$tcontent,strlen($tcontent)));
foreach ($lcolumns as $col) {
$$col = trim($content[$y++]);
if ($col == 'id' ) { settype($$col, "integer"); }
if (is_array ($cols)) { // return selected columns
if (in_array ($col, $cols)) { $tmp[$col] = $$col; }
} else { // return all columns (*)
$tmp[$col] = $$col;
}
}
}
/////
if (is_array ($tmp)) {
if (is_array ($cols)) { // order selected columns as set in SQL-string
foreach ($cols as $col) { $tmp2[$col] = $tmp[$col]; }
$tmp = $tmp2;
}
if (strlen ($searchstr) > 0) { // run search string if exist
eval ($searchstr);
if ($f) { $rs[$i++] = $tmp; }
} else {
$rs[$i++] = $tmp;
}
}
/////
}
}
closedir($dh);
} else {
$thiz->ErrorMsg[] = DB_ERRORMSG_100;
}
}
if (is_array ($rs)) {
/*rigo 165 */
$thiz->rowset = $rs;
return true;
} else {
return false;
/*rigo 169*/
}
}
?>
grazie a chi mi aiuterà ;)