Example #1
0
<?php

require_once ROOT_PATH . 'lib/utils/themes.php';
require_once ROOT_PATH . 'vendor/jsmin/jsmin.php';
/*
 * PUBLISH STEP - shows progress of publishing action and thumbnail generation
 * forwards to /chart/:id/finish
 */
$app->get('/chart/:id/publish', function ($id) use($app) {
    disable_cache($app);
    check_chart_writable($id, function ($user, $chart) use($app) {
        $cfg = $GLOBALS['dw_config'];
        $page = array('title' => $chart->getID() . ' :: ' . __('Publish'), 'chartData' => $chart->loadData(), 'chart' => $chart, 'visualizations' => DatawrapperVisualization::all(), 'vis' => DatawrapperVisualization::get($chart->getType()), 'chartUrl' => $chart->getPublicUrl(), 'chartUrlLocal' => '/chart/' . $chart->getID() . '/preview', 'themes' => DatawrapperTheme::all(), 'exportStaticImage' => !empty($cfg['phantomjs']), 'chartActions' => DatawrapperHooks::execute(DatawrapperHooks::GET_CHART_ACTIONS, $chart), 'estExportTime' => ceil(JobQuery::create()->estimatedTime('export_image') / 60));
        add_header_vars($page, 'chart', 'chart-editor/publish.css');
        add_editor_nav($page, 4);
        if ($user->isAbleToPublish() && ($chart->getLastEditStep() == 3 || $app->request()->get('republish') == 1)) {
            // actual publish process
            $chart->publish();
            $page['chartUrl'] = $chart->getPublicUrl();
            // generate thumbnails
            $page['publish'] = true;
            $page['republish'] = $app->request()->get('republish') == 1;
        }
        $app->render('chart/publish.twig', $page);
    });
});
Example #2
0
<?php

/*
 * VISUALIZE STEP
 */
$app->get('/chart/:id/visualize', function ($id) use($app) {
    disable_cache($app);
    check_chart_writable($id, function ($user, $chart) use($app) {
        $page = array('title' => $chart->getID() . ' :: ' . __('Visualize'), 'chartData' => $chart->loadData(), 'chart' => $chart, 'visualizations_deps' => DatawrapperVisualization::all('dependencies'), 'visualizations' => DatawrapperVisualization::all(), 'vis' => DatawrapperVisualization::get($chart->getType()), 'themes' => DatawrapperTheme::all(), 'theme' => DatawrapperTheme::get($chart->getTheme()), 'debug' => !empty($GLOBALS['dw_config']['debug_export_test_cases']) ? '1' : '0');
        add_header_vars($page, 'chart');
        add_editor_nav($page, 3);
        $app->render('chart/visualize.twig', $page);
    });
});
Example #3
0
<?php

/*
 * PUBLISH STEP - shows progress of publishing action and thumbnail generation
 */
$app->get('/chart/:id/publish', function ($id) use($app) {
    disable_cache($app);
    check_chart_writable($id, function ($user, $chart) use($app) {
        $cfg = $GLOBALS['dw_config'];
        $chartActions = DatawrapperHooks::execute(DatawrapperHooks::GET_CHART_ACTIONS, $chart);
        // add duplicate action
        $chartActions[] = array('id' => 'duplicate', 'icon' => 'code-fork', 'title' => __('Duplicate this chart'), 'order' => 500);
        // sort actions
        usort($chartActions, function ($a, $b) {
            return (isset($a['order']) ? $a['order'] : 999) - (isset($b['order']) ? $b['order'] : 999);
        });
        $chartW = $chart->getMetadata('publish.embed-width');
        $chartH = $chart->getMetadata('publish.embed-height');
        if (substr($chartW, -1) != '%') {
            $chartW .= 'px';
        }
        if (substr($chartH, -1) != '%') {
            $chartH .= 'px';
        }
        $page = array('title' => $chart->getID() . ' :: ' . __('Publish'), 'chartData' => $chart->loadData(), 'chart' => $chart, 'visualizations' => DatawrapperVisualization::all(), 'vis' => DatawrapperVisualization::get($chart->getType()), 'chartUrl' => $chart->getPublicUrl(), 'chartUrlLocal' => '/chart/' . $chart->getID() . '/preview', 'embedWidth' => $chartW, 'embedHeight' => $chartH, 'themes' => DatawrapperTheme::all(), 'exportStaticImage' => !empty($cfg['phantomjs']), 'chartActions' => $chartActions, 'estExportTime' => ceil(JobQuery::create()->estimatedTime('export') / 60));
        add_header_vars($page, 'chart', 'chart-editor/publish.css');
        add_editor_nav($page, 4);
        $app->render('chart/publish.twig', $page);
    });
});
Example #4
0
/*
 * get list of all currently available chart types
 * watch out: this request involves browsing in the file
 * system and parsing of several JSON files
 *
 * it will be cached once per user session but should be
 * used carefully anyway. never call this in embedded charts
 */
