function thb_upload_custom_fonts()
 {
     $key = 'custom_font';
     $upload_dir = wp_upload_dir();
     $basedir = $upload_dir['basedir'];
     if (!empty($_POST)) {
         thb_duplicable_remove($key, 0);
     }
     if (!empty($_FILES) && isset($_FILES[$key])) {
         $count = count($_FILES[$key]['name']);
         for ($i = 0; $i < $count; $i++) {
             $uploaded_file = array('name' => $_FILES[$key]['name'][$i], 'type' => $_FILES[$key]['type'][$i], 'tmp_name' => $_FILES[$key]['tmp_name'][$i], 'error' => $_FILES[$key]['error'][$i], 'size' => $_FILES[$key]['size'][$i]);
             if ($uploaded_file['name'] != '') {
                 $file = thb_upload($uploaded_file);
                 if (file_exists($file['file']['file'])) {
                     $archive_name = str_replace('-fontfacekit.zip', '', basename($uploaded_file['name']));
                     // if( !file_exists($basedir . '/fonts/' . $archive_name . '/stylesheet.css') ) {
                     thb_unzip($file['file']['file'], $basedir . '/fonts/' . $archive_name . '/');
                     unlink($file['file']['file']);
                     $stylesheet = @file_get_contents($basedir . '/fonts/' . $archive_name . '/stylesheet.css');
                     preg_match_all('|font-family:(.*)$|mi', $stylesheet, $families);
                     preg_match_all('|font-weight:(.*)$|mi', $stylesheet, $weights);
                     preg_match_all('|font-style:(.*)$|mi', $stylesheet, $styles);
                     if (isset($families[1]) && !empty($families[1])) {
                         $k = 0;
                         foreach ($families[1] as $family) {
                             $family = trim($family);
                             $family = str_replace("'", "", $family);
                             $family = str_replace(";", "", $family);
                             // $_POST[$key]['css'][] = $family;
                             // $_POST[$key]['folder'][] =$archive_name;
                             $_POST[$key]['family'][] = $family;
                             $_POST[$key]['css'][] = $family;
                             $_POST[$key]['folder'][] = $archive_name;
                             $var = array();
                             if (isset($weights[1]) && !empty($weights[1]) && isset($styles[1]) && !empty($styles[1])) {
                                 // for( $j=0; $j<count($weights[1]); $j++ ) {
                                 $w = $weights[1][$k];
                                 $s = $styles[1][$k];
                                 $w = trim($w);
                                 $w = str_replace("'", "", $w);
                                 $w = str_replace(";", "", $w);
                                 $s = trim($s);
                                 $s = str_replace("'", "", $s);
                                 $s = str_replace(";", "", $s);
                                 $v = $w . $s;
                                 if ($v == 'normalnormal') {
                                     $v = 'normal';
                                 }
                                 $var[] = $v;
                                 // }
                             }
                             $_POST[$key]['variants'][] = $var;
                             $k++;
                         }
                     }
                     // }
                 }
             }
         }
     }
     if (!empty($_POST) && isset($_POST[$key])) {
         $post_count = count($_POST[$key]['css']);
         $font = $_POST[$key];
         for ($i = 0; $i < $post_count; $i++) {
             $meta = array('subtemplate' => '');
             if (!empty($_POST['uniqid'][$i])) {
                 $meta['uniqid'] = $_POST['uniqid'][$i];
             } else {
                 $meta['uniqid'] = md5(time() . $i);
             }
             $family = $_POST[$key]['family'][$i];
             //$family_name . ': ' . implode(', ', $font['variants'][$i]);
             thb_duplicable_add($key, array('ord' => $i, 'value' => array('family' => $family, 'css' => $font['css'][$i], 'variants' => implode(',', $font['variants'][$i]), 'folder' => $font['folder'][$i]), 'meta' => $meta));
         }
     }
     if (!empty($_POST)) {
         $result = thb_system_raise_success(__('All saved!', 'thb_text_domain'));
         thb_system_set_flashdata($result);
     }
 }
 /**
  * Import options and skin into the system.
  *
  * @param boolean $importOptions
  * @param boolean $importMods
  * @param boolean $importDuplicable
  */
 function thb_import($importOptions = true, $importMods = true, $importDuplicable = true)
 {
     if (!empty($_FILES)) {
         foreach ($_FILES as $uploaded_file) {
             $file = thb_upload($uploaded_file);
             if (file_exists($file['file']['file'])) {
                 $fileinfo = pathinfo($file['file']['file']);
                 if ($fileinfo['extension'] == 'thb-backup') {
                     $backup = @file_get_contents($file['file']['file']);
                     $data = unserialize(base64_decode($backup));
                     $success = false;
                     if ($importOptions && isset($data['options'])) {
                         $thb_theme = thb_theme();
                         $thb_theme->importOptions($data['options']);
                         $success = true;
                     }
                     if ($importMods && isset($data['mods'])) {
                         $theme = get_option('stylesheet');
                         update_option("theme_mods_{$theme}", $data['mods']);
                         $success = true;
                     }
                     if ($importDuplicable && isset($data['duplicable'])) {
                         thb_duplicable_remove_all();
                         foreach ($data['duplicable'] as $itemKey => $datas) {
                             foreach ($datas as $dat) {
                                 thb_duplicable_add($itemKey, $dat);
                             }
                             // thb_duplicable_add($itemKey, $da)
                             // $row['meta'] = serialize($row['meta']);
                             // $row['value'] = serialize($row['value']);
                             // thb_duplicable_add($row);
                         }
                         $success = true;
                     }
                     if ($success) {
                         $result = thb_system_raise_success(__('Data imported correctly', 'thb_text_domain'));
                     } else {
                         $result = thb_system_raise_error(__('No data imported', 'thb_text_domain'));
                     }
                 } else {
                     $result = thb_system_raise_error(sprintf(__('Wrong file type. Only files with the following extensions are allowed: %s.', 'thb_text_domain'), '.thb-backup'));
                 }
                 unlink($file['file']['file']);
             } else {
                 $result = thb_system_raise_error(__('Upload failed', 'thb_text_domain'));
             }
             thb_system_set_flashdata($result);
         }
     }
 }