Fwaky

Untitled

Dec 25th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. include("../config.php");
  3. include("../library/tibiaparser.class.php");
  4. include("../library/mysql.db.class.php");
  5.  
  6. // Working
  7. // Last update: 2013-06-19 15:17 CEST
  8.  
  9.  
  10. // TEMP
  11. function getWorldType($t){
  12.     $t = strtolower($t);
  13.     if($t == 'optional pvp'){
  14.         return 0;
  15.     } elseif($t == 'open pvp'){
  16.         return 1;
  17.     } elseif($t == 'hardcore pvp'){
  18.         return 2;
  19.     }
  20. }
  21. function getLocation($l){
  22.     $l = strtolower($l);
  23.     if($l == "europe"){
  24.         return 0;
  25.     } elseif($l == "north america"){
  26.         return 1;
  27.     }
  28. }
  29. // Set database object
  30. global $db;
  31. $db = new database($db_host, $db_name, $db_user, $db_pass);
  32. // Updates Tibia Worlds based on Tibia.com
  33. $tc = new TibiaDotCom();
  34. $worlds = $tc->getWorlds();
  35. foreach($worlds as $w){
  36.     $name =     $w["name"];
  37.     $location = $w["location"];
  38.     $type =     $w["worldtype"];
  39.     // Check if world exists, if not add it.
  40.     $db->query("SELECT id FROM worlds WHERE name = :name");
  41.     $db->bind(":name", $name);
  42.     $data = $db->single();
  43.     if(empty($data)){
  44.         // Save world, if not already exists
  45.         $db->query("INSERT INTO worlds (name, type, location) VALUES(:name, :type, :location)");
  46.             // Bind data
  47.             $db->bind(":name", $name);
  48.             echo $name.' - '.$type.' - '.$location.'<br>';
  49.             $db->bind(":type", getWorldType($type));
  50.             $db->bind(":location", getLocation($location));
  51.             // End bind data
  52.         $db->execute();
  53.     }
  54. }
  55. ?>
Add Comment
Please, Sign In to add comment