CodeIgniter helpers are great, but that are some cool functions that we would love to have. Here is a list of custom helpers we have added:
This helper is loaded once on the dashboard section. It contains only one function for the moment but we will create other if needed.
label_condition: displays a Bootstrap label component depending of the provided condition status.
$cond = true; echo label_condition($cond, 'lang:active', 'lang:inactive'); // Yes, it handles translations.
Few functions have been added and more to come if needed:
array_keys_exist: Takes an array of keys and make sure they all exist in the array.
keys_in_array: Takes an array of keys and check in at least one of them is present..
array_keys_exist($keys, $array); keys_in_array($keys, $array);
We added only two functions but, if needed, we may add more in the future:
directory_delete: Delete all directory's files and subdirectories.
directory_files: Returns a list of all files in the selected directory and all its subdirectories up to 100 levels deep.
For the sake for security and functionality, we have added several functions:
validate_file: validates a file name and path against an allowed set of rules.
check_file_md5: Calculates the MD5 of the selected file then compares it to the expected value.
get_file_data: Retrieve metadata from the selected file. It is used to retrieve themes and plugins details and any thing you may developer in the future.
unzip_file: (thank your WordPress) this function is used by themes and plugins modules to upload ZIP archives and install files. If you develop something that may use this function.
unzip_file is automatic and should be used. In fact, it only checks if the
ZipArchive to use it via the
_unzip_file_ziparchive function. If the class does not exists, if will use a third party library
PclZip via the
It contains only three functions new functions created for the purpose of Skeleton project, and two more to extend CodeIgniter functions.
print_input: Prints a form input with possibility to add extra attributes instead of using array_merge on views.
validation_errors_list: Return form validation errors in custom HTML list. Default: unordered list.
_translate: Used by
print_input, This function simply attempts to translate a string if it finds "lang:" at the start of it.
Functions that extend CodeIgniter are:
safe_form_open: Function for creating the opening portion of the form, but with a secured action using "safe_url" from KB_url_helper.
safe_form_open_multipart: Function for creating the opening portion of the form, but with "multipart/form-data" and a secured action using "safe_url".
It contains three functions:
img: that simply inverts $attributes and $index_page of the original CodeIgniter
html_tag: it generates any type of HTML tags within your PHP code.
build_list(experimental): created to be used later for the menu builder, it is right there for the moment until we fully develop it. It takes and array and built a
sanitize: Sanitizes the given string using
generate_safe_token: Generates the safe token token used by other function that start with
readable_random_string: it does the same thing as Codeigniter
random_stringfunction, except that the result is a human-readable random string.
mask_string: yes, it mask a given string. For instance, you want to hide email addresses and keep only few characters at the beginning and the end, you can use it:
echo mask_string('email@example.com', 2, 2, '*'); // Outputs: my***************om
For the sake of this project, several functions were added and some were added to override CodeIgniter functions:
anchor: override default function in order to translate
$titleif it starts with
echo anchor('uri', 'lang:home');
anchor_popup: same as the one above it, it override default function to automatically translate titles.
current_url: overrides CodeIgniter default function so we can add
trace_anchor: they simply append a
$_GETparameter to URLs so you can use them for tracking purposes. Outputs something like
safe_anchor: use a lot in the project for security purposes, their URLs contain extra
tsthat you can check on the next request for security using the
For the other functions, we will use x that will refer to : admin, ajax, process and api.
The last function is
build_safe_url used to generate tokens for function with
safe_ at the beginning.