Esempio n. 1
0
 public function init()
 {
     $plugin = $this;
     // register plugin controller
     DatawrapperHooks::register(DatawrapperHooks::GET_ADMIN_PAGES, function () use($plugin) {
         return array('url' => '/users', 'title' => __('Users', $plugin->getName()), 'controller' => array($plugin, 'users'), 'order' => '2');
     });
     $this->declareAssets(array('vendor/serious-toolkit/serious-widget.js', 'dw.admin.users.js', 'users.css'), "|/admin/users|");
     $user = DatawrapperSession::getUser();
     if ($user->isAdmin()) {
         $this->registerController(function ($app) use($plugin) {
             $app->get('/admin/users/:user_id', function ($uid) use($app, $plugin) {
                 $theUser = UserQuery::create()->findPk($uid);
                 $page = array('title' => 'Users » ' . $theUser->guessName());
                 // manually add the admin nav menu vars
                 global $__dw_admin_pages;
                 foreach ($__dw_admin_pages as $adm_pg) {
                     $page['adminmenu'][$adm_pg['url']] = $adm_pg['title'];
                 }
                 add_header_vars($page, 'admin');
                 $page['the_user'] = $theUser;
                 $page['userPlugins'] = DatawrapperPluginManager::getUserPlugins($theUser->getId(), false);
                 $app->render('plugins/admin-users/admin-user-detail.twig', $page);
             });
         });
     }
 }
Esempio n. 2
0
 public function init()
 {
     // hook into chart publication
     DatawrapperHooks::register(DatawrapperHooks::POST_CHART_PUBLISH, array($this, 'triggerExportJob'));
     // hook into job execution
     DatawrapperHooks::register('export_static_chart', array($this, 'exportStaticPng'));
 }
Esempio n. 3
0
 public function init()
 {
     $plugin = $this;
     // register plugin controller
     DatawrapperHooks::register(DatawrapperHooks::GET_ADMIN_PAGES, function () use($plugin) {
         return array('url' => '/themes', 'title' => __('Themes', $plugin->getName()), 'controller' => array($plugin, 'themesAdmin'), 'order' => '3');
     });
 }
Esempio n. 4
0
 public function init()
 {
     $plugin = $this;
     // register plugin controller
     DatawrapperHooks::register(DatawrapperHooks::GET_ADMIN_PAGES, function () use($plugin) {
         return array('url' => '/users', 'title' => __('Users', $plugin->getName()), 'controller' => array($plugin, 'users'), 'order' => '2');
     });
     $this->declareAssets(array('vendor/serious-toolkit/serious-widget.js', 'dw.admin.users.js', 'users.css'), "|/admin/users|");
 }
Esempio n. 5
0
 public function init()
 {
     $plugin = $this;
     foreach ($this->getDemoDatasets() as $key => $dataset) {
         DatawrapperHooks::register(DatawrapperHooks::GET_DEMO_DATASETS, function () use($dataset) {
             return $dataset;
         });
     }
 }
Esempio n. 6
0
 public function init()
 {
     $plugin = $this;
     global $app;
     DatawrapperHooks::register(DatawrapperHooks::VIS_OPTION_CONTROLS, function ($o, $k) use($app, $plugin) {
         $env = array('option' => $o, 'key' => $k);
         $app->render('plugins/' . $plugin->getName() . '/controls.twig', $env);
     });
     DatawrapperHooks::register(DatawrapperHooks::VIS_OPTION_CONTROLS, function ($o, $k) use($app, $plugin) {
         $env = array('option' => $o, 'key' => $k);
         $app->render('plugins/' . $plugin->getName() . '/colorselector.twig', $env);
     });
     $this->declareAssets(array('sync-controls.js', 'sync-colorselector.js', 'colorpicker.css'), "|/chart/[^/]+/visualize|");
 }
