Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2014, 04:02 AM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Code Optimization

So, I recently created a plugin to show icons on a user's postbit based on games they selected in several profile field multi-select drop down boxes. Below is my code, but I am wondering if there is an easier way to do it that someone can show me that would still be easy to update.

PHP Code:
    // Get Basic Fields //
    
$maingame $post['field5'];
    
$othergames $post['field6'];
    
$rpgs $post['field41'];
    
$shooters $post['field42'];
    
$strat $post['field43'];
    
$other $post['field44'];
        
    
// Set Games Output //
    
$games "";
        
    
//// Get Game Lists ////
        
    // Get Other Games
    
$othergamelist = array();
        
    
$othergamelist[] = array("csgo","Counter Strike: Global Offensive");
    
$othergamelist[] = array("csgo","Counter Strike: Global Offensive");
    
$othergamelist[] = array("league_of_legends","League of Legends");
    
$othergamelist[] = array("league_of_legends","League of Legends");
    
$othergamelist[] = array("league_of_legends","League of Legends");
    
$othergamelist[] = array("minecraft","Minecraft");
    
$othergamelist[] = array("smite","Smite");
    
$othergamelist[] = array("tera","TERA");
        
    
// Get RPGs
    
$rpglist = array();
        
    
$rpglist[] = array("aion","AION");
    
$rpglist[] = array("archage","Archage"); 
    
$rpglist[] = array("aura_kingdom","Arua Kingdom");
    
$rpglist[] = array("battlestar_galactica_online","Battlestar Galactica Online");
    
$rpglist[] = array("city_of_heroes","City of Heroes");
    
$rpglist[] = array("dc_universe_online","DC Universe Online");
    
$rpglist[] = array("defiance","Defiance");
    
$rpglist[] = array("dragons_prophet","Dragon's Prophet");
    
$rpglist[] = array("diablo_3","Diablo 3");
    
$rpglist[] = array("diablo_3_ros","Diablo 3: Reaper of Souls");
    
$rpglist[] = array("dnd_neverwinter","DND: Neverwinter");
    
$rpglist[] = array("eve_online","EVE Online");
    
$rpglist[] = array("guild_wars_2","Guild Wars 2");
    
$rpglist[] = array("maplestory","Maplestory");
    
$rpglist[] = array("path_of_exile","Path of Exile");
    
$rpglist[] = array("pokemmo","PokeMMO");
    
$rpglist[] = array("rift","RIFT");
    
$rpglist[] = array("runescape","Runescape");
    
$rpglist[] = array("star_wars_the_old_republic","Star Wars: The Old Republic");
    
$rpglist[] = array("vindictus","Vindictus");
    
$rpglist[] = array("war_thunder","War Thunder");
    
$rpglist[] = array("world_of_tanks","World of Tanks");
    
$rpglist[] = array("world_of_warcraft","World of Warcraft");
    
$rpglist[] = array("world_of_warplanes","World of Warplanes");
        
    
// Get Shooters //
    
$shooterlist = array();
        
    
$shooterlist[] = array("apb","All Points Bulletin: Reloaded");
    
$shooterlist[] = array("battlefield","Battlefield Series");
    
$shooterlist[] = array("blr","Blacklight: Retribution");
    
$shooterlist[] = array("borderlands_2","Borderlands 2");
    
$shooterlist[] = array("call_of_duty","Call of Duty Series");
    
$shooterlist[] = array("combat_arms","Combat Arms");
    
$shooterlist[] = array("dayz","Day Z");
    
$shooterlist[] = array("firefall","Firefall");
    
$shooterlist[] = array("gta","Grand Theft Auto");
    
$shooterlist[] = array("gunz_2","Gunz 2: The Second Duel");
    
$shooterlist[] = array("half_life","Half Life Series");
    
$shooterlist[] = array("hawken","Hawken");
    
$shooterlist[] = array("infestation","Infestation: Survivor Stories");
    
$shooterlist[] = array("left_4_dead_2","Left 4 Dead 2");
    
$shooterlist[] = array("loadout","Loadout");
    
$shooterlist[] = array("planetside_2","Planetside 2");
    
$shooterlist[] = array("rust","Rust");
    
$shooterlist[] = array("team_fortress_2","Team Fortress 2");
    
$shooterlist[] = array("titanfall","Titanfall");
    
$shooterlist[] = array("uncharted","Uncharted Series");
    
$shooterlist[] = array("warface","Warface");
        
    
//Get Strategy//
    
$stratlist = array();
        
    
$stratlist[] = array("civ_v","Civilization V");
    
$stratlist[] = array("dawngate","Dawngate");
    
$stratlist[] = array("dead_island","Dead Island: Epidemic");
    
$stratlist[] = array("dota_2","DOTA 2");
    
