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