Skip to content

Commit

Permalink
Merge pull request #606 from mainwp/mainwp-dev
Browse files Browse the repository at this point in the history
Dev Merge
  • Loading branch information
thanghv committed Mar 22, 2023
2 parents 76754f6 + 415e976 commit 052dee0
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 30 deletions.
4 changes: 3 additions & 1 deletion class/class-mainwp-api-manager-key.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ public function get_purchased_software( $args ) {
MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api',
array(
'body' => $args,
'timeout' => 50,
'timeout' => 200,
'sslverify' => self::$apisslverify,
)
);

MainWP_Logger::instance()->debug( 'Get purchased softwares: ' . MainWP_Utility::value_to_string( $request ) );

if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) {
// Request failed.
return false;
Expand Down
2 changes: 1 addition & 1 deletion class/class-mainwp-api-manager-plugin-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function plugin_information( $args, $bulk_check = false ) {

$target_url = $this->create_upgrade_api_url( $args, $bulk_check );
$default = array(
'timeout' => 50,
'timeout' => 150,
'sslverify' => 1,
);

Expand Down
42 changes: 37 additions & 5 deletions class/class-mainwp-db-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,25 +1112,57 @@ public function get_client_fields( $general = true, $client_id = 0, $field_name_
return false;
}

$gene_results = array();

if ( $general ) {
// to fix: missing general fields for client without client fields values.
$gene_sql = 'SELECT f.* FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f WHERE f.client_id = 0 ORDER BY f.field_name ';
$gene_results = $this->wpdb->get_results( $gene_sql );
}

if ( $client_id ) { // get fields values of client.
$sql = 'SELECT f.*,v.value_client_id, v.field_value as field_value FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f LEFT JOIN ' .
$sql = 'SELECT f.*, v.field_value as field_value FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f LEFT JOIN ' .
$this->table_name( 'wp_clients_field_values' ) . ' v ON f.field_id = v.field_id WHERE ' . $where . ' ORDER BY f.field_name ';
} else {
$sql = 'SELECT f.* FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f WHERE ' . $where . ' ORDER BY f.field_name '; // value_client_id to compatible result.
}

$results = $this->wpdb->get_results( $sql );

$fields_list = array();
if ( $field_name_index ) {
$results = $this->wpdb->get_results( $sql );
$fields_list = array();
if ( $results ) {
foreach ( $results as $item ) {
$fields_list[ $item->field_name ] = $item;
}
}
return $fields_list;
if ( $gene_results ) {
foreach ( $gene_results as $gene_item ) {
if ( ! isset( $fields_list[ $gene_item->field_name ] ) ) {
$gene_item->field_value = '';
$fields_list[ $gene_item->field_name ] = $gene_item;
}
}
}
} else {
return $this->wpdb->get_results( $sql );
$check_list = array();
if ( $results ) {
foreach ( $results as $item ) {
$check_list[ $item->field_name ] = true;
$fields_list[] = $item;
}
}
if ( $gene_results ) {
foreach ( $gene_results as $gene_item ) {
if ( ! isset( $check_list[ $gene_item->field_name ] ) ) {
$check_list[ $gene_item->field_name ] = true;
$gene_item->field_value = '';
$fields_list[] = $gene_item;
}
}
}
}
return $fields_list;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions class/class-mainwp-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ public function get_website_options_array( &$website, $options ) {
} else {
$get_options[] = $option;
}
} else {
$get_options[] = $option;
}
}

Expand Down
12 changes: 6 additions & 6 deletions class/class-mainwp-system-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,18 +692,18 @@ public static function get_child_response( $data ) {
}

