fa_icons.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2024
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. //load icons
  24. $font_awesome_icons = [];
  25. if (file_exists($_SERVER["PROJECT_ROOT"].'/resources/fontawesome/metadata/icons.json')) {
  26. $icons_json = file_get_contents($_SERVER["PROJECT_ROOT"].'/resources/fontawesome/metadata/icons.json');
  27. if (!empty($icons_json)) {
  28. $icons_array = json_decode($icons_json, true);
  29. if (!empty($icons_array) && is_array($icons_array)) {
  30. $i = 0;
  31. foreach ($icons_array as $icon_name => $properties) {
  32. //loop through free icons
  33. if (!empty($properties['free']) && is_array($properties['free'])) {
  34. foreach ($properties['free'] as $icon_style) {
  35. //if search terms exist, add them to array
  36. $terms = [];
  37. if (!empty($properties['search']['terms']) && is_array($properties['search']['terms'])) {
  38. foreach ($properties['search']['terms'] as $term) {
  39. $words = explode(' ', $term);
  40. foreach ($words as $word) {
  41. if (strlen($word) >= 3) {
  42. $terms[] = strtolower($word);
  43. }
  44. }
  45. unset($words);
  46. }
  47. }
  48. //add icon name *words* themselves as search terms
  49. if (strlen(str_replace('fa-', '', $icon_name)) >= 3) {
  50. $words = explode(' ', str_replace(['fa-','-'], ['',' '], $icon_name));
  51. foreach ($words as $word) {
  52. if (strlen($word) >= 3) {
  53. $terms[] = strtolower($word);
  54. }
  55. }
  56. unset($words);
  57. }
  58. //remove duplicate terms
  59. if (!empty($terms) && is_array($terms)) {
  60. $terms = array_unique($terms);
  61. }
  62. //filter by search, if submitted
  63. if (
  64. !empty($_GET['search']) &&
  65. strlen(trim($_GET['search'])) >= 3 &&
  66. (
  67. empty($terms) ||
  68. (
  69. !empty($terms) &&
  70. is_array($terms) &&
  71. !in_array(trim(strtolower($_GET['search'])), $terms)
  72. )
  73. )
  74. ) {
  75. continue;
  76. }
  77. $font_awesome_icons[$i]['terms'] = $terms;
  78. //add classes (icon style and name)
  79. $font_awesome_icons[$i]['classes']['style'] = 'fa-'.$icon_style;
  80. $font_awesome_icons[$i]['classes']['name'] = 'fa-'.$icon_name;
  81. //detmine whether to append style to previous (and current) label
  82. $append_style = false;
  83. if (
  84. $i != 0 &&
  85. $font_awesome_icons[$i - 1]['classes']['name'] == $font_awesome_icons[$i]['classes']['name'] &&
  86. $font_awesome_icons[$i - 1]['classes']['style'] != $font_awesome_icons[$i]['classes']['style']
  87. ) {
  88. $font_awesome_icons[$i - 1]['label'] .= ' - '.ucwords(str_replace('fa-', '', $font_awesome_icons[$i - 1]['classes']['style']));
  89. $append_style = true;
  90. }
  91. //determine label
  92. $font_awesome_icons[$i]['label'] = ucwords(str_replace(['fa-','-'], ['',' '], $icon_name)).($append_style ? ' - '.ucwords(str_replace('fa-', '', $font_awesome_icons[$i]['classes']['style'])) : null);
  93. //clear vars
  94. $i++;
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }
  101. // view_array($font_awesome_icons);
  102. //output icons
  103. if (
  104. !empty($_GET['output']) && $_GET['output'] == 'icons' &&
  105. !empty($font_awesome_icons) && is_array($font_awesome_icons)
  106. ) {
  107. foreach ($font_awesome_icons as $icon) {
  108. echo "<span class='".escape(implode(' ', $icon['classes']))." fa-fw' style='font-size: 24px; float: left; margin: 0 8px 8px 0; cursor: pointer; opacity: 0.3;' title='".escape($icon['label'])."' onclick=\"$('#selected_icon').val('".escape(implode(' ', $icon['classes']))."'); $('#icons').slideUp(); $('#icon_search').fadeOut(200, function() { $('#icon_search').val(''); $('#grid_icon').fadeIn(); });\" onmouseover=\"this.style.opacity='1';\" onmouseout=\"this.style.opacity='0.3';\"></span>\n";
  109. }
  110. }