| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | return __( 'Images', 'propertyhive' ); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function get_icon() { |
| 18 | - return 'fa fa-images'; | |
| 18 | + return 'eicon-product-images'; | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function get_categories() { |
| 22 | 22 | return [ 'property-hive' ]; |
| @@ -25,19 +25,53 @@ | ||
| 25 | 25 | public function get_keywords() { |
| 26 | 26 | return [ 'property hive', 'propertyhive', 'property', 'images', 'photos', 'gallery', 'slideshow' ]; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - protected function _register_controls() { | |
| 29 | + protected function register_controls() { | |
| 30 | 30 | |
| 31 | 31 | $this->start_controls_section( |
| 32 | 32 | 'content_section', |
| 33 | 33 | [ |
| 34 | - 'label' => __( 'Images', 'plugin-name' ), | |
| 34 | + 'label' => __( 'Images', 'propertyhive' ), | |
| 35 | 35 | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 36 | 36 | ] |
| 37 | 37 | ); |
| 38 | 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 | + ); | |
| 39 | 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 | + | |
| 40 | 74 | $this->end_controls_section(); |
| 41 | 75 | |
| 42 | 76 | } |
| 43 | 77 | |
| @@ -50,10 +84,54 @@ | ||
| 50 | 84 | if ( !isset($property->id) ) { |
| 51 | 85 | return; |
| 52 | 86 | } |
| 53 | 87 | |
| 54 | - propertyhive_show_property_images(); | |
| 88 | + $suffix = ''; | |
| 89 | + $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; | |
| 55 | 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 | + | |
| 56 | 134 | // On render widget from Editor - trigger the init manually. |
| 57 | 135 | if ( wp_doing_ajax() ) { |
| 58 | 136 | ?> |
| 59 | 137 | <script> |
| @@ -64,5 +142,25 @@ | ||
| 64 | 142 | } |
| 65 | 143 | |
| 66 | 144 | } |
| 67 | 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 | + } | |
| 68 | 166 | } |