function brightcove_encode($string)
{
    $stream = new SabreAMF_OutputStream();
    $message = new SabreAMF_Message();
    $message->addBody($string);
    $message->setEncoding(SabreAMF_Const::AMF0);
    $message->serialize($stream);
    $data = $stream->getRawData();
    //strtr concierte de amf0 a amf3
    //return $data;
    return strtr($data, array("" => ""));
}
 /**
  * setResponse 
  * 
  * Send a response back to the client (based on a request you got through getRequests)
  * 
  * @param string $target This parameter should contain the same as the 'response' item you got through getRequests. This connects the request to the response
  * @param int $responsetype Set as either SabreAMF_Const::R_RESULT or SabreAMF_Const::R_STATUS, depending on if the call succeeded or an error was produced
  * @param mixed $data The result data
  * @return void
  */
 public function setResponse($target, $responsetype, $data)
 {
     switch ($responsetype) {
         case SabreAMF_Const::R_RESULT:
             $target = $target .= '/onResult';
             break;
         case SabreAMF_Const::R_STATUS:
             $target = $target .= '/onStatus';
             break;
         case SabreAMF_Const::R_DEBUG:
             $target = '/onDebugEvents';
             break;
     }
     return $this->amfResponse->addBody(array('target' => $target, 'response' => '', 'data' => $data));
 }
Exemple #3
0
 /**
  * Real AMF functioning simulation
  *
  * @param <type> $method_return
  * @return <type>
  */
 protected function _makeAmfResponseFromMethodReturn($method_return)
 {
     $response = new SabreAMF_AMF3_AcknowledgeMessage();
     $response->body = $method_return;
     $amfResponse = new SabreAMF_Message();
     $amfResponse->addBody(array('target' => '/onResult', 'response' => '', 'data' => $response));
     $amfOutputStream = new SabreAMF_OutputStream();
     $amfResponse->serialize($amfOutputStream);
     $amfInputStream = new SabreAMF_InputStream($amfOutputStream->getRawData());
     $amfResponse2 = new SabreAMF_Message();
     $amfResponse2->deserialize($amfInputStream);
     $bodies = $amfResponse2->getBodies();
     //var_dump($bodies);
     return $bodies[0]['data']->body;
 }
Exemple #4
0
 /**
  * sendRequest 
  *
  * sendRequest sends the request to the server. It expects the servicepath and methodname, and the parameters of the methodcall
  * 
  * @param string $servicePath The servicepath (e.g.: myservice.mymethod)
  * @param array $data The parameters you want to send
  * @return mixed 
  */
 public function sendRequest($servicePath, $data)
 {
     // We're using the FLEX Messaging framework
     if ($this->encoding & SabreAMF_Const::FLEXMSG) {
         // Setting up the message
         $message = new SabreAMF_AMF3_RemotingMessage();
         $message->body = $data;
         // We need to split serviceName.methodName into separate variables
         $service = explode('.', $servicePath);
         $method = array_pop($service);
         $service = implode('.', $service);
         $message->operation = $method;
         $message->source = $service;
         $data = $message;
     }
     $this->amfRequest->addBody(array('target' => $this->encoding & SabreAMF_Const::FLEXMSG ? 'null' : $servicePath, 'response' => '/1', 'data' => $data));
     $this->amfRequest->serialize($this->amfOutputStream);
     // The curl request
     $ch = curl_init($this->endPoint);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: ' . SabreAMF_Const::MIMETYPE));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $this->amfOutputStream->getRawData());
     if ($this->httpProxy) {
         curl_setopt($ch, CURLOPT_PROXY, $this->httpProxy);
     }
     $result = curl_exec($ch);
     if (curl_errno($ch)) {
         throw new Exception('CURL error: ' . curl_error($ch));
         false;
     } else {
         curl_close($ch);
     }
     $this->amfInputStream = new SabreAMF_InputStream($result);
     $this->amfResponse = new SabreAMF_Message();
     $this->amfResponse->deserialize($this->amfInputStream);
     $this->parseHeaders();
     foreach ($this->amfResponse->getBodies() as $body) {
         if (strpos($body['target'], '/1') === 0) {
             return $body['data'];
         }
     }
 }
 /**
  * sendRequest 
  *
  * sendRequest sends the request to the server. It expects the servicepath and methodname, and the parameters of the methodcall
  * 
  * @param string $servicePath The servicepath (e.g.: myservice.mymethod)
  * @param array $data The parameters you want to send
  * @return mixed 
  */
 public function sendRequest($servicePath, $data)
 {
     // We're using the FLEX Messaging framework
     if ($this->encoding & SabreAMF_Const::FLEXMSG) {
         // Setting up the message
         $message = new SabreAMF_AMF3_RemotingMessage();
         $message->body = $data;
         // We need to split serviceName.methodName into separate variables
         $service = explode('.', $servicePath);
         $method = array_pop($service);
         $service = implode('.', $service);
         $message->operation = $method;
         $message->source = $service;
         $data = $message;
     }
     $this->amfRequest->addBody(array('target' => $this->encoding & SabreAMF_Const::FLEXMSG ? 'null' : $servicePath, 'response' => '/1', 'data' => $data));
     $this->amfRequest->serialize($this->amfOutputStream);
     ##test
     /*
     			require '../Zebra_cURL.php';
     
     $curl = new Zebra_cURL($this->endPoint);
     $curl->cache('cache', 3600);
     $curl->threads = 10;
     $curl->option(array(
     CURLOPT_CURLOPT_POST  =>  1,
     CURLOPT_FOLLOWLOCATION  =>  TRUE,
     CURLOPT_REFERER => 'http://www.trilulilu.ro',
     CURLOPT_TIMEOUT => 20,
     CURLOPT_HTTPHEADER => array('Content-type: ' . SabreAMF_Const::MIMETYPE),
     CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13',
     CURLOPT_RETURNTRANSFER         =>  1,
     CURLOPT_POSTFIELDS => $this->amfOutputStream->getRawData(),
     ));
     $v=$curl->get($url);
     $data=$v->body;
     $result =   html_entity_decode($data);
     
     ##
     */
     // The curl request
     $ch = curl_init($this->endPoint);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_REFERER, 'http://www.trilulilu.ro');
     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: ' . SabreAMF_Const::MIMETYPE));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $this->amfOutputStream->getRawData());
     if ($this->httpProxy) {
         curl_setopt($ch, CURLOPT_PROXY, $this->httpProxy);
     }
     $result = curl_exec($ch);
     if (curl_errno($ch)) {
         throw new Exception('CURL error: ' . curl_error($ch));
         false;
     } else {
         curl_close($ch);
     }
     $this->amfInputStream = new SabreAMF_InputStream($result);
     $this->amfResponse = new SabreAMF_Message();
     $this->amfResponse->deserialize($this->amfInputStream);
     $this->parseHeaders();
     foreach ($this->amfResponse->getBodies() as $body) {
         if (strpos($body['target'], '/1') === 0) {
             return $body['data'];
         }
     }
 }