| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Property Images Widget. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
class Elementor_Property_Images_Widget extends \Elementor\Widget_Base { |
| 8 |
|
| 9 |
public function get_name() { |
| 10 |
return 'property-images'; |
| 11 |
} |
| 12 |
|
| 13 |
public function get_title() { |
| 14 |
return __( 'Images', 'propertyhive' ); |
| 15 |
} |
| 16 |
|
| 17 |
public function get_icon() { |
| 18 |
return 'eicon-product-images'; |
| 19 |
} |
| 20 |
|
| 21 |
public function get_categories() { |
| 22 |
return [ 'property-hive' ]; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_keywords() { |
| 26 |
return [ 'property hive', 'propertyhive', 'property', 'images', 'photos', 'gallery', 'slideshow' ]; |
| 27 |
} |
| 28 |
|
| 29 |
protected function register_controls() { |
| 30 |
|
| 31 |
$this->start_controls_section( |
| 32 |
'content_section', |
| 33 |
[ |
| 34 |
'label' => __( 'Images', 'propertyhive' ), |
| 35 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 36 |
] |
| 37 |
); |
| 38 |
|
| 39 |
$this->add_control( |
| 40 |
'hide_thumbnails', |
| 41 |
[ |
| 42 |
'label' => __( 'Hide Thumbnails', 'propertyhive' ), |
| 43 |
'type' => \Elementor\Controls_Manager::SWITCHER, |
| 44 |
'label_on' => __( 'Yes', 'propertyhive' ), |
| 45 |
'label_off' => __( 'No', 'propertyhive' ), |
| 46 |
'return_value' => 'yes', |
| 47 |
'default' => '', |
| 48 |
] |
| 49 |
); |
| 50 |
|
| 51 |
$this->add_control( |
| 52 |
'num_images', |
| 53 |
[ |
| 54 |
'label' => __( 'Images To Show', 'propertyhive' ), |
| 55 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 56 |
] |
| 57 |
); |
| 58 |
|
| 59 |
$this->add_control( |
| 60 |
'link_to', |
| 61 |
[ |
| 62 |
'label' => __( 'Link Images To', 'propertyhive' ), |
| 63 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 64 |
'default' => '', |
| 65 |
'options' => [ |
| 66 |
'' => esc_html__( 'Image In Lightbox', 'propertyhive' ), |
| 67 |
'blank' => esc_html__( 'Image In New Window', 'propertyhive' ), |
| 68 |
'property' => esc_html__( 'Property URL', 'propertyhive' ), |
| 69 |
'none' => esc_html__( 'None', 'propertyhive' ), |
| 70 |
], |
| 71 |
] |
| 72 |
); |
| 73 |
|
| 74 |
$this->end_controls_section(); |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
protected function render() { |
| 79 |
|
| 80 |
global $property; |
| 81 |
|
| 82 |
$settings = $this->get_settings_for_display(); |
| 83 |
|
| 84 |
if ( !isset($property->id) ) { |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
$suffix = ''; |
| 89 |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; |
| 90 |
|
| 91 |
wp_enqueue_script( 'flexslider', $assets_path . 'js/flexslider/jquery.flexslider' . $suffix . '.js', array( 'jquery' ), '2.7.2', true ); |
| 92 |
wp_enqueue_script( 'flexslider-init', $assets_path . 'js/flexslider/jquery.flexslider.init' . $suffix . '.js', array( 'jquery','flexslider' ), PH_VERSION, true ); |
| 93 |
wp_enqueue_style( 'flexslider_css', $assets_path . 'css/flexslider.css', array(), '2.7.2' ); |
| 94 |
|
| 95 |
if ( 'yes' === $settings['hide_thumbnails'] ) |
| 96 |
{ |
| 97 |
remove_action( 'propertyhive_product_thumbnails', 'propertyhive_show_property_thumbnails', 20 ); |
| 98 |
} |
| 99 |
|
| 100 |
if ( isset($settings['link_to']) ) |
| 101 |
{ |
| 102 |
switch ($settings['link_to']) |
| 103 |
{ |
| 104 |
case "blank": |
| 105 |
{ |
| 106 |
add_filter( 'propertyhive_single_property_image_html', array( $this, 'customise_property_images_html_blank' ), 10, 2 ); |
| 107 |
break; |
| 108 |
} |
| 109 |
case "none": |
| 110 |
{ |
| 111 |
add_filter( 'propertyhive_single_property_image_html', array( $this, 'customise_property_images_html_none' ), 10, 2 ); |
| 112 |
break; |
| 113 |
} |
| 114 |
case "property": |
| 115 |
{ |
| 116 |
add_filter( 'propertyhive_single_property_image_html', array( $this, 'customise_property_images_html_property' ), 10, 2 ); |
| 117 |
break; |
| 118 |
} |
| 119 |
default: |
| 120 |
{ |
| 121 |
wp_enqueue_script( 'propertyhive_fancybox' ); |
| 122 |
wp_enqueue_style( 'propertyhive_fancybox_css' ); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
else |
| 127 |
{ |
| 128 |
wp_enqueue_script( 'propertyhive_fancybox' ); |
| 129 |
wp_enqueue_style( 'propertyhive_fancybox_css' ); |
| 130 |
} |
| 131 |
|
| 132 |
propertyhive_show_property_images( ( isset($settings['num_images']) && !empty($settings['num_images']) && is_numeric($settings['num_images']) ) ? (int)$settings['num_images'] : '' ); |
| 133 |
|
| 134 |
// On render widget from Editor - trigger the init manually. |
| 135 |
if ( wp_doing_ajax() ) { |
| 136 |
?> |
| 137 |
<script> |
| 138 |
// The slider being synced must be initialized first |
| 139 |
//ph_init_slideshow(); |
| 140 |
</script> |
| 141 |
<?php |
| 142 |
} |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
public function customise_property_images_html_none( $html, $post_id ) |
| 147 |
{ |
| 148 |
$html = strip_tags($html, '<img>'); |
| 149 |
return $html; |
| 150 |
} |
| 151 |
|
| 152 |
public function customise_property_images_html_blank( $html, $post_id ) |
| 153 |
{ |
| 154 |
$html = str_replace("data-fancybox=\"gallery-" . (int)$post_id . "\"", "target=\"_blank\"", $html); |
| 155 |
return $html; |
| 156 |
} |
| 157 |
|
| 158 |
public function customise_property_images_html_property( $html, $post_id ) |
| 159 |
{ |
| 160 |
$html = str_replace("data-fancybox=\"gallery-" . (int)$post_id . "\"", "", $html); |
| 161 |
|
| 162 |
$html = preg_replace('/(href=")([^"]*)(")/', 'href="' . esc_url(get_permalink($post_id)) . '"', $html); |
| 163 |
|
| 164 |
return $html; |
| 165 |
} |
| 166 |
} |