Exemplo n.º 1
0
 public function dashboard($app, $page)
 {
     // returns a CSV from a MySQL resultset
     function res2csv($rs)
     {
         $csv = "";
         $keys = array();
         $results = array();
         foreach ($rs as $r) {
             if (count($keys) == 0) {
                 foreach ($r as $key => $val) {
                     if (is_string($key)) {
                         $keys[] = $key;
                     }
                 }
                 $csv = implode(";", $keys) . "\\n";
             }
             $results[] = $r;
         }
         $results = array_reverse($results);
         foreach ($results as $r) {
             $values = array();
             foreach ($keys as $key) {
                 $values[] = $r[$key];
             }
             $csv .= implode(";", $values) . "\\n";
         }
         return $csv;
     }
     $con = Propel::getConnection();
     $data = array();
     $publised_sql = 'SELECT DATE_FORMAT(published_at, \'%Y-%m-%d\') pub_date, COUNT(*) pub_count FROM `chart` WHERE last_edit_step = 5 GROUP BY pub_date ORDER BY `pub_date` DESC LIMIT 1,90';
     $publised_week_sql = 'SELECT DATE_FORMAT(published_at, \'%Y-w%u\') pub_date, COUNT(*) pub_count FROM `chart` WHERE last_edit_step = 5 GROUP BY pub_date ORDER BY `pub_date` DESC LIMIT 1,26';
     $user_signups_sql = 'SELECT DATE_FORMAT(created_at, \'%Y-%m-%d\') create_date, COUNT(*) user_count FROM `user` GROUP BY create_date ORDER BY `create_date` DESC LIMIT 1,90';
     $numUsers = UserQuery::create()->filterByDeleted(false)->count();
     $numUsersPending = UserQuery::create()->filterByDeleted(false)->filterByRole(UserPeer::ROLE_PENDING)->count();
     $numUsersActivated = UserQuery::create()->filterByDeleted(false)->filterByRole(UserPeer::ROLE_EDITOR)->count();
     $numUsersDeleted = UserQuery::create()->filterByDeleted(true)->count();
     $users_csv = "Type;Count\\nPending;{$numUsersPending}\\nActivated;{$numUsersActivated}\\nDeleted;{$numUsersDeleted}";
     $numCharts = ChartQuery::create()->filterByDeleted(false)->count();
     $numChartsUpload = ChartQuery::create()->filterByLastEditStep(array('max' => 1))->filterByDeleted(false)->count();
     $numChartsDescribe = ChartQuery::create()->filterByLastEditStep(2)->filterByDeleted(false)->count();
     $numChartsVisualize = ChartQuery::create()->filterByLastEditStep(3)->filterByDeleted(false)->count();
     $numChartsPublished = ChartQuery::create()->filterByLastEditStep(array('min' => 4))->filterByDeleted(false)->count();
     $charts_csv = "LastEditStep;Count\\nUpload;{$numChartsUpload}\\nDescribe;{$numChartsDescribe}\\nVisualize;{$numChartsVisualize}\\nPublish;{$numChartsPublished}\\n";
     $charts_by_type_csv = res2csv($con->query('SELECT type, COUNT(*) FROM chart WHERE deleted = 0 GROUP BY type;'));
     $charts_by_type_csv = str_replace('-chart', '', $charts_by_type_csv);
     $page = array_merge($page, array('num_users' => $numUsers, 'num_users_activated' => $numUsersActivated, 'num_charts' => $numCharts, 'num_charts_published' => $numChartsPublished, 'published_csv' => res2csv($con->query($publised_sql)), 'published_week_csv' => res2csv($con->query($publised_week_sql)), 'users_csv' => $users_csv, 'charts_edit_step_csv' => $charts_csv, 'charts_by_type_csv' => $charts_by_type_csv, 'created_csv' => res2csv($con->query('SELECT DATE_FORMAT(created_at, \'%Y-%m-%d\') pub_date, COUNT(*) pub_count FROM `chart` GROUP BY pub_date ORDER BY `pub_date` DESC LIMIT 1,90')), 'created_weekly_csv' => res2csv($con->query('SELECT DATE_FORMAT(created_at, \'%Y-w%u\') pub_date, COUNT(*) pub_count FROM `chart` GROUP BY pub_date ORDER BY `pub_date` DESC LIMIT 1,26')), 'user_signups_csv' => res2csv($con->query($user_signups_sql)), 'linechart' => DatawrapperVisualization::get('line-chart'), 'columnchart' => DatawrapperVisualization::get('column-chart'), 'donutchart' => DatawrapperVisualization::get('donut-chart'), 'chartLocale' => 'en-US'));
     $app->render('plugins/admin-dashboard/admin-dashboard.twig', $page);
 }
