LEPTON CMS 7.2.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 static function get_dateformats(): array
59 {
60 global $user_time;
61 global $TEXT;
62
63 // Get the current time (in the users timezone if required)
64 $actual_time = time();
65
66 // Get "System Default"
67 $sSystemDefault = "";
68 if ( isset( $user_time ) && $user_time === true )
69 {
70 $sSystemDefault = date(DEFAULT_DATE_FORMAT, $actual_time).' (';
71 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR).')';
72 }
73
74 // Add values to list
75 $DATE_FORMATS = array(
76 'system_default' => $sSystemDefault,
77 'j.n.Y' => date('j.n.Y', $actual_time).' (j.n.Y)',
78 'm/d/Y' => date('m/d/Y', $actual_time).' (M/D/Y)',
79 'd/m/Y' => date('d/m/Y', $actual_time).' (D/M/Y)',
80 'm.d.Y' => date('m.d.Y', $actual_time).' (M.D.Y)',
81 'd.m.Y' => date('d.m.Y', $actual_time).' (D.M.Y)',
82 'm-d-Y' => date('m-d-Y', $actual_time).' (M-D-Y)',
83 'd-m-Y' => date('d-m-Y', $actual_time).' (D-M-Y)',
84 'D M d, Y' => date( 'D M d, Y', $actual_time ),
85 'M d Y' => date( 'M d Y', $actual_time ),
86 'd M Y' => date( 'd M Y', $actual_time ),
87 'jS F, Y' => date( 'jS F, Y', $actual_time ),
88 'l, jS F, Y' => date( 'l, jS F, Y', $actual_time )
89 );
90
91 $oDateTool = lib_lepton::getToolInstance("datetools", true);
92 $oDateTool->set_core_language( DEFAULT_LANGUAGE );
93
94 $aFormatList = array(
95 'D M d, Y',
96 'M d Y',
97 'd M Y',
98 'jS F, Y',
99 'l, jS F, Y'
100 );
101
102 foreach ($aFormatList as &$format)
103 {
104 $DATE_FORMATS[ $format ] = $oDateTool->formatWithMySQL($format, $actual_time);
105 }
106
107 return $DATE_FORMATS;
108 }
109
116 static function get_timeformats(): array
117 {
118 global $user_time;
119 global $TEXT;
120
121 // Get the current time (in the users timezone if required)
122 $actual_time = time();
123
124 // Get "System Default"
125 $sSystemDefault = "";
126
127 if ((isset($user_time)) && ($user_time === true))
128 {
129 $sSystemDefault = date( DEFAULT_TIME_FORMAT, $actual_time ) . ' (';
130 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR) . ')';
131 }
132
133 return [
134 'system_default' => $sSystemDefault,
135 'H:i' => date('H:i', $actual_time),
136 'H:i:s' => date( 'H:i:s', $actual_time ),
137 'g:i a' => date( 'g:i a', $actual_time ), // Lowercase Ante meridiem and Post meridiem
138 'g:i A' => date( 'g:i A', $actual_time ) // Uppercase Ante meridiem and Post meridiem
139 ];
140 }
141
148 static function get_timezones(): array
149 {
150 return [
151 "Pacific/Kwajalein",
152 "Pacific/Samoa",
153 "Pacific/Honolulu",
154 "America/Anchorage",
155 "America/Los_Angeles",
156 "America/Phoenix",
157 "America/Mexico_City",
158 "America/Lima",
159 "America/Caracas",
160 "America/Halifax",
161 "America/Buenos_Aires",
162 "Atlantic/Reykjavik",
163 "Atlantic/Azores",
164 "Europe/London",
165 "Europe/Berlin",
166 "Europe/Kaliningrad",
167 "Europe/Moscow",
168 "Asia/Tehran",
169 "Asia/Baku",
170 "Asia/Kabul",
171 "Asia/Tashkent",
172 "Asia/Calcutta",
173 "Asia/Colombo",
174 "Asia/Bangkok",
175 "Asia/Hong_Kong",
176 "Asia/Tokyo",
177 "Australia/Adelaide",
178 "Pacific/Guam",
179 "Etc/GMT+10",
180 "Pacific/Fiji"
181 ];
182 }
183
190 static function get_errorlevels(): array
191 {
192 global $TEXT;
193 // Create array
194 $ER_LEVELS = [];
195
196 // Add values to list
197 if (isset($TEXT['SYSTEM_DEFAULT']))
198 {
199 $ER_LEVELS[''] = $TEXT['SYSTEM_DEFAULT'];
200 }
201 else
202 {
203 $ER_LEVELS[''] = self::SYSTEM_DEFAULT_STR;
204 }
205
206 $ER_LEVELS['0'] = 'E_NONE'; // standard for productive use
207 $ER_LEVELS[E_NOTICE] = 'E_NOTICE';
208 $ER_LEVELS[E_WARNING] = 'E_WARNING';
209 $ER_LEVELS['-1'] = 'E_EVERYTHING'; // highest level
210
211 return $ER_LEVELS;
212 }
213
223 static function get_backend_translation(string $sKey = ""): string
224 {
225 global $TEXT, $THEME;
226
227 $sLanguagePath_user = THEME_PATH."/languages/".LANGUAGE.".php";
228 $sLanguagePath_default = THEME_PATH."/languages/EN.php";
229
230 if (!isset($THEME))
231 {
235 if (file_exists($sLanguagePath_user))
236 {
237 require_once $sLanguagePath_user;
238 }
239 elseif( file_exists( $sLanguagePath_default ) )
240 {
241 require_once $sLanguagePath_default;
242 }
243 else
244 {
245 // avoid errors and conflicts for non existing $THEME
246 $THEME = [];
247 }
248 }
249
250 if (isset($THEME[$sKey]))
251 {
252 return $THEME[$sKey];
253 }
254 elseif (isset($TEXT[$sKey]))
255 {
256 return $TEXT[$sKey];
257 }
258 else
259 {
260 return "** ".$sKey." (Key not found in Languages!)";
261 }
262 }
263
271 static function getLanguagePath(string $sRootDir = ""): string
272 {
273 $lang = $sRootDir."/languages/".LANGUAGE.".php";
274 return (file_exists($lang))
275 ? $lang
276 : $sRootDir."/languages/EN.php"
277 ;
278 }
279}
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
const THEME_PATH