- Fixed for compatible with mysql for server infor page

- Fixed issue of listing wp timecapsule backups for some sites
- Fixed to support to fix issue of missing created post report - pro reports
- Fixed to display author name but not email for reports - pro reports
- Fixed issue of json encode response for some sites
- Fixed issue of incorrect url image of bulk post for some sites.
This commit is contained in:
thanghv 2020-03-27 19:18:06 +07:00
parent 14e9fd366b
commit df07e5a833
5 changed files with 132 additions and 25 deletions

View file

@ -1154,7 +1154,7 @@ class MainWP_Child_Server_Information {
/** @var $wpdb wpdb */
global $wpdb;
return $wpdb->get_var( 'SHOW VARIABLES LIKE "version"', 1 );
return $wpdb->get_var( "SHOW VARIABLES LIKE 'version'", 1 );
}
protected static function getMaxInputTime() {

View file

@ -301,7 +301,7 @@ class MainWP_Child_Timecapsule {
global $wpdb;
$all_backups = $wpdb->get_results(
$wpdb->prepare("
SELECT *
SELECT backupID
FROM {$wpdb->base_prefix}wptc_processed_files
WHERE backupID > %s ", $last_time)
);

View file

@ -7,7 +7,7 @@ if ( defined( 'MAINWP_DEBUG' ) && MAINWP_DEBUG === TRUE ) {
if (isset($_REQUEST['mainwpsignature'])) {
@ini_set( 'display_errors', FALSE );
@error_reporting( 0 );
}
}
}
define( 'MAINWP_CHILD_NR_OF_COMMENTS', 50 );
@ -4623,9 +4623,9 @@ class MainWP_Child {
$outComment['author_url'] = get_comment_author_url( $comment->comment_ID );
$outComment['author_ip'] = get_comment_author_IP( $comment->comment_ID );
$outComment['author_email'] = $email = apply_filters( 'comment_email', $comment->comment_author_email );
if ( ( ! empty( $outComment['author_email'] ) ) && ( '@' !== $outComment['author_email'] ) ) {
$outComment['author_email'] = '<a href="mailto:' . $outComment['author_email'] . '">' . $outComment['author_email'] . '</a>';
}
// if ( ( ! empty( $outComment['author_email'] ) ) && ( '@' !== $outComment['author_email'] ) ) {
// $outComment['author_email'] = '<a href="mailto:' . $outComment['author_email'] . '">' . $outComment['author_email'] . '</a>';
// }
$outComment['postId'] = $comment->comment_post_ID;
$outComment['postName'] = $post->post_title;
$outComment['comment_count'] = $post->comment_count;

View file

@ -332,9 +332,65 @@ class MainWP_Client_Report {
if ( ! is_array( $records ) ) {
$records = array();
}
// to fix invalid data
// to fix invalid data, or skip records
$skip_records = array();
// to fix for incorrect posts created logging
// query created posts from WP posts data to simulate records logging for created posts
if ( isset($_POST['direct_posts']) && !empty($_POST['direct_posts']) ) {
$query_string = array(
'post_type' => 'post',
'date_query' => array(
'column' => 'post_date',
'after' => $args['date_from'],
'before' => $args['date_to']
),
'post_status' => 'publish'
);
$records_created_posts = query_posts( $query_string );
if ($records_created_posts) {
for( $i = 0; $i < count($records); $i++ ) {
$record = $records[$i];
if ($record->connector == 'posts' && $record->context == 'post' && $record->action == 'created') {
if (!in_array($record->ID, $skip_records)) {
$skip_records[] = $record->ID; // so avoid this created logging, will use logging query from posts data
}
}
}
$post_authors = array();
foreach( $records_created_posts as $_post){
$au_id = $_post->post_author;
if ( !isset($post_authors[$au_id]) ) {
$au = get_user_by( 'id', $au_id );
$post_authors[$au_id] = $au->display_name;
}
$au_name = $post_authors[$au_id];
//simulate logging created posts record
$stdObj = new stdClass;
$stdObj->ID = 0; // simulate ID value
$stdObj->connector = 'posts';
$stdObj->context = 'post';
$stdObj->action = 'created';
$stdObj->created = $_post->post_date;
$stdObj->meta = array(
'post_title' => array( $_post->post_title ),
'user_meta' => array( $au_name )
);
$records[] = $stdObj;
}
}
}
if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
$other_tokens_data['header'] = $this->get_other_tokens_data( $records, $other_tokens['header'], $skip_records);
}
@ -437,6 +493,10 @@ class MainWP_Client_Report {
if ( ! in_array( $record->context, $comment_contexts ) ) {
continue;
}
} else if ( 'post' === $context && 'created' === $action ) {
if ( in_array($record->ID, $skip_records) ) {
continue;
}
} else if ( $context == "menus") {
// ok, pass, don't check context
} else if ( $record->connector == 'editor' ) {
@ -496,7 +556,7 @@ class MainWP_Client_Report {
continue;
}
}
}
}
}
$count ++;
}
@ -817,9 +877,10 @@ class MainWP_Client_Report {
if ( isset( $record->meta ) ) {
$meta = $record->meta;
if ( isset( $meta[ $meta_key ] ) ) {
if ( isset( $meta[ $meta_key ] ) ) {
$value = $meta[ $meta_key ];
$value = current( $value );
$value = ( $meta_key == 'user_meta' && isset($value[1]) ) ? $value[1] : current( $value ); // display name
// to compatible with old meta data
if ( 'author_meta' === $meta_key ) {

View file

@ -9,28 +9,72 @@ class MainWP_Helper {
$output = serialize( $val );
endif;
die( '<mainwp>' . base64_encode( $output ) . '</mainwp>' );
die( '<mainwp>' . base64_encode( $output ) . '</mainwp>');
}
public static function utf8ize($mixed) {
if (is_array($mixed)) {
foreach ($mixed as $key => $value) {
$mixed[$key] = self::utf8ize($value);
public static function json_valid_check( $data ) {
if (is_array( $data )) {
$output = array();
foreach ( $data as $key => $value) {
if ( is_string( $key ) ) {
$id = self::json_convert_string( $key );
} else {
$id = $key;
}
} elseif (is_string($mixed)) {
if ( function_exists( 'mb_convert_encoding' )) {
return mb_convert_encoding($mixed, "UTF-8", "UTF-8");
if ( is_array( $value ) || is_object( $value ) ) {
$output[ $id ] = self::json_valid_check( $value );
} elseif ( is_string( $value ) ) {
$output[ $id ] = self::json_convert_string( $value );
} else {
$output[ $id ] = $value;
}
}
}
elseif ( is_object( $data ) ) {
$output = new stdClass;
foreach ( $data as $key => $value ) {
if ( is_string( $key ) ) {
$id = self::json_convert_string( $key );
} else {
$id = $key;
}
if ( is_array( $value ) || is_object( $value ) ) {
$output->$id = self::json_valid_check($value);
} elseif ( is_string( $value ) ) {
$output->$id = self::json_convert_string( $value );
} else {
$output->$id = $value;
}
}
}
elseif (is_string( $data )) {
return self::json_convert_string( $data );
} else {
return $data;
}
return $mixed;
return $output;
}
public function json_convert_string( $str ) {
if ( function_exists( 'mb_convert_encoding' )) {
$encoding = mb_detect_encoding( $str, mb_detect_order(), true );
if ( $encoding ) {
return mb_convert_encoding( $str, 'UTF-8', $encoding );
} else {
return mb_convert_encoding( $str, 'UTF-8', 'UTF-8' );
}
}
return $str;
}
public static function safe_json_encode($value, $options = 0, $depth = 512) {
$encoded = @json_encode($value, $options, $depth);
if ($encoded === false && $value && json_last_error() == JSON_ERROR_UTF8) {
$encoded = @json_encode(self::utf8ize($value), $options, $depth);
if ($encoded === false && !empty( $value ) && json_last_error() == JSON_ERROR_UTF8 ) {
$encoded = @json_encode(self::json_valid_check($value), $options, $depth);
}
return $encoded;
return $encoded ;
}
static function close_connection( $val = null ) {
@ -170,7 +214,7 @@ class MainWP_Helper {
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . $filename; //Local name
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
$gen_unique_fn = true;
//$gen_unique_fn = true;
// to fix issue re-create new attachment
if ( $check_file_existed ) {
@ -210,7 +254,9 @@ class MainWP_Helper {
}
}
if ( $gen_unique_fn ) {
// file exists, do not overwrite, generate unique file name
// this may causing of issue incorrect source of image in post content
if ( file_exists( $local_img_path ) ) {
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
}