| 1 |
<?php |
| 2 |
if(!function_exists('blockspare_flash_render_block')){ |
| 3 |
function blockspare_flash_render_block($attributes) |
| 4 |
{ |
| 5 |
ob_start(); |
| 6 |
$unq_class = mt_rand(100000,999999); |
| 7 |
$blockuniqueclass = ''; |
| 8 |
|
| 9 |
if(!empty($attributes['uniqueClass'])){ |
| 10 |
$blockuniqueclass = $attributes['uniqueClass']; |
| 11 |
}else{ |
| 12 |
$blockuniqueclass = 'blockspare-posts-block-list-'.$unq_class; |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
if ( isset( $attributes['categories'] ) && ! empty( $attributes['categories'] ) && is_array( $attributes['categories'] ) ) { |
| 18 |
$categories = array(); |
| 19 |
$i = 1; |
| 20 |
foreach ( $attributes['categories'] as $key => $value ) { |
| 21 |
$categories[] = $value['value']; |
| 22 |
} |
| 23 |
} else { |
| 24 |
$categories = array(); |
| 25 |
} |
| 26 |
|
| 27 |
if ( isset( $attributes['tags'] ) && ! empty( $attributes['tags'] ) && is_array( $attributes['tags'] ) ) { |
| 28 |
$tags = array(); |
| 29 |
$i = 1; |
| 30 |
foreach ( $attributes['tags'] as $key => $value ) { |
| 31 |
$tags[] = $value['value']; |
| 32 |
} |
| 33 |
} else { |
| 34 |
$tags = array(); |
| 35 |
} |
| 36 |
|
| 37 |
/* Setup the query */ |
| 38 |
|
| 39 |
$query_args = array( |
| 40 |
'posts_per_page' => $attributes['postsToShow'], |
| 41 |
'post_status' => 'publish', |
| 42 |
'order' => $attributes['order'], |
| 43 |
'orderby' => $attributes['orderBy'], |
| 44 |
'offset' => $attributes['offset'], |
| 45 |
'post_type' => $attributes['postType'], |
| 46 |
'ignore_sticky_posts' => 1, |
| 47 |
); |
| 48 |
|
| 49 |
if($attributes['taxType'] =='category'){ |
| 50 |
$query_args['category__in'] =$categories; |
| 51 |
|
| 52 |
} |
| 53 |
if($attributes['taxType'] =='post_tag'){ |
| 54 |
$query_args['tag__in'] =$tags; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
if($attributes['taxType'] !='category' && $attributes['taxType'] != 'post_tag'){ |
| 60 |
|
| 61 |
$tax_type = $attributes['taxType']; |
| 62 |
if ( $tax_type ) { |
| 63 |
$query_args['tax_query'][] = array( |
| 64 |
'taxonomy' => ( isset( $tax_type ) ) ? $tax_type : 'category', |
| 65 |
'field' => 'id', |
| 66 |
'terms' => $categories, |
| 67 |
'operator' => 'IN' , |
| 68 |
); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
$grid_query = new WP_Query($query_args); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
$responsivelayoutTab = 1; |
| 77 |
$responsivelayoutMobile = 1; |
| 78 |
$verticals = false; |
| 79 |
|
| 80 |
if($attributes['carouselType']=='vertical'){ |
| 81 |
$verticals = true; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
/* Start the loop */ |
| 90 |
if ($grid_query->have_posts()) { |
| 91 |
$alignclass = blockspare_checkalignment($attributes['align']); |
| 92 |
/* Build the block classes */ |
| 93 |
$class = 'align'.$alignclass; |
| 94 |
|
| 95 |
if (isset($attributes['class'])) { |
| 96 |
$class .= ' ' . $attributes['class']; |
| 97 |
} |
| 98 |
if( $attributes['animation']){ |
| 99 |
$class .= ' blockspare-block-animation ' . $attributes['animation']; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
//$list_layout_class = $attributes['trending']; |
| 106 |
$listgridClass = 'blockspare-posts-block-is-carousel' ; |
| 107 |
|
| 108 |
/* Layout orientation class */ |
| 109 |
$block_post_wrap = $blockuniqueclass . ' blockspare-posts-block-post-wrap'; |
| 110 |
$count = 0; |
| 111 |
$layout_class = 'bs-flash-wrap flash-layout ' . $attributes['layoutStyle']; |
| 112 |
|
| 113 |
$exclusive_posts = 'bs-exclusive-posts'; |
| 114 |
if($attributes['border']){ |
| 115 |
$exclusive_posts .= ' bs-border-enabled bs-' . $attributes['borderStyle']; |
| 116 |
} else { |
| 117 |
$exclusive_posts .= ' bs-border-disabled'; |
| 118 |
} |
| 119 |
$flash_spiner_class = 'bs-spinner '; |
| 120 |
if($attributes['spinnerOption']=='spinner-option-1'){ |
| 121 |
$flash_spiner_class .= $attributes['spinnerStyle']; |
| 122 |
}else{ |
| 123 |
$flash_spiner_class .= $attributes['animationStyle']; |
| 124 |
} |
| 125 |
$spinner_icon = $attributes['spinnerIcon']; |
| 126 |
$marquee_class = 'marquee bs-flash-side ' . $attributes['direction']; |
| 127 |
if($attributes['pauseOnHover']){ |
| 128 |
$marquee_class .= ' pause-on-hover'; |
| 129 |
} |
| 130 |
?> |
| 131 |
|
| 132 |
<div class="<?php echo esc_attr($class);?>"> |
| 133 |
<section class="<?php echo esc_attr($block_post_wrap);?>"> |
| 134 |
<div class="<?php echo esc_attr($layout_class);?>"> |
| 135 |
<div class="<?php echo esc_attr($exclusive_posts);?>"> |
| 136 |
<div class="bs-exclusive-now"> |
| 137 |
<?php if($attributes['exclusiveSubtitle']){?> |
| 138 |
<span class="bs-exclusive-news-title"><?php echo esc_html($attributes['exclusiveSubtitleText']); ?></span> |
| 139 |
<?php }?> |
| 140 |
<div class="bs-exclusive-now-txt-animation-wrap"> |
| 141 |
<?php if($attributes['spinner']){?> |
| 142 |
<span class="<?php echo esc_attr($flash_spiner_class); ?>"> |
| 143 |
<?php if($attributes['spinnerOption'] == 'spinner-option-1') {?> |
| 144 |
<div class="ring"></div> |
| 145 |
<div class="ring"></div> |
| 146 |
<div class="ring"></div> |
| 147 |
<div class="ring"></div> |
| 148 |
<div class="ring"></div> |
| 149 |
<?php } else {?> |
| 150 |
<i class="<?php echo esc_attr($spinner_icon);?>"></i> |
| 151 |
<?php }?> |
| 152 |
</span> |
| 153 |
<?php }?> |
| 154 |
<span class="bs-exclusive-texts-wrapper"> |
| 155 |
<?php echo $attributes['exclusiveText'] != "" ? $attributes['exclusiveText'] : "Breaking News";?> |
| 156 |
</span> |
| 157 |
</div> |
| 158 |
</div> |
| 159 |
<div class="bs-exclusive-slides"> |
| 160 |
<div class="<?php echo esc_attr($marquee_class);?>"> |
| 161 |
<div class="bs-marquee-wrapper"> |
| 162 |
<?php while ($grid_query->have_posts()) { |
| 163 |
$grid_query->the_post(); |
| 164 |
|
| 165 |
$count++; |
| 166 |
|
| 167 |
/* Setup the post ID */ |
| 168 |
$post_id = get_the_ID(); |
| 169 |
|
| 170 |
/* Setup the featured image ID */ |
| 171 |
$post_thumb_id = get_post_thumbnail_id($post_id); |
| 172 |
|
| 173 |
|
| 174 |
/* Setup the post classes */ |
| 175 |
$post_classes = 'bs-post-title '; |
| 176 |
|
| 177 |
?> |
| 178 |
|
| 179 |
<h4 class="<?php echo esc_attr($post_classes) ?>"> |
| 180 |
<?php |
| 181 |
|
| 182 |
if (!empty($attributes['imageSize'])) { |
| 183 |
$post_thumb_size = 'thumbnail '; |
| 184 |
}?> |
| 185 |
<a href="<?php echo esc_url(get_permalink($post_id));?>" rel="bookmark" aria-hidden="true" |
| 186 |
tabindex="-1"> |
| 187 |
<span class="bs-circle-marq"> |
| 188 |
<?php if($attributes['enableCount']){?> |
| 189 |
<span class="bs-trending-no"><?php echo esc_html( $count );?></span> |
| 190 |
<?php }?> |
| 191 |
<?php |
| 192 |
if(has_post_thumbnail($post_id)){ |
| 193 |
echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size)); |
| 194 |
}else{?> |
| 195 |
<div class="bs-no-thumbnail-img"> </div> |
| 196 |
<?php } ?> |
| 197 |
</span> |
| 198 |
<span class="bs-post-title"> |
| 199 |
<?php |
| 200 |
$title = get_the_title($post_id); |
| 201 |
|
| 202 |
if (!$title) { |
| 203 |
$title = __('Untitled', 'blockspare'); |
| 204 |
} |
| 205 |
|
| 206 |
echo esc_html($title); |
| 207 |
?> |
| 208 |
</span> |
| 209 |
</a> |
| 210 |
</h4> |
| 211 |
<?php }?> |
| 212 |
</div> |
| 213 |
</div> |
| 214 |
</div> |
| 215 |
</div> |
| 216 |
</div> |
| 217 |
</section> |
| 218 |
</div> |
| 219 |
<?php wp_reset_postdata(); |
| 220 |
$data_content = latest_posts_style_control_flash($blockuniqueclass ,$attributes); |
| 221 |
$data_content .= ob_get_clean(); |
| 222 |
return $data_content; |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Registers the post grid block on server |
| 229 |
*/ |
| 230 |
if(!function_exists('blockspare_flash_register_block_core')){ |
| 231 |
function blockspare_flash_register_block_core() |
| 232 |
{ |
| 233 |
|
| 234 |
if (!function_exists('register_block_type')) { |
| 235 |
return; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
ob_start(); |
| 240 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/latest-post-block/posts-flash/block.json'; |
| 241 |
|
| 242 |
$metadata = json_decode(ob_get_clean(), true); |
| 243 |
|
| 244 |
|
| 245 |
/* Block attributes */ |
| 246 |
register_block_type( |
| 247 |
'blockspare/latest-posts-flash', |
| 248 |
array( |
| 249 |
'attributes' =>$metadata['attributes'], |
| 250 |
'render_callback' => 'blockspare_flash_render_block', |
| 251 |
) |
| 252 |
); |
| 253 |
} |
| 254 |
|
| 255 |
add_action('init', 'blockspare_flash_register_block_core'); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
if(!function_exists('latest_posts_style_control_flash')){ |
| 262 |
function latest_posts_style_control_flash($blockuniqueclass ,$attributes) |
| 263 |
{ |
| 264 |
|
| 265 |
$boxshadowcss = ''; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
$block_content = ''; |
| 272 |
$block_content .= '<style type="text/css">'; |
| 273 |
|
| 274 |
|
| 275 |
//post-flash-background |
| 276 |
if($attributes['background']) { |
| 277 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts{ |
| 278 |
background-color:' . $attributes['backGroundColor'] . '; |
| 279 |
}'; |
| 280 |
} |
| 281 |
|
| 282 |
//post-flash-border-radius |
| 283 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts, .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-now-txt-animation-wrap, .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides{ |
| 284 |
border-radius:' . $attributes['borderRadius'] . 'px; |
| 285 |
}'; |
| 286 |
|
| 287 |
//post-image-border-radius |
| 288 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides .bs-circle-marq{ |
| 289 |
border-radius:' . $attributes['imgBorderRadius'] . 'px; |
| 290 |
}'; |
| 291 |
|
| 292 |
//post-flash-animation-speed |
| 293 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides .marquee .bs-marquee-wrapper{ |
| 294 |
animation-duration:' . $attributes['animationSpeed'] . 'ms; |
| 295 |
}'; |
| 296 |
|
| 297 |
//Title color |
| 298 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides a .bs-post-title{ |
| 299 |
color:' . $attributes['postTitleColor'] . '; |
| 300 |
}'; |
| 301 |
|
| 302 |
//Title hover color |
| 303 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides a:hover .bs-post-title{ |
| 304 |
color:' . $attributes['titleOnHoverColor'] . '; |
| 305 |
}'; |
| 306 |
|
| 307 |
//Exclusive News color and background |
| 308 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-now .bs-exclusive-now-txt-animation-wrap{ |
| 309 |
color:' . $attributes['newsColor'] . '; |
| 310 |
background-color: ' . $attributes['newsBgColor'] . '; |
| 311 |
}'; |
| 312 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap.flash-style-2 .bs-exclusive-posts .bs-exclusive-now .bs-exclusive-now-txt-animation-wrap::after{ |
| 313 |
border-left-color:' . $attributes['newsBgColor'] . '; |
| 314 |
}'; |
| 315 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap.flash-style-3 .bs-exclusive-posts .bs-exclusive-now .bs-exclusive-now-txt-animation-wrap::after, .bs-flash-wrap.flash-style-4 .bs-exclusive-posts .bs-exclusive-now .bs-exclusive-now-txt-animation-wrap::after{ |
| 316 |
background-color:' . $attributes['newsBgColor'] . '; |
| 317 |
}'; |
| 318 |
|
| 319 |
//Border |
| 320 |
if($attributes['border']) { |
| 321 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts{ |
| 322 |
border-width:' . $attributes['borderWidth'] . 'px; |
| 323 |
border-color:' . $attributes['borderColor'] . '; |
| 324 |
}'; |
| 325 |
} |
| 326 |
|
| 327 |
//Exclusive Subtitle color and background |
| 328 |
if($attributes['exclusiveSubtitle']) { |
| 329 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-now > span{ |
| 330 |
color:' . $attributes['exclusiveColor'] . '; |
| 331 |
background-color: ' . $attributes['exclusiveBgColor'] . '; |
| 332 |
}'; |
| 333 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-now > span::before{ |
| 334 |
border-top-color:' . $attributes['exclusiveBgColor'] . '; |
| 335 |
}'; |
| 336 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-now > span::after{ |
| 337 |
border-bottom-color:' . $attributes['exclusiveBgColor'] . '; |
| 338 |
}'; |
| 339 |
} |
| 340 |
|
| 341 |
//Block Gaps |
| 342 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts{ |
| 343 |
margin-top:' . $attributes['marginTop'] . 'px; |
| 344 |
margin-right:' . $attributes['marginRight'] . 'px; |
| 345 |
margin-bottom:' . $attributes['marginBottom'] . 'px; |
| 346 |
margin-left:' . $attributes['marginLeft'] . 'px; |
| 347 |
padding-top:' . $attributes['paddingTop'] . 'px; |
| 348 |
padding-right:' . $attributes['paddingRight'] . 'px; |
| 349 |
padding-bottom:' . $attributes['paddingBottom'] . 'px; |
| 350 |
padding-left:' . $attributes['paddingLeft'] . 'px; |
| 351 |
}'; |
| 352 |
|
| 353 |
// Post Number Color |
| 354 |
if($attributes['enableCount']){ |
| 355 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides .marquee h4.bs-post-title a .bs-circle-marq .bs-trending-no{ |
| 356 |
color: ' . $attributes['countColor'] . '; |
| 357 |
}'; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
//Font Settings |
| 363 |
|
| 364 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides a .bs-post-title{ |
| 365 |
font-size: ' . $attributes['postTitleFontSize'] . $attributes['titleFontSizeType'] . '; |
| 366 |
'.bscheckFontfamily($attributes['titleFontFamily']).'; |
| 367 |
font-weight: ' . $attributes['titleFontWeight'] . '; |
| 368 |
}'; |
| 369 |
|
| 370 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-now .bs-exclusive-now-txt-animation-wrap .bs-exclusive-texts-wrapper{ |
| 371 |
font-size: ' . $attributes['exclusiveFontSize'] . $attributes['exclusiveFontSizeType'] . '; |
| 372 |
'.bscheckFontfamily($attributes['exclusiveFontFamily']).'; |
| 373 |
font-weight: ' . $attributes['exclusiveFontWeight'] . '; |
| 374 |
}'; |
| 375 |
|
| 376 |
$block_content .= '@media (max-width: 1025px) { '; |
| 377 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides a .bs-post-title{ |
| 378 |
font-size: ' . $attributes['titleFontSizeTablet'] . $attributes['titleFontSizeType'] . '; |
| 379 |
}'; |
| 380 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-now .bs-exclusive-now-txt-animation-wrap .bs-exclusive-texts-wrapper{ |
| 381 |
font-size: ' . $attributes['exclusiveFontSizeTablet'] . $attributes['exclusiveFontSizeType'] . '; |
| 382 |
}'; |
| 383 |
$block_content .= '}'; |
| 384 |
|
| 385 |
$block_content .= '@media (max-width: 767px) { '; |
| 386 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-posts .bs-exclusive-slides a .bs-post-title{ |
| 387 |
font-size: ' . $attributes['titleFontSizeMobile'] . $attributes['titleFontSizeType'] . '; |
| 388 |
}'; |
| 389 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-flash-wrap .bs-exclusive-now .bs-exclusive-now-txt-animation-wrap .bs-exclusive-texts-wrapper{ |
| 390 |
font-size: ' . $attributes['exclusiveFontSizeMobile'] . $attributes['exclusiveFontSizeType'] . '; |
| 391 |
}'; |
| 392 |
$block_content .= '}'; |
| 393 |
|
| 394 |
$block_content .= '</style>'; |
| 395 |
return $block_content; |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
|