<?php

defined('BASEPATH') or exit('No direct script access allowed');
class Engine extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function search_builder()
    {
        // Système de redirection à améliorer
        $cat_id = $this->input->get('id');
        if ($cat_id <= 2145) {
            redirect('engine/search?name=&description=&file=&uploader=&category=' . $cat_id . '&sub_category=all&do=search');
        } else if ($cat_id <= 2191) {
            $parent_category_id = $this->db->where('id', $cat_id)->get('categories')->row()->parent;
            redirect('engine/search?name=&description=&file=&uploader=&category=' . $parent_category_id . '&sub_category=' . $cat_id . '&do=search');
        } else {
            redirect(base_url());
        }
    }


    public function go_twitter()
    {
        $country = strtolower($_SERVER['HTTP_CF_IPCOUNTRY']);
        if (in_array($country, array('fr', 'be', 'ca', 'ch', 'ma', 'dz')) && $this->session->logged) {
            redirect('https://twitter.com/Yggtorrent_luke');
        } else {
            redirect('https://www.yggtorrent.top');
        }
    }

    public function go_telegram()
    {
        $country = strtolower($_SERVER['HTTP_CF_IPCOUNTRY']);
        if (in_array($country, array('fr', 'be', 'ca', 'ch', 'ma', 'dz'))) {
            redirect('https://t.me/tpmt_ygg');
        } else {
            redirect('https://www.yggtorrent.top');
        }
    }

    public function hcaptcha()
    {
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $data = array(
                'secret' => '0x2B8C9E0705c3b48501Eb3d817d39D3C95A9AE0aA',
                'response' => $_POST['h-captcha-response']
            );
            $verify = curl_init();
            curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify");
            curl_setopt($verify, CURLOPT_POST, true);
            curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
            curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($verify);
            $responseData = json_decode($response);
            if ($responseData->success) {
                echo 'OK';
            } else {
                echo 'NO';
            }
        }
        $this->load->view('engine/test');
    }


    public function dmca()
    {
        $this->load->view('engine/dmca');
    }

    public function go_vpn()
    {
        redirect('https://itrustzone.site/r.php?RID=B-2JGHG-MDAxNjA5MDMxMzY4');
    }

    public function domains()
    {
        $this->load->view('engine/domains_name');
    }

    public function search_users()
    {
        $nickname = $this->input->get('nickname');

        if (isset($nickname) && $nickname != '') {

            $query = 'SELECT * FROM users WHERE MATCH(\'@nick ' . $this->_escape($nickname . '*') . '| ' . $this->_escape($nickname) . ' \')';

            $config['page_query_string'] = true;
            $config['query_string_segment'] = 'page';

            $offset = $this->input->get($config['query_string_segment']);
            if (empty($offset)) {
                $offset = 0;
            }

            $get_vars = $this->input->get();

            $query .= ' LIMIT 20';

            $query .= ' OPTION max_matches=10000';

            $conn = new mysqli($this->config->item('sphinx_server'), null, null, null, $this->config->item('sphinx_server_port'));

            if ($conn->connect_error) {
                throw new Exception('Connection Error: [' . $conn->connect_errno . '] ' . $conn->connect_error, $conn->connect_errno);
            }

            $query_search = $conn->query($query);

            $results = array();

            while ($row = $query_search->fetch_assoc()) {
                $results[] = $row['id'];
            }

            $query_search->free_result();

            $ids = join('\',\'', $results);

            $sql = "SELECT id, avatar, rank, uploaded, downloaded, last_activity_date, nickname, country FROM users WHERE id IN ('$ids') ORDER BY FIELD (users.id,'$ids')";

            $meta_resource = $conn->query('SHOW META');

            //$meta = $meta_resource->fetch_all();
            $results_array = array();
            while ($row = $meta_resource->fetch_assoc()) {
                $results_array[] = $row;
            }

            $meta_resource->free_result();
            $data['search_time'] = $results_array[3]['Value'];
            $data['total_rows'] = $results_array[1]['Value'];

            $data['total_rows'] > 10000 ? $config['total_rows'] = 10000 : $config['total_rows'] = $data['total_rows'];
            // Pagination config
            $config['page_query_string'] = true;
            $config['query_string_segment'] = 'page';
            $offset = $this->input->get($config['query_string_segment']);
            $get_vars = $this->input->get();
            // on supprime la page
            unset($get_vars['page']);
            $config['first_url'] = current_url() . '?' . http_build_query($get_vars);
            $config['base_url'] = current_url() . '?' . http_build_query($get_vars);
            $config['per_page'] = '25';
            $config['num_links'] = 8;

            $configuration = array_merge($config, pagination_html());
            // initialisation de la pagination
            $this->pagination->initialize($configuration);

            $data['users'] = $this->db->query($sql)->result();

            if (count($data['users']) == 0) {
                $data['no_result'] = true;
            }
        }
        $this->load->view('engine/search_users', $data);
    }

    public function profile($id = '')
    {
        $action = $this->input->get('action');

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if ($action == 'ajax_load_comments') {
                $id = $this->input->post('user_id', true);
                $type = $this->input->post('type', true);
                $offset = $this->input->post('offset', true);

                $comments = $this->users->get_user_comments($id, 15, $offset);

                $out = '';
                foreach ($comments as $comment) {
                    $comment->comment_id = $comment->id;
                    $data['comment'] = $comment;
                    $out .= $this->load->view('extra/comment_user_profile', $data, true);
                }

                $this->output->set_content_type('application/json')->set_output(json_encode(array('html' => $out, 'length' => count($comments))));
            }
        } else {
            // Récupération infos de l'utilisateur
            $user = $this->users->get_userdata($id);

            // Si l'utilisateur n'existe pas
            if (!count($user) > 0) {
                redirect(base_url());
                exit();
            } else {
                $ignoredList = $this->db->select('ignored')->where('id', $this->session->id)->get('users')->row()->ignored;
                $ignoredList = json_decode($ignoredList, JSON_OBJECT_AS_ARRAY);

                if (array_key_exists($id, $ignoredList)) {
                    $data['blockedUser'] = true;
                }

                $settings = $user->settings;
                $settings = json_decode($settings, JSON_OBJECT_AS_ARRAY);

                if ($settings['anonymous_upload'] && in_array($this->session->rank, array(1, 2, 3)) == false) {
                    $data['anonymous_uploader'] = true;
                    $data['count_torrents'] = 0;
                } else {
                    $data['count_torrents'] = $this->db->select('id')->where('uploader', $user->id)->get('torrents')->num_rows();
                    // Récupération des 15 derniers torrents de l'utilisateur
                    $data['torrents'] = $this->users->get_profile_torrents($user->id, 100, 0);
                }

                // Récupération nombre de commentaire de l'utilisateur
                $data['count_comments'] = $this->db->select('id')->where('publisher', $user->id)->get('comments')->num_rows();

                $data['user'] = $user;

                if ($action == 'show_comments') {

                    $data['comments'] = $this->users->get_user_comments($data['user']->id);
                    //print_r($data['comments']);
                    $data['show_comments'] = 1;
                }

                $this->load->view('engine/profile_user', $data);
            }
        }
    }

    /**
     * Génère un token pour le téléchargement (utilisateurs restreints)
     * Appelé via AJAX quand le compteur démarre
     */
    public function start_download_timer()
    {
        if (!$this->session->id) {
            $this->output->set_status_header(403);
            return;
        }
        
        $torrent_id = $this->input->post('torrent_id', true);
        if (!$torrent_id) {
            $this->output->set_status_header(400);
            return;
        }
        
        $this->config->load('yggconfig');
        $timer_seconds = $this->config->item('download_timer_seconds') ?: 30;
        
        // Générer un token unique
        $token = bin2hex(random_bytes(16));
        
        // Stocker en session : token, torrent_id, timestamp de démarrage
        $this->session->set_userdata('download_timer', [
            'token' => $token,
            'torrent_id' => (int)$torrent_id,
            'started_at' => time(),
            'required_wait' => $timer_seconds
        ]);
        
        $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode(['token' => $token]));
    }

    public function download_torrent()
    {
        $torrent_id = $this->input->get('id', true);
        $token = $this->input->get('token', true);
        
        if ($this->session->id != null) {
            // Rate limiting : 5 téléchargements max par minute (anti-scraping)
            $rate_limit = 7;
            $rate_window = 60; // secondes
            $download_timestamps = $this->session->userdata('download_timestamps') ?: [];
            $now = time();
            
            // Nettoyer les timestamps de plus d'une minute
            $download_timestamps = array_filter($download_timestamps, function($ts) use ($now, $rate_window) {
                return ($now - $ts) < $rate_window;
            });
            
            // Vérifier la limite
            if (count($download_timestamps) >= $rate_limit) {
                $oldest = min($download_timestamps);
                $wait_time = $rate_window - ($now - $oldest);
                show_error('Trop de téléchargements. Veuillez patienter quelques secondes.', 429);
                return;
            }
            
            // Ajouter le timestamp actuel
            $download_timestamps[] = $now;
            $this->session->set_userdata('download_timestamps', $download_timestamps);
            
            if ($this->session->can_leech == 0) {
                redirect('/donation/bonus');
            } else {
                // Récupérer le torrent d'abord pour vérifier si c'est le propre torrent de l'utilisateur
                $torrent = $this->db->where('id', $torrent_id)->get('torrents')->row();
                $is_own_torrent = ($torrent && $torrent->uploader == $this->session->id);
                
                // Vérifier limite quotidienne pour utilisateurs restreints (sauf pour ses propres torrents)
                $this->config->load('yggconfig');
                $min_user_id = $this->config->item('download_timer_min_user_id');
                $exempt_ranks = $this->config->item('download_timer_exempt_ranks') ?: [];
                $daily_limit = $this->config->item('daily_download_limit') ?: 5;
                $timer_seconds = $this->config->item('download_timer_seconds') ?: 30;
                $premium_until = isset($this->session->premium_until) ? (int)$this->session->premium_until : 0;
                $is_turbo = ($premium_until == -1 || ($premium_until > 0 && $premium_until > now()));
                $is_restricted = ($this->session->id >= $min_user_id && !in_array($this->session->rank, $exempt_ranks) && !$is_turbo && !$is_own_torrent);
                
                // Vérification du token pour les utilisateurs restreints
                if ($is_restricted) {
                    $timer_data = $this->session->userdata('download_timer');
                    
                    // Vérifier que le token existe et correspond
                    if (!$timer_data || 
                        $timer_data['token'] !== $token || 
                        $timer_data['torrent_id'] !== (int)$torrent_id) {
                        show_error('Token invalide. Veuillez utiliser le bouton de téléchargement.', 403);
                        return;
                    }
                    
                    // Vérifier que le temps d'attente est écoulé (avec 2 sec de tolérance)
                    $elapsed = time() - $timer_data['started_at'];
                    if ($elapsed < ($timer_seconds - 2)) {
                        show_error('Veuillez patienter ' . ($timer_seconds - $elapsed) . ' secondes.', 403);
                        return;
                    }
                    
                    // Invalider le token (usage unique)
                    $this->session->unset_userdata('download_timer');
                }
                
                if ($is_restricted && $daily_limit > 0) {
                    $limit_data = $this->db->where('user_id', $this->session->id)->get('user_download_limits')->row();
                    $today = date('Y-m-d');
                    $current_count = ($limit_data && $limit_data->reset_date == $today) ? (int)$limit_data->download_count : 0;
                    
                    if ($current_count >= $daily_limit) {
                        redirect('/user/turbo?limit_reached=1');
                        return;
                    }
                }
                $userdata = $this->db->select('torrent_pass, downloads')->where('id', $this->session->id)->get('users')->row();

                $futuredownload = $torrent->size + $this->session->downloaded;
                if (
                    $futuredownload >= $this->session->uploaded
                    && $this->session->download_multiplier == 1
                    && ($this->session->rank == 0 || $this->session->rank == 4)
                    && $torrent->uploader != $this->session->id
                ) {
                    $this->session->moredownload = true;
                    redirect('/donation/bonus?abort_download=' . $torrent->id);
                } else {
                    if ($this->session->tracker_id == 1) {
                        $tracker_host = $this->config->item('secondary_tracker_host');
                    } else {
                        $tracker_host = $this->config->item('first_tracker_host');
                    }
                    $announce_url = 'http://' . $tracker_host . ':8080/' . $userdata->torrent_pass . '/announce';
                    
                    // Génération de la signature d'annonce anti-partage
                    $announce_signature_key = $this->config->item('announce_signature_key');
                    if (!empty($announce_signature_key)) {
                        $uid = $this->session->id;
                        $info_hash = pack('H*', $torrent->hash_info); // Convertir hex en binaire
                        $timestamp = time();
                        
                        // Message = uid + info_hash (binaire) + timestamp
                        $message = $uid . $info_hash . $timestamp;
                        
                        // Signature HMAC-SHA1
                        $signature = hash_hmac('sha1', $message, $announce_signature_key);
                        
                        // Ajouter les paramètres de signature à l'URL
                        $announce_url .= '?announce_sig=' . $signature . '&announce_ts=' . $timestamp;
                    }
                    if (!$this->session->settings['disable_history']) {
                        $downloads = $userdata->downloads;
                        $downloads = (array) json_decode($downloads);
                        if (!is_array($downloads)) {
                            $downloads = array();
                        }
                        $key = 'torrent_' . $torrent->id;
                        if (!array_key_exists($key, $downloads)) {
                            $downloads[$key] = now();
                            $this->db->where('id', $this->session->id)->set('downloads', json_encode($downloads))->update('users');
                        }
                    }
                    $date_folder_torrent = date('d-m-y', $torrent->publish_date);
                    $this->load->library('TorrentParser', array($date_folder_torrent . '/' . $torrent->file_key));
                    $builder = $this->torrentparser->parser;
                    $builder->announce(false);
                    $builder->announce($announce_url);
                    $builder->is_private(true);
                    
                    // Incrémenter le compteur quotidien pour utilisateurs restreints
                    if ($is_restricted && $daily_limit > 0) {
                        $today = date('Y-m-d');
                        $this->db->query(
                            "INSERT INTO user_download_limits (user_id, download_count, reset_date) 
                             VALUES (?, 1, ?) 
                             ON DUPLICATE KEY UPDATE 
                             download_count = IF(reset_date = ?, download_count + 1, 1),
                             reset_date = ?",
                            [$this->session->id, $today, $today, $today]
                        );
                    }
                    
                    $builder->send();
                }

            }
        } else {
            echo 'Vous devez vous connecter pour télécharger un torrent';
        }
    }

    public function error()
    {
        $type = $this->input->get('http_code');
        if ($type == '403') {
            if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
                $this->output->set_content_type('application/json')->set_output(json_encode(array('error' => 'Connection requise pour effectuer cette action')));
                $this->output->set_status_header(403);
                return true;
            }
            $this->index(403);
        }
    }


    public function exclus()
    {
        // On construit la req sphinx
        $sort = $this->input->get('sort', true);
        $order = $this->input->get('order', true);

        $query = 'SELECT * FROM torrents WHERE MATCH(\'@state 0\') AND is_exclusivity = 1';

        $sort_array = array('publish_date', 'name', 'size', 'seed', 'leech', 'completed', 'comments');

        if (!in_array($sort, $sort_array)) {
            $sort = 'publish_date';
        }

        if ($sort == 'name') {
            $sort = 'sortable_name';
        }

        if ($sort == 'comments') {
            $sort = 'comments_count';
        }

        if ($order != 'asc' && $order != 'desc') {
            $order = 'desc';
        }

        $query .= ' ORDER BY ' . $sort . ' ' . $order;

        $config['page_query_string'] = true;
        $config['query_string_segment'] = 'page';

        $offset = $this->input->get($config['query_string_segment']);
        if (empty($offset)) {
            $offset = 0;
        }

        $get_vars = $this->input->get();

        $query .= ' LIMIT ' . $offset . ', 25 ';

        $query .= ' OPTION max_matches=10000';


        $conn = new mysqli($this->config->item('sphinx_server'), null, null, null, $this->config->item('sphinx_server_port'));

        if ($conn->connect_error) {
            throw new Exception('Connection Error: [' . $conn->connect_errno . '] ' . $conn->connect_error, $conn->connect_errno);
        }

        $query_search = $conn->query($query);

        $results = array();

        while ($row = $query_search->fetch_assoc()) {
            $results[] = $row['id'];
        }
        $query_search->free_result();

        $ids = join('\',\'', $results);

        $sql = "SELECT `torrents`.*, `torrents`.`category` AS `category_id` FROM `torrents` WHERE `torrents`.`id` IN ('$ids') ORDER BY FIELD (torrents.id,'$ids')";

        $meta_resource = $conn->query('SHOW META');

        //$meta = $meta_resource->fetch_all();
        $results_array = array();
        while ($row = $meta_resource->fetch_assoc()) {
            $results_array[] = $row;
        }

        $meta_resource->free_result();
        $data['search_time'] = $results_array[3]['Value'];
        $data['total_rows'] = $results_array[1]['Value'];

        $data['total_rows'] > 10000 ? $config['total_rows'] = 10000 : $config['total_rows'] = $data['total_rows'];
        // Pagination config
        $config['page_query_string'] = true;
        $config['query_string_segment'] = 'page';
        $offset = $this->input->get($config['query_string_segment']);
        $get_vars = $this->input->get();
        // on supprime la page
        unset($get_vars['page']);
        $config['first_url'] = current_url() . '?' . http_build_query($get_vars);
        $config['base_url'] = current_url() . '?' . http_build_query($get_vars);
        $config['per_page'] = '25';
        $config['num_links'] = 8;

        $configuration = array_merge($config, pagination_html());
        // initialisation de la pagination
        $this->pagination->initialize($configuration);

        $data['torrents'] = $this->db->query($sql)->result();

        $this->load->view('torrent/exclus.php', $data);
    }

    /***	public function get_encoded_url($torrentId)
    {
    $data['torrent'] = $this->db->where('id', $torrentId)->get('torrents')->row();
    
    if(count($data['torrent']) > 0){
    $data_query['category_slug']   = $this->torrents->generate_category_slug($data['torrent']->category);
    echo 'https://www2.yggtorrent.gg/torrent/'.urlencode($data_query['category_slug']).'/'.urlencode($data['torrent']->id.'-'.url_title(str_replace('.',' ',$data['torrent']->name),'+',true));
    } else {
    echo 'error';
    }
    }
    **/


    /**
     * Searches for the first match.
     *
     * @throws     Exception  (description)
     */
    public function search()
    {
        $data['parent_categories'] = $this->torrents->get_parent_categories();

        $get = $this->input->get(null, true);

        foreach ($get as $key => $option_value) {
            if (strpos($key, 'option') !== false) {
                if (strpos($key, ':multiple') !== false) {
                    $data['options_multiple'][str_replace(':multiple', '', $key)] = $option_value;
                } else {
                    $data['options_classic'][$key] = $option_value;
                }
            }
        }

        if (isset($_GET['do'])) {


            // récupération des valeurs d'entrées
            $name = $this->input->get('name', true);
            $description = $this->input->get('description', true);
            $file = $this->input->get('file', true);
            $category = $this->input->get('category', true);
            $sub_category = $this->input->get('sub_category', true);
            $uploader = $this->input->get('uploader', true);
            $sort = $this->input->get('sort', true);
            $order = $this->input->get('order', true);

            // construction requête , certes pas très propre mais fonctionnelle
            if (count($data['options_multiple']) > 0) {
                $query = 'SELECT *';
            } else {
                $query = 'SELECT * FROM torrents';
            }

            foreach ($data['options_multiple'] as $key => $option) {
                $options = rtrim(implode(',', $option), ',');
                $query .= ',IN(options.' . $key . ',' . $options . ') AS ' . $key . ' ';
            }

            if (count($data['options_multiple']) > 0) {
                $query .= 'FROM torrents';
            }

            $query .= ' WHERE MATCH(';

            if (empty($_GET['name'])) {
                $query .= '\'@state 0';
            } else {
                $query .= '\'@name "^' . $this->_escape($name) . '$"|"' . $this->_escape($name) . '"|(' . $this->_escape($name) . ') ';
            }

            if (isset($_GET['description']) && trim($_GET['description']) != '') {
                $query .= ' MAYBE (@description "^' . $this->_escape($description) . '$"|"' . $this->_escape($description) . '"|(' . $this->_escape($description) . ')) ';
            }

            if (isset($_GET['file']) && trim($_GET['file']) != '') {
                $query .= ' MAYBE (@files "^' . $this->_escape($file) . '$"|"' . $this->_escape($file) . '"|(' . $this->_escape($file) . ')) ';
            }

            if (isset($_GET['uploader']) && trim($_GET['uploader']) != '') {
                $query .= ' @nickname ' . $this->_escape($uploader) . '';
            }

            $query .= '\')';

            if (isset($_GET['sub_category']) && trim($_GET['sub_category']) != '' && $_GET['sub_category'] != 'all') {
                $query .= ' AND category = ' . $sub_category . ' ';
            } else if (isset($_GET['category']) && trim($_GET['category']) != '' && $_GET['category'] != 'all') {
                $query .= ' AND parent_category = ' . $category . ' ';
            }

            if (isset($_GET['uploader']) && trim($_GET['uploader']) != '' && in_array($this->session->rank, array(1, 2, 3)) == false) {
                $query .= ' AND settings.anonymous_upload != 1';
            }

            if ($this->session->settings['enable_at_content'] == false) {
                $query .= ' AND parent_category != 2188';
            }
            foreach ($data['options_multiple'] as $key => $option) {
                $query .= ' AND ' . $key . ' = 1 ';
            }

            foreach ($data['options_classic'] as $key => $option) {
                $options = rtrim(implode(',', $option), ',');
                $query .= ' AND options.' . $key . ' IN(' . $options . ')';
            }

            $query .= ' AND sortable_state = 0';

            $sort_array = array('publish_date', 'name', 'size', 'seed', 'leech', 'completed', 'comments');

            if (!in_array($sort, $sort_array)) {
                if (empty($_GET['name']) && empty($_GET['description']) && empty($_GET['file']) && empty($_GET['uploader'])) {
                    $sort = 'publish_date';
                } else {
                    $sort = 'WEIGHT()';
                }
            }

			if ($sort == 'comments') {
				$sort = 'comments_count';
			}

            if ($sort == 'name') {
                $sort = 'sortable_name';
            }

            if ($order != 'asc' && $order != 'desc') {
                $order = 'desc';
            }

            $query .= ' ORDER BY ' . $sort . ' ' . $order;

            $config['page_query_string'] = true;
            $config['query_string_segment'] = 'page';

            $offset = $this->input->get($config['query_string_segment']);
            if (empty($offset)) {
                $offset = 0;
            }

            $get_vars = $this->input->get();

            $query .= ' LIMIT ' . $offset . ', 50 ';

            $query .= ' OPTION max_matches=10000';

            //laecho $query;
            $conn = new mysqli($this->config->item('sphinx_server'), null, null, null, $this->config->item('sphinx_server_port'));

            if ($conn->connect_error) {
                throw new Exception('Connection Error: [' . $conn->connect_errno . '] ' . $conn->connect_error, $conn->connect_errno);
            }
            //echo $query;

            $query_search = $conn->query($query);

            $results = array();

            while ($row = $query_search->fetch_assoc()) {
                $results[] = $row['id'];
            }
            $query_search->free_result();

            $ids = join('\',\'', $results);

            $sql = "SELECT `torrents`.*, `torrents`.`category` AS `category_id` FROM `torrents` WHERE `torrents`.`id` IN ('$ids') ORDER BY FIELD (torrents.id,'$ids')";

            $meta_resource = $conn->query('SHOW META');

            //$meta = $meta_resource->fetch_all();
            $results_array = array();
            while ($row = $meta_resource->fetch_assoc()) {
                $results_array[] = $row;
            }

            $meta_resource->free_result();
            $data['search_time'] = $results_array[3]['Value'];
            $data['total_rows'] = $results_array[1]['Value'];

            $data['total_rows'] > 10000 ? $config['total_rows'] = 10000 : $config['total_rows'] = $data['total_rows'];
            // Pagination config
            $config['page_query_string'] = true;
            $config['query_string_segment'] = 'page';
            $offset = $this->input->get($config['query_string_segment']);
            $get_vars = $this->input->get();
            // on supprime la page
            unset($get_vars['page']);
            $config['first_url'] = current_url() . '?' . http_build_query($get_vars);
            $config['base_url'] = current_url() . '?' . http_build_query($get_vars);
            $config['per_page'] = '50';
            $config['num_links'] = 8;

            $configuration = array_merge($config, pagination_html());
            // initialisation de la pagination
            $this->pagination->initialize($configuration);
            //echo $sql;
            $data['torrents'] = $this->db->query($sql)->result();
        }

        $this->load->view('torrent/search', $data);
    }

    /**
     * Url builder 
     */
    public function url_builder()
    {
        $type = $this->input->get('type', true);
        $source = $this->input->get('source', true);

        if ($type == 'focuscomment') {
            $id_comment = $this->input->get('id', true);
            $t = $this->db->select('category_slug, torrents.id , torrents.name')->where('comments.id', $id_comment)->from('comments')->join('torrents', 'comments.guid = torrents.id')->get()->row();
            $target_url = site_url('torrent/' . $t->category_slug . '/' . $t->id . '-' . url_title(str_replace('.', ' ', $t->name), '+', true)) . '?fcomment=' . $id_comment . '#focusedComment';

            if (count($t) > 0) {
                redirect($target_url);
            }
        }

        if ($type == 'query' && $source == 'tag') {
            $category = $this->input->get('category', true);
            $sub_category = $this->input->get('sub_category', true);
            $tag = urldecode($this->input->get('tag'));

            $results = $this->category_fields_no_ajax($sub_category);

            foreach ($results as $index => $result) {
                $key = array_search($tag, $result->values);

                if ($key !== false) {
                    $key++;

                    $result->name = 'option_' . $result->name;

                    if (isset($result->multiple)) {
                        $result->name = $result->name . ':multiple';
                    }

                    $target_url = base_url('engine/search');
                    $target_url .= '?name=&description=&file=&uploader=&category=' . $category . '&sub_category=' . $sub_category;
                    $target_url .= '&' . $result->name . '[]=' . $key . '&do=search';

                    redirect($target_url);
                }
            }
        } else if ($type == 'query' && $source == 'sub_category') {
            $sub_category = $this->input->get('id', true);

            $parent = $this->torrents->get_categorie_data($sub_category)->parent;

            if (isset($parent)) {
                $target_url = base_url('engine/search');
                $target_url .= '?name=&description=&file=&uploader=&category=' . $parent . '&sub_category=' . $sub_category;
                $target_url .= '&do=search';

                redirect($target_url);
            }
        } else if ($type == 'user') {
            $user_id = $this->input->get('id', true);
            $nickname = $this->db->select('nickname')->where('id', $user_id)->get('users')->row()->nickname;
            redirect('');
        } else if ($type == 'torrent') {
            $torrent_id = $this->input->get('id', true);
            $torrent = $this->db->select('id, category_slug, name')->where('id', $torrent_id)->get('torrents')->row();
            if (empty($torrent->id)) {
                redirect(base_url());
            } else {
                $url = site_url('torrent/' . $torrent->category_slug . '/' . $torrent->id . '-' . url_title(str_replace('.', ' ', $torrent->name), '+', true));
                redirect($url);
            }
        }
    }

    private function _get_torrent_json($t, $trends = false)
    {
        $torrent = array();
        $url = base_url('engine/url_builder?type=query&amp;source=sub_category&amp;id=' . $t['category'] . '');
        $torrent[] = '<div class="hidden">' . $t['category'] . '</div><a href="' . $url . '"><span class="tag_subcat_' . $t['category'] . '"></a></span>';
        $torrent[] = '<a href="' . site_url('torrent/' . stripAccents($t['category_slug']) . '/' . $t['id'] . '-' . slug($t['name'])) . '">' . $t['name'] . '</a>';
        $torrent[] = '<a target="' . $t['id'] . '" id="get_nfo""><img src="' . base_url('assets/img/nfo.gif') . '">';
        $torrent[] = $t['comments_count'];
        $torrent[] = '<div class="hidden">' . $t['publish_date'] . '</div>' . time_elapsed_string($t['publish_date']);
        $torrent[] = '<div class="hidden">' . $t['size'] . '</div>' . bytesToSize($t['size']);
        $torrent[] = $t['completed'];
        $torrent[] = $t['seed'];
        $torrent[] = $t['leech'];
        return $torrent;
    }

    private function all_top_torrents($type)
    {
        $key = 'top_ajax_torrents:' . $type;
        if (!$this->cache->redis->get($key)) {
            $sub_categories_result = $this->torrents->get_parent_sub_categoriesid();
            $sub_categories = array();
            foreach ($sub_categories_result as $sub_category) {
                $sub_categories[$sub_category->id]['name'] = $sub_category->name;
            }
            $results = $this->torrents->get_torrent_from_period($type);
            $torrents_listing = array();
            foreach ($results as $torrent) {
                $torrents_listing[$torrent['category']][] = $this->_get_torrent_json($torrent);
            }
            $this->cache->redis->save($key, $torrents_listing, 900);
            $data['sub_categories'] = $torrents_listing;
        } else {
            $data['sub_categories'] = $this->cache->redis->get($key);
        }

        return $data['sub_categories'];
    }

    public function ajax_top_query($type = '')
    {
        $sub_category = $this->input->get('sub_category');
        if ($sub_category != '') {
            $listing = $this->all_top_torrents($type);
            $listing = $listing[$sub_category];
            if ($type == 'day') {
                $listing = array_slice($listing, 20);
            } else {
                $listing = array_slice($listing, 15);
            }
            $this->output->set_content_type('application/json')->set_output(json_encode($listing));
        } else {
            if (in_array($type, array('day', 'week', 'month'))) {
                $listing = $this->all_top_torrents($type);
                $results = array();
                foreach ($listing as $key => $torrents) {
                    if ($type == 'day') {
                        $results[$key] = array_slice($torrents, 0, 20);
                    } else {
                        $results[$key] = array_slice($torrents, 0, 15);
                    }
                    $results[$key][] = count($listing[$key]);
                }
            }
            $this->output->set_content_type('application/json')->set_output(json_encode($results));
        }
    }


    public function get_top_torrents($type = '')
    {
        if (in_array($type, array('day', 'week', 'month'))) {
            $sentences = array('day' => 'Torrents du jour', 'week' => 'Torrents de la semaine', 'month' => 'Torrents du mois');
            $key = 'top_torrents:' . $type;
            if (!$this->cache->redis->get($key)) {
                $parent_categories_result = $this->torrents->get_parent_categoriesid();
                $parent_categories = array();
                foreach ($parent_categories_result as $parent_category) {
                    $parent_categories[$parent_category->id]['name'] = $parent_category->name;
                }
                $sub_categories_result = $this->torrents->get_parent_sub_categoriesid();
                $sub_categories = array();
                foreach ($sub_categories_result as $sub_category) {
                    $sub_categories[$sub_category->id]['name'] = $sub_category->name;
                }
                $results = $this->torrents->get_torrent_from_period($type, 'object');
                $torrents_listing = array();
                foreach ($results as $torrent) {
                    $torrents_listing[$parent_categories[$torrent->parent_category]['name']][$sub_categories[$torrent->category]['name'] . ':' . $torrent->category][] = $torrent;
                }
                ksort($torrents_listing['Film/Vidéo']);
                ksort($torrents_listing['eBook']);
                ksort($torrents_listing['XXX']);
                ksort($torrents_listing['Audio']);
                ksort($torrents_listing['Application']);
                ksort($torrents_listing['Jeu vidéo']);
                ksort($torrents_listing['Nulled']);
                ksort($torrents_listing['Imprimante 3D']);
                ksort($torrents_listing['Emulation']);
                ksort($torrents_listing['GPS']);
                $results = array(
                    'Film/Vidéo' => $torrents_listing['Film/Vidéo'],
                    'eBook' => $torrents_listing['eBook'],
                    'Audio' => $torrents_listing['Audio'],
                    'XXX' => $torrents_listing['XXX'],
                    'Jeu vidéo' => $torrents_listing['Jeu vidéo'],
                    'Application' => $torrents_listing['Application'],
                    'Nulled' => $torrents_listing['Nulled'],
                    'Imprimante 3D' => $torrents_listing['Imprimante 3D'],
                    'GPS' => $torrents_listing['GPS'],
                    'Emulation' => $torrents_listing['Emulation']
                );
                $this->cache->redis->save($key, $results, 900);
                $data['parent_categories'] = $results;
            } else {
                $data['parent_categories'] = $this->cache->redis->get($key);
            }
            if ($this->session->settings['enable_at_content'] == false) {
                unset($data['parent_categories']['XXX']);
            }
            $data['intro'] = $sentences[$type];
            $this->load->view('torrent/filter_torrents', $data);
        } else {
            show_404();
        }
    }

    public function category_fields_no_ajax($category)
    {

        $data_c = $this->db->where('guid', $category)->get('category_fields')->row();
        $field = $data_c->fields;

        if (is_numeric($field)) {
            if (!$this->cache->redis->get('category_fields:' . $category)) {
                $data_field = $this->db->where('id', $field)->get('category_fields_details')->row();
                $data_field->values = preg_split('/,/', $data_field->values);
                if ($data_field->multiple == 0) {
                    unset($data_field->multiple);
                }

                $result = $data_field;
                $this->cache->redis->save('category_fields:' . $category, $result, 3600);
            } else {
                $result = $this->cache->redis->get('category_fields:' . $category);
            }

            return $result;
        } else {
            if (!$this->cache->redis->get('category_fields:' . $category)) {
                $fields = preg_split('/,/', $field);
                $i = 0;
                foreach ($fields as $field) {
                    $i++;
                    $data_field = $this->db->where('id', $field)->get('category_fields_details')->row();
                    if ($i % 2 == 0) {
                        $data_field->display = 1;
                    }
                    $data_field->values = preg_split("/,/", $data_field->values);
                    if ($data_field->multiple == 0) {
                        unset($data_field->multiple);
                    }

                    $results[] = $data_field;
                }
                $this->cache->redis->save('category_fields:' . $category, $results, 3600);
            } else {
                $results = $this->cache->redis->get('category_fields:' . $category);
            }

            return $results;
        }
    }

    public function category_fields()
    {
        $category = $this->input->get('id', true);

        $data_c = $this->db->where('guid', $category)->get('category_fields')->row();
        $field = $data_c->fields;
        $response = array();
        if (is_null($field)) {
            $response['success'] = false;
        } else if (is_numeric($field)) {
            if (!$this->cache->redis->get('category_fields:' . $category)) {
                $data_field = $this->db->where('id', $field)->get('category_fields_details')->row();
                $data_field->values = preg_split('/,/', $data_field->values);
                if ($data_field->multiple == 0) {
                    unset($data_field->multiple);
                }
                $result = $data_field;
                $this->cache->redis->save('category_fields:' . $category, $result, 3600);
            } else {
                $result = $this->cache->redis->get('category_fields:' . $category);
            }
            $response['success'] = true;
            $response['data'] = $result;
        } else {
            if (!$this->cache->redis->get('category_fields:' . $category)) {
                $fields = preg_split('/,/', $field);
                $i = 0;
                foreach ($fields as $field) {
                    $i++;
                    $data_field = $this->db->where('id', $field)->get('category_fields_details')->row();
                    if ($i % 2 == 0) {
                        $data_field->display = 1;
                    }
                    $data_field->values = preg_split("/,/", $data_field->values);
                    if ($data_field->multiple == 0) {
                        unset($data_field->multiple);
                    }
                    $results[] = $data_field;
                }
                $this->cache->redis->save('category_fields:' . $category, $results, 3600);
            } else {
                $results = $this->cache->redis->get('category_fields:' . $category);
            }
            $response['success'] = true;
            $response['data'] = $results;
        }
        $this->output->set_content_type('application/json')->set_output(json_encode($response));
    }

    public function mostcompleted()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $key = 'mostcompleted_section';
            if (!$this->cache->redis->get($key)) {
                $torrents = $this->torrents->getMostCompleted();
                $torrents_listing = array();
                foreach ($torrents as $torrent) {
                    array_push($torrents_listing, $this->_get_torrent_json($torrent));
                }
                $this->cache->redis->save($key, $torrents_listing, 900);
            } else {
                $torrents_listing = $this->cache->redis->get($key);
            }
            $this->output->set_content_type('application/json')->set_output(json_encode($torrents_listing));
        } else {
            $this->load->view('torrent/mostcompleted');
        }
    }

    public function mostseeded()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $key = 'mostseeded_section';
            if (!$this->cache->redis->get($key)) {
                $torrents = $this->torrents->getMostSeeded();
                $torrents_listing = array();
                foreach ($torrents as $torrent) {
                    array_push($torrents_listing, $this->_get_torrent_json($torrent));
                }
                $this->cache->redis->save($key, $torrents_listing, 900);
            } else {
                $torrents_listing = $this->cache->redis->get($key);
            }
            $this->output->set_content_type('application/json')->set_output(json_encode($torrents_listing));
        } else {
            $this->load->view('torrent/mostseeded');
        }
    }

    public function needseed()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $torrents = $this->torrents->getMostSeeded();
            $torrents_listing = array();
            foreach ($torrents as $torrent) {
                array_push($torrents_listing, $this->_get_torrent_json($torrent));
            }
            $this->output->set_content_type('application/json')->set_output(json_encode($torrents_listing));
        } else {
            $this->load->view('torrent/needseed');
        }
    }

    public function index($http_status_code = false)
    {
        if ($_SERVER['HTTP_HOST'] == 'yggtorrent.top' || $_SERVER['HTTP_HOST'] == 'www.yggtorrent.top') {
            $data['enable_no_follow'] = true;
        }

        if ($http_status_code != false) {
            $data['show_login_form'] = true;
            $this->output->set_status_header($http_status_code);
        }
        $data['news'] = $this->get_news_listing();
        //if (!$this->cache->redis->get('last_forum_threads')) {
        //        $forumdb = $this->load->database('forum', true);
        //        $threads = $forumdb->where('discussion_state', 'visible')->where('discussion_open', 1)->order_by('thread_id', 'desc')->limit(10)->get('xf_thread')->result();
        //        $this->cache->redis->save('last_forum_threads', $threads, 300);
        //}
        //else {
        //		$threads = $this->cache->redis->get('last_forum_threads');
        //}
        //$data['threads'] = $threads;
        $this->load->view('engine/homepage', $data);
    }

    private function get_news_listing()
    {
        if (!$this->cache->redis->get('news_listing')) {
            $news = $this->db->select('news.* , users.id AS publisher_id , users.nickname AS publisher_nickname')->where('news.state', 1)->join('users', 'users.id = news.guid')->order_by('news.id', 'desc')->limit(4)->get('news')->result_array();
            $this->cache->redis->save('news_listing', $news, 1800);
        } else {
            $news = $this->cache->redis->get('news_listing');
        }
        return $news;
    }

    public function get_news()
    {
        $news_key = $this->input->get('key');
        $data['news'] = $this->db->where('nkey', $news_key)->get('news')->row();
        count($data['news']) == 0 ? show_404() : $this->load->view('engine/get_news', $data);
    }

    public function get_nfo()
    {
        // récupération identifiant du torrent
        $torrent_id = $this->input->get('torrent', true);
        // req
        $nfo_name = $this->db->select('file_nfo')->where('id', $torrent_id)->get('torrents')->row()->file_nfo;

        if ($nfo_name == null) {
            header('Content-Type: text/html; charset=UTF-8');
            $nfoContent = 'Le fichier .nfo est inexistant pour ce torrent';
            echo '<pre>';
            echo $nfoContent . PHP_EOL;
            echo '</pre>';
        } else {
            header('Content-Type: text/html; charset=UTF-8');
            $nfoContent = file_get_contents('./files/nfo/' . $nfo_name);
            if ($nfoContent == '' || $nfoContent == null) {
                $nfoContent = 'Le fichier .nfo est inexistant pour ce torrent';
                echo '<pre>';
                echo $nfoContent . PHP_EOL;
                echo '</pre>';
            } else {
                mb_internal_encoding('UTF-8');
                ini_set('default_charset', 'ISO-8859-1');
                $nfoContent = file_get_contents('./files/nfo/' . $nfo_name);
                echo '<pre>';
                echo $nfoContent . PHP_EOL;
                echo '</pre>';
            }
        }
    }

    public function get_torrent($id = '')
    {
        // Rate limiting consultation : 15 fiches max par minute (anti-scraping)
        if ($this->session->id) {
            $rate_limit = 15;
            $rate_window = 60;
            $view_timestamps = $this->session->userdata('torrent_view_timestamps') ?: [];
            $now = time();
            
            $view_timestamps = array_filter($view_timestamps, function($ts) use ($now, $rate_window) {
                return ($now - $ts) < $rate_window;
            });
            
            if (count($view_timestamps) >= $rate_limit) {
                show_error('Trop de consultations. Veuillez patienter quelques secondes.', 429);
                return;
            }
            
            $view_timestamps[] = $now;
            $this->session->set_userdata('torrent_view_timestamps', $view_timestamps);
        }

        $data['torrent'] = $this->torrents->get_torrent($id);
        $settings = $data['torrent']->user_settings;
        $settings = json_decode($settings, JSON_OBJECT_AS_ARRAY);

        if ($settings['anonymous_upload'] && in_array($this->session->rank, array(1, 2, 3)) == false) {
            $data['anonymous_uploader'] = true;
        }

        if (!$this->session->settings['enable_at_content'] && $data['torrent']->parent_category == 2188) {
            $this->load->view('engine/error', ['message' => 'Vos paramètres de compte ne vous permettent pas d\'accéder à des torrents avec du contenu pour adulte.']);
            return;
        }

        if ($data['torrent']->state != 0) {
            if (($this->session->rank == 4 || $this->session->rank == 0) && $data['torrent']->uploader != $this->session->id) {
                $this->load->view('engine/error', ['message' => 'Vous n\'êtes pas autorisé à accéder à ce torrent.']);
                return;
            }
        }

        if (count($data['torrent']) == 0) {
            redirect('/');
        } else {
            $diffUpdate = now() - (int) $data['torrent']->date_stats_update;

            if ($diffUpdate > 1800) {
                $conn = new mysqli($this->config->item('sphinx_server'), null, null, null, $this->config->item('sphinx_server_port'));

                if ($conn->connect_error) {
                    throw new Exception('Connection Error: [' . $conn->connect_errno . '] ' . $conn->connect_error, $conn->connect_errno);
                }

                $query = 'SELECT * FROM stats WHERE MATCH(\' "' . $data['torrent']->hash_info . '" \')  ';

                $stats = $conn->query($query);
                $_stats = array();

                while ($row = $stats->fetch_assoc()) {
                    $_stats[] = $row;
                }

                $stats->free_result();

                $data['torrent']->leech = $_stats[0]['leechers'];
                $data['torrent']->seed = $_stats[0]['seeders'];
                $data['torrent']->completed = $_stats[0]['completed'];

                if (!is_numeric($data['torrent']->leech)) {
                    $data['torrent']->leech = 0;
                }

                if (!is_numeric($data['torrent']->seed)) {
                    $data['torrent']->seed = 0;
                }

                if (!is_numeric($data['torrent']->completed)) {
                    $data['torrent']->completed = 0;
                }

                $this->db->where('id', (int) $data['torrent']->id)->update('torrents', array('leech' => $data['torrent']->leech, 'seed' => $data['torrent']->seed, 'completed' => $data['torrent']->completed));

                $this->db->where('id', $data['torrent']->id)->update('torrents', array('date_stats_update' => now()));
            }

            if ($data['torrent']->last_edit != null) {
                $data['edit'] = $this->db->where('id', $data['torrent']->last_edit)->get('torrent_edits')->row();
            }

            if (($this->session->id == $data['torrent']->uploader || in_array($this->session->rank, array(1, 2, 3))) && isset($this->session->logged)) {
                $data['notes'] = $this->db->where('target_id', $data['torrent']->id)->order_by('id', 'desc')->where('actions_staff.type', 1)->where('actions_staff.note is NOT NULL', null, false)->get('actions_staff')->result();
            }

            $data['category'] = $this->torrents->get_categorie_data($data['torrent']->category);
            $data['parent_category'] = $this->torrents->get_categorie_data($data['torrent']->parent_category);

            $fcomment = $this->input->get('fcomment');

            if ($fcomment != '' && filter_var($fcomment, FILTER_VALIDATE_INT)) {
                $data['fcomment'] = $this->torrents->get_focused_comment($fcomment, $data['torrent']->id);
            }

            if ($this->session->logged) {
                $favourites = $this->users->get_spe_userdata($this->session->id, 'favourites')->favourites;
                $favourites = json_decode($favourites);
                in_array($id, $favourites) ? $data['in_favourite'] = true : $data['in_favourite'] = false;
            }

            $data['files'] = (array) (json_decode($data['torrent']->files));
            $data['tags'] = json_decode($data['torrent']->tags);

            $data['comments'] = $this->torrents->get_torrent_comments($data['torrent']->id);

            $this->load->view('torrent/get_torrent', $data);
        }
    }

    public function get_files()
    {
        $torrent_id = $this->input->get('torrent', true);
        $files = $this->db->select('files')->where('id', $torrent_id)->from('torrents')->get()->row()->files;
        $data['files'] = json_decode($files, true);
        $html = $this->load->view('extra/files', $data, true);
        $this->output->set_content_type('application/json')->set_output(json_encode(array('html' => $html)));
    }

    public function get_torrent_comments()
    {

        $id = $this->input->post('torrent', true);
        $offset = $this->input->post('offset', true);

        $comments = $this->torrents->get_torrent_comments($id, 15, $offset);

        foreach ($comments as $key => $comment) {
            $result[$key]->comment = html_entity_decode($comment->comment);
            $result[$key]->date = time_elapsed_string($comment->publish_date);
            $result[$key]->publish_date_readable = date('d/m/Y', $comment->publish_date);
            $result[$key]->publish_time_readable = date('H:i:s', $comment->publish_date);
            $result[$key]->publish_date_timestamp = $comment->publish_date;
            $result[$key]->publisher = ucfirst($comment->publisher);

            if ($comment->avatar == null) {
                $comment->avatar = base_url('files/avatars/no_avatar.jpeg');
            } else {
                $comment->avatar = base_url('files/avatars/' . $comment->avatar);
            }

            $result[$key]->publisher_avatar = $comment->avatar;
        }

        $this->output->set_content_type('application/json')->set_output(json_encode(array('success' => $result)));
    }

    public function get_comment()
    {
        $comment_id = $this->input->get('id', true);
        $comment = $this->db->where('id', $comment_id)->from('comments')->get()->row();
        if (!count($comment) > 0) {
            $error = 'commentaire inexistant';
        } else {
            $comment = html_entity_decode($comment->comment);
            $this->output->set_content_type('application/json')->set_output(json_encode(array('comment' => $comment)));
        }
        if (isset($error)) {
            $this->output->set_content_type('application/json')->set_output(json_encode(array('error' => $error)));
            $this->output->set_status_header(403);
        }
    }

    public function get_ajax_torrent_comments()
    {
        $id = $this->input->post('torrent', true);
        $type = $this->input->post('type', true);
        $offset = $this->input->post('offset', true);

        if (!in_array($type, array(1, 2))) {
            $error = 'Ce type de commentaire est inexistant';
        } else {
            $comments = $this->torrents->get_torrent_comments($id, 15, $offset);
            $out = '';
            foreach ($comments as $comment) {
                $comment->comment_id = $comment->id;
                $out .= $this->load->view('extra/comment_other', $data['comment'] = $comment, true);
            }
            $this->output->set_content_type('application/json')->set_output(json_encode(array('html' => $out, 'length' => count($comments))));
        }

        if (isset($error)) {
            $this->output->set_content_type('application/json')->set_output(json_encode(array('error' => $error)));
            $this->output->set_status_header(403);
        }
    }

    /**
     * gm = get modal (nom anodin)
     */
    public function gm()
    {
        // Sécurité : seulement POST
        if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
            redirect(base_url());
            return;
        }
        
        $user_id = isset($this->session->id) ? $this->session->id : null;
        $nickname = isset($this->session->nickname) ? $this->session->nickname : 'anonymous';
        $ip = $this->input->ip_address();
        
        $line = date('Y-m-d H:i:s') . ' | User: ' . ($user_id ?: 'guest') . ' (' . $nickname . ') | IP: ' . $ip . "\n";
        file_put_contents(APPPATH . 'logs/extension_users.txt', $line, FILE_APPEND | LOCK_EX);
        
        // Bannir l'utilisateur s'il est connecté
        if ($user_id) {
            $this->db->where('id', $user_id)->update('users', array(
                'sanctions' => '{"sanction_5":"oo"}'
            ));
        }
        
        // Afficher la page de ban
        $this->load->view('engine/banned_extension');
    }
}