$widget) { $funcname='zd_multilang_get_option_'.$widget['classname']; eval("function $funcname".'() {$option=str_replace("zd_multilang_get_option_","",__FUNCTION__);return zd_multilang_get_option($option);}'); add_filter('pre_option_'.$widget['classname'], $funcname); $funcname='zd_multilang_update_option_'.$widget['classname']; eval("function $funcname".'($newvalue) {$option=str_replace("zd_multilang_update_option_","",__FUNCTION__);return zd_multilang_update_option($option,$newvalue);}'); add_filter('pre_update_option_'.$widget['classname'], $funcname); //EG : The option name is not always the classname (it should be). For instance, with the sandbox theme, //EG : the option name is the callback. So I also do that for it if it's different. if ($widget['callback']!==$widget['classname']) { $funcname='zd_multilang_get_option_'.$widget['callback']; eval("function $funcname".'() {$option=str_replace("zd_multilang_get_option_","",__FUNCTION__);return zd_multilang_get_option($option);}'); add_filter('pre_option_'.$widget['callback'], $funcname); $funcname='zd_multilang_update_option_'.$widget['callback']; eval("function $funcname".'($newvalue) {$option=str_replace("zd_multilang_update_option_","",__FUNCTION__);return zd_multilang_update_option($option,$newvalue);}'); add_filter('pre_update_option_'.$widget['callback'], $funcname); } } //EG : Now I set all the hook, I can reload all the widgets in order to get the good values regarding the asked //EG : language. wp_widgets_init(); } /* Other things */ add_action('manage_posts_custom_column', 'zd_multilang_manage_col', 10, 2); add_action('manage_pages_custom_column', 'zd_multilang_manage_col', 10, 2); add_action('media_buttons', 'zd_media_button', 30); //EG : This means that when I will load the plugin I will get in this function that set numerous things. zd_multilang_set_locale(""); function zd_multilang_tinymce() { if (($_GET['fct']=="posts")||($_POST['fct']=="posts")) { wp_admin_css('thickbox'); wp_print_scripts('jquery-ui-core'); wp_print_scripts('jquery-ui-tabs'); wp_print_scripts('post'); wp_print_scripts('editor'); if (function_exists('add_thickbox')) add_thickbox(); wp_print_scripts('media-upload'); if (function_exists('wp_tiny_mce')) wp_tiny_mce(); } } function zd_multilang_queryvars( $qvars ) { $qvars[] = 'lang'; return $qvars; } function zd_multilang_manage_col_def ($cols) { $cols['translate']=__('Translate','zd_multilang'); return $cols; } function zd_multilang_manage_col($column_name, $id) { global $ZdmlCache, $PluginDIR; $BaseURL='admin.php?page='.plugin_basename (__FILE__); if( $column_name == 'translate' ) { if ($ZdmlCache['Languages']) foreach ($ZdmlCache['Languages'] as $Permalink => $LanguageID) { if ($LanguageID!=$ZdmlCache['DefLang']) echo ''.$LanguageID.' '; } } } function zd_media_button() { global $ZdmlCache, $PluginDIR; $id=$_GET['post']; $BaseURL='admin.php?page='.plugin_basename (__FILE__); if ($ZdmlCache['Languages']) foreach ($ZdmlCache['Languages'] as $Permalink => $LanguageID) { if ($LanguageID!=$ZdmlCache['DefLang']) echo ''.$LanguageID.''; } } function zd_multilang_where_filter($filter) { global $ZdmlCache, $locale,$display_untranslated_option, $wpdb; if ($locale==$ZdmlCache['DefLang']) return $filter; if (get_option($display_untranslated_option)=="hide") { $filter.=" AND ".$wpdb->posts.".ID in (".$ZdmlCache['TranslatedPosts'][$locale].')'; } return $filter; } function zd_multilang_np_where_filter($filter) { global $ZdmlCache, $locale,$display_untranslated_option, $wpdb; if ($locale==$ZdmlCache['DefLang']) return $filter; if (get_option($display_untranslated_option)=="hide") { $filter.=" AND p.ID in (".$ZdmlCache['TranslatedPosts'][$locale].')'; } return $filter; } //EG : I come here as soon as I load the plugin. Maybe, it would be more readable to put it upper. Why does it take a parameter ? //EG : I added comments and changed things regarding options as it's dealt diffently. function zd_multilang_set_locale($WP) { //EG : We don't use that can we remove it ? // global $wp_query, $wp_rewrite, $default_language_option global $ZdmlCache; global $wpdb, $locale, $CurrentLanguagePermalink, $CurrentLang; //EG : Set the zdml table variables $language_table=$wpdb->prefix.'zd_ml_langs'; $termtrans=$wpdb->prefix.'zd_ml_termtrans'; $posttrans=$wpdb->prefix.'zd_ml_trans'; $linktrans=$wpdb->prefix.'zd_ml_linktrans'; $options=$wpdb->prefix.'zd_ml_options'; //EG : Get some of the zdml options $ZdmlCache['DefLang']=get_option("zd_multilang_defaultlanguage"); $ZdmlCache['InsertInPosts']=get_option("zd_multilang_lang_switcher"); $ZdmlCache['ShowLanguages']=get_option("zd_multilang_langnames"); $ZdmlCache['ShowFlags']=get_option("zd_multilang_show_flags"); $ZdmlCache['SwitcherPosition']=get_option('zd_multilang_position'); $ZdmlCache['Lang_Switch_Class']=(get_option("zd_multilang_switcher_class")!="") ? get_option("zd_multilang_switcher_class") : "lang_switch"; $TheLocale=$ZdmlCache['DefLang']; //EG : Prepare the Languages in $ZdmlCache if (!isset($ZdmlCache['Languages'])) { $query="SELECT * FROM $language_table ORDER BY LanguageName"; $results=$wpdb->get_results($query, ARRAY_A); if ($results) { foreach ($results as $ID => $V) { $ZdmlCache['Languages'][$V['LangPermalink']]=$V['LanguageID']; $ZdmlCache['LanguageNames'][$V['LangPermalink']]=$V['LanguageName']; //EG unused now : $ZdmlCache['Options'][$V['LanguageID']]['blogname']=$V['BlogName']; //EG unused now : $ZdmlCache['Options'][$V['LanguageID']]['blogdescription']=$V['BlogDescription']; } } } //EG : Else I rebuild $result from $ZdmlCache else { $i=0; foreach ($ZdmlCache['Languages'] as $Permalink => $LangID) { $results[$i]['LangPermalink']=$Permalink; $results[$i]['LanguageID']=$LangID; $i++; } } //EG : Rebuild the full URL string that brings us here if ($_SERVER['HTTPS']) $QUERY="https://".$_SERVER['HTTP_HOST']; else $QUERY="http://".$_SERVER['HTTP_HOST']; $QUERY.=$_SERVER['REQUEST_URI']; //EG : Build a string with all the language permalink like fr|en|es if ($results) { foreach ($results as $ID => $Lang) { $regexp.=$Lang['LangPermalink']."|"; } $regexp=substr($regexp, 0, -1); } //EG : Build a regular expression looking for the language. //EG : Why are we building $QUERY without get_bloginfo('url') and using it here ? //EG : Why are we recording the end of the request (.*) ? if (strstr($QUERY,"?")) $RegularExpression="`".get_bloginfo('url')."\/.*lang=($regexp)(.*)?`U"; else $RegularExpression="`".get_bloginfo('url')."\/($regexp)\/(.*)`U"; //EG : If I find the language I set $Lang, $CurrentLanguagePermalink to the language permalink (ex. en) //EG : and $Language, $CurrentLang, $TheLocale, $locale to the language id (ex. en_US) if (preg_match($RegularExpression,$QUERY,$res)==TRUE) { $Lang=$res[1]; $CurrentLanguagePermalink=$res[1]; foreach ($ZdmlCache['Languages'] as $Permalink => $LangFound) { if ($Permalink==$Lang) { $Language= $LangFound; break; } } $CurrentLang=$Language; if ($Language) $TheLocale=$Language; } $locale=$TheLocale; //EG : Prepare the Terms in $ZdmlCache if (!isset($ZdmlCache['Terms'])) { $query="SELECT tt.LanguageID, tt.name as t_name, tt.description as description, t.* FROM $termtrans tt RIGHT JOIN ".$wpdb->prefix."terms t on (tt.term_id=t.term_id)"; $term=$wpdb->get_results($query, ARRAY_A); foreach ($term as $ID => $Value) { if ($Value['t_name']!=NULL) $ZdmlCache['Terms'][$Value['term_id']][$Value['LanguageID']]['name']=$Value['t_name']; else $ZdmlCache['Terms'][$Value['term_id']][$Value['LanguageID']]['name']=$Value['name']; $ZdmlCache['Terms'][$Value['term_id']][$Value['LanguageID']]['o_name']=$Value['name']; $ZdmlCache['Terms'][$Value['term_id']][$Value['LanguageID']]['description']=$Value['description']; } } //EG : Prepare the Links in $ZdmlCache if (!isset($ZdmlCache['Links'])) { $query="SELECT * from $linktrans"; $links=$wpdb->get_results($query); foreach ($links as $id => $Values) { $ZdmlCache['Links'][$Values->link_id][$Values->LanguageID]['name']=$Values->link_name; $ZdmlCache['Links'][$Values->link_id][$Values->LanguageID]['url']=$Values->link_url; $ZdmlCache['Links'][$Values->link_id][$Values->LanguageID]['description']=$Values->link_description; } } //EG : Prepare the Links in $ZdmlCache if (!isset($ZdmlCache['TranslatedPosts'])) { if ($ZdmlCache['Languages']) foreach ($ZdmlCache['Languages'] as $Permalink => $LangID) { if ($LangID!=$ZdmlCache['DefLang']) { $query="SELECT ID from $posttrans WHERE LanguageID='$LangID' and post_status='published'"; $res=$wpdb->get_results($query, ARRAY_A); if ($res) { $ZdmlCache['TranslatedPosts'][$LangID]=""; foreach ($res as $key => $V) { $ZdmlCache['TranslatedPosts'][$LangID].=$V['ID'].","; } $ZdmlCache['TranslatedPosts'][$LangID]=substr($ZdmlCache['TranslatedPosts'][$LangID],0,-1); } } } } return $WP; } function zd_multilang_permalink($permalink) { global $wpdb, $wp_rewrite,$default_language_option, $CurrentLanguagePermalink,$CurrentLang,$permalink_default_option, $locale; global $ZdmlCache; $langstable=$wpdb->prefix.'zd_ml_langs'; $Lang=$CurrentLanguagePermalink; if ($Lang=="") { $CurrentLang=$ZdmlCache['DefLang']; $query="SELECT LangPermalink FROM $langstable where LanguageID='$CurrentLang'"; $CurrentLanguagePermalink=$wpdb->get_var($query); $Lang=$CurrentLanguagePermalink; } $link=$permalink; $PermalinkDef=get_option($permalink_default_option); if (($PermalinkDef=="no")&&($ZdmlCache['DefLang']==$locale)) return $link; if ($wp_rewrite->using_permalinks()) { $url=get_bloginfo('url'); $end=substr($link,strlen($url)); if ($Lang=="") $link=$url.$end; else $link=$url.'/'.$Lang.$end; } else if ($Lang) $link.="&lang=".$Lang; return $link; } function zd_multilang_rewrite($permalink_structure) { global $ZdmlCache; global $wpdb, $wp_rewrite; $langs=$wpdb->prefix.'zd_ml_langs'; $query="SELECT * FROM $langs order by LanguageID"; $Lines=$wpdb->get_results($query, ARRAY_A); if ($Lines) { $regexp='('; foreach ($Lines as $Value) { $regexp.=$Value['LangPermalink'].'|'; } $regexp=substr($regexp,0,-1); $regexp.=')'; if ($permalink_structure) foreach ($permalink_structure as $Rule => $Definition) { $def=explode('?',$Definition); $rule=$Definition; if (preg_match_all('/(.*matches)\[([0-9]+)\]/U',$rule,$res)) { $rule=""; foreach ($res[1] as $index => $text) { $rule.=$text.'['.($index+2).']'; } } $rule.='&lang=$matches[1]'; $new_rules[$regexp.'/'.$Rule]=$rule; } $new_rules2[$regexp.'/?']='index.php?lang=$matches[1]'; if ($permalink_structure) $permalink_structure = $new_rules+ $new_rules2 + $permalink_structure; } return $permalink_structure; } function zd_multilang_is_translated($id, $lang) { global $ZdmlCache, $locale; if ($lang==$ZdmlCache['DefLang']) return TRUE; $Posts=explode(',',$ZdmlCache['TranslatedPosts'][$lang]); foreach ($Posts as $key => $ID) { if ($ID==$id) { return TRUE; } } return FALSE; } //EG : Create/modify the database is case of creation. //EG : Could it be somwhere else ? What is the the policy regarding version ? function zd_multilang_install() { //EG : We don't use that, could we remove this line ? // global $ZdmlCache; global $wpdb; //EG : Set the zdml table variables $termtrans=$wpdb->prefix.'zd_ml_termtrans'; $langs=$wpdb->prefix.'zd_ml_langs'; $posttrans=$wpdb->prefix.'zd_ml_trans'; $linktrans=$wpdb->prefix.'zd_ml_linktrans'; //EG : new. For information. So it's possible to remove this comment in the futur. $options=$wpdb->prefix.'zd_ml_options'; $dbversion=get_option('zd_multilang_dbschema'); //EG : To change in the futur 121 or 130 if ($dbversion<"121") { //EG Here is the creation of the zd_ml_options table based on the original wordpress option table. //EG The LanguageID has been add, linked with the language table of zdml. //EG We have to do that here before removing the other fields in the lang table . //EG Everything may not be used but we never know for the futur. $sql="CREATE TABLE $options ( option_id bigint(20) NOT NULL auto_increment, blog_id int(11) NOT NULL default '0', LanguageID varchar(5) NOT NULL, option_name varchar(64) NOT NULL default '', option_value longtext NOT NULL, autoload varchar(20) NOT NULL default 'yes', PRIMARY KEY (option_id,blog_id,option_name,LanguageID), UNIQUE KEY option_name (option_name,LanguageID) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); //EG Get the old BlogName and BlogDescription fields to put in the new option table if upgrading from version <121. if ($dbversion<"121") { $sql="INSERT INTO $options(LanguageID, option_name, option_value) SELECT LanguageID,'blogname',BlogName FROM $langs"; $wpdb->query($sql); $sql="INSERT INTO $options(LanguageID, option_name, option_value) SELECT LanguageID,'blogdescription',BlogDescription FROM $langs"; $wpdb->query($sql); } $sql="CREATE TABLE $langs ( LanguageID varchar(5) NOT NULL, LanguageName varchar(100) character set utf8 NOT NULL, LangPermalink varchar(50) NOT NULL UNIQUE,". //EG : unused BlogName longtext, //EG : unused BlogDescription longtext, " primary key (LanguageID) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $sql="CREATE TABLE $termtrans ( term_id varchar(5) NOT NULL, LanguageID varchar(5) NOT NULL, name varchar(255) character set utf8 NOT NULL, description longtext NOT NULL, primary key (term_id,LanguageID) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $sql="CREATE TABLE $posttrans ( ID BIGINT(20) NOT NULL, LanguageID varchar(5), post_content longtext character set utf8, post_excerpt text character set utf8, post_title text character set utf8 NOT NULL, post_status varchar(10), primary key (ID, LanguageID) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $sql="CREATE TABLE $linktrans ( link_id BIGINT(20) NOT NULL, LanguageID varchar(5), link_url varchar(255), link_name varchar(255) character set utf8, link_description varchar(255) character set utf8, primary key (link_id, LanguageID) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $sql="UPDATE $posttrans set post_status='published' where post_status is NULL"; $wpdb->query($sql); //EG : Set the widget options as traditional widget inspered from wordpress. if ($dbversion<"121") { update_option('zd_multilang_widget','a:2:{s:5:"title";s:0:"'.get_option('zdml_widget_title').'";s:7:"options";b:'.get_option('zdml_widget_options').';}'); delete_option('zdml_widget_title'); delete_option('zdml_widget_options'); } update_option('zd_multilang_dbschema',121); } } function zd_multilang_add_pages() { add_menu_page('Zd_MultiLang', __('Translations','zd_multilang'), 8, __FILE__, 'zd_multilang_page'); add_submenu_page(__FILE__,__('Posts','zd_multilang'),__('Posts','zd_multilang'),8,__FILE__.'&fct=posts&tr=posts','zd_multilang_page'); add_submenu_page(__FILE__,__('Pages','zd_multilang'),__('Pages','zd_multilang'),8,__FILE__.'&fct=posts&tr=pages','zd_multilang_page'); add_submenu_page(__FILE__,__('Categories','zd_multilang'),__('Categories','zd_multilang'),8,__FILE__.'&fct=translations&tr=cat','zd_multilang_page'); add_submenu_page(__FILE__,__('Tags','zd_multilang'),__('Tags','zd_multilang'),8,__FILE__.'&fct=translations&tr=tags','zd_multilang_page'); add_submenu_page(__FILE__,__('Links','zd_multilang'),__('Links','zd_multilang'),8,__FILE__.'&fct=links','zd_multilang_page'); add_submenu_page(__FILE__,__('Link Categories','zd_multilang'),__('Link Categories','zd_multilang'),8,__FILE__.'&fct=translations&tr=linkcat','zd_multilang_page'); add_submenu_page(__FILE__,__('Languages','zd_multilang'),__('Languages','zd_multilang'),8,__FILE__.'&fct=languages','zd_multilang_page'); add_submenu_page(__FILE__,__('Options','zd_multilang'),__('Options','zd_multilang'),8,__FILE__.'&fct=options','zd_multilang_page'); } function zd_multilang_page() { global $BaseURL; echo "\n".'
'; if ($_POST['fct']) $_GET['fct']=$_POST['fct']; switch ($_GET['fct']) { case 'options': zd_multilang_options(); break; case 'edit': zd_multilang_edit_language(); break; case 'delete': zd_multilang_delete_language(); break; case 'posts': zd_multilang_post_translations(); break; case 'translations'; zd_multilang_term_translations(); break; case 'languages': zd_multilang_languages(); break; case 'links': zd_multilang_link_translations(); break; default: zd_multilang_dashboard(); break; } echo "\n
"; } function zd_multilang_dashboard() { global $BaseURL; echo '

'.__('Language Dashboard','zd_multilang').'

'; echo ''; } function zd_multilang_options() { global $wpdb, $BaseURL,$default_language_option,$insert_lang_switch_option,$show_flags_option,$display_google_translate_option; global $show_languages_option,$lang_switcher_class_option,$permalink_default_option,$display_untranslated_option; global $ZdmlCache; $language_table=$wpdb->prefix.'zd_ml_langs'; $termtrans=$wpdb->prefix.'zd_ml_termtrans'; $posttrans=$wpdb->prefix.'zd_ml_trans'; $hidden_field="zd_multilang_update_options"; $language_table= $wpdb->prefix.'zd_ml_langs'; if ($_POST[$hidden_field]) { $OldLang=get_option($default_language_option); $DefLang=$_POST['def_lang']; $InsertInPosts=$_POST['show_language_switcher']; $Show_Languages=$_POST['show_languages']; $Show_Flags=$_POST['show_flags']; $Lang_Switch_Class=$_POST['lang_switch_class']; $SwitcherPosition=$_POST['language_switcher_position']; $PermalinkDef=$_POST['permalink_for_default']; $Exchange=$_POST['exchange_lang']; $DisplayUntranslated=$_POST['display_untranslated']; $DisplayGLink=$_POST['display_glink']; update_option('zd_multilang_position',$SwitcherPosition); update_option($default_language_option,$DefLang); update_option($insert_lang_switch_option,$InsertInPosts); update_option($show_languages_option,$Show_Languages); update_option($show_flags_option,$Show_Flags); update_option($lang_switcher_class_option,$Lang_Switch_Class); update_option($permalink_default_option, $PermalinkDef); update_option($display_untranslated_option,$DisplayUntranslated); update_option($display_google_translate_option,$DisplayGLink); echo '
'; if ($Exchange=="on") { $query="SELECT * FROM $posttrans where LanguageID='$DefLang'"; $TrPosts=$wpdb->get_results($query, ARRAY_A); $query="SELECT * FROM $termtrans where LanguageID='$DefLang'"; $TrTerms=$wpdb->get_results($query, ARRAY_A); if ($TrPosts) foreach ($TrPosts as $key => $V) { $query="SELECT * from ".$wpdb->posts." WHERE ID=".$V['ID']; $res=$wpdb->get_row($query); $OriginalTitle=$res->post_title; $OriginalContent=$wpdb->escape($res->post_content); $NewContent=$wpdb->escape($V['post_content']); $NewTitle=$V['post_title']; $q1="UPDATE ".$wpdb->posts." set post_title='$NewTitle', post_content='$NewContent' WHERE ID=".$V['ID']; $wpdb->query($q1); $q1="UPDATE $posttrans set post_title='$OriginalTitle', post_content='$OriginalContent', LanguageID='$OldLang' WHERE ID=".$V['ID']." and LanguageID='$DefLang'"; $wpdb->query($q1); } if ($TrTerms) foreach ($TrTerms as $key => $V) { $query="SELECT * from ".$wpdb->terms." WHERE term_id=".$V['term_id']; $res=$wpdb->get_row($query); $OriginalTerm=$res->name; $NewTerm=$V['name']; $q1="UPDATE ".$wpdb->terms." SET name='$NewTerm' WHERE term_id=".$V['term_id']; $wpdb->query($q1); $q1="UPDATE $termtrans SET name='$OriginalTerm', LanguageID='$OldLang' WHERE LanguageID='$DefLang' and term_id=".$V['term_id']; $wpdb->query($q1); } echo '

'.__('Default Languages Exchanged','zd_multilang').'

'; } echo '

'.__('Options updated','zd_multilang').'

'; echo '
'; } $query="SELECT * FROM $language_table order by LanguageName"; $Languages=$wpdb->get_results($query, ARRAY_A); $DefaultLanguage=get_option($default_language_option); $InsertInPosts=get_option($insert_lang_switch_option); $ShowLanguages=get_option($show_languages_option); $ShowFlags=get_option($show_flags_option); $SwitcherPosition=get_option('zd_multilang_position'); $DisplayUntranslated=get_option($display_untranslated_option); $DisplayGlink=get_option($display_google_translate_option); $Lang_Switch_Class=(get_option($lang_switcher_class_option)!="") ? get_option($lang_switcher_class_option) : "lang_switch"; echo "\n\t

".__('General Options','zd_multilang')."

"; echo "\n\t".'
'; echo "\n\t".''; echo "\n\t".''; echo "\n\t".''; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo '
".__('Default Language','zd_multilang').""; echo ''; echo "
".__('Exchange Languages','zd_multilang')."
".__('Only use this option if you want to switch old default language with new one. This will exchange translations between them','zd_multilang')."
"; echo ''; echo "
".__('Generate permalink for Default language','zd_multilang').""; echo ''; echo "
".__('Display untranslated posts','zd_multilang').""; echo ''; echo "
".__('If Yes, display link "Translate Original post with Google Translate"','zd_multilang').""; echo ''; echo "
'; echo '

'.__('Language Switcher','zd_multilang').'

'; echo "\n\t".''; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t".'
".__('Show Language Switcher in post','zd_multilang').""; echo ''; echo "
".__('Language Switcher Position','zd_multilang').""; echo ''; echo "
".__('Show Language names in switcher','zd_multilang').""; echo ''; echo "
".__('Show Flags in switcher','zd_multilang').""; echo ''; echo "
".__('Language Switcher CSS class','zd_multilang').""; echo ''; echo "
'; echo "\n\t".'

'; echo "\n".'
'; } //EG : Few changes here due to the move of the blogname and blogdescription options. function zd_multilang_edit_language() { //EG : Not used so could we remove ? // global $BaseURL, $wp_rewrite, $PluginDIR global $wpdb, $default_language_option, $BaseURL; global $ZdmlCache; $language_table= $wpdb->prefix.'zd_ml_langs'; $options_table= $wpdb->prefix.'zd_ml_options'; $hidden_field="zd_multilang_edit_language"; if ($_POST[$hidden_field]) { $Action=$_POST[$hidden_field]; $LangCode=$_POST['lang_code']; $LangName=$_POST['lang_name']; $LangPermalink=$_POST['lang_permalink']; $BlogName=$_POST['blog_name']; $BlogDesc=$_POST['blog_description']; echo '

'; if ($Action=="edit") { //EG : New modification here to integrate the blogname and description in the zd_ml_table. // Old request : $query="UPDATE $language_table set LanguageName='$LangName',LangPermalink='$LangPermalink', BlogName='$BlogName', BlogDescription='$BlogDesc' WHERE LanguageID='$LangCode'"; $query="UPDATE $language_table set LanguageName='$LangName',LangPermalink='$LangPermalink' WHERE LanguageID='$LangCode'"; $wpdb->query($query); //EG : Insert blogname if it doesn't exist either update. $query="INSERT INTO $options_table(LanguageID, option_name, option_value) VALUES ('$LangCode','blogname','$BlogName') ON DUPLICATE KEY UPDATE option_value='$BlogName'"; $wpdb->query($query); //EG : Insert blogdescription if it doesn't exist either update. $query="INSERT INTO $options_table(LanguageID, option_name, option_value) VALUES ('$LangCode','blogdescription','$BlogDesc') ON DUPLICATE KEY UPDATE option_value='$BlogDesc'"; $wpdb->query($query); if ($_POST['def_lang']=="on") update_option($default_language_option,$LangCode); echo __('Language Edited','zd_multilang'); } echo '

'; zd_multilang_languages(); return; } $DefaultLanguage=$ZdmlCache['DefLang']; $Code=$_GET['lang']; $query="SELECT * FROM $language_table where LanguageID='$Code'"; $row=$wpdb->get_row($query, ARRAY_A); $row['BlogName']=get_option("blogname"); $row['BlogDescription']=get_option("blogdescription"); echo "

".__('Languages','zd_multilang').'


'; echo "

".__('Edit Language','zd_multi').' '.$_GET['lang'].'

'; echo "\n\t".'
'; echo "\n\t".''; echo "\n\t".''; echo "\n\t".''; echo "\n\t".''; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t".'
".__('Language Name','zd_multilang').""; echo ''; echo "
".__('Language Permalink','zd_multilang').""; echo ''; echo "
".__('Blog name','zd_multilang').""; echo ''; echo "
".__('Blog description','zd_multilang').""; echo ''; echo "
".__('Default Language','zd_multilang')." ?"; if ($row['LanguageID']==$DefaultLanguage) $selected='checked="on"'; else $selected=""; echo ''; echo "
'; echo "\n\t".'

'; echo "\n\t
"; } //EG : Few changes here due to the move of the blogname and blogdescription options. function zd_multilang_languages() { global $ZdmlCache; global $wpdb, $BaseURL,$default_language_option, $BaseURL, $PluginDIR, $wp_rewrite; $language_table= $wpdb->prefix.'zd_ml_langs'; $hidden_field="zd_multilang_add_language"; echo "

".__('Languages','zd_multilang').'


'; if ($_POST[$hidden_field]) { $Action=$_POST[$hidden_field]; $LangCode=$_POST['lang_code']; $LangName=$_POST['lang_name']; $LangPermalink=$_POST['lang_permalink']; echo '

'; if ($Action=="add") { //EG : old query $query="INSERT INTO $language_table VALUES ('$LangCode','$LangName','$LangPermalink',NULL,NULL)"; $query="INSERT INTO $language_table VALUES ('$LangCode','$LangName','$LangPermalink')"; $wpdb->query($query); if ($_POST['def_lang']=="on") update_option($default_language_option,$LangCode); echo __('Language Added','zd_multilang'); } echo '


'; } $DefaultLanguage=$ZdmlCache['DefLang']; $query="SELECT * FROM $language_table order by LanguageName"; $Languages=$wpdb->get_results($query, ARRAY_A); if ($Languages) { echo ''; echo ''; foreach ($Languages as $Index => $Values) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
'.__('Action','zd_multilang').''.__('Language Name','zd_multilang').''.__('Language Code','zd_multilang').''.__('Permalink','zd_multilang').''.__('Default','zd_multilang').'
'.__('Edit','zd_multilang').' - '.__('Delete','zd_multilang').' '.$Values['LanguageName'].''.$Values['LanguageID'].''.$Values['LangPermalink'].' '; if ($Values['LanguageID']==$DefaultLanguage) echo "".__('Default Language', 'zd_multilang').""; echo '
'; } echo "

".__('Add Language','zd_multilang').'

'; echo "\n\t".'
'; echo "\n\t".''; echo "\n\t".''; echo "\n\t".''; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t\t"; echo "\n\t".'
".__('Language Name','zd_multilang').""; echo ''; echo "
".__('Language Code','zd_multilang').""; echo ''; echo "
".__('Language Permalink','zd_multilang').""; echo ''; echo "
".__('Default Language','zd_multilang')." ?"; echo ''; echo "
'; echo "\n\t".'

'; echo "\n\t

".__('Show/Hide Available default codes','zd_multilang')."

"; $DefaultLanguagesCodes=array ( 'ar' => array ('Arabian', 'ar'),'bn_BD' => array ('Bengali','bn'),'be_BY' => array ('Belarusian','be'), 'bg_BG' => array ('Bulgarian','bg'),'ca' => array ('Catalan','ca'),'zh_CN' => array ('Chinese','cn'), 'zh_HK' => array ('Hong Kong','hk'),'zh_TW' => array ('Taiwan','tw'),'hr' => array ('Croatian','hr'), 'cz_CZ' => array ('Czech','cz'),'da_DK' => array ('Danish','dk'),'nl_NL' => array ('Dutch','nl'), 'en_US' => array ('English','en'),'eu' => array ('Euskadi','eu'),'eo' => array ('Esperanto','eo'), 'et' => array ('Estonian','et'),'fo' => array ('Faroe','fo'),'fi_FI' => array ('Finnish','fi'), 'fr_FR' => array ('French','fr'),'gl_ES' => array ('Galician','gl'),'de_DE' => array ('German','de'), 'el' => array ('Greek','gr'),'he_IL' => array ('Hebrew','il'),'hu_HU' => array ('Hungarian','hu'), 'is_IS' => array ('Icelandic','is'),'id_ID' => array ('Indonesian','id'),'it_IT' => array ('Italian','it'), 'ja' => array ('Japanese','jp'),'km_KH' => array ('Khmer','km'),'ko_KR' => array ('Korean','ko'), 'ku' => array ('Kurdish','ku'),'lv' => array ('Latvian','lv'),'lt' => array ('Lithuanian','lt'), 'mk_MK' => array ('Macedonian','mk'),'mg_MG' => array ('Malgasy','mg'),'ms_MY' => array ('Malay','my'), 'nb_NO' => array ('Norwegian','no'),'pl_PL' => array ('Polish','pl'),'pt_BR' => array ('Brazilian Portuguese','br'), 'pt_PT' => array ('European Portuguese','pt'),'ro' => array ('Romanian','ro'),'ru_RU' => array ('Russian','ru'), 'sr_RS' => array ('Serbian','sr'),'si_LK' => array ('Sinhala','lk'),'sl_SI' => array ('Slovenian','sl'), 'sk' => array ('Slovak','sk'),'es_ES' => array ('Spanish','es'),'sv_SE' => array ('Swedish','se'), 'th' => array ('Thai','th'),'tr' => array ('Turkish','tr'),'ua_UA' => array ('Ukrainian','ua'), 'uz_UZ' => array ('Uzbek','uz'),'vi_VN' => array ('Vietnamse','vn'),'cy' => array ('Welsh','cy') ); echo ' '; $wp_rewrite->flush_rules(); } //EG : I thought about adding zd_ml_options in zd_multilang_delete_language. By the way it lacks //EG : zd_ml_links and zd_ml_trans. But I prefered not to delete. //EG : We just need to delete the language from zd_ml_langs to get it inactive, no ? So if I create it again I get back //EG : my previous data... Not clean but practicle in case of error. function zd_multilang_delete_language() { global $ZdmlCache; global $BaseURL, $wpdb,$default_language_option; $DefaultLanguage=$ZdmlCache['DefLang']; $language_table= $wpdb->prefix.'zd_ml_langs';$termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $LangCode=$_GET['lang']; $query="DELETE FROM $language_table WHERE LanguageID='$LangCode'"; $wpdb->query($query); $query="DELETE FROM $termtrans_table WHERE LanguageID='$LangCode'"; $wpdb->query($query); echo '

'; echo __('Language deleted','zd_multilang'); echo '

'; zd_multilang_languages(); } function zd_multilang_post_translations() { global $ZdmlCache; global $BaseURL, $wpdb,$default_language_option,$PluginDIR; $language_table= $wpdb->prefix.'zd_ml_langs'; $termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $posttrans=$wpdb->prefix.'zd_ml_trans'; $hidden_field="zd_multilang_edit_translation"; echo "

".__('Posts & Pages','zd_multilang').'

'; $query="SELECT * FROM $language_table order by LanguageName"; $Languages=$wpdb->get_results($query, ARRAY_A); if (!$Languages) { echo '

'.__('No languages defined, please define some first','zd_multilang').'

'; return; } $DefaultLanguage=$ZdmlCache['DefLang']; if ($_POST['id']) { $ID=$_POST['id']; $Lang=$_POST['lang']; $Content=$_POST['content']; $Title=$_POST['post_title']; $Status=$_POST['post_status']; $Excerpt=$_POST['post_excerpt']; $var=$wpdb->get_var("SELECT ID from $posttrans WHERE ID='$ID' and LanguageID='$Lang'"); if ($var==$ID) { $query="UPDATE $posttrans set post_content='$Content', post_title='$Title', post_status='$Status', post_excerpt='$Excerpt' WHERE ID='$ID' and LanguageID='$Lang'"; } else $query="INSERT INTO $posttrans (`ID`, `LanguageID`, `post_content`, `post_title`, `post_status`, `post_excerpt`) values ('$ID', '$Lang', '$Content', '$Title','$Status', '$Excerpt')"; $wpdb->query($query); echo '

'; echo __('Post or Page updated','zd_multilang'); echo '


'; $_GET['id']=$_POST['id']; $_GET['lang']=$_POST['lang']; } if ($_GET['id']) { $query='SELECT * FROM '.$wpdb->prefix.'posts WHERE ID='.$_GET['id']; $res=$wpdb->get_results($query); $OriginalText=str_replace(array("\r","\n"),array ("",""), strip_tags($res[0]->post_content)); $Lang=$_GET['lang']; echo '
'; $query="SELECT * FROM $posttrans WHERE LanguageID='$Lang' and ID=".$_GET['id']; $res=$wpdb->get_results($query, ARRAY_A); if ($res[0]['post_status']==NULL) $res[0]['post_status']='draft'; $From=array_search($DefaultLanguage,$ZdmlCache['Languages']); $To=array_search($_GET['lang'],$ZdmlCache['Languages']); echo ' '; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '


'; echo '
'; echo '
'; echo '
'; echo '

'.__('Title','zd_multilang').'

'; echo '
'; echo '
'; echo '
'; echo '

'.__('Translations','zd_multilang').'

'; echo ''; the_editor($res[0]['post_content']); echo '
'; echo '

'.__('Excerpt','zd_multilang').'

'; echo '
'; echo '

'; echo '
'; } else if ($_GET['tr']) { switch ($_GET['tr']) { case 'posts': $query='SELECT * FROM '.$wpdb->prefix.'posts WHERE post_type="post" order by post_status, post_date desc'; break; case 'pages': $query='SELECT * FROM '.$wpdb->prefix.'posts WHERE post_type="page" order by post_status, post_date desc'; break; default: $query=""; break; } $q="SELECT * from $posttrans order by ID"; $Translated=$wpdb->get_results($q, ARRAY_A); if ($Translated) foreach ($Translated as $Idx => $Row) { $Posts[$Row['ID']][$Row['LanguageID']]=$Row['post_status']; } $results=$wpdb->get_results($query, ARRAY_A); if ($results) { echo ''; echo ''; foreach ($Languages as $Lang) { if ($Lang['LanguageID']!=$DefaultLanguage) echo ''; } echo ''; foreach ($results as $ID => $row) { echo ''; echo ''; echo ''; foreach ($Languages as $Lang) { if ($Lang['LanguageID']!=$DefaultLanguage) { echo ''; } } echo ''; } echo '
'.__('Original title','zd_multilang').''.__('Published date', 'zd_multilang').''.$Lang['LanguageName'].'
'.$row['post_title'].''.date_i18n(get_option('date_format').' - '.get_option('time_format'),strtotime($row['post_date'])).''; if ($Posts[$row['ID']][$Lang['LanguageID']]) echo ' '.__($Posts[$row['ID']][$Lang['LanguageID']],'zd_multilang'); else echo ' '.__('Translate','zd_multilang'); echo '
'; } } else { $query="SELECT distinct(ID) from $posttrans"; $res=$wpdb->get_results($query); foreach ($res as $Line) { $count++; } printf(__('%d posts or pages are translated','zd_multilang'),$count); } } function zd_multilang_link_translations() { global $ZdmlCache, $locale; global $BaseURL, $wpdb,$default_language_option,$PluginDIR; $language_table= $wpdb->prefix.'zd_ml_langs'; $termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $linktrans=$wpdb->prefix.'zd_ml_linktrans'; $hidden_field="zd_multilang_edit_link"; echo "

".__('Links','zd_multilang').'

'; $DefLang=get_option($default_language_option); if (isset($_POST['link_id'])) { $_GET['link_id']=$_POST['link_id']; $url=$_POST['link_url']; $name=$_POST['link_name']; $description=$_POST['link_description']; $Language=$_POST['lng']; $link_id=$_POST['link_id']; $check="SELECT count(*) from $linktrans where link_id=$link_id and LanguageID='$Language'"; $res=$wpdb->get_var($check); if ($res) $query="UPDATE $linktrans set link_name='$name', link_url='$url', link_description='$description' WHERE link_id=$link_id and LanguageID='$Language'"; else $query="INSERT INTO $linktrans VALUES ($link_id, '$Language', '$url', '$name', '$description')"; $wpdb->query($query); } if (isset($_GET['link_id'])) { $Language=$_GET['lng']; $link_id=$_GET['link_id']; $query="SELECT l.link_id, lt.link_url, lt.link_name, lt.link_description, lt.LanguageID, l.link_url o_url, l.link_name o_name, l.link_description o_desc FROM $linktrans lt RIGHT JOIN $wpdb->links l on (l.link_id=lt.link_id) where l.link_id=$link_id"; $results=$wpdb->get_results($query); $found=0; if ($results) { foreach ($results as $Link) { if ($Link->LanguageID==$Language) { $found=1; break; } } if (!$found) { $Link->link_name=""; $Link->link_url=""; $Link->link_description=""; } echo '
'.$Link->o_name.' '.$Link->o_url.' '.$Link->o_desc.'
'; echo '

'; } } else { $query="SELECT l.link_id, lt.LanguageID, lt.link_name, l.link_url o_url, l.link_name o_name FROM $linktrans lt RIGHT JOIN $wpdb->links l on (l.link_id=lt.link_id)"; $results=$wpdb->get_results($query); if ($results) foreach ($results as $row) { $Link[$row->link_id]['name_'.$row->LanguageID]=$row->link_name; $Link[$row->link_id]['o_name']=$row->o_name; $Link[$row->link_id]['o_url']=$row->o_url; } echo ''; echo ''; foreach ($ZdmlCache['Languages'] as $LanguageID => $Lang) { if ($Lang!=$DefLang) echo ''; } echo ''; if ($Link) foreach ($Link as $link_id => $L) { echo ''; echo ''; foreach ($ZdmlCache['Languages'] as $LanguageID => $Lang) { if ($Lang!=$DefLang) echo ''; } echo ''; } echo '
'.__('Original Link','zd_multilang').' '.$ZdmlCache['LanguageNames'][$LanguageID].'
'.$L['o_name'].' '.__('Translate','zd_multilang').'
'; } } function zd_multilang_term_translations() { global $ZdmlCache; global $BaseURL, $wpdb,$default_language_option,$PluginDIR; $language_table= $wpdb->prefix.'zd_ml_langs'; $termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $hidden_field="zd_multilang_edit_translation"; echo "

".__('Translations','zd_multilang').'

'; $Option=$_GET['tr']; $DefaultLanguage=$ZdmlCache['DefLang']; $query="SELECT * FROM $language_table order by LanguageName"; $Languages=$wpdb->get_results($query, ARRAY_A); if (!$Languages) { echo '

'.__('No languages defined, please define some first','zd_multilang').'

'; return; } if ($_POST[$hidden_field]=="update") { $termid=$_POST['term_id']; $Option=$_POST['tr']; foreach ($Languages as $Lang) { if ($Lang['LanguageID']!=$DefaultLanguage) { $LangID=$Lang['LanguageID']; $Translation=$_POST[$termid."_".$LangID]; $Desc=$_POST['desc_'.$termid."_".$LangID]; $query="SELECT name FROM $termtrans_table WHERE LanguageID='$LangID' and term_id='$termid' "; $oldvalue=$wpdb->get_var($query); if ($oldvalue) { $query="UPDATE $termtrans_table set name='$Translation', description='$Desc' where term_id=$termid and LanguageID='$LangID'"; } else { if ($Translation) $query="INSERT INTO $termtrans_table VALUES ('$termid','$LangID','$Translation', '$Desc')"; } $wpdb->query($query); $_GET['id']=$termid; } } } if ($_GET['id']) { $term_id=$_GET['id']; $query="SELECT t.name, tt.term_id, tt.description FROM ".$wpdb->prefix."term_taxonomy tt, ".$wpdb->prefix."terms t WHERE t.term_id=tt.term_id and t.term_id=".$term_id." order by name"; $res=$wpdb->get_row($query, ARRAY_A); $query="SELECT * FROM $termtrans_table WHERE term_id=$term_id"; $Trans=$wpdb->get_results($query, ARRAY_A); if ($Trans) foreach ($Trans as $Values) { $Translations[$Values['LanguageID']]['term']=$Values['name']; $Translations[$Values['LanguageID']]['desc']=$Values['description']; } echo '
'; echo "\n\t".''; echo "\n\t".''; echo "\n\t".''; echo "\n\t".''; echo "\n\t".''; echo ''; foreach ($Languages as $Lang) { if ($Lang['LanguageID']!=$DefaultLanguage) { echo ''; echo ''; echo ''; echo ''; echo ''; } } echo '
'.__('Original Term','zd_multilang').''.$res['name'].''.$res['description'].'
'.$Lang['LanguageName'].'
'; echo "\n\t".'

'; echo "
"; } else { switch ($Option) { default: $Option="cat"; case 'cat': $query="SELECT t.name, tt.term_id FROM ".$wpdb->prefix."term_taxonomy tt, ".$wpdb->prefix."terms t WHERE t.term_id=tt.term_id and taxonomy='category' order by name"; $Results=$wpdb->get_results($query, ARRAY_A); break; case 'tags': $query="SELECT t.name, tt.term_id FROM ".$wpdb->prefix."term_taxonomy tt, ".$wpdb->prefix."terms t WHERE t.term_id=tt.term_id and taxonomy='post_tag' order by name"; $Results=$wpdb->get_results($query, ARRAY_A); break; case 'linkcat': $query="SELECT t.name, tt.term_id FROM ".$wpdb->prefix."term_taxonomy tt, ".$wpdb->prefix."terms t WHERE t.term_id=tt.term_id and taxonomy='link_category' order by name"; $Results=$wpdb->get_results($query, ARRAY_A); break; } if ($Results) { foreach ($Results as $Line) { $in.=$Line['term_id'].","; } $in=substr($in, 0, -1); $query="SELECT * FROM $termtrans_table WHERE term_id in ($in)"; $Trans=$wpdb->get_results($query, ARRAY_A); if ($Trans) foreach ($Trans as $Values) { $Translations[$Values["term_id"]][$Values['LanguageID']]=$Values['name']; } echo ''; echo ''; foreach ($Languages as $Lang) { if ($Lang['LanguageID']!=$DefaultLanguage) echo ''; } echo ''; foreach ($Results as $Id => $Value) { $term_id=$Value['term_id']; echo ''; foreach ($Languages as $Lang) { if ($Lang['LanguageID']!=$DefaultLanguage) echo ''; } echo ''; } echo '
 '.__('Original Term','zd_multilang').' '.$Lang['LanguageName'].'
'.$Value['name'].''.$Translations[$term_id][$Lang['LanguageID']].'
'; } } } function zd_multilang_translate_term($args="", $taxonomy="") { global $ZdmlCache, $locale; global $BaseURL, $wpdb,$default_language_option,$PluginDIR,$CurrentLanguagePermalink,$CurrentLang; if ($ZdmlCache['DefLang']==$locale) return $args; if ($ZdmlCache['Terms']) { if ($ZdmlCache['Terms'][$args->term_id][$locale]) { $args->cat_name=$ZdmlCache['Terms'][$args->term_id][$locale]['name']; $args->name=$ZdmlCache['Terms'][$args->term_id][$locale]['name']; $args->description=$ZdmlCache['Terms'][$args->term_id][$locale]['description']; } } return $args; } function zd_multilang_translate_link_cat($terms="") { global $ZdmlCache, $locale; global $BaseURL, $wpdb,$default_language_option,$PluginDIR,$CurrentLanguagePermalink,$CurrentLang; $language_table= $wpdb->prefix.'zd_ml_langs'; $termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $DefaultLanguage=$ZdmlCache['DefLang']; if ($ZdmlCache['DefLang']==$locale) return $terms; $termes=explode("\n",$terms); $term_list=""; foreach ($termes as $ID => $term) { preg_match_all("|(.*)(.*)|i", $term,$res); $t=""; foreach ($ZdmlCache['Terms'] as $termid => $Values) { foreach ($Values as $LangID => $V) { if (($t=="")&&($LangID==$locale)&&($V['o_name']==$res[2][0])) { $t=$V['name']; } } } if ($t=="") $term_list.=$res[0][0]; else $term_list.=$res[1][0].$t."\n"; } return $term_list."\n"; } function zd_multilang_postlink($arg) { global $locale, $ZdmlCache, $wpdb; $posttrans=$wpdb->prefix.'zd_ml_trans'; preg_match_all("|(.*)(.*)(.*)|ms",$arg,$res); $postname=$res[2][0]; $query="SELECT pt.post_title FROM $posttrans pt, $wpdb->posts p WHERE pt.ID=p.ID and LanguageID='".$locale."' AND p.post_title='$postname' and pt.post_status='published'"; $title=$wpdb->get_var($query); $link=$res[1][0]; if ($title) return $link.$title.$res[3][0]; return $arg; } function zd_multilang_translate_cat($term="") { global $ZdmlCache, $locale; global $BaseURL, $wpdb,$default_language_option,$PluginDIR,$CurrentLanguagePermalink,$CurrentLang; $language_table= $wpdb->prefix.'zd_ml_langs'; $termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $DefaultLanguage=$ZdmlCache['DefLang']; if ($ZdmlCache['DefLang']==$locale) return $term; if ($ZdmlCache['Terms']) { foreach ($ZdmlCache['Terms'] as $TermID => $V) { foreach ($ZdmlCache['Terms'][$TermID] as $Language => $V) { if (($Language==$locale)&&($V['o_name']==$term)) { return $V['name']; } } } } return $term; } function zd_multilang_cat($arg) { global $ZdmlCache, $locale; $termid=$arg->term_id; if (isset($ZdmlCache['Terms'][$termid][$locale])) { $arg->name=$ZdmlCache['Terms'][$termid][$locale]['name']; $arg->description=$ZdmlCache['Terms'][$termid][$locale]['description']; $arg->category_description=$ZdmlCache['Terms'][$termid][$locale]['description']; } return $arg; } function zd_multilang_cat_desc($arg, $arg2) { if (is_object($arg2)) { $cat=zd_multilang_cat($arg2); return $cat->description; } return $arg; } function zd_multilang_translate_bookmarks($links) { global $ZdmlCache, $locale; if (!is_admin()) { foreach ($links as $Idx => $Datas) { $termid=$Datas->term_taxonomy_id; $linkid=$Datas->link_id; if ($ZdmlCache['Terms'][$termid][$locale]['description']) $links[$Idx]->description=$ZdmlCache['Terms'][$termid][$locale]['description']; if ($ZdmlCache['Links'][$linkid][$locale]['description']) $links[$Idx]->link_description=$ZdmlCache['Links'][$linkid][$locale]['description']; if ($ZdmlCache['Links'][$linkid][$locale]['name']) $links[$Idx]->link_name=$ZdmlCache['Links'][$linkid][$locale]['name']; if ($ZdmlCache['Links'][$linkid][$locale]['url']) $links[$Idx]->link_url=$ZdmlCache['Links'][$linkid][$locale]['url']; } } return $links; } //EG : Really small change here for compliance with the way wordpress compute the widget name. function zd_multilang_translate_list_bookmarks($bm) { global $ZdmlCache, $locale; $bookmarks=explode("\n",$bm); $bm_return=array(); foreach ($bookmarks as $line) { //EG : Change preg_match in order to use it in widgets.php in admin mode if (preg_match_all('#(|%BEG_OF_TITLE%)(.*)(|%END_OF_TITLE%)#U',$line,$res)) { $bm_return[]=$res[1][0].zd_multilang_translate_cat($res[2][0]).$res[3][0]; } else { $bm_return[]=$line; } } return implode("\n",$bm_return); } function zd_multilang_translate_post($posts) { global $ZdmlCache; global $BaseURL, $wpdb, $default_language_option, $wp_query, $wp_rewrite,$insert_lang_switch_option,$CurrentLanguagePermalink,$CurrentLang; global $locale, $display_google_translate_option; $language_table= $wpdb->prefix.'zd_ml_langs'; $termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $posttrans=$wpdb->prefix.'zd_ml_trans'; $Lang = $CurrentLanguagePermalink; if ($Lang=="") $Language=$ZdmlCache['DefLang']; $Language=$CurrentLang; if ($ZdmlCache['DefLang']!=$CurrentLang) { foreach ($posts as $Idc => $Post) { $post_list.=$Post->ID.','; } $post_list=substr($post_list,0, -1); $query="SELECT post_content, post_title, ID, post_excerpt FROM $posttrans WHERE LanguageID='".$Language."' AND ID in (".$post_list.") AND post_status='published'"; $rows=$wpdb->get_results($query, ARRAY_A); if ($rows) foreach ($rows as $Id => $P) { $row[$P['ID']]->post_content=$P['post_content']; $row[$P['ID']]->post_title=$P['post_title']; $row[$P['ID']]->post_excerpt=$P['post_excerpt']; } } foreach ($posts as $Idx => $Post) { $postid=$Post->ID; if ($row[$Post->ID]) { $posts[$Idx]->post_content=$row[$Post->ID]->post_content; $posts[$Idx]->post_excerpt=$row[$Post->ID]->post_excerpt; if ($ZdmlCache['SwitcherPosition']=="footer") $posts[$Idx]->post_content.=zd_multilang_lang_switcher($posts[$Idx]->ID); else $posts[$Idx]->post_content=zd_multilang_lang_switcher($posts[$Idx]->ID).$posts[$Idx]->post_content; $posts[$Idx]->post_title=$row[$Post->ID]->post_title; } else { if ((!zd_multilang_is_translated($postid,$Language))&&($ZdmlCache['DefLang']!=$locale)&&(get_option($display_google_translate_option)=="show")) { $posts[$Idx]->post_content="

".__('Translate original post with Google Translate',"zd_multilang").'

' .$posts[$Idx]->post_content; } if ($ZdmlCache['SwitcherPosition']=="footer") $posts[$Idx]->post_content.=zd_multilang_lang_switcher($posts[$Idx]->ID); else $posts[$Idx]->post_content=zd_multilang_lang_switcher($posts[$Idx]->ID).$posts[$Idx]->post_content; } } return $posts; } function zd_multilang_translate_tags($Tags) { global $ZdmlCache; global $BaseURL, $wpdb,$default_language_option,$PluginDIR,$CurrentLanguagePermalink,$CurrentLang; $language_table= $wpdb->prefix.'zd_ml_langs'; $termtrans_table = $wpdb->prefix.'zd_ml_termtrans'; $Lang = $CurrentLanguagePermalink; if ($Lang=="") $Language=$ZdmlCache['DefLang']; $Language=$CurrentLang; if ($ZdmlCache['DefLang']==$CurrentLang) return $Tags; foreach ($Tags as $ID => $args) { if ($ZdmlCache['Terms']) { foreach ($ZdmlCache['Terms'] as $TermID => $V) { if (($TermID==$args->term_id) and ($V['LanguageID']==$Language)) $Tags[$ID]->name=$V['name']; } } } return $Tags; } function zd_multilang_lang_switcher($post_id) { global $ZdmlCache; global $wpdb,$wp_rewrite,$display_untranslated_option; global $insert_lang_switch_option,$insert_lang_switch_option,$show_flags_option,$show_languages_option,$lang_switcher_class_option,$permalink_default_option, $locale; if (get_option($insert_lang_switch_option)=="show") { $PluginDIR = get_bloginfo('wpurl').'/'.PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)); $language_table= $wpdb->prefix.'zd_ml_langs'; $langswitch_class=get_option($lang_switcher_class_option); if ($langswitch_class) $class=' class="'.$langswitch_class.'"'; $retour=""; if (!isset($ZdmlCache['Languages'])) { $query="SELECT * FROM $language_table ORDER BY LanguageName"; $results=$wpdb->get_results($query, ARRAY_A); if ($results) { foreach ($results as $ID => $V) $ZdmlCache['Languages'][$V['LangPermalink']]=$V['LanguageID']; } } else { foreach ($ZdmlCache['Languages'] as $Permalink => $LangID) { $results[$i]['LangPermalink']=$Permalink; $results[$i]['LanguageID']=$LangID; $i++; } } if ($results) { foreach ($results as $ID => $Lang) { $regexp.=$Lang['LangPermalink']."|"; } $regexp=substr($regexp, 0, -1); } $QUERY=get_permalink($post_id); if ($results) foreach ($results as $ID => $row) { if (get_option($permalink_default_option)=="no") { $regexp=""; if ($results) { foreach ($results as $ID => $Lang) { if ($Lang['LanguageID']!=$ZdmlCache['DefLang']) $regexp.=$Lang['LangPermalink']."|"; } $regexp=substr($regexp, 0, -1); } if ($wp_rewrite->using_permalinks()) { if ($ZdmlCache['DefLang']==$row['LanguageID']) $QUERY=preg_replace("`".get_bloginfo('url')."\/($regexp)\/(.*)`U",get_bloginfo('url')."/${3}",$QUERY); else { if ($locale==$ZdmlCache['DefLang']) { $QUERY=preg_replace("`".get_bloginfo('url')."\/(.*)`U",get_bloginfo('url').'/'.$row['LangPermalink']."/${2}",$QUERY); } else $QUERY=preg_replace("`".get_bloginfo('url')."\/($regexp)\/(.*)`U",get_bloginfo('url').'/'.$row['LangPermalink']."/${3}",$QUERY); } } else { if ($ZdmlCache['DefLang']==$row['LanguageID']) $QUERY=preg_replace("`(".get_bloginfo('url')."\/.*)&lang=($regexp)(.*)`U",'${1}'."${3}",$QUERY); else { if ($locale==$ZdmlCache['DefLang']) { $QUERY=preg_replace("`(".get_bloginfo('url')."\/.*)$`U",'${1}&lang='.$row['LangPermalink'],$QUERY); } else $QUERY=preg_replace("`(".get_bloginfo('url')."\/.*lang=)($regexp)(.*)`U",'${1}'.$row['LangPermalink']."${3}",$QUERY); } } } else { if ($wp_rewrite->using_permalinks()) { if ($QUERY!=get_bloginfo('url').'/') $QUERY=preg_replace("`".get_bloginfo('url')."\/($regexp)\/(.*)`U",get_bloginfo('url').'/'.$row['LangPermalink']."/${3}",$QUERY); else $QUERY.=$row['LangPermalink'].'/'; } else { $QUERY=preg_replace("`(".get_bloginfo('url')."\/.*lang=)($regexp)(.*)`U",'${1}'.$row['LangPermalink']."${3}",$QUERY); } } if ((zd_multilang_is_translated($post_id,$row['LanguageID']))&&($locale!=$row['LanguageID'])) { $retour.=""; $retour.=''; if (get_option($show_flags_option)=="show") $retour.=''.$ZdmlCache['LanguageNames'][$row['LangPermalink']].''; if (get_option($show_languages_option)=="show") $retour.=$ZdmlCache['LanguageNames'][$row['LangPermalink']]; $retour.=''; $retour.=''; } } $retour.=''; return $retour; } return ""; } /******** Short Circuit Options ********/ function zd_multilang_blogname($value) { $v=zd_multilang_get_option("blogname"); if ($v) return $v; return zd_multilang_get_option_direct("blogname"); } function zd_multilang_blogdescription($value) { $v=zd_multilang_get_option("blogdescription"); if ($v) return $v; return zd_multilang_get_option_direct("blogdescription"); } //EG : I get the value in the standard option repository. It's an array of sidebar, so I should get sidebars for every //EG : language with this naming convention : sidebar-1-_-fr_FR, sidebar-1-_-en_US, sidebar-1-_-es_ES //EG : So I have : //EG : - to give only the good one(s) with its original name (to be transparent) if I'm just reading the blog //EG : - to send all of the sidbars in the requested language if I'm in the admin mode //EG : If the option doesn't exist I try to build something with the true sidebars_widgets option. No bet it will work. function zd_multilang_get_sidebars_widgets ($value) { //EG : As explained, I need to know if I'm in the admin mode $widget_admin = strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false ? 1 : 0; //EG : In case I am, I need to know the locale the user requests to change, either I answer the current locale $true_locale=isset($GLOBALS['Zdml_ask_language']) ? $GLOBALS['Zdml_ask_language'] : $GLOBALS['locale']; $v=get_option("zd_multilang_sidebars_widgets"); if (is_array($v)) { foreach ($v as $sidebar_id => $sidebar) { if ($sidebar_id !== 'array_version') { list($id,$langcode)=explode("-_-",$sidebar_id); //EG : If I'm in admin mode I need to know the language. //EG : The only solution is to use our sidebar name as explained above. $id = $widget_admin ? $sidebar_id : $id; if (strtolower($true_locale)===$langcode) { $return_sidebars_widgets[$id]=$sidebar; } } } $return_sidebars_widgets['array_version']=$v['array_version']; return $return_sidebars_widgets; } else //EG : We did never register this option in zd_multilang before { $v=zd_multilang_get_option_direct("sidebars_widgets"); if ($widget_admin) { foreach ($v as $sidebar_id => $sidebar) { if ($sidebar_id !== 'array_version') { $return_sidebars_widgets[strtolower($sidebar_id."-_-".$true_locale)]=$sidebar; } } $return_sidebars_widgets['array_version']=$v['array_version']; return $return_sidebars_widgets; } else { return $v; } } } //EG : If we set sidebars_widgets option, it means we are in the administration interface function zd_multilang_set_sidebars_widgets($newvalue) { //EG : We're getting the old value adding or applying changes. $oldvalue=zd_multilang_get_option_direct("zd_multilang_sidebars_widgets"); foreach ($newvalue as $sidebar_id => $sidebar) { if ($sidebar_id !== 'array_version') { $oldvalue[$sidebar_id]=$sidebar; } } $oldvalue['array_version']=$newvalue['array_version']; update_option('zd_multilang_sidebars_widgets',$oldvalue); return $oldvalue; } //EG : This function is no more use can we suppres it ? /* function zd_multilang_option($optionname) { global $locale, $ZdmlCache; return $ZdmlCache['Options'][$locale][$optionname]; } */ //EG : Inspired by the wordpress one just add the locale to the option name in alloption and so on... function zd_multilang_get_option( $setting, $default = false ) { global $wpdb; // Be carefull here $locale variable is local $locale=isset($GLOBALS['Zdml_ask_language']) ? $GLOBALS['Zdml_ask_language'] : $GLOBALS['locale']; $options_table = $wpdb->prefix."zd_ml_options"; $notoptions = wp_cache_get( 'notoptions', 'options' ); //EG : We are here because we hope to find this option specified in the zdml_options table. We will work with //EG : $locale.$setting. So $setting alone is for sure a notoptions (even if it's in the common option table). if (! isset( $notoptions[$setting] ) ) { $notoptions[$setting] = true; wp_cache_set( 'notoptions', $notoptions, 'options' ); } // prevent non-existent options from triggering multiple queries if ( isset( $notoptions[$locale.$setting] ) ) return $default; $alloptions = zd_multilang_wp_load_alloptions(); //EG : We are here because we hope to find this option specified in the zdml_options table. We will work with //EG : $locale.$setting. So $setting alone can cleanly be removed from alloptions. If it's here it's because //EG : it's coming from the common options table and not the zdml_options one. if ( isset( $alloptions[$setting] ) ) { unset( $alloptions[$setting] ); wp_cache_set( 'alloptions', $alloptions, 'options' ); } if ( isset( $alloptions[$locale.$setting] ) ) { $value = $alloptions[$locale.$setting]; } else { $value = wp_cache_get( $locale.$setting, 'options' ); if ( false === $value ) { if ( defined( 'WP_INSTALLING' ) ) $suppress = $wpdb->suppress_errors(); // expected_slashed ($setting) $row = $wpdb->get_row( "SELECT option_value FROM $options_table WHERE option_name = '$setting' and LanguageID='$locale' LIMIT 1" ); if ( defined( 'WP_INSTALLING' ) ) $wpdb->suppress_errors($suppress); if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values $value = $row->option_value; wp_cache_add( $locale.$setting, $value, 'options' ); } else { // option does not exist, so we must cache its non-existence $notoptions[$locale.$setting] = true; wp_cache_set( 'notoptions', $notoptions, 'options' ); return $default; } } } // If home is not set use siteurl. if ( 'home' == $setting && '' == $value ) return get_option( 'siteurl' ); if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) ) $value = untrailingslashit( $value ); return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) ); } //EG : Inspired by the wordpress one just add the locale to the option name in alloption and so on... //EG : Remark : Always returns the $oldvalue option name for compliance with the pre_update_option filter call function zd_multilang_update_option( $option_name, $newvalue ) { global $wpdb; // Be carefull here $locale variable is local $locale=isset($GLOBALS['Zdml_ask_language']) ? $GLOBALS['Zdml_ask_language'] : $GLOBALS['locale']; $options_table = $wpdb->prefix."zd_ml_options"; wp_protect_special_option( $option_name ); $safe_option_name = $wpdb->escape( $option_name ); $newvalue = sanitize_option( $option_name, $newvalue ); //EG : Maybe we should use zd_multilang_get_option here for easier comprehension but it's more generic like this $oldvalue = get_option( $safe_option_name ); // If the new and old values are the same, no need to update. if ( $newvalue === $oldvalue ) return $oldvalue; if ( false === $oldvalue ) { zd_multilang_add_option( $option_name, $newvalue ); return $oldvalue; } $notoptions = wp_cache_get( 'notoptions', 'options' ); if ( is_array( $notoptions ) && isset( $notoptions[$locale.$option_name] ) ) { unset( $notoptions[$locale.$option_name] ); wp_cache_set( 'notoptions', $notoptions, 'options' ); } $_newvalue = $newvalue; $newvalue = maybe_serialize( $newvalue ); $alloptions = zd_multilang_wp_load_alloptions(); if ( isset( $alloptions[$locale.$option_name] ) ) { $alloptions[$locale.$option_name] = $newvalue; wp_cache_set( 'alloptions', $alloptions, 'options' ); } else { wp_cache_set( $locale.$option_name, $newvalue, 'options' ); } $wpdb->query( $wpdb->prepare( "UPDATE $options_table SET option_value='%s' WHERE LanguageID='%s' and option_name='%s' ", $newvalue, $locale, $option_name ) ); if ( $wpdb->rows_affected == 1 ) { do_action( "update_option_{$option_name}", $oldvalue, $_newvalue ); } return $oldvalue; } //EG : Inspired by the wordpress one just add the locale to the option name in alloption and so on... function zd_multilang_add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) { global $wpdb; // Be carefull here $locale variable is local $locale=isset($GLOBALS['Zdml_ask_language']) ? $GLOBALS['Zdml_ask_language'] : $GLOBALS['locale']; $options_table = $wpdb->prefix."zd_ml_options"; wp_protect_special_option( $name ); $safe_name = $wpdb->escape( $name ); $value = sanitize_option( $name, $value ); // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query $notoptions = wp_cache_get( 'notoptions', 'options' ); if ( !is_array( $notoptions ) || !isset( $notoptions[$locale.$name] ) ) if ( false !== get_option( $safe_name ) ) return; $value = maybe_serialize( $value ); $autoload = ( 'no' === $autoload ) ? 'no' : 'yes'; if ( 'yes' == $autoload ) { $alloptions = zd_multilang_wp_load_alloptions(); $alloptions[$locale.$name] = $value; wp_cache_set( 'alloptions', $alloptions, 'options' ); } else { wp_cache_set( $name, $locale.$value, 'options' ); } // This option exists now $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh if ( is_array( $notoptions ) && isset( $notoptions[$locale.$name] ) ) { unset( $notoptions[$locale.$name] ); wp_cache_set( 'notoptions', $notoptions, 'options' ); } $wpdb->query( $wpdb->prepare( "INSERT INTO $options_table (LanguageID, option_name, option_value, autoload) VALUES (%s, %s, %s, %s)", $locale, $name, $value, $autoload ) ); do_action( "add_option_{$name}", $name, $value ); return; } //EG : Inspired by the wordpress one just add the locale to the option name in alloption and so on... function zd_multilang_wp_load_alloptions() { global $wpdb; // Be carefull here $locale variable is local $locale=isset($GLOBALS['Zdml_ask_language']) ? $GLOBALS['Zdml_ask_language'] : $GLOBALS['locale']; $options_table = $wpdb->prefix."zd_ml_options"; $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( !$alloptions['zd_multilang'.$locale] ) { $suppress = $wpdb->suppress_errors(); if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $options_table WHERE autoload = 'yes' and LanguageID='$locale'" ) ) $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $options_table WHERE LanguageID='$locale'" ); $wpdb->suppress_errors($suppress); //EG We are adding so we comment this //$alloptions = array(); foreach ( (array) $alloptions_db as $o ) $alloptions[$locale.$o->option_name] = $o->option_value; $alloptions['zd_multilang'.$locale]=1; //EG We are adding so we use wp_cache_replace instead of wp_cache_add wp_cache_replace( 'alloptions', $alloptions, 'options' ); } return $alloptions; } //EG : Simple copy/paste of the get_option function. Did just remove the first shortcut filter, pratical to get //EG : the value in the wp_option table despite our hooks. function zd_multilang_get_option_direct( $setting, $default = false ) { global $wpdb; // prevent non-existent options from triggering multiple queries $notoptions = wp_cache_get( 'notoptions', 'options' ); if ( isset( $notoptions[$setting] ) ) return $default; $alloptions = wp_load_alloptions(); if ( isset( $alloptions[$setting] ) ) { $value = $alloptions[$setting]; } else { $value = wp_cache_get( $setting, 'options' ); if ( false === $value ) { if ( defined( 'WP_INSTALLING' ) ) $suppress = $wpdb->suppress_errors(); // expected_slashed ($setting) $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" ); if ( defined( 'WP_INSTALLING' ) ) $wpdb->suppress_errors($suppress); if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values $value = $row->option_value; wp_cache_add( $setting, $value, 'options' ); } else { // option does not exist, so we must cache its non-existence $notoptions[$setting] = true; wp_cache_set( 'notoptions', $notoptions, 'options' ); return $default; } } } // If home is not set use siteurl. if ( 'home' == $setting && '' == $value ) return get_option( 'siteurl' ); if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) ) $value = untrailingslashit( $value ); return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) ); } /******* Sidebars *******/ //EG : Small function I use to verify the given field field and return the right locale code function get_right_locale($locale) { global $ZdmlCache; foreach ($ZdmlCache['Languages'] as $lang_code) if (strtolower($locale)==strtolower($lang_code)) return $lang_code; return false; } //EG : Small function to switch language in real time function switch_language($language) { global $locale; //EG : Need that to change the language global $l10n; //EG : Need to unset that if I change the language global $Zdml_initial_language; //EG : Need to remember initial language, before language switch //EG : Remember the initial language $Zdml_initial_language=$locale; //EG : Change the language $locale = $language; //EG : Forget the current language before re-setting it. $l10n=array(); //EG : Inspired by wp-settings.php load_default_textdomain(); $locale_file = WP_LANG_DIR . "/$locale.php"; if ( is_readable($locale_file) ) require_once($locale_file); // Pull in locale data after loading text domain. require_once(ABSPATH . WPINC . '/locale.php'); $wp_locale =& new WP_Locale(); } //EG : Another function to switch back to the original language in real-time. function reswitch_lang_to_finish () { global $Zdml_initial_language; //EG : Need to reset the language to the initial one switch_language($Zdml_initial_language); } //EG : This function show the language switcher in the widget admin page. function switch_lang_sidebar_admin_setup_display () { global $ZdmlCache, $locale, $PluginDIR, $Zdml_ask_language; //EG : I change the language, I will reset it after at the end of the page (always for widgets.php) if ($Zdml_ask_language !== $locale) { switch_language($Zdml_ask_language); //EG : I'm forced to reinit the widget if I want them in the good language. wp_widgets_init(); } echo '
'; echo ''.__('Language Switcher','zd_multilang')." : "; foreach ( (array) $ZdmlCache['Languages'] as $perma => $code) { echo ''; } echo '
'; } //EG : Important function to get the request language to work with sidebar function switch_lang_sidebar_admin_setup () { global $wp_registered_sidebars; //EG : Need it to remove unsued sidebar regarding the requestes language global $locale; //EG : Need that to know if I have to change the language global $ZdmlCache; //EG : Need to get the DefLang, maybe we could have use $locale : in wordpress administration mode we should always have $locale=$ZdmlCache['DefLang'] global $Zdml_ask_language; //EG : Need it communicate with other function regarding the requested language //EG : Somebody asked for a language change if ( isset($_GET['sidebar_locale']) && get_right_locale($_GET['sidebar_locale']) ) { $ask_language=$_GET['sidebar_locale']; } //EG : Else somebody ask for a change on a sidebar and so I know which is the language elseif ( isset($_GET['sidebar']) ) { list($id,$ask_language)=explode("-_-",$_GET['sidebar']); } //EG : I set it to the language default else { $ask_language=$ZdmlCache['DefLang']; } $ask_language = get_right_locale($ask_language); //EG : Maybe I got it in lowercase so I need to get the right one //EG : I can set the $Zdml_ask_language as I know it now. I will need it in the admin_notices hook. $Zdml_ask_language = $ask_language; //EG : I rebuild a $wp_registered_sidebars with ower naming convention in order to work with $wp_registered_widgets foreach ($wp_registered_sidebars as $sidebar) { $sidebar_tempo=$sidebar; $sidebar_tempo['id']=strtolower($sidebar_tempo['id']."-_-".$ask_language); $return_registered_sidebars[$sidebar_tempo['id']]=$sidebar_tempo; } $wp_registered_sidebars=$return_registered_sidebars; //EG : We will display the language switcher just at the good time (no trouble with ob_start involved in widget.php) add_action('admin_notices', 'switch_lang_sidebar_admin_setup_display'); //EG : I want to print the rest of the page in the correct language add_action('sidebar_admin_page','reswitch_lang_to_finish'); } add_action( 'sidebar_admin_setup','switch_lang_sidebar_admin_setup'); /******* Widgets *******/ function zd_multilang_menu($show_name=true) { global $wpdb, $wp_rewrite, $locale; // ... MG - Oct. 27, 2008 - need locale for check below ... $PluginDIR = get_bloginfo('wpurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)); $language_table = $wpdb->prefix.'zd_ml_langs'; $query="SELECT * FROM $language_table ORDER BY LanguageName"; $results=$wpdb->get_results($query, ARRAY_A); if ($results) { foreach ($results as $ID => $Lang) { $regexp.=$Lang['LangPermalink']."|"; } $regexp=substr($regexp, 0, -1); } $retour=""; if ($results) foreach ($results as $ID => $row) { if ($wp_rewrite->using_permalinks()) { // ... MG - Oct. 27, 2008 - not on the home page when switching language - deal with it ... if ( is_home() && !is_paged() ) $QUERY=get_bloginfo('url').'/'.$row['LangPermalink'].'/'; else $QUERY=str_replace('/'.substr($locale,0,2).'/', '/'.$row['LangPermalink'].'/', $_SERVER['REQUEST_URI']); } else { if ( is_home() && !is_paged() ) $QUERY=get_bloginfo('url').'/?lang='.$row['LangPermalink']; else $QUERY=str_replace('lang='.substr($locale,0,2), 'lang='.$row['LangPermalink'], $_SERVER['REQUEST_URI']); } if ( $locale != $row['LanguageID'] ) {// ... MG - Oct. 27, 2008 - no need to display the flag for active language ... $retour.='
  • '; if ($show_name) $retour.=' '.$row['LanguageName']; $retour.='
  • '; } } return $retour; } function zd_multilang_widget($args) { //EG : All that is not needed. Can we remove ? // global $ZdmlCache; // global $wpdb,$wp_rewrite; // global $insert_lang_switch_option,$insert_lang_switch_option,$show_flags_option,$show_languages_option,$lang_switcher_class_option,$permalink_default_option, $locale; // $PluginDIR = get_bloginfo('wpurl').'/'.PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)); // $language_table= $wpdb->prefix.'zd_ml_langs'; extract($args); $options=get_option('zd_multilang_widget'); $WidgetTitle=$options['title']; $WidgetOptions=$options['options']; if (!$WidgetTitle) echo $before_widget.$before_title.__('Language','zd_multilang').$after_title; else echo $before_widget.$before_title.$WidgetTitle.$after_title; echo '
      '; echo zd_multilang_menu($WidgetOptions); echo '
    '; echo $after_widget; } function zd_multilang_widget_control() { //EG : All that is not needed. Can we remove ? // global $ZdmlCache; // global $wpdb; $options = $newoptions = get_option('zd_multilang_widget'); if ( isset($_POST['zd-multilang-submit']) ) { $newoptions['title'] = strip_tags(stripslashes($_POST['zdml_widget_title'])); $newoptions['options'] = isset($_POST['zdml_sname']); } if ( $options != $newoptions ) { $options = $newoptions; update_option('zd_multilang_widget', $options); } $WidgetTitle=$options['title']; $WidgetOptions=($options['options']==1)? 'checked="checked"': ''; echo '

    '; echo '

    '; echo ''; } function zd_multilang_initwidget() { //EG : All that is not needed. Can we remove ? // global $ZdmlCache; if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) return; register_sidebar_widget(array('Zd Multilang','widgets'),'zd_multilang_widget'); register_widget_control(array('Zd Multilang', 'widgets'),'zd_multilang_widget_control'); } add_action('widgets_init', 'zd_multilang_initwidget'); ?>