You are here

class panels_cache_object in Panels 6.2

Same name and namespace in other branches
  1. 5.2 includes/plugins.inc \panels_cache_object
  2. 6.3 includes/plugins.inc \panels_cache_object
  3. 7.3 includes/plugins.inc \panels_cache_object

An object to hold caching information while it is happening.

Hierarchy

Expanded class hierarchy of panels_cache_object

Related topics

File

includes/plugins.inc, line 628
plugins.inc

View source
class panels_cache_object {
  var $content = '';
  var $head = NULL;
  var $css = NULL;
  var $js = NULL;
  var $ready = FALSE;

  /**
   * When constructed, take a snapshot of our existing out of band data.
   */
  function panels_cache_object() {
    $this->head = drupal_set_html_head();
    $this->css = drupal_add_css();
    foreach (array(
      'header',
      'footer',
    ) as $scope) {
      $this->js[$scope] = drupal_add_js(NULL, NULL, $scope);
    }
  }

  /**
   * Add content to the cache. This assumes a pure stream;
   * use set_content() if it's something else.
   */
  function add_content($content) {
    $this->content .= $content;
  }
  function set_content($content) {
    $this->content = $content;
  }

  /**
   * Set the object for storing. This overwrites.
   */
  function cache() {
    if ($this->ready) {
      return;
    }
    $this->ready = TRUE;

    // Simple replacement for head
    $this->head = str_replace($this->head, '', drupal_set_html_head());

    // Slightly less simple for CSS:
    $css = drupal_add_css();
    $start = $this->css;
    $this->css = array();
    foreach ($css as $media => $medias) {
      foreach ($medias as $type => $types) {
        foreach ($types as $path => $preprocess) {
          if (!isset($start[$media][$type][$path])) {
            $this->css[] = array(
              $path,
              $type,
              $media,
              $preprocess,
            );
          }
        }
      }
    }
    $js = array();

    // A little less simple for js
    foreach (array(
      'header',
      'footer',
    ) as $scope) {
      $js[$scope] = drupal_add_js(NULL, NULL, $scope);
    }
    $start = $this->js;
    $this->js = array();
    foreach ($js as $scope => $scopes) {
      foreach ($scopes as $type => $types) {
        foreach ($types as $id => $info) {
          if (!isset($start[$scope][$type][$id])) {
            switch ($type) {
              case 'setting':
                $this->js[] = array(
                  $info,
                  $type,
                  $scope,
                );
                break;
              case 'inline':
                $this->js[] = array(
                  $info['code'],
                  $type,
                  $scope,
                  $info['defer'],
                );
                break;
              default:
                $this->js[] = array(
                  $id,
                  $type,
                  $scope,
                  $info['defer'],
                  $info['cache'],
                );
            }
          }
        }
      }
    }
  }

  /**
   * Restore out of band data saved to cache.
   */
  function restore() {
    if (!empty($this->head)) {
      drupal_set_html_head($this->head);
    }
    if (!empty($this->css)) {
      foreach ($this->css as $args) {
        call_user_func_array('drupal_add_css', $args);
      }
    }
    if (!empty($this->js)) {
      foreach ($this->js as $args) {
        call_user_func_array('drupal_add_js', $args);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
panels_cache_object::$content property
panels_cache_object::$css property
panels_cache_object::$head property
panels_cache_object::$js property
panels_cache_object::$ready property
panels_cache_object::add_content function Add content to the cache. This assumes a pure stream; use set_content() if it's something else.
panels_cache_object::cache function Set the object for storing. This overwrites.
panels_cache_object::panels_cache_object function When constructed, take a snapshot of our existing out of band data.
panels_cache_object::restore function Restore out of band data saved to cache.
panels_cache_object::set_content function