<?php

    
//PHP PlaySMS Class by Sloenthran

    
class PlaySMS
    
{
    
        function 
Login($Login$Pass)
        {
        
            
$SAML = array('SAMLRequest' => $this->GetGateway(), 'target'=> 'https://bramka.play.pl');
            
            
$Query $this->cURL('https://logowanie.play.pl/p4-idp2/SSOrequest.do'$SAML'https://bramka.play.pl/composer/public/mmsCompose.do');
            
            
preg_match('/name="random" value="(.+?)"/'$Query$Rand);
            
            
$Post = array('step' => 1'next' => 'Next''random' => $Rand[1], 'login' => $Login'password' => $Pass);
            
            
$Logged $this->cURL('https://logowanie.play.pl/p4-idp2/Login.do'$Post''0);

            
$LoggedPost = array('SAMLResponse' => $this->GetResponse($Logged), 'target'=>'https://bramka.play.pl');
            
            
$this->cURL('https://bramka.play.pl/composer/samlLog?action=sso'$LoggedPost'https://logowanie.play.pl/p4-idp2/SSOrequest.do');
    
            
$this->cURL('https://bramka.play.pl/composer/j_security_check'$LoggedPost'https://bramka.play.pl/composer/samlLog?action=sso');
        
        }
        
        public function 
SendSMS($Number$Text)
        {

            
$Query $this->cURL('https://bramka.play.pl/composer/public/editableSmsCompose.do');

            
preg_match('/name="randForm" value="(.+?)"/'$Query$Rand);
    
            
$SMS = array('recipents' => $Number'content_in' => $Text'czas' => 0'sendform' => 'on''randForm' => $Rand[1], 'old_signature' => '''old_content' => $Text'content_out' => $Text'agreement' => 'true');
  
            
$this->cURL('https://bramka.play.pl/composer/public/editableSmsCompose.do'$SMS);
    
            
$SMS['SMS_SEND_CONFIRMED'] = 'Wyƛlij';
            
            
$CheckQuery $this->cURL('https://bramka.play.pl/composer/public/editableSmsCompose.do'$SMS);
    
            if(
preg_match('/Wiadomo(.*) zosta(.*)a wys(.*)ana/'$CheckQuery))
            {

                return 
true;
                
            }
        
            else
            {

                return 
FALSE;
                
            }
            
        }
    
        function 
cURL($URL$Post NULL$Reffer NULL$Follow 1)
        {
            
            
$Connect curl_init($URL);
    
            
curl_setopt($ConnectCURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7');
            
curl_setopt($ConnectCURLOPT_RETURNTRANSFER1);
    
            
curl_setopt($ConnectCURLOPT_COOKIEJAR'cookies.txt');
            
curl_setopt($ConnectCURLOPT_COOKIEFILE'cookies.txt');
    
            
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
    
            if(!empty(
$Post))
            {
                
                
$Vars '';

                foreach (
$Post as $Key => $Value)
                {
                    
                    
$Vars .= $Key.'='.urlencode($Value).'&';
                    
                }

                
curl_setopt($ConnectCURLOPT_POST1);
                
curl_setopt($ConnectCURLOPT_POSTFIELDS$Vars);
            
            }
      
            if(!empty(
$Reffer))
            {
                
                
curl_setopt($ConnectCURLOPT_REFERER$Reffer);
                
            }
    
            
curl_setopt($ConnectCURLOPT_RETURNTRANSFER1);
            
curl_setopt($ConnectCURLOPT_HEADER1);
            
curl_setopt($ConnectCURLOPT_FOLLOWLOCATION$Follow);
    
            
$Return curl_exec($Connect);
            
            
curl_close($Connect);
    
            return 
$Return;
        
        }
        
        function 
GetGateway()
        {
            
            
$Query $this->cURL('https://bramka.play.pl/composer/public/mmsCompose.do'NULL''0);

            
preg_match('/value="(.*)"/msU'$Query$Return);
            
            return 
$Return[1];
        
        }
        
        public function 
GetResponse($Text)
        {
            
            
preg_match('/value="(.*)"/msU'$Text$Return);
            
            return 
trim($Return[1]);
        
        }
        
        function 
__destruct()
        {
        
            
unlink('cookies.txt');
        
        }
    
    }

?>