Plugin Directory

Changeset 2018218


Ignore:
Timestamp:
01/24/2019 09:39:10 AM (7 years ago)
Author:
AmitDeyUS
Message:

Repointed replication pull to use ByGUID and allowed cascading multiple defaults for shortcode

Location:
marketpowerwp/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • marketpowerwp/trunk/leplugin.php

    r2018123 r2018218  
    44 * Plugin Name: Multisoft MarketPowerPRO Tools
    55 * Description: Integration of MarketPowerPro to Wordpress
    6  * Version: 2.2.3
     6 * Version: 2.2.4
    77 * Author: Rodine Mark Paul L. Villar
    88 * Author URI: mailto:dine@multisoft.com?subject=Multisoft+MarketPowerPRO+Tools
  • marketpowerwp/trunk/readme.txt

    r2018123 r2018218  
    33Tags: marketpowerpro, multisoft
    44Requires at least: 3.4+
    5 Stable tag: 2.2.3
    6 Version: 2.2.3
     5Stable tag: 2.2.4
     6Version: 2.2.4
    77Tested up to: 5.0.1
    88License: Commercial
  • marketpowerwp/trunk/src/Multisoft/MPP/Replication/ReplicationController.php

    r2018123 r2018218  
    254254                $mppe_data = trim($mppe_info[strtoupper($info)]);
    255255                if (empty($mppe_data) && $default) {
    256                     $mppe_data = str_replace(""", "", $default);
     256                    $defaults = explode(",", $default);
     257                    foreach ($defaults as $default) {
     258                        $default = trim(str_replace(""", "", $default));
     259                        $key_default = strtoupper($default);
     260                        if (strpos($key_default, "MPPE_") === 0) {
     261                            $key = str_replace("MPPE_", "", $key_default);
     262                            if (isset($mppe_info[$key]) && !empty(trim($mppe_info[$key]))) {
     263                                $mppe_data = $mppe_info[$key];
     264                                break;
     265                            }
     266                        } else {
     267                            $mppe_data = $default;
     268                            break;
     269                        }
     270                    }
    257271                }
    258272                return $mppe_data;
  • marketpowerwp/trunk/src/Multisoft/MPP/Replication/ReplicationGateway.php

    r1957871 r2018218  
    3737        return static::$instance;
    3838    }
    39    
    40     public function get_original_site_url(){
     39
     40    public function get_original_site_url()
     41    {
    4142        global $wpdb;
    4243
    4344        $prefix = $wpdb->prefix;
    44        
     45
    4546        $original_site_url = $wpdb->get_var("SELECT option_value FROM {$prefix}options WHERE option_name = 'siteurl'");
    4647
     
    4849
    4950        $original_site_url = Utils::str_replace_first('www.', '', strtolower($original_site_url));
    50    
     51
    5152        return $original_site_url;
    5253    }
     
    5556    {
    5657        $settingsGateway = SettingsGateway::getInstance();
    57        
     58
    5859        global $wpdb;
    5960
     
    6768
    6869        if (!strlen($xxx) || $xxx === 'localhost' || $xxx === 'www') {
    69             if($false_empty){
     70            if ($false_empty) {
    7071                return false;
    7172            }
     
    7576        return $xxx;
    7677
     78    }
     79
     80    private function parse_received_info($data)
     81    {
     82        $parser = xml_parser_create();
     83        xml_parse_into_struct($parser, $data['body'], $values, $index);
     84        xml_parser_free($parser);
     85        $parsed_replication_info = array();
     86        foreach ($values as $xml_child) {
     87            if ($xml_child["level"] == 2) {
     88                $parsed_replication_info[$xml_child["tag"]] =
     89                    isset($xml_child["value"]) ? $xml_child["value"] : "";
     90            }
     91        }
     92        return $parsed_replication_info;
    7793    }
    7894
     
    109125                try {
    110126                    $q_str = sprintf($mppe_replication_query_format, $mppe_application_id, $subdomain);
    111                     parse_str($q_str, $post_fields);
    112                     $url = $mppe_domain . $mppe_web_path . $mppe_replication_path;
    113                     $logger->info('Pulling replication info from: ' . $url);
    114                     $logger->debug('Post fields: ', $post_fields);
    115                     $data = wp_remote_post($url, array(
     127                    parse_str($q_str, $distributor_post_fields);
     128                    $distributor_url = $mppe_domain . $mppe_web_path . $mppe_replication_path;
     129                    $logger->info('Pulling distributor info from: ' . $distributor_url);
     130                    $logger->debug('Distributor Post fields: ', $distributor_post_fields);
     131                    $distributor_data = wp_remote_post($distributor_url, array(
    116132                        'method' => 'POST',
    117133                        'timeout' => 45,
     
    120136                        'blocking' => true,
    121137                        'headers' => array(),
    122                         'body' => $post_fields,
     138                        'body' => $distributor_post_fields,
    123139                        'cookies' => array()
    124140                    ));
    125                     if (is_wp_error($data)) {
    126                         $error_message = $data->get_error_message();
     141                    if (is_wp_error($distributor_data)) {
     142                        $error_message = $distributor_data->get_error_message();
    127143                        $logger->critical($error_message);
    128                         $replication_info = $data;
     144                        $replication_info = $distributor_data;
    129145                    } else {
    130                         if ($data['response']['code'] == '200') {
    131                             $logger->info("Successfully pulled replication info. Parsing replication data...");
    132                             $logger->debug("Received data: " . PHP_EOL . $data['body']);
    133                             $parser = xml_parser_create();
    134                             xml_parse_into_struct($parser, $data['body'], $values, $index);
    135                             xml_parser_free($parser);
    136                             $parsed_replication_info = array();
    137                             foreach ($values as $xml_child) {
    138                                 if ($xml_child["level"] == 2) {
    139                                     $parsed_replication_info[$xml_child["tag"]] =
    140                                         isset($xml_child["value"]) ? $xml_child["value"] : "";
    141                                 }
    142                             }
    143                             $logger->debug('Parsed replication info:', $parsed_replication_info);
    144                             if ($parsed_replication_info["DISTRIBUTORID"] != "00000000-0000-0000-0000-000000000000") {
    145                                 $replication_info = $parsed_replication_info;
     146                        if ($distributor_data['response']['code'] == '200') {
     147                            $logger->info("Successfully pulled distributor info. Parsing distributor data...");
     148                            $logger->debug("Received data: " . PHP_EOL . $distributor_data['body']);
     149                            $parsed_distributor_info = $this->parse_received_info($distributor_data);
     150                            $logger->debug('Parsed distributor info:', $parsed_distributor_info);
     151                            if (!empty($parsed_distributor_info["DISTRIBUTORID"]) && $parsed_distributor_info["DISTRIBUTORID"] != "00000000-0000-0000-0000-000000000000") {
     152                                $logger->info("Getting replication info for distributor...");
     153                                $infoUrl = $mppe_domain . $mppe_web_path . $mppe_replication_path . "ByGUID";
     154                                $logger->info('Pulling replication info from: ' . $infoUrl);
     155                                $distributorGuid = trim($parsed_distributor_info["DISTRIBUTORID"]);
     156                                $replication_q_str = sprintf("hashKey=%s&UserGuid=%s", $mppe_application_id, $distributorGuid);
     157                                parse_str($replication_q_str, $replication_post_fields);
     158                                $logger->debug('Replication Post fields: ', $replication_post_fields);
     159                                $replication_data = wp_remote_post($infoUrl, array(
     160                                    'method' => 'POST',
     161                                    'timeout' => 45,
     162                                    'redirection' => 5,
     163                                    'httpversion' => '1.0',
     164                                    'blocking' => true,
     165                                    'headers' => array(),
     166                                    'body' => $replication_post_fields,
     167                                    'cookies' => array()
     168                                ));
     169                                $logger->info("Successfully pulled replication info. Parsing replication data...");
     170                                $logger->debug("Received data: " . PHP_EOL . $replication_data['body']);
     171                                $replication_info = $this->parse_received_info($replication_data);
     172                                $logger->debug('Parsed replication info:', $replication_info);
    146173                                $coreGateway->set_transient(self::TRANS_REPLICATION_KEY, $replication_info, $subdomain);
    147174                                $logger->info('Successfully set replication info in mpp transient.');
     
    152179                            }
    153180                        } else {
    154                             $logger->error("HTTP Error: ", $data['response']);
    155                             $replication_info = new \WP_Error($data['response']['code'], $data['response']['message']);
     181                            $logger->error("HTTP Error: ", $distributor_data['response']);
     182                            $replication_info = new \WP_Error($distributor_data['response']['code'], $distributor_data['response']['message']);
    156183                        }
    157184                    }
Note: See TracChangeset for help on using the changeset viewer.