%PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 49.231.201.246 / Your IP : 216.73.216.149 Web Server : Apache/2.4.18 (Ubuntu) System : Linux 246 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : root ( 0) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/11584/task/11584/cwd/html/egp/vendor/kartik-v/yii2-grid/src/controllers/ |
Upload File : |
<?php /** * @package yii2-grid * @author Kartik Visweswaran <kartikv2@gmail.com> * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2020 * @version 3.3.6 */ namespace kartik\grid\controllers; use Yii; use yii\base\InvalidCallException; use yii\base\InvalidConfigException; use yii\helpers\Json; use yii\web\Controller; use yii\web\Response; use kartik\base\Config; use kartik\grid\GridView; use kartik\mpdf\Pdf; use kartik\grid\Module; /** * ExportController manages actions for downloading the [[GridView]] tabular content in various export formats. * * @author Kartik Visweswaran <kartikv2@gmail.com> * @since 1.0 */ class ExportController extends Controller { /** * Download the exported file * * @return mixed * @throws \yii\base\InvalidConfigException */ public function actionDownload() { /** * @var Module $module */ $request = Yii::$app->request; $moduleId = $request->post('module_id', Module::MODULE); $module = Config::getModule($moduleId, Module::class); $type = $request->post('export_filetype', 'html'); $name = $request->post('export_filename', Yii::t('kvgrid', 'export')); $content = $request->post('export_content', Yii::t('kvgrid', 'No data found')); $mime = $request->post('export_mime', 'text/plain'); $encoding = $request->post('export_encoding', 'utf-8'); $bom = $request->post('export_bom', 1); $hashConfig = $request->post('hash_export_config', 0); $hashConfig = empty($hashConfig) ? 0 : 1; $config = $request->post('export_config', '{}'); $cfg = empty($hashConfig) ? '' : $config; $oldHash = $request->post('export_hash'); $newData = $moduleId . $name . $mime . $encoding . $bom . $hashConfig . $cfg; $security = Yii::$app->security; $salt = $module->exportEncryptSalt; $newHash = $security->hashData($newData, $salt); if (!$security->validateData($oldHash, $salt) || $oldHash !== $newHash) { $params = "\nOld Hash:{$oldHash}\nNew Hash:{$newHash}\n"; throw new InvalidCallException("The parameters for yii2-grid export seem to be tampered. Please retry!{$params}"); } if ($type == GridView::PDF) { $config = Json::decode($config); return $this->generatePDF($content, "{$name}.pdf", $config); } elseif ($type == GridView::CSV || $type == GridView::TEXT) { if ($encoding != 'utf-8') { $content = mb_convert_encoding($content, $encoding, 'utf-8'); } elseif ($bom) { $content = chr(239) . chr(187) . chr(191) . $content; // add BOM } } $this->setHttpHeaders($type, $name, $mime, $encoding); return $content; } /** * Generates the PDF file * * @param string $content the file content * @param string $filename the file name * @param array $config the configuration for yii2-mpdf component * * @return Response * @throws InvalidConfigException */ protected function generatePDF($content, $filename, $config = []) { unset($config['contentBefore'], $config['contentAfter']); $config['filename'] = $filename; $config['methods']['SetAuthor'] = [Yii::t('kvgrid', 'Krajee Solutions')]; $config['methods']['SetCreator'] = [Yii::t('kvgrid', 'Krajee Yii2 Grid Export Extension')]; $config['content'] = $content; $pdf = new Pdf($config); return $pdf->render(); } /** * Sets the HTTP headers needed by file download action. * * @param string $type the file type * @param string $name the file name * @param string $mime the mime time for the file * @param string $encoding the encoding for the file content */ protected function setHttpHeaders($type, $name, $mime, $encoding = 'utf-8') { $response = Yii::$app->response; $response->format = Response::FORMAT_RAW; $headers = $response->getHeaders(); $headers->set('Content-Type', "{$mime}; charset={$encoding}"); $headers->set('Content-Transfer-Encoding', $encoding); $headers->set('Cache-Control', 'public, must-revalidate, max-age=0'); $headers->set('Pragma', 'public'); $headers->set('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT'); $headers->set('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT'); $headers->set('Content-Disposition', "attachment; filename={$name}.{$type}"); } }