PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.7.8
Post Grid Gutenberg Blocks – PostX v2.7.8
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / addons / builder / blocks / Related_Posts.php

Related_Posts.php in Post Grid Gutenberg Blocks – PostX 2.7.8, at addons/builder/blocks/Related_Posts.php

443 lines 15.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 defined('ABSPATH') || exit;
5
6 class Related_Posts {
7 public function __construct() {
8 add_action('init', array($this, 'register'));
9 }
10 public function get_attributes($default = false) {
11
12 $attributes = array(
13 'blockId' => [
14 'type' => 'string',
15 'default' => '',
16 ],
17 'layout' => [
18 'type' => 'string',
19 'default' => '',
20 ],
21 //--------------------------
22 // Related Post Style
23 //--------------------------
24 'checkboxTest' => [
25 'type' => 'string',
26 'default' => '[]',
27 ],
28 'radioImage' => [
29 'type' => 'string',
30 'default' => '',
31 ],
32 'checkbox' => [
33 'type' => 'boolean',
34 'default' => true,
35 ],
36 'relSelectPostType' => [
37 'type' => 'string',
38 'default' => "",
39 ],
40 'relNumberItems' => [
41 'type' => 'object',
42 'default' => (object)['lg' =>'8', 'unit' =>'px'],
43 'style' => [
44 (object)[
45 'depends' => [
46 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
47 ],
48 'selector'=>'{{ULTP}} .ultp-view-count > span{ margin-left: {{viewSpace}} }'
49 ],
50 ],
51 ],
52 'relOrderBy' => [
53 'type' => 'string',
54 'default' => '',
55 ],
56 'relPastPost' => [
57 'type' => 'number',
58 'default' => '',
59 ],
60 'viewIconStyle' => [
61 'type' => 'string',
62 'default' => '',
63 ],
64 'disCurrentPost' => [
65 'type' => 'boolean',
66 'default' => true,
67 ],
68 'disPastPost' => [
69 'type' => 'boolean',
70 'default' => true,
71 ],
72 'relExcludeCat' => [
73 'type' => 'string',
74 'default' => ''
75 ],
76 'relExcludeTag' => [
77 'type' => 'string',
78 'default' => '',
79 ],
80 'relExcludePost' => [
81 'type' => 'string',
82 'default' => '',
83 ],
84 'enAutoScroll' => [
85 'type' => 'boolean',
86 'default' => true,
87 ],
88 'relColumns' => [
89 'type' => 'object',
90 'default' => (object)['lg' =>'8', 'unit' =>'px'],
91 'style' => [
92 (object)[
93 'depends' => [
94 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
95 ],
96 'selector'=>'{{ULTP}} { margin-left: {{viewSpace}} }'
97 ],
98 ],
99 ],
100 'relRowGap' => [
101 'type' => 'object',
102 'default' => (object)['lg' =>'8', 'unit' =>'px'],
103 'style' => [
104 (object)[
105 'selector'=>'{{ULTP}} { margin-left: {{viewSpace}} }'
106 ],
107 ],
108 ],
109 'relColumnsGap' => [
110 'type' => 'object',
111 'default' => (object)['lg' =>'8', 'unit' =>'px'],
112 'style' => [
113 (object)[
114 'selector'=>'{{ULTP}} { margin-left: {{viewSpace}} }'
115 ],
116 ],
117 ],
118 'relHeading' => [
119 'type' => 'boolean',
120 'default' => true,
121 ],
122 'relExcerpt' => [
123 'type' => 'boolean',
124 'default' => true,
125 ],
126 'relTitle' => [
127 'type' => 'boolean',
128 'default' => true,
129 ],
130 'relCategory' => [
131 'type' => 'boolean',
132 'default' => true,
133 ],
134 'relMeta' => [
135 'type' => 'boolean',
136 'default' => true,
137 ],
138 'relImage' => [
139 'type' => 'boolean',
140 'default' => true,
141 ],
142 'relAlign' => [
143 'type' => 'object',
144 'default' => '',
145 ],
146
147 //--------------------------
148 // Post View Style
149 //--------------------------
150 'viewTypo' => [
151 'type' => 'object',
152 'default' => (object)['openTypography' => 1,'size' => (object)['lg' =>14, 'unit' =>'px'],'height' => (object)['lg' =>20, 'unit' =>'px']],
153 'style' => [
154 (object)[
155 'selector'=>'{{ULTP}} .ultp-view-count > span'
156 ],
157 ],
158 ],
159 'viewIconColor' => [
160 'type' => 'string',
161 'default' => '#656565',
162 'style' => [
163 (object)[
164 'selector'=>'.ultp-view-count >span{ color:{{viewIconColor}} }'
165 ],
166 ],
167 ],
168 'viewIconShow' => [
169 'type' => 'boolean',
170 'default' => true,
171 ],
172 'viewIconStyle' => [
173 'type' => 'string',
174 'default' => 'viewCount1',
175 'style' => [
176 (object)[
177 'depends' => [
178 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
179 ],
180 ],
181 ],
182 ],
183 'iconColor' => [
184 'type' => 'string',
185 'default' => '#656565',
186 'style' => [
187 (object)[
188 'depends' => [
189 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
190 ],
191 'selector'=>'{{ULTP}} .ultp-view-count > svg { fill:{{iconColor}}; stroke:{{iconColor}};} '
192 ],
193 ],
194 ],
195 'viewIconSize' => [
196 'type' => 'object',
197 'default' => (object)['lg' =>'15', 'unit' =>'px'],
198 'style' => [
199 (object)[
200 'depends' => [
201 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
202 ],
203 'selector'=>'{{ULTP}} .ultp-view-count svg{ width:{{viewIconSize}}; height:{{viewIconSize}} }'
204 ],
205 ],
206 ],
207 'viewCountAlign' => [
208 'type' => 'object',
209 'default' => ['lg' => 'left'],
210 'style' => [
211 (object)[
212 'selector'=>'{{ULTP}} .ultp-block-wrapper { text-align: {{viewCountAlign}};}'
213 ],
214 ],
215 ],
216 'viewSpace' => [
217 'type' => 'object',
218 'default' => (object)['lg' =>'8', 'unit' =>'px'],
219 'style' => [
220 (object)[
221 'depends' => [
222 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
223 ],
224 'selector'=>'{{ULTP}} .ultp-view-count { margin-left: {{viewSpace}} }'
225 ],
226 ],
227 ],
228 'viewColor' => [
229 'type' => 'string',
230 'default' => '',
231 'style' => [
232 (object)[
233 'selector'=>'{{ULTP}} .ultp-view-count { color:{{viewColor}} }'
234 ],
235 ],
236 ],
237 'viewLabel' => [
238 'type' => 'boolean',
239 'default' => false,
240 ],
241 'viewLabelText' => [
242 'type' => 'string',
243 'default' => 'View',
244 'style' => [
245 (object)[
246 'depends' => [
247 (object)['key'=>'viewLabel','condition'=>'==','value'=> true],
248 ],
249 ],
250 ],
251 ],
252
253
254 //--------------------------
255 // Advanced Settings
256 //--------------------------
257 'advanceId' => [
258 'type' => 'string',
259 'default' => '',
260 ],
261 'advanceZindex' => [
262 'type' => 'number',
263 'default' => '',
264 'style' => [
265 (object)[
266 'selector' => '{{ULTP}} {z-index:{{advanceZindex}};}'
267 ],
268 ],
269 ],
270 'wrapMargin' => [
271 'type' => 'object',
272 'default' => (object)['lg' =>(object)['top' => '','bottom' => '', 'unit' =>'px']],
273 'style' => [
274 (object)[
275 'selector'=>'{{ULTP}} .ultp-block-wrapper { margin:{{wrapMargin}}; }'
276 ],
277 ],
278 ],
279 'wrapOuterPadding' => [
280 'type' => 'object',
281 'default' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']],
282 'style' => [
283 (object)[
284 'selector'=>'{{ULTP}} .ultp-block-wrapper { padding:{{wrapOuterPadding}}; }'
285 ],
286 ],
287 ],
288 'wrapBg' => [
289 'type' => 'object',
290 'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#f5f5f5'],
291 'style' => [
292 (object)[
293 'selector'=>'{{ULTP}} .ultp-block-wrapper'
294 ],
295 ],
296 ],
297 'wrapBorder' => [
298 'type' => 'object',
299 'default' => (object)['openBorder'=>0, 'width' =>(object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'],
300 'style' => [
301 (object)[
302 'selector'=>'{{ULTP}} .ultp-block-wrapper'
303 ],
304 ],
305 ],
306 'wrapShadow' => [
307 'type' => 'object',
308 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
309 'style' => [
310 (object)[
311 'selector'=>'{{ULTP}} .ultp-block-wrapper'
312 ],
313 ],
314 ],
315 'wrapRadius' => [
316 'type' => 'object',
317 'default' => (object)['lg' =>'', 'unit' =>'px'],
318 'style' => [
319 (object)[
320 'selector'=>'{{ULTP}} .ultp-block-wrapper { border-radius:{{wrapRadius}}; }'
321 ],
322 ],
323 ],
324 'wrapHoverBackground' => [
325 'type' => 'object',
326 'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#037fff'],
327 'style' => [
328 (object)[
329 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
330 ],
331 ],
332 ],
333 'wrapHoverBorder' => [
334 'type' => 'object',
335 'default' => (object)['openBorder'=>0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'],
336 'style' => [
337 (object)[
338 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
339 ],
340 ],
341 ],
342 'wrapHoverRadius' => [
343 'type' => 'object',
344 'default' => (object)['lg' =>'', 'unit' =>'px'],
345 'style' => [
346 (object)[
347 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover { border-radius:{{wrapHoverRadius}}; }'
348 ],
349 ],
350 ],
351 'wrapHoverShadow' => [
352 'type' => 'object',
353 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
354 'style' => [
355 (object)[
356 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
357 ],
358 ],
359 ],
360 'hideExtraLarge' => [
361 'type' => 'boolean',
362 'default' => false,
363 'style' => [
364 (object)[
365 'selector' => '{{ULTP}} {display:none;}'
366 ],
367 ],
368 ],
369 'hideDesktop' => [
370 'type' => 'boolean',
371 'default' => false,
372 'style' => [
373 (object)[
374 'selector' => '{{ULTP}} {display:none;}'
375 ],
376 ],
377 ],
378 'hideTablet' => [
379 'type' => 'boolean',
380 'default' => false,
381 'style' => [
382 (object)[
383 'selector' => '{{ULTP}} {display:none;}'
384 ],
385 ],
386 ],
387 'hideMobile' => [
388 'type' => 'boolean',
389 'default' => false,
390 'style' => [
391 (object)[
392 'selector' => '{{ULTP}} {display:none;}'
393 ],
394 ],
395 ],
396 'advanceCss' => [
397 'type' => 'string',
398 'default' => '',
399 'style' => [
400 (object)[
401 'selector' => '{{ULTP}} {display:none;}'
402 ],
403 ],
404 ],
405 );
406
407 if ($default) {
408 $temp = array();
409 foreach ($attributes as $key => $value) {
410 if (isset($value['default'])) {
411 $temp[$key] = $value['default'];
412 }
413 }
414 return $temp;
415 } else {
416 return $attributes;
417 }
418 }
419
420 public function register() {
421 register_block_type( 'ultimate-post/related-posts',
422 array(
423 'editor_script' => 'ultp-blocks-editor-script',
424 'editor_style' => 'ultp-blocks-editor-css',
425 'attributes' => $this->get_attributes(),
426 'render_callback' => array($this, 'content')
427 )
428 );
429 }
430
431 public function content($attr, $noAjax) {
432 $block_name = 'related Posts';
433 $wrapper_before = $wrapper_after = $wrapper_content = $attachment_title = '';
434
435 $wrapper_before .= '<div '.($attr['advanceId']?'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].(isset($attr["className"])?' '.$attr["className"]:'').'">';
436 $wrapper_before .= '<div class="ultp-block-wrapper">';
437 $wrapper_content .= $attr['checkbox'];
438 $wrapper_after .= '</div>';
439 $wrapper_after .= '</div>';
440
441 return $wrapper_before.$wrapper_content.$wrapper_after;
442 }
443 }