コード例 #1
0
ファイル: embed.php プロジェクト: elaOnMars/datawrapper
<?php

require_once ROOT_PATH . 'lib/utils/themes.php';
require_once ROOT_PATH . 'lib/utils/chart_content.php';
/*
 * Shows a preview of a chart for display in an iFrame
 */
$app->get('/chart/:id/', function ($id) use($app) {
    disable_cache($app);
    check_chart_public($id, function ($user, $chart) use($app) {
        $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;
        $app->render('chart.twig', $page);
    });
});
$app->get('/chart/:id', function ($id) use($app) {
    $app->redirect('/chart/' . $id . '/');
});
コード例 #2
0
ファイル: embed.php プロジェクト: Halfnhav4/datawrapper
<?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 . '/');
});
コード例 #3
0
    disable_cache($app);
    check_chart_public($id, function ($user, $chart) use($app) {
        function get($var, $default)
        {
            global $app;
            $v = $app->request()->params($var);
            return empty($v) ? $default : $v;
        }
        $w = get('w', 300);
        $h = get('h', 220);
        $format = get('f', 'png');
        $out = $chart->getId() . '-' . $w . '-' . $h . '.' . $format;
        $img_dir = dirname(dirname(__FILE__)) . '/charts/images/';
        $script = dirname(dirname(__FILE__)) . '/scripts/render.js';
        $cmd = PHANTOMJS . ' ' . $script . ' ' . $chart->getId() . ' ' . $img_dir . $out . ' ' . $w . ' ' . $h;
        if ($format == 'png') {
            header("Content-Type: image/png");
        } else {
            $title = trim(strtolower($chart->getTitle()));
            $name = $chart->getId() . '-' . preg_replace('/[äöüa-z0-9ß]+/', '-', $title) . '.pdf';
            header('Content-Disposition: attachment;filename="' . $name . '"');
            header("Content-Type: application/pdf");
        }
        if (!file_exists($img_dir . $out)) {
            exec($cmd);
        }
        $fp = fopen($img_dir . $out, 'rb');
        fpassthru($fp);
        exit;
    });
});