- Timestamp:
- 11/26/2011 09:27:16 PM (6 months ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 13 edited
-
core/constants.php (modified) (3 diffs)
-
js/transposh.js (modified) (2 diffs)
-
transposh.php (modified) (1 diff)
-
widgets/default/tpw_default.php (modified) (1 diff)
-
widgets/dropdown/tpw_image_dropdown.js (modified) (1 diff)
-
widgets/dropdown/tpw_image_dropdown.php (modified) (1 diff)
-
widgets/flags/tpw_flags.php (modified) (1 diff)
-
widgets/flags/tpw_flags_css.php (modified) (1 diff)
-
widgets/flagslist/tpw_list_with_flags.php (modified) (1 diff)
-
widgets/flagslist/tpw_list_with_flags_css.php (modified) (1 diff)
-
wp/transposh_admin.php (modified) (14 diffs)
-
wp/transposh_options.php (modified) (6 diffs)
-
wp/transposh_widget.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/constants.php
r667 r674 21 21 define('TP_ENABLE_CACHE', TRUE); 22 22 //What is the cache items TTL 23 define('TP_CACHE_TTL', 3600 *24);23 define('TP_CACHE_TTL', 3600 * 24); 24 24 //Constants for memcached 25 25 define('TP_MEMCACHED_SRV', '127.0.0.1'); … … 128 128 // a bit tricky, but we'll see - starting with just esperanto 129 129 public static $apertium_languages = array('eo'); 130 131 130 // Array for holding po domains we have problems with 132 131 public static $ignored_po_domains = array('MailPress'); 132 // Array holding list of jQueryUI themes 133 public static $jqueryui_themes = array('base', 'black-tie', 'blitzer', 'cupertino', 'dark-hive', 'dot-luv', 'eggplant', 'excite-bike', 'flick', 134 'hot-sneaks', 'humanity', 'le-frog', 'mint-choc', 'overcast', 'pepper-grinder', 'redmond', 'smoothness', 'south-street', 135 'start', 'sunny', 'swanky-purse', 'trontastic', 'ui-darkness', 'ui-lightness', 'vader'); 133 136 134 137 } … … 140 143 define('TRANSPOSH_PLUGIN_VER', '%VERSION%'); 141 144 145 //Current jQuery UI 142 146 define('JQUERYUI_VER', '1.8.16'); 143 147 -
trunk/WordPress/plugin/transposh/js/transposh.js
r671 r674 358 358 // this is the set_default_language function 359 359 // attach a function to the set_default_language link if its there 360 $(' #' + t_jp_prefix + 'setdeflang').click(function () {360 $('.' + t_jp_prefix + 'setdeflang').click(function () { 361 361 $.ajax({ 362 362 url: t_jp.ajaxurl, … … 366 366 cache: false 367 367 } ); 368 $( this).hide("slow");368 $('.' + t_jp_prefix + 'setdeflang').hide("slow"); 369 369 return false; 370 370 }); -
trunk/WordPress/plugin/transposh/transposh.php
r672 r674 768 768 function add_rel_alternate() { 769 769 if (is_404()) return; 770 $widget_args = $this->widget->create_widget_args( true,$this->get_clean_url());770 $widget_args = $this->widget->create_widget_args($this->get_clean_url()); 771 771 logger($widget_args, 4); 772 772 foreach ($widget_args as $lang) { -
trunk/WordPress/plugin/transposh/widgets/default/tpw_default.php
r526 r674 34 34 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 35 35 */ 36 function tp_widget_do($args) { 37 echo '<span class="' . NO_TRANSLATE_CLASS . '">'; // wrapping in no_translate to avoid translation of this list 38 echo '<select name="lang" id="lang" onchange="Javascript:this.form.submit();">'; // this is a select box which posts on change 39 echo '<option value="none">[Language]</option>'; 40 foreach ($args as $langrecord) { 41 $is_selected = $langrecord['active'] ? " selected=\"selected\"" : ""; 42 echo "<option value=\"{$langrecord['isocode']}\"{$is_selected}>{$langrecord['langorig']}</option>"; 36 class tpw_default extends transposh_base_widget { 37 38 static function tp_widget_do($args) { 39 echo '<span class="' . NO_TRANSLATE_CLASS . '">'; // wrapping in no_translate to avoid translation of this list 40 41 echo '<select name="lang" id="lang" onchange="document.location.href=this.options[this.selectedIndex].value;">'; // this is a select box which posts on change 42 echo '<option value="none">[Language]</option>'; 43 foreach ($args as $langrecord) { 44 $is_selected = $langrecord['active'] ? " selected=\"selected\"" : ""; 45 echo "<option value=\"{$langrecord['url']}\"{$is_selected}>{$langrecord['langorig']}</option>"; 46 } 47 echo "</select><br/>"; 48 49 echo "</span>"; 43 50 } 44 echo "</select><br/>"; 45 echo "</span>"; 51 46 52 } 53 47 54 ?> -
trunk/WordPress/plugin/transposh/widgets/dropdown/tpw_image_dropdown.js
r435 r674 4 4 5 5 $(document).ready(function() { 6 $(".dropdown dt a").click(function() { 7 $(".dropdown dd ul").toggle(); 8 }); 6 $(".dropdown dt a").click(function() { 7 $(".dropdown dd ul").toggle(); 8 return false; 9 }); 9 10 10 $(".dropdown dd ul li a").click(function() { 11 var text = $(this).html(); 12 $(".dropdown dt a span").html(text); 13 $(".dropdown dd ul").hide(); 14 //$() 15 $("form #lang").val( getSelectedValue("tp_dropdown")); 16 $("#tp_form").submit(); 17 }); 11 $(".dropdown dd ul li a").click(function() { 12 var text = $(this).html(); 13 $(".dropdown dt a span").html(text); 14 $(".dropdown dd ul").hide(); 18 15 19 function getSelectedValue(id) { 20 return $("#" + id).find("dt a span.value").html();21 } 16 document.location.href=getSelectedValue("tp_dropdown"); 17 return false; 18 }); 22 19 23 $(document).bind('click', function(e) { 24 var $clicked = $(e.target); 25 if (! $clicked.parents().hasClass("dropdown")) 26 $(".dropdown dd ul").hide(); 27 }); 20 function getSelectedValue(id) { 21 return $("#" + id).find("dt a span.value").html(); 22 } 23 24 $(document).bind('click', function(e) { 25 var $clicked = $(e.target); 26 if (! $clicked.parents().hasClass("dropdown")) 27 $(".dropdown dd ul").hide(); 28 }); 28 29 }); 29 30 }(jQuery)); // end of closure -
trunk/WordPress/plugin/transposh/widgets/dropdown/tpw_image_dropdown.php
r500 r674 22 22 */ 23 23 24 /** 25 * This function makes sure that the jquery dependency will be met 26 * @global transposh_plugin $my_transposh_plugin 27 */ 28 function tp_widget_js() { 29 global $my_transposh_plugin; 30 wp_enqueue_script("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/{$my_transposh_plugin->widget->base_widget_file_name}.js", array('jquery'), TRANSPOSH_PLUGIN_VER); 24 class tpw_image_dropdown extends transposh_base_widget { 25 26 /** 27 * This function makes sure that the jquery dependency will be met 28 * @global transposh_plugin $my_transposh_plugin 29 */ 30 static function tp_widget_js($file, $dir, $url) { 31 wp_enqueue_script("transposh_widget", "$url/widgets/dropdown/tpw_image_dropdown.js", array('jquery'), TRANSPOSH_PLUGIN_VER); 32 } 33 34 /** 35 * This function does the actual HTML for the widget 36 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 37 */ 38 static function tp_widget_do($args) { 39 global $my_transposh_plugin; 40 // we calculate the plugin path part, so we can link the images there 41 $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 42 43 // we use this hidden field to later post the value 44 echo '<input type="hidden" name="lang" id="lang" value=""/>'; 45 46 echo '<dl id="tp_dropdown" class="dropdown">'; 47 echo '<dt><a href="#"><span>' . __('Select language') . '</span></a></dt><dd><ul class="' . NO_TRANSLATE_CLASS . '">'; 48 foreach ($args as $langrecord) { 49 $is_selected = $langrecord['active'] ? " selected=\"selected\"" : ""; 50 echo '<li><a href="#"><img class="flag" src="' . "$plugpath/img/flags/{$langrecord['flag']}" . '.png" alt="' . $langrecord['langorig'] . '"/> ' . $langrecord['langorig'] . '<span class="value">' . $langrecord['url'] . '</span></a></li>'; 51 } 52 53 echo '</ul></dd></dl>'; 54 } 55 31 56 } 32 57 33 /**34 * This function does the actual HTML for the widget35 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs36 */37 function tp_widget_do($args) {38 global $my_transposh_plugin;39 // we calculate the plugin path part, so we can link the images there40 $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH);41 42 // we use this hidden field to later post the value43 echo '<input type="hidden" name="lang" id="lang" value=""/>';44 45 echo '<span class="' . NO_TRANSLATE_CLASS . '">';46 echo '<dl id="tp_dropdown" class="dropdown">';47 echo '<dt><a href="#"><span>Select language</span></a></dt><dd><ul>';48 49 foreach ($args as $langrecord) {50 $is_selected = $langrecord['active'] ? " selected=\"selected\"" : "";51 echo '<li><a href="#"><img class="flag" src="' . "$plugpath/img/flags/{$langrecord['flag']}" . '.png" alt="' . $langrecord['langorig'] . '"/> ' . $langrecord['langorig'] . '<span class="value">' . $langrecord['isocode'] . '</span></a></li>';52 }53 54 echo '</ul></dd></dl>';55 echo '</span>';56 }57 58 ?> -
trunk/WordPress/plugin/transposh/widgets/flags/tpw_flags.php
r500 r674 26 26 * @return boolean 27 27 */ 28 function tp_widget_needs_post_url() { 29 return true; 28 class tpw_flags extends transposh_base_widget { 29 30 static function tp_widget_needs_post_url() { 31 return true; 32 } 33 34 /** 35 * Creates the list of flags 36 * @global transposh_plugin $my_transposh_plugin 37 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 38 */ 39 static function tp_widget_do($args) { 40 global $my_transposh_plugin; 41 // we calculate the plugin path part, so we can link the images there 42 $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 43 44 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 45 foreach ($args as $langrecord) { 46 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 47 transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . 48 "</a>"; 49 } 50 echo "</div>"; 51 } 52 30 53 } 31 54 32 /**33 * Creates the list of flags34 * @global transposh_plugin $my_transposh_plugin35 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs36 */37 function tp_widget_do($args) {38 global $my_transposh_plugin;39 // we calculate the plugin path part, so we can link the images there40 $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH);41 42 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";43 foreach ($args as $langrecord) {44 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .45 transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) .46 "</a>";47 }48 echo "</div>";49 }50 55 ?> -
trunk/WordPress/plugin/transposh/widgets/flags/tpw_flags_css.php
r500 r674 22 22 */ 23 23 24 /** 25 * This function allows the widget to tell the invoker if it needs to calculate different urls per language, here it is needed 26 * @return boolean 27 */ 28 function tp_widget_needs_post_url() { 29 return true; 24 class tpw_flags_css extends transposh_base_widget { 25 26 /** 27 * Creates the list of flags (with css) 28 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 29 */ 30 static function tp_widget_do($args) { 31 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 32 foreach ($args as $langrecord) { 33 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 34 transposh_utils::display_flag("", $langrecord['flag'], $langrecord['langorig'], true) . 35 "</a>"; 36 } 37 echo "</div>"; 38 } 39 30 40 } 31 41 32 /**33 * Creates the list of flags (with css)34 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs35 */36 function tp_widget_do($args) {37 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";38 foreach ($args as $langrecord) {39 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .40 transposh_utils::display_flag("", $langrecord['flag'], $langrecord['langorig'], true) .41 "</a>";42 }43 echo "</div>";44 }45 42 ?> -
trunk/WordPress/plugin/transposh/widgets/flagslist/tpw_list_with_flags.php
r500 r674 22 22 */ 23 23 24 /** 25 * This function allows the widget to tell the invoker if it needs to calculate different urls per language 26 * @return boolean 27 */ 28 function tp_widget_needs_post_url() { 29 return true; 24 class tpw_list_with_flags extends transposh_base_widget { 25 26 /** 27 * Instructs usage of a different .css file 28 * @global transposh_plugin $my_transposh_plugin 29 */ 30 static function tp_widget_css($file, $dir, $url) { 31 wp_enqueue_style("flags/tpw_flags", "$url/widgets/flags/tpw_flags.css", array(), TRANSPOSH_PLUGIN_VER); 32 } 33 34 /** 35 * Creates the list of flags - followed by a language name link 36 * @global transposh_plugin $my_transposh_plugin 37 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 38 */ 39 static function tp_widget_do($args) { 40 global $my_transposh_plugin; 41 // we calculate the plugin path part, so we can link the images there 42 $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 43 44 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 45 foreach ($args as $langrecord) { 46 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 47 transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>"; 48 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 49 } 50 echo "</div>"; 51 } 52 30 53 } 31 54 32 /**33 * Instructs usage of a different .css file34 * @global transposh_plugin $my_transposh_plugin35 */36 function tp_widget_css() {37 global $my_transposh_plugin;38 wp_enqueue_style("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/flags/tpw_flags.css", array(), TRANSPOSH_PLUGIN_VER);39 }40 41 /**42 * Creates the list of flags - followed by a language name link43 * @global transposh_plugin $my_transposh_plugin44 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs45 */46 function tp_widget_do($args) {47 global $my_transposh_plugin;48 // we calculate the plugin path part, so we can link the images there49 $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH);50 51 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";52 foreach ($args as $langrecord) {53 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .54 transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>";55 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>";56 }57 echo "</div>";58 }59 55 ?> -
trunk/WordPress/plugin/transposh/widgets/flagslist/tpw_list_with_flags_css.php
r531 r674 22 22 */ 23 23 24 /** 25 * This function allows the widget to tell the invoker if it needs to calculate different urls per language 26 * @return boolean 27 */ 28 function tp_widget_needs_post_url() { 29 return true; 24 class tpw_list_with_flags_css extends transposh_base_widget { 25 26 /** 27 * Instructs usage of a different .css file 28 * @global transposh_plugin $my_transposh_plugin 29 */ 30 static function tp_widget_css($file, $dir, $url) { 31 wp_enqueue_style("flags/tpw_flags_css", "$url/widgets/flags/tpw_flags_css.css", array(), TRANSPOSH_PLUGIN_VER); 32 } 33 34 /** 35 * Creates the list of flags (using css sprites) - followed by a language name link 36 * @global transposh_plugin $my_transposh_plugin 37 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 38 */ 39 static function tp_widget_do($args) { 40 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 41 foreach ($args as $langrecord) { 42 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 43 transposh_utils::display_flag('', $langrecord['flag'], $langrecord['langorig'], true) . '</a>'; 44 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 45 } 46 echo "</div>"; 47 } 48 30 49 } 31 50 32 /**33 * Instructs usage of a different .css file34 * @global transposh_plugin $my_transposh_plugin35 */36 function tp_widget_css() {37 global $my_transposh_plugin;38 wp_enqueue_style("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/flags/tpw_flags_css.css", array(), TRANSPOSH_PLUGIN_VER);39 }40 41 /**42 * Creates the list of flags (using css sprites) - followed by a language name link43 * @global transposh_plugin $my_transposh_plugin44 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs45 */46 function tp_widget_do($args) {47 echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";48 foreach ($args as $langrecord) {49 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .50 transposh_utils::display_flag('', $langrecord['flag'], $langrecord['langorig'], true) . '</a>';51 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>";52 }53 echo "</div>";54 }55 51 ?> -
trunk/WordPress/plugin/transposh/wp/transposh_admin.php
r667 r674 130 130 $this->transposh->options->set_google_key($_POST[GOOGLE_TRANSLATE_KEY]); 131 131 $this->transposh->options->set_transposh_key($_POST[TRANSPOSH_KEY]); 132 // frontend stuff 133 $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]); 134 $this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]); 135 $this->transposh->options->set_widget_remove_logo($_POST[WIDGET_REMOVE_LOGO_FOR_AD]); 136 $this->transposh->options->set_widget_theme($_POST[WIDGET_THEME]); 132 137 133 138 // handle change of schedule for backup to daily … … 196 201 //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore 197 202 add_meta_box('transposh-sidebox-about', __('About this plugin', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_about_content'), $this->pagehook, 'side', 'core'); 198 add_meta_box('transposh-sidebox-widget', __('Widget settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_widget_content'), $this->pagehook, 'side', 'core');199 203 add_meta_box('transposh-sidebox-news', __('Plugin news', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_news_content'), $this->pagehook, 'side', 'core'); 200 204 add_meta_box('transposh-sidebox-stats', __('Plugin stats', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_stats_content'), $this->pagehook, 'side', 'core'); … … 203 207 add_meta_box('transposh-contentbox-translation', __('Translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core'); 204 208 add_meta_box('transposh-contentbox-autotranslation', __('Automatic translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core'); 209 add_meta_box('transposh-contentbox-frontend', __('Frontend settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_frontend_content'), $this->pagehook, 'normal', 'core'); 205 210 add_meta_box('transposh-contentbox-general', __('Generic settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core'); 206 211 add_meta_box('transposh-contentbox-database', __('Database maintenance', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_database_content'), $this->pagehook, 'normal', 'core'); … … 302 307 // donate with PayPal 303 308 echo '</ul>'; 304 }305 306 function on_sidebox_widget_content($data) {307 $this->transposh->widget->transposh_widget_control();308 309 } 309 310 … … 423 424 } 424 425 426 private function checkbox($id, $value, $head, $text) { 427 echo '<h4>' . $head . '</h4>'; 428 echo '<input type="checkbox" value="1" name="' . $id . '" ' . $this->checked($value) . '/> ' . $text; 429 } 430 425 431 function on_contentbox_translation_content($data) { 426 432 /* … … 440 446 * Disabled by default. 441 447 */ 442 echo '<h4>' . __('Enable default language translation', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 443 echo '<input type="checkbox" value="1" name="' . ENABLE_DEFAULT_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_default_translate()) . '/> ' . 444 __('Allow translation of default language - useful for sites with more than one major language', TRANSPOSH_TEXT_DOMAIN); 448 $this->checkbox(ENABLE_DEFAULT_TRANSLATE, $this->transposh->options->get_enable_default_translate(), __('Enable default language translation', TRANSPOSH_TEXT_DOMAIN), __('Allow translation of default language - useful for sites with more than one major language', TRANSPOSH_TEXT_DOMAIN)); 445 449 446 450 /** … … 449 453 * @since 0.3.6 450 454 */ 451 echo '<h4>' . __('Enable search in translated languages', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 452 echo '<input type="checkbox" value="1" name="' . ENABLE_SEARCH_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_search_translate()) . '/> ' . 453 __('Allow search of translated languages (and the original language)', TRANSPOSH_TEXT_DOMAIN); 455 $this->checkbox(ENABLE_SEARCH_TRANSLATE, $this->transposh->options->get_enable_search_translate(), __('Enable search in translated languages', TRANSPOSH_TEXT_DOMAIN), __('Allow search of translated languages (and the original language)', TRANSPOSH_TEXT_DOMAIN)); 454 456 455 457 /** … … 458 460 * @since 0.5.3 459 461 */ 460 echo '<h4>' . __('Enable url translation', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN) . ')</h4>'; 461 echo '<input type="checkbox" value="1" name="' . ENABLE_URL_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_url_translate()) . '/> ' . 462 __('Allow translation of permalinks and urls', TRANSPOSH_TEXT_DOMAIN); 462 $this->checkbox(ENABLE_URL_TRANSLATE, $this->transposh->options->get_enable_url_translate(), __('Enable url translation', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN), __('Allow translation of permalinks and urls', TRANSPOSH_TEXT_DOMAIN)); 463 463 464 464 /** … … 467 467 * @since 0.6.4 468 468 */ 469 echo '<h4>' . __('Enable gettext integration', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN) . ')</h4>'; 470 echo '<input type="checkbox" value="1" name="' . TRANSPOSH_GETTEXT_INTEGRATION . '" ' . $this->checked($this->transposh->options->get_transposh_gettext_integration()) . '/> ' . 471 __('Enable integration of Transposh with existing gettext interface (.po/.mo files)', TRANSPOSH_TEXT_DOMAIN); 469 $this->checkbox(TRANSPOSH_GETTEXT_INTEGRATION, $this->transposh->options->get_transposh_gettext_integration(), __('Enable gettext integration', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN), __('Enable integration of Transposh with existing gettext interface (.po/.mo files)', TRANSPOSH_TEXT_DOMAIN)); 472 470 473 471 /** … … 476 474 * @since 0.7.5 477 475 */ 478 echo '<h4>' . __('Enable override for default locale', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 479 echo '<input type="checkbox" value="1" name="' . TRANSPOSH_DEFAULT_LOCALE_OVERRIDE . '" ' . $this->checked($this->transposh->options->get_transposh_default_locale_override()) . '/> ' . 480 __('Enable overriding the default locale that is set in WP_LANG on default languages pages (such as untranslated pages and admin pages)', TRANSPOSH_TEXT_DOMAIN); 476 $this->checkbox(TRANSPOSH_DEFAULT_LOCALE_OVERRIDE, $this->transposh->options->get_transposh_default_locale_override(), __('Enable override for default locale', TRANSPOSH_TEXT_DOMAIN), __('Enable overriding the default locale that is set in WP_LANG on default languages pages (such as untranslated pages and admin pages)', TRANSPOSH_TEXT_DOMAIN)); 481 477 } 482 478 … … 487 483 * Enabled by default. 488 484 */ 489 echo '<h4>' . __('Enable automatic translation', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 490 echo '<input type="checkbox" value="1" name="' . ENABLE_AUTO_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_auto_translate()) . '/> ' . 491 __('Allow automatic translation of pages', TRANSPOSH_TEXT_DOMAIN); 485 $this->checkbox(ENABLE_AUTO_TRANSLATE, $this->transposh->options->get_enable_auto_translate(), __('Enable automatic translation', TRANSPOSH_TEXT_DOMAIN), __('Allow automatic translation of pages', TRANSPOSH_TEXT_DOMAIN)); 492 486 493 487 /** … … 495 489 * Disabled by default. 496 490 * @since 0.3.5 */ 497 echo '<h4>' . __('Enable automatic translation after posting', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 498 echo '<input type="checkbox" value="1" name="' . ENABLE_AUTO_POST_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_auto_post_translate()) . '/> ' . 499 __('Do automatic translation immediately after a post has been published', TRANSPOSH_TEXT_DOMAIN); 491 $this->checkbox(ENABLE_AUTO_POST_TRANSLATE, $this->transposh->options->get_enable_auto_post_translate(), __('Enable automatic translation after posting', TRANSPOSH_TEXT_DOMAIN), __('Do automatic translation immediately after a post has been published', TRANSPOSH_TEXT_DOMAIN)); 500 492 501 493 /** … … 523 515 } 524 516 517 function on_contentbox_frontend_content($data) { 518 $this->checkbox(WIDGET_PROGRESSBAR, $this->transposh->options->get_widget_progressbar(), __('Show progress bar', TRANSPOSH_TEXT_DOMAIN), __('Show progress bar when a client triggers automatic translation', TRANSPOSH_TEXT_DOMAIN)); 519 520 $this->checkbox(WIDGET_ALLOW_SET_DEFLANG, $this->transposh->options->get_widget_allow_set_default_language(), __('Allow user to set current language as default', TRANSPOSH_TEXT_DOMAIN), __('Widget will allow setting this language as user default', TRANSPOSH_TEXT_DOMAIN)); 521 522 $this->checkbox(WIDGET_REMOVE_LOGO_FOR_AD, $this->transposh->options->get_widget_remove_logo(), __('Remove transposh logo (see <a href="http://transposh.org/logoterms">terms</a>)', TRANSPOSH_TEXT_DOMAIN), __('Transposh logo will not appear on widget', TRANSPOSH_TEXT_DOMAIN)); 523 524 echo '<h4>' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 525 echo '<label for="' . WIDGET_THEME . '">' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . 526 '<select id="transposh-style" name="' . WIDGET_THEME . '">'; 527 foreach (transposh_consts::$jqueryui_themes as $theme) { 528 $selected = ($this->transposh->options->get_widget_theme() == $theme) ? ' selected="selected"' : ''; 529 echo "<option value=\"$theme\"$selected>{$theme}</option>"; 530 } 531 echo '</select>' . 532 '</label>'; 533 } 534 525 535 function on_contentbox_generic_content($data) { 526 536 /* … … 528 538 * When disabled only parameters will be used to identify the current language. 529 539 */ 530 echo '<h4>' . __('Rewrite URLs', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 531 echo '<input type="checkbox" value="1" name="' . ENABLE_PERMALINKS . '" ' . $this->checked($this->transposh->options->get_enable_permalinks()) . '/> ' . 532 __('Rewrite URLs to be search engine friendly, ' . 533 'e.g. (http://transposh.org/<strong>en</strong>). ' . 534 'Requires that permalinks will be enabled.', TRANSPOSH_TEXT_DOMAIN); 540 $this->checkbox(ENABLE_PERMALINKS, $this->transposh->options->get_enable_permalinks(), __('Rewrite URLs', TRANSPOSH_TEXT_DOMAIN), __('Rewrite URLs to be search engine friendly, ' . 541 'e.g. (http://transposh.org/<strong>en</strong>). ' . 542 'Requires that permalinks will be enabled.', TRANSPOSH_TEXT_DOMAIN)); 535 543 536 544 /* 537 545 * Insert the option to enable/disable pushing of scripts to footer. 538 * Works on wordpress 2.8 and up 539 */ 540 if (floatval($GLOBALS['wp_version']) >= 2.8) { 541 echo '<h4>' . __('Add scripts to footer', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 542 echo '<input type="checkbox" value="1" name="' . ENABLE_FOOTER_SCRIPTS . '" ' . $this->checked($this->transposh->options->get_enable_footer_scripts()) . '/> ' . 543 __('Push transposh scripts to footer of page instead of header, makes pages load faster. ' . 544 'Requires that your theme should have proper footer support.', TRANSPOSH_TEXT_DOMAIN); 545 } 546 * Works on wordpress 2.8 and up (but we no longer care...) 547 */ 548 $this->checkbox(ENABLE_FOOTER_SCRIPTS, $this->transposh->options->get_enable_footer_scripts(), __('Add scripts to footer', TRANSPOSH_TEXT_DOMAIN), __('Push transposh scripts to footer of page instead of header, makes pages load faster. ' . 549 'Requires that your theme should have proper footer support.', TRANSPOSH_TEXT_DOMAIN)); 546 550 547 551 /** 548 552 * Insert the option to enable/disable language auto-detection 549 553 * @since 0.3.8 */ 550 echo '<h4>' . __('Auto detect language for users', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 551 echo '<input type="checkbox" value="1" name="' . ENABLE_DETECT_LANG_AND_REDIRECT . '" ' . $this->checked($this->transposh->options->get_enable_detect_language()) . '/> ' . 552 __('This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. ' . 553 'This will redirect the first page accessed in the session to the same page with the detected language.', TRANSPOSH_TEXT_DOMAIN); 554 $this->checkbox(ENABLE_DETECT_LANG_AND_REDIRECT, $this->transposh->options->get_enable_detect_language(), __('Auto detect language for users', TRANSPOSH_TEXT_DOMAIN), __('This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. ' . 555 'This will redirect the first page accessed in the session to the same page with the detected language.', TRANSPOSH_TEXT_DOMAIN)); 554 556 555 557 /** 556 558 * Insert the option to enable/disable statics collection 557 * @since 0.3.8 */ 558 echo '<h4>' . __('Allow collecting usage statistics', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 559 echo '<input type="checkbox" value="1" name="' . TRANSPOSH_COLLECT_STATS . '" ' . $this->checked($this->transposh->options->get_transposh_collect_stats()) . '/> ' . 560 __('This option enables collection of statistics by transposh that will be used to improve the product. ', TRANSPOSH_TEXT_DOMAIN); 559 * @since 0.7.6 */ 560 $this->checkbox(TRANSPOSH_COLLECT_STATS, $this->transposh->options->get_transposh_collect_stats(), __('Allow collecting usage statistics', TRANSPOSH_TEXT_DOMAIN), __('This option enables collection of statistics by transposh that will be used to improve the product. ', TRANSPOSH_TEXT_DOMAIN)); 561 561 562 562 /* WIP2 -
trunk/WordPress/plugin/transposh/wp/transposh_options.php
r664 r674 23 23 //Option to enable/disable msn translation 24 24 define('OLD_ENABLE_MSN_TRANSLATE', 'enable_msntranslate'); 25 //Option defining transposh widget file used @since 0.5.6 26 define('OLD_WIDGET_FILE', 'widget_file'); //unset!!! 25 27 //Option to store the msn API key 26 28 define('MSN_TRANSLATE_KEY', 'msn_key'); … … 61 63 //Option defining the default language 62 64 define('DEFAULT_LANG', 'default_language'); 63 //Option defining transposh widget file used @since 0.5.664 define('WIDGET_FILE', 'widget_file');65 65 //Option allowing progress bar display 66 66 define('WIDGET_PROGRESSBAR', 'widget_progressbar'); … … 84 84 /** @var array storing all our options */ 85 85 private $options = array(); 86 86 87 /** @var boolean set to true if any option was changed */ 87 88 private $changed = false; … … 184 185 185 186 /** 186 * return file name of the widget used187 * @since 0.5.6188 * @return string189 */190 function get_widget_file() {191 return $this->options[WIDGET_FILE];192 }193 194 /**195 187 * return theme 196 188 * @since 0.7.0 … … 331 323 332 324 /** 333 * Set the widget file used334 * @since 0.5.6335 * @param string $val336 */337 function set_widget_file($val) {338 $this->set_value($val, $this->options[WIDGET_FILE]);339 }340 341 /**342 325 * Set the widget theme 343 326 * @since 0.7.0 … … 388 371 } 389 372 390 function set_msn_key($val) {373 function set_msn_key($val) { 391 374 $this->set_value($val, $this->options[MSN_TRANSLATE_KEY]); 392 375 } 393 376 394 function set_google_key($val) {377 function set_google_key($val) { 395 378 $this->set_value($val, $this->options[GOOGLE_TRANSLATE_KEY]); 396 379 } -
trunk/WordPress/plugin/transposh/wp/transposh_widget.php
r667 r674 13 13 14 14 /* 15 * Provides the sidebar widget for selecting a language and switching between edit/view15 * Provides the sidebar widget instance for selecting a language and switching between edit/view 16 16 * mode. 17 17 */ 18 18 19 //Define widget fileprefix19 //Define subwidget files prefix 20 20 define('TRANSPOSH_WIDGET_PREFIX', 'tpw_'); 21 21 22 //class that reperesent the complete plugin 23 class transposh_plugin_widget { 22 /** 23 * Class for subwidgets to inherit from 24 */ 25 class transposh_base_widget { 26 27 /** 28 * Function that performs the actual subwidget rendering 29 */ 30 static function tp_widget_do() { 31 echo "you should override this function in your widget"; 32 } 33 34 /** 35 * Attempts inclusion of css needed for the subwidget 36 * @param string $file 37 * @param string $plugin_dir 38 * @param string $plugin_url 39 */ 40 static function tp_widget_css($file, $plugin_dir, $plugin_url) { 41 $basefile = substr($file, 0, -4); 42 $widget_css = TRANSPOSH_DIR_WIDGETS . '/' . $basefile . ".css"; 43 if (file_exists($plugin_dir . $widget_css)) { 44 wp_enqueue_style($basefile, $plugin_url . '/' . $widget_css, '', TRANSPOSH_PLUGIN_VER); 45 } 46 } 47 48 /** 49 * Attempts inclusion of javascript needed for the subwidget 50 * @param string $file 51 * @param string $plugin_dir 52 * @param string $plugin_url 53 */ 54 static function tp_widget_js($file, $plugin_dir, $plugin_url) { 55 $basefile = substr($file, 0, -4); 56 $widget_js = TRANSPOSH_DIR_WIDGETS . '/' . $basefile . ".js"; 57 if (file_exists($plugin_dir . $widget_js)) { 58 wp_enqueue_script('transposh_widget', $plugin_url . '/' . $widget_js, '', TRANSPOSH_PLUGIN_VER); 59 } 60 } 61 62 } 63 64 // END class 65 //class that reperesent the complete widget 66 class transposh_plugin_widget extends WP_Widget { 24 67 25 68 /** @var transposh_plugin Container class */ 26 69 private $transposh; 27 /** @var string Contains the name of the used widget file */ 28 public $base_widget_file_name; 29 30 //constructor of class, PHP4 compatible construction for backward compatibility 31 function transposh_plugin_widget(&$transposh) { 32 //Register callback for WordPress events 33 $this->transposh = &$transposh; 34 add_action('init', array(&$this, 'init_transposh'), 1); 35 add_action('widgets_init', array(&$this, 'transposh_widget_init')); 36 } 37 38 /** 39 * Intercept init calls to see if it was posted by the widget. 40 */ 41 function init_transposh() { 42 if (isset($_POST['transposh_widget_posted'])) { 43 logger("Enter", 4); 44 45 $ref = getenv('HTTP_REFERER'); 46 $lang = $_POST[LANG_PARAM]; 47 if ($lang == '') { 48 $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url); 49 } 50 if ($lang == $this->transposh->options->get_default_language() || $lang == "none") 51 $lang = ''; 52 logger("Widget referrer: $ref, lang: $lang", 4); 53 54 // first, we might need to get the original url back 55 if ($this->transposh->options->get_enable_url_translate()) { 56 $ref = transposh_utils::get_original_url($ref, $this->transposh->home_url, transposh_utils::get_language_from_url($ref, $this->transposh->home_url), array($this->transposh->database, 'fetch_original')); 57 } 58 59 //remove existing language settings. 60 $ref = transposh_utils::cleanup_url($ref, $this->transposh->home_url); 61 logger("cleaned referrer: $ref, lang: $lang", 4); 62 63 if ($lang && $this->transposh->options->get_enable_url_translate()) { 64 // and then, we might have to translate it 65 $ref = transposh_utils::translate_url($ref, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation')); 66 $ref = transposh_utils::urlencode($ref); 67 logger("translated to referrer: $ref, lang: $lang", 3); 68 } 69 $ref = transposh_utils::rewrite_url_lang_param($ref, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]); 70 71 logger("Widget redirect url: $ref", 3); 72 73 $this->transposh->tp_redirect($ref); 74 exit; 75 } 76 } 77 78 /** 79 * Register the widget. 80 */ 81 function transposh_widget_init() { 82 logger('Enter', 4); 83 if (!function_exists('register_sidebar_widget')) { 84 return; 85 } 86 87 // Register widget 88 wp_register_sidebar_widget('Transposh', __('Transposh', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'transposh_widget'), array('description' => __('Transposh language selection widget', TRANSPOSH_TEXT_DOMAIN))); 89 90 // Register widget control 91 wp_register_widget_control('Transposh', __('Transposh', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'transposh_widget_control')); 92 93 // Register callback for widget's css and js 94 add_action('wp_print_styles', array(&$this, 'add_transposh_widget_css')); 95 add_action('wp_print_scripts', array(&$this, 'add_transposh_widget_js')); 96 } 97 98 /** 99 * Loads the widget code 100 */ 101 function load_widget() { 102 // avoid dual loadings 103 if ($this->base_widget_file_name) return; 104 105 $file = $this->transposh->options->get_widget_file(); 70 71 /** @staticvar boolean Contains the fact that this is our first run */ 72 static $first_init = true; 73 74 /** @staticvar int Counts call to the widget do to generate unique IDs */ 75 static $draw_calls = ''; 76 77 function transposh_plugin_widget() { 78 // We get the transposh details from the global variable 79 $this->transposh = &$GLOBALS['my_transposh_plugin']; 80 81 // Widget control defenitions 82 $widget_ops = array('classname' => 'widget_transposh', 'description' => __('Transposh language selection widget', TRANSPOSH_TEXT_DOMAIN)); 83 $control_ops = array('width' => 200, 'height' => 300); 84 $this->WP_Widget('transposh', __('Transposh'), $widget_ops, $control_ops); 85 86 // We only need to add those actions once, makes life simpler 87 if (is_active_widget(false, false, $this->id_base) && self::$first_init) { 88 self::$first_init = false; 89 add_action('widgets_init', create_function('', 'register_widget("transposh_plugin_widget");')); 90 add_action('wp_print_styles', array(&$this, 'add_transposh_widget_css')); 91 add_action('wp_print_scripts', array(&$this, 'add_transposh_widget_js')); 92 } 93 } 94 95 /** 96 * Saves the widgets settings. (override of wp_widget) 97 */ 98 function update($new_instance, $old_instance) { 99 $instance = $old_instance; 100 logger($instance); 101 logger($new_instance); 102 $instance['title'] = strip_tags(stripslashes($new_instance['title'])); 103 $instance['widget_file'] = strip_tags(stripslashes($new_instance['widget_file'])); 104 return $instance; 105 } 106 107 /** 108 * Creates the edit form for the widget. (override of wp_widget) 109 * 110 */ 111 function form($instance) { 112 // Defaults 113 $instance = wp_parse_args((array) $instance, array('title' => 'Translation')); 114 115 // Output the options - title first 116 $title = htmlspecialchars($instance['title']); 117 118 echo '<p><label for="' . $this->get_field_name('title') . '">' . __('Title:') . ' <input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>'; 119 120 // Followed by subwisgets selection 121 $widgets = $this->get_widgets(); 122 123 echo '<p><label for="' . $this->get_field_name('widget_file') . '">' . __('Style:', TRANSPOSH_TEXT_DOMAIN) . 124 '<select id="' . $this->get_field_id('widget_file') . '" name="' . $this->get_field_name('widget_file') . '">'; 125 foreach ($widgets as $file => $widget) { 126 logger($widget, 4); 127 $selected = ($instance['widget_file'] == $file) ? ' selected="selected"' : ''; 128 echo "<option value=\"$file\"$selected>{$widget['Name']}</option>"; 129 } 130 echo '</select>' . 131 '</label></p>' 132 ; 133 } 134 135 /** 136 * Loads the subwidget class code 137 */ 138 function load_widget($file) { 106 139 $widget_src = $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file; 107 140 if ($file && file_exists($widget_src)) { … … 111 144 include_once $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file; 112 145 } 113 $this->base_widget_file_name = substr($file, 0, -4);146 return substr($file, strpos($file, '/') + 1, -4); 114 147 } 115 148 … … 117 150 * Add custom css, i.e. transposh_widget.css, flags now override widget 118 151 */ 119 function add_transposh_widget_css() { //TODO ! goway 120 $this->load_widget(); 121 122 if (function_exists('tp_widget_css')) { 123 tp_widget_css(); 124 } else { 125 $widget_css = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".css"; 126 if (file_exists($this->transposh->transposh_plugin_dir . $widget_css)) { 127 wp_enqueue_style('transposh_widget', $this->transposh->transposh_plugin_url . '/' . $widget_css, '', TRANSPOSH_PLUGIN_VER); 128 } 129 } 130 152 function add_transposh_widget_css() { 153 // first we discover all active widgets of ours, and aggregate the files 154 $settings = $this->get_settings(); 155 foreach ($settings as $key => $value) { 156 if (is_active_widget(false, $this->id_base . '-' . $key, $this->id_base)) { 157 $activewidgets[$value['widget_file']] = true; 158 } 159 } 160 161 // we than load the classes and perform the css queueing 162 foreach ($activewidgets as $key => $v) { 163 $class = $this->load_widget($key); 164 $class::tp_widget_css($key, $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url); 165 } 131 166 logger('Added transposh_widget_css', 4); 132 167 } 133 168 134 169 /** 135 * Add custom css, i.e. transposh_widget.css, flags now override widget 136 */ 137 function add_transposh_widget_js() { //TODO ! goway 138 $this->load_widget(); 139 140 if (function_exists('tp_widget_js')) { 141 tp_widget_js(); 142 } else { 143 $widget_js = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".js"; 144 if (file_exists($this->transposh->transposh_plugin_dir . $widget_js)) { 145 wp_enqueue_script('transposh_widget', $this->transposh->transposh_plugin_url . '/' . $widget_js, '', TRANSPOSH_PLUGIN_VER); 146 } 170 * Add custom js, i.e. transposh_widget.js 171 */ 172 function add_transposh_widget_js() { 173 $settings = $this->get_settings(); 174 foreach ($settings as $key => $value) { 175 if (is_active_widget(false, $this->id_base . '-' . $key, $this->id_base)) { 176 $activewidgets[$value['widget_file']] = true; 177 } 178 } 179 180 // we than load the classes and perform the css queueing 181 foreach ($activewidgets as $key => $v) { 182 $class = $this->load_widget($key); 183 $class::tp_widget_js($key, $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url); 147 184 } 148 185 logger('Added transposh_widget_js', 4); 149 186 } 150 187 151 function create_widget_args($calc_url, $clean_page_url) { 188 /** 189 * Calculate arguments needed by subwidgets 190 * @param string $clean_page_url 191 * @return array 192 */ 193 function create_widget_args($clean_page_url) { 194 // only calculate urls once even for multiple instances 195 static $widget_args; 196 if (is_array($widget_args)) return $widget_args; 152 197 $widget_args = array(); 153 198 $page_url = ''; 154 199 if (is_404()) { 155 $clean_page_url = transposh_utils::cleanup_url($this->transposh->home_url, $this->transposh->home_url,true);200 $clean_page_url = transposh_utils::cleanup_url($this->transposh->home_url, $this->transposh->home_url, true); 156 201 } 157 202 // loop on the languages … … 163 208 ($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) || 164 209 ($this->transposh->options->is_default_language($code))) { 165 if ($calc_url) { 166 if ($this->transposh->options->get_enable_url_translate() && !$this->transposh->options->is_default_language($code)) { 167 $page_url = transposh_utils::translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation')); 168 } else { 169 $page_url = $clean_page_url; 170 } 171 // clean $code in default lanaguge 172 $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); 210 // now we alway do this... maybe cache this to APC/Memcache 211 if ($this->transposh->options->get_enable_url_translate() && !$this->transposh->options->is_default_language($code)) { 212 $page_url = transposh_utils::translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation')); 213 } else { 214 $page_url = $clean_page_url; 173 215 } 216 // clean $code in default lanaguge 217 $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); 174 218 $widget_args[] = array( 175 219 'lang' => $langname, … … 188 232 * @param array $args Contains such as $before_widget, $after_widget, $before_title, $after_title, etc 189 233 */ 190 function transposh_widget($args) { 191 $this->load_widget(); 192 193 // hmmm, this should actually prepare all vars needed, include the correct widget and send the vars to that function, 194 $calc_url = false; // By default, avoid calculating the urls 195 if (function_exists('tp_widget_needs_post_url')) 196 $calc_url = tp_widget_needs_post_url(); 197 198 $clean_page = $this->transposh->get_clean_url(); 199 200 logger("WIDGET: clean page url: $clean_page", 4); 201 202 $widget_args = $this->create_widget_args($calc_url, $clean_page); 203 // at this point the widget args are ready 204 205 logger('Enter widget', 4); 206 234 function widget($args, $instance) { 207 235 // extract args given by wordpress 208 236 extract($args); 209 237 logger($args, 4); 210 238 239 // we load the class needed and get its base name for later 240 $class = $this->load_widget($instance['widget_file']); 241 242 $clean_page = $this->transposh->get_clean_url(); 243 244 logger("WIDGET: clean page url: $clean_page", 4); 245 246 $widget_args = $this->create_widget_args($clean_page); 247 // at this point the widget args are ready 248 249 logger('Enter widget', 4); 250 211 251 // widget default title 212 echo $before_widget . $before_title . __('Translation', TRANSPOSH_TEXT_DOMAIN) . $after_title; 213 214 // the widget is inside a form used for posting a language change or edit request 215 echo '<form id="tp_form" action="' . $clean_page . '" method="post">'; 252 //echo $before_widget . $before_title . __('Translation', TRANSPOSH_TEXT_DOMAIN) . $after_title; - hmm? po/mo? 253 echo $before_widget; 254 if ($instance['title']) { 255 echo $before_title . __($instance['title'], TRANSPOSH_TEXT_DOMAIN) . $after_title; 256 } 216 257 217 258 // actually run the external widget code 218 tp_widget_do($widget_args);259 $class::tp_widget_do($widget_args); 219 260 220 261 //at least one language showing - add the edit box if applicable … … 223 264 if ($this->transposh->options->get_widget_allow_set_default_language()) { 224 265 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))) { 225 echo '<a id="' . 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/>';266 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/>'; 226 267 } 227 268 } 228 269 // add the edit checkbox only for translators for languages marked as editable 270 $ref = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->target_language, !$this->transposh->edit_mode); 229 271 if ($this->transposh->is_editing_permitted()) { 230 272 echo '<input type="checkbox" name="' . EDIT_PARAM . '" value="1" ' . 231 ($this->transposh->edit_mode ? 'checked="checked"' : '') . 232 ' onclick="this.form.submit();"/> Edit Translation'; 233 } 234 235 echo '<input type="hidden" name="transposh_widget_posted" value="1"/>'; 273 ($this->transposh->edit_mode ? 'checked="checked" ' : '') . 274 ' onclick="document.location.href=\'' . $ref . '\';"/> Edit Translation'; 275 } 236 276 } else { 237 277 //no languages configured - error message 238 278 echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>'; 239 279 } 240 241 echo "</form>";242 280 243 281 // Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget … … 278 316 } 279 317 280 echo '<div id="' . SPAN_PREFIX . 'credit ">';318 echo '<div id="' . SPAN_PREFIX . 'credit' . self::$draw_calls . '">'; 281 319 if (!$this->transposh->options->get_widget_remove_logo()) { 282 320 echo 'by <a href="http://tran' . 'sposh.org/' . $extralang . '"><img height="16" width="16" src="' . … … 285 323 echo '</div>'; 286 324 echo $after_widget; 287 } 288 289 function transposh_widget_post($save = true) { 290 logger($_POST); 291 logger('handled widget post'); 292 $this->transposh->options->set_widget_file($_POST[WIDGET_FILE]); 293 $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]); 294 $this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]); 295 $this->transposh->options->set_widget_remove_logo($_POST[WIDGET_REMOVE_LOGO_FOR_AD]); 296 $this->transposh->options->set_widget_theme($_POST[WIDGET_THEME]); 297 if ($save) $this->transposh->options->update_options(); 298 // Avoid coming here twice... 299 unset($_POST['transposh-submit']); 325 // increase the number of calls for unique IDs 326 self::$draw_calls++; 300 327 } 301 328 … … 353 380 } 354 381 355 /**356 * This is the widget control, allowing the selection of presentation type.357 */358 function transposh_widget_control() {359 if (isset($_POST['transposh-submit'])) $this->transposh_widget_post();360 $themes = array('base', 'black-tie', 'blitzer', 'cupertino', 'dark-hive', 'dot-luv', 'eggplant', 'excite-bike', 'flick',361 'hot-sneaks', 'humanity', 'le-frog', 'mint-choc', 'overcast', 'pepper-grinder', 'redmond', 'smoothness', 'south-street',362 'start', 'sunny', 'swanky-purse', 'trontastic', 'ui-darkness', 'ui-lightness', 'vader');363 364 $widgets = $this->get_widgets();365 366 echo '<p><label for="' . WIDGET_FILE . '">' . __('Style:', TRANSPOSH_TEXT_DOMAIN) . '<br/>' .367 '<select id="transposh-style" name="' . WIDGET_FILE . '">';368 foreach ($widgets as $file => $widget) {369 logger($widget, 4);370 $selected = ($this->transposh->options->get_widget_file() == $file) ? ' selected="selected"' : '';371 echo "<option value=\"$file\"$selected>{$widget['Name']}</option>";372 }373 echo '</select>' .374 '</label></p>' .375 '<p><label for="transposh-progress">' . __('Effects:', TRANSPOSH_TEXT_DOMAIN) . '</label><br/>' .376 '<input type="checkbox" id="' . WIDGET_PROGRESSBAR . '" name="' . WIDGET_PROGRESSBAR . '"' . ($this->transposh->options->get_widget_progressbar() ? ' checked="checked"' : '') . '/>' .377 '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="' . esc_attr__('Show progress bar when a client triggers automatic translation', TRANSPOSH_TEXT_DOMAIN) . '">' . __('Show progress bar', TRANSPOSH_TEXT_DOMAIN) . '</span><br/>' .378 '<input type="checkbox" id="' . WIDGET_ALLOW_SET_DEFLANG . '" name="' . WIDGET_ALLOW_SET_DEFLANG . '"' . ($this->transposh->options->get_widget_allow_set_default_language() ? ' checked="checked"' : '') . '/>' .379 '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="' . esc_attr__('Widget will allow setting this language as user default', TRANSPOSH_TEXT_DOMAIN) . '">' . __('Allow user to set current language as default', TRANSPOSH_TEXT_DOMAIN) . '</span><br/>' .380 '<input type="checkbox" id="' . WIDGET_REMOVE_LOGO_FOR_AD . '" name="' . WIDGET_REMOVE_LOGO_FOR_AD . '"' . ($this->transposh->options->get_widget_remove_logo() ? ' checked="checked"' : '') . '/>' .381 '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="' . esc_attr__('Transposh logo will not appear on widget', TRANSPOSH_TEXT_DOMAIN) . '">' . __('Remove transposh logo (see <a href="http://transposh.org/logoterms">terms</a>)', TRANSPOSH_TEXT_DOMAIN) . '</span><br/>' .382 '</p>';383 384 echo '<p><label for="' . WIDGET_THEME . '">' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . '<br/>' .385 '<select id="transposh-style" name="' . WIDGET_THEME . '">';386 foreach ($themes as $theme) {387 $selected = ($this->transposh->options->get_widget_theme() == $theme) ? ' selected="selected"' : '';388 echo "<option value=\"$theme\"$selected>{$theme}</option>";389 }390 echo '</select>' .391 '</label></p>' .392 '<input type="hidden" name="transposh-submit" id="transposh-submit" value="1"/>';393 }394 395 382 } 396 383 … … 399 386 * @param array $args Not needed 400 387 */ 401 function transposh_widget($args = array() ) {402 $GLOBALS['my_transposh_plugin']->widget->transposh_widget($args );388 function transposh_widget($args = array(), $instance= array('title' => 'Translation')) { 389 $GLOBALS['my_transposh_plugin']->widget->transposh_widget($args, $instance); 403 390 } 404 391
Note: See TracChangeset
for help on using the changeset viewer.
