These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Modules\Preview; |
||
3 | |||
4 | use Redaxscript\Filesystem; |
||
5 | use Redaxscript\Head; |
||
6 | use Redaxscript\Html; |
||
7 | use Redaxscript\Module; |
||
8 | use function str_replace; |
||
9 | |||
10 | /** |
||
11 | * preview template elements |
||
12 | * |
||
13 | * @since 3.0.0 |
||
14 | * |
||
15 | * @package Redaxscript |
||
16 | * @category Modules |
||
17 | * @author Henry Ruhs |
||
18 | */ |
||
19 | |||
20 | class Preview extends Module\Module |
||
21 | { |
||
22 | /** |
||
23 | * array of the module |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | |||
28 | protected static $_moduleArray = |
||
29 | [ |
||
30 | 'name' => 'Preview', |
||
31 | 'alias' => 'Preview', |
||
32 | 'author' => 'Redaxmedia', |
||
33 | 'description' => 'Preview template elements', |
||
34 | 'version' => '4.0.0' |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * array of the option |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | |||
43 | protected $_optionArray = |
||
44 | [ |
||
45 | 'className' => |
||
46 | [ |
||
47 | 'title' => 'rs-title-preview', |
||
48 | 'box' => 'rs-is-preview' |
||
49 | ] |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * renderStart |
||
54 | * |
||
55 | * @since 4.0.0 |
||
56 | */ |
||
57 | |||
58 | public function renderStart() : void |
||
59 | { |
||
60 | if ($this->_registry->get('firstParameter') === 'module' && $this->_registry->get('secondParameter') === 'preview') |
||
61 | { |
||
62 | $link = Head\Link::getInstance(); |
||
63 | $link |
||
64 | ->init() |
||
65 | ->appendFile( |
||
66 | [ |
||
67 | 'modules/Dialog/dist/styles/dialog.min.css', |
||
68 | 'modules/Preview/dist/styles/preview.min.css' |
||
69 | ]); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * routeHeader |
||
75 | * |
||
76 | * @since 3.3.0 |
||
77 | */ |
||
78 | |||
79 | public function routeHeader() : void |
||
80 | { |
||
81 | if ($this->_registry->get('firstParameter') === 'module' && $this->_registry->get('secondParameter') === 'preview') |
||
82 | { |
||
83 | $this->_registry->set('useTitle', $this->_language->get('preview', '_preview')); |
||
84 | $this->_registry->set('useDescription', $this->_language->get('description', '_preview')); |
||
85 | $this->_registry->set('routerBreak', true); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * routeContent |
||
91 | * |
||
92 | * @since 3.3.0 |
||
93 | */ |
||
94 | |||
95 | public function routeContent() : void |
||
96 | { |
||
97 | if ($this->_registry->get('firstParameter') === 'module' && $this->_registry->get('secondParameter') === 'preview') |
||
98 | { |
||
99 | echo $this->render(); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * render |
||
105 | * |
||
106 | * @since 3.2.0 |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | |||
111 | public function render() : string |
||
112 | { |
||
113 | $output = null; |
||
114 | $partialsFilesystem = new Filesystem\File(); |
||
115 | $partialsFilesystem->init('modules/Preview/partials'); |
||
116 | $thirdParameter = $this->_registry->get('thirdParameter'); |
||
117 | $extension = '.phtml'; |
||
118 | |||
119 | /* collect output */ |
||
120 | |||
121 | if ($thirdParameter) |
||
122 | { |
||
123 | $output = $this->_renderPartial($thirdParameter, $partialsFilesystem->renderFile($thirdParameter . $extension)); |
||
0 ignored issues
–
show
|
|||
124 | } |
||
125 | else |
||
126 | { |
||
127 | foreach ($partialsFilesystem->getSortArray() as $value) |
||
128 | { |
||
129 | $alias = str_replace($extension, '', $value); |
||
130 | $output .= $this->_renderPartial($alias, $partialsFilesystem->renderFile($value)); |
||
131 | } |
||
132 | } |
||
133 | return $output; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * renderPartial |
||
138 | * |
||
139 | * @since 3.2.0 |
||
140 | * |
||
141 | * @param string $alias |
||
142 | * @param string $html |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | |||
147 | protected function _renderPartial(string $alias = null, string $html = null) : string |
||
148 | { |
||
149 | $thirdParameter = $this->_registry->get('thirdParameter'); |
||
150 | $parameterRoute = $this->_registry->get('parameterRoute'); |
||
151 | |||
152 | /* html element */ |
||
153 | |||
154 | $element = new Html\Element(); |
||
155 | $linkElement = $element |
||
156 | ->copy() |
||
157 | ->init('a', |
||
158 | [ |
||
159 | 'href' => $thirdParameter === $alias ? $parameterRoute . 'module/preview#' . $alias : $parameterRoute . 'module/preview/' . $alias |
||
160 | ]) |
||
161 | ->text($thirdParameter === $alias ? $this->_language->get('back') : $alias); |
||
162 | $titleElement = $element |
||
163 | ->copy() |
||
164 | ->init('h2', |
||
165 | [ |
||
166 | 'class' => $this->_optionArray['className']['title'], |
||
167 | 'id' => $alias |
||
168 | ]) |
||
169 | ->html($linkElement); |
||
170 | $boxElement = $element |
||
171 | ->copy() |
||
172 | ->init('div', |
||
173 | [ |
||
174 | 'class' => $this->_optionArray['className']['box'], |
||
175 | ]) |
||
176 | ->html($html); |
||
177 | |||
178 | /* collect output */ |
||
179 | |||
180 | $output = $titleElement . $boxElement; |
||
181 | return $output; |
||
182 | } |
||
183 | } |
||
184 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.