tplPath = ABSPATH."wp-content/plugins/anyfont/tpl"; self::readFontDir(); 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); } public function getStyleBlock($style, $option){ $url = get_bloginfo('wpurl'); $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 = "
"; $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"); } private function get_page(){ $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("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::getFonts(); break; case 'styles': 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; self::isReplaceEnabled(AF_PAGE_TITLE, "PAGE"); self::isReplaceEnabled(AF_POST_TITLE, "POST"); self::isReplaceEnabled(AF_WIDGET_TITLE, "WIDGET"); $this->tpl->assign("POST_TITLE_STYLES", self::titleStyleConfig(AF_POST_TITLE_STYLE)); $this->tpl->assign("PAGE_TITLE_STYLES", self::titleStyleConfig(AF_PAGE_TITLE_STYLE)); $this->tpl->assign("WIDGET_TITLE_STYLES", self::titleStyleConfig(AF_WIDGET_TITLE_STYLE)); $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", self::bytecalc($totalsize)); } private function isReplaceEnabled($section, $assign){ if($section){ $this->tpl->assign("{$assign}_CHECKED", "checked=\"checked\""); } else { $this->tpl->assign("{$assign}_DISABLED", "disabled=\"disabled\""); } } private 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; } private function getFonts(){ $list = ""; $tpl = new fastTPL($this->tplPath); $tpl->define(array("font_block" => "fonts-block.html")); self::readFontDir(); foreach($this->fontlist as $name){ $urlname = $name; $tpl->assign('FONT_NAME', $name); $tpl->assign('FONT_URL', get_bloginfo('wpurl')."/images/admin/$urlname.png"); $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() { $fontdir = ANYFONT_FONTDIR; $this->fontlist = array(); if(!is_dir($fontdir)){ return false; } else { $dir = opendir($fontdir); while ($file = readdir($dir)) { $fileinfo = explode(".", $file); if ($fileinfo[1] == "ttf") { array_push($this->fontlist, $fileinfo[0]); } } } } private function getStyles(){ $styles = ""; $settings = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true); foreach($settings as $style => $option){ if($style != "admin"){ $styles.=self::getStyleBlock($style, $option); } } $new_style = "