tplPath = ANYFONT_ROOT."/tpl"; if(is_array($config) && isset($config['page'])){ $this->page = $config['page']; $this->page_title = $config['title']; $this->get_page(); } } function printPage(){ print($this->page_html); } function get_page(){ $url = get_bloginfo('wpurl'); $jslang_array = array( "del_style_note" => __("Please note that once a style is deleted, any generated images that are assosiated with the style will no longer load.", 'anyfont'), "chk_del_style" => __("Are you sure you want to delete this style?", 'anyfont'), "chk_del_styles" => __("Are you sure you want to delete the selected styles?", 'anyfont'), "msg_del_fonts" => __("Deleting Selected Fonts...", 'anyfont'), "msg_del_styles" => __("Deleting Selected Styles...", 'anyfont'), "msg_del" => __("Deleting", 'anyfont'), "err_select_font" => __("No Fonts Selected!", 'anyfont'), "err_select_style" => __("No Styles Selected!", 'anyfont'), "chk_clear_cache" => __("Are you sure you want to clear the cache?", 'anyfont'), "msg_clear_cache" => __("Clearing the cache...", 'anyfont'), "msg_no_images" => __("no images", 'anyfont'), "msg_upload_success" => __("was uploaded successfully", 'anyfont'), "err_upload_failed" => __("Upload Failed:", 'anyfont'), "err_saving_style" => __("Save Failed! Please ensure that the font folder and all files inside are writable by the webserver.", 'anyfont'), "msg_saved_style" => __("Style has been saved.", 'anyfont'), "msg_saving_style" => __("Saving Style...", 'anyfont'), "msg_upload_start" => __("Uploading Font...", 'anyfont'), "msg_saving_settings" => __("Saving Settings...", 'anyfont') ); if (function_exists('json_encode')) { $jslang = json_encode($jslang_array); } else { require_once(ANYFONT_ROOT.'/lib/class.json.php'); $JSON = new serviceJSON(); $jslang = $JSON->encode($jslang_array); } $this->tpl = new fastTPL($this->tplPath); $this->tpl->define(array($this->page => "{$this->page}.html", "header" => "header.html", "footer" => "footer.html", )); $this->tpl->assign("STYLE", file_get_contents(ANYFONT_ROOT."/styles.css")); $this->tpl->assign("URL", $url."/"); $this->tpl->assign("JSLANG", $jslang); $this->tpl->assign("ICON_CLASS", $this->page); $this->tpl->assign("PAGE_TITLE", "AnyFont - ".$this->page_title); $this->tpl->assign("HEADER", $this->tpl->fetchParsed("header")); switch($this->page){ case 'settings': $this->getSettings(); break; case 'fonts': $this->readFontDir(); $this->getFonts(); break; case 'styles': $this->readFontDir(); $this->getStyles(); break; } $this->tpl->assign("FOOTER", $this->tpl->fetchParsed("footer")); $this->page_html = $this->tpl->fetchParsed($this->page); } function getSettings(){ $cachedir = ANYFONT_CACHE; $totalsize = 0; $imagecount = 0; if(!is_dir($cachedir)){ return false; } else { $dir = opendir($cachedir); while ($file = readdir($dir)) { $fileinfo = explode(".", $file); if ($fileinfo[1] == "png") { $imagecount++; $totalsize += filesize($cachedir."/".$file); } } } $imageplural = $imagecount == 1 ? " image" : " images"; $isare = $imagecount == 1 ? "is" : "are"; $imagecount == 0 ? $imagecount = "no" : 0; $opt = array("auto(Default)" => "auto", "gd" => "php4", "imagick" => "php5"); $imageopt = ""; foreach($opt as $mod => $val){ $selected = ($val == get_option('anyfont_image_module')) ? "selected=\"selected\"" : ""; if($val == "auto"){ $imageopt .= ""; }else if(extension_loaded($mod)){ $imageopt .= ""; } } $this->isReplaceEnabled(get_option('anyfont_page_title'), "PAGE"); $this->isReplaceEnabled(get_option('anyfont_post_title'), "POST"); $this->isReplaceEnabled(get_option('anyfont_cat_title'), "CAT"); $this->isReplaceEnabled(get_option('anyfont_tag_title'), "TAG"); $this->isReplaceEnabled(get_option('anyfont_widget_title'), "WIDGET"); $this->isReplaceEnabled(get_option('anyfont_blog_title'), "BLOG_TITLE"); $this->isReplaceEnabled(get_option('anyfont_blog_desc'), "BLOG_DESC"); $this->isReplaceEnabled(get_option('anyfont_disable_hotlinking'), "DISABLE_HOTLINKING"); $this->tpl->assign("REPLACE_H2", __("Replace Text Titles", 'anyfont')); $this->tpl->assign("IMAGE_H2", __("Image Cache", 'anyfont')); $this->tpl->assign("ADVANCED_H2", __("Advanced Settings", 'anyfont')); $this->tpl->assign("ADVANCED_MSG", __("It is recommended that the following options are left on their default settings.", 'anyfont')); $this->tpl->assign("HELP_MSG", __("To replace certain plain text titles with images in your wordpress blog, enable the appropriate section below and then assign it one of your styles.", 'anyfont')); $this->tpl->assign("SEO_NOTE", __("The post title, page title, blog name and blog description image replacements are SEO compatible.", 'anyfont')); $this->tpl->assign("DISCLAIMER", __("PLEASE NOTE:
These options may not be compatible with ALL themes and/or custom widgets.
If your theme already uses a custom image for the title, it is NOT advisable to enable the blog name option.", 'anyfont')); $this->tpl->assign("DISCLAIMER_CONT", __("If you encounter any problems, Please check the FAQ for known issues with certain themes, check with the developer of your theme, or contact me for assistance.", 'anyfont')); $this->tpl->assign("POST_TITLE_STYLES", $this->titleStyleConfig( get_option('anyfont_post_title_style'))); $this->tpl->assign("PAGE_TITLE_STYLES", $this->titleStyleConfig(get_option('anyfont_page_title_style'))); $this->tpl->assign("TAG_TITLE_STYLES", $this->titleStyleConfig(get_option('anyfont_tag_title_style'))); $this->tpl->assign("CAT_TITLE_STYLES", $this->titleStyleConfig(get_option('anyfont_cat_title_style'))); $this->tpl->assign("WIDGET_TITLE_STYLES", $this->titleStyleConfig(get_option('anyfont_widget_title_style'))); $this->tpl->assign("BLOG_TITLE_STYLES", $this->titleStyleConfig(get_option('anyfont_blog_title_style'))); $this->tpl->assign("BLOG_DESC_STYLES", $this->titleStyleConfig(get_option('anyfont_blog_desc_style'))); $this->tpl->assign("IMAGE_MODULE_OPTIONS", $imageopt); $this->tpl->assign("URL", WP_ADMIN_URL."/admin.php?page=anyfont-styles"); $this->tpl->assign("IMAGE_COUNT", $imagecount.$imageplural); $this->tpl->assign("ISARE", $isare); $this->tpl->assign("TOTAL_SIZE", $this->bytecalc($totalsize)); } function isReplaceEnabled($section, $assign){ if($section){ $this->tpl->assign("{$assign}_CHECKED", "checked=\"checked\""); $this->tpl->assign("{$assign}_ON_CLASS", " anyfont_checkbox_on"); } else { $this->tpl->assign("{$assign}_DISABLED", "disabled=\"disabled\""); } } function titleStyleConfig($section){ $styles = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true); $styleoptions = ''; foreach($styles as $style => $option){ if($style != "admin"){ $selected = $style == $section ? "selected=\"selected\"" : ''; $styleoptions .= ""; } } return $styleoptions; } function getFonts(){ $list = ""; $tpl = new fastTPL($this->tplPath); $tpl->define(array("font_block" => "fonts-block.html")); foreach($this->fontlist as $displayname => $fontdetail){ $fontname = urlencode($fontdetail['filename']); $fonttypes = ""; $i = 1; $t = count($fontdetail["type"]); foreach($fontdetail["type"] as $type){ $i != 1 && $i <= $t ? $fonttypes .= ", " : 0; $fonttypes .= "{$type['ftype']}"; $i++; } $tpl->assign('FONTID', preg_replace('/\s+/', "", $displayname)); $tpl->assign('FONT_NAME', $fontname); $tpl->assign('FONT_DISPLAY_NAME', $displayname); $tpl->assign('FONT_TYPES', $fonttypes); $tpl->assign('DISPLAY_NAME', $displayname); $tpl->assign('COPYRIGHT', $fontdetail['copyright']); $tpl->assign('FONT_URL', get_bloginfo('wpurl')."/images/admin/$fontname/".urlencode("The quick brown fox jumps over the lazy dog").".png"); // !get_option('anyfont_display_charmap') ? $tpl->assign('CHARMAP_URL', get_bloginfo('wpurl')."/images/admin/$fontname/charactermap.png") : 0; $tpl->assign('DELETE_ICON', ANYFONT_URL."/img/icon-delete.png"); $list .= $tpl->fetchParsed("font_block"); } $this->tpl->assign("FONTS", $list); $this->tpl->assign("UPLOAD_URL", ANYFONT_URL."/upload.php"); } function readFontDir() { $this->fontlist = array(); $filelist = array(); $sortlist = array(); $buildlist = array(); if(!is_dir(ANYFONT_FONTDIR)){ return false; } else { $dir = dir(ANYFONT_FONTDIR); while (false !== ($e = $dir->read())){ if($e != '.' && $e != '..' && $this->is_font($e) === true){ $fontdetails = $this->getFontInfo( ANYFONT_FONTDIR ."/". $e); $buildlist[$fontdetails[1]]["name"] = $fontdetails[1]; if(!$buildlist[$fontdetails[1]]["type"]){ $buildlist[$fontdetails[1]]["type"] = array(); } array_push($buildlist[$fontdetails[1]]["type"], array("ftype" => $fontdetails[2], "filename" => $this->getFontName($e))); $buildlist[$fontdetails[1]]["trademark"] = $fontdetails[7]; $buildlist[$fontdetails[1]]["copyright"] = $fontdetails[10]; $buildlist[$fontdetails[1]]["version"] = $fontdetails[5]; $buildlist[$fontdetails[1]]["author"] = !isset($fontdetails[8]) ? $fontdetails[9] : $fontdetails[8]; $buildlist[$fontdetails[1]]["url"] = $fontdetails[11]; $buildlist[$fontdetails[1]]["license"] = $fontdetails[13]; $buildlist[$fontdetails[1]]["filename"] = $this->getFontName($e); array_push($sortlist, $fontdetails[1]); } } } natcasesort($sortlist); foreach($sortlist as $fontname){ $this->fontlist[$fontname] = $buildlist[$fontname]; } } function getStyles(){ $styles = ""; if(file_exists(ANYFONT_FONTDIR."/styles.ini")){ $settings = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true); if(file_exists(ANYFONT_FONTDIR."/styles.ini")){ $settings = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true); foreach($settings as $style => $option){ if($style != "admin"){ ksort($option); $styles.=$this->getStyleBlock($style, $option); } } } $new_style = "

"; $new_style .= "

"; $new_style .= "

"; $sizes = array("7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "18", "22", "24", "28", "36", "40", "44", "48", "54", "60", "72"); $new_style .= ""; $new_style .= "

"; // Contribution from RW // Added new checkbox styles - RP $new_style .= "

"; $new_style .= "
(character limit)

"; // End $new_style .= "

"; $new_style .= "


"; $new_style .= "

"; $new_style .= "

"; $new_style .= ""; $this->tpl->assign("NEW_STYLE_FORM", $new_style); $this->tpl->assign("STYLES", $styles); } } function getStyleBlock($style, $option){ $url = get_bloginfo('wpurl'); ksort($option); $tpl = new fastTPL($this->tplPath); $tpl->define(array("styles_block" => "styles_block.html")); $tpl->assign('STYLE_NAME', $style); $tpl->assign('STYLE_NAME_ID', str_replace(" ", "_", $style)); $tpl->assign('PREVIEW_URL', $url."/images/$style/$style.png"); $options = "
"; !isset($option['limit-width']) ? $option['limit-width'] = false : 0; !isset($option['max-width']) ? $option['max-width'] = 50 : 0; !isset($option['background-color']) ? $option['background-color'] = "FFFFFF" : 0; !isset($option['shadow']) ? $option['shadow'] = false : 0; !isset($option['shadow-color']) ? $option['shadow-color'] = "000000" : 0; !isset($option['shadow-distance']) ? $option['shadow-distance'] = 1 : 0; !isset($option['soften-shadow']) ? $option['soften-shadow'] = false : 0; ksort($option); foreach($option as $name => $value){ $dolabel = true; switch($name){ case 'shadow-color': $options .= "
"; break; case 'max-width': $options .= "
"; break; case 'shadow': $option_on = !$option['shadow'] ? "" : " anyfont_checkbox_on"; $options .= "
"; $for = "#"; break; case 'soften-shadow': $option_on = !$option['soften-shadow'] ? "" : " anyfont_checkbox_on"; $options .= "
"; $for = "#"; break; case 'limit-width': $option_on = !$option['limit-width'] ? "" : " anyfont_checkbox_on"; $options .= "
"; $for = "#"; break; case 'shadow-spread': $options .= ""; $dolabel = false; } $dolabel !== false ? $options .= "" : 0; switch($name){ case "color": $options .= "

"; break; case "background-color": $options .= "

"; break; case "font-name": $options .= ""; $options .= ""; $options .= "
    "; foreach($this->fontlist as $displayname => $fontdetail){ $fontname = $fontdetail['filename']; if(count($fontdetail["type"]) > 1){ foreach($fontdetail["type"] as $type){ $displayname = $fontdetail['name']." ".$type['ftype']; $filename = $type['filename']; $options .= "
  • \"$displayname\"
  • "; } } else { $options .= "
  • \"$displayname\"
  • "; } // $options .= "
  • \"$displayname\"
  • "; } $options .= "


"; break; case "font-size": $sizes = array("7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "18", "22", "24", "28", "36", "40", "44", "48", "54", "60", "72"); $options .= ""; $options .= "
    "; foreach($sizes as $size){ $options .= "
  • {$size}pt
  • "; } $options .= "


