diff --git a/select/taxonomy-dropdown-custom-control.php b/select/taxonomy-dropdown-custom-control.php index 8833d43..902371f 100644 --- a/select/taxonomy-dropdown-custom-control.php +++ b/select/taxonomy-dropdown-custom-control.php @@ -1,69 +1,113 @@ options = $options; - + $this->fonts = $this->get_fonts(); parent::__construct( $manager, $id, $args ); } - /** - * Render the control's content. - * - * Allows the content to be overriden without having to rewrite the wrapper. - * - * @since 11/14/2012 - * @return void - */ - public function render_content() + /** + * Render the content of the category dropdown + * + * @return HTML + */ + public function render_content() { - // call wp_dropdown_cats to get data and add to select field - add_action( 'wp_dropdown_cats', array( $this, 'wp_dropdown_cats' ) ); - - // Set defaults - $this->defaults = array( - 'show_option_none' => __( 'None' ), - 'orderby' => 'name', - 'hide_empty' => 0, - 'id' => $this->id, - 'selected' => $this->value() - ); - - // parse defaults and user data - $cats = wp_parse_args( - $this->options, - $this->defaults - ); - - ?> - - fonts)) + { + ?> + + +
The font list is empty.
+ get_link(), $output ); + global $wp_filesystem; + // Initialize the WP filesystem, no more using 'file-put-contents' function + if (empty($wp_filesystem)) { + require_once (ABSPATH . '/wp-admin/includes/file.php'); + WP_Filesystem(); + } + + $selectDirectory = get_stylesheet_directory().'/tbnframework/admin/options/customizer-custon-controls/select/'; + $selectDirectoryInc = get_template_directory().'/tbnframework/admin/options/customizer-custon-controls/select/'; + + $finalselectDirectory = ''; + + if(is_dir($selectDirectory)) + { + $finalselectDirectory = $selectDirectory; + } + + if(is_dir($selectDirectoryInc)) + { + $finalselectDirectory = $selectDirectoryInc; + } + + $fontFile = $finalselectDirectory . '/cache/google-web-fonts.txt'; + + //Total time the file will be cached in seconds, set to 180 days + $cachetime = 86400 * 180; + if(file_exists($fontFile) && time() - $cachetime < filemtime($fontFile)) + { + $content = json_decode($wp_filesystem->get_contents($fontFile)); + } else { + $Api = 'AIzaSyCWMkc4xnpZZVE5HUG3CAAq8X8lrs5HhKQ'; + $googleApi = 'https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key='.$Api; + + $fontContent = wp_remote_get( $googleApi, array('sslverify' => false) ); + + if( $wp_filesystem ) { + $wp_filesystem->put_contents( + $fontFile, + $fontContent['body'], + FS_CHMOD_FILE // predefined mode settings for WP files + ); + } - return $output; + $content = json_decode($fontContent['body']); + } + if( !empty($content->items) ) { + if($amount == 'all') { + return $content->items; + } else { + return array_slice($content->items, 0, $amount); + } + } else { + return false; + } } -} -?> \ No newline at end of file + } +?>