| 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 |
$this->form->add_error_message('wdk_slug_format', __('Custom Listing Preview Page Slug allowed only a-z 0-9 - _ ', 'wpdirectorykit')); |
| 20 |
|
| 21 |
if($this->form->run($this->data['fields'])) |
| 22 |
{ |
| 23 |
// Save procedure for basic data |
| 24 |
|
| 25 |
$data = $this->settings_m->prepare_data($this->input->post(), $this->data['fields']); |
| 26 |
$wdk_slug_listing_preview_page = get_option('wdk_slug_listing_preview_page'); |
| 27 |
|
| 28 |
// Save standard wp post |
| 29 |
foreach($data as $key => $val) |
| 30 |
{ |
| 31 |
update_option( $key, $val, TRUE); |
| 32 |
} |
| 33 |
|
| 34 |
if(isset($data['wdk_slug_listing_preview_page']) && $wdk_slug_listing_preview_page != $data['wdk_slug_listing_preview_page']) { |
| 35 |
update_option('wdk_slug_listing_preview_page_changed', 1); |
| 36 |
} |
| 37 |
|
| 38 |
// redirect |
| 39 |
if(empty($listing_post_id) && !empty($id)) |
| 40 |
{ |
| 41 |
//wp_redirect(admin_url("admin.php?page=wdk_settings&is_updated=true")); |
| 42 |
exit; |
| 43 |
} |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
// fetch data, after update/insert to get updated last data |
| 48 |
$fields_data = $this->settings_m->get(); |
| 49 |
|
| 50 |
/* slug udpate rules*/ |
| 51 |
//flush_rewrite_rules(); |
| 52 |
|
| 53 |
foreach($fields_data as $field) |
| 54 |
{ |
| 55 |
$this->data['db_data'][$field->option_name] = $field->option_value; |
| 56 |
} |
| 57 |
|
| 58 |
$this->load->view('wdk_settings/index', $this->data); |
| 59 |
} |
| 60 |
|
| 61 |
function reset_data () { |
| 62 |
|
| 63 |
$this->load->model('location_m'); |
| 64 |
$this->load->model('category_m'); |
| 65 |
$this->load->model('field_m'); |
| 66 |
$this->load->model('listingfield_m'); |
| 67 |
$this->load->model('listing_m'); |
| 68 |
$this->load->model('resultitem_m'); |
| 69 |
$this->load->model('searchform_m'); |
| 70 |
|
| 71 |
/* remove fields */ |
| 72 |
$this->db->delete($this->location_m->_table_name); |
| 73 |
/* end remove fields */ |
| 74 |
|
| 75 |
/* remove fields */ |
| 76 |
$this->db->delete($this->category_m->_table_name); |
| 77 |
/* end remove fields */ |
| 78 |
|
| 79 |
/* remove fields */ |
| 80 |
$this->db->delete($this->location_m->_table_name); |
| 81 |
/* end remove fields */ |
| 82 |
|
| 83 |
/* remove fields */ |
| 84 |
$this->db->delete($this->field_m->_table_name); |
| 85 |
$field_names = $this->listingfield_m->get_available_fields(); |
| 86 |
foreach($field_names as $field_name => $value){ |
| 87 |
if(strpos($field_name, 'field_') ===FALSE) continue; |
| 88 |
$this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.''); |
| 89 |
} |
| 90 |
/* end remove fields */ |
| 91 |
|
| 92 |
/* remove listings */ |
| 93 |
$this->db->delete($this->listing_m->_table_name); |
| 94 |
$this->db->delete($this->listingfield_m->_table_name); |
| 95 |
/* end remove listings */ |
| 96 |
|
| 97 |
/* reset autoincrement */ |
| 98 |
$this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`'); |
| 99 |
$this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`'); |
| 100 |
$this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`'); |
| 101 |
$this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`'); |
| 102 |
$this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`'); |
| 103 |
/* end reset autoincrement */ |
| 104 |
|
| 105 |
/* remove listings */ |
| 106 |
$this->db->delete($this->resultitem_m->_table_name); |
| 107 |
$this->db->delete($this->searchform_m->_table_name); |
| 108 |
/* end remove listings */ |
| 109 |
|
| 110 |
/* reset autoincrement */ |
| 111 |
$this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`'); |
| 112 |
$this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`'); |
| 113 |
|
| 114 |
$wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1)); |
| 115 |
foreach( $wdk_posts as $post ) { |
| 116 |
// Delete's each post. |
| 117 |
wp_delete_post( $post->ID, true); |
| 118 |
// Set to False if you want to send them to Trash. |
| 119 |
} |
| 120 |
|
| 121 |
$redirect_url = admin_url("admin.php?page=wdk_settings&is_updated"); |
| 122 |
if(isset($_GET['redirect_url'])) |
| 123 |
$redirect_url = sanitize_text_field($_GET['redirect_url']); |
| 124 |
|
| 125 |
wp_redirect($redirect_url); |
| 126 |
exit; |
| 127 |
} |
| 128 |
|
| 129 |
// Import demo data listing method |
| 130 |
public function import_demo() |
| 131 |
{ |
| 132 |
|
| 133 |
$this->load->model('field_m'); |
| 134 |
$this->load->model('listingfield_m'); |
| 135 |
$this->load->model('listing_m'); |
| 136 |
$this->load->model('category_m'); |
| 137 |
$this->load->model('location_m'); |
| 138 |
$this->load->model('searchform_m'); |
| 139 |
$this->load->model('resultitem_m'); |
| 140 |
$this->load->model('listingusers_m'); |
| 141 |
|
| 142 |
$this->data['installed'] = false; |
| 143 |
if($this->field_m->get() || $this->listingfield_m->get() || $this->listing_m->get() || $this->category_m->get() || $this->location_m->get()) |
| 144 |
$this->data['installed'] = true; |
| 145 |
|
| 146 |
$this->data['required_plugins'] = false; |
| 147 |
if(!function_exists('eli_installer') || !function_exists('run_elementinvader') || !is_plugin_active('elementor/elementor.php')) |
| 148 |
$this->data['required_plugins'] = true; |
| 149 |
|
| 150 |
$this->data['db_data'] = NULL; |
| 151 |
$this->data['fields'] = array( |
| 152 |
array('field' => 'import_locations', 'field_label' => __('Locations', 'wpdirectorykit'), 'hint' => __('All Locations will be removed and import demo locations', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 153 |
array('field' => 'import_categories', 'field_label' => __('Categories', 'wpdirectorykit'), 'hint' => __('All categories will be removed and import demo categories', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 154 |
array('field' => 'import_fields', 'field_label' => __('Fields', 'wpdirectorykit'), 'hint' => __('All fiedls will be removed and import demo fields', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 155 |
array('field' => 'import_listings', 'field_label' => __('Listings', 'wpdirectorykit'), 'hint' => __('All listings will be removed and import demo listings', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 156 |
array('field' => 'import_visual_data', 'field_label' => __('Search Form & Result Card', 'wpdirectorykit'), 'hint' => __('Import demo Search Form & Result Card', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 157 |
array('field' => 'import_page_listing_preview', 'field_label' => __('Listing Preview Page', 'wpdirectorykit'), 'hint' => __('Import demo Listing Preivew Page', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 158 |
array('field' => 'import_page_results', 'field_label' => __('Results Page', 'wpdirectorykit'), 'hint' => __('Import demo Results Page', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''), |
| 159 |
); |
| 160 |
|
| 161 |
$multipurpose_values = array('' => __('Not Selected', 'wpdirectorykit')); |
| 162 |
if(file_exists(WPDIRECTORYKIT_PATH.'demo-data/')) |
| 163 |
{ |
| 164 |
$files = array(); |
| 165 |
$dir = WPDIRECTORYKIT_PATH.'demo-data/'; |
| 166 |
if (is_dir($dir)) { |
| 167 |
if ($dh = opendir($dir)) { |
| 168 |
while (($file = readdir($dh)) !== false) { |
| 169 |
if($file == 'locations.xml') continue; |
| 170 |
if(strpos($file, '.xml') !== false && strpos($file, '~') === false) |
| 171 |
$multipurpose_values[$file] = ucwords(str_replace(array('_', '-', '.xml'), ' ', $file)); |
| 172 |
} |
| 173 |
closedir($dh); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
ksort($multipurpose_values); |
| 178 |
if(count($multipurpose_values) > 0) |
| 179 |
$this->data['fields']['multipurpose'] = array('field'=>'multipurpose', 'field_label'=>__('Portal version', 'wpdirectorykit'), 'field_type'=>'DROPDOWN', 'rules'=>'required', 'values'=>$multipurpose_values); |
| 180 |
|
| 181 |
|
| 182 |
$this->data['form'] = &$this->form; |
| 183 |
ini_set('max_execution_time', 900); |
| 184 |
|
| 185 |
// [/Check requirements] |
| 186 |
|
| 187 |
foreach($this->data['fields'] as $field) |
| 188 |
{ |
| 189 |
$this->data['db_data'][$field['field']] = 1; |
| 190 |
} |
| 191 |
|
| 192 |
if($this->field_m->get()) { |
| 193 |
$this->data['db_data']['import_fields'] = 0; |
| 194 |
} |
| 195 |
if($this->listing_m->get()) { |
| 196 |
$this->data['db_data']['import_listings'] = 0; |
| 197 |
} |
| 198 |
if($this->category_m->get()) { |
| 199 |
$this->data['db_data']['import_categories'] = 0; |
| 200 |
} |
| 201 |
if($this->location_m->get()) { |
| 202 |
$this->data['db_data']['import_locations'] = 0; |
| 203 |
} |
| 204 |
|
| 205 |
if($this->searchform_m->get() || $this->resultitem_m->get()){ |
| 206 |
$this->data['db_data']['import_visual_data'] = 0; |
| 207 |
$this->import_settings(); |
| 208 |
} |
| 209 |
|
| 210 |
if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){ |
| 211 |
$this->data['db_data']['import_page_listing_preview'] = 0; |
| 212 |
} |
| 213 |
|
| 214 |
if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){ |
| 215 |
$this->data['db_data']['import_page_results'] = 0; |
| 216 |
} |
| 217 |
|
| 218 |
$this->data['db_data']['multipurpose'] = 'real-estate.xml'; |
| 219 |
|
| 220 |
if(isset($_GET['multipurpose'])) |
| 221 |
$this->data['db_data']['multipurpose'] = sanitize_text_field($_GET['multipurpose']); |
| 222 |
|
| 223 |
$this->data['import_log'] = ''; |
| 224 |
$rules = array( |
| 225 |
array( |
| 226 |
'field' => 'import_locations', |
| 227 |
'label' => __('Locations', 'wpdirectorykit'), |
| 228 |
'rules' => '' |
| 229 |
), |
| 230 |
array( |
| 231 |
'field' => 'import_categories', |
| 232 |
'label' => __('Categories', 'wpdirectorykit'), |
| 233 |
'rules' => '' |
| 234 |
), |
| 235 |
array( |
| 236 |
'field' => 'import_fields', |
| 237 |
'label' => __('Fields', 'wpdirectorykit'), |
| 238 |
'rules' => '' |
| 239 |
), |
| 240 |
array( |
| 241 |
'field' => 'import_listings', |
| 242 |
'label' => __('Listings', 'wpdirectorykit'), |
| 243 |
'rules' => '' |
| 244 |
), |
| 245 |
array( |
| 246 |
'field' => 'import_visual_data', |
| 247 |
'label' => __('Search Form & Result Card', 'wpdirectorykit'), |
| 248 |
'rules' => '' |
| 249 |
), |
| 250 |
array( |
| 251 |
'field' => 'import_page_listing_preview', |
| 252 |
'label' => __('Listing Preview Page', 'wpdirectorykit'), |
| 253 |
'rules' => '' |
| 254 |
), |
| 255 |
array( |
| 256 |
'field' => 'import_page_results', |
| 257 |
'label' => __('Results Page', 'wpdirectorykit'), |
| 258 |
'rules' => '' |
| 259 |
), |
| 260 |
array( |
| 261 |
'field' => 'multipurpose', |
| 262 |
'label' => __('Purpose', 'wpdirectorykit'), |
| 263 |
'rules' => 'required' |
| 264 |
), |
| 265 |
); |
| 266 |
|
| 267 |
$plugin = 'elementor/elementor.php'; |
| 268 |
if (in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ))) && !class_exists('Elementor\Plugin') ) { |
| 269 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Your Elementor Plugin is not fully active, usually this happen because of old PHP version on server, in such case eventually you can try older Elementor Version or Update PHP on your server').'</div>'; |
| 270 |
$this->data['required_plugins'] = true; |
| 271 |
} |
| 272 |
|
| 273 |
if(!$this->data['required_plugins']) |
| 274 |
if($this->form->run($rules)) |
| 275 |
{ |
| 276 |
// Save procedure for basic data |
| 277 |
$data = $this->input->post(); |
| 278 |
|
| 279 |
if( !empty($data['import_locations'])) { |
| 280 |
$this->import_locations(); |
| 281 |
} |
| 282 |
|
| 283 |
if( !empty($data['import_categories'])) { |
| 284 |
$this->import_categories($data['multipurpose']); |
| 285 |
} |
| 286 |
|
| 287 |
if( !empty($data['import_fields'])) { |
| 288 |
$this->import_fields($data['multipurpose']); |
| 289 |
} |
| 290 |
|
| 291 |
if( !empty($data['import_listings'])) { |
| 292 |
$this->import_listings($data['multipurpose']); |
| 293 |
} |
| 294 |
|
| 295 |
if( !empty($data['import_visual_data'])) { |
| 296 |
$this->import_visual_data($data['multipurpose']); |
| 297 |
} |
| 298 |
|
| 299 |
if( !empty($data['import_page_listing_preview'])) { |
| 300 |
$this->demo_page_listing($data['multipurpose']); |
| 301 |
} |
| 302 |
|
| 303 |
if( !empty($data['import_page_results'])) { |
| 304 |
$this->demo_page_results($data['multipurpose']); |
| 305 |
} |
| 306 |
|
| 307 |
$this->replace_content_data($data['multipurpose']); |
| 308 |
|
| 309 |
} |
| 310 |
$this->load->view('wdk_install/index', $this->data); |
| 311 |
} |
| 312 |
|
| 313 |
// Import demo data listing method |
| 314 |
public function remove() |
| 315 |
{ |
| 316 |
$this->load->model('field_m'); |
| 317 |
$this->load->model('listingfield_m'); |
| 318 |
$this->load->model('listing_m'); |
| 319 |
$this->load->model('category_m'); |
| 320 |
$this->load->model('location_m'); |
| 321 |
|
| 322 |
$this->data['data_log'] = ''; |
| 323 |
|
| 324 |
$this->load->model('location_m'); |
| 325 |
$this->load->model('category_m'); |
| 326 |
$this->load->model('field_m'); |
| 327 |
$this->load->model('listingfield_m'); |
| 328 |
$this->load->model('listing_m'); |
| 329 |
$this->load->model('resultitem_m'); |
| 330 |
$this->load->model('searchform_m'); |
| 331 |
|
| 332 |
/* remove fields */ |
| 333 |
$this->db->delete($this->location_m->_table_name); |
| 334 |
|
| 335 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations removed').'</div>'; |
| 336 |
/* end remove fields */ |
| 337 |
|
| 338 |
/* remove fields */ |
| 339 |
$this->db->delete($this->category_m->_table_name); |
| 340 |
|
| 341 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories removed').'</div>'; |
| 342 |
/* end remove fields */ |
| 343 |
|
| 344 |
/* remove fields */ |
| 345 |
$this->db->delete($this->field_m->_table_name); |
| 346 |
$field_names = $this->listingfield_m->get_available_fields(); |
| 347 |
foreach($field_names as $field_name => $value){ |
| 348 |
if(strpos($field_name, 'field_') ===FALSE) continue; |
| 349 |
$this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.''); |
| 350 |
} |
| 351 |
|
| 352 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields removed').'</div>'; |
| 353 |
/* end remove fields */ |
| 354 |
|
| 355 |
/* remove listings */ |
| 356 |
$this->db->delete($this->listing_m->_table_name); |
| 357 |
$this->db->delete($this->listingfield_m->_table_name); |
| 358 |
|
| 359 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings removed').'</div>'; |
| 360 |
/* end remove listings */ |
| 361 |
|
| 362 |
|
| 363 |
/* remove listings */ |
| 364 |
$this->db->delete($this->resultitem_m->_table_name); |
| 365 |
$this->db->delete($this->searchform_m->_table_name); |
| 366 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Result Card And Search form removed').'</div>'; |
| 367 |
/* end remove listings */ |
| 368 |
|
| 369 |
|
| 370 |
/* reset autoincrement */ |
| 371 |
$this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`'); |
| 372 |
$this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`'); |
| 373 |
$this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`'); |
| 374 |
$this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`'); |
| 375 |
$this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`'); |
| 376 |
$this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`'); |
| 377 |
$this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`'); |
| 378 |
|
| 379 |
$this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Tables reset').'</div>'; |
| 380 |
/* end reset autoincrement */ |
| 381 |
|
| 382 |
$wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1)); |
| 383 |
foreach( $wdk_posts as $post ) { |
| 384 |
// Delete's each post. |
| 385 |
wp_delete_post( $post->ID, true); |
| 386 |
// Set to False if you want to send them to Trash. |
| 387 |
} |
| 388 |
|
| 389 |
if(isset($_GET['redirect_url'])){ |
| 390 |
if(wmvc_xss_clean($_GET['redirect_url']) =='on_install') { |
| 391 |
$redirect_url = admin_url("admin.php?page=wdk_settings&function=import_demo&is_updated"); |
| 392 |
} else { |
| 393 |
$redirect_url = sanitize_text_field($_GET['redirect_url']); |
| 394 |
} |
| 395 |
wp_redirect($redirect_url); |
| 396 |
} |
| 397 |
|
| 398 |
$this->load->view('wdk_install/remove_log', $this->data); |
| 399 |
} |
| 400 |
|
| 401 |
/* add demo pages */ |
| 402 |
public function demo_pages($purpose = '') { |
| 403 |
|
| 404 |
// if(get_option('wdk_listing_page') || get_option('wdk_results_page')) return true; |
| 405 |
|
| 406 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 407 |
$self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt'); |
| 408 |
}); |
| 409 |
|
| 410 |
add_action('wpdirectorykit/elementor-elements/register_widget', function(){ |
| 411 |
add_action('eli/includes', function(){ |
| 412 |
require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php'; |
| 413 |
}); |
| 414 |
|
| 415 |
add_action('eli/register_widget', function(){ |
| 416 |
$object = new Wdk\Elementor\Extensions\WdkContactFormExt(); |
| 417 |
\Elementor\Plugin::instance()->widgets_manager->register( $object ); |
| 418 |
}); |
| 419 |
}); |
| 420 |
|
| 421 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 422 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel'); |
| 423 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue'); |
| 424 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages'); |
| 425 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon'); |
| 426 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings'); |
| 427 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider'); |
| 428 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection'); |
| 429 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingMap'); |
| 430 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent'); |
| 431 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField'); |
| 432 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar'); |
| 433 |
}); |
| 434 |
|
| 435 |
|
| 436 |
// Import elementor templates |
| 437 |
$page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 438 |
$this->elementor_assign($page_listing_preview->ID, 'page-listing-preview.json'); |
| 439 |
|
| 440 |
$page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 441 |
$this->elementor_assign($page_results->ID, 'page-results-listings.json'); |
| 442 |
|
| 443 |
|
| 444 |
$menus = get_registered_nav_menus(); |
| 445 |
// first menu defined by template |
| 446 |
$first_menu = key($menus); |
| 447 |
|
| 448 |
if ( has_nav_menu($first_menu) ) { |
| 449 |
$menus = wp_get_nav_menus(); |
| 450 |
$menu_id = (int)$menus[0]->term_id; |
| 451 |
} else { |
| 452 |
wp_delete_nav_menu('Primary menu'); |
| 453 |
$menu_name = 'Primary menu'; |
| 454 |
$menu_exists = wp_get_nav_menu_object( $menu_name ); |
| 455 |
$menu_term = $menu_exists; |
| 456 |
$menu_id = wp_create_nav_menu($menu_name); |
| 457 |
} |
| 458 |
|
| 459 |
// first menu defined by template |
| 460 |
if (!empty($menu_id)) { |
| 461 |
$itemData = array( |
| 462 |
'menu-item-object-id' => $page_results->ID, |
| 463 |
'menu-item-title' => esc_html__('Grid Map', 'wpdirectorykit'), |
| 464 |
'menu-item-parent-id' => 0, |
| 465 |
'menu-item-position' => 3, |
| 466 |
'menu-item-object' => 'page', |
| 467 |
'menu-item-type' => 'post_type', |
| 468 |
'menu-item-status' => 'publish' |
| 469 |
); |
| 470 |
|
| 471 |
wp_update_nav_menu_item((int)$menu_id, 0, $itemData); |
| 472 |
|
| 473 |
// assign menu to top menu |
| 474 |
$locations = get_theme_mod( 'nav_menu_locations' ); |
| 475 |
$locations[$first_menu] = $menu_id; |
| 476 |
set_theme_mod('nav_menu_locations', $locations); |
| 477 |
} |
| 478 |
|
| 479 |
// Assign page. |
| 480 |
update_option( 'show_on_front', 'page' ); |
| 481 |
update_option( 'page_on_front', $page_results->ID ); |
| 482 |
|
| 483 |
if($page_listing_preview) |
| 484 |
update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE); |
| 485 |
|
| 486 |
if($page_results) |
| 487 |
update_option( 'wdk_results_page', $page_results->ID, TRUE); |
| 488 |
|
| 489 |
$this->replace_content_data($purpose); |
| 490 |
|
| 491 |
return true; |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
private function add_demo_user($username, $name, $surname, $email_address='', $type='wdk_agent', $password=NULL, $meta_data = array()) |
| 496 |
{ |
| 497 |
|
| 498 |
if ( username_exists( $username )) { |
| 499 |
return username_exists( $username ); |
| 500 |
} |
| 501 |
|
| 502 |
if ( email_exists($email_address)) { |
| 503 |
return email_exists($email_address); |
| 504 |
} |
| 505 |
|
| 506 |
if ( empty($email_address)) { |
| 507 |
return false; |
| 508 |
} |
| 509 |
|
| 510 |
// Generate the password and create the user |
| 511 |
if(empty($password)) |
| 512 |
$password = wp_generate_password( 12, false ); |
| 513 |
|
| 514 |
$user_id = wp_create_user( $username, $password, $email_address ); |
| 515 |
|
| 516 |
// Set the nickname |
| 517 |
wp_update_user( |
| 518 |
array( |
| 519 |
'ID' => $user_id, |
| 520 |
'nickname' => $name.' '.$surname, |
| 521 |
'first_name' => $name, |
| 522 |
'last_name' => $surname, |
| 523 |
'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.', |
| 524 |
'display_name'=> $name.' '.$surname, |
| 525 |
'user_url' => '' , |
| 526 |
'admin_bar_front' => 0 , |
| 527 |
'wdk_phone' => '123456789' |
| 528 |
) |
| 529 |
); |
| 530 |
|
| 531 |
$user = new WP_User( $user_id ); |
| 532 |
$user->set_role($type); |
| 533 |
|
| 534 |
if(!empty($meta_data)) |
| 535 |
foreach ($meta_data as $meta_key => $meta_value){ |
| 536 |
update_user_meta( $user_id, $meta_key, wmvc_xss_clean($meta_value) ); |
| 537 |
} |
| 538 |
|
| 539 |
update_user_meta( $user_id, 'show_admin_bar_front', 'false' ); |
| 540 |
update_user_meta( $user_id, 'show_admin_bar_admin', 'false' ); |
| 541 |
|
| 542 |
return $user_id; |
| 543 |
} |
| 544 |
|
| 545 |
function replace_content_data($purpose = '') { |
| 546 |
/* Replace Links */ |
| 547 |
/* login */ |
| 548 |
$from = 'https://www.wpdirectorykit.com/nexproperty/wp-admin/wp-login.php'; |
| 549 |
$to = get_admin_url(); |
| 550 |
$this->replace_meta($from, $to); |
| 551 |
|
| 552 |
|
| 553 |
$from = 'https://www.wpdirectorykit.com/nexproperty'; |
| 554 |
$to = get_home_url(); |
| 555 |
$this->replace_meta($from, $to); |
| 556 |
|
| 557 |
/* homepage */ |
| 558 |
$from = '2020'; |
| 559 |
$to = date('Y'); |
| 560 |
$this->replace_meta($from, $to); |
| 561 |
|
| 562 |
|
| 563 |
/* replace in db */ |
| 564 |
$xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose; |
| 565 |
if(file_exists($xml_list)) { |
| 566 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 567 |
if(isset($dom_array['replace']) && !empty($dom_array['replace'])) { |
| 568 |
if(!empty($dom_array['replace']['text'])) { |
| 569 |
foreach($dom_array['replace']['text'] as $string){ |
| 570 |
if(!isset($string['@attributes']) || !isset($string['@attributes']['from']) || !isset($string['@attributes']['to'])) continue; |
| 571 |
if(empty($string['@attributes']['from']) || empty( $string['@attributes']['to'])) continue; |
| 572 |
$this->replace_meta($string['@attributes']['from'], $string['@attributes']['to']); |
| 573 |
} |
| 574 |
} |
| 575 |
} else { |
| 576 |
|
| 577 |
} |
| 578 |
} |
| 579 |
return true; |
| 580 |
|
| 581 |
} |
| 582 |
|
| 583 |
/* add demo listing preview page */ |
| 584 |
public function demo_page_listing($purpose = '') { |
| 585 |
|
| 586 |
if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){ |
| 587 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listing Preview Page already exists').'</div>'; |
| 588 |
return false; |
| 589 |
} |
| 590 |
|
| 591 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 592 |
$self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt'); |
| 593 |
}); |
| 594 |
|
| 595 |
add_action('wpdirectorykit/elementor-elements/register_widget', function(){ |
| 596 |
add_action('eli/includes', function(){ |
| 597 |
require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php'; |
| 598 |
}); |
| 599 |
|
| 600 |
add_action('eli/register_widget', function(){ |
| 601 |
$object = new Wdk\Elementor\Extensions\WdkContactFormExt(); |
| 602 |
\Elementor\Plugin::instance()->widgets_manager->register( $object ); |
| 603 |
}); |
| 604 |
}); |
| 605 |
|
| 606 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 607 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel'); |
| 608 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue'); |
| 609 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages'); |
| 610 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon'); |
| 611 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings'); |
| 612 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider'); |
| 613 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection'); |
| 614 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingMap'); |
| 615 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent'); |
| 616 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField'); |
| 617 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar'); |
| 618 |
}); |
| 619 |
|
| 620 |
// Import elementor templates |
| 621 |
$page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 622 |
$this->elementor_assign($page_listing_preview->ID, 'page-listing-preview.json'); |
| 623 |
|
| 624 |
// Assign page. |
| 625 |
if($page_listing_preview) |
| 626 |
update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE); |
| 627 |
|
| 628 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listing Preview Page imported').'</div>'; |
| 629 |
|
| 630 |
return true; |
| 631 |
} |
| 632 |
|
| 633 |
/* add demo results page */ |
| 634 |
public function demo_page_results($purpose = '') { |
| 635 |
|
| 636 |
if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){ |
| 637 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Results Listings Page already exists').'</div>'; |
| 638 |
return false; |
| 639 |
} |
| 640 |
|
| 641 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 642 |
$self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt'); |
| 643 |
}); |
| 644 |
|
| 645 |
add_action('wpdirectorykit/elementor-elements/register_widget', function(){ |
| 646 |
add_action('eli/includes', function(){ |
| 647 |
require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php'; |
| 648 |
}); |
| 649 |
|
| 650 |
add_action('eli/register_widget', function(){ |
| 651 |
$object = new Wdk\Elementor\Extensions\WdkContactFormExt(); |
| 652 |
\Elementor\Plugin::instance()->widgets_manager->register( $object ); |
| 653 |
}); |
| 654 |
}); |
| 655 |
|
| 656 |
add_action('wpdirectorykit/elementor-elements/register_widget', function($self){ |
| 657 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel'); |
| 658 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue'); |
| 659 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages'); |
| 660 |
$self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon'); |
| 661 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings'); |
| 662 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider'); |
| 663 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection'); |
| 664 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingMap'); |
| 665 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent'); |
| 666 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField'); |
| 667 |
$self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar'); |
| 668 |
}); |
| 669 |
|
| 670 |
$page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas'); |
| 671 |
$this->elementor_assign($page_results->ID, 'page-results-listings.json'); |
| 672 |
|
| 673 |
// Assign page. |
| 674 |
update_option( 'show_on_front', 'page' ); |
| 675 |
update_option( 'page_on_front', $page_results->ID ); |
| 676 |
|
| 677 |
update_option( 'wdk_results_page', $page_results->ID, TRUE); |
| 678 |
|
| 679 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Results Listings Page imported').'</div>'; |
| 680 |
|
| 681 |
|
| 682 |
$menus = get_registered_nav_menus(); |
| 683 |
// first menu defined by template |
| 684 |
$first_menu = key($menus); |
| 685 |
|
| 686 |
if ( has_nav_menu($first_menu) ) { |
| 687 |
$menus = wp_get_nav_menus(); |
| 688 |
$menu_id = (int)$menus[0]->term_id; |
| 689 |
} else { |
| 690 |
wp_delete_nav_menu('Primary menu'); |
| 691 |
$menu_name = 'Primary menu'; |
| 692 |
$menu_exists = wp_get_nav_menu_object( $menu_name ); |
| 693 |
$menu_term = $menu_exists; |
| 694 |
$menu_id = wp_create_nav_menu($menu_name); |
| 695 |
} |
| 696 |
|
| 697 |
// first menu defined by template |
| 698 |
if (!empty($menu_id)) { |
| 699 |
$itemData = array( |
| 700 |
'menu-item-object-id' => $page_results->ID, |
| 701 |
'menu-item-title' => esc_html__('Grid Map', 'wpdirectorykit'), |
| 702 |
'menu-item-parent-id' => 0, |
| 703 |
'menu-item-position' => 3, |
| 704 |
'menu-item-object' => 'page', |
| 705 |
'menu-item-type' => 'post_type', |
| 706 |
'menu-item-status' => 'publish' |
| 707 |
); |
| 708 |
|
| 709 |
wp_update_nav_menu_item((int)$menu_id, 0, $itemData); |
| 710 |
|
| 711 |
// assign menu to top menu |
| 712 |
$locations = get_theme_mod( 'nav_menu_locations' ); |
| 713 |
$locations[$first_menu] = $menu_id; |
| 714 |
set_theme_mod('nav_menu_locations', $locations); |
| 715 |
} |
| 716 |
|
| 717 |
return true; |
| 718 |
} |
| 719 |
|
| 720 |
/* Create Page */ |
| 721 |
function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0) |
| 722 |
{ |
| 723 |
$post = get_page_by_title($post_title, 'OBJECT', 'page' ); |
| 724 |
|
| 725 |
$post_id = NULL; |
| 726 |
|
| 727 |
// Delete posts and rebuild |
| 728 |
if(!empty($post)) |
| 729 |
{ |
| 730 |
wp_delete_post($post->ID, true); |
| 731 |
$post=NULL; |
| 732 |
} |
| 733 |
|
| 734 |
if(!empty($post)) |
| 735 |
$post_id = $post->ID; |
| 736 |
|
| 737 |
if(empty($post_id)) |
| 738 |
{ |
| 739 |
$error_obj = NULL; |
| 740 |
$post_insert = array( |
| 741 |
'post_title' => wp_strip_all_tags( $post_title ), |
| 742 |
'post_content' => $post_content, |
| 743 |
'post_status' => 'publish', |
| 744 |
'post_type' => 'page', |
| 745 |
'post_author' => get_current_user_id(), |
| 746 |
'post_category' => array(1,2), |
| 747 |
'page_template' => $post_template, |
| 748 |
'post_parent' => $post_parent |
| 749 |
); |
| 750 |
$post_id = wp_insert_post( $post_insert, $error_obj ); |
| 751 |
} |
| 752 |
|
| 753 |
$post_insert = get_post( $post_id ); |
| 754 |
|
| 755 |
return $post_insert; |
| 756 |
} |
| 757 |
|
| 758 |
/* Elementor Import Template */ |
| 759 |
private function elementor_assign($page_id, $json_template_name = '') |
| 760 |
{ |
| 761 |
|
| 762 |
$file = false; |
| 763 |
|
| 764 |
if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name)) |
| 765 |
{ |
| 766 |
$file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name; |
| 767 |
} |
| 768 |
elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name)) |
| 769 |
{ |
| 770 |
$file = get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name; |
| 771 |
} |
| 772 |
elseif(file_exists( WPDIRECTORYKIT_PATH. '/demo-data/'.$json_template_name)) |
| 773 |
{ |
| 774 |
$file = WPDIRECTORYKIT_PATH.'demo-data/'.$json_template_name; |
| 775 |
} |
| 776 |
|
| 777 |
if(!$file || !class_exists('Elementor\Plugin')) |
| 778 |
{ |
| 779 |
return false; |
| 780 |
} |
| 781 |
|
| 782 |
$page_template = get_page_template_slug( $page_id ); |
| 783 |
|
| 784 |
add_post_meta( $page_id, '_elementor_edit_mode', 'builder' ); |
| 785 |
|
| 786 |
global $wp_filesystem; |
| 787 |
// Initialize the WP filesystem, no more using 'file-put-contents' function |
| 788 |
if (empty($wp_filesystem)) { |
| 789 |
WP_Filesystem(); |
| 790 |
} |
| 791 |
|
| 792 |
$string = $wp_filesystem->get_contents($file); |
| 793 |
|
| 794 |
$json_template = json_decode($string, true); |
| 795 |
$elements = $json_template['content']; |
| 796 |
|
| 797 |
$data = array( |
| 798 |
'elements' => $elements, |
| 799 |
'settings' => array('post_status'=>'autosave', 'template'=>$page_template), |
| 800 |
); |
| 801 |
// @codingStandardsIgnoreStart |
| 802 |
$document = Elementor\Plugin::$instance->documents->get( $page_id, false ); |
| 803 |
// @codingStandardsIgnoreEnd |
| 804 |
return $document->save( $data ); |
| 805 |
} |
| 806 |
|
| 807 |
private function import_visual_data($purpose = '') { |
| 808 |
$this->load->model('searchform_m'); |
| 809 |
$this->load->model('resultitem_m'); |
| 810 |
$this->load->model('field_m'); |
| 811 |
|
| 812 |
if($this->searchform_m->get() || $this->resultitem_m->get()){ |
| 813 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Search and result card already imported', 'wpdirectorykit').'</div>'; |
| 814 |
return false; |
| 815 |
} |
| 816 |
|
| 817 |
/* remove listings */ |
| 818 |
$this->db->delete($this->resultitem_m->_table_name); |
| 819 |
$this->db->delete($this->searchform_m->_table_name); |
| 820 |
/* end remove listings */ |
| 821 |
|
| 822 |
/* reset autoincrement */ |
| 823 |
$this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`'); |
| 824 |
$this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`'); |
| 825 |
|
| 826 |
$xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose; |
| 827 |
if(file_exists($xml_list)) { |
| 828 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 829 |
|
| 830 |
if(!isset($dom_array['search_form']) && empty($dom_array['search_form'])) { |
| 831 |
} else { |
| 832 |
// Save searchform_m |
| 833 |
$data = array(); |
| 834 |
$data['searchform_name'] = 'Primary'; |
| 835 |
$data['searchform_json'] = trim($dom_array['search_form']); |
| 836 |
|
| 837 |
if (function_exists('run_wdk_bookings') && isset($dom_array['search_form_premium']) && !empty($dom_array['search_form_premium'])) { |
| 838 |
$data['searchform_json'] = trim($dom_array['search_form_premium']); |
| 839 |
} |
| 840 |
|
| 841 |
$data['idsearchform'] = 1; |
| 842 |
$insert_id = $this->searchform_m->insert($data, NULL); |
| 843 |
} |
| 844 |
|
| 845 |
if(!isset($dom_array['resultitem']) && empty($dom_array['resultitem'])) { |
| 846 |
} else { |
| 847 |
// Save searchform_m |
| 848 |
$data = array(); |
| 849 |
$data['resultitem_name'] = 'Primary'; |
| 850 |
$data['resultitem_json'] = trim($dom_array['resultitem']); |
| 851 |
$data['idresultitem'] = 1; |
| 852 |
$insert_id = $this->resultitem_m->insert($data, NULL); |
| 853 |
} |
| 854 |
|
| 855 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Search Form & Result Card imported').'</div>'; |
| 856 |
return true; |
| 857 |
} |
| 858 |
|
| 859 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 860 |
return false; |
| 861 |
|
| 862 |
} |
| 863 |
|
| 864 |
private function import_locations() { |
| 865 |
$xml_list = WPDIRECTORYKIT_PATH.'demo-data/locations.xml'; |
| 866 |
$this->load->model('location_m'); |
| 867 |
|
| 868 |
if($this->location_m->get()){ |
| 869 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>'; |
| 870 |
return false; |
| 871 |
} |
| 872 |
|
| 873 |
if(file_exists($xml_list)) { |
| 874 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 875 |
if(!isset($dom_array['locations']['location']) && empty($dom_array['locations']['location'])) { |
| 876 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 877 |
return false; |
| 878 |
} |
| 879 |
foreach ($dom_array['locations']['location'] as $key => $location_data) { |
| 880 |
$this->_recursive_add_locations($location_data); |
| 881 |
} |
| 882 |
|
| 883 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations imported').'</div>'; |
| 884 |
return true; |
| 885 |
} |
| 886 |
|
| 887 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 888 |
return false; |
| 889 |
} |
| 890 |
|
| 891 |
private function _recursive_add_locations ($data = array(), $parent_id = 0, $level = 0 ) { |
| 892 |
$base = array( |
| 893 |
'location_title' => '', |
| 894 |
'parent_id' => $parent_id, |
| 895 |
'order_index' => '', |
| 896 |
'level' => $level, |
| 897 |
'font_icon_code' => '', |
| 898 |
'image_id' => '', |
| 899 |
'icon_id' => '', |
| 900 |
'code' => '', |
| 901 |
); |
| 902 |
$location_data = array_intersect_key(array_merge($base, $data), $base); |
| 903 |
array_walk($location_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 904 |
|
| 905 |
if(empty(wmvc_show_data('location_title', $location_data))) { |
| 906 |
return false; |
| 907 |
} |
| 908 |
|
| 909 |
if(!empty($location_data['image_id']) && file_exists(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['image_id'])){ |
| 910 |
/* add files */ |
| 911 |
$location_data['image_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['image_id']); |
| 912 |
} |
| 913 |
|
| 914 |
if(!empty($location_data['icon_id']) && file_exists(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['icon_id'])){ |
| 915 |
/* add files */ |
| 916 |
$location_data['icon_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['icon_id']); |
| 917 |
} |
| 918 |
|
| 919 |
$location_data['icon_path'] = wdk_generate_path_image($location_data['icon_id']); |
| 920 |
$location_data['image_path'] = wdk_generate_path_image($location_data['image_id']); |
| 921 |
|
| 922 |
/* add locations */ |
| 923 |
$insert_id = $this->location_m->insert($location_data, NULL); |
| 924 |
if(isset($data['childs']["location"]) && !empty($data['childs']["location"])) { |
| 925 |
foreach ($data['childs']["location"] as $sub_location_data) { |
| 926 |
$this->_recursive_add_locations($sub_location_data, $insert_id, ($level+1)); |
| 927 |
} |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
private function import_categories($purpose = '') { |
| 932 |
$xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose; |
| 933 |
$this->load->model('category_m'); |
| 934 |
|
| 935 |
if($this->category_m->get()){ |
| 936 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>'; |
| 937 |
return false; |
| 938 |
} |
| 939 |
|
| 940 |
if(file_exists($xml_list)) { |
| 941 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 942 |
if(!isset($dom_array['categories']['category']) && empty($dom_array['categories']['category'])) { |
| 943 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 944 |
return false; |
| 945 |
} |
| 946 |
|
| 947 |
foreach ($dom_array['categories']['category'] as $key => $category_data) { |
| 948 |
$this->_recursive_add_categories($category_data); |
| 949 |
} |
| 950 |
|
| 951 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories imported').'</div>'; |
| 952 |
return true; |
| 953 |
} |
| 954 |
|
| 955 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 956 |
return false; |
| 957 |
} |
| 958 |
|
| 959 |
private function _recursive_add_categories ($data = array(), $parent_id = 0, $level = 0 ) { |
| 960 |
$base = array( |
| 961 |
'category_title' => '', |
| 962 |
'parent_id' => $parent_id, |
| 963 |
'order_index' => '', |
| 964 |
'level' => $level, |
| 965 |
'font_icon_code' => '', |
| 966 |
'image_id' => '', |
| 967 |
'icon_id' => '', |
| 968 |
'code' => '', |
| 969 |
); |
| 970 |
|
| 971 |
$category_data = array_intersect_key(array_merge($base, $data), $base); |
| 972 |
array_walk($category_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 973 |
|
| 974 |
if(empty(wmvc_show_data('category_title', $category_data))) { |
| 975 |
return false; |
| 976 |
} |
| 977 |
|
| 978 |
if(!empty($category_data['image_id'])){ |
| 979 |
|
| 980 |
$file = false; |
| 981 |
if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['image_id'])) |
| 982 |
{ |
| 983 |
$file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['image_id']; |
| 984 |
} |
| 985 |
elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id'])) |
| 986 |
{ |
| 987 |
$file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id']; |
| 988 |
} |
| 989 |
elseif(file_exists( WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['image_id'])) |
| 990 |
{ |
| 991 |
$file = WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['image_id']; |
| 992 |
} |
| 993 |
/* add files */ |
| 994 |
|
| 995 |
if($file) |
| 996 |
$category_data['image_id'] = wmvc_add_wp_image($file); |
| 997 |
} |
| 998 |
|
| 999 |
if(!empty($category_data['icon_id'])){ |
| 1000 |
/* add files */ |
| 1001 |
$file = false; |
| 1002 |
if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['icon_id'])) |
| 1003 |
{ |
| 1004 |
$file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['icon_id']; |
| 1005 |
} |
| 1006 |
elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id'])) |
| 1007 |
{ |
| 1008 |
$file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id']; |
| 1009 |
} |
| 1010 |
elseif(file_exists( WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['icon_id'])) |
| 1011 |
{ |
| 1012 |
$file = WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['icon_id']; |
| 1013 |
} |
| 1014 |
/* add files */ |
| 1015 |
|
| 1016 |
if($file) |
| 1017 |
$category_data['icon_id'] = wmvc_add_wp_image($file); |
| 1018 |
} |
| 1019 |
|
| 1020 |
$category_data['icon_path'] = wdk_generate_path_image($category_data['icon_id']); |
| 1021 |
$category_data['image_path'] = wdk_generate_path_image($category_data['image_id']); |
| 1022 |
|
| 1023 |
/* add categories */ |
| 1024 |
$insert_id = $this->category_m->insert($category_data, NULL); |
| 1025 |
if(isset($data['childs']["category"]) && !empty($data['childs']["category"])) { |
| 1026 |
foreach ($data['childs']["category"] as $sub_category_data) { |
| 1027 |
$this->_recursive_add_categories($sub_category_data, $insert_id, ($level+1)); |
| 1028 |
} |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
private function import_fields($purpose = '') { |
| 1033 |
$this->load->model('field_m'); |
| 1034 |
$this->load->model('listingfield_m'); |
| 1035 |
|
| 1036 |
if($this->field_m->get()){ |
| 1037 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Fields already imported', 'wpdirectorykit').'</div>'; |
| 1038 |
return false; |
| 1039 |
} |
| 1040 |
|
| 1041 |
$xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose; |
| 1042 |
|
| 1043 |
$sections_added_array = array(); |
| 1044 |
if(file_exists($xml_list)) { |
| 1045 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 1046 |
|
| 1047 |
$base = array( |
| 1048 |
'field_type' => '', |
| 1049 |
'field_label' => '', |
| 1050 |
'hint' => '', |
| 1051 |
'columns_number' => '', |
| 1052 |
'is_visible_frontend' => '1', |
| 1053 |
'is_visible_dashboard' => '1', |
| 1054 |
'prefix' => '', |
| 1055 |
'suffix' => '', |
| 1056 |
'values_list' => '', |
| 1057 |
'icon_id' => '', |
| 1058 |
'is_required' => '', |
| 1059 |
); |
| 1060 |
|
| 1061 |
if(!isset($dom_array['fields']['field']) && empty($dom_array['fields']['field'])) { |
| 1062 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1063 |
return false; |
| 1064 |
} |
| 1065 |
$order_index = 0; |
| 1066 |
foreach ($dom_array['fields']['field'] as $key => $field) { |
| 1067 |
$field_data = array_intersect_key(array_merge($base, $field), $base); |
| 1068 |
array_walk($field_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 1069 |
|
| 1070 |
if(empty(wmvc_show_data('field_type', $field_data)) || empty(wmvc_show_data('field_label', $field_data))) { |
| 1071 |
continue; |
| 1072 |
} |
| 1073 |
|
| 1074 |
$field_data['is_visible_frontend'] = 1; |
| 1075 |
$field_data['is_visible_dashboard'] = 1; |
| 1076 |
|
| 1077 |
|
| 1078 |
/* special set number format for price fields */ |
| 1079 |
if($field_data['field_label'] == 'Rent Price' || $field_data['field_label'] == 'Sale Price') { |
| 1080 |
$field_data['is_price_format'] = 1; |
| 1081 |
} |
| 1082 |
|
| 1083 |
if(!in_array($field['section'], $sections_added_array)) { |
| 1084 |
/* add section */ |
| 1085 |
$section_data = array( |
| 1086 |
'field_type' => 'SECTION', |
| 1087 |
'field_label' => $field['section'], |
| 1088 |
'columns_number' => '12', |
| 1089 |
'is_visible_frontend' => '1', |
| 1090 |
'is_visible_dashboard' => '1', |
| 1091 |
'order_index' => ++$order_index, |
| 1092 |
); |
| 1093 |
/* add field */ |
| 1094 |
$this->field_m->insert($section_data, NULL); |
| 1095 |
|
| 1096 |
$sections_added_array[] = $field['section']; |
| 1097 |
} |
| 1098 |
|
| 1099 |
$field_data['order_index'] = ++$order_index; |
| 1100 |
/* add field */ |
| 1101 |
$insert_id = $this->field_m->insert($field_data, NULL); |
| 1102 |
// check if column exists, add if nto exists |
| 1103 |
if(!empty($insert_id)) |
| 1104 |
$this->listingfield_m->create_table_column($field_data, $insert_id); |
| 1105 |
} |
| 1106 |
|
| 1107 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields imported').'</div>'; |
| 1108 |
return true; |
| 1109 |
} |
| 1110 |
|
| 1111 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1112 |
return false; |
| 1113 |
} |
| 1114 |
|
| 1115 |
private function import_listings($purpose = '') { |
| 1116 |
$this->load->model('field_m'); |
| 1117 |
$this->load->model('listingfield_m'); |
| 1118 |
$this->load->model('listing_m'); |
| 1119 |
$this->load->model('category_m'); |
| 1120 |
$this->load->model('location_m'); |
| 1121 |
$this->load->model('listingusers_m'); |
| 1122 |
|
| 1123 |
if($this->listing_m->get()){ |
| 1124 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listings already imported', 'wpdirectorykit').'</div>'; |
| 1125 |
return false; |
| 1126 |
} |
| 1127 |
|
| 1128 |
/* generate listings */ |
| 1129 |
$categories_list = $this->category_m->get(); |
| 1130 |
$locations_list = $this->location_m->get(); |
| 1131 |
$categories = array(); |
| 1132 |
$locations = array(); |
| 1133 |
if($categories_list) |
| 1134 |
foreach($categories_list as $category){ |
| 1135 |
$categories[] = $category->idcategory; |
| 1136 |
} |
| 1137 |
if($locations_list) |
| 1138 |
foreach($locations_list as $location){ |
| 1139 |
$locations[] = $location->idlocation; |
| 1140 |
} |
| 1141 |
|
| 1142 |
$this->db->where(array('field_type !='=> 'SECTION')); |
| 1143 |
$fields = $this->field_m->get(); |
| 1144 |
|
| 1145 |
$listingfield_list = $this->listingfield_m->get_available_fields(); |
| 1146 |
foreach($fields as $key => $field_data) { |
| 1147 |
if(!isset($listingfield_list['field_'.$field_data->idfield.'_'.$field_data->field_type])) { |
| 1148 |
unset($fields[$key]); |
| 1149 |
} |
| 1150 |
} |
| 1151 |
|
| 1152 |
// Open a known directory, and proceed to read its contents |
| 1153 |
$dir = WPDIRECTORYKIT_PATH.'demo-data/images'; |
| 1154 |
$purpose_name = str_replace('.xml','',$purpose); |
| 1155 |
$files = array(); |
| 1156 |
if (is_dir($dir)) { |
| 1157 |
if ($dh = opendir($dir)) { |
| 1158 |
while (($file = readdir($dh)) !== false) { |
| 1159 |
if(strpos($file, '.jpg') !== false && strpos($file, $purpose_name) !== false && strpos($file, 'category') === false) |
| 1160 |
$files[] = $file; |
| 1161 |
} |
| 1162 |
closedir($dh); |
| 1163 |
} |
| 1164 |
} |
| 1165 |
sort($files); |
| 1166 |
|
| 1167 |
$xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose; |
| 1168 |
if(file_exists($xml_list)) { |
| 1169 |
$dom_array = $this->xmlstr_to_array(file_get_contents($xml_list)); |
| 1170 |
if(!isset($dom_array['listings']['listing']) && empty($dom_array['listings']['listing'])) { |
| 1171 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No listings in xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1172 |
return false; |
| 1173 |
} |
| 1174 |
|
| 1175 |
/* demo agent add/get if exists */ |
| 1176 |
$user_ids = array(); |
| 1177 |
$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'=>'#')); |
| 1178 |
$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'=>'#')); |
| 1179 |
$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'=>'#')); |
| 1180 |
|
| 1181 |
foreach ($dom_array['listings']['listing'] as $listing_num => $listing) { |
| 1182 |
$location_id = ''; |
| 1183 |
$category_id = ''; |
| 1184 |
|
| 1185 |
if(!empty($categories)) |
| 1186 |
$category_id = $categories[rand(0, count($categories)-1)]; |
| 1187 |
|
| 1188 |
if(!empty($location)) |
| 1189 |
$location_id = $locations[rand(0, count($locations)-1)]; |
| 1190 |
|
| 1191 |
$data_listing = array( |
| 1192 |
'post_title' => '', |
| 1193 |
'post_content' => '', |
| 1194 |
'category_id' => $category_id, |
| 1195 |
'location_id' => $location_id, |
| 1196 |
'address' => '', |
| 1197 |
'lat' => '', |
| 1198 |
'listing_images' => '', |
| 1199 |
'listing_images_path' => '', |
| 1200 |
'listing_images_path_medium' => '', |
| 1201 |
'date_modified' => date('Y-m-d H:i:s'), |
| 1202 |
'lng' => '', |
| 1203 |
'is_featured' => '', |
| 1204 |
'is_activated' => '1', |
| 1205 |
'is_approved' => '1', |
| 1206 |
'user_id_editor' => NULL, |
| 1207 |
); |
| 1208 |
|
| 1209 |
$data_listing = array_intersect_key(array_merge($data_listing, $listing), $data_listing); |
| 1210 |
array_walk($data_listing, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));}); |
| 1211 |
|
| 1212 |
if(empty(wmvc_show_data('post_title', $data_listing))) { |
| 1213 |
continue; |
| 1214 |
} |
| 1215 |
|
| 1216 |
/*fields */ |
| 1217 |
foreach($fields as $field_data) { |
| 1218 |
if(isset($listing['field_'.$field_data->idfield])) { |
| 1219 |
$data_listing['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield]; |
| 1220 |
} else { |
| 1221 |
if($field_data->field_type == 'DROPDOWN' || $field_data->field_type == 'DROPDOWN_MULTIPLE') |
| 1222 |
{ |
| 1223 |
if(empty($field_data->values_list)) continue; |
| 1224 |
$values = explode(',', $field_data->values_list); |
| 1225 |
if(count($values) > 0) |
| 1226 |
{ |
| 1227 |
$start=0; |
| 1228 |
if(empty($values[0]))$start=1; |
| 1229 |
$data_listing['field_'.$field_data->idfield] = $values[rand($start, count($values)-1)]; |
| 1230 |
} |
| 1231 |
} |
| 1232 |
elseif($field_data->field_type == 'NUMBER') |
| 1233 |
{ |
| 1234 |
$data_listing['field_'.$field_data->idfield] = rand(2,499); |
| 1235 |
} |
| 1236 |
elseif($field_data->field_type == 'CHECKBOX') |
| 1237 |
{ |
| 1238 |
$data_listing['field_'.$field_data->idfield] = rand(0,1); |
| 1239 |
} |
| 1240 |
elseif($field_data->field_type == 'TEXTAREA') |
| 1241 |
{ |
| 1242 |
//$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.'; |
| 1243 |
} |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
/* add files */ |
| 1248 |
$count_images = 2; |
| 1249 |
if($purpose == 'car-dealer.xml') { |
| 1250 |
$count_images = 1; |
| 1251 |
} |
| 1252 |
|
| 1253 |
for ($i=0,$image_num=$listing_num; $i<$count_images; $i++,$image_num++) { |
| 1254 |
if($image_num >= count($files)) |
| 1255 |
$image_num = 0; |
| 1256 |
|
| 1257 |
if(!empty($data_listing['listing_images'])) |
| 1258 |
$data_listing['listing_images'].= ','; |
| 1259 |
|
| 1260 |
$image_id = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'demo-data/images/'.esc_html($files[$image_num])); |
| 1261 |
$data_listing['listing_images'] .= $image_id; |
| 1262 |
|
| 1263 |
$image_path = wp_get_original_image_path( $image_id); |
| 1264 |
|
| 1265 |
if($image_path) { |
| 1266 |
/* path of image */ |
| 1267 |
$next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path); |
| 1268 |
|
| 1269 |
/* check length listing_images_path + next image + comma, should be less 200*/ |
| 1270 |
if(strlen($data_listing['listing_images_path'].$next_path)<195) { |
| 1271 |
if(!empty($data_listing['listing_images_path'])) |
| 1272 |
$data_listing['listing_images_path'] .= ','; |
| 1273 |
|
| 1274 |
$data_listing['listing_images_path'] .= $next_path; |
| 1275 |
} |
| 1276 |
} |
| 1277 |
|
| 1278 |
$image_url = wp_get_attachment_image_url($image_id, 'large'); |
| 1279 |
if($image_url) { |
| 1280 |
$parsed = parse_url($image_url); |
| 1281 |
$next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8); |
| 1282 |
|
| 1283 |
if(!empty($data_listing['listing_images_path_medium'])) |
| 1284 |
$data_listing['listing_images_path_medium'] .= ','; |
| 1285 |
|
| 1286 |
$data_listing['listing_images_path_medium'] .= $next_path; |
| 1287 |
} |
| 1288 |
} |
| 1289 |
|
| 1290 |
// Create post object |
| 1291 |
$listing_post = array( |
| 1292 |
'ID' => NULL, |
| 1293 |
'post_type' => 'wdk-listing', |
| 1294 |
'post_title' => wp_strip_all_tags( $data_listing['post_title'] ), |
| 1295 |
'post_content' => $data_listing['post_content'], |
| 1296 |
'post_status' => 'publish', |
| 1297 |
'post_author' => get_current_user_id() |
| 1298 |
); |
| 1299 |
// Insert the post into the database |
| 1300 |
$id = wp_insert_post( $listing_post ); |
| 1301 |
|
| 1302 |
$listing_data = array('post_id' => $id); |
| 1303 |
$listing_data_fields = array('category_id', 'location_id', 'address', 'lat', 'lng', 'listing_images', 'is_featured', 'is_activated','is_approved','listing_images_path', 'listing_images_path_medium'); |
| 1304 |
foreach($listing_data_fields as $field_name) |
| 1305 |
{ |
| 1306 |
if(isset( $data_listing[$field_name])) |
| 1307 |
$listing_data[$field_name] = $data_listing[$field_name]; |
| 1308 |
} |
| 1309 |
$listing_data['user_id_editor'] = $user_ids[array_rand($user_ids)]; |
| 1310 |
|
| 1311 |
$this->listing_m->insert($listing_data, NULL); |
| 1312 |
|
| 1313 |
$data_listing['post_id'] = $id; |
| 1314 |
$this->listingfield_m->insert_custom_fields($fields, $data_listing, NULL); |
| 1315 |
} |
| 1316 |
$this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported').'</div>'; |
| 1317 |
return true; |
| 1318 |
} |
| 1319 |
|
| 1320 |
$this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>'; |
| 1321 |
return false; |
| 1322 |
} |
| 1323 |
|
| 1324 |
protected function xmlstr_to_array($xmlstr) { |
| 1325 |
$doc = new DOMDocument(); |
| 1326 |
|
| 1327 |
if ( !@$doc->loadXML($xmlstr) ) { |
| 1328 |
return false; |
| 1329 |
} |
| 1330 |
|
| 1331 |
$root = $doc->documentElement; |
| 1332 |
$output = $this->domnode_to_array($root); |
| 1333 |
$output['@root'] = $root->tagName; |
| 1334 |
return $output; |
| 1335 |
} |
| 1336 |
|
| 1337 |
protected function domnode_to_array($node) { |
| 1338 |
$output = array(); |
| 1339 |
switch ($node->nodeType) { |
| 1340 |
case XML_CDATA_SECTION_NODE: |
| 1341 |
case XML_TEXT_NODE: |
| 1342 |
$output = trim($node->textContent); |
| 1343 |
break; |
| 1344 |
case XML_ELEMENT_NODE: |
| 1345 |
for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) { |
| 1346 |
$child = $node->childNodes->item($i); |
| 1347 |
$v = $this->domnode_to_array($child); |
| 1348 |
if(isset($child->tagName)) { |
| 1349 |
$t = $child->tagName; |
| 1350 |
if(!isset($output[$t])) { |
| 1351 |
$output[$t] = array(); |
| 1352 |
} |
| 1353 |
$output[$t][] = $v; |
| 1354 |
} |
| 1355 |
elseif($v || $v === '0') { |
| 1356 |
$output = (string) $v; |
| 1357 |
} |
| 1358 |
} |
| 1359 |
if($node->attributes->length && !is_array($output)) { //Has attributes but isn't an array |
| 1360 |
$output = array('@content'=>$output); //Change output into an array. |
| 1361 |
} |
| 1362 |
if(is_array($output)) { |
| 1363 |
if($node->attributes->length) { |
| 1364 |
$a = array(); |
| 1365 |
foreach($node->attributes as $attrName => $attrNode) { |
| 1366 |
$a[$attrName] = (string) $attrNode->value; |
| 1367 |
} |
| 1368 |
$output['@attributes'] = $a; |
| 1369 |
} |
| 1370 |
foreach ($output as $t => $v) { |
| 1371 |
if(is_array($v) && count($v)==1 && $t!='@attributes') { |
| 1372 |
$output[$t] = $v[0]; |
| 1373 |
} |
| 1374 |
} |
| 1375 |
} |
| 1376 |
break; |
| 1377 |
} |
| 1378 |
return $output; |
| 1379 |
} |
| 1380 |
|
| 1381 |
public function run() |
| 1382 |
{ |
| 1383 |
ini_set('max_execution_time', 900); |
| 1384 |
$this->data['import_log'] = ''; |
| 1385 |
$multipurpose = 'real-estate.xml'; |
| 1386 |
if(isset($_GET['multipurpose'])) |
| 1387 |
$multipurpose = sanitize_text_field($_GET['multipurpose']); |
| 1388 |
|
| 1389 |
$redirect_url = admin_url("admin.php?page=wdk_fields&is_updated"); |
| 1390 |
if(isset($_GET['redirect_url'])) |
| 1391 |
$redirect_url = sanitize_text_field($_GET['redirect_url']); |
| 1392 |
|
| 1393 |
$this->import_locations(); |
| 1394 |
$this->import_categories($multipurpose); |
| 1395 |
$this->import_fields($multipurpose); |
| 1396 |
$this->import_listings($multipurpose); |
| 1397 |
$this->import_visual_data($multipurpose); |
| 1398 |
$this->demo_pages($multipurpose); |
| 1399 |
|
| 1400 |
$message = str_replace(" ", '+', __('Import completed successfuly', 'wpdirectorykit')); |
| 1401 |
|
| 1402 |
wp_redirect($redirect_url.'&message='.$message); |
| 1403 |
exit; |
| 1404 |
} |
| 1405 |
|
| 1406 |
public function api_import() |
| 1407 |
{ |
| 1408 |
ini_set('max_execution_time', 900); |
| 1409 |
$this->data['import_log'] = ''; |
| 1410 |
$multipurpose = 'real-estate.xml'; |
| 1411 |
if(isset($_GET['multipurpose'])) |
| 1412 |
$multipurpose = sanitize_text_field($_GET['multipurpose']); |
| 1413 |
|
| 1414 |
$this->import_locations(); |
| 1415 |
$this->import_categories($multipurpose); |
| 1416 |
$this->import_fields($multipurpose); |
| 1417 |
$this->import_listings($multipurpose); |
| 1418 |
$this->import_visual_data($multipurpose); |
| 1419 |
$this->import_settings(); |
| 1420 |
|
| 1421 |
/* action */ |
| 1422 |
do_action('wpdirectorykit/install/api'); |
| 1423 |
|
| 1424 |
return true; |
| 1425 |
} |
| 1426 |
|
| 1427 |
private function replace_meta($from = '', $to = '') { |
| 1428 |
global $wpdb; |
| 1429 |
// @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes |
| 1430 |
$rows_affected = $wpdb->query( |
| 1431 |
"UPDATE ".esc_sql($wpdb->postmeta)." " . |
| 1432 |
"SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', esc_sql($from) ) . "', '" . str_replace( '/', '\\\/', esc_sql($to) ) . "') " . |
| 1433 |
"WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" ); |
| 1434 |
/* end login */ |
| 1435 |
} |
| 1436 |
|
| 1437 |
public function import_settings() { |
| 1438 |
update_option( 'wdk_is_category_enabled', '1' ); |
| 1439 |
update_option( 'wdk_is_location_enabled', '1' ); |
| 1440 |
update_option( 'wdk_is_address_enabled', '1' ); |
| 1441 |
update_option( 'wdk_is_results_page_require', '1' ); |
| 1442 |
update_option( 'wdk_seo_description', '2' ); |
| 1443 |
update_option( 'wdk_seo_keywords', '3' ); |
| 1444 |
update_option( 'wdk_card_slider_enable', '1' ); |
| 1445 |
return true; |
| 1446 |
} |
| 1447 |
|
| 1448 |
} |
| 1449 |
|