"settings", "title" => "Settings"); $page = new anyfontAdmin($config); $page->printPage(); } function anyfont_fonts_page() { $config = array("page" => "fonts", "title" => "Font Manager"); $page = new anyfontAdmin($config); $page->printPage(); } function anyfont_styles_page() { $config = array("page" => "styles", "title" => "Style Manager"); $page = new anyfontAdmin($config); $page->printPage(); } function anyfont_insert_scripts() { wp_enqueue_script("anyfont", ANYFONT_URL."/anyfont.js", array('prototype', 'scriptaculous')); } function anyfont_install(){ $home_root = parse_url(get_option('home')); if ( isset( $home_root['path'] ) ) { $home_root = trailingslashit($home_root['path']); } else { $home_root = '/'; } if(!file_exists(ANYFONT_CACHE)){ mkdir(ANYFONT_CACHE, 0777); } if(!file_exists(ANYFONT_FONTDIR)){ mkdir(ANYFONT_FONTDIR, 0777); } $htaccess_file = ABSPATH.".htaccess"; $rules = "# BEGIN AnyFont\n"; $rules .= "\n"; $rules .= "RewriteEngine On\n"; $rules .= "RewriteBase $home_root\n"; $rules .= "RewriteRule ^images/(.*)/(.*)\.png$ wp-content/plugins/anyfont/img.php?t=$2&s=$1 [L]\n"; $rules .= "\n\n"; $rules .= "# END AnyFont\n\n"; if(!file_exists($htaccess_file)){ file_put_contents($htaccess_file, $rules); } else { $orig = file_get_contents($htaccess_file); if(!strstr($orig, $rules)){ file_put_contents($htaccess_file, $rules.$orig); } } if(file_exists(ANYFONT_FONTDIR."/styles.ini")){ if(file_exists(ANYFONT_ROOT."/styles.default")){ unlink(ANYFONT_ROOT."/styles.default"); } } if(file_exists(ANYFONT_ROOT."/styles.default")){ file_put_contents(ANYFONT_FONTDIR."/styles.ini", file_get_contents(ANYFONT_ROOT."/styles.default")); unlink(ANYFONT_ROOT."/styles.default"); } } function anyfont_uninstall(){ $htaccess_file = ABSPATH.".htaccess"; $rules = "# BEGIN AnyFont\n"; $rules .= "\n"; $rules .= "RewriteEngine On\n"; $rules .= "RewriteBase $home_root\n"; $rules .= "RewriteRule ^images/(.*)/(.*)\.png$ wp-content/plugins/anyfont/img.php?t=$2&s=$1 [L]\n"; $rules .= "\n\n"; $rules .= "# END AnyFont\n\n"; $len = strlen($rules)+14; if(is_writeable($htaccess_file)){ if(file_exists($htaccess_file)){ $contents = file_get_contents($htaccess_file); $start = strpos($contents, "# BEGIN AnyFont\n"); if(is_numeric($start)){ $new_contents = substr_replace($contents, "", $start, $len); file_put_contents($htaccess_file, $new_contents); } } } } function serializeArray($array, $prefix = ''){ $ini = array(); if( is_array($array)){ ksort($array); foreach ($array as $key => $value){ // parse data types if ($value === true || $value == '1') $value = 'true'; else if ($value === false || $value === '') $value = 'false'; else if (is_string($value) && $key != 'font-size') $value = '"' . addslashes($value) . '"'; // serialize value if (!is_array($value) && !is_numeric($key)) $ini[] = ($prefix ? $prefix . '.' : '') . $key . ' = ' . $value; else if (!is_array($value)) $ini[] = $prefix . '[] = ' . $value; else $ini = array_merge($ini, serializeArray($value, ($prefix ? $prefix . '.' : '') . $key)); } return $ini; } else { return false; } } function anyfont_edit_styles(){ if(isset($_REQUEST['update_style']) && $_REQUEST['update_style'] != ''){ $style = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true); $style[$_REQUEST['update_style']]['font-name'] = $_REQUEST['font-name']; $style[$_REQUEST['update_style']]['font-size'] = intval($_REQUEST['font-size']); $style[$_REQUEST['update_style']]['color'] = str_replace("#", "", $_REQUEST['color']); $style[$_REQUEST['update_style']]['shadow'] = $_REQUEST['shadow'] == 'on' ? true : false; $style[$_REQUEST['update_style']]['shadow-color'] = str_replace("#", "", $_REQUEST['shadow-color']); anyfont_write_styles($style); if(!isset($_REQUEST['new-style'])){ $result = array("status" => "saved", "stylename" => $_REQUEST['update_style'], "img" => base64_encode(file_get_contents(get_option('siteurl')."/images/".urlencode($_REQUEST['update_style'])."/".urlencode($_REQUEST['update_style']).".png")) ); } else { $admn = new anyfontAdmin(); $style_block = $admn->getStyleBlock($_REQUEST['update_style'], $style[$_REQUEST['update_style']]); $result = array("status" => "savedNew", "styleblock" => $style_block, "msg" => $_REQUEST['update_style']." has been saved."); } } else { $result = array("status" => "failed", "error" => "Please enter the style name."); } echo json_encode($result); } function anyfont_write_styles($style){ ksort($style); $sections = array_unique(array_merge(array(''), array_keys($style))); $ini = array(); foreach ($sections as $section) { // write sections if ($section != '') $ini[] = '[' . $section . ']'; // serialize value array if(is_array($style[$section])){ $ini = array_merge($ini, serializeArray($style[$section])); } $ini[] = ''; } file_put_contents(ANYFONT_FONTDIR."/styles.ini", implode("\r\n", $ini)); } function anyfont_delete_font(){ if(isset($_REQUEST['font-name'])){ $font = $_REQUEST['font-name']; unlink(ANYFONT_FONTDIR."$font.ttf"); echo "$font has been deleted."; }else if(isset($_REQUEST['fonts'])){ $fonts = explode(",", $_REQUEST['fonts']); foreach($fonts as $font){ $font = str_replace("[amp]", "&", $_REQUEST['font-name']); unlink(ANYFONT_FONTDIR."/$font.ttf"); } echo "The selected fonts have been deleted."; } } function anyfont_delete_style(){ $style = parse_ini_file(ANYFONT_FONTDIR."/styles.ini", true); if(isset($_REQUEST['styles'])){ $styles = explode(",", $_REQUEST['styles']); foreach($styles as $stylename){ unset($style[$stylename]); $msg = "The selected styles have been deleted."; } }else if(isset($_REQUEST['style-name'])){ unset($style[$_REQUEST['style-name']]); $msg = $_REQUEST['style-name']." has been deleted."; } anyfont_write_styles($style); echo $msg; } function anyfont_clear_cache(){ $cachedir = ANYFONT_CACHE; $dir = opendir($cachedir); while ($file = readdir($dir)) { if($file !== ".." || $file !== ".") unlink($cachedir."/".$file); } rmdir($cachedir); mkdir($cachedir, 0777); echo "Cache Cleared"; } // function anyfont_replace_title($title){ // $uri = explode("/", $_SERVER['REQUEST_URI']); // $title_replace = get_option('anyfont_replace_title'); // if($title_replace && !in_array("wp-admin", $uri)){ // $style = get_option('anyfont_replace_title_style'); // $url =get_option('siteurl'); // $urltitle = urlencode($title); // return "\"$title\""; // }else{ // return $title; // } // } // // function anyfont_update_option(){ // $result = $_REQUEST['result'] == "on" ? true : false; // update_option($_REQUEST['option'], $result); // if($_REQUEST['style'] !== "false"){ // update_option('anyfont_replace_title_style', $_REQUEST['style']); // echo "AutoReplace Options Updated!"; // } else { // echo "No Style Selected!"; // } // } register_activation_hook(__FILE__, 'anyfont_install'); register_deactivation_hook(__FILE__, 'anyfont_uninstall'); add_action('wp_ajax_anyfont_edit_styles', 'anyfont_edit_styles'); add_action('wp_ajax_anyfont_delete_font', 'anyfont_delete_font'); add_action('wp_ajax_anyfont_delete_style', 'anyfont_delete_style'); add_action('wp_ajax_anyfont_clear_cache', 'anyfont_clear_cache'); // add_action('wp_ajax_anyfont_update_option', 'anyfont_update_option'); add_action('admin_menu', 'anyfont_admin_page'); add_action("admin_print_scripts", 'anyfont_insert_scripts'); // add_filter("the_title", "anyfont_replace_title"); ?>