<?php _e("Restore Backup of WP-Property Configuration", ud_get_wp_property()->domain); ?> : <input name="wpp_settings[settings_from_backup]" class="" id="wpp_backup_file" type="file"/> <a href="<?php echo wp_nonce_url("edit.php?post_type=property&page=property_settings&wpp_action=download-wpp-backup", 'download-wpp-backup'); ?> "><?php _e('Download Backup of Current WP-Property Configuration.', ud_get_wp_property()->domain); ?> </a> </div> <div class="wpp_settings_block"> <?php $google_map_localizations = WPP_F::draw_localization_dropdown('return_array=true'); ?> <?php _e('Revalidate all addresses using', ud_get_wp_property()->domain); ?> <b><?php echo $google_map_localizations[$wp_properties['configuration']['google_maps_localization']]; ?> </b> <?php _e('localization', ud_get_wp_property()->domain); ?> <input type="button" value="<?php _e('Revalidate', ud_get_wp_property()->domain); ?> " id="wpp_ajax_revalidate_all_addresses" class="button"> </div>
/** * Revalidate all addresses * * Revalidates addresses of all publishd properties. * If Google daily addres lookup is exceeded, breaks the function and notifies the user. * * @since 1.05 * */ public static function revalidate_all_addresses($args = '') { global $wp_properties, $wpdb; set_time_limit(0); ob_start(); $args = wp_parse_args($args, array('property_ids' => false, 'echo_result' => 'true', 'skip_existing' => 'false', 'return_geo_data' => false, 'attempt' => 1, 'max_attempts' => 7, 'delay' => 0, 'increase_delay_by' => 0.25)); extract($args, EXTR_SKIP); $delay = isset($delay) ? $delay : 0; $attempt = isset($attempt) ? $attempt : 1; $max_attempts = isset($max_attempts) ? $max_attempts : 10; $increase_delay_by = isset($increase_delay_by) ? $increase_delay_by : 0.25; $echo_result = isset($echo_result) ? $echo_result : 'true'; $skip_existing = isset($skip_existing) ? $skip_existing : 'false'; $return_geo_data = isset($return_geo_data) ? $return_geo_data : false; if (is_array($args['property_ids'])) { $all_properties = $args['property_ids']; } else { $all_properties = $wpdb->get_col("\n SELECT ID FROM {$wpdb->posts} p\n left outer join {$wpdb->postmeta} pm on (pm.post_id=p.ID and pm.meta_key='wpp::last_address_validation' )\n WHERE p.post_type = 'property' AND p.post_status = 'publish'\n ORDER by pm.meta_value DESC\n "); } $return['updated'] = $return['failed'] = $return['over_query_limit'] = $return['over_query_limit'] = array(); $google_map_localizations = WPP_F::draw_localization_dropdown('return_array=true'); foreach ((array) $all_properties as $post_id) { if ($delay) { sleep($delay); } $result = WPP_F::revalidate_address($post_id, array('skip_existing' => $skip_existing, 'return_geo_data' => $return_geo_data)); $return[$result['status']][] = $post_id; if ($return_geo_data) { $return['geo_data'][$post_id] = $result['geo_data']; } } $return['attempt'] = $attempt; /* // Instead of re-revalidate, must be overwritten UI: to dp separate AJAX request for every property and output results dynamicly. if ( !empty( $return[ 'over_query_limit' ] ) && $max_attempts >= $attempt && $delay < 2 ) { $_args = array( 'property_ids' => $return[ 'over_query_limit' ], 'echo_result' => false, 'attempt' => $attempt + 1, 'delay' => $delay + $increase_delay_by, ) + $args; $rerevalidate_result = self::revalidate_all_addresses( $_args ); $return[ 'updated' ] = array_merge( (array) $return[ 'updated' ], (array) $rerevalidate_result[ 'updated' ] ); $return[ 'failed' ] = array_merge( (array) $return[ 'failed' ], (array) $rerevalidate_result[ 'failed' ] ); $return[ 'over_query_limit' ] = $rerevalidate_result[ 'over_query_limit' ]; $return[ 'attempt' ] = $rerevalidate_result[ 'attempt' ]; } //*/ foreach (array('updated', 'over_query_limit', 'failed', 'empty_address') as $status) { $return[$status] = $echo_result == 'true' ? count(array_unique((array) $return[$status])) : array_unique((array) $return[$status]); } $return['success'] = 'true'; $return['message'] = sprintf(__('Updated %1$d %2$s using the %3$s localization.', ud_get_wp_property()->domain), $echo_result == 'true' ? $return['updated'] : count($return['updated']), WPP_F::property_label('plural'), $google_map_localizations[$wp_properties['configuration']['google_maps_localization']]); if ($return['empty_address']) { $return['message'] .= "<br />" . sprintf(__('%1$d %2$s has empty address.', ud_get_wp_property()->domain), $echo_result == 'true' ? $return['empty_address'] : count($return['empty_address']), WPP_F::property_label('plural')); } if ($return['failed']) { $return['message'] .= "<br />" . sprintf(__('%1$d %2$s could not be updated.', ud_get_wp_property()->domain), $echo_result == 'true' ? $return['failed'] : count($return['failed']), WPP_F::property_label('plural')); } if ($return['over_query_limit']) { $return['message'] .= "<br />" . sprintf(__('%1$d %2$s was ignored because query limit was exceeded.', ud_get_wp_property()->domain), $echo_result == 'true' ? $return['over_query_limit'] : count($return['over_query_limit']), WPP_F::property_label('plural')); } //** Warning Silincer */ ob_end_clean(); if ($echo_result == 'true') { die(json_encode($return)); } else { return $return; } }