HerbIgniter User Guide Version 1.7.2


Quick Reference Card

Class Reference

 

Helper Reference

Benchmarking Class
// Mark a start point
$this->benchmark->mark('dog');

// Mark an end point
$this- >benchmark->mark('cat');

/* Run "elapsed_time()" to view results */
echo $this->benchmark->elapsed_time('dog','cat');
//{elapsed_time} or {memory_usage}

Calendar Class
$prefs['template'] =
'!Click Calendar Class Link Above For Template!';

$prefs = array (
               'start_day'    => 'saturday',
               'month_type'   => 'long',
               'day_type'     => 'short'
             );

$this->load->library('calendar', $prefs);
echo $this->calendar->generate(2006, 6);
$data = array( 3  => 'http://x.com/article/2006/03/',
               7  => 'http://x.com/article/2006/07/',
               13 => 'http://x.com/article/2006/13/',
               26 => 'http://x.com/article/2006/26/'
             );

echo $this->calendar->generate(2006, 6, $data);

Cart Class
^Read the docs on this one (click the link above).
$this->cart->insert();
$this->cart->update();
$this->cart->total();
$this->cart->total_items();
$this->cart->contents();
$this->cart->has_options(rowid);
$this->cart->options(rowid);
$this->cart->destroy();

Config Class
// Loads a config file "settings.php"
$this->config->load('settings', TRUE);

// Retrieve config item option in settings
$option = $this->config->item('option','settings');

// An alternate way to specify the item:
$blogcfg = $this->config->item('blog_settings');
$site_name = $blogcfg['site_name'];

Database Class
^Read the docs on this one (click the link above).
See "Query" Helper in Helper Reference ->

Email Class
$this->load->library('email');

$this->email->from('your@x.com', 'Name');
$this->email->to('someone@x.com');
$this->email->cc('another@another-x.com');
$this->email->bcc('them@their-x.com');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.\nMuahahah.\n\t\tSincerely,\n\t\tHerb');

$this->email->send();

echo $this->email->print_debugger();

Encryption Class
$this->load->library('encrypt');
$config['encryption_key'] = "YOUR KEY";
$msg = 'My secret message';
$key = 'super-secret-key';

$encryptd = $this->encrypt->encode($msg,$key);
$plaintext = $this->encrypt->decode($encryptd);

File Uploading Class
^Read the docs on this one (click the link above).

Form Validation Class
^Read the docs on this one (click the link above).

FTP Class

$this->load->library('ftp');

$config['hostname'] = 'ftp.example.com';
$config['username'] = 'your-username';
$config['password'] = 'your-password';
$config['debug'] = TRUE;

$this->ftp->connect($config);
$this->ftp->upload('/local/path/file.html', '/remote/file.html', 'ascii', 0775);
$this->ftp->rename('/remote/src.html', '/remote/dest.html');
$this->ftp->move('/remote/from.html', '/remote/to.html');
$this->ftp->delete_file('/remote/blog.html');
//!!!! $this->ftp->delete_dir('/deletes/recursive');
$list = $this->ftp->list_files('/remote/');
$this->ftp->mirror('/local/path/', '/remote/path/');
$this->ftp->mkdir('/remote/', 777);
// Chmod "bar" to 777
$this->ftp->chmod('/remote/',777);
$this->ftp->close();

HTML Table Class

$this->load->library('table');
$data = array(
             array('Name', 'Color', 'Size'),
             array('Fred', 'Blue', 'Small'),
             array('Mary', 'Red', 'Large'),
             array('John', 'Green', 'Medium')
             );
echo $this->table->generate($data);

$this->table->set_caption();
$this->table->set_heading();
$this->table->add_row('Blue', 'Red', 'Green'); //or array()

$list = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve');
$new_list = $this->table->make_columns($list, 3);
$this->table->generate($new_list);

$tmpl = array( 'table_open'  => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );
$this->table->set_template($tmpl);
$this->table->set_empty("&nbsp;");

$this->table->clear(); // required for multiple tables

Image Manipulation Class

$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;

$this->load->library('image_lib', $config);

if ( ! $this->image_lib->resize())
    echo $this->image_lib->display_errors();

$config['image_library'] = 'netpbm';
$config['library_path'] = '/usr/bin/';
$config['source_image'] = '/path/to/mypic.jpg';
$config['rotation_angle'] = 'hor'; // vrt,90,180,270

$this->image_lib->initialize($config);

if ( ! $this->image_lib->rotate())
    echo $this->image_lib->display_errors();

$this->image_lib->clear();
$config['source_image'] = '/path/to/mypic.jpg';
$config['wm_text'] = 'Copyright 2006 - John Doe';
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';

$this->image_lib->initialize($config);

$this->image_lib->watermark();

Note: class only works on files with "write" permissions. Like, 777.
^See the actual doc for more configuration options (like overlay).

Input and Security Class

Security Filtering
The security filtering function is called automatically when a new controller is invoked.

-Destroys the global GET array.
-Destroys all global variables if register_globals=true
-
Filters the POST/COOKIE keys, allows only alpha-numeric (and a few other) characters.
-XSS (Cross-site Scripting Hacks) filtering.
-Normalize newlines to \n

XSS Filtering
$data = $this->input->xss_clean($data);

If you want the filter to run automatically, enable it by opening your application/config/config.php file and setting this:

