google.web.fonts.inc

  1. cis7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
  2. cle7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
  3. ecd7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
  4. elmsmedia7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
  5. harmony7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
  6. icor7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
  7. meedjum_blog7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
  8. mooc7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc

Build CSS for Google fonts

This file exists for backwards compatibility for pre 7.x-3.x themes, it is never used in 7.x-3.x themes or newer.

Functions

Globals

Namesort descending Description
$theme_key

File

sites/all/themes/ulmus/adaptivetheme/at_core/inc/google.web.fonts.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Build CSS for Google fonts
  5. *
  6. * This file exists for backwards compatibility for pre 7.x-3.x themes, it is
  7. * never used in 7.x-3.x themes or newer.
  8. */
  9. global $theme_key, $theme_name;
  10. $theme_name = $theme_key;
  11. $path_to_at_core = drupal_get_path('theme', 'adaptivetheme');
  12. // Include the font definition arrays
  13. include_once($path_to_at_core . '/inc/fonts.inc');
  14. // Backwards compatibility cruft for pre 7.x-3.x subthemes that have google fonts
  15. // We dont want them to use this but if saves the site blowing up if a user tries...
  16. // Return a list of options
  17. function google_web_fonts_list_options() {
  18. $google_web_font_families = array();
  19. $fonts = google_font_names();
  20. foreach ($fonts as $font) {
  21. $google_web_font_families[] = $font;
  22. }
  23. return $google_web_font_families;
  24. }
  25. // Return the style name
  26. function google_web_fonts_get_style_name($key, $font_type, $font_value) {
  27. $font_value = trim($font_value);
  28. $font_value = strtolower($font_value);
  29. $font_value = str_replace(' ', '-', $font_value);
  30. return $key . (!empty($font_type) ? '-' . $font_type : "") . "-" . $font_value;
  31. }
  32. // Process font families, this is not specific to Google fonts but makes sense including it here
  33. function get_font_families($fonts, $theme_name) {
  34. $google_font_families = array();
  35. $font_type = '';
  36. $font_families = array();
  37. foreach ($fonts as $key => $value) {
  38. $font_type = theme_get_setting($value . '_type', $theme_name);
  39. $font_value = theme_get_setting($value . (!empty($font_type) ? '_' . $font_type : ''), $theme_name);
  40. if ($font_type == '') {
  41. $font_families[] = $font_value;
  42. }
  43. else {
  44. if ($font_type == 'gwf') {
  45. $gff = str_replace(' ', '+', $font_value);
  46. $google_font_families[] = $gff;
  47. $font_value = preg_replace('/[^\w\d_ -]/si', '', $font_value);
  48. $style_name = google_web_fonts_get_style_name($key, $font_type, $font_value);
  49. $font_families[] = $style_name;
  50. switch ($key) {
  51. case 'bf':
  52. drupal_add_css("body.$style_name, .$style_name .form-text {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  53. break;
  54. case 'snf':
  55. drupal_add_css("body.$style_name #site-name {font-family : '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  56. break;
  57. case 'ssf':
  58. drupal_add_css("body.$style_name #site-slogan {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  59. break;
  60. case 'mmf':
  61. drupal_add_css(".$style_name #nav-wrapper {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  62. break;
  63. case 'ptf':
  64. drupal_add_css("body.$style_name #page-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  65. break;
  66. case 'ntf':
  67. drupal_add_css("body.$style_name .article-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  68. break;
  69. case 'ctf':
  70. drupal_add_css("body.$style_name .comment-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  71. break;
  72. case 'btf':
  73. drupal_add_css("body.$style_name .block-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. if (!empty($google_font_families)) {
  80. $array = array_unique($google_font_families);
  81. $google_fonts = trim(implode('|', $array));
  82. drupal_add_css('//fonts.googleapis.com/css?family=' . $google_fonts, array(
  83. 'group' => CSS_THEME,
  84. 'type' => 'external',
  85. 'weight' => -1,
  86. 'preprocess' => FALSE,
  87. )
  88. );
  89. }
  90. return $font_families;
  91. }