Export content in various formats

@return Void
550346
public function exportAction() {
        $mem = new Garp_Util_Memory();
        $mem->useHighMemory();

        $params = new Garp_Util_Configuration($this->getRequest()->getParams());
        // make sure some required parameters are in place
        $params->obligate('exporttype')
            ->obligate('model')
            ->obligate('selection')
            ->setDefault('fields', Zend_Db_Select::SQL_WILDCARD);

        // fetch exporter
        $exporter = Garp_Content_Export_Factory::getExporter($params['exporttype']);
        $bytes = $exporter->getOutput($params);
        $filename = $exporter->getFilename($params);

        $download = Zend_Controller_Action_HelperBroker::getStaticHelper('download');
        $download->force($bytes, $filename, $this->_response);
        $this->_helper->viewRenderer->setNoRender();
    }
1333425
public function prepare_package() {
        global $DB;

        $format = $this->exporter->get('format');
        $content = self::entry_content($this->course, $this->cm, $this->glossary, $this->entry, $this->aliases, $format);

        if ($this->exporter->get('formatclass') === PORTFOLIO_FORMAT_PLAINHTML) {
            $filename = clean_filename($this->entry->concept) . '.html';
            $this->exporter->write_new_file($content, $filename);

        } else if ($this->exporter->get('formatclass') === PORTFOLIO_FORMAT_RICHHTML) {
            if ($this->multifiles) {
                foreach ($this->multifiles as $file) {
                    $this->exporter->copy_existing_file($file);
                }
            }
            $filename = clean_filename($this->entry->concept) . '.html';
            $this->exporter->write_new_file($content, $filename);

        } else if ($this->exporter->get('formatclass') === PORTFOLIO_FORMAT_LEAP2A) {
            $writer = $this->get('exporter')->get('format')->leap2a_writer();
            $entry = new portfolio_format_leap2a_entry('glossaryentry' . $this->entry->id, $this->entry->concept, 'entry', $content);
            $entry->author = $DB->get_record('user', array('id' => $this->entry->userid), 'id,firstname,lastname,email');
            $entry->published = $this->entry->timecreated;
            $entry->updated = $this->entry->timemodified;
            if ($this->multifiles) {
                $writer->link_files($entry, $this->multifiles);
                foreach ($this->multifiles as $file) {
                    $this->exporter->copy_existing_file($file);
                }
            }
            if ($this->categories) {
                foreach ($this->categories as $cat) {
                    // this essentially treats them as plain tags
                    // leap has the idea of category schemes
                    // but I think this is overkill here
                    $entry->add_category($cat->name);
                }
            }
            $writer->add_entry($entry);
            $content = $writer->to_xml();
            $filename = $this->get('exporter')->get('format')->manifest_name();
            $this->exporter->write_new_file($content, $filename);

        } else {
            throw new portfolio_caller_exception('unexpected_format_class', 'glossary');
        }
    }
685221
protected function exportInternal()
    {
        // Read the TypoScript rendering configuration for the given content record
        if ($this->config !== null) {
            $this->template = '10 = RECORDS'.PHP_EOL.TypoScriptUtility::serialize('', [10 => $this->config]);
        }

        return parent::exportInternal();
    }
1088604
protected function exportDownload()
    {
        $this->view->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $batch = $this->loader->getTaskRunnerBatch('export_surveys');
        $file = $batch->getSessionVariable('file');
        foreach($file['headers'] as $header) {
            header($header);
        }
        while (ob_get_level()) {
            ob_end_clean();
        }
        readfile($file['file']);
        // Now clean up the file
        unlink($file['file']);

        exit;
    }
874004
protected function createOutputContents()
    {
        $dom = $this->formatterInstance()
                    ->forge(
                        $this->rows,
                        $this->rootElementName,
                        $this->replaceSpacesByUnderScoresInKeyNames,
                        $this->versionOfXmlDeclaration,
                        $this->encodingOfXmlDeclaration
                    )->toDom();

        $dom->formatOutput = $this->formatOutput;

        return $dom->saveXML();
    }
425672
private function exportTables()
    {
        // Exporting tables one by one
        foreach ($this->tables as $table) {
            if ($this->matches($table, $this->dumpSettings['exclude-tables'])) {
                continue;
            }
            $this->getTableStructure($table);
            if (false === $this->dumpSettings['no-data']) { // don't break compatibility with old trigger
                $this->listValues($table);
            } elseif (true === $this->dumpSettings['no-data']
                 || $this->matches($table, $this->dumpSettings['no-data'])) {
                continue;
            } else {
                $this->listValues($table);
            }
        }
    }
887548
public function exportAction()
    {
        $cwd = getcwd();
        if (substr($cwd, -3) === 'web') {
            chdir($cwd . DIRECTORY_SEPARATOR . '..');
        }

        $output = ['error' => false];

        if ($this->get('ongr_translations.command.export')->run(new ArrayInput([]), new NullOutput()) != 0) {
            $output['error'] = true;
        }

        return new JsonResponse($output);
    }
289469
protected function export_format($contents)
	{
		if ( ! function_exists('spyc_load'))
		{
			import('spyc/spyc', 'vendor');
		}

		$this->prep_vars($contents);
		return \Spyc::YAMLDump($contents);
	}
