public function showChart(Chart $chart) { $referer_s = \Request::header('referer'); if ($referer_s) { $root = parse_url(\Request::root()); $referer = parse_url($referer_s); if ($root['host'] == $referer['host'] && strlen($referer['path']) > 1 && !str_contains($referer_s, ".html") && !str_contains($referer_s, "wp-admin") && !str_contains($referer_s, "preview=true") && !str_contains($referer_s, "how-to") && !str_contains($referer_s, "grapher") && !str_contains($referer_s, "about") && !str_contains($referer_s, "roser/")) { $chart->origin_url = "https://" . $root['host'] . $referer['path']; $chart->save(); } } if ($chart) { $config = Chart::getConfigWithUrl($chart); $data = new \StdClass(); $logoUrl = Setting::where('meta_name', 'logoUrl')->first(); $data->logoUrl = !empty($logoUrl) ? url('/') . '/' . $logoUrl->meta_value : ''; $canonicalUrl = URL::to($chart->slug); // Make metadata for twitter embed cards! $chartMeta = new \StdClass(); // Replace the chart title placeholders with generic equivalents for now $title = $config->{"chart-name"}; $title = preg_replace("/, \\*time\\*/", " over time", $title); $title = preg_replace("/\\*time\\*/", "over time", $title); $chartMeta->title = $title; // Description is required by twitter if (isset($config->{"chart-subname"})) { $chartMeta->description = $config->{"chart-subname"}; } else { $chartMeta->description = "An interactive visualization from Our World In Data."; } $query = $_SERVER['QUERY_STRING']; $baseUrl = \Request::root() . "/" . $chart->slug; $canonicalUrl = $baseUrl; $imageUrl = $baseUrl . ".png"; if ($query != '') { $canonicalUrl .= "?" . $query; $imageUrl .= "?" . $query; } $chartMeta->imageUrl = $imageUrl; $chartMeta->canonicalUrl = $canonicalUrl; // Give the image exporter a head start on the request for imageUrl if (!str_contains(\Request::path(), ".export")) { Chart::exportPNGAsync($chart->slug, $_SERVER['QUERY_STRING'] . "&size=1000x700", 1000, 700); } return view('view.show', compact('chart', 'config', 'data', 'canonicalUrl', 'chartMeta')); } else { return 'No chart found to view'; } }