Plugin Directory

Changeset 2017382


Ignore:
Timestamp:
01/23/2019 06:14:26 AM (7 years ago)
Author:
AmitDeyUS
Message:

Fixed invalid site name redirection.

Location:
marketpowerwp/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • marketpowerwp/trunk/leplugin.php

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

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

    r1957871 r2017382  
    7575       
    7676        $this->add_action('wp_enqueue_scripts', 'mppe_enqueue_autoprefix', 99999);
    77        
    78         // Deprecated - Too Many Bugs
    79         // if (!is_admin()) {
    80         //     ob_start();
    81         //     add_action('shutdown', function () {
    82         //         $final = '';
    83         //         $levels = ob_get_level();
    84 
    85         //         for ($i = 0; $i < $levels; $i++) {
    86         //             $final .= ob_get_clean();
    87         //         }
    88         //         echo apply_filters('final_output', $final);
    89         //     }, 0);
    90         //     $this->add_filter('final_output', 'mppe_autoprefix_content');
    91         // }
    9277
    9378    }
     
    223208        $settingsGateway = SettingsGateway::getInstance();
    224209        $autoprefix = $settingsGateway->get(self::OPTION_AUTOPREFIX);
    225        
     210
    226211        if($autoprefix){
    227212            wp_enqueue_script('mppe-jurlp', $this->_js_dir_url . 'jurlp/jurlp.min.js', ['jquery']);
     
    242227        }       
    243228    }
    244    
    245     // @Deprecated - too many bugs
    246     // public function mppe_autoprefix_content($output)
    247     // {
    248     //     require_once $this->_plugin_dir . '/src/Multisoft/MPP/Replication/simple_html_dom.php';
    249     //     /* @var $replicationGateway ReplicationGateway */
    250     //     /* @var $settingsGateway SettingsGateway */
    251     //     $replicationGateway = $this->replicationGateway;
    252     //     $settingsGateway = SettingsGateway::getInstance();
    253     //     $autoprefix = $settingsGateway->get(self::OPTION_AUTOPREFIX);
    254 
    255     //     $xxx = $replicationGateway->get_replication_site_name(true);
    256     //     if($xxx === false){
    257     //         return $output;
    258     //     }
    259     //     $host = Utils::get_domain(site_url());
    260     //     $web_address_host = Utils::get_domain($settingsGateway->get(CoreController::OPTION_WEB_ADDRESS));
    261     //     $html = str_get_html($output);
    262     //     if ($html) {
    263     //         foreach ($html->find('a') as $element) {
    264     //             $href = parse_url($element->href);
    265     //             $element_host = Utils::get_domain($href['host']);
    266     //             if (strtolower($element_host) == strtolower($host) ||
    267     //                 strtolower($element_host) == strtolower($web_address_host)
    268     //             ) {
    269     //                 $url_splice = explode('.', $href['host']);
    270     //                 $site_name = $url_splice[0];
    271     //                 if (strtolower($site_name) === 'www') {
    272     //                     $site_name = $url_splice[1];
    273     //                 }
    274     //                 if ($autoprefix && $site_name !== $xxx) {
    275     //                     $new_href = $href['scheme'] . '://' . $xxx . '.' .
    276     //                         Utils::str_replace_first($href['scheme'] . '://', '', $element->href);
    277     //                     $element->href = $new_href;
    278     //                 } else if (!$autoprefix && $site_name === $xxx) {
    279     //                     $new_href = Utils::str_replace_first($xxx . '.', '', $element->href);
    280     //                     $element->href = $new_href;
    281     //                 }
    282     //             }
    283     //         }
    284     //     }
    285     //     return $html;
    286     // }
    287229
    288230    public function mppe_replication_info($atts, $content = null)
     
    325267        $settingsGateway = SettingsGateway::getInstance();
    326268        $replicationGateway = $this->replicationGateway;
    327         $site_name = $replicationGateway->get_replication_site_name();
    328         $valid = $replicationGateway->check_site_name($site_name);
    329         $this->mpp_error_view = new View($this, '');
    330         if (is_wp_error($valid)) {
    331             /* @var $valid \WP_Error */
    332             $this->mpp_error_view->addNotice(
    333                 'Multisoft MarketPowerPRO ' .
    334                 $valid->get_error_code() . ': ' . $valid->get_error_message(),
    335                 'notice-error', false
    336             );
    337         } else if ($valid === false) {
    338             $redirection_page = $settingsGateway->get(self::OPTION_NON_EXIST_REDIRECTION);
    339             if ($redirection_page) {
    340                 wp_redirect(get_permalink($redirection_page));
    341                 exit();
    342             } else {
     269        $site_name = $replicationGateway->get_replication_site_name(true);
     270        if ($site_name) {
     271            $valid = $replicationGateway->check_site_name($site_name);
     272            $this->mpp_error_view = new View($this, '');
     273            if (is_wp_error($valid)) {
     274                /* @var $valid \WP_Error */
     275                $this->mpp_error_view->addNotice(
     276                    'Multisoft MarketPowerPRO ' .
     277                    $valid->get_error_code() . ': ' . $valid->get_error_message(),
     278                    'notice-error', false   
     279                );
     280            } else if ($valid === false) {
    343281                if (is_admin()) {
    344282                    $this->mpp_error_view->addNotice(
     
    348286                    );
    349287                } else {
    350 //                    No more redirect on non-existing subdomain. Just display the page
    351 //                    wp_redirect(Utils::getMainDomain());
    352 //                    exit();
     288                    add_action("template_redirect", [$this, "mppe_invalid_site_name_redirect"]);
    353289                }
    354290            }
    355291        }
     292    }
     293
     294    public function mppe_invalid_site_name_redirect() {
     295        $settingsGateway = SettingsGateway::getInstance();
     296        $redirection_page = $settingsGateway->get(self::OPTION_NON_EXIST_REDIRECTION);
     297        global $wpdb;
     298        $prefix = $wpdb->prefix;
     299        $original_site_url = $wpdb->get_var("SELECT option_value FROM {$prefix}options WHERE option_name = 'siteurl'");
     300        if($redirection_page) {
     301            $url = strtolower(get_permalink($redirection_page));
     302            $url = Utils::str_replace_first(strtolower(site_url()), $original_site_url, $url);
     303        } else {
     304            $url = strtolower($original_site_url);
     305        }
     306        wp_redirect($url);
     307        exit();
    356308    }
    357309
  • marketpowerwp/trunk/views/mpp_replication_general_settings_section.php

    r1431993 r2017382  
    88            <?php wp_dropdown_pages($this->page_drop_down_args); ?>
    99
    10             <p class="description">Empty by default and plugin will just send 404 page when a non-existent site
     10            <p class="description">Empty by default and plugin will just redirect to the home page when a non-existent site
    1111                name has been detected. You can optionally select a page to redirect to when this occurs.</p>
    1212        </td>
Note: See TracChangeset for help on using the changeset viewer.