checkAnyFontHealth() !== false){
update_option("anyfont_init_error", 0);
}
}
//check cache size limit
if( get_option( 'anyfont-limit-cache-size' ) && get_option( 'anyfont_cache_last_checked' ) < ( time()+( 24*60*60 ) ) ){
if(is_readable(ANYFONT_CACHE)){
$cachedir = opendir( ANYFONT_CACHE );
$cachesize = 0;
while ($curfile = readdir($cachedir)) {
if(!is_dir($curfile)){
$cachesize += filesize(ANYFONT_CACHE."/$curfile");
}
}
$cache_limit = 1048576*(int)get_option('anyfont-cache-size-limit');
if($cachesize > $cache_limit){
$cachedir = opendir(ANYFONT_CACHE);
while ($curfile = readdir($cachedir)) {
if(!is_dir($curfile)){
$split = explode("-", $curfile);
if($split[1] == "admin.png"){
unlink(ANYFONT_CACHE."/$curfile");
}
}
}
}
update_option('anyfont_cache_last_checked', time());
}
}
function anyfont_admin_menu(){
$settings = __("Settings", 'anyfont');
$fontmanager = __("Manage Fonts", 'anyfont');
$stylemanager = __("Manage Styles", 'anyfont');
add_menu_page('AnyFont', 'AnyFont', 8, 'anyfont-settings', 'anyfont_settings_page', ANYFONT_URL."/img/anyfont-icon.png");
add_submenu_page('anyfont-settings', $settings, $settings, 8, 'anyfont-settings', 'anyfont_settings_page');
add_submenu_page('anyfont-settings', $fontmanager, $fontmanager, 8, 'anyfont-fonts', 'anyfont_fonts_page');
add_submenu_page('anyfont-settings', $stylemanager, $stylemanager, 8, 'anyfont-styles', 'anyfont_styles_page');
}
function anyfont_settings_page(){
require_once(ANYFONT_LIBDIR."/class.admin.php");
$config = array("page" => "settings", "title" => __("Settings", 'anyfont'));
$page = new anyfontAdmin($config);
$page->printPage();
}
function anyfont_fonts_page() {
require_once(ANYFONT_LIBDIR."/class.admin.php");
$config = array("page" => "fonts", "title" => __("Font Manager", 'anyfont'));
$page = new anyfontAdmin($config);
$page->printPage();
}
function anyfont_styles_page() {
require_once(ANYFONT_LIBDIR."/class.admin.php");
$config = array("page" => "styles", "title" => __("Style Manager", 'anyfont'));
$page = new anyfontAdmin($config);
$page->printPage();
}
function anyfont_insert_scripts() {
$page_req = parse_url( $_SERVER['REQUEST_URI']);
if(isset($page_req['query'])){
$page = explode("=", $page_req['query']);
$anyfont_pages = array('anyfont-settings','anyfont-fonts','anyfont-styles');
if(in_array($page[1], $anyfont_pages)){
wp_enqueue_script("anyfont", ANYFONT_URL."/anyfont.js", array('prototype', 'scriptaculous'));
}
}
}
/**
* Check if permalinks are in use.
* @return boolean
*/
function anyfont_check_permalink_status(){
return (get_option("permalink_structure") != '' && !get_option('anyfont-use-htaccess')) ? true : false;
}
/**
* Update .htaccess file according to permalink status
* @param string
*/
function anyfont_update_permalink_status($rules){
if((!anyfont_check_permalink_status() && $rules !== "uninstall") || (!anyfont_check_permalink_status() && $rules === "install")){
$htaccess_file = ABSPATH.".htaccess";
$anyfont_url = parse_url(ANYFONT_URL);
$anyfont_path = trailingslashit($anyfont_url['path']);
$rules = "# BEGIN AnyFont\n";
$rules .= "
";
}else{
return $title;
}
}
}
function anyfont_replace_tag_title($title){
$uri = explode("/", $_SERVER['REQUEST_URI']);
if(get_option('anyfont_tag_title') && !in_array("wp-admin", $uri)){
remove_filter("single_tag_title", "anyfont_replace_tag_title", 10, 2);
$style = get_option('anyfont_tag_title_style');
$url = get_option('siteurl');
$urltitle = urlencode($title);
$style = urlencode($style);
return "
";
}else{
return $title;
}
}
function anyfont_replace_cat_title($title){
$uri = explode("/", $_SERVER['REQUEST_URI']);
if(is_category() && get_option('anyfont_cat_title') && !in_array("wp-admin", $uri)){
remove_filter("single_cat_title", "anyfont_replace_cat_title", 10, 2);
$style = get_option('anyfont_cat_title_style');
$url = get_option('siteurl');
$urltitle = urlencode($title);
$style = urlencode($style);
echo "
";
}else{
return $title;
}
}
function anyfont_replace_widget_title($params){
if(get_option('anyfont_widget_title')){
$style = urlencode(get_option('anyfont_widget_title_style'));
$url = get_option('siteurl');
foreach($params as $key => $param){
if(!preg_match("//", $params[$key]['before_title'], $match) && !preg_match("//", $params[$key]['after_title'], $match)){
$params[$key]['before_title'] = $params[$key]['before_title']."".$params[$key]['after_title'];
}
}
}
return $params;
}
function anyfont_update_option(){
if(is_array($_REQUEST['option'])){
foreach($_REQUEST['option'] as $option){
if(!is_array($_REQUEST[$option])){
update_option($option , $_REQUEST[$option]);
$option === 'anyfont-use-htaccess' && $_REQUEST['anyfont-use-htaccess'] == "on" ? anyfont_update_permalink_status("install") : 0;
if($option == 'anyfont-limit-cache-size' || $option == 'anyfont-cache-size-limit'){
require_once(ANYFONT_LIBDIR."/class.admin.php");
$html = new anyfontAdmin(false);
$html->checkAnyFontHealth(false);
$return = array("type"=>"replace",
"block"=>"anyfont_disk_usage",
"content"=>$html->getDiskCache(true),
"message"=>__("Your settings have been saved!", 'anyfont')
);
} else {
$return = array("type"=>"message",
"message"=>__("Your settings have been saved!", 'anyfont')
);
}
}else {
$result = $_REQUEST[$option]['result'] == "on" ? true : false;
update_option($option , $result);
if($result){
if($option['style'] !== "false"){
update_option($option."_style", $_REQUEST[$option]['style']);
if($option == "anyfont_menu"){
update_option($option."_hover", $_REQUEST[$option]['hover']);
update_option($option."_active", $_REQUEST[$option]['active']);
}
$return = array("type"=>"message",
"message"=>__("Your settings have been saved!", 'anyfont')
);
} else {
$return = array("type"=>"message",
"message"=>__("Error: No Style Selected! If you have not created any styles yet, click here to go to the style manager now.", 'anyfont')
);
}
}
}
}
}
anyfont_return_json($return);
}
function anyfont_return_json($return){
header("Content-type: application/json");
if (function_exists('json_encode')) {
echo json_encode($return);
exit(0);
} else {
require_once(ANYFONT_ROOT.'/lib/class.json.php');
$JSON = new serviceJSON();
echo $JSON->encode($return);
exit(0);
}
}
function anyfont_bloginfo_replace($output, $show){
switch($show){
case 'name':
if(get_option('anyfont_blog_title')){
$style = get_option('anyfont_blog_title_style');
$url = get_option('siteurl');
$urltitle = urlencode($output);
$style = urlencode($style);
!get_option('anyfont_blog_desc') ? remove_filter("bloginfo", "anyfont_bloginfo_replace", 10, 2) : 0;
return "
";
}else{
return $output;
}
case 'description':
if(get_option('anyfont_blog_desc')){
$style = get_option('anyfont_blog_desc_style');
$url = get_option('siteurl');
$urltitle = urlencode($output);
$style = urlencode($style);
remove_filter("bloginfo", "anyfont_bloginfo_replace", 10, 2);
return "
";
}else{
return $output;
}
default:
return $output;
}
}
function anyfont_img_output(){
// if(anyfont_ini_get_bool('display_errors')){
// ini_set('display_errors', 0);
// }
if($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']){
$site_url = parse_url(get_option('siteurl'));
$referer = parse_url($_SERVER['HTTP_REFERER']);
if(!strstr($site_url['host'], $referer['host']) && get_option('anyfont_disable_hotlinking')){
wp_redirect(get_option('siteurl'));
exit(0);
}
}
$req_vars = explode( "/", (!defined("ANYFONT_IMG_VAR") ? $_SERVER['REQUEST_URI'] : ANYFONT_IMG_VAR));
foreach($req_vars as $n => $v){
if($v == "images"){
$sn = $n;
continue;
}
}
$style = urldecode($req_vars[($sn+1)]);
$text = str_replace(".png", "", html_entity_decode(urldecode($req_vars[($sn+2)]), ENT_QUOTES, 'UTF-8'));
$displaytext = isset($req_vars[($sn+3)]) ? str_replace(".png", "", html_entity_decode(urldecode($req_vars[($sn+3)]), ENT_QUOTES, 'UTF-8')) : false;
if(!isset($text) || !isset($style)){
wp_redirect(get_option('siteurl'));
exit(0);
}else{
$gzip = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') ? get_option('anyfont_enable_gzip') == "on" ? 1 : 0 : 0 : 0;
require_once(ANYFONT_LIBDIR."/".ANYFONT_LIB_VERSION."/class.image.php");
new ttfImage($text, $style, $displaytext, $gzip);
}
}
function anyfont_img_headers($headers){
$headers = false;
return $headers;
}
function anyfont_add_header_filter(){
add_filter("bloginfo", "anyfont_bloginfo_replace", 10, 2);
add_filter("single_cat_title", "anyfont_replace_cat_title", 10, 2);
add_filter("single_tag_title", "anyfont_replace_tag_title", 10, 2);
}
function anyfont_page_menu_filter($menu){
$url = get_option('siteurl');
$urltitle = urlencode($url);
$standard = $url.'/images/'.urlencode(get_option('anyfont_menu_style'));
$hover = $url.'/images/'.urlencode(get_option('anyfont_menu_hover'));
if(!anyfont_check_permalink_status()){
$active = $url.'/images/'.urlencode(get_option('anyfont_menu_active'));
if($_SERVER['REQUEST_URI'] == "/"){
$page = "/home/i";
} else {
$url_array = explode("/", $_SERVER['REQUEST_URI']);
$count = count($url_array);
$page = "/".$url_array[$count-2]."/i";
}
}
if(preg_match_all('/title="([\w*\.*\?*\!*\s*]+)/', $menu, $titles) > 0){
$n=0;
foreach($titles[0] as $key){
if(!anyfont_check_permalink_status()){
$imgurl = preg_match($page, $titles[1][$n]) ? $active : $standard;
}else{
$imgurl = $standard;
}
$encoded_title = urlencode($titles[1][$n]);
$menu = preg_replace("/($key\W.*>??)({$titles[1][$n]})/", '$1
', $menu);
$n++;
}
}
return $menu;
}
function anyfont_ini_get_bool($a){
$b = ini_get($a);
switch (strtolower($b)){
case 'on':
case 'yes':
case 'true':
return 'assert.active' !== $a;
case 'stdout':
case 'stderr':
return 'display_errors' === $a;
default:
return (bool)(int)$b;
}
}
function anyfont_register_button($buttons) {
array_push($buttons, "separator", "anyfont");
return $buttons;
}
function anyfont_add_tinymce_plugin($plugin_array) {
$plugin_array['anyfont'] = WP_PLUGIN_URL.'/anyfont/mce_anyfont/editor_plugin.js';
return $plugin_array;
}
function anyfont_settings_link($links, $filename) {
$filename == plugin_basename(__FILE__) ? array_unshift($links, 'Settings') : 0;
return $links;
}
function anyfont_dashboard_widget_function() {
require_once(ANYFONT_LIBDIR."/class.admin.php");
$html = new anyfontAdmin(false);
$html->checkAnyFontHealth();
echo $html->getDiskCache();
}
function anyfont_dashboard_widget() {
wp_add_dashboard_widget('anyfont_dashboard_widget', 'AnyFont Disk Usage Summary', 'anyfont_dashboard_widget_function');
}
function anyfont_dec2ord($dec){
return anyfont_dec2hex(ord($dec));
}
function anyfont_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 anyfont_get_font_info($filename){
$fd = fopen ($filename, "r");
$text = fread ($fd, filesize($filename));
fclose ($fd);
$number_of_tables = hexdec(anyfont_dec2ord($text[4]).anyfont_dec2ord($text[5]));
for($i=0;$i<$number_of_tables;$i++){
$tag = $text[12+$i*16].$text[12+$i*16+1].$text[12+$i*16+2].$text[12+$i*16+3];
if($tag == 'name'){
$ntOffset = hexdec(
anyfont_dec2ord($text[12+$i*16+8]).anyfont_dec2ord($text[12+$i*16+8+1]).
anyfont_dec2ord($text[12+$i*16+8+2]).anyfont_dec2ord($text[12+$i*16+8+3])
);
$offset_storage_dec = hexdec(anyfont_dec2ord($text[$ntOffset+4]).anyfont_dec2ord($text[$ntOffset+5]));
$number_name_records_dec = hexdec(anyfont_dec2ord($text[$ntOffset+2]).anyfont_dec2ord($text[$ntOffset+3]));
}
}
$storage_dec = $offset_storage_dec + $ntOffset;
$storage_hex = strtoupper(dechex($storage_dec));
for($j=0;$j<$number_name_records_dec;$j++){
$platform_id_dec = hexdec(anyfont_dec2ord($text[$ntOffset+6+$j*12+0]).anyfont_dec2ord($text[$ntOffset+6+$j*12+1]));
$name_id_dec = hexdec(anyfont_dec2ord($text[$ntOffset+6+$j*12+6]).anyfont_dec2ord($text[$ntOffset+6+$j*12+7]));
$string_length_dec = hexdec(anyfont_dec2ord($text[$ntOffset+6+$j*12+8]).anyfont_dec2ord($text[$ntOffset+6+$j*12+9]));
$string_offset_dec = hexdec(anyfont_dec2ord($text[$ntOffset+6+$j*12+10]).anyfont_dec2ord($text[$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($text[$storage_dec+$string_offset_dec+$l]) == '0'){
continue;
} else {
$font_tags[$name_id_dec] .= ($text[$storage_dec+$string_offset_dec+$l]);
}
}
}
}
return $font_tags;
}
function anyfont_check_apache_module($mod_name){
if(function_exists("apache_get_modules")){
$modules = apache_get_modules();
return in_array($mod_name, $modules);
} else {
return "result unknown";
}
}
if(defined("ANYFONT_IMG_VAR") || preg_match("/\/images\/(.*)\.png/", $_SERVER['REQUEST_URI'])){
add_filter("wp_headers", "anyfont_img_headers");
add_action('plugins_loaded', 'anyfont_img_output');
} else {
if(get_option('anyfont_menu') != false){
add_filter("wp_page_menu", 'anyfont_page_menu_filter');
add_filter("wp_list_page", 'anyfont_page_menu_filter');
add_filter("wp_list_pages", 'anyfont_page_menu_filter');
add_filter("wp_nav_menu_items", "anyfont_page_menu_filter");
}
add_filter("dynamic_sidebar_params", "anyfont_replace_widget_title");
if(is_single()){
add_filter("single_post_title", "anyfont_replace_title");
}
add_filter("the_title", "anyfont_replace_title");
add_filter( 'plugin_action_links', 'anyfont_settings_link', 10, 2 );
add_action("wp_head", "anyfont_add_header_filter", 10, 0);
add_action("permalink_structure_changed", "anyfont_update_permalink_status");
if(get_option('anyfont_cache_dashboard_widget') != false){
add_action('wp_dashboard_setup', 'anyfont_dashboard_widget' );
}
if(get_option('anyfont_enable_tinymce') != false){
add_filter("mce_external_plugins", "anyfont_add_tinymce_plugin");
add_filter('mce_buttons', 'anyfont_register_button');
}
if(get_option("anyfont_init_error") != false){
add_action( 'admin_notices', create_function('', 'echo \'