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