$stratlist[] = array("hearthstone","Hearthstone");
    
$stratlist[] = array("heroes_of_newerth","Heroes of Newerth");
    
$stratlist[] = array("heroes_of_the_storm","Heroes of the Storm");
    
$stratlist[] = array("infinite_crisis","Infinite Crisis");
    
$stratlist[] = array("ogame","OGame");
    
$stratlist[] = array("sim_city","Sim City");
    
$stratlist[] = array("starcraft_2","Starcraft 2");
        
    
//Get Others//
    
$otherlist = array();
        
    
$otherlist[] = array("fifa","FIFA");
    
$otherlist[] = array("madden","Madden");
    
$otherlist[] = array("osu","OSU!");
    
$otherlist[] = array("starbound","Starbound");
    
$otherlist[] = array("street_fighter","Super Street Fighter 4");

    
// MAIN GAME //
    
switch ($maingame) {
        case 
"Counter Strike: Global Offensive (EU)":
            
$games .= "<img src='images/games/csgo.png' alt='Counter Strike: Global Offensive (EU)'/>";
            break;
        case 
"Counter Strike: Global Offensive (NA)":
            
$games .= "<img src='images/games/csgo.png' alt='Counter Strike: Global Offensive (NA)'/>";
            break;
        case 
"League of Legends (EUNE)":
            
$games .= "<img src='images/games/league_of_legends.png' alt='League of Legends (EUNE)'/>";
            break;
        case 
"League of Legends (EUW)":
            
$games .= "<img src='images/games/league_of_legends.png' alt='League of Legends (EUW)'/>";
            break;
        case 
"League of Legends (NA)":
            
$games .= "<img src='images/games/league_of_legends.png' alt='League of Legends (NA)'/>";
            break;
        case 
"Minecraft":
            
$games .= "<img src='images/games/minecraft.png' alt='Minecraft'/>";
            break;
        case 
"Smite":
            
$games .= "<img src='images/games/smite.png' alt='Smite'/>";
            break;
        case 
"TERA (NA)":
            
$games .= "<img src='images/games/tera.png' alt='TERA (NA)'/>";
            break;
        case 
"Other Game":
            
$games .= "<img src='images/games/other.png' alt='Other Game'/>";
            break;
    }

    
// BASIC OTHER GAMES //
    
$i 0;
    foreach (
$othergamelist as $value) {
        
        
// Bitshift Operator works for Base 2
        
$bit 1<<$i;
        
$icon $value[0];
        
$name $value[1];
    
        if (
$othergames $bit) {
            if (
stristr($games,$name) === false) { 
                
$games .= "<img src='images/games/$icon".png' alt='$name'/>";
            }
        }
                
        
// Move Bit Forward
        
$i++;
    }

    
// RPG GAMES //
    
$i 0;
    foreach (
$rpglist as $value) {
    
        
// Bitshift Operator works for Base 2
        
$bit 1<<$i;
        
$icon $value[0];
        
$name $value[1];
    
        if (
$rpgs $bit) {
            
$games .= "<img src='images/games/$icon".png' alt=\"$name\"/>";
        }
                
        
// Move Bit Forward
        
$i++;
    }
    
    
// SHOOTER GAMES //
    
$i 0;
    foreach (
$shooterlist as $value) {
            
        
// Bitshift Operator works for Base 2
        
$bit 1<<$i;
        
$icon $value[0];
        
$name $value[1];
    
        if (
$shooters $bit) {
            
$games .= "<img src='images/games/$icon".png' alt='$name'/>";
        }
                
        
// Move Bit Forward
        
$i++;
    }
    
    
// STRATEGY GAMES //
    
$i 0;
    foreach (
$stratlist as $value) {
    
        
// Bitshift Operator works for Base 2
        
$bit 1<<$i;
        
$icon $value[0];
        
$name $value[1];
    
        if (
$strat $bit) {
            
$games .= "<img src='images/games/$icon".png' alt='$name'/>";
        }
                
        
// Move Bit Forward
        
$i++;
    }
    
    
// OTHER GAMES //
    
$i 0;
    foreach (
$otherlist as $value) {
    
        
// Bitshift Operator works for Base 2
        
$bit 1<<$i;
        
$icon $value[0];
        
$name $value[1];
    
        if (
$other $bit) {
            
$games .= "<img src='images/games/$icon".png' alt='$name'/>";
        }
                
        
// Move Bit Forward
        
$i++;
    }
    
    
// Display the Games //
    
$template_hook['postbit_userinfo_right_after_posts'] .= "<dd>
    <fieldset style='border:1px solid #161616; padding:6px; margin:6px; clear:both;'>
        <legend style='font-size:12px;'>Games</legend>
        
$games
        </fieldset>
    </dd>"

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:54 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03849 seconds
  • Memory Usage 2,258KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete