You are here

public function Sweaver::get_current_style in Sweaver 7

Same name and namespace in other branches
  1. 6 sweaver.inc \Sweaver::get_current_style()

Return a style for a theme.

Parameters

$theme: The machine name of the theme.

$reset: Whether to reset the current $css variable or not.

Return value

$css The css definition for this theme.

File

./sweaver.inc, line 167
Class Sweaver.

Class

Sweaver
@file Class Sweaver.

Code

public function get_current_style($reset = FALSE) {
  $run =& drupal_static('run', FALSE);
  $css =& drupal_static('css', FALSE);
  if (!$run || $reset) {
    $run = TRUE;
    if (sweaver_session(NULL, 'sweaver_temp')) {
      ctools_include('object-cache');
      $css = ctools_object_cache_get('sweaver-styling', 'sweaver-styling');
      if (!isset($css->style_id)) {
        $css = new stdClass();
      }
      $css->type = 'draft';
    }
    elseif (sweaver_session(NULL, 'draft_mode')) {
      $table = sweaver_session(NULL, 'loaded_table') == 'live' ? 'sweaver_style' : 'sweaver_style_draft';
      $css = db_query("SELECT * FROM {" . $table . "} where style_id = :style_id", array(
        ':style_id' => sweaver_session(NULL, 'loaded_style'),
      ))
        ->fetchObject();
      if (!isset($css->style_id)) {
        $css = new stdClass();
      }
      $css->type = 'draft';
    }
    else {
      $css = db_query("SELECT * FROM {sweaver_style} where theme = :theme and active = 1", array(
        ':theme' => $this->theme,
      ))
        ->fetchObject();
      if (!isset($css->style_id)) {
        $css = new stdClass();
      }
      $css->type = 'live';
    }

    // We check if the style can be loaded on this page
    if (isset($css->pages)) {
      $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
      $css->pages = drupal_strtolower($css->pages);
      $page_match = drupal_match_path($path, $css->pages);
      if ($path != $_GET['q']) {
        $page_match = $page_match || drupal_match_path($_GET['q'], $css->pages);
      }
      $page_match = !($css->visibility xor $page_match);
      if (!$page_match) {
        $css = NULL;
      }
    }
    if (!isset($css->style_id)) {
      $css = NULL;
    }
  }
  $this->style = $css;
  return $css;
}