tplPath = ANYFONT_ROOT."/tpl";
if(is_array($config) && isset($config['page'])){
$this->page = $config['page'];
$this->page_title = $config['title'];
self::get_page();
}
}
public function printPage(){
print($this->page_html);
}
private 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':
self::getSettings();
break;
case 'fonts':
self::readFontDir();
self::getFonts();
break;
case 'styles':
self::readFontDir();
self::getStyles();
break;
}
$this->tpl->assign("FOOTER", $this->tpl->fetchParsed("footer"));
$this->page_html = $this->tpl->fetchParsed($this->page);
}
private 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 .= "";
}
}
self::isReplaceEnabled(get_option('anyfont_page_title'), "PAGE");
self::isReplaceEnabled(get_option('anyfont_post_title'), "POST");
self::isReplaceEnabled(get_option('anyfont_cat_title'), "CAT");
self::isReplaceEnabled(get_option('anyfont_tag_title'), "TAG");
self::isReplaceEnabled(get_option('anyfont_widget_title'), "WIDGET");
self::isReplaceEnabled(get_option('anyfont_blog_title'), "BLOG_TITLE");
self::isReplaceEnabled(get_option('anyfont_blog_desc'), "BLOG_DESC");
self::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", self::titleStyleConfig( get_option('anyfont_post_title_style')));
$this->tpl->assign("PAGE_TITLE_STYLES", self::titleStyleConfig(get_option('anyfont_page_title_style')));
$this->tpl->assign("TAG_TITLE_STYLES", self::titleStyleConfig(get_option('anyfont_tag_title_style')));
$this->tpl->assign("CAT_TITLE_STYLES", self::titleStyleConfig(get_option('anyfont_cat_title_style')));
$this->tpl->assign("WIDGET_TITLE_STYLES", self::titleStyleConfig(get_option('anyfont_widget_title_style')));
$this->tpl->assign("BLOG_TITLE_STYLES", self::titleStyleConfig(get_option('anyfont_blog_title_style')));
$this->tpl->assign("BLOG_DESC_STYLES", self::titleStyleConfig(get_option('anyfont_blog_desc_style')));
$this->tpl->assign("IMAGE_MODULE_OPTIONS", $imageopt);
$this->tpl->assign("STYLE_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", self::bytecalc($totalsize));
}
private 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\"");
}
}
private function titleStyleConfig($section){
$styleoptions = '';
if(file_exists(ANYFONT_FONTDIR."/styles.ini")){
$styles = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true);
foreach($styles as $style => $option){
if($style != "admin"){
$selected = $style == $section ? "selected=\"selected\"" : '';
$styleoptions .= "";
}
}
}
return $styleoptions;
}
private 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']);
$tpl->assign('FONT_NAME', $fontname);
$tpl->assign('DISPLAY_NAME', $displayname);
$tpl->assign('FONT_URL', get_bloginfo('wpurl')."/images/admin/$fontname/$displayname.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");
}
private 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 != '..'){
array_push($filelist, $e);
}
}
}
natcasesort($this->fontlist);
foreach($filelist as $file){
if (self::is_font($file) === true){
$fontdetails = $this->getFontInfo( ANYFONT_FONTDIR ."/". $file);
$font["name"] = $fontdetails[1];
$font["type"] = $fontdetails[2];
$font["trademark"] = $fontdetails[7];
$font["copyright"] = $fontdetails[10];
$font["version"] = $fontdetails[5];
$font["author"] = !isset($fontdetails[8]) ? $fontdetails[9] : $fontdetails[8];
$font["url"] = $fontdetails[11];
$font["license"] = $fontdetails[13];
$font["filename"] = self::getFontName($file);
$buildlist[$fontdetails[1]] = $font;
array_push($sortlist, $fontdetails[1]);
}
}
natcasesort($sortlist);
foreach($sortlist as $fontname){
$this->fontlist[$fontname] = $buildlist[$fontname];
}
// echo '
'; // print_r($this->fontlist); // echo ''; // exit(); } private function getStyles(){ $styles = ""; 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.=self::getStyleBlock($style, $option); } } } $new_style = "