<commit_before><?php
// Initialize Container
$container = $app->getContainer();

// Configure Database
$db = $container['settings']['db'][$container['settings']['environment']];
$capsule = new \Illuminate\Database\Capsule\Manager();
$capsule->addConnection($db);
$capsule->setAsGlobal();
$capsule->bootEloquent();

$container['db'] = function () use ($capsule) {
    return $capsule;
};

$container['session'] = function () use ($container) {
    return new \SlimSession\Helper;
};

$container['projectDir'] = function ($container) {
    $directory = __DIR__ . "/../../";
    return realpath($directory);
};

$container['publicDir'] = function ($container) {
    $directory = __DIR__ . "/../../public/";
    return realpath($directory);
};

$container['uploadDir'] = function ($container) {
    $directory = __DIR__ . "/../../public/uploads/";
    return realpath($directory);
};

// Bind config table from database
$container['config'] = function () use ($container) {
    $config = new \Dappur\Dappurware\SiteConfig;
    $config = $config->getGlobalConfig();

    return $config;
};

// Bind Sentinel Authorization plugin
$container['auth'] = function () {
    $sentinel = new \Cartalyst\Sentinel\Native\Facades\Sentinel(
        new \Cartalyst\Sentinel\Native\SentinelBootstrapper(__DIR__ . '/sentinel.php')
    );

    return $sentinel->getSentinel();
};

// Bind User Permissions
$container['userAccess'] = function ($container) {
    return (new \Dappur\Dappurware\Sentinel($container))->userAccess();
};

// Bind Flash Messages
$container['flash'] = function () {
    return new \Slim\Flash\Messages();
};

// Bind Respect Validation
$container['validator'] = function () {
    return new \Awurth\SlimValidation\Validator();
};

// CSRF
$container['csrf'] = function ($container) {
    $guard = new \Slim\Csrf\Guard(
        $container->settings['csrf']['prefix'],
        $storage,
        null,
        $container->settings['csrf']['storage_limit'],
        $container->settings['csrf']['strength'],
        $container->settings['csrf']['persist_tokens']
    );

    $guard->setFailureCallable(function ($request, $response, $next) use ($container) {
        return $container['view']
            ->render($response, 'errors/csrf.twig')
            ->withHeader('Content-type', 'text/html')
            ->withStatus(401);
    });

    return $guard;
};

