Welcome to Geeklog, Anonymous Wednesday, December 07 2022 @ 05:59 pm EST

Geeklog Forums

need some quick help on a php block


Status: offline

kermit

Forum User
Junior
Registered: 03/27/04
Posts: 18
Hi all,

I have setup this block:



function phpblock_teamspeak()
{
// retrieve server info
require("TS_config.php");
$tss2info->getInfo();
$tss2info->userName="Guest";
$return.= "";
$return.= "";


$return.= "";
$return.= "";

// display channel list
echo "tabellenbreite."" cellpadding="0" cellspacing="0">n";
echo "n";
echo "n";
//-------------------------------------------------------------------------------------------------
//---> Refresh
echo "n";
echo "n";
echo "refreshauto onn";
echo "n";
echo "n";
//---> Refresh
//-------------------------------------------------------------------------------------------------
echo "n";
echo "n";
echo "n";
echo "n";
//-------------------------------------------------------------------------------------------------
//---> TeamSpeak
echo "n";
echo "n";
echo " TeamSpeakn";
echo "n";
echo "n";
//---> TeamSpeak
//-------------------------------------------------------------------------------------------------
echo "n";
echo "n";
$counter = 0;
foreach($tss2info->channelList as $channelInfo) {
$channelname = $channelInfo[channelname];
// determine codec (verbose)
$codec = $tss2info->getVerboseCodec($channelInfo[codec]);
// default?
if($channelInfo[isdefault] == "1") $isDefault = "yes"; else $isDefault = "no";
if ($channelInfo[channelid] != "id") {
echo ("n");
echo ("n");
//-------------------------------------------------------------------------------------------------
//---> Channel
echo (" n");
echo (" n");
echo (" serverAddress.":".$tss2info->serverUDPPort."/?channel=".$channelname."?password=".$tss2info->serverPasswort."" title="".$channelInfo[topic]."">".$channelname." (".$channelInfo[currentplayers]."/".$channelInfo[maxplayers].")n");
echo (" n");
echo (" n");
//---> Channel
//-------------------------------------------------------------------------------------------------
echo ("n");
echo ("n");
$counter_player = 0;
foreach($tss2info->playerList as $playerInfo) {
if ($playerInfo[channelid] == $channelInfo[channelid]) {
//-------------------------------------------------------------------------------------------------
//--- UserStatusBild --
if ($playerInfo[attribute] == "0") $playergif = "player.gif";
if (($playerInfo[attribute] == "8") or
($playerInfo[attribute] == "9") or
($playerInfo[attribute] == "12") or
($playerInfo[attribute] == "13") or
($playerInfo[attribute] == "24") or
($playerInfo[attribute] == "25") or
($playerInfo[attribute] == "28") or
($playerInfo[attribute] == "29") or
($playerInfo[attribute] == "40") or
($playerInfo[attribute] == "41") or
($playerInfo[attribute] == "44") or
($playerInfo[attribute] == "45") or
($playerInfo[attribute] == "56") or
($playerInfo[attribute] == "57")) $playergif = "away.gif";
if (($playerInfo[attribute] == "16") or
($playerInfo[attribute] == "17") or
($playerInfo[attribute] == "20") or
($playerInfo[attribute] == "21")) $playergif = "mutemicro.gif";
if (($playerInfo[attribute] == "32") or
($playerInfo[attribute] == "33") or
($playerInfo[attribute] == "36") or
($playerInfo[attribute] == "37") or
($playerInfo[attribute] == "48") or
($playerInfo[attribute] == "49") or
($playerInfo[attribute] == "52") or
($playerInfo[attribute] == "53")) $playergif = "mutespeakers.gif";
if ($playerInfo[attribute] == "4") $playergif = "player.gif";
if (($playerInfo[attribute] == "1") or
($playerInfo[attribute] == "5")) $playergif = "channelcommander.gif";
//--- UserStatusBild --
//-------------------------------------------------------------------------------------------------
//--- UserRechte ---
if ($playerInfo[userstatus]

if ($playerInfo[userstatus] == "4") { $playerstatus = "R"; } // Registriert

if ($playerInfo[userstatus] == "5") { $playerstatus = "R SA"; } // Serveradmin
//--- UserRechte ---
//-------------------------------------------------------------------------------------------------
//--- Privilegien ---
if ($playerInfo[privileg] == "0") { $privileg = ""; } // nix
if ($playerInfo[privileg] == "1") { $privileg = " CA"; } // Channeladmin
//--- Privilegien ---
//-------------------------------------------------------------------------------------------------
//--- Online Seit ---
if ($playerInfo[totaltime]
$playertotaltime = strftime("%S Sekunden", $playerInfo[totaltime]);
} else {
if ($playerInfo[totaltime] >= 3600 ) {
$playertotaltime = strftime("%H:%M:%S Stunden", $playerInfo[totaltime] - 3600);
} else {
$playertotaltime = strftime("%M:%S Minuten", $playerInfo[totaltime]);
}
}
//--- Online Seit ---
//-------------------------------------------------------------------------------------------------
//--- Idle Seit ---
if ($playerInfo[idletime]
$playeridletime = strftime("%S Sekunden", $playerInfo[idletime]);
} else {
if ($playerInfo[idletime] >= 3600 ) {
$playeridletime = strftime("%H:%M:%S Stunden", $playerInfo[idletime] - 3600);
} else {
$playeridletime = strftime("%M:%S Minuten", $playerInfo[idletime]);
}
}
//--- Idle Seit ---
//-------------------------------------------------------------------------------------------------
//---> Player
echo ("n");
echo ("n");
echo (" n");
echo (" ".$playerInfo[playername]." (".$playerstatus."".$privileg.")n");
echo (" n");
echo ("n");
echo ("n");
//---> Player
//-------------------------------------------------------------------------------------------------
$counter_player++;
}
}
}
$counter++;
}// end foreach
//-------------------------------------------------------------------------------------------------
//---> OFFLINE
if ($counter == 0) {
echo ("n");
echo ("n");
echo (" n");
echo (" Offlinen");
}
//---> OFFLINE
//-------------------------------------------------------------------------------------------------
echo ("n");
echo ("n");
echo ("n");
echo ("n");
echo ("n
");
echo ($tss2info->sitetitle."
n");
echo ("designed by Dooki
n");
echo ("n");
echo ("n");
echo ("n");

$return.= "";
$return.= "";
return $return;
}


if you check on my website:
clik me

the block appears in the top left corner, and not in the block called TeamSpeak.

Can someone tell me why ?????

thanks a lot all of you
Stephane
 Quote

Status: offline

Blaine

Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
You have a combination of echo's and use of $return .= to build up the display output.

The php echo command will display immediately what you tell it to output (excluding buffering effects) and this is why it appears as it does.

You want to ensure you build up your display information in it's complete form - all required HTML and data to a variable such as $retval and then return that variable (with the formatted block contents) to the calling Geeklog Calling Functions that are building up the page.
Geeklog components by PortalParts -- www.portalparts.com
 Quote

Status: offline

kermit

Forum User
Junior
Registered: 03/27/04
Posts: 18
Quote by Blaine: You have a combination of echo's and use of $return .= to build up the display output.

The php echo command will display immediately what you tell it to output (excluding buffering effects) and this is why it appears as it does.


Righ, that I understand.... i think

Quote by Blaine:
You want to ensure you build up your display information in it's complete form - all required HTML and data to a variable such as $retval and then return that variable (with the formatted block contents) to the calling Geeklog Calling Functions that are building up the page.


but that.......erm you talking chinese to me there.
sorry, I am not php guru.
 Quote

Status: offline

kermit

Forum User
Junior
Registered: 03/27/04
Posts: 18
shoul I do :

[QUOTE}
// display channel list
$return.= "echo "tabellenbreite."" cellpadding="0" cellspacing="0">n";";
$return.= "echo "n";";
$return.= "echo "n";";
[/QUOTE]

???
thanks for you help
 Quote

Status: offline

kermit

Forum User
Junior
Registered: 03/27/04
Posts: 18
cool i fix it myself.

I will post the all lot soonish

tada
Stephane
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
No, don't return or echo anything until the end. Anything you want to display, stick into the $return variable. Then, at the very end, return it.
 Quote

Bob

Anonymous
Could someone please post the PHP code you need to display your teamspeak stats in a block? This is what I have but not sure if it's right and I don't know what to put into the "Block Function:" box.
Text Formatted Code
<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/************************************************************************/
/* block-Teamspeak3.php                                                 */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2004 by jaj (jaj@nukecops.com)                         */
/* http://nukecops.com                                                  */
/************************************************************************/
/* Cosmetic changes by CaptDD at webmaster@rapidfireclan.com            */
/* http://rapidfireclan.com                                             */
/************************************************************************/
/* Additional Cosmetic changes by Aleister at admin@dcwclan.com         */
/* http://www.dcwclan.com                                               */
/************************************************************************/



// **** settings - to be edited before first use ****

$serverAddress = "69.30.192.149:25";  // can be ip address or url

$serverQueryPort = 14534;  // default 51234, must be accessible and usable. check server.ini

$serverUDPPort = 8767;  // default 8767

// **** end of settings ****

if (eregi("block-Teamspeak3.php", $PHP_SELF)) {
  Header("Location: index.php");
  die();
}


global $user, $cookie;
getusrinfo($user);
cookiedecode($user);
$username = $cookie[1];

// opens a connection to the teamspeak server
function getSocket($host, $port, $errno, $errstr, $timeout) {
   global $errno, $errstr;
   @$socket = fsockopen($host, $port, $errno, $errstr, $timeout);
        if($socket and fread($socket, 4) == "[TS]") {
            fgets($socket, 128);
            return $socket;
        }// end if
        return false;
}// end function getSocket(...)

// sends a query to the teamspeak server
function sendQuery($socket, $query) {
   fputs($socket, $query."\n");
}

// answer OK?
function getOK($socket) {
        $result = fread($socket, 2);
        fgets($socket, 128);
        return($result == "OK");
}

// closes the connection to the teamspeak server
function closeSocket($socket) {
        fputs($socket, "quit");
        fclose($socket);
}

// retrieves the next argument in a tabulator-separated string (PHP scanf function bug workaround)
function getNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, 0, $pos);
        }
        else {
            return $evalString;
        }
}

// removes the first argument in a tabulator-separated string (PHP scanf function bug workaround)
function chopNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, $pos + 1);
        }
        else {
           return "";
        }
}

