PluginProbe
WP Directory Kit / 1.2.3
WP Directory Kit v1.2.3
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.2.3, at elementor-elements/classes/wdk-listing-agent-field.php

325 lines 10.0 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 );
234
235 $this->add_control(
236 'field_id',
237 [
238 'label' => __( 'Field id', 'wpdirectorykit' ),
239 'type' => \Elementor\Controls_Manager::SELECT,
240 'default' => '',
241 'options' => $meta_fields,
242 'separator' => 'after',
243 ]
244 );
245
246 $this->add_control(
247 'index_user',
248 [
249 'label' => __( 'Agent Index', 'wpdirectorykit' ),
250 'description' => __( 'Agent id, where 0 is user edit, then 1,2,3,4 ... is alternative agent by index', 'wpdirectorykit' ),
251 'type' => \Elementor\Controls_Manager::NUMBER,
252 'default' => 0,
253 'min' => 0,
254 'max' => 100,
255 'step' => 1,
256 ]
257 );
258
259 $this->add_control(
260 'field_suffix',
261 [
262 'label' => __( 'Label suffix', 'wpdirectorykit' ),
263 'type' => \Elementor\Controls_Manager::TEXT,
264 'default' => '',
265 ]
266 );
267
268 $this->add_control(
269 'field_prefix',
270 [
271 'label' => __( 'Label prefix', 'wpdirectorykit' ),
272 'type' => \Elementor\Controls_Manager::TEXT,
273 'default' => '',
274 ]
275 );
276
277 $this->end_controls_section();
278
279 }
280
281 private function generate_controls_layout() {
282 }
283
284
285 private function generate_controls_styles() {
286 $items = [
287 [
288 'key'=>'field_value',
289 'label'=> esc_html__('Field Label', 'wpdirectorykit'),
290 'selector'=>'.wdk-listing-agent-field',
291 'options'=>'full',
292 ]
293 ];
294
295
296 foreach ($items as $item) {
297 $this->start_controls_section(
298 $item['key'].'_section',
299 [
300 'label' => $item['label'],
301 'tab' => 'tab_layout'
302 ]
303 );
304
305 $selectors = array(
306 'normal' => '{{WRAPPER}} '.$item['selector'],
307 'hover'=>'{{WRAPPER}} '.$item['selector'].'%1$s'
308 );
309 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
310
311
312 $this->end_controls_section();
313 /* END special for some elements */
314 }
315 }
316
317 private function generate_controls_content() {
318
319 }
320
321 public function enqueue_styles_scripts() {
322
323 }
324 }
325