mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-06 09:20:28 +08:00
sync with branch01
This commit is contained in:
parent
acdde0a28b
commit
aaf70d27af
10 changed files with 1939 additions and 1681 deletions
File diff suppressed because it is too large
Load diff
|
@ -53,6 +53,10 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$information['error'] = 'NO_BACKUPWORDPRESS';
|
||||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
if (false === get_option('mainwp_backupwordpress_ext_enabled'))
|
||||
MainWP_Helper::update_option( 'mainwp_backupwordpress_ext_enabled', 'Y' );
|
||||
|
||||
if ( isset( $_POST['mwp_action'] ) ) {
|
||||
switch ( $_POST['mwp_action'] ) {
|
||||
case 'set_showhide':
|
||||
|
@ -171,7 +175,6 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
|
||||
function set_showhide() {
|
||||
MainWP_Helper::update_option( 'mainwp_backupwordpress_ext_enabled', 'Y' );
|
||||
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
||||
MainWP_Helper::update_option( 'mainwp_backupwordpress_hide_plugin', $hide );
|
||||
$information['result'] = 'SUCCESS';
|
||||
|
|
|
@ -38,7 +38,7 @@ class MainWP_Child_Branding {
|
|||
if ( ! self::is_branding() ) {
|
||||
return $plugin_meta;
|
||||
}
|
||||
|
||||
// hide View details links
|
||||
$meta_total = count( $plugin_meta );
|
||||
for ( $i = 0; $i < $meta_total; $i++ ) {
|
||||
$str_meta = $plugin_meta[ $i ];
|
||||
|
|
|
@ -30,7 +30,7 @@ class MainWP_Child_Server_Information {
|
|||
}
|
||||
|
||||
public static function showWarnings() {
|
||||
if ( stristr( $_SERVER['REQUEST_URI'], 'MainWP_Child_Server_Information' ) ) {
|
||||
if ( stristr( $_SERVER['REQUEST_URI'], 'mainwp_child_tab' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-page' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-settings' )) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ class MainWP_Child_Server_Information {
|
|||
$warning = '';
|
||||
|
||||
if ( $warnings > 0 ) {
|
||||
$warning .= '<tr><td colspan="2">This site may not connect to your dashboard or may have other issues. Check your <a href="admin.php?page=MainWP_Child_Server_Information">MainWP server information page</a> to review and <a href="http://docs.mainwp.com/child-site-issues/">check here for more information on possible fixes</a></td><td style="text-align: right;"><a href="#" id="mainwp-child-connect-warning-dismiss">Dismiss</a></td></tr>';
|
||||
$warning .= '<tr><td colspan="2">This site may not connect to your dashboard or may have other issues. Check your <a href="options-general.php?page=mainwp_child_tab">MainWP server information page</a> to review and <a href="http://docs.mainwp.com/child-site-issues/">check here for more information on possible fixes</a></td><td style="text-align: right;"><a href="#" id="mainwp-child-connect-warning-dismiss">Dismiss</a></td></tr>';
|
||||
}
|
||||
echo $warning;
|
||||
?>
|
||||
|
@ -598,7 +598,7 @@ class MainWP_Child_Server_Information {
|
|||
<td style="background: #333; color: #fff;"
|
||||
colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td>
|
||||
</tr><?php
|
||||
self::renderRow( 'PHP Version', '>=', '5.3', 'getPHPVersion' );
|
||||
self::renderRow( 'PHP Version', '>=', '5.6', 'getPHPVersion' );
|
||||
?>
|
||||
<tr>
|
||||
<td></td>
|
||||
|
@ -606,7 +606,7 @@ class MainWP_Child_Server_Information {
|
|||
<td colspan="3"><?php self::getPHPSafeMode(); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
self::renderRow( 'PHP Max Execution Time', '>=', '30', 'getMaxExecutionTime', 'seconds', '=', '0' );
|
||||
self::renderRowSec( 'PHP Max Execution Time', '>=', '30', 'getMaxExecutionTime', 'seconds', '=', '0' );
|
||||
self::renderRowSec( 'PHP Max Input Time', '>=', '30', 'getMaxInputTime', 'seconds', '=', '0' );
|
||||
self::renderRow( 'PHP Memory Limit', '>=', '128M', 'getPHPMemoryLimit', '(256M+ best for big backups)', null, null, true );
|
||||
self::renderRow( 'PCRE Backtracking Limit', '>=', '10000', 'getOutputBufferSize' );
|
||||
|
@ -1033,7 +1033,7 @@ class MainWP_Child_Server_Information {
|
|||
<td><?php echo( self::filesize_compare( $currentVersion, $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td>
|
||||
<?php } else if ( $whatType == 'curlssl' ) { ?>
|
||||
<td><?php echo( self::curlssl_compare( $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td>
|
||||
<?php } else if ($pGetter == 'getMaxInputTime' && $currentVersion == -1) { ?>
|
||||
<?php } else if (($pGetter == 'getMaxInputTime' || $pGetter == 'getMaxExecutionTime') && $currentVersion == -1) { ?>
|
||||
<td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td>
|
||||
<?php } else { ?>
|
||||
<td><?php echo (version_compare($currentVersion, $pVersion, $pCompare) || (($pExtraCompare != null) && version_compare($currentVersion, $pExtraVersion, $pExtraCompare)) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType )); ?></td>
|
||||
|
|
|
@ -372,17 +372,21 @@ class MainWP_Child_Updraft_Plus_Backups {
|
|||
if ( class_exists( 'UpdraftPlus_Options' ) ) {
|
||||
foreach ( $keys as $key ) {
|
||||
if ( isset( $settings[ $key ] ) ) {
|
||||
if ( 'updraft_dropbox' === $key ) {
|
||||
$opts = UpdraftPlus_Options::get_updraft_option( 'updraft_dropbox' );
|
||||
$opts['appkey'] = $settings[ $key ]['appkey'];
|
||||
$opts['secret'] = $settings[ $key ]['secret'];
|
||||
$opts['folder'] = $settings[ $key ]['folder'];
|
||||
if ( 'updraft_dropbox' === $key && is_array($settings[ $key ])) {
|
||||
$opts = UpdraftPlus_Options::get_updraft_option( 'updraft_dropbox' );
|
||||
if (isset($settings['is_general']) && !empty($settings['is_general'])){
|
||||
$opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']);
|
||||
} else {
|
||||
$opts['appkey'] = $settings[ $key ]['appkey'];
|
||||
$opts['secret'] = $settings[ $key ]['secret'];
|
||||
$opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']);
|
||||
}
|
||||
UpdraftPlus_Options::update_updraft_option( $key, $opts );
|
||||
} else if ( 'updraft_googledrive' === $key ) {
|
||||
$opts = UpdraftPlus_Options::get_updraft_option( 'updraft_googledrive' );
|
||||
$opts['clientid'] = $settings[ $key ]['clientid'];
|
||||
$opts['secret'] = $settings[ $key ]['secret'];
|
||||
$opts['folder'] = $settings[ $key ]['folder'];
|
||||
$opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']);
|
||||
UpdraftPlus_Options::update_updraft_option( $key, $opts );
|
||||
} else if ( 'updraft_googlecloud' === $key ) {
|
||||
$opts = UpdraftPlus_Options::get_updraft_option( $key );
|
||||
|
@ -397,7 +401,7 @@ class MainWP_Child_Updraft_Plus_Backups {
|
|||
$opts = UpdraftPlus_Options::get_updraft_option( 'updraft_onedrive' );
|
||||
$opts['clientid'] = $settings[ $key ]['clientid'];
|
||||
$opts['secret'] = $settings[ $key ]['secret'];
|
||||
$opts['folder'] = $settings[ $key ]['folder'];
|
||||
$opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']);
|
||||
UpdraftPlus_Options::update_updraft_option( $key, $opts );
|
||||
} else if ( 'updraft_email' === $key ) {
|
||||
$value = $settings[ $key ];
|
||||
|
@ -408,6 +412,21 @@ class MainWP_Child_Updraft_Plus_Backups {
|
|||
}
|
||||
}
|
||||
UpdraftPlus_Options::update_updraft_option( $key, $value );
|
||||
} else if ( 'updraft_s3' === $key ) {
|
||||
$opts = UpdraftPlus_Options::get_updraft_option( 'updraft_s3' );
|
||||
$opts['accesskey'] = $settings[ $key ]['accesskey'];
|
||||
$opts['secretkey'] = $settings[ $key ]['secretkey'];
|
||||
$opts['path'] = $this->replace_tokens($settings[ $key ]['path']);
|
||||
$opts['rrs'] = $settings[ $key ]['rrs'];
|
||||
$opts['server_side_encryption'] = $settings[ $key ]['server_side_encryption'];
|
||||
UpdraftPlus_Options::update_updraft_option( $key, $opts );
|
||||
} else if ( 'updraft_s3generic' === $key ) {
|
||||
$opts = UpdraftPlus_Options::get_updraft_option( 'updraft_s3generic' );
|
||||
$opts['endpoint'] = $settings[ $key ]['endpoint'];
|
||||
$opts['accesskey'] = $settings[ $key ]['accesskey'];
|
||||
$opts['secretkey'] = $settings[ $key ]['secretkey'];
|
||||
$opts['path'] = $this->replace_tokens($settings[ $key ]['path']);
|
||||
UpdraftPlus_Options::update_updraft_option( $key, $opts );
|
||||
} else {
|
||||
UpdraftPlus_Options::update_updraft_option( $key, $settings[ $key ] );
|
||||
}
|
||||
|
@ -452,7 +471,24 @@ class MainWP_Child_Updraft_Plus_Backups {
|
|||
return $out;
|
||||
}
|
||||
|
||||
function addons_connect() {
|
||||
function replace_tokens($str = '') {
|
||||
if (stripos($str, '%sitename%') !== false) {
|
||||
$replace_token = get_bloginfo( 'name' );
|
||||
$replace_token = sanitize_file_name($replace_token);
|
||||
$replace_token = strtolower($replace_token);
|
||||
$str = str_ireplace("%sitename%", $replace_token, $str);
|
||||
}
|
||||
|
||||
if (stripos($str, '%siteurl%') !== false) {
|
||||
$replace_token = get_bloginfo( 'url' );
|
||||
$replace_token = preg_replace('/^https?:\/\//i', '', $replace_token);
|
||||
$replace_token = sanitize_file_name($replace_token);
|
||||
$str = str_ireplace("%siteurl%", $replace_token, $str);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
function addons_connect() {
|
||||
if ( ! defined( 'UDADDONS2_SLUG' ) ) {
|
||||
return array( 'error' => 'NO_PREMIUM' );
|
||||
}
|
||||
|
@ -1326,12 +1362,7 @@ class MainWP_Child_Updraft_Plus_Backups {
|
|||
|
||||
$mess = array();
|
||||
parse_str( $_POST['restoreopts'], $res );
|
||||
|
||||
// error_log(print_r($_POST, true));
|
||||
// error_log(print_r($res, true));
|
||||
|
||||
if ( isset( $res['updraft_restore'] ) ) {
|
||||
|
||||
if ( isset( $res['updraft_restore'] ) ) {
|
||||
set_error_handler( array( $this, 'get_php_errors' ), E_ALL & ~E_STRICT );
|
||||
|
||||
$elements = array_flip( $res['updraft_restore'] );
|
||||
|
|
|
@ -8,11 +8,13 @@ class MainWP_Child_Wordfence {
|
|||
public static $options_filter = array(
|
||||
'alertEmails',
|
||||
'alertOn_adminLogin',
|
||||
'alertOn_firstAdminLoginOnly',
|
||||
'alertOn_block',
|
||||
'alertOn_critical',
|
||||
'alertOn_loginLockout',
|
||||
'alertOn_lostPasswdForm',
|
||||
'alertOn_nonAdminLogin',
|
||||
'alertOn_firstNonAdminLoginOnly',
|
||||
'alertOn_update',
|
||||
'alertOn_warnings',
|
||||
'alert_maxHourly',
|
||||
|
@ -101,6 +103,7 @@ class MainWP_Child_Wordfence {
|
|||
'email_summary_interval',
|
||||
'email_summary_excluded_directories',
|
||||
'allowed404s',
|
||||
'wafAlertOnAttacks'
|
||||
//'ajaxWatcherDisabled_front', // do not update those values when save settings
|
||||
//'ajaxWatcherDisabled_admin'
|
||||
);
|
||||
|
|
|
@ -417,7 +417,7 @@ class MainWP_Child {
|
|||
$fix_update_plugins = array();
|
||||
if ( is_array( $plugin_updates ) ) {
|
||||
foreach ( $plugin_updates as $slug => $plugin_update ) {
|
||||
if ( in_array( $slug, array( 'ithemes-security-pro/ithemes-security-pro.php', 'monarch/monarch.php', 'cornerstone/cornerstone.php') ) ) {
|
||||
if ( in_array( $slug, array( 'ithemes-security-pro/ithemes-security-pro.php', 'monarch/monarch.php', 'cornerstone/cornerstone.php', 'updraftplus/updraftplus.php') ) ) {
|
||||
$fix_update_plugins[ $slug ] = $plugin_update;
|
||||
}
|
||||
}
|
||||
|
@ -1515,7 +1515,7 @@ class MainWP_Child {
|
|||
if ( ! empty( $fileName ) ) {
|
||||
do_action( 'mainwp_child_installPluginTheme', $args );
|
||||
if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) {
|
||||
activate_plugin( $path . $fileName, '', false, true );
|
||||
activate_plugin( $path . $fileName, '' /* false, true */ );
|
||||
do_action( 'activate_plugin', $args['slug'], null );
|
||||
}
|
||||
}
|
||||
|
@ -2128,6 +2128,14 @@ class MainWP_Child {
|
|||
update_post_meta( $postId, $key, $meta_value[ $i ] );
|
||||
}
|
||||
}
|
||||
} else if ( 'get_edit' === $action ) {
|
||||
$postId = $_POST['id'];
|
||||
$post_type = $_POST['post_type'];
|
||||
if ( $post_type == 'post' ) {
|
||||
$my_post = $this->get_post_edit( $postId );
|
||||
} else {
|
||||
$my_post = $this->get_page_edit( $postId );
|
||||
}
|
||||
} else {
|
||||
$information['status'] = 'FAIL';
|
||||
}
|
||||
|
@ -2139,6 +2147,152 @@ class MainWP_Child {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
function get_post_edit($id) {
|
||||
$post = get_post( $id );
|
||||
if ( $post ) {
|
||||
$categoryObjects = get_the_category( $post->ID );
|
||||
$categories = '';
|
||||
foreach ( $categoryObjects as $cat ) {
|
||||
if ( '' !== $categories ) {
|
||||
$categories .= ', ';
|
||||
}
|
||||
$categories .= $cat->name;
|
||||
}
|
||||
$post_category = $categories;
|
||||
|
||||
$tagObjects = get_the_tags( $post->ID );
|
||||
$tags = '';
|
||||
if ( is_array( $tagObjects ) ) {
|
||||
foreach ( $tagObjects as $tag ) {
|
||||
if ( '' !== $tags ) {
|
||||
$tags .= ', ';
|
||||
}
|
||||
$tags .= $tag->name;
|
||||
}
|
||||
}
|
||||
$post_tags = $tags;
|
||||
|
||||
$post_custom = get_post_custom( $id );
|
||||
|
||||
$galleries = get_post_gallery( $id, false );
|
||||
$post_gallery_images = array();
|
||||
|
||||
if ( is_array($galleries) && isset($galleries['ids']) ) {
|
||||
$attached_images = explode( ',', $galleries['ids'] );
|
||||
foreach( $attached_images as $attachment_id ) {
|
||||
$attachment = get_post( $attachment_id );
|
||||
if ( $attachment ) {
|
||||
$post_gallery_images[] = array(
|
||||
'id' => $attachment_id,
|
||||
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
||||
'caption' => $attachment->post_excerpt,
|
||||
'description' => $attachment->post_content,
|
||||
'src' => $attachment->guid,
|
||||
'title' => $attachment->post_title
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php' );
|
||||
$post_featured_image = get_post_thumbnail_id( $id );
|
||||
$child_upload_dir = wp_upload_dir();
|
||||
$new_post = array(
|
||||
'edit_id' => $id,
|
||||
'is_sticky' => is_sticky( $id ) ? 1 : 0,
|
||||
'post_title' => $post->post_title,
|
||||
'post_content' => $post->post_content,
|
||||
'post_status' => $post->post_status, //was 'publish'
|
||||
'post_date' => $post->post_date,
|
||||
'post_date_gmt' => $post->post_date_gmt,
|
||||
'post_tags' => $post_tags,
|
||||
'post_name' => $post->post_name,
|
||||
'post_excerpt' => $post->post_excerpt,
|
||||
'comment_status' => $post->comment_status,
|
||||
'ping_status' => $post->ping_status
|
||||
);
|
||||
|
||||
if ( $post_featured_image != null ) { //Featured image is set, retrieve URL
|
||||
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
||||
$post_featured_image = $img[0];
|
||||
}
|
||||
|
||||
$post_data = array(
|
||||
'new_post' => base64_encode( serialize( $new_post ) ),
|
||||
'post_custom' => base64_encode( serialize( $post_custom ) ),
|
||||
'post_category' => base64_encode( $post_category ),
|
||||
'post_featured_image' => base64_encode( $post_featured_image ),
|
||||
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ),
|
||||
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ),
|
||||
);
|
||||
return $post_data;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_page_edit($id) {
|
||||
$post = get_post( $id );
|
||||
if ( $post ) {
|
||||
$post_custom = get_post_custom( $id );
|
||||
//post_slug = base64_decode( get_post_meta( $id, '_slug', true ) );
|
||||
include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php' );
|
||||
$post_featured_image = get_post_thumbnail_id( $id );
|
||||
$child_upload_dir = wp_upload_dir();
|
||||
|
||||
$new_post = array(
|
||||
'edit_id' => $id,
|
||||
'post_title' => $post->post_title,
|
||||
'post_content' => $post->post_content,
|
||||
'post_status' => $post->post_status,
|
||||
'post_date' => $post->post_date,
|
||||
'post_date_gmt' => $post->post_date_gmt,
|
||||
'post_type' => 'page',
|
||||
'post_name' => $post->post_name,
|
||||
'post_excerpt' => $post->post_excerpt,
|
||||
'comment_status' => $post->comment_status,
|
||||
'ping_status' => $post->ping_status
|
||||
);
|
||||
|
||||
|
||||
if ( $post_featured_image != null ) { //Featured image is set, retrieve URL
|
||||
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
||||
$post_featured_image = $img[0];
|
||||
}
|
||||
|
||||
$galleries = get_post_gallery( $id, false );
|
||||
$post_gallery_images = array();
|
||||
|
||||
if ( is_array($galleries) && isset($galleries['ids']) ) {
|
||||
$attached_images = explode( ',', $galleries['ids'] );
|
||||
foreach( $attached_images as $attachment_id ) {
|
||||
$attachment = get_post( $attachment_id );
|
||||
if ( $attachment ) {
|
||||
$post_gallery_images[] = array(
|
||||
'id' => $attachment_id,
|
||||
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
||||
'caption' => $attachment->post_excerpt,
|
||||
'description' => $attachment->post_content,
|
||||
'src' => $attachment->guid,
|
||||
'title' => $attachment->post_title
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$post_data = array(
|
||||
'new_post' => base64_encode( serialize( $new_post ) ),
|
||||
'post_custom' => base64_encode( serialize( $post_custom ) ),
|
||||
'post_featured_image' => base64_encode( $post_featured_image ),
|
||||
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ),
|
||||
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ),
|
||||
);
|
||||
return $post_data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function user_action() {
|
||||
//Read form data
|
||||
$action = $_POST['action'];
|
||||
|
@ -2149,9 +2303,9 @@ class MainWP_Child {
|
|||
|
||||
global $current_user;
|
||||
$reassign = ( isset( $current_user ) && isset( $current_user->ID ) ) ? $current_user->ID : 0;
|
||||
|
||||
include_once( ABSPATH . '/wp-admin/includes/user.php' );
|
||||
|
||||
if ( 'delete' === $action ) {
|
||||
include_once( ABSPATH . '/wp-admin/includes/user.php' );
|
||||
wp_delete_user( $userId, $reassign );
|
||||
} else if ( 'changeRole' === $action ) {
|
||||
$my_user = array();
|
||||
|
@ -3234,12 +3388,13 @@ class MainWP_Child {
|
|||
}
|
||||
|
||||
$information['recent_comments'] = $this->get_recent_comments( array( 'approve', 'hold' ), 5 );
|
||||
$information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash' ), 5 );
|
||||
$information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), 5 );
|
||||
$information['recent_pages'] = $this->get_recent_posts( array(
|
||||
'publish',
|
||||
'draft',
|
||||
'pending',
|
||||
'trash',
|
||||
'future'
|
||||
), 5, 'page' );
|
||||
|
||||
$securityIssuess = 0;
|
||||
|
|
|
@ -241,8 +241,12 @@ class MainWP_Client_Report {
|
|||
}
|
||||
}
|
||||
|
||||
if ( MainWP_Child_Branding::is_branding() ) {
|
||||
$args['hide_child_reports'] = 1;
|
||||
}
|
||||
|
||||
$args['records_per_page'] = 9999;
|
||||
// error_log(print_r($args, true));
|
||||
|
||||
|
||||
if ( self::$mainwpChildReports ) {
|
||||
$records = mainwp_wp_stream_query( $args );
|
||||
|
|
|
@ -121,17 +121,26 @@ class MainWP_Helper {
|
|||
|
||||
}
|
||||
|
||||
static function uploadImage( $img_url, $img_data = array() ) {
|
||||
static function uploadImage( $img_url, $img_data = array() , $check_file_existed = false ) {
|
||||
if (!is_array($img_data))
|
||||
$img_data = array();
|
||||
include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
|
||||
$upload_dir = wp_upload_dir();
|
||||
|
||||
if ($check_file_existed) {
|
||||
$local_img_url = $upload_dir['url'] . '/' . basename( $img_url );
|
||||
$attach_id = MainWP_Helper::get_image_id($local_img_url);
|
||||
if ($attach_id) {
|
||||
return array( 'id' => $attach_id, 'url' => $local_img_url );
|
||||
}
|
||||
}
|
||||
|
||||
//Download $img_url
|
||||
$temporary_file = download_url( $img_url );
|
||||
|
||||
if ( is_wp_error( $temporary_file ) ) {
|
||||
throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
|
||||
} else {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); //Local name
|
||||
$local_img_url = $upload_dir['url'] . '/' . basename( $img_url );
|
||||
$moved = @rename( $temporary_file, $local_img_path );
|
||||
|
@ -160,6 +169,12 @@ 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 uploadFile( $file_url, $path, $file_name ) {
|
||||
$file_name = sanitize_file_name( $file_name );
|
||||
$full_file_name = $path . DIRECTORY_SEPARATOR . $file_name; //Local name
|
||||
|
@ -272,6 +287,11 @@ class MainWP_Helper {
|
|||
|
||||
$wpr_options = isset( $_POST['wpr_options'] ) ? $_POST['wpr_options'] : array();
|
||||
|
||||
$edit_post_id = 0;
|
||||
if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
|
||||
$edit_post_id = current($post_custom['_mainwp_edit_post_id']);
|
||||
}
|
||||
|
||||
//Search for all the images added to the new post
|
||||
//some images have a href tag to click to navigate to the image.. we need to replace this too
|
||||
$foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER );
|
||||
|
@ -294,7 +314,13 @@ class MainWP_Helper {
|
|||
}
|
||||
|
||||
try {
|
||||
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl );
|
||||
// in the case edit post will check if file existed
|
||||
if ( $edit_post_id ) {
|
||||
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl , array(), true );
|
||||
} else {
|
||||
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl );
|
||||
}
|
||||
|
||||
$localUrl = $downloadfile['url'];
|
||||
$linkToReplaceWith = dirname( $localUrl );
|
||||
if ( '' !== $hrefLink ) {
|
||||
|
@ -407,6 +433,16 @@ class MainWP_Helper {
|
|||
remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html
|
||||
$post_status = $new_post['post_status'];
|
||||
$new_post['post_status'] = 'auto-draft';
|
||||
|
||||
// update post
|
||||
if ( $edit_post_id ) {
|
||||
// check if post existed
|
||||
$current_post = get_post($edit_post_id);
|
||||
if ( $current_post && ( ( !isset( $new_post['post_type'] ) && $current_post->post_type == 'post' ) || ( isset( $new_post['post_type'] ) && $new_post['post_type'] == $current_post->post_type ) ) ) {
|
||||
$new_post['ID'] = $edit_post_id;
|
||||
}
|
||||
}
|
||||
|
||||
$new_post_id = wp_insert_post( $new_post, $wp_error );
|
||||
|
||||
//Show errors if something went wrong
|
||||
|
@ -461,6 +497,9 @@ class MainWP_Helper {
|
|||
$not_allowed[] = '_saved_draft_publish_date_to';
|
||||
$not_allowed[] = '_post_to_only_existing_categories';
|
||||
$not_allowed[] = '_mainwp_robot_post_comments';
|
||||
$not_allowed[] = '_mainwp_edit_post_site_id';
|
||||
$not_allowed[] = '_mainwp_edit_post_id';
|
||||
$not_allowed[] = '_edit_post_status';
|
||||
|
||||
$post_to_only_existing_categories = false;
|
||||
foreach ( $post_custom as $meta_key => $meta_values ) {
|
||||
|
@ -472,10 +511,10 @@ class MainWP_Helper {
|
|||
if ( ! $seo_ext_activated ) {
|
||||
// if Wordpress SEO plugin is not activated do not save yoast post meta
|
||||
if ( strpos( $meta_key, '_yoast_wpseo_' ) === false ) {
|
||||
add_post_meta( $new_post_id, $meta_key, $meta_value );
|
||||
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
||||
}
|
||||
} else {
|
||||
add_post_meta( $new_post_id, $meta_key, $meta_value );
|
||||
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
||||
}
|
||||
}
|
||||
} else if ( '_sticky' === $meta_key ) {
|
||||
|
@ -536,6 +575,7 @@ class MainWP_Helper {
|
|||
}
|
||||
}
|
||||
|
||||
$featured_image_exist = false;
|
||||
//If featured image exists - set it
|
||||
if ( null !== $post_featured_image ) {
|
||||
try {
|
||||
|
@ -543,12 +583,17 @@ class MainWP_Helper {
|
|||
|
||||
if ( null !== $upload ) {
|
||||
update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); //Add the thumbnail to the post!
|
||||
$featured_image_exist = true;
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$featured_image_exist ) {
|
||||
delete_post_meta( $new_post_id, '_thumbnail_id' );
|
||||
}
|
||||
|
||||
// post plus extension process
|
||||
if ( $is_post_plus ) {
|
||||
$random_privelege = isset( $post_custom['_saved_draft_random_privelege'] ) ? $post_custom['_saved_draft_random_privelege'] : null;
|
||||
|
@ -590,6 +635,12 @@ class MainWP_Helper {
|
|||
}
|
||||
// end of post plus
|
||||
|
||||
// to support custom post author
|
||||
$custom_post_author = apply_filters('mainwp_create_post_custom_author', false, $new_post_id);
|
||||
if ( !empty( $custom_post_author ) ) {
|
||||
wp_update_post( array( 'ID' => $new_post_id, 'post_author' => $custom_post_author ) );
|
||||
}
|
||||
|
||||
// MainWP Robot
|
||||
if ( $is_robot_post ) {
|
||||
$all_comments = $post_custom['_mainwp_robot_post_comments'];
|
||||
|
|
|
@ -131,7 +131,6 @@ class MainWP_Keyword_Links {
|
|||
if ( empty( $redirection_folder ) ) {
|
||||
$rules = $this->get_cloak_rules();
|
||||
$rules = $this->mod_rewrite_rules( $rules );
|
||||
//error_log(print_r($rules, true));
|
||||
//self::clear_htaccess();
|
||||
} else {
|
||||
//Create rewrite ruler
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue