Changeset 762519
- Timestamp:
- 08/26/2013 04:37:30 PM (13 years ago)
- Location:
- web-fonts/trunk
- Files:
-
- 4 edited
-
modules/fonts-com/fonts-com.php (modified) (61 diffs)
-
modules/google-web-fonts/google-web-fonts.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
web-fonts.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
web-fonts/trunk/modules/fonts-com/fonts-com.php
r507063 r762519 4 4 Plugin URI: http://webfonts.fonts.com 5 5 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.06 Version: 1.1.6 7 7 Author: Nick Ohrn of Plugin-Developer.com 8 8 Author URI: http://plugin-developer.com/ … … 11 11 if(!class_exists('Fonts_Com_Plugin')) { 12 12 class Fonts_Com_Plugin { 13 13 14 14 /// KEYS 15 15 16 16 //// API 17 17 const APPLICATION_KEY = 'fce41f18-1aa1-48d8-a5ab-ea50fb6361981128835'; 18 18 19 19 //// VERSION 20 const VERSION = '1. 0.0';21 20 const VERSION = '1.1.6'; 21 22 22 //// KEYS 23 23 const SETTINGS_KEY = '_fonts_com_web_fonts_settings'; 24 24 25 25 const SELECTOR_DATA_KEY = '_fonts_com_selector_data'; 26 26 const ACTIVE_PROJECT_KEY = '_fonts_com_active_project'; 27 27 28 28 /// DATA STORAGE 29 29 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 32 32 public static function init() { 33 33 self::add_actions(); 34 34 self::add_filters(); 35 35 36 36 if(function_exists('register_web_fonts_provider')) { 37 37 register_web_fonts_provider('Fonts_Com_Provider'); 38 38 } 39 39 } 40 40 41 41 private static function add_actions() { 42 42 if(is_admin()) { … … 49 49 add_action('wp_head', array(__CLASS__, 'display_fallbacks'), 11); 50 50 } 51 51 52 52 add_action('wp_ajax_web_fonts_fonts_com_clear_active_project', array(__CLASS__, 'ajax_container')); 53 53 add_action('wp_ajax_web_fonts_fonts_com_clear_key', array(__CLASS__, 'ajax_container')); … … 61 61 add_action('wp_ajax_web_fonts_fonts_com_validate_key', array(__CLASS__, 'ajax_container')); 62 62 } 63 63 64 64 private static function add_filters() { 65 65 add_filter('web_fonts_manage_stylesheet_fonts_and_selectors', array(__CLASS__, 'add_stylesheet_fonts_and_selectors')); 66 66 } 67 67 68 68 /// AJAX CALLBACKS 69 69 70 70 public static function ajax_container() { 71 71 $data = self::trim_r(stripslashes_deep($_REQUEST)); 72 72 $action = str_replace('web_fonts_fonts_com_', '', $data['action']); 73 73 $method_name = "ajax_{$action}"; 74 74 75 75 if(isset($data['nonce']) && wp_verify_nonce($data['nonce'], 'fonts-com-action') && method_exists(__CLASS__, $method_name)) { 76 76 $results = self::$method_name($data); … … 78 78 $results = self::get_response(array(), __('Something went wrong. Please refresh the page and try again.'), true); 79 79 } 80 80 81 81 header('Content-Type: application/json'); 82 82 echo json_encode($results); 83 83 exit; 84 84 } 85 85 86 86 public static function ajax_clear_active_project($data) { 87 87 self::set_active_project(null); 88 88 89 89 return self::get_response(array(), __('The active project was cleared succesfully.')); 90 90 } 91 91 92 92 public static function ajax_clear_key($data) { 93 93 $settings = array(); 94 94 self::set_settings($settings); 95 95 96 96 return self::get_response(array(), __('The authentication key was successfully cleared.')); 97 97 } 98 98 99 99 public static function ajax_create_account($data) { 100 100 $first_name = $data['first_name']; 101 101 $last_name = $data['last_name']; 102 102 $email_address = $data['email_address']; 103 103 104 104 if(empty($first_name)) { 105 105 $results = self::get_response(null, __('Please provide a non-empty first name for the new account.'), true); … … 113 113 $service = self::require_library(); 114 114 $new_account_result = $service->create_account($first_name, $last_name, $email_address); 115 115 116 116 if('Success' == $new_account_result->Message) { 117 117 $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.')); … … 120 120 } 121 121 } 122 122 123 123 return $results; 124 124 } … … 131 131 $page_number = isset($data['page_number']) ? ($data['page_number'] - 1) : 0; 132 132 $offset_number = $page_limit * $page_number; 133 133 134 134 $service->set_pagination_parameters($offset_number, $page_limit); 135 135 136 136 $response_data = array(); 137 137 $get_fonts_response = $service->list_fonts($data['Keywords'], $data['FreeOrPaid'], $data['Classification'], $data['Designer'], $data['Foundry'], $data['Language'], $data['Alpha']); … … 139 139 $response_data['fonts'] = $get_fonts_response->Font; 140 140 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 144 144 ob_start(); 145 145 foreach($response_data['fonts'] as $font) { … … 147 147 } 148 148 $response_data['css'] = ob_get_clean(); 149 149 150 150 $number_records = $get_fonts_response->TotalRecords; 151 151 $query_args = $data; 152 152 unset($query_args['nonce']); 153 153 unset($query_args['page_number']); 154 154 155 155 foreach($query_args as $key => $value) { 156 156 $query_args[$key] = urlencode($value); 157 157 } 158 158 159 159 $pagination_args = array( 160 160 'base' => admin_url('admin-ajax.php') . '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below) … … 172 172 'add_fragment' => '' 173 173 ); 174 174 175 175 $response_data['pagination_links'] = paginate_links($pagination_args); 176 176 177 177 $available_filters = array(); 178 178 $filter_values_response = $service->list_all_filter_values($data['FreeOrPaid'], $data['Classification'], $data['Designer'], $data['Foundry'], $data['Language'], $data['Alpha']); … … 182 182 $available_filters[$filter_value_data->FilterType] = array(); 183 183 } 184 184 185 185 $available_filters[$filter_value_data->FilterType][$filter_value_data->ValueID] = $filter_value_data->ValueName; 186 186 } 187 187 } 188 188 $response_data['filters'] = $available_filters; 189 189 190 190 $response_data = self::add_project_data($response_data, $data['project_id'], $service); 191 191 … … 194 194 $results = self::get_response(null, __('There was an issue retrieving the appropriate fonts. Please try again.'), true); 195 195 } 196 196 197 197 return $results; 198 198 } … … 200 200 public static function ajax_get_project_data($data) { 201 201 $project_id = $data['project_id']; 202 202 203 203 $project_data = array('project_name' => '', 'project_domains' => array()); 204 204 if(empty($project_id)) { … … 207 207 } else { 208 208 $settings = self::get_settings(); 209 209 210 210 $service = self::require_library($settings['public-key'], $settings['private-key']); 211 211 $projects_response = $service->list_projects(); 212 212 213 213 if('Success' == $projects_response->Message) { 214 214 foreach($projects_response->Project as $single_project) { … … 218 218 } 219 219 } 220 220 221 221 $domains_response = $service->list_domains($project_id); 222 222 if('Success' == $domains_response->Message) { … … 225 225 } 226 226 } 227 227 228 228 $results = self::get_response($project_data, null); 229 229 } else { … … 241 241 242 242 self::set_settings($settings); 243 243 244 244 return self::get_response($settings, __('The embed method has been set successfully.')); 245 245 } … … 249 249 $font_id = $data['font_id']; 250 250 $enabled = $data['enabled'] == 1; 251 251 252 252 if(empty($project_id)) { 253 253 $results = self::get_response(null, __('Please select a project that you wish to enable this font for.'), true); … … 257 257 $settings = self::get_settings(); 258 258 $service = self::require_library($settings['public-key'], $settings['private-key']); 259 259 260 260 $font_status_response = ($enabled ? $service->add_font($project_id, $font_id) : $service->delete_font($project_id, $font_id)); 261 261 262 262 if('Success' == $font_status_response->Message) { 263 263 $response_data = array('font_id' => $font_id, 'enabled' => $enabled); 264 264 265 265 $response_data = self::add_project_data($response_data, $project_id, $service); 266 266 267 267 $results = self::get_response($response_data, $enabled ? __('You have successfully enabled the selected font.') : __('You have successfully disabled the selected font.')); 268 268 } else { … … 270 270 } 271 271 } 272 272 273 273 return $results; 274 274 } 275 275 276 276 public static function ajax_save_project_settings($data) { 277 277 set_time_limit(0); 278 278 279 279 $project_id = $data['project_id']; 280 280 $project_name = $data['project_name']; 281 281 $project_domains = (array)$data['project_domains']; 282 282 283 283 if(empty($project_name)) { 284 284 $results = self::get_response(null, __('Please provide a non-empty project name.'), true); … … 286 286 $settings = self::get_settings(); 287 287 $service = self::require_library($settings['public-key'], $settings['private-key']); 288 288 289 289 $response_data = array(); 290 290 $response_error = false; 291 291 $response_message = ''; 292 292 293 293 $existing_domains = array(); 294 294 295 295 if(empty($project_id)) { // NEW PROJECT 296 296 $project_add_response = $service->add_project($project_name); 297 297 298 298 if('Success' == $project_add_response->Message) { 299 299 $result_message = __('Your project was added successfully.'); 300 300 301 301 $projects_list = array(); 302 302 foreach($project_add_response->Project as $single_project) { … … 304 304 $project_id = $single_project->ProjectKey; 305 305 } 306 306 307 307 $projects_list[$single_project->ProjectName] = $single_project->ProjectKey; 308 308 } 309 309 310 310 $response_data['projects'] = $projects_list; 311 311 } else { … … 313 313 $response_message = __('There was a problem adding your project. Please make sure you aren\'t using an existing project name and try again.'); 314 314 } 315 315 316 316 } else { // EDIT PROJECT 317 317 $project_edit_response = $service->edit_project($project_id, $project_name); 318 318 319 319 if('Success' == $project_edit_response->Message) { 320 320 $response_message = __('Your project was edited successfully.'); 321 321 322 322 $projects_list = array(); 323 323 foreach($project_edit_response->Project as $single_project) { 324 324 $projects_list[$single_project->ProjectName] = $single_project->ProjectKey; 325 325 } 326 326 327 327 $response_data['projects'] = $projects_list; 328 328 329 329 $list_domains_response = $service->list_domains($project_id); 330 330 331 331 $existing_domains = array(); 332 332 if('Success' == $list_domains_response->Message) { … … 339 339 $response_message = __('There was a problem editing your project. Please make sure you aren\'t using an existing project name and try again.'); 340 340 } 341 342 } 343 341 342 } 343 344 344 if(!$response_error) { 345 345 $old_active_project = self::get_active_project(); 346 346 347 347 $response_data['project_id'] = $project_id; 348 348 self::set_active_project($project_id); 349 349 350 350 if(!empty($old_active_project)) { 351 351 self::swap_data_from_projects($old_active_project, $project_id); 352 352 } 353 353 354 354 $deleted_domains = array_diff($existing_domains, $project_domains); 355 355 foreach($deleted_domains as $deleted_domain => $deleted_domain_key) { 356 356 $delete_domain_response = $service->delete_domain($project_id, $deleted_domain_key); 357 357 } 358 358 359 359 $existing_domains_flipped = array_flip($existing_domains); 360 360 foreach($project_domains as $project_domain => $project_domain_key) { … … 366 366 } 367 367 } 368 368 369 369 $list_projects_response = $service->list_projects(); 370 370 371 371 $the_projects = array(); 372 372 if('Success' == $list_projects_response->Message) { … … 376 376 } 377 377 $response_data['projects'] = $the_projects; 378 378 379 379 $list_domains_response = $service->list_domains($project_id); 380 380 381 381 $the_domains = array(); 382 382 if('Success' == $list_domains_response->Message) { … … 386 386 } 387 387 $response_data['project_domains'] = $the_domains; 388 388 389 389 $service->publish(); 390 390 391 391 $results = self::get_response($response_data, $response_message, $response_error); 392 392 } 393 393 394 394 return $results; 395 395 } 396 396 397 397 public static function ajax_validate_email_password($data) { 398 398 $email = $data['email_address']; 399 399 $password = $data['password']; 400 400 401 401 if(empty($email)) { 402 402 $results = self::get_response(null, __('Please provide a non-empty email address to validate.'), true); … … 408 408 $service = self::require_library(); 409 409 $authentication_key_response = $service->get_token($email, $password); 410 410 411 411 if('Success' == $authentication_key_response->Message) { 412 412 $settings = array('authentication-key' => $authentication_key_response->Account->AuthorizationKey); 413 413 self::set_settings($settings); 414 414 415 415 $results = self::get_response($settings, __('The email and password combination you provided was verified and your authentication key has been saved.')); 416 416 } else { … … 418 418 } 419 419 } 420 420 421 421 return $results; 422 422 } 423 423 424 424 public static function ajax_validate_key($data) { 425 425 $key = $data['key']; 426 426 427 427 if(empty($key)) { 428 428 $results = self::get_response(null, __('Please provide a non-empty authentication key to validate.'), true); 429 429 } else { 430 430 list($public, $private) = explode('--', $key); 431 431 432 432 $service = self::require_library($public, $private); 433 433 $projects = $service->list_projects(); 434 434 435 435 if('Success' == $projects->Message) { 436 436 $settings = array('authentication-key' => $key); 437 437 self::set_settings($settings); 438 438 439 439 $results = self::get_response($settings, __('Your authentication key was successfully validated and has been saved.')); 440 440 } else { … … 442 442 } 443 443 } 444 444 445 445 return $results; 446 446 } 447 447 448 448 /// CALLBACKS 449 449 450 450 public static function add_stylesheet_fonts_and_selectors($data) { 451 451 $active_project = self::get_active_project(); … … 453 453 $service = self::require_library($settings['public-key'], $settings['private-key']); 454 454 $project_data = self::add_project_data(array(), $active_project, $service); 455 455 456 456 $font_selector_map = array(); 457 457 foreach($project_data['project_selectors'] as $selector_data) { 458 458 $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 460 460 if(!empty($selector_data->SelectorFontID) && 0 < $selector_data->SelectorFontID) { 461 461 if(!is_array($font_selector_map[$selector_data->SelectorFontID])) { … … 464 464 $font_selector_map[$selector_data->SelectorFontID][] = $prepared_selector; 465 465 } 466 467 } 468 466 467 } 468 469 469 foreach($project_data['project_fonts'] as $font_data) { 470 470 $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]); 471 471 } 472 472 473 473 return $data; 474 474 } 475 475 476 476 public static function detect_submissions() { 477 477 $data = stripslashes_deep($_REQUEST); 478 478 } 479 479 480 480 public static function enqueue_administrative_resources($hook) { 481 481 if(!in_array($hook, self::$admin_page_hooks)) { return; } 482 482 483 483 wp_enqueue_script('fonts-com-backend', plugins_url('resources/backend/fonts-com.js', __FILE__), array('jquery', 'jquery-form', 'thickbox'), self::VERSION); 484 484 wp_enqueue_style('fonts-com-backend', plugins_url('resources/backend/fonts-com.css', __FILE__), array('thickbox'), self::VERSION); 485 485 486 486 $strings = array( 487 487 'request_in_progress_message' => __('There is already a request in progress. Please wait until the request has completed before trying another action.'), … … 489 489 'assign_fonts_title' => __('Assign Fonts'), 490 490 ); 491 491 492 492 wp_localize_script('fonts-com-backend', 'Fonts_Com_Config', $strings); 493 493 } 494 494 495 495 public static function enqueue_frontend_resources() { 496 496 $active_project = self::get_active_project(); 497 497 498 498 if(!empty($active_project)) { 499 499 $settings = self::get_settings(); 500 500 501 501 $query_args = array('v' => web_fonts_get_last_saved_stylesheet_time()); 502 502 if('javascript' == $settings['embed-method']) { … … 509 509 } 510 510 } 511 511 512 512 public static function handle_stylesheet_fonts($fonts) { 513 513 $settings = self::get_settings(); 514 514 $service = self::require_library($settings['public-key'], $settings['private-key']); 515 515 $service->set_pagination_parameters(0, 1000); 516 516 517 517 $project_id = self::get_active_project(); 518 518 519 519 // Delete all existing selectors so we start with a clean slate 520 520 $existing_selectors = $service->list_selectors($project_id); … … 524 524 } 525 525 } 526 526 527 527 $selector_to_fallback_map = array(); 528 528 $font_ids = array(); … … 532 532 foreach($font->selectors as $selector) { 533 533 $selector_tag = $selector->tag; 534 534 535 535 $add_selector_response = $service->add_selector($project_id, $selector_tag); 536 536 if('Success' == $add_selector_response->Message) { 537 537 $selector_to_fallback_map[$selector_tag] = array('family' => $font->family, 'fallback' => $selector->fallback); 538 538 539 539 foreach($add_selector_response->Selector as $selector_data) { 540 540 if($selector_data->SelectorTag == $selector_tag) { … … 547 547 } 548 548 } 549 549 550 550 if(!empty($font_ids) && !empty($selector_ids)) { 551 551 $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 555 555 $service->publish(); 556 556 } 557 557 558 558 public static function handle_stylesheet_selectors($selectors) { 559 559 $settings = self::get_settings(); 560 560 $service = self::require_library($settings['public-key'], $settings['private-key']); 561 561 $service->set_pagination_parameters(0, 1000); 562 562 563 563 $project_id = self::get_active_project(); 564 564 565 565 // Delete all existing selectors so we start with a clean slate 566 566 $existing_selectors = $service->list_selectors($project_id); … … 570 570 } 571 571 } 572 572 573 573 $selector_to_fallback_map = array(); 574 574 $font_ids = array(); … … 578 578 $font_id = str_replace('fonts-com-', '', $selector->font->id); 579 579 $selector_tag = $selector->tag; 580 580 581 581 $add_selector_response = $service->add_selector($project_id, $selector_tag); 582 582 if('Success' == $add_selector_response->Message) { 583 583 $selector_to_fallback_map[$selector_tag] = array('family' => $selector->font->family, 'fallback' => $selector->fallback); 584 584 585 585 foreach($add_selector_response->Selector as $selector_data) { 586 586 if($selector_data->SelectorTag == $selector_tag) { … … 592 592 } 593 593 } 594 594 595 595 if(!empty($font_ids) && !empty($selector_ids)) { 596 596 $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 600 600 $service->publish(); 601 601 } 602 602 603 603 /// DISPLAY CALLBACKS 604 604 605 605 public static function display_fallbacks() { 606 606 $active_project = self::get_active_project(); 607 607 $selector_data = self::get_selector_data(); 608 608 609 609 if(!empty($active_project) && !empty($selector_data)) { 610 610 echo "\n<!-- Fonts.com Fallbacks -->\n"; … … 617 617 } 618 618 } 619 619 620 620 public static function display_settings_page() { 621 621 $data = stripslashes_deep($_REQUEST); 622 622 623 623 $settings = self::get_settings(); 624 624 $is_setup = self::is_setup(); 625 625 $active_project = self::get_active_project(); 626 626 627 627 $base_url = add_query_arg(array('page' => $data['page']), admin_url('admin.php')); 628 628 $valid_tabs = $is_setup ? array('setup', 'projects', 'fonts') : array('setup'); 629 629 $current_tab = in_array($data['tab'], $valid_tabs) ? $data['tab'] : ($is_setup ? (empty($active_project) ? 'projects' : 'fonts') : 'setup'); 630 630 631 631 if('fonts' == $current_tab && empty($active_project)) { 632 632 add_settings_error('fonts-com-current-tab', 'fonts-com-current-tab', __('Please select an active project before attempting to manage fonts.'), 'error'); 633 633 634 634 $current_tab = 'projects'; 635 635 } 636 636 637 637 include('views/backend/settings/_inc/nav.php'); 638 638 639 639 // Make this dynamic 640 640 switch($current_tab) { … … 645 645 $service = self::require_library($settings['public-key'], $settings['private-key']); 646 646 $projects_response = $service->list_projects(); 647 647 648 648 if('Success' == $projects_response->Message) { 649 649 $projects = (array)$projects_response->Project; … … 651 651 $projects = array(); 652 652 } 653 653 654 654 $active_project = self::get_active_project(); 655 655 656 656 include('views/backend/settings/projects.php'); 657 657 break; … … 659 659 $service = self::require_library($settings['public-key'], $settings['private-key']); 660 660 $projects_response = $service->list_projects(); 661 661 662 662 if('Success' == $projects_response->Message) { 663 663 $projects = (array)$projects_response->Project; … … 665 665 $projects = array(); 666 666 } 667 667 668 668 $available_filters = array(); 669 669 $filter_values_response = $service->list_all_filter_values(); … … 673 673 $available_filters[$filter_value_data->FilterType] = array(); 674 674 } 675 675 676 676 $available_filters[$filter_value_data->FilterType][$filter_value_data->ValueID] = $filter_value_data->ValueName; 677 677 } 678 678 } 679 679 $active_project = self::get_active_project(); 680 680 681 681 include('views/backend/settings/fonts.php'); 682 682 break; … … 685 685 686 686 /// SELECTORS 687 687 688 688 private static function get_active_project() { 689 689 $active_project = wp_cache_get(self::ACTIVE_PROJECT_KEY); 690 690 691 691 if(empty($active_project)) { 692 692 $active_project = get_option(self::ACTIVE_PROJECT_KEY); 693 693 wp_cache_set(self::ACTIVE_PROJECT_KEY, $active_project, null, time() + CACHE_PERIOD); 694 694 } 695 695 696 696 return $active_project; 697 697 } 698 698 699 699 private static function set_active_project($active_project) { 700 700 if(!empty($active_project)) { … … 707 707 708 708 /// ACTIVE PROJECT 709 709 710 710 private static function get_selector_data() { 711 711 $selector_data = wp_cache_get(self::SELECTOR_DATA_KEY); 712 712 713 713 if(!is_array($selector_data)) { 714 714 $selector_data = get_option(self::SELECTOR_DATA_KEY); 715 715 wp_cache_set(self::SELECTOR_DATA_KEY, $selector_data, null, time() + CACHE_PERIOD); 716 716 } 717 717 718 718 return $selector_data; 719 719 } 720 720 721 721 private static function set_selector_data($selector_data) { 722 722 if(is_array($selector_data)) { … … 725 725 } 726 726 } 727 727 728 728 /// SETTINGS 729 729 730 730 private static function get_settings() { 731 731 $settings = wp_cache_get(self::SETTINGS_KEY); 732 732 733 733 if(!is_array($settings)) { 734 734 $settings = wp_parse_args(get_option(self::SETTINGS_KEY, self::$default_settings), self::$default_settings); 735 735 wp_cache_set(self::SETTINGS_KEY, $settings, null, time() + CACHE_PERIOD); 736 736 } 737 737 738 738 return $settings; 739 739 } 740 740 741 741 private static function set_settings($settings) { 742 742 if(is_array($settings)) { … … 744 744 list($settings['public-key'], $settings['private-key']) = explode('--', $settings['authentication-key']); 745 745 } 746 746 747 747 $settings = wp_parse_args($settings, self::$default_settings); 748 748 update_option(self::SETTINGS_KEY, $settings); … … 750 750 } 751 751 } 752 752 753 753 /// UTILITY 754 754 755 755 private static function add_project_data($response_data, $project_id, $service) { 756 756 $service->set_pagination_parameters(0, 150); 757 757 758 758 $project_fonts_response = $service->list_project_fonts($project_id); 759 759 $response_data['project_fonts'] = array(); … … 761 761 $response_data['project_fonts'] = array_filter((array)$project_fonts_response->Font); 762 762 usort($response_data['project_fonts'], array(__CLASS__, 'usort_sort_by_font_name')); 763 763 764 764 $response_data['project_font_ids'] = array(); 765 765 foreach($response_data['project_fonts'] as $font) { … … 767 767 } 768 768 } 769 769 770 770 $project_selectors_response = $service->list_selectors($project_id); 771 771 $response_data['project_selectors'] = array(); 772 772 if('Success' == $project_selectors_response->Message) { 773 773 $response_data['project_selectors'] = array_filter((array)$project_selectors_response->Selector); 774 774 775 775 $selector_data = self::get_selector_data(); 776 776 foreach($response_data['project_selectors'] as $project_selector) { … … 778 778 } 779 779 } 780 780 781 781 return $response_data; 782 782 } … … 784 784 private static function get_nice_filter_type_text($filter_type) { 785 785 $filtered = array('Alpha' => __('a Beginning Character'), 'FreeOrPaid' => __('Free or All Fonts')); 786 786 787 787 if(isset($filtered[$filter_type])) { 788 788 $filter_type = $filtered[$filter_type]; … … 790 790 $filter_type = "a {$filter_type}"; 791 791 } 792 792 793 793 return $filter_type; 794 794 } 795 795 796 796 private static function get_response($data = array(), $message = null, $error = false) { 797 797 return array_merge(array('error' => (bool)$error, 'message' => $message), (array)$data); 798 798 } 799 799 800 800 private static function is_setup() { 801 801 $settings = self::get_settings(); 802 802 803 803 return !empty($settings['authentication-key']); 804 804 } 805 805 806 806 /** 807 807 * @return WP_Web_Fonts_Service … … 809 809 private static function require_library($public_key = null, $private_key = null) { 810 810 require_once('lib/wp-web-fonts-service.php'); 811 811 812 812 $service = new WP_Web_Fonts_Service(self::APPLICATION_KEY); 813 813 $service->set_credentials($public_key, $private_key); 814 814 $service->set_logging_enabled(true); 815 815 816 816 return $service; 817 817 } 818 818 819 819 private static function swap_data_from_projects($old_project_id, $new_project_id) { 820 820 if($old_project_id != $new_project_id) { 821 821 $settings = self::get_settings(); 822 822 823 823 $service = self::require_library($settings['public-key'], $settings['private-key']); 824 824 $service->set_pagination_parameters(0, 1000); 825 825 826 826 $old_selectors = $service->list_selectors($old_project_id); 827 827 if('Success' == $old_selectors->Message) { 828 828 $font_ids = array(); 829 829 $selector_ids = array(); 830 830 831 831 foreach($old_selectors->Selector as $selector) { 832 832 $delete_selector_response = $service->delete_selector($old_project_id, $selector->SelectorID); 833 833 $add_selector_response = $service->add_selector($new_project_id, $selector->SelectorTag); 834 834 835 835 if('Success' == $add_selector_response->Message) { 836 836 if($selector->SelectorFontID > 0) { 837 837 $font_ids[] = $selector->SelectorFontID; 838 838 839 839 foreach($add_selector_response->Selector as $added_selector) { 840 840 if($selector->SelectorTag == $added_selector->SelectorTag) { … … 846 846 } 847 847 } 848 848 849 849 $old_fonts = $service->list_project_fonts($old_project_id); 850 850 if('Success' == $old_fonts->Message) { … … 854 854 } 855 855 } 856 856 857 857 $service->assign_to_selector($new_project_id, $font_ids, $selector_ids); 858 858 859 859 $service->publish(); 860 860 } 861 861 } 862 862 863 863 private static function trim_r($data) { 864 864 if(is_array($data)) { … … 872 872 } 873 873 } 874 874 875 875 public static function usort_sort_by_font_name($a, $b) { 876 876 return strcmp($b->FontName, $a->FontName); 877 877 } 878 878 } 879 879 880 880 require_once('lib/provider.php'); 881 881 Fonts_Com_Plugin::init(); -
web-fonts/trunk/modules/google-web-fonts/google-web-fonts.php
r762516 r762519 4 4 Plugin URI: http://www.google.com/webfonts 5 5 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-RC26 Version: 1.1.6 7 7 Author: Nick Ohrn of Plugin-Developer.com 8 8 Author URI: http://plugin-developer.com/ … … 15 15 16 16 //// VERSION 17 const VERSION = '1. 0.0-RC2';17 const VERSION = '1.1.6'; 18 18 19 19 //// KEYS -
web-fonts/trunk/readme.txt
r523478 r762519 3 3 Tags: fonts, webfonts, content display, theme enhancement, plugin, admin, google, web fonts, api integration 4 4 Requires at least: 3.3 5 Tested up to: 3. 3.16 Stable tag: 1.1. 55 Tested up to: 3.6 6 Stable tag: 1.1.6 7 7 8 8 Start using web fonts on your site today! Support for web fonts from Fonts.com and Google Web Fonts is included. … … 93 93 == Changelog == 94 94 95 = 1.1.6 = 96 * Fixed bug preventing users from disabling Google Web Fonts 97 95 98 = 1.1.5 = 96 99 * Fixed Google Web Fonts CSS declaration per -
web-fonts/trunk/web-fonts.php
r523474 r762519 4 4 Plugin URI: http://webfonts.fonts.com 5 5 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. 56 Version: 1.1.6 7 7 Author: Nick Ohrn of Plugin-Developer.com 8 8 Author URI: http://plugin-developer.com/ … … 12 12 class Web_Fonts { 13 13 /// CONSTANTS 14 14 15 15 //// VERSION 16 const VERSION = '1.1. 5';17 16 const VERSION = '1.1.6'; 17 18 18 //// KEYS 19 19 const SETTINGS_KEY = '_web_fonts_settings'; 20 20 const SAVED_TIMESTAMP_KEY = '_web_fonts_stylesheet_saved_timestamp'; 21 21 22 22 //// SLUGS 23 23 const SETTINGS_PAGE_SLUG = 'web-fonts'; 24 24 25 25 //// CACHE 26 26 const CACHE_PERIOD = 86400; // 24 HOURS 27 27 28 28 /// DATA STORAGE 29 29 private static $admin_page_hooks = array(); … … 47 47 48 48 /// CALLBACKS 49 49 50 50 public static function add_administrative_interface_items() { 51 51 if(!empty(self::$registered_providers)) { 52 52 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__)); 53 53 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 55 55 add_action("load-{$stylesheet}", array(__CLASS__, 'process_manage_stylesheet')); 56 56 57 57 foreach(self::$registered_providers as $provider_class_name) { 58 58 $provider_name = call_user_func(array($provider_class_name, 'get_provider_name')); 59 59 60 60 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 62 62 call_user_func(array($provider_class_name, 'settings_page_registered'), $menu_slug); 63 63 } 64 64 } 65 65 } 66 66 67 67 public static function enqueue_administrative_resources($hook) { 68 68 if(!in_array($hook, self::$admin_page_hooks)) { return; } 69 69 70 70 wp_enqueue_script('knockout', plugins_url('resources/backend/knockout.js', __FILE__), array(), '2.0.0'); 71 71 wp_enqueue_script('web-fonts-backend', plugins_url('resources/backend/web-fonts.js', __FILE__), array('jquery', 'knockout'), self::VERSION); 72 72 wp_enqueue_style('web-fonts-backend', plugins_url('resources/backend/web-fonts.css', __FILE__), array(), self::VERSION); 73 73 } 74 74 75 75 public static function process_manage_stylesheet() { 76 76 $data = stripslashes_deep($_REQUEST); … … 78 78 if(isset($data['web-fonts-manage-stylesheet-nonce']) && wp_verify_nonce($data['web-fonts-manage-stylesheet-nonce'], 'web-fonts-manage-stylesheet')) { 79 79 $stylesheet_data = json_decode($data['web-fonts-stylesheet-data']); 80 80 81 81 do_action("web_fonts_manage_stylesheet_{$stylesheet_data->visible_tab}s", $stylesheet_data->{"{$stylesheet_data->visible_tab}s"}); 82 82 83 83 add_settings_error('general', 'stylesheet_updated', __('Stylesheet updated!'), 'updated'); 84 84 set_transient('settings_errors', get_settings_errors(), 30); 85 85 86 86 self::set_stylesheet_timestamp(current_time('timestamp')); 87 87 88 88 wp_redirect(add_query_arg(array('page' => 'web-fonts', 'settings-updated' => 'true'), admin_url('admin.php'))); 89 89 exit; 90 90 } 91 91 } 92 92 93 93 /// DISPLAY CALLBACKS 94 94 95 95 public static function display_stylesheet_page() { 96 96 include('views/backend/settings/overview.php'); 97 97 } 98 98 99 99 public static function display_settings_page() { 100 100 $data = stripslashes_deep($_GET); 101 101 102 102 $provider_key = str_replace('web-fonts-', '', $data['page']); 103 103 $provider_class_name = self::$registered_providers[$provider_key]; 104 104 105 105 include('views/backend/settings/settings.php'); 106 106 } 107 107 108 108 /// SETTINGS 109 109 110 110 private static function get_settings() { 111 111 $settings = wp_cache_get(self::SETTINGS_KEY); 112 112 113 113 if(!is_array($settings)) { 114 114 $settings = wp_parse_args(get_option(self::SETTINGS_KEY, self::$default_settings), self::$default_settings); 115 115 wp_cache_set(self::SETTINGS_KEY, $settings, null, time() + CACHE_PERIOD); 116 116 } 117 117 118 118 return $settings; 119 119 } 120 120 121 121 private static function set_settings($settings) { 122 122 if(is_array($settings)) { … … 126 126 } 127 127 } 128 128 129 129 private static function get_stylesheet_timestamp() { 130 130 $timestamp = wp_cache_get(self::SAVED_TIMESTAMP_KEY); 131 131 132 132 if(!is_array($timestamp)) { 133 133 $timestamp = get_option(self::SAVED_TIMESTAMP_KEY, time()); 134 134 wp_cache_set(self::SAVED_TIMESTAMP_KEY, $timestamp, null, time() + CACHE_PERIOD); 135 135 } 136 136 137 137 return $timestamp; 138 138 } 139 139 140 140 private static function set_stylesheet_timestamp($timestamp) { 141 141 if(!empty($timestamp)) { … … 144 144 } 145 145 } 146 146 147 147 /// UTILITY 148 148 149 149 private static function get_page_slug_for_provider($provider_class_name) { 150 150 return 'web-fonts-' . call_user_func(array($provider_class_name, 'get_provider_key')); 151 151 } 152 152 153 153 /// TEMPLATE TAGS 154 154 … … 156 156 return self::get_stylesheet_timestamp(); 157 157 } 158 158 159 159 public static function register_web_fonts_provider($provider_class_name) { 160 160 if(class_exists($provider_class_name) && is_subclass_of($provider_class_name, 'Web_Fonts_Provider') && !in_array($provider_class_name, self::$registered_providers)) { 161 161 $provider_key = call_user_func(array($provider_class_name, 'get_provider_key')); 162 162 163 163 self::$registered_providers[$provider_key] = $provider_class_name; 164 164 } 165 165 166 166 return self::$registered_providers; 167 167 } … … 173 173 // Include by default the Fonts.com provider plugin 174 174 require_once('modules/fonts-com/fonts-com.php'); 175 175 176 176 // Include by default the Google Web Fonts provider plugin 177 177 require_once('modules/google-web-fonts/google-web-fonts.php'); 178 178 179 179 Web_Fonts::init(); 180 180 }
Note: See TracChangeset
for help on using the changeset viewer.