LEPTON CMS 7.4.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
lepton_abstract.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
24abstract class LEPTON_abstract
25{
31 const NOT_SET_IN_INFO = "(unknown - not set in info.php)";
32
38 public array $language = [];
39
45 public array $parents = [];
46
52 public string $module_directory = "";
53
59 public string $module_name = "";
60
66 public string $module_function = "";
67
73 public string $module_version = "";
74
80 public string $module_platform = "";
81
87 public int $module_delete = 1;
88
94 public string $module_author = "";
95
101 public string $module_license = "";
102
108 public string $module_license_terms = "";
109
115 public string $module_description = "";
116
122 public string $module_guid = "";
123
129 public string $module_home = "";
130
135 public static $instance;
136
141 public static function getInstance(mixed $value = null): object
142 {
143 if (null === static::$instance)
144 {
145 static::$instance = new static();
146 static::$instance->getParents();
147 static::$instance->getLanguageFile();
148 static::$instance->getModuleInfo();
149 static::$instance->initialize($value);
150 }
151 return static::$instance;
152 }
153
157 protected function getParents(): void
158 {
159 // First the class itself
160 static::$instance->parents[] = get_class(static::$instance);
161
162 // Now the parents
163 $aTempParents = class_parents(static::$instance, true);
164 foreach($aTempParents as $sParentName)
165 {
166 static::$instance->parents[] = $sParentName;
167 }
168 }
169
175 protected function getModuleInfo(): void
176 {
177
178 foreach(static::$instance->parents as $sModuleDirectoryTop)
179 {
180 // strip namespace
181 $aTemp = explode("\\", $sModuleDirectoryTop);
182 foreach($aTemp as $sModuleDirectory)
183 {
184
185 $aMainClassNames = $this->getMainClassNames( $sModuleDirectory );
186
187 foreach($aMainClassNames as $sTempModuleDirectory)
188 {
189 $sLookUpPath = __DIR__."/../../modules/".$sTempModuleDirectory."/info.php";
190
191 if( file_exists($sLookUpPath) )
192 {
193 require $sLookUpPath;
194 // [1.1] mandatory information
195 static::$instance->module_name = ($module_name ?? self::NOT_SET_IN_INFO);
196 static::$instance->module_directory = ($module_directory ?? self::NOT_SET_IN_INFO);
197 static::$instance->module_function = ($module_function ?? self::NOT_SET_IN_INFO);
198 static::$instance->module_version = ($module_version ?? self::NOT_SET_IN_INFO);
199 static::$instance->module_author = ($module_author ?? self::NOT_SET_IN_INFO);
200 static::$instance->module_license = ($module_license ?? self::NOT_SET_IN_INFO);
201 static::$instance->module_description = ($module_description ?? self::NOT_SET_IN_INFO);
202 static::$instance->module_guid = ($module_guid ?? self::NOT_SET_IN_INFO);
203
204 // [1.2] optional information
205 if(isset($module_platform))
206 {
207 static::$instance->module_platform = $module_platform;
208 }
209 if(isset($module_delete))
210 {
211 static::$instance->module_delete = intval($module_delete);
212 }
213 if(isset($module_license_terms))
214 {
215 static::$instance->module_license_terms = $module_license_terms;
216 }
217 if(isset($module_home))
218 {
219 static::$instance->module_home = $module_home;
220 }
221 break;
222 }
223 }
224 }
225 }
226 }
227
231 protected function getLanguageFile(): void
232 {
233 if(defined("LEPTON_PATH"))
234 {
235 $aLookUpFilenames = [
236 LANGUAGE."_add.php",
237 LANGUAGE."_custom.php",
238 LANGUAGE.".php",
239 "EN_add.php",
240 "EN_custom.php",
241 "EN.php"
242 ];
243
244 foreach (static::$instance->parents as $sClassNameTop)
245 {
246 // strip namespace
247 $aTemp = explode("\\", $sClassNameTop);
248 $bExitGraceful = false;
249 foreach( $aTemp as $sClassName )
250 {
251 $aMainClassNames = $this->getMainClassNames( $sClassName );
252
253 foreach($aMainClassNames as $sTempModuleDirectory)
254 {
255 $lookUpPath = LEPTON_PATH."/modules/".$sTempModuleDirectory."/languages/";
256
257 $bFoundFile = false;
258
259 $sUsedFilename = "";
260 foreach ($aLookUpFilenames as $sTempFilename)
261 {
262 if (true === file_exists($lookUpPath.$sTempFilename))
263 {
264 require $lookUpPath.$sTempFilename;
265 $sUsedFilename = $sTempFilename;
266 $bFoundFile = true;
267 break;
268 }
269 }
270
271 if (false === $bFoundFile)
272 {
273 continue;
274 }
275
276 $tempName = "MOD_".strtoupper($sTempModuleDirectory);
277 if (isset(${$tempName}))
278 {
282 if (str_contains($sUsedFilename, "_add.php"))
283 {
284 $sDefaultFileName = str_replace("_add", "", $sUsedFilename);
285 $aLanguageAdd = ${$tempName};
286
287 require $lookUpPath.$sDefaultFileName;
288
289 ${$tempName} = array_merge(${$tempName}, $aLanguageAdd);
290 }
291
292 static::$instance->language = ${$tempName};
293 $bExitGraceful = true;
294 break;
295 }
296 }
297
298 if (true === $bExitGraceful)
299 {
300 break;
301 }
302 }
303 }
304 }
305 }
306
313 public function getHeadInfo(): array
314 {
315 return array(
316 "title" => "",
317 "description" => "",
318 "keywords" => ""
319 );
320 }
321
326 protected function getMainClassNames( $sAnyClassname )
327 {
328 $aElements = explode("_", $sAnyClassname);
329
330 $sTempName = array_shift($aElements);
331
332 $aReturnValue = array( $sTempName );
333
334 foreach($aElements as $term)
335 {
336 $sTempName .= "_".$term;
337 $aReturnValue[] = $sTempName;
338 }
339
340 if( 1 < count($aReturnValue) )
341 {
342 $aReturnValue = array_reverse( $aReturnValue );
343 }
344
345 return $aReturnValue;
346 }
347
363 public static function saveLastEditSection(int $iSectionID = 0): void
364 {
365 if ($iSectionID === 0)
366 {
367 if (true === isset($GLOBALS['section_id']))
368 {
369 $_SESSION['last_edit_section'] = $GLOBALS['section_id'];
370 }
371 } else {
372 $_SESSION['last_edit_section'] = $iSectionID;
373 }
374 }
375
376 public static function getConstants(): array
377 {
378 // "static::class" here does the magic
379 $reflectionClass = new \ReflectionClass(static::class);
380 return $reflectionClass->getConstants();
381 }
382
386 abstract protected function initialize();
387
396 public function showmodinfo(array $modvalues = [],bool $bPrompt = true )
397 {
398$info = '@DEPRECATED_TEMP 20250823: this method will be removed in L* > 7.4.0, see "cookie" for an example how to solve it';
399echo(LEPTON_tools::display_dev($info, 'pre','ui orange message'));
400echo (LEPTON_tools::display(debug_print_backtrace(), 'pre','ui message'));
401
402 // create a default data set
403 $showmodinfo = array(
404 /* the leptoken */
405 'leptoken' => get_leptoken() // $leptoken
406 /* this object including translations (THIS->language[ code ]) */
407 ,"THIS" => $this
408 /* the color to be used for frames */
409 ,"COLOR" => ( $this->module_function == "page" ? "olive" : "blue" )
410 /* the header title to be shown */
411 ,"HEADER" => $this->module_name
412 /* the module description to be shown */
413 ,"DESCRIPTION" => ( isset( $this->module_description ) ? $this->module_description : "" )
414 /* the full url to the image to be shown */
415 ,"IMAGE_URL" => LEPTON_URL."/modules/".$this->module_directory. "/icon.png"
416 /* array of buttons to be shown (or not) and how */
417 ,"BUTTONS" => array(
418 /*
419 * Listed below are the 4 default buttons, but additional buttons can be added in $modvalues
420 *
421 * Supported attributes:
422 * AVAILABLE => true (show active), false (show as no) or hide (do not show, default if not available or empty);
423 * URL => url for support details/contact (required when AVAILABLE => true, otherwise not used)
424 * TITLE => title to be shown for support button if not default
425 * ICON => icon to be shown if not hide
426 */
427 "LIVE_SUPPORT" => array( "AVAILABLE" => false
428 ,"URL" => ""
429 ,"TITLE" => ""
430 ,"ICON" => "call square"
431 )
432 ,"FORUM_SUPPORT"=> array( "AVAILABLE" => true
433 ,"URL" => "https://forum.lepton-cms.org/viewforum.php?f=14" // LEPTON forum for addons
434 ,"TITLE" => ""
435 ,"ICON" => "align left"
436 )
437 ,"README" => array( "AVAILABLE" => "hide"
438 ,"URL" => ""
439 ,"TITLE" => ""
440 ,"ICON" => "book"
441 )
442 ,"HELP" => array( "AVAILABLE" => "hide"
443 ,"URL" => ""
444 ,"TITLE" => ""
445 ,"ICON" => "question"
446 )
447 )
448 /* the data to be shown in sequence added. Also, spacers with unique key can be added.
449 * values can also be a link
450 * empty values are not shown
451 * also spacers can be added, but key must be unique
452 */
453 ,"INFO" => array()
454 );
455 if ( isset( $this->module_version ) && empty( $this->module_version ) === false )
456 { $showmodinfo[ "INFO" ][ "module_version" ] = $this->module_version; }
457 if ( isset( $this->module_platform ) && empty( $this->module_platform ) === false )
458 { $showmodinfo[ "INFO" ][ "module_platform" ] = $this->module_platform; }
459 if ( isset( $this->module_guid ) && empty( $this->module_guid ) === false )
460 { $showmodinfo[ "INFO" ][ "module_guid" ] = $this->module_guid; }
461 if ( isset( $this->module_author ) && empty( $this->module_author ) === false )
462 { $showmodinfo[ "INFO" ][ "module_author" ] = $this->module_author; }
463 if ( isset( $this->module_license ) && empty( $this->module_license ) === false )
464 {
465 $showmodinfo[ "INFO" ][ "S1" ] = "spacer2";
466 $showmodinfo[ "INFO" ][ "module_license" ] = $this->module_license;
467 if ( isset( $this->module_license_terms ) && empty( $this->module_license_terms ) === false )
468 {
469 $showmodinfo[ "INFO" ][ "module_license" ] .= "<br />" . $this->module_license_terms;
470 }
471 }
472 if ( isset( $this->module_home ) && empty( $this->module_home ) === false )
473 {
474 $showmodinfo[ "INFO" ][ "S2" ] = "spacer2";
475 if ( strpos ( $this->module_home , "href" ) == 0 )
476 {
477 $showmodinfo[ "INFO" ][ "module_home" ] = "<a href='".$this->module_home."' >".$this->module_home."</a>";
478 }
479 else
480 {
481 $showmodinfo[ "INFO" ][ "module_home" ] = $this->module_home;
482 }
483 }
484 // additional info values are normally not shown or are already used explicitly
485
486 // [1] load input params if available and merge with the default data set
487 if ( ( is_null( $modvalues ) === false ) // ist gesetzt
488 && ( is_array( $modvalues ) === true ) // ist ein array
489 && ( !empty( $modvalues ) ) // ist NICHT leer
490 )
491 {
492 $showmodinfo = array_replace_recursive( $showmodinfo, $modvalues );
493 }
494
495 // prepare needed libraries
496 $oTWIG = lib_twig_box::getInstance();
497
498 // create & render twig template engine
499 $sSource = $oTWIG->render(
500 "@theme/showmodinfo.lte"
501 ,$showmodinfo
502 );
503
504 if( true === $bPrompt )
505 {
506 echo $sSource;
507
508 return true;
509 } else {
510 return $sSource;
511 }
512 }
513
514
523 public function getEditorSettings()
524 {
525 // [1] base class name
526 $sBaseClassName = $this->parents[0];
527
528 // [2] custom class?
529 $sCustom = (class_exists( $sBaseClassName."_settings_custom", true)) ? "_custom" : "";
530 // [2.1] class exists?
531 if(class_exists($sBaseClassName."_settings".$sCustom, true))
532 {
533 // [2.2] try to get instance of the class
534 return eval("return ".$sBaseClassName."_settings".$sCustom."::getInstance();");
535 }
536 else
537 {
538 // [2.3] class not exists - return NULL
539 return NULL;
540 }
541 }
542
554 public function getAdditionalClass( string $basename="settings", string $classname="") : mixed
555 {
556 // [1] Basename
557 if($classname === "")
558 {
559 $classname = $this->parents[0];
560 }
561
562 // [2] Custom?
563 $custom = (class_exists($classname."_".$basename."_custom", true)) ? "_custom" : "";
564
565 // [3] class exists?
566 if( class_exists( $classname."_".$basename.$custom, true))
567 {
568 return eval("return ".$classname."_".$basename.$custom."::getInstance();");
569 }
570 else
571 {
572 return NULL;
573 }
574 }
575}
getAdditionalClass(string $basename="settings", string $classname="")
static getInstance(mixed $value=null)
static saveLastEditSection(int $iSectionID=0)
getMainClassNames( $sAnyClassname)
showmodinfo(array $modvalues=[], bool $bPrompt=true)
static display(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)
static display_dev(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)