Merged with branch01

* Fixed: an issue with checking Page Speed data
* Fixed: an issue with empty update data
* Fixed: an issue with incorrect plugin update data
* Added: Send From field in the Branding support form
* Updated: compatibility with the latest Yoast SEO plugin version
This commit is contained in:
Thang Hoang Van 2019-03-25 22:11:41 +07:00
parent 37c30fbf58
commit c06edcf95e
8 changed files with 131 additions and 37 deletions

View file

@ -793,13 +793,15 @@ class MainWP_Child_Branding {
public function send_support_mail() {
$email = $this->child_branding_options['support_email'];
$sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
$from = trim($_POST['mainwp_branding_contact_send_from']);
$subject = !empty( $sub ) ? $sub : "MainWP - Support Contact";
$content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
$mail = $headers = '';
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
global $current_user;
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
//$headers .= "From: \"" . $current_user->user_email . "\" <" . $current_user->user_email . ">\r\n";
if (!empty($from))
$headers .= "From: \"" . $from . "\" <" . $from . ">\r\n";
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
$mail .= "<p>Sent from WordPress page: " . ( ! empty( $_POST["mainwp_branding_send_from_page"] ) ? "<a href='" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "'>" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "</a></p>\r\n\r\n" : "" );
$mail .= "<p>Client Email: " . $current_user->user_email . " </p>\r\n\r\n";
@ -817,6 +819,7 @@ class MainWP_Child_Branding {
}
function contact_support() {
global $current_user;
?>
<style>
.mainwp_info-box-yellow {
@ -867,6 +870,7 @@ class MainWP_Child_Branding {
$support_message = $opts['support_message'];
$support_message = nl2br( stripslashes( $support_message ) );
$from_email = $current_user ? $current_user->user_email : '';
?>
<form action="" method="post">
<div style="width: 99%;">
@ -875,7 +879,9 @@ class MainWP_Child_Branding {
<div style="height: auto; margin-bottom: 10px; text-align: left">
<p><?php echo wp_kses_post( $support_message ); ?></p>
<p><label for="mainwp_branding_contact_message_subject"><?php _e('Subject:', 'mainwp-child'); ?></label><br>
<input type="text" name="mainwp_branding_contact_message_subject" style="width: 650px;"></p>
<input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;"></p>
<p><label for="mainwp_branding_contact_send_from"><?php _e('From:', 'mainwp-child'); ?></label><br>
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_html( $from_email ); ?>"></p>
<div style="max-width: 650px;">
<label for="mainwp_branding_contact_message_content"><?php _e('Your message:', 'mainwp-child'); ?></label><br>
<?php

View file

@ -272,7 +272,8 @@ class MainWP_Child_Pagespeed {
if ( $checkstatus ) {
$information['error'] = __( 'The API is busy checking other pages, please try again later.', 'gpagespeedi' );
} else {
do_action( 'googlepagespeedinsightsworker', array(), $forceRecheck );
//do_action( 'googlepagespeedinsightsworker', array(), $forceRecheck );
do_action( 'run_gpi', $forceRecheck ); // to fix
$information['checked_pages'] = 1;
}
}

View file

@ -928,7 +928,8 @@ class MainWP_Child_Updraft_Plus_Backups {
);
// to fix issue for some site
//$this->close_browser_connection( $msg );
// unfix for tic#22678
$this->close_browser_connection( $msg );
$options = array( 'nocloud' => $backupnow_nocloud, 'use_nonce' => $nonce );
if ( ! empty( $_REQUEST['onlythisfileentity'] ) && is_string( $_REQUEST['onlythisfileentity'] ) ) {

View file

@ -115,7 +115,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
}
class MainWP_Child {
public static $version = '3.5.5';
public static $version = '3.5.6';
private $update_version = '1.5';
private $callableFunctions = array(
@ -3819,6 +3819,11 @@ class MainWP_Child {
continue;
}
// to fix incorrect info
if ( !property_exists( $plugin_update, 'update' ) || !property_exists( $plugin_update->update, 'new_version' ) || empty($plugin_update->update->new_version)) {
continue;
}
$information['plugin_updates'][ $slug ] = $plugin_update;
}
}
@ -3834,6 +3839,10 @@ class MainWP_Child {
$information['plugin_updates'] = array();
}
foreach( $cached_plugins_update as $slug => $plugin_update ) {
// to fix incorrect info
if ( !property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) {
continue;
}
if ( !isset( $information['plugin_updates'][ $slug ] ) ) {
$information['plugin_updates'][ $slug ] = $plugin_update;
}
@ -3894,7 +3903,8 @@ class MainWP_Child {
if ( 'plugin' === $translation_update->type ) {
$all_plugins = get_plugins();
foreach ( $all_plugins as $file => $plugin ) {
if ( stristr( $file, $translation_update->slug ) ) {
$path = dirname($file);
if ( $path == $translation_update->slug ) {
$new_translation_update['name'] = $plugin['Name'];
break;
}

View file

@ -134,17 +134,45 @@ class MainWP_Helper {
if ( is_wp_error( $temporary_file ) ) {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
} else {
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); //Local name
$filename = basename( $img_url );
$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;
// to fix issue re-create new attachment
if ( $check_file_existed ) {
if ( file_exists( $local_img_path ) ) {
if ( filesize( $local_img_path ) == filesize( $temporary_file ) ) { // file exited
$attach_id = attachment_url_to_postid( $local_img_url );
if ( $attach_id ) { // found attachment
return array( 'id' => $attach_id, 'url' => $local_img_url );
$result = self::get_maybe_existed_attached_id( $local_img_url );
if ( is_array($result) ) { // found attachment
$attach = current($result);
if (is_object($attach)) {
if ( file_exists( $temporary_file ) ) {
unlink( $temporary_file );
}
return array( 'id' => $attach->ID, 'url' => $local_img_url );
}
}
}
} else { // find in other path
$result = self::get_maybe_existed_attached_id( $filename, false );
if ( is_array( $result ) ) { // found attachment
$attach = current($result);
if (is_object($attach)) {
$basedir = $upload_dir['basedir'];
$baseurl = $upload_dir['baseurl'];
$local_img_path = str_replace( $baseurl, $basedir, $attach->guid );
if ( file_exists($local_img_path) && (filesize( $local_img_path ) == filesize( $temporary_file )) ) { // file exited
if ( file_exists( $temporary_file ) ) {
unlink( $temporary_file );
}
return array( 'id' => $attach->ID, 'url' => $attach->guid );
}
}
}
}
@ -189,10 +217,17 @@ class MainWP_Helper {
return null;
}
static function get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
static function get_maybe_existed_attached_id( $filename, $full_guid = true ) {
global $wpdb;
if ( $full_guid ) {
$sql = $wpdb->prepare(
"SELECT ID,guid FROM $wpdb->posts WHERE post_type = 'attachment' AND guid = %s",
$filename
);
} else {
$sql = "SELECT ID,guid FROM $wpdb->posts WHERE post_type = 'attachment' AND guid LIKE '%/" . $filename . "'";
}
return $wpdb->get_results( $sql );
}
static function uploadFile( $file_url, $path, $file_name ) {

View file

@ -53,28 +53,62 @@ class MainWP_Wordpress_SEO {
}
public function import_settings() {
$file_url = base64_decode( $_POST['file_url'] );
$temporary_file = '';
try {
include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
$temporary_file = download_url( $file_url );
// to compatible
if ( isset($_POST['file_url']) ) {
$file_url = base64_decode( $_POST['file_url'] );
$temporary_file = '';
try {
include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
$temporary_file = download_url( $file_url );
if ( is_wp_error( $temporary_file ) ) {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
} else {
if ( $this->import_seo_settings( $temporary_file ) ) {
$information['success'] = true;
} else {
throw new Exception( __( 'Settings could not be imported.', 'wordpress-seo' ) );
}
}
} catch ( Exception $e ) {
$information['error'] = $e->getMessage();
}
if ( is_wp_error( $temporary_file ) ) {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
} else {
if ( $this->import_seo_settings( $temporary_file ) ) {
$information['success'] = true;
} else {
throw new Exception( __( 'Settings could not be imported.', 'wordpress-seo' ) );
}
}
} catch ( Exception $e ) {
$information['error'] = $e->getMessage();
}
if ( file_exists( $temporary_file ) ) {
unlink( $temporary_file );
}
} else if ( isset( $_POST['settings'] ) ) {
try {
$settings = base64_decode( $_POST['settings'] );
// @codingStandardsIgnoreLine
$options = parse_ini_string( $settings, true, INI_SCANNER_RAW ); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.parse_ini_stringFound -- We won't get to this function if PHP < 5.3 due to the WPSEO_NAMESPACES check above.
if ( is_array( $options ) && array() !== $options ) {
$old_wpseo_version = null;
if ( isset( $options['wpseo']['version'] ) && '' !== $options['wpseo']['version'] ) {
$old_wpseo_version = $options['wpseo']['version'];
}
foreach ( $options as $name => $optgroup ) {
if ( 'wpseo_taxonomy_meta' === $name ) {
$optgroup = json_decode( urldecode( $optgroup['wpseo_taxonomy_meta'] ), true );
}
// Make sure that the imported options are cleaned/converted on import
$option_instance = WPSEO_Options::get_option_instance( $name );
if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) {
$optgroup = $option_instance->import( $optgroup, $old_wpseo_version, $options );
}
}
$information['success'] = true;
} else {
throw new Exception( __( 'Settings could not be imported:', 'wordpress-seo' ) );
}
} catch ( Exception $e ) {
$information['error'] = $e->getMessage();
}
}
if ( file_exists( $temporary_file ) ) {
unlink( $temporary_file );
}
MainWP_Helper::write( $information );
}

View file

@ -6,7 +6,7 @@
Author: MainWP
Author URI: https://mainwp.com
Text Domain: mainwp-child
Version: 3.5.5
Version: 3.5.6
*/
//if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) {
// header( 'X-Frame-Options: ALLOWALL' );

View file

@ -6,8 +6,8 @@ Author: mainwp
Author URI: https://mainwp.com
Plugin URI: https://mainwp.com
Requires at least: 3.6
Tested up to: 5.1
Stable tag: 3.5.5
Tested up to: 5.1.1
Stable tag: 3.5.6
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -71,6 +71,13 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
== Changelog ==
= 3.5.6 - 3-25-19 =
* Fixed: an issue with checking Page Speed data
* Fixed: an issue with empty update data
* Fixed: an issue with incorrect plugin update data
* Added: Send From field in the Branding support form
* Updated: compatibility with the latest Yoast SEO plugin version
= 3.5.5 - 3-6-19 =
* Fixed: an issue with hook for controlling branding options for specific roles
* Fixed: branding issues