You are here

class FrxDocument in Forena Reports 7.3

Same name and namespace in other branches
  1. 7.4 FrxDocument.inc \FrxDocument

@file FrxDocument.inc Given a report, render the appropriate output given the document format. @author davidmetzler

Hierarchy

Expanded class hierarchy of FrxDocument

File

./FrxDocument.inc, line 8
FrxDocument.inc Given a report, render the appropriate output given the document format. @author davidmetzler

View source
class FrxDocument {
  public $format;
  public $content_type = '';
  public $charset = 'UTF-8';
  public function loadCSSFiles($format) {

    // Add css files
    $css = '';
    foreach (Frx::Skin()->stylesheets as $type => $sheets) {
      foreach ($sheets as $sheet) {
        switch ($type) {
          case 'all':
          case $format:
            $css .= file_get_contents($sheet);
            break;
        }
      }
    }
    return $css;
  }

  // All document objects must implement this method.
  public function render($r, $format, $options = array()) {
    $header = '<h1>' . $r->title . '</h1>';
    $output = $header . $output;
    $css_text = '';
    $r_text = '';
    $stylesheets = Frx::Skin()->stylesheets;
    foreach ($stylesheets as $type => $sheets) {
      foreach ($sheets as $sheet) {
        switch ($type) {
          case 'all':
          case $this->format:
            $css_file[] = $sheet;
            break;
        }
      }
    }
    if ($css_files) {
      foreach ($css_files as $css_file) {
        $css_text .= file_get_contents($css_file);
      }
    }
    $options = array(
      'css' => $css_text,
      'docname' => str_replace(' ', '_', $title),
      'xml' => $r_text,
      'title' => $title,
    );
    $output = $this
      ->generate_doc($format, $output, $options, $print);
    if ($format != 'email') {
      print $output;
    }
  }
  public function output($output) {
    if ($this->content_type) {
      header('Content-Type: ' . $this->content_type . ' ;charset=' . $this->charset);
      header('Cache-Control:');
      header('Pragma:');
      $file_name = basename($_GET['q']);
      header('Content-Disposition: attachment; filename="' . $file_name . '"');
      header('Cache-Control: must-revalidate');
      print $output;
      return TRUE;
    }
    else {
      return FALSE;
    }
  }

  /**
   * Wrapper function for check output to default the right type.
   * @param $output
   */
  public function check_markup($output) {
    return check_markup($output, variable_get('forena_input_format', filter_default_format()));
  }
  public function convertCharset($data, $default_encoding = 'UTF-8') {
    if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
      $parts = @explode(';', $_SERVER['HTTP_ACCEPT_CHARSET']);
      $parts = @explode(',', $parts[0]);
      $to_encoding = @$parts[0];
    }
    else {
      $to_encoding = $default_encoding;
    }
    if ($to_encoding != 'UTF-8') {
      $this->charset = $to_encoding;
      $data = mb_convert_encoding($data, $to_encoding, 'UTF-8');
    }
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrxDocument::$charset public property
FrxDocument::$content_type public property
FrxDocument::$format public property
FrxDocument::check_markup public function Wrapper function for check output to default the right type.
FrxDocument::convertCharset public function
FrxDocument::loadCSSFiles public function
FrxDocument::output public function 9
FrxDocument::render public function 10