PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 1.0.5
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v1.0.5
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
← All changes | src/blocks/latest-posts-list/index.php +67 -158 1.3.51.0.5 View file →
@@ -1,19 +1,10 @@
1 1 <?php
2 2
3 3 function blockspare_blocks_render_block_core_latest_posts_list($attributes)
4 4 {
5 -
6 - $unq_class = mt_rand(100000,999999);
7 - $blockuniqueclass = '';
8 -
9 - if(!empty($attributes['uniqueClass'])){
10 - $blockuniqueclass = $attributes['uniqueClass'];
11 - }else{
12 - $blockuniqueclass = 'blockspare-list-'.$unq_class;
13 - }
14 -
15 5
6 +
16 7 $categories = isset($attributes['categories']) ? $attributes['categories'] : '';
17 8
18 9 /* Setup the query */
19 10 $grid_query = new WP_Query(
@@ -41,17 +32,11 @@
41 32 $post_id = get_the_ID();
42 33
43 34 /* Setup the featured image ID */
44 35 $post_thumb_id = get_post_thumbnail_id($post_id);
45 -
46 - $has_img_class = '';
47 -
48 - if(!$post_thumb_id){
49 - $has_img_class = "post-has-no-image";
50 - }
51 36
52 37 /* Setup the post classes */
53 - $post_classes = 'blockspare-post-single ';
38 + $post_classes = 'blockspare-post-single';
54 39
55 40 /* Add sticky class */
56 41 if (is_sticky($post_id)) {
57 42 $post_classes .= ' sticky';
@@ -59,24 +44,37 @@
59 44 $post_classes .= null;
60 45 }
61 46
62 47 /* Join classes together */
63 - //$post_classes = join(' ', get_post_class($post_classes, $post_id));
48 + $post_classes = join(' ', get_post_class($post_classes, $post_id));
64 49
65 50
66 51 if ($attributes['enableBackgroundColor']) {
67 52 $post_classes .= 'has-background';
68 53 }
69 -
70 -
71 54
55 +
56 + $item_background_color = ($attributes['enableBackgroundColor']) ? esc_attr($attributes['backGroundColor']) : '';
57 +
58 + $bxshadow = 'none';
59 +
60 + if ($attributes['enableBoxShadow']) {
61 + $bxshadow = $attributes['xOffset'] . "px " . $attributes['yOffset'] . "px " . $attributes['blur'] . "px " . $attributes['spread'] . "px " . $attributes['shadowColor'];
62 + }
63 +
64 + $item_style = '';
65 + if ($attributes['design'] != 'blockspare-list-layout-4' && $attributes['design'] != 'blockspare-list-layout-5' && $attributes['design'] != 'blockspare-list-layout-6') {
66 + $item_style .= 'background-color:' . esc_attr($item_background_color) . ';';
67 + $item_style .= ' border-radius:' . esc_attr($attributes['borderRadius']) . "px;";
68 + $item_style .= ' box-shadow:' . esc_attr($bxshadow) . ';';
69 + }
70 +
72 71 /* Start the markup for the post */
73 72 $blockspare_content_markup .= sprintf(
74 - '<div id="post-%1$s" class="%2$s %3$s">',
73 + '<article id="post-%1$s" class="%2$s" style="%3$s">',
75 74 esc_attr($post_id),
76 75 esc_attr($post_classes),
77 - $has_img_class
78 -
76 + $item_style
79 77
80 78 );
81 79
82 80 /* Get the featured image */
@@ -110,11 +108,11 @@
110 108 '<header class="blockspare-block-post-grid-header">'
111 109 );
112 110 if ($attributes['displayPostCategory']) {
113 111 $blockspare_content_markup .= sprintf(
114 - '<div class="blockspare-post-category" >%1$s</div>',
115 - get_the_category_list(esc_html__(' ', 'blockspare'), '', $post_id)
116 -
112 + '<div class="blockspare-post-category" style="color:%2$s;">%1$s</div>',
113 + get_the_category_list(esc_html__(' ', 'blockspare'), '', $post_id),
114 + esc_attr($attributes['linkColor'])
117 115 );
118 116 }
119 117
120 118
@@ -133,12 +131,14 @@
133 131 $post_title_tag = 'h4';
134 132 }
135 133
136 134 $blockspare_content_markup .= sprintf(
137 - '<%3$s class="blockspare-block-post-grid-title"><a href="%1$s" class="blockspare-title-link" rel="bookmark"><span>%2$s</span></a></%3$s>',
135 + '<%3$s class="blockspare-block-post-grid-title" style="font-size: %5$s;"><a style="color:%4$s;" href="%1$s" rel="bookmark">%2$s</a></%3$s>',
138 136 esc_url(get_permalink($post_id)),
139 137 esc_html($title),
140 - esc_attr($post_title_tag)
138 + esc_attr($post_title_tag),
139 + esc_attr($attributes['postTitleColor']),
140 + esc_attr($attributes['postTitleFontSize']) . 'px'
141 141 );
142 142 }
143 143
144 144 if (isset($attributes['postType']) && ($attributes['postType'] === 'post') && (isset($attributes['displayPostAuthor']) || isset($attributes['displayPostDate']))) {
@@ -149,12 +149,12 @@
149 149
150 150 /* Get the post author */
151 151 if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor']) {
152 152 $blockspare_content_markup .= sprintf(
153 - '<div class="blockspare-block-post-grid-author"><a class="blockspare-text-link" href="%2$s" itemprop="url" rel="author"><span itemprop="name">%1$s</span></a></div>',
153 + '<div class="blockspare-block-post-grid-author"><a style="color:%3$s;" class="blockspare-text-link" href="%2$s" itemprop="url" rel="author"><span itemprop="name">%1$s</span></a></div>',
154 154 esc_html(get_the_author_meta('display_name', get_the_author_meta('ID'))),
155 - esc_url(get_author_posts_url(get_the_author_meta('ID')))
156 -
155 + esc_url(get_author_posts_url(get_the_author_meta('ID'))),
156 + esc_attr($attributes['linkColor'])
157 157 );
158 158 }
159 159
160 160 /* Get the post date */
@@ -159,12 +159,12 @@
159 159
160 160 /* Get the post date */
161 161 if (isset($attributes['displayPostDate']) && $attributes['displayPostDate']) {
162 162 $blockspare_content_markup .= sprintf(
163 - '<time " datetime="%1$s" class="blockspare-block-post-grid-date" itemprop="datePublished">%2$s</time>',
163 + '<time style="color: %3$s" " datetime="%1$s" class="blockspare-block-post-grid-date" itemprop="datePublished">%2$s</time>',
164 164 esc_attr(get_the_date('c', $post_id)),
165 - esc_html(get_the_date('', $post_id))
166 -
165 + esc_html(get_the_date('', $post_id)),
166 + esc_attr($attributes['generalColor'])
167 167 );
168 168 }
169 169
170 170 /* Close the byline content */
@@ -179,65 +179,43 @@
179 179 );
180 180
181 181 /* Wrap the excerpt content */
182 182 $blockspare_content_markup .= sprintf(
183 - '<div class="blockspare-block-post-grid-excerpt">'
184 -
183 + '<div class="blockspare-block-post-grid-excerpt" style="color: %1$s">',
184 + esc_attr($attributes['generalColor'])
185 185
186 186 );
187 187
188 188 /* Get the excerpt */
189 -
190 - $post_id = get_the_ID();
191 -
192 - $excerpt = apply_filters('the_excerpt',
193 - get_post_field(
194 - 'post_excerpt',
195 - $post_id,
196 - 'display'
197 - )
198 - );
199 -
200 - if(empty($excerpt) && isset($attributes['excerptLength'])) {
201 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket -- Running the_excerpt directly, Previous rule doesn't take without the_excerpt being moved up a line
202 - $excerpt = apply_filters('the_excerpt',
203 - wp_trim_words(
204 - preg_replace(
205 - array(
206 - '/\<figcaption>.*\<\/figcaption>/',
207 - '/\[caption.*\[\/caption\]/',
208 - ),
209 - '',
210 - get_the_content()
211 - ),
212 - $attributes['excerptLength']
213 - )
214 - );
189 +
190 + global $post;
191 +
192 +
193 + $excerpt = blockspare_post_excerpt($post_id, $post);
194 +
195 + if (!$excerpt) {
196 + $excerpt = null;
215 197 }
216 -
217 - // Trim the excerpt if necessary.
218 - if ( isset( $attributes['excerptLength'] ) ) {
219 - $excerpt = wp_trim_words(
220 - $excerpt,
221 - $attributes['excerptLength']
222 - );
198 +
199 + if (!empty($excerpt)) {
200 + $excerpt = explode(' ', $excerpt);
201 + $trim_to_length = (int)$attributes['excerptLength'] ? (int)$attributes['excerptLength'] : 55;
202 + if (count($excerpt) > $trim_to_length) {
203 + $excerpt = implode(' ', array_slice($excerpt, 0, $trim_to_length)) . '...';
204 + } else {
205 + $excerpt = implode(' ', $excerpt);
206 + }
207 +
223 208 }
224 -
225 - $excerpt = apply_filters( 'the_excerpt', $excerpt );
226 -
227 - if(!$excerpt) {
228 - $excerpt = null;
229 - }
230 -
231 -
232 -
209 +
210 +
233 211 if ((isset($attributes['displayPostExcerpt']) && $excerpt != null) || isset($attributes['displayPostLink'])) {
234 212
235 213
236 214 /* Wrap the excerpt content */
237 215 $blockspare_content_markup .= sprintf(
238 - '<div class="blockspare-block-post-grid-excerpt">'
239 -
216 + '<div class="blockspare-block-post-grid-excerpt" style="color: %1$s">',
217 + esc_attr($attributes['generalColor'])
240 218
241 219 );
242 220
243 221 if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt']) {
@@ -249,12 +227,13 @@
249 227
250 228 /* Get the read more link */
251 229 if (isset($attributes['displayPostLink']) && $attributes['displayPostLink']) {
252 230 $blockspare_content_markup .= sprintf(
253 - '<p><a class="blockspare-block-post-grid-more-link blockspare-text-link" href="%1$s" rel="bookmark">%2$s <span class="screen-reader-text">%3$s</span></a></p>',
231 + '<p><a style="color:%4$s;" class="blockspare-block-post-grid-more-link blockspare-text-link" href="%1$s" rel="bookmark">%2$s <span class="screen-reader-text">%3$s</span></a></p>',
254 232 esc_url(get_permalink($post_id)),
255 233 esc_html($attributes['readMoreText']),
256 - esc_html($title)
234 + esc_html($title),
235 + esc_attr($attributes['linkColor'])
257 236 );
258 237 }
259 238
260 239 /* Close the excerpt content */
@@ -267,15 +246,11 @@
267 246 /* Close the text content */
268 247 $blockspare_content_markup .= sprintf(
269 248 '</div>'
270 249 );
271 -
272 - $blockspare_content_markup .= sprintf(
273 - '</div>'
274 - );
275 250
276 251 /* Close the post */
277 - $blockspare_content_markup .= "</div>\n";
252 + $blockspare_content_markup .= "</article>\n";
278 253 }
279 254
280 255 /* Restore original post data */
281 256 wp_reset_postdata();
@@ -295,9 +270,9 @@
295 270
296 271 $list_layout_class = $attributes['design'];
297 272
298 273 /* Layout orientation class */
299 - $grid_class = $blockuniqueclass .' blockspare-latest-post-wrap blockspare-is-list ' . $list_layout_class;
274 + $grid_class = 'blockspare-latest-post-wrap blockspare-is-list ' . $list_layout_class;
300 275
301 276
302 277 /* Post grid section title */
303 278 if (isset($attributes['displaySectionTitle']) && $attributes['displaySectionTitle'] && !empty($attributes['sectionTitle'])) {
@@ -320,85 +295,19 @@
320 295 }
321 296
322 297 /* Output the post markup */
323 298 $block_content = sprintf(
324 - '<%1$s class="%2$s"><div class="%4$s">%5$s</div></%1$s>',
299 + '<%1$s class="%2$s" style="margin-top: %6$s;margin-bottom: %7$s;" ><div class="%4$s">%5$s</div></%1$s>',
325 300 $section_tag,
326 301 esc_attr($class),
327 302 $section_title,
328 303 esc_attr($grid_class),
329 - $blockspare_content_markup
304 + $blockspare_content_markup,
305 + esc_attr($attributes['marginTop']) . 'px',
306 + esc_attr($attributes['marginBottom']) . 'px'
330 307
331 308
332 309 );
333 -
334 - $block_content .= '<style type="text/css">';
335 - $block_content .= ' .' . $blockuniqueclass . '.blockspare-latest-post-wrap{
336 - margin-top:' . $attributes['marginTop'] . 'px;
337 - margin-bottom:' . $attributes['marginBottom'] . 'px;
338 - }';
339 -
340 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-post-category{
341 - color:' . $attributes['linkColor'] . ';
342 - }';
343 -
344 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-block-post-grid-author a span{
345 - color:' . $attributes['linkColor'] . ';
346 - }';
347 -
348 - $block_content .= ' .' . $blockuniqueclass . ' a.blockspare-text-link.blockspare-block-post-grid-more-link{
349 - color:' . $attributes['linkColor'] . ';
350 - }';
351 -
352 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-block-post-grid-title a span{
353 - color: ' . $attributes['postTitleColor'] . ';
354 - font-size: ' . $attributes['postTitleFontSize'] . $attributes['titleFontSizeType'] . ';
355 - font-family: ' . $attributes['titleFontFamily'] . ';
356 - font-weight: ' . $attributes['titleFontWeight'] . ';
357 - }';
358 -
359 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-block-post-grid-date{
360 - color:' . $attributes['generalColor'] . ';
361 - }';
362 -
363 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-block-post-grid-excerpt{
364 - color:' . $attributes['generalColor'] . ';
365 - }';
366 -
367 -
368 -
369 -
370 - if ($attributes['design'] != 'blockspare-list-layout-4' && $attributes['design'] != 'blockspare-list-layout-5' && $attributes['design'] != 'blockspare-list-layout-6') {
371 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-post-single{
372 - border: 1px solid ' . $attributes['borderColor'] . ';
373 - background-color:' . $attributes['backGroundColor'] . ';
374 - border-radius:' . $attributes['borderRadius'] . ';
375 - }';
376 -
377 - }
378 -
379 - if ($attributes['enableBoxShadow']) {
380 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-post-single{
381 - box-shadow = ' . $attributes['xOffset'] . 'px ' . $attributes['yOffset'] . 'px ' . $attributes['blur'] . 'px ' . $attributes['spread'] . 'px ' . $attributes['shadowColor'] . ';
382 - }';
383 - }
384 -
385 -
386 - $block_content .= '@media (max-width: 1025px) { ';
387 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-block-post-grid-title a{
388 - font-size: ' . $attributes['titleFontSizeTablet'] . $attributes['titleFontSizeType'] . ';
389 - }';
390 - $block_content .= '}';
391 -
392 -
393 - $block_content .= '@media (max-width: 768px) { ';
394 - $block_content .= ' .' . $blockuniqueclass . ' .blockspare-block-post-grid-title a{
395 - font-size: ' . $attributes['titleFontSizeMobile'] . $attributes['titleFontSizeType'] . ';
396 - }';
397 - $block_content .= '}';
398 -
399 -
400 - $block_content .= '</style>';
401 310 return $block_content;
402 311 }
403 312 }
404 313