/** * * Construct the google array from the stored JSON/HTML * */ function getGoogleArray() { global $wp_filesystem; if (isset($this->parent->fonts['google']) && !empty($this->parent->fonts['google'])) { return; } if (isset($this->field['update_weekly']) && $this->field['update_weekly'] === true && $this->field['google'] === true && !empty($this->parent->args['google_api_key'])) { //if (file_exists(ReduxFramework::$_dir . 'inc/fields/typography/googlefonts.html')) { if (file_exists($this->google_html)) { // Keep the fonts updated weekly $weekback = strtotime(date('jS F Y', time() + 60 * 60 * 24 * -7)); //$last_updated = filemtime(ReduxFramework::$_dir . 'inc/fields/typography/googlefonts.html'); $last_updated = filemtime($this->google_html); if ($last_updated < $weekback) { //unlink(ReduxFramework::$_dir . 'inc/fields/typography/googlefonts.html'); unlink($this->google_html); //unlink(ReduxFramework::$_dir . 'inc/fields/typography/googlefonts.json'); unlink($this->google_json); } } } // Initialize the Wordpress filesystem, no more using file_put_contents function if (empty($wp_filesystem)) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); } //if (!file_exists(ReduxFramework::$_dir . 'inc/fields/typography/googlefonts.json')) { if (!file_exists($this->google_json)) { $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)); if (!is_wp_error($result) && $result['response']['code'] == 200) { $result = json_decode($result['body']); foreach ($result->items as $font) { $this->parent->googleArray[$font->family] = array('variants' => $this->getVariants($font->variants), 'subsets' => $this->getSubsets($font->subsets)); } if (!empty($this->parent->googleArray)) { //$wp_filesystem->put_contents(ReduxFramework::$_dir . 'inc/fields/typography/googlefonts.json', json_encode($this->parent->googleArray), FS_CHMOD_FILE $wp_filesystem->put_contents($this->google_json, json_encode($this->parent->googleArray), FS_CHMOD_FILE); } } //if } //if if (!isset($this->parent->fonts['google']) || empty($this->parent->fonts['google'])) { //$fonts = json_decode($wp_filesystem->get_contents(ReduxFramework::$_dir . 'inc/fields/typography/googlefonts.json'), true); $fonts = json_decode($wp_filesystem->get_contents($this->google_json), true); // Fallback if file_get_contents won't work for wordpress. MEDIATEMPLE if (empty($fonts)) { $fonts = Redux_Helpers::curlRead($this->google_json); } if (isset($fonts) && !empty($fonts) && is_array($fonts) && $fonts != false) { $this->parent->fonts['google'] = $fonts; $this->parent->font_groups['google'] = array('id' => 'google', 'text' => __('Google Webfonts', 'redux-framework'), 'children' => array()); foreach ($this->parent->fonts['google'] as $font => $extra) { $this->parent->font_groups['google']['children'][] = array('id' => $font, 'text' => $font); } } } }
/** * * Construct the google array from the stored JSON/HTML * */ function getGoogleArray() { global $wp_filesystem; // Is already present? if (isset($this->parent->fonts['google']) && !empty($this->parent->fonts['google'])) { return; } // Weekly update if (isset($this->field['update_weekly']) && $this->field['update_weekly'] === true && $this->field['google'] === true && !empty($this->parent->args['google_api_key'])) { if (file_exists($this->google_json)) { // Keep the fonts updated weekly $weekback = strtotime(date('jS F Y', time() + 60 * 60 * 24 * -7)); $last_updated = filemtime($this->google_json); if ($last_updated < $weekback) { unlink($this->google_json); } } } // Initialize the Wordpress filesystem, no more using file_put_contents function Redux_Functions::initWpFilesystem(); if (!file_exists($this->google_json)) { $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)); if (!is_wp_error($result) && $result['response']['code'] == 200) { $result = json_decode($result['body']); foreach ($result->items as $font) { $this->parent->googleArray[$font->family] = array('variants' => $this->getVariants($font->variants), 'subsets' => $this->getSubsets($font->subsets)); } if (!empty($this->parent->googleArray)) { $wp_filesystem->put_contents($this->google_json, json_encode($this->parent->googleArray), FS_CHMOD_FILE); } } //if } if (!isset($this->parent->fonts['google']) || empty($this->parent->fonts['google'])) { $fonts = json_decode($wp_filesystem->get_contents($this->google_json), true); // Fallback if file_get_contents won't work for wordpress. MEDIATEMPLE if (empty($fonts)) { $fonts = Redux_Helpers::curlRead($this->google_json); } if (isset($fonts) && !empty($fonts) && is_array($fonts) && $fonts != false) { $this->parent->fonts['google'] = $fonts; $this->parent->googleArray = $fonts; // optgroup $this->parent->font_groups['google'] = array('text' => __('Google Webfonts', 'redux-framework'), 'children' => array()); // options foreach ($this->parent->fonts['google'] as $font => $extra) { $this->parent->font_groups['google']['children'][] = array('id' => $font, 'text' => $font, 'data-google' => 'true'); } } } }