Changeset 599 for trunk


Ignore:
Timestamp:
01/16/2011 12:41:03 AM (16 months ago)
Author:
ofer
Message:

Fix for #139, by making sure wp_redirect gets rewritten, this probably needs more testing

Location:
trunk/WordPress/plugin/transposh
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/transposh.php

    r580 r599  
    8989    /** @var might be that page is json... */ 
    9090    private $attempt_json = false; 
     91    /** @var boolean Is the wp_redirect being called by transposh? */ 
     92    private $transposh_redirect = false; 
    9193 
    9294    /** 
     
    161163 
    162164        // debug function for bad redirects 
    163         // add_filter('wp_redirect', array(&$this, 'on_wp_redirect'), 10, 2); 
     165        add_filter('wp_redirect', array(&$this, 'on_wp_redirect'), 10, 2); 
    164166        add_filter('redirect_canonical', array(&$this, 'on_redirect_canonical'), 10, 2); 
    165167        // 
     
    175177    } 
    176178 
    177 //    function on_wp_redirect($location, $status) { 
    178 //        logger($location); 
    179 //        logger($status); 
    180 //        $trace = debug_backtrace(); 
    181 //        logger($trace); 
    182 //        return $location; 
    183 //    } 
     179    /** 
     180     * Attempt to fix a wp_redirect being called by someone else to include the language 
     181     * hoping for no cycles 
     182     * @param string $location 
     183     * @param int $status 
     184     * @return string 
     185     */ 
     186    function on_wp_redirect($location, $status) { 
     187        if ($this->transposh_redirect) return $location; 
     188        logger($status . ' ' . $location); 
     189        // $trace = debug_backtrace(); 
     190        // logger($trace); 
     191        // logger($this->target_language); 
     192        $location = str_replace(array('%2F', '%3A', '%3B', '%3F', '%3D', '%26'), array('/', ':', ';', '?', '=', '&'), urlencode($this->rewrite_url($location))); 
     193        return $location; 
     194    } 
     195 
     196    /** 
     197     * Internally used by transposh redirection, to avoid being rewritten by self 
     198     * assuming we know what we are doing when redirecting 
     199     * @param string $location 
     200     * @param int $status 
     201     */ 
     202    function tp_redirect($location, $status = 302) { 
     203        $this->transposh_redirect = true; 
     204        wp_redirect($location, $status); 
     205    } 
    184206 
    185207    /** 
     
    265287                if (file_exists(ABSPATH . $wp->query_vars['pagename'])) { 
    266288                    logger('Redirecting a static file ' . $wp->query_vars['pagename'], 1); 
    267                     wp_redirect('/' . $wp->query_vars['pagename'], 301); 
     289                    $this->tp_redirect('/' . $wp->query_vars['pagename'], 301); 
    268290                } 
    269291            } 
     
    449471                                $url = transposh_utils::cleanup_url($_SERVER["REQUEST_URI"], $this->home_url); 
    450472                        logger("redirected to $url because of cookie", 4); 
    451                         wp_redirect($url); 
     473                        $this->tp_redirect($url); 
    452474                        exit; 
    453475                    } 
     
    461483                                $url = transposh_utils::cleanup_url($_SERVER['REQUEST_URI'], $this->home_url); 
    462484                        logger("redirected to $url because of bestlang", 4); 
    463                         wp_redirect($url); 
     485                        $this->tp_redirect($url); 
    464486                        exit; 
    465487                    } 
     
    477499            } 
    478500            if (transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) { 
    479                 wp_redirect(transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false)); //."&stop=y"); 
     501                $this->tp_redirect(transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false)); //."&stop=y"); 
    480502                exit; 
    481503            } 
  • trunk/WordPress/plugin/transposh/wp/transposh_3rdparty.php

    r558 r599  
    3838        add_action('bp_activity_after_save', array(&$this, 'bp_activity_after_save')); 
    3939        add_action('transposh_human_translation', array(&$this, 'transposh_buddypress_stream'), 10, 3); 
    40  
     40        //bp_activity_permalink_redirect_url (can fit here if generic setting fails) 
     41         
    4142        // google xml sitemaps - with patch 
    4243        add_action('sm_addurl', array(&$this, 'add_sm_transposh_urls')); 
     
    190191 
    191192} 
     193 
    192194?> 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r587 r599  
    267267 
    268268        // lets redirect the post request into get request (you may add additional params at the url, if you need to show save results 
    269         wp_redirect($_POST['_wp_http_referer']); 
     269        $this->transposh->tp_redirect($_POST['_wp_http_referer']); 
    270270    } 
    271271 
  • trunk/WordPress/plugin/transposh/wp/transposh_ajax.php

    r587 r599  
    6868    setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN); 
    6969    if ($_SERVER['HTTP_REFERER']) { 
    70         wp_redirect($_SERVER['HTTP_REFERER']); 
     70        $this->transposh->tp_redirect($_SERVER['HTTP_REFERER']); 
    7171    } else { 
    72         wp_redirect($my_transposh_plugin->home_url); 
     72        $this->transposh->tp_redirect($my_transposh_plugin->home_url); 
    7373    } 
    7474} 
  • trunk/WordPress/plugin/transposh/wp/transposh_widget.php

    r588 r599  
    7171            logger("Widget redirect url: $ref", 3); 
    7272 
    73             wp_redirect($ref); 
     73            $this->transposh->tp_redirect($ref); 
    7474            exit; 
    7575        } 
     
    277277        echo '<div id="' . SPAN_PREFIX . 'credit">'; 
    278278        if (!$this->transposh->options->get_widget_remove_logo()) { 
    279             echo 'by <a href="http://tran' . 'sposh.org/' . $extralang . '"><img class="' . NO_TRANSLATE_CLASS . '" height="16" width="16" src="' . 
     279            echo 'by <a href="http://tran' . 'sposh.org/' . $extralang . '"><img height="16" width="16" src="' . 
    280280            $plugpath . '/img/tplog' . 'o.png" style="padding:1px;border:0px" title="' . $tagline . '" alt="' . $tagline . '"/></a>'; 
    281281        } 
Note: See TracChangeset for help on using the changeset viewer.