zero-perfoliate
zero-perfoliate

Author Topic: A (hopefully) simple task  (Read 262 times)

Offline Marencian

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
A (hopefully) simple task
« on: August 06, 2009, 11:21:39 PM »
Basically I have been given a php script that displays the players in a certain guild on a certain online game that are currently playing. It works perfectly however there is one thing I would like to change. Basically in the code it is required that you manually edit the 'settings' to define the guild you would like displayed. What I would like to do with your help is to change the script slightly so that I have the option to enter the guild name and have it then display - rather than manually editing.

e.g. enter guild name, click submit, result is displayed.

the complete script is as follows
Code: [Select]
<?php/*-------------------------
Title: Tibia Guild Online List
Author: Mike Haugland
Date: January 06, 2005
URL: http://haugland.ca
Description:
This script is used to display a list of
online and offline characters for a chosen
guild in the game of Tibia.
Copyright:
All code written by Mike Haugland with the exception of some noted code below for parsing which was from http://www.magicasoft.net/?id=18
-------------------------*/
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="/styles.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Online List Test</title>
</head>
<body>
<h1>Member List</h1>
<?php
//-------[Settings]-----------
// This is the only thing you really need to edit!
$guildname "";
//----------------------------
//Get the online list for the world of your choice.
//if ($contents = file_get_contents($path)) {
//Create arrays to store the names of online and offline characters.
$onlineList = array();
$offlineList = array();
//Retrieve and parse the guildlist for up-to-date members. Some code used from BBMan at http://www.magicasoft.net/?id=18
$members file_get_contents('http://www.tibia.com/community/?subtopic=guilds&page=view&GuildName='.urlencode($guildname));
$world split("The guild was founded on \s|\S* on ",$members);
if (
strstr($world[2],' ')===false) {
$world $world[2];
} else {
$world $world[1];
}
$path "http://www.tibia.com/community/?subtopic=whoisonline&world=".urlencode($world);
$contents file_get_contents($path);
$members split("<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>\s|\S*</TABLE>",$members); // get the big parts
$members strip_tags($members[1],'<tr>'); //take the members element
$members preg_replace('!<TR BGCOLOR=#w{6,6}|</TR>!','',$members);
$members str_replace(' ',' ',$members); //Replace HTML entity with normal space.
$members explode('>',$members);
//End of BBMan code
//Clear unnecessary array values.
unset($members[0],$members[1],$members[2]);
//Loop through and put characters in online or offline array.
for($count=3;$count<count($members)+3;$count++){
$newmember explode("\n",$members[$count]); //Split up user info.
if (count($newmember) == 3) {
$name $newmember[2];
} else {
$name $newmember[1];
}
$name explode(" (",$name);
$characterSearch str_replace(' ',' ',$name[0]); //Recovert space to HTML entity for searching.
//Apply ">" and "<" around name to eliminate chances of mistakenly reporting a name as online.
//If you don't do this, searching for Thor would return as online if someone had the name Asthorm.
$characterSearch ">".$characterSearch."<";
//Get the numbers for the lists.
$inOnline count($onlineList);
$inOffline count($offlineList);
//Check to see if character is in the source of the online list. Put into array accordingly.
if (strpos($contents,$characterSearch)) {
$onlineList[$inOnline] = $name[0];
} else {
$offlineList[$inOffline] = $name[0];
}
}
//Sort names alphabetically and reset the array numbers.
@reset(sort($onlineList));
@
reset(sort($offlineList));
//Display number of online members versus total members.
echo count($onlineList)." of ".count($members)." members online.";
//Display online list.
echo "<ul id=\"onlineList\">";
for (
$count=0;$count<count($onlineList);$count++) {
echo 
"<li><a href=\"http://www.tibia.com/community/?subtopic=character&name=" urlencode($onlineList[$count])."\">" $onlineList[$count]."</a> is <span class=\"online\">Online</span></li>";
}
//Display offline list.
echo "</ul><ul id=\"offlineList\">";
for (
$count=0;$count<count($offlineList);$count++) {
echo 
"<li><a href=\"http://www.tibia.com/community/?subtopic=character&name=" urlencode($offlineList[$count]) . "\">" $offlineList[$count] . "</a> is <span class=\"offline\">Offline</span></li>";
}
echo 
"</ul>";
//} else {
//In the event of failure, let the people know.
//echo "<p>Opening ".$path." failed.</p>";
//}
?>

</body></html>

As you can see at the moment, you define the guild name here:
$guildname = "";
I would like to remove this and change it so it is defined by what the user types into the text field.
I have no idea how to go about this, I believe that it should not be too difficult though.

Any support is greatly appreciated
small cash reward to someone who posts a complete script?