<?php 

/**
 * @author vladfr - http://nomorestories.com
 */

/** Edit the font formats that you use. 
 * 
 * The first part, before the first =>, is the handle, the font 
 * type unique identifier. The script needs that.
 * 
 * The second part contains name and extension. You should set
 * these right, as the name is used for the format value in the 
 * css font-face tag, and the extension is used to include the
 * actual font file. But you already knew that :P
 */

$font_formats = array(
    
'ttf' => array(
        
'name' => 'truetype',
        
'extension' => 'ttf'
    
),
    
'open' => array(
        
'name' => 'opentype',
        
'extension' => 'otf'
    
),
);

/** Tell the script which font format you most frequently use. 
 * This will be the default value and will be used whenever
 * the client does not supply a format.
 * 
 * This can happen if someone does not know that they need
 * to supply one.
 * 
 * If the script doesn't find a font file with the specified
 * format, it will search your fonts directory for the font
 * using all the other formats that you specified in the
 * font_formats array.
 */
$default_format 'ttf';

/**
 * Path to your license file. It should be html, because that's
 * prettier, but it really can be anything else. 
 * 
 * It can be an absolute link (has to contain http://)
 * to a blog post or to a web page, and the script will
 * redirect the user there
 * 
 * or it can be a local page, static(text, html) or dynamic(php), 
 * and the script will render it.
 */
$license_notice_file 'http://nomorestories.com/';

/**
 * This text will appear in the css file.
 */
$css_copyright_notice 'This typeface is created by me.';


/**
 * As your images directory, your css directory, this needs to be 
 * publicly accesible. That means it must have an absolute url,
 * and you have to provide it here, so that the script can
 * provide it to your users.
 */
$font_dir 'http://sparkle.muhaha.net/';

/* Ok, no more configurations. Thank you!
 * 
 * DO NOT EDIT after this line, unless you know what you're doing 
 * or a little bird whispered it in your ear.
 */

$page getenv('HTTP_REFERER'); 

if(empty(
$page) || empty($_GET['name'])){
    if(
strpos($license_notice_file'http') === false){
        include(
$license_notice_file);
    }
    else{
        
header('Location:'.$license_notice_file.'?fontname='.$_GET['name']);    
    }

else{
    
header('Content-type:text/css');
    if(empty(
$_GET['format'])) $format $default_format;
    
$url $font_dir.$_GET['name'].'.'.$font_formats[$format]['extension'];

    if(!
url_exists($url)){
        
$found false;        
        foreach(
$font_formats as $key=>$f){
            if(
$f['extension'] != $font_formats[$format]['extension']){
                
$test_url $font_dir.$_GET['name'].'.'.$f['extension'];
                if(
url_exists($test_url)){
                    
$found true;
                    
$format $key;
                    
$url $font_dir.$_GET['name'].'.'.$font_formats[$format]['extension'];
                } 
            }
        }
        if(!
$found) echo 'Bad font name: '.$_GET['name'];
    }
        
    if(empty(
$_GET['alts'])) $_GET['alts'] = 'sans-serif';
    
?>

    /* 
    <?php echo $css_copyright_notice?> 
    Please link to this typeface using <?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?name='.$_GET['name']?>
    
    */

    @font-face {
      font-family: "<?php echo $_GET['name']?>";
      src: url(<?php echo $url?>) format("<?php echo $font_formats[$format]['name']?>");
    }

<?php }

/**
 * Function by Boaz Yahav - http://www.linkedin.com/in/berber
 * From http://www.weberdev.com/get_example-4335.html
 * retrieved on 19.04.2008
 */
function url_exists($strURL) {
    
$resURL curl_init();
    
curl_setopt($resURLCURLOPT_URL$strURL);
    
curl_setopt($resURLCURLOPT_BINARYTRANSFER1);
    
curl_setopt($resURLCURLOPT_HEADERFUNCTION'curlHeaderCallback');
    
curl_setopt($resURLCURLOPT_FAILONERROR1);

    
curl_exec ($resURL);

    
$intReturnCode curl_getinfo($resURLCURLINFO_HTTP_CODE);
    
curl_close ($resURL);

    if (
$intReturnCode != 200 && $intReturnCode != 302 && $intReturnCode != 304) {
       return 
false;
    }Else{
        return 
true ;
    }


 
?>