kann sein, das es so eine API hier schon irgendwo gibt, aber dann ich habe sie nicht gefunden...
Mit der API erhaltet ihr eure Profildaten im JSON-Format und könnt diese dann einfach in euer Anwendung nutzen.
index.php
PHP Code:
error_reporting(0);
include 'classes/TBMAPI.php';
if(isset($_GET['profile'])) {
if($_GET['profile'] != "") {
$p = $_GET['profile'];
$TBMAPI = new TBMAPI($p);
$DATA = array(
'RegisterDate' => $TBMAPI->getRegDate(),
'Posts' => $TBMAPI->getPosts(),
'BlogPosts' => $TBMAPI->getBlogPosts(),
'EliteGold' => $TBMAPI->getGold(),
'Positive' => $TBMAPI->getPositiveTBM(),
'Neutral' => $TBMAPI->getNeutraleTBM(),
'Negative' => $TBMAPI->getNegativeTBM(),
'Mediations' => $TBMAPI->getMediations()
);
$JSON = json_encode($DATA);
echo "<pre>";
echo $JSON;
echo "</pre>";
}
}
PHP Code:
/**
* @author Caiv
*/
class TBMAPI {
/**
* Profillink
* @var String
*/
private $profile;
/**
* Benötigte Durchläufe für Schleife
* @var int
*/
private $profilelength;
/**
* Anzahl der Mediations als String!!!
* @var String
*/
private $mediations;
/**
* Positive TBM
* @var int
*/
private $positiveTBM;
/**
* Neutrale TBM
* @var int
*/
private $neutraleTBM;
/**
* Negative TBM
* @var int
*/
private $negativeTBM;
/**
* Anzahl der Blogeintraege
* @var int
*/
private $blog;
/**
* Aktueller E*Gold Stand
* @var int
*/
private $elitegold;
/**
* Aktueller Beitraege Stand
* @var String
*/
private $beitraege;
/**
* Register Datum
* @var int
*/
private $regdate;
/**
* Konstruktor benötigt einen Profillink
* @param String $p
*/
public function __construct($p) {
$this->profile = $p;
$this->ParseHTML();
}
/**
* Gibt den Profillink zurück
* @return String
*/
public function getProfile() {
return $this->profile;
}
/**
* Gibt "Länge" des Profils zurück
* @return int
*/
public function getProfilelength() {
return $this->profilelength;
}
/**
* Gibt Positive TBm zurück
* @return int
*/
public function getPositiveTBM() {
return $this->positiveTBM;
}
/**
* Gibt Neutrale TBM zurück
* @return int
*/
public function getNeutraleTBM() {
return $this->neutraleTBM;
}
/**
* Gibt negative TBM zurück
* @return int
*/
public function getNegativeTBM() {
return $this->negativeTBM;
}
/**
* Gibt Mediations zurück
* @return String
*/
public function getMediations() {
return $this->mediations;
}
/**
* Gibt Posts zurück
* @return String
*/
public function getPosts() {
return $this->beitraege;
}
/**
* Gibt Blogeintraege zurück
* @return int
*/
public function getBlogPosts() {
return $this->blog;
}
/**
* Gibt Elitegold zurück
* @return int
*/
public function getGold() {
return $this->elitegold;
}
/**
* Gibt Register Datum zurück
* @return String
*/
public function getRegDate() {
return $this->regdate;
}
/**
* Parsing starten
*/
private function ParseHTML() {
$items = $this->CreatNewXPath($this->CreatNewDOM());
$this->CountProfileRows($items);
$this->AssignValues($items);
$this->ConvertTBM($items);
}
/**
* Gibt HTML zurück
* @return \DOMDocument
*/
private function CreatNewDOM() {
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument;
$dom->loadHTMLFile($this->profile);
libxml_clear_errors();
return $dom;
}
/**
* Bestimmten Bereich parsen
* @param DOMDocument $d
*/
private function CreatNewXPath(DOMDocument $d) {
$xp = new DOMXPath($d);
$matches = $xp->query('//dl[@class="smallfont list_no_decoration profilefield_list"]//dd');
return $matches;
}
/**
* Benötigt die Ergebnisse des Parsings als Parameter
* @param $items
*/
private function CountProfileRows($items) {
for($i=0; $i < $items->length; $i++) {
$this->profilelength++;
}
}
/**
* Anhand der Profillänge die Werte zuweisen
*/
private function AssignValues($items) {
$this->mediations = $this->RemoveSpaces($items->item($this->profilelength-1)->nodeValue);
$this->elitegold = $this->RemoveSpaces($items->item($this->profilelength-3)->nodeValue);
$this->blog = $this->RemoveSpaces($items->item($this->profilelength-4)->nodeValue);
$this->beitraege = $this->RemoveSpaces($items->item($this->profilelength-5)->nodeValue);
$this->regdate = $this->RemoveSpaces($items->item($this->profilelength-6)->nodeValue);
}
/**
* String mit TBM's bearbeiten
*/
private function ConvertTBM($items) {
$string = $items->item($this->profilelength-2)->nodeValue;
$TBM = explode("/", $string);
$this->positiveTBM = $TBM[0];
$this->neutraleTBM = $TBM[1];
$this->negativeTBM = $TBM[2];
}
/**
* Leerzeichen aus einem String entfernen
* @return String
*/
private function RemoveSpaces($string) {
return str_replace(" ", "", $string);
}
}