if ( isset( $resp['notices'] ) ) {
$notices = array();
if ( is_string( $resp['notices'] ) ) {
$notices = MainWP_Utility::esc_content( $resp['notices'] );
$resp['notices'] = MainWP_Utility::esc_content( $resp['notices'] );
} elseif ( is_array( $resp['notices'] ) ) {
$notices = array();
foreach ( $resp['notices'] as $noti ) {
if ( is_string( $noti ) ) {
if ( ! empty( $noti ) && is_string( $noti ) ) {
$notices[] = MainWP_Utility::esc_content( $noti );
}
}
}
if ( ! empty( $notices ) ) {
$resp['notices'] = $notices;
if ( ! empty( $notices ) ) {
$resp['notices'] = implode( ' || ', $notices );
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions class/class-mainwp-system.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function __construct( $mainwp_plugin_file ) {

if ( is_admin() ) {
include_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php';
$pluginData = get_plugin_data( $mainwp_plugin_file );
$pluginData = get_plugin_data( $mainwp_plugin_file, true, false ); // to fix issue of user language setting.
$this->current_version = $pluginData['Version'];
$currentVersion = get_option( 'mainwp_plugin_version' );

Expand Down Expand Up @@ -165,7 +165,7 @@ public function __construct( $mainwp_plugin_file ) {

$systemHandler = MainWP_System_Handler::instance();

add_action( 'init', array( &$this, 'localization' ) );
add_action( 'plugins_loaded', array( &$this, 'localization' ) );
add_filter( 'site_transient_update_plugins', array( $systemHandler, 'check_update_custom' ) );
add_filter( 'pre_set_site_transient_update_plugins', array( $systemHandler, 'pre_check_update_custom' ) );
add_filter( 'plugins_api', array( $systemHandler, 'plugins_api_info' ), 10, 3 );
Expand Down
23 changes: 16 additions & 7 deletions class/class-mainwp-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -1130,23 +1130,32 @@ public static function gen_groups_sites_selection() {
*
* @uses \MainWP\Dashboard\MainWP_DB::get_websites_count()
*/
public static function render_header_actions() {
public static function render_header_actions() { //phpcs:ignore -- complex method.
$sites_count = MainWP_DB::instance()->get_websites_count();
$website_id = '';
$sidebar_pages = array( 'ManageGroups', 'PostBulkManage', 'PostBulkAdd', 'PageBulkManage', 'PageBulkAdd', 'ThemesManage', 'ThemesInstall', 'ThemesAutoUpdate', 'PluginsManage', 'PluginsInstall', 'PluginsAutoUpdate', 'UserBulkManage', 'UserBulkAdd', 'UpdateAdminPasswords', 'Extensions' );
$sidebar_pages = apply_filters( 'mainwp_sidbar_pages', $sidebar_pages ); // deprecated filter.
$sidebar_pages = apply_filters( 'mainwp_sidebar_pages', $sidebar_pages );
ob_start();
if ( isset( $_GET['dashboard'] ) ) :
$id = intval( $_GET['dashboard'] );
if ( isset( $_GET['dashboard'] ) || isset( $_GET['id'] ) || isset( $_GET['updateid'] ) || isset( $_GET['emailsettingsid'] ) || isset( $_GET['scanid'] ) ) :
if ( isset( $_GET['dashboard'] ) ) {
$id = intval( $_GET['dashboard'] );
} elseif ( isset( $_GET['id'] ) ) {
$id = intval( $_GET['id'] );
} elseif ( isset( $_GET['updateid'] ) ) {
$id = intval( $_GET['updateid'] );
} elseif ( isset( $_GET['emailsettingsid'] ) ) {
$id = intval( $_GET['emailsettingsid'] );
} elseif ( isset( $_GET['scanid'] ) ) {
$id = intval( $_GET['scanid'] );
}

$website = MainWP_DB::instance()->get_website_by_id( $id );

if ( '' != $website->sync_errors ) :
?>
<a href="#" class="mainwp-updates-overview-reconnect-site ui green button" siteid="<?php echo $website->id; ?>" data-position="bottom right" data-tooltip="Reconnect <?php echo stripslashes( $website->name ); ?>" data-inverted=""><?php esc_html_e( 'Reconnect Site', 'mainwp' ); ?></a>
<?php
else :
?>
<?php else : ?>
<button class="ui button green <?php echo ( 0 < $sites_count ? '' : 'disabled' ); ?>" id="mainwp-sync-sites" data-inverted="" data-position="bottom right" data-tooltip="<?php esc_attr_e( 'Get fresh data from your child sites.', 'mainwp' ); ?>">
<i class="sync icon mainwp-sync-button-icon"></i>
<span class="mainwp-sync-button-text">
Expand All @@ -1158,7 +1167,7 @@ public static function render_header_actions() {
*
* @since 4.1
*/
echo esc_html( apply_filters( 'mainwp_site_sync_button_text', esc_html__( 'Sync Dashboard with Site', 'mainwp' ) ) );
echo esc_html( apply_filters( 'mainwp_site_sync_button_text', esc_html__( 'Sync Site', 'mainwp' ) ) );
?>
</span>
</button>
Expand Down
10 changes: 8 additions & 2 deletions pages/page-mainwp-updates-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ public static function upgrade_plugin_theme_translation( $id, $type, $list ) {
}
$result = self::update_plugin_theme_translation( $website, $type, $list );
if ( is_array( $result ) ) {
$undefined = true;
if ( isset( $result['upgrades'] ) ) {
$tmp = array();
if ( isset( $result['upgrades'] ) ) {
Expand All @@ -669,8 +670,13 @@ public static function upgrade_plugin_theme_translation( $id, $type, $list ) {
} elseif ( isset( $result['error'] ) ) {
throw new MainWP_Exception( 'WPERROR', esc_html( $result['error'] ) );
} elseif ( isset( $result['notices'] ) ) {
throw new MainWP_Exception( $result['notices'], '', 'MAINWP_NOTICE' );
} else {
$noti = $result['notices'];
if ( ! empty( $noti ) && is_string( $noti ) ) {
throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' );
}
}

if ( $undefined ) {
throw new MainWP_Exception( 'ERROR', esc_html__( 'Invalid response retured from the child site. Please try again.', 'mainwp' ) );
}
}
Expand Down
16 changes: 10 additions & 6 deletions widgets/widget-mainwp-clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,23 @@ private static function render_clients( $clients ) {
</td>
<td class="left aligned middle aligned">
<?php
$contact = false;
if ( isset( $client['primary_contact_id'] ) && '' != $client['primary_contact_id'] ) {
$contact = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'contact_id', $client['primary_contact_id'] );
?>
if ( $contact ) {
?>
<span><?php echo esc_html( $contact->contact_name ); ?> <?php echo ( isset( $contact->contact_role ) && '' != $contact->contact_role ) ? ' - ' . esc_html( $contact->contact_role ) : ''; ?></span><br/>
<?php if ( isset( $contact->contact_email ) && '' != $contact->contact_email ) : ?>
<?php if ( isset( $contact->contact_email ) && '' != $contact->contact_email ) : ?>
<span class="ui small text"><a href="mailto:<?php echo $contact->contact_email; ?>"><i class="envelope icon"></i> <?php echo esc_html( $contact->contact_email ); ?></a></span><br/>
<?php endif; ?>
<?php if ( isset( $contact->contact_phone ) && '' != $contact->contact_phone ) : ?>
<?php if ( isset( $contact->contact_phone ) && '' != $contact->contact_phone ) : ?>
<span class="ui small text"><a href="tel:<?php echo $contact->contact_phone; ?>"><i class="phone alternate icon"></i> <?php echo esc_html( $contact->contact_phone ); ?></a></span>
<?php endif; ?>
<?php
} else {
echo esc_html_( 'No Contacts', 'mainwp' );
<?php
}
}
if ( empty( $contact ) ) {
echo esc_html__( 'No Contacts', 'mainwp' );
}
?>
</td>
Expand Down

0 comments on commit 052dee0

Please sign in to comment.