function thb_save_tab() { thb_system_verify_nonce('THB_tab'); $theme = thb_theme(); $page = $theme->getAdmin()->getPage($_POST['page']); $tab = $page->getTab($_POST['tab']); $containers = $tab->getContainers(); $uniqids = array(); foreach ($containers as $container) { if (!$container->isDuplicable()) { $newoptions = array(); foreach ($container->getFields() as $field) { if ($field->isComplex()) { $value = array(); foreach ($field->getSubkeys() as $subKey) { $value[$subKey] = thb_text_toDB($_POST[$field->getName()][$subKey]); } } else { $value = thb_text_toDB($_POST[$field->getName()]); } $newoptions[$field->getName()] = $value; } $theme->saveOptions($newoptions); } else { $uniqids[$container->getSlug()] = thb_duplicable_fields_save($container->getField()); } } thb_system_raise_success(__('All saved!', 'thb_text_domain'), $uniqids); }
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); } }
function thb_system_send_mail($to) { /** * Verify we have data to send. */ if ($_SERVER['REQUEST_METHOD'] != 'POST' || empty($_POST) || !isset($_POST['thb_system_send_mail_nonce'])) { return; } /** * Verify that the nonce is correct. */ if (!wp_verify_nonce($_POST['thb_system_send_mail_nonce'], 'thb_system_send_mail')) { return; } header('Content-type: application/json'); /** * Email data */ $thb_data = array('contact_email' => '', 'contact_name' => '', 'contact_message' => ''); $thb_data = $_POST + $thb_data; /** * Sanitize the data */ array_walk($thb_data, 'thb_system_xss_protect'); /** * Data validation */ foreach ($thb_data as $d) { if (trim($d) == '') { thb_system_raise_error(__('Please fill in all the required fields.', 'thb_text_domain')); } } /** * Composing the email */ $contact_name = $thb_data['contact_name']; $contact_email = $thb_data['contact_email']; $contact_message = $thb_data['contact_message']; $subject = get_bloginfo('contact_name'); $subject = apply_filters('thb_email_subject', $subject); $thb_contact_message = html_entity_decode(stripslashes(strip_tags($contact_message))); $headers = "From: " . $contact_name . " <" . $contact_email . ">" . "\r\n"; /** * Filters */ remove_all_filters('wp_mail_from'); remove_all_filters('wp_mail_from_name'); // add_filter( 'wp_mail_from','thb_wp_mail_from', 9999 ); // add_filter( 'wp_mail_from_name','thb_wp_mail_from_name', 9999 ); /** * Sending the email */ if (wp_mail($to, $subject, $thb_contact_message, $headers, array())) { thb_system_raise_success(__('Email sent successfully!', 'thb_text_domain')); } else { thb_system_raise_error(__('An error has occurred while sending your email.', 'thb_text_domain')); } }
/** * 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(); } }