1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ffcms\Core\Arch; |
4
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\App as AppRecord; |
6
|
|
|
use Ffcms\Core\App; |
7
|
|
|
use Ffcms\Core\Helper\Type\Obj; |
8
|
|
|
use Ffcms\Core\Helper\Type\Str; |
9
|
|
|
use Ffcms\Core\Interfaces\iWidget; |
10
|
|
|
use Ffcms\Core\Traits\DynamicGlobal; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Widget. Provide constructor to work with widget-type based extensions for ffcms. |
14
|
|
|
* @package Ffcms\Core\Arch |
15
|
|
|
*/ |
16
|
|
|
class Widget implements iWidget |
17
|
|
|
{ |
18
|
|
|
use DynamicGlobal; |
19
|
|
|
|
20
|
|
|
/** @var string|null */ |
21
|
|
|
public static $class; |
22
|
|
|
|
23
|
|
|
public static function widget(array $params = null) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
self::$class = get_called_class(); |
26
|
|
|
|
27
|
|
|
// check if class exist |
28
|
|
|
if (!class_exists(self::$class)) { |
29
|
|
|
return 'Error: Widget is not founded: ' . App::$Security->strip_tags(self::$class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// init class and pass properties |
33
|
|
|
$object = new self::$class; |
34
|
|
|
if (Obj::isArray($params) && count($params) > 0) { |
35
|
|
|
foreach ($params as $property => $value) { |
|
|
|
|
36
|
|
|
if (property_exists($object, $property)) { |
37
|
|
|
$object->$property = $value; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// prepare output |
43
|
|
|
$out = null; |
44
|
|
|
try { |
45
|
|
|
$object->init(); |
46
|
|
|
$out = $object->display(); |
47
|
|
|
} catch (\Exception $e) { |
48
|
|
|
throw $e; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $out; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get widget configs from admin part as array $cfg=>$value |
56
|
|
|
* @return array|null|string |
57
|
|
|
*/ |
58
|
|
|
public function getConfigs() |
59
|
|
|
{ |
60
|
|
|
$realName = Str::lastIn(self::$class, '\\', true); |
61
|
|
|
return AppRecord::getConfigs('widget', $realName); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function display() {} |
65
|
|
|
public function init() {} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Check if widget is enabled. For native widget is always enabled |
69
|
|
|
* @param string $name |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public static function enabled($name) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
} |