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_option('siteurl');
$this->helptext = array(
"default" => __("Help for this setting is not yet available.", 'anyfont'),
"settings_menu_text" => __("Enables replacement of the text in your page menus with the styles chosen below.", 'anyfont'),
"image-padding" => __("Enable this setting if the text in your generated images is cut off.", 'anyfont'),
"image-padding-top" => __("Amount of empty space at the top of the generated image.", 'anyfont'),
"image-padding-bottom" => __("Amount of empty space at the bottom of the generated image.", 'anyfont'),
"image-padding-right" => __("Amount of empty space on the right of the generated image.", 'anyfont'),
"image-padding-left" => __("Amount of empty space on the left of the generated image.", 'anyfont'),
"use-htaccess" => __("Unless you are using an alternative mod_rewrite method you should NEVER disable this setting.", 'anyfont'),
"enable-custom-fontdir" => __("Enabling this setting will allow you to set the folder for uploaded font files. Note: Changing this setting will automatically move any fonts you have already uploaded to the new folder.", 'anyfont'),
"enable-custom-cache" => __("Enabling this setting will allow you to set the folder which is used to store generated images. Note: Changing this setting will automatically move any images already cached to the new folder.", 'anyfont'),
"enable_tinymce" => __("When this setting is enabled, a button will be added to the editor for posts/pages which allows you to apply AnyFont styles to text in your post.", 'anyfont'),
"enable_gzip" => __("Enable this setting if you would like to compress AnyFont generated images using gzip before they sent to the browser. Note: In some cases this may actually increase the size of the image as all generated images are already optimized. Use at your own discretion.", 'anyfont'),
"disable_hotlinking" => __("This will prevent any unauthorized websites from using your generated images on their own pages. Disabling this setting is not recommended.", 'anyfont'),
"cache_show_bytes" => __("When enabled, Disk usage will be shown in bytes. This was the default behaviour prior to version 1.0 so this setting is here just in case someone actually liked it that way! ;)", 'anyfont'),
"cache_dashboard_widget" => __("Enabling this will add an admin widget to your dashboard showing disk usage information for AnyFont", 'anyfont'),
"limit-cache-size" => __("If you want to make sure AnyFont doesn't use more disk space than what you're allowed, enabling this setting will allow you to set a size limit. If enabled, the cache will be checked once every day and cleaned only if it is found to be larger than the set limit", 'anyfont'),
"cache-size-limit" => __("Enter the maximum amount of disk space AnyFont is allowed to use in MB", 'anyfont'),
"post-titles" => __("When this setting is enabled, the primary text heading of your blog posts will automatically be replaced with a dynamically generated image which is 100% SEO friendly. Dont forget to select a style from the dropdown list after enabling this setting.", 'anyfont'),
"page-titles" => __("When this setting is enabled, the primary text heading of your blog pages will automatically be replaced with a dynamically generated image which is 100% SEO friendly. Dont forget to select a style from the dropdown list after enabling this setting.", 'anyfont'),
"tag_title" => __("When this setting is enabled, the tag name, which is normally displayed at the top of the page when browsing a specific tag, will automatically be replaced with a dynamically generated image which is 100% SEO friendly. Dont forget to select a styles from the dropdown list after enabling this setting.", 'anyfont'),
"cat_title" => __("When this setting is enabled, the category name, which is normally displayed at the top of the page when browsing a specific category, will automatically be replaced with a dynamically generated image which is 100% SEO friendly. Dont forget to select a styles from the dropdown list after enabling this setting.", 'anyfont'),
"widget_title" => __("When this setting is enabled, widget titles will automatically be replaced with a dynamically generated image. NOTE: Widget title images are NOT SEO friendly. Dont forget to select a styles from the dropdown list after enabling this setting.", 'anyfont'),
"blog_title" => __("When enabled, AnyFont will attempt to style your Blogs Name in the site header using the chosen style. Note: Results may vary depending on the theme.", 'anyfont'),
"blog_desc" => __("When enabled, AnyFont will attempt to style your Blogs Description in the site header using the chosen style. Note: Results may vary depending on the theme.", 'anyfont'),
"menu" => __("Enabling this setting will allow you to set styles for menus generated with the wp_list_pages or wp_page_menu WordPress functions and the new menu builder available in WordPress 3(Requires the 'Title Attribute' to be set for each entry on the WordPress menus admin page). Note: Results may vary depending on the theme.", 'anyfont'),
"name" => __("The name of the style. Acceptable characters to use include letters, numbers, spaces, underscores and dashes.", 'anyfont'),
"color" => __("The main color of the font face, Select a color by clicking the color square and choosing a preset or type in your own color code in hex format", 'anyfont'),
"font-name" => __("Select an uploaded font from the list, if you have not yet uploaded any fonts, you should do so before attempting to create a style.", 'anyfont'),
"font-size" => __("Select a size from the dropdown or type in a custom size.", 'anyfont'),
"limit-width" => __("Enabling this setting will allow you to set a character limit for the width of the image, after which the text will then continue on a new line.", 'anyfont'),
"max-width" => __("Set the pixel width for the generated images", 'anyfont'),
"text-align" => __("Align the text to display either centered or left aligned(default) in the generated image.", 'anyfont'),
"line-height" => __("Adjust the height for each line of text on multi-line images. NOTE: When set to '0px', this setting will be ignored and the default line height will be used", 'anyfont'),
"shadow" => __("Enabling this setting will allow you to add shadow effects to the text", 'anyfont'),
"shadow-color" => __("Set the color for the text shadow by clicking the color square and choosing a preset or type in your own color code in hex format", 'anyfont'),
"shadow-distance" => __("This controls how far the shadow is from the text. The higher the value, the further down and to the right the shadow will appear.", 'anyfont'),
"shadow-spread" => __("Control the amount of blur/stretch that is applied to the shadow.", 'anyfont'),
"soften-shadow" => __("Enabling this setting will blur the shadow slightly and smoothly merge it into the background.", 'anyfont'),
"background-color" => __("This must be set to the background color that the image will be placed on when used on your site. ie: If your site has a white background, this color should then be set to white.", 'anyfont'),
"api-key" => __("Enter your API key which can be found on your Account page at FontServ.com. Sign up now for free if you do not yet have an account.", 'anyfont'),
"body_text" => __("This setting will apply the selected style to all the text on every page of your site.", 'anyfont'),
"content_text" => __("This setting will apply the selected style to just the content element on every page of your site. WARNING: This setting may not work with all themes as it depends on there being a div element with the id 'content'.", 'anyfont'),
"footer_text" => __("This setting will apply the selected style to just the footer element on every page of your site. WARNING: This setting may not work with all themes as it depends on there being a div element with the id 'footer'.", 'anyfont'),
"custom_element" => __("Apply styles to any Element, Element ID or Element Classname. For more details, please click help in the upper right hand corner of this page.", 'anyfont'),
"fontserv-remote-images" => __("Enable this setting to have all images generated at FontServ instead of your own server.", 'anyfont'),
"fontserv-run-backups" => __("Backup your font files to FontServ.com automatically whenever a change is detected.", 'anyfont'),
"style-backups" => __("Backup all your styles to FontServ.com automatically whenever a change is detected.", 'anyfont'),
"font-family" => __("Select one of your converted fonts from the list in the dropdown menu", 'anyfont'),
"font-formatting" => __("Set whether your styles text should be bold, italic or underlined. Multiple options may be selected.", 'anyfont'),
"text-align-css" => __("Set the styles text to be either left, center or right aligned.", 'anyfont'),
"max-width-text-align" => __("Set the styles text to be aligned to either the left or the center.", 'anyfont'),
"post-type-titles" => __("Custom post type title replacement. Both image styles and css styles can be assigned.", 'anyfont')
);
$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'),
"chk_del_fonts" => __("Are you sure you want to delete the selected font(s)?", 'anyfont'),
"del_font_note" => __("Please note that once a font is deleted, any styles which are using the font will break.", 'anyfont'),
"msg_del_fonts" => __("Deleting Selected Fonts...", 'anyfont'),
"msg_del_styles" => __("Deleting Selected Styles...", 'anyfont'),
"msg_del" => __("Deleting", 'anyfont'),
"err_select_style" => __("No Styles Selected!", 'anyfont'),
"chk_clear_cache" => __("Are you sure you want to clear the cache?\nNote: this action will not delete any uploaded font files.", '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_preview_style" => __("Loading Preview...", '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_LIBDIR.'/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("SETTINGS_PAGE_TITLE", __("AnyFont Settings", 'anyfont'));
$this->tpl->assign("FONTS_PAGE_TITLE", __("Install Fonts", 'anyfont'));
$this->tpl->assign("STYLES_PAGE_TITLE", __("Create Styles", 'anyfont'));
$this->checkAnyFontHealth();
switch($this->page){
case 'settings':
$this->tpl->assign("SETTINGS_ACTIVE_NAV", " nav-tab-active");
$this->getSettings();
break;
case 'fonts':
$this->tpl->assign("FONTS_ACTIVE_NAV", " nav-tab-active");
$this->readFontDir() ? $this->getFonts() : 0;
break;
case 'styles':
$this->tpl->assign("STYLES_ACTIVE_NAV", " nav-tab-active");
if($this->readFontDir()){
$this->getStyles('image');
$this->getStyles('css');
}
break;
}
$this->tpl->assign("HEADER", $this->tpl->fetchParsed("header"));
$this->tpl->assign("VERSION", ANYFONT_VERSION);
$this->tpl->assign("FOOTER_TXT", __("Please click the help button in the top right corner of this page for links to the documentation and support options.", 'anyfont'));
$this->tpl->assign("FOOTER", $this->tpl->fetchParsed("footer"));
$this->page_html = $this->tpl->fetchParsed($this->page);
}
function getSettings(){
$tpl = new fastTPL($this->tplPath);
$tpl->define(array("autoreplace" => "inserts.html",
"cache" => "cache.html",
"disk_cache_settings" => "disk_cache_settings.html",
"fontserv" => "fontserv.html",
"fontserv_settings" => "fontserv_settings.html",
"advanced" => "advanced.html",
"post_block" => "image_single_title_replace.html"
));
$opt = array("auto(Default)" => "auto", "gd" => "php4", "imagick" => "php5", "FontServ.com" => "remote");
$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($tpl, 'anyfont_cat_title', "CAT");
$this->isReplaceEnabled($tpl, 'anyfont_body_text', "BODY");
$this->isReplaceEnabled($tpl, 'anyfont_content_text', "CONTENT");
$this->isReplaceEnabled($tpl, 'anyfont_footer_text', "FOOTER");
$this->isReplaceEnabled($tpl, 'anyfont_tag_title', "TAG");
$this->isReplaceEnabled($tpl, 'anyfont_widget_title', "WIDGET");
$this->isReplaceEnabled($tpl, 'anyfont_blog_title', "BLOG_TITLE");
$this->isReplaceEnabled($tpl, 'anyfont_blog_desc', "BLOG_DESC");
$this->isReplaceEnabled($tpl, 'anyfont_menu', "MENU");
$this->isReplaceEnabled($tpl, 'anyfont_disable_hotlinking', "DISABLE_HOTLINKING");
$this->isReplaceEnabled($tpl, 'anyfont-limit-cache-size', 'CACHE_LIMIT');
$this->isReplaceEnabled($tpl, 'anyfont_cache_show_bytes', 'CACHE_SHOW_BYTES');
$this->isReplaceEnabled($tpl, 'anyfont_cache_dashboard_widget', 'CACHE_DASHBOARD');
$this->isReplaceEnabled($tpl, 'anyfont_enable_gzip', 'ENABLE_GZIP');
$this->isReplaceEnabled($tpl, 'anyfont_enable_tinymce', 'ENABLE_TINYMCE');
$this->isReplaceEnabled($tpl, 'anyfont-enable-custom-fontdir', 'ENABLE_CUSTOM_FONTDIR');
$this->isReplaceEnabled($tpl, 'anyfont-enable-custom-cache', 'ENABLE_CUSTOM_CACHEDIR');
$this->isReplaceEnabled($tpl, 'anyfont_fav_links', 'ENABLE_FAV_LINKS');
$this->isReplaceEnabled($tpl, 'anyfont-use-htaccess', 'ENABLE_HTACCESS');
$this->isReplaceEnabled($tpl, 'anyfont-fontserv-remote-images', 'REMOTE_IMAGES');
$this->isReplaceEnabled($tpl, 'anyfont-fontserv-run-backup', 'BACKUP');
$tpl->assign("REPLACE_H2", __("AutoReplace Titles", 'anyfont'));
$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'));
$tpl->assign("SEO_NOTE", __("The post title, page title, blog name and blog description image replacements are SEO compatible.", 'anyfont'));
$tpl->assign("DISCLAIMER", __("PLEASE NOTE:
The above options may not be compatible with ALL themes and/or custom widgets.", 'anyfont'));
$tpl->assign("DISCLAIMER_CONT", __("If you encounter any problems:
"; echo $fontdetails[13]; echo""; $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]]["description"] = nl2br($fontdetails[10]); $buildlist[$fontdetails[1]]["version"] = $fontdetails[5]; $buildlist[$fontdetails[1]]["author"] = !isset($fontdetails[8]) ? $fontdetails[9] : $fontdetails[8]; $buildlist[$fontdetails[1]]["url"] = $fontdetails[12]; $buildlist[$fontdetails[1]]["license"] = nl2br($fontdetails[13]); $buildlist[$fontdetails[1]]["filename"] = $this->getFontName($e); $buildlist[$fontdetails[1]]["file"] = $e; $buildlist[$fontdetails[1]]["webfont"] = file_exists(ANYFONT_FONTDIR ."/".substr($e, 0, -4).".eot") ? "Yes" : "No"; // $buildlist[$fontdetails[1]]["cufon"] = file_exists(ANYFONT_FONTDIR ."/".substr($e, 0, -4).".js") ? "Yes" : "No"; (count($buildlist[$fontdetails[1]]["type"]) <= 1) ? array_push($sortlist, $fontdetails[1]) : 0; } } natcasesort($sortlist); foreach($sortlist as $fontname){ $this->fontlist[$fontname] = $buildlist[$fontname]; } if(!$returndata){ return true; } else { return $this->fontlist; } } } function readStyles($type){ if(file_exists(ANYFONT_FONTDIR."/styles.ini")){ $styles = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true); if(isset($styles['admin'])) unset($styles['admin']); $new_styles = array( "image" => $styles, "css" => array() ); anyfont_write_styles($new_styles); unlink(ANYFONT_FONTDIR."/styles.ini"); } $styles = unserialize(get_option('anyfont_styles')); return $styles[$type]; } function getHelpText($section){ $helptext = isset($this->helptext[$section]) ? $this->helptext[$section] : $this->helptext['default']; return ""; } function bytecalc($bytes, $base10=false, $round=0){ $labels=array('bytes', 'kB', 'MB', 'GB'); if (($bytes <= 0) || (! is_array($labels)) || (count($labels) <= 0)) return "0 bytes"; $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 = round($bytes/pow($base,$pow),$round).$lab; get_option("anyfont_cache_show_bytes") == "on" ? $text = $bytes." bytes (".$text.")" : 0; 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]); } } } } // echo "
";print_r($font_tags);echo "\n"; return $font_tags; } function is_font($filename){ $ext = explode('.', $filename); $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($filename){ $fontfile = explode(".", $filename); $fontname = ""; for($i = 0; $i < (count($fontfile)-1);$i++){ $i > 0 ? $fontname .= "." : 0; $fontname .= $fontfile[$i]; } return $fontname; } function getStyles($type){ if(!is_array($this->fontlist) || count($this->fontlist) <= 0){ $this->readFontDir(); } if($type == "css"){ $fonts = $this->fontlist; foreach($fonts as $displayname => $fontdetail){ if($fontdetail['webfont'] != "Yes"){ unset($fonts[$displayname]); } } if(count($fonts) == 0){ $this->tpl->assign(strtoupper($type)."_STYLES", "
"; $this->styletpl->assign("NEW_STYLE_FORM", $new_style); $this->styletpl->assign("STYLES", $styles); $this->styletpl->assign("TYPE", $type); $this->tpl->assign(strtoupper($type)."_STYLES", $this->styletpl->fetchParsed("styles_list")); } function getStyleBlock($style, $option, $type){ if(!is_array($this->fontlist) || count($this->fontlist) <= 0){ $this->readFontDir(); } $styleBlocktpl = new fastTPL($this->tplPath); $styleBlocktpl->define(array("styles_block" => "styles_block.html")); $url = get_bloginfo('wpurl'); $styleBlocktpl->assign('TYPE', $type); $style_id = str_replace(" ", "__", $style); $styleBlocktpl->assign('STYLE_NAME', $style); $styleBlocktpl->assign('STYLE_NAME_ID', $style_id); $options = ""; $styleBlocktpl->assign('DELETE_ICON', ANYFONT_URL."/img/icon-delete.png"); $styleBlocktpl->assign('EDIT_ICON', ANYFONT_URL."/img/icon-edit.png"); $styleBlocktpl->assign('OPTIONS', $options); return $styleBlocktpl->fetchParsed("styles_block"); } function showError($err){ // global $anyfont_errors; update_option('anyfont_init_error', $err); // add_action( 'admin_notices', create_function('', 'echo \'
ERROR:'.get_option('anyfont_init_error').'