[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/panels/plugins/display_renderers/ -> panels_renderer_legacy.class.php (source)

   1  <?php
   2  
   3  /**
   4   * Legacy render pipeline for a panels display.
   5   *
   6   * This render pipeline mirrors the old procedural system exactly, and plugins
   7   * written for the legacy system will work exactly as they did before with this
   8   * renderer.
   9   *
  10   * Most plugins will work with the newer renderer. These are the exceptions:
  11   *  - Style plugins that implement panel styling no longer need to call
  12   *    panels_render_pane() on all contained panes; rendered pane HTML is now
  13   *    passed in directly.
  14   *  - Cache plugins are now triggered on rendered HTML, rather than on
  15   *    unrendered datastructures, when acting at the display level. When acting
  16   *    at the pane level, they still receive the unrendered datastructure.
  17   *
  18   * If your site relies on any of these plugin behaviors, you will need to use
  19   * this renderer instead of the new panels_renderer_standard() until those
  20   * plugins are updated.
  21   */
  22  class panels_renderer_legacy {
  23    var $meta_location = 'standard';
  24  
  25    var $display;
  26    var $plugins = array();
  27  
  28    /**
  29     * Include rendered HTML prior to the layout.
  30     *
  31     * @var string
  32     */
  33    var $prefix = '';
  34  
  35    /**
  36     * Include rendered HTML after the layout.
  37     *
  38     * @var string
  39     */
  40    var $suffix = '';
  41  
  42    function init($plugin, &$display) {
  43      $this->plugin = $plugin;
  44      $this->plugins['layout'] = panels_get_layout($display->layout);
  45      if (empty($this->plugins['layout'])) {
  46        watchdog('panels', "Layout: @layout couldn't been found, maybe the theme is disabled.", array('@layout' => $display->layout));
  47      }
  48      $this->display = &$display;
  49    }
  50  
  51    /**
  52     * Add CSS information to the renderer.
  53     *
  54     * To facilitate previews over Views, CSS can now be added in a manner
  55     * that does not necessarily mean just using drupal_add_css. Therefore,
  56     * during the panel rendering process, this method can be used to add
  57     * css and make certain that ti gets to the proper location.
  58     *
  59     * The arguments should exactly match drupal_add_css().
  60     *
  61     * @see drupal_add_css
  62     */
  63    function add_css($filename, $type = 'module', $media = 'all', $preprocess = TRUE) {
  64      $path = file_create_path($filename);
  65      switch ($this->meta_location) {
  66        case 'standard':
  67          if ($path) {
  68            // Use CTools CSS add because it can handle temporary CSS in private
  69            // filesystem.
  70            ctools_include('css');
  71            ctools_css_add_css($filename, $type, $media, $preprocess);
  72          }
  73          else {
  74            drupal_add_css($filename, $type, $media, $preprocess);
  75          }
  76          break;
  77        case 'inline':
  78          if ($path) {
  79            $url = file_create_url($filename);
  80          }
  81          else {
  82            $url = base_path() . $filename;
  83          }
  84  
  85          $this->prefix .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . $url . '" />'."\n";
  86          break;
  87      }
  88    }
  89  
  90    /**
  91     * Builds inner content, then hands off to layout-specified theme function for
  92     * final render step.
  93     *
  94     * This is the outermost method in the Panels render pipeline. It calls the
  95     * inner methods, which return a content array, which is in turn passed to the
  96     * theme function specified in the layout plugin.
  97     *
  98     * @return string
  99     *  Themed & rendered HTML output.
 100     */
 101    function render() {
 102      if (!empty($this->plugins['layout']['css'])) {
 103        if (file_exists(path_to_theme() . '/' . $this->plugins['layout']['css'])) {
 104          drupal_add_css(path_to_theme() . '/' . $this->plugins['layout']['css']);
 105        }
 106        else {
 107          drupal_add_css($this->plugins['layout']['path'] . '/' . $this->plugins['layout']['css']);
 108        }
 109      }
 110      // This now comes after the CSS is added, because panels-within-panels must
 111      // have their CSS added in the right order; inner content before outer content.
 112  
 113      if (empty($this->display->cache['method']) || !empty($this->display->skip_cache)) {
 114        $content = $this->render_regions();
 115      }
 116      else {
 117        $cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context);
 118        if ($cache === FALSE) {
 119          $cache = new panels_cache_object();
 120          $cache->set_content($this->render_regions());
 121          panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context);
 122        }
 123        $content = $cache->content;
 124      }
 125  
 126      $output = theme($this->plugins['layout']['theme'], check_plain($this->display->css_id), $content, $this->display->layout_settings, $this->display, $this->plugins['layout'], $this);
 127  
 128      return $this->prefix . $output . $this->suffix;
 129    }
 130  
 131    /**
 132     * Render all panes in the attached display into their panel regions, then
 133     * render those regions.
 134     *
 135     * @return array $content
 136     *    An array of rendered panel regions, keyed on the region name.
 137     */
 138    function render_regions() {
 139      ctools_include('content');
 140  
 141      // First, render all the panes into little boxes. We do this here because
 142      // some panes request to be rendered after other panes (primarily so they
 143      // can do the leftovers of forms).
 144      $panes = $first = $normal = $last = array();
 145  
 146      foreach ($this->display->content as $pid => $pane) {
 147        $pane->shown = !empty($pane->shown); // guarantee this field exists.
 148        // If the user can't see this pane, do not render it.
 149        if (!$pane->shown || !panels_pane_access($pane, $this->display)) {
 150          continue;
 151        }
 152  
 153        $content_type = ctools_get_content_type($pane->type);
 154  
 155        // If this pane wants to render last, add it to the $last array. We allow
 156        // this because some panes need to be rendered after other panes,
 157        // primarily so they can do things like the leftovers of forms.
 158        if (!empty($content_type['render last'])) {
 159          $last[$pid] = $pane;
 160        }
 161        // If it wants to render first, add it to the $first array. This is used
 162        // by panes that need to do some processing before other panes are
 163        // rendered.
 164        else if (!empty($content_type['render first'])) {
 165          $first[$pid] = $pane;
 166        }
 167        // Otherwise, render it in the normal order.
 168        else {
 169          $normal[$pid] = $pane;
 170        }
 171      }
 172  
 173      foreach (($first + $normal + $last) as $pid => $pane) {
 174        $panes[$pid] = $this->render_pane($pane);
 175      }
 176  
 177      // Loop through all panels, put all panes that belong to the current panel
 178      // in an array, then render the panel. Primarily this ensures that the
 179      // panes are in the proper order.
 180      $content = array();
 181      foreach ($this->display->panels as $panel_name => $pids) {
 182        $panel_panes = array();
 183        foreach ($pids as $pid) {
 184          if (!empty($panes[$pid])) {
 185            $panel_panes[$pid] = $panes[$pid];
 186          }
 187        }
 188        $content[$panel_name] = $this->render_region($panel_name, $panel_panes);
 189      }
 190  
 191      // Prevent notices by making sure that all panels at least have an entry:
 192      $panels = panels_get_regions($this->plugins['layout'], $this->display);
 193      foreach ($panels as $id => $panel) {
 194        if (!isset($content[$id])) {
 195          $content[$id] = NULL;
 196        }
 197      }
 198  
 199      return $content;
 200    }
 201  
 202    /**
 203     * Render the contents of a single pane.
 204     *
 205     * This method retrieves pane content and produces a ready-to-render content
 206     * object. It also manages pane-specific caching.
 207     *
 208     * @param stdClass $pane
 209     *    A Panels pane object, as loaded from the database.
 210     */
 211    function render_pane(&$pane) {
 212      ctools_include('context');
 213      if (!is_array($this->display->context)) {
 214        $this->display->context = array();
 215      }
 216  
 217      $content = FALSE;
 218      $caching = !empty($pane->cache['method']) && empty($this->display->skip_cache);
 219      if ($caching && ($cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context, $pane))) {
 220        $content = $cache->content;
 221      }
 222      else {
 223        $content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, array(), $this->display->args, $this->display->context);
 224        foreach (module_implements('panels_pane_content_alter') as $module) {
 225          $function = $module . '_panels_pane_content_alter';
 226          $function($content, $pane, $this->display->args, $this->display->context);
 227        }
 228        if ($caching) {
 229          $cache = new panels_cache_object();
 230          $cache->set_content($content);
 231          panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context, $pane);
 232          $content = $cache->content;
 233        }
 234      }
 235  
 236      // Pass long the css_id that is usually available.
 237      if (!empty($pane->css['css_id'])) {
 238        $content->css_id = $pane->css['css_id'];
 239      }
 240  
 241      // Pass long the css_class that is usually available.
 242      if (!empty($pane->css['css_class'])) {
 243        $content->css_class = $pane->css['css_class'];
 244      }
 245  
 246      return $content;
 247    }
 248  
 249    /**
 250     * Render a single panel region.
 251     *
 252     * Primarily just a passthrough to the panel region rendering callback
 253     * specified by the style plugin that is attached to the current panel region.
 254     *
 255     * @param $region_name
 256     *   The ID of the panel region being rendered
 257     * @param $panes
 258     *   An array of panes that are assigned to the panel that's being rendered.
 259     *
 260     * @return
 261     *   The rendered HTML for the passed-in panel region.
 262     */
 263    function render_region($region_name, $panes) {
 264      list($style, $style_settings) = panels_get_panel_style_and_settings($this->display->panel_settings, $region_name);
 265      $callback = 'render panel';
 266  
 267      // Retrieve the pid (can be a panel page id, a mini panel id, etc.), this
 268      // might be used (or even necessary) for some panel display styles.
 269      $owner_id = 0;
 270      if (isset($this->display->owner) && is_object($this->display->owner) && isset($this->display->owner->id)) {
 271        $owner_id = $this->display->owner->id;
 272      }
 273  
 274      // Check to see if we're actually running a current style plugin even though
 275      // we're in the legacy renderer
 276      if (version_compare($style['version'], 2.0, '>=')) {
 277        // We are, so pre-render the content as the current version expects
 278        foreach($panes as $pane_id => $pane) {
 279          $content = panels_render_pane($pane, $this->display->content[$pane_id], $this->display);
 280          if ($content) {
 281            $panes[$pane_id] = $content;
 282          }
 283          else {
 284            unset($panes[$pane_id]);
 285          }
 286        }
 287        // And set the callback to the new key
 288        $callback = 'render region';
 289  
 290      }
 291  
 292      return theme($style[$callback], $this->display, $owner_id, $panes, $style_settings, $region_name, $style);
 293    }
 294  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7