<?php
// Uyghur

$text_direction = 'rtl';

add_action('admin_init','load_bedit_script');
add_action('init','load_bedit_script');
add_action('admin_init','set_font_face');
add_action('init','set_font_face');
// add bedit.js to admin-header.php
// and enable Uyghur input

function load_bedit_script () {
	wp_register_script('bEdit', WP_CONTENT_URL . '/languages/bedit.js');
	wp_enqueue_script('bEdit');
return;
}

function set_font_face () {
	$cssFile = dirname(dirname(__FILE__)). '/languages/fontfaces.css';

	if (!file_exists($cssFile) || filesize($cssFile)==273) {
		$baseFile = basename($_SERVER['PHP_SELF']);
		if( strcmp($baseFile, 'install.php') == 0 )
			$wpUrl = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('wp-admin/install.php','',$_SERVER['PHP_SELF']);
		else if( strcmp($baseFile, 'update-core.php') == 0 )
			$wpUrl = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('wp-admin/update-core.php','',$_SERVER['PHP_SELF']);
		else if( strcmp($baseFile, 'wp-login.php') == 0 )
			$wpUrl = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('wp-login.php','',$_SERVER['PHP_SELF']);
		else 
			$wpUrl = get_bloginfo('wpurl') . '/';

		$hndFile = fopen($cssFile, 'w') or die("wp-content/languages/fontfaces.css ni qurghili bolmidi.");
    	$stringData = '@font-face {' . "\n\t" . 'font-family:UKIJ Tuz Tom;' . "\n\t" . 'font-size: normal;';
		$stringData = $stringData . "\n\t" . 'font-weight: normal;' . "\n\t" . 'src:url(';
		$stringData = $stringData . $wpUrl . 'wp-content/languages/UKIJTuT.eot);' . "\n\t" . 'src:local(\'UKIJ Tuz Tom\'),url(';
		$stringData = $stringData . $wpUrl . 'wp-content/languages/UKIJTuT.ttf);format("OpenType")' . "\n" . '}';
		fwrite($hndFile, $stringData);
		fclose($hndFile);
	}

	$cssFontFile = WP_CONTENT_URL . '/languages/fontfaces.css';
	wp_register_style('fontFaces', $cssFontFile);
	wp_enqueue_style( 'fontFaces');
}
function PluginUrl() {

        //Try to use WP API if possible, introduced in WP 2.6
        if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));

        //Try to find manually... can't work if wp-content was renamed or is redirected
        $path = dirname(__FILE__);
        $path = str_replace("\\","/",$path);
        $path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
        return $path;
    }

?>