Exemplo n.º 2
0
 public function nbChartsByType()
 {
     $con = Propel::getConnection();
     $sql = "SELECT type, COUNT(*) c FROM chart WHERE show_in_gallery = 1 AND last_edit_step >= 4 and deleted = 0 GROUP BY type ORDER BY c DESC ;";
     $rs = $con->query($sql);
     $res = array();
     $max = 0;
     foreach ($rs as $r) {
         $vis = DatawrapperVisualization::get($r['type']);
         $lang = substr(DatawrapperSession::getLanguage(), 0, 2);
         $res[] = array('count' => $r['c'], 'id' => $r['type'], 'name' => $vis['title']);
         $max = max($max, $r['c']);
     }
     foreach ($res as $c => $r) {
         $res[$c]['bar'] = round($r['count'] / $max * 80);
     }
     return $res;
 }
Exemplo n.º 3
0
function nbChartsByType($user)
{
    $con = Propel::getConnection();
    $sql = "SELECT type, COUNT(*) c FROM chart WHERE author_id = " . $user->getId() . " AND deleted = 0 AND last_edit_step >= 2 GROUP BY type ORDER BY c DESC ;";
    $rs = $con->query($sql);
    $res = array();
    foreach ($rs as $r) {
        $vis = DatawrapperVisualization::get($r['type']);
        $lang = substr(DatawrapperSession::getLanguage(), 0, 2);
        if (!isset($vis['title'])) {
            continue;
        }
        if (empty($vis['title'][$lang])) {
            $lang = 'en';
        }
        $res[] = array('count' => $r['c'], 'id' => $r['type'], 'name' => $vis['title']);
    }
    return $res;
}
Exemplo n.º 4
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);
    });
});
Exemplo n.º 5
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);
    });
});
Exemplo n.º 6
0
function get_chart_content($chart, $user, $published = false, $debug = false)
{
    if (!function_exists('unique_scripts')) {
        function unique_scripts($scripts)
        {
            $exist = array();
            $out = array();
            foreach ($scripts as $s) {
                $src = is_array($s) ? $s['src'] : $s;
                if (isset($exist[$src])) {
                    continue;
                }
                $exist[$src] = true;
                $out[] = is_array($s) ? $s : array('src' => $s);
            }
            return $out;
        }
    }
    $theme_css = array();
    $theme_js = array();
    $protocol = get_current_protocol();
    $next_theme_id = $chart->getTheme();
    $locale = DatawrapperSession::getLanguage();
    if ($chart->getLanguage() != '') {
        $locale = $chart->getLanguage();
    }
    $static_path = $GLOBALS['dw_config']['static_path'];
    $abs = $protocol . '://' . $GLOBALS['dw_config']['domain'];
    if ($static_path == 'static/') {
        $static_path = $abs . $static_path;
    }
    while (!empty($next_theme_id)) {
        $theme = DatawrapperTheme::get($next_theme_id);
        // $theme_static_path = str_replace('/static/', $static_path . '/', $theme['__static_path']);
        $theme_static_path = $theme['__static_path'];
        $theme_js[] = $theme_static_path . $next_theme_id . '.js';
        if ($theme['hasStyles']) {
            $theme_css[] = $theme_static_path . $next_theme_id . '.css';
        }
        $next_theme_id = $theme['extends'];
    }
    $abs = $protocol . '://' . $GLOBALS['dw_config']['domain'];
    $debug = $GLOBALS['dw_config']['debug'] == true || $debug;
    $culture = str_replace('_', '-', $locale);
    if ($published && !empty($GLOBALS['dw_config']['asset_domain'])) {
        $base_js = array('//' . $GLOBALS['dw_config']['asset_domain'] . '/globalize.min.js', '//' . $GLOBALS['dw_config']['asset_domain'] . '/cultures/globalize.culture.' . $culture . '.js', '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js', '//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js');
    } else {
        // use "local" assets
        $base_js = array($abs . '/static/vendor/globalize/globalize.min.js', $abs . '/static/vendor/globalize/cultures/globalize.culture.' . $culture . '.js', $abs . '/static/vendor/underscore/underscore-min.js', $abs . '/static/vendor/jquery/jquery.min.js');
    }
    $vis_js = array();
    $vis_css = array();
    $next_vis_id = $chart->getType();
    $vis_libs = array();
    $vis_libs_cdn = array();
    $vis_libs_local = array();
    $vis_locale = array();
    // visualizations may define localized strings, e.g. "other"
    while (!empty($next_vis_id)) {
        $vis = DatawrapperVisualization::get($next_vis_id);
        // $vis_static_path = str_replace('/static/', $static_path . '/', $vis['__static_path']);
        $vis_static_path = $vis['__static_path'];
        $vjs = array();
        if (!empty($vis['libraries'])) {
            foreach (array_reverse($vis['libraries']) as $script) {
                if (!is_array($script)) {
                    $script = array("local" => $script, "cdn" => false);
                }
                if (!empty($script['cdn'])) {
                    $script['src'] = $script['cdn'];
                    $vis_libs_cdn[] = $script;
                }
                // at first we check if the library lives in ./lib of the vis module
                if (file_exists(ROOT_PATH . 'www' . $vis['__static_path'] . $script['local'])) {
                    $u = $vis_static_path . $script['local'];
                } else {
                    if (file_exists(ROOT_PATH . 'www/static/vendor/' . $script['local'])) {
                        $u = '/static/vendor/' . $script['local'];
                    } else {
                        print ROOT_PATH . 'www' . $vis['__static_path'] . $script['local'];
                        die("could not find required library " . $script["local"]);
                    }
                }
                $script['src'] = $u;
                $vis_libs[] = $script;
                if (empty($url['cdn'])) {
                    $vis_libs_local[] = $script;
                }
            }
        }
        if (!empty($vis['locale']) && is_array($vis['locale'])) {
            foreach ($vis['locale'] as $term => $translations) {
                if (!isset($vis_locale[$term])) {
                    $vis_locale[$term] = $translations;
                }
            }
        }
        $vjs[] = $vis_static_path . $vis['id'] . '.js';
        $vis_js = array_merge($vis_js, array_reverse($vjs));
        if ($vis['hasCSS']) {
            $vis_css[] = $vis_static_path . $vis['id'] . '.css';
        }
        $next_vis_id = !empty($vis['extends']) ? $vis['extends'] : null;
    }
    $stylesheets = array_merge(array('/static/css/chart.base.css'), $vis_css, array_reverse($theme_css));
    $the_vis = DatawrapperVisualization::get($chart->getType());
    $the_vis['locale'] = $vis_locale;
    $the_theme = DatawrapperTheme::get($chart->getTheme());
    $l10n__domain = $the_theme['__static_path'];
    $the_vis_js = get_vis_js($the_vis, array_merge(array_reverse($vis_js), $vis_libs_local));
    $the_theme_js = get_theme_js($the_theme, array_reverse($theme_js));
    $the_chart_js = get_chart_js();
    if ($published) {
        $scripts = array_merge($base_js, $vis_libs_cdn, array('/lib/' . $the_vis_js[0], '/lib/' . $the_theme_js[0], '/lib/' . $the_chart_js[0]));
        $stylesheets = array($chart->getID() . '.all.css');
        // NOTE: replace `/static/` by `assets/` in the `__static_path` value,
        //       since vis assets are handle by DatawrapperVisualization
        $replace_in = $the_vis['__static_path'];
        $replace_by = 'assets/';
        $replace = '/static/';
        $the_vis['__static_path'] = substr_replace($replace_in, $replace_by, strrpos($replace_in, $replace), strlen($replace));
        // length
        $the_theme['__static_path'] = '';
    } else {
        $scripts = unique_scripts(array_merge($base_js, array($static_path . '/js/dw-2.0' . ($debug ? '' : '.min') . '.js'), array_reverse($theme_js), array_reverse($vis_js), array_reverse($vis_libs), array($static_path . '/js/dw/chart.base.js')));
    }
    $cfg = $GLOBALS['dw_config'];
    $published_urls = DatawrapperHooks::execute(DatawrapperHooks::GET_PUBLISHED_URL, $chart);
    if (empty($published_urls)) {
        $chart_url = $protocol . '://' . $cfg['chart_domain'] . '/' . $chart->getID() . '/';
    } else {
        $chart_url = $published_urls[0];
        // ignore urls except from the first one
    }
    $page = array('chartData' => $chart->loadData(), 'chart' => $chart, 'lang' => strtolower(substr($locale, 0, 2)), 'metricPrefix' => get_metric_prefix($locale), 'l10n__domain' => $l10n__domain, 'origin' => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'DW_DOMAIN' => $protocol . '://' . $cfg['domain'] . '/', 'DW_CHART_DATA' => $protocol . '://' . $cfg['domain'] . '/chart/' . $chart->getID() . '/data.csv', 'ASSET_PATH' => $published ? '' : $the_theme['__static_path'], 'published' => $published, 'chartUrl' => $chart_url, 'embedCode' => '<iframe src="' . $chart_url . '" frameborder="0" allowtransparency="true" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen width="' . $chart->getMetadata('publish.embed-width') . '" height="' . $chart->getMetadata('publish.embed-height') . '"></iframe>', 'chartUrlFs' => strpos($chart_url, '.html') > 0 ? str_replace('index.html', 'fs.html', $chart_url) : $chart_url . '?fs=1', 'stylesheets' => $stylesheets, 'scripts' => $scripts, 'visualization' => $the_vis, 'theme' => $the_theme, 'chartLocale' => str_replace('_', '-', $locale), 'vis_js' => $the_vis_js, 'theme_js' => $the_theme_js, 'chart_js' => $the_chart_js);
    return $page;
}
Exemplo n.º 7
0
 */
