Plugin Directory

Changeset 762519


Ignore:
Timestamp:
08/26/2013 04:37:30 PM (13 years ago)
Author:
nickohrn
Message:

Bumped version number in all modules and the main plugin, as well as the readme file.

Location:
web-fonts/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • web-fonts/trunk/modules/fonts-com/fonts-com.php

    r507063 r762519  
    44 Plugin URI: http://webfonts.fonts.com
    55 Description: A plugin for the Web Fonts plugin produced by Fonts.com and Monotype Imaging. This built in plugin adds Fonts.com web fonts support to the Web Fonts plugin.
    6  Version: 1.0.0
     6 Version: 1.1.6
    77 Author: Nick Ohrn of Plugin-Developer.com
    88 Author URI: http://plugin-developer.com/
     
    1111if(!class_exists('Fonts_Com_Plugin')) {
    1212    class Fonts_Com_Plugin {
    13        
     13
    1414        /// KEYS
    15        
     15
    1616        //// API
    1717        const APPLICATION_KEY = 'fce41f18-1aa1-48d8-a5ab-ea50fb6361981128835';
    18        
     18
    1919        //// VERSION
    20         const VERSION = '1.0.0';
    21        
     20        const VERSION = '1.1.6';
     21
    2222        //// KEYS
    2323        const SETTINGS_KEY = '_fonts_com_web_fonts_settings';
    24        
     24
    2525        const SELECTOR_DATA_KEY = '_fonts_com_selector_data';
    2626        const ACTIVE_PROJECT_KEY = '_fonts_com_active_project';
    27        
     27
    2828        /// DATA STORAGE
    2929        public static $admin_page_hooks = array();
    30         private static $default_settings = array('embed-method' => 'javascript');       
    31        
     30        private static $default_settings = array('embed-method' => 'javascript');
     31
    3232        public static function init() {
    3333            self::add_actions();
    3434            self::add_filters();
    35                
     35
    3636            if(function_exists('register_web_fonts_provider')) {
    3737                register_web_fonts_provider('Fonts_Com_Provider');
    3838            }
    3939        }
    40        
     40
    4141        private static function add_actions() {
    4242            if(is_admin()) {
     
    4949                add_action('wp_head', array(__CLASS__, 'display_fallbacks'), 11);
    5050            }
    51            
     51
    5252            add_action('wp_ajax_web_fonts_fonts_com_clear_active_project', array(__CLASS__, 'ajax_container'));
    5353            add_action('wp_ajax_web_fonts_fonts_com_clear_key', array(__CLASS__, 'ajax_container'));
     
    6161            add_action('wp_ajax_web_fonts_fonts_com_validate_key', array(__CLASS__, 'ajax_container'));
    6262        }
    63        
     63
    6464        private static function add_filters() {
    6565            add_filter('web_fonts_manage_stylesheet_fonts_and_selectors', array(__CLASS__, 'add_stylesheet_fonts_and_selectors'));
    6666        }
    67        
     67
    6868        /// AJAX CALLBACKS
    69        
     69
    7070        public static function ajax_container() {
    7171            $data = self::trim_r(stripslashes_deep($_REQUEST));
    7272            $action = str_replace('web_fonts_fonts_com_', '', $data['action']);
    7373            $method_name = "ajax_{$action}";
    74            
     74
    7575            if(isset($data['nonce']) && wp_verify_nonce($data['nonce'], 'fonts-com-action') && method_exists(__CLASS__, $method_name)) {
    7676                $results = self::$method_name($data);
     
    7878                $results = self::get_response(array(), __('Something went wrong. Please refresh the page and try again.'), true);
    7979            }
    80            
     80
    8181            header('Content-Type: application/json');
    8282            echo json_encode($results);
    8383            exit;
    8484        }
    85        
     85
    8686        public static function ajax_clear_active_project($data) {
    8787            self::set_active_project(null);
    88            
     88
    8989            return self::get_response(array(), __('The active project was cleared succesfully.'));
    9090        }
    91        
     91
    9292        public static function ajax_clear_key($data) {
    9393            $settings = array();
    9494            self::set_settings($settings);
    95            
     95
    9696            return self::get_response(array(), __('The authentication key was successfully cleared.'));
    9797        }
    98        
     98
    9999        public static function ajax_create_account($data) {
    100100            $first_name = $data['first_name'];
    101101            $last_name = $data['last_name'];
    102102            $email_address = $data['email_address'];
    103            
     103
    104104            if(empty($first_name)) {
    105105                $results = self::get_response(null, __('Please provide a non-empty first name for the new account.'), true);
     
    113113                $service = self::require_library();
    114114                $new_account_result = $service->create_account($first_name, $last_name, $email_address);
    115                
     115
    116116                if('Success' == $new_account_result->Message) {
    117117                    $results = self::get_response(null, __('A new account has been created for you. Check the email you registered with to activate your account and then <a class="fonts-com-setup-new-cancel" href="#">click here</a> to register your authentication key with the plugin.'));
     
    120120                }
    121121            }
    122            
     122
    123123            return $results;
    124124        }
     
    131131            $page_number = isset($data['page_number']) ? ($data['page_number'] - 1) : 0;
    132132            $offset_number = $page_limit * $page_number;
    133            
     133
    134134            $service->set_pagination_parameters($offset_number, $page_limit);
    135            
     135
    136136            $response_data = array();
    137137            $get_fonts_response = $service->list_fonts($data['Keywords'], $data['FreeOrPaid'], $data['Classification'], $data['Designer'], $data['Foundry'], $data['Language'], $data['Alpha']);
     
    139139                $response_data['fonts'] = $get_fonts_response->Font;
    140140                foreach($response_data['fonts'] as $single_response_font) {
    141                     $single_response_font->FontSizeDisplayed = sprintf('%.1f K', ($single_response_font->FontSize / 1024)); 
    142                 }
    143                
     141                    $single_response_font->FontSizeDisplayed = sprintf('%.1f K', ($single_response_font->FontSize / 1024));
     142                }
     143
    144144                ob_start();
    145145                foreach($response_data['fonts'] as $font) {
     
    147147                }
    148148                $response_data['css'] = ob_get_clean();
    149                
     149
    150150                $number_records = $get_fonts_response->TotalRecords;
    151151                $query_args = $data;
    152152                unset($query_args['nonce']);
    153153                unset($query_args['page_number']);
    154                
     154
    155155                foreach($query_args as $key => $value) {
    156156                    $query_args[$key] = urlencode($value);
    157157                }
    158                
     158
    159159                $pagination_args = array(
    160160                    'base' => admin_url('admin-ajax.php') . '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
     
    172172                    'add_fragment' => ''
    173173                );
    174                
     174
    175175                $response_data['pagination_links'] = paginate_links($pagination_args);
    176                
     176
    177177                $available_filters = array();
    178178                $filter_values_response = $service->list_all_filter_values($data['FreeOrPaid'], $data['Classification'], $data['Designer'], $data['Foundry'], $data['Language'], $data['Alpha']);
     
    182182                            $available_filters[$filter_value_data->FilterType] = array();
    183183                        }
    184                        
     184
    185185                        $available_filters[$filter_value_data->FilterType][$filter_value_data->ValueID] = $filter_value_data->ValueName;
    186186                    }
    187187                }
    188188                $response_data['filters'] = $available_filters;
    189                
     189
    190190                $response_data = self::add_project_data($response_data, $data['project_id'], $service);
    191191
     
    194194                $results = self::get_response(null, __('There was an issue retrieving the appropriate fonts. Please try again.'), true);
    195195            }
    196            
     196
    197197            return $results;
    198198        }
     
    200200        public static function ajax_get_project_data($data) {
    201201            $project_id = $data['project_id'];
    202            
     202
    203203            $project_data = array('project_name' => '', 'project_domains' => array());
    204204            if(empty($project_id)) {
     
    207207            } else {
    208208                $settings = self::get_settings();
    209                
     209
    210210                $service = self::require_library($settings['public-key'], $settings['private-key']);
    211211                $projects_response = $service->list_projects();
    212                
     212
    213213                if('Success' == $projects_response->Message) {
    214214                    foreach($projects_response->Project as $single_project) {
     
    218218                        }
    219219                    }
    220                    
     220
    221221                    $domains_response = $service->list_domains($project_id);
    222222                    if('Success' == $domains_response->Message) {
     
    225225                        }
    226226                    }
    227                    
     227
    228228                    $results = self::get_response($project_data, null);
    229229                } else {
     
    241241
    242242            self::set_settings($settings);
    243            
     243
    244244            return self::get_response($settings, __('The embed method has been set successfully.'));
    245245        }
     
    249249            $font_id = $data['font_id'];
    250250            $enabled = $data['enabled'] == 1;
    251            
     251
    252252            if(empty($project_id)) {
    253253                $results = self::get_response(null, __('Please select a project that you wish to enable this font for.'), true);
     
    257257                $settings = self::get_settings();
    258258                $service = self::require_library($settings['public-key'], $settings['private-key']);
    259                
     259
    260260                $font_status_response = ($enabled ? $service->add_font($project_id, $font_id) : $service->delete_font($project_id, $font_id));
    261                
     261
    262262                if('Success' == $font_status_response->Message) {
    263263                    $response_data = array('font_id' => $font_id, 'enabled' => $enabled);
    264                    
     264
    265265                    $response_data = self::add_project_data($response_data, $project_id, $service);
    266                    
     266
    267267                    $results = self::get_response($response_data, $enabled ? __('You have successfully enabled the selected font.') : __('You have successfully disabled the selected font.'));
    268268                } else {
     
    270270                }
    271271            }
    272            
     272
    273273            return $results;
    274274        }
    275        
     275
    276276        public static function ajax_save_project_settings($data) {
    277277            set_time_limit(0);
    278            
     278
    279279            $project_id = $data['project_id'];
    280280            $project_name = $data['project_name'];
    281281            $project_domains = (array)$data['project_domains'];
    282            
     282
    283283            if(empty($project_name)) {
    284284                $results = self::get_response(null, __('Please provide a non-empty project name.'), true);
     
    286286                $settings = self::get_settings();
    287287                $service = self::require_library($settings['public-key'], $settings['private-key']);
    288                
     288
    289289                $response_data = array();
    290290                $response_error = false;
    291291                $response_message = '';
    292                
     292
    293293                $existing_domains = array();
    294                
     294
    295295                if(empty($project_id)) { // NEW PROJECT
    296296                    $project_add_response = $service->add_project($project_name);
    297                    
     297
    298298                    if('Success' == $project_add_response->Message) {
    299299                        $result_message = __('Your project was added successfully.');
    300                        
     300
    301301                        $projects_list = array();
    302302                        foreach($project_add_response->Project as $single_project) {
     
    304304                                $project_id = $single_project->ProjectKey;
    305305                            }
    306                            
     306
    307307                            $projects_list[$single_project->ProjectName] = $single_project->ProjectKey;
    308308                        }
    309                        
     309
    310310                        $response_data['projects'] = $projects_list;
    311311                    } else {
     
    313313                        $response_message = __('There was a problem adding your project. Please make sure you aren\'t using an existing project name and try again.');
    314314                    }
    315                    
     315
    316316                } else { // EDIT PROJECT
    317317                    $project_edit_response = $service->edit_project($project_id, $project_name);
    318                
     318
    319319                    if('Success' == $project_edit_response->Message) {
    320320                        $response_message = __('Your project was edited successfully.');
    321                        
     321
    322322                        $projects_list = array();
    323323                        foreach($project_edit_response->Project as $single_project) {
    324324                            $projects_list[$single_project->ProjectName] = $single_project->ProjectKey;
    325325                        }
    326                        
     326
    327327                        $response_data['projects'] = $projects_list;
    328                        
     328
    329329                        $list_domains_response = $service->list_domains($project_id);
    330                        
     330
    331331                        $existing_domains = array();
    332332                        if('Success' == $list_domains_response->Message) {
     
    339339                        $response_message = __('There was a problem editing your project. Please make sure you aren\'t using an existing project name and try again.');
    340340                    }
    341                    
    342                 }
    343                
     341
     342                }
     343
    344344                if(!$response_error) {
    345345                    $old_active_project = self::get_active_project();
    346                    
     346
    347347                    $response_data['project_id'] = $project_id;
    348348                    self::set_active_project($project_id);
    349                    
     349
    350350                    if(!empty($old_active_project)) {
    351351                        self::swap_data_from_projects($old_active_project, $project_id);
    352352                    }
    353                    
     353
    354354                    $deleted_domains = array_diff($existing_domains, $project_domains);
    355355                    foreach($deleted_domains as $deleted_domain => $deleted_domain_key) {
    356356                        $delete_domain_response = $service->delete_domain($project_id, $deleted_domain_key);
    357357                    }
    358                    
     358
    359359                    $existing_domains_flipped = array_flip($existing_domains);
    360360                    foreach($project_domains as $project_domain => $project_domain_key) {
     
    366366                    }
    367367                }
    368                
     368
    369369                $list_projects_response = $service->list_projects();
    370                
     370
    371371                $the_projects = array();
    372372                if('Success' == $list_projects_response->Message) {
     
    376376                }
    377377                $response_data['projects'] = $the_projects;
    378                
     378
    379379                $list_domains_response = $service->list_domains($project_id);
    380                
     380
    381381                $the_domains = array();
    382382                if('Success' == $list_domains_response->Message) {
     
    386386                }
    387387                $response_data['project_domains'] = $the_domains;
    388                
     388
    389389                $service->publish();
    390                
     390
    391391                $results = self::get_response($response_data, $response_message, $response_error);
    392392            }
    393            
     393
    394394            return $results;
    395395        }
    396        
     396
    397397        public static function ajax_validate_email_password($data) {
    398398            $email = $data['email_address'];
    399399            $password = $data['password'];
    400            
     400
    401401            if(empty($email)) {
    402402                $results = self::get_response(null, __('Please provide a non-empty email address to validate.'), true);
     
    408408                $service = self::require_library();
    409409                $authentication_key_response = $service->get_token($email, $password);
    410                
     410
    411411                if('Success' == $authentication_key_response->Message) {
    412412                    $settings = array('authentication-key' => $authentication_key_response->Account->AuthorizationKey);
    413413                    self::set_settings($settings);
    414                    
     414
    415415                    $results = self::get_response($settings, __('The email and password combination you provided was verified and your authentication key has been saved.'));
    416416                } else {
     
    418418                }
    419419            }
    420            
     420
    421421            return $results;
    422422        }
    423        
     423
    424424        public static function ajax_validate_key($data) {
    425425            $key = $data['key'];
    426            
     426
    427427            if(empty($key)) {
    428428                $results = self::get_response(null, __('Please provide a non-empty authentication key to validate.'), true);
    429429            } else {
    430430                list($public, $private) = explode('--', $key);
    431                
     431
    432432                $service = self::require_library($public, $private);
    433433                $projects = $service->list_projects();
    434                
     434
    435435                if('Success' == $projects->Message) {
    436436                    $settings = array('authentication-key' => $key);
    437437                    self::set_settings($settings);
    438                    
     438
    439439                    $results = self::get_response($settings, __('Your authentication key was successfully validated and has been saved.'));
    440440                } else {
     
    442442                }
    443443            }
    444            
     444
    445445            return $results;
    446446        }
    447        
     447
    448448        /// CALLBACKS
    449        
     449
    450450        public static function add_stylesheet_fonts_and_selectors($data) {
    451451            $active_project = self::get_active_project();
     
    453453            $service = self::require_library($settings['public-key'], $settings['private-key']);
    454454            $project_data = self::add_project_data(array(), $active_project, $service);
    455            
     455
    456456            $font_selector_map = array();
    457457            foreach($project_data['project_selectors'] as $selector_data) {
    458458                $data['selectors'][] = $prepared_selector = web_fonts_prepare_selector_item('fonts-com', $selector_data->SelectorID, $selector_data->SelectorTag, $selector_data->SelectorFallback, 'fonts-com-' . $selector_data->SelectorFontID);
    459                
     459
    460460                if(!empty($selector_data->SelectorFontID) && 0 < $selector_data->SelectorFontID) {
    461461                    if(!is_array($font_selector_map[$selector_data->SelectorFontID])) {
     
    464464                    $font_selector_map[$selector_data->SelectorFontID][] = $prepared_selector;
    465465                }
    466                
    467             }
    468            
     466
     467            }
     468
    469469            foreach($project_data['project_fonts'] as $font_data) {
    470470                $data['fonts'][] = web_fonts_prepare_font_item('fonts-com', $font_data->FontID, $font_data->FontName, $font_data->FontCSSName, $font_data->FontPreviewTextLong, $font_selector_map[$font_data->FontID]);
    471471            }
    472            
     472
    473473            return $data;
    474474        }
    475        
     475
    476476        public static function detect_submissions() {
    477477            $data = stripslashes_deep($_REQUEST);
    478478        }
    479        
     479
    480480        public static function enqueue_administrative_resources($hook) {
    481481            if(!in_array($hook, self::$admin_page_hooks)) { return; }
    482            
     482
    483483            wp_enqueue_script('fonts-com-backend', plugins_url('resources/backend/fonts-com.js', __FILE__), array('jquery', 'jquery-form', 'thickbox'), self::VERSION);
    484484            wp_enqueue_style('fonts-com-backend', plugins_url('resources/backend/fonts-com.css', __FILE__), array('thickbox'), self::VERSION);
    485            
     485
    486486            $strings = array(
    487487                'request_in_progress_message' => __('There is already a request in progress. Please wait until the request has completed before trying another action.'),
     
    489489                'assign_fonts_title' => __('Assign Fonts'),
    490490            );
    491            
     491
    492492            wp_localize_script('fonts-com-backend', 'Fonts_Com_Config', $strings);
    493493        }
    494        
     494
    495495        public static function enqueue_frontend_resources() {
    496496            $active_project = self::get_active_project();
    497            
     497
    498498            if(!empty($active_project)) {
    499499                $settings = self::get_settings();
    500            
     500
    501501                $query_args = array('v' => web_fonts_get_last_saved_stylesheet_time());
    502502                if('javascript' == $settings['embed-method']) {
     
    509509            }
    510510        }
    511        
     511
    512512        public static function handle_stylesheet_fonts($fonts) {
    513513            $settings = self::get_settings();
    514514            $service = self::require_library($settings['public-key'], $settings['private-key']);
    515515            $service->set_pagination_parameters(0, 1000);
    516            
     516
    517517            $project_id = self::get_active_project();
    518            
     518
    519519            // Delete all existing selectors so we start with a clean slate
    520520            $existing_selectors = $service->list_selectors($project_id);
     
    524524                }
    525525            }
    526            
     526
    527527            $selector_to_fallback_map = array();
    528528            $font_ids = array();
     
    532532                    foreach($font->selectors as $selector) {
    533533                        $selector_tag = $selector->tag;
    534                        
     534
    535535                        $add_selector_response = $service->add_selector($project_id, $selector_tag);
    536536                        if('Success' == $add_selector_response->Message) {
    537537                            $selector_to_fallback_map[$selector_tag] = array('family' => $font->family, 'fallback' => $selector->fallback);
    538                            
     538
    539539                            foreach($add_selector_response->Selector as $selector_data) {
    540540                                if($selector_data->SelectorTag == $selector_tag) {
     
    547547                }
    548548            }
    549            
     549
    550550            if(!empty($font_ids) && !empty($selector_ids)) {
    551551                $service->assign_to_selector($project_id, $font_ids, $selector_ids);
    552                 self::set_selector_data($selector_to_fallback_map);             
    553             }
    554            
     552                self::set_selector_data($selector_to_fallback_map);
     553            }
     554
    555555            $service->publish();
    556556        }
    557        
     557
    558558        public static function handle_stylesheet_selectors($selectors) {
    559559            $settings = self::get_settings();
    560560            $service = self::require_library($settings['public-key'], $settings['private-key']);
    561561            $service->set_pagination_parameters(0, 1000);
    562            
     562
    563563            $project_id = self::get_active_project();
    564            
     564
    565565            // Delete all existing selectors so we start with a clean slate
    566566            $existing_selectors = $service->list_selectors($project_id);
     
    570570                }
    571571            }
    572            
     572
    573573            $selector_to_fallback_map = array();
    574574            $font_ids = array();
     
    578578                    $font_id = str_replace('fonts-com-', '', $selector->font->id);
    579579                    $selector_tag = $selector->tag;
    580                    
     580
    581581                    $add_selector_response = $service->add_selector($project_id, $selector_tag);
    582582                    if('Success' == $add_selector_response->Message) {
    583583                        $selector_to_fallback_map[$selector_tag] = array('family' => $selector->font->family, 'fallback' => $selector->fallback);
    584                        
     584
    585585                        foreach($add_selector_response->Selector as $selector_data) {
    586586                            if($selector_data->SelectorTag == $selector_tag) {
     
    592592                }
    593593            }
    594            
     594
    595595            if(!empty($font_ids) && !empty($selector_ids)) {
    596596                $service->assign_to_selector($project_id, $font_ids, $selector_ids);
    597                 self::set_selector_data($selector_to_fallback_map);             
    598             }
    599            
     597                self::set_selector_data($selector_to_fallback_map);
     598            }
     599
    600600            $service->publish();
    601601        }
    602        
     602
    603603        /// DISPLAY CALLBACKS
    604        
     604
    605605        public static function display_fallbacks() {
    606606            $active_project = self::get_active_project();
    607607            $selector_data = self::get_selector_data();
    608            
     608
    609609            if(!empty($active_project) && !empty($selector_data)) {
    610610                echo "\n<!-- Fonts.com Fallbacks -->\n";
     
    617617            }
    618618        }
    619        
     619
    620620        public static function display_settings_page() {
    621621            $data = stripslashes_deep($_REQUEST);
    622            
     622
    623623            $settings = self::get_settings();
    624624            $is_setup = self::is_setup();
    625625            $active_project = self::get_active_project();
    626            
     626
    627627            $base_url = add_query_arg(array('page' => $data['page']), admin_url('admin.php'));
    628628            $valid_tabs = $is_setup ? array('setup', 'projects', 'fonts') : array('setup');
    629629            $current_tab = in_array($data['tab'], $valid_tabs) ? $data['tab'] : ($is_setup ? (empty($active_project) ? 'projects' : 'fonts') : 'setup');
    630            
     630
    631631            if('fonts' == $current_tab && empty($active_project)) {
    632632                add_settings_error('fonts-com-current-tab', 'fonts-com-current-tab', __('Please select an active project before attempting to manage fonts.'), 'error');
    633                
     633
    634634                $current_tab = 'projects';
    635635            }
    636            
     636
    637637            include('views/backend/settings/_inc/nav.php');
    638            
     638
    639639            // Make this dynamic
    640640            switch($current_tab) {
     
    645645                    $service = self::require_library($settings['public-key'], $settings['private-key']);
    646646                    $projects_response = $service->list_projects();
    647                    
     647
    648648                    if('Success' == $projects_response->Message) {
    649649                        $projects = (array)$projects_response->Project;
     
    651651                        $projects = array();
    652652                    }
    653                    
     653
    654654                    $active_project = self::get_active_project();
    655                    
     655
    656656                    include('views/backend/settings/projects.php');
    657657                    break;
     
    659659                    $service = self::require_library($settings['public-key'], $settings['private-key']);
    660660                    $projects_response = $service->list_projects();
    661                    
     661
    662662                    if('Success' == $projects_response->Message) {
    663663                        $projects = (array)$projects_response->Project;
     
    665665                        $projects = array();
    666666                    }
    667                    
     667
    668668                    $available_filters = array();
    669669                    $filter_values_response = $service->list_all_filter_values();
     
    673673                                $available_filters[$filter_value_data->FilterType] = array();
    674674                            }
    675                            
     675
    676676                            $available_filters[$filter_value_data->FilterType][$filter_value_data->ValueID] = $filter_value_data->ValueName;
    677677                        }
    678678                    }
    679679                    $active_project = self::get_active_project();
    680                    
     680
    681681                    include('views/backend/settings/fonts.php');
    682682                    break;
     
    685685
    686686        /// SELECTORS
    687        
     687
    688688        private static function get_active_project() {
    689689            $active_project = wp_cache_get(self::ACTIVE_PROJECT_KEY);
    690            
     690
    691691            if(empty($active_project)) {
    692692                $active_project = get_option(self::ACTIVE_PROJECT_KEY);
    693693                wp_cache_set(self::ACTIVE_PROJECT_KEY, $active_project, null, time() + CACHE_PERIOD);
    694694            }
    695            
     695
    696696            return $active_project;
    697697        }
    698        
     698
    699699        private static function set_active_project($active_project) {
    700700            if(!empty($active_project)) {
     
    707707
    708708        /// ACTIVE PROJECT
    709        
     709
    710710        private static function get_selector_data() {
    711711            $selector_data = wp_cache_get(self::SELECTOR_DATA_KEY);
    712            
     712
    713713            if(!is_array($selector_data)) {
    714714                $selector_data = get_option(self::SELECTOR_DATA_KEY);
    715715                wp_cache_set(self::SELECTOR_DATA_KEY, $selector_data, null, time() + CACHE_PERIOD);
    716716            }
    717            
     717
    718718            return $selector_data;
    719719        }
    720        
     720
    721721        private static function set_selector_data($selector_data) {
    722722            if(is_array($selector_data)) {
     
    725725            }
    726726        }
    727        
     727
    728728        /// SETTINGS
    729        
     729
    730730        private static function get_settings() {
    731731            $settings = wp_cache_get(self::SETTINGS_KEY);
    732            
     732
    733733            if(!is_array($settings)) {
    734734                $settings = wp_parse_args(get_option(self::SETTINGS_KEY, self::$default_settings), self::$default_settings);
    735735                wp_cache_set(self::SETTINGS_KEY, $settings, null, time() + CACHE_PERIOD);
    736736            }
    737            
     737
    738738            return $settings;
    739739        }
    740        
     740
    741741        private static function set_settings($settings) {
    742742            if(is_array($settings)) {
     
    744744                    list($settings['public-key'], $settings['private-key']) = explode('--', $settings['authentication-key']);
    745745                }
    746                
     746
    747747                $settings = wp_parse_args($settings, self::$default_settings);
    748748                update_option(self::SETTINGS_KEY, $settings);
     
    750750            }
    751751        }
    752        
     752
    753753        /// UTILITY
    754        
     754
    755755        private static function add_project_data($response_data, $project_id, $service) {
    756756            $service->set_pagination_parameters(0, 150);
    757            
     757
    758758            $project_fonts_response = $service->list_project_fonts($project_id);
    759759            $response_data['project_fonts'] = array();
     
    761761                $response_data['project_fonts'] = array_filter((array)$project_fonts_response->Font);
    762762                usort($response_data['project_fonts'], array(__CLASS__, 'usort_sort_by_font_name'));
    763                
     763
    764764                $response_data['project_font_ids'] = array();
    765765                foreach($response_data['project_fonts'] as $font) {
     
    767767                }
    768768            }
    769            
     769
    770770            $project_selectors_response = $service->list_selectors($project_id);
    771771            $response_data['project_selectors'] = array();
    772772            if('Success' == $project_selectors_response->Message) {
    773773                $response_data['project_selectors'] = array_filter((array)$project_selectors_response->Selector);
    774                
     774
    775775                $selector_data = self::get_selector_data();
    776776                foreach($response_data['project_selectors'] as $project_selector) {
     
    778778                }
    779779            }
    780            
     780
    781781            return $response_data;
    782782        }
     
    784784        private static function get_nice_filter_type_text($filter_type) {
    785785            $filtered = array('Alpha' => __('a Beginning Character'), 'FreeOrPaid' => __('Free or All Fonts'));
    786            
     786
    787787            if(isset($filtered[$filter_type])) {
    788788                $filter_type = $filtered[$filter_type];
     
    790790                $filter_type = "a {$filter_type}";
    791791            }
    792            
     792
    793793            return $filter_type;
    794794        }
    795        
     795
    796796        private static function get_response($data = array(), $message = null, $error = false) {
    797797            return array_merge(array('error' => (bool)$error, 'message' => $message), (array)$data);
    798798        }
    799        
     799
    800800        private static function is_setup() {
    801801            $settings = self::get_settings();
    802            
     802
    803803            return !empty($settings['authentication-key']);
    804804        }
    805        
     805
    806806        /**
    807807         * @return WP_Web_Fonts_Service
     
    809809        private static function require_library($public_key = null, $private_key = null) {
    810810            require_once('lib/wp-web-fonts-service.php');
    811            
     811
    812812            $service = new WP_Web_Fonts_Service(self::APPLICATION_KEY);
    813813            $service->set_credentials($public_key, $private_key);
    814814            $service->set_logging_enabled(true);
    815            
     815
    816816            return $service;
    817817        }
    818        
     818
    819819        private static function swap_data_from_projects($old_project_id, $new_project_id) {
    820820            if($old_project_id != $new_project_id) {
    821821                $settings = self::get_settings();
    822                
     822
    823823                $service = self::require_library($settings['public-key'], $settings['private-key']);
    824824                $service->set_pagination_parameters(0, 1000);
    825                
     825
    826826                $old_selectors = $service->list_selectors($old_project_id);
    827827                if('Success' == $old_selectors->Message) {
    828828                    $font_ids = array();
    829829                    $selector_ids = array();
    830                    
     830
    831831                    foreach($old_selectors->Selector as $selector) {
    832832                        $delete_selector_response = $service->delete_selector($old_project_id, $selector->SelectorID);
    833833                        $add_selector_response = $service->add_selector($new_project_id, $selector->SelectorTag);
    834                        
     834
    835835                        if('Success' == $add_selector_response->Message) {
    836836                            if($selector->SelectorFontID > 0) {
    837837                                $font_ids[] = $selector->SelectorFontID;
    838                                
     838
    839839                                foreach($add_selector_response->Selector as $added_selector) {
    840840                                    if($selector->SelectorTag == $added_selector->SelectorTag) {
     
    846846                    }
    847847                }
    848                
     848
    849849                $old_fonts = $service->list_project_fonts($old_project_id);
    850850                if('Success' == $old_fonts->Message) {
     
    854854                    }
    855855                }
    856                
     856
    857857                $service->assign_to_selector($new_project_id, $font_ids, $selector_ids);
    858                
     858
    859859                $service->publish();
    860860            }
    861861        }
    862        
     862
    863863        private static function trim_r($data) {
    864864            if(is_array($data)) {
     
    872872            }
    873873        }
    874        
     874
    875875        public static function usort_sort_by_font_name($a, $b) {
    876876            return strcmp($b->FontName, $a->FontName);
    877877        }
    878878    }
    879    
     879
    880880    require_once('lib/provider.php');
    881881    Fonts_Com_Plugin::init();
  • web-fonts/trunk/modules/google-web-fonts/google-web-fonts.php

    r762516 r762519  
    44 Plugin URI: http://www.google.com/webfonts
    55 Description: A plugin for the Web Fonts plugin produced by Fonts.com and Monotype Imaging. This built in plugin adds Google Web Fonts support to the Web Fonts plugin.
    6  Version: 1.0.0-RC2
     6 Version: 1.1.6
    77 Author: Nick Ohrn of Plugin-Developer.com
    88 Author URI: http://plugin-developer.com/
     
    1515
    1616        //// VERSION
    17         const VERSION = '1.0.0-RC2';
     17        const VERSION = '1.1.6';
    1818
    1919        //// KEYS
  • web-fonts/trunk/readme.txt

    r523478 r762519  
    33Tags: fonts, webfonts, content display, theme enhancement, plugin, admin, google, web fonts, api integration
    44Requires at least: 3.3
    5 Tested up to: 3.3.1
    6 Stable tag: 1.1.5
     5Tested up to: 3.6
     6Stable tag: 1.1.6
    77
    88Start using web fonts on your site today! Support for web fonts from Fonts.com and Google Web Fonts is included.
     
    9393== Changelog ==
    9494
     95= 1.1.6 =
     96* Fixed bug preventing users from disabling Google Web Fonts
     97
    9598= 1.1.5 =
    9699* Fixed Google Web Fonts CSS declaration per
  • web-fonts/trunk/web-fonts.php

    r523474 r762519  
    44 Plugin URI: http://webfonts.fonts.com
    55 Description: The canonical Web Fonts plugin for WordPress. This plugin includes support for Fonts.com and Google web fonts and supports a variety of web font providers via an easy to implement plugin architecture.
    6  Version: 1.1.5
     6 Version: 1.1.6
    77 Author: Nick Ohrn of Plugin-Developer.com
    88 Author URI: http://plugin-developer.com/
     
    1212    class Web_Fonts {
    1313        /// CONSTANTS
    14        
     14
    1515        //// VERSION
    16         const VERSION = '1.1.5';
    17        
     16        const VERSION = '1.1.6';
     17
    1818        //// KEYS
    1919        const SETTINGS_KEY = '_web_fonts_settings';
    2020        const SAVED_TIMESTAMP_KEY = '_web_fonts_stylesheet_saved_timestamp';
    21        
     21
    2222        //// SLUGS
    2323        const SETTINGS_PAGE_SLUG = 'web-fonts';
    24        
     24
    2525        //// CACHE
    2626        const CACHE_PERIOD = 86400; // 24 HOURS
    27    
     27
    2828        /// DATA STORAGE
    2929        private static $admin_page_hooks = array();
     
    4747
    4848        /// CALLBACKS
    49        
     49
    5050        public static function add_administrative_interface_items() {
    5151            if(!empty(self::$registered_providers)) {
    5252                self::$admin_page_hooks[] = $settings = add_menu_page(__('Web Fonts'), __('Web Fonts'), 'manage_options', self::SETTINGS_PAGE_SLUG, array(__CLASS__, 'display_stylesheet_page'), plugins_url('resources/backend/img/web-fonts-16.png', __FILE__));
    5353                self::$admin_page_hooks[] = $stylesheet = add_submenu_page(self::SETTINGS_PAGE_SLUG, __('Manage Web Font Stylesheet'), __('Manage Stylesheet'), 'manage_options', 'web-fonts', array(__CLASS__, 'display_stylesheet_page'));
    54                
     54
    5555                add_action("load-{$stylesheet}", array(__CLASS__, 'process_manage_stylesheet'));
    56                
     56
    5757                foreach(self::$registered_providers as $provider_class_name) {
    5858                    $provider_name = call_user_func(array($provider_class_name, 'get_provider_name'));
    59                    
     59
    6060                    self::$admin_page_hooks[] = $menu_slug = add_submenu_page(self::SETTINGS_PAGE_SLUG, sprintf(__('Web Fonts - %s'), $provider_name), $provider_name, 'manage_options', self::get_page_slug_for_provider($provider_class_name), array(__CLASS__, 'display_settings_page'));
    61                    
     61
    6262                    call_user_func(array($provider_class_name, 'settings_page_registered'), $menu_slug);
    6363                }
    6464            }
    6565        }
    66        
     66
    6767        public static function enqueue_administrative_resources($hook) {
    6868            if(!in_array($hook, self::$admin_page_hooks)) { return; }
    69            
     69
    7070            wp_enqueue_script('knockout', plugins_url('resources/backend/knockout.js', __FILE__), array(), '2.0.0');
    7171            wp_enqueue_script('web-fonts-backend', plugins_url('resources/backend/web-fonts.js', __FILE__), array('jquery', 'knockout'), self::VERSION);
    7272            wp_enqueue_style('web-fonts-backend', plugins_url('resources/backend/web-fonts.css', __FILE__), array(), self::VERSION);
    7373        }
    74        
     74
    7575        public static function process_manage_stylesheet() {
    7676            $data = stripslashes_deep($_REQUEST);
     
    7878            if(isset($data['web-fonts-manage-stylesheet-nonce']) && wp_verify_nonce($data['web-fonts-manage-stylesheet-nonce'], 'web-fonts-manage-stylesheet')) {
    7979                $stylesheet_data = json_decode($data['web-fonts-stylesheet-data']);
    80                
     80
    8181                do_action("web_fonts_manage_stylesheet_{$stylesheet_data->visible_tab}s", $stylesheet_data->{"{$stylesheet_data->visible_tab}s"});
    82                
     82
    8383                add_settings_error('general', 'stylesheet_updated', __('Stylesheet updated!'), 'updated');
    8484                set_transient('settings_errors', get_settings_errors(), 30);
    85                
     85
    8686                self::set_stylesheet_timestamp(current_time('timestamp'));
    87                
     87
    8888                wp_redirect(add_query_arg(array('page' => 'web-fonts', 'settings-updated' => 'true'), admin_url('admin.php')));
    8989                exit;
    9090            }
    9191        }
    92        
     92
    9393        /// DISPLAY CALLBACKS
    94        
     94
    9595        public static function display_stylesheet_page() {
    9696            include('views/backend/settings/overview.php');
    9797        }
    98        
     98
    9999        public static function display_settings_page() {
    100100            $data = stripslashes_deep($_GET);
    101            
     101
    102102            $provider_key = str_replace('web-fonts-', '', $data['page']);
    103103            $provider_class_name = self::$registered_providers[$provider_key];
    104            
     104
    105105            include('views/backend/settings/settings.php');
    106106        }
    107107
    108108        /// SETTINGS
    109        
     109
    110110        private static function get_settings() {
    111111            $settings = wp_cache_get(self::SETTINGS_KEY);
    112            
     112
    113113            if(!is_array($settings)) {
    114114                $settings = wp_parse_args(get_option(self::SETTINGS_KEY, self::$default_settings), self::$default_settings);
    115115                wp_cache_set(self::SETTINGS_KEY, $settings, null, time() + CACHE_PERIOD);
    116116            }
    117            
     117
    118118            return $settings;
    119119        }
    120        
     120
    121121        private static function set_settings($settings) {
    122122            if(is_array($settings)) {
     
    126126            }
    127127        }
    128        
     128
    129129        private static function get_stylesheet_timestamp() {
    130130            $timestamp = wp_cache_get(self::SAVED_TIMESTAMP_KEY);
    131            
     131
    132132            if(!is_array($timestamp)) {
    133133                $timestamp = get_option(self::SAVED_TIMESTAMP_KEY, time());
    134134                wp_cache_set(self::SAVED_TIMESTAMP_KEY, $timestamp, null, time() + CACHE_PERIOD);
    135135            }
    136            
     136
    137137            return $timestamp;
    138138        }
    139        
     139
    140140        private static function set_stylesheet_timestamp($timestamp) {
    141141            if(!empty($timestamp)) {
     
    144144            }
    145145        }
    146        
     146
    147147        /// UTILITY
    148        
     148
    149149        private static function get_page_slug_for_provider($provider_class_name) {
    150150            return 'web-fonts-' . call_user_func(array($provider_class_name, 'get_provider_key'));
    151151        }
    152        
     152
    153153        /// TEMPLATE TAGS
    154154
     
    156156            return self::get_stylesheet_timestamp();
    157157        }
    158        
     158
    159159        public static function register_web_fonts_provider($provider_class_name) {
    160160            if(class_exists($provider_class_name) && is_subclass_of($provider_class_name, 'Web_Fonts_Provider') && !in_array($provider_class_name, self::$registered_providers)) {
    161161                $provider_key = call_user_func(array($provider_class_name, 'get_provider_key'));
    162                
     162
    163163                self::$registered_providers[$provider_key] = $provider_class_name;
    164164            }
    165            
     165
    166166            return self::$registered_providers;
    167167        }
     
    173173    // Include by default the Fonts.com provider plugin
    174174    require_once('modules/fonts-com/fonts-com.php');
    175    
     175
    176176    // Include by default the Google Web Fonts provider plugin
    177177    require_once('modules/google-web-fonts/google-web-fonts.php');
    178        
     178
    179179    Web_Fonts::init();
    180180}
Note: See TracChangeset for help on using the changeset viewer.