Exemplo n.º 1
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new DatawrapperTheme();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 /**
  * creates a new empty chart
  */
 public function createEmptyChart($user)
 {
     $cfg = $GLOBALS['dw_config'];
     $defaults = isset($cfg['defaults']) ? $cfg['defaults'] : array();
     $chart = new Chart();
     $chart->setId($this->getUnusedRandomId());
     $chart->setCreatedAt(time());
     $chart->setLastModifiedAt(time());
     if ($user->isLoggedIn()) {
         $chart->setAuthorId($user->getId());
         $org = $user->getCurrentOrganization();
         if (!empty($org)) {
             $chart->setOrganization($org);
         }
     } else {
         // remember session id to be able to assign this chart
         // to a newly registered user
         $chart->setGuestSession(session_id());
     }
     // find a nice, more or less unique title
     $untitled = __('Insert title here');
     $title = '[ ' . $untitled . ' ]';
     $chart->setTitle($title);
     // todo: use global default theme
     $chart->setTheme(isset($defaults['theme']) ? $defaults['theme'] : 'default');
     // use organization default theme if possible
     if ($user->isLoggedIn()) {
         $org = $user->getCurrentOrganization();
         if (!empty($org)) {
             $def_org_theme = $org->getDefaultTheme();
             if (!empty($def_org_theme) && DatawrapperTheme::get($def_org_theme)) {
                 $chart->setTheme($def_org_theme);
                 $theme = DatawrapperTheme::get($def_org_theme);
                 if (isset($theme['default_width'])) {
                     $def_org_theme_default_width = $theme['default_width'];
                 }
                 if (isset($theme['default_height'])) {
                     $def_org_theme_default_height = $theme['default_height'];
                 }
             }
         }
     }
     $chart->setLocale('');
     // no default locale
     $chart->setType(isset($defaults['vis']) ? $defaults['vis'] : 'bar-chart');
     $chart->setPublicUrl($chart->getLocalUrl());
     $defaultMeta = Chart::defaultMetaData();
     if (isset($def_org_theme_default_width)) {
         $defaultMeta['publish']['embed-width'] = $def_org_theme_default_width;
     }
     if (isset($def_org_theme_default_height)) {
         $defaultMeta['publish']['embed-height'] = $def_org_theme_default_height;
     }
     $chart->setMetadata(json_encode($defaultMeta));
     // $chart->setLanguage($user->getLanguage());  // defaults to user language
     $chart->setShowInGallery(isset($defaults['show_in_gallery']) ? $defaults['show_in_gallery'] : false);
     $chart->save();
     return $chart;
 }
Exemplo n.º 3
0
function nbChartsByLayout($user)
{
    $con = Propel::getConnection();
    $sql = "SELECT theme, COUNT(*) c FROM chart WHERE author_id = " . $user->getId() . " AND deleted = 0 AND last_edit_step >= 2 GROUP BY theme ORDER BY c DESC ;";
    $rs = $con->query($sql);
    $res = array();
    foreach ($rs as $r) {
        $theme = DatawrapperTheme::get($r['theme']);
        if (!$theme) {
            continue;
        }
        // ignoring charts whose themes have been removed
        $res[] = array('count' => $r['c'], 'id' => $r['theme'], 'name' => $theme['title']);
    }
    return $res;
}
Exemplo n.º 4
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.º 5
0
 public function init()
 {
     DatawrapperTheme::register($this, $this->getMeta());
 }
Exemplo n.º 6
0
<?php

DatawrapperTheme::register($plugin, array('id' => 'slate', 'title' => 'Datawrapper (dark)', 'extends' => 'default'));
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
        $d = array(array(1, "second"), array(60, "minute"), array(3600, "hour"), array(86400, "day"), array(604800, "week"), array(2592000, "month"), array(31104000, "year"));
        $w = array();
        $return = array();
        $now = time();
        $diff = $now - $time;
        $secondsLeft = $diff;
        for ($i = 6; $i > -1; $i--) {
            $w[$i] = intval($secondsLeft / ($d[$i][0] * 2));
            $secondsLeft -= $w[$i] * $d[$i][0];
            if ($w[$i] != 0) {
                $return[] = abs($w[$i] * 2) . " " . $d[$i][1] . ($w[$i] > 1 ? 's' : '') . " ";
            }
        }
        $return = implode(' and ', array_slice($return, 0, 1));
        //. ($diff>0 ?"ago" : "left");
        return $return;
    };
    return array('url' => '/themes', 'title' => __('Themes', $plugin->getName()), 'controller' => function ($app, $page) use($plugin, $relativeTime) {
        $themes = DatawrapperTheme::all();
        foreach ($themes as $i => $theme) {
            $c = ChartQuery::create()->filterByTheme($theme['id'])->orderByLastModifiedAt('desc')->findOne();
            if ($c) {
                $themes[$i]['last_used'] = $relativeTime(strtotime($c->getLastModifiedAt()));
            } else {
                $themes[$i]['last_used'] = 'never';
            }
        }
        $page = array_merge($page, array('title' => 'Themes', 'themes' => $themes, 'count' => count_charts_per_themes()));
        $app->render('plugins/' . $plugin->getName() . '/admin-themes.twig', $page);
    }, 'order' => '3');
});
Exemplo n.º 10
0
            $chart->save();
        }
    }
    // delete user
    $user->delete();
    $user->save();
}
// create test user
$user = new User();
$user->setEmail('test');
$pwd = !empty($dw_config['testuser_pwd']) ? $dw_config['testuser_pwd'] : 'test';
$user->setPwd(hash_hmac('sha256', $pwd, DW_AUTH_SALT));
$user->setRole('editor');
$user->setCreatedAt(time());
$user->save();
$themes = DatawrapperTheme::all(true);
foreach (glob("../test/test-charts/*.json") as $test) {
    $config = json_decode(file_get_contents($test), true);
    $data = $config['_data'];
    unset($config['_data']);
    unset($config['_sig']);
    if (isset($config['_id'])) {
        $config['metadata']['describe']['__test_id'] = $config['_id'];
        unset($config['_id']);
    }
    unset($config['id']);
    foreach ($themes as $theme) {
        $chart = new Chart();
        $chart->setId(ChartQuery::create()->getUnusedRandomId());
        $chart->setUser($user);
        $chart->unserialize($config);
Exemplo n.º 11
0
<?php

/*
 * get list of all currently available themes
 *
 */
$app->get('/themes', function () {
    $res = DatawrapperTheme::all();
    ok($res);
});
$app->get('/themes/:themeid', function ($themeid) {
    $res = DatawrapperTheme::get($themeid);
    ok($res);
});
Exemplo n.º 12
0
 public function themesAdmin($app, $page)
 {
     $page = array_merge($page, array('title' => 'Themes', 'themes' => DatawrapperTheme::all(), 'count' => count_charts_per_themes()));
     $app->render('plugins/admin-themes/admin-themes.twig', $page);
 }
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
0
            $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 {
        $app->notFound();
    }
});
$app->get('/admin/users/?', function () use($app) {
    $user = DatawrapperSession::getUser();
    if ($user->isAdmin()) {
        $page = array('title' => 'Users', 'q' => $app->request()->params('q', ''));
        add_header_vars($page, 'admin');
        add_adminpage_vars($page, '/admin/users');
        $sort = $app->request()->params('sort', '');
        function getQuery($user)