<commit_before><?php
namespace RpsCompetition\Frontend;

use Avh\Network\Session;
use Illuminate\Container\Container;
use Illuminate\Http\Request;
use RpsCompetition\Api\Client;
use RpsCompetition\Common\Core;
use RpsCompetition\Common\Helper as CommonHelper;
use RpsCompetition\Constants;
use RpsCompetition\Db\QueryCompetitions;
use RpsCompetition\Db\QueryEntries;
use RpsCompetition\Db\QueryMiscellaneous;
use RpsCompetition\Db\RpsDb;
use RpsCompetition\Frontend\Requests as FrontendRequests;
use RpsCompetition\Options\General as Options;
use RpsCompetition\Photo\Helper as PhotoHelper;
use RpsCompetition\Settings;
use Symfony\Component\HttpFoundation\File\Exception\FileException;

/**
 * Class Frontend
 *
 * @package RpsCompetition\Frontend
 */
class Frontend
{
    /** @var Container */
    private $container;
    /** @var Core */
    private $core;
    /** @var Options */
    private $options;
    /** @var Request */
    private $request;
    /** @var RpsDb */
    private $rpsdb;
    private $session;
    /** @var Settings */
    private $settings;
    private $view;

    /**
     * Constructor
     *
     * @param Container $container
     */
    public function __construct(Container $container)
    {
        $this->session = new Session(array('name' => 'raritan_' . COOKIEHASH));
        $this->session->start();

        $this->container = $container;

        $this->settings = $container->make('RpsCompetition\Settings');
        $this->rpsdb = $container->make('RpsCompetition\Db\RpsDb');
        $this->request = $container->make('Illuminate\Http\Request');
        $this->options = $container->make('RpsCompetition\Options\General');
        $this->core = new Core($this->settings);
        $requests = new FrontendRequests($this->settings, $this->rpsdb, $this->request, $this->session);
        $this->view = new View($this->settings, $this->rpsdb, $this->request);

        // The actions are in order as how WordPress executes them
        add_action('after_setup_theme', array($this, 'actionAfterThemeSetup'), 14);
        add_action('init', array($this, 'actionInit'), 11);
        add_action('parse_query', array($requests, 'actionHandleRequests'));
        add_action('wp_enqueue_scripts', array($this, 'actionEnqueueScripts'), 999);

        if ($this->request->isMethod('POST')) {
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsMyEntries'));
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsEditTitle'));
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsUploadEntry'));
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsBanquetEntries'));
        }
        add_action('template_redirect', array($this, 'actionTemplateRedirectRpsWindowsClient'));
        add_filter('query_vars', array($this, 'filterQueryVars'));
    }

    /**
     * Implement actions.
     * This method is called by the action after_setup_theme and is used to setup:
     *  - New actions
     *
     * @internal Hook: after_setup_theme
     */
    public function actionAfterThemeSetup()
    {
        add_action('rps_showcase', array($this, 'actionShowcaseCompetitionThumbnails'));
    }

    /**
     * Enqueue the needed javascripts.
     *
     * @internal Hook: wp_enqueue_scripts
     */
    public function actionEnqueueScripts()
    {
        global $wp_query;
        global $post;

        $scripts_directory_uri = $this->settings->get('plugin_url') . '/js/';
        if (WP_LOCAL_DEV !== true) {
            $rps_masonry_version = "a128c24";
            $masonry_version = "";
            $imagesloaded_version = "";
            $version_separator = '-';
        } else {
            $rps_masonry_version = "";
            $masonry_version = "";
            $imagesloaded_version = "";
            $version_separator = '';
        }

        $rps_masonry_script = 'rps.masonry' . $version_separator . $rps_masonry_version . '.js';
        $masonry_script = 'masonry' . $version_separator . $masonry_version . '.js';
        $imagesloaded_script = 'imagesloaded' . $version_separator . $imagesloaded_version . '.js';

        //todo Make as an option in the admin section.
        $options = get_option('avh-rps');
        $all_masonry_pages = array();
        $all_masonry_pages[] = $options['monthly_entries_post_id'];
        $scripts_directory_uri = $this->settings->get('plugin_url') . '/js/';
        wp_deregister_script('masonry');
        wp_register_script('masonry', $scripts_directory_uri . 'masonry.js', array(), 'to_remove', 1);
        wp_register_script('rps-imagesloaded', $scripts_directory_uri . 'imagesloaded.js', array('masonry'), 'to_remove', true);

        //wp_enqueue_script('rps-masonry');
        //wp_enqueue_script('rps-imagesloaded');
        if (in_array($wp_query->get_queried_object_id(), $all_masonry_pages)) {
            wp_enqueue_script('rps-masonryInit', $scripts_directory_uri . $rps_masonry_script, array('rps-imagesloaded'), 'to_remove', true);
        }

        if (has_shortcode($post->post_content, 'rps_person_winners')) {
            wp_enqueue_script('rps-masonryInit', $scripts_directory_uri . $rps_masonry_script, array('rps-imagesloaded'), 'to_remove', true);
        }
    }

