Vider les cookies de votre navigateur, si vous n'arrivez pas, à vous connectez

Un cadeau sera à gagner pour la Manche 2 du Championnat de Noël ! Regarder la vidéo pour tout savoir !

Nous vous avons créé une Boutique de Noël avec des petits prix, vous avez le lien vinted pour voir la totalité des articles ! :nyoupi:

Cliquez ici, pour voir tous les Articles sur Vinted ! :nbisous:

Cliquez pour voir la Boutique de Noël City



Extensions Quick Style et Drapeaux

Avatar du membre
ABDev
Le Déserteur
Le Déserteur
En ligne : Non
Messages : 12
Enregistré le : 26 juil. 2012, 17:07
Joueur de Poker : non
Pseudo Winamax : aucun
Localisation : Lens / Pas-de-Calais / France
Genre :
Olympus Arcade : 0 Top 20 des joueurs de l arcade
    Windows 10 Firefox

Re: Extensions Quick Style et Drapeaux

Message non lu par ABDev »

  • Statistiques
  • Stats Relax
  • Stats Poker/Aracde
Voilà, c'est optimisé et corrigé.
C'est chiant les IDE pour le Web, qui ne permettent pas de bosser de la même façon qu'en développement de logiciels système -_-

Donc, pour ce qui est des modifications que j'ai apportées, tout se passe dans le fichier index.php de la racine du forum.

Trouver :

Code : Tout sélectionner

    function getuser($uid) {
        global $db;
        global $request;
        $request->enable_super_globals();
        $username = '';
        if ($uid) {
            $user  = $db->sql_query('SELECT * FROM phpbb_users WHERE user_id = ' . $uid);
            $us    = $db->sql_fetchrow($user);
            $color = '';
            if ($us['user_colour']) {
                $color = 'style="font-weight:bold;color:#' . $us['user_colour'] . '"';
            }
            $username = '<a href=' . generate_board_url() . '/memberlist.php?mode=viewprofile&u=' . $uid . '" ' . $color . '>' . $us['username'] . '</a>';
        }

        return $username;
    }

    function getgame($gameid) {
        global $db;
        global $request;
        $gameoutput = '';
        $request->enable_super_globals();
        if ($gameid) {
            $games = $db->sql_query('SELECT * FROM phpbb_games WHERE id = ' . $gameid);
            $game  = $db->sql_fetchrow($games);

            $gameoutput = <<<HTML
<a href="{$_SERVER['BOARD_URL']}/arcadeoa.php?mode=game&id={$game['id']}"><img src="pics/{$game['picture']}" style="width:24px;height:24px;display:inline-block;vertical-align:middle;"> {$game['name']}</a>
HTML;
        }

        return $gameoutput;
    }
Ajouter avant :

Code : Tout sélectionner

//-- mod : fix by abdev --------------------------------------------------------
//-- delete
/*-MOD
Ajouter après :

Code : Tout sélectionner

MOD-*/
//-- add
	function getuser($this_user_id, $this_username, $this_user_colour)
	{
		global $request;
		$request->enable_super_globals();

		if ($this_user_id == ANONYMOUS)
		{
			global $user;
			return $this_username ? $this_username : $user->lang['GUEST'];
		}

		return '<a href=' . generate_board_url() . '/memberlist.php?mode=viewprofile&u=' . $this_user_id . '"' . ($this_user_colour ? ' style="font-weight:bold;color:#' . $this_user_colour . '"' : '') . '>' . $this_username . '</a>';
	}

	function getgame($this_game_id, $this_gamename, $this_game_picture)
	{
		global $request;
		$request->enable_super_globals();

		if ($this_gamename === '')
		{
			return '';
		}

		$board_url = generate_board_url();
		return <<<HTML
<a href="{$board_url}/arcadeoa.php?mode=game&id={$this_game_id}"><img src="pics/{$this_game_picture}" style="width:24px;height:24px;display:inline-block;vertical-align:middle;"> {$this_gamename}</a>
HTML;
	}
