PluginProbe
WP Directory Kit / 1.3.1
WP Directory Kit v1.3.1
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / elementor-elements / classes / wdk-listing-agent-field.php

wdk-listing-agent-field.php in WP Directory Kit 1.3.1, at elementor-elements/classes/wdk-listing-agent-field.php

326 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Wdk\Elementor\Widgets;
4
5 use Wdk\Elementor\Widgets\WdkElementorBase;
6 use Elementor\Widget_Base;
7 use Elementor\Controls_Manager;
8 use Elementor\Utils;
9 use Elementor\Typography;
10 use Elementor\Editor;
11 use Elementor\Plugin;
12 use Elementor\Repeater;
13 use Elementor\Core\Schemes;
14 use Elementor\Icons_Manager;
15 use Elementor\Group_Control_Typography;
16 use Elementor\Group_Control_Border;
17 use Elementor\Group_Control_Box_Shadow;
18
19 if (!defined('ABSPATH'))
20 exit; // Exit if accessed directly
21
22 /**
23 * @since 1.1.0
24 */
25 class WdkListingAgentField extends WdkElementorBase {
26
27 public $field_id = NULL;
28 public $fields_list = array();
29
30 public function __construct($data = array(), $args = null) {
31
32 \Elementor\Controls_Manager::add_tab(
33 'tab_conf',
34 esc_html__('Settings', 'wpdirectorykit')
35 );
36
37 \Elementor\Controls_Manager::add_tab(
38 'tab_layout',
39 esc_html__('Layout', 'wpdirectorykit')
40 );
41
42 \Elementor\Controls_Manager::add_tab(
43 'tab_content',
44 esc_html__('Main', 'wpdirectorykit')
45 );
46
47 add_action( 'elementor/editor/after_enqueue_styles', function()
48 {
49 wp_add_inline_style( 'elementor-editor', '.elementor-control-content select option[value*="section"]{color:#fff;background:#000}');
50 } );
51
52 if ($this->is_edit_mode_load()) {
53 $this->enqueue_styles_scripts();
54 }
55
56 parent::__construct($data, $args);
57
58 }
59
60 /**
61 * Retrieve the list of categories the widget belongs to.
62 *
63 * Used to determine where to display the widget in the editor.
64 *
65 * Note that currently Elementor supports only one category.
66 * When multiple categories passed, Elementor uses the first one.
67 *
68 * @since 1.1.0
69 *
70 * @access public
71 *
72 * @return array Widget categories.
73 */
74 public function get_categories() {
75 return [ 'wdk-elementor-listing-preview' ];
76 }
77
78 /**
79 * Retrieve the widget name.
80 *
81 * @since 1.1.0
82 *
83 * @access public
84 *
85 * @return string Widget name.
86 */
87 public function get_name() {
88 return 'wdk-listing-agent-field';
89 }
90
91 /**
92 * Retrieve the widget title.
93 *
94 * @since 1.1.0
95 *
96 * @access public
97 *
98 * @return string Widget title.
99 */
100 public function get_title() {
101 return esc_html__('Wdk Listing Agent Field', 'wpdirectorykit');
102 }
103
104 /**
105 * Retrieve the widget icon.
106 *
107 * @since 1.1.0
108 *
109 * @access public
110 *
111 * @return string Widget icon.
112 */
113 public function get_icon() {
114 return 'eicon-animation-text';
115 }
116
117 /**
118 * Register the widget controls.
119 *
120 * Adds different input fields to allow the user to change and customize the widget settings.
121 *
122 * @since 1.1.0
123 *
124 * @access protected
125 */
126 protected function register_controls() {
127 $this->generate_controls_conf();
128 $this->generate_controls_layout();
129 $this->generate_controls_styles();
130 $this->generate_controls_content();
131
132 $this->insert_pro_message('1');
133 parent::register_controls();
134 }
135
136 /**
137 * Render the widget output on the frontend.
138 *
139 * Written in PHP and used to generate the final HTML.
140 *
141 * @since 1.1.0
142 *
143 * @access protected
144 */
145 protected function render() {
146 parent::render();
147 global $wdk_listing_id;
148
149 $this->data['id_element'] = $this->get_id();
150 $this->data['settings'] = $this->get_settings();
151
152 $this->data['field_value'] = '';
153 $this->data['field_prefix'] = $this->data['settings']['field_prefix'];
154 $this->data['field_suffix'] = $this->data['settings']['field_suffix'];
155
156 if(!Plugin::$instance->editor->is_edit_mode()){
157 $this->WMVC->model('listing_m');
158 if($this->data['settings']['index_user'] == 0) {
159 $listing = $this->WMVC->listing_m->get($wdk_listing_id, TRUE);
160 if($listing && !empty(wmvc_show_data('user_id_editor', $listing)) ) {
161 $userdata = get_userdata(wmvc_show_data('user_id_editor', $listing));
162 if($userdata && !empty(wmvc_show_data($this->data['settings']['field_id'], $userdata))) {
163 $this->data['field_value'] = wmvc_show_data($this->data['settings']['field_id'], $userdata);
164 }
165 }
166 } else {
167
168 $this->WMVC->model('listingusers_m');
169
170 $this->WMVC->db->limit(1);
171 $this->WMVC->db->offset($this->data['settings']['index_user']-1);
172
173 $listing_alt_agents = $this->WMVC->listingusers_m->get($wdk_listing_id);
174 if(!empty($listing_alt_agents)) {
175 $listing_alt_agents = current($listing_alt_agents);
176 $userdata = get_userdata(wmvc_show_data('user_id', $listing_alt_agents));
177 if($userdata && !empty(wmvc_show_data($this->data['settings']['field_id'], $userdata))) {
178 $this->data['field_value'] = wmvc_show_data($this->data['settings']['field_id'], $userdata);
179 }
180 }
181
182 }
183
184 }
185
186 $this->data['is_edit_mode']= false;
187 if(Plugin::$instance->editor->is_edit_mode()){
188 $this->data['is_edit_mode']= true;
189 if(!empty($this->data['settings']['field_id'])) {
190 $this->data['field_value'] .= esc_html__('Example Field').' '.$this->data['settings']['field_id'];
191 } else {
192 $this->data['field_value'] = esc_html__('Please Set Field');
193 }
194
195 } else {
196 /* return false if no content */
197 if(empty($this->data['field_value']))
198 return false;
199 }
200
201 echo $this->view('wdk-listing-agent-field', $this->data);
202 }
203
204
205 private function generate_controls_conf() {
206 $this->start_controls_section(
207 'tab_conf_main_section',
208 [
209 'label' => esc_html__('Main', 'wpdirectorykit'),
210 'tab' => '1',
211 ]
212 );
213
214 $meta_fields = array(
215 '' => __('Not Selected', 'wpdirectorykit'),
216 'display_name' => __('Display Name', 'wpdirectorykit'),
217 'wdk_phone' => __('Phone', 'wpdirectorykit'),
218 'user_email' => __('Email', 'wpdirectorykit'),
219 'user_url' => __('Url', 'wpdirectorykit'),
220 'description' => __('Bio', 'wpdirectorykit'),
221 'wdk_facebook' => __('Facebook', 'wpdirectorykit'),
222 'wdk_youtube' => __('Youtube', 'wpdirectorykit'),
223 'wdk_address' => __('Address', 'wpdirectorykit'),
224 'wdk_city' => __('City', 'wpdirectorykit'),
225 'wdk_position_title' => __('Position Title', 'wpdirectorykit'),
226 'wdk_linkedin' => __('Linkedin', 'wpdirectorykit'),
227 'wdk_twitter' => __('Twitter', 'wpdirectorykit'),
228 'wdk_telegram' => __('Telegram', 'wpdirectorykit'),
229 'wdk_whatsapp' => __('What`s App', 'wpdirectorykit'),
230 'wdk_viber' => __('Viber', 'wpdirectorykit'),
231 'wdk_iban' => __('IBAN', 'wpdirectorykit'),
232 'wdk_company_name' => __('Company name', 'wpdirectorykit'),
233 'agency_name' => __('Agency Name', 'wpdirectorykit'),
234 );
235
236 $this->add_control(
237 'field_id',
238 [
239 'label' => __( 'Field id', 'wpdirectorykit' ),
240 'type' => \Elementor\Controls_Manager::SELECT2,
241 'default' => '',
242 'options' => $meta_fields,
243 'separator' => 'after',
244 ]
245 );
246
247 $this->add_control(
248 'index_user',
249 [
250 'label' => __( 'Agent Index', 'wpdirectorykit' ),
251 'description' => __( 'Agent id, where 0 is user edit, then 1,2,3,4 ... is alternative agent by index', 'wpdirectorykit' ),
252 'type' => \Elementor\Controls_Manager::NUMBER,
253 'default' => 0,
254 'min' => 0,
255 'max' => 100,
256 'step' => 1,
257 ]
258 );
259
260 $this->add_control(
261 'field_suffix',
262 [
263 'label' => __( 'Label suffix', 'wpdirectorykit' ),
264 'type' => \Elementor\Controls_Manager::TEXT,
265 'default' => '',
266 ]
267 );
268
269 $this->add_control(
270 'field_prefix',
271 [
272 'label' => __( 'Label prefix', 'wpdirectorykit' ),
273 'type' => \Elementor\Controls_Manager::TEXT,
274 'default' => '',
275 ]
276 );
277
278 $this->end_controls_section();
279
280 }
281
282 private function generate_controls_layout() {
283 }
284
285
286 private function generate_controls_styles() {
287 $items = [
288 [
289 'key'=>'field_value',
290 'label'=> esc_html__('Field Label', 'wpdirectorykit'),
291 'selector'=>'.wdk-listing-agent-field',
292 'options'=>'full',
293 ]
294 ];
295
296
297 foreach ($items as $item) {
298 $this->start_controls_section(
299 $item['key'].'_section',
300 [
301 'label' => $item['label'],
302 'tab' => 'tab_layout'
303 ]
304 );
305
306 $selectors = array(
307 'normal' => '{{WRAPPER}} '.$item['selector'],
308 'hover'=>'{{WRAPPER}} '.$item['selector'].'%1$s'
309 );
310 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
311
312
313 $this->end_controls_section();
314 /* END special for some elements */
315 }
316 }
317
318 private function generate_controls_content() {
319
320 }
321
322 public function enqueue_styles_scripts() {
323
324 }
325 }
326