Wer Interesse hat, selbst sich Banner über seinen Space generieren zulassen, der kann gerne meine Klassen benutzen, die ich hier zur Verfügung stelle - ein kleiner Hinweis zum Autor wäre nett (pctflux.net).
Falls Fragen auftauchen, oder das Script nicht wie erwartet funktioniert, zögert nicht, mich zu fragen
(Am besten hier im Thread) PHP-Code: <?php /****************************************************** pctflux services BF BC 2 Stats Classes @Author: Hans-Heinrich Auditor // www.pctflux.net @Version: 0.2 @Copyright: Hans-Heinrich Auditor Aenderungen sind erlaubt mit dem Hinweis auf den urspruenglichen Autor. Changes are permitted with reference to the original author. Data provided by http://bfbcs.com Requirements: mysql-database write permissions curl php-extension gd php-extension Setup: (You can jump through the #Edit marks) Fill in the MYSQL_Interface Data Set path to TrueTypeFont Edit the redirect-method in SignatureGenerator-Class Edit the Template (400x80px PNG) Maybe adjust the generateSignature-method Usage: get-bc2-stats.php?spieler=Playername If data exists @ bfbcs.com, data will be pulled and aligned. If it differs, new banner will be generated, else, requests gets redirected to the banner-file. In case there is no userdata, it will be requested at bfbcs.com. *****************************************************/
class MYSQL_Interface #Edit { private $_mysql_user = ""; private $_mysql_password = ""; private $_mysql_server = "localhost"; private $_mysql_database = ""; public $_mysql_connection; public $_mysql_open; public $_mysql_kill_connection; public $_mysql_query_result; public $_mysql_result = array();
public function connectDB() { $this->_mysql_connection = mysql_connect($this->_mysql_server, $this->_mysql_user, $this->_mysql_password); $this->_mysql_open = mysql_select_db($this->_mysql_database); return $this->_mysql_connection; }
public function disconnectDB() { $this->_mysql_kill_connection = mysql_close($this->_mysql_connection); }
public function getQuery($args) { $this->connectDB(); $this->_query_result = mysql_query($args); while($this->_mysql_query_result = mysql_fetch_array($this->_query_result)) { $this->_mysql_result[] = $this->_mysql_query_result; } $this->disconnectDB(); return $this->_mysql_result; }
public function sendQuery($args) { $this->connectDB(); if(mysql_query($args)) { return true; } else { return false; } $this->disconnectDB(); }
public function countQuery($args) { $this->connectDB(); $this->_query_result = mysql_query($args); $is_selecting = preg_match_all('/SELECT/', $args, $treffer); if($is_selecting == 0 or $is_selecting == false) { return mysql_affected_rows(); } else { return mysql_num_rows($this->_query_result); } $this->disconnectDB(); } }
class SignatureGenerator { private $_spielername; private $_dbhandle; private $_font = ""; #Edit | Path to TrueTypeFont-File eg. "/var/www/yourpage/public_html/fonts/arial.ttf"; public $_spielerdaten;
function __construct() { $this->_spielername = $this->safeMYSQL($_REQUEST["spieler"]); $this->_dbhandle = new MYSQL_Interface; }
private function safeMYSQL($var) { return mysql_real_escape_string($var, $this->_dbhandle->connectDB()); $this->_dbhandle->disconnectDB(); }
public function retrieveData() { if(empty($this->_spielername)) { $this->_spielerdaten["name"] = "nicht angegeben!"; return false; } else { $url = 'http://api.bfbcs.com/api/pc'; $postdata = "players=".$this->_spielername."&fields=general"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); $data = curl_exec($ch); curl_close($ch); $data = json_decode($data,true); $this->_spielerdaten = $data["players"][0]; $this->_spielerdaten["timestamp"] = strtotime($data["players"][0]["date_lastupdate"]); $this->_spielerdaten["md5"] = md5($this->_spielername); return $this->_spielerdaten; } }
public function necessaryAction() { $this->retrieveData(); if($this->existsData()) { if($this->existsEntry()) { if($this->differingDate()) { $this->updateData(); } else { $this->incrementViews(); } } else { $this->insertData(); } } else { $this->redirect(false); } }
private function existsEntry() { if($this->_dbhandle->countQuery("SELECT * FROM bc2_stats WHERE name = '$this->_spielername'") != 0) { return true; } else { return false; } }
private function existsData() { if($this->_spielerdaten["timestamp"] == 0) { return false; } else { return true; } }
private function differingDate() { $lup = $this->_dbhandle->getQuery("SELECT last_update FROM bc2_stats WHERE name = '$this->_spielername'"); $aup = $this->_spielerdaten["timestamp"]; if($lup[0][0] == $aup) { return false; } else { return true; } }
private function redirect($tf) #Edit { if(!$tf) { header('Location: http://pctflux.net/bc2/err.png'); } #Error-image, user not existing or not recorded at bfbcs.com else { $weiterleitung = "Location: http://pctflux.net/bc2/"; $weiterleitung .= $this->_spielerdaten["md5"]; $weiterleitung .= ".png"; header($weiterleitung); } }
private function incrementViews() { $this->_dbhandle->sendQuery("UPDATE bc2_stats SET views_slu=views_slu+1 , views=views+1 WHERE name = '$this->_spielername'"); $this->redirect(true); }
private function insertData() { $name = $this->_spielerdaten["name"]; $name_md5 = $this->_spielerdaten["md5"]; $timestamp = $this->_spielerdaten["timestamp"]; $this->_dbhandle->sendQuery("INSERT INTO bc2_stats (name, name_md5, last_update) VALUES ('$name', '$name_md5', '$timestamp')"); if($this->generateSignature()) { $this->_dbhandle->sendQuery("UPDATE bc2_stats SET views_slu=views_slu+1 , views=views+1 WHERE name = '$this->_spielername'"); $this->redirect(true); } }
private function updateData() { $aktueller_stamp = $this->_spielerdaten["timestamp"]; $this->_dbhandle->sendQuery("UPDATE bc2_stats SET last_update = '$aktueller_stamp', views_slu = '1' WHERE name = '$this->_spielername'"); if($this->generateSignature()) { $this->_dbhandle->sendQuery("UPDATE bc2_stats SET views_slu=1, views=views+1 WHERE name = '$this->_spielername'"); $this->redirect(true); } }
private function generateSignature() { $sname = $this->_spielerdaten["name"]; $srank = $this->_spielerdaten["rank"]; $srank_name = $this->_spielerdaten["rank_name"]; $sscore = $this->_spielerdaten["score"]; $skills = $this->_spielerdaten["kills"]; $sdeaths = $this->_spielerdaten["deaths"]; $skd = round(($skills/$sdeaths) , 2); #K/D Ratio $stime = $this->_spielerdaten["time"]; #Anzahl Spielsekunden / Game seconds $stime_hours = intval($stime / 3600); #Anzahl Spielstunden / Game hours $stime_mins = round(($stime % 3600) / 60); #Anzahl Spielminuten minus Stunden / Game minutes minus Hours $stime_mins_complete = intval($stime / 60); #Anzahl Spielminuten / Overall game minutes $sppm = round($sscore / $stime_mins_complete); #Anzahl Punkte pro Minute / Points per minute $supd = $this->_spielerdaten["date_lastupdate"]; #Letztes Update / Last update by bfbcs.com $supd_date = date("d.m.Y", strtotime($supd));
$trc = imagecreatetruecolor(400, 80); $vorlage = imagecreatefrompng("stats_vorlage.png"); #Template #Edit imagecopyresampled($trc, $vorlage, 0, 0, 0, 0, 400, 116, 400, 116); $textcolor = imagecolorallocate($trc, 0, 0, 0);
#Left Side imagettftext($trc, 11, 0, 10, 17, $textcolor, $this->_font, $sname); #Playername imagettftext($trc, 8, 0, 10, 34, $textcolor, $this->_font, "Rang: $srank | $srank_name"); #Rank No. & Name imagettftext($trc, 8, 0, 10, 46, $textcolor, $this->_font, "Punkte: $sscore"); #Score imagettftext($trc, 8, 0, 10, 58, $textcolor, $this->_font, "Kills: $skills"); #Kills imagettftext($trc, 8, 0, 10, 70, $textcolor, $this->_font, "Deaths: $sdeaths"); #Deaths
#Right Side imagettftext($trc, 8, 0, 268, 34, $textcolor, $this->_font, "K/D Ratio: $skd"); #K/D Ratio imagettftext($trc, 8, 0, 268, 46, $textcolor, $this->_font, "PpM: $sppm"); #Points per Minute imagettftext($trc, 8, 0, 268, 58, $textcolor, $this->_font, "Zeit: $stime_hours h $stime_mins m"); #Time imagettftext($trc, 8, 0, 268, 70, $textcolor, $this->_font, "Upd: $supd_date"); #last Update by bfbcs.com imagepng($trc, $this->_spielerdaten["md5"].".png"); return true; } }
$start = new SignatureGenerator; $start->necessaryAction(); ?> mySQL Query zum Erstellen der Datenbankstruktur: Code: CREATE TABLE IF NOT EXISTS `bc2_stats` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`name_md5` varchar(255) NOT NULL,
`last_update` int(11) NOT NULL default '0',
`views` int(7) NOT NULL default '0',
`views_slu` int(3) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=0; | | #1 | | | |