Example #1
0
 /**
  * Creates the widget html
  * @param array $args Contains such as $before_widget, $after_widget, $before_title, $after_title, etc
  */
 function widget($args, $instance, $extcall = false)
 {
     // extract args given by wordpress
     extract($args);
     tp_logger($args, 4);
     // we load the class needed and get its base name for later
     $class = $this->load_widget($instance['widget_file']);
     if (!class_exists($class)) {
         echo __('Transposh subwidget was not loaded correctly', TRANSPOSH_TEXT_DOMAIN) . ": {$class}";
     }
     $clean_page = $this->transposh->get_clean_url();
     tp_logger("WIDGET: clean page url: {$clean_page}", 4);
     $widget_args = $this->create_widget_args($clean_page);
     // at this point the widget args are ready
     tp_logger('Enter widget', 4);
     // widget default title
     //echo $before_widget . $before_title . __('Translation', TRANSPOSH_TEXT_DOMAIN) . $after_title; - hmm? po/mo?
     if (isset($before_widget)) {
         echo $before_widget;
     }
     if ($instance['title']) {
         /* TRANSLATORS: no need to translate this string */
         echo $before_title . __($instance['title'], TRANSPOSH_TEXT_DOMAIN) . $after_title;
     }
     // actually run the external widget code
     //if (version_compare(PHP_VERSION, '5.3.0','gt')) { (for the future)
     //   $class::tp_widget_do($widget_args);
     //} else {
     $tmpclass = new $class();
     $tmpclass->tp_widget_do($widget_args);
     if ($extcall) {
         $tmpclass->tp_widget_css($instance['widget_file'], $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url);
         $tmpclass->tp_widget_js($instance['widget_file'], $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url);
         // don't display edit and other things for shortcode embedding
         if (isset($after_widget)) {
             echo $after_widget;
         }
         // increase the number of calls for unique IDs
         self::$draw_calls++;
         return;
     }
     //}
     //at least one language showing - add the edit box if applicable
     if (!empty($widget_args)) {
         // this is the set default language line
         if ($this->transposh->options->widget_allow_set_deflang) {
             if (isset($_COOKIE['TR_LNG']) && $_COOKIE['TR_LNG'] != $this->transposh->target_language || !isset($_COOKIE['TR_LNG']) && !$this->transposh->options->is_default_language($this->transposh->target_language)) {
                 echo '<a id="' . SPAN_PREFIX . 'setdeflang' . self::$draw_calls . '" class="' . SPAN_PREFIX . 'setdeflang' . '" onClick="return false;" href="' . admin_url('admin-ajax.php') . '?action=tp_cookie_bck">' . __('Set as default language', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>';
             }
         }
         // add the edit checkbox only for translators for languages marked as editable
         if ($this->transposh->is_editing_permitted()) {
             $ref = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->options->is_default_language($this->transposh->target_language) ? "" : $this->transposh->target_language, !$this->transposh->edit_mode);
             echo '<input type="checkbox" name="' . EDIT_PARAM . '" value="1" ' . ($this->transposh->edit_mode ? 'checked="checked" ' : '') . ' onclick="document.location.href=\'' . $ref . '\';"/>&nbsp;Edit Translation';
         }
     } else {
         //no languages configured - error message
         echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
     }
     // Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
     // first - according to the gpl, you may do so - but since the code has changed - please make in available under the gpl
     // second - we did invest a lot of time and effort into this, and the link is a way to help us grow and show your appreciation, if it
     // upsets you, feel more than free to move this link somewhere else on your page, such as the footer etc.
     // third - feel free to write your own widget, the translation core will work
     // forth - you can ask for permission, with a good reason, if you contributed to the code - it's a good enough reason :)
     // fifth - if you just delete the following line, it means that you have little respect to the whole copyright thing, which as far as we
     // understand means that by doing so - you are giving everybody else the right to do the same and use your work without any attribution
     // last - you can now remove the logo in exchange to a few percentage of ad and affiliate revenues on your pages, isn't that better?
     $plugpath = parse_url($this->transposh->transposh_plugin_url, PHP_URL_PATH);
     echo '<div id="' . SPAN_PREFIX . 'credit' . self::$draw_calls . '">';
     echo '</div>';
     if (isset($after_widget)) {
         echo $after_widget;
     }
     // increase the number of calls for unique IDs
     self::$draw_calls++;
 }
 function woo_uri_filter($url)
 {
     $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url);
     tp_logger('altering woo url to:' . transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $lang, $this->transposh->edit_mode));
     return transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $lang, $this->transposh->edit_mode);
 }
Example #3
0
 /**
  * After a user adds a comment, makes sure he gets back to the proper language
  * TODO - check the three other params
  * @param string $url
  * @return string fixed url
  */
 function comment_post_redirect_filter($url)
 {
     $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);
     if ($lang) {
         $url = transposh_utils::rewrite_url_lang_param($url, $this->home_url, $this->enable_permalinks_rewrite, $lang, $this->edit_mode);
     }
     return $url;
 }