You are here

function _google_fonts_cache in Google Fonts 7

Same name and namespace in other branches
  1. 7.2 google_fonts.module \_google_fonts_cache()

Create the CSS file and store it locally.

2 calls to _google_fonts_cache()
google_fonts_admin_settings_form_submit in ./google_fonts.admin.inc
Submit handler of the admin settings form Saves the fonts, CSS code and settings
_google_fonts_add_custom_css in ./google_fonts.module

File

./google_fonts.module, line 201
This module enables Google Fonts on your website.

Code

function _google_fonts_cache($file_contents, $reset = FALSE) {
  $file_destination = 'public://google_fonts.css';
  if ((!file_exists($file_destination) || $reset) && !empty($file_contents)) {

    // Append a comment in the CSS code
    $file_contents = '/* CSS code for the Google Fonts module */' . PHP_EOL . $file_contents;

    // Save as a file (unmanaged) and return it
    $file = file_unmanaged_save_data($file_contents, $file_destination, FILE_EXISTS_REPLACE);

    // Set standard file permissions for webserver-generated files.
    drupal_chmod($file);
    return TRUE;
  }
  else {
    return $file_destination;
  }
}