Changeset 1172963
- Timestamp:
- 06/02/2015 05:51:21 PM (11 years ago)
- Location:
- typecase/trunk
- Files:
-
- 1 deleted
- 1 edited
-
pro.php (deleted)
-
typecase.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
typecase/trunk/typecase.php
r1047561 r1172963 4 4 Plugin URI: http://wordpress.org/plugins/typecase/ 5 5 Description: A plugin that makes it dead simple to add custom webfonts to your website. 6 Version: 1.1. 16 Version: 1.1.2 7 7 Author: UpThemes 8 8 Author URI: https://upthemes.com … … 52 52 53 53 /** 54 * PHP 5.3 and lower compatibility55 *56 * @uses Typecase::__construct()57 *58 */59 public function Typecase(){60 $this->__construct();61 }62 63 /**64 54 * Constructor for the Typecase class 65 55 * … … 92 82 add_action('after_setup_theme', array($this, 'customizer_init') ); 93 83 94 } 95 96 /** 97 * Initializes the Typecase() class 98 * 99 * Checks for an existing Typecase() instance 100 * and if it doesn't find one, creates it. 101 * 102 * @uses Typecase() 103 * 104 */ 105 public function &init() { 106 static $instance = false; 107 108 if ( !$instance ) { 109 $instance = new Typecase(); 84 85 86 add_action('wp_ajax_reloadFontPreview',array(&$this,'ajax_reload_font_preview')); 87 add_action('init',array(&$this,'set_pro_filters'),1); 88 89 if( isset($_GET['front_end_editor']) && !is_admin() ){ 90 remove_action('wp_head',array(&$this,'display_frontend')); 91 add_action('init',array(&$this,'set_front_end_filters'),1); 92 add_action('init',array(&$this,'admin_styles')); 93 add_action('wp_head',array(&$this,'frontend_js_globals')); 94 add_action('wp_enqueue_scripts', array(&$this,'frontend_scripts')); 95 add_action('wp_footer',array(&$this,'ui')); 110 96 } 111 112 return $instance;113 97 } 114 98 … … 864 848 } 865 849 850 851 /** 852 * Set up Typecase Pro admin filters 853 * 854 * Sets up all the appropriate filters for Pro version 855 * within the admin section of plugin. 856 * 857 * @uses add_filter() 858 * 859 */ 860 public function set_pro_filters(){ 861 add_filter('typecase-buttons',array(&$this,'buttons_replace')); 862 } 863 864 /** 865 * Set up Typecase Pro front-end filters 866 * 867 * Sets up all the appropriate filters for Pro version 868 * within front-end of plugin. 869 * 870 * @uses add_filter() 871 * 872 */ 873 public function set_front_end_filters(){ 874 add_filter('typecase-front-end-editor',array(&$this,'front_end_editor_ui')); 875 add_filter('typecase-classname',array(&$this,'front_end_classname')); 876 } 877 878 /** 879 * Set up global variables for our Javascript on the frontend. 880 * 881 * @uses admin_url() 882 * 883 */ 884 public function frontend_js_globals() { 885 $admin_url = admin_url('admin-ajax.php'); 886 $output = " 887 <script type='text/javascript'> 888 var ajaxurl = '$admin_url'; 889 var frontend = true; 890 </script>"; 891 echo $output; 892 } 893 894 /** 895 * Enqueues scripts/styles for front-end editor 896 * 897 * @uses wp_enqueue_style() 898 * @uses wp_enqueue_script() 899 * @uses plugins_url() 900 * 901 */ 902 public function frontend_scripts(){ 903 wp_enqueue_style('front-end-editor', plugins_url( 'styles/front_end_editor.css', TYPECASE_FILE ), false, date( 'Ymd' ) ); 904 wp_enqueue_script('front-end-editor', plugins_url( 'scripts/pro.js', TYPECASE_FILE ), false, date( 'Ymd' ) ); 905 } 906 907 /** 908 * Live font preview updater. 909 * 910 * Regenerates the CSS for our fonts every time something gets saved. 911 * 912 * @uses get_option() 913 * @uses explode() 914 * @uses substr() 915 * @uses strpos() 916 * @uses mb_substr() 917 * @uses str_replace() 918 * @uses json_encode() 919 * @uses header() 920 * 921 */ 922 public function ajax_reload_font_preview(){ 923 $fonts = get_option('typecase_fonts'); 924 925 if( $fonts[0] ){ 926 927 $apiUrl = &$this->api_url; 928 $import_url = ''; 929 $font_styles = ''; 930 931 foreach($fonts as $font){ 932 933 $family = explode("|",$font[0]); 934 $family = $family[0]; 935 $selectors = substr( $font[1], 1); 936 $weights = substr( $font[2], 1); 937 938 $import_url .= str_replace(" ","+",$family).$this->stringify_font_part($weights).$this->stringify_font_part($charsets); 939 940 $selectors = explode("|",$selectors); 941 942 foreach( $selectors as $i => $selector){ 943 if($i>0) 944 $font_styles .= ","; 945 $font_styles .= $selector; 946 } 947 948 $font_styles .= "{ font-family: \"$family\"; }\n"; 949 950 } 951 952 $import_fonts = "@import url($apiUrl$import_url);\n"; 953 954 $font_css = "\n\n<!--====== Typecase Font Declarations ======-->"; 955 $font_css .= "\n<style type=\"text/css\">\n"; 956 $font_css .= $import_fonts; 957 $font_css .= $font_styles; 958 $font_css .= "</style>\n"; 959 $font_css .= "<!--==-- End Typecase Font Declarations --==-->\n\n"; 960 961 $new_nonce = array( 'nonce' => wp_create_nonce($this->nonce_key) ); 962 963 $response = json_encode( array( '_new_nonce' => $new_nonce, 'success' => true, 'css' => $font_css ) ); 964 965 header( "Content-Type: application/json" ); 966 echo $response; 967 exit; 968 969 } else { 970 971 $response = json_encode( array( 'success' => false, 'error' => __('There were no fonts defined','typecase') ) ); 972 973 header( "Content-Type: application/json" ); 974 echo $response; 975 exit; 976 977 } 978 979 } 980 981 /** 982 * Modifies admin header buttons and returns Typecase Pro buttons 983 * 984 * @return $buttons New set of buttons 985 * 986 */ 987 public function buttons_replace($buttons){ 988 989 $buttons = '<div class="buttons"><a class="typecase-btn primary" href="' . get_bloginfo('url') . '/?front_end_editor=1" target="_blank">' . __("Open Live Editor","typecase") . '</a> <a class="typecase-btn" href="http://upthemes.com/" target="_blank">WordPress Themes by UpThemes</a></div>'; 990 991 return $buttons; 992 993 } 994 995 /** 996 * Modifies front-end editor UI and returns new buttons 997 * 998 * @return $editor_ui Modified editor UI 999 * 1000 */ 1001 public function front_end_editor_ui($editor_ui){ 1002 $front_end_editor = '<iframe></iframe><button class="collection typecase-btn" id="your-collection-toggle" data-target="your-collection"><i class="badge"></i>' . __("View Your Collection","typecase") . '</button> <button class="available typecase-btn" id="available-fonts-toggle" data-target="available-fonts">' . __("Find New Fonts","typecase") . '</button>'; 1003 $editor_ui = $editor_ui.$front_end_editor; 1004 return $editor_ui; 1005 } 1006 1007 /** 1008 * Returns front-end editor classname 1009 * 1010 * @return $classname Modified classname for front-end #typecase container 1011 * 1012 */ 1013 public function front_end_classname($classname){ 1014 $classname = ' class="front_end_editor"'; 1015 1016 return $classname; 1017 } 1018 866 1019 } 867 1020 868 /** 869 * Bootstrap Typecase Pro, if it exists. 870 * 871 * @uses file_exists() 872 * @uses dirname() 873 * @uses Typecase::init() 874 * 875 */ 876 if( file_exists( dirname(TYPECASE_FILE) . '/pro.php' ) ){ 877 include_once(dirname(TYPECASE_FILE) . '/pro.php'); 878 }else{ 879 $typecase = Typecase::init(); 880 } 1021 $typecase = new Typecase();
Note: See TracChangeset
for help on using the changeset viewer.