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