Added a chapter analysing Fortify's results; some general beautification; modified...
[ssproject1617.git] / testcms-final-anon / themes / default / functions.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 /**
4 Custom theme functions
5
6 Note: we recommend you prefix all your functions to avoid any naming
7 collisions or wrap your functions with if function_exists braces.
8 */
9
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;
14 }
15
16 function count_words($str) {
17 return count(preg_split('/\s+/', strip_tags($str), null, PREG_SPLIT_NO_EMPTY));
18 }
19
20 function pluralise($amount, $str, $alt = '') {
21 return intval($amount) === 1 ? $str : $str . ($alt !== '' ? $alt : 's');
22 }
23
24 function relative_time($date) {
25 $elapsed = time() - $date;
26
27 if($elapsed <= 1) {
28 return 'Just now';
29 }
30
31 $times = array(
32 31104000 => 'year',
33 2592000 => 'month',
34 604800 => 'week',
35 86400 => 'day',
36 3600 => 'hour',
37 60 => 'minute',
38 1 => 'second'
39 );
40
41 foreach($times as $seconds => $title) {
42 $rounded = $elapsed / $seconds;
43
44 if($rounded > 1) {
45 $rounded = round($rounded);
46 return $rounded . ' ' . pluralise($rounded, $title) . ' ago';
47 }
48 }
49 }
50
51
52 /**
53 Binding custom functions
54 This is just an example of what can be done
55
56 bind('about', function() {
57 return 'about page';
58 });
59 */