$app->get('/visualizations', function () {
    if (false && isset($_SESSION['dw-visualizations'])) {
        // read from session cache
        // ToDo: use user-independend cache here (e.g. memcache)
        $res = $_SESSION['dw-visualizations'];
    } else {
        // read from file system
        $res = DatawrapperVisualization::all();
        // store in cache
        $_SESSION['dw-visualizations'] = $res;
    }
    ok($res);
});
$app->get('/visualizations/:visid', function ($visid) {
    if (false && isset($_SESSION['dw-visualizations-' . $visid])) {
        // read from session cache
        // ToDo: use user-independend cache here (e.g. memcache)
        $res = $_SESSION['dw-visualizations-' . $visid];
    } else {
        // read from file system
        $res = DatawrapperVisualization::get($visid);
        // store in cache
        $_SESSION['dw-visualizations-' . $visid] = $res;
<?php

require_once '../lib/utils/themes.php';
/*
 * VISUALIZE STEP
 */
$app->get('/chart/:id/visualize', function ($id) use($app) {
    disable_cache($app);
    check_chart_writable($id, function ($user, $chart) use($app) {
        $page = array('chartData' => $chart->loadData(), 'chart' => $chart, 'visualizations' => DatawrapperVisualization::all(), 'vis' => DatawrapperVisualization::get($chart->getType()), 'themes' => DatawrapperTheme::all(), 'theme' => DatawrapperTheme::get($chart->getTheme()), 'debug' => !empty($GLOBALS['dw_config']['debug_export_test_cases']) ? '1' : '0');
        add_header_vars($page, 'chart');
        add_editor_nav($page, 3);
        $app->render('chart-visualize.twig', $page);
    });
});
Example #6
0
    if (!empty($GLOBALS['dw_config']['debug_export_test_cases'])) {
        if_chart_exists($chart_id, function ($chart) use($app) {
            $json = $chart->serialize();
            $payload = json_decode($app->request()->getBody(), true);
            $name = $payload['id'];
            $json['_data'] = $chart->loadData();
            $json['_sig'] = $payload['signature'];
            if (empty($name)) {
                error('', 'no name specified');
            } else {
                $name = str_replace(" ", "-", $name);
                $json['_id'] = $name;
                file_put_contents("../../test/test-charts/" . $name . ".json", json_encode($json));
                ok();
            }
        });
    }
});
$app->get('/charts/:id/vis-data', function ($chart_id) {
    if_chart_is_readable($chart_id, function ($user, $chart) {
        try {
            $allVis = array();
            foreach (DatawrapperVisualization::all() as $vis) {
                $allVis[$vis['id']] = $vis;
            }
            ok(array('visualizations' => $allVis, 'vis' => DatawrapperVisualization::get($chart->getType()), 'themes' => DatawrapperTheme::all()));
        } catch (Exception $e) {
            error('io-error', $e->getMessage());
        }
    });
});