Example #1
0
 function ot_type_googlefont($args = array())
 {
     /* turns arguments array into variables */
     extract($args);
     /* format setting outer wrapper */
     echo '<div class="format-setting type-typography">';
     /* description */
     echo $field_desc ? '<div class="description"><p>' . htmlspecialchars_decode($field_desc) . '</p></div>' : '';
     /* format setting inner wrapper */
     echo '<div class="format-setting-inner">';
     /* allow fields to be filtered */
     $ot_recognized_typography_fields = apply_filters('ot_recognized_typography_fields', array('font-color', 'font-family', 'font-id', 'font-style', 'font-variant', 'font-weight', 'font-subset', 'letter-spacing', 'text-decoration', 'text-transform'), $field_id);
     /* build font family */
     if (in_array('font-family', $ot_recognized_typography_fields)) {
         $font_family = isset($field_value['font-family']) ? $field_value['font-family'] : '';
         echo '<select name="' . esc_attr($field_name) . '[font-family]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-family" class="option-tree-ui-select hb-google-font-select' . esc_attr($field_class) . '">';
         echo '<option value="">font-family</option>';
         $current_font = NULL;
         foreach (hb_recognized_google_fonts($field_id) as $id => $font) {
             $key = preg_replace('/\\s+/', '', strtolower($font['family']));
             $variants = implode(",", $font['variants']);
             $subsets = implode(",", $font['subsets']);
             if ($font_family == esc_attr($key)) {
                 $current_font = $font['family'];
             }
             echo '<option data-fontid="' . $id . '" data-subsets="' . $subsets . '" data-variants="' . $variants . '" data-font="' . esc_attr($font['family']) . '" data-family="' . esc_attr($font['family']) . '" value="' . esc_attr($key) . '" ' . selected($font_family, $key, false) . '>' . esc_attr($font['family']) . '</option>';
         }
         echo '</select>';
     }
     /* hidden font id */
     if (in_array('font-id', $ot_recognized_typography_fields)) {
         $font_id = isset($field_value['font-id']) ? esc_attr($field_value['font-id']) : '';
         echo '<input type="hidden" name="' . esc_attr($field_name) . '[font-id]" id="' . esc_attr($field_id) . '-fontid" value="' . esc_attr($font_id) . '" autocomplete="off" />';
     }
     /* build font subsets */
     if (in_array('font-subset', $ot_recognized_typography_fields)) {
         $font_subset = isset($field_value['font-subset']) ? esc_attr($field_value['font-subset']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-subset]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-subset" class="option-tree-ui-select hb-google-font-subset ' . esc_attr($field_class) . '">';
         echo '<option value="">font-subset</option>';
         foreach (ot_recognized_google_subsets($field_id) as $key => $value) {
             echo '<option value="' . esc_attr($key) . '" ' . selected($font_subset, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build font size */
     if (in_array('font-size', $ot_recognized_typography_fields)) {
         $font_size = isset($field_value['font-size']) ? esc_attr($field_value['font-size']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-size]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-size" class="option-tree-ui-select hb-google-font-size ' . esc_attr($field_class) . '">';
         echo '<option value="">font-size</option>';
         $current_font_size = '16px';
         foreach (ot_recognized_font_sizes($field_id) as $option) {
             if ($font_size == $option) {
                 $current_font_size = esc_attr($option);
             }
             echo '<option value="' . esc_attr($option) . '" ' . selected($font_size, $option, false) . '>' . esc_attr($option) . '</option>';
         }
         echo '</select>';
     }
     /* build font weight */
     $current_weight = NULL;
     if (in_array('font-weight', $ot_recognized_typography_fields)) {
         $font_weight = isset($field_value['font-weight']) ? esc_attr($field_value['font-weight']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-weight]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-weight" class="option-tree-ui-select hb-google-font-weight ' . esc_attr($field_class) . '">';
         echo '<option value="">font-weight</option>';
         foreach (ot_recognized_google_font_weights($field_id) as $key => $value) {
             if ($font_weight == $key) {
                 $current_weight = esc_attr($key);
             }
             echo '<option value="' . esc_attr($key) . '" ' . selected($font_weight, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build line height */
     if (in_array('line-height', $ot_recognized_typography_fields)) {
         $line_height = isset($field_value['line-height']) ? esc_attr($field_value['line-height']) : '';
         echo '<select name="' . esc_attr($field_name) . '[line-height]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-line-height" class="option-tree-ui-select hb-google-line-height ' . esc_attr($field_class) . '">';
         echo '<option value="">line-height</option>';
         foreach (ot_recognized_line_heights($field_id) as $option) {
             echo '<option value="' . esc_attr($option) . '" ' . selected($line_height, $option, false) . '>' . esc_attr($option) . '</option>';
         }
         echo '</select>';
     }
     /* build font style */
     $current_style = NULL;
     if (in_array('font-style', $ot_recognized_typography_fields)) {
         $font_style = isset($field_value['font-style']) ? esc_attr($field_value['font-style']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-style]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-style" class="option-tree-ui-select hb-google-font-style ' . esc_attr($field_class) . '">';
         echo '<option value="">font-style</option>';
         foreach (ot_recognized_google_font_styles($field_id) as $key => $value) {
             if ($font_style == $key) {
                 $current_style = esc_attr($key);
             }
             echo '<option value="' . esc_attr($key) . '" ' . selected($font_style, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build text transform */
     if (in_array('text-transform', $ot_recognized_typography_fields)) {
         $text_transform = isset($field_value['text-transform']) ? esc_attr($field_value['text-transform']) : '';
         echo '<select name="' . esc_attr($field_name) . '[text-transform]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-text-transform" class="option-tree-ui-select hb-google-text-transform ' . esc_attr($field_class) . '">';
         echo '<option value="">text-transform</option>';
         foreach (ot_recognized_text_transformations($field_id) as $key => $value) {
             echo '<option value="' . esc_attr($key) . '" ' . selected($text_transform, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build text decoration */
     if (in_array('text-decoration', $ot_recognized_typography_fields)) {
         $text_decoration = isset($field_value['text-decoration']) ? esc_attr($field_value['text-decoration']) : '';
         echo '<select name="' . esc_attr($field_name) . '[text-decoration]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-text-decoration" class="option-tree-ui-select hb-google-text-decoration ' . esc_attr($field_class) . '">';
         echo '<option value="">text-decoration</option>';
         foreach (ot_recognized_text_decorations($field_id) as $key => $value) {
             echo '<option value="' . esc_attr($key) . '" ' . selected($text_decoration, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build letter spacing */
     if (in_array('letter-spacing', $ot_recognized_typography_fields)) {
         $letter_spacing = isset($field_value['letter-spacing']) ? esc_attr($field_value['letter-spacing']) : '';
         echo '<select name="' . esc_attr($field_name) . '[letter-spacing]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-letter-spacing" class="option-tree-ui-select hb-google-letter-spacing ' . esc_attr($field_class) . '">';
         echo '<option value="">letter-spacing</option>';
         foreach (ot_recognized_letter_spacing($field_id) as $key => $value) {
             echo '<option value="' . esc_attr($key) . '" ' . selected($letter_spacing, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build preview window */
     if (!empty($current_font)) {
         echo '<link id="hb-google-style-link-' . esc_attr($field_id) . '" rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=' . $current_font . ':' . $current_weight . $current_style . '">';
     } else {
         echo '<link id="hb-google-style-link-' . esc_attr($field_id) . '" rel="stylesheet" type="text/css" href="">';
     }
     $font_preview_style = NULL;
     if (!empty($field_value['font-family'])) {
         // $font_preview_style = '#hb-google-preview-' . esc_attr( $field_id ) . ' { font-size: '.$current_font_size.'; font-family: "'.$field_value['font-family'].'" !important; }';
         $font_preview_style = '#hb-google-preview-' . esc_attr($field_id) . ' {  font-family: "' . $field_value['font-family'] . '" !important; }';
     }
     echo '<style id="hb-google-style-' . esc_attr($field_id) . '" type="text/css">' . $font_preview_style . '</style>';
     echo '<div id="hb-google-preview-' . esc_attr($field_id) . '" class="hb-google-font-preview clearfix">';
     $lorem = 'Grumpy wizards make toxic brew for the evil Queen and Jack.';
     _e(apply_filters('hb_font_preview_text', $lorem, $field_id), HB_DOMAIN_TXT);
     echo '</div>';
     echo '</div>';
     echo '</div>';
 }
 function ot_type_googlefont($args = array())
 {
     /* turns arguments array into variables */
     extract($args);
     /* format setting outer wrapper */
     echo '<div class="format-setting type-typography">';
     /* format setting inner wrapper */
     echo '<div class="format-setting-inner">';
     /* allow fields to be filtered */
     $ot_recognized_typography_fields = apply_filters('ot_recognized_typography_fields', array('font-color', 'font-family', 'font-id', 'font-size', 'font-style', 'font-variant', 'font-weight', 'font-subset', 'letter-spacing', 'line-height', 'text-decoration', 'text-transform'), $field_id);
     /* build font family */
     if (in_array('font-family', $ot_recognized_typography_fields)) {
         $font_family = isset($field_value['font-family']) ? $field_value['font-family'] : '';
         echo '<select name="' . esc_attr($field_name) . '[font-family]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-family" class="option-tree-ui-select ut-google-font-select' . esc_attr($field_class) . '">';
         echo '<option value="">font-family</option>';
         $current_font = NULL;
         foreach (ut_recognized_google_fonts($field_id) as $id => $font) {
             $key = preg_replace('/\\s+/', '', strtolower($font['family']));
             $variants = implode(",", $font['variants']);
             $subsets = implode(",", $font['subsets']);
             if ($font_family == esc_attr($key)) {
                 $current_font = $font['family'];
             }
             echo '<option data-fontid="' . $id . '" data-subsets="' . $subsets . '" data-variants="' . $variants . '" data-font="' . esc_attr($font['family']) . '" data-family="' . esc_attr($font['family']) . '" value="' . esc_attr($key) . '" ' . selected($font_family, $key, false) . '>' . esc_attr($font['family']) . '</option>';
         }
         echo '</select>';
     }
     /* hidden font id */
     if (in_array('font-id', $ot_recognized_typography_fields)) {
         $font_id = isset($field_value['font-id']) ? esc_attr($field_value['font-id']) : '';
         echo '<input type="hidden" name="' . esc_attr($field_name) . '[font-id]" id="' . esc_attr($field_id) . '-fontid" value="' . esc_attr($font_id) . '" autocomplete="off" />';
     }
     /* build font subsets */
     if (in_array('font-subset', $ot_recognized_typography_fields)) {
         $font_subset = isset($field_value['font-subset']) ? esc_attr($field_value['font-subset']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-subset]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-subset" class="option-tree-ui-select ut-google-font-subset ' . esc_attr($field_class) . '">';
         echo '<option value="">font-subset</option>';
         foreach (ot_recognized_google_subsets($field_id) as $key => $value) {
             echo '<option value="' . esc_attr($key) . '" ' . selected($font_subset, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build font size */
     if (in_array('font-size', $ot_recognized_typography_fields)) {
         $font_size = isset($field_value['font-size']) ? esc_attr($field_value['font-size']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-size]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-size" class="option-tree-ui-select ut-google-font-size ' . esc_attr($field_class) . '">';
         echo '<option value="">font-size</option>';
         $current_font_size = '16px';
         foreach (ot_recognized_font_sizes($field_id) as $option) {
             if ($font_size == $option) {
                 $current_font_size = esc_attr($option);
             }
             echo '<option value="' . esc_attr($option) . '" ' . selected($font_size, $option, false) . '>' . esc_attr($option) . '</option>';
         }
         echo '</select>';
     }
     /* build font weight */
     if (in_array('font-weight', $ot_recognized_typography_fields)) {
         $font_weight = isset($field_value['font-weight']) ? esc_attr($field_value['font-weight']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-weight]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-weight" class="option-tree-ui-select ut-google-font-weight ' . esc_attr($field_class) . '">';
         echo '<option value="">font-weight</option>';
         $current_weight = NULL;
         foreach (ot_recognized_google_font_weights($field_id) as $key => $value) {
             if ($font_weight == $key) {
                 $current_weight = esc_attr($key);
             }
             echo '<option value="' . esc_attr($key) . '" ' . selected($font_weight, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build line height */
     if (in_array('line-height', $ot_recognized_typography_fields)) {
         $line_height = isset($field_value['line-height']) ? esc_attr($field_value['line-height']) : '';
         echo '<select name="' . esc_attr($field_name) . '[line-height]" id="' . esc_attr($field_id) . '-line-height" class="option-tree-ui-select ' . esc_attr($field_class) . '">';
         echo '<option value="">line-height</option>';
         foreach (ot_recognized_line_heights($field_id) as $option) {
             echo '<option value="' . esc_attr($option) . '" ' . selected($line_height, $option, false) . '>' . esc_attr($option) . '</option>';
         }
         echo '</select>';
     }
     /* build font style */
     if (in_array('font-style', $ot_recognized_typography_fields)) {
         $font_style = isset($field_value['font-style']) ? esc_attr($field_value['font-style']) : '';
         echo '<select name="' . esc_attr($field_name) . '[font-style]" data-group="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '-font-style" class="option-tree-ui-select ut-google-font-style ' . esc_attr($field_class) . '">';
         echo '<option value="">font-style</option>';
         $current_style = NULL;
         foreach (ot_recognized_google_font_styles($field_id) as $key => $value) {
             if ($font_style == $key) {
                 $current_style = esc_attr($key);
             }
             echo '<option value="' . esc_attr($key) . '" ' . selected($font_style, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build text transform */
     if (in_array('text-transform', $ot_recognized_typography_fields)) {
         $text_transform = isset($field_value['text-transform']) ? esc_attr($field_value['text-transform']) : '';
         echo '<select name="' . esc_attr($field_name) . '[text-transform]" id="' . esc_attr($field_id) . '-text-transform" class="option-tree-ui-select ' . esc_attr($field_class) . '">';
         echo '<option value="">text-transform</option>';
         foreach (ot_recognized_text_transformations($field_id) as $key => $value) {
             echo '<option value="' . esc_attr($key) . '" ' . selected($text_transform, $key, false) . '>' . esc_attr($value) . '</option>';
         }
         echo '</select>';
     }
     /* build preview window */
     if (!empty($current_font)) {
         echo '<link id="ut-google-style-link-' . esc_attr($field_id) . '" rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=' . $current_font . ':' . $current_weight . $current_style . '">';
     } else {
         echo '<link id="ut-google-style-link-' . esc_attr($field_id) . '" rel="stylesheet" type="text/css" href="">';
     }
     $font_preview_style = NULL;
     if (!empty($field_value['font-family'])) {
         $font_preview_style = '#ut-google-preview-' . esc_attr($field_id) . ' { font-size: ' . $current_font_size . '; font-family: "' . $field_value['font-family'] . '" !important; }';
     }
     echo '<style id="ut-google-style-' . esc_attr($field_id) . '" type="text/css">' . $font_preview_style . '</style>';
     echo '<div id="ut-google-preview-' . esc_attr($field_id) . '" class="ut-google-font-preview">';
     _e('The quick brown fox jumps over the lazy dog.', 'unitedthemes');
     echo '</div>';
     echo '</div>';
     echo '</div>';
 }