You are here

function follow_save_css in Follow 7.2

Save the Follow module generated CSS.

5 calls to follow_save_css()
follow_block_save in ./follow.module
Implements hook_block_save().
follow_css in ./follow.module
Menu callback to generate Follow module CSS.
follow_install in ./follow.install
Implements hook_install().
follow_update_7004 in ./follow.install
Rename the alignment and link style variables to have 'site' in the name.
_follow_links_element in ./follow.inc
Helper function to build a follow links element.

File

./follow.inc, line 23
Follow module API and helper functions.

Code

function follow_save_css($reset = FALSE) {

  // Destination where the file will be saved.
  $destination = 'public://css/follow.css';

  // Delete stale CSS file if necessary.
  if (file_exists($destination)) {
    drupal_delete_file_if_stale($destination);
  }

  // If reset is FALSE and the file exists, do nothing.
  if (!$reset && file_exists($destination)) {
    return TRUE;
  }

  // We have to prepare the directory, in case it doesn't exist.
  $directory = 'public://css';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY);

  // Clean out any existing aggregated CSS files.
  file_scan_directory($directory, '/.*/', array(
    'callback' => 'file_unmanaged_delete',
  ));

  // Generate a new CSS/JS token since we just wiped the CSS dir.
  _drupal_flush_css_js();

  // Load up the styles for each follow link type.
  $site_style = variable_get('follow_site_icon_style', 'small');
  $user_style = variable_get('follow_user_icon_style', 'small');
  $site_hide_text = variable_get('follow_site_hide_text', FALSE);
  $user_hide_text = variable_get('follow_user_hide_text', FALSE);
  $contents = "/**\n * This CSS file is generated by Follow module. DO NOT edit it directly.\n * Instead, copy the file to your theme's CSS directory and edit it there.\n */\n\n";
  $variables = array(
    'icon_style_name' => $site_style,
    'hide_text' => $site_hide_text,
  );
  $contents .= theme('follow_css', $variables);

  // If the user style is different, append it to our contents, with a selector
  // prefix to override the previous styles.
  if ($site_style != $user_style || $site_hide_text != $user_hide_text) {
    $variables = array(
      'icon_style_name' => $user_style,
      'hide_text' => $user_hide_text,
      'selector_prefix' => '.follow-links.user',
    );
    $contents .= theme('follow_css', $variables);
  }
  return file_unmanaged_save_data($contents, $destination, FILE_EXISTS_REPLACE);
}