LEPTON CMS 7.2.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_custom.php",
240 "EN.php"
241 ];
242
243 foreach( static::$instance->parents as $sClassNameTop)
244 {
245 // strip namespace
246 $aTemp = explode("\\", $sClassNameTop);
247 $bExitGraceful = false;
248 foreach( $aTemp as $sClassName )
249 {
250 $aMainClassNames = $this->getMainClassNames( $sClassName );
251
252 foreach($aMainClassNames as $sTempModuleDirectory)
253 {
254 $lookUpPath = LEPTON_PATH."/modules/".$sTempModuleDirectory."/languages/";
255
256 $bFoundFile = false;
257
258 foreach($aLookUpFilenames as $sTempFilename)
259 {
260 if(true === file_exists( $lookUpPath.$sTempFilename ) )
261 {
262 require $lookUpPath.$sTempFilename;
263 $bFoundFile = true;
264 break;
265 }
266 }
267
268 if(false === $bFoundFile)
269 {
270 continue;
271 }
272
273 $tempName = "MOD_".strtoupper($sTempModuleDirectory);
274 if(isset(${$tempName}))
275 {
276 static::$instance->language = ${$tempName};
277 $bExitGraceful = true;
278 break;
279 }
280 }
281
282 if(true === $bExitGraceful)
283 {
284 break;
285 }
286 }
287 }
288 }
289 }
290
297 public function getHeadInfo(): array
298 {
299 return array(
300 "title" => "",
301 "description" => "",
302 "keywords" => ""
303 );
304 }
305
310 protected function getMainClassNames( $sAnyClassname )
311 {
312 $aElements = explode("_", $sAnyClassname);
313
314 $sTempName = array_shift($aElements);
315
316 $aReturnValue = array( $sTempName );
317
318 foreach($aElements as $term)
319 {
320 $sTempName .= "_".$term;
321 $aReturnValue[] = $sTempName;
322 }
323
324 if( 1 < count($aReturnValue) )
325 {
326 $aReturnValue = array_reverse( $aReturnValue );
327 }
328
329 return $aReturnValue;
330 }
331
347 public static function saveLastEditSection(int $iSectionID = 0): void
348 {
349 if ($iSectionID === 0)
350 {
351 if (true === isset($GLOBALS['section_id']))
352 {
353 $_SESSION['last_edit_section'] = $GLOBALS['section_id'];
354 }
355 } else {
356 $_SESSION['last_edit_section'] = $iSectionID;
357 }
358 }
359
360 public static function getConstants(): array
361 {
362 // "static::class" here does the magic
363 $reflectionClass = new \ReflectionClass(static::class);
364 return $reflectionClass->getConstants();
365 }
366
370 abstract protected function initialize();
371
380 public function showmodinfo(array $modvalues = [],bool $bPrompt = true )
381 {
382 // create a default data set
383 $showmodinfo = array(
384 /* the leptoken */
385 'leptoken' => get_leptoken() // $leptoken
386 /* this object including translations (THIS->language[ code ]) */
387 ,"THIS" => $this
388 /* the color to be used for frames */
389 ,"COLOR" => ( $this->module_function == "page" ? "olive" : "blue" )
390 /* the header title to be shown */
391 ,"HEADER" => $this->module_name
392 /* the module description to be shown */
393 ,"DESCRIPTION" => ( isset( $this->module_description ) ? $this->module_description : "" )
394 /* the full url to the image to be shown */
395 ,"IMAGE_URL" => LEPTON_URL."/modules/".$this->module_directory. "/icon.png"
396 /* array of buttons to be shown (or not) and how */
397 ,"BUTTONS" => array(
398 /*
399 * Listed below are the 4 default buttons, but additional buttons can be added in $modvalues
400 *
401 * Supported attributes:
402 * AVAILABLE => true (show active), false (show as no) or hide (do not show, default if not available or empty);
403 * URL => url for support details/contact (required when AVAILABLE => true, otherwise not used)
404 * TITLE => title to be shown for support button if not default
405 * ICON => icon to be shown if not hide
406 */
407 "LIVE_SUPPORT" => array( "AVAILABLE" => false
408 ,"URL" => ""
409 ,"TITLE" => ""
410 ,"ICON" => "call square"
411 )
412 ,"FORUM_SUPPORT"=> array( "AVAILABLE" => true
413 ,"URL" => "https://forum.lepton-cms.org/viewforum.php?f=14" // LEPTON forum for addons
414 ,"TITLE" => ""
415 ,"ICON" => "align left"
416 )
417 ,"README" => array( "AVAILABLE" => "hide"
418 ,"URL" => ""
419 ,"TITLE" => ""
420 ,"ICON" => "book"
421 )
422 ,"HELP" => array( "AVAILABLE" => "hide"
423 ,"URL" => ""
424 ,"TITLE" => ""
425 ,"ICON" => "question"
426 )
427 )
428 /* the data to be shown in sequence added. Also, spacers with unique key can be added.
429 * values can also be a link
430 * empty values are not shown
431 * also spacers can be added, but key must be unique
432 */
433 ,"INFO" => array()
434 );
435 if ( isset( $this->module_version ) && empty( $this->module_version ) === false )
436 { $showmodinfo[ "INFO" ][ "module_version" ] = $this->module_version; }
437 if ( isset( $this->module_platform ) && empty( $this->module_platform ) === false )
438 { $showmodinfo[ "INFO" ][ "module_platform" ] = $this->module_platform; }
439 if ( isset( $this->module_guid ) && empty( $this->module_guid ) === false )
440 { $showmodinfo[ "INFO" ][ "module_guid" ] = $this->module_guid; }
441 if ( isset( $this->module_author ) && empty( $this->module_author ) === false )
442 { $showmodinfo[ "INFO" ][ "module_author" ] = $this->module_author; }
443 if ( isset( $this->module_license ) && empty( $this->module_license ) === false )
444 {
445 $showmodinfo[ "INFO" ][ "S1" ] = "spacer2";
446 $showmodinfo[ "INFO" ][ "module_license" ] = $this->module_license;
447 if ( isset( $this->module_license_terms ) && empty( $this->module_license_terms ) === false )
448 {
449 $showmodinfo[ "INFO" ][ "module_license" ] .= "<br />" . $this->module_license_terms;
450 }
451 }
452 if ( isset( $this->module_home ) && empty( $this->module_home ) === false )
453 {
454 $showmodinfo[ "INFO" ][ "S2" ] = "spacer2";
455 if ( strpos ( $this->module_home , "href" ) == 0 )
456 {
457 $showmodinfo[ "INFO" ][ "module_home" ] = "<a href='".$this->module_home."' >".$this->module_home."</a>";
458 }
459 else
460 {
461 $showmodinfo[ "INFO" ][ "module_home" ] = $this->module_home;
462 }
463 }
464 // additional info values are normally not shown or are already used explicitly
465
466 // [1] load input params if available and merge with the default data set
467 if ( ( is_null( $modvalues ) === false ) // ist gesetzt
468 && ( is_array( $modvalues ) === true ) // ist ein array
469 && ( !empty( $modvalues ) ) // ist NICHT leer
470 )
471 {
472 $showmodinfo = array_replace_recursive( $showmodinfo, $modvalues );
473 }
474
475 // prepare needed libraries
476 $oTWIG = lib_twig_box::getInstance();
477
478 // create & render twig template engine
479 $sSource = $oTWIG->render(
480 "@theme/showmodinfo.lte"
481 ,$showmodinfo
482 );
483
484 if( true === $bPrompt )
485 {
486 echo $sSource;
487
488 return true;
489 } else {
490 return $sSource;
491 }
492 }
493
494
503 public function getEditorSettings()
504 {
505 // [1] base class name
506 $sBaseClassName = $this->parents[0];
507
508 // [2] custom class?
509 $sCustom = (class_exists( $sBaseClassName."_settings_custom", true)) ? "_custom" : "";
510 // [2.1] class exists?
511 if(class_exists($sBaseClassName."_settings".$sCustom, true))
512 {
513 // [2.2] try to get instance of the class
514 return eval("return ".$sBaseClassName."_settings".$sCustom."::getInstance();");
515 }
516 else
517 {
518 // [2.3] class not exists - return NULL
519 return NULL;
520 }
521 }
522
534 public function getAdditionalClass( string $basename="settings", string $classname="") : mixed
535 {
536 // [1] Basename
537 if($classname === "")
538 {
539 $classname = $this->parents[0];
540 }
541
542 // [2] Custom?
543 $custom = (class_exists($classname."_".$basename."_custom", true)) ? "_custom" : "";
544
545 // [3] class exists?
546 if( class_exists( $classname."_".$basename.$custom, true))
547 {
548 return eval("return ".$classname."_".$basename.$custom."::getInstance();");
549 }
550 else
551 {
552 return NULL;
553 }
554 }
555}
getAdditionalClass(string $basename="settings", string $classname="")
static getInstance(mixed $value=null)
static saveLastEditSection(int $iSectionID=0)
getMainClassNames( $sAnyClassname)
showmodinfo(array $modvalues=[], bool $bPrompt=true)