You are here

function panels_views_all_views_render in Panels 6.2

Output function for the 'views' content type.

Outputs a view based on the module and delta supplied in the configuration.

1 string reference to 'panels_views_all_views_render'
panels_views_panels_content_types in panels_views/panels_views.module
Implementation of hook_panels_content_types()

File

panels_views/panels_views.module, line 99
panels_views.module

Code

function panels_views_all_views_render($subtype, $conf, $panel_args, $contexts) {
  if (!is_array($contexts)) {
    $contexts = array(
      $contexts,
    );
  }
  list($name, $display) = explode('-', $subtype);
  $view = views_get_view($name);
  if (empty($view)) {
    return;
  }
  $view
    ->set_display($display);
  if (!$view->display_handler
    ->access($GLOBALS['user'])) {
    return;
  }
  $arguments = explode('/', $_GET['q']);
  $args = $conf['args'];
  foreach ($arguments as $id => $arg) {
    $args = str_replace("%{$id}", $arg, $args);
  }
  foreach ($panel_args as $id => $arg) {
    $args = str_replace("@{$id}", $arg, $args);
  }
  $args = preg_replace(',/?(%\\d|@\\d),', '', $args);
  $args = $args ? explode('/', $args) : array();
  if ($conf['panel_args'] && is_array($panel_args)) {
    $args = array_merge($panel_args, $args);
  }
  if (is_array($conf['context'])) {
    foreach ($conf['context'] as $count => $cid) {
      if ($cid != 'any' && !empty($contexts[$count]) && isset($contexts[$count]->argument)) {
        array_splice($args, $count, 0, array(
          $contexts[$count]->argument,
        ));
      }
    }
  }
  $view
    ->set_arguments($args);
  if ($conf['url']) {
    $view->display_handler
      ->set_option('path', $conf['url']);
  }
  $block = new stdClass();
  $block->module = 'views';
  $block->delta = $view->name . $display;
  $block->subject = $view
    ->get_title();
  if (!empty($conf['link_to_view'])) {
    $block->title_link = $view
      ->get_url();
  }
  if (!empty($conf['more_link'])) {
    $block->more = array(
      'href' => $view
        ->get_url(),
    );
    $view->display_handler
      ->set_option('use_more', FALSE);
  }
  $view->display_handler
    ->set_option('use_pager', $conf['use_pager']);
  $view->display_handler
    ->set_option('pager_element', $conf['pager_id']);
  $view->display_handler
    ->set_option('items_per_page', $conf['nodes_per_page']);
  $view->display_handler
    ->set_option('offset', $conf['offset']);
  $stored_feeds = drupal_add_feed();
  $block->content = $view
    ->preview();
  if (!empty($conf['feed_icons'])) {
    $new_feeds = drupal_add_feed();
    if ($diff = array_diff(array_keys($new_feeds), array_keys($stored_feeds))) {
      foreach ($diff as $url) {
        $block->feeds[$url] = $new_feeds[$url];
      }
    }
  }
  return $block;
}