| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Post_Grid_1{ |
| 7 |
public function __construct() { |
| 8 |
add_action('init', array($this, 'register')); |
| 9 |
} |
| 10 |
public function get_attributes() { |
| 11 |
|
| 12 |
return array( |
| 13 |
'blockId' => '', |
| 14 |
'previewImg' => '', |
| 15 |
/*============================ |
| 16 |
Layout |
| 17 |
============================*/ |
| 18 |
'layout' => 'layout1', |
| 19 |
/*============================ |
| 20 |
Query Setting |
| 21 |
============================*/ |
| 22 |
'queryQuick' => '', |
| 23 |
'queryNumPosts' => (object)['lg'=>4], |
| 24 |
'queryNumber' => 4, |
| 25 |
'queryType' => 'post', |
| 26 |
'queryTax' => 'category', |
| 27 |
'queryTaxValue' => '[]', |
| 28 |
'queryRelation' => 'OR', |
| 29 |
'queryOrderBy' => 'date', |
| 30 |
'metaKey' => 'custom_meta_key', |
| 31 |
'queryOrder' => 'desc', |
| 32 |
// Include Remove from Version 2.5.4 |
| 33 |
'queryInclude' => '', |
| 34 |
'queryExclude' => '[]', |
| 35 |
'queryAuthor' => '[]', |
| 36 |
'queryOffset' => '0', |
| 37 |
'queryExcludeTerm' => '[]', |
| 38 |
'queryExcludeAuthor' => '[]', |
| 39 |
'querySticky' => true, |
| 40 |
'queryUnique' => '', |
| 41 |
'queryPosts' => '[]', |
| 42 |
'queryCustomPosts' => '[]', |
| 43 |
/*============================ |
| 44 |
General Setting |
| 45 |
============================*/ |
| 46 |
'gridStyle' => 'style1', |
| 47 |
'columns' => (object)['lg' =>'2'], |
| 48 |
'titleShow' => true, |
| 49 |
'titleStyle' => 'none', |
| 50 |
'headingShow' => true, |
| 51 |
'excerptShow' => true, |
| 52 |
'catShow' => true, |
| 53 |
'metaShow' => true, |
| 54 |
'showImage' => true, |
| 55 |
'filterShow' => false, |
| 56 |
'paginationShow' => true, |
| 57 |
'readMore' => false, |
| 58 |
'equalHeight' => true, |
| 59 |
'contentTag' => 'div', |
| 60 |
'openInTab' => false, |
| 61 |
'notFoundMessage' => 'No Post Found', |
| 62 |
|
| 63 |
/*============================ |
| 64 |
Heading Setting/Style |
| 65 |
============================*/ |
| 66 |
'headingText' => 'Post Grid #1', |
| 67 |
'headingURL' => '', |
| 68 |
'headingBtnText' => 'View More', |
| 69 |
'headingStyle' => 'style9', |
| 70 |
'headingTag' => 'h2', |
| 71 |
'headingAlign' => 'left', |
| 72 |
'subHeadingShow' => false, |
| 73 |
'subHeadingText' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut sem augue. Sed at felis ut enim dignissim sodales.', |
| 74 |
|
| 75 |
/*============================ |
| 76 |
Title Setting/Style |
| 77 |
============================*/ |
| 78 |
'titleTag' => 'h3', |
| 79 |
'titlePosition' => true, |
| 80 |
'titleLength' => 0, |
| 81 |
|
| 82 |
/*============================ |
| 83 |
Content Setting/Style |
| 84 |
============================*/ |
| 85 |
'showSeoMeta' => false, |
| 86 |
'showFullExcerpt' => false, |
| 87 |
'excerptLimit' => 30, |
| 88 |
|
| 89 |
/*============================ |
| 90 |
Category Setting/Style |
| 91 |
============================*/ |
| 92 |
'maxTaxonomy'=> '30', |
| 93 |
'taxonomy' => 'category', |
| 94 |
'catStyle' => 'classic', |
| 95 |
'catPosition' => 'aboveTitle', |
| 96 |
'customCatColor' => false, |
| 97 |
'seperatorLink' => admin_url( 'edit-tags.php?taxonomy=category' ), |
| 98 |
'onlyCatColor' => false, |
| 99 |
|
| 100 |
/*============================ |
| 101 |
Meta Setting/Style |
| 102 |
============================*/ |
| 103 |
'metaPosition' => 'top', |
| 104 |
'metaStyle' => 'icon', |
| 105 |
'authorLink' => true, |
| 106 |
'metaSeparator' => 'dot', |
| 107 |
'metaList' => '["metaAuthor","metaDate","metaRead"]', |
| 108 |
'metaMinText' => 'min read', |
| 109 |
'metaAuthorPrefix' => 'By', |
| 110 |
'metaDateFormat' => 'M j, Y', |
| 111 |
|
| 112 |
/*============================ |
| 113 |
Image Style |
| 114 |
============================*/ |
| 115 |
'imgAnimation' => 'opacity', |
| 116 |
'imgCrop' => (ultimate_post()->get_setting('disable_image_size') == 'yes' ? 'full' : 'ultp_layout_landscape'), |
| 117 |
'imgCropSmall' => (ultimate_post()->get_setting('disable_image_size') == 'yes' ? 'full' : 'ultp_layout_square'), |
| 118 |
'imgOverlay' => false, |
| 119 |
'imgOverlayType' => 'default', |
| 120 |
'fallbackEnable' => true, |
| 121 |
'fallbackImg' => '', |
| 122 |
'imgSrcset' => false, |
| 123 |
'imgLazy' => false, |
| 124 |
|
| 125 |
/*============================ |
| 126 |
Video Style |
| 127 |
============================*/ |
| 128 |
'vidIconEnable' => true, |
| 129 |
'popupAutoPlay' => true, |
| 130 |
'iconSize' => (object)['lg'=>'80', 'sm'=> '50', 'xs'=> '50', 'unit' => 'px'], |
| 131 |
// by default should be off |
| 132 |
'enablePopup' => false, |
| 133 |
'enablePopupTitle' => true, |
| 134 |
|
| 135 |
/*============================ |
| 136 |
Separator Style |
| 137 |
============================*/ |
| 138 |
'separatorShow' => true, |
| 139 |
|
| 140 |
/*============================ |
| 141 |
Read More Style |
| 142 |
============================*/ |
| 143 |
'readMoreText' => '', |
| 144 |
'readMoreIcon' => 'rightArrowLg', |
| 145 |
|
| 146 |
/*============================ |
| 147 |
Filter Setting/Style |
| 148 |
============================*/ |
| 149 |
'filterBelowTitle' => false, |
| 150 |
// 'filterAlign' => (object)['lg' =>''], |
| 151 |
'filterType' => 'category', |
| 152 |
'filterText' => 'all', |
| 153 |
'filterValue' => '[]', |
| 154 |
|
| 155 |
'filterMobile' => true, |
| 156 |
'filterMobileText' => 'More', |
| 157 |
|
| 158 |
/*============================ |
| 159 |
Pagination Setting/Style |
| 160 |
============================*/ |
| 161 |
'paginationType' => 'pagination', |
| 162 |
'loadMoreText' => 'Load More', |
| 163 |
'paginationText' => 'Previous|Next', |
| 164 |
'paginationNav' => 'textArrow', |
| 165 |
'paginationAjax' => true, |
| 166 |
'navPosition' => 'topRight', |
| 167 |
|
| 168 |
/*============================ |
| 169 |
Wrapper Style |
| 170 |
============================*/ |
| 171 |
'advanceId' => '', |
| 172 |
'advanceZindex' => '', |
| 173 |
'hideExtraLarge' => false, |
| 174 |
'hideTablet' => false, |
| 175 |
'hideMobile' => false, |
| 176 |
'advanceCss' => '', |
| 177 |
'currentPostId' => '', |
| 178 |
); |
| 179 |
} |
| 180 |
|
| 181 |
public function register() { |
| 182 |
register_block_type( 'ultimate-post/post-grid-1', |
| 183 |
array( |
| 184 |
'editor_script' => 'ultp-blocks-editor-script', |
| 185 |
'editor_style' => 'ultp-blocks-editor-css', |
| 186 |
'render_callback' => array($this, 'content') |
| 187 |
) |
| 188 |
); |
| 189 |
} |
| 190 |
|
| 191 |
public function content($attr, $noAjax) { |
| 192 |
$attr = wp_parse_args($attr, $this->get_attributes()); |
| 193 |
global $unique_ID; |
| 194 |
|
| 195 |
if (!$noAjax) { |
| 196 |
$paged = is_front_page() ? get_query_var('page') : get_query_var('paged'); |
| 197 |
$attr['paged'] = $paged ? $paged : 1; |
| 198 |
} |
| 199 |
if($attr['queryUnique'] && isset($attr['savedQueryUnique'])) { |
| 200 |
$unique_ID = $attr['savedQueryUnique']; |
| 201 |
} |
| 202 |
$block_name = 'post-grid-1'; |
| 203 |
$wraper_before = $wraper_after = $post_loop = ''; |
| 204 |
$attr['queryNumber'] = ultimate_post()->get_post_number(4, $attr['queryNumber'], $attr['queryNumPosts']); |
| 205 |
|
| 206 |
// Current Post Id For Pagiantion |
| 207 |
$curr_post_id = ''; |
| 208 |
if(is_single()){ |
| 209 |
$curr_post_id = get_the_ID(); |
| 210 |
} |
| 211 |
$recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) ); |
| 212 |
$pageNum = ultimate_post()->get_page_number($attr, $recent_posts->found_posts); |
| 213 |
// Dummy Img Url |
| 214 |
$dummy_url = ULTP_URL.'assets/img/ultp-fallback-img.png'; |
| 215 |
|
| 216 |
// Loadmore and Unique content |
| 217 |
if($attr['queryUnique'] && isset($attr['loadMoreQueryUnique']) && $attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) { |
| 218 |
$unique_ID = $attr['loadMoreQueryUnique']; |
| 219 |
$current_unique_posts = $attr['ultp_current_unique_posts']; |
| 220 |
} |
| 221 |
|
| 222 |
$attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; |
| 223 |
$attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; |
| 224 |
$attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 225 |
$attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 226 |
$attr['contentTag'] = in_array( $attr['contentTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['contentTag'] : 'div'; |
| 227 |
$attr['gridStyle'] = sanitize_html_class( $attr['gridStyle'] ); |
| 228 |
$attr['layout'] = sanitize_html_class( $attr['layout'] ); |
| 229 |
$attr['imgAnimation'] = sanitize_html_class( $attr['imgAnimation'] ); |
| 230 |
$attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] ); |
| 231 |
$attr['popupAutoPlay'] = $attr['popupAutoPlay'] == true ; |
| 232 |
$attr['readMoreText'] = wp_kses($attr['readMoreText'], ultimate_post()->ultp_allowed_html_tags()); |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
if ($recent_posts->have_posts()) { |
| 237 |
$wraper_before .= '<div '.($attr['advanceId']?'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].''.( $attr["align"] ? ' align' .$attr["align"]:'').''.($attr["className"] ? ' '.$attr["className"]:'').'">'; |
| 238 |
$wraper_before .= '<div class="ultp-block-wrapper">'; |
| 239 |
|
| 240 |
// Loading |
| 241 |
$wraper_before .= ultimate_post()->loading(); |
| 242 |
|
| 243 |
if ($attr['headingShow'] || $attr['filterShow'] || $attr['paginationShow']) { |
| 244 |
$wraper_before .= '<div class="ultp-heading-filter">'; |
| 245 |
$wraper_before .= '<div class="ultp-heading-filter-in">'; |
| 246 |
|
| 247 |
// Heading |
| 248 |
include ULTP_PATH.'blocks/template/heading.php'; |
| 249 |
|
| 250 |
if ($attr['filterShow'] || $attr['paginationShow']) { |
| 251 |
$wraper_before .= '<div class="ultp-filter-navigation">'; |
| 252 |
|
| 253 |
// Filter |
| 254 |
if($attr['filterShow'] && $attr['queryType'] != 'posts' && $attr['queryType'] != 'customPosts') { |
| 255 |
include ULTP_PATH.'blocks/template/filter.php'; |
| 256 |
} |
| 257 |
|
| 258 |
// Navigation |
| 259 |
if ($attr['paginationShow'] && ($attr['paginationType'] == 'navigation') && ($attr['navPosition'] == 'topRight')) { |
| 260 |
include ULTP_PATH.'blocks/template/navigation-before.php'; |
| 261 |
} |
| 262 |
$wraper_before .= '</div>'; |
| 263 |
} |
| 264 |
|
| 265 |
$wraper_before .= '</div>'; |
| 266 |
$wraper_before .= '</div>'; |
| 267 |
} |
| 268 |
|
| 269 |
$colClass = ($attr['gridStyle'] == 'style1' || $attr['gridStyle'] == 'style2') ? 'ultp-block-column-'.json_decode(wp_json_encode($attr['columns']), True)['lg'] : ''; |
| 270 |
|
| 271 |
$wraper_before .= '<div class="ultp-block-items-wrap ultp-block-row ultp-pg1a-'.$attr['gridStyle'].' '.sanitize_html_class( $colClass ).' ultp-'.$attr['layout'].'">'; |
| 272 |
$idx = ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) ? ( $noAjax ? 1 : 0 ) : 0; |
| 273 |
while ( $recent_posts->have_posts() ): $recent_posts->the_post(); |
| 274 |
|
| 275 |
include ULTP_PATH.'blocks/template/data.php'; |
| 276 |
|
| 277 |
include ULTP_PATH.'blocks/template/category.php'; |
| 278 |
|
| 279 |
if ($attr['queryUnique']) { |
| 280 |
$unique_ID[$attr['queryUnique']][] = $post_id; |
| 281 |
$current_unique_posts[] = $post_id; |
| 282 |
} |
| 283 |
$divStyle = ''; |
| 284 |
if ($post_thumb_id && $attr['showImage']) { |
| 285 |
$divStyle = 'background-image:url('.get_the_post_thumbnail_url($post_id, $attr['imgCrop']).')'; |
| 286 |
} |
| 287 |
$post_loop .= '<'.$attr['contentTag'].' class="ultp-block-item post-id-'.$post_id.'">'; |
| 288 |
$post_loop .= '<div class="ultp-block-content-wrap">'; |
| 289 |
if(($post_thumb_id || $attr['fallbackEnable']) && $attr['showImage'] && $attr['layout'] != 'layout2') { |
| 290 |
$post_loop .= '<div class="ultp-block-image ultp-block-image-'.$attr['imgAnimation'].($attr["imgOverlay"] ? ' ultp-block-image-overlay ultp-block-image-'.$attr["imgOverlayType"].' ultp-block-image-'.$attr["imgOverlayType"].$idx : '' ).'">'; |
| 291 |
$post_loop .= '<a href="'.$titlelink.'" '.($attr['openInTab'] ? 'target="_blank"' : '').'>'; |
| 292 |
$imgSize = (($attr['gridStyle'] == 'style1') || |
| 293 |
($attr['gridStyle'] == 'style2' && $idx == 0) || |
| 294 |
($attr['gridStyle'] == 'style3' && $idx%3 == 0) || |
| 295 |
($attr['gridStyle'] == 'style4' && ($idx == 0 || $idx == 1))) ? $attr['imgCrop'] : $attr['imgCropSmall']; |
| 296 |
// Post Img Id |
| 297 |
$block_img_id = $post_thumb_id ? $post_thumb_id : ($attr['fallbackEnable'] && isset($attr['fallbackImg']['id']) ? $attr['fallbackImg']['id'] : ''); |
| 298 |
// Post Image |
| 299 |
if($post_thumb_id || ($attr['fallbackEnable'] && $block_img_id)) { |
| 300 |
$post_loop .= ultimate_post()->get_image($block_img_id , $imgSize, '', $title, $attr['imgSrcset'], $attr['imgLazy']); |
| 301 |
} else { |
| 302 |
$video = ultimate_post()->get_youtube_id($post_video); |
| 303 |
$post_loop .= '<img src="'.($video ? 'https://img.youtube.com/vi/'.$video.'/0.jpg' : $dummy_url).'" alt="dummy-img" />'; |
| 304 |
} |
| 305 |
$post_loop .= '</a>'; |
| 306 |
if($post_video){ |
| 307 |
$post_loop .= '<div enableAutoPlay="'.$attr['popupAutoPlay'].'" class="ultp-video-icon">'.ultimate_post()->svg_icon('play_line').'</div>'; |
| 308 |
} |
| 309 |
if (($attr['catPosition'] != 'aboveTitle') && $attr['catShow'] ) { |
| 310 |
$post_loop .= '<div class="ultp-category-img-grid">'.$category.'</div>'; |
| 311 |
} |
| 312 |
$post_loop .= '</div>'; |
| 313 |
} |
| 314 |
if ($attr['layout'] === 'layout2' ) { $post_loop .= '<div class="ultp-block-content-image" style='.$divStyle.'></div>';} |
| 315 |
$post_loop .= '<div class="ultp-block-content">'; |
| 316 |
|
| 317 |
// Category |
| 318 |
if (($attr['catPosition'] == 'aboveTitle') && $attr['catShow']) { |
| 319 |
$post_loop .= $category; |
| 320 |
} |
| 321 |
|
| 322 |
// Title |
| 323 |
if ($title && $attr['titleShow'] && $attr['titlePosition'] == 1) { |
| 324 |
include ULTP_PATH.'blocks/template/title.php'; |
| 325 |
} |
| 326 |
|
| 327 |
// Meta |
| 328 |
if ($attr['metaPosition'] =='top' ) { |
| 329 |
include ULTP_PATH.'blocks/template/meta.php'; |
| 330 |
} |
| 331 |
|
| 332 |
// Title |
| 333 |
if ($title && $attr['titleShow'] && $attr['titlePosition'] == 0) { |
| 334 |
include ULTP_PATH.'blocks/template/title.php'; |
| 335 |
} |
| 336 |
|
| 337 |
// Excerpt |
| 338 |
if ($attr['excerptShow']) { |
| 339 |
$post_loop .= '<div class="ultp-block-excerpt">'.ultimate_post()->get_excerpt($post_id, $attr['showSeoMeta'], $attr['showFullExcerpt'], $attr['excerptLimit']).'</div>'; |
| 340 |
} |
| 341 |
|
| 342 |
// Read More |
| 343 |
if ( $attr['readMore'] ) { |
| 344 |
$post_loop .= '<div class="ultp-block-readmore"><a aria-label="'.$title.'" href="'.$titlelink.'" '.($attr['openInTab'] ? 'target="_blank"' : '').'>'.($attr['readMoreText'] ? $attr['readMoreText'] : esc_html__( "Read More", "ultimate-post" )).ultimate_post()->svg_icon($attr['readMoreIcon']).'</a></div>'; |
| 345 |
} |
| 346 |
|
| 347 |
// Meta |
| 348 |
if ($attr['metaPosition'] =='bottom' ) { |
| 349 |
include ULTP_PATH.'blocks/template/meta.php'; |
| 350 |
} |
| 351 |
|
| 352 |
$post_loop .= '</div>'; |
| 353 |
$post_loop .= '</div>'; |
| 354 |
if($post_video && $attr['enablePopup'] && $attr['layout'] !== 'layout2') { |
| 355 |
include ULTP_PATH.'blocks/template/video_popup.php'; |
| 356 |
} |
| 357 |
$post_loop .= '</'.$attr['contentTag'].'>'; |
| 358 |
$idx ++; |
| 359 |
endwhile; |
| 360 |
if($attr['queryUnique']) { |
| 361 |
$post_loop .= "<span style='display: none;' class='ultp-current-unique-posts' data-ultp-unique-ids= ".wp_json_encode($unique_ID)." data-current-unique-posts= ".wp_json_encode($current_unique_posts)."> </span>"; |
| 362 |
} |
| 363 |
if ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) { |
| 364 |
$wraper_after .= '<span class="ultp-loadmore-insert-before"></span>'; |
| 365 |
} |
| 366 |
$wraper_after .= '</div>';//ultp-block-items-wrap |
| 367 |
|
| 368 |
// Load More |
| 369 |
if ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) { |
| 370 |
include ULTP_PATH.'blocks/template/loadmore.php'; |
| 371 |
} |
| 372 |
|
| 373 |
// Navigation |
| 374 |
if ($attr['paginationShow'] && ($attr['paginationType'] == 'navigation') && ($attr['navPosition'] != 'topRight')) { |
| 375 |
include ULTP_PATH.'blocks/template/navigation-after.php'; |
| 376 |
} |
| 377 |
|
| 378 |
// Pagination |
| 379 |
if ($attr['paginationShow'] && ($attr['paginationType'] == 'pagination')) { |
| 380 |
include ULTP_PATH.'blocks/template/pagination.php'; |
| 381 |
} |
| 382 |
|
| 383 |
$wraper_after .= '</div>'; |
| 384 |
$wraper_after .= '</div>'; |
| 385 |
|
| 386 |
wp_reset_query(); |
| 387 |
|
| 388 |
}else { |
| 389 |
$wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] ); |
| 390 |
} |
| 391 |
|
| 392 |
return $noAjax ? $post_loop : $wraper_before.$post_loop.$wraper_after; |
| 393 |
} |
| 394 |
|
| 395 |
} |