Пример #1
0
 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);
     }
 }
Пример #2
0
 /**
  * Get the flash data transient.
  *
  * @return array
  */
 function thb_system_get_flashdata()
 {
     $user_id = get_current_user_id();
     $transient_key = 'thb_system_flashdata_' . $user_id;
     $value = get_transient($transient_key);
     thb_system_set_flashdata(array('message' => '', 'type' => ''));
     // delete_transient( $transient_key );
     return $value;
 }
 /**
  * Save the framework settings access option.
  */
 function thb_save_super_users()
 {
     $superUsers = isset($_POST['thb_super_users']) ? $_POST['thb_super_users'] : '';
     $usernames = explode(',', $superUsers);
     array_walk($usernames, 'trim');
     if (!empty($usernames)) {
         update_option('thb_super_users', implode(',', $usernames));
     }
     $result = thb_system_raise_success(__('All saved!', 'thb_text_domain'));
     thb_system_set_flashdata($result);
     if (!thb_is_super_user()) {
         $thb_theme = thb_theme();
         $thb_theme->getAdmin()->redirectToThemePage();
     }
 }