PluginProbe
Borderless – Addons and Templates for Elementor / 1.2.3
Borderless – Addons and Templates for Elementor v1.2.3
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 78 releases
borderless / includes / icon-manager / icon-manager.php

icon-manager.php in Borderless – Addons and Templates for Elementor 1.2.3, at includes/icon-manager/icon-manager.php

593 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( '-1' );
4 }
5
6 if ( ! class_exists( 'Borderless_IF' ) ) {
7 class Borderless_IF {
8 var $paths = array();
9 var $svg_file;
10 var $json_file;
11 var $ip_name = 'unknown';
12 var $svg_config = array();
13 var $json_config = array();
14 static $ip_list = array();
15
16 function __construct() {
17 $this->paths = wp_upload_dir();
18 $this->paths['fonts'] = 'borderless_icon_fonts';
19 $this->paths['temp'] = trailingslashit( $this->paths['fonts'] ) . 'borderless_temp';
20 $this->paths['fontdir'] = trailingslashit( $this->paths['basedir'] ) . $this->paths['fonts'];
21 $this->paths['tempdir'] = trailingslashit( $this->paths['basedir'] ) . $this->paths['temp'];
22 $this->paths['fonturl'] = set_url_scheme( trailingslashit( $this->paths['baseurl'] ) . $this->paths['fonts'] );
23 $this->paths['tempurl'] = trailingslashit( $this->paths['baseurl'] ) . trailingslashit( $this->paths['temp'] );
24 $this->paths['config'] = 'charmap.php';
25 add_action( 'wp_ajax_borderless_ajax_add_zipped_font', array( $this, 'add_zipped_font' ) );
26 add_action( 'wp_ajax_borderless_ajax_remove_zipped_font', array( $this, 'remove_zipped_font' ) );
27
28 }
29
30 function admin_scripts() {
31 $upload_paths = wp_upload_dir();
32 wp_enqueue_script( 'borderless-admin-media', plugin_dir_url( __FILE__ ) . 'assets/js/icon-manager.min.js', array( 'jquery' ) );
33 wp_enqueue_script( 'media-upload' );
34 wp_enqueue_media();
35 wp_enqueue_style( 'borderless-wpbakery-icon-manager-admin', plugin_dir_url( __FILE__ ) . 'assets/css/icon-manager.css' );
36 $custom_fonts = get_option( 'borderless_icon_fonts' );
37 if ( is_array( $custom_fonts ) ) {
38 foreach ( $custom_fonts as $font => $info ) {
39 if ( strpos( $info['style'], 'http://' ) !== false ) {
40 wp_enqueue_style( 'borderless-' . $font, $info['style'], null, '1.0', 'all' );
41 } else {
42 wp_enqueue_style( 'borderless-' . $font, trailingslashit( $upload_paths['baseurl'] . '/borderless_icon_fonts/' ) . $info['style'], null, '1.0', 'all' );
43 }
44 }
45 }
46 }
47
48 /*-----------------------------------------------------------------------------------*/
49 /* *. Icon Pack Manager On Page Edit
50 /*-----------------------------------------------------------------------------------*/
51
52 public function get_icon_manager( $input_name, $icon ) {
53 $font_manager = self::get_font_manager( $id );
54 $output = '<div class="my_param_block">';
55 $output .= '<input name="' . $input_name . '" class="textinput ' . $input_name . ' text_field" type="text" value="' . $icon . '"/>';
56 $output .= '</div>';
57 $output .= '<script type="text/javascript">
58 jQuery(document).ready(function(){
59
60 //debugger;
61 //alert("' . $id . '");
62 jQuery(".icon-manager-preview-icon-' . $id . '").html("<i class=\'' . $icon . '\'></i>");
63 jQuery(".icons-list-' . $id . ' li[data-icons=\'' . $icon . '\']").addClass("selected");
64 });
65 jQuery(".icons-list-' . $id . ' li").click(function() {
66 jQuery(this).attr("class","selected").siblings().removeAttr("class");
67 var icon = jQuery(this).attr("data-icons");
68 jQuery("input[name=\'' . $input_name . '\']").val(icon);
69 jQuery(".icon-manager-preview-icon-' . $id . '").html("<i class=\'"+icon+"\'></i>");
70 });
71 </script>';
72 $output .= $font_manager;
73
74 return $output;
75 }
76
77 public function get_font_manager( $id ) {
78
79 $fonts = get_option( 'borderless_icon_fonts' );
80 $output = '<div class="icon-manager-preview"><div class="icon-manager-preview-icon preview-icon-' . $id . '"><i class=""></i></div><input class="icon-manager-search-icon" type="text" placeholder="Search for a suitable icon.." /></div>';
81 $output .= '<div id="icon-manager-search-icon-inner">';
82 $output .= '<ul class="icons-list borderless_icon icon-list-' . $id . '">';
83 foreach ( $fonts as $font => $info ) {
84 $icon_set = array();
85 $icons = array();
86 $upload_dir = wp_upload_dir();
87 $path = trailingslashit( $upload_dir['basedir'] );
88 $file = $path . $info['include'] . '/' . $info['config'];
89 include( $file );
90 if ( ! empty( $icons ) ) {
91 $icon_set = array_merge( $icon_set, $icons );
92 }
93
94 $set_name = ucfirst( $font );
95
96 if ( ! empty( $icon_set ) ) {
97 $output .= '<p><strong>' . $set_name . '</strong></p>';
98 $output .= '<li title="no-icon" data-icons="none" data-icons-tag="none,blank" style="cursor: pointer;" id="' . $id . '"></li>';
99 foreach ( $icon_set as $icons ) {
100 foreach ( $icons as $icon ) {
101 $output .= '<li title="' . $icon['class'] . '" data-icons="' . $font . '-' . $icon['class'] . '" data-icons-tag="' . $icon['tags'] . '" id="' . $id . '">';
102 $output .= '<i class="icon-manager-icon ' . $font . '-' . $icon['class'] . '"></i><label class="icon">' . $icon['class'] . '</label></li>';
103 }
104 }
105 }
106 }
107 $output . '</ul>';
108 $output .= '<script type="text/javascript">
109 jQuery(document).ready(function(){
110 jQuery(".icon-manager-search-icon").keyup(function(){
111 // Retrieve the input field text and reset the count to zero
112 var filter = jQuery(this).val(), count = 0;
113 // Loop through the icon list
114 jQuery(".icons-list li").each(function(){
115 // If the list item does not contain the text phrase fade it out
116 if (jQuery(this).attr("data-icons-tag").search(new RegExp(filter, "i")) < 0) {
117 jQuery(this).fadeOut();
118 } else {
119 jQuery(this).show();
120 count++;
121 }
122 });
123 });
124 });
125 </script>';
126 $output .= '</div>';
127
128 return $output;
129 }
130
131 /*-----------------------------------------------------------------------------------*/
132 /* *. Icon Pack Manager
133 /*-----------------------------------------------------------------------------------*/
134
135 function icon_pack_manager() {
136 ?>
137 <div class="wrap">
138 <h2>
139 <?php esc_html_e( 'Icon Pack Manager', 'borderless' ); ?>
140 <a href="#borderless_upload_icon" class="button button-primary borderless-upload-icon" data-target="iconfont_upload"
141 data-title="<?php echo esc_html__( "Upload/Select Fontello Font Zip", "borderless" ) ?>"
142 data-type="application/octet-stream, application/zip"
143 data-button="<?php echo esc_html__( "Insert Fonts Zip File", "borderless" ); ?>" data-trigger="borderless_insert_zip"
144 data-class="media-frame ">
145 <?php esc_html_e( 'Add New Icon Pack', 'borderless' ); ?>
146 </a> &nbsp;<span class="spinner"></span></h2>
147 <div id="msg"></div>
148 <?php
149 $fonts = get_option( 'borderless_icon_fonts' );
150 if ( is_array( $fonts ) ) :
151 ?>
152 <div class="metabox-holder meta-search">
153 <div class="postbox borderless-postbox-search">
154 <h2 class="hndle ui-sortable-handle"><span>Search for Icons</h2>
155 <div class="inside">
156 <div class="search-area">
157 <input class="search-icon" type="text" placeholder="<?php esc_attr_e( 'Start typing to search', 'borderless' ); ?>"/>
158 <span class="search-count"></span>
159 </div>
160 </div>
161 </div>
162 </div>
163 <?php self::get_ipm(); ?>
164 </div>
165 <?php else: ?>
166 <div class="error">
167 <p>
168 <?php esc_html_e( 'No icon pack uploaded. Upload some icon pack to display here.', 'borderless' ); ?>
169 </p>
170 </div>
171 <?php
172 endif;
173 }
174
175 // Generate Icon Pack Preview and settings page
176 static function get_ipm() {
177 $fonts = get_option( 'borderless_icon_fonts' );
178 $n = count( $fonts );
179 foreach ( $fonts as $font => $info ) {
180 $icon_set = array();
181 $icons = array();
182 $upload_dir = wp_upload_dir();
183 $path = trailingslashit( $upload_dir['basedir'] );
184 $file = $path . $info['include'] . '/' . $info['config'];
185 $output = '<div class="icon_set-' . $font . ' metabox-holder">';
186 $output .= '<div class="postbox borderless-postbox-icon-manager">';
187 include( $file );
188 if ( ! empty( $icons ) ) {
189 $icon_set = array_merge( $icon_set, $icons );
190 }
191 if ( ! empty( $icon_set ) ) {
192 foreach ( $icon_set as $icons ) {
193 $count = count( $icons );
194 }
195
196 $output .= '<h3 class="ip_name"><strong>' . esc_html( ucfirst( $font ) ) . '</strong>';
197
198 $output .= '<span class="fonts-count wp-core-ui wp-ui-notification count-' . esc_attr( $font ) . '">' . esc_html( $count ) . '</span>';
199 if ( $n != 1 ) {
200 $output .= '<button class="button button-primary button-small borderless_del_icon" data-delete=' . esc_attr( $font ) . ' data-title="' . esc_attr__( 'Remove Pack', 'borderless' ) . '">' . esc_html__( 'Remove Pack', 'borderless' ) . '</button>';
201 }
202 $output .= '</h3>';
203 $output .= '<div class="inside"><div class="icon_actions">';
204 $output .= '</div>';
205 $output .= '<div class="icon_search"><ul class="icons-list borderless_icon">';
206 foreach ( $icon_set as $icons ) {
207 foreach ( $icons as $icon ) {
208 $output .= '<li " data-icons="' . esc_attr( $icon['class'] ) . '" data-icons-tag="' . esc_attr( $icon['tags'] ) . '">';
209 $output .= '<i class="' . esc_attr( $font ) . '-' . esc_attr( $icon['class'] ) . '"></i><a class="tooltips" href="#"><span>' . esc_html( $icon['class'] ) . '</span></a></li>';
210 }
211 }
212 $output . '</ul>';
213 $output .= '</div><!-- .icon_search-->';
214 $output .= '</div><!-- .inside-->';
215 $output .= '</div><!-- .postbox-->';
216 $output .= '</div><!-- .icon_set-' . esc_html( $font ) . ' -->';
217 echo $output;
218 }
219 }
220 $script = '<script type="text/javascript">
221 jQuery(document).ready(function(){
222 jQuery(".search-icon").keyup(function(){
223 jQuery(".fonts-count").hide();
224 // Retrieve the input field text and reset the count to zero
225 var filter = jQuery(this).val(), count = 0;
226 // Loop through the icon list
227 jQuery(".icons-list li").each(function(){
228 // If the list item does not contain the text phrase fade it out
229 if (jQuery(this).attr("data-icons-tag").search(new RegExp(filter, "i")) < 0) {
230 jQuery(this).fadeOut();
231 } else {
232 jQuery(this).show();
233 count++;
234 }
235 if(count == 0)
236 jQuery(".search-count").html(" ' . esc_js( __( 'Can\'t find the icon?', 'borderless' ) ) . ' <a href=\'#borderless_upload_icon\' class=\'button button-primary borderless_upload_icon\' data-target=\'iconfont_upload\' data-title=\' ' . esc_js( __( 'Upload/Select Fontello Font Zip', 'borderless' ) ) . ' \' data-type=\'application/octet-stream, application/zip\' data-button=\' ' . esc_js( __( 'Insert Fonts Zip File', 'borderless' ) ) . ' \' data-trigger=\'borderless_insert_zip\' data-class=\'media-frame\'>' . esc_js( __( 'Upload New Font Pack', 'borderless' ) ) . '</a>");
237 else
238 jQuery(".search-count").html(count+" ' . esc_js( __( 'Icons found.', 'borderless' ) ) . '");
239 jQuery( ".search-count" ).addClass( "search-count-open" );
240 if(filter == "")
241 jQuery(".fonts-count").show();
242 });
243 });
244 });
245 </script>';
246 echo $script;
247 }
248
249 function add_zipped_font() {
250 $cap = apply_filters( 'avf_file_upload_capability', 'update_plugins' );
251 if ( ! current_user_can( $cap ) ) {
252 die( esc_html__( "Using this feature is reserved for Super Admins. You unfortunately don't have the necessary permissions.", "borderless" ) );
253 }
254 //get the file path of the zip file
255 $attachment = $_POST['values'];
256 $path = realpath( get_attached_file( sanitize_text_field( $attachment['id'] ) ) );
257 $unzipped = $this->zip_flatten( $path, array( '\.eot', '\.svg', '\.ttf', '\.woff', '\.json', '\.css' ) );
258 // if we were able to unzip the file and save it to our temp folder extract the svg file
259 if ( $unzipped ) {
260 $this->create_config();
261 }
262 //if we got no name for the font dont add it and delete the temp folder
263 if ( $this->ip_name == 'unknown' ) {
264 $this->delete_folder( $this->paths['tempdir'] );
265 die( esc_html__( 'Was not able to retrieve the Icon Pack name from your Uploaded Folder', 'borderless' ) );
266 }
267 die( esc_html__( 'borderless_font_added:', 'borderless' ) . $this->ip_name );
268 }
269
270 function remove_zipped_font() {
271 //get the file path of the zip file
272 $font = sanitize_text_field( $_POST['del_font'] );
273 $list = self::load_iconfont_list();
274 $delete = isset( $list[ $font ] ) ? $list[ $font ] : false;
275 if ( $delete ) {
276 $this->delete_folder( $delete['include'] );
277 $this->remove_font( $font );
278 die( esc_html__( 'borderless_font_removed', 'borderless' ) );
279 }
280 die( esc_html__( 'Was not able to remove Icon Pack', 'borderless' ) );
281 }
282
283 //extract the zip file to a flat folder and remove the files that are not needed
284 function zip_flatten( $zipfile, $filter ) {
285 if ( is_dir( $this->paths['tempdir'] ) ) {
286 $this->delete_folder( $this->paths['tempdir'] );
287 $tempdir = borderless_backend_create_folder( $this->paths['tempdir'], false );
288 } else {
289 $tempdir = borderless_backend_create_folder( $this->paths['tempdir'], false );
290 }
291 //$fontdir = borderless_backend_create_folder($this->paths['fontdir'], false);
292 if ( ! $tempdir ) {
293 die( esc_html__( 'Could not create temporary folder.', 'borderless' ) );
294 }
295 $zip = new ZipArchive;
296 if ( $zip->open( $zipfile ) ) {
297 for ( $i = 0; $i < $zip->numFiles; $i ++ ) {
298 $entry = $zip->getNameIndex( $i );
299 if ( ! empty( $filter ) ) {
300 $delete = true;
301 $matches = array();
302 foreach ( $filter as $regex ) {
303 preg_match( "!" . $regex . "!", $entry, $matches );
304 if ( ! empty( $matches ) ) {
305 $delete = false;
306 break;
307 }
308 }
309 }
310 if ( substr( $entry, - 1 ) == '/' || ! empty( $delete ) ) {
311 continue;
312 } // skip directories and non matching files
313 $fp = $zip->getStream( $entry );
314 $ofp = fopen( $this->paths['tempdir'] . '/' . basename( $entry ), 'w' );
315 if ( ! $fp ) {
316 die( esc_html__( 'Unable to unpack Icon Pack.', 'borderless' ) );
317 }
318 while ( ! feof( $fp ) ) {
319 fwrite( $ofp, fread( $fp, 8192 ) );
320 }
321 fclose( $fp );
322 fclose( $ofp );
323 }
324 $zip->close();
325 } else {
326 die( esc_html__( "Icon Pack Zip file is corrupted.", 'borderless' ) );
327 }
328
329 return true;
330 }
331
332 //iterate over xml file and extract the glyphs for the font
333 function create_config() {
334 $this->json_file = $this->find_json();
335 $this->svg_file = $this->find_svg();
336 if ( empty( $this->json_file ) || empty( $this->svg_file ) ) {
337 $this->delete_folder( $this->paths['tempdir'] );
338 die( esc_html__( 'SVG file or selection.json not found. Please check the integrity of the Icon Pack files.', 'borderless' ) );
339 }
340 //$response = wp_remote_get( $this->paths['tempurl'].$this->svg_file );
341 $response = wp_remote_fopen( trailingslashit( $this->paths['tempurl'] ) . $this->svg_file );
342 //if wordpress wasnt able to get the file which is unlikely try to fetch it old school
343 $json = file_get_contents( trailingslashit( $this->paths['tempdir'] ) . $this->json_file );
344 if ( empty( $response ) ) {
345 $response = file_get_contents( trailingslashit( $this->paths['tempdir'] ) . $this->svg_file );
346 }
347 if ( ! is_wp_error( $json ) && ! empty( $json ) ) {
348 $xml = simplexml_load_string( $response );
349 $font_attr = $xml->defs->font->attributes();
350 $glyphs = $xml->defs->font->children();
351 $this->ip_name = (string) $font_attr['id'];
352 $font_folder = trailingslashit( $this->paths['fontdir'] ) . $this->ip_name;
353 if ( is_dir( $font_folder ) ) {
354 $this->delete_folder( $this->paths['tempdir'] );
355 die( esc_html__( "There is already an Icon Pack with this name, add an icon with another name.", "borderless" ) );
356 }
357 $file_contents = json_decode( $json );
358 if ( ! isset( $file_contents->IcoMoonType ) ) {
359 $this->delete_folder( $this->paths['tempdir'] );
360 die( esc_html__( "This Icon Pack does not belong to Icomoon. Use only Icomoon's Icon Pack.", 'borderless' ) );
361 }
362 $icons = $file_contents->icons;
363 $n = 1;
364 foreach ( $icons as $icon ) {
365 $icon_name = $icon->properties->name;
366 $icon_class = str_replace( ' ', '', $icon_name );
367 $icon_class = str_replace( ',', ' ', $icon_class );
368 $tags = implode( ",", $icon->icon->tags );
369 $this->json_config[ $this->ip_name ][ $icon_name ] = array(
370 "class" => $icon_class,
371 "tags" => $tags
372 );
373 $n ++;
374 }
375 if ( ! empty( $this->json_config ) && $this->ip_name != 'unknown' ) {
376 $this->write_config();
377 $this->re_write_css();
378 $this->rename_files();
379 $this->rename_folder();
380 $this->add_font();
381 }
382 }
383
384 return false;
385 }
386
387 //writes the php config file for the font
388 function write_config() {
389 $charmap = $this->paths['tempdir'] . '/' . $this->paths['config'];
390 $handle = @fopen( $charmap, 'w' );
391 if ( $handle ) {
392 fwrite( $handle, '<?php $icons = array();' );
393 foreach ( $this->json_config[ $this->ip_name ] as $icon => $info ) {
394 if ( ! empty( $info ) ) {
395 $delimiter = "'";
396 fwrite( $handle, "\r\n" . '$icons[\'' . $this->ip_name . '\'][' . $delimiter . $icon . $delimiter . '] = array("class"=>' . $delimiter . $info["class"] . $delimiter . ',"tags"=>' . $delimiter . $info["tags"] . $delimiter . ');' );
397 } else {
398 $this->delete_folder( $this->paths['tempdir'] );
399 die( esc_html__( 'Error generating configuration file.', 'borderless' ) );
400 }
401 }
402 fclose( $handle );
403 } else {
404 $this->delete_folder( $this->paths['tempdir'] );
405 die( esc_html__( 'Error generating configuration file.', 'borderless' ) );
406 }
407 }
408
409 //re-writes the php config file for the font
410 function re_write_css() {
411 $style = $this->paths['tempdir'] . '/style.css';
412 $file = @file_get_contents( $style );
413 if ( $file ) {
414 $str = str_replace( 'fonts/', '', $file );
415 $str = str_replace( 'icon-', $this->ip_name . '-', $str );
416 $str = str_replace( '.icon {', '[class^="' . $this->ip_name . '-"], [class*=" ' . $this->ip_name . '-"] {', $str );
417 $str = str_replace( 'i {', '[class^="' . $this->ip_name . '-"], [class*=" ' . $this->ip_name . '-"] {', $str );
418
419 /* remove comments */
420 $str = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $str );
421
422 /* remove tabs, spaces, newlines, etc. */
423 $str = str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $str );
424
425 @file_put_contents( $style, $str );
426 } else {
427 die( esc_html__( "Error generating CSS file. Use only Icomoon's Icon Pack.", 'borderless' ) );
428 }
429 }
430
431 function rename_files() {
432 $extensions = array( 'eot', 'svg', 'ttf', 'woff', 'css' );
433 $folder = trailingslashit( $this->paths['tempdir'] );
434 foreach ( glob( $folder . '*' ) as $file ) {
435 $path_parts = pathinfo( $file );
436 if ( strpos( $path_parts['filename'], '.dev' ) === false && in_array( $path_parts['extension'], $extensions ) ) {
437 if ( $path_parts['filename'] !== $this->ip_name ) {
438 rename( $file, trailingslashit( $path_parts['dirname'] ) . $this->ip_name . '.' . $path_parts['extension'] );
439 }
440 }
441 }
442 }
443
444 //rename the temp folder and all its font files
445 function rename_folder() {
446 $new_name = trailingslashit( $this->paths['fontdir'] ) . $this->ip_name;
447 //delete folder and contents if they already exist
448 $this->delete_folder( $new_name );
449 if ( rename( $this->paths['tempdir'], $new_name ) ) {
450 return true;
451 } else {
452 $this->delete_folder( $this->paths['tempdir'] );
453 die( esc_html__( "This Icon Pack could not be added.", "borderless" ) );
454 }
455 }
456
457 //delete a folder
458 function delete_folder( $new_name ) {
459 //delete folder and contents if they already exist
460 if ( is_dir( $new_name ) ) {
461 $objects = scandir( $new_name );
462 foreach ( $objects as $object ) {
463 if ( $object != "." && $object != ".." ) {
464 unlink( $new_name . "/" . $object );
465 }
466 }
467 reset( $objects );
468 rmdir( $new_name );
469 } else {
470 echo $new_name . ' no found<br/>';
471 }
472 }
473
474 function add_font() {
475 $fonts = get_option( 'borderless_icon_fonts' );
476 if ( empty( $fonts ) ) {
477 $fonts = array();
478 }
479 $fonts[ $this->ip_name ] = array(
480 'include' => sanitize_text_field( trailingslashit( $this->paths['fonts'] ) ) . $this->ip_name,
481 'folder' => sanitize_text_field( trailingslashit( $this->paths['fonts'] ) ) . $this->ip_name,
482 'style' => $this->ip_name . '/' . $this->ip_name . '.css',
483 'config' => sanitize_text_field( $this->paths['config'] )
484 );
485 update_option( 'borderless_icon_fonts', $fonts );
486 }
487
488 function remove_font( $font ) {
489 $fonts = get_option( 'borderless_icon_fonts' );
490 if ( isset( $fonts[ $font ] ) ) {
491 unset( $fonts[ $font ] );
492 update_option( 'borderless_icon_fonts', $fonts );
493 }
494 }
495
496 //finds the json file we need to create the config
497 function find_json() {
498 $files = scandir( $this->paths['tempdir'] );
499 foreach ( $files as $file ) {
500 if ( strpos( strtolower( $file ), '.json' ) !== false && $file[0] != '.' ) {
501 return $file;
502 }
503 }
504 }
505
506 //finds the svg file we need to create the config
507 function find_svg() {
508 $files = scandir( $this->paths['tempdir'] );
509 foreach ( $files as $file ) {
510 if ( strpos( strtolower( $file ), '.svg' ) !== false && $file[0] != '.' ) {
511 return $file;
512 }
513 }
514 }
515
516 static function load_iconfont_list() {
517 if ( ! empty( self::$ip_list ) ) {
518 return self::$ip_list;
519 }
520 $extra_fonts = get_option( 'borderless_icon_fonts' );
521 if ( empty( $extra_fonts ) ) {
522 $extra_fonts = array();
523 }
524 $font_configs = $extra_fonts;//array_merge(borderlessBuilder::$default_iconfont, $extra_fonts);
525 //if we got any include the charmaps and add the chars to an array
526 $upload_dir = wp_upload_dir();
527 $path = trailingslashit( $upload_dir['basedir'] );
528 $url = trailingslashit( $upload_dir['baseurl'] );
529 foreach ( $font_configs as $key => $config ) {
530 if ( empty( $config['full_path'] ) ) {
531 $font_configs[ $key ]['include'] = $path . $font_configs[ $key ]['include'];
532 $font_configs[ $key ]['folder'] = $url . $font_configs[ $key ]['folder'];
533 }
534 }
535 //cache the result
536 self::$ip_list = $font_configs;
537
538 return $font_configs;
539 }
540 }// End class
541
542 /*
543 * creates a folder for the theme framework
544 */
545
546 if ( ! function_exists( 'borderless_backend_create_folder' ) ) {
547 function borderless_backend_create_folder( &$folder, $addindex = true ) {
548 if ( is_dir( $folder ) && $addindex == false ) {
549 return true;
550 }
551 $created = wp_mkdir_p( trailingslashit( $folder ) );
552 @chmod( $folder, 0777 );
553 if ( $addindex == false ) {
554 return $created;
555 }
556 $index_file = trailingslashit( $folder ) . 'index.php';
557 if ( file_exists( $index_file ) ) {
558 return $created;
559 }
560 $handle = @fopen( $index_file, 'w' );
561 if ( $handle ) {
562 fwrite( $handle, "<?php\r\necho 'We're sorry for the inconvenience, but you're not allowed to browse the directory.';\r\n?>
563 " );
564 fclose( $handle );
565 }
566
567 return $created;
568 }
569 }
570 // Instantiate the Icon Fonts
571 new Borderless_IF;
572 }
573
574 function borderless_custom_icons_menu() {
575 $Borderless_IF = new Borderless_IF;
576 $Borderless_IF->icon_pack_manager();
577 }
578
579 function borderless_custom_icons() {
580 $upload_paths = wp_upload_dir();
581 $custom_fonts = get_option( 'borderless_icon_fonts' );
582 if ( is_array( $custom_fonts ) ) {
583 foreach ( $custom_fonts as $font => $info ) {
584 if ( strpos( $info['style'], 'http://' ) !== false ) {
585 wp_enqueue_style( 'borderless-' . $font, $info['style'], null, '1.0', 'all' );
586 } else {
587 wp_enqueue_style( 'borderless-' . $font, trailingslashit( $upload_paths['baseurl'] . '/borderless_icon_fonts/' ) . $info['style'], null, '1.0', 'all' );
588 }
589 }
590 }
591 }
592
593 add_action( 'wp_enqueue_scripts', 'borderless_custom_icons' );