ReduxFramework_typography

The Gravity Forms Advanced File Uploader ReduxFramework typography class.

Defined (1)

The class is defined in the following location(s).

/inc/ReduxFramework/ReduxCore/inc/fields/typography/field_typography.php  
  1. class ReduxFramework_typography { 
  2.  
  3. private $std_fonts = array( 
  4. "Arial, Helvetica, sans-serif" => "Arial, Helvetica, sans-serif",  
  5. "'Arial Black', Gadget, sans-serif" => "'Arial Black', Gadget, sans-serif",  
  6. "'Bookman Old Style', serif" => "'Bookman Old Style', serif",  
  7. "'Comic Sans MS', cursive" => "'Comic Sans MS', cursive",  
  8. "Courier, monospace" => "Courier, monospace",  
  9. "Garamond, serif" => "Garamond, serif",  
  10. "Georgia, serif" => "Georgia, serif",  
  11. "Impact, Charcoal, sans-serif" => "Impact, Charcoal, sans-serif",  
  12. "'Lucida Console', Monaco, monospace" => "'Lucida Console', Monaco, monospace",  
  13. "'Lucida Sans Unicode', 'Lucida Grande', sans-serif" => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",  
  14. "'MS Sans Serif', Geneva, sans-serif" => "'MS Sans Serif', Geneva, sans-serif",  
  15. "'MS Serif', 'New York', sans-serif" => "'MS Serif', 'New York', sans-serif",  
  16. "'Palatino Linotype', 'Book Antiqua', Palatino, serif" => "'Palatino Linotype', 'Book Antiqua', Palatino, serif",  
  17. "Tahoma, Geneva, sans-serif" => "Tahoma, Geneva, sans-serif",  
  18. "'Times New Roman', Times, serif" => "'Times New Roman', Times, serif",  
  19. "'Trebuchet MS', Helvetica, sans-serif" => "'Trebuchet MS', Helvetica, sans-serif",  
  20. "Verdana, Geneva, sans-serif" => "Verdana, Geneva, sans-serif",  
  21. ); 
  22.  
  23. private $user_fonts = true; 
  24.  
  25. /** 
  26. * Field Constructor. 
  27. * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function 
  28. * @since ReduxFramework 1.0.0 
  29. */ 
  30. function __construct( $field = array(), $value = '', $parent ) { 
  31. $this->parent = $parent; 
  32. $this->field = $field; 
  33. $this->value = $value; 
  34.  
  35. // Shim out old arg to new 
  36. if ( isset( $this->field['all_styles'] ) && ! empty( $this->field['all_styles'] ) ) { 
  37. $this->field['all-styles'] = $this->field['all_styles']; 
  38. unset ( $this->field['all_styles'] ); 
  39.  
  40. // Set field array defaults. No errors please 
  41. $defaults = array( 
  42. 'font-family' => true,  
  43. 'font-size' => true,  
  44. 'font-weight' => true,  
  45. 'font-style' => true,  
  46. 'font-backup' => false,  
  47. 'subsets' => true,  
  48. 'custom_fonts' => true,  
  49. 'text-align' => true,  
  50. 'text-transform' => false,  
  51. 'font-variant' => false,  
  52. 'text-decoration' => false,  
  53. 'color' => true,  
  54. 'preview' => true,  
  55. 'line-height' => true,  
  56. 'word-spacing' => false,  
  57. 'letter-spacing' => false,  
  58. 'google' => true,  
  59. 'update_weekly' => false, // Enable to force updates of Google Fonts to be weekly 
  60. 'font_family_clear' => true 
  61. ); 
  62. $this->field = wp_parse_args( $this->field, $defaults ); 
  63.  
  64. // Set value defaults. 
  65. $defaults = array( 
  66. 'font-family' => '',  
  67. 'font-options' => '',  
  68. 'font-backup' => '',  
  69. 'text-align' => '',  
  70. 'text-transform' => '',  
  71. 'font-variant' => '',  
  72. 'text-decoration' => '',  
  73. 'line-height' => '',  
  74. 'word-spacing' => '',  
  75. 'letter-spacing' => '',  
  76. 'subsets' => '',  
  77. 'google' => false,  
  78. 'font-script' => '',  
  79. 'font-weight' => '',  
  80. 'font-style' => '',  
  81. 'color' => '',  
  82. 'font-size' => '',  
  83. ); 
  84. $this->value = wp_parse_args( $this->value, $defaults ); 
  85.  
  86. // Get the google array 
  87. $this->getGoogleArray(); 
  88.  
  89. if ( empty( $this->field['fonts'] ) ) { 
  90. $this->user_fonts = false; 
  91. $this->field['fonts'] = $this->std_fonts; 
  92.  
  93. // Localize std fonts 
  94. $this->localizeStdFonts(); 
  95.  
  96.  
  97. function localize( $field, $value = "" ) { 
  98. $params = array(); 
  99.  
  100. if ( true == $this->user_fonts && ! empty( $this->field['fonts'] ) ) { 
  101. $params['std_font'] = $this->field['fonts']; 
  102.  
  103. return $params; 
  104.  
  105.  
  106. /** 
  107. * Field Render Function. 
  108. * Takes the vars and outputs the HTML for the field in the settings 
  109. * @since ReduxFramework 1.0.0 
  110. */ 
  111. function render() { 
  112. // Since fonts declared is CSS (@font-face) are not rendered in the preview,  
  113. // they can be declared in a CSS file and passed here so they DO display in 
  114. // font preview. Do NOT pass style.css in your theme, as that will mess up 
  115. // admin page styling. It's recommended to pass a CSS file with ONLY font 
  116. // declarations. 
  117. // If field is set and not blank, then enqueue field 
  118. if ( isset( $this->field['ext-font-css'] ) && $this->field['ext-font-css'] != '' ) { 
  119. wp_register_style( 'redux-external-fonts', $this->field['ext-font-css'] ); 
  120. wp_enqueue_style( 'redux-external-fonts' ); 
  121.  
  122. if ( empty( $this->field['units'] ) && ! empty( $this->field['default']['units'] ) ) { 
  123. $this->field['units'] = $this->field['default']['units']; 
  124.  
  125. if ( empty( $this->field['units'] ) || ! in_array( $this->field['units'], array( 
  126. 'px',  
  127. 'em',  
  128. 'rem',  
  129. '%' 
  130. ) ) 
  131. ) { 
  132. $this->field['units'] = 'px'; 
  133.  
  134. $unit = $this->field['units']; 
  135.  
  136. echo '<div id="' . $this->field['id'] . '" class="redux-typography-container" data-id="' . $this->field['id'] . '" data-units="' . $unit . '">'; 
  137.  
  138. if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js 
  139. $select2_params = json_encode( $this->field['select2'] ); 
  140. $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES ); 
  141.  
  142. echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">'; 
  143.  
  144. /** Font Family */ 
  145. if ( $this->field['font-family'] === true ) { 
  146.  
  147. // font family clear 
  148. echo '<input type="hidden" class="redux-font-clear" value="' . $this->field['font_family_clear'] . '">'; 
  149.  
  150. //if (filter_var($this->value['google'], FILTER_VALIDATE_BOOLEAN)) { 
  151. if ( filter_var( $this->value['google'], FILTER_VALIDATE_BOOLEAN ) ) { 
  152.  
  153. // Divide and conquer 
  154. $fontFamily = explode( ', ', $this->value['font-family'], 2 ); 
  155.  
  156. // If array 0 is empty and array 1 is not 
  157. if ( empty( $fontFamily[0] ) && ! empty( $fontFamily[1] ) ) { 
  158.  
  159. // Make array 0 = array 1 
  160. $fontFamily[0] = $fontFamily[1]; 
  161.  
  162. // Clear array 1 
  163. $fontFamily[1] = ""; 
  164.  
  165. // If no fontFamily array exists, create one and set array 0 
  166. // with font value 
  167. if ( ! isset( $fontFamily ) ) { 
  168. $fontFamily = array(); 
  169. $fontFamily[0] = $this->value['font-family']; 
  170. $fontFamily[1] = ""; 
  171.  
  172. // Is selected font a Google font 
  173. $isGoogleFont = '0'; 
  174. if ( isset( $this->parent->fonts['google'][ $fontFamily[0] ] ) ) { 
  175. $isGoogleFont = '1'; 
  176.  
  177. // If not a Google font, show all font families 
  178. if ( $isGoogleFont != '1' ) { 
  179. $fontFamily[0] = $this->value['font-family']; 
  180.  
  181. $userFonts = '0'; 
  182. if ( true == $this->user_fonts ) { 
  183. $userFonts = '1'; 
  184.  
  185. echo '<input type="hidden" class="redux-typography-font-family ' . $this->field['class'] . '" data-user-fonts="' . $userFonts . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-family]' . '" value="' . $this->value['font-family'] . '" data-id="' . $this->field['id'] . '" />'; 
  186. echo '<input type="hidden" class="redux-typography-font-options ' . $this->field['class'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-options]' . '" value="' . $this->value['font-options'] . '" data-id="' . $this->field['id'] . '" />'; 
  187.  
  188. echo '<input type="hidden" class="redux-typography-google-font" value="' . $isGoogleFont . '" id="' . $this->field['id'] . '-google-font">'; 
  189.  
  190. echo '<div class="select_wrapper typography-family" style="width: 220px; margin-right: 5px;">'; 
  191. echo '<label>' . __( 'Font Family', 'redux-framework' ) . '</label>'; 
  192. $placeholder = $fontFamily[0] ? $fontFamily[0] : __( 'Font family', 'redux-framework' ); 
  193.  
  194. echo '<div class=" redux-typography redux-typography-family select2-container ' . $this->field['class'] . '" id="' . $this->field['id'] . '-family" placeholder="' . $placeholder . '" data-id="' . $this->field['id'] . '" data-value="' . $fontFamily[0] . '">'; 
  195.  
  196. echo '</div>'; 
  197. echo '</div>'; 
  198.  
  199. $googleSet = false; 
  200. if ( $this->field['google'] === true ) { 
  201.  
  202. // Set a flag so we know to set a header style or not 
  203. echo '<input type="hidden" class="redux-typography-google' . $this->field['class'] . '" id="' . $this->field['id'] . '-google" name="' . $this->field['name'] . $this->field['name_suffix'] . '[google]' . '" type="text" value="' . $this->field['google'] . '" data-id="' . $this->field['id'] . '" />'; 
  204. $googleSet = true; 
  205.  
  206. /** Backup Font */ 
  207. if ( $this->field['font-family'] === true && $this->field['google'] === true ) { 
  208.  
  209. if ( false == $googleSet ) { 
  210. // Set a flag so we know to set a header style or not 
  211. echo '<input type="hidden" class="redux-typography-google' . $this->field['class'] . '" id="' . $this->field['id'] . '-google" name="' . $this->field['name'] . $this->field['name_suffix'] . '[google]' . '" type="text" value="' . $this->field['google'] . '" data-id="' . $this->field['id'] . '" />'; 
  212.  
  213. if ( $this->field['font-backup'] === true ) { 
  214. echo '<div class="select_wrapper typography-family-backup" style="width: 220px; margin-right: 5px;">'; 
  215. echo '<label>' . __( 'Backup Font Family', 'redux-framework' ) . '</label>'; 
  216. echo '<select data-placeholder="' . __( 'Backup Font Family', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-backup]' . '" class="redux-typography redux-typography-family-backup ' . $this->field['class'] . '" id="' . $this->field['id'] . '-family-backup" data-id="' . $this->field['id'] . '" data-value="' . $this->value['font-backup'] . '">'; 
  217. echo '<option data-google="false" data-details="" value=""></option>'; 
  218.  
  219. foreach ( $this->field['fonts'] as $i => $family ) { 
  220. echo '<option data-google="true" value="' . $i . '"' . selected( $this->value['font-backup'], $i, false ) . '>' . $family . '</option>'; 
  221.  
  222. echo '</select></div>'; 
  223.  
  224. /** Font Style/Weight */ 
  225. if ( $this->field['font-style'] === true || $this->field['font-weight'] === true ) { 
  226.  
  227. echo '<div class="select_wrapper typography-style" original-title="' . __( 'Font style', 'redux-framework' ) . '">'; 
  228. echo '<label>' . __( 'Font Weight & Style', 'redux-framework' ) . '</label>'; 
  229.  
  230. $style = $this->value['font-weight'] . $this->value['font-style']; 
  231.  
  232. echo '<input type="hidden" class="typography-font-weight" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-weight]' . '" value="' . $this->value['font-weight'] . '" data-id="' . $this->field['id'] . '" /> '; 
  233. echo '<input type="hidden" class="typography-font-style" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-style]' . '" value="' . $this->value['font-style'] . '" data-id="' . $this->field['id'] . '" /> '; 
  234. echo '<select data-placeholder="' . __( 'Style', 'redux-framework' ) . '" class="redux-typography redux-typography-style select' . $this->field['class'] . '" original-title="' . __( 'Font style', 'redux-framework' ) . '" id="' . $this->field['id'] . '_style" data-id="' . $this->field['id'] . '" data-value="' . $style . '">'; 
  235.  
  236. if ( empty( $this->value['subset'] ) || empty( $this->value['font-weight'] ) ) { 
  237. echo '<option value=""></option>'; 
  238.  
  239. $nonGStyles = array( 
  240. '200' => 'Lighter',  
  241. '400' => 'Normal',  
  242. '700' => 'Bold',  
  243. '900' => 'Bolder' 
  244. ); 
  245.  
  246. if ( isset( $gfonts[ $this->value['font-family'] ] ) ) { 
  247. foreach ( $gfonts[ $this->value['font-family'] ]['variants'] as $v ) { 
  248. echo '<option value="' . $v['id'] . '" ' . selected( $this->value['subset'], $v['id'], false ) . '>' . $v['name'] . '</option>'; 
  249. } else { 
  250. if ( ! isset( $this->value['font-weight'] ) && isset( $this->value['subset'] ) ) { 
  251. $this->value['font-weight'] = $this->value['subset']; 
  252.  
  253. foreach ( $nonGStyles as $i => $style ) { 
  254. if ( ! isset( $this->value['font-weight'] ) ) { 
  255. $this->value['font-weight'] = false; 
  256.  
  257. if ( ! isset( $this->value['subset'] ) ) { 
  258. $this->value['subset'] = false; 
  259.  
  260. echo '<option value="' . $i . '" ' . selected( $this->value['font-weight'], $i, false ) . '>' . $style . '</option>'; 
  261.  
  262. echo '</select></div>'; 
  263.  
  264. /** Font Script */ 
  265. if ( $this->field['font-family'] == true && $this->field['subsets'] == true && $this->field['google'] == true ) { 
  266. echo '<div class="select_wrapper typography-script tooltip" original-title="' . __( 'Font subsets', 'redux-framework' ) . '">'; 
  267. echo '<input type="hidden" class="typography-subsets" name="' . $this->field['name'] . $this->field['name_suffix'] . '[subsets]' . '" value="' . $this->value['subsets'] . '" data-id="' . $this->field['id'] . '" /> '; 
  268. echo '<label>' . __( 'Font Subsets', 'redux-framework' ) . '</label>'; 
  269. echo '<select data-placeholder="' . __( 'Subsets', 'redux-framework' ) . '" class="redux-typography redux-typography-subsets' . $this->field['class'] . '" original-title="' . __( 'Font script', 'redux-framework' ) . '" id="' . $this->field['id'] . '-subsets" data-value="' . $this->value['subsets'] . '" data-id="' . $this->field['id'] . '" >'; 
  270.  
  271. if ( empty( $this->value['subsets'] ) ) { 
  272. echo '<option value=""></option>'; 
  273.  
  274. if ( isset( $gfonts[ $this->value['font-family'] ] ) ) { 
  275. foreach ( $gfonts[ $this->value['font-family'] ]['subsets'] as $v ) { 
  276. echo '<option value="' . $v['id'] . '" ' . selected( $this->value['subset'], $v['id'], false ) . '>' . $v['name'] . '</option>'; 
  277.  
  278. echo '</select></div>'; 
  279.  
  280. /** Font Align */ 
  281. if ( $this->field['text-align'] === true ) { 
  282. echo '<div class="select_wrapper typography-align tooltip" original-title="' . __( 'Text Align', 'redux-framework' ) . '">'; 
  283. echo '<label>' . __( 'Text Align', 'redux-framework' ) . '</label>'; 
  284. echo '<select data-placeholder="' . __( 'Text Align', 'redux-framework' ) . '" class="redux-typography redux-typography-align' . $this->field['class'] . '" original-title="' . __( 'Text Align', 'redux-framework' ) . '" id="' . $this->field['id'] . '-align" name="' . $this->field['name'] . $this->field['name_suffix'] . '[text-align]' . '" data-value="' . $this->value['text-align'] . '" data-id="' . $this->field['id'] . '" >'; 
  285. echo '<option value=""></option>'; 
  286.  
  287. $align = array( 
  288. 'inherit',  
  289. 'left',  
  290. 'right',  
  291. 'center',  
  292. 'justify',  
  293. 'initial' 
  294. ); 
  295.  
  296. foreach ( $align as $v ) { 
  297. echo '<option value="' . $v . '" ' . selected( $this->value['text-align'], $v, false ) . '>' . ucfirst( $v ) . '</option>'; 
  298.  
  299. echo '</select></div>'; 
  300.  
  301. /** Text Transform */ 
  302. if ( $this->field['text-transform'] === true ) { 
  303. echo '<div class="select_wrapper typography-transform tooltip" original-title="' . __( 'Text Transform', 'redux-framework' ) . '">'; 
  304. echo '<label>' . __( 'Text Transform', 'redux-framework' ) . '</label>'; 
  305. echo '<select data-placeholder="' . __( 'Text Transform', 'redux-framework' ) . '" class="redux-typography redux-typography-transform' . $this->field['class'] . '" original-title="' . __( 'Text Transform', 'redux-framework' ) . '" id="' . $this->field['id'] . '-transform" name="' . $this->field['name'] . $this->field['name_suffix'] . '[text-transform]' . '" data-value="' . $this->value['text-transform'] . '" data-id="' . $this->field['id'] . '" >'; 
  306. echo '<option value=""></option>'; 
  307.  
  308. $values = array( 
  309. 'none',  
  310. 'capitalize',  
  311. 'uppercase',  
  312. 'lowercase',  
  313. 'initial',  
  314. 'inherit' 
  315. ); 
  316.  
  317. foreach ( $values as $v ) { 
  318. echo '<option value="' . $v . '" ' . selected( $this->value['text-transform'], $v, false ) . '>' . ucfirst( $v ) . '</option>'; 
  319.  
  320. echo '</select></div>'; 
  321.  
  322. /** Font Variant */ 
  323. if ( $this->field['font-variant'] === true ) { 
  324. echo '<div class="select_wrapper typography-font-variant tooltip" original-title="' . __( 'Font Variant', 'redux-framework' ) . '">'; 
  325. echo '<label>' . __( 'Font Variant', 'redux-framework' ) . '</label>'; 
  326. echo '<select data-placeholder="' . __( 'Font Variant', 'redux-framework' ) . '" class="redux-typography redux-typography-font-variant' . $this->field['class'] . '" original-title="' . __( 'Font Variant', 'redux-framework' ) . '" id="' . $this->field['id'] . '-font-variant" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-variant]' . '" data-value="' . $this->value['font-variant'] . '" data-id="' . $this->field['id'] . '" >'; 
  327. echo '<option value=""></option>'; 
  328.  
  329. $values = array( 
  330. 'inherit',  
  331. 'normal',  
  332. 'small-caps' 
  333. ); 
  334.  
  335. foreach ( $values as $v ) { 
  336. echo '<option value="' . $v . '" ' . selected( $this->value['font-variant'], $v, false ) . '>' . ucfirst( $v ) . '</option>'; 
  337.  
  338. echo '</select></div>'; 
  339.  
  340. /** Text Decoration */ 
  341. if ( $this->field['text-decoration'] === true ) { 
  342. echo '<div class="select_wrapper typography-decoration tooltip" original-title="' . __( 'Text Decoration', 'redux-framework' ) . '">'; 
  343. echo '<label>' . __( 'Text Decoration', 'redux-framework' ) . '</label>'; 
  344. echo '<select data-placeholder="' . __( 'Text Decoration', 'redux-framework' ) . '" class="redux-typography redux-typography-decoration' . $this->field['class'] . '" original-title="' . __( 'Text Decoration', 'redux-framework' ) . '" id="' . $this->field['id'] . '-decoration" name="' . $this->field['name'] . $this->field['name_suffix'] . '[text-decoration]' . '" data-value="' . $this->value['text-decoration'] . '" data-id="' . $this->field['id'] . '" >'; 
  345. echo '<option value=""></option>'; 
  346.  
  347. $values = array( 
  348. 'none',  
  349. 'inherit',  
  350. 'underline',  
  351. 'overline',  
  352. 'line-through',  
  353. 'blink' 
  354. ); 
  355.  
  356. foreach ( $values as $v ) { 
  357. echo '<option value="' . $v . '" ' . selected( $this->value['text-decoration'], $v, false ) . '>' . ucfirst( $v ) . '</option>'; 
  358.  
  359. echo '</select></div>'; 
  360.  
  361. /** Font Size */ 
  362. if ( $this->field['font-size'] === true ) { 
  363. echo '<div class="input_wrapper font-size redux-container-typography">'; 
  364. echo '<label>' . __( 'Font Size', 'redux-framework' ) . '</label>'; 
  365. echo '<div class="input-append"><input type="text" class="span2 redux-typography redux-typography-size mini typography-input' . $this->field['class'] . '" title="' . __( 'Font Size', 'redux-framework' ) . '" placeholder="' . __( 'Size', 'redux-framework' ) . '" id="' . $this->field['id'] . '-size" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-size]' . '" value="' . str_replace( $unit, '', $this->value['font-size'] ) . '" data-value="' . str_replace( $unit, '', $this->value['font-size'] ) . '"><span class="add-on">' . $unit . '</span></div>'; 
  366. echo '<input type="hidden" class="typography-font-size" name="' . $this->field['name'] . $this->field['name_suffix'] . '[font-size]' . '" value="' . $this->value['font-size'] . '" data-id="' . $this->field['id'] . '" />'; 
  367. echo '</div>'; 
  368.  
  369. /** Line Height */ 
  370. if ( $this->field['line-height'] === true ) { 
  371. echo '<div class="input_wrapper line-height redux-container-typography">'; 
  372. echo '<label>' . __( 'Line Height', 'redux-framework' ) . '</label>'; 
  373. echo '<div class="input-append"><input type="text" class="span2 redux-typography redux-typography-height mini typography-input' . $this->field['class'] . '" title="' . __( 'Line Height', 'redux-framework' ) . '" placeholder="' . __( 'Height', 'redux-framework' ) . '" id="' . $this->field['id'] . '-height" value="' . str_replace( $unit, '', $this->value['line-height'] ) . '" data-value="' . str_replace( $unit, '', $this->value['line-height'] ) . '"><span class="add-on">' . $unit . '</span></div>'; 
  374. echo '<input type="hidden" class="typography-line-height" name="' . $this->field['name'] . $this->field['name_suffix'] . '[line-height]' . '" value="' . $this->value['line-height'] . '" data-id="' . $this->field['id'] . '" />'; 
  375. echo '</div>'; 
  376.  
  377. /** Word Spacing */ 
  378. if ( $this->field['word-spacing'] === true ) { 
  379. echo '<div class="input_wrapper word-spacing redux-container-typography">'; 
  380. echo '<label>' . __( 'Word Spacing', 'redux-framework' ) . '</label>'; 
  381. echo '<div class="input-append"><input type="text" class="span2 redux-typography redux-typography-word mini typography-input' . $this->field['class'] . '" title="' . __( 'Word Spacing', 'redux-framework' ) . '" placeholder="' . __( 'Word Spacing', 'redux-framework' ) . '" id="' . $this->field['id'] . '-word" value="' . str_replace( $unit, '', $this->value['word-spacing'] ) . '" data-value="' . str_replace( $unit, '', $this->value['word-spacing'] ) . '"><span class="add-on">' . $unit . '</span></div>'; 
  382. echo '<input type="hidden" class="typography-word-spacing" name="' . $this->field['name'] . $this->field['name_suffix'] . '[word-spacing]' . '" value="' . $this->value['word-spacing'] . '" data-id="' . $this->field['id'] . '" />'; 
  383. echo '</div>'; 
  384.  
  385. /** Letter Spacing */ 
  386. if ( $this->field['letter-spacing'] === true ) { 
  387. echo '<div class="input_wrapper letter-spacing redux-container-typography">'; 
  388. echo '<label>' . __( 'Letter Spacing', 'redux-framework' ) . '</label>'; 
  389. echo '<div class="input-append"><input type="text" class="span2 redux-typography redux-typography-letter mini typography-input' . $this->field['class'] . '" title="' . __( 'Letter Spacing', 'redux-framework' ) . '" placeholder="' . __( 'Letter Spacing', 'redux-framework' ) . '" id="' . $this->field['id'] . '-letter" value="' . str_replace( $unit, '', $this->value['letter-spacing'] ) . '" data-value="' . str_replace( $unit, '', $this->value['letter-spacing'] ) . '"><span class="add-on">' . $unit . '</span></div>'; 
  390. echo '<input type="hidden" class="typography-letter-spacing" name="' . $this->field['name'] . $this->field['name_suffix'] . '[letter-spacing]' . '" value="' . $this->value['letter-spacing'] . '" data-id="' . $this->field['id'] . '" />'; 
  391. echo '</div>'; 
  392.  
  393. echo '<div class="clearfix"></div>'; 
  394.  
  395. /** Font Color */ 
  396. if ( $this->field['color'] === true ) { 
  397. $default = ""; 
  398.  
  399. if ( empty( $this->field['default']['color'] ) && ! empty( $this->field['color'] ) ) { 
  400. $default = $this->value['color']; 
  401. } else if ( ! empty( $this->field['default']['color'] ) ) { 
  402. $default = $this->field['default']['color']; 
  403.  
  404. echo '<div class="picker-wrapper">'; 
  405. echo '<label>' . __( 'Font Color', 'redux-framework' ) . '</label>'; 
  406. echo '<div id="' . $this->field['id'] . '_color_picker" class="colorSelector typography-color"><div style="background-color: ' . $this->value['color'] . '"></div></div>'; 
  407. echo '<input data-default-color="' . $default . '" class="redux-color redux-typography-color' . $this->field['class'] . '" original-title="' . __( 'Font color', 'redux-framework' ) . '" id="' . $this->field['id'] . '-color" name="' . $this->field['name'] . $this->field['name_suffix'] . '[color]' . '" type="text" value="' . $this->value['color'] . '" data-id="' . $this->field['id'] . '" />'; 
  408. echo '</div>'; 
  409.  
  410. echo '<div class="clearfix"></div>'; 
  411.  
  412. /** Font Preview */ 
  413. if ( ! isset( $this->field['preview'] ) || $this->field['preview'] !== false ) { 
  414. if ( isset( $this->field['preview']['text'] ) ) { 
  415. $g_text = $this->field['preview']['text']; 
  416. } else { 
  417. $g_text = '1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z'; 
  418.  
  419. $style = ''; 
  420. if ( isset( $this->field['preview']['always_display'] ) ) { 
  421. if ( true === filter_var( $this->field['preview']['always_display'], FILTER_VALIDATE_BOOLEAN ) ) { 
  422. if ( $isGoogleFont == true ) { 
  423. $this->parent->typography_preview[ $fontFamily[0] ] = array( 
  424. 'font-style' => array( $this->value['font-weight'] . $this->value['font-style'] ),  
  425. 'subset' => array( $this->value['subset'] ) 
  426. ); 
  427.  
  428. $protocol = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ) ? "https:" : "http:"; 
  429.  
  430. wp_deregister_style( 'redux-typography-preview' ); 
  431. wp_dequeue_style( 'redux-typography-preview' ); 
  432.  
  433. wp_register_style( 'redux-typography-preview', $protocol . $this->makeGoogleWebfontLink( $this->parent->typography_preview ), '', time() ); 
  434. wp_enqueue_style( 'redux-typography-preview' ); 
  435.  
  436. $style = 'display: block; font-family: ' . $this->value['font-family'] . '; font-weight: ' . $this->value['font-weight'] . ';'; 
  437.  
  438. if ( isset( $this->field['preview']['font-size'] ) ) { 
  439. $style .= 'font-size: ' . $this->field['preview']['font-size'] . ';'; 
  440. $inUse = '1'; 
  441. } else { 
  442. //$g_size = ''; 
  443. $inUse = '0'; 
  444.  
  445. echo '<p data-preview-size="' . $inUse . '" class="clear ' . $this->field['id'] . '_previewer typography-preview" ' . 'style="' . $style . '">' . $g_text . '</p>'; 
  446. echo '</div>'; // end typography container 
  447. } //function 
  448.  
  449. /** 
  450. * Enqueue Function. 
  451. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  452. * @since ReduxFramework 1.0.0 
  453. */ 
  454. function enqueue() { 
  455.  
  456. wp_enqueue_script( 
  457. 'redux-field-typography-js',  
  458. ReduxFramework::$_url . 'inc/fields/typography/field_typography' . Redux_Functions::isMin() . '.js',  
  459. array( 'jquery', 'wp-color-picker', 'select2-js', 'redux-js' ),  
  460. time(),  
  461. true 
  462. ); 
  463.  
  464. wp_localize_script( 
  465. 'redux-field-typography-js',  
  466. 'redux_ajax_script',  
  467. array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) 
  468. ); 
  469.  
  470. redux_enqueue_style( 
  471. $this->parent,  
  472. 'redux-field-typography-css',  
  473. ReduxFramework::$_url . 'inc/fields/typography/field_typography.css',  
  474. ReduxFramework::$_dir . 'inc/fields/typography',  
  475. array(),  
  476. time(),  
  477. false 
  478. );  
  479.  
  480. // wp_enqueue_style( 
  481. // 'redux-field-typography-css',  
  482. // ReduxFramework::$_url . 'inc/fields/typography/field_typography.css',  
  483. // time(),  
  484. // true 
  485. // ); 
  486. } //function 
  487.  
  488. /** 
  489. * makeGoogleWebfontLink Function. 
  490. * Creates the google fonts link. 
  491. * @since ReduxFramework 3.0.0 
  492. */ 
  493. function makeGoogleWebfontLink( $fonts ) { 
  494. $link = ""; 
  495. $subsets = array(); 
  496.  
  497. foreach ( $fonts as $family => $font ) { 
  498. if ( ! empty( $link ) ) { 
  499. $link .= "%7C"; // Append a new font to the string 
  500. $link .= $family; 
  501.  
  502. if ( ! empty( $font['font-style'] ) || ! empty( $font['all-styles'] ) ) { 
  503. $link .= ':'; 
  504. if ( ! empty( $font['all-styles'] ) ) { 
  505. $link .= implode( ', ', $font['all-styles'] ); 
  506. } else if ( ! empty( $font['font-style'] ) ) { 
  507. $link .= implode( ', ', $font['font-style'] ); 
  508.  
  509. if ( ! empty( $font['subset'] ) ) { 
  510. foreach ( $font['subset'] as $subset ) { 
  511. if ( ! in_array( $subset, $subsets ) ) { 
  512. array_push( $subsets, $subset ); 
  513.  
  514. if ( ! empty( $subsets ) ) { 
  515. $link .= "&subset=" . implode( ', ', $subsets ); 
  516.  
  517.  
  518. return '//fonts.googleapis.com/css?family=' . str_replace( '|', '%7C', $link ); 
  519.  
  520. /** 
  521. * makeGoogleWebfontString Function. 
  522. * Creates the google fonts link. 
  523. * @since ReduxFramework 3.1.8 
  524. */ 
  525. function makeGoogleWebfontString( $fonts ) { 
  526. $link = ""; 
  527. $subsets = array(); 
  528.  
  529. foreach ( $fonts as $family => $font ) { 
  530. if ( ! empty( $link ) ) { 
  531. $link .= "', '"; // Append a new font to the string 
  532. $link .= $family; 
  533.  
  534. if ( ! empty( $font['font-style'] ) || ! empty( $font['all-styles'] ) ) { 
  535. $link .= ':'; 
  536. if ( ! empty( $font['all-styles'] ) ) { 
  537. $link .= implode( ', ', $font['all-styles'] ); 
  538. } else if ( ! empty( $font['font-style'] ) ) { 
  539. $link .= implode( ', ', $font['font-style'] ); 
  540.  
  541. if ( ! empty( $font['subset'] ) ) { 
  542. foreach ( $font['subset'] as $subset ) { 
  543. if ( ! in_array( $subset, $subsets ) ) { 
  544. array_push( $subsets, $subset ); 
  545.  
  546. if ( ! empty( $subsets ) ) { 
  547. $link .= "&subset=" . implode( ', ', $subsets ); 
  548.  
  549. return "'" . $link . "'"; 
  550.  
  551. function output() { 
  552. $font = $this->value; 
  553.  
  554. // Shim out old arg to new 
  555. if ( isset( $this->field['all_styles'] ) && ! empty( $this->field['all_styles'] ) ) { 
  556. $this->field['all-styles'] = $this->field['all_styles']; 
  557. unset ( $this->field['all_styles'] ); 
  558.  
  559. // Check for font-backup. If it's set, stick it on a variabhle for 
  560. // later use. 
  561. if ( ! empty( $font['font-family'] ) && ! empty( $font['font-backup'] ) ) { 
  562. $font['font-family'] = str_replace( ', ' . $font['font-backup'], '', $font['font-family'] ); 
  563. $fontBackup = ', ' . $font['font-backup']; 
  564.  
  565. // if (strpos($font['font-family'], ' ')) { 
  566. // $font['font-family'] = '"' . $font['font-family'] . '"'; 
  567. // } 
  568.  
  569. $style = ''; 
  570.  
  571. $fontValueSet = false; 
  572.  
  573. if ( ! empty( $font ) ) { 
  574. foreach ( $font as $key => $value ) { 
  575. if ( ! empty( $value ) && in_array( $key, array( 'font-family', 'font-weight' ) ) ) { 
  576. $fontValueSet = true; 
  577.  
  578. if ( ! empty( $font ) ) { 
  579. foreach ( $font as $key => $value ) { 
  580. if ( $key == 'font-options' ) { 
  581. continue; 
  582. // Check for font-family key 
  583. if ( 'font-family' == $key ) { 
  584.  
  585. // Enclose font family in quotes if spaces are in the 
  586. // name. This is necessary because if there are numerics 
  587. // in the font name, they will not render properly. 
  588. // Google should know better. 
  589. if (strpos($value, ' ') && !strpos($value, ', ')) { 
  590. $value = '"' . $value . '"'; 
  591.  
  592. // Ensure fontBackup isn't empty (we already option 
  593. // checked this earlier. No need to do it again. 
  594. if ( ! empty( $fontBackup ) ) { 
  595.  
  596. // Apply the backup font to the font-family element 
  597. // via the saved variable. We do this here so it 
  598. // doesn't get appended to the Google stuff below. 
  599. $value .= $fontBackup; 
  600.  
  601. if ( empty( $value ) && in_array( $key, array( 
  602. 'font-weight',  
  603. 'font-style' 
  604. ) ) && $fontValueSet == true 
  605. ) { 
  606. $value = "normal"; 
  607.  
  608. if ($key == 'font-weight' && $this->field['font-weight'] == false) { 
  609. continue; 
  610.  
  611. if ($key == 'font-style' && $this->field['font-style'] == false) { 
  612. continue; 
  613.  
  614.  
  615. if ( $key == "google" || $key == "subsets" || $key == "font-backup" || empty( $value ) ) { 
  616. continue; 
  617. $style .= $key . ':' . $value . ';'; 
  618. if ( isset( $this->parent->args['async_typography'] ) && $this->parent->args['async_typography'] ) { 
  619. $style .= 'opacity: 1;visibility: visible;-webkit-transition: opacity 0.24s ease-in-out;-moz-transition: opacity 0.24s ease-in-out;transition: opacity 0.24s ease-in-out;'; 
  620.  
  621. if ( ! empty( $style ) ) { 
  622. if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { 
  623. $keys = implode( ", ", $this->field['output'] ); 
  624. $this->parent->outputCSS .= $keys . "{" . $style . '}'; 
  625. if ( isset( $this->parent->args['async_typography'] ) && $this->parent->args['async_typography'] ) { 
  626. $key_string = ""; 
  627. $key_string_ie = ""; 
  628. foreach ( $this->field['output'] as $value ) { 
  629. $key_string .= ".wf-loading " . $value . ', '; 
  630. $key_string_ie .= ".ie.wf-loading " . $value . ', '; 
  631. $this->parent->outputCSS .= $key_string . "{opacity: 0;}"; 
  632. $this->parent->outputCSS .= $key_string_ie . "{visibility: hidden;}"; 
  633.  
  634. if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { 
  635. $keys = implode( ", ", $this->field['compiler'] ); 
  636. $this->parent->compilerCSS .= $keys . "{" . $style . '}'; 
  637. if ( isset( $this->parent->args['async_typography'] ) && $this->parent->args['async_typography'] ) { 
  638. $key_string = ""; 
  639. $key_string_ie = ""; 
  640. foreach ( $this->field['compiler'] as $value ) { 
  641. $key_string .= ".wf-loading " . $value . ', '; 
  642. $key_string_ie .= ".ie.wf-loading " . $value . ', '; 
  643. $this->parent->compilerCSS .= $key_string . "{opacity: 0;}"; 
  644. $this->parent->compilerCSS .= $key_string_ie . "{visibility: hidden;}"; 
  645.  
  646. // Google only stuff! 
  647. if ( ! empty( $font['font-family'] ) && ! empty( $this->field['google'] ) && filter_var( $this->field['google'], FILTER_VALIDATE_BOOLEAN ) ) { 
  648.  
  649. // Added standard font matching check to avoid output to Google fonts call - kp 
  650. // If no custom font array was supplied, the load it with default 
  651. // standard fonts. 
  652. if ( empty( $this->field['fonts'] ) ) { 
  653. $this->field['fonts'] = $this->std_fonts; 
  654.  
  655. // Ensure the fonts array is NOT empty 
  656. if ( ! empty( $this->field['fonts'] ) ) { 
  657.  
  658. //Make the font keys in the array lowercase, for case-insensitive matching 
  659. $lcFonts = array_change_key_case( $this->field['fonts'] ); 
  660.  
  661. // Rebuild font array with all keys stripped of spaces 
  662. $arr = array(); 
  663. foreach ( $lcFonts as $key => $value ) { 
  664. $key = str_replace( ', ', ', ', $key ); 
  665. $arr[ $key ] = $value; 
  666.  
  667. $lcFonts = array_change_key_case( $this->field['custom_fonts'] ); 
  668. foreach ( $lcFonts as $group => $fontArr ) { 
  669. foreach ( $fontArr as $key => $value ) { 
  670. $arr[ strtolower( $key ) ] = $key; 
  671.  
  672. $lcFonts = $arr; 
  673.  
  674. unset( $arr ); 
  675.  
  676. // lowercase chosen font for matching purposes 
  677. $lcFont = strtolower( $font['font-family'] ); 
  678.  
  679. // Remove spaces after commas in chosen font for mathcing purposes. 
  680. $lcFont = str_replace( ', ', ', ', $lcFont ); 
  681.  
  682. // If the lower cased passed font-family is NOT found in the standard font array 
  683. // Then it's a Google font, so process it for output. 
  684. if ( ! array_key_exists( $lcFont, $lcFonts ) ) { 
  685. $family = $font['font-family']; 
  686.  
  687. // Strip out spaces in font names and replace with with plus signs 
  688. // TODO?: This method doesn't respect spaces after commas, hence the reason 
  689. // for the std_font array keys having no spaces after commas. This could be 
  690. // fixed with RegEx in the future. 
  691. $font['font-family'] = str_replace( ' ', '+', $font['font-family'] ); 
  692.  
  693. // Push data to parent typography variable. 
  694. if ( empty( $this->parent->typography[ $font['font-family'] ] ) ) { 
  695. $this->parent->typography[ $font['font-family'] ] = array(); 
  696.  
  697. if ( isset( $this->field['all-styles'] ) ) { 
  698. if ( ! isset( $font['font-options'] ) || empty( $font['font-options'] ) ) { 
  699. $this->getGoogleArray(); 
  700.  
  701. if ( isset( $this->parent->googleArray ) && ! empty( $this->parent->googleArray ) && isset( $this->parent->googleArray[ $family ] ) ) { 
  702. $font['font-options'] = $this->parent->googleArray[ $family ]; 
  703. } else { 
  704. $font['font-options'] = json_decode( $font['font-options'], true ); 
  705.  
  706. if ( isset( $font['font-options'] ) && ! empty( $font['font-options'] ) && isset( $this->field['all-styles'] ) && filter_var( $this->field['all-styles'], FILTER_VALIDATE_BOOLEAN ) ) { 
  707. if ( isset( $font['font-options'] ) && ! empty( $font['font-options']['variants'] ) ) { 
  708. if ( ! isset( $this->parent->typography[ $font['font-family'] ]['all-styles'] ) || empty( $this->parent->typography[ $font['font-family'] ]['all-styles'] ) ) { 
  709. $this->parent->typography[ $font['font-family'] ]['all-styles'] = array(); 
  710. foreach ( $font['font-options']['variants'] as $variant ) { 
  711. $this->parent->typography[ $font['font-family'] ]['all-styles'][] = $variant['id']; 
  712.  
  713. if ( ! empty( $font['font-weight'] ) ) { 
  714. if ( empty( $this->parent->typography[ $font['font-family'] ]['font-weight'] ) || ! in_array( $font['font-weight'], $this->parent->typography[ $font['font-family'] ]['font-weight'] ) ) { 
  715. $style = $font['font-weight']; 
  716.  
  717. if ( ! empty( $font['font-style'] ) ) { 
  718. $style .= $font['font-style']; 
  719.  
  720. if ( empty( $this->parent->typography[ $font['font-family'] ]['font-style'] ) || ! in_array( $style, $this->parent->typography[ $font['font-family'] ]['font-style'] ) ) { 
  721. $this->parent->typography[ $font['font-family'] ]['font-style'][] = $style; 
  722.  
  723. if ( ! empty( $font['subsets'] ) ) { 
  724. if ( empty( $this->parent->typography[ $font['font-family'] ]['subset'] ) || ! in_array( $font['subsets'], $this->parent->typography[ $font['font-family'] ]['subset'] ) ) { 
  725. $this->parent->typography[ $font['font-family'] ]['subset'][] = $font['subsets']; 
  726. } // !array_key_exists 
  727. } //!empty fonts array 
  728. } // Typography not set 
  729.  
  730. private function localizeStdFonts() { 
  731. if ( false == $this->user_fonts ) { 
  732. if ( isset( $this->parent->fonts['std'] ) && ! empty( $this->parent->fonts['std'] ) ) { 
  733. return; 
  734.  
  735. $this->parent->font_groups['std'] = array( 
  736. 'text' => __( 'Standard Fonts', 'redux-framework' ),  
  737. 'children' => array(),  
  738. ); 
  739.  
  740. foreach ( $this->field['fonts'] as $font => $extra ) { 
  741. $this->parent->font_groups['std']['children'][] = array( 
  742. 'id' => $font,  
  743. 'text' => $font,  
  744. 'data-google' => 'false',  
  745. ); 
  746.  
  747. if ( $this->field['custom_fonts'] !== false ) { 
  748. $this->field['custom_fonts'] = apply_filters( "redux/{$this->parent->args['opt_name']}/field/typography/custom_fonts", array() ); 
  749.  
  750. if ( ! empty( $this->field['custom_fonts'] ) ) { 
  751. foreach ( $this->field['custom_fonts'] as $group => $fonts ) { 
  752. $this->parent->font_groups['customfonts'] = array( 
  753. 'text' => $group,  
  754. 'children' => array(),  
  755. ); 
  756.  
  757. foreach ( $fonts as $family => $v ) { 
  758. $this->parent->font_groups['customfonts']['children'][] = array( 
  759. 'id' => $family,  
  760. 'text' => $family,  
  761. 'data-google' => 'false',  
  762. ); 
  763.  
  764. /** 
  765. * Construct the google array from the stored JSON/HTML 
  766.   
  767. */ 
  768. function getGoogleArray() { 
  769.  
  770. if ( ( isset( $this->parent->fonts['google'] ) && ! empty( $this->parent->fonts['google'] ) ) || isset( $this->parent->fonts['google'] ) && $this->parent->fonts['google'] == false ) { 
  771. return; 
  772.  
  773. $gFile = dirname( __FILE__ ) . '/googlefonts.php'; 
  774.  
  775. // Weekly update 
  776. if ( isset( $this->parent->args['google_update_weekly'] ) && $this->parent->args['google_update_weekly'] && ! empty( $this->parent->args['google_api_key'] ) ) { 
  777.  
  778. if ( file_exists( $gFile ) ) { 
  779. // Keep the fonts updated weekly 
  780. $weekback = strtotime( date( 'jS F Y', time() + ( 60 * 60 * 24 * - 7 ) ) ); 
  781. $last_updated = filemtime( $gFile ); 
  782. if ( $last_updated < $weekback ) { 
  783. unlink( $gFile ); 
  784.  
  785. if ( ! file_exists( $gFile ) ) { 
  786.  
  787. $result = wp_remote_get( apply_filters( 'redux-google-fonts-api-url', 'https://www.googleapis.com/webfonts/v1/webfonts?key=' ) . $this->parent->args['google_api_key'], array( 'sslverify' => false ) ); 
  788.  
  789. if ( ! is_wp_error( $result ) && $result['response']['code'] == 200 ) { 
  790. $result = json_decode( $result['body'] ); 
  791. foreach ( $result->items as $font ) { 
  792. $this->parent->googleArray[ $font->family ] = array( 
  793. 'variants' => $this->getVariants( $font->variants ),  
  794. 'subsets' => $this->getSubsets( $font->subsets ) 
  795. ); 
  796.  
  797. if ( ! empty( $this->parent->googleArray ) ) { 
  798. $this->parent->filesystem->execute( 'put_contents', $gFile, array( 'content' => "<?php return json_decode( '" . json_encode( $this->parent->googleArray ) . "', true );" ) ); 
  799.  
  800. if ( ! file_exists( $gFile ) ) { 
  801. $this->parent->fonts['google'] = false; 
  802.  
  803. return; 
  804.  
  805. if ( ! isset( $this->parent->fonts['google'] ) || empty( $this->parent->fonts['google'] ) ) { 
  806.  
  807. $fonts = include $gFile; 
  808.  
  809. if ( $fonts === true ) { 
  810. $this->parent->fonts['google'] = false; 
  811.  
  812. return; 
  813.  
  814. if ( isset( $fonts ) && ! empty( $fonts ) && is_array( $fonts ) && $fonts != false ) { 
  815. $this->parent->fonts['google'] = $fonts; 
  816. $this->parent->googleArray = $fonts; 
  817.  
  818. // optgroup 
  819. $this->parent->font_groups['google'] = array( 
  820. 'text' => __( 'Google Webfonts', 'redux-framework' ),  
  821. 'children' => array(),  
  822. ); 
  823.  
  824. // options 
  825. foreach ( $this->parent->fonts['google'] as $font => $extra ) { 
  826. $this->parent->font_groups['google']['children'][] = array( 
  827. 'id' => $font,  
  828. 'text' => $font,  
  829. 'data-google' => 'true' 
  830. ); 
  831.  
  832. /** 
  833. * getSubsets Function. 
  834. * Clean up the Google Webfonts subsets to be human readable 
  835. * @since ReduxFramework 0.2.0 
  836. */ 
  837. private function getSubsets( $var ) { 
  838. $result = array(); 
  839.  
  840. foreach ( $var as $v ) { 
  841. if ( strpos( $v, "-ext" ) ) { 
  842. $name = ucfirst( str_replace( "-ext", " Extended", $v ) ); 
  843. } else { 
  844. $name = ucfirst( $v ); 
  845.  
  846. array_push( $result, array( 
  847. 'id' => $v,  
  848. 'name' => $name 
  849. ) ); 
  850.  
  851. return array_filter( $result ); 
  852. } //function 
  853.  
  854. /** 
  855. * getVariants Function. 
  856. * Clean up the Google Webfonts variants to be human readable 
  857. * @since ReduxFramework 0.2.0 
  858. */ 
  859. private function getVariants( $var ) { 
  860. $result = array(); 
  861. $italic = array(); 
  862.  
  863. foreach ( $var as $v ) { 
  864. $name = ""; 
  865. if ( $v[0] == 1 ) { 
  866. $name = 'Ultra-Light 100'; 
  867. } else if ( $v[0] == 2 ) { 
  868. $name = 'Light 200'; 
  869. } else if ( $v[0] == 3 ) { 
  870. $name = 'Book 300'; 
  871. } else if ( $v[0] == 4 || $v[0] == "r" || $v[0] == "i" ) { 
  872. $name = 'Normal 400'; 
  873. } else if ( $v[0] == 5 ) { 
  874. $name = 'Medium 500'; 
  875. } else if ( $v[0] == 6 ) { 
  876. $name = 'Semi-Bold 600'; 
  877. } else if ( $v[0] == 7 ) { 
  878. $name = 'Bold 700'; 
  879. } else if ( $v[0] == 8 ) { 
  880. $name = 'Extra-Bold 800'; 
  881. } else if ( $v[0] == 9 ) { 
  882. $name = 'Ultra-Bold 900'; 
  883.  
  884. if ( $v == "regular" ) { 
  885. $v = "400"; 
  886.  
  887. if ( strpos( $v, "italic" ) || $v == "italic" ) { 
  888. $name .= " Italic"; 
  889. $name = trim( $name ); 
  890. if ( $v == "italic" ) { 
  891. $v = "400italic"; 
  892. $italic[] = array( 
  893. 'id' => $v,  
  894. 'name' => $name 
  895. ); 
  896. } else { 
  897. $result[] = array( 
  898. 'id' => $v,  
  899. 'name' => $name 
  900. ); 
  901.  
  902. foreach ( $italic as $item ) { 
  903. $result[] = $item; 
  904.  
  905. return array_filter( $result ); 
  906. } //function 
  907. } //class