Esempio n. 7
0
 public function init()
 {
     $plugin = $this;
     // hook into chart publication
     DatawrapperHooks::register(DatawrapperHooks::GET_CHART_ACTIONS, function () use($plugin) {
         return array('id' => 'export-image', 'title' => __("Export to static image for printing", $plugin->getName()), 'icon' => 'print');
     });
     // provide static assets files
     DatawrapperHooks::register(DatawrapperHooks::GET_PLUGIN_ASSETS, function ($uri) {
         if (basename($uri) == 'publish') {
             return array('export-image/export-image.js', 'export-image/export-image.css');
         }
     });
     // hook into job execution
     DatawrapperHooks::register('export_image', array($this, 'exportImage'));
 }
Esempio n. 8
0
 public function init()
 {
     $plugin = $this;
     // hook into chart publication
     DatawrapperHooks::register(DatawrapperHooks::GET_CHART_ACTIONS, function () use($plugin) {
         // no export possible without email
         $user = DatawrapperSession::getUser();
         if ($user->getEmail() == '') {
             return array();
         }
         return array('id' => 'export-image', 'title' => __("Export to static image for printing", $plugin->getName()), 'icon' => 'print');
     });
     // provide static assets files
     $this->declareAssets(array('export-image.js', 'export-image.css'), "|/chart/[^/]+/publish|");
     // hook into job execution
     DatawrapperHooks::register('export_image', array($this, 'exportImage'));
 }
Esempio n. 9
0
 public function init()
 {
     // register plugin controller under /gallery/
     $this->registerController($this, 'controller');
     // show link 'show in gallery'
     DatawrapperHooks::register(DatawrapperHooks::PUBLISH_AFTER_CHART_ACTIONS, function () {
         global $app;
         $app->render('plugins/gallery/show-in-gallery.twig');
     });
     // show link to gallery in mycharts page
     DatawrapperHooks::register(DatawrapperHooks::MYCHARTS_AFTER_SIDEBAR, function ($chart, $user) {
         global $app;
         $app->render('plugins/gallery/take-a-look.twig');
     });
     if (!DatawrapperSession::getUser()->isLoggedIn()) {
         $this->addHeaderNav('mycharts', array('url' => '/gallery/', 'id' => 'gallery', 'title' => __('Gallery'), 'icon' => 'signal'));
     }
 }
Esempio n. 10
0
 public function init()
 {
     $plugin = $this;
     // register plugin controller
     DatawrapperHooks::register(DatawrapperHooks::GET_ADMIN_PAGES, function () use($plugin) {
         // add badges to menu title
         $title = __('Jobs', $plugin->getName());
         $q = JobQuery::create()->filterByStatus('queued')->count();
         if ($q > 0) {
             $title .= ' <span class="badge badge-info">' . $q . '</span>';
         }
         $f = JobQuery::create()->filterByStatus('failed')->count();
         if ($f > 0) {
             $title .= ' <span class="badge badge-important">' . $f . '</span>';
         }
         return array('url' => '/jobs', 'title' => $title, 'controller' => array($plugin, 'jobsAdmin'), 'order' => '10');
     });
 }
Esempio n. 11
0
 public function init()
 {
     $meta = $this->getMeta();
     $datasets = $this->getDemoDataSets();
     $demo_hook = DatawrapperHooks::GET_DEMO_DATASETS;
     if (!empty($meta)) {
         DatawrapperVisualization::register($this, $meta);
     }
     if (!empty($datasets)) {
         $first_element = reset($datasets);
         if (is_array($first_element)) {
             foreach ($datasets as $key => $dataset) {
                 DatawrapperHooks::register($demo_hook, function () use($dataset) {
                     return $dataset;
                 });
             }
         } else {
             DatawrapperHooks::register($demo_hook, function () use($datasets) {
                 return $datasets;
             });
         }
     }
 }
Esempio n. 12
0
<?php

