LEPTON CMS 7.3.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
lepton_basics.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
25{
26 const SYSTEM_DEFAULT_STR = 'System Default';
33 public static $instance;
34
41 public static function getInstance(): object
42 {
43 if (null === static::$instance)
44 {
45 static::$instance = new static();
46 }
47
48 return static::$instance;
49 }
50
58 // @DEPRECATED_TEMP 20250117: will be replaced by LEPTON_date in L* > 7.3.0
59 static function get_dateformats(): array
60 {
61 global $user_time;
62 global $TEXT;
63
64 // Get the current time (in the users timezone if required)
65 $actual_time = time();
66
67 // Get "System Default"
68 $sSystemDefault = "";
69 if ( isset( $user_time ) && $user_time === true )
70 {
71 $sSystemDefault = date(DEFAULT_DATE_FORMAT, $actual_time).' (';
72 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR).')';
73 }
74
75 // Add values to list
76 $DATE_FORMATS = array(
77 'system_default' => $sSystemDefault,
78 'j.n.Y' => date('j.n.Y', $actual_time).' (j.n.Y)',
79 'm/d/Y' => date('m/d/Y', $actual_time).' (M/D/Y)',
80 'd/m/Y' => date('d/m/Y', $actual_time).' (D/M/Y)',
81 'm.d.Y' => date('m.d.Y', $actual_time).' (M.D.Y)',
82 'd.m.Y' => date('d.m.Y', $actual_time).' (D.M.Y)',
83 'm-d-Y' => date('m-d-Y', $actual_time).' (M-D-Y)',
84 'd-m-Y' => date('d-m-Y', $actual_time).' (D-M-Y)',
85 'D M d, Y' => date( 'D M d, Y', $actual_time ),
86 'M d Y' => date( 'M d Y', $actual_time ),
87 'd M Y' => date( 'd M Y', $actual_time ),
88 'jS F, Y' => date( 'jS F, Y', $actual_time ),
89 'l, jS F, Y' => date( 'l, jS F, Y', $actual_time )
90 );
91
92 $oDateTool = lib_lepton::getToolInstance("datetools", true);
93 $oDateTool->set_core_language( DEFAULT_LANGUAGE );
94
95 $aFormatList = array(
96 'D M d, Y',
97 'M d Y',
98 'd M Y',
99 'jS F, Y',
100 'l, jS F, Y'
101 );
102
103 foreach ($aFormatList as &$format)
104 {
105 $DATE_FORMATS[ $format ] = $oDateTool->formatWithMySQL($format, $actual_time);
106 }
107
108 return $DATE_FORMATS;
109 }
110
117 // @DEPRECATED_TEMP 20250117: will be replaced by LEPTON_date in L* > 7.3.0
118 static function get_timeformats(): array
119 {
120 global $user_time;
121 global $TEXT;
122
123 // Get the current time (in the users timezone if required)
124 $actual_time = time();
125
126 // Get "System Default"
127 $sSystemDefault = "";
128
129 if ((isset($user_time)) && ($user_time === true))
130 {
131 $sSystemDefault = date( DEFAULT_TIME_FORMAT, $actual_time ) . ' (';
132 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR) . ')';
133 }
134
135 return [
136 'system_default' => $sSystemDefault,
137 'H:i' => date('H:i', $actual_time),
138 'H:i:s' => date( 'H:i:s', $actual_time ),
139 'g:i a' => date( 'g:i a', $actual_time ), // Lowercase Ante meridiem and Post meridiem
140 'g:i A' => date( 'g:i A', $actual_time ) // Uppercase Ante meridiem and Post meridiem
141 ];
142 }
143
155 // @DEPRECATED_TEMP 20250117: will be replaced by LEPTON_date in L* > 7.3.0
156 static function get_days(string $lang= "en_EN", bool $abbr= false): array
157 {
158 $oDATETOOLS = lib_lepton::getToolInstance("datetools");
159 return $oDATETOOLS->getWeekdayNames($lang, $abbr); // Wochentagsnamen ausgeschrieben
171 }
172
184 // @DEPRECATED_TEMP 20250117: will be replaced by LEPTON_date in L* > 7.3.0
185 static function get_months(string $lang= "en_EN", bool $abbr= false): array
186 {
187 $oDATETOOLS = lib_lepton::getToolInstance("datetools");
188 return $oDATETOOLS->getMonthNames($lang, $abbr); // Monatsnamen ausgeschrieben
205 }
206
213 // @DEPRECATED_TEMP 20250117: will be replaced by LEPTON_date in L* > 7.3.0
214 static function get_timezones(): array
215 {
216 return [
217 "Pacific/Kwajalein",
218 "Pacific/Samoa",
219 "Pacific/Honolulu",
220 "America/Anchorage",
221 "America/Los_Angeles",
222 "America/Phoenix",
223 "America/Mexico_City",
224 "America/Lima",
225 "America/Caracas",
226 "America/Halifax",
227 "America/Buenos_Aires",
228 "Atlantic/Reykjavik",
229 "Atlantic/Azores",
230 "Europe/London",
231 "Europe/Berlin",
232 "Europe/Kaliningrad",
233 "Europe/Moscow",
234 "Asia/Tehran",
235 "Asia/Baku",
236 "Asia/Kabul",
237 "Asia/Tashkent",
238 "Asia/Calcutta",
239 "Asia/Colombo",
240 "Asia/Bangkok",
241 "Asia/Hong_Kong",
242 "Asia/Tokyo",
243 "Australia/Adelaide",
244 "Pacific/Guam",
245 "Etc/GMT+10",
246 "Pacific/Fiji"
247 ];
248 }
249
256 static function get_errorlevels(): array
257 {
258 global $TEXT;
259 // Create array
260 $ER_LEVELS = [];
261
262 // Add values to list
263 if (isset($TEXT['SYSTEM_DEFAULT']))
264 {
265 $ER_LEVELS[''] = $TEXT['SYSTEM_DEFAULT'];
266 }
267 else
268 {
269 $ER_LEVELS[''] = self::SYSTEM_DEFAULT_STR;
270 }
271
272 $ER_LEVELS['0'] = 'E_NONE'; // standard for productive use
273 $ER_LEVELS[E_NOTICE] = 'E_NOTICE';
274 $ER_LEVELS[E_WARNING] = 'E_WARNING';
275 $ER_LEVELS['-1'] = 'E_EVERYTHING'; // highest level
276
277 return $ER_LEVELS;
278 }
279
289 static function get_backend_translation(string $sKey = ""): string
290 {
291 global $TEXT, $THEME;
292
293 $sLanguagePath_user = THEME_PATH."/languages/".LANGUAGE.".php";
294 $sLanguagePath_default = THEME_PATH."/languages/EN.php";
295
296 if (!isset($THEME))
297 {
301 if (file_exists($sLanguagePath_user))
302 {
303 require_once $sLanguagePath_user;
304 }
305 elseif( file_exists( $sLanguagePath_default ) )
306 {
307 require_once $sLanguagePath_default;
308 }
309 else
310 {
311 // avoid errors and conflicts for non existing $THEME
312 $THEME = [];
313 }
314 }
315
316 if (isset($THEME[$sKey]))
317 {
318 return $THEME[$sKey];
319 }
320 elseif (isset($TEXT[$sKey]))
321 {
322 return $TEXT[$sKey];
323 }
324 else
325 {
326 return "** ".$sKey." (Key not found in Languages!)";
327 }
328 }
329
337 static function getLanguagePath(string $sRootDir = ""): string
338 {
339 $lang = $sRootDir."/languages/".LANGUAGE.".php";
340 return (file_exists($lang))
341 ? $lang
342 : $sRootDir."/languages/EN.php"
343 ;
344 }
345}
static get_months(string $lang="en_EN", bool $abbr=false)
static get_timezones()
static getLanguagePath(string $sRootDir="")
static get_timeformats()
static get_errorlevels()
static getInstance()
static get_dateformats()
static get_backend_translation(string $sKey="")
const SYSTEM_DEFAULT_STR
static get_days(string $lang="en_EN", bool $abbr=false)
const THEME_PATH