public function json_list_google_fonts() { $model = new Upfront_Model_GoogleFonts(); $fonts = $model->get_all(); $response = !empty($fonts) ? new Upfront_JsonResponse_Success($fonts) : new Upfront_JsonResponse_Error("Cache error"); $this->_out($response); }
function prepare_typography_styles($layout, $grid) { $typography = $layout->get_property_value('typography'); if (!$typography) { return ''; } $out = ''; $faces = array(); foreach ($typography as $element => $properties) { $properties = wp_parse_args($properties, array('font_face' => false, 'weight' => false, 'style' => false, 'size' => false, 'line_height' => false, 'color' => false)); $face = !empty($properties['font_face']) ? $properties['font_face'] : false; $faces[] = array('face' => $face, 'weight' => $properties['weight']); if (!empty($face) && false !== strpos($face, ' ')) { $face = '"' . $face . '"'; } $font = $properties['font_face'] ? "{$face}, {$properties['font_family']}" : "inherit"; $out .= ".upfront-output-object {$element} {\n" . "font-family: {$font};\n" . ($properties['weight'] ? "font-weight: {$properties['weight']};\n" : "") . ($properties['style'] ? "font-style: {$properties['style']};\n" : "") . ($properties['size'] ? "font-size: {$properties['size']}px;\n" : "") . ($properties['line_height'] ? "line-height: {$properties['line_height']}em;\n" : "") . "color: {$properties['color']};\n" . "}\n"; } // Responsive/breakpoint typography $breakpoints = $grid->get_breakpoints(); $tablet_typography; foreach ($breakpoints as $breakpoint) { // Ignore default/desktop breakpoint as we store it separately if ($breakpoint->is_default()) { continue; } $breakpoint_css = ''; // Breakpoint's typography should load (inherit) like this: // - if there is no typography for current breakpoint it should inherit settings from // wider one, if wider one is not defined inherit from one above, last one is default // typography // - in case of widest (tablet for now) it should inherit from default typography $breakpoint_id = $breakpoint->get_id(); $typography = $breakpoint->get_typography(); if ($breakpoint_id === 'tablet') { $tablet_typography = $typography; // needed for mobile } if (empty($typography) || false === isset($typography['h2'])) { switch ($breakpoint_id) { case 'tablet': $layout_properties = Upfront_ChildTheme::get_instance()->getLayoutProperties(); $value = upfront_get_property_value('typography', array('properties' => $layout_properties)); $typography = $value; break; case 'mobile': if (empty($tablet_typography)) { $layout_properties = Upfront_ChildTheme::get_instance()->getLayoutProperties(); $value = upfront_get_property_value('typography', array('properties' => $layout_properties)); $typography = $value; } else { $typography = $tablet_typography; } break; } } foreach ($typography as $element => $properties) { $properties = wp_parse_args($properties, array('font_face' => 'Arial', 'weight' => '400', 'style' => 'normal', 'size' => '16px', 'line_height' => '1.3', 'color' => 'black', 'font_family' => 'sans-serif')); $faces[] = array('face' => $properties['font_face'], 'weight' => $properties['weight']); $font = $properties['font_face'] ? "{$properties['font_face']}, {$properties['font_family']}" : "inherit"; $breakpoint_css .= ".upfront-output-object {$element} {\n" . "font-family: {$font};\n" . ($properties['weight'] ? "font-weight: {$properties['weight']};\n" : "") . ($properties['style'] ? "font-style: {$properties['style']};\n" : "") . ($properties['size'] ? "font-size: {$properties['size']}px;\n" : "") . ($properties['line_height'] ? "line-height: {$properties['line_height']}em;\n" : "") . "color: {$properties['color']};\n" . "}\n"; } $out .= $breakpoint->wrap($breakpoint_css, $breakpoints); } // Include Google fonts $faces = array_values(array_filter(array_unique($faces, SORT_REGULAR))); $google_fonts = new Upfront_Model_GoogleFonts(); $imports = ''; foreach ($faces as $face) { if (!$google_fonts->is_from_google($face['face'])) { continue; } $imports .= "@import \"https://fonts.googleapis.com/css?family=" . preg_replace('/\\s/', '+', $face['face']); if (400 !== (int) $face['weight'] && 'inherit' !== $face['weight']) { $imports .= ':' . $face['weight']; } $imports .= "\";\n"; } if (!empty($imports)) { $out = "{$imports}\n\n{$out}"; } $out = apply_filters('upfront_prepare_typography_styles', $out); return $out; }