DatawrapperHooks::register(DatawrapperHooks::GET_ACCOUNT_PAGES, function () {
    return array('url' => 'mycharts', 'title' => __('My Charts'), 'icon' => 'fa-bar-chart-o', 'order' => 20, 'controller' => function ($app) {
        return function () use($app) {
            $app->redirect('/mycharts');
        };
    });
});
Esempio n. 13
0
    $body = __("email / activation / body");
    send_dw_mail($userEmail, __('email / activation / subject'), $body, array('name' => $userName, 'activation_link' => $activationLink));
});
/*
 * email when someone wants to reset password
 */
DatawrapperHooks::register(DatawrapperHooks::SEND_RESET_PASSWORD_EMAIL, function ($userEmail, $userName, $passwordResetLink) {
    $body = __("email / password-reset / body");
    send_dw_mail($userEmail, __('email / password-reset / subject'), $body, array('name' => $userName, 'password_reset_link' => $passwordResetLink));
});
/*
 * confirmation email when someone requests a change of email address
 */
DatawrapperHooks::register(DatawrapperHooks::SEND_CHANGE_EMAIL_EMAIL, function ($userEmail, $userName, $oldEmail, $confirmationLink) {
    $body = __('email / change-email / body');
    send_dw_mail($userEmail, __('email / change-email / subject'), $body, array('name' => $userName, 'email_change_token_link' => $confirmationLink, 'old_email' => $oldEmail, 'new_email' => $userEmail));
});
/*
 * classic invite email
 */
DatawrapperHooks::register(DatawrapperHooks::SEND_INVITE_EMAIL_TO_NEW_USER, function ($userEmail, $userName, $inviteLink) {
    $body = __("email / invite / body");
    send_dw_mail($userEmail, __('email / invite / subject'), $body, array('name' => $userName, 'invite_link' => $inviteLink));
});
/*
 * invite email to join a team
 */
DatawrapperHooks::register(DatawrapperHooks::SEND_TEAM_INVITE_EMAIL, function ($userEmail, $userName, $invitedByName, $teamName, $inviteLink) {
    $body = __("email / team-invite / body");
    send_dw_mail($userEmail, __('email / team-invite / subject'), $body, array('name' => $userName, 'team_name' => $teamName, 'invited_by' => $invitedByName, 'invite_link' => $inviteLink));
});
Esempio n. 14
0
DatawrapperHooks::register(DatawrapperHooks::GET_ACCOUNT_PAGES, function () {
    return array('title' => __('Edit profile'), 'order' => 5, 'icon' => 'fa-wrench', 'url' => 'profile', 'controller' => function ($app, $page) {
        return function () use($app, $page) {
            disable_cache($app);
            $user = $page['user'];
            if ($user->getRole() == 'guest') {
                error_settings_need_login();
                return;
            }
            if ($app->request()->get('token')) {
                // look for action with this token
                $t = ActionQuery::create()->filterByUser($user)->filterByKey('email-change-request')->orderByActionTime('desc')->findOne();
                if (!empty($t)) {
                    // check if token is valid
                    $params = json_decode($t->getDetails(), true);
                    if (!empty($params['token']) && $params['token'] == $app->request()->get('token')) {
                        // token matches
                        $user->setEmail($params['new-email']);
                        $user->save();
                        $page['new_email_confirmed'] = true;
                        // clear token to prevent future changes
                        $params['token'] = '';
                        $t->setDetails(json_encode($params));
                        $t->save();
                    }
                }
            }
            if ($user->getRole() == 'pending') {
                $t = ActionQuery::create()->filterByUser($user)->filterByKey('resend-activation')->orderByActionTime('desc')->findOne();
                if (empty($t)) {
                    $t = $user->getCreatedAt('U');
                } else {
                    $t = $t->getActionTime('U');
                }
                $page['activation_email_date'] = strftime('%x', $t);
            }
            $app->render('account/profile.twig', $page);
        };
    });
});
Esempio n. 15
0
<?php

