<?php
function zwsp_by_save_post($content){
	global $wp_query, $content, $post, $zwsp, $written_font;

	$written_font = awk_option('written_font');
	$reader_font = awk_option('reader_font');
	if  ( $written_font == 'ayar' ){
		 $content = $zwsp->zwsp_ayar($content);
	} elseif( $written_font == 'zawgyi' ) {
		 $content = $zwsp->zwsp_zawgyi($content);
	} elseif ( $written_font == 'mm3' ){
		 $content = $zwsp->zwsp_mm3($content);
	} else {
		return;	
	}
	return $content;
	}
add_filter('content_save_pre','zwsp_by_save_post');
function zwsp2ayar($html){
	global $zwsp;
$html = $zwsp->zwsp_ayar($html);

$info = sprintf(
        "<!-- \nPage : %s\nHTML size : %d bytes\n Generated by AyarWebKit Plugin-->",
        $_SERVER['REQUEST_URI'],
        strlen($html)
    );
return $html.$info;
}

function zwsp2mm3($html){
	global $zwsp;
$html = $zwsp->zwsp_mm3($html);

$info = sprintf(
        "<!-- \nPage : %s\nHTML size : %d bytes\n Generated by AyarWebKit Plugin-->",
        $_SERVER['REQUEST_URI'],
        strlen($html)
    );
return $html.$info;
}

function zwsp2zawgyi($html){
	global $zwsp;
$html = $zwsp->zwsp_zawgyi($html);

$info = sprintf(
        "<!-- \nPage : %s\nHTML size : %d bytes\n Generated by AyarWebKit Plugin-->",
        $_SERVER['REQUEST_URI'],
        strlen($html)
    );
return $html.$info;
}

function zwsp_by_default(){
	global $crawler, $written_font, $reader_font, $fonts_server, $fonts_server_url, $font_encoding;
	if ( is_admin() ){
        return;
    }
	$written_font = awk_option('written_font');
	$reader_font = awk_option('reader_font');
	if ( ( $written_font == $reader_font ) && ( $reader_font == 'ayar' ) && ( $font_encoding == $reader_font ) ){
		 ob_start('zwsp2ayar');
	} elseif ( ( $written_font == $reader_font ) && ( $reader_font == 'zawgyi' ) && ( $font_encoding == $reader_font ) ){
		 ob_start('zwsp2zawgyi');
	} elseif ( ( $written_font == $reader_font ) && ( $reader_font == 'mm3' ) && ( $font_encoding == $reader_font ) ){
		 ob_start('zwsp2mm3');
	} else {
		return;	
	}
	
	}
add_action('wp', 'zwsp_by_default', 10, 0);
