Esempio n. 1
0
 /**
  * Calculate arguments needed by subwidgets
  * @param string $clean_page_url
  * @return array
  */
 function create_widget_args($clean_page_url)
 {
     // only calculate urls once even for multiple instances
     static $widget_args;
     if (is_array($widget_args)) {
         return $widget_args;
     }
     $widget_args = array();
     $page_url = '';
     if (is_404()) {
         $clean_page_url = transposh_utils::cleanup_url($this->transposh->home_url, $this->transposh->home_url, true);
     }
     // loop on the languages
     foreach ($this->transposh->options->get_sorted_langs() as $code => $langrecord) {
         list($langname, $language, $flag) = explode(',', $langrecord);
         // Only send languages which are active
         if ($this->transposh->options->is_active_language($code) || $this->transposh->options->is_default_language($code)) {
             // now we alway do this... maybe cache this to APC/Memcache
             if ($this->transposh->options->enable_url_translate && !$this->transposh->options->is_default_language($code)) {
                 $page_url = transposh_utils::translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation'));
             } else {
                 $page_url = $clean_page_url;
             }
             // clean $code in default lanaguge
             $page_url = transposh_utils::rewrite_url_lang_param($page_url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->options->is_default_language($code) ? '' : $code, $this->transposh->edit_mode);
             $widget_args[] = array('lang' => $langname, 'langorig' => $language, 'flag' => $flag, 'isocode' => $code, 'url' => htmlentities($page_url), 'active' => $this->transposh->target_language == $code);
         }
     }
     return $widget_args;
 }
Esempio n. 2
0
 /**
  * This filter method helps buddypress understand the transposh generated URLs
  * @param string $uri The url that was originally received
  * @return string The url that buddypress should see
  */
 function bp_uri_filter($uri)
 {
     $lang = transposh_utils::get_language_from_url($uri, $this->transposh->home_url);
     //TODO - check using get_clean_url
     $uri = transposh_utils::cleanup_url($uri, $this->transposh->home_url);
     if ($this->transposh->options->enable_url_translate) {
         $uri = transposh_utils::get_original_url($uri, '', $lang, array($this->transposh->database, 'fetch_original'));
     }
     return $uri;
 }
Esempio n. 3
0
 /**
  * Callback from parser allowing to overide the global setting of url rewriting using permalinks.
  * Some urls should be modified only by adding parameters and should be identified by this
  * function.
  * @param $href Original href
  * @return boolean Modified href
  */
 function rewrite_url($href)
 {
     tp_logger("got: {$href}", 5);
     // fix what might be messed up -- TODO
     $href = str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $href);
     // Ignore urls not from this site
     if (!transposh_utils::is_rewriteable_url($href, $this->home_url)) {
         return $href;
     }
     // don't fix links pointing to real files as it will cause that the
     // web server will not be able to locate them
     if (stripos($href, '/wp-admin') !== FALSE || stripos($href, WP_CONTENT_URL) !== FALSE || stripos($href, '/wp-login') !== FALSE || stripos($href, '/.php') !== FALSE) {
         return $href;
     }
     $use_params = !$this->enable_permalinks_rewrite;
     // we don't really know, but we sometime rewrite urls when we are in the default language (canonicals?), so just clean them up
     //       if ($this->target_language == $this->options->default_language)
     if ($this->options->is_default_language($this->target_language)) {
         $href = transposh_utils::cleanup_url($href, $this->home_url);
         tp_logger("cleaned up: {$href}", 4);
         return $href;
     }
     // some hackery needed for url translations
     // first cut home
     if ($this->options->enable_url_translate) {
         $href = transposh_utils::translate_url($href, $this->home_url, $this->target_language, array(&$this->database, 'fetch_translation'));
     }
     $href = transposh_utils::rewrite_url_lang_param($href, $this->home_url, $this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params);
     tp_logger("rewritten: {$href}", 4);
     return $href;
 }