DatawrapperVisualization::register($plugin, array('title' => __('Line Chart'), 'id' => 'line-chart', 'extends' => 'raphael-chart', 'dimensions' => 2, 'order' => 40, 'axes' => array('x' => array('accepts' => array('text', 'date')), 'y1' => array('accepts' => array('number'), 'multiple' => true), 'y2' => array('accepts' => array('number'), 'multiple' => true, 'optional' => true)), 'options' => array('base-color' => array('type' => 'base-color', 'label' => __('Base color')), 'sep-labeling' => array('type' => 'separator', 'label' => __('Customize labeling'), 'depends-on' => array('chart.min_columns[y1]' => 2)), 'direct-labeling' => array('type' => 'checkbox', 'label' => __('Direct labeling'), 'default' => false, 'depends-on' => array('chart.min_columns[y1]' => 2, 'chart.max_columns[y2]' => 0), 'help' => __('Show the labels right nearby the line ends instead of a separate legend')), 'legend-position' => array('type' => 'radio-left', 'label' => __('Legend position'), 'default' => 'right', 'depends-on' => array('direct-labeling' => false, 'chart.min_columns[y1]' => 2), 'options' => array(array('value' => 'right', 'label' => __('right')), array('value' => 'top', 'label' => __('top')), array('value' => 'inside', 'label' => __('inside left')), array('value' => 'inside-right', 'label' => __('inside right')))), 'sep-lines' => array('type' => 'separator', 'label' => __('Customize lines')), 'show-grid' => array('type' => 'checkbox', 'hidden' => true, 'label' => __('Show grid'), 'default' => false), 'connect-missing-values' => array('type' => 'checkbox', 'label' => __('Connect lines between missing values')), 'fill-between' => array('type' => 'checkbox', 'label' => __('Fill area between lines'), 'default' => false, 'depends-on' => array('chart.min_columns[y1]' => 2, 'chart.max_columns[y1]' => 2, 'chart.max_columns[y2]' => 0)), 'fill-below' => array('type' => 'checkbox', 'label' => __('Fill area below line'), 'defaut' => false, 'depends-on' => array('chart.min_columns[y1]' => 1, 'chart.max_columns[y1]' => 1, 'chart.max_columns[y2]' => 0)), 'banking' => array('type' => 'linechart-banking', 'label' => __('Suggest aspect ratio that banks average line slopes to 45°'), 'help' => __('Adjust the chart height so that the lines are banked to 45° (on average). Can help to avoid exaggerating and understating of slopes.')), 'line-mode' => array('type' => 'radio-left', 'label' => __('Line interpolation'), 'options' => array(array('label' => __('Straight'), 'value' => 'straight'), array('label' => __('Curved'), 'value' => 'curved'), array('label' => __('Stepped'), 'value' => 'stepped')), 'default' => 'straight'), 'sep-y-axis' => array('type' => 'separator', 'label' => __('Customize y-axis')), 'custom-range-y' => array('type' => 'custom-range', 'label' => __('Custom range'), 'help' => __('This feature allows you to explicitely extend the y axis to custom values. Swap min/max to invert the axis.')), 'scale-y1' => array('type' => 'radio-left', 'label' => __('Scale (y-axis)'), 'options' => array(array('label' => __('linear'), 'value' => 'linear'), array('label' => __('logarithmic'), 'value' => 'log')), 'default' => 'linear', 'depends-on' => array('chart.min_value[y1]' => '>0', 'chart.magnitude_range[y1]' => '>3')), 'user-change-scale' => array('type' => 'checkbox', 'label' => __('Let user change scale'), 'default' => false, 'depends-on' => array('chart.min_value[y1]' => '>0', 'chart.magnitude_range[y1]' => '>3')), 'annotate-time-axis' => array('type' => 'textarea', 'label' => __('Annotate x axis') . ':', 'placeholder' => 'from,to,text', 'width' => '180px')), 'locale' => array('tooManyLinesToLabel' => __('Your chart contains <b>more lines than we can label</b>, so automatic labeling is turned off. To fix this <ul><li>filter some columns in the data table in the previous step, or</li><li>use direct labeling and the highlight feature to label the lines that are important to your story.</li></ul>'), 'useLogarithmicScale' => __('Use logarithmic scale'), 'couldNotParseAllDates' => str_replace('%s', 'http://blog.datawrapper.de/2013/cleaning-your-data-in-datawrapper/', __('Some of the <b>dates in your x-axis could not be parsed</b>, hence the line chart cannot display a proper date axis. To fix this<ul><li>return to the previous step and clean your date column.</li><li><a href="%s">Read more about how to do this.</a></li></ul>')))));
global $app;
DatawrapperHooks::register(DatawrapperHooks::VIS_OPTION_CONTROLS, function ($o, $k) use($app, $plugin) {
    $env = array('option' => $o, 'key' => $k);
    $app->render('plugins/' . $plugin->getName() . '/banking.twig', $env);
});
$plugin->declareAssets(array('banking.js'), "|/chart/[^/]+/visualize|");
Esempio n. 16
0
DatawrapperHooks::register(DatawrapperHooks::GET_ADMIN_PAGES, function () use($plugin) {
    $relativeTime = function ($time) {
        $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');
});
Esempio n. 17
0
 public function init()
 {
     DatawrapperHooks::register('phantomjs_exec', array($this, 'executeScript'));
 }
Esempio n. 18
0
<?php

DatawrapperHooks::register(DatawrapperHooks::GET_ACCOUNT_PAGES, function () {
    return array('title' => __('Delete account'), 'order' => 9999, 'icon' => 'fa-frown-o', 'url' => 'delete', 'controller' => function ($app, $context) {
        return function () use($app, $context) {
            disable_cache($app);
            $user = $context['user'];
            if ($user->getRole() == 'guest') {
                error_settings_need_login();
                return;
            }
            $app->render('account/delete.twig', $context);
        };
    });
});
Esempio n. 19
0
 public function init()
 {
     DatawrapperHooks::register(DatawrapperHooks::AFTER_CHART_BODY, array($this, 'getTrackingCode'));
     DatawrapperHooks::register(DatawrapperHooks::AFTER_CORE_BODY, array($this, 'getTrackingCode'));
 }
Esempio n. 20
0
 public function registerController($obj, $func)
 {
     DatawrapperHooks::register(DatawrapperHooks::GET_PLUGIN_CONTROLLER, array($obj, $func));
 }
Esempio n. 21
0
 public function init()
 {
     DatawrapperHooks::register(DatawrapperHooks::PUBLISH_FILES, array($this, 'publish'));
     DatawrapperHooks::register(DatawrapperHooks::UNPUBLISH_FILES, array($this, 'unpublish'));
     DatawrapperHooks::register(DatawrapperHooks::GET_PUBLISHED_URL, array($this, 'getUrl'));
 }
Esempio n. 22
0
 public function registerAdminPage($obj, $func = null)
 {
     DatawrapperHooks::register(DatawrapperHooks::GET_ADMIN_PAGES, is_callable($obj) ? $obj : array($obj, $func));
 }
Esempio n. 23
0
 public function init()
 {
     DatawrapperHooks::register(DatawrapperHooks::SEND_EMAIL, array($this, 'sendMail'));
 }
Esempio n. 24
0
<?php

DatawrapperHooks::register(DatawrapperHooks::SEND_EMAIL, function ($to, $subject, $body, $headers = '') {
    $config = $GLOBALS['dw_config'];
    if (empty($headers)) {
        $from = isset($config['email']['sender']) ? $config['email']['sender'] : 'noreply@' . $config['domain'];
        $headers = 'From: ' . $from;
    }
    return mail($to, $subject, $body, $headers);
});