You are here

function _media_install_copy_icons in D7 Media 7.3

Same name and namespace in other branches
  1. 7.4 media.install \_media_install_copy_icons()
  2. 7.2 media.install \_media_install_copy_icons()

Copy the media file icons to files directory for use with image styles.

2 calls to _media_install_copy_icons()
media_install in ./media.install
Implements hook_install().
media_update_7217 in ./media.install
Copy file type icons to public files directory.

File

./media.install, line 32
Install, update and uninstall functions for the Media module.

Code

function _media_install_copy_icons() {
  $destination = variable_get('media_icon_base_directory', 'public://media-icons') . '/' . variable_get('media_icon_set', 'default');
  if (!file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS || FILE_CREATE_DIRECTORY)) {
    throw new Exception("Unable to create directory {$destination}.");
  }

  // @todo If we ever add another default icon set, this should copy all images from one directory up.
  $source = drupal_get_path('module', 'media') . '/images/icons/' . variable_get('media_icon_set', 'default');
  $files = file_scan_directory($source, '/.*\\.(png|jpg)$/');
  foreach ($files as $file) {
    $result = file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_REPLACE);
    if (!$result) {
      throw new Exception("Unable to copy {$file->uri} to {$destination}.");
    }
  }
}