web/wp-content/plugins/wptouch/include/class.prowl.php
branchwordpress
changeset 123 561aa6d282f6
equal deleted inserted replaced
112:fb7cd02b9848 123:561aa6d282f6
       
     1 <?php
       
     2 
       
     3 class Prowl
       
     4 {
       
     5    var $apikey;
       
     6    var $application;
       
     7    
       
     8    function Prowl($apikey, $application)
       
     9    {
       
    10       $this->apikey = $apikey;
       
    11       $this->application = $application;
       
    12      // $this->verify();
       
    13    }
       
    14    
       
    15    function add($priority, $event, $description)
       
    16    {
       
    17       $options = array(
       
    18          'apikey' => $this->apikey,
       
    19          'priority' => $priority,
       
    20          'application' => urlencode($this->application),
       
    21          'event' => urlencode($event),
       
    22          'description' => urlencode($description)
       
    23       );
       
    24       
       
    25       $response = $this->request('https://prowl.weks.net/publicapi/add', $options);
       
    26       return $this->getresult($response);
       
    27    }
       
    28    
       
    29    function getresult($response) {
       
    30 		$response = str_replace("\n", " ", $response);
       
    31 	
       
    32 		if(preg_match("/code=\"200\"/i", $response))
       
    33 			return true;
       
    34 		else
       
    35 		{
       
    36 			preg_match("/<error.*?>(.*?)<\/error>/i", $response, $out);
       
    37 			return $out[1];
       
    38 		}
       
    39    }
       
    40    
       
    41    function verify()
       
    42    {
       
    43       $options = array('apikey' => $this->apikey);
       
    44       return $this->getresult( $this->request('https://prowl.weks.net/publicapi/verify', $options) );
       
    45    }
       
    46    
       
    47    function request($file, $options)
       
    48    {
       
    49       $url = $file;
       
    50       
       
    51       $first = true;
       
    52       foreach ($options as $key => $value) {
       
    53          $url .= ($first ? '?' : '&') . $key . '=' . $value;
       
    54          $first = false;
       
    55       }
       
    56       
       
    57       $ch = curl_init($url);
       
    58       curl_setopt($ch, CURLOPT_HEADER, false);
       
    59       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       
    60       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
       
    61       curl_setopt($ch, CURLOPT_TIMEOUT, 10);
       
    62       $response = curl_exec($ch);
       
    63       curl_close($ch);
       
    64 
       
    65       return $response;
       
    66    }
       
    67 }
       
    68 ?>