Exemple #1
0
 public function controller($app)
 {
     $plugin = $this;
     $app->get('/gallery(/?|/by/:key/:val)', function ($key = false, $val = false) use($app, $plugin) {
         disable_cache($app);
         $user = DatawrapperSession::getUser();
         $curPage = $app->request()->params('page');
         if (empty($curPage)) {
             $curPage = 0;
         }
         $perPage = 60;
         $filter = !empty($key) ? array($key => $val) : array();
         try {
             $charts = ChartQuery::create()->getGalleryCharts($filter, $curPage * $perPage, $perPage);
             $total = ChartQuery::create()->countGalleryCharts($filter);
         } catch (Exception $e) {
             // make sure bogus input for the filter doesn't kill the site
             $charts = array();
             $total = 0;
         }
         $page = array('charts' => $charts, 'byvis' => $plugin->nbChartsByType(), 'key' => $key, 'val' => $val);
         add_pagination_vars($page, $total, $curPage, $perPage);
         add_header_vars($page, 'gallery');
         $app->render('plugins/' . $plugin->getName() . '/gallery.twig', $page);
     });
 }
Exemple #2
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);
    });
});