You are here

function fontyourface_save_font in @font-your-face 7.2

Same name and namespace in other branches
  1. 8.3 fontyourface.module \fontyourface_save_font()
  2. 6.2 fontyourface.module \fontyourface_save_font()
  3. 7 fontyourface.module \fontyourface_save_font()

Adds or updates font, depending on whether it already exists.

15 calls to fontyourface_save_font()
edge_fonts_fontyourface_import in modules/edge_fonts/edge_fonts.module
Implements hook_fontyourface_import().
fontdeck_fontyourface_import in modules/fontdeck/fontdeck.module
Implements hook_fontyourface_import().
fontsquirrel_batch_import in modules/fontsquirrel/fontsquirrel.module
Batch processing function - import font variants.
fontsquirrel_fontyourface_enable in modules/fontsquirrel/fontsquirrel.module
Implements hook_fontyourface_enable().
fontsquirrel_fontyourface_import in modules/fontsquirrel/fontsquirrel.module
Implements hook_fontyourface_import().

... See full list

File

./fontyourface.module, line 429

Code

function fontyourface_save_font(&$font, $revert = FALSE) {
  $tags = array();
  if (!empty($font->tags)) {
    $tags = $font->tags;
    unset($font->tags);
  }
  $exists = db_query("SELECT fid FROM {fontyourface_font} WHERE url = :url", array(
    ':url' => $font->url,
  ))
    ->fetchObject();
  if ($exists) {
    $existing_font = fontyourface_get_font($exists->fid);
    $font->fid = $existing_font->fid;
    if (!$revert) {

      // Keep status, selector, and tags the same.
      $font->enabled = $existing_font->enabled;
      $font->css_selector = $existing_font->css_selector;
    }
    fontyourface_add_font_tags($font);
    drupal_write_record('fontyourface_font', $font, 'fid');
    $tags = $font->tags;
  }
  else {
    drupal_write_record('fontyourface_font', $font);
  }

  // else
  db_delete('fontyourface_tag_font')
    ->condition('fid', $font->fid)
    ->execute();
  if (!is_array($tags)) {
    $tags = array();
  }

  // if
  fontyourface_add_tags_to_font($tags, $font->fid);
  $font->tags = $tags;
}