$config['global_xss_filtering'] = TRUE;
if ($this->input->xss_clean($file, TRUE)===FALSE)
{ /* file failed the XSS test */ }

Posts, Gets, Cookies and Server Variables
/*function returns FALSE (boolean) if item does not exist; second optional parameter activates XSS when TRUE */

$this->input->post('some_data', TRUE);
$this->input->get('some_data', TRUE);
$this->input->get_post('some_data', TRUE);
$this->input->cookie('some_data', TRUE);
$this->input->server('some_data');
echo $this->input->ip_address();//invalid=0.0.0.0

if ( ! $this->input->valid_ip($ip))
{ echo 'Not Valid'; } else { echo 'Valid'; }

$this->input->user_agent()
/* Returns the user agent (web browser) being used by the current user. Returns FALSE if it's not available. */

Loader Class
$this->load->library('class', $config, 'object');
// class converted to $this->method:
$this->load->library('class', '', 'my_class');
$this->my_class
$string = $this->load->view('myfile', '', true);
$this->load->model('blog/queries');
$this->load->model('Model_name', 'fubar');
$this->fubar->function();
$this->load->database('options', true/false)
$this->load->scaffolding('table_name')
$this->load->vars($array)
$this->load->helper('file_name')
$this->load->plugin('file_name')
$this->load->lang('file_name')
$this->load->config('file_name')
$this->load->file('filepath/filename', true/false)

Language Class

Language files are typically stored in your system/language directory. Alternately you can create a folder called language inside your application folder and store them there. HerbIgniter will look first in your system/application/language directory. If the directory does not exist or the specified language is not located there HI will instead look in your global system/language folder.

$lang['language_key'] = "The actual message to be shown";

$lang['error_email_missing'] = "You must submit an email";
$lang['error_url_missing'] = "You must submit a URL";
$lang['error_username_missing'] = "No username";

$this->lang->load('filename', 'language');

$this->lang->line('language_key');

Output Class

$this->output->set_output($data);
$string = $this->output->get_output();
$this->output->set_header("HTTP/1.0 200 OK"); //etc
$this->output->set_status_header('420'); // 401..500..
$this->output->enable_profiler(TRUE);
$this->output->cache(); -> see documentation here

Page Class
$this->page->set_head($data);
$string = $this->page->get_head();

$this->page->set_body($data);
$string = $this->page->get_body();

$this = $this->page->get_onload();
$string = $this->page->add_onload("jsfunc()");

$this->page->set_header("HTTP/1.0 200 OK"); //etc
$this->page->set_status_header('401');
$this->page->enable_profiler(TRUE);
$this->page->cache(); -> see documentation here

Pagination Class

$this->load->library('pagination');

$config['base_url'] = 'http://x.com/index.php/pg/';
$config['total_rows'] = '200';
$config['per_page'] = '20';

$this->pagination->initialize($config);

echo $this->pagination->create_links();

Session Class
^Read the docs on this one (click the link above).

$this->load->library('session');
$session_id = $this->session->userdata('session_id');

$this->session->set_flashdata('item', 'value');
$this->session->flashdata('item');
$this->session->keep_flashdata('item');

Trackback Class

^Read the docs on this one (click the link above).

///////////////////// Sending:

$this->load->library('trackback');

$tb_data = array(
      'ping_url'  => 'http://x.com/trackback/456',
      'url'       => 'http://www.my-x.com/blog/entry/123',
      'title'     => 'The Title of My Entry',
      'excerpt'   => 'The entry content.',
      'blog_name' => 'My Blog Name',
      'charset'   => 'utf-8'
      );

if ( ! $this->trackback->send($tb_data))
     echo $this->trackback->display_errors();
else
     echo 'Trackback was sent!';

///////////////////// P-p-processing:

$this->load->database();

if ($this->uri->segment(3) == FALSE)
    $this->trackback->send_error("Unable to find entry ID");

if ( ! $this->trackback->receive())
    $this->trackback->send_error("Did not contain valid data");

$data = array(
           'tb_id'      => '',
           'entry_id'   => $this->uri->segment(3),
           'url'        => $this->trackback->data('url'),
           'title'      => $this->trackback->data('title'),
           'excerpt'    => $this->trackback->data('excerpt'),
           'blog_name' => $this->trackback->data('blog_name'),
           'tb_date' => time(),
           'ip_address' => $this->input->ip_address()
           );

$sql = $this->db->insert_string('trackbacks', $data);
$this->db->query($sql);

$this->trackback->send_success();

Template Parser Class

^Read the docs on this one (click the link above).

Typography Class

^Read the docs on this one (click the link above). It's considered processor intensive and caching is recommended.

$this->load->library('typography');
$string = $this->typography->auto_typography($string);
$string = $this->typography->auto_typography($string,FALSE);
$string = $this->typography->format_characters($string);
$string = $this->typography->nl2br_except_pre($string);
$this->typography->protect_braced_quotes = TRUE;

Unit Testing Class

^Read the docs on this one (click the link above).

URI Class
*This class is initialized automatically by the system so there is no need to do it manually.

Permits you to retrieve a specific segment. Where n is the segment number you wish to retrieve. Segments are numbered from left to right. For example, if your full URL is this:

http://x.com/index.php/local/pot/dispensaries

$dispensaries = $this->uri->segment(3, 'ifnoseg');

$this->uri->rsegment(n) // "route segment"