996807
protected function sendHttpHeaders(): void
    {
        // grab content disposition
        $disposition = $this->opt->getContentDisposition();

        if ($this->output_name) {
            // Various different browsers dislike various characters here. Strip them all for safety.
            $safe_output = trim(str_replace(['"', "'", '\\', ';', "\n", "\r"], '', $this->output_name));

            // Check if we need to UTF-8 encode the filename
            $urlencoded = rawurlencode($safe_output);
            $disposition .= "; filename*=UTF-8''{$urlencoded}";
        }

        $headers = array(
            'Content-Type' => $this->opt->getContentType(),
            'Content-Disposition' => $disposition,
            'Pragma' => 'public',
            'Cache-Control' => 'public, must-revalidate',
            'Content-Transfer-Encoding' => 'binary'
        );

        $call = $this->opt->getHttpHeaderCallback();
        foreach ($headers as $key => $val) {
            $call("$key: $val");
        }
    }
1181904
public function export() : array
    {
        return array_combine(
            $this->keys,
            array_map(function ($f) {
                return $this->getField($f);
            }, $this->keys)
        );
    }
840558
public function exportAction()
	{
		$cntl = $this->createAdmin();

		if( ( $html = $cntl->export() ) == '' ) {
			return $this->setPsrResponse( $cntl->getView()->response() );
		}

		$this->view->assign( 'content', $html );
	}
1314044
public function exportFiles($content)
    {
        $uploadFiles = [];
        if ($content) {
            $dom = new DOMDocument;
            libxml_use_internal_errors(true);
            $dom->loadHTML($content);
            $tags = ['a' => 'href', 'img' => 'src'];
            foreach ($tags as $tag => $attribute) {
                foreach ($dom->getElementsByTagName($tag) as $node) {
                    $uploadFiles[] = $node->getAttribute($attribute);
                }
            }
            foreach ($uploadFiles as $k => $uploadFile) {
                if (strpos($uploadFile, '/uploads/') === 0 || strpos($uploadFile, URL::to('/')) === 0) {
                    $uploadFiles[$k] = str_replace(URL::to('/'), '', parse_url($uploadFile, PHP_URL_PATH));
                } else {
                    unset($uploadFiles[$k]);
                }
            }
        }
        return $uploadFiles;
    }
549606
protected function exportViews()
    {
        foreach ($this->views as $key => $value) {
            if (file_exists($view = $this->getViewPath($value)) && ! $this->option('force')) {
                if (! $this->confirm("The [{$value}] view already exists. Do you want to replace it?")) {
                    continue;
                }
            }

            copy(
                __DIR__.'/stubs/make/views/'.$key,
                $view
            );
        }
    }
467887
public function export()
    {
        // moved initialization of subject here because of the following issue
        // https://github.com/yiisoft/yii2/issues/1446
        if (empty($this->message['subject'])) {
            $this->message['subject'] = 'Application Log';
        }

        $module = Module::getInstance();
        $this->message['from'] = $module->flagEmail($this->message['from']);
        $this->message['subject'] = $module->flagText($this->message['subject']);

        $messages = array_map([$this, 'formatMessage'], $this->messages);
        $body = $this->getDebugLogLink();
        $body .= implode("\n", $messages);
        $this->composeMessage($body)->send($this->mailer);
    }
680471
public function export()
    {
        $text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";
        if (($fp = @fopen($this->logFile, 'a')) === false) {
            throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
        }
        @flock($fp, LOCK_EX);
        if ($this->enableRotation) {
            // clear stat cache to ensure getting the real current file size and not a cached one
            // this may result in rotating twice when cached file size is used on subsequent calls
            clearstatcache();
        }
        if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
            $this->rotateFiles();
            @flock($fp, LOCK_UN);
            @fclose($fp);
            @file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX);
        } else {
            @fwrite($fp, $text);
            @flock($fp, LOCK_UN);
            @fclose($fp);
        }
        if ($this->fileMode !== null) {
            @chmod($this->logFile, $this->fileMode);
        }
    }
677530
public function export($request)
    {
        $dataClass = $this->dataRecord->getDataClass();
        $resultColumns = $this->dataRecord->getDataSingleton()->fieldLabels();

        // Used for the browser, not stored on the server
        $filepath = sprintf('export-%s.csv', date('Y-m-dHis'));

        // Allocates up to 1M of memory storage to write to, then will fail over to a temporary file on the filesystem
        $handle = fopen('php://temp/maxmemory:' . (1024 * 1024), 'w');

        $cols = array_keys($resultColumns);

        // put the headers in the first row
        fputcsv($handle, $cols);

        // put the data in the rows after
        foreach ($this->RegistryEntries(false) as $result) {
            $item = [];
            foreach ($cols as $col) {
                $item[] = $result->$col;
            }
            fputcsv($handle, $item);
        }

        rewind($handle);

        // if the headers can't be sent (i.e. running a unit test, or something)
        // just return the file path so the user can manually download the csv
        if (!headers_sent() && $this->config()->get('output_headers')) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=' . $filepath);
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . fstat($handle)['size']);
            ob_clean();
            flush();

            echo stream_get_contents($handle);

            fclose($handle);
        } else {
            $contents = stream_get_contents($handle);
            fclose($handle);

            return $contents;
        }
    }
1033287
public function export_headers()
    {
        $header_string = '';
        foreach ($this->headers as $header => $value) {
            $header_string .= "$header: $value\n";
        }
        $poified = self::poify($header_string);
        if ($this->comments_before_headers) {
            $before_headers = self::prepend_each_line(
                rtrim($this->comments_before_headers) . "\n",
                '# '
            );
        } else {
            $before_headers = '';
        }

        return rtrim("{$before_headers}msgid \"\"\nmsgstr $poified");
    }