29030400, // seconds in a year (12 months) "month" => 2419200, // seconds in a month (4 weeks) "week" => 604800, // seconds in a week (7 days) "day" => 86400, // seconds in a day (24 hours) "hour" => 3600, // seconds in an hour (60 minutes) "minute" => 60, // seconds in a minute (60 seconds) "second" => 1 // 1 second ); $diff = abs($from - $to); if ($diff < 1) { return "Just now"; } $suffix = (($from > $to) ? ("from now") : ("ago")); $unitCount = 0; $output = ""; foreach($units as $unit => $mult) if($diff >= $mult && $unitCount < 1) { $unitCount += 1; // $and = (($mult != 1) ? ("") : ("and ")); $and = ""; $output .= ", ".$and.intval($diff / $mult)." ".$unit.((intval($diff / $mult) == 1) ? ("") : ("s")); $diff -= intval($diff / $mult) * $mult; } $output .= " ".$suffix; $output = substr($output, strlen(", ")); return $output; } class UserPrefs { public $theme; public function __construct($theme = "light") { $this->theme = $theme; } } function get_theme() { if (isset($_SESSION['id'])) { if (!isset($_COOKIE['user-prefs'])) { $up_cookie = base64_encode(serialize(new UserPrefs())); setcookie('user-prefs', $up_cookie); } else { $up_cookie = $_COOKIE['user-prefs']; } $up = unserialize(base64_decode($up_cookie)); return $up->theme; } else { return "light"; } } function get_theme_class($theme = null) { if (!isset($theme)) { $theme = get_theme(); } if (strcmp($theme, "light")) { return "uk-light"; } else { return "uk-dark"; } } function set_theme($val) { if (isset($_SESSION['id'])) { setcookie('user-prefs',base64_encode(serialize(new UserPrefs($val)))); } } class Avatar { public $imgPath; public function __construct($imgPath) { $this->imgPath = $imgPath; } public function save($tmp) { $f = fopen($this->imgPath, "w"); fwrite($f, file_get_contents($tmp)); fclose($f); } } class AvatarInterface { public $tmp; public $imgPath; public function __wakeup() { $a = new Avatar($this->imgPath); $a->save($this->tmp); } } ?>