Merge with branch01 + version update

This commit is contained in:
ruben- 2017-05-11 21:07:42 +02:00
parent 0361aae19c
commit 1eb6842d53
11 changed files with 287 additions and 124 deletions

View file

@ -13,7 +13,9 @@ class MainWP_Child_Back_Up_Buddy {
}
public function __construct() {
if ( is_plugin_active( 'backupbuddy/backupbuddy.php' )) {
// To fix bug run dashboard on local machine
//if ( is_plugin_active( 'backupbuddy/backupbuddy.php' )) {
if ( class_exists('pb_backupbuddy')) {
$this->is_backupbuddy_installed = true;
}
@ -86,6 +88,10 @@ class MainWP_Child_Back_Up_Buddy {
return;
}
if ( ! class_exists( 'backupbuddy_core' ) ) {
require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' );
}
$backups = array();
$backup_sort_dates = array();
@ -155,7 +161,7 @@ class MainWP_Child_Back_Up_Buddy {
public function action() {
$information = array();
if ( ! $this->is_backupbuddy_installed || !class_exists('pb_backupbuddy')) {
if ( ! $this->is_backupbuddy_installed ) {
MainWP_Helper::write( array( 'error' => __( 'Please install the BackupBuddy plugin on the child site.', $this->plugin_translate ) ) );
}
@ -404,6 +410,7 @@ class MainWP_Child_Back_Up_Buddy {
'email_notify_send_finish',
'email_notify_send_finish_subject',
'email_notify_send_finish_body',
'no_new_backups_error_days',
'email_notify_error',
'email_notify_error_subject',
'email_notify_error_body',

View file

@ -1165,6 +1165,13 @@ class MainWP_Child_Back_WP_Up {
update_site_option( 'backwpup_messages', array() );
if (isset($settings['value']['backupdir']) && empty($settings['value']['backupdir'])) {
$backupdir = BackWPup_Option::get( (int)$job_id, 'backupdir' );
if (!empty($backupdir)) {
$settings['value']['backupdir'] = $backupdir;
}
}
foreach ( $settings['value'] as $key => $val ) {
$_POST[ $key ] = $val;
}

View file

@ -1074,7 +1074,7 @@ class MainWP_Child_iThemes_Security {
);
if ( $all_sites ) {
$query = 'SHOW_TABLES';
$query = 'SHOW TABLES';
} else {
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
}

View file

@ -538,8 +538,10 @@ class MainWP_Child_Server_Information {
public static function render() {
$branding_title = 'MainWP Child';
$isBranding = false;
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
$isBranding = true;
}
?>
@ -811,6 +813,16 @@ class MainWP_Child_Server_Information {
<?php
$all_plugins = get_plugins();
foreach ( $all_plugins as $slug => $plugin) {
if ( $slug == 'mainwp-child/mainwp-child.php' || $slug == 'mainwp-child-reports/mainwp-child-reports.php' ) {
if ( $isBranding ) {
if ( $slug == 'mainwp-child/mainwp-child.php' ) {
$plugin['Name'] = esc_html( stripslashes( $branding_title ) );
} else if ($slug == 'mainwp-child-reports/mainwp-child-reports.php') {
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports';
}
}
}
?>
<tr>
<td>&nbsp;</td>
@ -1454,8 +1466,13 @@ class MainWP_Child_Server_Information {
$lines = array_filter( $lines );
if ( empty( $lines ) ) {
echo '<tr><td colspan="2">' . esc_html__( 'MainWP is unable to find your error logs, please contact your host for server error logs.', 'mainwp-child' ) . '</td></tr>';
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
} else {
$msg = esc_html__( 'MainWP is unable to find your error logs, please contact your host for server error logs.', 'mainwp-child' );
}
echo '<tr><td colspan="2">' . $msg . '</td></tr>';
return;
}

View file

@ -74,6 +74,8 @@ class MainWP_Child_Vulnerability_Checker {
unset($plug_vuln_filter[$slug]);
} else {
$plug_vuln_filter[$slug]['vulnerabilities'] = $plug_vulner_data;
$plug_vuln_filter[$slug]['detected_version'] = $plugin_version;
$plug_vuln_filter[$slug]['plugin_slug'] = $plug;
}
} else {
@ -167,6 +169,7 @@ class MainWP_Child_Vulnerability_Checker {
$result[$th['id']]['vulner_data'] = $th_vuln;
$result[$th['id']]['name'] = $th['name'];
$result[$th['id']]['author'] = $th['author'];
$result[$th['id']]['detected_version'] = $th['version'];
}
}
}

View file

@ -95,7 +95,7 @@ class MainWP_Child_Wordfence {
'deleteTablesOnDeact',
'disableCookies',
'startScansRemotely',
'disableConfigCaching',
//'disableConfigCaching',
'addCacheComment',
'disableCodeExecutionUploads',
//'isPaid',
@ -109,17 +109,18 @@ class MainWP_Child_Wordfence {
'email_summary_interval',
'email_summary_excluded_directories',
'allowed404s',
'wafAlertWhitelist',
'wafAlertOnAttacks'
//'ajaxWatcherDisabled_front', // do not update those values when save settings
//'ajaxWatcherDisabled_admin'
);
public static $diagnosticParams = array(
'addCacheComment',
//'addCacheComment',
'debugOn',
'startScansRemotely',
'ssl_verify',
'disableConfigCaching',
//'disableConfigCaching',
'betaThreatDefenseFeed',
);
@ -323,6 +324,9 @@ class MainWP_Child_Wordfence {
case 'update_config':
$information = $this->updateConfig();
break;
case 'save_country_blocking':
$information = $this->saveCountryBlocking();
break;
}
}
MainWP_Helper::write( $information );
@ -490,10 +494,26 @@ class MainWP_Child_Wordfence {
'isPaid' => wfConfig::get('isPaid'),
'lastscan_timestamp' => $this->get_lastscan(),
'isNginx' => wfUtils::isNginx() ? 1 : 0,
'todayAttBlocked' => $this->count_attacks_blocked(1),
'weekAttBlocked' => $this->count_attacks_blocked(7),
'monthAttBlocked' => $this->count_attacks_blocked(30),
'wafData' => $this->_getWAFData()
);
}
public function count_attacks_blocked($maxAgeDays) {
global $wpdb;
$interval = 'FLOOR(UNIX_TIMESTAMP(DATE_SUB(NOW(), interval ' . $maxAgeDays . ' day)) / 86400)';
return $wpdb->get_var(<<<SQL
SELECT SUM(blockCount) as blockCount
FROM {$wpdb->prefix}wfBlockedIPLog
WHERE unixday >= {$interval}
SQL
);
}
function get_lastscan() {
global $wpdb;
$wfdb = new wfDB();
@ -1188,6 +1208,23 @@ class MainWP_Child_Wordfence {
}
}
public static function saveCountryBlocking(){
if(! wfConfig::get('isPaid')){
return array('error' => "Sorry but this feature is only available for paid customers.");
}
$settings = $_POST['setings'];
wfConfig::set('cbl_action', $settings['blockAction']);
wfConfig::set('cbl_countries', $settings['codes']);
wfConfig::set('cbl_redirURL', $settings['redirURL']);
wfConfig::set('cbl_loggedInBlocked', $settings['loggedInBlocked']);
wfConfig::set('cbl_loginFormBlocked', $settings['loginFormBlocked']);
wfConfig::set('cbl_restOfSiteBlocked', $settings['restOfSiteBlocked']);
wfConfig::set('cbl_bypassRedirURL', $settings['bypassRedirURL']);
wfConfig::set('cbl_bypassRedirDest', $settings['bypassRedirDest']);
wfConfig::set('cbl_bypassViewURL', $settings['bypassViewURL']);
return array('ok' => 1);
}
public function load_static_panel() {
$mode = $_POST['mode'];
$wfLog = wordfence::getLog();
@ -1358,7 +1395,7 @@ class MainWP_Child_Wordfence {
$changed = true;
}
wfConfig::set('allowHTTPSCaching', $_POST['allowHTTPSCaching'] == '1' ? 1 : 0);
wfConfig::set('addCacheComment', $_POST['addCacheComment'] == 1 ? '1' : 0);
//wfConfig::set('addCacheComment', $_POST['addCacheComment'] == 1 ? '1' : 0);
wfConfig::set('clearCacheSched', $_POST['clearCacheSched'] == 1 ? '1' : 0);
if($changed && wfConfig::get('cacheType', false) == 'falcon'){
$err = wfCache::addHtaccessCode('add');
@ -1550,7 +1587,7 @@ class MainWP_Child_Wordfence {
<tbody>
<?php
$howGet = wfConfig::get('howGetIPs', false);
list($currentIP, $currentServerVarForIP) = wfUtils::getIPAndServerVarible();
list($currentIP, $currentServerVarForIP) = wfUtils::getIPAndServerVariable();
foreach (array(
'REMOTE_ADDR' => 'REMOTE_ADDR',
'HTTP_CF_CONNECTING_IP' => 'CF-Connecting-IP',

View file

@ -84,7 +84,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
}
class MainWP_Child {
public static $version = '3.3';
public static $version = '3.4';
private $update_version = '1.3';
private $callableFunctions = array(
@ -584,19 +584,29 @@ class MainWP_Child {
}
function render_pages($shownPage) {
$shownPage = '';
if ( isset($_GET['tab']) ) {
$shownPage = $_GET['tab'];
}
if (empty($shownPage))
$shownPage = 'settings';
$hide_settings = get_option( 'mainwp_branding_remove_setting' ) ? true : false;
$hide_restore = get_option( 'mainwp_branding_remove_restore' ) ? true : false;
$hide_server_info = get_option( 'mainwp_branding_remove_server_info' ) ? true : false;
$hide_connection_detail = get_option( 'mainwp_branding_remove_connection_detail' ) ? true : false;
$hide_style = 'style="display:none"';
if ($shownPage == '') {
if (!$hide_settings ) {
$shownPage = 'settings';
} else if (!$hide_restore) {
$shownPage = 'restore-clone';
} else if (!$hide_server_info) {
$shownPage = 'server-info';
} else if (!$hide_connection_detail) {
$shownPage = 'connection-detail';
}
}
self::render_header($shownPage, false);
?>
<?php if (!$hide_settings ) { ?>
@ -1318,6 +1328,8 @@ class MainWP_Child {
define( 'DOING_CRON', true );
MainWP_Child::fix_for_custom_themes();
call_user_func( array( $this, $this->callableFunctionsNoAuth[ $_POST['function'] ] ) );
} else if (isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && !isset($this->callableFunctions[ $_POST['function'] ]) && !isset( $this->callableFunctionsNoAuth[ $_POST['function'] ]) ) {
MainWP_Helper::error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) );
}
if ( 1 === (int) get_option( 'mainwpKeywordLinks' ) ) {
@ -1581,7 +1593,7 @@ class MainWP_Child {
@wp_version_check();
$core_updates = get_core_updates();
if ( count( $core_updates ) > 0 ) {
if ( is_array($core_updates) && count( $core_updates ) > 0 ) {
foreach ( $core_updates as $core_update ) {
if ( 'latest' === $core_update->response ) {
$information['upgrade'] = 'SUCCESS';
@ -1769,8 +1781,11 @@ class MainWP_Child {
if ( count( $plugins ) > 0 ) {
//@see wp-admin/update.php
$failed = true;
// to fix logging update
foreach($plugins as $plugin) {
$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
$result = $upgrader->bulk_upgrade( $plugins );
$result = $upgrader->bulk_upgrade( array($plugin) );
if ( ! empty( $result ) ) {
foreach ( $result as $plugin => $info ) {
if ( empty( $info ) ) {
@ -1779,7 +1794,10 @@ class MainWP_Child {
$information['upgrades'][ $plugin ] = true;
}
}
} else {
$failed = false;
}
}
if ($failed) {
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
}
}
@ -1858,9 +1876,26 @@ class MainWP_Child {
// }
// @wp_update_themes();
$failed = true;
// to fix logging update
foreach($themes as $theme) {
$upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
$result = $upgrader->bulk_upgrade( $themes );
$result = $upgrader->bulk_upgrade( array($theme) );
if ( ! empty( $result ) ) {
foreach ( $result as $theme => $info ) {
if ( empty( $info ) ) {
$information['upgrades'][ $theme ] = false;
} else {
$information['upgrades'][ $theme ] = true;
}
}
$failed = false;
}
}
if ($failed) {
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
}
if ( null !== $this->filterFunction ) {
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
}
@ -1874,17 +1909,6 @@ class MainWP_Child {
), 99 );
}
if ( ! empty( $result ) ) {
foreach ( $result as $theme => $info ) {
if ( empty( $info ) ) {
$information['upgrades'][ $theme ] = false;
} else {
$information['upgrades'][ $theme ] = true;
}
}
} else {
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
}
}
// $last_update = get_site_transient( 'update_themes' );
@ -2106,7 +2130,9 @@ class MainWP_Child {
$my_post = array();
if ( 'publish' === $action ) {
wp_publish_post( $postId );
// to fix error post slug
//wp_publish_post( $postId );
wp_update_post(array('ID' => $postId, 'post_status' => 'publish' ));
} else if ( 'update' === $action ) {
$postData = $_POST['post_data'];
$my_post = is_array( $postData ) ? $postData : array();
@ -3257,7 +3283,7 @@ class MainWP_Child {
}
@wp_version_check();
$core_updates = get_core_updates();
if ( count( $core_updates ) > 0 ) {
if ( is_array($core_updates) && count( $core_updates ) > 0 ) {
foreach ( $core_updates as $core_update ) {
if ( 'latest' === $core_update->response ) {
break;

View file

@ -251,16 +251,18 @@ class MainWP_Client_Report {
//return $records;
//$other_tokens_data = $this->get_other_tokens_data($records, $other_tokens);
// to fix invalid data
$skip_records = array();
if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
$other_tokens_data['header'] = $this->get_other_tokens_data( $records, $other_tokens['header'] );
$other_tokens_data['header'] = $this->get_other_tokens_data( $records, $other_tokens['header'], $skip_records);
}
if ( isset( $other_tokens['body'] ) && is_array( $other_tokens['body'] ) ) {
$other_tokens_data['body'] = $this->get_other_tokens_data( $records, $other_tokens['body'] );
$other_tokens_data['body'] = $this->get_other_tokens_data( $records, $other_tokens['body'], $skip_records );
}
if ( isset( $other_tokens['footer'] ) && is_array( $other_tokens['footer'] ) ) {
$other_tokens_data['footer'] = $this->get_other_tokens_data( $records, $other_tokens['footer'] );
$other_tokens_data['footer'] = $this->get_other_tokens_data( $records, $other_tokens['footer'], $skip_records );
}
$sections_data = array();
@ -268,19 +270,19 @@ class MainWP_Client_Report {
if ( isset( $sections['header'] ) && is_array( $sections['header'] ) && ! empty( $sections['header'] ) ) {
foreach ( $sections['header']['section_token'] as $index => $sec ) {
$tokens = $sections['header']['section_content_tokens'][ $index ];
$sections_data['header'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec );
$sections_data['header'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
}
}
if ( isset( $sections['body'] ) && is_array( $sections['body'] ) && ! empty( $sections['body'] ) ) {
foreach ( $sections['body']['section_token'] as $index => $sec ) {
$tokens = $sections['body']['section_content_tokens'][ $index ];
$sections_data['body'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec );
$sections_data['body'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
}
}
if ( isset( $sections['footer'] ) && is_array( $sections['footer'] ) && ! empty( $sections['footer'] ) ) {
foreach ( $sections['footer'] as $index => $sec ) {
foreach ( $sections['footer']['section_token'] as $index => $sec ) {
$tokens = $sections['footer']['section_content_tokens'][ $index ];
$sections_data['footer'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec );
$sections_data['footer'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
}
}
@ -292,7 +294,7 @@ class MainWP_Client_Report {
return $information;
}
function get_other_tokens_data( $records, $tokens ) {
function get_other_tokens_data( $records, $tokens, &$skip_records ) {
$convert_context_name = array(
'comment' => 'comments',
@ -400,8 +402,24 @@ class MainWP_Client_Report {
if ( 'draft' === $new_status ) { // avoid auto save post
continue;
}
} else if ( 'updated' === $action && ('themes' === $context || 'plugins' === $context)) {
$name = $this->get_stream_meta_data( $record, 'name' );
if ( empty($name) ) { // to fix empty value
if (!in_array($record->ID, $skip_records))
$skip_records[] = $record->ID;
continue;
} else {
$old_version = $this->get_stream_meta_data( $record, 'old_version' );
$version = $this->get_stream_meta_data( $record, 'version' );
if (version_compare($version, $old_version, '<=')) { // to fix
if (!in_array($record->ID, $skip_records))
$skip_records[] = $record->ID;
continue;
}
}
}
}
$count ++;
}
@ -414,7 +432,7 @@ class MainWP_Client_Report {
return $token_values;
}
function get_section_loop_data( $records, $tokens, $section ) {
function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) {
$convert_context_name = array(
'comment' => 'comments',
@ -439,6 +457,7 @@ class MainWP_Client_Report {
);
$some_allowed_data = array(
'ID',
'name',
'title',
'oldversion',
@ -469,6 +488,10 @@ class MainWP_Client_Report {
$loop_count = 0;
foreach ( $records as $record ) {
if (in_array($record->ID, $skip_records)) {
continue;
}
$theme_edited = $users_updated = $plugin_edited = false;
if ( $plugin_edited ) {
@ -565,6 +588,9 @@ class MainWP_Client_Report {
}
switch ( $data ) {
case 'ID':
$token_values[ $token ] = $record->ID;
break;
case 'date':
$token_values[ $token ] = MainWP_Helper::formatDate( MainWP_Helper::getTimestamp( strtotime( $record->created ) ) );
break;

View file

@ -297,10 +297,22 @@ class MainWP_Clone {
}
?>
<p><?php esc_html_e( 'Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child' ); ?><?php echo esc_html( $uploadSize ); ?>)</p>
<em><?php esc_html_e( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.', 'mainwp-child' ); ?>
<?php
$branding_msg = '';
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
$branding_msg = 'If you have a FULL backup created by basic ' . esc_html( stripslashes( $branding_title ) ) . ' Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.';
}
?>
<em>
<?php
if ($branding_msg != '') {
echo $branding_msg ;
} else {
esc_html_e( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.', 'mainwp-child' );
}
?>
<br/>
<?php esc_html_e( 'A database only backup will not work.', 'mainwp-child' ); ?></em><br/><br/>
<form action="<?php echo esc_attr( admin_url( 'admin.php?page=MainWPRestore&upload=yes' ) ); ?>"
method="post"
@ -1438,6 +1450,16 @@ class MainWP_Clone {
// $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key);
// $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone);
// $cloneInstall->update_option('mainwp_child_clone_permalink', true);
// to fix update values
delete_option('mainwp_child_pubkey');
delete_option('mainwp_child_uniqueId');
delete_option('mainwp_child_server');
delete_option('mainwp_child_nonce');
delete_option('mainwp_child_nossl');
delete_option('mainwp_child_nossl_key');
delete_option('mainwp_child_clone_sites');
MainWP_Helper::update_option( 'mainwp_child_pubkey', $pubkey, 'yes' );
MainWP_Helper::update_option( 'mainwp_child_uniqueId', $uniqueId );
MainWP_Helper::update_option( 'mainwp_child_server', $server );

View file

@ -57,6 +57,75 @@ class MainWP_Custom_Post_Type {
if ( empty( $data ) || ! is_array( $data ) || ! isset( $data['post'] ) ) {
return array( 'error' => __( 'Cannot decode data', $this->plugin_translate ) );
}
$edit_id = (isset($_POST['post_id']) && !empty($_POST['post_id'])) ? $_POST['post_id'] : 0;
$return = $this->_insert_post($data, $edit_id, $parent_id = 0);
if (isset($return['success']) && $return['success'] == 1) {
if (isset($data['product_variation']) && is_array($data['product_variation'])) {
foreach ($data['product_variation'] as $product_variation) {
$return_variantion = $this->_insert_post($product_variation, 0, $return['post_id']);
}
}
}
return $return;
}
/**
* Search image inside post content and upload it to child
**/
private function _search_images( $post_content, $upload_dir ) {
$foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $post_content, $matches, PREG_SET_ORDER );
if ( $foundMatches > 0 ) {
foreach ( $matches as $match ) {
$hrefLink = $match[2];
$imgUrl = $match[4];
if ( ! isset( $upload_dir['baseurl'] ) || ( 0 !== strripos( $imgUrl, $upload_dir['baseurl'] ) ) ) {
continue;
}
if ( preg_match( '/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $imgUrl, $imgMatches ) ) {
$search = $imgMatches[0];
$replace = '.' . $match[6];
$originalImgUrl = str_replace( $search, $replace, $imgUrl );
} else {
$originalImgUrl = $imgUrl;
}
try {
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl );
$localUrl = $downloadfile['url'];
$linkToReplaceWith = dirname( $localUrl );
if ( '' !== $hrefLink ) {
$server = get_option( 'mainwp_child_server' );
$serverHost = parse_url( $server, PHP_URL_HOST );
if ( ! empty( $serverHost ) && strpos( $hrefLink, $serverHost ) !== false ) {
$serverHref = 'href="' . $serverHost;
$replaceServerHref = 'href="' . parse_url( $localUrl, PHP_URL_SCHEME ) . '://' . parse_url( $localUrl, PHP_URL_HOST );
$post_content = str_replace( $serverHref, $replaceServerHref, $post_content );
} else if ( strpos( $hrefLink, 'http' ) !== false ) {
$lnkToReplace = dirname( $hrefLink );
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content );
}
}
}
$lnkToReplace = dirname( $imgUrl );
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content );
}
} catch ( Exception $e ) {
}
}
}
return $post_content;
}
private function _insert_post( $data, $edit_id, $parent_id = 0 ) {
// Insert post
$data_insert = array();
@ -98,13 +167,13 @@ class MainWP_Custom_Post_Type {
$data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'] );
$is_woocomerce = false;
if ( $data_insert['post_type'] == 'product' && function_exists( 'wc_product_has_unique_sku' ) ) {
if ( ($data_insert['post_type'] == 'product' || $data_insert['post_type'] == 'product_variation' )&& function_exists( 'wc_product_has_unique_sku' ) ) {
$is_woocomerce = true;
}
// Support post_edit
if ( isset( $_POST['post_id'] ) ) {
$old_post_id = (int) $_POST['post_id'];
if ( !empty( $edit_id ) ) {
$old_post_id = (int) $edit_id;
$old_post = get_post( $old_post_id, ARRAY_A );
if ( is_null( $old_post ) ) {
return array(
@ -131,7 +200,9 @@ class MainWP_Custom_Post_Type {
// Remove all previous taxonomy
wp_delete_object_term_relationships( $old_post_id, get_object_taxonomies( $data_insert['post_type'] ) );
}
if (!empty($parent_id)) {
$data_insert['post_parent'] = $parent_id; // for product variation
}
$post_id = wp_insert_post( $data_insert, true );
if ( is_wp_error( $post_id ) ) {
return array( 'error' => __( 'Error when insert new post:', $this->plugin_translate ) . ' ' . $post_id->get_error_message() );
@ -189,7 +260,8 @@ class MainWP_Custom_Post_Type {
}
}
if ( add_post_meta( $post_id, $key['meta_key'], $key['meta_value'] ) === false ) {
$meta_value = maybe_unserialize( $key['meta_value'] );
if ( add_post_meta( $post_id, $key['meta_key'], $meta_value ) === false ) {
return array( 'error' => __( 'Error when adding post meta', $this->plugin_translate ) . ' `' . esc_html( $key['meta_key'] ) . '`' );
}
}
@ -252,58 +324,4 @@ class MainWP_Custom_Post_Type {
return array( 'success' => 1, 'post_id' => $post_id );
}
/**
* Search image inside post content and upload it to child
**/
private function _search_images( $post_content, $upload_dir ) {
$foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $post_content, $matches, PREG_SET_ORDER );
if ( $foundMatches > 0 ) {
foreach ( $matches as $match ) {
$hrefLink = $match[2];
$imgUrl = $match[4];
if ( ! isset( $upload_dir['baseurl'] ) || ( 0 !== strripos( $imgUrl, $upload_dir['baseurl'] ) ) ) {
continue;
}
if ( preg_match( '/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $imgUrl, $imgMatches ) ) {
$search = $imgMatches[0];
$replace = '.' . $match[6];
$originalImgUrl = str_replace( $search, $replace, $imgUrl );
} else {
$originalImgUrl = $imgUrl;
}
try {
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl );
$localUrl = $downloadfile['url'];
$linkToReplaceWith = dirname( $localUrl );
if ( '' !== $hrefLink ) {
$server = get_option( 'mainwp_child_server' );
$serverHost = parse_url( $server, PHP_URL_HOST );
if ( ! empty( $serverHost ) && strpos( $hrefLink, $serverHost ) !== false ) {
$serverHref = 'href="' . $serverHost;
$replaceServerHref = 'href="' . parse_url( $localUrl, PHP_URL_SCHEME ) . '://' . parse_url( $localUrl, PHP_URL_HOST );
$post_content = str_replace( $serverHref, $replaceServerHref, $post_content );
} else if ( strpos( $hrefLink, 'http' ) !== false ) {
$lnkToReplace = dirname( $hrefLink );
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content );
}
}
}
$lnkToReplace = dirname( $imgUrl );
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content );
}
} catch ( Exception $e ) {
}
}
}
return $post_content;
}
}

View file

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