Exemplo n.º 1
0
 function on_wp_login($who)
 {
     //TODO: standardize the USER-META behavoir
     global $wp_version;
     $langs = wp_native_dashboard_collect_installed_languages();
     if (!isset($_POST['wp_native_dashboard_language']) || !in_array($_POST['wp_native_dashboard_language'], $langs)) {
         return;
     }
     if (version_compare($wp_version, '3.0', '>=')) {
         $user = get_user_by('login', $who);
         update_user_meta((int) $user->ID, 'wp_native_dashboard_language', $_POST['wp_native_dashboard_language']);
     } else {
         update_usermeta(get_profile('ID', $who), 'wp_native_dashboard_language', $_POST['wp_native_dashboard_language']);
     }
 }
Exemplo n.º 2
0
    function on_profile_personal_options()
    {
        ?>
		<table class="form-table">
		<tbody>
		<tr valign="top">
			<th scope="row"><?php 
        _e('Language', 'wp-native-dashboard');
        ?>
</th>
			<td>
				<label>
				<select name="wp_native_dashboard_language">
				<?php 
        $langs = wp_native_dashboard_collect_installed_languages();
        //TODO: standardize the USER-META behavoir
        $u = wp_get_current_user();
        if (!isset($u->wp_native_dashboard_language)) {
            $u->wp_native_dashboard_language = get_locale();
            //persist it now for later update only
            update_user_meta($u->ID, 'wp_native_dashboard_language', $u->wp_native_dashboard_language);
        }
        foreach ($langs as $lang) {
            echo "<option value=\"{$lang}\"";
            if ($u->wp_native_dashboard_language == $lang) {
                echo ' selected="selected"';
            }
            echo ">" . wp_native_dashboard_get_name_of($lang) . "</option>";
        }
        ?>
				</select>
				<?php 
        _e('Select your prefered language that will be used to show the Admin Center.', 'wp-native-dashboard');
        ?>
				</label>
			</td>
		</tr>		
		</tbody>
		</table>
		<?php 
    }
Exemplo n.º 3
0
 function on_print_dashboard_switcher()
 {
     $langs = wp_native_dashboard_collect_installed_languages();
     $loc = get_locale();
     echo '<div id="csp-langswitcher-actions" class="alignleft">';
     echo '<div id="csp-langswitcher-current"><span class="csp-' . $loc . '">' . wp_native_dashboard_get_name_of($loc) . '</span></div>';
     echo '<div id="csp-langswitcher-toggle"><br/></div>';
     if (count($langs) > 1) {
         echo '<div id="csp-langoptions" style="display: none;">';
         foreach ($langs as $lang) {
             if ($lang != $loc) {
                 echo '<a href="javascript:void(0);" class="csp-langoption" hreflang="' . $lang . '"><span class="csp-' . $lang . '">' . wp_native_dashboard_get_name_of($lang) . '</span></a>';
             }
         }
         echo '</div>';
     }
     echo '</div>';
 }
