« File Structure of the Framework | Main | CherryPy does ZPT »
March 23, 2009
The common_php directory
The common_php
directory contains a number of common function files that need to be included in each script in any application. It includes PHP files with one or more functions related either to the application framework or to individual web applications.
add_update_functions.php book_request_functions.php calendar.php calendar_style.css check_url.php cip_functions.php convert_line_breaks.php date_parser.php db_name.inc.php do_sql.php email_functions.php has_value.php interface_functions.php is_even.php kpi_functions.php libfaq.ini option_switcher.php quote_me.php read_config.php read_file.php round_me.php target_use_attributes.php upload_file.php user_functions.phpFramework Specific Files
- .htaccess
protection for the credentials files - add_update_functions.php
Functions for adding and updating rows in MySQL tables with the contents of the $_REQUEST hash ($r). - calendar.php
A calendar pop-up used to populates date fields in the interface. - calendar_style.css
Stylesheet for the above - check_url.php
Contains one function for validating URLs - convert_line_breaks.php
Converts new lines to <br/> tags. - db_name.inc.php
Formally a holder for the database name for a single application, but now deprecated. File still needs to be present though. - do_sql.php
Holds a number of key functions related to SQL querying including just_sql($sql) which is used extensively in every application. - email_functions.php
Functions for building multipart email headers for sending attachments and HTML email. - has_value.php
One function of the same name which runs the gauntlet of PHP tests to determine if a value is or isn't set for a particular variable. Note that if a value of zero is set it returns false. Be careful when trying to set zero as a value in SQL transactions.
In terms of MySQL zero is a value (as different from NULL). Because PHP values are scalar and typing is dynamic this can get you into all kinds of trouble if you are testing a value from a MySQL row as a boolean, (zero == false in PHP).function has_value($var){ if(is_array($var)){ return has_value($var[0]); } if(!isset($var)){ return(false); } if(is_null($var)){ return(false); } if($var === 0){ return(false); } if($var === NULL){ return(false); } if($var === 'NULL'){ return(false); } if($var === 'null'){ return(false); } if($var === ""){ return(false); } preg_match('/\w/', $var, $matches); if(count($matches) == 0){ return(false); } return(true); }
- interface_functions.php
Functions for building HTML forms from .skini definitions in the skins/ directory. These are written in Windows .ini file format. Picklists in <select/> elements are handled separately by functions in the option_switcher.php file. - is_even.php
Two functions, one to tell if a number is odd or even and the other to set the style class for alternating rows in a table. - libfaq.ini
DB connection definition and credentials store in a windows .ini file (ensure this file type is excluded from display in the Apache configuration). Used by the functions in do_sql.php.[connection_parameters] user = youruser password = yourpasswordhere host = localhost type = mysql db = yourdbnamehere
- option_switcher.php
Used to define the <options/> for any select form elements built using the interface functions. - quote_me.php
Contains a function of the same name which properly escapes MySQL inserts automatically detecting for get_magic_quotes_gpc to avoid double escaping. - read_config.php
Contains one function of the same name and is used for pulling the contents of a Windows .ini file into a hash. - read_file.php
Functions for reading a file into a string or a list of lines. - round_me.php
An attempt at a function which correctly rounds monetary values to 2 decimal places as PHP's round function does odd things which might be mathematically more accurate but are annoying in the context of pounds and pence and lead to inaccuracies. I'm not clear whether this solves the issue, and it is a work in progress. Use with caution. - upload_file.php
Functions related to uploading files once they get to the server. You need to read the PHP manual to see what extra elements to include in your form for the process to work. The error reporting functions in this code don't work properly. - user_functions.php
Some basic user functions, including functions to determine if the user is an administrator.
Tags: Lightweight PHP Web Application Framework
Posted by pj at March 23, 2009 04:43 PM