File modules/template_engine/components/html/component_date/component-date.php

Last commit: Wed Mar 9 00:53:10 2022 +0100	dankert	Fix: Setting the correct timezone from the user property.
1 <?php 2 3 use cms\action\Action; 4 use language\Messages; 5 use util\Cookie; 6 use template_engine\Output; 7 8 function component_date($time ) 9 { 10 if ( $time==0) 11 echo Output::lang(Messages::UNKNOWN ); 12 else 13 { 14 echo '<span class="or-table-sort-value">'.str_pad($time, 20, "0", STR_PAD_LEFT).'</span>'; // For sorting a table. 15 16 echo '<time title="'; 17 $dl = Output::lang(Messages::DATE_FORMAT_LONG); 18 $dl = str_replace('{weekday}',addcslashes(Output::lang('DATE_WEEKDAY'.strval(date('w',$time))),'A..z'),$dl); 19 $dl = str_replace('{month}' ,addcslashes(Output::lang('DATE_MONTH' .strval(date('n',$time))),'A..z'),$dl); 20 $dl = date( $dl,$time ); 21 echo $dl; 22 unset($dl); 23 24 25 $past = abs(time()-$time ); 26 27 $units = [ 28 [ 60, Messages::SECOND, Messages::SECONDS ], 29 [ 60, Messages::MINUTE, Messages::MINUTES ], 30 [ 24, Messages::HOUR , Messages::HOURS ], 31 [ 30, Messages::DAY , Messages::DAYS ], 32 [ 12, Messages::MONTH , Messages::MONTHS ], 33 [ 999, Messages::YEAR , Messages::YEARS ], 34 ]; 35 36 echo ' ('; 37 38 if ( time()<$time) 39 echo "+"; 40 41 foreach ( $units as $unit ) { 42 if ( $past == 1 ) { 43 echo $past.' '.Output::lang($unit[1] ); 44 break; 45 } 46 elseif ( $past < $unit[0] ) { 47 echo $past.' '.Output::lang( $unit[2] ); 48 break; 49 } 50 else { 51 $past = intval( $past / $unit[0] ); 52 continue; 53 } 54 } 55 56 echo ')"'; 57 58 echo ' datetime="'.date('c',$time).'"'; 59 60 echo '>'; 61 $format = abs(\cms\base\Startup::getStartTime()-$time)>(60*60*24)?Messages::DATE_FORMAT:Messages::DATE_FORMAT_TODAY; 62 echo date( Output::lang($format),$time ); 63 echo '</time>'; 64 } 65 }
Download modules/template_engine/components/html/component_date/component-date.php
History Wed, 9 Mar 2022 00:53:10 +0100 dankert Fix: Setting the correct timezone from the user property. Sun, 5 Dec 2021 22:52:08 +0100 dankert Fix: Condider dates in future. Sat, 4 Dec 2021 00:36:49 +0100 dankert New: Short date format if the date is not older than 24 houres. Thu, 19 Nov 2020 00:45:44 +0100 Jan Dankert Security fix: We must update the login token on every login; Administrators are able to see the login tokens of users. Wed, 18 Nov 2020 20:42:57 +0100 Jan Dankert Getting/Setting cookies with constants, this is more safe. Mon, 9 Nov 2020 22:58:36 +0100 Jan Dankert Code-Cleanup Mon, 9 Nov 2020 22:20:51 +0100 Jan Dankert Using the