You are here

function views_data_export_plugin_style_export::generate_filename in Views data export 7.4

Same name and namespace in other branches
  1. 7.3 plugins/views_data_export_plugin_style_export.inc \views_data_export_plugin_style_export::generate_filename()

Generate the filename for the export.

1 call to views_data_export_plugin_style_export::generate_filename()
views_data_export_plugin_style_export::add_http_headers in plugins/views_data_export_plugin_style_export.inc
Add any HTTP headers that this style plugin wants to.

File

plugins/views_data_export_plugin_style_export.inc, line 461
Plugin include file for export style plugin.

Class

views_data_export_plugin_style_export
Generalized style plugin for export plugins.

Code

function generate_filename() {
  $view = $this->view;
  $filename = '';
  if (isset($this->options['filename']) && !empty($this->options['provide_file'])) {

    // General tokens.
    $tokens = array(
      '%view' => check_plain($view->name),
      '%display' => check_plain($view->current_display),
    );

    // Argument tokens.
    $count = 0;
    foreach ($view->display_handler
      ->get_handlers('argument') as $arg => $handler) {
      $token = '%' . ++$count;
      $tokens[$token . '-title'] = $handler
        ->get_title();
      $tokens[$token . '-value'] = isset($view->args[$count - 1]) ? check_plain($view->args[$count - 1]) : '';
    }

    // Effective exposed filters token.
    $exposed = array();
    foreach ($view->display_handler
      ->get_handlers('filter') as $arg => $handler) {
      if (!$handler->options['exposed']) {
        continue;
      }
      if (!empty($view->exposed_input[$handler->options['expose']['identifier']])) {
        $identifier = $handler->options['expose']['identifier'];
        $option = $view->exposed_input[$identifier];

        // The option may be a string or an array, depending on whether the
        // widget is a text box/area or a select box.
        if (is_array($option)) {
          $option = implode('--', $option);
        }
        $exposed[] = check_plain($identifier) . '_' . check_plain($option);
      }
    }
    if (!empty($exposed)) {
      $tokens['%exposed'] = implode('-', $exposed);
    }
    else {
      $tokens['%exposed'] = 'default';
    }

    // Timestamp token.
    $time = REQUEST_TIME;
    $parts = array(
      'full' => 'Y-m-d\\TH-i-s',
      'yy' => 'y',
      'yyyy' => 'Y',
      'mm' => 'm',
      'mmm' => 'M',
      'dd' => 'd',
      'ddd' => 'D',
      'hh' => 'H',
      'ii' => 'i',
      'ss' => 's',
    );
    foreach ($parts as $part => $format) {
      $tokens['%timestamp-' . $part] = format_date($time, 'custom', $format);
    }
    $filename = strtr($this->options['filename'], $tokens);
  }
  return $filename;
}