// Bind Twig View
$container['view'] = function ($container) {
    $template_path = __DIR__ . '/../views/' . $container->config['theme'];
    if (strpos($container['request']->getUri()->getPath(), '/dashboard') !== false) {
        $template_path = __DIR__ . '/../views/' . $container->config['dashboard-theme'];
    }

    $view = new \Slim\Views\Twig(
        $template_path,
        $container['settings']['view']['twig']
    );

    // Add Twig Extensions
    $view->addExtension(new \Slim\Views\TwigExtension(
        $container['router'],
        $container['request']->getUri()
    ));
    $view->addExtension(new \Twig_Extension_Debug());
    $view->addExtension(new \Dappur\TwigExtension\Asset($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\JsonDecode($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\Oauth2($container));
    $view->addExtension(new \Dappur\TwigExtension\Recaptcha($container['settings']['recaptcha']));
    $view->addExtension(new \Dappur\TwigExtension\Csrf($container['csrf']));
    $view->addExtension(new \Awurth\SlimValidation\ValidatorExtension($container['validator']));
    $view->addExtension(new \Dappur\TwigExtension\Md5($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\Gravatar($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\Menus($container));

    // Cloudinary View Settings
    $view->addExtension(new \Dappur\TwigExtension\Cloudinary());
    $view->getEnvironment()->addGlobal('hasCloudinary', 0);
    if ($container['cloudinary']) {
        $view->getEnvironment()->addGlobal('hasCloudinary', 1);
        if ($container->auth->check() && $container->auth->hasAccess('media.cloudinary')) {
            $view->getEnvironment()->addGlobal(
                'cloudinaryCmsUrl',
                \Dappur\Controller\Admin\Media::getCloudinaryCMS($container)
            );
            $view->getEnvironment()->addGlobal(
                'cloudinarySignature',
                \Dappur\Controller\Admin\Media::getCloudinaryCMS($container, true)
            );
            $view->getEnvironment()->addGLobal('cloudinaryApiKey', $container['settings']['cloudinary']['api_key']);
            $view->getEnvironment()->addGLobal('cloudinaryCloudName', $container['settings']['cloudinary']['cloud_name']);
        }
    }

    // Blog View Settings
    if ($container['config']['blog-enabled']) {
        // Get Categories With Count
        $blog_categories = new \Dappur\Model\BlogCategories;
        $blog_categories = $blog_categories->withCount(['posts' => function ($query) {
            $query->where('blog_posts.status', 1);
        }])
            ->whereHas('posts', function ($query) {
                $query->where('blog_posts.status', 1);
            })
            ->get();

        // Get Tags With Count
        $blog_tags = new \Dappur\Model\BlogTags;
        $blog_tags = $blog_tags->withCount([
            'posts' => function ($query) {
                $query->where('blog_posts.status', 1);
            }
        ])
            ->whereHas('posts', function ($query) {
                $query->where('blog_posts.status', 1);
            })
            ->get();

        // Get Recent Posts
        $blogPosts = \Dappur\Model\BlogPosts::orderBy('publish_at', 'DESC')
            ->where('publish_at', '<=', \Carbon\Carbon::now())
            ->where('status', 1)
            ->whereNotNull('featured_image')
            ->skip(0)
            ->take(4)
            ->get();

        // Get Recent Comments
        $blogComments = \Dappur\Model\BlogPostsComments::orderBy('created_at', 'DESC')
            ->where('status', 1)
            ->skip(0)
            ->take(4)
            ->get();

        $view->getEnvironment()->addGlobal('blogCategories', $blog_categories);
        $view->getEnvironment()->addGlobal('blogTags', $blog_tags);
        $view->getEnvironment()->addGlobal('blogRecent', $blogPosts);
        $view->getEnvironment()->addGlobal('blogComments', $blogComments);
    }
    
    $view->getEnvironment()->addGlobal('flash', $container['flash']);
    $view->getEnvironment()->addGlobal('auth', $container['auth']);
    $view->getEnvironment()->addGlobal('config', $container['config']);
    $view->getEnvironment()->addGlobal('displayErrorDetails', $container['settings']['displayErrorDetails']);
    $view->getEnvironment()->addGlobal('currentRoute', $container['request']->getUri()->getPath());
    $view->getEnvironment()->addGlobal('request', $container['request']);
    $view->getEnvironment()->addGlobal('requestParams', $container['request']->getParams());
    
    $page_name = $container['request']->getAttribute('name');
    if (strpos($container['request']->getUri()->getPath(), '/dashboard') !== false) {
        $page_settings = new \Dappur\Model\ConfigGroups;
        $page_settings = $page_settings
            ->select('page_name')<commit_msg>moved global variables<commit_after><?php
// Initialize Container
$container = $app->getContainer();

// Configure Database
$db = $container['settings']['db'][$container['settings']['environment']];
$capsule = new \Illuminate\Database\Capsule\Manager();
$capsule->addConnection($db);
$capsule->setAsGlobal();
$capsule->bootEloquent();

$container['db'] = function () use ($capsule) {
    return $capsule;
};

$container['session'] = function () use ($container) {
    return new \SlimSession\Helper;
};

$container['projectDir'] = function ($container) {
    $directory = __DIR__ . "/../../";
    return realpath($directory);
};

$container['publicDir'] = function ($container) {
    $directory = __DIR__ . "/../../public/";
    return realpath($directory);
};

$container['uploadDir'] = function ($container) {
    $directory = __DIR__ . "/../../public/uploads/";
    return realpath($directory);
};

// Bind config table from database
$container['config'] = function () use ($container) {
    $config = new \Dappur\Dappurware\SiteConfig;
    $config = $config->getGlobalConfig();

    return $config;
};

// Bind Sentinel Authorization plugin
$container['auth'] = function () {
    $sentinel = new \Cartalyst\Sentinel\Native\Facades\Sentinel(
        new \Cartalyst\Sentinel\Native\SentinelBootstrapper(__DIR__ . '/sentinel.php')
    );

    return $sentinel->getSentinel();
};

// Bind User Permissions
$container['userAccess'] = function ($container) {
    return (new \Dappur\Dappurware\Sentinel($container))->userAccess();
};

// Bind Flash Messages
$container['flash'] = function () {
    return new \Slim\Flash\Messages();
};

// Bind Respect Validation
$container['validator'] = function () {
    return new \Awurth\SlimValidation\Validator();
};

// CSRF
$container['csrf'] = function ($container) {
    $guard = new \Slim\Csrf\Guard(
        $container->settings['csrf']['prefix'],
        $storage,
        null,
        $container->settings['csrf']['storage_limit'],
        $container->settings['csrf']['strength'],
        $container->settings['csrf']['persist_tokens']
    );

    $guard->setFailureCallable(function ($request, $response, $next) use ($container) {
        return $container['view']
            ->render($response, 'errors/csrf.twig')
            ->withHeader('Content-type', 'text/html')
            ->withStatus(401);
    });

    return $guard;
};

// Bind Twig View
$container['view'] = function ($container) {
    $template_path = __DIR__ . '/../views/' . $container->config['theme'];
    if (strpos($container['request']->getUri()->getPath(), '/dashboard') !== false) {
        $template_path = __DIR__ . '/../views/' . $container->config['dashboard-theme'];
    }

    $view = new \Slim\Views\Twig(
        $template_path,
        $container['settings']['view']['twig']
    );

    // Add Twig Extensions
    $view->addExtension(new \Slim\Views\TwigExtension(
        $container['router'],
        $container['request']->getUri()
    ));
    $view->addExtension(new \Twig_Extension_Debug());
    $view->addExtension(new \Dappur\TwigExtension\Asset($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\JsonDecode($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\Oauth2($container));
    $view->addExtension(new \Dappur\TwigExtension\Recaptcha($container['settings']['recaptcha']));
    $view->addExtension(new \Dappur\TwigExtension\Csrf($container['csrf']));
    $view->addExtension(new \Awurth\SlimValidation\ValidatorExtension($container['validator']));
    $view->addExtension(new \Dappur\TwigExtension\Md5($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\Gravatar($container['request']));
    $view->addExtension(new \Dappur\TwigExtension\Menus($container));

    // Globla Variables
    $view->getEnvironment()->addGlobal('flash', $container['flash']);
    $view->getEnvironment()->addGlobal('auth', $container['auth']);
    $view->getEnvironment()->addGlobal('config', $container['config']);
    $view->getEnvironment()->addGlobal('displayErrorDetails', $container['settings']['displayErrorDetails']);
    $view->getEnvironment()->addGlobal('currentRoute', $container['request']->getUri()->getPath());
    $view->getEnvironment()->addGlobal('requestParams', $container['request']->getParams());

    // Cloudinary View Settings
    $view->addExtension(new \Dappur\TwigExtension\Cloudinary());
    $view->getEnvironment()->addGlobal('hasCloudinary', 0);
    if ($container['cloudinary']) {
        $view->getEnvironment()->addGlobal('hasCloudinary', 1);
        if ($container->auth->check() && $container->auth->hasAccess('media.cloudinary')) {
            $view->getEnvironment()->addGlobal(
                'cloudinaryCmsUrl',
                \Dappur\Controller\Admin\Media::getCloudinaryCMS($container)
            );
            $view->getEnvironment()->addGlobal(
                'cloudinarySignature',
                \Dappur\Controller\Admin\Media::getCloudinaryCMS($container, true)
            );
            $view->getEnvironment()->addGLobal('cloudinaryApiKey', $container['settings']['cloudinary']['api_key']);
            $view->getEnvironment()->addGLobal('cloudinaryCloudName', $container['settings']['cloudinary']['cloud_name']);
        }
    }

    // Blog View Settings
    if ($container['config']['blog-enabled']) {
        // Get Categories With Count
        $blog_categories = new \Dappur\Model\BlogCategories;
        $blog_categories = $blog_categories->withCount(['posts' => function ($query) {
            $query->where('blog_posts.status', 1);
        }])
            ->whereHas('posts', function ($query) {
                $query->where('blog_posts.status', 1);
            })
            ->get();

        // Get Tags With Count
        $blog_tags = new \Dappur\Model\BlogTags;
        $blog_tags = $blog_tags->withCount([
            'posts' => function ($query) {
                $query->where('blog_posts.status', 1);
            }
        ])
            ->whereHas('posts', function ($query) {
                $query->where('blog_posts.status', 1);
            })
            ->get();

        // Get Recent Posts
        $blogPosts = \Dappur\Model\BlogPosts::orderBy('publish_at', 'DESC')
            ->where('publish_at', '<=', \Carbon\Carbon::now())
            ->where('status', 1)
            ->whereNotNull('featured_image')
            ->skip(0)
            ->take(4)
            ->get();

        // Get Recent Comments
        $blogComments = \Dappur\Model\BlogPostsComments::orderBy('created_at', 'DESC')
            ->where('status', 1)
            ->skip(0)
            ->take(4)
            ->get();

        $view->getEnvironment()->addGlobal('blogCategories', $blog_categories);
        $view->getEnvironment()->addGlobal('blogTags', $blog_tags);
        $view->getEnvironment()->addGlobal('blogRecent', $blogPosts);
        $view->getEnvironment()->addGlobal('blogComments', $blogComments);
    }
    
    
    
    $page_name = $container['request']->getAttribute('name');
    if (strpos($container['request']->getUri()->getPath(), '/dashboard') !== false) {
        $page_settings = new \Dappur\Model\ConfigGroups;
        $page_settings = $page_settings
            ->select('page_name')
{'fraction_non_alphanumeric': 0.18937676080533222, 'fraction_numerical': 0.002336288050573765, 'mean_word_length': 3.2580456407255705, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 199, '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': '99176', 'n_tokens_mistral': 4285, 'n_tokens_neox': 4168, 'n_words': 625}