Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.     class Phant {
  3.         protected $url = ""; // Phant szerver címe
  4.         protected $pubkey = ""; // Publikus kulcs
  5.         protected $privkey = ""; // Privát kulcs
  6.         protected $delkey = ""; // Kulcs a törléshez
  7.  
  8.         function __construct($url, $pubkey, $privkey, $delkey = "") {
  9.             $this->url = $url;
  10.             $this->pubkey = $pubkey;
  11.             $this->privkey = $privkey;
  12.             $this->delkey = $delkey;
  13.         } // __constructor
  14.  
  15.         public function post($data) {
  16.             $url = $this->url . "input/" . $this->pubkey . ".json";
  17.             $data_str = "";
  18.             foreach ($data as $key => $val) {
  19.                 $data_str .= $key . "=" . urlencode($val) . "&";
  20.             } // foreach
  21.             $data_str = substr($data_str, 0, -1);
  22.             // curl
  23.             $ch = curl_init();
  24.             curl_setopt($ch, CURLOPT_URL, $url);
  25.             curl_setopt($ch, CURLOPT_POST, count($data));
  26.             curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str);
  27.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28.             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
  29.             curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  30.             curl_setopt($ch, CURLOPT_HTTPHEADER, array("Phant-Private-Key: " . $this->privkey));
  31.             $response = json_decode(curl_exec($ch));
  32.             curl_close($ch);
  33.             return $response;
  34.         } // post
  35.  
  36.         public function get($format = "json", $page = false, $pubkey = "") {
  37.             $url = $this->url . "output/" . ($pubkey ? $pubkey : $this->pubkey) . "." . $format . ($page ? "?page=" . $page : "");
  38.             if ($format == "csv") return file_get_contents($url);
  39.             return json_decode(file_get_contents($url));
  40.         } // get
  41.        
  42.         // Stream tartalmának törlése
  43.         public function clear() {
  44.             $url = $this->url . "input/" . $this->pubkey . "/clear?private_key=" . $this->privkey;
  45.             return json_decode(file_get_contents($url));
  46.         } // clear
  47.  
  48.         // Stream statisztika
  49.         public function stats($format = "json", $pubkey = "") {
  50.             $url = $this->url . "output/" . ($pubkey ? $pubkey : $this->pubkey) . "/stats." . $format;
  51.             if ($format == "csv") return file_get_contents($url);
  52.             return json_decode(file_get_contents($url));
  53.         } // stats
  54.        
  55.     } // Phant class