function publish_css($user, $chart) { $cdn_files = array(); $static_path = get_static_path($chart); $data = get_chart_content($chart, $user, false, '../'); $all = ''; foreach ($data['stylesheets'] as $css) { $all .= file_get_contents('..' . $css) . "\n\n"; } // move @imports to top of file $imports = array(); $body = ""; $lines = explode("\n", $all); foreach ($lines as $line) { if (substr($line, 0, 7) == '@import') { $imports[] = $line; } else { $body .= $line . "\n"; } } $all = implode("\n", $imports) . "\n\n" . $body; $cssmin = new CSSmin(); $minified = $all; //$cssmin->run($all); file_put_contents($static_path . "/" . $chart->getID() . '.min.css', $minified); $cdn_files[] = array($static_path . "/" . $chart->getID() . '.min.css', $chart->getID() . '/' . $chart->getID() . '.min.css', 'text/css'); // copy themes assets $theme = $data['theme']; if (isset($theme['assets'])) { foreach ($theme['assets'] as $asset) { $asset_src = '../../www/' . $theme['__static_path'] . '/' . $asset; $asset_tgt = $static_path . "/" . $asset; if (file_exists($asset_src)) { file_put_contents($asset_tgt, file_get_contents($asset_src)); $cdn_files[] = array($asset_src, $chart->getID() . '/' . $asset); } } } // copy visualization assets $vis = $data['visualization']; $src = '..' . $vis['__static_path']; $dest = '../../charts/static/' . $chart->getID(); if (isset($vis['assets'])) { foreach ($vis['assets'] as $asset) { copy($src . DIRECTORY_SEPARATOR . $asset, $dest . DIRECTORY_SEPARATOR . $asset); $cdn_files[] = array($dest . DIRECTORY_SEPARATOR . $asset, $chart->getID() . '/' . $asset); } } return $cdn_files; }
function publish_css($user, $chart) { $cdn_files = array(); $static_path = get_static_path($chart); $data = get_chart_content($chart, $user, false, '../'); $all = ''; foreach ($data['stylesheets'] as $css) { $all .= file_get_contents(ROOT_PATH . 'www' . $css) . "\n\n"; } // move @imports to top of file $imports = array(); $body = ""; $lines = explode("\n", $all); foreach ($lines as $line) { if (substr($line, 0, 7) == '@import') { $imports[] = $line; } else { $body .= $line . "\n"; } } $all = implode("\n", $imports) . "\n\n" . $body; $cssmin = new CSSmin(); $minified = $all; //$cssmin->run($all); disabled minification file_put_contents($static_path . "/" . $chart->getID() . '.all.css', $minified); $cdn_files[] = array($static_path . "/" . $chart->getID() . '.all.css', $chart->getCDNPath() . $chart->getID() . '.all.css', 'text/css'); // copy themes assets $theme = $data['theme']; if (isset($theme['assets'])) { foreach ($theme['assets'] as $asset) { $asset_src = '../../www/' . $theme['__static_path'] . '/' . $asset; $asset_tgt = $static_path . "/" . $asset; if (file_exists($asset_src)) { file_put_contents($asset_tgt, file_get_contents($asset_src)); $cdn_files[] = array($asset_src, $chart->getCDNPath() . $asset); } } } // copy visualization assets $vis = $data['visualization']; $assets = DatawrapperVisualization::assets($vis['id'], $chart); foreach ($assets as $asset) { $asset_src = ROOT_PATH . 'www/static/' . $asset; $asset_tgt = $static_path . '/assets/' . $asset; create_missing_directories($asset_tgt); copy($asset_src, $asset_tgt); $cdn_files[] = array($asset_src, $chart->getCDNPath() . 'assets/' . $asset); } return $cdn_files; }
<?php /* * Main controller for chart rendering */ $app->get('/chart/:id/', function ($id) use($app) { disable_cache($app); check_chart_public($id, function ($user, $chart) use($app) { if ($chart->getLanguage() != '') { global $__l10n; $__l10n->loadMessages($chart->getLanguage()); } $page = get_chart_content($chart, $user, $app->request()->get('minify') == 1); $page['thumb'] = $app->request()->params('t') == 1; $page['innersvg'] = $app->request()->get('innersvg') == 1; $page['plain'] = $app->request()->get('plain') == 1; $page['fullscreen'] = $app->request()->get('fs') == 1; if (!empty($GLOBALS['dw_config']['prevent_chart_preview_in_iframes'])) { // prevent this url from being rendered in iframes on different // domains, mainly to protect server resources $res = $app->response(); $res['X-Frame-Options'] = 'SAMEORIGIN'; } $app->render('chart.twig', $page); }); }); $app->get('/chart/:id', function ($id) use($app) { $app->redirect('/chart/' . $id . '/'); });
<?php require_once '../lib/utils/themes.php'; require_once '../lib/utils/chart_content.php'; /* * Shows a preview of a chart for display in an iFrame */ $app->get('/chart/:id/preview/?', function ($id) use($app) { disable_cache($app); check_chart_writable($id, function ($user, $chart) use($app) { $page = get_chart_content($chart, $user, $app->request()->get('minify'), $app->request()->get('debug')); $page['plain'] = $app->request()->get('plain') == 1; $page['fullscreen'] = $app->request()->get('fs') == 1; $page['innersvg'] = $app->request()->get('innersvg') == 1; $app->render('chart.twig', $page); }); });