<?php
    if(!defined("__ZBXE__")) exit();

    /**
     * @file webfontface.addon.php
     * @author hhgyu (hhgyu15@gmail.com)
     * @brief Web Font-Face
     **/
    //if($called_position != 'after_module_proc') return; // || Context::get('module')=='admin'
    if($called_position == 'before_display_content'){
        $webfonturl[url]="http://commondatastorage.googleapis.com/fontfacekr-fonts/";
        $webfonturl[home]="./addons/webfontface/font/";
        if($addon_info->fonttype=='') $fonttype="NanumGothic";
        else $fonttype=$addon_info->fonttype;
        if($fonttype=="NanumGothic")$fonttypekr="나눔고딕";
        elseif($fonttype=="NanumGothicBold")$fonttypekr="나눔고딕 Bold";
        elseif($fonttype=="NanumMyeongjo")$fonttypekr="나눔명조";
        elseif($fonttype=="NanumMyeongjoBold")$fonttypekr="나눔명조 Bold";
        elseif($fonttype=="NanumBrush")$fonttypekr="나눔손글씨 붓";
        elseif($fonttype=="NanumPen")$fonttypekr="나눔손글씨 펜";
        if($addon_info->webfonturl=="home"){
            $url[eot]=$webfonturl[home].$fonttype.".eot";
            $url[woff]=$webfonturl[home].$fonttype.".woff";
            $url[ttf]=$webfonturl[home].$fonttype.".ttf";
        }elseif($addon_info->webfonturl=="local"){
            $url[eot]="";
            $url[woff]="";
            $url[ttf]="";
        }else{
            $url[eot]=$webfonturl[url].$fonttype.".eot";
            $url[woff]=$webfonturl[url].$fonttype.".woff";
            $url[ttf]=$webfonturl[url].$fonttype.".ttf";
        }
        if(($addon_info->important=="")||($addon_info->important=="yes"))
        { 
          $important="!important";
        } 
        else $important="";
        if(!($addon_info->webfonturl=="local")){
        $fontface_style="
<style type=\"text/css\">
@font-face {
	font-family: '".$fonttype."';
	src: url('".$url[eot]."');
	src: local(\"".$fonttype."\"),
		url('".$url[woff]."') format('woff'),
		url('".$url[ttf]."') format('truetype');
}
*{
  font-family: ".$fonttype." ".$important.";
}
</style>
        ";
        }else{
        $fontface_style="
<style type=\"text/css\">
@font-face {
	font-family: '".$fonttype."';
	src: local(\"".$fonttype."\"),local(\"".$fonttypekr."\");
}
*{
  font-family: ".$fonttype." ".$important.";
}
#gBtn1 a{display:block; background:url('./addons/webfontface/img/gBtn1_bg.gif') left 0; font:12px 굴림; color:#555; padding-left:6px; text-decoration:none; height:27px; cursor:pointer; margin-right:3px; overflow:hidden}
#gBtn1 a:hover{background:url('./addons/webfontface/img/gBtn1_bg.gif') left -27px}
#gBtn1 a span{display:block; background:url('./addons/webfontface/img/gBtn1_bg.gif') right 0; line-height:240%; padding-right:6px; height:27px; overflow:hidden}
#gBtn1 a:hover span{background:url('./addons/webfontface/img/gBtn1_bg.gif') right -27px; color:#0A82A7} 
</style>
<div id=\"webfontfac\" style=\"position:fixed; width:289px; top:120px; left:50%; padding:30px; border:2px solid #737373; margin:0 0 0 -175px; background:#fff;z-index:5;display:none;\">
<b>
<p style=\"margin: 0px 0pt 5px;\">우리 사이트는 <span style='color:blue;font-size:20pt;'>".$fonttypekr."</span>폰트를 사용하고 있습니다.</p>
<p style=\"margin: 0px 0pt 5px;\">재대로 보시려면 ".$fonttypekr."폰트를 설치하여 주시기 바랍니다.</p>
<p style=\"margin: 0px 0pt 5px;\">
<center>
<div id=\"gBtn1\">
<a href=\"http://hangeul.naver.com/download.nhn\" onclick=\"window.open(this.href);return false;\">
<span>나눔글꼴 다운으로 가기</span>
</a>
</div>
</center>
        ";
        $fontface_style2="
<center>
<div id=\"gBtn1\">
<a href=\"#\" onclick=\"javascript:set_webfontfaceCookie();\">
<span>".$addon_info->h24."일 동안 보이지않기</span>
</a>
</div>
</center>
        ";
        $fontface_style3="
</p>
</b>
</div>
        ";
          if(($_COOKIE['webfontface_Close'] != 'y')and(!(Context::get('module')=='admin'||Context::get('module')=='module'||Context::get('module')=='addon'))){
                $fontface_style4="
<div id='fontcheck1' style='visibility:hidden;z-index:-999;position:absolute;top:10px;left:10px;font-family:".$fonttype.",".$fonttypekr.",Verdana,돋움 !important;font-size:9pt;border:1px solid #e0e0e0;padding:5px;'>".$fonttype.",".$fonttypekr."1234</div>
<div id='fontcheck2' style='visibility:hidden;z-index:-999;position:absolute;top:10px;left:100px;font-family:Verdana,돋움 !important;font-size:9pt;border:1px solid #e0e0e0;padding:5px;'>".$fonttype.",".$fonttypekr."1234</div>
<script type='text/javascript'>
jQuery(document).ready(function() {
    if(document.getElementById(\"fontcheck1\").clientWidth==document.getElementById(\"fontcheck2\").clientWidth){
        jQuery(\"#webfontfac\").show();
        //alert(\"폰트가 적용되지 않으면 나옵니다.\\n밑에 값이 갔으면 적용 안된 것입니다.\\n\"+document.getElementById(\"fontcheck1\").clientWidth+\" , \"+document.getElementById(\"fontcheck2\").clientWidth);
    }else{
        //alert(\"폰트가 적용되면 나옵니다.\\n밑에 값이 다르면 적용된것입니다.\\n\"+document.getElementById(\"fontcheck1\").clientWidth+\" , \"+document.getElementById(\"fontcheck2\").clientWidth);
    }
});
</script>
                ";
            $fontface_style3=$fontface_style3.$fontface_style4;
            }
        }
        if($addon_info->h24!=""&&($_COOKIE['webfontface_Close'] != 'y')&&(!(Context::get('module')=='admin'||Context::get('module')=='module'||Context::get('module')=='addon'))){
          $fontface_style="
<script type='text/javascript'>
function set_webfontfaceCookie() {
    var expire = new Date();
    expire.setDate(expire.getDate()+ ".$addon_info->h24.");
    xSetCookie('webfontface_Close', 'y', expire);
    javascript:jQuery('#webfontfac').fadeOut(600,0);
}
</script>
".$fontface_style.$fontface_style2.$fontface_style3;
        }else{
            $fontface_style=$fontface_style.$fontface_style3;
        }
        Context::addHtmlHeader($fontface_style);
    }

?>