// MAIN PROGRAM START

// establish connection to teamspeak server
$socket = getSocket($serverAddress, $serverQueryPort, $errno, $errstr, 3);
if($socket == false) {
        $content .= "An error connecting to the TeamSpeak server has occured!<br>\n";
        $content .= "Error number: ".$errno."<br>\n";
        $content .= "Error description: ".$errstr."<br>\n";
        return;
}

// select the one and only running server on port 8767
sendQuery($socket, "sel ".$serverUDPPort);

// retrieve answer "OK"
if(!getOK($socket)) {
   die("Server didn't answer "OK" after last command. Aborting.");
}// end if

// retrieve player list
sendQuery($socket,"pl");

// read player info
$playerList = array();

//Skip the first line. It only contains header labels
fgets($socket);
while (true)
{
   //Read the next line from the socket
   $line = fgets($socket);

   //Break it up on the tab delimiter
   $playerinfo = explode("\t", $line);

   //Bail out if only one element
   if (count($playerinfo) == 1)
   {
      //Only one element means the OK has been encountered.
      //The list is done.
      break;
   }
   
   //Stuff the array values into variables
   list($playerid, $channelid, $receivedpackets, $receivedbytes, $sentpackets, $sentbytes, $d, $d, $totaltime, $idletime, $d, $d, $d, $s, $playername) = $playerinfo;
   
   $playerList[$playerid] = array("playerid" => $playerid,
               "channelid" => $channelid,
               "receivedpackets" => $receivedpackets,
               "receivedbytes" => $receivedbytes,
               "sentpackets" => $sentpackets,
               "sentbytes" => $sentbytes,
               "totaltime" => $totaltime,
               "idletime" => $idletime,
               "playername" => str_replace("\"", "", $playername));
}



