コード例 #1
0
ファイル: Page.php プロジェクト: NotPrometey/kvetky.loc
 public function scopeGetPage($query, $slug)
 {
     $query = $query->where('slug', '=', $slug)->firstOrFail();
     if (!$query) {
         App::abort(404);
     } else {
         return $query;
     }
 }
コード例 #2
0
 /**
  * Shell out to phantomjs to take a screenshot of our chart + download the svg
  *
  * @param string $slug The chart slug to export.
  * @param int $width Desired width in pixels of the exported image.
  * @param int $height Desired height in pixels of the exported image. 
  * @param string $format Either "svg" or "png". Both will be saved, only affects return
  * @return string Path to exported file.
  */
 public static function export($slug, $query, $width, $height, $format)
 {
     $phantomjs = base_path() . "/node_modules/.bin/phantomjs";
     $rasterize = base_path() . "/phantomjs/rasterize.js";
     $target = \Request::root() . "/" . $slug . ".export" . "?" . $query;
     $queryHash = hash('md5', $query);
     $pngFile = public_path() . "/exports/" . $slug . "-" . $queryHash . ".png";
     $returnFile = public_path() . "/exports/" . $slug . "-" . $queryHash . "." . $format;
     if (!file_exists($returnFile)) {
         $command = $phantomjs . " " . $rasterize . " " . escapeshellarg($target) . " " . escapeshellarg($pngFile) . " '" . $width . "px*" . $height . "px'" . " 2>&1";
         Log::info($command);
         exec($command, $output, $retval);
         if ($retval != 0) {
             return \App::abort(406, json_encode($output));
         }
     }
     return $returnFile;
 }