PluginProbe
Flexmls® IDX Plugin / 2.3
Flexmls® IDX Plugin v2.3
4.0.1 4.0.0 3.18.2 trunk 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 2.0 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 2.4.2 3.0.0 3.0.1 3.0.10 3.0.11 All 157 releases
flexmls-idx / components / lead-generation.php

lead-generation.php in Flexmls® IDX Plugin 2.3, at components/lead-generation.php

285 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4
5 class fmcLeadGen extends fmcWidget {
6
7 function fmcLeadGen() {
8 global $fmc_widgets;
9
10 $widget_info = $fmc_widgets[ get_class($this) ];
11
12 $widget_ops = array( 'description' => $widget_info['description'] );
13 $this->WP_Widget( get_class($this) , $widget_info['title'], $widget_ops);
14
15 // have WP replace instances of [first_argument] with the return from the second_argument function
16 add_shortcode($widget_info['shortcode'], array(&$this, 'shortcode'));
17
18 // register where the AJAX calls should be routed when they come in
19 add_action('wp_ajax_fmcLeadGen_submit', array(&$this, 'submit_lead') );
20 add_action('wp_ajax_nopriv_fmcLeadGen_submit', array(&$this, 'submit_lead') );
21
22 add_action('wp_ajax_'.get_class($this).'_shortcode', array(&$this, 'shortcode_form') );
23 add_action('wp_ajax_'.get_class($this).'_shortcode_gen', array(&$this, 'shortcode_generate') );
24
25 }
26
27
28 function jelly($args, $settings, $type) {
29 global $fmc_api;
30 extract($args);
31
32 if ($type == "widget" && empty($settings['title']) && flexmlsConnect::use_default_titles()) {
33 $settings['title'] = "Lead Generation";
34 }
35
36 $return = '';
37
38 $api_prefs = $fmc_api->ConnectPrefs();
39
40 if ($api_prefs === false) {
41 return flexmlsConnect::widget_not_available($fmc_api, false, $args, $settings);
42 }
43
44 if (!array_key_exists('RequiredFields', $api_prefs)) {
45 $api_prefs['RequiredFields'] = array();
46 }
47
48 $title = trim($settings['title']);
49 $blurb = trim($settings['blurb']);
50 $buttontext = trim($settings['buttontext']);
51 if (empty($buttontext)) {
52 $buttontext = "Submit";
53 }
54 $success = trim($settings['success']);
55
56 if (empty($success)) {
57 $success = "Thank you for your request";
58 }
59
60 $return .= $before_widget;
61
62 if ( !empty($title) ) {
63 $return .= $before_title;
64 $return .= $title;
65 $return .= $after_title;
66 $return .= "\n";
67 }
68
69 if ( !empty($blurb) ) {
70 $return .= "<p>{$blurb}</p>\n";
71 }
72
73 $return .= "<form data-connect-validate='true' data-connect-ajax='true' action='".admin_url('admin-ajax.php')."'>\n";
74
75 $return .= "<input type='hidden' name='action' value='fmcLeadGen_submit' />\n";
76 $return .= "<input type='hidden' name='nonce' value='".wp_create_nonce('fmcLeadGen')."' />\n";
77 $return .= "<input type='hidden' name='callback' value='?' />\n";
78 $return .= "<input type='hidden' name='success-message' value='".htmlspecialchars($success, ENT_QUOTES)."' />\n";
79
80 $return .= "<input type='text' name='name' data-connect-default='First and Last Name' data-connect-validate='text' /><br />\n";
81 $return .= "<input type='text' name='email' data-connect-default='Email Address' data-connect-validate='email' /><br />\n";
82
83 if ( in_array('address', $api_prefs['RequiredFields']) ) {
84 $return .= "<input type='text' name='address' data-connect-default='Home Address' data-connect-validate='text' /><br />\n";
85 }
86
87 if ( in_array('address', $api_prefs['RequiredFields']) ) {
88 $return .= "<input type='text' name='city' data-connect-default='City' data-connect-validate='text' /><br />\n";
89 }
90
91 if ( in_array('address', $api_prefs['RequiredFields']) ) {
92 $return .= "<input type='text' name='state' data-connect-default='State' data-connect-validate='text' /><br />\n";
93 }
94
95 if ( in_array('address', $api_prefs['RequiredFields']) ) {
96 $return .= "<input type='text' name='zip' data-connect-default='Zip' data-connect-validate='text' /><br />\n";
97 }
98
99 if ( in_array('phone', $api_prefs['RequiredFields']) ) {
100 $return .= "<input type='text' name='phone' data-connect-default='Phone Number' data-connect-validate='phone' /><br />\n";
101 }
102 $return .= "<br />\n";
103
104 $return .= "<input type='submit' value='{$buttontext}' />\n";
105
106 $return .= "</form>";
107
108 $return .= $after_widget;
109
110 return $return;
111
112 }
113
114
115 function widget($args, $instance) {
116 echo $this->jelly($args, $instance, "widget");
117 }
118
119
120 function shortcode($attr = array()) {
121
122 $args = array(
123 'before_title' => '<h3>',
124 'after_title' => '</h3>',
125 'before_widget' => '',
126 'after_widget' => ''
127 );
128
129 return $this->jelly($args, $attr, "shortcode");
130
131 }
132
133
134 function settings_form($instance) {
135 $title = esc_attr($instance['title']);
136 $blurb = esc_attr($instance['blurb']);
137 $success = esc_attr($instance['success']);
138 $buttontext = esc_attr($instance['buttontext']);
139
140 if (array_key_exists('_instance_type', $instance) && $instance['_instance_type'] == "shortcode") {
141 $special_neighborhood_title_ability = flexmlsConnect::special_location_tag_text();
142 }
143
144 $return = "";
145
146 $return .= "
147
148 <p>
149 <label for='".$this->get_field_id('title')."'>" . __('Title:') . "
150 <input fmc-field='title' fmc-type='text' type='text' class='widefat' id='".$this->get_field_id('title')."' name='".$this->get_field_name('title')."' value='{$title}'>
151 $special_neighborhood_title_ability
152 </label>
153 </p>
154 <p>
155 <label for='".$this->get_field_id('blurb')."'>" . __('Description:') . "
156 <textarea fmc-field='blurb' fmc-type='text' id='".$this->get_field_id('blurb')."' name='".$this->get_field_name('blurb')."'>{$blurb}</textarea>
157 </label><br /><span class='description'>This text appears below the title</span>
158 </p>
159 <p>
160 <label for='".$this->get_field_id('success')."'>" . __('Success Message:') . "
161 <textarea fmc-field='success' fmc-type='text' id='".$this->get_field_id('success')."' name='".$this->get_field_name('success')."'>{$success}</textarea>
162 </label><br /><span class='description'>This text appears after the user sends the information</span>
163 </p>
164 <p>
165 <label for='".$this->get_field_id('buttontext')."'>" . __('Button Text:') . "
166 <input fmc-field='buttontext' fmc-type='text' type='text' class='widefat' id='".$this->get_field_id('buttontext')."' name='".$this->get_field_name('buttontext')."' value='{$buttontext}'>
167 </label><br /><span class='description'>Customize the text of the submit button</span>
168 </p>
169
170 ";
171
172 $return .= "<input type='hidden' name='shortcode_fields_to_catch' value='title,blurb,success,buttontext' />\n";
173 $return .= "<input type='hidden' name='widget' value='". get_class($this) ."' />\n";
174
175 return $return;
176 }
177
178
179
180 function update($new_instance, $old_instance) {
181 $instance = $old_instance;
182
183 $instance['title'] = strip_tags($new_instance['title']);
184 $instance['blurb'] = strip_tags($new_instance['blurb']);
185 $instance['success'] = strip_tags($new_instance['success']);
186 $instance['buttontext'] = strip_tags($new_instance['buttontext']);
187
188 return $instance;
189 }
190
191
192
193 function submit_lead() {
194
195 // verify that the AJAX hit is legit. returns -1 and stops if not
196 check_ajax_referer('fmcLeadGen', 'nonce');
197
198 $fmc_api = new flexmlsApiWp();
199 $fmc_api->Authenticate(true);
200
201 $api_prefs = $fmc_api->ConnectPrefs();
202
203 $data = array();
204
205 $success = true;
206 $message = "";
207
208
209
210 if (is_array($api_prefs) && !array_key_exists('RequiredFields', $api_prefs)) {
211 $api_prefs['RequiredFields'] = array();
212 }
213
214 if (!is_array($api_prefs['RequiredFields'])) {
215 $api_prefs['RequiredFields'] = array();
216 }
217
218 // check to see if all of the required fields were provided to us filled out
219 $data['DisplayName'] = flexmlsConnect::wp_input_get_post('name');
220 if ( in_array('name', $api_prefs['RequiredFields']) && empty($data['DisplayName'] ) ) {
221 $success = false;
222 $message = "Name is a required field.";
223 }
224
225 $data['PrimaryEmail'] = flexmlsConnect::wp_input_get_post('email');
226 if ( in_array('email', $api_prefs['RequiredFields']) && empty($data['PrimaryEmail']) ) {
227 $success = false;
228 $message = "Email Address is a required field.";
229 }
230
231 $data['HomeStreetAddress'] = flexmlsConnect::wp_input_get_post('address');
232 if ( in_array('address', $api_prefs['RequiredFields']) && empty($data['HomeStreetAddress']) ) {
233 $success = false;
234 $message = "Home Address is a required field.";
235 }
236
237 $data['HomeLocality'] = flexmlsConnect::wp_input_get_post('city');
238 if ( in_array('address', $api_prefs['RequiredFields']) && empty($data['HomeLocality']) ) {
239 $success = false;
240 $message = "City is a required field.";
241 }
242
243 $data['HomeRegion'] = flexmlsConnect::wp_input_get_post('state');
244 if ( in_array('address', $api_prefs['RequiredFields']) && empty($data['HomeRegion']) ) {
245 $success = false;
246 $message = "State is a required field.";
247 }
248
249 $data['HomePostalCode'] = flexmlsConnect::wp_input_get_post('zip');
250 if ( in_array('address', $api_prefs['RequiredFields']) && empty($data['HomePostalCode']) ) {
251 $success = false;
252 $message = "Zip is a required field.";
253 }
254
255 $data['PrimaryPhoneNumber'] = flexmlsConnect::wp_input_get_post('phone');
256 if ( in_array('phone', $api_prefs['RequiredFields']) && empty($data['PrimaryPhoneNumber']) ) {
257 $success = false;
258 $message = "Phone Number is a required field.";
259 }
260
261 if ($success == true) {
262 $contact = $fmc_api->SendContact($data);
263 $return = array('success' => true, 'nonce' => wp_create_nonce('fmcLeadGen'));
264 }
265 else {
266 $return = array('success' => false, 'nonce' => wp_create_nonce('fmcLeadGen'), 'message' => $message);
267 }
268
269
270 // the JSON parser included with TinyMCE is favored over PHP's built-in json_encode and json_decode functions
271 // because json_encode/decode weren't included with PHP until 5.2 and TinyMCE's implementation works on earlier
272 // versions of PHP. see http://themocracy.com/2010/02/json-wordpress/
273 require_once(ABSPATH . "/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
274
275 $this->jsObj = new Moxiecode_JSON();
276 echo $this->jsObj->encode($return);
277
278 die();
279
280 }
281
282
283
284 }
285