| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly; |
| 3 |
|
| 4 |
class Wdk_settings extends Winter_MVC_Controller { |
| 5 |
public $import_log = ''; |
| 6 |
|
| 7 |
public function __construct(){ |
| 8 |
parent::__construct(); |
| 9 |
} |
| 10 |
|
| 11 |
// Edit listing method |
| 12 |
public function index() |
| 13 |
{ |
| 14 |
$this->load->model('settings_m'); |
| 15 |
$this->data['db_data'] = NULL; |
| 16 |
$this->data['form'] = &$this->form; |
| 17 |
$this->data['fields'] = $this->settings_m->fields_list; |
| 18 |
|
| 19 |
if($this->form->run($this->data['fields'])) |
| 20 |
{ |
| 21 |
// Save procedure for basic data |
| 22 |
|
| 23 |
$data = $this->settings_m->prepare_data($this->input->post(), $this->data['fields']); |
| 24 |
$wdk_slug_listing_preview_page = get_option('wdk_slug_listing_preview_page'); |
| 25 |
|
| 26 |
// Save standard wp post |
| 27 |
foreach($data as $key => $val) |
| 28 |
{ |
| 29 |
update_option( $key, $val, TRUE); |
| 30 |
} |
| 31 |
|
| 32 |
if(isset($data['wdk_slug_listing_preview_page']) && $wdk_slug_listing_preview_page != $data['wdk_slug_listing_preview_page']) { |
| 33 |
update_option('wdk_slug_listing_preview_page_changed', 1); |
| 34 |
} |
| 35 |
|
| 36 |
// redirect |
| 37 |
if(empty($listing_post_id) && !empty($id)) |
| 38 |
{ |
| 39 |
//wp_redirect(admin_url("admin.php?page=wdk_settings&is_updated=true")); |
| 40 |
exit; |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
// fetch data, after update/insert to get updated last data |
| 46 |
$fields_data = $this->settings_m->get(); |
| 47 |
|
| 48 |
/* slug udpate rules*/ |
| 49 |
//flush_rewrite_rules(); |
| 50 |
|
| 51 |
foreach($fields_data as $field) |
| 52 |
{ |
| 53 |
$this->data['db_data'][$field->option_name] = $field->option_value; |
| 54 |
} |
| 55 |
|
| 56 |
$this->load->view('wdk_settings/index', $this->data); |
| 57 |
} |
| 58 |
|
| 59 |
function reset_data () { |
| 60 |
|
| 61 |
$this->load->model('location_m'); |
| 62 |
$this->load->model('category_m'); |
| 63 |
$this->load->model('field_m'); |
| 64 |
$this->load->model('listingfield_m'); |
| 65 |
$this->load->model('listing_m'); |
| 66 |
$this->load->model('resultitem_m'); |
| 67 |
$this->load->model('searchform_m'); |
| 68 |
|
| 69 |
/* remove fields */ |
| 70 |
$this->db->delete($this->location_m->_table_name); |
| 71 |
/* end remove fields */ |
| 72 |
|
| 73 |
/* remove fields */ |
| 74 |
$this->db->delete($this->category_m->_table_name); |
| 75 |
/* end remove fields */ |
| 76 |
|
| 77 |
/* remove fields */ |
| 78 |
$this->db->delete($this->location_m->_table_name); |
| 79 |
/* end remove fields */ |
| 80 |
|
| 81 |
/* remove fields */ |
| 82 |
$this->db->delete($this->field_m->_table_name); |
| 83 |
$field_names = $this->listingfield_m->get_available_fields(); |
| 84 |
foreach($field_names as $field_name => $value){ |
| 85 |
if(strpos($field_name, 'field_') ===FALSE) continue; |
| 86 |
$this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.''); |
| 87 |
} |
| 88 |
/* end remove fields */ |
| 89 |
|
| 90 |
/* remove listings */ |
| 91 |
$this->db->delete($this->listing_m->_table_name); |
| 92 |
$this->db->delete($this->listingfield_m->_table_name); |
| 93 |
/* end remove listings */ |
| 94 |
|
| 95 |
/* reset autoincrement */ |
| 96 |
$this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`'); |
| 97 |
$this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`'); |
| 98 |
$this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`'); |
| 99 |
$this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`'); |
| 100 |
$this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`'); |
| 101 |
/* end reset autoincrement */ |
| 102 |
|
| 103 |
/* remove listings */ |
| 104 |
$this->db->delete($this->resultitem_m->_table_name); |
| 105 |
$this->db->delete($this->searchform_m->_table_name); |
| 106 |
/* end remove listings */ |
| 107 |
|
| 108 |
/* reset autoincrement */ |
| 109 |
$this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`'); |
| 110 |
$this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`'); |
| 111 |
|
| 112 |
$wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1)); |
| 113 |
foreach( $wdk_posts as $post ) { |
| 114 |
// Delete's each post. |
| 115 |
wp_delete_post( $post->ID, true); |
| 116 |
// Set to False if you want to send them to Trash. |
| 117 |
} |
| 118 |
|
| 119 |
$redirect_url = admin_url("admin.php?page=wdk_settings&is_updated"); |
| 120 |
if(isset($_GET['redirect_url'])) |
| 121 |
$redirect_url = sanitize_text_field($_GET['redirect_url']); |
| 122 |
|
| 123 |
wp_redirect($redirect_url); |
| 124 |
exit; |
| 125 |
} |
| 126 |
|
| 127 |
// Import demo data listing method |
| 128 |
public function import_demo() |
| 129 |
{ |
| 130 |
|
| 131 |
$this->load->model('field_m'); |
| 132 |
$this->load->model('listingfield_m'); |
| 133 |
$this->load->model('listing_m'); |
| 134 |
$this->load->model('category_m'); |
| 135 |
$this->load->model('location_m'); |
| 136 |
$this->load->model('searchform_m'); |
| 137 |
$this->load->model('resultitem_m'); |
| 138 |
$this->load->model('listingusers_m'); |
| 139 |
|
| 140 |
$this->data['installed'] = false; |
| 141 |
if($this->field_m->get() || $this->listingfield_m->get() || $this->listing_m->get() || $this->category_m->get() || $this->location_m->get()) |
| 142 |
$this->data['installed'] = true; |
| 143 |
|
| 144 |
$this->data['required_plugins'] = false; |
| 145 |
if(!function_exists('eli_installer') || !function_exists('run_elementinvader') || !is_plugin_active('elementor/elementor.php')) |
| 146 |
$this->data['required_plugins'] = true; |
| 147 |
|
| 148 |
$this->data['db_data'] = NULL; |
| 149 |
$this->data['fields'] = array( |
| 150 |
array('field' => 'import_locations', 'field_label' => __('Locations', 'wpdirectorykit'), 'hint' => __('All Locations will be removed and import demo locations', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 151 |
array('field' => 'import_categories', 'field_label' => __('Categories', 'wpdirectorykit'), 'hint' => __('All categories will be removed and import demo categories', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 152 |
array('field' => 'import_fields', 'field_label' => __('Fields', 'wpdirectorykit'), 'hint' => __('All fiedls will be removed and import demo fields', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 153 |
array('field' => 'import_listings', 'field_label' => __('Listings', 'wpdirectorykit'), 'hint' => __('All listings will be removed and import demo listings', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 154 |
array('field' => 'import_visual_data', 'field_label' => __('Search Form & Result Card', 'wpdirectorykit'), 'hint' => __('Import demo Search Form & Result Card', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 155 |
array('field' => 'import_page_listing_preview', 'field_label' => __('Listing Preview Page', 'wpdirectorykit'), 'hint' => __('Import demo Listing Preivew Page', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 156 |
array('field' => 'import_page_results', 'field_label' => __('Results Page', 'wpdirectorykit'), 'hint' => __('Import demo Results Page', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 157 |
); |
| 158 |
|
| 159 |
$multipurpose_values = array('' => __('Not Selected', 'wpdirectorykit')); |
| 160 |
if(file_exists(WPDIRECTORYKIT_PATH.'/demo-data/')) |
| 161 |
{ |
| 162 |
$files = array(); |
| 163 |
$dir = WPDIRECTORYKIT_PATH.'/demo-data/'; |
| 164 |
if (is_dir($dir)) { |
| 165 |
if ($dh = opendir($dir)) { |
| 166 |
while (($file = readdir($dh)) !== false) { |
| 167 |
if($file == 'locations.xml') continue; |
| 168 |
if(strpos($file, '.xml') !== false && strpos($file, '~') === false) |
| 169 |
$multipurpose_values[$file] = ucwords(str_replace(array('_', '-', '.xml'), ' ', $file)); |
| 170 |
} |
| 171 |
closedir($dh); |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
ksort($multipurpose_values); |
| 176 |
if(count($multipurpose_values) > 0) |
| 177 |
$this->data['fields']['multipurpose'] = array('field'=>'multipurpose', 'field_label'=>__('Portal version', 'wpdirectorykit'), 'field_type'=>'DROPDOWN', 'rules'=>'required', 'values'=>$multipurpose_values); |
| 178 |
|
| 179 |
|
| 180 |
$this->data['form'] = &$this->form; |
| 181 |
ini_set('max_execution_time', 900); |
| 182 |
|
| 183 |
// [/Check requirements] |
| 184 |
|
| 185 |
foreach($this->data['fields'] as $field) |
| 186 |
{ |
| 187 |
$this->data['db_data'][$field['field']] = 1; |
| 188 |
} |
| 189 |
|
| 190 |
if($this->field_m->get()) { |
| 191 |
$this->data['db_data']['import_fields'] = 0; |
| 192 |
} |
| 193 |
if($this->listing_m->get()) { |
| 194 |
$this->data['db_data']['import_listings'] = 0; |
| 195 |
} |
| 196 |
if($this->category_m->get()) { |
| 197 |
$this->data['db_data']['import_categories'] = 0; |
| 198 |
} |
| 199 |
if($this->location_m->get()) { |
| 200 |
$this->data['db_data']['import_locations'] = 0; |
| 201 |
} |
| 202 |
|
| 203 |
if($this->searchform_m->get() || $this->resultitem_m->get()){ |
| 204 |
$this->data['db_data']['import_visual_data'] = 0; |
| 205 |
$this->import_settings(); |
| 206 |
} |
| 207 |
|
| 208 |
if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){ |
| 209 |
$this->data['db_data']['import_page_listing_preview'] = 0; |
| 210 |
} |
| 211 |
|
| 212 |
if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){ |
| 213 |
$this->data['db_data']['import_page_results'] = 0; |
| 214 |
} |
| 215 |
|
| 216 |
$this->data['db_data']['multipurpose'] = 'real-estate.xml'; |
| 217 |
|
| 218 |
if(isset($_GET['multipurpose'])) |
| 219 |
$this->data['db_data']['multipurpose'] = sanitize_text_field($_GET['multipurpose']); |
| 220 |
|
| 221 |
$this->data['import_log'] = ''; |
| 222 |
$rules = array( |
| 223 |
array( |
| 224 |
'field' => 'import_locations', |
| 225 |
'label' => __('Locations', 'wpdirectorykit'), |
| 226 |
'rules' => '' |
| 227 |
), |
| 228 |
array( |
| 229 |
'field' => 'import_categories', |
| 230 |
'label' => __('Categories', 'wpdirectorykit'), |
| 231 |
'rules' => '' |
| 232 |
), |
| 233 |
array( |
| 234 |
'field' => 'import_fields', |
| 235 |
'label' => __('Fields', 'wpdirectorykit'), |
| 236 |
'rules' => '' |
| 237 |
), |
| 238 |
array( |
| 239 |
'field' => 'import_listings', |
| 240 |
'label' => __('Listings', 'wpdirectorykit'), |
| 241 |
'rules' => '' |
| 242 |
), |
| 243 |
array( |
| 244 |
'field' => 'import_visual_data', |
| 245 |
'label' => __('Search Form & Result Card', 'wpdirectorykit'), |
| 246 |
'rules' => '' |
| 247 |
), |
| 248 |
array( |
| 249 |
'field' => 'import_page_listing_preview', |
| 250 |
'label' => __('Listing Preview Page', 'wpdirectorykit'), |
| 251 |
'rules' => '' |
| 252 |
), |
| 253 |
array( |
| 254 |
'field' => 'import_page_results', |
| 255 |
'label' => __('Results Page', 'wpdirectorykit'), |
| 256 |
'rules' => '' |
| 257 |
), |
| 258 |
array( |
| 259 |
'field' => 'multipurpose', |
| 260 |
'label' => __('Purpose', 'wpdirectorykit'), |
| 261 |
'rules' => 'required' |
| 262 |
), |
| 263 |
); |
| 264 |
|
| 265 |
if($this->data['required_plugins'] && isset($_POST['multipurpose'])) { |
| 266 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing required plugins').'</div>'; |
| 267 |
} |
| 268 |
|
| 269 |
if(!$this->data['required_plugins']) |
| 270 |
if($this->form->run($rules)) |
| 271 |
{ |
| 272 |
// Save procedure for basic data |
| 273 |
$data = $this->input->post(); |
| 274 |
|
| 275 |
if( !empty($data['import_locations'])) { |
| 276 |
$this->import_locations(); |
| 277 |
} |
| 278 |
|
| 279 |
if( !empty($data['import_categories'])) { |
| 280 |
$this->import_categories($data['multipurpose']); |
| 281 |
} |
| 282 |
|
| 283 |
if( !empty($data['import_fields'])) { |
| 284 |
$this->import_fields($data['multipurpose']); |
| 285 |
} |
| 286 |
|
| 287 |
if( !empty($data['import_listings'])) { |
| 288 |
$this->import_listings($data['multipurpose']); |
| 289 |
} |
| 290 |
|
| 291 |
if( !empty($data['import_visual_data'])) { |
| 292 |
$this->import_visual_data($data['multipurpose']); |
| 293 |
} |
| 294 |
|
| 295 |
if( !empty($data['import_page_listing_preview'])) { |
| 296 |
$this->demo_page_listing($data['multipurpose']); |
| 297 |
} |
| 298 |
|
| 299 |
if( !empty($data['import_page_results'])) { |
| 300 |
$this->demo_page_results($data['multipurpose']); |
| 301 |
} |
| 302 |
|
| 303 |
$this->replace_content_data($data['multipurpose']); |
| 304 |
|
| 305 |
} |
| 306 |
$this->load->view('wdk_install/index', $this->data); |
| 307 |
} |
| 308 |
|
| 309 |
// Import demo data listing method |
| 310 |
public function remove() |
| 311 |
{ |
| 312 |
$this->load->model('field_m'); |
| 313 |
$this->load->model('listingfield_m'); |
| 314 |
$this->load->model('listing_m'); |
| 315 |
$this->load->model('category_m'); |
| 316 |
$this->load->model('location_m'); |
| 317 |
|
| 318 |
$this->data['data_log'] = ''; |
| 319 |
|
| 320 |
$this->load->model('location_m'); |
| 321 |
$this->load->model('category_m'); |
| 322 |
$this->load->model('field_m'); |
| 323 |
$this->load->model('listingfield_m'); |
| 324 |
$this->load->model('listing_m'); |
| 325 |
$this->load->model('resultitem_m'); |
| 326 |
$this->load->model('searchform_m'); |
| 327 |
|
| 328 |
/* remove fields */ |
| 329 |
$this->db->delete($this->location_m->_table_name); |
| 330 |
|
| 331 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations removed').'</div>'; |
| 332 |
/* end remove fields */ |
| 333 |
|
| 334 |
/* remove fields */ |
| 335 |
$this->db->delete($this->category_m->_table_name); |
| 336 |
|
| 337 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories removed').'</div>'; |
| 338 |
/* end remove fields */ |
| 339 |
|
| 340 |
/* remove fields */ |
| 341 |
$this->db->delete($this->field_m->_table_name); |
| 342 |
$field_names = $this->listingfield_m->get_available_fields(); |
| 343 |
foreach($field_names as $field_name => $value){ |
| 344 |
if(strpos($field_name, 'field_') ===FALSE) continue; |
| 345 |
$this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.''); |
| 346 |
} |
| 347 |
|
| 348 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields removed').'</div>'; |
| 349 |
/* end remove fields */ |
| 350 |
|
| 351 |
/* remove listings */ |
| 352 |
$this->db->delete($this->listing_m->_table_name); |
| 353 |
$this->db->delete($this->listingfield_m->_table_name); |
| 354 |
|
| 355 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings removed').'</div>'; |
| 356 |
/* end remove listings */ |
| 357 |
|
| 358 |
|
| 359 |
/* remove listings */ |
| 360 |
$this->db->delete($this->resultitem_m->_table_name); |
| 361 |
$this->db->delete($this->searchform_m->_table_name); |
| 362 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Result Card And Search form removed').'</div>'; |
| 363 |
/* end remove listings */ |
| 364 |
|
| 365 |
|
| 366 |
/* reset autoincrement */ |
| 367 |
$this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`'); |
| 368 |
$this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`'); |
| 369 |
$this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`'); |
| 370 |
$this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`'); |
| 371 |
$this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`'); |
| 372 |
$this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`'); |
| 373 |
$this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`'); |
| 374 |
|
| 375 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Tables reset').'</div>'; |
| 376 |
/* end reset autoincrement */ |
| 377 |
|
| 378 |
$wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1)); |
| 379 |
foreach( $wdk_posts as $post ) { |
| 380 |
// Delete's each post. |
| 381 |
wp_delete_post( $post->ID, true); |
| 382 |
// Set to False if you want to send them to Trash. |
| 383 |
} |
| 384 |
|
| 385 |
if(isset($_GET['redirect_url'])){ |
| 386 |
if(wmvc_xss_clean($_GET['redirect_url']) =='on_install') { |
| 387 |
$redirect_url = admin_url("admin.php?page=wdk_settings&function=import_demo&is_updated"); |
| 388 |
} else { |
| 389 |
$redirect_url = sanitize_text_field($_GET['redirect_url']); |
| 390 |
} |
| 391 |
wp_redirect($redirect_url); |
| 392 |
} |
| 393 |
|
| 394 |
$this->load->view('wdk_install/remove_log', $this->data); |
| 395 |
} |
| 396 |
|
| 397 |
/* add demo pages */ |
| 398 |
public function demo_pages($purpose = '') { |
| 399 |
|
| 400 |
// if(get_option('wdk_listing_page') || get_option('wdk_results_page')) return true; |
| 401 |
|
| 402 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 403 |
$self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt'); |
| 404 |
}); |
| 405 |
|
| 406 |
add_action('wpdirectorykit/elementor-elements/register_widget', function(){ |
| 407 |
add_action('eli/includes', function(){ |
| 408 |
require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php'; |
| 409 |
}); |
| 410 |
|
| 411 |
add_action('eli/register_widget', function(){ |
| 412 |
$object = new Wdk\Elementor\Extensions\WdkContactFormExt(); |
| 413 |
\Elementor\Plugin::instance()->widgets_manager->register( $object ); |
| 414 |
}); |
| 415 |
}); |
| 416 |
|
| 417 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 418 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel'); |
| 419 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue'); |
| 420 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages'); |
| 421 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon'); |
| 422 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings'); |
| 423 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider'); |
| 424 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection'); |
| 425 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingMap'); |
| 426 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent'); |
| 427 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField'); |
| 428 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar'); |
| 429 |
}); |
| 430 |
|
| 431 |
|
| 432 |
// Import elementor templates |
| 433 |
$page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 434 |
$this->elementor_assign($page_listing_preview->ID, 'page-listing-preview.json'); |
| 435 |
|
| 436 |
$page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 437 |
$this->elementor_assign($page_results->ID, 'page-results-listings.json'); |
| 438 |
|
| 439 |
|
| 440 |
$menus = get_registered_nav_menus(); |
| 441 |
// first menu defined by template |
| 442 |
$first_menu = key($menus); |
| 443 |
|
| 444 |
if ( has_nav_menu($first_menu) ) { |
| 445 |
$menus = wp_get_nav_menus(); |
| 446 |
$menu_id = (int)$menus[0]->term_id; |
| 447 |
} else { |
| 448 |
wp_delete_nav_menu('Primary menu'); |
| 449 |
$menu_name = 'Primary menu'; |
| 450 |
$menu_exists = wp_get_nav_menu_object( $menu_name ); |
| 451 |
$menu_term = $menu_exists; |
| 452 |
$menu_id = wp_create_nav_menu($menu_name); |
| 453 |
} |
| 454 |
|
| 455 |
// first menu defined by template |
| 456 |
if (!empty($menu_id)) { |
| 457 |
$itemData = array( |
| 458 |
'menu-item-object-id' => $page_results->ID, |
| 459 |
'menu-item-title' => esc_html__('Grid Map', 'wpdirectorykit'), |
| 460 |
'menu-item-parent-id' => 0, |
| 461 |
'menu-item-position' => 3, |
| 462 |
'menu-item-object' => 'page', |
| 463 |
'menu-item-type' => 'post_type', |
| 464 |
'menu-item-status' => 'publish' |
| 465 |
); |
| 466 |
|
| 467 |
wp_update_nav_menu_item((int)$menu_id, 0, $itemData); |
| 468 |
|
| 469 |
// assign menu to top menu |
| 470 |
$locations = get_theme_mod( 'nav_menu_locations' ); |
| 471 |
$locations[$first_menu] = $menu_id; |
| 472 |
set_theme_mod('nav_menu_locations', $locations); |
| 473 |
} |
| 474 |
|
| 475 |
// Assign page. |
| 476 |
update_option( 'show_on_front', 'page' ); |
| 477 |
update_option( 'page_on_front', $page_results->ID ); |
| 478 |
|
| 479 |
if($page_listing_preview) |
| 480 |
update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE); |
| 481 |
|
| 482 |
if($page_results) |
| 483 |
update_option( 'wdk_results_page', $page_results->ID, TRUE); |
| 484 |
|
| 485 |
$this->replace_content_data($purpose); |
| 486 |
|
| 487 |
return true; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
private function add_demo_user($username, $name, $surname, $email_address='', $type='wdk_agent', $password=NULL, $meta_data = array()) |
| 492 |
{ |
| 493 |
|
| 494 |
if ( username_exists( $username )) { |
| 495 |
return username_exists( $username ); |
| 496 |
} |
| 497 |
|
| 498 |
if ( email_exists($email_address)) { |
| 499 |
return email_exists($email_address); |
| 500 |
} |
| 501 |
|
| 502 |
if ( empty($email_address)) { |
| 503 |
return false; |
| 504 |
} |
| 505 |
|
| 506 |
// Generate the password and create the user |
| 507 |
if(empty($password)) |
| 508 |
$password = wp_generate_password( 12, false ); |
| 509 |
|
| 510 |
$user_id = wp_create_user( $username, $password, $email_address ); |
| 511 |
|
| 512 |
// Set the nickname |
| 513 |
wp_update_user( |
| 514 |
array( |
| 515 |
'ID' => $user_id, |
| 516 |
'nickname' => $name.' '.$surname, |
| 517 |
'first_name' => $name, |
| 518 |
'last_name' => $surname, |
| 519 |
'description' => 'Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet maurs. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odi non mauris vitae erat consequat Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit.', |
| 520 |
'display_name'=> $name.' '.$surname, |
| 521 |
'user_url' => '' , |
| 522 |
'admin_bar_front' => 0 , |
| 523 |
'wdk_phone' => '123456789' |
| 524 |
) |
| 525 |
); |
| 526 |
|
| 527 |
$user = new WP_User( $user_id ); |
| 528 |
$user->set_role($type); |
| 529 |
|
| 530 |
if(!empty($meta_data)) |
| 531 |
foreach ($meta_data as $meta_key => $meta_value){ |
| 532 |
update_user_meta( $user_id, $meta_key, wmvc_xss_clean($meta_value) ); |
| 533 |
} |
| 534 |
|
| 535 |
update_user_meta( $user_id, 'show_admin_bar_front', 'false' ); |
| 536 |
update_user_meta( $user_id, 'show_admin_bar_admin', 'false' ); |
| 537 |
|
| 538 |
return $user_id; |
| 539 |
} |
| 540 |
|
| 541 |
function replace_content_data($purpose = '') { |
| 542 |
/* Replace Links */ |
| 543 |
/* login */ |
| 544 |
$from = 'https://www.wpdirectorykit.com/nexproperty/wp-admin/wp-login.php'; |
| 545 |
$to = get_admin_url(); |
| 546 |
$this->replace_meta($from, $to); |
| 547 |
|
| 548 |
|
| 549 |
$from = 'https://www.wpdirectorykit.com/nexproperty'; |
| 550 |
$to = get_home_url(); |
| 551 |
$this->replace_meta($from, $to); |
| 552 |
|
| 553 |
/* homepage */ |
| 554 |
$from = '2020'; |
| 555 |
$to = date('Y'); |
| 556 |
$this->replace_meta($from, $to); |
| 557 |
|
| 558 |
|
| 559 |
/* replace in db */ |
| 560 |
$xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose; |
| 561 |
if(file_exists($xml_list)) { |
| 562 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 563 |
if(isset($dom_array['replace']) && !empty($dom_array['replace'])) { |
| 564 |
if(!empty($dom_array['replace']['text'])) { |
| 565 |
foreach($dom_array['replace']['text'] as $string){ |
| 566 |
if(!isset($string['@attributes']) || !isset($string['@attributes']['from']) || !isset($string['@attributes']['to'])) continue; |
| 567 |
if(empty($string['@attributes']['from']) || empty( $string['@attributes']['to'])) continue; |
| 568 |
$this->replace_meta($string['@attributes']['from'], $string['@attributes']['to']); |
| 569 |
} |
| 570 |
} |
| 571 |
} else { |
| 572 |
|
| 573 |
} |
| 574 |
} |
| 575 |
return true; |
| 576 |
|
| 577 |
} |
| 578 |
|
| 579 |
/* add demo listing preview page */ |
| 580 |
public function demo_page_listing($purpose = '') { |
| 581 |
|
| 582 |
if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){ |
| 583 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listing Preview Page already exists').'</div>'; |
| 584 |
return false; |
| 585 |
} |
| 586 |
|
| 587 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 588 |
$self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt'); |
| 589 |
}); |
| 590 |
|
| 591 |
add_action('wpdirectorykit/elementor-elements/register_widget', function(){ |
| 592 |
add_action('eli/includes', function(){ |
| 593 |
require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php'; |
| 594 |
}); |
| 595 |
|
| 596 |
add_action('eli/register_widget', function(){ |
| 597 |
$object = new Wdk\Elementor\Extensions\WdkContactFormExt(); |
| 598 |
\Elementor\Plugin::instance()->widgets_manager->register( $object ); |
| 599 |
}); |
| 600 |
}); |
| 601 |
|
| 602 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 603 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel'); |
| 604 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue'); |
| 605 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages'); |
| 606 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon'); |
| 607 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings'); |
| 608 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider'); |
| 609 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection'); |
| 610 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingMap'); |
| 611 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent'); |
| 612 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField'); |
| 613 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar'); |
| 614 |
}); |
| 615 |
|
| 616 |
// Import elementor templates |
| 617 |
$page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 618 |
$this->elementor_assign($page_listing_preview->ID, 'page-listing-preview.json'); |
| 619 |
|
| 620 |
// Assign page. |
| 621 |
if($page_listing_preview) |
| 622 |
update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE); |
| 623 |
|
| 624 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listing Preview Page imported').'</div>'; |
| 625 |
|
| 626 |
return true; |
| 627 |
} |
| 628 |
|
| 629 |
/* add demo results page */ |
| 630 |
public function demo_page_results($purpose = '') { |
| 631 |
|
| 632 |
if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){ |
| 633 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Results Listings Page already exists').'</div>'; |
| 634 |
return false; |
| 635 |
} |
| 636 |
|
| 637 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 638 |
$self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt'); |
| 639 |
}); |
| 640 |
|
| 641 |
add_action('wpdirectorykit/elementor-elements/register_widget', function(){ |
| 642 |
add_action('eli/includes', function(){ |
| 643 |
require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php'; |
| 644 |
}); |
| 645 |
|
| 646 |
add_action('eli/register_widget', function(){ |
| 647 |
$object = new Wdk\Elementor\Extensions\WdkContactFormExt(); |
| 648 |
\Elementor\Plugin::instance()->widgets_manager->register( $object ); |
| 649 |
}); |
| 650 |
}); |
| 651 |
|
| 652 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 653 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel'); |
| 654 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue'); |
| 655 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages'); |
| 656 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon'); |
| 657 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings'); |
| 658 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider'); |
| 659 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection'); |
| 660 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingMap'); |
| 661 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent'); |
| 662 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField'); |
| 663 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar'); |
| 664 |
}); |
| 665 |
|
| 666 |
$page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 667 |
$this->elementor_assign($page_results->ID, 'page-results-listings.json'); |
| 668 |
|
| 669 |
// Assign page. |
| 670 |
update_option( 'show_on_front', 'page' ); |
| 671 |
update_option( 'page_on_front', $page_results->ID ); |
| 672 |
|
| 673 |
update_option( 'wdk_results_page', $page_results->ID, TRUE); |
| 674 |
|
| 675 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Results Listings Page imported').'</div>'; |
| 676 |
|
| 677 |
|
| 678 |
$menus = get_registered_nav_menus(); |
| 679 |
// first menu defined by template |
| 680 |
$first_menu = key($menus); |
| 681 |
|
| 682 |
if ( has_nav_menu($first_menu) ) { |
| 683 |
$menus = wp_get_nav_menus(); |
| 684 |
$menu_id = (int)$menus[0]->term_id; |
| 685 |
} else { |
| 686 |
wp_delete_nav_menu('Primary menu'); |
| 687 |
$menu_name = 'Primary menu'; |
| 688 |
$menu_exists = wp_get_nav_menu_object( $menu_name ); |
| 689 |
$menu_term = $menu_exists; |
| 690 |
$menu_id = wp_create_nav_menu($menu_name); |
| 691 |
} |
| 692 |
|
| 693 |
// first menu defined by template |
| 694 |
if (!empty($menu_id)) { |
| 695 |
$itemData = array( |
| 696 |
'menu-item-object-id' => $page_results->ID, |
| 697 |
'menu-item-title' => esc_html__('Grid Map', 'wpdirectorykit'), |
| 698 |
'menu-item-parent-id' => 0, |
| 699 |
'menu-item-position' => 3, |
| 700 |
'menu-item-object' => 'page', |
| 701 |
'menu-item-type' => 'post_type', |
| 702 |
'menu-item-status' => 'publish' |
| 703 |
); |
| 704 |
|
| 705 |
wp_update_nav_menu_item((int)$menu_id, 0, $itemData); |
| 706 |
|
| 707 |
// assign menu to top menu |
| 708 |
$locations = get_theme_mod( 'nav_menu_locations' ); |
| 709 |
$locations[$first_menu] = $menu_id; |
| 710 |
set_theme_mod('nav_menu_locations', $locations); |
| 711 |
} |
| 712 |
|
| 713 |
return true; |
| 714 |
} |
| 715 |
|
| 716 |
/* Create Page */ |
| 717 |
function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0) |
| 718 |
{ |
| 719 |
$post = get_page_by_title($post_title, 'OBJECT', 'page' ); |
| 720 |
|
| 721 |
$post_id = NULL; |
| 722 |
|
| 723 |
// Delete posts and rebuild |
| 724 |
if(!empty($post)) |
| 725 |
{ |
| 726 |
wp_delete_post($post->ID, true); |
| 727 |
$post=NULL; |
| 728 |
} |
| 729 |
|
| 730 |
if(!empty($post)) |
| 731 |
$post_id = $post->ID; |
| 732 |
|
| 733 |
if(empty($post_id)) |
| 734 |
{ |
| 735 |
$error_obj = NULL; |
| 736 |
$post_insert = array( |
| 737 |
'post_title' => wp_strip_all_tags( $post_title ), |
| 738 |
'post_content' => $post_content, |
| 739 |
'post_status' => 'publish', |
| 740 |
'post_type' => 'page', |
| 741 |
'post_author' => get_current_user_id(), |
| 742 |
'post_category' => array(1,2), |
| 743 |
'page_template' => $post_template, |
| 744 |
'post_parent' => $post_parent |
| 745 |
); |
| 746 |
$post_id = wp_insert_post( $post_insert, $error_obj ); |
| 747 |
} |
| 748 |
|
| 749 |
$post_insert = get_post( $post_id ); |
| 750 |
|
| 751 |
return $post_insert; |
| 752 |
} |
| 753 |
|
| 754 |
/* Elementor Import Template */ |
| 755 |
private function elementor_assign($page_id, $json_template_name = '') |
| 756 |
{ |
| 757 |
|
| 758 |
$file = false; |
| 759 |
|
| 760 |
if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name)) |
| 761 |
{ |
| 762 |
$file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name; |
| 763 |
} |
| 764 |
elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name)) |
| 765 |
{ |
| 766 |
$file = get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name; |
| 767 |
} |
| 768 |
elseif(file_exists( WPDIRECTORYKIT_PATH. '/demo-data/'.$json_template_name)) |
| 769 |
{ |
| 770 |
$file = WPDIRECTORYKIT_PATH.'/demo-data/'.$json_template_name; |
| 771 |
} |
| 772 |
|
| 773 |
if(!$file || !class_exists('Elementor\Plugin')) |
| 774 |
{ |
| 775 |
return false; |
| 776 |
} |
| 777 |
|
| 778 |
$page_template = get_page_template_slug( $page_id ); |
| 779 |
|
| 780 |
add_post_meta( $page_id, '_elementor_edit_mode', 'builder' ); |
| 781 |
|
| 782 |
global $wp_filesystem; |
| 783 |
// Initialize the WP filesystem, no more using 'file-put-contents' function |
| 784 |
if (empty($wp_filesystem)) { |
| 785 |
WP_Filesystem(); |
| 786 |
} |
| 787 |
|
| 788 |
$string = $wp_filesystem->get_contents($file); |
| 789 |
if ($file == WPDIRECTORYKIT_PATH. '/demo-data/page-listing-preview.json') { |
| 790 |
$str = ''; |
| 791 |
if (function_exists('run_wdk_bookings')) { |
| 792 |
$str = ' { |
| 793 |
"id": "67302676", |
| 794 |
"settings": { |
| 795 |
"title": "Rates / Prices", |
| 796 |
"typography_typography": "custom", |
| 797 |
"typography_font_family": "Montserrat", |
| 798 |
"typography_font_size": { |
| 799 |
"unit": "px", |
| 800 |
"size": 18, |
| 801 |
"sizes": [] |
| 802 |
}, |
| 803 |
"typography_font_weight": "700", |
| 804 |
"_margin": { |
| 805 |
"unit": "px", |
| 806 |
"top": "0", |
| 807 |
"right": "0", |
| 808 |
"bottom": "31", |
| 809 |
"left": "0", |
| 810 |
"isLinked": false |
| 811 |
}, |
| 812 |
"title_color": "#161616" |
| 813 |
}, |
| 814 |
"elements": [], |
| 815 |
"isInner": false, |
| 816 |
"widgetType": "heading", |
| 817 |
"elType": "widget" |
| 818 |
}, |
| 819 |
{ |
| 820 |
"id": "283028da", |
| 821 |
"settings": { |
| 822 |
"_padding": { |
| 823 |
"unit": "px", |
| 824 |
"top": "0", |
| 825 |
"right": "0", |
| 826 |
"bottom": "55", |
| 827 |
"left": "0", |
| 828 |
"isLinked": false |
| 829 |
} |
| 830 |
}, |
| 831 |
"elements": [], |
| 832 |
"isInner": false, |
| 833 |
"widgetType": "wdk-booking-listing-table", |
| 834 |
"elType": "widget" |
| 835 |
}, |
| 836 |
{ |
| 837 |
"id": "1a243dfd", |
| 838 |
"settings": { |
| 839 |
"title": "Availability Calendar", |
| 840 |
"typography_typography": "custom", |
| 841 |
"typography_font_family": "Montserrat", |
| 842 |
"typography_font_size": { |
| 843 |
"unit": "px", |
| 844 |
"size": 18, |
| 845 |
"sizes": [] |
| 846 |
}, |
| 847 |
"typography_font_weight": "700", |
| 848 |
"_margin": { |
| 849 |
"unit": "px", |
| 850 |
"top": "0", |
| 851 |
"right": "0", |
| 852 |
"bottom": "31", |
| 853 |
"left": "0", |
| 854 |
"isLinked": false |
| 855 |
}, |
| 856 |
"title_color": "#161616" |
| 857 |
}, |
| 858 |
"elements": [], |
| 859 |
"isInner": false, |
| 860 |
"widgetType": "heading", |
| 861 |
"elType": "widget" |
| 862 |
}, |
| 863 |
{ |
| 864 |
"id": "4780b1c7", |
| 865 |
"settings": { |
| 866 |
"_margin": { |
| 867 |
"unit": "px", |
| 868 |
"top": "0", |
| 869 |
"right": "0", |
| 870 |
"bottom": "50", |
| 871 |
"left": "0", |
| 872 |
"isLinked": false |
| 873 |
} |
| 874 |
}, |
| 875 |
"elements": [], |
| 876 |
"isInner": false, |
| 877 |
"widgetType": "wdk-booking-listing-calendar", |
| 878 |
"elType": "widget" |
| 879 |
},'; |
| 880 |
} |
| 881 |
$string = str_replace('{booking}', $str, $string); |
| 882 |
|
| 883 |
$str = ''; |
| 884 |
if (function_exists('run_wdk_reviews')) { |
| 885 |
$str = ' { |
| 886 |
"id": "403a73f6", |
| 887 |
"settings": { |
| 888 |
"title": "Reviews", |
| 889 |
"header_size": "span", |
| 890 |
"typography_typography": "custom", |
| 891 |
"typography_font_family": "Montserrat", |
| 892 |
"typography_font_weight": "700", |
| 893 |
"_element_width": "auto", |
| 894 |
"typography_font_size": { |
| 895 |
"unit": "px", |
| 896 |
"size": 18, |
| 897 |
"sizes": [] |
| 898 |
}, |
| 899 |
"_margin": { |
| 900 |
"unit": "px", |
| 901 |
"top": "0", |
| 902 |
"right": "0", |
| 903 |
"bottom": "5", |
| 904 |
"left": "0", |
| 905 |
"isLinked": false |
| 906 |
}, |
| 907 |
"title_color": "#161616" |
| 908 |
}, |
| 909 |
"elements": [], |
| 910 |
"isInner": false, |
| 911 |
"widgetType": "heading", |
| 912 |
"elType": "widget" |
| 913 |
}, |
| 914 |
{ |
| 915 |
"id": "34dd7429", |
| 916 |
"settings": { |
| 917 |
"_margin": { |
| 918 |
"unit": "px", |
| 919 |
"top": "0", |
| 920 |
"right": "0", |
| 921 |
"bottom": "0", |
| 922 |
"left": "5", |
| 923 |
"isLinked": false |
| 924 |
}, |
| 925 |
"_element_width": "auto" |
| 926 |
}, |
| 927 |
"elements": [], |
| 928 |
"isInner": false, |
| 929 |
"widgetType": "wdk-reviews-average-basic", |
| 930 |
"elType": "widget" |
| 931 |
}, |
| 932 |
{ |
| 933 |
"id": "2f7cdac8", |
| 934 |
"settings": { |
| 935 |
"space": { "unit": "px", "size": 1, "sizes": [] }, |
| 936 |
"_padding": { |
| 937 |
"unit": "px", |
| 938 |
"top": "5", |
| 939 |
"right": "0", |
| 940 |
"bottom": "0", |
| 941 |
"left": "0", |
| 942 |
"isLinked": false |
| 943 |
} |
| 944 |
}, |
| 945 |
"elements": [], |
| 946 |
"isInner": false, |
| 947 |
"widgetType": "spacer", |
| 948 |
"elType": "widget" |
| 949 |
}, |
| 950 |
{ |
| 951 |
"id": "30da7684", |
| 952 |
"settings": { |
| 953 |
"average_hide": "none", |
| 954 |
"_margin": { |
| 955 |
"unit": "px", |
| 956 |
"top": "0", |
| 957 |
"right": "0", |
| 958 |
"bottom": "0", |
| 959 |
"left": "0", |
| 960 |
"isLinked": false |
| 961 |
} |
| 962 |
}, |
| 963 |
"elements": [], |
| 964 |
"isInner": false, |
| 965 |
"widgetType": "wdk-reviews-average", |
| 966 |
"elType": "widget" |
| 967 |
}, |
| 968 |
{ |
| 969 |
"id": "6b7a32df", |
| 970 |
"settings": { |
| 971 |
"space": { "unit": "px", "size": 37, "sizes": [] } |
| 972 |
}, |
| 973 |
"elements": [], |
| 974 |
"isInner": false, |
| 975 |
"widgetType": "spacer", |
| 976 |
"elType": "widget" |
| 977 |
}, |
| 978 |
{ |
| 979 |
"id": "38432829", |
| 980 |
"settings": { |
| 981 |
"field_message": "Review", |
| 982 |
"field_message_placeholder": "Write your Review", |
| 983 |
"field_submit": "Send Review", |
| 984 |
"_margin": { |
| 985 |
"unit": "px", |
| 986 |
"top": "0", |
| 987 |
"right": "0", |
| 988 |
"bottom": "45", |
| 989 |
"left": "0", |
| 990 |
"isLinked": false |
| 991 |
}, |
| 992 |
"form_title": "Write a Review", |
| 993 |
"comment_name_dynamic_paddingnormal": { |
| 994 |
"unit": "px", |
| 995 |
"top": "1", |
| 996 |
"right": "1", |
| 997 |
"bottom": "1", |
| 998 |
"left": "1", |
| 999 |
"isLinked": true |
| 1000 |
}, |
| 1001 |
"form_title_dynamic_paddingnormal": { |
| 1002 |
"unit": "px", |
| 1003 |
"top": "0", |
| 1004 |
"right": "0", |
| 1005 |
"bottom": "5", |
| 1006 |
"left": "0", |
| 1007 |
"isLinked": false |
| 1008 |
} |
| 1009 |
}, |
| 1010 |
"elements": [], |
| 1011 |
"isInner": false, |
| 1012 |
"widgetType": "wdk-reviews-list", |
| 1013 |
"elType": "widget" |
| 1014 |
}, |
| 1015 |
'; |
| 1016 |
} |
| 1017 |
$string = str_replace('{reviews}', $str, $string); |
| 1018 |
|
| 1019 |
$str = ''; |
| 1020 |
if (function_exists('run_wdk_mortgage')) { |
| 1021 |
$str = ' { |
| 1022 |
"id": "7bfe253b", |
| 1023 |
"settings": { |
| 1024 |
"box_shadow_box_shadow_type": "yes", |
| 1025 |
"box_shadow_box_shadow": { |
| 1026 |
"horizontal": 0, |
| 1027 |
"vertical": 0, |
| 1028 |
"blur": 10, |
| 1029 |
"spread": 0, |
| 1030 |
"color": "rgba(1, 1, 1, 0.11)" |
| 1031 |
}, |
| 1032 |
"margin": { |
| 1033 |
"unit": "px", |
| 1034 |
"top": "0", |
| 1035 |
"right": 0, |
| 1036 |
"bottom": "35", |
| 1037 |
"left": 0, |
| 1038 |
"isLinked": false |
| 1039 |
} |
| 1040 |
}, |
| 1041 |
"elements": [ |
| 1042 |
{ |
| 1043 |
"id": "5da49154", |
| 1044 |
"settings": { |
| 1045 |
"_column_size": 100, |
| 1046 |
"_inline_size": null, |
| 1047 |
"content_position": "top", |
| 1048 |
"align": "flex-start", |
| 1049 |
"space_between_widgets": 0, |
| 1050 |
"padding": { |
| 1051 |
"unit": "px", |
| 1052 |
"top": "25", |
| 1053 |
"right": "25", |
| 1054 |
"bottom": "25", |
| 1055 |
"left": "25", |
| 1056 |
"isLinked": false |
| 1057 |
} |
| 1058 |
}, |
| 1059 |
"elements": [ |
| 1060 |
{ |
| 1061 |
"id": "3db04015", |
| 1062 |
"settings": { |
| 1063 |
"title": "Mortgage", |
| 1064 |
"typography_typography": "custom", |
| 1065 |
"typography_font_family": "Montserrat", |
| 1066 |
"typography_font_size": { |
| 1067 |
"unit": "px", |
| 1068 |
"size": 16, |
| 1069 |
"sizes": [] |
| 1070 |
}, |
| 1071 |
"typography_font_weight": "700", |
| 1072 |
"_margin": { |
| 1073 |
"unit": "px", |
| 1074 |
"top": "0", |
| 1075 |
"right": "0", |
| 1076 |
"bottom": "0", |
| 1077 |
"left": "0", |
| 1078 |
"isLinked": false |
| 1079 |
}, |
| 1080 |
"_padding": { |
| 1081 |
"unit": "px", |
| 1082 |
"top": "0", |
| 1083 |
"right": "0", |
| 1084 |
"bottom": "27", |
| 1085 |
"left": "0", |
| 1086 |
"isLinked": false |
| 1087 |
}, |
| 1088 |
"typography_letter_spacing": { |
| 1089 |
"unit": "px", |
| 1090 |
"size": -0.4, |
| 1091 |
"sizes": [] |
| 1092 |
}, |
| 1093 |
"title_color": "#161616" |
| 1094 |
}, |
| 1095 |
"elements": [], |
| 1096 |
"isInner": false, |
| 1097 |
"widgetType": "heading", |
| 1098 |
"elType": "widget" |
| 1099 |
}, |
| 1100 |
{ |
| 1101 |
"id": "263622d0", |
| 1102 |
"settings": { |
| 1103 |
"field_currency": "$", |
| 1104 |
"field_product_price_label": "Home Price", |
| 1105 |
"field_product_price_placeholder": "Home Price", |
| 1106 |
"field_down_payment_label": "Down Payment", |
| 1107 |
"field_down_payment_placeholder": "Down Payment", |
| 1108 |
"field_mortgage_rate_label": "Mortgage Interest Rate", |
| 1109 |
"field_mortgage_rate_placeholder": "Mortgage Rate", |
| 1110 |
"field_years_label": "Years", |
| 1111 |
"field_years_placeholder": "Loan Years", |
| 1112 |
"field_submit": "Calculate", |
| 1113 |
"_padding": { |
| 1114 |
"unit": "px", |
| 1115 |
"top": "0", |
| 1116 |
"right": "0", |
| 1117 |
"bottom": "0", |
| 1118 |
"left": "0", |
| 1119 |
"isLinked": false |
| 1120 |
} |
| 1121 |
}, |
| 1122 |
"elements": [], |
| 1123 |
"isInner": false, |
| 1124 |
"widgetType": "wdk-mortgage-calculator", |
| 1125 |
"elType": "widget" |
| 1126 |
} |
| 1127 |
], |
| 1128 |
"isInner": true, |
| 1129 |
"elType": "column" |
| 1130 |
} |
| 1131 |
], |
| 1132 |
"isInner": true, |
| 1133 |
"elType": "section" |
| 1134 |
}, |
| 1135 |
'; |
| 1136 |
} |
| 1137 |
$string = str_replace('{mortgage}', $str, $string); |
| 1138 |
} |
| 1139 |
|
| 1140 |
$json_template = json_decode($string, true); |
| 1141 |
$elements = $json_template['content']; |
| 1142 |
|
| 1143 |
$data = array( |
| 1144 |
'elements' => $elements, |
| 1145 |
'settings' => array('post_status'=>'autosave', 'template'=>$page_template), |
| 1146 |
); |
| 1147 |
// @codingStandardsIgnoreStart |
| 1148 |
$document = Elementor\Plugin::$instance->documents->get( $page_id, false ); |
| 1149 |
// @codingStandardsIgnoreEnd |
| 1150 |
return $document->save( $data ); |
| 1151 |
} |
| 1152 |
|
| 1153 |
private function import_visual_data($purpose = '') { |
| 1154 |
$this->load->model('searchform_m'); |
| 1155 |
$this->load->model('resultitem_m'); |
| 1156 |
$this->load->model('field_m'); |
| 1157 |
|
| 1158 |
if($this->searchform_m->get() || $this->resultitem_m->get()){ |
| 1159 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Search and result card already imported', 'wpdirectorykit').'</div>'; |
| 1160 |
return false; |
| 1161 |
} |
| 1162 |
|
| 1163 |
/* remove listings */ |
| 1164 |
$this->db->delete($this->resultitem_m->_table_name); |
| 1165 |
$this->db->delete($this->searchform_m->_table_name); |
| 1166 |
/* end remove listings */ |
| 1167 |
|
| 1168 |
/* reset autoincrement */ |
| 1169 |
$this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`'); |
| 1170 |
$this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`'); |
| 1171 |
|
| 1172 |
$xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose; |
| 1173 |
if(file_exists($xml_list)) { |
| 1174 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 1175 |
|
| 1176 |
if(!isset($dom_array['search_form']) && empty($dom_array['search_form'])) { |
| 1177 |
} else { |
| 1178 |
// Save searchform_m |
| 1179 |
$data = array(); |
| 1180 |
$data['searchform_name'] = 'Primary'; |
| 1181 |
$data['searchform_json'] = trim($dom_array['search_form']); |
| 1182 |
|
| 1183 |
if (function_exists('run_wdk_bookings') && isset($dom_array['search_form_premium']) && !empty($dom_array['search_form_premium'])) { |
| 1184 |
$data['searchform_json'] = trim($dom_array['search_form_premium']); |
| 1185 |
} |
| 1186 |
|
| 1187 |
$data['idsearchform'] = 1; |
| 1188 |
$insert_id = $this->searchform_m->insert($data, NULL); |
| 1189 |
} |
| 1190 |
|
| 1191 |
if(!isset($dom_array['resultitem']) && empty($dom_array['resultitem'])) { |
| 1192 |
} else { |
| 1193 |
// Save searchform_m |
| 1194 |
$data = array(); |
| 1195 |
$data['resultitem_name'] = 'Primary'; |
| 1196 |
$data['resultitem_json'] = trim($dom_array['resultitem']); |
| 1197 |
$data['idresultitem'] = 1; |
| 1198 |
$insert_id = $this->resultitem_m->insert($data, NULL); |
| 1199 |
} |
| 1200 |
|
| 1201 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Search Form & Result Card imported').'</div>'; |
| 1202 |
return true; |
| 1203 |
} |
| 1204 |
|
| 1205 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1206 |
return false; |
| 1207 |
|
| 1208 |
} |
| 1209 |
|
| 1210 |
private function import_locations() { |
| 1211 |
$xml_list = WPDIRECTORYKIT_PATH.'/demo-data/locations.xml'; |
| 1212 |
$this->load->model('location_m'); |
| 1213 |
|
| 1214 |
if($this->location_m->get()){ |
| 1215 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>'; |
| 1216 |
return false; |
| 1217 |
} |
| 1218 |
|
| 1219 |
if(file_exists($xml_list)) { |
| 1220 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 1221 |
if(!isset($dom_array['locations']['location']) && empty($dom_array['locations']['location'])) { |
| 1222 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1223 |
return false; |
| 1224 |
} |
| 1225 |
foreach ($dom_array['locations']['location'] as $key => $location_data) { |
| 1226 |
$this->_recursive_add_locations($location_data); |
| 1227 |
} |
| 1228 |
|
| 1229 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations imported').'</div>'; |
| 1230 |
return true; |
| 1231 |
} |
| 1232 |
|
| 1233 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1234 |
return false; |
| 1235 |
} |
| 1236 |
|
| 1237 |
private function _recursive_add_locations ($data = array(), $parent_id = 0, $level = 0 ) { |
| 1238 |
$base = array( |
| 1239 |
'location_title' => '', |
| 1240 |
'parent_id' => $parent_id, |
| 1241 |
'order_index' => '', |
| 1242 |
'level' => $level, |
| 1243 |
'font_icon_code' => '', |
| 1244 |
'image_id' => '', |
| 1245 |
'icon_id' => '', |
| 1246 |
'code' => '', |
| 1247 |
); |
| 1248 |
$location_data = array_intersect_key(array_merge($base, $data), $base); |
| 1249 |
array_walk($location_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 1250 |
|
| 1251 |
if(empty(wmvc_show_data('location_title', $location_data))) { |
| 1252 |
return false; |
| 1253 |
} |
| 1254 |
|
| 1255 |
if(!empty($location_data['image_id']) && file_exists(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['image_id'])){ |
| 1256 |
/* add files */ |
| 1257 |
$location_data['image_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['image_id']); |
| 1258 |
} |
| 1259 |
|
| 1260 |
if(!empty($location_data['icon_id']) && file_exists(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['icon_id'])){ |
| 1261 |
/* add files */ |
| 1262 |
$location_data['icon_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['icon_id']); |
| 1263 |
} |
| 1264 |
|
| 1265 |
/* add locations */ |
| 1266 |
$insert_id = $this->location_m->insert($location_data, NULL); |
| 1267 |
if(isset($data['childs']["location"]) && !empty($data['childs']["location"])) { |
| 1268 |
foreach ($data['childs']["location"] as $sub_location_data) { |
| 1269 |
$this->_recursive_add_locations($sub_location_data, $insert_id, ($level+1)); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
private function import_categories($purpose = '') { |
| 1275 |
$xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose; |
| 1276 |
$this->load->model('category_m'); |
| 1277 |
|
| 1278 |
if($this->category_m->get()){ |
| 1279 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>'; |
| 1280 |
return false; |
| 1281 |
} |
| 1282 |
|
| 1283 |
if(file_exists($xml_list)) { |
| 1284 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 1285 |
if(!isset($dom_array['categories']['category']) && empty($dom_array['categories']['category'])) { |
| 1286 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1287 |
return false; |
| 1288 |
} |
| 1289 |
|
| 1290 |
foreach ($dom_array['categories']['category'] as $key => $category_data) { |
| 1291 |
$this->_recursive_add_categories($category_data); |
| 1292 |
} |
| 1293 |
|
| 1294 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories imported').'</div>'; |
| 1295 |
return true; |
| 1296 |
} |
| 1297 |
|
| 1298 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1299 |
return false; |
| 1300 |
} |
| 1301 |
|
| 1302 |
private function _recursive_add_categories ($data = array(), $parent_id = 0, $level = 0 ) { |
| 1303 |
$base = array( |
| 1304 |
'category_title' => '', |
| 1305 |
'parent_id' => $parent_id, |
| 1306 |
'order_index' => '', |
| 1307 |
'level' => $level, |
| 1308 |
'font_icon_code' => '', |
| 1309 |
'image_id' => '', |
| 1310 |
'icon_id' => '', |
| 1311 |
'code' => '', |
| 1312 |
); |
| 1313 |
|
| 1314 |
$category_data = array_intersect_key(array_merge($base, $data), $base); |
| 1315 |
array_walk($category_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 1316 |
|
| 1317 |
if(empty(wmvc_show_data('category_title', $category_data))) { |
| 1318 |
return false; |
| 1319 |
} |
| 1320 |
|
| 1321 |
if(!empty($category_data['image_id'])){ |
| 1322 |
|
| 1323 |
$file = false; |
| 1324 |
if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['image_id'])) |
| 1325 |
{ |
| 1326 |
$file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['image_id']; |
| 1327 |
} |
| 1328 |
elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id'])) |
| 1329 |
{ |
| 1330 |
$file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id']; |
| 1331 |
} |
| 1332 |
elseif(file_exists( WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['image_id'])) |
| 1333 |
{ |
| 1334 |
$file = WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['image_id']; |
| 1335 |
} |
| 1336 |
/* add files */ |
| 1337 |
|
| 1338 |
if($file) |
| 1339 |
$category_data['image_id'] = wmvc_add_wp_image($file); |
| 1340 |
} |
| 1341 |
|
| 1342 |
if(!empty($category_data['icon_id'])){ |
| 1343 |
/* add files */ |
| 1344 |
$file = false; |
| 1345 |
if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['icon_id'])) |
| 1346 |
{ |
| 1347 |
$file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['icon_id']; |
| 1348 |
} |
| 1349 |
elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id'])) |
| 1350 |
{ |
| 1351 |
$file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id']; |
| 1352 |
} |
| 1353 |
elseif(file_exists( WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['icon_id'])) |
| 1354 |
{ |
| 1355 |
$file = WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['icon_id']; |
| 1356 |
} |
| 1357 |
/* add files */ |
| 1358 |
|
| 1359 |
if($file) |
| 1360 |
$category_data['icon_id'] = wmvc_add_wp_image($file); |
| 1361 |
} |
| 1362 |
|
| 1363 |
/* add categories */ |
| 1364 |
$insert_id = $this->category_m->insert($category_data, NULL); |
| 1365 |
if(isset($data['childs']["category"]) && !empty($data['childs']["category"])) { |
| 1366 |
foreach ($data['childs']["category"] as $sub_category_data) { |
| 1367 |
$this->_recursive_add_categories($sub_category_data, $insert_id, ($level+1)); |
| 1368 |
} |
| 1369 |
} |
| 1370 |
} |
| 1371 |
|
| 1372 |
private function import_fields($purpose = '') { |
| 1373 |
$this->load->model('field_m'); |
| 1374 |
$this->load->model('listingfield_m'); |
| 1375 |
|
| 1376 |
if($this->field_m->get()){ |
| 1377 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Fields already imported', 'wpdirectorykit').'</div>'; |
| 1378 |
return false; |
| 1379 |
} |
| 1380 |
|
| 1381 |
$xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose; |
| 1382 |
|
| 1383 |
$sections_added_array = array(); |
| 1384 |
if(file_exists($xml_list)) { |
| 1385 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 1386 |
|
| 1387 |
$base = array( |
| 1388 |
'field_type' => '', |
| 1389 |
'field_label' => '', |
| 1390 |
'hint' => '', |
| 1391 |
'columns_number' => '', |
| 1392 |
'is_visible_frontend' => '', |
| 1393 |
'is_visible_dashboard' => '', |
| 1394 |
'prefix' => '', |
| 1395 |
'suffix' => '', |
| 1396 |
'values_list' => '', |
| 1397 |
'icon_id' => '', |
| 1398 |
'is_required' => '', |
| 1399 |
); |
| 1400 |
|
| 1401 |
if(!isset($dom_array['fields']['field']) && empty($dom_array['fields']['field'])) { |
| 1402 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1403 |
return false; |
| 1404 |
} |
| 1405 |
|
| 1406 |
foreach ($dom_array['fields']['field'] as $key => $field) { |
| 1407 |
$field_data = array_intersect_key(array_merge($base, $field), $base); |
| 1408 |
array_walk($field_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 1409 |
|
| 1410 |
if(empty(wmvc_show_data('field_type', $field_data)) || empty(wmvc_show_data('field_label', $field_data))) { |
| 1411 |
continue; |
| 1412 |
} |
| 1413 |
|
| 1414 |
if(!in_array($field['section'], $sections_added_array)) { |
| 1415 |
/* add section */ |
| 1416 |
$section_data = array( |
| 1417 |
'field_type' => 'SECTION', |
| 1418 |
'field_label' => $field['section'], |
| 1419 |
'columns_number' => '12', |
| 1420 |
'is_visible_frontend' => '', |
| 1421 |
'is_visible_dashboard' => '', |
| 1422 |
); |
| 1423 |
/* add field */ |
| 1424 |
$this->field_m->insert($section_data, NULL); |
| 1425 |
|
| 1426 |
$sections_added_array[] = $field['section']; |
| 1427 |
} |
| 1428 |
|
| 1429 |
/* add field */ |
| 1430 |
$insert_id = $this->field_m->insert($field_data, NULL); |
| 1431 |
// check if column exists, add if nto exists |
| 1432 |
if(!empty($insert_id)) |
| 1433 |
$this->listingfield_m->create_table_column($field_data, $insert_id); |
| 1434 |
} |
| 1435 |
|
| 1436 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields imported').'</div>'; |
| 1437 |
return true; |
| 1438 |
} |
| 1439 |
|
| 1440 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1441 |
return false; |
| 1442 |
} |
| 1443 |
|
| 1444 |
private function import_listings($purpose = '') { |
| 1445 |
$this->load->model('field_m'); |
| 1446 |
$this->load->model('listingfield_m'); |
| 1447 |
$this->load->model('listing_m'); |
| 1448 |
$this->load->model('category_m'); |
| 1449 |
$this->load->model('location_m'); |
| 1450 |
$this->load->model('listingusers_m'); |
| 1451 |
|
| 1452 |
if($this->listing_m->get()){ |
| 1453 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listings already imported', 'wpdirectorykit').'</div>'; |
| 1454 |
return false; |
| 1455 |
} |
| 1456 |
|
| 1457 |
/* generate listings */ |
| 1458 |
$categories_list = $this->category_m->get(); |
| 1459 |
$locations_list = $this->location_m->get(); |
| 1460 |
$categories = array(); |
| 1461 |
$locations = array(); |
| 1462 |
if($categories_list) |
| 1463 |
foreach($categories_list as $category){ |
| 1464 |
$categories[] = $category->idcategory; |
| 1465 |
} |
| 1466 |
if($locations_list) |
| 1467 |
foreach($locations_list as $location){ |
| 1468 |
$locations[] = $location->idlocation; |
| 1469 |
} |
| 1470 |
|
| 1471 |
$this->db->where(array('field_type !='=> 'SECTION')); |
| 1472 |
$fields = $this->field_m->get(); |
| 1473 |
|
| 1474 |
$listingfield_list = $this->listingfield_m->get_available_fields(); |
| 1475 |
foreach($fields as $key => $field_data) { |
| 1476 |
if(!isset($listingfield_list['field_'.$field_data->idfield.'_'.$field_data->field_type])) { |
| 1477 |
unset($fields[$key]); |
| 1478 |
} |
| 1479 |
} |
| 1480 |
|
| 1481 |
// Open a known directory, and proceed to read its contents |
| 1482 |
$dir = WPDIRECTORYKIT_PATH.'/demo-data/images'; |
| 1483 |
$purpose_name = str_replace('.xml','',$purpose); |
| 1484 |
$files = array(); |
| 1485 |
if (is_dir($dir)) { |
| 1486 |
if ($dh = opendir($dir)) { |
| 1487 |
while (($file = readdir($dh)) !== false) { |
| 1488 |
if(strpos($file, '.jpg') !== false && strpos($file, $purpose_name) !== false && strpos($file, 'category') === false) |
| 1489 |
$files[] = $file; |
| 1490 |
} |
| 1491 |
closedir($dh); |
| 1492 |
} |
| 1493 |
} |
| 1494 |
sort($files); |
| 1495 |
|
| 1496 |
$xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose; |
| 1497 |
if(file_exists($xml_list)) { |
| 1498 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 1499 |
if(!isset($dom_array['listings']['listing']) && empty($dom_array['listings']['listing'])) { |
| 1500 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No listings in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1501 |
return false; |
| 1502 |
} |
| 1503 |
|
| 1504 |
/* demo agent add/get if exists */ |
| 1505 |
$user_ids = array(); |
| 1506 |
$user_ids[] = $this->add_demo_user('Debra_Moran', 'Debra', 'Moran', 'agent1@wpdirectorykit.com','wdk_agent', NULL, array('wdk_phone' =>'(917) 367-2058','wdk_facebook'=>'#','wdk_linkedin'=>'#','wdk_instagram'=>'#','wdk_telegram'=>'#','wdk_twitter'=>'#')); |
| 1507 |
$user_ids[] = $this->add_demo_user('Garry_Novan', 'Garry', 'Novan', 'agent2@wpdirectorykit.com','wdk_agent', NULL, array('wdk_phone' =>'(918) 345-2054','wdk_facebook'=>'#','wdk_linkedin'=>'#','wdk_instagram'=>'#','wdk_telegram'=>'#','wdk_twitter'=>'#')); |
| 1508 |
$user_ids[] = $this->add_demo_user('Kety_Spear', 'Kety', 'Spear', 'agent3@wpdirectorykit.com','wdk_agent', NULL, array('wdk_phone' =>'(919) 854-2056','wdk_facebook'=>'#','wdk_linkedin'=>'#','wdk_instagram'=>'#','wdk_telegram'=>'#','wdk_twitter'=>'#')); |
| 1509 |
|
| 1510 |
foreach ($dom_array['listings']['listing'] as $listing_num => $listing) { |
| 1511 |
$location_id = ''; |
| 1512 |
$category_id = ''; |
| 1513 |
|
| 1514 |
if(!empty($categories)) |
| 1515 |
$category_id = $categories[rand(0, count($categories)-1)]; |
| 1516 |
|
| 1517 |
if(!empty($location)) |
| 1518 |
$location_id = $locations[rand(0, count($locations)-1)]; |
| 1519 |
|
| 1520 |
$data_listing = array( |
| 1521 |
'post_title' => '', |
| 1522 |
'post_content' => '', |
| 1523 |
'category_id' => $category_id, |
| 1524 |
'location_id' => $location_id, |
| 1525 |
'address' => '', |
| 1526 |
'lat' => '', |
| 1527 |
'listing_images' => '', |
| 1528 |
'date_modified' => date('Y-m-d H:i:s'), |
| 1529 |
'lng' => '', |
| 1530 |
'is_featured' => '', |
| 1531 |
'is_activated' => '1', |
| 1532 |
'is_approved' => '1', |
| 1533 |
); |
| 1534 |
|
| 1535 |
$data_listing = array_intersect_key(array_merge($data_listing, $listing), $data_listing); |
| 1536 |
array_walk($data_listing, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 1537 |
|
| 1538 |
if(empty(wmvc_show_data('post_title', $data_listing))) { |
| 1539 |
continue; |
| 1540 |
} |
| 1541 |
|
| 1542 |
/*fields */ |
| 1543 |
foreach($fields as $field_data) { |
| 1544 |
if(isset($listing['field_'.$field_data->idfield])) { |
| 1545 |
$data_listing['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield]; |
| 1546 |
} else { |
| 1547 |
if($field_data->field_type == 'DROPDOWN' || $field_data->field_type == 'DROPDOWN_MULTIPLE') |
| 1548 |
{ |
| 1549 |
if(empty($field_data->values_list)) continue; |
| 1550 |
$values = explode(',', $field_data->values_list); |
| 1551 |
if(count($values) > 0) |
| 1552 |
{ |
| 1553 |
$start=0; |
| 1554 |
if(empty($values[0]))$start=1; |
| 1555 |
$data_listing['field_'.$field_data->idfield] = $values[rand($start, count($values)-1)]; |
| 1556 |
} |
| 1557 |
} |
| 1558 |
elseif($field_data->field_type == 'NUMBER') |
| 1559 |
{ |
| 1560 |
$data_listing['field_'.$field_data->idfield] = rand(2,499); |
| 1561 |
} |
| 1562 |
elseif($field_data->field_type == 'CHECKBOX') |
| 1563 |
{ |
| 1564 |
$data_listing['field_'.$field_data->idfield] = rand(0,1); |
| 1565 |
} |
| 1566 |
elseif($field_data->field_type == 'TEXTAREA') |
| 1567 |
{ |
| 1568 |
//$data_listing['field_'.$field_data->idfield] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; |
| 1569 |
} |
| 1570 |
} |
| 1571 |
} |
| 1572 |
|
| 1573 |
/* add files */ |
| 1574 |
$count_images = 2; |
| 1575 |
if($purpose == 'car-dealer.xml') { |
| 1576 |
$count_images = 1; |
| 1577 |
} |
| 1578 |
|
| 1579 |
for ($i=0,$image_num=$listing_num; $i<$count_images; $i++,$image_num++) { |
| 1580 |
if($image_num >= count($files)) |
| 1581 |
$image_num = 0; |
| 1582 |
|
| 1583 |
if(!empty($data_listing['listing_images'])) |
| 1584 |
$data_listing['listing_images'].= ','; |
| 1585 |
|
| 1586 |
$data_listing['listing_images'] .= wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'/demo-data/images/'.esc_html($files[$image_num])); |
| 1587 |
} |
| 1588 |
|
| 1589 |
// Create post object |
| 1590 |
$listing_post = array( |
| 1591 |
'ID' => NULL, |
| 1592 |
'post_type' => 'wdk-listing', |
| 1593 |
'post_title' => wp_strip_all_tags( $data_listing['post_title'] ), |
| 1594 |
'post_content' => $data_listing['post_content'], |
| 1595 |
'post_status' => 'publish', |
| 1596 |
'post_author' => get_current_user_id() |
| 1597 |
); |
| 1598 |
// Insert the post into the database |
| 1599 |
$id = wp_insert_post( $listing_post ); |
| 1600 |
|
| 1601 |
$listing_data = array('post_id' => $id); |
| 1602 |
$listing_data_fields = array('category_id', 'location_id', 'address', 'lat', 'lng', 'listing_images', 'is_featured', 'is_activated','is_approved'); |
| 1603 |
foreach($listing_data_fields as $field_name) |
| 1604 |
{ |
| 1605 |
if(isset( $data_listing[$field_name])) |
| 1606 |
$listing_data[$field_name] = $data_listing[$field_name]; |
| 1607 |
} |
| 1608 |
|
| 1609 |
$this->listing_m->insert($listing_data, NULL); |
| 1610 |
|
| 1611 |
$data_listing['post_id'] = $id; |
| 1612 |
$this->listingfield_m->insert_custom_fields($fields, $data_listing, NULL); |
| 1613 |
|
| 1614 |
$this->listingusers_m->insert(array('post_id' => $id, 'user_id' => $user_ids[array_rand($user_ids)]), NULL); |
| 1615 |
} |
| 1616 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported').'</div>'; |
| 1617 |
return true; |
| 1618 |
} |
| 1619 |
|
| 1620 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1621 |
return false; |
| 1622 |
} |
| 1623 |
|
| 1624 |
protected function xmlstr_to_array($xmlstr) { |
| 1625 |
$doc = new DOMDocument(); |
| 1626 |
|
| 1627 |
if ( !@$doc->loadXML($xmlstr) ) { |
| 1628 |
return false; |
| 1629 |
} |
| 1630 |
|
| 1631 |
$root = $doc->documentElement; |
| 1632 |
$output = $this->domnode_to_array($root); |
| 1633 |
$output['@root'] = $root->tagName; |
| 1634 |
return $output; |
| 1635 |
} |
| 1636 |
|
| 1637 |
protected function domnode_to_array($node) { |
| 1638 |
$output = array(); |
| 1639 |
switch ($node->nodeType) { |
| 1640 |
case XML_CDATA_SECTION_NODE: |
| 1641 |
case XML_TEXT_NODE: |
| 1642 |
$output = trim($node->textContent); |
| 1643 |
break; |
| 1644 |
case XML_ELEMENT_NODE: |
| 1645 |
for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) { |
| 1646 |
$child = $node->childNodes->item($i); |
| 1647 |
$v = $this->domnode_to_array($child); |
| 1648 |
if(isset($child->tagName)) { |
| 1649 |
$t = $child->tagName; |
| 1650 |
if(!isset($output[$t])) { |
| 1651 |
$output[$t] = array(); |
| 1652 |
} |
| 1653 |
$output[$t][] = $v; |
| 1654 |
} |
| 1655 |
elseif($v || $v === '0') { |
| 1656 |
$output = (string) $v; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
if($node->attributes->length && !is_array($output)) { //Has attributes but isn't an array |
| 1660 |
$output = array('@content'=>$output); //Change output into an array. |
| 1661 |
} |
| 1662 |
if(is_array($output)) { |
| 1663 |
if($node->attributes->length) { |
| 1664 |
$a = array(); |
| 1665 |
foreach($node->attributes as $attrName => $attrNode) { |
| 1666 |
$a[$attrName] = (string) $attrNode->value; |
| 1667 |
} |
| 1668 |
$output['@attributes'] = $a; |
| 1669 |
} |
| 1670 |
foreach ($output as $t => $v) { |
| 1671 |
if(is_array($v) && count($v)==1 && $t!='@attributes') { |
| 1672 |
$output[$t] = $v[0]; |
| 1673 |
} |
| 1674 |
} |
| 1675 |
} |
| 1676 |
break; |
| 1677 |
} |
| 1678 |
return $output; |
| 1679 |
} |
| 1680 |
|
| 1681 |
public function run() |
| 1682 |
{ |
| 1683 |
ini_set('max_execution_time', 900); |
| 1684 |
$this->data['import_log'] = ''; |
| 1685 |
$multipurpose = 'real-estate.xml'; |
| 1686 |
if(isset($_GET['multipurpose'])) |
| 1687 |
$multipurpose = sanitize_text_field($_GET['multipurpose']); |
| 1688 |
|
| 1689 |
$redirect_url = admin_url("admin.php?page=wdk_fields&is_updated"); |
| 1690 |
if(isset($_GET['redirect_url'])) |
| 1691 |
$redirect_url = sanitize_text_field($_GET['redirect_url']); |
| 1692 |
|
| 1693 |
$this->import_locations(); |
| 1694 |
$this->import_categories($multipurpose); |
| 1695 |
$this->import_fields($multipurpose); |
| 1696 |
$this->import_listings($multipurpose); |
| 1697 |
$this->import_visual_data($multipurpose); |
| 1698 |
$this->demo_pages($multipurpose); |
| 1699 |
|
| 1700 |
$message = str_replace(" ", '+', __('Import completed successfuly', 'wpdirectorykit')); |
| 1701 |
|
| 1702 |
wp_redirect($redirect_url.'&message='.$message); |
| 1703 |
exit; |
| 1704 |
} |
| 1705 |
|
| 1706 |
public function api_import() |
| 1707 |
{ |
| 1708 |
ini_set('max_execution_time', 900); |
| 1709 |
$this->data['import_log'] = ''; |
| 1710 |
$multipurpose = 'real-estate.xml'; |
| 1711 |
if(isset($_GET['multipurpose'])) |
| 1712 |
$multipurpose = sanitize_text_field($_GET['multipurpose']); |
| 1713 |
|
| 1714 |
$this->import_locations(); |
| 1715 |
$this->import_categories($multipurpose); |
| 1716 |
$this->import_fields($multipurpose); |
| 1717 |
$this->import_listings($multipurpose); |
| 1718 |
$this->import_visual_data($multipurpose); |
| 1719 |
$this->import_settings(); |
| 1720 |
|
| 1721 |
/* action */ |
| 1722 |
do_action('wpdirectorykit/install/api'); |
| 1723 |
|
| 1724 |
return true; |
| 1725 |
} |
| 1726 |
|
| 1727 |
private function replace_meta($from = '', $to = '') { |
| 1728 |
global $wpdb; |
| 1729 |
// @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes |
| 1730 |
$rows_affected = $wpdb->query( |
| 1731 |
"UPDATE ".esc_sql($wpdb->postmeta)." " . |
| 1732 |
"SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', esc_sql($from) ) . "', '" . str_replace( '/', '\\\/', esc_sql($to) ) . "') " . |
| 1733 |
"WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" ); |
| 1734 |
/* end login */ |
| 1735 |
} |
| 1736 |
|
| 1737 |
public function import_settings() { |
| 1738 |
update_option( 'wdk_is_category_enabled', '1' ); |
| 1739 |
update_option( 'wdk_is_location_enabled', '1' ); |
| 1740 |
update_option( 'wdk_is_address_enabled', '1' ); |
| 1741 |
update_option( 'wdk_is_results_page_require', '1' ); |
| 1742 |
update_option( 'wdk_seo_description', '2' ); |
| 1743 |
update_option( 'wdk_seo_keywords', '3' ); |
| 1744 |
return true; |
| 1745 |
} |
| 1746 |
|
| 1747 |
} |
| 1748 |
|