web_font_loader.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. include "root.php";
  3. require_once "resources/require.php";
  4. $font_loader_version = ($_GET['v'] != '') ? $_GET['v'] : 1;
  5. header("Content-type: text/javascript; charset: UTF-8");
  6. //web font loader
  7. if ($_SESSION['theme']['font_loader']['text'] == 'true') {
  8. //parse font names
  9. if (is_array($_SESSION['theme']) && sizeof($_SESSION['theme']) > 0) {
  10. foreach ($_SESSION['theme'] as $subcategory => $type) {
  11. if (substr_count($subcategory, '_font') > 0) {
  12. $font_string = $type['text'];
  13. if ($font_string != '') {
  14. if (substr_count($font_string, ',') > 0) {
  15. $tmp_array = explode(',', $font_string);
  16. }
  17. else {
  18. $tmp_array[] = $font_string;
  19. }
  20. foreach ($tmp_array as $font_name) {
  21. $font_name = trim($font_name, "'");
  22. $font_name = trim($font_name, '"');
  23. $font_name = trim($font_name);
  24. $fonts[] = $font_name;
  25. }
  26. }
  27. }
  28. unset($tmp_array);
  29. }
  30. }
  31. //optimize fonts array
  32. if (is_array($fonts) && sizeof($fonts) > 0) {
  33. $fonts = array_unique($fonts);
  34. $common_fonts = 'serif,sans-serif,arial,arial black,arial narrow,calibri,'.
  35. 'candara,apple gothic,geneva,tahoma,microsoft sans serif,'.
  36. 'lucidia,lucidia console,monaco,lucidia sans unicode,'.
  37. 'lucidiagrande,consolas,menlo,trebuchet,trebuchet ms,'.
  38. 'helvetica,times,times new roman,courier,courier new,'.
  39. 'impact,comic sans,comic sans ms,georgia,palatino,'.
  40. 'palatino linotype,verdana,franklin gothic,'.
  41. 'franklin gothic medium,gill sans,gill sans mt,'.
  42. 'brush script,corbel,segoe,segoe ui,optima,';
  43. $common_fonts = explode(',', $common_fonts);
  44. foreach ($fonts as $index => $font) {
  45. if (in_array(strtolower($font), $common_fonts)) {
  46. unset($fonts[$index]);
  47. }
  48. }
  49. }
  50. //load fonts
  51. if (is_array($fonts) && sizeof($fonts) > 0) {
  52. if ($_SESSION['theme']['font_retrieval']['text'] == 'asynchronous') {
  53. ?>
  54. WebFontConfig = {
  55. google: {
  56. families: ['<?php echo implode("','", $fonts); ?>']
  57. }
  58. };
  59. (function(d) {
  60. var wf = d.createElement('script'), s = d.scripts[0];
  61. wf.src = '//ajax.googleapis.com/ajax/libs/webfont/<?php echo $font_loader_version; ?>/webfont.js';
  62. s.parentNode.insertBefore(wf, s);
  63. })(document);
  64. <?php
  65. }
  66. else { //synchronous
  67. ?>
  68. WebFont.load({
  69. google: {
  70. families: ['<?php echo implode("','", $fonts); ?>']
  71. }
  72. });
  73. <?php
  74. }
  75. }
  76. }
  77. ?>