/** * Show the requestet file and calculate headers * * @param string $filename * @return mixed */ public function show($filename) { $path = getUploadDirectory() . '/' . $filename . '/default'; if (Storage::exists($path)) { clearstatcache(); $file = Storage::get($path); $lastModified = filemtime(storage_path('/app/') . $path); $etagFile = md5_file(storage_path('/app/') . $path); $etagHeader = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false; $responseCode = 200; if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified || $etagHeader == $etagFile) { $responseCode = 304; } return response($file, $responseCode)->header('Content-Type', getFileContentTypeByFilename($filename))->header('Last-Modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT')->header('Etag', $etagFile)->header('Cache-Control', 'public'); } abort(404); }
/** * Get full file path * * @return string */ protected function getFilePath() { return storage_path('/app/') . getUploadDirectory() . '/' . $this->filename . '/default'; }
/** * Tries to match the PlantUML given as argument against the cache. * If the picture has not been rendered before, it'll * try to render the PlantUML and drop it in the picture cache directory. * Embedded links will be expanded into a image map file with the same * name, but extension ".cmapx". When found, it will be included in the * results. * * @param string model in been format * @returns an array with four elements: * 'src': the webserver based URL to a picture which contains the * requested PlantUML model. If anything fails, this value is * false. * 'file': the full pathname to the file containing the image map data * when present. When no map data is present, this value is empty. * 'map': the rendered HTML-fragment for an image map. Empty when not * needed. * 'mapid': the unique id for the rendered image map , useable for further * HTML-rendering. */ function getImage($PlantUML_Source, $argv, $parser = null) { global $plantumlImagetype; global $usecloud; // Compute hash $title_hash = md5(getPageTitle($parser)); $formula_hash = md5($PlantUML_Source); $filename_prefix = 'uml-' . $title_hash . "-" . $formula_hash; $dirname = getUploadDirectory(); $full_path_prefix = $dirname . "/" . $filename_prefix; $result = array('mapid' => $formula_hash, 'src' => false, 'map' => '', 'file' => ''); $imgFile = $dirname . "/" . $filename_prefix . ".{$plantumlImagetype}"; // Check cache. When found, reuse it. When not, generate image. // Honor the redraw tag as found in <uml redraw> if (is_file($imgFile) and !array_key_exists('redraw', $argv)) { $result['file'] = $imgFile; } else { if ($usecloud) { $result['file'] = renderPlantUML_cloud($PlantUML_Source, $imgFile); } else { $result['file'] = renderPlantUML($PlantUML_Source, $imgFile, $dirname, $filename_prefix); } } if ($result['file']) { $result['src'] = getUploadPath() . "/" . basename($result['file']); if (!$usecloud && $plantumlImagetype == 'png') { $map_filename = $full_path_prefix . ".cmapx"; if (is_file($map_filename)) { // map file is temporary data - read it and delete it. $fp = fopen($map_filename, 'r'); $image_map_data = fread($fp, filesize($map_filename)); fclose($fp); //unlink($map_filename); // Replace generic ids with unique ids: first two ".." fields. $result['map'] = preg_replace('/"[^"]*"/', "\"{$result['mapid']}\"", $image_map_data, 2); } } } return $result; }
/** * Get directory path for the new file * * @return string */ protected function getNewFileDirectory() { return getUploadDirectory() . '/' . $this->to; }
/** * Get the file directory * * @return string */ protected function getFileDirectory() { return getUploadDirectory() . '/' . $this->filename; }