I'm hoping to get some critical feedback on a part of a opensource project I'm working on.
Here is what I wanted to happen. The only functions I wanted parsed are the functions that are being used. I don't want any other other module's functions to be able to be called or seen. I'm running a MySQL/Apache backend. A table in MySQL houses all of the function. For example.
function print($string)
{
print "$string";
}
Would be in a blob field in a record in a table in the database.
Here is the code I'm currently using to pull only a certain module's functions (system functions for this example module=1) out of the database and parse them. I've truncated all the mysql_ to make the code database independent with functions accordingly.
The parsed function's descriptions are then put into a $_SESSION variable so I can see what ones were parsed in my debug screen.
It also opens a writable file to copy the parsed code into and count the lines for debugging purposes as well. I think I might add a line to erase the file after since that it's only purpose is to count the lines of code.
Another benefit of this is now I can add/edit/delete the functions on the fly from a webpage instead of opening up files.
Please analyze and be extremely critical.
//**********************************************************************
// Query & Eval all system functions out of the contentblock table.
$query="SELECT contentblock_content,contentblock_description,module_id FROM ".$config['table_prefix']."mod1_contentblock WHERE contentblock_show='1' AND contentblock_type='1' AND module_id='1'";
$resource_result=query($query);
$num_rows=num_rows($resource_result);
if ($num_rows==0)
{
record_error("Evaluate Functions","No rows returned in query: ".$query);
return '';
}
// Clear Evaluated Functions Log
@$SESSION['evaluated_functions']='';
$filename="./tmp.php";
$handle=fopen($filename, 'w');
for($y=0; $y<$num_rows; $y++)
{
$function=result($resource_result,$y,0);
$function_description=result($resource_result,$y,1);
$function_module_id=result($resource_result,$y,2);
$query="SELECT module_name FROM ".$config['table_prefix']."mod1_moduleinfo WHERE module_id='".$function_module_id."'";
$resource_result2=query($query);
$module_name=result($resource_result2,0);
eval("$function;");
@$SESSION['evaluated_functions'].="<br>".$module_name.": ".$function_description;
fwrite($handle, $function);
}
fclose($handle);