<commit_before><?php

require_once ROOT_PATH . 'lib/utils/themes.php';


class DatawrapperPlugin_Gallery extends DatawrapperPlugin {

    public function init() {
        // register plugin controller under /gallery/
        DatawrapperHooks::register(
            DatawrapperHooks::GET_PLUGIN_CONTROLLER,
            array($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');
            }
        );
    }

    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 = 12;
            $filter = !empty($key) ? array($key => $val) : array();

            $charts =  ChartQuery::create()->getGalleryCharts($filter, $curPage * $perPage, $perPage);
            $total = ChartQuery::create()->countGalleryCharts($filter);
<commit_msg>hooking gallery link into header nav<commit_after><?php

require_once ROOT_PATH . 'lib/utils/themes.php';


class DatawrapperPlugin_Gallery extends DatawrapperPlugin {

    public function init() {
        // register plugin controller under /gallery/
        DatawrapperHooks::register(
            DatawrapperHooks::GET_PLUGIN_CONTROLLER,
            array($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'
            ));
        }
    }

    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 = 12;
            $filter = !empty($key) ? array($key => $val) : array();

            $charts =  ChartQuery::create()->getGalleryCharts($filter, $curPage * $perPage, $perPage);
            $total = ChartQuery::create()->countGalleryCharts($filter);

{'fraction_non_alphanumeric': 0.14195583596214512, 'fraction_numerical': 0.0017206767995411529, 'mean_word_length': 2.012089810017271, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6313874', 'n_tokens_mistral': 1021, 'n_tokens_neox': 968, 'n_words': 181}