// retrieve channel list
sendQuery($socket,"cl");

// read channel info
$channelList = array();
do {
        $channelinfo = "";
        do {
      $input = fread($socket, 1);
      if($input != "\n" && $input != "\r") $channelinfo .= $input;
        } while($input != "\n");

        $channelid = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $codec = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $parent = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $maxplayers = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $channelname = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $topic = getNext($channelinfo);

        if($channelid != "OK") {
      if($isdefault == "Default") $isdefault = 1; else $isdefault = 0;

               // determine number of players in channel
               $playercount = 0;
               foreach($playerList as $playerInfo) {
                   if($playerInfo[channelid] == $channelid) $playercount++;
               }

               $channelList[$channelid] = array("channelid" => $channelid,
                                             "codec" => $codec,
                                             "parent" => $parent,
                                             "maxplayers" => $maxplayers,
                                             "channelname" => $channelname,
                                             "isdefault" => $isdefault,
                                             "topic" => $topic,
                                             "currentplayers" => $playercount);
   }
} while($channelid != "OK");

// display channel list
/*$content .= "<table width=\"100%\">\n";*/
$counter = 0;
foreach($channelList as $channelInfo) {
   // default channel?
        if($channelInfo[isdefault] == 1) {
            $channelname = $channelInfo[channelname];
        } else {
            $channelname = $channelInfo[channelname];
        }

      if ($channelInfo[currentplayers] > 0) {
/*         $content .= "<tr><td><img src=\"images/bullet_channel.gif\" border=\"0\" align=\"left\">".$channelname."</tr></td>\n";*/
         $content .= "<font color=\"#FFCC00\"><strong>".$channelname."</strong></font><br>\n";
      }

        $counter++;
        foreach ($playerList as $playerInfo) {
           if ($channelInfo[channelid] == $playerInfo[channelid]) {

/*              $content .= "<tr><td><img src=\"images/bullet_0.gif\" border=\"0\" align=\"left\">".$playerInfo[playername]."</tr></td>\n"; */

            $temp_playername = $playerInfo[playername];

            if (strlen($temp_playername) > 15) {
         
               $temp_playername = substr($temp_playername, 0, 15);
               $temp_playername .= "...";

            }


              $content .= " - ".$temp_playername."<br>\n";
           }
        }
    }

    if($counter == 0) $content .= "No channels<br>\n";


