From 2356cad4bc31e9cc7b4eecb6f2ccf7c4c3de7e64 Mon Sep 17 00:00:00 2001 From: Christine Ho Date: Sun, 22 Jun 2014 22:53:31 +0200 Subject: [PATCH 1/2] - optimization of prepareDate function --- app/helpers/DateHelper.php | 63 +++++++++++++---------------- app/widgets/AdminMain/AdminMain.php | 5 ++- bootstrap.php | 3 +- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/app/helpers/DateHelper.php b/app/helpers/DateHelper.php index 41982e64f..d63b5e154 100644 --- a/app/helpers/DateHelper.php +++ b/app/helpers/DateHelper.php @@ -38,50 +38,41 @@ function getTimezoneCorrection() { $timezones = getTimezoneList(); return $timezones[date_default_timezone_get()]; } - /** * Return a human-readable date * * @param timestamp $string * @return string */ -function prepareDate($time, $hours = true) { - $dotw = getDays(); - - $moty = getMonths(); - - $today = strtotime(date('M j, Y')); - - // We fix the timezone - $time = $time + 3600*(int)getTimezoneCorrection(); - - $reldays = ($time - $today)/86400; - - if ($reldays >= 0 && $reldays < 1) { //$reldays == 0 ? - $date = __('date.today'); - } else if ($reldays >= 1 && $reldays < 2) { //$reldays == 1 ? - $date = __('date.tomorrow'); - } else if ($reldays >= -1 && $reldays < 0) { //$reldays == -1 ? - $date = __('date.yesterday'); - } else { - - if (abs($reldays) < 7) { - if ($reldays > 0) { //=> $reldays > 1 - $reldays = floor($reldays); - $date = 'In ' . $reldays . ' '.__('date.day') . ($reldays != 1 ? 's' : ''); //you always have s - } else { - $reldays = abs(floor($reldays)); - $date = __('date.ago', $reldays); - } - } else { - $date = $dotw[date('N',$time ? $time : time())] .', '.date('j',$time ? $time : time()).' '.$moty[date('n',$time ? $time : time())] ; - if (abs($reldays) > 182) - $date .= date(', Y',$time ? $time : time()); +function prepareDate($time, $hours = true) { + $t = $time ? $time : time(); + + $reldays = ((time() - $t)-(time()%86400))/86400; + // if $time is within a week + if($reldays < 7 && $reldays >= -1){ + //if $time is today or yesterday + if($reldays < 0) { + $date = __('date.tomorrow'); + } else if ($reldays <= 0) { + $date = __('date.today'); + } else if ($reldays <= 1) { + $date = __('date.yesterday'); } + //else print date "ago" + else { + $date = __('date.ago', ceil($reldays)); + } + } + //else print full date + else { + $date = __('day.'.strtolower(date('l', $t))) .', '.date('j', $t).' '.__('month.'.strtolower(date('F', $t))) ; + //if over 6months print year + if (abs($reldays) > 182) + $date .= date(', Y', $t); } + //if $hours option print the time if($hours) $date .= ' - '. date('H:i', $time); - - if($time) - return $date; + return $date; + } diff --git a/app/widgets/AdminMain/AdminMain.php b/app/widgets/AdminMain/AdminMain.php index 149322f3d..62ed57fe2 100644 --- a/app/widgets/AdminMain/AdminMain.php +++ b/app/widgets/AdminMain/AdminMain.php @@ -33,12 +33,13 @@ class AdminMain extends WidgetBase } unset($form['repassword']); - foreach($form as $key => $value) { $config->$key = $value; } - $cd->set($config); + + //set timezone + date_default_timezone_set($form['timezone']); } } diff --git a/bootstrap.php b/bootstrap.php index 445f3003b..4c44a556f 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -239,8 +239,7 @@ class Bootstrap { $cd = new \Modl\ConfigDAO(); $config = $cd->get(); - //date_default_timezone_set($config->timezone); - date_default_timezone_set(date_default_timezone_get()); + date_default_timezone_set($config->timezone); } private function setLogLevel() { From 6719a96168837c66a71a0065c67111ceed664758 Mon Sep 17 00:00:00 2001 From: Christine Ho Date: Sun, 22 Jun 2014 23:15:59 +0200 Subject: [PATCH 2/2] - tiny little fix on administration UX --- app/widgets/AdminMain/adminmain.tpl | 12 ++--- themes/movim/css/forms.css | 69 +++++++++++++++-------------- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/app/widgets/AdminMain/adminmain.tpl b/app/widgets/AdminMain/adminmain.tpl index 378d5b18f..9a7a58f4e 100644 --- a/app/widgets/AdminMain/adminmain.tpl +++ b/app/widgets/AdminMain/adminmain.tpl @@ -120,12 +120,10 @@ {$c->__('whitelist.title')}
-

{$c->__('whitelist.info1')}

-

{$c->__('whitelist.info2')}

- -
+

{$c->__('whitelist.info1')}

+

{$c->__('whitelist.info2')}

@@ -141,12 +139,10 @@
-

{$c->__('information.info1')}

-

{$c->__('information.info2')}

- -
+

{$c->__('information.info1')}

+

{$c->__('information.info2')}

diff --git a/themes/movim/css/forms.css b/themes/movim/css/forms.css index 2daff7ab0..cb38ba68d 100644 --- a/themes/movim/css/forms.css +++ b/themes/movim/css/forms.css @@ -40,7 +40,7 @@ legend { display: block; box-sizing: border-box; -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; + -moz-box-sizing: border-box; overflow-y: hidden; } @@ -58,18 +58,9 @@ legend { min-height: 0; } -.element.mini > input { - min-height: 2em; - margin-bottom: 0.5em; -} - -.element > label { - display: block; - margin: 1em 0px; - font-weight: bold; -} - -.element > *:not(label):not(img):not(span):not(a):not(dl) { +/*.element > *:not(label):not(img):not(span):not(a):not(dl) {*/ +.element > input, +.element > textarea { display: inline-block; width: 100%; border: 1px solid #DDD; @@ -80,9 +71,21 @@ legend { padding: 0% 0.5em; box-sizing: border-box; -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; + -moz-box-sizing: border-box; +} + +.element.mini > input { + min-height: 2em; + margin-bottom: 0.5em; } +.element > label { + display: block; + margin: 1em 0px; + font-weight: bold; +} + + .element > *:not(label):not(img):focus { border: 1px solid gray; outline: none; @@ -154,7 +157,7 @@ legend { margin-right: 2%; box-sizing: border-box; -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; + -moz-box-sizing: border-box; } .element input[type="radio"] + label:hover { @@ -172,7 +175,7 @@ legend { border-radius: 0.1em; box-sizing: border-box; -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; + -moz-box-sizing: border-box; } .element input[type="radio"]:checked + label .preview { @@ -186,11 +189,11 @@ legend { } .checkbox { - width: 6em; - max-width: 6em; + width: 6em; + max-width: 6em; overflow: hidden; - position: relative; + position: relative; height: 2em; border-radius: 0.1em; @@ -200,7 +203,7 @@ legend { } .checkbox:after { - content: 'NO'; + content: 'NO'; display: block; position: absolute; @@ -214,11 +217,11 @@ legend { color: white; background-color: #D92727; - font-weight: bold; + font-weight: bold; } .checkbox:before { - content: 'YES'; + content: 'YES'; display: block; position: absolute; left: 0px; @@ -229,21 +232,21 @@ legend { background-color: #333; text-align: center; color: white; - font-weight: bold; + font-weight: bold; } .checkbox > input[type="checkbox"] + label { - display: block; - width: 3.3em; - height: 2em; + display: block; + width: 3.3em; + height: 2em; transition: left 0.5s ease; - cursor: pointer; - position: absolute; - top: 0px; - left: 0px; - z-index: 1; + cursor: pointer; + position: absolute; + top: 0px; + left: 0px; + z-index: 1; border-left: none; @@ -251,7 +254,7 @@ legend { } .checkbox > input[type="checkbox"]:checked + label { - left: 2.8em; + left: 2.8em; border-right: none; } @@ -262,7 +265,7 @@ legend { border: 1px solid transparent; box-sizing: border-box; -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; + -moz-box-sizing: border-box; padding: 0 0.7em; text-decoration: none;