//-- end mod : fix by abdev ----------------------------------------------------
Rechercher :

Code : Tout sélectionner

    $totalgames   = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_games'));
    $totalparty   = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_scores'));
    $totalplayers = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_scores GROUP BY gamer_id'));
    $totalcups    = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_scores WHERE is_first = 1'));
    $ultimscores  = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_ultim_scores'));
    $ultimplayers = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_ultim_scores GROUP BY gamer_id'));
    $favoplayers  = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_games_bookmarks GROUP BY gamer_id'));
    $favofavos    = mysqli_num_rows($db->sql_query('SELECT * FROM phpbb_games_bookmarks'));
    $longnew      = $db->sql_query('SELECT * FROM phpbb_scores WHERE is_first = 1 ORDER BY score_date');
    $lg           = $db->sql_fetchrow($longnew);
    $totalausgabe = sprintf($user->lang('TOTAL_STATS'), $totalgames, $totalparty, $totalplayers, $totalcups, $ultimscores, $ultimplayers, $favoplayers, $favofavos, getuser($lg['gamer_id']), $lg['points'], getgame($lg['game_id']), elapsed_time($lg['score_date']));
Ajouter avant :

Code : Tout sélectionner

//-- mod : fix by abdev --------------------------------------------------------
//-- delete
/*-MOD
Ajouter après :

Code : Tout sélectionner

MOD-*/
//-- add
	$sql = 'SELECT main.cnt_jeux, main.cnt_parties, main.cnt_joueurs, main.cnt_coupes, main.cnt_scores_ultimes, main.cnt_joueurs_ultimes, main.cnt_favoris, main.cnt_favoris_joueurs, main.gamer_id, u.username AS gamer_username, u.user_colour AS gamer_colour, main.points, main.game_id, g.name AS game_name, g.picture AS game_picture, main.score_date
		FROM (
			SELECT MAX(sub.cnt_jeux) AS cnt_jeux, MAX(sub.cnt_parties) AS cnt_parties, MAX(sub.cnt_joueurs) AS cnt_joueurs, MAX(sub.cnt_coupes) AS cnt_coupes, MAX(sub.cnt_scores_ultimes) AS cnt_scores_ultimes, MAX(sub.cnt_joueurs_ultimes) AS cnt_joueurs_ultimes, MAX(sub.cnt_favoris) AS cnt_favoris, MAX(sub.cnt_favoris_joueurs) AS cnt_favoris_joueurs, MAX(sub.gamer_id) AS gamer_id, MAX(sub.points) AS points, MAX(sub.game_id) AS game_id, MAX(sub.score_date) AS score_date
			FROM (
				SELECT COUNT(id) AS cnt_jeux, 0 AS cnt_parties, 0 AS cnt_joueurs, 0 AS cnt_coupes, 0 AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, 0 AS cnt_favoris, 0 AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_games
				UNION
				SELECT 0 AS cnt_jeux, COUNT(id) AS cnt_parties, 0 AS cnt_joueurs, 0 AS cnt_coupes, 0 AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, 0 AS cnt_favoris, 0 AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_scores
				UNION
				SELECT 0 AS cnt_jeux, 0 AS cnt_parties, COUNT(DISTINCT gamer_id) AS cnt_joueurs, 0 AS cnt_coupes, 0 AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, 0 AS cnt_favoris, 0 AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_scores
				UNION
				SELECT 0 AS cnt_jeux, 0 AS cnt_parties, 0 AS cnt_joueurs, COUNT(DISTINCT id) AS cnt_coupes, 0 AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, 0 AS cnt_favoris, 0 AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_scores WHERE is_first = 1
				UNION
				SELECT 0 AS cnt_jeux, 0 AS cnt_parties, 0 AS cnt_joueurs, 0 AS cnt_coupes, COUNT(id) AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, 0 AS cnt_favoris, 0 AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_ultim_scores
				UNION
				SELECT 0 AS cnt_jeux, 0 AS cnt_parties, 0 AS cnt_joueurs, 0 AS cnt_coupes, 0 AS cnt_scores_ultimes, COUNT(DISTINCT gamer_id) AS cnt_joueurs_ultimes, 0 AS cnt_favoris, 0 AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_ultim_scores
				UNION
				SELECT 0 AS cnt_jeux, 0 AS cnt_parties, 0 AS cnt_joueurs, 0 AS cnt_coupes, 0 AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, COUNT(id) AS cnt_favoris, 0 AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_games_bookmarks
				UNION
				SELECT 0 AS cnt_jeux, 0 AS cnt_parties, 0 AS cnt_joueurs, 0 AS cnt_coupes, 0 AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, 0 AS cnt_favoris, COUNT(DISTINCT gamer_id) AS cnt_favoris_joueurs, 0 AS gamer_id, 0 AS points, 0 AS game_id, 0 AS score_date FROM phpbb_games_bookmarks
				UNION
				(SELECT 0 AS cnt_jeux, 0 AS cnt_parties, 0 AS cnt_joueurs, 0 AS cnt_coupes, 0 AS cnt_scores_ultimes, 0 AS cnt_joueurs_ultimes, 0 AS cnt_favoris, 0 AS cnt_favoris_joueurs, gamer_id, points, game_id, score_date FROM phpbb_scores WHERE is_first = 1 ORDER BY score_date LIMIT 1)
			) AS sub)
		AS main
		LEFT JOIN phpbb_users u
			ON main.gamer_id = u.user_id
		LEFT JOIN phpbb_games g
			ON main.game_id = g.id';
	$result = $db->sql_query($sql);

	// totaux
	$cnt_jeux = (int) $db->sql_fetchfield('cnt_jeux');
	$cnt_parties = (int) $db->sql_fetchfield('cnt_parties');
	$cnt_joueurs = (int) $db->sql_fetchfield('cnt_joueurs');
	$cnt_coupes = (int) $db->sql_fetchfield('cnt_coupes');
	$cnt_scores_ultimes = (int) $db->sql_fetchfield('cnt_scores_ultimes');
	$cnt_joueurs_ultimes = (int) $db->sql_fetchfield('cnt_joueurs_ultimes');
	$cnt_favoris_joueurs = (int) $db->sql_fetchfield('cnt_favoris_joueurs');
	$cnt_favoris = (int) $db->sql_fetchfield('cnt_favoris');

	// informations
	$gamer_id = (int) $db->sql_fetchfield('gamer_id');
	$gamer_username = (string) $db->sql_fetchfield('gamer_username');
	$gamer_colour = (string) $db->sql_fetchfield('gamer_colour');

	$game_id = (int) $db->sql_fetchfield('game_id');
	$game_name = (string) $db->sql_fetchfield('game_name');
	$game_picture = (string) $db->sql_fetchfield('game_picture');
	$game_points = (int) $db->sql_fetchfield('points');
	$game_score_date = (int) $db->sql_fetchfield('score_date');

	$db->sql_freeresult($result);

	$totalausgabe = sprintf($user->lang('TOTAL_STATS'), $cnt_jeux, $cnt_parties, $cnt_joueurs, $cnt_coupes, $cnt_scores_ultimes, $cnt_joueurs_ultimes, $cnt_favoris_joueurs, $cnt_favoris, getuser($gamer_id, $gamer_username, $gamer_colour), $game_points, getgame($game_id, $game_name, $game_picture), elapsed_time($game_score_date));
//-- fin mod : fix by abdev ----------------------------------------------------
Grâce à cette "petite" bidouille, vous passez, en réalité, de onze requêtes à une seule.
Ce qui va soulager le serveur de base de données ;)

Désolé pour les plantages, j'avais oublié depuis le temps que phpBB n'aimait pas certaines méthodes d'écriture :grouge:

Edit : Je referai une petite optimisation du code, surtout par rapport au nombre de variables, dès que possible.
On peut normalement tout concaténer.
Et moins il y a de code, mieux c'est.


Image Image Image
Répondre

Retourner vers « Modifs styles et extension »