1 <?php
defined('IN_CMS') or die('No direct access allowed.');
6 Note: we recommend you prefix all your functions to avoid any naming
7 collisions or wrap your functions with if function_exists braces.
10 function numeral($number) {
11 $test = abs($number) %
10;
12 $ext = ((abs($number) %
100 < 21 and abs($number) %
100 > 4) ?
'th' : (($test < 4) ?
($test < 3) ?
($test < 2) ?
($test < 1) ?
'th' : 'st' : 'nd' : 'rd' : 'th'));
13 return $number . $ext;
16 function count_words($str) {
17 return count(preg_split('/\s+/', strip_tags($str), null, PREG_SPLIT_NO_EMPTY
));
20 function pluralise($amount, $str, $alt = '') {
21 return intval($amount) === 1 ?
$str : $str . ($alt !== '' ?
$alt : 's');
24 function relative_time($date) {
25 $elapsed = time() - $date;
41 foreach($times as $seconds => $title) {
42 $rounded = $elapsed / $seconds;
45 $rounded = round($rounded);
46 return $rounded . ' ' . pluralise($rounded, $title) . ' ago';
53 Binding custom functions
54 This is just an example of what can be done
56 bind('about', function() {