/*   $content .= "</table>\n";*/

    // close connection to teamspeak server
    closeSocket($socket);



 

$content .= "<form name=\"testform\">";
$content .= "   <input type=\"text\" name=\"NICKNAME\" size=\"12\"> Nick";
$content .= "<br>";
$content .= "<br>";
$content .= "   <input type=\"text\" name=\"LOGINNAME\" size=\"12\"> Login";
$content .= "<br>";
$content .= "<br>";
$content .= "   <input type=\"text\" name=\"PASSWORD\" size=\"12\"> Pass";
$content .= "<br>";
$content .= "<br>";
$content .= "<center>";
$content .= "<input type=\"button\" value=\"Submit\" onClick=\"location.href='teamspeak://$serverAddress: $serverUDPPort/nickname=' + testform.NICKNAME.value + '?loginname=' + testform.LOGINNAME.value + '?password=' + testform.PASSWORD.value;\"></center>";
$content .= "<br>";

$content .= "</form>";
$content .= "<center>";
$content .="<a href=\"http://www.goteamspeak.com\" target=\"_blank\"><img src=\"graphics/teamspeak.gif\" border=\"0\" align=absmiddle alt=\"Go to goteamspeak.com\"></a></center>"
 ."";






?>
 
 Quote

All times are EST. The time is now 05:59 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content