1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
|
<?php /* * Add-on Name: Icon Manager * Add-on URI: https://www.brainstormforce.com */ if ( ! class_exists( 'AIO_Icon_Manager' ) ) { class AIO_Icon_Manager { var $paths = array(); var $svg_file; var $json_file; var $vc_fonts; var $vc_fonts_dir; var $font_name = 'unknown'; var $unicode = ''; var $svg_config = array(); var $json_config = array(); static $charlist = array(); static $charlist_fallback = array(); static $iconlist = array(); var $assets_js; var $assets_css; var $admin_js; var $admin_css;
function __construct() { $this->assets_js = UAVC_URL.'assets/js/'; $this->assets_css = UAVC_URL.'assets/css/'; $this->admin_js = UAVC_URL.'admin/js/'; $this->admin_css = UAVC_URL.'admin/css/'; $this->paths = wp_upload_dir(); $this->paths['fonts'] = 'smile_fonts'; $this->paths['temp'] = trailingslashit( $this->paths['fonts'] ) . 'smile_temp'; $this->paths['fontdir'] = trailingslashit( $this->paths['basedir'] ) . $this->paths['fonts']; $this->paths['tempdir'] = trailingslashit( $this->paths['basedir'] ) . $this->paths['temp']; $this->paths['fonturl'] = set_url_scheme( trailingslashit( $this->paths['baseurl'] ) . $this->paths['fonts'] ); $this->paths['tempurl'] = trailingslashit( $this->paths['baseurl'] ) . trailingslashit( $this->paths['temp'] ); $this->paths['config'] = 'charmap.php'; $this->vc_fonts = trailingslashit( $this->paths['basedir'] ) . $this->paths['fonts'] . '/Defaults'; $this->vc_fonts_dir = plugin_dir_path( __FILE__ ) . '../assets/fonts/'; //font file extract by ajax function add_action( 'wp_ajax_smile_ajax_add_zipped_font', array( $this, 'add_zipped_font' ) ); add_action( 'wp_ajax_smile_ajax_remove_zipped_font', array( $this, 'remove_zipped_font' ) );
if ( isset( $_GET['delete-bsf-fonts'] ) ) { $this->delete_all_fonts(); }
//add_action('admin_menu',array($this,'icon_manager_menu')); $defaults = get_option( 'smile_fonts' ); if ( ! $defaults ) { add_action( 'admin_init', array( $this, 'AIO_move_fonts' ) ); } else if ( ( isset($defaults['Defaults'] ) && $defaults['Defaults'] == 'Array' ) ) { delete_option( 'smile_fonts' ); add_action( 'admin_init', array( $this, 'AIO_move_fonts' ) ); } }
// Icon font manager public function get_icon_manager( $input_name, $icon ) { $font_manager = self::get_font_manager( $id ); $output = '<div class="my_param_block">'; $output .= '<input name="' . esc_attr( $input_name ) . '" class="textinput ' . esc_attr($input_name) . ' text_field" type="text" value="' . esc_attr($icon) . '"/>'; $output .= '</div>'; $output .= '<script type="text/javascript"> jQuery(document).ready(function(){
//debugger; //alert("' . esc_attr($id) . '"); jQuery(".preview-icon-' . esc_attr($id) . '").html("<i class=\'' . esc_attr($icon) . '\'></i>"); jQuery(".icons-list-' . esc_attr($id) . ' li[data-icons=\'' . esc_attr($icon) . '\']").addClass("selected"); }); jQuery(".icons-list-' . esc_attr($id) . ' li").click(function() { jQuery(this).attr("class","selected").siblings().removeAttr("class"); var icon = jQuery(this).attr("data-icons"); jQuery("input[name=\'' . esc_attr($input_name) . '\']").val(icon); jQuery(".preview-icon-' . esc_attr($id) . '").html("<i class=\'"+icon+"\'></i>"); }); </script>'; $output .= $font_manager;
return $output; }
function icon_manager_menu() { $page = add_submenu_page( "bsf-dashboard", __( "Icon Manager", "ultimate_vc" ), __( "Icon Manager", "ultimate_vc" ), "administrator", "font-icon-Manager", array( $this, 'icon_manager_dashboard' ) ); add_action( 'admin_print_scripts-' . $page, array( $this, 'admin_scripts' ) ); }
function admin_scripts() { // enqueue js files on backend wp_enqueue_script( 'aio-admin-media', $this->admin_js . 'admin-media.js', array( 'jquery' ) ); wp_enqueue_script( 'media-upload' ); wp_enqueue_media(); wp_enqueue_style( 'aio-icon-manager-admin', $this->admin_css . 'icon-manager-admin.css' );
$fonts = get_option( 'smile_fonts' ); if ( is_array( $fonts ) ) { foreach ( $fonts as $font => $info ) { if ( strpos( $info['style'], 'http://' ) !== false ) { wp_enqueue_style( 'bsf-' . $font, $info['style'] ); } else { wp_enqueue_style( 'bsf-' . $font, trailingslashit( $this->paths['fonturl'] ) . $info['style'] ); } } } }// end AIO_admin_scripts
function icon_manager_dashboard() { ?> <div class="wrap"> <h2> <?php _e( 'Icon Fonts Manager', 'ultimate_vc' ); ?> <a href="#smile_upload_icon" class="add-new-h2 smile_upload_icon" data-target="iconfont_upload" data-title="<?php echo __( "Upload/Select Fontello Font Zip", "ultimate_vc" ) ?>" data-type="application/zip" data-button="<?php echo __( "Insert Fonts Zip File", "ultimate_vc" ); ?>" data-trigger="smile_insert_zip" data-class="media-frame "> <?php _e( 'Upload New Icons', 'ultimate_vc' ); ?> </a> <span class="spinner"></span></h2> <div id="msg"></div> <?php $fonts = get_option( 'smile_fonts' ); if ( is_array( $fonts ) ) : ?> <div class="metabox-holder meta-search"> <div class="postbox"> <h3> <input class="search-icon" type="text" placeholder="Search"/> <span class="search-count"></span></h3> </div> </div> <?php self::get_font_set(); ?> </div> <?php else: ?> <div class="error"> <p> <?php _e( 'No font icons uploaded. Upload some font icons to display here.', 'ultimate_vc' ); ?> </p> </div> <?php endif; }
public function get_font_manager( $id ) {
$fonts = get_option( 'smile_fonts' ); $fonts = get_option( 'smile_fonts' ); $output = '<p><div class="preview-icon preview-icon-' . esc_attr($id) . '"><i class=""></i></div><input class="search-icon" type="text" placeholder="Search for a suitable icon.." /></p>'; $output .= '<div id="smile_icon_search">'; $output .= '<ul class="icons-list smile_icon icon-list-' . esc_attr($id) . '">'; foreach ( $fonts as $font => $info ) { $icon_set = array(); $icons = array(); $upload_dir = wp_upload_dir(); $path = trailingslashit( $upload_dir['basedir'] ); $file = $path . $info['include'] . '/' . $info['config']; include( $file ); if ( ! empty( $icons ) ) { $icon_set = array_merge( $icon_set, $icons ); } if ( $font == "smt" ) { $set_name = 'Default Icons'; } else { $set_name = ucfirst( $font ); } if ( ! empty( $icon_set ) ) { $output .= '<p><strong>' . esc_html($set_name) . '</strong></p>'; $output .= '<li title="no-icon" data-icons="none" data-icons-tag="none,blank" style="cursor: pointer;" id="' . esc_attr($id) . '"></li>'; foreach ( $icon_set as $icons ) { foreach ( $icons as $icon ) { $output .= '<li title="' . esc_attr($icon['class']) . '" data-icons="' . esc_attr($font) . '-' . esc_attr($icon['class']) . '" data-icons-tag="' . esc_attr($icon['tags']) . '" id="' . esc_attr($id) . '">'; $output .= '<i class="icon ' . esc_attr($font) . '-' . esc_attr($icon['class']) . '"></i><label class="icon">' . esc_html($icon['class']) . '</label></li>'; } } } } $output . '</ul>'; $output .= '<script type="text/javascript"> jQuery(document).ready(function(){ jQuery(".search-icon").keyup(function(){ // Retrieve the input field text and reset the count to zero var filter = jQuery(this).val(), count = 0; // Loop through the icon list jQuery(".icons-list li").each(function(){ // If the list item does not contain the text phrase fade it out if (jQuery(this).attr("data-icons-tag").search(new RegExp(filter, "i")) < 0) { jQuery(this).fadeOut(); } else { jQuery(this).show(); count++; } }); }); }); </script>'; $output .= '</div>';
return $output; }
// Generate Icon Set Preview and settings page static function get_font_set() { $fonts = get_option( 'smile_fonts' ); $n = count( $fonts ); foreach ( $fonts as $font => $info ) { $icon_set = array(); $icons = array(); $upload_dir = wp_upload_dir(); $path = trailingslashit( $upload_dir['basedir'] ); $file = $path . $info['include'] . '/' . $info['config']; $output = '<div class="icon_set-' . esc_attr($font) . ' metabox-holder">'; $output .= '<div class="postbox">'; include( $file ); if ( ! empty( $icons ) ) { $icon_set = array_merge( $icon_set, $icons ); } if ( ! empty( $icon_set ) ) { foreach ( $icon_set as $icons ) { $count = count( $icons ); } if ( $font == 'smt' || $font == 'Defaults' ) { $output .= '<h3 class="icon_font_name"><strong>' . __( "Default Icons", "smile" ) . '</strong>'; } else { $output .= '<h3 class="icon_font_name"><strong>' . esc_html(ucfirst( $font )) . '</strong>'; } $output .= '<span class="fonts-count count-' . esc_attr($font) . '">' . $count . '</span>'; if ( $n != 1 ) { $output .= '<button class="button button-secondary button-small smile_del_icon" data-delete=' . esc_attr($font) . ' data-title="Delete This Icon Set">Delete Icon Set</button>'; } $output .= '</h3>'; $output .= '<div class="inside"><div class="icon_actions">'; $output .= '</div>'; $output .= '<div class="icon_search"><ul class="icons-list fi_icon">'; foreach ( $icon_set as $icons ) { foreach ( $icons as $icon ) { $output .= '<li title="' . esc_attr($icon['class']) . '" data-icons="' . esc_attr($icon['class']) . '" data-icons-tag="' . esc_attr($icon['tags']) . '">'; $output .= '<i class="' . esc_attr($font) . '-' . esc_attr($icon['class']) . '"></i><label class="icon">' . esc_html($icon['class']) . '</label></li>'; } } $output . '</ul>'; $output .= '</div><!-- .icon_search-->'; $output .= '</div><!-- .inside-->'; $output .= '</div><!-- .postbox-->'; $output .= '</div><!-- .icon_set-' . esc_html($font) . ' -->'; echo $output; } } $script = '<script type="text/javascript"> jQuery(document).ready(function(){ jQuery(".search-icon").keyup(function(){ jQuery(".fonts-count").hide(); // Retrieve the input field text and reset the count to zero var filter = jQuery(this).val(), count = 0; // Loop through the icon list jQuery(".icons-list li").each(function(){ // If the list item does not contain the text phrase fade it out if (jQuery(this).attr("data-icons-tag").search(new RegExp(filter, "i")) < 0) { jQuery(this).fadeOut(); } else { jQuery(this).show(); count++; } if(count == 0) jQuery(".search-count").html(" Can\'t find the icon? <a href=\'#smile_upload_icon\' class=\'add-new-h2 smile_upload_icon\' data-target=\'iconfont_upload\' data-title=\'Upload/Select Fontello Font Zip\' data-type=\'application/octet-stream, application/zip\' data-button=\'Insert Fonts Zip File\' data-trigger=\'smile_insert_zip\' data-class=\'media-frame\'>Click here to upload</a>"); else jQuery(".search-count").html(count+" Icons found."); if(filter == "") jQuery(".fonts-count").show(); }); }); }); </script>'; echo $script; }
public function add_zipped_font() { //check if referer is ok check_ajax_referer( 'smile-add-zipped-fonts-nonce', 'security' ); //check if capability is ok $cap = apply_filters( 'avf_file_upload_capability', 'update_plugins' ); if ( ! current_user_can( $cap ) ) { die( __( "Using this feature is reserved for Super Admins. You unfortunately don't have the necessary permissions.", "ultimate_vc" ) ); } //get the file path of the zip file $attachment = $_POST['values']; $path = realpath( get_attached_file( $attachment['id'] ) ); $unzipped = $this->zip_flatten( $path, array( '\.eot', '\.svg', '\.ttf', '\.woff', '\.json', '\.css' ) ); // if we were able to unzip the file and save it to our temp folder extract the svg file if ( $unzipped ) { $this->create_config(); } //if we got no name for the font dont add it and delete the temp folder if ( $this->font_name == 'unknown' ) { $this->delete_folder( $this->paths['tempdir'] ); die( __( 'Was not able to retrieve the Font name from your Uploaded Folder', 'ultimate_vc' ) ); } die( __( 'smile_font_added:', 'ultimate_vc' ) . $this->font_name ); }
public function remove_zipped_font() {
check_ajax_referer( 'smile-remove-zipped-fonts-nonce', 'security' );
//get the file path of the zip file $font = sanitize_text_field( $_POST['del_font'] ); $list = self::load_iconfont_list(); $delete = isset( $list[ $font ] ) ? $list[ $font ] : false; if ( $delete ) { $this->delete_folder( $delete['include'] ); $this->remove_font( $font ); die( __( 'smile_font_removed', 'ultimate_vc' ) ); } die( __( 'Was not able to remove Font', 'ultimate_vc' ) ); }
//extract the zip file to a flat folder and remove the files that are not needed function zip_flatten( $zipfile, $filter ) { @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); if ( is_dir( $this->paths['tempdir'] ) ) { $this->delete_folder( $this->paths['tempdir'] ); $tempdir = smile_backend_create_folder( $this->paths['tempdir'], false ); } else { $tempdir = smile_backend_create_folder( $this->paths['tempdir'], false ); } //$fontdir = smile_backend_create_folder($this->paths['fontdir'], false); if ( ! $tempdir ) { die( __( 'Wasn\'t able to create temp folder', 'ultimate_vc' ) ); }
if ( class_exists( 'ZipArchive' ) ) { $zip = new ZipArchive; if ( $zip->open( $zipfile ) ) { for ( $i = 0; $i < $zip->numFiles; $i ++ ) { $entry = $zip->getNameIndex( $i ); if ( ! empty( $filter ) ) { $delete = true; $matches = array(); foreach ( $filter as $regex ) { preg_match( "!" . $regex . "$!", $entry, $matches ); if ( ! empty( $matches ) ) { $delete = false; break; } } } if ( substr( $entry, - 1 ) == '/' || ! empty( $delete ) ) { continue; } // skip directories and non matching files $fp = $zip->getStream( $entry ); $ofp = fopen( $this->paths['tempdir'] . '/' . basename( $entry ), 'w' ); if ( ! $fp ) { die( __( 'Unable to extract the file.', 'ultimate_vc' ) ); } while ( ! feof( $fp ) ) { fwrite( $ofp, fread( $fp, 8192 ) ); } fclose( $fp ); fclose( $ofp ); } $zip->close(); } } else { die( __( "Wasn't able to work with Zip Archive", 'ultimate_vc' ) ); }
return true; }
//iterate over xml file and extract the glyphs for the font function create_config() { $this->json_file = $this->find_json(); $this->svg_file = $this->find_svg(); if ( empty( $this->json_file ) || empty( $this->svg_file ) ) { $this->delete_folder( $this->paths['tempdir'] ); die( __( 'selection.json or SVG file not found. Was not able to create the necessary config files', 'ultimate_vc' ) ); } $json = ''; $response = '';
global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once( ABSPATH . '/wp-admin/includes/file.php' ); WP_Filesystem(); }
if ( file_exists( trailingslashit( $this->paths['tempdir'] ) . $this->svg_file ) ) { $response = $wp_filesystem->get_contents( trailingslashit( $this->paths['tempdir'] ) . $this->svg_file ); }
if ( file_exists( trailingslashit( $this->paths['tempdir'] ) . $this->svg_file ) ) { $json = $wp_filesystem->get_contents( trailingslashit( $this->paths['tempdir'] ) . $this->json_file ); }
if ( '' !== $json && '' !== $response ) { $xml = simplexml_load_string( $response ); $font_attr = $xml->defs->font->attributes(); $glyphs = $xml->defs->font->children(); $this->font_name = (string) $font_attr['id']; $unicodes = array(); foreach ( $glyphs as $item => $glyph ) { if ( $item == 'glyph' ) { $attributes = $glyph->attributes(); $unicode = (string) $attributes['unicode']; array_push( $unicodes, $unicode ); } } $font_folder = trailingslashit( $this->paths['fontdir'] ) . $this->font_name; if ( is_dir( $font_folder ) ) { $this->delete_folder( $this->paths['tempdir'] ); die( __( "It seems that the font with the same name is already exists! Please upload the font with different name.", "ultimate_vc" ) ); } $file_contents = json_decode( $json ); if ( ! isset( $file_contents->IcoMoonType ) ) { $this->delete_folder( $this->paths['tempdir'] ); die( __( 'Uploaded font is not from IcoMoon. Please upload fonts created with the IcoMoon App Only.', 'ultimate_vc' ) ); } $icons = $file_contents->icons; unset( $unicodes[0] ); $n = 1; foreach ( $icons as $icon ) { $icon_name = $icon->properties->name; $icon_class = str_replace( ' ', '', $icon_name ); $icon_class = str_replace( ',', ' ', $icon_class ); $tags = implode( ",", $icon->icon->tags ); $this->json_config[ $this->font_name ][ $icon_name ] = array( "class" => $icon_class, "tags" => $tags, "unicode" => $unicodes[ $n ] ); $n ++; } if ( ! empty( $this->json_config ) && $this->font_name != 'unknown' ) { $this->write_config(); $this->re_write_css(); $this->rename_files(); $this->rename_folder(); $this->add_font(); } }
return false; }
//writes the php config file for the font function write_config() { $charmap = $this->paths['tempdir'] . '/' . $this->paths['config']; $handle = @fopen( $charmap, 'w' ); if ( $handle ) { fwrite( $handle, '<?php $icons = array();' ); foreach ( $this->json_config[ $this->font_name ] as $icon => $info ) { if ( ! empty( $info ) ) { $delimiter = "'"; fwrite( $handle, "\r\n" . '$icons[\'' . $this->font_name . '\'][' . $delimiter . $icon . $delimiter . '] = array("class"=>' . $delimiter . $info["class"] . $delimiter . ',"tags"=>' . $delimiter . $info["tags"] . $delimiter . ',"unicode"=>' . $delimiter . $info["unicode"] . $delimiter . ');' ); } else { $this->delete_folder( $this->paths['tempdir'] ); die( __( 'Was not able to write a config file', 'ultimate_vc' ) ); } } fclose( $handle ); } else { $this->delete_folder( $this->paths['tempdir'] ); die( __( 'Was not able to write a config file', 'ultimate_vc' ) ); } }
//re-writes the php config file for the font function re_write_css() { $style = $this->paths['tempdir'] . '/style.css'; $file = @file_get_contents( $style ); if ( $file ) { $str = str_replace( 'fonts/', '', $file ); $str = str_replace( 'icon-', $this->font_name . '-', $str ); $str = str_replace( '.icon {', '[class^="' . $this->font_name . '-"], [class*=" ' . $this->font_name . '-"] {', $str ); $str = str_replace( 'i {', '[class^="' . $this->font_name . '-"], [class*=" ' . $this->font_name . '-"] {', $str );
/* remove comments */ $str = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $str );
/* remove tabs, spaces, newlines, etc. */ $str = str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $str );
@file_put_contents( $style, $str ); } else { die( __( 'Unable to write css. Upload icons downloaded only from icomoon', 'ultimate_vc' ) ); } }
function rename_files() { $extensions = array( 'eot', 'svg', 'ttf', 'woff', 'css' ); $folder = trailingslashit( $this->paths['tempdir'] ); foreach ( glob( $folder . '*' ) as $file ) { $path_parts = pathinfo( $file ); if ( strpos( $path_parts['filename'], '.dev' ) === false && in_array( $path_parts['extension'], $extensions ) ) { if ( $path_parts['filename'] !== $this->font_name ) { rename( $file, trailingslashit( $path_parts['dirname'] ) . $this->font_name . '.' . $path_parts['extension'] ); } } } }
//rename the temp folder and all its font files function rename_folder() { $new_name = trailingslashit( $this->paths['fontdir'] ) . $this->font_name; //delete folder and contents if they already exist $this->delete_folder( $new_name ); if ( rename( $this->paths['tempdir'], $new_name ) ) { return true; } else { $this->delete_folder( $this->paths['tempdir'] ); die( __( "Unable to add this font. Please try again.", "ultimate_vc" ) ); } }
//delete a folder function delete_folder( $new_name ) { //delete folder and contents if they already exist if ( is_dir( $new_name ) ) { $objects = scandir( $new_name ); foreach ( $objects as $object ) { if ( $object != "." && $object != ".." ) { unlink( $new_name . "/" . $object ); } } reset( $objects ); rmdir( $new_name ); } else { echo $new_name . ' no found<br/>'; } }
// delete_all_fonts function delete_all_fonts() { $new_name = $this->paths['fontdir']; $objects = scandir( $new_name ); foreach ( $objects as $object ) { if ( $object != "." && $object != ".." ) { $this->delete_folder( $new_name . '/' . $object ); } } delete_option( 'smile_fonts' ); wp_redirect( admin_url( 'admin.php?page=bsf-font-icon-manager' ) ); exit; }
function add_font() { $fonts = get_option( 'smile_fonts' ); if ( empty( $fonts ) ) { $fonts = array(); } $fonts[ $this->font_name ] = array( 'include' => trailingslashit( $this->paths['fonts'] ) . $this->font_name, 'folder' => trailingslashit( $this->paths['fonts'] ) . $this->font_name, 'style' => $this->font_name . '/' . $this->font_name . '.css', 'config' => $this->paths['config'] ); update_option( 'smile_fonts', $fonts ); }
function remove_font( $font ) { $fonts = get_option( 'smile_fonts' ); if ( isset( $fonts[ $font ] ) ) { unset( $fonts[ $font ] ); update_option( 'smile_fonts', $fonts ); } }
//finds the json file we need to create the config function find_json() { $files = scandir( $this->paths['tempdir'] ); foreach ( $files as $file ) { if ( strpos( strtolower( $file ), '.json' ) !== false && $file[0] != '.' ) { return $file; } } }
//finds the svg file we need to create the config function find_svg() { $files = scandir( $this->paths['tempdir'] ); foreach ( $files as $file ) { if ( strpos( strtolower( $file ), '.svg' ) !== false && $file[0] != '.' ) { return $file; } } }
static function load_iconfont_list() { if ( ! empty( self::$iconlist ) ) { return self::$iconlist; } $extra_fonts = get_option( 'smile_fonts' ); if ( empty( $extra_fonts ) ) { $extra_fonts = array(); } $font_configs = $extra_fonts;//array_merge(SmileBuilder::$default_iconfont, $extra_fonts); //if we got any include the charmaps and add the chars to an array $upload_dir = wp_upload_dir(); $path = trailingslashit( $upload_dir['basedir'] ); $url = trailingslashit( $upload_dir['baseurl'] ); foreach ( $font_configs as $key => $config ) { if ( empty( $config['full_path'] ) ) { $font_configs[ $key ]['include'] = $path . $font_configs[ $key ]['include']; $font_configs[ $key ]['folder'] = $url . $font_configs[ $key ]['folder']; } } //cache the result self::$iconlist = $font_configs;
return $font_configs; }
function AIO_move_fonts() { // Make destination directory if ( ! is_dir( $this->vc_fonts ) ) { wp_mkdir_p( $this->vc_fonts ); } @chmod( $this->vc_fonts, 0777 ); foreach ( glob( $this->vc_fonts_dir . '*' ) as $file ) { $new_file = basename( $file ); @copy( $file, $this->vc_fonts . '/' . $new_file ); } $fonts['Defaults'] = array( 'include' => sanitize_text_field( trailingslashit( $this->paths['fonts'] ) ) . 'Defaults', 'folder' => sanitize_text_field( trailingslashit( $this->paths['fonts'] ) ) . 'Defaults', 'style' => 'Defaults' . '/' . 'Defaults' . '.css', 'config' => sanitize_text_field( $this->paths['config'] ) ); $defaults = get_option( 'smile_fonts' ); if ( ! $defaults ) { update_option( 'smile_fonts', $fonts ); } }// end AIO_move_fonts }// End class /* * creates a folder for the theme framework */ if ( ! function_exists( 'smile_backend_create_folder' ) ) { function smile_backend_create_folder( &$folder, $addindex = true ) { if ( is_dir( $folder ) && $addindex == false ) { return true; } $created = wp_mkdir_p( trailingslashit( $folder ) ); @chmod( $folder, 0777 ); if ( $addindex == false ) { return $created; } $index_file = trailingslashit( $folder ) . 'index.php'; if ( file_exists( $index_file ) ) { return $created; } $handle = @fopen( $index_file, 'w' ); if ( $handle ) { fwrite( $handle, "<?php\r\necho 'Sorry, browsing the directory is not allowed!';\r\n?> " ); fclose( $handle ); }
return $created; } } // Instantiate the Icon Manager } $AIO_Icon_Manager = new AIO_Icon_Manager;
add_action( 'wp_ajax_smile_ajax_add_zipped_font', array( $AIO_Icon_Manager, 'add_zipped_font' ) ); add_action( 'wp_ajax_smile_ajax_remove_zipped_font', array( $AIO_Icon_Manager, 'remove_zipped_font' ) );
|