HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1014-azure #14~24.04.1-Ubuntu SMP Fri Oct 3 20:52:11 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/dreamsrent-wp/wp-content/plugins/dreamsrent-widgets/widgets/class-tax-carousel.php
<?php
/**
 * Awesomesauce class.
 *
 * @category   Class
 * @package    ElementorAwesomesauce
 * @subpackage WordPress
 * @author     Ben Marshall <[email protected]>
 * @copyright  2020 Ben Marshall
 * @license    https://opensource.org/licenses/GPL-3.0 GPL-3.0-only
 * @link       link(https://www.benmarshall.me/build-custom-elementor-widgets/,
 *             Build Custom Elementor Widgets)
 * @since      1.0.0
 * php version 7.3.9
 */

namespace Dreamsrentelementor\Widgets;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Utils;

if ( ! defined( 'ABSPATH' ) ) {
	// Exit if accessed directly.
	exit;
}

/**
 * Awesomesauce widget class.
 *
 * @since 1.0.0
 */
class DSR_TaxonomyCarousel extends Widget_Base {

	/**
	 * Retrieve the widget name.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'dreamsrent-taxonomy-carousel';
	}

	/**
	 * Retrieve the widget title.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'DR Taxonomy Carousel', 'dreamsrent_elementor' );
	}

	/**
	 * Retrieve the widget icon.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'eicon-posts-grid';
	}

	/**
	 * Retrieve the list of categories the widget belongs to.
	 *
	 * Used to determine where to display the widget in the editor.
	 *
	 * Note that currently Elementor supports only one category.
	 * When multiple categories passed, Elementor uses the first one.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return array( 'dreamsrentelemetortheme' );
	}

	/**
	 * Register the widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */
	protected function _register_controls() {
		$this->start_controls_section(
			'section_content',
			array(
				'label' => __( 'Content', 'dreamsrent_elementor' ),
			)
		);
// 	'taxonomy' => '',
			// 'xd' 	=> '',
			// 'only_top' 	=> 'yes',
			// 'autoplay'      => '',
   //          'autoplayspeed'      => '3000',
		
		$this->add_control(
			'taxonomy',
			[
				'label' => __( 'Taxonomy 1', 'dreamsrent_elementor' ),
				'type' => Controls_Manager::SELECT2,
				'label_block' => true,
				'default' => [],
				'options' => $this->get_taxonomies(),
				
			]
		);

		$taxonomy_names = get_object_taxonomies( 'rental','object' );
		foreach ($taxonomy_names as $key => $value) {
			
			$this->add_control(
				$value->name.'_include',
				[
					'label' => __( 'Include product from '.$value->label, 'dreamsrent_elementor' ),
					'type' => Controls_Manager::SELECT2,
					'label_block' => true,
					'multiple' => true,
					'default' => [],
					'options' => $this->get_terms($value->name),
					'condition' => [
						'taxonomy' => $value->name,
					],
				]
			);
			$this->add_control(
				$value->name.'_exclude',
				[
					'label' => __( 'Exclude products from '.$value->label, 'dreamsrent_elementor' ),
					'type' => Controls_Manager::SELECT2,
					'label_block' => true,
					'multiple' => true,
					'default' => [],
					'options' => $this->get_terms($value->name),
					'condition' => [
						'taxonomy' => $value->name,
					],
				]
			);
		}
		$this->add_control(
			'number',
			[
				'label' => __( 'Terms to display', 'dreamsrent_elementor' ),
				'type' => \Elementor\Controls_Manager::NUMBER,
				'min' => 1,
				'max' => 199,
				'step' => 1,
				'default' => 6,
			]
		);
		$this->add_control(
			'only_top',
			[
				'label' => __( 'Show only top terms', 'dreamsrent_elementor' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => __( 'Show', 'dreamsrent_elementor' ),
				'label_off' => __( 'Hide', 'dreamsrent_elementor' ),
				'return_value' => 'yes',
				'default' => 'yes',
				
			]
		);

		$this->add_control(
			'label',
			array(
				'label'   => __( 'Label', 'dreamsrent_elementor' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( 'View All', 'dreamsrent_elementor' ),
			)
		);
 
		$this->add_control(
			'website_link',
			[
				'label' => __( 'Link','dreamsrent_elementor' ),
				'type' => \Elementor\Controls_Manager::URL,
				'placeholder' => __( 'https://your-link.com', 'dreamsrent_elementor' ),
				'show_external' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
					'nofollow' => true,
				],
			]
		);

	
	

		$this->end_controls_section();

		// Style tab
		$this->start_controls_section(
			'tax_carousel_style_section',
			[
				'label' => __( 'Styles', 'dreamsrent_elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);

		// Term title
		$this->add_control(
			'tax_carousel_title_color',
			[
				'label'     => __( 'Title Color', 'dreamsrent_elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .listing-owl-group h6' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'tax_carousel_title_typography',
				'label'    => __( 'Title Typography', 'dreamsrent_elementor' ),
				'selector' => '{{WRAPPER}} .listing-owl-group h6',
			]
		);

		// Count text
		$this->add_control(
			'tax_carousel_count_color',
			[
				'label'     => __( 'Count Text Color', 'dreamsrent_elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .listing-owl-group p' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'tax_carousel_count_typography',
				'label'    => __( 'Count Typography', 'dreamsrent_elementor' ),
				'selector' => '{{WRAPPER}} .listing-owl-group p',
			]
		);

		$this->end_controls_section();

	}

	/**
	 * Render the widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */
	protected function render() {
		$settings = $this->get_settings_for_display();

	
		$target = $settings['website_link']['is_external'] ? ' target="_blank"' : '';
		$nofollow = $settings['website_link']['nofollow'] ? ' rel="nofollow"' : '';
		if(!empty($settings['website_link']['url'])){
			$full_url =  $settings['website_link']['url'];	
		} else {
			$full_url = '';
		}

		$taxonomy_names = get_object_taxonomies( 'product','object' );
		
		$taxonomy = $settings['taxonomy'];

        
	      if(empty($taxonomy)){
	      	$taxonomy = "type";
	      }
		$query_args = array(
			'include' => $settings[$taxonomy.'_include'],
			'exclude' => $settings[$taxonomy.'_exclude'],
			'hide_empty' => false,
			'number' => $settings['number'],
		);
		if($settings['only_top'] == 'yes'){
			$query_args['parent'] = 0;
		}
       	$terms = get_terms( $settings['taxonomy'],$query_args);
       	
       	if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
       	?>
 

 

 
					<div class="popular-slider-group">
			        	<div class="owl-carousel popular-cartype-slider owl-theme">
 			<?php 
      		foreach ( $terms as $term ) { 
		        $t_id = $term->term_id;  ?>


<div class="listing-owl-item">
							    <div class="listing-owl-group">
								    <div class="listing-owl-img">

									<?php
// Get the category image URL using the Categories Images plugin
$category_image_url = z_taxonomy_image_url($term->term_id);

// Define the plugin's default placeholder image URL
$placeholder_image_url = get_template_directory_uri() . '/assets/images/vehicle-placeholder.png'; // For parent theme

// Check if the category image exists, otherwise use the placeholder
$image_to_display = !empty($category_image_url) ? $category_image_url : $placeholder_image_url;
?>

<img src="<?php echo esc_url($image_to_display); ?>" class="img-fluid" alt="<?php echo esc_attr__( 'Category image', 'dreamsrent_elementor' ); ?>">

 </div>
									<h6><?php echo $term->name; ?></h6>
									<p><?php echo $term->count; ?> <?php if($term->count<="1") { ?> <?php echo esc_html__('Car','dreamsrent_elementor'); ?> <?php } else { ?><?php echo esc_html__('Cars','dreamsrent_elementor'); ?><?php } ?></p>	
								</div>
							</div>
 
			<?php } ?>
			</div>
		</div>
	 

 		<?php }

	}

	
	protected function get_taxonomies() {
		$taxonomies = get_object_taxonomies( 'rental', 'objects' );

		$options = [ '' => '' ];

		foreach ( $taxonomies as $taxonomy ) {
			$options[ $taxonomy->name ] = $taxonomy->label;
		}

		return $options;
	}

	protected function get_terms($taxonomy) {
		$taxonomies = get_terms( array( 'taxonomy' =>$taxonomy,'hide_empty' => false) );

		$options = [ '' => '' ];
		
		if ( !empty($taxonomies) ) :
			foreach ( $taxonomies as $taxonomy ) {
				$options[ $taxonomy->term_id ] = $taxonomy->name;
			}
		endif;

		return $options;
	}

}