|
|
|
| Ajax
Library |
| lib/ajax.php |
| Celeroo Frame
aims to provide some functions which to make your work with Ajax
libraries. Most of them are in our to do list, but currently you can
use the function parse_ajax_request(). |
| parse_ajax_request(); |
| This function
does not receive any arguments. Instead of that it cheks $_POST array
for a variable named "request" which contains an URL encoded string of
names and values. If such variable is presented, the function breaks it
into an array of $_POST variables. |
| The function is
designed to work with Scriptaculous/Prototype Ajax libraries which can
send all the form data in such single variable. (Check Form.Serialize()) |
|
| Database
Library |
| lib/db.php |
| Celeroo Frame
have several functions simplifying your work with the database. |
| get_setting($name); |
| Receives a
setting name (from settings table) and returns its value. Typically you
will not need to use this function because all the settings are
available as constants. You will need to use this function only if you
have just changed the setting and have not refreshed the page yet. |
| dumpto_table($table,$vars,$escape=TRUE) |
A super easy
function to insert anything to any database table. Just pass it the
table name and the variables array which most often is $_POST. This
function is a huge time saver because you don't need to construct long
database queries. Unlike the well known ActiveRecord functions, our
function will not die with an error if some of the variables in the
$vars array does not match a table name. The function will construct a
query using only the well matching names, which means that typically
you'll just pass it the $_POST array and don't worry if there are
variables that will not need to be inserted.
$escape is a parmeter defining whether the data should be filtered and
defaults to TRUE when you are calling the funciton from procedural
code. The default object methods (add() and update()) of the Celeroo
models are filtering the data using the Sanitization helper, that's why
they set $escape to FALSE. |
| Example: |
dumpto_table($T_USERS, $_POST);
|
| update_table($table,$vars,$fld,$vle,
$escape=TRUE) |
| This is another
big time saver. Works similar to dumpto_table but
creates UPDATE query. Again it includes only matching fields so you
don't need to worry about details. The function accepts the table name,
associative array with variables, primary key field name (typically
"id") and field value. |
| Example: |
update_table($T_USERS, $_POST, "id", $_GET['id']);
|
|
| Javascript
Library |
| lib/functions.js |
| Celeroo Frame
comes with a very simple library of several javascript functions. For
more comprehensive libraries we recommend using Scriptaculous/Prototype
or other javascript library. |
|
| HTML
Library |
| lib/html.php |
| This is a set of
functions creating some common pieces of HTML code. |
| redirect($where); |
| Receives absolute
or relative URL and generates redirect header. |
| nav_pages($path,$count,$offset,$limit,$width) |
| This is a
pagination function which generates pagination links in a HTML table.
Works with non - rewritten URLs. |
| nav_pages_se_friendly($path,$count,$offset,$limit,$width) |
| This is a
pagination function which generates search engine friendly pagination
links in a HTML table. Works with rewritten URLs. |
| msg_die($message) |
| Simple function
to display an error message and exit. Receives the message and outputs
HTML. |
| dateformat($date,$noyear) |
| Hardcoded format
of the date thru the site. The current version does not support
different formats, so if you want to change the default one, you need
to modify the function. This function however is preferred over
formatting the data with php native date() or mysql function, because
the format can be changed at one place and reflect entire site. |
| Receives date in
YYYY-MM-DD format. If the second argument is set to 1, the returned
date will not contain the year. |
| date_chooser($name,$value="") |
| Generates HTML
code for date dropdown and returns it. Receives name which becomes part
of the name in the three dropdowns. The second argument is optional -
if presented, it will default the date dropdown to the passed date in
YYYY-MM-DD format. If empty, it defaults to today's date. |
| Example: |
|
|
| Will create a
date dropdown defaulting to today. The three dropdowns will have names
as follow: startmonth, startday, startyear. |
| form_sdropdown($values,$displays,$sel='') |
| Generates HTML
code for the options part in a dropdown from single dimentional arrays.
The first array contains the values, the second - the values that will
be displayed to the user. Both arrays can be the same. |
| form_cdropdown($hashes,$val,$display,$sel='') |
| Similar to
form_sdropdown but works with array of associative arrays (typically
returned from a DB query. Works perfect with the arrays returned from
Celeroo Frame database object - $DB->aq()). Receives the array, the
key name and the value name. |
| Example: |
$users=new
array(0=>array("id"=>1,"name"=>"John"),
1=>array("id"=>2,"name"=>"Ann"));
Will return the following HML code:<option
value="1">John</option>
<option value="2">Ann</option>
|
| You need to put
the <select> and </select> tags around the function call
which gives you a way to name and format the select box. |
| resume($text,$limit=7) |
| Very simple
function creating a short resume from a text without breaking the
words. Defaults to 7 words. |
| radiogroup($name,$vals,$displays="",$selval="",$sep=" ") |
| Creates a group
of radio buttons. Receives the group name, array with values, array
with corresponding texts to display (if empty, the values are
displayed), selected value if any and separator between the different
radio buttons (typically a non breaking space or new line) |
|
| Javascript
PHP Library |
| lib/js.php
|
| This is different
from the javascript library in functions.js. Here Celeroo Frame offers
PHP functions which generate javascript to save you some coding. |
| jsredirect($where) |
| Outputs a
javascript code for browser redirect. The function is useful if headers
are already sent to the browser and the standard redirect function
causes a "header already sent" error. |
| alert($what,$output=false) |
| Prepares a
javascript alert. If $output is true, then the alert is immediately
send to the browser. Otherwise it's saved in $GLOBALS['jsalert']. You
can include the variable in your templates in proper place so it does
not come before the <html> opening tag. |
| jsvalidate($fields,$havepass=0) |
| Generates a
simple code for javascript form validation. Receives an array with the
required field names. For field whose names contain "email", an email
validation happens. If $havepass is true, the script will generate code
for fields called "pass" and "repass" and will compare both (password
and password confirmation fields) |
|
| Miscellaneous
Library |
| lib/misc.php |
| Contains various
functions |
| send_mail($from,$to,$subject,$message,$ctype='text/html') |
| A simple wrapper
for the PHP native mail() function. It generates the headers so all you
have to pass to the function is sender, receiver, subject and message.
If you want to send a text mail, pass also the last parameter as
'text/plain'. |
| upload_file($name,
$dir="files/",$newname="") |
| Just does a file
upload. Pass it the field name, the directory where you want it
uploaded (if none, Celeroo Frame will try to write in directory called
"files/") and the desired file name (if none, automatically a unique
name will be generated). |
| Output($buffer,$name='') |
| Forces the
browser to output some content for download. Pass it the content and
the desired file name. If none, the file will be called "file.txt". |
| cut($start,$end,$word) |
| Cuts a string by
start and end marker. The third argument is the string. The function
returns a new string, the original one remains intact. |
| make_thumbnail($path,$name) |
| Generates a
thumbnail from already uploaded image. Receives the path to the image
(to the directory level) and the file name. The new file is saved in
the same directory and the same name with "thumb_" prefix. |
| write($path,$content) |
| Writes $content
as a file in the given $path. The target folder should allow writing. |
|
| Benchmark
Helper |
| helpers/benchmark.php |
| Celeroo Frame has
a class for behchmarking your code performance. You can set several
anchors and track the time elapsed between them in microseconds. |
| Example: |
$benchmark=new Benchmark();
$benchmark->anchor('begin');
// ...some code
$benchmark->anchor('middle');
//...more code
$benchmark->anchor('end');
//Now, let's see the time elapsed between any two anchors
echo $benchmark->show("start","middle");
echo $benchmark->show("start","end");
//or you can a list of all anchors and the time elapsed between the
class initiation and each of the anchors
echo $benchmark->show_all();
|
|
| Encrypt
Helper |
| helpers/encrypt.php
|
| Celeroo Frame
provides simple but reliable enough class for two-way encryption. The
class uses a special key which is set in the constructor. If you want
to use the same key in your entire application, you can insert it in
the settings table. |
| Example
usage: |
$enc=new Encrypt("123456");
$var=$enc->encode("John Smith");
//insert encoded var in the DB, pass it over the web or watever
$decohded_var=$enc->decode($var);
echo $decoded_var; // echoes "John Smith"
|
|
| FileUtil
Helper |
| helpers/fileutil.php |
| This is a class
helping you with some common file operations like file upload, writing,
deleting etc. Some of the functions are avialble in procedural format
in the Miscellaneous library. |
| helpers/image.php |
| Helper for common
image manipulation. Provides function for thumbnail generation
(available also as procedural library), cropping images and framing
images. |
|
|
Sanitize Helper
helpers/sanitize.php
This heloper prepares basic filtering against
SQL injections and other attacks. It's used internally in the Basic
object, but you can also use it in your code.
|
| |
|
 |
| |
| Need
Help? Click
here to send us your queries on the framework
and/or the manual, and we will respond
promptly. |
|
|
|