Changeset 488
- Timestamp:
- 08/07/2010 02:45:58 AM (18 months ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 15 edited
-
core/constants.php (modified) (1 diff)
-
core/parser.php (modified) (2 diffs)
-
core/utils.php (modified) (1 diff)
-
transposh.php (modified) (12 diffs)
-
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_3rdparty.php (modified) (4 diffs)
-
wp/transposh_admin.php (modified) (3 diffs)
-
wp/transposh_ajax.php (modified) (1 diff)
-
wp/transposh_db.php (modified) (2 diffs)
-
wp/transposh_options.php (modified) (3 diffs)
-
wp/transposh_postpublish.php (modified) (3 diffs)
-
wp/transposh_widget.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/constants.php
r458 r488 32 32 define('ONLY_THISLANGUAGE_CLASS', 'only_thislanguage'); 33 33 34 /** 35 * Holds our arrays staticly to reduce chance of namespace collision 36 */ 37 class transposh_consts { 38 34 39 //Supported languages, new languages can be added here 35 40 //the array directs from language code to - English Name, Native name, flag 36 $languages = array( 37 'en' => 'English,English,us', 38 'af' => 'Afrikaans,Afrikaans,za', 39 'sq' => 'Albanian,Shqip,al', 40 'ar' => 'Arabic,Ø§ÙØ¹Ø±ØšÙØ©,sa', 41 'hy' => 'Armenian,ÕÕ¡ÕµÕ¥ÖÕ¥Õ¶,am', 42 'az' => 'Azerbaijani,azÉrbaycan dili,az', 43 'eu' => 'Basque,euskara,basque', 44 'be' => 'Belarusian,ÐелаÑÑÑкаÑ,by', 45 'bg' => 'Bulgarian,ÐÑлгаÑÑкО,bg', 46 'ca' => 'Catalan,Català ,catalonia', 47 'zh' => 'Chinese (Simplified),äžæ(ç®äœ),cn', 48 'zh-tw' => 'Chinese (Traditional),äžæ(挢å),tw', 49 'hr' => 'Croatian,Hrvatski,hr', 50 'cs' => 'Czech,ÄeÅ¡tina,cz', 51 'da' => 'Danish,dansk,dk', 52 'nl' => 'Dutch,Nederlands,nl', 53 'et' => 'Estonian,Eesti keel,ee', 54 'fi' => 'Finnish,Suomi,fi', 55 'fr' => 'French,Français,fr', 56 'gl' => 'Galician,Galego,galicia', 57 'ka' => 'Georgian,á¥áá áá£áá,ge', 58 'de' => 'German,Deutsch,de', 59 'el' => 'Greek,ÎλληΜικά,gr', 60 'ht' => 'Haitian,Kreyòl ayisyen,ht', 61 'he' => 'Hebrew,×¢×ך×ת,il', 62 'hi' => 'Hindi,à€¹à€¿à€šà¥à€Šà¥; à€¹à€¿à€à€Šà¥,in', 63 'hu' => 'Hungarian,magyar,hu', 64 'is' => 'Icelandic,Ãslenska,is', 65 'id' => 'Indonesian,Bahasa Indonesia,id', 66 'ga' => 'Irish,Gaeilge,ie', 67 'it' => 'Italian,Italiano,it', 68 'ja' => 'Japanese,æ¥æ¬èª,jp', 69 'ko' => 'Korean,ì°ëЬë§,kr', 70 'lv' => 'Latvian,latvieÅ¡u valoda,lv', 71 'lt' => 'Lithuanian,lietuvių kalba,lt', 72 'mk' => 'Macedonian,ЌакеЎПМÑкО ÑазОк,mk', 73 'ms' => 'Malay,bahasa Melayu,my', 74 'mt' => 'Maltese,Malti,mt', 75 'no' => 'Norwegian,Norsk,no', 76 'fa' => 'Persian,ÙØ§Ø±Ø³Û,ir', 77 'pl' => 'Polish,Polski,pl', 78 'pt' => 'Portuguese,Português,pt', 79 'ro' => 'Romanian,RomânÄ,ro', 80 'ru' => 'Russian,Ð ÑÑÑкОй,ru', 81 'sr' => 'Serbian,ÑÑпÑкО ÑезОк,rs', 82 'sk' => 'Slovak,slovenÄina,sk', 83 'sl' => 'Slovene,slovenÅ¡Äina,sl', //slovenian 84 'es' => 'Spanish,Español,es', 85 'sw' => 'Swahili,Kiswahili,ke', 86 'sv' => 'Swedish,svenska,se', 87 'tl' => 'Tagalog,Tagalog,ph', // fhilipino 88 'th' => 'Thai,àž àž²àž©àž²à¹àžàž¢,th', 89 'tr' => 'Turkish,TÃŒrkçe,tr', 90 'uk' => 'Ukrainian,УкÑаÑМÑÑка,ua', 91 'ur' => 'Urdu,اردÙ,pk', 92 'vi' => 'Vietnamese,Tiếng Viá»t,vn', 93 'cy' => 'Welsh,Cymraeg,wales', 94 'yi' => 'Yiddish,××ÖŽ××ש,europeanunion' 95 ); 96 41 public static $languages = array( 42 'en' => 'English,English,us', 43 'af' => 'Afrikaans,Afrikaans,za', 44 'sq' => 'Albanian,Shqip,al', 45 'ar' => 'Arabic,Ø§ÙØ¹Ø±ØšÙØ©,sa', 46 'hy' => 'Armenian,ÕÕ¡ÕµÕ¥ÖÕ¥Õ¶,am', 47 'az' => 'Azerbaijani,azÉrbaycan dili,az', 48 'eu' => 'Basque,euskara,basque', 49 'be' => 'Belarusian,ÐелаÑÑÑкаÑ,by', 50 'bg' => 'Bulgarian,ÐÑлгаÑÑкО,bg', 51 'ca' => 'Catalan,Català ,catalonia', 52 'zh' => 'Chinese (Simplified),äžæ(ç®äœ),cn', 53 'zh-tw' => 'Chinese (Traditional),äžæ(挢å),tw', 54 'hr' => 'Croatian,Hrvatski,hr', 55 'cs' => 'Czech,ÄeÅ¡tina,cz', 56 'da' => 'Danish,dansk,dk', 57 'nl' => 'Dutch,Nederlands,nl', 58 'et' => 'Estonian,Eesti keel,ee', 59 'fi' => 'Finnish,Suomi,fi', 60 'fr' => 'French,Français,fr', 61 'gl' => 'Galician,Galego,galicia', 62 'ka' => 'Georgian,á¥áá áá£áá,ge', 63 'de' => 'German,Deutsch,de', 64 'el' => 'Greek,ÎλληΜικά,gr', 65 'ht' => 'Haitian,Kreyòl ayisyen,ht', 66 'he' => 'Hebrew,×¢×ך×ת,il', 67 'hi' => 'Hindi,à€¹à€¿à€šà¥à€Šà¥; à€¹à€¿à€à€Šà¥,in', 68 'hu' => 'Hungarian,magyar,hu', 69 'is' => 'Icelandic,Ãslenska,is', 70 'id' => 'Indonesian,Bahasa Indonesia,id', 71 'ga' => 'Irish,Gaeilge,ie', 72 'it' => 'Italian,Italiano,it', 73 'ja' => 'Japanese,æ¥æ¬èª,jp', 74 'ko' => 'Korean,ì°ëЬë§,kr', 75 'lv' => 'Latvian,latvieÅ¡u valoda,lv', 76 'lt' => 'Lithuanian,lietuvių kalba,lt', 77 'mk' => 'Macedonian,ЌакеЎПМÑкО ÑазОк,mk', 78 'ms' => 'Malay,bahasa Melayu,my', 79 'mt' => 'Maltese,Malti,mt', 80 'no' => 'Norwegian,Norsk,no', 81 'fa' => 'Persian,ÙØ§Ø±Ø³Û,ir', 82 'pl' => 'Polish,Polski,pl', 83 'pt' => 'Portuguese,Português,pt', 84 'ro' => 'Romanian,RomânÄ,ro', 85 'ru' => 'Russian,Ð ÑÑÑкОй,ru', 86 'sr' => 'Serbian,ÑÑпÑкО ÑезОк,rs', 87 'sk' => 'Slovak,slovenÄina,sk', 88 'sl' => 'Slovene,slovenÅ¡Äina,sl', //slovenian 89 'es' => 'Spanish,Español,es', 90 'sw' => 'Swahili,Kiswahili,ke', 91 'sv' => 'Swedish,svenska,se', 92 'tl' => 'Tagalog,Tagalog,ph', // fhilipino 93 'th' => 'Thai,àž àž²àž©àž²à¹àžàž¢,th', 94 'tr' => 'Turkish,TÃŒrkçe,tr', 95 'uk' => 'Ukrainian,УкÑаÑМÑÑка,ua', 96 'ur' => 'Urdu,اردÙ,pk', 97 'vi' => 'Vietnamese,Tiếng Viá»t,vn', 98 'cy' => 'Welsh,Cymraeg,wales', 99 'yi' => 'Yiddish,××ÖŽ××ש,europeanunion' 100 ); 97 101 //Language which are read from right to left (rtl) 98 $rtl_languages = array('ar', 'he', 'fa', 'ur', 'yi'); 99 102 public static $rtl_languages = array('ar', 'he', 'fa', 'ur', 'yi'); 100 103 //Google supported languages 101 104 //(got using - var langs =''; jQuery.each(google.language.Languages,function(){if (google.language.isTranslatable(this)) {langs += this +'|'}}); console.log(langs); - fixed for our codes) 102 105 //@updated 2010-Jul-01 (hy,az,eu,ka,ur) 103 106 //$google_languages = array('en', 'af', 'sq', 'ar', 'hy', 'az', 'eu', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'ur', 'vi', 'cy', 'yi'); 104 $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi');105 $google_proxied_languages = array('hy','az','eu','ka','ur');107 public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi'); 108 public static $google_proxied_languages = array('hy', 'az', 'eu', 'ka', 'ur'); 106 109 //Bing supported languages 107 110 //(got this using Microsoft.Translator.GetLanguages() - fixed to match our codes) 108 111 //@updated 2010-Jun-30 109 $bing_languages = array('en', 'ar', 'bg', 'zh', 'zh-tw', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'de', 'el', 'ht', 'he', 'hu', 'it', 'ja', 'ko', 'lv', 'lt', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'es', 'sv', 'th', 'tr'); 112 public static $bing_languages = array('en', 'ar', 'bg', 'zh', 'zh-tw', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'de', 'el', 'ht', 'he', 'hu', 'it', 'ja', 'ko', 'lv', 'lt', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'es', 'sv', 'th', 'tr'); 113 114 115 } 110 116 111 117 //Define the new capability that will be assigned to roles - translator -
trunk/WordPress/plugin/transposh/core/parser.php
r483 r488 484 484 // Use base64 encoding to make that when the page is translated (i.e. update_translation) we 485 485 // get back exactlly the same string without having the client decode/encode it in anyway. 486 $span = '<span class ="' . SPAN_PREFIX . '" id="' . SPAN_PREFIX . $this->segment_id . '" data-token="' . base64_url_encode($original_text) . '" data-source="'.$source.'"';486 $span = '<span class ="' . SPAN_PREFIX . '" id="' . SPAN_PREFIX . $this->segment_id . '" data-token="' . transposh_utils::base64_url_encode($original_text) . '" data-source="'.$source.'"'; 487 487 // those are needed for on the fly image creation / hidden elements translations 488 488 if ($this->is_edit_mode || $for_hidden_element) { … … 673 673 if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null)) && $ep->inbody) { 674 674 // prevent duplicate translation (title = text) 675 if (strpos($e->innertext, base64_url_encode($ep->phrase)) === false) {675 if (strpos($e->innertext, transposh_utils::base64_url_encode($ep->phrase)) === false) { 676 676 //no need to translate span the same hidden phrase more than once 677 677 if (!in_array($ep->phrase, $hidden_phrases)) { -
trunk/WordPress/plugin/transposh/core/utils.php
r472 r488 27 27 28 28 /** 29 * Remove from url any language (or editing) params that were added for our use. 30 * Return the scrubed url 29 * This is a static class to reduce chance of namespace collisions with other plugins 31 30 */ 32 function cleanup_url($url, $home_url, $remove_host = false) { 33 34 $parsedurl = @parse_url($url); 35 //cleanup previous lang & edit parameter from url 36 37 if (isset($parsedurl['query'])) { 38 $params = explode('&', $parsedurl['query']); 39 foreach ($params as $key => $param) { 40 if (stripos($param, LANG_PARAM) === 0) unset($params[$key]); 41 if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]); 42 } 43 } 44 // clean the query 45 unset($parsedurl['query']); 46 if (isset($params) && $params) { 47 $parsedurl['query'] = implode('&', $params); 48 } 49 50 //cleanup lang identifier in permalinks 51 //remove the language from the url permalink (if in start of path, and is a defined language) 52 $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/"); 53 logger("home: $home_path " . $parsedurl['path'], 5); 54 if ($home_path && strpos($parsedurl['path'], $home_path) === 0) { 55 logger("homein!: $home_path", 5); 56 $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path)); 57 $gluebackhome = true; 58 } 59 60 if (strlen($parsedurl['path']) > 2) { 61 $secondslashpos = strpos($parsedurl['path'], "/", 1); 62 if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']); 63 $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1); 64 if (isset($GLOBALS['languages'][$prevlang])) { 65 logger("prevlang: " . $prevlang, 4); 66 $parsedurl['path'] = substr($parsedurl['path'], $secondslashpos); 67 } 68 } 69 if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path']; 70 if ($remove_host) { 71 unset($parsedurl['scheme']); 72 unset($parsedurl['host']); 73 } 74 $url = glue_url($parsedurl); 75 if (!$url) return '/'; 76 return $url; 77 } 78 79 /** 80 * Update the given url to include language params. 81 * @param string $url - Original URL to rewrite 82 * @param string $lang - Target language code 83 * @param boolean $is_edit - should url indicate editing 84 * @param boolean $use_params_only - only use paramaters and avoid permalinks 85 */ 31 class transposh_utils { 32 33 /** 34 * Remove from url any language (or editing) params that were added for our use. 35 * Return the scrubed url 36 */ 37 public static function cleanup_url($url, $home_url, $remove_host = false) { 38 39 $parsedurl = @parse_url($url); 40 //cleanup previous lang & edit parameter from url 41 42 if (isset($parsedurl['query'])) { 43 $params = explode('&', $parsedurl['query']); 44 foreach ($params as $key => $param) { 45 if (stripos($param, LANG_PARAM) === 0) unset($params[$key]); 46 if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]); 47 } 48 } 49 // clean the query 50 unset($parsedurl['query']); 51 if (isset($params) && $params) { 52 $parsedurl['query'] = implode('&', $params); 53 } 54 55 //cleanup lang identifier in permalinks 56 //remove the language from the url permalink (if in start of path, and is a defined language) 57 $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/"); 58 logger("home: $home_path " . $parsedurl['path'], 5); 59 if ($home_path && strpos($parsedurl['path'], $home_path) === 0) { 60 logger("homein!: $home_path", 5); 61 $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path)); 62 $gluebackhome = true; 63 } 64 65 if (strlen($parsedurl['path']) > 2) { 66 $secondslashpos = strpos($parsedurl['path'], "/", 1); 67 if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']); 68 $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1); 69 if (isset(transposh_consts::$languages[$prevlang])) { 70 logger("prevlang: " . $prevlang, 4); 71 $parsedurl['path'] = substr($parsedurl['path'], $secondslashpos); 72 } 73 } 74 if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path']; 75 if ($remove_host) { 76 unset($parsedurl['scheme']); 77 unset($parsedurl['host']); 78 } 79 $url = transposh_utils::glue_url($parsedurl); 80 if (!$url) return '/'; 81 return $url; 82 } 83 84 /** 85 * Update the given url to include language params. 86 * @param string $url - Original URL to rewrite 87 * @param string $lang - Target language code 88 * @param boolean $is_edit - should url indicate editing 89 * @param boolean $use_params_only - only use paramaters and avoid permalinks 90 */ 86 91 // Should send a transposh interface to here TODO - enable permalinks rewrite 87 92 // TODO - Should be able to not write default language for url (done with empty lang?) 88 function rewrite_url_lang_param($url, $home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only=FALSE) { 89 logger("rewrite old url: $url, permalinks: $enable_permalinks_rewrite, lang: $lang, is_edit: $is_edit, home_url: $home_url", 5); 90 91 $newurl = str_replace('&', '&', $url); 92 $newurl = html_entity_decode($newurl, ENT_NOQUOTES); 93 $parsedurl = parse_url($newurl); 94 95 // if we are dealing with some other url, we won't touch it! 96 if (isset($parsedurl['host']) && !($parsedurl['host'] == parse_url($home_url, PHP_URL_HOST))) { 93 public static function rewrite_url_lang_param($url, $home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only=FALSE) { 94 logger("rewrite old url: $url, permalinks: $enable_permalinks_rewrite, lang: $lang, is_edit: $is_edit, home_url: $home_url", 5); 95 96 $newurl = str_replace('&', '&', $url); 97 $newurl = html_entity_decode($newurl, ENT_NOQUOTES); 98 $parsedurl = parse_url($newurl); 99 100 // if we are dealing with some other url, we won't touch it! 101 if (isset($parsedurl['host']) && !($parsedurl['host'] == parse_url($home_url, PHP_URL_HOST))) { 102 return $url; 103 } 104 105 //remove prev lang and edit params - from query string - reserve other params 106 if (isset($parsedurl['query'])) { 107 $params = explode('&', $parsedurl['query']); 108 foreach ($params as $key => $param) { 109 if (stripos($param, LANG_PARAM) === 0) unset($params[$key]); 110 if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]); 111 } 112 } 113 // clean the query 114 unset($parsedurl['query']); 115 116 // remove the language from the url permalink (if in start of path, and is a defined language) 117 $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/"); 118 logger("home: $home_path " . $parsedurl['path'], 5); 119 if ($home_path && strpos($parsedurl['path'], $home_path) === 0) { 120 logger("homein!: $home_path", 5); 121 $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path)); 122 $gluebackhome = true; 123 } 124 if (strlen($parsedurl['path']) > 2) { 125 $secondslashpos = strpos($parsedurl['path'], "/", 1); 126 if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']); 127 $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1); 128 if (isset(transposh_consts::$languages[$prevlang])) { 129 logger("prevlang: " . $prevlang, 4); 130 $parsedurl['path'] = substr($parsedurl['path'], $secondslashpos); 131 } 132 } 133 134 // override the use only params - admin configured system to not touch permalinks 135 if (!$enable_permalinks_rewrite) { 136 $use_params_only = TRUE; 137 } 138 139 //$params =""; 140 if ($is_edit) { 141 $params[edit] = EDIT_PARAM . '=1'; 142 } 143 144 if ($use_params_only && $lang) { 145 $params['lang'] = LANG_PARAM . "=$lang"; 146 } else { 147 if ($lang) { 148 if (!$parsedurl['path']) $parsedurl['path'] = "/"; 149 $parsedurl['path'] = "/" . $lang . $parsedurl['path']; 150 } 151 } 152 if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path']; 153 154 // insert params to url 155 if (isset($params) && $params) { 156 $parsedurl['query'] = implode('&', $params); 157 logger("params: $params", 4); 158 } 159 160 // more cleanups 161 //$url = preg_replace("/&$/", "", $url); 162 //$url = preg_replace("/\?$/", "", $url); 163 // $url = htmlentities($url, ENT_NOQUOTES); 164 $url = transposh_utils::glue_url($parsedurl); 165 logger("new url: $url", 5); 97 166 return $url; 98 167 } 99 168 100 //remove prev lang and edit params - from query string - reserve other params 101 if (isset($parsedurl['query'])) { 102 $params = explode('&', $parsedurl['query']); 103 foreach ($params as $key => $param) { 104 if (stripos($param, LANG_PARAM) === 0) unset($params[$key]); 105 if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]); 106 } 107 } 108 // clean the query 109 unset($parsedurl['query']); 110 111 // remove the language from the url permalink (if in start of path, and is a defined language) 112 $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/"); 113 logger("home: $home_path " . $parsedurl['path'], 5); 114 if ($home_path && strpos($parsedurl['path'], $home_path) === 0) { 115 logger("homein!: $home_path", 5); 116 $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path)); 117 $gluebackhome = true; 118 } 119 if (strlen($parsedurl['path']) > 2) { 120 $secondslashpos = strpos($parsedurl['path'], "/", 1); 121 if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']); 122 $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1); 123 if (isset($GLOBALS['languages'][$prevlang])) { 124 logger("prevlang: " . $prevlang, 4); 125 $parsedurl['path'] = substr($parsedurl['path'], $secondslashpos); 126 } 127 } 128 129 // override the use only params - admin configured system to not touch permalinks 130 if (!$enable_permalinks_rewrite) { 131 $use_params_only = TRUE; 132 } 133 134 //$params =""; 135 if ($is_edit) { 136 $params[edit] = EDIT_PARAM . '=1'; 137 } 138 139 if ($use_params_only && $lang) { 140 $params['lang'] = LANG_PARAM . "=$lang"; 141 } else { 142 if ($lang) { 143 if (!$parsedurl['path']) $parsedurl['path'] = "/"; 144 $parsedurl['path'] = "/" . $lang . $parsedurl['path']; 145 } 146 } 147 if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path']; 148 149 // insert params to url 150 if (isset($params) && $params) { 151 $parsedurl['query'] = implode('&', $params); 152 logger("params: $params", 4); 153 } 154 155 // more cleanups 156 //$url = preg_replace("/&$/", "", $url); 157 //$url = preg_replace("/\?$/", "", $url); 158 // $url = htmlentities($url, ENT_NOQUOTES); 159 $url = glue_url($parsedurl); 160 logger("new url: $url", 5); 161 return $url; 162 } 163 164 function get_language_from_url($url, $home_url) { 165 166 $parsedurl = @parse_url($url); 167 168 //option 1, lanaguage is in the query ?lang=xx 169 if (isset($parsedurl['query'])) { 170 $params = explode('&', $parsedurl['query']); 171 foreach ($params as $key => $param) { 172 if (stripos($param, LANG_PARAM) === 0) { 173 $langa = explode("=", $params[$key]); 174 return ($langa[1]); 175 } 176 } 177 } 178 179 // option 2, language is in permalink 180 // cleanup lang identifier in permalinks 181 // remove the language from the url permalink (if in start of path, and is a defined language) 182 $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/"); 169 public static function get_language_from_url($url, $home_url) { 170 171 $parsedurl = @parse_url($url); 172 173 //option 1, lanaguage is in the query ?lang=xx 174 if (isset($parsedurl['query'])) { 175 $params = explode('&', $parsedurl['query']); 176 foreach ($params as $key => $param) { 177 if (stripos($param, LANG_PARAM) === 0) { 178 $langa = explode("=", $params[$key]); 179 return ($langa[1]); 180 } 181 } 182 } 183 184 // option 2, language is in permalink 185 // cleanup lang identifier in permalinks 186 // remove the language from the url permalink (if in start of path, and is a defined language) 187 $home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/"); 183 188 // logger ("home: $home_path ".$parsedurl['path'],5); 184 if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {189 if ($home_path && strpos($parsedurl['path'], $home_path) === 0) { 185 190 // logger ("homein!: $home_path",5); 186 $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));191 $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path)); 187 192 // $gluebackhome = true; 188 } 189 190 if (strlen($parsedurl['path']) > 2) { 191 $secondslashpos = strpos($parsedurl['path'], "/", 1); 192 if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']); 193 $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1); 194 if (isset($GLOBALS['languages'][$prevlang])) { 195 //logger ("prevlang: ".$prevlang,4); 196 //$parsedurl['path'] = substr($parsedurl['path'],$secondslashpos); 197 return $prevlang; 198 } 199 } 200 return false; 201 } 202 203 /** 204 * glue a parse_url array back to a url 205 * @param array $parsed url_parse style array 206 * @return combined url 207 */ 208 function glue_url($parsed) { 209 if (!is_array($parsed)) { 193 } 194 195 if (strlen($parsedurl['path']) > 2) { 196 $secondslashpos = strpos($parsedurl['path'], "/", 1); 197 if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']); 198 $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1); 199 if (isset(transposh_consts::$languages[$prevlang])) { 200 //logger ("prevlang: ".$prevlang,4); 201 //$parsedurl['path'] = substr($parsedurl['path'],$secondslashpos); 202 return $prevlang; 203 } 204 } 210 205 return false; 211 206 } 212 207 213 $uri = isset($parsed['scheme']) ? $parsed['scheme'] . ':' . ((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : ''; 214 $uri .= isset($parsed['user']) ? $parsed['user'] . (isset($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : ''; 215 $uri .= isset($parsed['host']) ? $parsed['host'] : ''; 216 $uri .= isset($parsed['port']) ? ':' . $parsed['port'] : ''; 217 218 if (isset($parsed['path'])) { 219 $uri .= ( substr($parsed['path'], 0, 1) == '/') ? 220 $parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']); 221 } 222 223 $uri .= isset($parsed['query']) ? '?' . $parsed['query'] : ''; 224 $uri .= isset($parsed['fragment']) ? '#' . $parsed['fragment'] : ''; 225 226 return $uri; 227 } 228 229 /** 230 * Encode a string as base 64 while avoiding characters which should be avoided 231 * in uri, e.g. + is interpeted as a space. 232 */ 233 function base64_url_encode($input) { 234 return strtr(base64_encode($input), '+/=', '-_,'); 235 } 236 237 /** 238 * Decode a string previously decoded with base64_url_encode 239 */ 240 function base64_url_decode($input) { 241 return base64_decode(strtr($input, '-_,', '+/=')); 242 } 243 244 /** 245 * Function to translate a given url permalink to a target language 246 * TODO - check params 247 * @param string $href 248 * @param string $home_url 249 * @param string $target_language 250 * @param function $fetch_translation_func 251 * @return string translated url permalink 252 */ 253 function translate_url($href, $home_url, $target_language, $fetch_translation_func) { 254 // todo - check query part... sanitize 255 if (strpos($href, '?') !== false) { 256 list ($href, $querypart) = explode('?', $href); 257 $querypart = '?' . $querypart; 258 } 259 $href = substr($href, strlen($home_url)); 260 $parts = explode('/', $href); 261 foreach ($parts as $part) { 262 if (!$part) continue; 263 list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array($part, $target_language)); 264 if ($translated_text) 265 $url .= '/' . str_replace(' ', '-', $translated_text); 266 else { 267 // now the same attempt with '-' replaced to ' ' 268 list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language)); 269 //logger ($part. ' '.str_replace('-', ' ', $part).' '.$translated_text); 208 /** 209 * glue a parse_url array back to a url 210 * @param array $parsed url_parse style array 211 * @return combined url 212 */ 213 public static function glue_url($parsed) { 214 if (!is_array($parsed)) { 215 return false; 216 } 217 218 $uri = isset($parsed['scheme']) ? $parsed['scheme'] . ':' . ((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : ''; 219 $uri .= isset($parsed['user']) ? $parsed['user'] . (isset($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : ''; 220 $uri .= isset($parsed['host']) ? $parsed['host'] : ''; 221 $uri .= isset($parsed['port']) ? ':' . $parsed['port'] : ''; 222 223 if (isset($parsed['path'])) { 224 $uri .= ( substr($parsed['path'], 0, 1) == '/') ? 225 $parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']); 226 } 227 228 $uri .= isset($parsed['query']) ? '?' . $parsed['query'] : ''; 229 $uri .= isset($parsed['fragment']) ? '#' . $parsed['fragment'] : ''; 230 231 return $uri; 232 } 233 234 /** 235 * Encode a string as base 64 while avoiding characters which should be avoided 236 * in uri, e.g. + is interpeted as a space. 237 */ 238 public static function base64_url_encode($input) { 239 return strtr(base64_encode($input), '+/=', '-_,'); 240 } 241 242 /** 243 * Decode a string previously decoded with base64_url_encode 244 */ 245 public static function base64_url_decode($input) { 246 return base64_decode(strtr($input, '-_,', '+/=')); 247 } 248 249 /** 250 * Function to translate a given url permalink to a target language 251 * TODO - check params 252 * @param string $href 253 * @param string $home_url 254 * @param string $target_language 255 * @param function $fetch_translation_func 256 * @return string translated url permalink 257 */ 258 public static function translate_url($href, $home_url, $target_language, $fetch_translation_func) { 259 // todo - check query part... sanitize 260 if (strpos($href, '?') !== false) { 261 list ($href, $querypart) = explode('?', $href); 262 $querypart = '?' . $querypart; 263 } 264 $href = substr($href, strlen($home_url)); 265 $parts = explode('/', $href); 266 foreach ($parts as $part) { 267 if (!$part) continue; 268 list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array($part, $target_language)); 270 269 if ($translated_text) 271 270 $url .= '/' . str_replace(' ', '-', $translated_text); 272 else $url .= '/' . $part; 273 } 274 } 275 if (substr($href, strlen($href) - 1) == '/') $url.='/'; 276 return $home_url . $url . $querypart; 277 } 278 279 /** 280 * From a given translated url, tries to get the original URL 281 * @param string $href 282 * @param string $home_url 283 * @param string $target_language 284 * @param function $fetch_translation_func 285 * @return string 286 */ 287 function get_original_url($href, $home_url, $target_language, $fetch_translation_func) { 288 $href = substr($href, strlen($home_url)); 289 $url = urldecode($href); 290 $url = (($pos = strpos($url, '?')) ? substr($url, 0, $pos) : $url); 291 $parts = explode('/', $url); 292 foreach ($parts as $part) { 293 if (!$part) continue; 294 // don't attempt for lang or numbers 295 if ($part == $target_language || is_numeric($part)) { 296 $url2 .= '/' . $part; 297 continue; 298 } 299 300 // we attempt to find an original text 301 $original_text = call_user_func_array($fetch_translation_func, array($part, $target_language)); 302 if (!$original_text) { 303 // if the part has dashes we attempt to resolve original without them 304 if ($part != str_replace('-', ' ', $part)) { 305 $original_text = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language)); 306 } 307 } 308 // we'll add it if we have it 309 if ($original_text) 310 $url2 .= '/' . strtolower(str_replace(' ', '-', $original_text)); 311 else $url2 .= '/' . $part; 312 } 313 // TODO: Consider sanitize_title_with_dashes 314 // TODO : need to handle params.... 315 //logger(substr($url,strlen($url)-1)); 316 //if (substr($url,strlen($url)-1) == '/') $url2 .= '/'; 317 //$url2 = rtrim($url2,'/'); 318 //logger ("$href $url $url2"); 319 //$href = $this->home_url.$url2; 320 if (substr($href, strlen($href) - 1) == '/') $url2.='/'; 321 return $home_url . $url2; 322 } 323 324 /** 325 * Function to display a flag 326 * @param string $path path to flag images 327 * @param string $flag the flag (normally iso code) 328 * @param string $language the name of the lanaguage 329 * @param boolean $css using css code? 330 * @return string Html with flag 331 */ 332 function display_flag($path, $flag, $language, $css = false) { 333 if (!$css) { 334 return "<img src=\"$path/$flag.png\" title=\"$language\" alt=\"$language\"/>"; 335 } else { 336 return "<span title=\"$language\" class=\"trf trf-{$flag}\"></span>"; 337 } 338 } 339 340 /** 341 * determine which language out of an available set the user prefers most 342 * adapted from php documentation page 343 * @param array $available_languages array with language-tag-strings (must be lowercase) that are available 344 * @param string $default_lang Language that will be default (first in available languages if not provided) 345 * @param string $http_accept_language a HTTP_ACCEPT_LANGUAGE string (read from $_SERVER['HTTP_ACCEPT_LANGUAGE'] if left out) 346 * @return string 347 */ 348 function prefered_language($available_languages, $default_lang="auto", $http_accept_language="auto") { 349 // if $http_accept_language was left out, read it from the HTTP-Header 350 if ($http_accept_language == "auto") 351 $http_accept_language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; 352 353 // standard for HTTP_ACCEPT_LANGUAGE is defined under 354 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 355 // pattern to find is therefore something like this: 356 // 1#( language-range [ ";" "q" "=" qvalue ] ) 357 // where: 358 // language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" ) 359 // qvalue = ( "0" [ "." 0*3DIGIT ] ) 360 // | ( "1" [ "." 0*3("0") ] ) 361 preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" . 362 "(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i", 363 $http_accept_language, $hits, PREG_SET_ORDER); 364 365 // default language (in case of no hits) is the first in the array 366 if ($default_lang == 'auto') $bestlang = $available_languages[0]; else 367 $bestlang = $default_lang; 368 $bestqval = 0; 369 370 foreach ($hits as $arr) { 371 // read data from the array of this hit 372 $langprefix = strtolower($arr[1]); 373 if (!empty($arr[3])) { 374 $langrange = strtolower($arr[3]); 375 $language = $langprefix . "-" . $langrange; 376 } 377 else $language = $langprefix; 378 $qvalue = 1.0; 379 if (!empty($arr[5])) $qvalue = floatval($arr[5]); 380 381 // find q-maximal language 382 if (in_array($language, $available_languages) && ($qvalue > $bestqval)) { 383 $bestlang = $language; 384 $bestqval = $qvalue; 385 } 386 // if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does) 387 else if (in_array($languageprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) { 388 $bestlang = $languageprefix; 389 $bestqval = $qvalue * 0.9; 390 } 391 } 392 return $bestlang; 271 else { 272 // now the same attempt with '-' replaced to ' ' 273 list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language)); 274 //logger ($part. ' '.str_replace('-', ' ', $part).' '.$translated_text); 275 if ($translated_text) 276 $url .= '/' . str_replace(' ', '-', $translated_text); 277 else $url .= '/' . $part; 278 } 279 } 280 if (substr($href, strlen($href) - 1) == '/') $url.='/'; 281 return $home_url . $url . $querypart; 282 } 283 284 /** 285 * From a given translated url, tries to get the original URL 286 * @param string $href 287 * @param string $home_url 288 * @param string $target_language 289 * @param function $fetch_translation_func 290 * @return string 291 */ 292 public static function get_original_url($href, $home_url, $target_language, $fetch_translation_func) { 293 $href = substr($href, strlen($home_url)); 294 $url = urldecode($href); 295 $url = (($pos = strpos($url, '?')) ? substr($url, 0, $pos) : $url); 296 $parts = explode('/', $url); 297 foreach ($parts as $part) { 298 if (!$part) continue; 299 // don't attempt for lang or numbers 300 if ($part == $target_language || is_numeric($part)) { 301 $url2 .= '/' . $part; 302 continue; 303 } 304 305 // we attempt to find an original text 306 $original_text = call_user_func_array($fetch_translation_func, array($part, $target_language)); 307 if (!$original_text) { 308 // if the part has dashes we attempt to resolve original without them 309 if ($part != str_replace('-', ' ', $part)) { 310 $original_text = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language)); 311 } 312 } 313 // we'll add it if we have it 314 if ($original_text) 315 $url2 .= '/' . strtolower(str_replace(' ', '-', $original_text)); 316 else $url2 .= '/' . $part; 317 } 318 // TODO: Consider sanitize_title_with_dashes 319 // TODO : need to handle params.... 320 //logger(substr($url,strlen($url)-1)); 321 //if (substr($url,strlen($url)-1) == '/') $url2 .= '/'; 322 //$url2 = rtrim($url2,'/'); 323 //logger ("$href $url $url2"); 324 //$href = $this->home_url.$url2; 325 if (substr($href, strlen($href) - 1) == '/') $url2.='/'; 326 return $home_url . $url2; 327 } 328 329 /** 330 * Function to display a flag 331 * @param string $path path to flag images 332 * @param string $flag the flag (normally iso code) 333 * @param string $language the name of the lanaguage 334 * @param boolean $css using css code? 335 * @return string Html with flag 336 */ 337 public static function display_flag($path, $flag, $language, $css = false) { 338 if (!$css) { 339 return "<img src=\"$path/$flag.png\" title=\"$language\" alt=\"$language\"/>"; 340 } else { 341 return "<span title=\"$language\" class=\"trf trf-{$flag}\"></span>"; 342 } 343 } 344 345 /** 346 * determine which language out of an available set the user prefers most 347 * adapted from php documentation page 348 * @param array $available_languages array with language-tag-strings (must be lowercase) that are available 349 * @param string $default_lang Language that will be default (first in available languages if not provided) 350 * @param string $http_accept_language a HTTP_ACCEPT_LANGUAGE string (read from $_SERVER['HTTP_ACCEPT_LANGUAGE'] if left out) 351 * @return string 352 */ 353 public static function prefered_language($available_languages, $default_lang="auto", $http_accept_language="auto") { 354 // if $http_accept_language was left out, read it from the HTTP-Header 355 if ($http_accept_language == "auto") 356 $http_accept_language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; 357 358 // standard for HTTP_ACCEPT_LANGUAGE is defined under 359 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 360 // pattern to find is therefore something like this: 361 // 1#( language-range [ ";" "q" "=" qvalue ] ) 362 // where: 363 // language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" ) 364 // qvalue = ( "0" [ "." 0*3DIGIT ] ) 365 // | ( "1" [ "." 0*3("0") ] ) 366 preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" . 367 "(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i", 368 $http_accept_language, $hits, PREG_SET_ORDER); 369 370 // default language (in case of no hits) is the first in the array 371 if ($default_lang == 'auto') $bestlang = $available_languages[0]; else 372 $bestlang = $default_lang; 373 $bestqval = 0; 374 375 foreach ($hits as $arr) { 376 // read data from the array of this hit 377 $langprefix = strtolower($arr[1]); 378 if (!empty($arr[3])) { 379 $langrange = strtolower($arr[3]); 380 $language = $langprefix . "-" . $langrange; 381 } 382 else $language = $langprefix; 383 $qvalue = 1.0; 384 if (!empty($arr[5])) $qvalue = floatval($arr[5]); 385 386 // find q-maximal language 387 if (in_array($language, $available_languages) && ($qvalue > $bestqval)) { 388 $bestlang = $language; 389 $bestqval = $qvalue; 390 } 391 // if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does) 392 else if (in_array($languageprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) { 393 $bestlang = $languageprefix; 394 $bestqval = $qvalue * 0.9; 395 } 396 } 397 return $bestlang; 398 } 399 393 400 } 394 401 ?> -
trunk/WordPress/plugin/transposh/transposh.php
r487 r488 199 199 $parse->prefetch_translate_func = array(&$this->database, 'prefetch_translations'); 200 200 $parse->url_rewrite_func = array(&$this, 'rewrite_url'); 201 $parse->dir_rtl = (in_array($this->target_language, $GLOBALS['rtl_languages']));201 $parse->dir_rtl = (in_array($this->target_language, transposh_consts::$rtl_languages)); 202 202 $parse->lang = $this->target_language; 203 203 $parse->default_lang = $this->options->is_default_language($this->target_language); … … 239 239 logger(substr($_SERVER['SCRIPT_FILENAME'], -11), 4); 240 240 if (substr($_SERVER['SCRIPT_FILENAME'], -11) == 'wp-load.php') { 241 $this->target_language = get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);241 $this->target_language = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url); 242 242 } 243 243 … … 333 333 334 334 // make themes that support rtl - go rtl http://wordpress.tv/2010/05/01/yoav-farhi-right-to-left-themes-sf10 335 if (in_array($this->target_language, $GLOBALS['rtl_languages'])) {335 if (in_array($this->target_language, transposh_consts::$rtl_languages)) { 336 336 global $wp_locale; 337 337 $wp_locale->text_direction = 'rtl'; … … 351 351 if (isset($_COOKIE['TR_LNG']) && $this->options->get_widget_allow_set_default_language()) { 352 352 if ($_COOKIE['TR_LNG'] != $this->target_language) { 353 $url = rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $_COOKIE['TR_LNG'], $this->edit_mode);353 $url = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $_COOKIE['TR_LNG'], $this->edit_mode); 354 354 if ($this->options->is_default_language($_COOKIE['TR_LNG'])) 355 $url = cleanup_url($_SERVER["REQUEST_URI"], $this->home_url);355 $url = transposh_utils::cleanup_url($_SERVER["REQUEST_URI"], $this->home_url); 356 356 logger("redirected to $url because of cookie", 4); 357 357 wp_redirect($url); … … 359 359 } 360 360 } else { 361 $bestlang = prefered_language(explode(',', $this->options->get_viewable_langs()), $this->options->get_default_language());361 $bestlang = transposh_utils::prefered_language(explode(',', $this->options->get_viewable_langs()), $this->options->get_default_language()); 362 362 // we won't redirect if we should not, or this is a presumable bot 363 363 if ($bestlang && $bestlang != $this->target_language && $this->options->get_enable_detect_language() && !(preg_match("#(bot|yandex|validator|google|jeeves|spider|crawler|slurp)#si", $_SERVER['HTTP_USER_AGENT']))) { 364 $url = rewrite_url_lang_param($_SERVER['REQUEST_URI'], $this->home_url, $this->enable_permalinks_rewrite, $bestlang, $this->edit_mode);364 $url = transposh_utils::rewrite_url_lang_param($_SERVER['REQUEST_URI'], $this->home_url, $this->enable_permalinks_rewrite, $bestlang, $this->edit_mode); 365 365 if ($this->options->is_default_language($bestlang)) 366 $url = cleanup_url($_SERVER['REQUEST_URI'], $this->home_url);366 $url = transposh_utils::cleanup_url($_SERVER['REQUEST_URI'], $this->home_url); 367 367 logger("redirected to $url because of bestlang", 4); 368 368 wp_redirect($url); … … 381 381 add_action('posts_where_request', array(&$this, 'posts_where_request')); 382 382 } 383 if ( get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) {384 wp_redirect( rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite,get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false)); //."&stop=y");383 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)) { 384 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"); 385 385 exit; 386 386 } … … 548 548 ); 549 549 if ($this->edit_mode) $script_params['edit'] = 1; 550 if (in_array($this->target_language, $GLOBALS['bing_languages']))550 if (in_array($this->target_language, transposh_consts::$bing_languages)) 551 551 $script_params['msn'] = 1; 552 if (in_array($this->target_language, $GLOBALS['google_languages']))552 if (in_array($this->target_language, transposh_consts::$google_languages)) 553 553 $script_params['google'] = 1; 554 if (function_exists('curl_init') && in_array($this->target_language, $GLOBALS['google_proxied_languages']))554 if (function_exists('curl_init') && in_array($this->target_language, transposh_consts::$google_proxied_languages)) 555 555 $script_params['tgp'] = 1; 556 556 if ($this->options->get_widget_progressbar()) … … 627 627 // first cut home 628 628 if ($this->options->get_enable_url_translate()) { 629 $href = trans late_url($href, $this->home_url, $this->target_language, array(&$this->database, 'fetch_translation'));630 } 631 $href = rewrite_url_lang_param($href, $this->home_url, $this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params);629 $href = transposh_utils::translate_url($href, $this->home_url, $this->target_language, array(&$this->database, 'fetch_translation')); 630 } 631 $href = transposh_utils::rewrite_url_lang_param($href, $this->home_url, $this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params); 632 632 logger("rewritten: $href", 4); 633 633 return $href; … … 724 724 */ 725 725 function add_comment_meta_settings($post_id) { 726 if ( get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url))727 add_comment_meta($post_id, 'tp_language', get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), true);726 if (transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url)) 727 add_comment_meta($post_id, 'tp_language', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), true); 728 728 } 729 729 … … 735 735 */ 736 736 function comment_post_redirect_filter($url) { 737 $lang = get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);737 $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url); 738 738 if ($lang) { 739 $url = rewrite_url_lang_param($url, $this->home_url, $this->enable_permalinks_rewrite, $lang, $this->edit_mode);739 $url = transposh_utils::rewrite_url_lang_param($url, $this->home_url, $this->enable_permalinks_rewrite, $lang, $this->edit_mode); 740 740 } 741 741 return $url; … … 766 766 $lang = get_post_meta($id, 'tp_language', true); 767 767 if ($lang) { 768 logger($_SERVER['REQUEST_URI']);769 768 if (strpos($_SERVER['REQUEST_URI'], 'wp-admin/edit') !== false) { 770 769 logger('iamhere?' . strpos($_SERVER['REQUEST_URI'], 'wp-admin/edit')); 771 770 $plugpath = parse_url($this->transposh_plugin_url, PHP_URL_PATH); 772 list($langeng, $langorig, $langflag) = explode(',', $GLOBALS['languages'][$lang]);773 $text = display_flag("$plugpath/img/flags", $langflag, $langorig, false) . ' ' . $text;771 list($langeng, $langorig, $langflag) = explode(',', transposh_consts::$languages[$lang]); 772 $text = transposh_utils::display_flag("$plugpath/img/flags", $langflag, $langorig, false) . ' ' . $text; 774 773 } else { 775 774 $text = "<span lang =\"$lang\">" . $text . "</span>"; … … 788 787 //We only do this once, and if we have a lang 789 788 $requri = $_SERVER['REQUEST_URI']; 790 $lang = get_language_from_url($requri, $this->home_url);789 $lang = transposh_utils::get_language_from_url($requri, $this->home_url); 791 790 if ($lang && !$this->got_request) { 792 791 logger('Trying to find original url'); 793 792 $this->got_request = true; 794 793 // the trick is to replace the URI and put it back afterwards 795 $_SERVER['REQUEST_URI'] = get_original_url($requri, '', $lang, array($this->database, 'fetch_original'));794 $_SERVER['REQUEST_URI'] = transposh_utils::get_original_url($requri, '', $lang, array($this->database, 'fetch_original')); 796 795 global $wp; 797 796 $wp->parse_request(); -
trunk/WordPress/plugin/transposh/widgets/flags/tpw_flags.php
r435 r488 49 49 foreach ($args as $langrecord) { 50 50 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 51 display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) .51 transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . 52 52 "</a>"; 53 53 } -
trunk/WordPress/plugin/transposh/widgets/flags/tpw_flags_css.php
r435 r488 44 44 foreach ($args as $langrecord) { 45 45 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 46 display_flag("", $langrecord['flag'], $langrecord['langorig'], true) .46 transposh_utils::display_flag("", $langrecord['flag'], $langrecord['langorig'], true) . 47 47 "</a>"; 48 48 } -
trunk/WordPress/plugin/transposh/widgets/flagslist/tpw_list_with_flags.php
r435 r488 58 58 foreach ($args as $langrecord) { 59 59 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 60 display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>";60 transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>"; 61 61 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 62 62 } -
trunk/WordPress/plugin/transposh/widgets/flagslist/tpw_list_with_flags_css.php
r435 r488 54 54 foreach ($args as $langrecord) { 55 55 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 56 display_flag('', $langrecord['flag'], $langrecord['langorig'], false) . '</a>';56 transposh_utils::display_flag('', $langrecord['flag'], $langrecord['langorig'], false) . '</a>'; 57 57 echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 58 58 } -
trunk/WordPress/plugin/transposh/wp/transposh_3rdparty.php
r484 r488 95 95 */ 96 96 function bp_uri_filter($uri) { 97 $lang = get_language_from_url($uri, $this->transposh->home_url);98 $uri = cleanup_url($uri, $this->transposh->home_url);97 $lang = transposh_utils::get_language_from_url($uri, $this->transposh->home_url); 98 $uri = transposh_utils::cleanup_url($uri, $this->transposh->home_url); 99 99 if ($this->transposh->options->get_enable_url_translate()) { 100 $uri = get_original_url($uri, '', $lang, array($this->transposh->database, 'fetch_original'));100 $uri = transposh_utils::get_original_url($uri, '', $lang, array($this->transposh->database, 'fetch_original')); 101 101 } 102 102 return $uri; … … 110 110 // we don't need to modify our own activity stream 111 111 if ($params->type == 'new_translation') return; 112 if ( get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url))113 bp_activity_update_meta($params->id, 'tp_language', get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url));112 if (transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url)) 113 bp_activity_update_meta($params->id, 'tp_language', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url)); 114 114 } 115 115 … … 152 152 $values = array( 153 153 'user_id' => $bp->loggedin_user->id, 154 'action' => sprintf(__('%s translated a phrase to %s with transposh:', 'buddypress'), bp_core_get_userlink($bp->loggedin_user->id), substr( $GLOBALS['languages'][$lang], 0, strpos($GLOBALS['languages'][$lang], ','))),154 'action' => sprintf(__('%s translated a phrase to %s with transposh:', 'buddypress'), bp_core_get_userlink($bp->loggedin_user->id), substr(transposh_consts::$languages[$lang], 0, strpos(transposh_consts::$languages[$lang], ','))), 155 155 'content' => "Original: <span class=\"no_translate\">$original</span>\nTranslation: <span class=\"no_translate\">$translation</span>", 156 156 'primary_link' => '', … … 186 186 $newloc = $orig_url; 187 187 if ($this->transposh->options->get_enable_url_translate()) { 188 $newloc = trans late_url($newloc, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation'));188 $newloc = transposh_utils::translate_url($newloc, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation')); 189 189 } 190 $newloc = rewrite_url_lang_param($newloc, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, false);190 $newloc = transposh_utils::rewrite_url_lang_param($newloc, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, false); 191 191 $sm_page->SetUrl($newloc); 192 192 $generatorObject->AddElement($sm_page); -
trunk/WordPress/plugin/transposh/wp/transposh_admin.php
r455 r488 172 172 wp_localize_script('transposh_control', 't_jp', array( 173 173 'post_url' => $this->transposh->post_url, 174 //'msn_langs' => json_encode($GLOBALS['bing_languages']),175 //'google_lang' => json_encode($GLOBALS['google_languages']),176 174 'preferred' => $this->transposh->options->get_preferred_translator(), 177 'l10n_print_after' => 't_jp.g_langs = ' . json_encode( $GLOBALS['google_languages']) . '; t_jp.m_langs = ' . json_encode($GLOBALS['bing_languages']) . ';'/*175 'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';'/* 178 176 /* , 179 177 'plugin_url' => $this->transposh_plugin_url, … … 388 386 389 387 // this is the default language location 390 list ($langname, $langorigname, $flag) = explode(",", $GLOBALS['languages'][$this->transposh->options->get_default_language()]);388 list ($langname, $langorigname, $flag) = explode(",", transposh_consts::$languages[$this->transposh->options->get_default_language()]); 391 389 echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;">Default Language (drag another language here to make it default)'; 392 390 echo '<ul id="default_list"><li id="' . $this->transposh->options->get_default_language() . '" class="languages">' 393 . display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false/* $this->transposh->options->get_widget_css_flags() */)391 . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false/* $this->transposh->options->get_widget_css_flags() */) 394 392 . '<input type="hidden" name="languages[]" value="' . $this->transposh->options->get_default_language() . '" />' 395 393 . ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></li>'; … … 402 400 echo '<li id="' . $langcode . '" class="languages ' . ($this->transposh->options->is_viewable_language($langcode) || $this->transposh->options->is_default_language($langcode) ? "active" : "") 403 401 . (!$this->transposh->options->is_viewable_language($langcode) && $this->transposh->options->is_editable_language($langcode) ? "translateable" : "") . '"><div style="float:left">' 404 . display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false /* $langorigname,$this->transposh->options->get_widget_css_flags() */)402 . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false /* $langorigname,$this->transposh->options->get_widget_css_flags() */) 405 403 . '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_viewable_language($langcode) ? ",v" : ",") . ($this->transposh->options->is_viewable_language($langcode) ? ",t" : ",") . '" />' 406 404 . ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></div>'; 407 if (in_array($langcode, $GLOBALS['google_languages']))405 if (in_array($langcode, transposh_consts::$google_languages)) 408 406 echo '<img width="16" height="16" alt="g" class="logoicon" title="Language supported by google translate" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/googleicon.png"/>'; 409 if (in_array($langcode, $GLOBALS['bing_languages']))407 if (in_array($langcode, transposh_consts::$bing_languages)) 410 408 echo '<img width="16" height="16" alt="b" class="logoicon" title="Language supported by bing translate" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/bingicon.png"/>'; 411 if (in_array($langcode, $GLOBALS['rtl_languages']))409 if (in_array($langcode, transposh_consts::$rtl_languages)) 412 410 echo '<img width="16" height="16" alt="r" class="logoicon" title="Language is written from right to left" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/rtlicon.png"/>'; 413 411 echo '</li>'; -
trunk/WordPress/plugin/transposh/wp/transposh_ajax.php
r483 r488 59 59 // set the cookie with ajax, no redirect needed 60 60 elseif (isset($_GET['tr_cookie'])) { 61 setcookie('TR_LNG', get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);62 logger('Cookie ' . get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url));61 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); 62 logger('Cookie ' . transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url)); 63 63 } 64 64 // Set our cookie and return (if no js works - or we are in the default language) 65 65 elseif (isset($_GET['tr_cookie_bck'])) { 66 setcookie('TR_LNG', get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);66 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); 67 67 if ($_SERVER['HTTP_REFERER']) { 68 68 wp_redirect($_SERVER['HTTP_REFERER']); -
trunk/WordPress/plugin/transposh/wp/transposh_db.php
r468 r488 250 250 for ($i = 0; $i < $items; $i++) { 251 251 if (isset($_POST["tk$i"])) { 252 $original = base64_url_decode($_POST["tk$i"]);252 $original = transposh_utils::base64_url_decode($_POST["tk$i"]); 253 253 //The original content is encoded as base64 before it is sent (i.e. token), after we 254 254 //decode it should just the same after it was parsed. … … 342 342 343 343 $ref = getenv('HTTP_REFERER'); 344 $original = base64_url_decode($token);344 $original = transposh_utils::base64_url_decode($token); 345 345 logger("Inside history for $original ($token)", 4); 346 346 -
trunk/WordPress/plugin/transposh/wp/transposh_options.php
r460 r488 135 135 function get_sorted_langs() { 136 136 if (isset($this->options[SORTED_LANGS])) 137 return array_merge(array_flip(explode(",", $this->options[SORTED_LANGS])), $GLOBALS['languages']);138 return $GLOBALS['languages'];137 return array_merge(array_flip(explode(",", $this->options[SORTED_LANGS])), transposh_consts::$languages); 138 return transposh_consts::$languages; 139 139 } 140 140 … … 208 208 function get_default_language() { 209 209 $default = $this->options[DEFAULT_LANG]; 210 if (! $GLOBALS['languages'][$default]) {211 if (defined('WPLANG') && $GLOBALS['languages'][WPLANG]) {210 if (!transposh_consts::$languages[$default]) { 211 if (defined('WPLANG') && transposh_consts::$languages[WPLANG]) { 212 212 $default = WPLANG; 213 213 } else { … … 329 329 */ 330 330 function set_default_language($val) { 331 if (! $GLOBALS['languages'][$val]) {331 if (!transposh_consts::$languages[$val]) { 332 332 $val = "en"; 333 333 } -
trunk/WordPress/plugin/transposh/wp/transposh_postpublish.php
r485 r488 63 63 'post' => $_GET['post'], 64 64 'preferred' => $this->transposh->options->get_preferred_translator(), 65 'l10n_print_after' => 't_jp.g_langs = ' . json_encode( $GLOBALS['google_languages']) . '; t_jp.m_langs = ' . json_encode($GLOBALS['bing_languages']) . ';'/*65 'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';'/* 66 66 'plugin_url' => $this->transposh_plugin_url, 67 67 'edit' => ($this->edit_mode? '1' : ''), … … 120 120 if (!$this->transposh->options->is_default_language($lang) || $this->transposh->options->get_enable_default_translate()) { 121 121 // There is no point in returning phrases, languages pairs that cannot be translated 122 if (in_array($lang, $GLOBALS['bing_languages']) || in_array($lang, $GLOBALS['google_languages'])) {122 if (in_array($lang, transposh_consts::$bing_languages) || in_array($lang, transposh_consts::$google_languages)) { 123 123 list($translation, $source) = $this->transposh->database->fetch_translation($key, $lang); 124 124 if (!$translation) { … … 134 134 // only if a languages list was created we'll need to translate this 135 135 if (is_array($json['p'][$key]['l'])) { 136 $json['p'][$key]['t'] = base64_url_encode($key);136 $json['p'][$key]['t'] = transposh_utils::base64_url_encode($key); 137 137 $json['length']++; 138 138 } -
trunk/WordPress/plugin/transposh/wp/transposh_widget.php
r460 r488 52 52 $lang = $_POST[LANG_PARAM]; 53 53 if ($lang == '') { 54 $lang = get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url);54 $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url); 55 55 } 56 56 if ($lang == $this->transposh->options->get_default_language() || $lang == "none") … … 60 60 // first, we might need to get the original url back 61 61 if ($this->transposh->options->get_enable_url_translate()) { 62 $ref = get_original_url($ref, $this->transposh->home_url,get_language_from_url($ref, $this->transposh->home_url), array($this->transposh->database, 'fetch_original'));62 $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')); 63 63 } 64 64 65 65 //remove existing language settings. 66 $ref = cleanup_url($ref, $this->transposh->home_url);66 $ref = transposh_utils::cleanup_url($ref, $this->transposh->home_url); 67 67 logger("cleaned referrer: $ref, lang: $lang", 4); 68 68 69 69 if ($lang && $this->transposh->options->get_enable_url_translate()) { 70 70 // and then, we might have to translate it 71 $ref = trans late_url($ref, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation'));71 $ref = transposh_utils::translate_url($ref, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation')); 72 72 $ref = str_replace(array('%2F', '%3A', '%3B', '%3F', '%3D', '%26'), array('/', ':', ';', '?', '=', '&'), urlencode($ref)); 73 73 logger("translated to referrer: $ref, lang: $lang", 3); 74 74 } 75 $ref = rewrite_url_lang_param($ref, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]);75 $ref = transposh_utils::rewrite_url_lang_param($ref, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]); 76 76 77 77 logger("Widget redirect url: $ref", 3); … … 171 171 172 172 //remove any language identifier and find the "clean" url, used for posting and calculating urls if needed 173 $clean_page_url = cleanup_url($page_url, $this->transposh->home_url, true);173 $clean_page_url = transposh_utils::cleanup_url($page_url, $this->transposh->home_url, true); 174 174 // we need this if we are using url translations 175 175 if ($this->transposh->options->get_enable_url_translate() && $calc_url) { 176 $clean_page_url = get_original_url($clean_page_url, '', $this->transposh->target_language, array($this->transposh->database, 'fetch_original'));176 $clean_page_url = transposh_utils::get_original_url($clean_page_url, '', $this->transposh->target_language, array($this->transposh->database, 'fetch_original')); 177 177 } 178 178 logger("WIDGET: clean page url: $clean_page_url ,orig: $page_url", 4); … … 187 187 ($this->transposh->options->is_default_language($code))) { 188 188 if ($this->transposh->options->get_enable_url_translate() && $calc_url) { 189 $page_url = trans late_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation'));189 $page_url = transposh_utils::translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation')); 190 190 } else { 191 191 $page_url = $clean_page_url; … … 193 193 // clean $code in default lanaguge 194 194 if ($calc_url) 195 $page_url = rewrite_url_lang_param($page_url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, ($code == $this->transposh->options->get_default_language()) ? '' : $code, $this->transposh->edit_mode);195 $page_url = transposh_utils::rewrite_url_lang_param($page_url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, ($code == $this->transposh->options->get_default_language()) ? '' : $code, $this->transposh->edit_mode); 196 196 $widget_args[] = array( 197 197 'lang' => $langname,
Note: See TracChangeset
for help on using the changeset viewer.