$app->get('/xhr/header/:page', function ($active) use($app) {
    disable_cache($app);
    $page = array();
    add_header_vars($page, $active);
    $res = $app->response();
    $res['Cache-Control'] = 'max-age=0';
    $app->render('header.twig', $page);
});
/**
 * reloads the header menu after login/logout
 */
$app->get('/xhr/home-login', function () use($app) {
    $page = array();
    add_header_vars($page);
    $res = $app->response();
    $res['Cache-Control'] = 'max-age=0';
    $app->render('home-login.twig', $page);
});
/**
 * reloads visualization specific options after the user
 * changed the visualization type
 */
require_once '../lib/utils/themes.php';
$app->get('/xhr/:chartid/vis-options', function ($id) use($app) {
    disable_cache($app);
    check_chart_writable($id, function ($user, $chart) use($app) {
        $page = array('vis' => DatawrapperVisualization::get($chart->getType()), 'theme' => DatawrapperTheme::get($chart->getTheme()), 'language' => substr(DatawrapperSession::getLanguage(), 0, 2));
        $app->render('vis-options.twig', $page);
    });
});
Exemplo n.º 8
0
function get_chart_content($chart, $user, $published = false, $debug = false)
{
    $theme_css = array();
    $theme_js = array();
    $next_theme_id = $chart->getTheme();
    $locale = DatawrapperSession::getLanguage();
    while (!empty($next_theme_id)) {
        $theme = DatawrapperTheme::get($next_theme_id);
        $theme_js[] = $theme['__static_path'] . $next_theme_id . '.js';
        if ($theme['hasStyles']) {
            $theme_css[] = $theme['__static_path'] . $next_theme_id . '.css';
        }
        $next_theme_id = $theme['extends'];
    }
    $abs = 'http://' . $GLOBALS['dw_config']['domain'];
    $debug = $GLOBALS['dw_config']['debug'] == true || $debug;
    if ($published && !$debug) {
        $base_js = array('//assets-datawrapper.s3.amazonaws.com/globalize.min.js', '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js', '//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js');
        if (substr($locale, 0, 2) != 'en') {
            $base_js[] = '//assets-datawrapper.s3.amazonaws.com/cultures/globalize.culture.' . str_replace('_', '-', $locale) . '.js';
        }
    } else {
        // use local assets
        $base_js = array($abs . '/static/vendor/globalize/globalize.min.js', $abs . '/static/vendor/underscore/underscore-min.js', $abs . '/static/vendor/jquery/jquery-1.9.1' . ($debug ? '' : '.min') . '.js');
        if (substr($locale, 0, 2) != 'en') {
            $base_js[] = $abs . '/static/vendor/globalize/cultures/globalize.culture.' . str_replace('_', '-', $locale) . '.js';
        }
    }
    $vis_js = array();
    $vis_css = array();
    $next_vis_id = $chart->getType();
    $vis_libs = array();
    $vis_locale = array();
    // visualizations may define localized strings, e.g. "other"
    while (!empty($next_vis_id)) {
        $vis = DatawrapperVisualization::get($next_vis_id);
        $vjs = array();
        if (!empty($vis['libraries'])) {
            foreach ($vis['libraries'] as $url) {
                // at first we check if the library lives in ./lib of the vis module
                if (file_exists(ROOT_PATH . 'www/' . $vis['__static_path'] . $url)) {
                    $vis_libs[] = $vis['__static_path'] . $url;
                } else {
                    if (file_exists(ROOT_PATH . 'www/static/vendor/' . $url)) {
                        $vis_libs[] = '/static/vendor/' . $url;
                    }
                }
            }
        }
        if (!empty($vis['locale']) && is_array($vis['locale'])) {
            foreach ($vis['locale'] as $term => $translations) {
                if (!isset($vis_locale[$term])) {
                    $vis_locale[$term] = $translations;
                }
            }
        }
        $vjs[] = $vis['__static_path'] . $vis['id'] . '.js';
        $vis_js = array_merge($vis_js, array_reverse($vjs));
        if ($vis['hasCSS']) {
            $vis_css[] = $vis['__static_path'] . $vis['id'] . '.css';
        }
        $next_vis_id = !empty($vis['extends']) ? $vis['extends'] : null;
    }
    $styles = array_merge($vis_css, array_reverse($theme_css));
    $the_vis = DatawrapperVisualization::get($chart->getType());
    $the_vis['locale'] = $vis_locale;
    $the_theme = DatawrapperTheme::get($chart->getTheme());
    if ($published) {
        $scripts = array_merge($base_js, array('/lib/vis/' . $the_vis['id'] . '-' . $the_vis['version'] . '.min.js', '/lib/theme/' . $the_theme['id'] . '-' . $the_theme['version'] . '.min.js'));
        $styles = array($chart->getID() . '.min.css');
        $the_vis['__static_path'] = '';
        $the_theme['__static_path'] = '';
    } else {
        $scripts = array_unique(array_merge($base_js, array('/static/js/datawrapper' . ($debug ? '' : '.min') . '.js'), array_reverse($theme_js), array_reverse($vis_js), $vis_libs));
    }
    $cfg = $GLOBALS['dw_config'];
    $published_urls = DatawrapperHooks::execute(DatawrapperHooks::GET_PUBLISHED_URL, $chart);
    if (empty($published_urls)) {
        $chart_url = 'http://' . $cfg['chart_domain'] . '/' . $chart->getID() . '/';
    } else {
        $chart_url = $published_urls[0];
        // ignore urls except from the first one
    }
    $page = array('chartData' => $chart->loadData(), 'chart' => $chart, 'chartLocale' => str_replace('_', '-', $locale), 'lang' => strtolower(substr($locale, 0, 2)), 'metricPrefix' => get_metric_prefix($locale), 'theme' => $the_theme, 'l10n__domain' => $the_theme['__static_path'], 'visualization' => $the_vis, 'stylesheets' => $styles, 'scripts' => $scripts, 'themeJS' => array_reverse($theme_js), 'visJS' => array_merge(array_reverse($vis_js), $vis_libs), 'origin' => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'DW_DOMAIN' => 'http://' . $cfg['domain'] . '/', 'DW_CHART_DATA' => 'http://' . $cfg['domain'] . '/chart/' . $chart->getID() . '/data', 'ASSET_PATH' => $published ? '' : $the_theme['__static_path'], 'trackingCode' => !empty($analyticsMod) ? $analyticsMod->getTrackingCode($chart) : '', 'chartUrl' => $chart_url, 'embedCode' => '<iframe src="' . $chart_url . '" frameborder="0" allowtransparency="true" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen width="' . $chart->getMetadata('publish.embed-width') . '" height="' . $chart->getMetadata('publish.embed-height') . '"></iframe>', 'chartUrlFs' => strpos($chart_url, '.html') > 0 ? str_replace('index.html', 'fs.html', $chart_url) : $chart_url . '?fs=1');
    return $page;
}
Exemplo n.º 9
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);
    });
});
Exemplo n.º 10
0
 * 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;
    }
    ok($res);
});
Exemplo n.º 11
0
        $page['plain'] = $app->request()->get('plain') == 1;
        $page['fullscreen'] = $app->request()->get('fs') == 1;
        $page['innersvg'] = $app->request()->get('innersvg') == 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/nojs.png', function ($id) use($app) {
    $app->redirect('/static/img/nojs.png');
});
// always redirect to url without trailing slash
$app->get('/chart/:id/preview/', function ($id) use($app) {
    $app->redirect("/chart/{$id}/preview");
});
// static route to emulate published vis files
$app->get('/chart/:id/_static/:file+', function ($id, $parts) use($app) {
    check_chart_readable($id, function ($user, $chart) use($app, $parts) {
        $fn = implode('/', $parts);
        $vis = DatawrapperVisualization::get($chart->getType());
        if (file_exists(ROOT_PATH . 'www/' . $vis['__static_path'] . $fn)) {
            $app->redirect($vis['__static_path'] . $fn);
        } else {
            $app->notFound();
        }
    });
});
Exemplo n.º 12
0
<?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);
    });
});
Exemplo n.º 13
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());
        }
    });
});
Exemplo n.º 14
0
            $user_csv .= $lbl . ';';
            $user_csv .= isset($data['users_activated'][$key]) ? $data['users_activated'][$key] : '-';
            $user_csv .= ';';
            $user_csv .= isset($data['users_signed'][$key]) ? $data['users_signed'][$key] : '-';
            $user_csv .= "\\n";
            $chart_csv .= $lbl . ';';
            // $chart_csv .= isset($data['charts_uploaded'][$lbl]) ? $data['charts_uploaded'][$lbl] : '-';
            // $chart_csv .= ';';
            // $chart_csv .= isset($data['charts_described'][$lbl]) ? $data['charts_described'][$lbl] : '-';
            // $chart_csv .= ';';
            $chart_csv .= isset($data['charts_visualized'][$key]) ? $data['charts_visualized'][$key] : '-';
            $chart_csv .= ';';
            $chart_csv .= isset($data['charts_published'][$key]) ? $data['charts_published'][$key] : '-';
            $chart_csv .= "\\n";
        }
        $page = array('title' => 'Dashboard', 'user_csv' => $user_csv, 'chart_csv' => $chart_csv, 'linechart' => DatawrapperVisualization::get('line-chart'), 'chartLocale' => 'en-US');
        add_header_vars($page, 'admin');
        add_adminpage_vars($page, '/admin');
        $app->render('admin-dashboard.twig', $page);
    } else {
        $app->notFound();
    }
});
$app->get('/admin/themes/?', function () use($app) {
    $user = DatawrapperSession::getUser();
    if ($user->isAdmin()) {
        $page = array('title' => 'Themes', 'themes' => DatawrapperTheme::all(), 'count' => count_charts_per_themes());
        add_header_vars($page, 'admin');
        add_adminpage_vars($page, '/admin/themes');
        $app->render('admin-themes.twig', $page);
    } else {