PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 2.1.2
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v2.1.2
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / src / blocks / latest-posts-list / index.php

index.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites 2.1.2, at src/blocks/latest-posts-list/index.php

409 lines 16.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if(!function_exists('blockspare_render_block_core_latest_posts_list')){
3 function blockspare_render_block_core_latest_posts_list($attributes)
4 {
5
6 ob_start();
7 $unq_class = mt_rand(100000,999999);
8 $blockuniqueclass = '';
9
10 if($attributes['enableTwoColumn']){
11 $design = $attributes['design'].' list-col-2';
12 }else{
13 $design = $attributes['design'].' list-col-1';
14 }
15
16 if(!empty($attributes['uniqueClass'])){
17 $blockuniqueclass = $attributes['uniqueClass'];
18 }else{
19 $blockuniqueclass = 'blockspare-posts-block-list-'.$unq_class;
20 }
21
22 $block_class = 'blockspare-posts-block-is-list';
23 blockspare_query_loop_and_wrapper($attributes,$block_class,$design);
24
25 $data_content = blockspare_post_style_css($blockuniqueclass ,$attributes);
26 $data_content .= ob_get_clean();
27 return $data_content;
28
29 }
30 }
31
32 /**
33 * Registers the post grid block on server
34 */
35 if(!function_exists('blockspare_register_block_core_latest_posts_list')){
36 function blockspare_register_block_core_latest_posts_list()
37 {
38
39 if (!function_exists('register_block_type')) {
40 return;
41 }
42
43
44 ob_start();
45 include BLOCKSPARE_PLUGIN_DIR . 'src/blocks/latest-posts-list/block.json';
46 $metadata = json_decode(ob_get_clean(), true);
47
48
49 /* Block attributes */
50 register_block_type(
51 'blockspare/blockspare-latest-posts-list',
52 array(
53 'attributes' =>$metadata['attributes'],
54 'render_callback' => 'blockspare_render_block_core_latest_posts_list',
55 )
56 );
57 }
58
59 add_action('init', 'blockspare_register_block_core_latest_posts_list');
60 }
61
62
63 /**
64 * Create API fields for additional info
65 */
66 if(!function_exists('blockspare_post_register_rest_fields')){
67 function blockspare_post_register_rest_fields()
68 {
69
70 register_rest_field('post', 'featured_image_urls',
71 array(
72 'get_callback' => 'blockspare_featured_image_urls',
73 'update_callback' => null,
74 'schema' => array(
75 'description' => __('Different sized featured images', 'blockspare'),
76 'type' => 'array',
77 ),
78 )
79 );
80
81 // Excer
82
83 /* Add author info */
84 register_rest_field(
85 'post',
86 'author_info',
87 array(
88 'get_callback' => 'blockspare_get_author_infos',
89 'update_callback' => null,
90 'schema' => null,
91 )
92 );
93
94 /* Add author info */
95 register_rest_field(
96 'post',
97 'category_info',
98 array(
99 'get_callback' => 'blockspare_get_category_infos',
100 'update_callback' => null,
101 'schema' => null,
102 )
103 );
104
105 /* Add author info */
106 register_rest_field(
107 'post',
108 'tag_info',
109 array(
110 'get_callback' => 'blockspare_get_tag_infos',
111 'update_callback' => null,
112 'schema' => null,
113 )
114 );
115
116 register_rest_field(
117 'post',
118 'comment_count',
119 array(
120 'get_callback' => 'blockspare_get_comment_count',
121 'update_callback' => null,
122 'schema' => null,
123 )
124 );
125 }
126
127 add_action('rest_api_init', 'blockspare_post_register_rest_fields');
128 }
129
130
131 /**
132 * Get author info for the rest field
133 *
134 * @param String $object The object type.
135 * @param String $field_name Name of the field to retrieve.
136 * @param String $request The current request object.
137 */
138 if(!function_exists('blockspare_get_author_infos')){
139 function blockspare_get_author_infos($object, $field_name, $request){
140 if(!isset($object['author']))
141 return;
142
143 /* Get the author name */
144 $author_data['display_name'] = get_the_author_meta('display_name', $object['author']);
145
146 /* Get the author link */
147 $author_data['author_link'] = get_author_posts_url($object['author']);
148
149 /* Return the author data */
150 return $author_data;
151 }
152 }
153 if(!function_exists('blockspare_get_category_infos')){
154 function blockspare_get_category_infos($object, $field_name, $request){
155 return get_the_category_list(' ', '', $object['id']);
156
157 }
158 }
159
160 if(!function_exists('blockspare_get_tag_infos')){
161 function blockspare_get_tag_infos($object, $field_name, $request) {
162
163 ob_start();
164 $cate_name = '';
165 if (!empty($object)) {
166 foreach ($object['categories'] as $cat_id) {
167 $cate_name = get_cat_name($cat_id);
168 }
169 }
170 ob_clean();
171 return $cate_name;
172
173 }
174 }
175
176 if(!function_exists('blockspare_get_comment_count')){
177 function blockspare_get_comment_count($object, $field_name, $reques){
178
179 return get_comments_number( $object['id'] );
180
181 }
182 }
183
184 if (!function_exists('blockspare_featured_image_urls')) {
185 /**
186 * Get the different featured image sizes that the blog will use.
187 * Used in the custom REST API endpoint.
188 *
189 * @since 1.7
190 */
191 function blockspare_featured_image_urls($object, $field_name, $request)
192 {
193 return blockspare_featured_image_urls_from_url(!empty($object['featured_media']) ? $object['featured_media'] : '');
194 }
195 }
196
197
198 if (!function_exists('blockspare_featured_image_urls_from_url')) {
199 /**
200 * Get the different featured image sizes that the blog will use.
201 *
202 * @since 2.0
203 */
204 function blockspare_featured_image_urls_from_url($attachment_id)
205 {
206
207 $image = wp_get_attachment_image_src($attachment_id, 'full', false);
208 $sizes = get_intermediate_image_sizes();
209
210 $imageSizes = array(
211 'full' => is_array($image) ? $image : '',
212 );
213
214 foreach ($sizes as $size) {
215 $imageSizes[$size] = is_array($image) ? wp_get_attachment_image_src($attachment_id, $size, false) : '';
216 }
217
218 return $imageSizes;
219 }
220 }
221 if(!function_exists('blockspare_post_style_css')){
222 function blockspare_post_style_css($blockuniqueclass ,$attributes){
223
224
225 $block_content ='';
226 $block_content .= '<style type="text/css">';
227 $block_content .= ' .' . $blockuniqueclass . '.blockspare-posts-block-latest-post-wrap{
228 margin-top:' . $attributes['marginTop'] . 'px;
229 margin-bottom:' . $attributes['marginBottom'] . 'px;
230 }';
231
232 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content{
233 padding-top:' . $attributes['contentPaddingTop'] . 'px;
234 padding-right:' . $attributes['contentPaddingRight'] . 'px;
235 padding-bottom:' . $attributes['contentPaddingBottom'] . 'px;
236 padding-left:' . $attributes['contentPaddingLeft'] . 'px;
237 }';
238
239
240 if ($attributes['categoryLayoutOption'] == 'solid') {
241
242 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-category a{
243 color:' . $attributes['categoryTextColor'] . "!important" . ';
244 background-color:' . $attributes['categoryBackgroundColor'] . "!important" . ';
245 border-radius:' . $attributes['categoryBorderRadius'] . "px" . ';
246 }';
247
248
249 } else if ($attributes['categoryLayoutOption'] == 'border') {
250
251
252 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-category a{
253 color:' . $attributes['categoryTextColor'] . "!important" . ';
254 background-color:' . "transparent" . ';
255 border:' . "1px solid" . $attributes['categoryBorderColor'] . ';
256 border-radius:' . $attributes['categoryBorderRadius'] . "px" . ';
257 border-width:' . $attributes['categoryBorderWidth'] . "px" . ';
258 }';
259
260
261
262 } else {
263 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-category a{
264 color:' . $attributes['categoryTextColor'] . "!important" . ';
265 }';
266 }
267
268
269 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-category{
270 margin-top:' . $attributes['categoryMarginTop'] . 'px' . ';
271 margin-bottom:' . $attributes['categoryMarginBottom'] . 'px' . ';
272 }';
273
274
275 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-byline{
276
277 margin-top:' . $attributes['metaMarginTop'] . 'px' . ';
278 margin-bottom:' . $attributes['metaMarginBottom'] . 'px' . ';
279 }';
280
281
282 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-more-link{
283 margin-top:' . $attributes['moreLinkMarginTop'] . 'px' . ';
284 margin-bottom:' . $attributes['moreLinkMarginBottom'] . 'px' . ';
285 }';
286
287 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
288 color: ' . $attributes['postTitleColor'] . ';
289
290 }';
291
292 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-author a span{
293 color:' . $attributes['linkColor'] . ';
294 }';
295
296
297 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-more-link span{
298 color:' . $attributes['linkColor'] . ';
299 }';
300
301 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-date{
302 color:' . $attributes['generalColor'] . ';
303 }';
304
305 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-excerpt-content,'.' .' . $blockuniqueclass . ' .comment_count{
306 color:' . $attributes['generalColor'] . ';
307
308 }';
309
310
311 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title{
312 margin-top:' . $attributes['titleMarginTop'] . 'px' . ';
313 margin-bottom:' . $attributes['titleMarginBottom'] . 'px' . ';
314 }';
315
316
317 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-excerpt-content{
318 margin-top:' . $attributes['exceprtMarginTop'] . 'px' . ';
319 margin-bottom:' . $attributes['exceprtMarginBottom'] . 'px' . ';
320 }';
321
322 $layoutstyle = explode('-',$attributes['design']);
323 if($layoutstyle[5] >3){
324 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single .blockspare-posts-block-post-img img{
325 border-radius:' . $attributes['borderRadius'] . 'px'.';
326
327 }';
328 if($attributes['enableBoxShadow']){
329 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single .blockspare-posts-block-post-img img{
330 box-shadow: ' . $attributes['xOffset'] . 'px ' . $attributes['yOffset'] . 'px ' . $attributes['blur'] . 'px ' . $attributes['spread'] . 'px ' . $attributes['shadowColor'] . ';
331 }';
332 }
333 }else{
334 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single{
335 border-radius:' . $attributes['borderRadius'] . 'px'.';
336 background-color:'.$attributes['backGroundColor'].'
337 }';
338
339 if($attributes['enableBoxShadow']){
340 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single{
341 box-shadow: ' . $attributes['xOffset'] . 'px ' . $attributes['yOffset'] . 'px ' . $attributes['blur'] . 'px ' . $attributes['spread'] . 'px ' . $attributes['shadowColor'] . ';
342 }';
343 }
344 }
345
346
347 //Title Hover
348
349 if($attributes['titleOnHover']=='lpc-title-hover') {
350 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-title-link:hover span{
351 color: ' . $attributes['titleOnHoverColor'] . ';
352
353 }';
354 }
355
356 if($attributes['titleOnHover']=='lpc-title-border') {
357 $block_content .= ' .' . $blockuniqueclass . ' .lpc-title-border .blockspare-posts-block-post-grid-title .blockspare-posts-block-title-link span:hover{
358 box-shadow: inset 0 -2px 0 0 ' . $attributes['titleOnHoverColor'] . ';
359
360 }';
361 }
362
363
364
365 //Font Settings
366
367
368
369 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
370
371 font-size: ' . $attributes['postTitleFontSize'] . $attributes['titleFontSizeType'] . ';
372
373 '.bscheckFontfamily($attributes['titleFontFamily']).';
374 font-weight: ' . $attributes['titleFontWeight'] . ';
375 }';
376
377 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content {
378 font-size:' . $attributes['descriptionFontSize'] . $attributes['descriptionFontSizeType'] . ';
379
380 '.bscheckFontfamily($attributes['descriptionFontFamily']).';
381 font-weight: ' . $attributes['descriptionFontWeight'] . ';
382 }';
383
384 $block_content .= '@media (max-width: 1025px) { ';
385 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
386 font-size: ' . $attributes['titleFontSizeTablet'] . $attributes['titleFontSizeType'] . ';
387 }';
388 $block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content {
389 font-size:' . $attributes['descriptionFontSizeTablet'].$attributes['descriptionFontSizeType'].'
390 }';
391 $block_content .= '}';
392
393
394 $block_content .= '@media (max-width: 768px) { ';
395 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
396 font-size: ' . $attributes['titleFontSizeMobile'] . $attributes['titleFontSizeType'] . ';
397 }';
398 $block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content {
399 font-size:' . $attributes['descriptionFontSizeMobile'].$attributes['descriptionFontSizeType'].'
400 }';
401 $block_content .= '}';
402
403
404 $block_content .= '</style>';
405 return $block_content;
406 }
407 }
408
409