CMS for the late garbage.fm
at main 66 lines 1.3 kB view raw
1<?php 2 3class ApplicationHelper extends HalfMoon\Helper { 4 public function bytes_h($size, $precision = 1) { 5 if ($size == 0) 6 return "0"; 7 8 $base = log($size, 1024); 9 $suffixes = array('', 'Kb', 'Mb', 'Gb', 'Tb'); 10 11 return round(pow(1024, $base - floor($base)), $precision) . 12 $suffixes[floor($base)]; 13 } 14 15 public function time_to_secs($time) { 16 $secs = 0; 17 18 $pieces = explode(":", $time); 19 20 $secs = floatval(array_pop($pieces)); 21 if (count($pieces)) 22 $secs += (intval(array_pop($pieces)) * 60); 23 if (count($pieces)) 24 $secs += (intval(array_pop($pieces)) * 60 * 60); 25 26 return $secs; 27 } 28 29 public function joined_host_names($C) { 30 $hosts = array(); 31 foreach ($C->hosts() as $host) 32 array_push($hosts, $host->full_name); 33 34 return $this->comma_join($hosts); 35 } 36 37 public function comma_join($list) { 38 $out = ""; 39 if (count($list) <= 1) 40 $out = $list[0]; 41 elseif (count($list) == 2) 42 $out = $list[0] . " and " . $list[1]; 43 else { 44 for ($x = 0; $x < count($list); $x++) { 45 if ($x > 0) 46 $out .= ", "; 47 48 if ($x == count($list) - 1) 49 $out .= " and "; 50 51 $out .= $list[$x]; 52 } 53 } 54 55 return $out; 56 } 57 58 public function settings() { 59 if (!$this->_settings) 60 $this->_settings = Settings::fetch(); 61 62 return $this->_settings; 63 } 64} 65 66?>