Exemplo n.º 4
0
    function on_ajax_wp_native_dashboard_check_language()
    {
        //disable snitch
        $snitch = remove_filter('pre_http_request', array('Snitch_HTTP', 'inspect_request'), 10);
        $lang = $_POST['language'];
        $row = $_POST['row'];
        $ver = isset($_POST['ver']) ? $_POST['ver'] : $this->root_tagged_version;
        $installed = wp_native_dashboard_collect_installed_languages();
        $url = "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $this->tagged_version . "/messages/";
        $url_root = "http://svn.automattic.com/wordpress-i18n/" . $lang . "/tags/" . $ver . "/messages/";
        $snitch = $this->_snitch_off();
        $response_mo = @wp_remote_get($url);
        if ($snitch) {
            $this->_snitch_on();
        }
        $found = false;
        $tagged = $this->tagged_version;
        if (!is_wp_error($response_mo) && $response_mo['response']['code'] != 404) {
            if (preg_match("/href\\s*=\\s*\"" . $lang . "\\.mo\"/", $response_mo['body'])) {
                $found = true;
            }
        }
        if ($found === false) {
            $url = $url_root;
            $tagged = $ver;
            $snitch = $this->_snitch_off();
            $response_mo = @wp_remote_get($url);
            if ($snitch) {
                $this->_snitch_on();
            }
            if (!is_wp_error($response_mo) && $response_mo['response']['code'] != 404) {
                if (preg_match("/href\\s*=\\s*\"" . $lang . "\\.mo\"/", $response_mo['body'])) {
                    $found = true;
                }
            }
        }
        //add snitch again if present
        if ($snitch) {
            add_filter('pre_http_request', array('Snitch_HTTP', 'inspect_request'), 10, 3);
        }
        if ($found === false) {
            exit;
        }
        $url .= $lang . '.mo';
        ?>
		<tr id="tr-i18n-download-<?php 
        echo $lang;
        ?>
" class="<?php 
        if (($row + 1) % 2) {
            echo 'alternate';
        }
        ?>
">
		<td><span class="i18n-file csp-<?php 
        echo $lang;
        ?>
"><?php 
        echo wp_native_dashboard_get_name_of($lang);
        ?>
</span></td>
		<td><?php 
        echo wp_native_dashboard_is_rtl_language($lang) ? __('right to left', 'wp-native-dashboard') : '&nbsp;';
        ?>
</td>
		<td>-n.a.-</td>
		<td><?php 
        if (!in_array($lang, $installed)) {
            ?>
				<a class="csp-download-svn-file" href="<?php 
            echo $url;
            ?>
"><?php 
            _e('Download', 'wp-native-dashboard');
            echo '&nbsp;(' . $tagged . ')';
            ?>
</a>&nbsp;<span><img src="images/loading.gif" class="ajax-feedback" title="" alt="" /></span>
			<?php 
        } else {
            echo '&nbsp;';
        }
        ?>
		</td>
		</tr>
		<?php 
        exit;
    }
Exemplo n.º 5
0
    function on_print_metabox_installed_i18n()
    {
        $installed = wp_native_dashboard_collect_installed_languages();
        ?>
		<p><?php 
        _e('Your WordPress installation currectly supports this list of languages at your Dashboard.', 'wp-native-dashboard');
        ?>
</p>
		<table id="table_local_i18n" class="widefat fixed" cellspacing="0">
			<tbody>
				<?php 
        $state = 0;
        foreach ($installed as $lang) {
            $state = ($state + 1) % 2;
            $mo = str_replace('\\', '/', WP_LANG_DIR . '/' . $lang . '.mo');
            ?>
					<tr id="tr-i18n-installed-<?php 
            echo $lang;
            ?>
" class="<?php 
            if ($state) {
                echo 'alternate';
            }
            ?>
">
						<td><span class="i18n-file csp-<?php 
            echo $lang;
            ?>
"><?php 
            echo wp_native_dashboard_get_name_of($lang);
            ?>
</span></td>
						<td><?php 
            echo wp_native_dashboard_is_rtl_language($lang) ? __('right to left', 'wp-native-dashboard') : '&nbsp;';
            ?>
</td>
						<td><?php 
            echo is_file($mo) ? filesize($mo) . '&nbsp;Bytes' : '-n.a.-';
            ?>
</td>
						<td><?php 
            if ($lang != 'en_US') {
                ?>
<a class="csp-delete-local-file" href="<?php 
                echo $mo;
                ?>
"><?php 
                _e('Delete', 'wp-native-dashboard');
                ?>
</a>&nbsp;<span><img src="images/loading.gif" class="ajax-feedback" title="" alt="" /></span><?php 
            }
            ?>
</td>
					</tr>
					<?php 
        }
        ?>
			</tbody>
		</table>
		<?php 
    }