Exemplo 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;
 }
Exemplo n.º 2
0
 /**
  * This function integrates with google sitemap generator, and adds for each viewable language, the rest of the languages url
  * Also - priority is reduced by 0.2
  * And this requires the following line at the sitemap-core.php, add-url function (line 1509 at version 3.2.4)
  * do_action('sm_addurl', $page);
  * @param GoogleSitemapGeneratorPage $sm_page Object containing the page information
  */
 function add_sm_transposh_urls($sm_page)
 {
     tp_logger("in sitemap add url: " . $sm_page->GetUrl() . " " . $sm_page->GetPriority(), 4);
     $sm_page = clone $sm_page;
     // we need the generator object (we know it must exist...)
     $generatorObject =& GoogleSitemapGenerator::GetInstance();
     // we reduce the priorty by 0.2, but not below zero
     $sm_page->SetProprity(max($sm_page->GetPriority() - 0.2, 0));
     /* <xhtml:link 
        rel="alternate"
        hreflang="de"
        href="http://www.example.com/de" /> */
     $viewable_langs = explode(',', $this->transposh->options->viewable_languages);
     $orig_url = $sm_page->GetUrl();
     foreach ($viewable_langs as $lang) {
         if (!$this->transposh->options->is_default_language($lang)) {
             $newloc = $orig_url;
             if ($this->transposh->options->enable_url_translate) {
                 $newloc = transposh_utils::translate_url($newloc, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation'));
             }
             $newloc = transposh_utils::rewrite_url_lang_param($newloc, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, false);
             $sm_page->SetUrl($newloc);
             $generatorObject->AddElement($sm_page);
         }
     }
 }
Exemplo 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;
 }