示例#1
0
<?php

class HeadwayGoogleFonts extends HeadwayWebFontProvider
{
    public $id = 'google';
    public $name = 'Google Web Fonts';
    public $webfont_provider = 'google';
    public $load_with_ajax = true;
    public $sorting_options = array('popularity' => 'Popularity', 'trending' => 'Trending', 'alpha' => 'Alphabetically', 'date' => 'Date Added', 'style' => 'Style');
    protected $api_url = 'http://headwaythemes.com/api/google-fonts';
    protected $backup_api_url = 'http://cdn.headwaythemes.com/api/google-fonts';
    public function query_fonts($sortby = 'date', $retry = false)
    {
        $fonts_query = wp_remote_get(add_query_arg(array('license' => headway_get_license_key(), 'sortby' => $sortby), trailingslashit($this->api_url)), array('timeout' => 20));
        /* If the original query to Headway cannot connect, find a way to proxy to Headway's CDN */
        if (is_wp_error($fonts_query)) {
            $fonts_query = wp_remote_get($this->backup_api_url . '/' . headway_get_license_key() . '/' . $sortby, array('timeout' => 20));
        }
        return json_decode(wp_remote_retrieve_body($fonts_query), true);
    }
}
headway_register_web_font_provider('HeadwayGoogleFonts');
        echo '</div><!-- .fonts-list -->';
    }
}
class HeadwayFonts
{
    public static $fonts = array('georgia' => 'Georgia', 'cambria' => 'Cambria', 'palatino' => 'Palatino', 'times' => 'Times', 'times new roman' => 'Times New Roman', 'arial' => 'Arial', 'arial black' => 'Arial Black', 'arial narrow' => 'Arial Narrow', 'century gothic' => 'Century Gothic', 'gill sans' => 'Gill Sans', 'helvetica' => 'Helvetica', 'impact' => 'Impact', 'lucida grande' => 'Lucida Grande', 'tahoma' => 'Tahoma', 'trebuchet ms' => 'Trebuchet MS', 'verdana' => 'Verdana', 'courier' => 'Courier', 'courier new' => 'Courier New', 'papyrus' => 'Papyrus', 'copperplate' => 'Copperplate');
    public static $font_stacks = array('georgia' => 'georgia, serif', 'cambria' => 'cambria, georgia, serif', 'palatino' => 'palatino linotype, palatino, serif', 'times' => 'times, serif', 'times new roman' => 'times new roman, serif', 'arial' => 'arial, sans-serif', 'arial black' => 'arial black, sans-serif', 'arial narrow' => 'arial narrow, sans-serif', 'century gothic' => '\'Century Gothic\', CenturyGothic, AppleGothic, sans-serif', 'gill sans' => 'gill sans, sans-serif', 'helvetica' => 'helvetica, sans-serif', 'impact' => 'impact, sans-serif', 'lucida grande' => 'lucida grande, sans-serif', 'tahoma' => 'tahoma,  sans-serif', 'trebuchet ms' => 'trebuchet ms,  sans-serif', 'verdana' => 'verdana, sans-serif', 'courier' => 'courier, monospace', 'courier new' => 'courier new, monospace', 'papyrus' => 'papyrus, fantasy', 'copperplate' => 'copperplate, copperplate gothic bold, fantasy');
    public static function get_fonts()
    {
        return apply_filters('headway_fonts', self::$fonts);
    }
    public static function get_stack($font_id)
    {
        return headway_get($font_id, apply_filters('headway_fonts_stacks', self::$font_stacks));
    }
    public static function register_font(array $args)
    {
        extract($args);
        /* Check args */
        if (!isset($id) || !isset($stack) || !isset($name)) {
            return new WP_Error('hw_fonts_register_font_invalid_args', __('To register a font, the argument array must include an "id", "stack", and "name".', 'headway'), $args);
        }
        /* Add the font to the stacks first */
        self::$font_stacks[$id] = $stack;
        /* Add the font */
        self::$fonts[$id] = $name;
        return true;
    }
}
headway_register_web_font_provider('HeadwayTraditionalFonts');