PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.7.8
Post Grid Gutenberg Blocks – PostX v2.7.8
5.0.41 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 All 238 releases
ultimate-post / addons / builder / blocks / Post_View_Count.php

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

364 lines 13.8 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 Post_View_Count {
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
18 /*============================
19 Post View Settings
20 ============================*/
21 'viewLabel' => [
22 'type' => 'boolean',
23 'default' => true,
24 ],
25 'viewIconShow' => [
26 'type' => 'boolean',
27 'default' => true,
28 ],
29 'viewColor' => [
30 'type' => 'string',
31 'default' => '',
32 'style' => [
33 (object)[
34 'selector'=>'{{ULTP}} .ultp-view-count { color:{{viewColor}} }'
35 ],
36 ],
37 ],
38 'viewTypo' => [
39 'type' => 'object',
40 'default' => (object)['openTypography' => 0,'size' => (object)['lg' => '', 'unit' =>'px']],
41 'style' => [
42 (object)[
43 'selector'=>'{{ULTP}} .ultp-view-count > span'
44 ],
45 ],
46 ],
47 'viewCountAlign' => [
48 'type' => 'object',
49 'default' => [],
50 'style' => [
51 (object)[
52 'selector'=>'{{ULTP}} .ultp-block-wrapper { text-align: {{viewCountAlign}};}'
53 ],
54 ],
55 ],
56 /*============================
57 Post View Label Style
58 ============================*/
59
60 'viewLabelText' => [
61 'type' => 'string',
62 'default' => 'View',
63 'style' => [
64 (object)[
65 'depends' => [
66 (object)['key'=>'viewLabel','condition'=>'==','value'=> true],
67 ],
68 ],
69 ],
70 ],
71 "viewLabelAlign" => [
72 "type" => "string",
73 "default" => "after",
74 'style' => [
75 (object)[
76 'depends' => [
77 (object)['key'=>'viewLabelAlign','condition'=>'==','value'=> "before"],
78 (object)['key'=>'viewLabel','condition'=>'==','value'=> true],
79 ],
80 'selector'=>'{{ULTP}} .ultp-view-count .ultp-view-label {order: -1;margin-right: 5px;}'
81 ],
82 (object)[
83 'depends' => [
84 (object)['key'=>'viewLabelAlign','condition'=>'==','value'=> "after"],
85 (object)['key'=>'viewLabel','condition'=>'==','value'=> true],
86 ],
87 'selector'=>'{{ULTP}} .ultp-view-count .ultp-view-label {order: unset; margin-left: 5px;}'
88 ],
89 ],
90 ],
91
92 /*============================
93 Post View Icon Style
94 ============================*/
95 'viewIconColor' => [
96 'type' => 'string',
97 'default' => '#656565',
98 'style' => [
99 (object)[
100 'selector'=>'.ultp-view-count >span{ color:{{viewIconColor}} }'
101 ],
102 ],
103 ],
104 'viewIconStyle' => [
105 'type' => 'string',
106 'default' => 'viewCount1',
107 'style' => [
108 (object)[
109 'depends' => [
110 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
111 ],
112 ],
113 ],
114 ],
115 'iconColor' => [
116 'type' => 'string',
117 'default' => '#656565',
118 'style' => [
119 (object)[
120 'depends' => [
121 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
122 ],
123 'selector'=>'{{ULTP}} .ultp-view-count > svg { fill:{{iconColor}}; stroke:{{iconColor}};} '
124 ],
125 ],
126 ],
127 'viewIconSize' => [
128 'type' => 'object',
129 'default' => (object)['lg' =>'15', 'unit' =>'px'],
130 'style' => [
131 (object)[
132 'depends' => [
133 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
134 ],
135 'selector'=>'{{ULTP}} .ultp-view-count svg{ width:{{viewIconSize}}; height:{{viewIconSize}} }'
136 ],
137 ],
138 ],
139 'viewSpace' => [
140 'type' => 'object',
141 'default' => (object)['lg' =>'8', 'unit' =>'px'],
142 'style' => [
143 (object)[
144 'depends' => [
145 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
146 ],
147 'selector'=>'{{ULTP}} .ultp-view-count > span.ultp-view-count-number { margin-left: {{viewSpace}} }'
148 ],
149 (object)[
150 'depends' => [
151 (object)['key'=>'viewIconShow','condition'=>'==','value'=> true],
152 (object)['key'=>'viewLabelAlign','condition'=>'==','value'=> "before"],
153 ],
154 'selector'=>'{{ULTP}} .ultp-view-count > svg { margin: {{viewSpace}} } {{ULTP}} .ultp-view-count .ultp-view-label {margin: 0px !important;}'
155 ],
156 ],
157 ],
158
159
160
161
162
163 //--------------------------
164 // Advanced Settings
165 //--------------------------
166 'advanceId' => [
167 'type' => 'string',
168 'default' => '',
169 ],
170 'advanceZindex' => [
171 'type' => 'number',
172 'default' => '',
173 'style' => [
174 (object)[
175 'selector' => '{{ULTP}} {z-index:{{advanceZindex}};}'
176 ],
177 ],
178 ],
179 'wrapMargin' => [
180 'type' => 'object',
181 'default' => (object)['lg' =>(object)['top' => '','bottom' => '', 'unit' =>'px']],
182 'style' => [
183 (object)[
184 'selector'=>'{{ULTP}} .ultp-block-wrapper { margin:{{wrapMargin}}; }'
185 ],
186 ],
187 ],
188 'wrapOuterPadding' => [
189 'type' => 'object',
190 'default' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']],
191 'style' => [
192 (object)[
193 'selector'=>'{{ULTP}} .ultp-block-wrapper { padding:{{wrapOuterPadding}}; }'
194 ],
195 ],
196 ],
197 'wrapBg' => [
198 'type' => 'object',
199 'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#f5f5f5'],
200 'style' => [
201 (object)[
202 'selector'=>'{{ULTP}} .ultp-block-wrapper'
203 ],
204 ],
205 ],
206 'wrapBorder' => [
207 'type' => 'object',
208 'default' => (object)['openBorder'=>0, 'width' =>(object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'],
209 'style' => [
210 (object)[
211 'selector'=>'{{ULTP}} .ultp-block-wrapper'
212 ],
213 ],
214 ],
215 'wrapShadow' => [
216 'type' => 'object',
217 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
218 'style' => [
219 (object)[
220 'selector'=>'{{ULTP}} .ultp-block-wrapper'
221 ],
222 ],
223 ],
224 'wrapRadius' => [
225 'type' => 'object',
226 'default' => (object)['lg' =>'', 'unit' =>'px'],
227 'style' => [
228 (object)[
229 'selector'=>'{{ULTP}} .ultp-block-wrapper { border-radius:{{wrapRadius}}; }'
230 ],
231 ],
232 ],
233 'wrapHoverBackground' => [
234 'type' => 'object',
235 'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#037fff'],
236 'style' => [
237 (object)[
238 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
239 ],
240 ],
241 ],
242 'wrapHoverBorder' => [
243 'type' => 'object',
244 'default' => (object)['openBorder'=>0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'],
245 'style' => [
246 (object)[
247 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
248 ],
249 ],
250 ],
251 'wrapHoverRadius' => [
252 'type' => 'object',
253 'default' => (object)['lg' =>'', 'unit' =>'px'],
254 'style' => [
255 (object)[
256 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover { border-radius:{{wrapHoverRadius}}; }'
257 ],
258 ],
259 ],
260 'wrapHoverShadow' => [
261 'type' => 'object',
262 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
263 'style' => [
264 (object)[
265 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
266 ],
267 ],
268 ],
269 'hideExtraLarge' => [
270 'type' => 'boolean',
271 'default' => false,
272 'style' => [
273 (object)[
274 'selector' => '{{ULTP}} {display:none;}'
275 ],
276 ],
277 ],
278 'hideDesktop' => [
279 'type' => 'boolean',
280 'default' => false,
281 'style' => [
282 (object)[
283 'selector' => '{{ULTP}} {display:none;}'
284 ],
285 ],
286 ],
287 'hideTablet' => [
288 'type' => 'boolean',
289 'default' => false,
290 'style' => [
291 (object)[
292 'selector' => '{{ULTP}} {display:none;}'
293 ],
294 ],
295 ],
296 'hideMobile' => [
297 'type' => 'boolean',
298 'default' => false,
299 'style' => [
300 (object)[
301 'selector' => '{{ULTP}} {display:none;}'
302 ],
303 ],
304 ],
305 'advanceCss' => [
306 'type' => 'string',
307 'default' => '',
308 'style' => [
309 (object)[
310 'selector' => '{{ULTP}} {display:none;}'
311 ],
312 ],
313 ],
314 );
315
316 if ($default) {
317 $temp = array();
318 foreach ($attributes as $key => $value) {
319 if (isset($value['default'])) {
320 $temp[$key] = $value['default'];
321 }
322 }
323 return $temp;
324 } else {
325 return $attributes;
326 }
327 }
328
329 public function register() {
330 register_block_type( 'ultimate-post/post-view-count',
331 array(
332 'editor_script' => 'ultp-blocks-editor-script',
333 'editor_style' => 'ultp-blocks-editor-css',
334 'attributes' => $this->get_attributes(),
335 'render_callback' => array($this, 'content')
336 )
337 );
338 }
339
340 public function content($attr, $noAjax) {
341 $block_name = 'post-view-count';
342 $wrapper_before = $wrapper_after = $content = '';
343
344 $count = get_post_meta( get_the_ID(), '__post_views_count', true );
345
346 $wrapper_before .= '<div '.($attr['advanceId']?'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].(isset($attr["className"])?' '.$attr["className"]:'').''.(isset($attr["align"])? ' align' .$attr["align"]:'').'">';
347 $wrapper_before .= '<div class="ultp-block-wrapper">';
348 $content .= '<span class="ultp-view-count">';
349 if ($attr["viewIconShow"] && $attr["viewIconStyle"]) {
350 $content .= ultimate_post()->svg_icon($attr["viewIconStyle"]);
351 }
352 $content .= '<span class="ultp-view-count-number">';
353 $content .= $count ? $count : 0;
354 $content .= '</span>';
355 if ($attr["viewLabel"]) {
356 $content .= '<span class="ultp-view-label"> '.$attr["viewLabelText"].'</span>';
357 }
358 $content .= '</span>';
359 $wrapper_after .= '</div>';
360 $wrapper_after .= '</div>';
361
362 return $wrapper_before.$content.$wrapper_after;
363 }
364 }