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

Reply
 
Thread Tools Display Modes
  #1  
Old 12-29-2009, 08:57 AM
jaffaman jaffaman is offline
 
Join Date: Nov 2004
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Widget and side block.

I have aske over at vbulletin.com but i thought i would ask here as well.

I have got a cms php widget working on a test site with the code below but when i try and make a side forums block the code does not work even tho i have got a html block working ok.
I do not know how 2 code so i thought i would ask if anyone cold help please as i am looking at putting our site live soon and want to get tings sorted before i do the upgrade.

Here's the working widget code for our BHD server status.

Code:
ob_start();

$dbhost     = "localhost";    // Database host
$dbname     = "******";    // Database name
$dbusername = "******";    // Database user name
$dbuserpw   = "******";    // Database password

$link_id = mysql_connect($dbhost,$dbusername,$dbuserpw)
               or die("Could not connect to MySQL.");

$selected = mysql_select_db($dbname,$link_id) or die("Could not select database");

$result = mysql_query("SELECT name, server_name, map_name, game_type, dedicated, time, max_players, num_players, player_names, player_teams  
                           FROM chronos_servers ORDER BY max_players DESC");
$onlinex = 0;
while ($row = mysql_fetch_row($result)) {
    $name = $row[0];
    $sname = htmlspecialchars(base64_decode($row[1]));
    $max = $row[6];
    $map = htmlspecialchars(base64_decode($row[2]));
    $mapname = $row[2];
    $dedi = $row[4];
    $type = $row[3];
    $num = $row[7];
    $sertime = $row[5];
    $players = $row[8];
    $teams = $row[9];
    $status = $row[12];
    $curtime = time();
    $tdiff = $curtime - $sertime;
    if ($tdiff < 120) {
        $onlinex = 1;
        $result1 = mysql_query("SELECT name, thumbnail, game_type, id FROM chronos_maps WHERE name = '$mapname' AND game_type = '$type' ");
        while ($row2 = mysql_fetch_array($result1)) {
            $mtn = $row2[1];
            $mpid = $row2[3];
        }
        switch($result["age"]) {
            case -1: $status = "<font color='red'>Loading Map"; break;
            case -2: $status = "<font color='yellow'>Waiting for Players"; break;
            case -4: $status = "<font color='blue'>Scoring Map"; break;
            default: $status = "<font color='green'>Hosting Map";
        }

        $url = "<a href='http://www.csa-squad.co.uk/index.php?page=bhdserverstatus'BORDER=0 >";
            $url2 = "<a href='http://lobby.sigurd-project.com/server-383.xml'BORDER=0 target=\"_blank\">";

        echo "<CENTER>$name</CENTER>";
            echo "<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/serverstatus/img/online.gif'></CENTER>";
            echo "<CENTER>$type</CENTER>";
            echo "<CENTER>$map</CENTER><P>";
            echo "$url<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/$mtn'></a></CENTER><br>";
            echo "<CENTER>I.P = 85.236.103.11</CENTER>";
            echo "<CENTER>PORT 17479</CENTER>";
            echo "<CENTER>Players : $num/$max</CENTER>";
        
        if(strlen($players) > 0) {
            $PlayStr = explode("\n", $players);
            $TeamStr = explode("\n", $teams);
            echo "<CENTER><marquee scrollamount='2' width='150'>";
            for($i = 0; $i < count($PlayStr); $i++) {
                if($TeamStr[$i] == "None") echo "[<font color=\"Green\">";
                if($TeamStr[$i] == "Red") echo "[<font color=\"Red\">";
                if($TeamStr[$i] == "Blue") echo "[<font color=\"Blue\">";
                echo base64_decode($PlayStr[$i])."</font>] ";
            }
            echo "</marquee></center>";
        }
            echo "$url2<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/serverstatus/sigurdstatus.gif'></a></CENTER><br>"; 
            echo "<center><a href=\"http://www.babstats.com\" target=\"_blank\">Babstats</a></center>";
        //echo "Status:$status<br />";
        echo "<CENTER>_____________</CENTER>";
    }
}
if ($onlinex == 0) {
    echo "<CENTER>! CsA Tryouts</CENTER>";
    echo "<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/serverstatus/img/offline.gif'></CENTER>";
      echo "<center><a href=\"http://www.babstats.com\" target=\"_blank\">Babstats</a></center>";
 
        //echo "Status:$status<br />";
    echo "<CENTER>_____________</CENTER>";

}

$output .= ob_get_contents();
ob_end_clean();
Thanks in advance for any help
Attached Images
File Type: png block.png (23.3 KB, 0 views)
Reply With Quote
  #2  
Old 12-29-2009, 11:15 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try replacing $output .= with return in the last line but one.
Reply With Quote
  #3  
Old 12-29-2009, 11:55 AM
jaffaman jaffaman is offline
 
Join Date: Nov 2004
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That sort of works thanks i can now see it in the side bar but it also shows above the header as well this seems to be intermitment so might just be me but i had the sam problem with Firefox & IE.

So the end of the code now looks like.

Code:
return ob_get_contents();
ob_end_clean();



Thanks again for helping me
Attached Images
File Type: jpg both.jpg (80.8 KB, 0 views)
Reply With Quote
  #4  
Old 12-29-2009, 01:25 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this (all echo replaced with $output .= and removed then unnecessary output buffering):

PHP Code:
$dbhost     "localhost";    // Database host
$dbname     "******";    // Database name
$dbusername "******";    // Database user name
$dbuserpw   "******";    // Database password

$link_id mysql_connect($dbhost,$dbusername,$dbuserpw)
               or die(
"Could not connect to MySQL.");

$selected mysql_select_db($dbname,$link_id) or die("Could not select database");

$result mysql_query("SELECT name, server_name, map_name, game_type, dedicated, time, max_players, num_players, player_names, player_teams  
                           FROM chronos_servers ORDER BY max_players DESC"
);
$onlinex 0;
while (
$row mysql_fetch_row($result)) {
    
$name $row[0];
    
$sname htmlspecialchars(base64_decode($row[1]));
    
$max $row[6];
    
$map htmlspecialchars(base64_decode($row[2]));
    
$mapname $row[2];
    
$dedi $row[4];
    
$type $row[3];
    
$num $row[7];
    
$sertime $row[5];
    
$players $row[8];
    
$teams $row[9];
    
$status $row[12];
    
$curtime time();
    
$tdiff $curtime $sertime;
    if (
$tdiff 120) {
        
$onlinex 1;
        
$result1 mysql_query("SELECT name, thumbnail, game_type, id FROM chronos_maps WHERE name = '$mapname' AND game_type = '$type' ");
        while (
$row2 mysql_fetch_array($result1)) {
            
$mtn $row2[1];
            
$mpid $row2[3];
        }
        switch(
$result["age"]) {
            case -
1$status "<font color='red'>Loading Map"; break;
            case -
2$status "<font color='yellow'>Waiting for Players"; break;
            case -
4$status "<font color='blue'>Scoring Map"; break;
            default: 
$status "<font color='green'>Hosting Map";
        }

        
$url "<a href='http://www.csa-squad.co.uk/index.php?page=bhdserverstatus'BORDER=0 >";
            
$url2 "<a href='http://lobby.sigurd-project.com/server-383.xml'BORDER=0 target=\"_blank\">";

        
$output "<CENTER>$name</CENTER>";
            
$output .= "<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/serverstatus/img/online.gif'></CENTER>";
            
$output .= "<CENTER>$type</CENTER>";
            
$output .= "<CENTER>$map</CENTER><P>";
            
$output .= "$url<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/$mtn'></a></CENTER><br>";
            
$output .= "<CENTER>I.P = 85.236.103.11</CENTER>";
            
$output .= "<CENTER>PORT 17479</CENTER>";
            
$output .= "<CENTER>Players : $num/$max</CENTER>";
        
        if(
strlen($players) > 0) {
            
$PlayStr explode("\n"$players);
            
$TeamStr explode("\n"$teams);
            
$output .= "<CENTER><marquee scrollamount='2' width='150'>";
            for(
$i 0$i count($PlayStr); $i++) {
                if(
$TeamStr[$i] == "None"$output .= "[<font color=\"Green\">";
                if(
$TeamStr[$i] == "Red"$output .= "[<font color=\"Red\">";
                if(
$TeamStr[$i] == "Blue"$output .= "[<font color=\"Blue\">";
                
$output .= base64_decode($PlayStr[$i])."</font>] ";
            }
            
$output .= "</marquee></center>";
        }
            
$output .= "$url2<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/serverstatus/sigurdstatus.gif'></a></CENTER><br>"
            
$output .= "<center><a href=\"http://www.babstats.com\" target=\"_blank\">Babstats</a></center>";
        
//$output .= "Status:$status<br />";
        
$output .= "<CENTER>_____________</CENTER>";
    }
}
if (
$onlinex == 0) {
    
$output .= "<CENTER>! CsA Tryouts</CENTER>";
    
$output .= "<CENTER><img src='http://www.csa-squad.co.uk/Neos_Chronos/serverstatus/img/offline.gif'></CENTER>";
      
$output .= "<center><a href=\"http://www.babstats.com\" target=\"_blank\">Babstats</a></center>";
 
        
//$output .= "Status:$status<br />";
    
$output .= "<CENTER>_____________</CENTER>";
    
}

return 
$output
Reply With Quote
  #5  
Old 12-29-2009, 02:24 PM
jaffaman jaffaman is offline
 
Join Date: Nov 2004
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thats stoped the side bar and above the header issue but for some reason it will not update the players on the server.
When i done the edit and save it and went to the sideblock for the 1st time it showed 2 players on but it is still showing 2 players on even tho the server is empty ? the widget on the cms is updateing ok as that shows 0 players.
Attached Images
File Type: png 2players.png (21.4 KB, 0 views)
Reply With Quote
  #6  
Old 12-29-2009, 02:36 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The forum blocks are cached. Try changing Cache Time (in minutes) setting to 0 for your block. But beware, that will run the query every single time a page is loaded.
Reply With Quote
  #7  
Old 12-29-2009, 02:53 PM
jaffaman jaffaman is offline
 
Join Date: Nov 2004
Posts: 153
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks alot for your help that done the trick
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 09:48 PM.


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.04446 seconds
  • Memory Usage 2,293KB
  • Queries Executed 12 (?)
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
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (3)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete