You are here

function local_fonts_delete_font in @font-your-face 7.2

Same name and namespace in other branches
  1. 7 modules/local_fonts/local_fonts.module \local_fonts_delete_font()

Deletes given font.

1 call to local_fonts_delete_font()
local_fonts_delete_form_submit in modules/local_fonts/local_fonts.module
Handles submission of delete form.

File

modules/local_fonts/local_fonts.module, line 421

Code

function local_fonts_delete_font($font) {

  // Bail out if attempting to delete a non-local font.
  if ($font->provider != 'local_fonts') {
    drupal_set_message(t('This is not a local font and cannot be deleted.'));
    return TRUE;
  }

  // if
  $metadata = unserialize($font->metadata);
  $directory = dirname($metadata['path']);

  // Delete all the files.
  $files = scandir($directory);
  foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
      unlink($directory . '/' . $file);
    }

    // if
  }

  // foreach
  // Delete the directory.
  rmdir($directory);

  // Delete from the database.
  db_delete('fontyourface_font')
    ->condition('fid', $font->fid)
    ->execute();
  fontyourface_delete_unused_tags();
  return TRUE;
}