    /**
     * Handle POST request for the Banquet Entries.
     * This method handles the POST request generated on the page for Banquet Entries
     * The action is called from the theme!<commit_msg>Make sure to load minified scripts in production<commit_after><?php
namespace RpsCompetition\Frontend;

use Avh\Network\Session;
use Illuminate\Container\Container;
use Illuminate\Http\Request;
use RpsCompetition\Api\Client;
use RpsCompetition\Common\Core;
use RpsCompetition\Common\Helper as CommonHelper;
use RpsCompetition\Constants;
use RpsCompetition\Db\QueryCompetitions;
use RpsCompetition\Db\QueryEntries;
use RpsCompetition\Db\QueryMiscellaneous;
use RpsCompetition\Db\RpsDb;
use RpsCompetition\Frontend\Requests as FrontendRequests;
use RpsCompetition\Options\General as Options;
use RpsCompetition\Photo\Helper as PhotoHelper;
use RpsCompetition\Settings;
use Symfony\Component\HttpFoundation\File\Exception\FileException;

/**
 * Class Frontend
 *
 * @package RpsCompetition\Frontend
 */
class Frontend
{
    /** @var Container */
    private $container;
    /** @var Core */
    private $core;
    /** @var Options */
    private $options;
    /** @var Request */
    private $request;
    /** @var RpsDb */
    private $rpsdb;
    private $session;
    /** @var Settings */
    private $settings;
    private $view;

    /**
     * Constructor
     *
     * @param Container $container
     */
    public function __construct(Container $container)
    {
        $this->session = new Session(array('name' => 'raritan_' . COOKIEHASH));
        $this->session->start();

        $this->container = $container;

        $this->settings = $container->make('RpsCompetition\Settings');
        $this->rpsdb = $container->make('RpsCompetition\Db\RpsDb');
        $this->request = $container->make('Illuminate\Http\Request');
        $this->options = $container->make('RpsCompetition\Options\General');
        $this->core = new Core($this->settings);
        $requests = new FrontendRequests($this->settings, $this->rpsdb, $this->request, $this->session);
        $this->view = new View($this->settings, $this->rpsdb, $this->request);

        // The actions are in order as how WordPress executes them
        add_action('after_setup_theme', array($this, 'actionAfterThemeSetup'), 14);
        add_action('init', array($this, 'actionInit'), 11);
        add_action('parse_query', array($requests, 'actionHandleRequests'));
        add_action('wp_enqueue_scripts', array($this, 'actionEnqueueScripts'), 999);

        if ($this->request->isMethod('POST')) {
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsMyEntries'));
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsEditTitle'));
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsUploadEntry'));
            add_action('suffusion_before_post', array($this, 'actionHandleHttpPostRpsBanquetEntries'));
        }
        add_action('template_redirect', array($this, 'actionTemplateRedirectRpsWindowsClient'));
        add_filter('query_vars', array($this, 'filterQueryVars'));
    }

    /**
     * Implement actions.
     * This method is called by the action after_setup_theme and is used to setup:
     *  - New actions
     *
     * @internal Hook: after_setup_theme
     */
    public function actionAfterThemeSetup()
    {
        add_action('rps_showcase', array($this, 'actionShowcaseCompetitionThumbnails'));
    }

    /**
     * Enqueue the needed javascripts.
     *
     * @internal Hook: wp_enqueue_scripts
     */
    public function actionEnqueueScripts()
    {
        global $wp_query;
        global $post;

        $scripts_directory_uri = $this->settings->get('plugin_url') . '/js/';
        if (WP_LOCAL_DEV !== true) {
            $rps_masonry_version = "a128c24";
            $masonry_version = "";
            $imagesloaded_version = "";
            $version_separator = '-';
        } else {
            $rps_masonry_version = "";
            $masonry_version = "";
            $imagesloaded_version = "";
            $version_separator = '';
        }

        $rps_masonry_script = 'rps.masonry' . $version_separator . $rps_masonry_version . '.js';
        $masonry_script = 'masonry' . $version_separator . $masonry_version . '.js';
        $imagesloaded_script = 'imagesloaded' . $version_separator . $imagesloaded_version . '.js';

        //todo Make as an option in the admin section.
        $options = get_option('avh-rps');
        $all_masonry_pages = array();
        $all_masonry_pages[] = $options['monthly_entries_post_id'];
        $scripts_directory_uri = $this->settings->get('plugin_url') . '/js/';
        wp_deregister_script('masonry');
        wp_register_script('masonry', $scripts_directory_uri . $masonry_script, array(), 'to_remove', 1);
        wp_register_script('rps-imagesloaded', $scripts_directory_uri . $imagesloaded_script, array('masonry'), 'to_remove', true);

        //wp_enqueue_script('rps-masonry');
        //wp_enqueue_script('rps-imagesloaded');
        if (in_array($wp_query->get_queried_object_id(), $all_masonry_pages)) {
            wp_enqueue_script('rps-masonryInit', $scripts_directory_uri . $rps_masonry_script, array('rps-imagesloaded'), 'to_remove', true);
        }

        if (has_shortcode($post->post_content, 'rps_person_winners')) {
            wp_enqueue_script('rps-masonryInit', $scripts_directory_uri . $rps_masonry_script, array('rps-imagesloaded'), 'to_remove', true);
        }
    }

    /**
     * Handle POST request for the Banquet Entries.
     * This method handles the POST request generated on the page for Banquet Entries
     * The action is called from the theme!
{'fraction_non_alphanumeric': 0.13349052326108643, 'fraction_numerical': 0.0023578489162963635, 'mean_word_length': 3.294392523364486, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '398519', 'n_tokens_mistral': 3419, 'n_tokens_neox': 3334, 'n_words': 624}