$this->uri->slash_segment(n)

This function is almost identical to $this->uri->segment(), adds a trailing and/or leading slash based on the second parameter. If the parameter is not used, a trailing slash added.

$this->uri->slash_segment(3);
$this->uri->slash_segment(3, 'leading');
$this->uri->slash_segment(3, 'both');

Returns:
1. segment/
2. /segment
3. /segment/

$this->uri->slash_rsegment(n)

$this->uri->uri_to_assoc(n)

This function lets you turn URI segments into and associative array of key/value pairs.

$this->uri->ruri_to_assoc(n)

Creates an associative array using the re-routed URI in the event you are using HerbIgniter's URI Routing feature.

$this->uri->assoc_to_uri()

Takes an associative array as input and generates a URI string from it.

$array = array('product' => 'shoes', 'size' => 'large', 'color' => 'red'); $str = $this->uri->assoc_to_uri($array);
// Produces: product/shoes/size/large/color/red

$this->uri->uri_string() // Returns string complete URI.

http://example.com/index.php/news/local/345
The function would return this: /news/local/345

$this->uri->ruri_string(n)

This function is identical to the previous one, except that it returns the re-routed URI in the event you are using HerbIgniter's URI Routing feature.

$this->uri->total_segments()

Returns the total number of segments.

$this->uri->total_rsegments()

This function is identical to the previous one, except that it returns the total number of segments in your re-routed URI in the event you are using HerbIgniter's URI Routing feature.

$this->uri->segment_array()

Returns an array containing the URI segments. For example:

$segs = $this->uri->segment_array();

foreach ($segs as $segment) echo $segment . '<br />';

$this->uri->rsegment_array()

User Agent Class

$this->load->library('user_agent');

if ($this->agent->is_browser())
    $agent = $this->agent->browser().' '.
$this->agent->version();
elseif ($this->agent->is_robot())
    $agent = $this->agent->robot();
elseif ($this->agent->is_mobile())
    $agent = $this->agent->mobile();
else
    $agent = 'Unidentified User Agent';

echo $agent;

echo $this->agent->platform(); //Platform (Win/Lin/Mac/etc)$this->agent->referrer()

The referrer, if the user agent was referred from another site. Typically you'll test for this as follows:

if ($this->agent->is_referral())
{    echo $this->agent->referrer(); }

$this->agent->agent_string()

Returns a string containing the full user agent string. Typically it will be something like this:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.4) Gecko/20060613 Camino/1.0.2

if ($this->agent->accept_lang('en'))
{
    echo 'You might accept English!';
}

if ($this->agent->accept_charset('utf-8'))
{
    echo 'You browser supports UTF-8!';
}

XML-RPC Class

^Read the docs on this one (click the link above).

Zip Encoding Class

$this->zip->add_data($name, $data);
$this->zip->add_dir('myfolder'); // Creates a folder in the zip
$this->zip->read_file('/path/to/photo.jpg');
$this->zip->read_dir('/some/path/');

// Creates a file named myarchive.zip
$this->zip->archive('/path/to/folder/myarchive.zip');

// Download the file. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');

$zip_file = $this->zip->get_zip();

$this->zip->clear_data();
  Ajax Helper
$this->load->helper('ajax');

$code = init_ajax(); // returns js for GetXmlHttpObject()

// Generate a unique AJAX object ID
$ajax_id = unique_ajax();

// Generate a unique AJAX object ID with the prefix "hotel" :
$hotel_ajax_id = unique_ajax( "hotel" );

// The most common use of the get_ functions, to create links that trigger the region to repopulate:

$page->append_head( ajax_element_init( here()."/page/param/etc", ""<img src="loading.gif">", "div" );
$page->append_body( ajax_element( ) );
$page->append_body( '<a href="javascript:' . get_ajax() . '()"><img src="refresh.gif" alt="Click to Refresh"></a>' );

ajax_div($page,"jsid",here()."/object/params","Wait ...", 'div');

//create a div, init AJAX, use when a link is clicked:
$page->append_head ( ajax_element_init( here()."/page/param/etc" ) );
$page->append_body( ajax_element( ) );
$page->append_body( ajax_element_link( '<img src="myicon.jpg" border=0>' ) );

// Multiple AJAX regions
for( $i=0; $i<10; $i++ ) {
$page->append_head( ajax_element_init( here()."/page/param/etc", "<img src=\"loading.gif\">", "div" );
$page->append_body( ajax_element( ) );
$page->append_body( '<a href="javascript:' . get_ajax() . '()"> <img src="refresh.gif"></a>' );
}

// If you need to specify only the <HTML> element tag for the active AJAX object ids (the JSID and AJID):
$page->append_body( ajax_element( '', 'span' ) );

// Flipper examples
flipper( $this->page, "", lorem_ipsum(5).'<br>', "the form" );

flipper( $this->page, "Submit Link Text", "<input type='text' size='50' value=''>", "Click to confirm", "", "" );
// <- Note! You must use "" for result parameter!

flipper( $this->page, '&uarr; Upload A Track For ' . $album['name'],
"<form enctype='multipart/form-data' action='" . here() . "/band/manage' method='post' name='upload" . $n
. "'> Title<input type='text' name='title' size=50><br>"
. "Price <input name='Price' type='text' value='0.99'><br>"
. hiddens("album",$album['id'])
. "Description<br><textarea name='description' rows=4 cols=50></textarea><br>MP3 file: <input type='file' value='' name='mp3'></form>",
"Click to add a new track!", "Add Track", "cancel", "upload" );

// toggler()
define( SOME_BITVECTOR, 1 );
define( SOME_OTHER_BIT, 4 );
toggler( $this->page, "users_table", "flags_field", SOME_BITVECTOR, "The switch is on.", "The switch is off.", "Flip Switch" );

// updater()
updater( $this->page, "echo 'test'", 500, 'span');

Array Helper
$this->load->helper('array');

$array = array('color' => 'red', 'shape' => 'round', 'size' => '');

// returns "red"
echo element('color', $array);
// returns NULL
echo element('size', $array, NULL);

$random= random_element($array);
$intersection = multipleArrayIntersect( $array1, ... $arrayN );

$node = array();
$node[1] = array('@parent' => 0, 'title' => 'I am node 1.');
#     ^-----------------------v Link @parent value to key.
$node[2] = array('@parent' => 1, 'title' => 'I am node 2.');
$node[3] = array('@parent' => 2, 'title' => 'I am node 3.');
array_stack($node);
$node['leaf'][1]['title'] = 'I am node one.';
$node['leaf'][2]['title'] = 'I am node two.';
$node['leaf'][3]['title'] = 'I am node three.';
echo '<pre>',print_r($node['tree'],TRUE),'</pre>';

$averages = array_avg( $baseball_stats, 3 );

$javascript_array = array2js( $php_array );

print_r(array_mix_recursive($array_a, $array_b));

Audio Helper
$this->load->helper('audio');

$mp3_info = mp3titles( 'somefile.mp3' );
echo $mp3_info['title'] . '<br>' . $mp3_info['artist'] . '<br>' . $mp3_info['album'];

Biz Helper
$this->load->helper('biz');

////////////////// authorize.net
$authorize_response = authorize_net($x_card_num, $x_exp_date, $x_invoice_num, $x_description, $x_amount, $x_cust_id, $x_first_name, $x_last_name, $x_company, $x_address, $x_city, $x_state, $x_zip, $x_country, $x_phone, $x_fax, $x_email, $x_ship_to_first_name, $x_ship_to_last_name, $x_ship_to_company, $x_ship_to_address, $x_ship_to_city, $x_ship_to_state, $x_ship_to_zip, $x_ship_to_country, $x_tax, $x_duty, $x_freight, $x_tax_exempt, $x_po_num);
////////////////// check response code for 'SUCCESS'

// Simple PayPal Button "buy it now"
$page->append_body( PayPal_Button( "my@email.com", "Blue Prada Boots", 340.0, "USD" );

// PayPal Button with Color and Size options
$page->append_body(
PayPal_Button( "my@email.com", "Prada Boots", 340.0, "USD",
array( "Colors:", "Sizes:" ),
array( "color", "size" ),
array( array( "Blue"=>5, "Red"=>6, "Turquoise"=>7 ), array( "Small"=>"S", "Medium"=>"M" ) ),
array( "5", "M" ), '<!--none-->' )
) ;

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// Masspay example; we only have two recipients.
$payees = array(
array( 'email'=>'john@doe.com', 'amount'=>'45.00',
'id'=>'Unique Paycheck Number', 'note'=> 'Here is your pay for September 2009' ),
array( 'email'=>'mary@smith.com', 'amount'=>'67.00',
'id'=>'Another Unique PayCheck Number', 'note'=>'Mary, thanks for the fish tank!' )
);

$response = DoMassPayRequest( $credentials, "You have been paid via MassPay!", "referenceme@someemail.com", "USD", $payees, 'beta-sandbox' );
if("SUCCESS" == strtoupper($response["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($response["ACK"])) return true; else return false;

$response = DoAuthorize( $credentials, "2314", "22.42", "USD", 'beta-sandbox' );

$response = DoReauthorization( $credentials, $auth_id, "22.42", "USD", 'beta-sandbox' );

$response = DoVoid( $credentials, $auth_id, "Refund for out of stock item", 'beta-sandbox' );

$response = DoCapture( $credentials, $auth_id, "22.42", "USD", "Some ID", 'beta-sandbox' );

$response = GetBalance( $credentials, 'beta-sandbox' );

$response = DoRefund( $credentials, $transaction_id, 'Partial', 'USD', '21.50', 'Partial refund for damaged item.', 'sandbox' );

$response = GetTransactions( $credentials, $transaction_id, strototime("-2 days"), strtotime("now"), 'live' );

// check a paypal response
if ( $response['ACK'] == "SUCCESS" || $response['ACK'] == "SUCCESSWITHWARNING" ) { .. } else { .. }

Chart Helper
$this->load->helper('chart');

$slices = array(
array( 'title'=>'Percentage of Herb Growers', 'pullout'=>true, 'value'=>17, 'url=>'http://www.potgrowersusa.com' ),
array( 'title'=>'Percentage of Herb Consumers, 'pullout'=>true, 'value'=>35, 'url=>'http://www.hightimes.com' ),
array( 'title'=>'Percentage of Herb Drinkers', 'pullout'=>true, 'value'=>70, 'url=>'http://www.moderndrunkard.com' )
);

$settings = array( 'base_color'=>'FF0000' );
$page->append_body( pie( $settings, $slices, "somewriteable.xml" ) );

Compatibility Helper
$this->load->helper('compatibility');

PHP_EOL (constant)

file_put_contents() - 4th parameter, $context, is not supported.

fputcsv()

http_build_query()
stripos()

str_ireplace() - 4th parameter, $count, is not supported, as PHP 4 would make it become required.

Cookie Helper

$this->load->helper('cookie');

cook( "username", "fred" );
uncook("username");

$cookie = array( 'name'   => 'The Cookie Name',
                   'value'  => 'The Value',
                   'expire' => '86500',
                   'domain' => '.some-domain.com',
                   'path'   => '/',
                   'prefix' => 'myprefix_' );
set_cookie($cookie);
set_cookie($name, $value, $expire, $domain, $path, $prefix);

get_cookie('some_cookie');
get_cookie('some_cookie', TRUE);
delete_cookie("name");
delete_cookie($name, $domain, $path, $prefix);

Country Helper
$this->load->helper('country');

$my_lang = show_my_language();
$output = find_key_in_file( 'langs/ourfile', 'key' );
echo $output , form_input( ... );

$keys = prefetch_keys( "path/to/someKVfile.txt" );
$keys = prefetch_keys_special( "path/to/someKVfile.txt" );

$our_language_code = find_language();
$translated=prefetch_language( "lang/shoppingcart" );

// reads file lang/nav.lang
$navigation = prefetch_language( "lang/nav" );
$indexpage = prefetch_language( "lang/index" );
$translated = merge_keys( $navigation, $indexpage );

$keys = show_keyfile( "path/to/someKVfile.txt" );
$key = fast_lang_block( "path/to/KVfile","key",$lang_code );
$key = safe_lang_block( "path/to/KVfile","key", $lang_code );
$uses_currency = find_currency( find_language() );
$cash = exchange( "USD", "EUR", "22.50", "12/22/2009" );

$page->append_body( currency_combo( "currency_form_element", 4 ) );
$code = currency_to_code( 3 );

$geoinfo = getgeo();
putgeo( "users", $user_id );
$maxmind_info = maxmind();

CSS Helper
$this->load->helper('css');

$code = cssdiv( "an_id", "width:534px" );

Data Helper
$this->load->helper('data');

if ( not_null( $somevariable ) ) ..
$trimmed_array = dropzerolen($array);
$interpolated = interpolate( 50, 120, 0.5 );

Date Helper
$this->load->helper('date');

$time = now();
echo mdate($datestring, $time);

$format = 'DATE_RFC822';
$time = time();
echo standard_date($format, $time);

$gmt = local_to_gmt(time());

$timestamp = '1140153693'; $timezone = 'UM8';
$daylight_saving = TRUE;
echo gmt_to_local($timestamp, $timezone, $daylight_saving);
$unix = mysql_to_unix($mysql);

echo unix_to_human(time()); // U.S., no seconds
echo unix_to_human(time(), TRUE, 'us'); // U.S.
echo unix_to_human(time(), TRUE, 'eu'); // Euro

$span = timespan($post_date, $now);
$month = days_in_month(06, 2005);
echo timezones('UM5');
echo timezone_menu('UM8');

Directory Helper
$this->load->helper('directory');

$map = directory_map('./mydirectory/');
$map = directory_map('./mydirectory/', TRUE);
$map = directory_map('./mydirectory/', FALSE, TRUE);

Download Helper
$this->load->helper('download');

$data = file_get_contents("/path/to/photo.jpg");
$name = 'myphoto.jpg';
force_download($name, $data);

Email Helper
$this->load->helper('email');

if (valid_email('email@somesite.com')) ...
send_email('recipient', 'subject', 'message');

File Helper
$this->load->helper('file');

$string = read_file('./path/to/file.php');
if ( !write_file('./path/to/file.php', $data)) { /*can't write*/ }
write_file('./path/to/file.php', $data, 'r+');
delete_files('./path/to/directory/');
delete_files('./path/to/directory/', TRUE);
get_filenames('path/to/directory/')
get_dir_file_info('path/to/directory/')
get_file_info('path/to/file', $file_information)
echo $file . ' is mime type of ' . get_mime_by_extension($file);
echo symbolic_permissions(fileperms('./index.php'));
echo octal_permissions(fileperms('./index.php'));
file_put_contents_atomic( "somefile.txt", "some content" );

Flash Helper
$this->load->helper('flash');

$page->append_body( swf( "../some.swf", 534, 380 ) );

Form Helper
$this->load->helper('form');

echo form_open('email/send');
echo form_open('email/send', $attributes);
echo form_open('email/send', '', $hidden);
echo form_hidden('username', 'johndoe');
echo form_input('username', 'johndoe');
echo form_dropdown('shirts', $options, 'large'); // see docs
echo form_multiselect( .. );
echo form_fieldset('Address Information');
echo "<p>fieldset content here</p>\n";
echo form_fieldset_close();
echo form_checkbox('newsletter', 'accept', TRUE);
echo form_submit('mysubmit', 'Submit Post!');
echo form_label('What is your Name', 'username');
echo form_reset( .. )
echo form_button($data);
echo form_close($string);

// See additional functions set_value(), set_select(), etc.. in docs

GeSHi Helper
$this->load->helper('geshi');

$page->append_body( '<div id="highlighted">' . $content . '</div>' . geshi_select( "highlighted", get_ajax() ) );
$page->append_body( geshify( "<html></html>", "html" ) );

Hash Helper
$this->load->helper('hash');

$unique_code = hash_code( "Users", 32 );
$hash = hash_temp( 16 );
$sql = hash_key( 16 );
$sql = hash_ref();

HTML Helper
$this->load->helper('html');

$this->page->append_body( div( "main_content", 'name="content"', "width:200px" ) );
echo group( 500, 400 ) . "content" . ungroup() );
$this->page->append_body( scrolly( "scrolling", "<b>Some HTML!</b><br>" . lorem_ipsum(10) ) );
echo br(3);
echo heading('Welcome!', 3);
echo img('images/picture.jpg');
echo link_tag('css/mystyles.css');
echo link_tag('favicon.ico', 'shortcut icon', 'image/ico');
echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
echo nbs(3);
echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
echo doctype('html4-trans');

Inflector Helper
$this->load->helper('inflector');

$word = "dogs"; echo singular($word); // Returns "dog"
$word = "dog"; echo plural($word); // Returns "dogs"
$word = "my_dog_spot"; echo camelize($word); // "myDogSpot"
$word = "a spot"; echo underscore($word); // "a_spot"
$word = "my_spot"; echo humanize($word); // "My Spot"

JS Helper
$this->load->helper('js');

$page->append_head( js( "var a=5;" ) );

$page->append_head( add_event( "domid", "onchange", "javascript:this()" ) );
$page->append_head( add_event_id( "domid", "onchange", "javascript:this()" ) );

$page->append_head( alert( "Alert! Alert! All hands to battlestations!" ) );

$page->append_body( jsredirect( "http://foofle.com", 20 ) );

add_onload( "javascriptfunction()" );

$page->append_body( js_character_counter( 1024, "message", "msg_counter"));

$page->append_head( setup_tinymce( ) );
$page->append_body( tinymce("my_text_id","some default content" ) );

$page->append_head( use_zorng( ) );
/* see docs for more on zorng VectorGraphics functions */

Menu Helper
$this->load->helper('menu');

$page->append_head( init_stylish_buttons() );
$page->add_onload( onload_preload_images( array( "someimage.jpg", "someotherimage.png" ) );

$items=array();
$items[] = array( 0=>here().'/home', 1=>'View your home wall.', 2=>'wall' );
$items[] = array( 0=>here().'/photos', 1=>'View and manage your photos.', 2=>'photos' );
$fillwidth=146;

make_menu_horiz( "name", base_url().'MENU', $items, base_url().'MENU/filler.png', $fillwidth );
make_menu_vert( "name2", base_url().'MENU', $items2, base_url().'MENU/filler.png' );

$menus = get_menus();
$page->append_head( $menus['head'] );
$page->add_onload( $menus['onload'] );
$page->append_body( $menus['name'] );

Number Helper
$this->load->helper('menu');

echo byte_format(456); // Returns 456 Bytes
echo byte_format(4567); // Returns 4.5 KB
echo byte_format(45678); // Returns 44.8 KB
echo byte_format(456789); // Returns 447.8 KB
echo byte_format(3456789); // Returns 3.3 MB
echo byte_format(12345678912345); // Returns 1.8 GB
echo byte_format(123456789123456789); // Returns 11,228.3 TB

Path Helper
$this->load->helper('path');

$directory = '/etc/passwd';
echo set_realpath($directory); // returns "/etc/passwd"

$non_existent_directory = '/path/to/nowhere';
echo set_realpath($non_existent_directory, TRUE);
// returns an error, as the path could not be resolved

echo set_realpath($non_existent_directory, FALSE);
// returns "/path/to/nowhere"

ProJAX Helper
$this->load->helper('projax');
$this->page->append_head( "<script src="http://www.ngcoders.com/projax/js/prototype.js" type="text/javascript"></script><script src="http://www.ngcoders.com/projax/js/scriptaculous.js" type="text/javascript"></script>" );
// or call init_jquery() from ajax_helper

$projax = new Projax();

echo "Please enter your year of birth:
<?=$projax->text_field_with_auto_complete( 'dob',null,array('url'=>'index.php?task=ajax' ));?> ";
for($i=1900;$i<2006;$i++)$ret_val.=(strstr($i,$_POST['dob']))
?'<li>'.$i.'</li>':'';
echo '<ul>'.$ret_val.'</ul>';

$javascript= new JavaScript();
echo button_to_function('Greetigs', 'alert("Hello world!")' );
echo escape($javascript);
echo tag('alert("All is good")');
echo link_to_function("Greeting","alert('Hello world!')");

$prototype= new Prototype();
$js=evaluate_remote_response();
echo form_remote_tag( array('url'=>$some_url) );
echo link_to_remote("Delete this post",array('url'=>$some_url."task=delete&id=".$some_id."'" , 'complete'=>'undoRequestCompleted(request)'));
echo observe_field($field_id,$options=null);echo observe_form($form,$options=null);
echo periodically_call_remote($options=null);
echo remote_function($options);
echo submit_to_remote($name,$value,$options=null);
dump($javascript);
ID('blank_slate'); // => Will return $('blank_slate');
ID('blank_slate','show'); // => $('blank_slate').show();
alert($message);
assign($variable,$value);
call($function,$args=null);
delay($seconds=1,$script="");
hide($ids);
insert_html($position,$id,$options_for_render=null);
insert_html('before','content',array('partial'=>'navigation');
redirect_to($location);
remove($domids ..); // removes DOM elements
replace($domid,$options_for_render=null);
replace_html($id,$options_for_render=null);
select('p') // => $$('p');
show($domids);
toggle($ids);

$scriptaculous= new Scriptaculous();

draggable_element('my_image',array('revert'=?'true'));
drop_receiving_element('my_cart',array('url'=>$update_url));
sortable_element('my_list',array('url'=>$order_url));
auto_complete_field($field_id,$options=null);
in_place_editor($field_id,$options=null);
in_place_editor_field(object, $tag_options=null,$options=null);
text_field_with_auto_complete(object,$tag_options=null,$options=null);

Query Helper
$this->load->helper('query');

if ( !flag( SOME_CONSTANT_BIT, $flags ) ) return true; else return false;
if ( !on( SOME_CONSTANT_BIT, $flags ) ) return true; else return false;
if ( off( SOME_CONSTANT_BIT, $flags ) ) return true; else return false;
bittoggle( SOME_CONSTANT_BIT, $flags );

$result_str = adt( "this, that, the, other, thing"); // Adds `this`,`that`
$result_str = adq( $strlist ); // Adds 'this','that'
$result_str = sq( $str ); // turns \" and \' -> " '
$result_str = msq( $str ); // " ' -> \" \'
$result_str = qs( $str ); // " -> \"

// mysql-related functions
$res = mysql_query($query,$target_db) or err(mysql_error(),$query);
$last_id = mysql_get_last_id( "users" );
mysql_insert( "users", "id", 7 );
mysql_set( "users", $user_id, "username", "Zephyr667" );
mysql_now( "users", $user_id, "modified" );
define( SOME_FLAG, 1 );
mysql_activate( "users", $user_id, "access_flags", SOME_FLAG );
mysql_deactivate( "users", $user_id, "access_flags", SOME_FLAG );
mysql_toggle( "users", $user_id, "access_flags", SOME_FLAG );
$flags = mysql_flag_value( "users", $user_id, "access_flags" );
if ( mysql_has( "users", $user_id, "access_flags', SOME_FLAG ) ) {...} else {...}
mysql_add_field( "users", "brief_bio", "VARCHAR(255)" );
$row=mysql_find( "users", "username", "jrichards" );
// Use the optional fourth parameter to filter more specifically.
$row=mysql_find( "users", "username", "jrichards", " AND WHERE modified=NOW() ORDER BY `username` LIMIT 1" );
$rows=mysql_find_like( "cars", "brand", "Ford" );
$rows=mysql_find_like( "cars", "brand", "Ford", " AND `released`>1997 ORDER BY `released` ASC LIMIT 100" );
$september09 = mysql_find_month( "logins", "time", 9, 2009 );
$table = mysql_find_all( "users" );
$table = mysql_find_all( "users", " WHERE `username` LIKE '%john%'" );
$table = mysql_find_all( "users", " WHERE `username` LIKE '%john%' AND `age`>17 LIMIT 5" );
$rows=mysql_get_related( "cars", "brand", "Ford" );
$sorted = mysql_find_sorted( "users", "username", 10, "ASC" );
$array = mysql_to_array( mysql_query ( $db_con, $query ) ) ;

// integrated with the Database class
$rows=find_like( "cars", "brand", "Ford" );
$rows=find_like( "cars", "brand", "Ford", " AND `released`>1997 ORDER BY `released` ASC LIMIT 100" );
$rows=find_similar( "cars", "brand", "Ford" );
$rows=find_similar( "cars", "brand", "Ford", " AND `released`>1997 ORDER BY `released` ASC LIMIT 100" );
$table = find_all( "users" );
$table = find_all( "users", " WHERE `username` LIKE '%john%'" );
$table = find_all( "users", " WHERE `username` LIKE '%john%' AND `age`>17 LIMIT 5" );
$september09 = find_month( "logins", "time", 9, 2009 );
insert( "users", "id", 7 );
$next_id = new_id( "users" );
$user_id = multiinsert( "users", "username", "MMoore", "first_name", "Michael", "last_name", "Moore" ... );
multiupdate( "users", $user_id, "username", "MikeyMoore", "first_name", "Mikey" );
set( "users", $user_id, "username", "Mikey420" );
now( "users", $user_id, "logged_off" );
activate( "users", $user_id, "flags", FLAG1_USER );
deactivate( "users", $user_id, "flags", FLAG2_USER );
toggle( "users", $user_id, "flags", FLAG_ONLINE_STATUS );
$flag = flag_value( "users", $user_id, "flags" );
$flag = has( "users", $user_id, "flags" );
$row=find( "users", "username", "jrichards" );
$row=find( "users", "username", "jrichards", " AND WHERE modified=NOW() ORDER BY `username` LIMIT 1" );
delete( "users", "username", "Mikey420" );
if ( yes( "users", "id", $user_id, "is_active" ) ) {...} else {...}
if ( no( "users", "id", $user_id, "is_active" ) ) {...} else {...}

reCAPTCHA Helper
$this->load->helper('recaptcha');

$captcha_public_key = "reCAPTCHA public key";
$captcha_private_key="reCAPTCHA private key";
generate_captcha();

// or use ours:
generate_captcha();

if ( validate_captcha( $this->post ) ) { ... login ... } else { ... don't ... }

Security Helper
$this->load->helper('security');

xss_clean() // see Input class

$str = dohash($str); // SHA1
$str = dohash($str, 'md5'); // MD5
$string = strip_image_tags($string);
$string = encode_php_tags($string);
$string = inject_protect_sql($string);
$string = inject_protect_email($string);
$string = inject_protect_numbers($string);
$string = inject_protect_ssn($string);
$string = inject_protect_CC($string);
$string = inject_protect_zip($string); // zip codes
$string = inject_protect_punctuate($string);
$string = keyED($string,"somekey");
$string = decrypt($string,"somekey");

Smiley Helper
^Read the docs on this one (click the link above).

Social Helper
$this->load->helper('social');

$page->append_head( track_with_ga( "Your Google Analytics Code" ) );

$page->append_head( meta_tagger( "This Page Title", here().'/images/this_page_thumb.jpg', "A great page, come visit.", "page visit thumb title" ) );

// send it to a search object in your site
$page->append_body( tag_cloud( array( "alpha", "beta", "gamma", "delta" ), here().'/search/' ) );

String Helper
$this->load->helper('string');

$limited = slimit( $text, 250 );
$no_more_slashes = strip_slashes( "/this/" );

echo random_string('alnum', 16);

for ($i = 0; $i < 10; $i++)
echo alternator('string one', 'string two');
for ($i = 0; $i < 10; $i++)
echo alternator('one', 'two', 'three', 'four', 'five');

$string = "\n"; echo repeater($string, 30);

$string = "http://example.com//index.php";
echo reduce_double_slashes($string);
// results in "http://example.com/index.php"

$string = "/this/that/theother/";
echo trim_slashes($string); // results in this/that/theother

$string="Fred, Bill,, Joe, Jimmy";
$string=reduce_multiples("F, B,, J, Y",","); // results in "F, B, J, Y"
$str=reduce_multiples(",F,B,,J,Y,", ", ", TRUE); //results in "F,B,J,Y"

$string=quotes_to_entities("Joe's \"dinner\"");
//results in "Joe&#39;s &quot;dinner&quot;"

$string=strip_quotes("Joe's \"dinner\"");
//results in "Joes dinner"

Text Helper
$this->load->helper('text');

$page->append_body( fine( "Do not remove this tag." ) );
echo nicetime(date("Y-m-j",strotime("now"))));
$page->append_body( lorem_ipsum( 1, "div", 16 ) );
$page->append_body(censorship( "This is a fucking joke." ));
$string = "Here is a text string consisting of ten words.";
$string = word_limiter($string, 4); // Returns: Here is a text…
$string = "Here is a text string consisting of ten words.";
$string = character_limiter($string, 20);
// Returns: Here is a nice text string…
$string = ascii_to_entities($string);
$disallowed = array('darn', 'shucks', 'golly', 'phooey');
$string = word_censor($string, $disallowed, 'Beep!');
$string = highlight_code($string); // Use GeSHi Helper!
$string = "Here is a nice text string about nothing in particular.";
$st= highlight_phrase($string, "nice text", '<span style="color:#990000">', '</span>');
$pg = "Here is a simple string of text that will help us demonstrate this function.";
echo word_wrap($pg, 25); // wraps at 25 characters

Typography Helper
$this->load->helper('typography');

$string = auto_typography($string);
$string = nl2br_except_pre($string);

URL Helper
$this->load->helper('url');

echo site_url("news/local/123");

$segments = array('news', 'local', '123');
echo site_url($segments);

echo base_url();
echo index_page(); // basically returns index.php
echo here(); // base_url() . index_page()
echo current_url(); // where we are
echo uri_string(); // returns the uri portion of the page

echo anchor('news/local/123', 'title="News"');
echo anchor('news/local/123', 'News', array('title'=>'The best!'));

$atts = array( 'width'      => '800',
              'height'     => '600',
              'scrollbars' => 'yes',
              'status'     => 'yes',
              'resizable'  => 'yes',
              'screenx'    => '0',
              'screeny'    => '0'  );
echo anchor_popup('news/local/123', 'Click Me!', $atts);
echo anchor_popup('news/local/123', 'Click Me!', array());

echo mailto('me@my-site.com', 'Click Here to Contact Me');
echo safe_mailto('me@my-site.com', 'Click Here to Contact Me');

$string = auto_link($string);
$string = auto_link($string, 'url');
$string = auto_link($string, 'email');
$string = auto_link($string, 'both', TRUE);

$t = "What's wrong with CSS?";
$url_title = url_title($t); // Produces: Whats-wrong-with-CSS
$t = url_title("What's wrong?", 'underscore', TRUE);
// Produces: whats_wrong

$url = prep_url("example.com");

if ($logged_in == FALSE) redirect('/login/form/', 'refresh');
// with 301 redirect
redirect('/article/13', 'location', 301);

$array = array( "one"=>1, "two"=>2, "three"=>3 );
$encoded = urlEncodeArray( $array );
$decoded = urlDecodeArray( $encoded );

XML Helper
$this->load->helper('xml');

$string = xml_convert($string);
print_r( xml2array( "http://someplace.com/this.xml" ) );
$sanitized = ajax_xml_sanitize( $dirty_xml );
$html = xml_to_html_code( $xml );
$sanitized = ajax_xml_sanitize( $dirty_xml );