PluginProbe
Social Share Buttons / 1.30
Social Share Buttons v1.30
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / classes / class-fautils.php

class-fautils.php in Social Share Buttons 1.30, at classes/class-fautils.php

163 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MbSocial;
3 defined('ABSPATH') or die('No direct access permitted');
4
5 use \maxbuttons\maxUtils as maxUtils;
6
7 // temp class ( hopefully ) for doing FA conversion on the server
8 class FAUtils
9 {
10 protected static $instance = null;
11
12 protected $faicons_array = null;
13 protected $fashims_array = null;
14 protected $faicons_searcharray = null;
15
16 public static function getInstance()
17 {
18 if (is_null(self::$instance))
19 {
20 self::$instance = new FAUtils();
21
22 }
23
24 return self::$instance;
25 }
26
27 protected function getFAIcons()
28 {
29 if (! is_null($this->faicons_array) )
30 {
31 return $this->faicons_array;
32 }
33
34 $dir = MB()->get_plugin_path() . "assets/libraries/font-awesome-5";
35
36 $icon_list = array();
37
38 $icon_json = file_get_contents($dir . '/icons_processed.json');
39 $file_icon_array = json_decode($icon_json, true);
40
41 $icon_array = array();
42 $search_array = array();
43
44 if ( is_array($file_icon_array))
45 {
46 foreach($file_icon_array as $name => $data)
47 {
48 $styles = $data['styles']; // [brands, solid, regular]
49 $nice_name = $data['label'];
50
51 $style_tag = '';
52 foreach($styles as $style)
53 {
54 switch ($style)
55 {
56 case 'brands':
57 $style_tag = 'fab';
58 $category = 'brands';
59 break;
60 case 'solid':
61 $style_tag = 'fas';
62 $category = 'solid';
63 break;
64 case 'regular':
65 $style_tag = 'far';
66 $category = 'regular';
67 break;
68 }
69 $full_icon = $style_tag . ' fa-' . $name;
70 $icon_array[$name][$style]['icon'] = $full_icon;
71 $icon_array[$name][$style]['name'] = $name;
72 $icon_array[$name][$style]['category'] = $category;
73 $icon_array[$name][$style]['nice_name'] = $nice_name;
74 $search_array[$full_icon]['path'] = $data['svg'][$style]['path'];
75 $search_array[$full_icon]['viewbox'] = $data['svg'][$style]['viewBox'];
76 }
77
78 }
79 }
80 $this->faicons_array = $icon_array;
81 $this->faicons_searcharray = $search_array;
82 return $icon_array;
83
84 }
85
86 public function getFASVG($args)
87 {
88 $defaults = array('icon'=> null,
89 'title' => null,
90 'size' => 20,
91 );
92 $args = wp_parse_args($args, $defaults);
93
94 if (is_null($args['icon']) || strlen($args['icon']) <= 0)
95 {
96 return '';
97 }
98
99 if (is_null ($this->faicons_searcharray))
100 {
101 $this->getFAIcons();
102 }
103
104 $icons = $this->faicons_searcharray;
105
106 $icon = $args['icon'];
107 $size = $args['size'];
108
109 if (! isset($icons[$icon]))
110 {
111 echo 'Icon not in icon set: ' . $icon;
112 }
113
114 $faicon_svg = $icons[$icon]['path'];
115 $faicon_viewbox = implode(' ', $icons[$icon]['viewbox']);
116 //$faicon_viewbox = '0 0 ' . $args['size'] . ' ' . $args['size'];
117
118 $svg = '<svg class="svg-mbp-fa" width="' . $size . '" height="' . $size . '" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="' . $faicon_viewbox . '"><path fill="currentColor" d="' . $faicon_svg . '"></path></svg>';
119
120 return $svg;
121 }
122
123 public function checkShims($icon)
124 {
125 if (is_null($this->fashims_array ) )
126 {
127 $conversion_path = MB()->get_plugin_path() . '/assets/libraries/font-awesome-5/shims.json';
128 $this->fashims_array = json_decode(file_get_contents($conversion_path), ARRAY_A);
129 }
130
131 $old_value = $icon;
132
133 $old_value = str_replace('fa-','', $old_value);
134 $old_value = str_replace('fa', '', $old_value);
135 $old_value = trim($old_value);
136
137 return $this->searchNewFA($old_value, $this->fashims_array);
138 }
139
140 public function searchNewFA($old, $conversion_array)
141 {
142 $new = false;
143 foreach($conversion_array as $key => $items)
144 {
145 if ($items[0] == $old)
146 {
147 $new = (strlen($items[1]) > 0) ? $items[1] : 'fas'; // if not set, fas is the set
148 $new .= ' fa-';
149 $new .= (strlen($items[2]) > 0) ? $items[2] : $old ;
150 }
151
152 }
153
154 if (! $new)
155 {
156 $new = 'fas fa-'. $old;
157 }
158
159 return $new;
160 }
161
162 }
163