| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class Taxonomy { |
| 7 |
|
| 8 |
public function __construct() { |
| 9 |
add_action('init', array($this, 'register')); |
| 10 |
} |
| 11 |
|
| 12 |
public function get_attributes() { |
| 13 |
return array( |
| 14 |
'blockId' => '', |
| 15 |
'previewImg' => '', |
| 16 |
// Layout |
| 17 |
'layout' => '1', |
| 18 |
// Query Setting |
| 19 |
'taxType' => 'regular', |
| 20 |
'taxSlug' => 'category', |
| 21 |
'taxValue' => '[]', |
| 22 |
'queryNumber' => 6, |
| 23 |
// General Setting |
| 24 |
'taxGridEn' => true, |
| 25 |
'columns' => (object)['lg' =>'1'], |
| 26 |
'rowGap' => (object)['lg' =>'20', 'unit' =>'px'], |
| 27 |
'titleShow' => true, |
| 28 |
'headingShow' => true, |
| 29 |
'excerptShow' => false, |
| 30 |
'countShow' => true, |
| 31 |
'openInTab' => false, |
| 32 |
'notFoundMessage' => 'No Taxonomy Found.', |
| 33 |
|
| 34 |
// Heading Setting/Style |
| 35 |
'headingText' => 'Post Taxonomy', |
| 36 |
'headingURL' => '', |
| 37 |
'headingBtnText' => 'View More', |
| 38 |
'headingStyle' => 'style9', |
| 39 |
'headingTag' => 'h2', |
| 40 |
'headingAlign' => 'left', |
| 41 |
'subHeadingShow' => false, |
| 42 |
'subHeadingText' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut sem augue. Sed at felis ut enim dignissim sodales.', |
| 43 |
'titleTag' => 'span', |
| 44 |
'contentTitleAlign' => 'left', |
| 45 |
'titlePosition' => true, |
| 46 |
'customTaxTitleColor' => false, |
| 47 |
'seperatorTaxTitleLink' => admin_url( 'edit-tags.php?taxonomy=category' ), |
| 48 |
|
| 49 |
// Content Setting/Style |
| 50 |
'excerptLimit' => 30, |
| 51 |
|
| 52 |
// Image Setting/Style |
| 53 |
'imgCrop' => (ultimate_post()->get_setting('disable_image_size') == 'yes' ? 'full' : 'ultp_layout_landscape'), |
| 54 |
|
| 55 |
// Separator |
| 56 |
'separatorShow' => false, |
| 57 |
|
| 58 |
// Custom Wrapper Style |
| 59 |
'customTaxColor' => false, |
| 60 |
'seperatorTaxLink' => admin_url( 'edit-tags.php?taxonomy=category' ), |
| 61 |
'TaxAnimation' => 'none', |
| 62 |
'advanceId' => '', |
| 63 |
'advanceZindex' => '', |
| 64 |
'hideExtraLarge' => false, |
| 65 |
'hideTablet' => false, |
| 66 |
'hideMobile' => false, |
| 67 |
'advanceCss' => '', |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
public function register() { |
| 72 |
register_block_type( 'ultimate-post/ultp-taxonomy', |
| 73 |
array( |
| 74 |
'editor_script' => 'ultp-blocks-editor-script', |
| 75 |
'editor_style' => 'ultp-blocks-editor-css', |
| 76 |
'render_callback' => array($this, 'content') |
| 77 |
) |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
public function content( $attr, $noAjax ) { |
| 82 |
$attr = wp_parse_args( $attr, $this->get_attributes() ); |
| 83 |
|
| 84 |
if ( ! $noAjax ) { |
| 85 |
$paged = is_front_page() ? get_query_var('page') : get_query_var('paged'); |
| 86 |
$attr['paged'] = $paged ? $paged : 1; |
| 87 |
} |
| 88 |
|
| 89 |
$block_name = 'ultp-taxonomy'; |
| 90 |
$wraper_before = $wraper_after = $post_loop = ''; |
| 91 |
$recent_posts = ultimate_post()->get_category_data( json_decode($attr['taxValue']), $attr['queryNumber'], $attr['taxType'], $attr['taxSlug'] ); |
| 92 |
|
| 93 |
if ( ! empty( $recent_posts ) ) { |
| 94 |
|
| 95 |
$attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; |
| 96 |
$attr['imgCrop'] = isset($attr['imgCrop']) && $attr['imgCrop'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['imgCrop']) : ''; |
| 97 |
$attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 98 |
$attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 99 |
$attr['titleTag'] = in_array( $attr['titleTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['titleTag'] : 'span'; |
| 100 |
$attr['layout'] = sanitize_html_class( $attr['layout'] ); |
| 101 |
$attr['TaxAnimation'] = sanitize_html_class( $attr['TaxAnimation'] ); |
| 102 |
|
| 103 |
$wraper_before .= '<div '.( $attr['advanceId'] ? 'id="'.$attr['advanceId'].'" ':'' ).' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].' '.( $attr["className"] ? $attr["className"]:'' ).'">'; |
| 104 |
$wraper_before .= '<div class="ultp-block-wrapper">'; |
| 105 |
$wraper_before .= ultimate_post()->loading(); // Loading |
| 106 |
|
| 107 |
if ( $attr['headingShow'] ) { |
| 108 |
$wraper_before .= '<div class="ultp-heading-filter">'; |
| 109 |
$wraper_before .= '<div class="ultp-heading-filter-in">'; |
| 110 |
include ULTP_PATH.'blocks/template/heading.php'; // Heading |
| 111 |
$wraper_before .= '</div>'; |
| 112 |
$wraper_before .= '</div>'; |
| 113 |
} |
| 114 |
|
| 115 |
$wraper_before .= '<div class="ultp-block-items-wrap">'; |
| 116 |
$wraper_before .= '<ul class="ultp-taxonomy-items '.(isset($attr["TaxAnimation"])? ' ultp-taxonomy-animation-' .$attr["TaxAnimation"]:'').' ultp-taxonomy-column-'.sanitize_html_class( json_decode(wp_json_encode($attr['columns']), true)['lg'] ).' ultp-taxonomy-layout-'.$attr['layout'].'">'; |
| 117 |
|
| 118 |
foreach ( $recent_posts as $value ) { |
| 119 |
$_style = ( ($attr["customTaxColor"] && $value['color']) ? ' style="background-color:'.$value['color'].';"' : ''); |
| 120 |
$_style_color = ((in_array($attr['layout'], [1,4,5]) && $value['color'] && $attr["customTaxTitleColor"] ) ? ' style="color:'.$value['color'].';"' : ''); |
| 121 |
$_style_title_bg = ((in_array($attr['layout'], [7,8]) && $value['color'] && $attr["customTaxTitleColor"] ) ? ' style="background:'.$value['color'].';"' : ''); |
| 122 |
$post_loop .= '<li class="ultp-block-item ultp-taxonomy-item">'; |
| 123 |
$style = in_array($attr['layout'], [2,3,6,7,8]) ? 'style="'.($value['image'] ? 'background-image: url('.$value['image'][ $attr['imgCrop']].')' : 'background-color:'.$value['color']).'"' : ''; |
| 124 |
$name = ($attr['titleShow'] && $value['name']) ? '<'.$attr['titleTag'].' class="ultp-taxonomy-name" '.$_style_color.'>'.$value['name'].'</'.$attr['titleTag'].'>' : ''; |
| 125 |
$count = ($attr['countShow'] && $value['count']) ? '<span class="ultp-taxonomy-count" '.$_style_color.'>'.$value['count'].'</span>' : ''; |
| 126 |
$excerpt = ($attr['excerptShow'] && $value['desc']) ? '<div class="ultp-taxonomy-desc">'.$value['desc'].'</div>' : ''; |
| 127 |
$post_loop .= '<a href="'.$value['url'].'" '.($attr['layout'] != 3 ? $style : '').'>'; |
| 128 |
switch ( $attr['layout'] ) { |
| 129 |
case 1: |
| 130 |
$post_loop .= $name.$count.$excerpt; |
| 131 |
break; |
| 132 |
case 2: |
| 133 |
$post_loop .= '<div class="ultp-taxonomy-lt2-overlay"'.$_style.'></div><div class="ultp-taxonomy-lt2-content">'.$name.'<span class="ultp-taxonomy-bar"></span>'.$count.'</div>'.$excerpt; |
| 134 |
break; |
| 135 |
case 3: |
| 136 |
$post_loop .= '<div class="ultp-taxonomy-lt3-img" '.$style.'></div><div class="ultp-taxonomy-lt3-overlay"'.$_style.'></div><div class="ultp-taxonomy-lt3-content">'.$name.'<span class="ultp-taxonomy-bar"></span>'.$count.'</div>'.$excerpt; |
| 137 |
break; |
| 138 |
case 4: |
| 139 |
$img = $value['image'] ? '<img src="'.$value['image'][ $attr['imgCrop']].'" alt="'.$value['name'].'"/>' : ''; |
| 140 |
$post_loop .= $img.'<div class="ultp-taxonomy-lt4-content">'.$name.$count.'</div>'.$excerpt; |
| 141 |
break; |
| 142 |
case 5: |
| 143 |
$img = $value['image'] ? '<img src="'.$value['image'][ $attr['imgCrop']].'" alt="'.$value['name'].'"/>' : ''; |
| 144 |
$post_loop .= $img.'<span class="ultp-taxonomy-lt5-content">'.$name.$count.$excerpt.'</span>'; |
| 145 |
break; |
| 146 |
case 6: |
| 147 |
$post_loop .= '<div class="ultp-taxonomy-lt6-overlay"'.$_style.'></div>'.$name.$count.$excerpt; |
| 148 |
break; |
| 149 |
case 7: |
| 150 |
$post_loop .= '<div class="ultp-taxonomy-lt7-overlay"'.$_style.'></div><'.$attr['titleTag'].' class="ultp-taxonomy-name" '.$_style_title_bg.'>'.$value['name'].$count.'</'.$attr['titleTag'].'>'.$excerpt; |
| 151 |
break; |
| 152 |
case 8: |
| 153 |
$post_loop .= '<div class="ultp-taxonomy-lt8-overlay"'.$_style.'></div><'.$attr['titleTag'].' class="ultp-taxonomy-name" '.$_style_title_bg.'>'.$value['name'].$count.'</'.$attr['titleTag'].'>'.$excerpt; |
| 154 |
break; |
| 155 |
default: |
| 156 |
# code... |
| 157 |
break; |
| 158 |
} |
| 159 |
$post_loop .= '</a>'; |
| 160 |
$post_loop .= '</li>'; |
| 161 |
} |
| 162 |
|
| 163 |
$wraper_after .= '</ul>'; |
| 164 |
$wraper_after .= '</div>'; |
| 165 |
$wraper_after .= '</div>'; |
| 166 |
$wraper_after .= '</div>'; |
| 167 |
wp_reset_query(); |
| 168 |
} else { |
| 169 |
$wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] ); |
| 170 |
} |
| 171 |
|
| 172 |
return $noAjax ? $post_loop : $wraper_before.$post_loop.$wraper_after; |
| 173 |
} |
| 174 |
} |