"; break; case "shadow": $checked = !$value ? "" : "checked=\"checked\""; $options .= "

"; break; case "shadow-distance": $options .= "

"; break; case "shadow-color": $options .= "

"; break; case "soften-shadow": $checked = !$value ? "" : "checked=\"checked\""; $options .= "

"; break; // Contribution from RW case "limit-width": $checked = !$value ? "" : "checked=\"checked\""; $options .= "

"; break; case "max-width": $options .= "(character limit)

"; // End } } $options .= "
"; $tpl->assign('DELETE_ICON', ANYFONT_URL."/img/icon-delete.png"); $tpl->assign('EDIT_ICON', ANYFONT_URL."/img/icon-edit.png"); $tpl->assign('OPTIONS', $options); return $tpl->fetchParsed("styles_block"); } function bytecalc($bytes, $base10=false, $round=0){ $labels=array(' bytes', ' kB', ' MB', ' GB'); if (($bytes <= 0) || (! is_array($labels)) || (count($labels) <= 0)) return null; $step = $base10 ? 3 : 10 ; $base = $base10 ? 10 : 2; $log = (int)(log10($bytes)/log10($base)); krsort($labels); foreach ($labels as $p=>$lab) { $pow = $p * $step; if ($log < $pow) continue; $text = $bytes." bytes (".round($bytes/pow($base,$pow),$round) . $lab.")"; break; } return $text; } function dec2ord($dec){ return $this->dec2hex(ord($dec)); } function dec2hex($dec){ return str_repeat('0', 2-strlen(($hex=strtoupper(dechex($dec))))) . $hex; } /** * @original author Unknown * found at http://www.phpclasses.org/browse/package/2144.html */ function getFontInfo($filename){ $fd = fopen ($filename, "r"); $this->text = fread ($fd, filesize($filename)); fclose ($fd); $number_of_tables = hexdec($this->dec2ord($this->text[4]).$this->dec2ord($this->text[5])); for ($i=0;$i<$number_of_tables;$i++) { $tag = $this->text[12+$i*16].$this->text[12+$i*16+1].$this->text[12+$i*16+2].$this->text[12+$i*16+3]; if ($tag == 'name') { $this->ntOffset = hexdec( $this->dec2ord($this->text[12+$i*16+8]).$this->dec2ord($this->text[12+$i*16+8+1]). $this->dec2ord($this->text[12+$i*16+8+2]).$this->dec2ord($this->text[12+$i*16+8+3])); $offset_storage_dec = hexdec($this->dec2ord($this->text[$this->ntOffset+4]).$this->dec2ord($this->text[$this->ntOffset+5])); $number_name_records_dec = hexdec($this->dec2ord($this->text[$this->ntOffset+2]).$this->dec2ord($this->text[$this->ntOffset+3])); } } $storage_dec = $offset_storage_dec + $this->ntOffset; $storage_hex = strtoupper(dechex($storage_dec)); for ($j=0;$j<$number_name_records_dec;$j++) { $platform_id_dec = hexdec($this->dec2ord($this->text[$this->ntOffset+6+$j*12+0]).$this->dec2ord($this->text[$this->ntOffset+6+$j*12+1])); $name_id_dec = hexdec($this->dec2ord($this->text[$this->ntOffset+6+$j*12+6]).$this->dec2ord($this->text[$this->ntOffset+6+$j*12+7])); $string_length_dec = hexdec($this->dec2ord($this->text[$this->ntOffset+6+$j*12+8]).$this->dec2ord($this->text[$this->ntOffset+6+$j*12+9])); $string_offset_dec = hexdec($this->dec2ord($this->text[$this->ntOffset+6+$j*12+10]).$this->dec2ord($this->text[$this->ntOffset+6+$j*12+11])); if (!empty($name_id_dec) and empty($font_tags[$name_id_dec])) { for($l=0;$l<$string_length_dec;$l++) { if (ord($this->text[$storage_dec+$string_offset_dec+$l]) == '0') { continue; } else { $font_tags[$name_id_dec] .= ($this->text[$storage_dec+$string_offset_dec+$l]); } } } } return $font_tags; } function is_font($file){ $ext = explode('.', $file); $ext = $ext[count($ext)-1]; if( preg_match("/ttf$/i",$ext) ){ return true; } elseif(preg_match("/otf$/i",$ext)){ return true; } return false; } function getFontName($file){ $fontfile = explode(".", $file); $fontname = ""; for($i = 0; $i < (count($fontfile)-1);$i++){ $i > 0 ? $fontname .= "." : 0; $fontname .= $fontfile[$i]; } return $fontname; } }