Custom Icons for Elementor - Version 0.3

Version Description

  • Added support for the new Elementor v2.6+ icons manager
Download this release

Release Info

Developer michaelbourne
Plugin Icon 128x128 Custom Icons for Elementor
Version 0.3
Comparing to
See all releases

Code changes from version 0.2.4 to 0.3

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/yycpro
4
  Tags: elementor, icons, fontello, icon fonts
5
  Requires at least: 4.5
6
  Tested up to: 5.2.1
7
- Stable tag: 0.2.4
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
@@ -63,6 +63,9 @@ None yet
63
 
64
  == Changelog ==
65
 
 
 
 
66
  = 0.2.4 =
67
  * Supress PHP warning if Fontello file can't be read by server
68
  * Add URL fallback for Fontello file reading (some servers are setup in a way that prevents server path reading)
@@ -109,6 +112,9 @@ None yet
109
 
110
  == Upgrade Notice ==
111
 
 
 
 
112
  = 0.2.4 =
113
  PHP & CSS fixes
114
 
4
  Tags: elementor, icons, fontello, icon fonts
5
  Requires at least: 4.5
6
  Tested up to: 5.2.1
7
+ Stable tag: 0.3
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
63
 
64
  == Changelog ==
65
 
66
+ = 0.3 =
67
+ * Added support for the new Elementor v2.6+ icons manager
68
+
69
  = 0.2.4 =
70
  * Supress PHP warning if Fontello file can't be read by server
71
  * Add URL fallback for Fontello file reading (some servers are setup in a way that prevents server path reading)
112
 
113
  == Upgrade Notice ==
114
 
115
+ = 0.3 =
116
+ Elementor version 2.6+ Support. You MUST 'regen CSS' after this update.
117
+
118
  = 0.2.4 =
119
  PHP & CSS fixes
120
 
assets/js/elementor-custom-icons.js CHANGED
@@ -127,7 +127,7 @@ jQuery(document).ready(function($) {
127
  e.preventDefault();
128
 
129
  var conf = confirm( EC_ICONS.delete );
130
-
131
  if(conf == true){
132
 
133
  var request = new FormData(),
127
  e.preventDefault();
128
 
129
  var conf = confirm( EC_ICONS.delete );
130
+
131
  if(conf == true){
132
 
133
  var request = new FormData(),
elementor-custom-icons.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Custom Icons for Elementor
4
  Description: Add custom icon fonts to the built in Elementor controls
5
- Version: 0.2.4
6
  Author: Michael Bourne
7
  Author URI: https://michaelbourne.ca
8
  License: GPL3
@@ -23,461 +23,513 @@ You should have received a copy of the GNU General Public License along with thi
23
  You can contact me at michael@michaelbourne.ca
24
  */
25
 
26
- if( ! defined( 'ABSPATH' ) ) {
27
- return;
28
  }
29
 
30
  defined( 'ECIcons_ROOT' ) or define( 'ECIcons_ROOT', dirname( __FILE__ ) );
31
  defined( 'ECIcons_URI' ) or define( 'ECIcons_URI', plugin_dir_url( __FILE__ ) );
32
- defined( 'ECIcons_VERSION' ) or define( 'ECIcons_VERSION', '0.2.4' );
33
  defined( 'ECIcons_UPLOAD' ) or define( 'ECIcons_UPLOAD', 'elementor_icons_files' );
34
 
35
  class ECIcons {
36
 
37
- /**
38
- * Core singleton class
39
- *
40
- * @var self - pattern realization
41
- */
42
- private static $_instance;
43
-
44
- /**
45
- * Prefix for plugin
46
- *
47
- * @var $prefix
48
- */
49
- private $prefix;
50
-
51
- /**
52
- * Path upload folder
53
- *
54
- * @var $upload_dir
55
- */
56
- public $upload_dir;
57
-
58
- /**
59
- * URL upload folder
60
- *
61
- * @var $upload_url
62
- */
63
- private $upload_url;
64
-
65
- /**
66
- * uploads folder name
67
- *
68
- * @var $upload_dir_single
69
- */
70
- private $upload_dir_single;
71
-
72
- /**
73
- * Prefix for custom icons
74
- *
75
- * @var $prefix_icon
76
- */
77
- private $prefix_icon;
78
-
79
- /**
80
- * Constructor.
81
- */
82
- private function __construct() {
83
-
84
-
85
- // merge font css to single .css file
86
- include_once( ECIcons_ROOT . '/includes/merge.css.php' );
87
-
88
- // save font class
89
- include_once( ECIcons_ROOT . '/includes/save.font.php' );
90
-
91
- // add menu item
92
- add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 99 );
93
-
94
- add_action( 'admin_init', array( $this, 'admin_init' ) );
95
-
96
- // add admin styles and scripts
97
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
98
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
99
-
100
- // for front end
101
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 999999 );
102
- add_action( 'wp_enqueue_scripts_clean', array( $this, 'enqueue_scripts' ), 10 );
103
-
104
- // add icon css to footer for builder support
105
- add_action( 'wp_print_footer_scripts', array( $this, 'insert_footer_css' ) );
106
-
107
- // load icons
108
- add_action( 'elementor/controls/controls_registered', array( $this, 'icons_filters' ), 100, 1);
109
-
110
- // default wp upload directory
111
- $upload = wp_upload_dir();
112
-
113
- // main variables
114
- $this->prefix = 'eci_';
115
- $this->prefix_icon = 'efs-';
116
- $this->upload_dir = $upload['basedir'] . '/' . ECIcons_UPLOAD;
117
- $this->upload_url = $upload['baseurl'] . '/' . ECIcons_UPLOAD;
118
- //$this->upload_dir_single = str_replace( get_option('siteurl'), '', $this->upload_url );
119
-
120
- // set plugin version
121
- $this->version = '0.2.4';
122
-
123
- // SSL fix because WordPress core function wp_upload_dir() doesn't check protocol.
124
- if ( is_ssl() ) $this->upload_url = str_replace( 'http://', 'https://', $this->upload_url );
125
-
126
- // load translations
127
- add_action( 'plugins_loaded', array( $this, 'eci_load_textdomain' ) );
128
  }
129
 
130
- /**
131
- * Get the instance of ECIcons Plugins
132
- *
133
- * @return self
134
- */
135
- public static function getInstance() {
136
 
137
- if ( ! ( self::$_instance instanceof self ) ) {
138
- self::$_instance = new self();
139
- }
 
 
140
 
141
- return self::$_instance;
 
142
 
 
 
 
143
  }
144
 
145
- /**
146
- * @param mixed $instance
147
- */
148
- public static function setInstance( $instance ) {
149
 
150
- self::$_instance = $instance;
 
 
 
 
 
151
 
 
 
152
  }
153
 
154
- /**
155
- * Init main functions (for hook admin_init)
156
- */
157
- public function admin_init() {
158
 
159
- $this->settings_init();
160
 
161
- $saveFont = new SaveFont_ECIcons();
162
- $saveFont->init();
 
 
163
 
164
- }
165
 
166
- /**
167
- * Internationalization
168
- */
169
- public function eci_load_textdomain() {
170
- load_plugin_textdomain( 'custom-icons-for-elementor', false, dirname( plugin_basename(__FILE__) ) . '/languages/' );
171
- }
172
 
173
- /**
174
- * Add new pages to admin
175
- */
176
- public function add_admin_menu() {
177
-
178
- add_submenu_page(
179
- 'elementor',
180
- __( 'Custom Icons for Elementor', 'custom-icons-for-elementor' ),
181
- __( 'Custom Icons', 'custom-icons-for-elementor' ),
182
- 'manage_options',
183
- 'elementor-custom-icons',
184
- array(
185
- $this,
186
- 'options_page',
187
- )
188
- );
189
 
190
- }
191
 
192
- /**
193
- * Render all options
194
- */
195
- public function options_page() {
196
 
197
- include_once 'includes/template.options.page.php';
198
 
199
- }
 
 
 
 
 
200
 
 
 
 
 
201
 
202
- /**
203
- * ECIcons settings init
204
- */
205
- protected function settings_init() {
 
 
 
 
 
 
 
206
 
207
- register_setting( $this->prefix . 'fontellos_page', $this->prefix . 'elementor_icons_settings' );
208
- add_settings_section( $this->prefix . 'fontellos_pluginPage_section', '', '', $this->prefix . 'fontellos_page' );
209
 
210
- }
 
 
 
211
 
 
212
 
213
- /**
214
- * Enqueue admin scripts
215
- */
216
- public function admin_enqueue_scripts() {
217
-
218
- wp_enqueue_style( 'elementor-custom-icons-css', ECIcons_URI . 'assets/css/elementor-custom-icons.css', array(), ECIcons_VERSION );
219
-
220
- wp_enqueue_script( 'elementor-custom-icons', ECIcons_URI . 'assets/js/elementor-custom-icons.js', array('jquery'), ECIcons_VERSION, true );
221
-
222
- if ( is_admin() ) {
223
- $eci_script = array(
224
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
225
- 'plugin_url' => ECIcons_URI,
226
- 'exist' => __( "This font file already exists. Make sure you're giving it a unique name!", 'custom-icons-for-elementor' ),
227
- 'failedopen' => __( 'Failed to open the ZIP archive. If you uploaded a valid Fontello ZIP file, your host may be blocking this PHP function. Please get in touch with them.', 'custom-icons-for-elementor' ),
228
- 'failedextract' => __( 'Failed to extract the ZIP archive. Your host may be blocking this PHP function. Please get in touch with them.', 'custom-icons-for-elementor' ),
229
- 'emptyfile' => __( 'Your browser failed to upload the file. Please try again.', 'custom-icons-for-elementor' ),
230
- 'regen' => __( 'Custom Icon CSS file has been regenerated.', 'custom-icons-for-elementor' ),
231
- 'delete' => __( 'Are you sure you want to delete this font?', 'custom-icons-for-elementor' ),
232
- 'updatefailed' => __( 'Plugin failed to update the WP options table.', 'custom-icons-for-elementor' ),
233
- );
234
- wp_localize_script( 'elementor-custom-icons', 'EC_ICONS', $eci_script );
235
- }
236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  }
238
 
239
- /**
240
- * Enqueue public scripts
241
- */
242
- public function enqueue_scripts() {
243
 
244
- if ( file_exists( $this->upload_dir . '/merged-icons-font.css' ) ) {
 
 
 
245
 
246
- $modtime = @filemtime( $this->upload_dir . '/merged-icons-font.css' );
247
- if(!$modtime){ $modtime = mt_rand(); }
248
- wp_enqueue_style( 'eci-icon-fonts', esc_url( $this->upload_url . '/merged-icons-font.css' ), false, $modtime );
249
- }
250
 
 
 
 
 
251
  }
252
 
253
- /**
254
- * Add custom font CSS to footer so it actually works in the builder
255
- * - to do: get this working with the builder boilerplate action
256
- */
257
- public function insert_footer_css() {
258
 
259
- if( current_user_can( 'manage_options' ) ){
 
 
 
 
260
 
261
- if ( file_exists( $this->upload_dir . '/merged-icons-font.css' ) ) {
262
 
263
- $modtime = @filemtime( $this->upload_dir . '/merged-icons-font.css' );
264
- if(!$modtime){ $modtime = mt_rand(); }
265
- echo '<link rel="stylesheet" type="text/css" href="' . $this->upload_url . '/merged-icons-font.css?ver=' . $modtime . '">';
266
- }
 
 
267
  }
 
268
  }
269
 
270
- /**
271
- * Get uploaded font package's config file
272
- *
273
- * @param string $file_name
274
- * @return array $data
275
- */
276
- public function get_config_font( $file_name ) {
277
-
278
- $file_config = glob( $this->upload_dir . '/' . $file_name . '/*/*' );
279
- $data = array();
280
- $css_folder = '';
281
-
282
- foreach ( $file_config as $key => $file ) {
283
-
284
- if ( strpos( $file, 'config.json' ) !== false ) {
285
- $file_info = json_decode( file_get_contents( $file ) );
286
- $data['name'] = trim($file_info->name);
287
- $data['icons'] = $file_info->glyphs;
288
- $data['css_prefix_text'] = $file_info->css_prefix_text;
289
- }
290
 
291
- if ( is_string( $file ) && strpos( $file, 'css' ) !== false ) {
292
- $file_part = explode( ECIcons_UPLOAD . '/', $file );
293
- $data['css_folder'] = $file;
294
- $css_folder = $file_part[1];
295
- }
 
 
296
 
297
- if ( is_string( $file ) && strpos( $file, 'font' ) !== false ) {
298
- $file_part = explode( ECIcons_UPLOAD . '/', $file );
299
- //$data['font_url'] = $this->upload_url . $file_part[1];
300
- $data['font_url'] = $file_part[1];
301
- }
302
 
303
- }
 
 
304
 
305
- if ( empty( $data['name'] ) ) {
306
- $noname = explode('.', $file_name);
307
- $data['name'] = $noname[0];
308
- $data['nameempty'] = true;
309
- $data['css_root'] = $data['css_folder'] . '/fontello.css';
310
- $data['css_url'] = $this->upload_url . '/' . $css_folder . '/fontello.css';
311
- } else {
312
- $data['css_root'] = $data['css_folder'] . '/' . $data['name'] . '.css';
313
- $data['css_url'] = $this->upload_url . '/' . $css_folder . '/' . $data['name'] . '.css';
314
  }
315
 
 
 
 
 
 
316
 
317
- $data['file_name'] = $file_name;
318
-
 
 
 
 
319
 
320
- return $data;
 
 
 
 
 
321
 
 
 
 
322
  }
323
 
324
- /**
325
- * Add custom icons to Elementor registry
326
- *
327
- * @param object $controls_registry
328
- * @return void
329
- */
330
- public function icons_filters( $controls_registry ) {
331
 
332
- // Get existing icons
333
- $icons = $controls_registry->get_control( 'icon' )->get_settings( 'options' );
334
 
335
- // Provide developer filter to remove FA icons from selectors
336
- if ( apply_filters( 'eci_drop_fa', false ) ) {
337
- $icons = array();
338
- }
339
 
340
- // get loaded icon files
341
- $options = get_option( 'ec_icons_fonts' );
 
 
 
 
 
342
 
 
 
343
 
344
- if ( empty( $options ) ) {
345
- return;
346
- }
 
 
 
 
347
 
348
- foreach ( $options as $key => $font ) {
349
- if ( $font['status'] == '1' ) {
 
350
 
351
- $font_data = json_decode($font['data'],true);
 
352
 
353
- $new_icons_reverse = $this->parse_css_reverse( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
354
- if ( !empty($new_icons_reverse) && is_array( $new_icons_reverse ) ) {
355
- $icons = array_merge($new_icons_reverse, $icons);
356
- }
 
357
  }
358
  }
 
 
 
 
 
 
 
359
 
360
- // send back new array
361
- $controls_registry->get_control( 'icon' )->set_settings( 'options', $icons );
 
 
 
 
 
362
 
 
 
 
 
 
363
  }
364
 
 
365
 
366
- /**
367
- * Parse CSS file to get proper icon names
368
- *
369
- * @param string $css_file
370
- * @param string $name
371
- * @param string $url
372
- * @return array $icons
373
- */
374
- protected function parse_css( $css_file, $name, $url ) {
375
 
376
- /**
377
- if ( ! file_exists( $css_file ) ) {
378
- return null;
379
- }
380
- **/
381
-
382
- $css_source = @file_get_contents( $css_file );
 
 
 
 
 
 
 
 
383
 
384
- if ( $css_source === false ) {
385
- $css_source = @file_get_contents( $url );
386
- if ( $css_source === false ) return null;
387
  }
 
388
 
389
- $icons = array();
390
 
391
- preg_match_all( "/\.\w*?\-(.*?):\w*?\s*?{?\s*?{\s*?\w*?:\s*?\'\\\\?(\w*?)\'.*?}/", $css_source, $matches, PREG_SET_ORDER, 0 );
392
- foreach ( $matches as $match ) {
393
- $icons[ $name . '-' . $match[1] ] = $match[2];
394
- }
395
 
396
- return $icons;
397
 
398
- }
399
 
 
 
 
 
 
 
 
 
 
400
 
401
- /**
402
- * Parse CSS file to get proper icon names (reverse parse)
403
- *
404
- * @param string $css_file
405
- * @param string $name
406
- * @param string $url
407
- * @return array $icons
408
- */
409
- protected function parse_css_reverse( $css_file, $name, $url ) {
410
 
411
- /**
412
- if ( ! file_exists( $css_file ) ) {
 
 
 
 
413
  return null;
414
  }
415
- **/
416
 
417
- $css_source = @file_get_contents( $css_file );
418
 
419
- if ( $css_source === false ) {
420
- $css_source = @file_get_contents( $url );
421
- if ( $css_source === false ) return null;
422
- }
423
 
424
- $icons = array();
 
 
 
425
 
426
- preg_match_all( "/\.\w*?\-(.*?):\w*?\s*?{?\s*?{\s*?\w*?:\s*?\'\\\\?(\w*?)\'.*?}/", $css_source, $matches, PREG_SET_ORDER, 0 );
427
- foreach ( $matches as $match ) {
428
- $icons['eci ' . $name . '-' . $match[1] ] = $match[1];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  }
430
 
431
- return $icons;
 
 
432
 
 
 
 
433
  }
434
 
435
- /**
436
- * remove folder (recursive)
437
- *
438
- * @param string $dir
439
- * @return void
440
- */
441
- protected function rrmdir( $dir ) {
442
-
443
- if ( is_dir( $dir ) ) {
444
- $objects = scandir( $dir );
445
- foreach ( $objects as $object ) {
446
- if ( $object != "." && $object != ".." ) {
447
- if ( is_dir( $dir . "/" . $object ) ) {
448
- $this->rrmdir( $dir . "/" . $object );
449
- } else {
450
- unlink( $dir . "/" . $object );
451
- }
 
 
 
 
 
 
452
  }
453
  }
454
- rmdir( $dir );
455
  }
456
-
457
  }
458
 
459
- /**
460
- * @param string $name
461
- * @param bool $default
462
- * @param string $type
463
- *
464
- * @return bool|string
465
- */
466
- protected function getRequest( $name, $default = false, $type = 'POST' ) {
467
-
468
- $TYPE = ( strtolower( $type ) == 'post' ) ? $_POST : $_GET;
469
- if ( ! empty( $TYPE[ $name ] ) ) {
470
- return sanitize_text_field( $TYPE[ $name ] );
471
- }
472
 
473
- return $default;
 
 
 
 
 
 
 
474
 
 
 
 
475
  }
476
 
 
 
 
 
477
  }
478
 
479
  function ec_icons_manager() {
480
  return ECIcons::getInstance();
481
  }
482
 
483
- ec_icons_manager();
2
  /*
3
  Plugin Name: Custom Icons for Elementor
4
  Description: Add custom icon fonts to the built in Elementor controls
5
+ Version: 0.3
6
  Author: Michael Bourne
7
  Author URI: https://michaelbourne.ca
8
  License: GPL3
23
  You can contact me at michael@michaelbourne.ca
24
  */
25
 
26
+ if ( ! defined( 'ABSPATH' ) ) {
27
+ return;
28
  }
29
 
30
  defined( 'ECIcons_ROOT' ) or define( 'ECIcons_ROOT', dirname( __FILE__ ) );
31
  defined( 'ECIcons_URI' ) or define( 'ECIcons_URI', plugin_dir_url( __FILE__ ) );
32
+ defined( 'ECIcons_VERSION' ) or define( 'ECIcons_VERSION', '0.3' );
33
  defined( 'ECIcons_UPLOAD' ) or define( 'ECIcons_UPLOAD', 'elementor_icons_files' );
34
 
35
  class ECIcons {
36
 
37
+ /**
38
+ * Core singleton class
39
+ *
40
+ * @var self - pattern realization
41
+ */
42
+ private static $_instance;
43
+
44
+ /**
45
+ * Prefix for plugin
46
+ *
47
+ * @var $prefix
48
+ */
49
+ public $prefix;
50
+
51
+ /**
52
+ * Path upload folder
53
+ *
54
+ * @var $upload_dir
55
+ */
56
+ public $upload_dir;
57
+
58
+ /**
59
+ * URL upload folder
60
+ *
61
+ * @var $upload_url
62
+ */
63
+ public $upload_url;
64
+
65
+ /**
66
+ * Prefix for custom icons
67
+ *
68
+ * @var $prefix_icon
69
+ */
70
+ public $prefix_icon;
71
+
72
+ /**
73
+ * Constructor.
74
+ */
75
+ private function __construct() {
76
+
77
+ // merge font css to single .css file
78
+ include_once( ECIcons_ROOT . '/includes/merge.css.php' );
79
+
80
+ // save font class
81
+ include_once( ECIcons_ROOT . '/includes/save.font.php' );
82
+
83
+ // add menu item
84
+ add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 99 );
85
+
86
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
87
+
88
+ // add admin styles and scripts
89
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
90
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
91
+
92
+ // for front end
93
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 999999 );
94
+ add_action( 'wp_enqueue_scripts_clean', array( $this, 'enqueue_scripts' ), 10 );
95
+
96
+ // add icon css to footer for builder support
97
+ add_action( 'wp_print_footer_scripts', array( $this, 'insert_footer_css' ) );
98
+
99
+ // load icons
100
+ add_action( 'elementor/controls/controls_registered', array( $this, 'icons_filters' ), 100, 1 );
101
+ add_filter( 'elementor/icons_manager/additional_tabs', array( $this, 'icons_filters_new' ), 9999999, 1 );
102
+
103
+ // Provide developer filter to remove FA icons from selectors
104
+ if ( apply_filters( 'eci_drop_fa', false ) ) {
105
+ // TODO: this doesn't work yet, because the "default icon" in widgets requires these tabs to be active. Need to override all default icon selections in all icon based widgets to enable this.
106
+ //add_filter( 'elementor/icons_manager/native', '__return_empty_array' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
108
 
109
+ // default wp upload directory
110
+ $upload = wp_upload_dir();
 
 
 
 
111
 
112
+ // main variables
113
+ $this->prefix = 'eci_';
114
+ $this->prefix_icon = 'efs-';
115
+ $this->upload_dir = $upload['basedir'] . '/' . ECIcons_UPLOAD;
116
+ $this->upload_url = $upload['baseurl'] . '/' . ECIcons_UPLOAD;
117
 
118
+ // set plugin version
119
+ $this->version = '0.3';
120
 
121
+ // SSL fix because WordPress core function wp_upload_dir() doesn't check protocol.
122
+ if ( is_ssl() ) {
123
+ $this->upload_url = str_replace( 'http://', 'https://', $this->upload_url );
124
  }
125
 
126
+ // load translations
127
+ add_action( 'plugins_loaded', array( $this, 'eci_load_textdomain' ) );
128
+ }
 
129
 
130
+ /**
131
+ * Get the instance of ECIcons Plugins
132
+ *
133
+ * @return self
134
+ */
135
+ public static function getInstance() {
136
 
137
+ if ( ! ( self::$_instance instanceof self ) ) {
138
+ self::$_instance = new self();
139
  }
140
 
141
+ return self::$_instance;
 
 
 
142
 
143
+ }
144
 
145
+ /**
146
+ * @param mixed $instance
147
+ */
148
+ public static function setInstance( $instance ) {
149
 
150
+ self::$_instance = $instance;
151
 
152
+ }
 
 
 
 
 
153
 
154
+ /**
155
+ * Init main functions (for hook admin_init)
156
+ */
157
+ public function admin_init() {
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
+ $this->settings_init();
160
 
161
+ $saveFont = new SaveFont_ECIcons();
162
+ $saveFont->init();
 
 
163
 
164
+ }
165
 
166
+ /**
167
+ * Internationalization
168
+ */
169
+ public function eci_load_textdomain() {
170
+ load_plugin_textdomain( 'custom-icons-for-elementor', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
171
+ }
172
 
173
+ /**
174
+ * Add new pages to admin
175
+ */
176
+ public function add_admin_menu() {
177
 
178
+ add_submenu_page(
179
+ 'elementor',
180
+ __( 'Custom Icons for Elementor', 'custom-icons-for-elementor' ),
181
+ __( 'Custom Icons', 'custom-icons-for-elementor' ),
182
+ 'manage_options',
183
+ 'elementor-custom-icons',
184
+ array(
185
+ $this,
186
+ 'options_page',
187
+ )
188
+ );
189
 
190
+ }
 
191
 
192
+ /**
193
+ * Render all options
194
+ */
195
+ public function options_page() {
196
 
197
+ include_once 'includes/template.options.page.php';
198
 
199
+ }
200
+
201
+
202
+ /**
203
+ * ECIcons settings init
204
+ */
205
+ protected function settings_init() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
+ register_setting( $this->prefix . 'fontellos_page', $this->prefix . 'elementor_icons_settings' );
208
+ add_settings_section( $this->prefix . 'fontellos_pluginPage_section', '', '', $this->prefix . 'fontellos_page' );
209
+
210
+ }
211
+
212
+
213
+ /**
214
+ * Enqueue admin scripts
215
+ */
216
+ public function admin_enqueue_scripts() {
217
+
218
+ wp_enqueue_style( 'elementor-custom-icons-css', ECIcons_URI . 'assets/css/elementor-custom-icons.css', array(), ECIcons_VERSION );
219
+
220
+ wp_enqueue_script( 'elementor-custom-icons', ECIcons_URI . 'assets/js/elementor-custom-icons.js', array( 'jquery' ), ECIcons_VERSION, true );
221
+
222
+ if ( is_admin() ) {
223
+ $eci_script = array(
224
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
225
+ 'plugin_url' => ECIcons_URI,
226
+ 'exist' => __( "This font file already exists. Make sure you're giving it a unique name!", 'custom-icons-for-elementor' ),
227
+ 'failedopen' => __( 'Failed to open the ZIP archive. If you uploaded a valid Fontello ZIP file, your host may be blocking this PHP function. Please get in touch with them.', 'custom-icons-for-elementor' ),
228
+ 'failedextract' => __( 'Failed to extract the ZIP archive. Your host may be blocking this PHP function. Please get in touch with them.', 'custom-icons-for-elementor' ),
229
+ 'emptyfile' => __( 'Your browser failed to upload the file. Please try again.', 'custom-icons-for-elementor' ),
230
+ 'regen' => __( 'Custom Icon CSS file has been regenerated.', 'custom-icons-for-elementor' ),
231
+ 'delete' => __( 'Are you sure you want to delete this font?', 'custom-icons-for-elementor' ),
232
+ 'updatefailed' => __( 'Plugin failed to update the WP options table.', 'custom-icons-for-elementor' ),
233
+ );
234
+ wp_localize_script( 'elementor-custom-icons', 'EC_ICONS', $eci_script );
235
  }
236
 
237
+ }
 
 
 
238
 
239
+ /**
240
+ * Enqueue public scripts
241
+ */
242
+ public function enqueue_scripts() {
243
 
244
+ if ( file_exists( $this->upload_dir . '/merged-icons-font.css' ) ) {
 
 
 
245
 
246
+ $modtime = get_option( 'eci_css_timestamp' );
247
+ if ( ! $modtime ) {
248
+ $modtime = mt_rand(); }
249
+ wp_enqueue_style( 'eci-icon-fonts', esc_url( $this->upload_url . '/merged-icons-font.css' ), false, $modtime );
250
  }
251
 
252
+ }
 
 
 
 
253
 
254
+ /**
255
+ * Add custom font CSS to footer so it actually works in the builder
256
+ * - to do: get this working with the builder boilerplate action
257
+ */
258
+ public function insert_footer_css() {
259
 
260
+ if ( current_user_can( 'manage_options' ) ) {
261
 
262
+ if ( file_exists( $this->upload_dir . '/merged-icons-font.css' ) ) {
263
+
264
+ $modtime = get_option( 'eci_css_timestamp' );
265
+ if ( ! $modtime ) {
266
+ $modtime = mt_rand(); }
267
+ echo '<link rel="stylesheet" type="text/css" href="' . $this->upload_url . '/merged-icons-font.css?ver=' . $modtime . '">';
268
  }
269
+
270
  }
271
 
272
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
+ /**
275
+ * Get uploaded font package's config file
276
+ *
277
+ * @param string $file_name
278
+ * @return array $data
279
+ */
280
+ public function get_config_font( $file_name ) {
281
 
282
+ if ( ! is_dir( $this->upload_dir . '/' . $file_name ) ) return false;
 
 
 
 
283
 
284
+ $file_config = glob( $this->upload_dir . '/' . $file_name . '/*/*' );
285
+ $data = array();
286
+ $css_folder = '';
287
 
288
+ foreach ( $file_config as $key => $file ) {
289
+
290
+ if ( strpos( $file, 'config.json' ) !== false ) {
291
+ $file_info = json_decode( file_get_contents( $file ) );
292
+ $data['name'] = trim( $file_info->name );
293
+ $data['icons'] = $file_info->glyphs;
294
+ $data['css_prefix_text'] = $file_info->css_prefix_text;
 
 
295
  }
296
 
297
+ if ( is_string( $file ) && strpos( $file, 'css' ) !== false ) {
298
+ $file_part = explode( ECIcons_UPLOAD . '/', $file );
299
+ $data['css_folder'] = $file;
300
+ $css_folder = $file_part[1];
301
+ }
302
 
303
+ if ( is_string( $file ) && strpos( $file, 'font' ) !== false ) {
304
+ $file_part = explode( ECIcons_UPLOAD . '/', $file );
305
+ //$data['font_url'] = $this->upload_url . $file_part[1];
306
+ $data['font_url'] = $file_part[1];
307
+ }
308
+ }
309
 
310
+ if ( empty( $data['name'] ) ) {
311
+ $noname = explode( '.', $file_name );
312
+ $data['name'] = $noname[0];
313
+ $data['nameempty'] = true;
314
+ $data['css_root'] = $data['css_folder'] . '/fontello.css';
315
+ $data['css_url'] = $this->upload_url . '/' . $css_folder . '/fontello.css';
316
 
317
+ } else {
318
+ $data['css_root'] = $data['css_folder'] . '/' . $data['name'] . '.css';
319
+ $data['css_url'] = $this->upload_url . '/' . $css_folder . '/' . $data['name'] . '.css';
320
  }
321
 
322
+ $data['json_url'] = $this->upload_url . '/' . $data['name'] . '.json';
323
+ $data['file_name'] = $file_name;
 
 
 
 
 
324
 
325
+ return $data;
 
326
 
327
+ }
 
 
 
328
 
329
+ /**
330
+ * Add custom icons to Elementor registry
331
+ *
332
+ * @param object $controls_registry
333
+ * @return void
334
+ */
335
+ public function icons_filters( $controls_registry ) {
336
 
337
+ // Get existing icons
338
+ $icons = $controls_registry->get_control( 'icon' )->get_settings( 'options' );
339
 
340
+ // Provide developer filter to remove FA icons from selectors
341
+ if ( apply_filters( 'eci_drop_fa', false ) ) {
342
+ $icons = array();
343
+ }
344
+
345
+ // get loaded icon files
346
+ $options = get_option( 'ec_icons_fonts' );
347
 
348
+ if ( empty( $options ) ) {
349
+ return;
350
+ }
351
 
352
+ foreach ( $options as $key => $font ) {
353
+ if ( $font['status'] == '1' ) {
354
 
355
+ $font_data = json_decode( $font['data'], true );
356
+
357
+ $new_icons_reverse = $this->parse_css_reverse( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
358
+ if ( ! empty( $new_icons_reverse ) && is_array( $new_icons_reverse ) ) {
359
+ $icons = array_merge( $new_icons_reverse, $icons );
360
  }
361
  }
362
+ }
363
+
364
+ // send back new array
365
+ $controls_registry->get_control( 'icon' )->set_settings( 'options', $icons );
366
+
367
+ }
368
+
369
 
370
+ /**
371
+ * Add custom icons to Elementor Icons tabs (new in v2.6+)
372
+ *
373
+ * @param array $tabs Additional tabs for new icon interface.
374
+ * @return array $tabs
375
+ */
376
+ public function icons_filters_new( $tabs = array() ) {
377
 
378
+ // get loaded icon files
379
+ $options = get_option( 'ec_icons_fonts' );
380
+
381
+ if ( empty( $options ) ) {
382
+ return;
383
  }
384
 
385
+ $newicons = [];
386
 
387
+ foreach ( $options as $key => $font ) {
388
+ if ( $font['status'] == '1' ) {
 
 
 
 
 
 
 
389
 
390
+ $font_data = json_decode( $font['data'], true );
391
+ $icons = $this->parse_css( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
392
+ $first_icon = ! empty( $icons ) ? key( $icons ) : '';
393
+
394
+ $newicons[ $font_data['name'] ] = [
395
+ 'name' => $font_data['name'],
396
+ 'label' => $font_data['name'],
397
+ 'url' => '',
398
+ 'enqueue' => '',
399
+ 'prefix' => '',
400
+ 'displayPrefix' => 'eci ',
401
+ 'labelIcon' => 'eci ' . $first_icon,
402
+ 'ver' => ECIcons_VERSION,
403
+ 'fetchJson' => $font_data['json_url'],
404
+ ];
405
 
 
 
 
406
  }
407
+ }
408
 
409
+ return array_merge( $tabs, $newicons );
410
 
411
+ }
 
 
 
412
 
 
413
 
 
414
 
415
+ /**
416
+ * Parse CSS file to get proper icon names
417
+ *
418
+ * @param string $css_file
419
+ * @param string $name
420
+ * @param string $url
421
+ * @return array $icons
422
+ */
423
+ protected function parse_css( $css_file, $name, $url ) {
424
 
425
+ $css_source = @file_get_contents( $css_file );
 
 
 
 
 
 
 
 
426
 
427
+ if ( $css_source === false ) {
428
+ $response = wp_remote_get( $url );
429
+
430
+ if ( is_array( $response ) && ! is_wp_error( $response ) ) {
431
+ $css_source = $response['body'];
432
+ } else {
433
  return null;
434
  }
 
435
 
436
+ }
437
 
438
+ $icons = array();
 
 
 
439
 
440
+ preg_match_all( "/\.\w*?\-(.*?):\w*?\s*?{?\s*?{\s*?\w*?:\s*?\'\\\\?(\w*?)\'.*?}/", $css_source, $matches, PREG_SET_ORDER, 0 );
441
+ foreach ( $matches as $match ) {
442
+ $icons[ $name . '-' . $match[1] ] = $match[2];
443
+ }
444
 
445
+ return $icons;
446
+
447
+ }
448
+
449
+
450
+ /**
451
+ * Parse CSS file to get proper icon names (reverse parse)
452
+ *
453
+ * @param string $css_file
454
+ * @param string $name
455
+ * @param string $url
456
+ * @return array $icons
457
+ */
458
+ protected function parse_css_reverse( $css_file, $name, $url ) {
459
+
460
+ $css_source = @file_get_contents( $css_file );
461
+
462
+ if ( $css_source === false ) {
463
+ $response = wp_remote_get( $url );
464
+
465
+ if ( is_array( $response ) && ! is_wp_error( $response ) ) {
466
+ $css_source = $response['body'];
467
+ } else {
468
+ return null;
469
  }
470
 
471
+ }
472
+
473
+ $icons = array();
474
 
475
+ preg_match_all( "/\.\w*?\-(.*?):\w*?\s*?{?\s*?{\s*?\w*?:\s*?\'\\\\?(\w*?)\'.*?}/", $css_source, $matches, PREG_SET_ORDER, 0 );
476
+ foreach ( $matches as $match ) {
477
+ $icons[ 'eci ' . $name . '-' . $match[1] ] = $match[1];
478
  }
479
 
480
+ return $icons;
481
+
482
+ }
483
+
484
+
485
+ /**
486
+ * remove folder (recursive)
487
+ *
488
+ * @param string $dir
489
+ * @return void
490
+ */
491
+ protected function rrmdir( $dir ) {
492
+
493
+ if ( ! current_user_can( 'manage_options' ) ) return;
494
+
495
+ if ( is_dir( $dir ) ) {
496
+ $objects = scandir( $dir );
497
+ foreach ( $objects as $object ) {
498
+ if ( $object != '.' && $object != '..' ) {
499
+ if ( is_dir( $dir . '/' . $object ) ) {
500
+ $this->rrmdir( $dir . '/' . $object );
501
+ } else {
502
+ unlink( $dir . '/' . $object );
503
  }
504
  }
 
505
  }
506
+ rmdir( $dir );
507
  }
508
 
509
+ }
 
 
 
 
 
 
 
 
 
 
 
 
510
 
511
+ /**
512
+ * @param string $name
513
+ * @param bool $default
514
+ * @param string $type
515
+ *
516
+ * @return bool|string
517
+ */
518
+ protected function getRequest( $name, $default = false, $type = 'POST' ) {
519
 
520
+ $TYPE = ( strtolower( $type ) == 'post' ) ? $_POST : $_GET;
521
+ if ( ! empty( $TYPE[ $name ] ) ) {
522
+ return sanitize_text_field( $TYPE[ $name ] );
523
  }
524
 
525
+ return $default;
526
+
527
+ }
528
+
529
  }
530
 
531
  function ec_icons_manager() {
532
  return ECIcons::getInstance();
533
  }
534
 
535
+ ec_icons_manager();
includes/merge.css.php CHANGED
@@ -9,14 +9,15 @@
9
  * @since 0.1.0
10
  */
11
 
12
- if( ! defined( 'ABSPATH' ) ) {
13
- return;
14
  }
15
 
16
  class MergeCss_ECIcons extends ECIcons {
17
 
18
  public function __construct() {
19
  $this->generate_css();
 
20
  }
21
 
22
  /**
@@ -26,7 +27,6 @@ class MergeCss_ECIcons extends ECIcons {
26
 
27
  $options = get_option( 'ec_icons_fonts' );
28
 
29
-
30
  $css_content = "i.eci {
31
  display: block;
32
  font: normal normal normal 14px/1 FontAwesome;
@@ -38,11 +38,18 @@ class MergeCss_ECIcons extends ECIcons {
38
  .select2-container i.eci,
39
  .elementor-icon-list-icon i.eci {
40
  display: inline-block;
41
- }\n";
42
- if ( !empty( $options ) && is_array($options) ) {
 
 
 
 
 
 
 
43
  foreach ( $options as $key => $font ) {
44
 
45
- if ( isset( $font['status'] ) && $font['status'] !== '1' ){
46
  continue;
47
  }
48
 
@@ -50,33 +57,33 @@ class MergeCss_ECIcons extends ECIcons {
50
  continue;
51
  }
52
 
53
- $font_data = json_decode($font['data'],true);
54
 
55
- if ( isset($font_data['nameempty']) && $font_data['nameempty'] == true ){
56
  $fontfilename = 'fontello';
57
  } else {
58
  $fontfilename = strtolower( $font_data['name'] );
59
  }
60
 
61
- $randomver = mt_rand();
62
  $css_content .= "@font-face {
63
  font-family: '" . strtolower( $font_data['name'] ) . "';
64
- src: url('" . $font_data['font_url'] . "/" . $fontfilename . ".eot?" . $randomver . "');
65
- src: url('" . $font_data['font_url'] . "/" . $fontfilename . ".eot?" . $randomver . "#iefix') format('embedded-opentype'),
66
- url('" . $font_data['font_url'] . "/" . $fontfilename . ".woff2?" . $randomver . "') format('woff2'),
67
- url('" . $font_data['font_url'] . "/" . $fontfilename . ".woff?" . $randomver . "') format('woff'),
68
- url('" . $font_data['font_url'] . "/" . $fontfilename . ".ttf?" . $randomver . "') format('truetype'),
69
- url('" . $font_data['font_url'] . "/" . $fontfilename . ".svg?" . $randomver . "#" . $fontfilename . "') format('svg');
70
  font-weight: normal;
71
  font-style: normal;
72
  }\n";
73
 
74
- $icons = ec_icons_manager()->parse_css( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
75
 
76
- if (!empty($icons) && is_array($icons)){
77
 
78
  foreach ( $icons as $name_icon => $code ) {
79
- $css_content .= ".eci." . $name_icon . "::before { content: '\\" . $code . "'; font-family: '" . strtolower( $font_data['name'] ) . "'; }\n";
80
 
81
  }
82
  }
@@ -87,9 +94,53 @@ class MergeCss_ECIcons extends ECIcons {
87
  }
88
 
89
  $css_content = preg_replace( '/\t+/', '', $css_content );
90
- if ( is_dir( ec_icons_manager()->upload_dir ) ) {
91
  file_put_contents( ec_icons_manager()->upload_dir . '/merged-icons-font.css', $css_content );
 
 
 
92
  }
93
  }
94
 
95
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  * @since 0.1.0
10
  */
11
 
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ return;
14
  }
15
 
16
  class MergeCss_ECIcons extends ECIcons {
17
 
18
  public function __construct() {
19
  $this->generate_css();
20
+ $this->generate_json();
21
  }
22
 
23
  /**
27
 
28
  $options = get_option( 'ec_icons_fonts' );
29
 
 
30
  $css_content = "i.eci {
31
  display: block;
32
  font: normal normal normal 14px/1 FontAwesome;
38
  .select2-container i.eci,
39
  .elementor-icon-list-icon i.eci {
40
  display: inline-block;
41
+ }
42
+ .elementor-icons-manager__tab__item__icon.eci {
43
+ font-size: 28px;
44
+ }
45
+ .elementor-icons-manager__tab-link i.eci {
46
+ display: inline-block;
47
+ font-size: 18px;
48
+ }\n";
49
+ if ( ! empty( $options ) && is_array( $options ) ) {
50
  foreach ( $options as $key => $font ) {
51
 
52
+ if ( isset( $font['status'] ) && $font['status'] !== '1' ) {
53
  continue;
54
  }
55
 
57
  continue;
58
  }
59
 
60
+ $font_data = json_decode( $font['data'], true );
61
 
62
+ if ( isset( $font_data['nameempty'] ) && $font_data['nameempty'] == true ) {
63
  $fontfilename = 'fontello';
64
  } else {
65
  $fontfilename = strtolower( $font_data['name'] );
66
  }
67
 
68
+ $randomver = mt_rand();
69
  $css_content .= "@font-face {
70
  font-family: '" . strtolower( $font_data['name'] ) . "';
71
+ src: url('" . $font_data['font_url'] . '/' . $fontfilename . '.eot?' . $randomver . "');
72
+ src: url('" . $font_data['font_url'] . '/' . $fontfilename . '.eot?' . $randomver . "#iefix') format('embedded-opentype'),
73
+ url('" . $font_data['font_url'] . '/' . $fontfilename . '.woff2?' . $randomver . "') format('woff2'),
74
+ url('" . $font_data['font_url'] . '/' . $fontfilename . '.woff?' . $randomver . "') format('woff'),
75
+ url('" . $font_data['font_url'] . '/' . $fontfilename . '.ttf?' . $randomver . "') format('truetype'),
76
+ url('" . $font_data['font_url'] . '/' . $fontfilename . '.svg?' . $randomver . '#' . $fontfilename . "') format('svg');
77
  font-weight: normal;
78
  font-style: normal;
79
  }\n";
80
 
81
+ $icons = $this->parse_css( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
82
 
83
+ if ( ! empty( $icons ) && is_array( $icons ) ) {
84
 
85
  foreach ( $icons as $name_icon => $code ) {
86
+ $css_content .= '.eci.' . $name_icon . "::before { content: '\\" . $code . "'; font-family: '" . strtolower( $font_data['name'] ) . "'; }\n";
87
 
88
  }
89
  }
94
  }
95
 
96
  $css_content = preg_replace( '/\t+/', '', $css_content );
97
+ if ( is_dir( ec_icons_manager()->upload_dir ) ) {
98
  file_put_contents( ec_icons_manager()->upload_dir . '/merged-icons-font.css', $css_content );
99
+ update_option( 'eci_css_timestamp', time(), true );
100
+ } else {
101
+ error_log('error saving css file to: ' . ec_icons_manager()->upload_dir);
102
  }
103
  }
104
 
105
+ /**
106
+ * Generate new JSON
107
+ */
108
+ private function generate_json() {
109
+
110
+ $options = get_option( 'ec_icons_fonts' );
111
+
112
+ if ( ! empty( $options ) && is_array( $options ) ) {
113
+ foreach ( $options as $key => $font ) {
114
+
115
+ if ( isset( $font['status'] ) && $font['status'] !== '1' ) {
116
+ continue;
117
+ }
118
+
119
+ if ( empty( $font['data'] ) ) {
120
+ continue;
121
+ }
122
+
123
+ $font_data = json_decode( $font['data'], true );
124
+
125
+ $icons = $this->parse_css( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
126
+
127
+ if ( ! empty( $icons ) && is_array( $icons ) ) {
128
+
129
+ $json = [];
130
+ $json['icons'] = [];
131
+
132
+ foreach ( $icons as $name_icon => $code ) {
133
+ $json['icons'][] = $name_icon;
134
+
135
+ }
136
+ }
137
+
138
+ if ( is_dir( ec_icons_manager()->upload_dir ) ) {
139
+ file_put_contents( ec_icons_manager()->upload_dir . '/' . $font_data['name'] . '.json', json_encode( $json ) );
140
+ }
141
+ }
142
+ }
143
+
144
+ }
145
+
146
+ }
includes/save.font.php CHANGED
@@ -9,8 +9,8 @@
9
  * @since 0.1.0
10
  */
11
 
12
- if( ! defined( 'ABSPATH' ) ) {
13
- return;
14
  }
15
 
16
  class SaveFont_ECIcons extends ECIcons {
@@ -18,11 +18,12 @@ class SaveFont_ECIcons extends ECIcons {
18
 
19
  public function init() {
20
 
21
- $action = ec_icons_manager()->getRequest( 'action', 'ec_icons_save_font' );
22
 
23
  // ajax events
24
- add_action( 'wp_ajax_' . $action, array( $this, $action ) );
25
-
 
26
  }
27
 
28
 
@@ -32,9 +33,9 @@ class SaveFont_ECIcons extends ECIcons {
32
  */
33
  public function ec_icons_save_font() {
34
 
35
- if ( wp_verify_nonce( $this->getRequest( '_wpnonce' ), 'ec_icons_nonce' ) ) {
36
 
37
- if ( !class_exists('ZipArchive') ) {
38
  $result['status_save'] = 'failedopen';
39
  echo json_encode( $result );
40
  die();
@@ -64,27 +65,26 @@ class SaveFont_ECIcons extends ECIcons {
64
 
65
  $font_data = $this->get_config_font( $file_name );
66
 
67
- $icons = $this->parse_css( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
68
 
69
  if ( ! empty( $icons ) && is_array( $icons ) ) {
70
  $result['count_icons'] = count( $icons );
71
- $first_icon = ! empty( $icons ) ? key( $icons ) : '';
72
  $result['first_icon'] = $first_icon;
73
- $iconlist = '';
74
- foreach($icons as $iconkey => $iconcode){
75
  $iconlist .= '<div><i class="eci ' . $iconkey . '" style="font-size: 16px;"></i><span>' . $iconkey . '</span></div>';
76
  }
77
  $result['iconlist'] = $iconlist;
78
 
79
- $result['name'] = $font_data['name'];
80
- $result['status_save'] = $this->update_options( $font_data, '1');
81
- $result['data'] = $font_data;
82
 
83
  new MergeCss_ECIcons();
84
  } else {
85
  $result['status_save'] = 'emptyfile';
86
  }
87
-
88
  } else {
89
  $result['status_save'] = 'emptyfile';
90
  }
@@ -136,7 +136,7 @@ class SaveFont_ECIcons extends ECIcons {
136
  */
137
  public function ec_icons_delete_font() {
138
 
139
- if ( wp_verify_nonce( $this->getRequest( '_wpnonce' ), 'ec_icons_nonce' ) ) {
140
 
141
  $file_name = $this->getRequest( 'file_name', 'font' );
142
 
@@ -152,10 +152,11 @@ class SaveFont_ECIcons extends ECIcons {
152
  unset( $options[ $file_name ] );
153
 
154
  // remove file
155
- $this->rrmdir( $this->upload_dir . '/' . $data['file_name'] );
 
156
 
157
  $result = array(
158
- 'name' => $file_name,
159
  'status_save' => 'none',
160
  );
161
 
@@ -187,20 +188,22 @@ class SaveFont_ECIcons extends ECIcons {
187
 
188
  $options = get_option( 'ec_icons_fonts' );
189
 
190
- if ( !empty( $options ) && is_array($options) ) {
191
 
192
  $newoptions = array();
193
-
194
  foreach ( $options as $key => $font ) {
195
 
196
  if ( empty( $font['data'] ) ) {
197
  continue;
198
  }
199
 
200
- $font_decode = json_decode($font['data'],true);
201
 
202
  $font_data = $this->get_config_font( $font_decode['file_name'] );
203
 
 
 
204
  $newoptions[ $font_data['name'] ] = array(
205
  'status' => '1',
206
  'data' => json_encode( $font_data ),
@@ -213,7 +216,7 @@ class SaveFont_ECIcons extends ECIcons {
213
 
214
  new MergeCss_ECIcons();
215
 
216
- $result = array();
217
  $result['status_regen'] = 'regen';
218
  echo json_encode( $result );
219
 
@@ -221,4 +224,4 @@ class SaveFont_ECIcons extends ECIcons {
221
  }
222
 
223
 
224
- }
9
  * @since 0.1.0
10
  */
11
 
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ return;
14
  }
15
 
16
  class SaveFont_ECIcons extends ECIcons {
18
 
19
  public function init() {
20
 
21
+ $action = $this->getRequest( 'action' );
22
 
23
  // ajax events
24
+ if ( ! empty( $action ) && is_callable( array( $this, $action ) ) ) {
25
+ add_action( 'wp_ajax_' . $action, array( $this, $action ) );
26
+ }
27
  }
28
 
29
 
33
  */
34
  public function ec_icons_save_font() {
35
 
36
+ if ( wp_verify_nonce( $this->getRequest( '_wpnonce' ), 'ec_icons_nonce' ) && current_user_can( 'manage_options' ) ) {
37
 
38
+ if ( ! class_exists( 'ZipArchive' ) ) {
39
  $result['status_save'] = 'failedopen';
40
  echo json_encode( $result );
41
  die();
65
 
66
  $font_data = $this->get_config_font( $file_name );
67
 
68
+ $icons = $this->parse_css( $font_data['css_root'], $font_data['name'], $font_data['css_url'] );
69
 
70
  if ( ! empty( $icons ) && is_array( $icons ) ) {
71
  $result['count_icons'] = count( $icons );
72
+ $first_icon = ! empty( $icons ) ? key( $icons ) : '';
73
  $result['first_icon'] = $first_icon;
74
+ $iconlist = '';
75
+ foreach ( $icons as $iconkey => $iconcode ) {
76
  $iconlist .= '<div><i class="eci ' . $iconkey . '" style="font-size: 16px;"></i><span>' . $iconkey . '</span></div>';
77
  }
78
  $result['iconlist'] = $iconlist;
79
 
80
+ $result['name'] = $font_data['name'];
81
+ $result['status_save'] = $this->update_options( $font_data, '1' );
82
+ $result['data'] = $font_data;
83
 
84
  new MergeCss_ECIcons();
85
  } else {
86
  $result['status_save'] = 'emptyfile';
87
  }
 
88
  } else {
89
  $result['status_save'] = 'emptyfile';
90
  }
136
  */
137
  public function ec_icons_delete_font() {
138
 
139
+ if ( wp_verify_nonce( $this->getRequest( '_wpnonce' ), 'ec_icons_nonce' ) && current_user_can( 'manage_options' ) ) {
140
 
141
  $file_name = $this->getRequest( 'file_name', 'font' );
142
 
152
  unset( $options[ $file_name ] );
153
 
154
  // remove file
155
+ $this->rrmdir( ec_icons_manager()->upload_dir . '/' . $data['file_name'] );
156
+ unlink( ec_icons_manager()->upload_dir . '/' . $data['name'] . '.json' );
157
 
158
  $result = array(
159
+ 'name' => $file_name,
160
  'status_save' => 'none',
161
  );
162
 
188
 
189
  $options = get_option( 'ec_icons_fonts' );
190
 
191
+ if ( ! empty( $options ) && is_array( $options ) ) {
192
 
193
  $newoptions = array();
194
+
195
  foreach ( $options as $key => $font ) {
196
 
197
  if ( empty( $font['data'] ) ) {
198
  continue;
199
  }
200
 
201
+ $font_decode = json_decode( $font['data'], true );
202
 
203
  $font_data = $this->get_config_font( $font_decode['file_name'] );
204
 
205
+ if ( ! $font_data ) continue;
206
+
207
  $newoptions[ $font_data['name'] ] = array(
208
  'status' => '1',
209
  'data' => json_encode( $font_data ),
216
 
217
  new MergeCss_ECIcons();
218
 
219
+ $result = array();
220
  $result['status_regen'] = 'regen';
221
  echo json_encode( $result );
222
 
224
  }
225
 
226
 
227
+ }
uninstall.php CHANGED
@@ -38,6 +38,9 @@ if ( !empty( $options ) && is_array($options) ) {
38
  $font_decode = json_decode($font['data'],true);
39
 
40
  ecicons_rrmdir( $upload_dir . '/' . $font_decode['file_name'] );
 
 
 
41
 
42
  }
43
 
38
  $font_decode = json_decode($font['data'],true);
39
 
40
  ecicons_rrmdir( $upload_dir . '/' . $font_decode['file_name'] );
41
+ if ( file_exists( $upload_dir . '/' . $font_decode['name'] . '.json' ) ) {
42
+ unlink( $upload_dir . '/' . $font_decode['name'] . '.json' );
43
+ }
44
 
45
  }
46