You are here

function skinr_skin_get_files in Skinr 6.2

Helper function to fetch all css or js files from an array of skins.

Parameters

$skins: A an array of available skins.

$type: Either 'css' or 'js', depending on which files you wish to retrieve from these skins.

$theme: The theme from which to grab these files. Defaults to the current theme.

Return value

An array of file data.

2 calls to skinr_skin_get_files()
skinr_skin_extract in ./skinr.module
skinr_ui_skin_get_files in ./skinr_ui.module
AJAX Callback function to fetch all css or js files from a particular skin.

File

./skinr.module, line 161

Code

function skinr_skin_get_files($skins, $type, $theme = NULL) {
  if (empty($theme)) {
    $theme = skinr_current_theme();
  }
  $info = skinr_skin_data();
  $files = array();
  if ($type == 'css') {
    foreach ($skins as $skin => $classes) {

      // Add custom CSS files.
      if (isset($info[$theme]->skins[$skin])) {
        if (!empty($info[$theme]->skins[$skin]['stylesheets'])) {
          foreach ($info[$theme]->skins[$skin]['stylesheets'] as $media => $stylesheets) {
            foreach ($stylesheets as $file => $path) {
              $files[] = array(
                'file' => $file,
                'path' => $path,
                'media' => $media,
                'enabled' => TRUE,
                'skin' => $skin,
                'options' => 0,
              );
            }
          }
        }
        foreach ($info[$theme]->skins[$skin]['options'] as $option_id => $option) {
          if (!empty($option['stylesheets'])) {
            foreach ($option['stylesheets'] as $media => $stylesheets) {
              foreach ($stylesheets as $file => $path) {
                $enabled = FALSE;
                if (is_array($classes)) {
                  if (in_array($option['class'], $classes)) {
                    $enabled = TRUE;
                  }
                }
                else {
                  if ($option['class'] == $classes) {
                    $enabled = TRUE;
                  }
                }
                $files[] = array(
                  'file' => $file,
                  'path' => $path,
                  'media' => $media,
                  'enabled' => $enabled,
                  'skin' => $skin,
                  'options' => $option_id,
                );
              }
            }
          }
        }
      }
    }
  }
  elseif ($type == 'js') {
    foreach ($skins as $skin => $classes) {

      // Add custom JS files.
      if (isset($info[$theme]->skins[$skin])) {
        if (isset($info[$theme]->skins[$skin]['scripts'])) {
          foreach ($info[$theme]->skins[$skin]['scripts'] as $file => $path) {
            $files[] = array(
              'file' => $file,
              'path' => $path,
              'enabled' => TRUE,
              'skin' => $skin,
              'options' => 0,
            );
          }
        }
        foreach ($info[$theme]->skins[$skin]['options'] as $option_id => $option) {
          if (isset($option['scripts'])) {
            foreach ($option['scripts'] as $file => $path) {
              $enabled = FALSE;
              if (is_array($classes)) {
                if (in_array($option['class'], $classes)) {
                  $enabled = TRUE;
                }
              }
              else {
                if ($option['class'] == $classes) {
                  $enabled = TRUE;
                }
              }
              $files[] = array(
                'file' => $file,
                'path' => $path,
                'enabled' => $enabled,
                'skin' => $skin,
                'options' => $option_id,
              );
            }
          }
        }
      }
    }
  }
  return $files;
}