function publish_data($user, $chart) { $cdn_files = array(); $static_path = get_static_path($chart); file_put_contents($static_path . "/data.csv", $chart->loadData()); $cdn_files[] = array($static_path . "/data.csv", $chart->getCDNPath() . 'data.csv', 'text/plain'); return $cdn_files; }
$app->get('/charts/:id/publish/status', function ($chart_id) use($app) { disable_cache($app); if_chart_is_writable($chart_id, function ($user, $chart) use($app) { echo _getPublishStatus($chart); }); }); /* * stores client-side generated chart thumbnail */ $app->put('/charts/:id/thumbnail/:thumb', function ($chart_id, $thumb) use($app) { disable_cache($app); if_chart_is_writable($chart_id, function ($user, $chart) use($app, $thumb) { try { $imgurl = $app->request()->getBody(); $imgdata = base64_decode(substr($imgurl, strpos($imgurl, ",") + 1)); $static_path = get_static_path($chart); file_put_contents($static_path . "/" . $thumb . '.png', $imgdata); DatawrapperHooks::execute(DatawrapperHooks::PUBLISH_FILES, array(array($static_path . "/" . $thumb . '.png', $chart->getID() . '/' . $thumb . '.png', 'image/png'))); ok(); } catch (Exception $e) { error('io-error', $e->getMessage()); } }); }); /* * stores static snapshot of a chart (data, configuration, etc) as JSON * to /test/test-charts. This aims to simplify the generation of test * cases using the Datawrapper editor. Only for debugging. */ $app->post('/charts/:id/store_snapshot', function ($chart_id) use($app) { if (!empty($GLOBALS['dw_config']['debug_export_test_cases'])) {