示例#1
0
 /**
  * @return bool
  */
 public function Send()
 {
     if (!$this->_config) {
         Quark::Log('PushNotification does not have a valid config', Quark::LOG_WARN);
         return false;
     }
     $ok = true;
     $providers = $this->_config->Providers();
     foreach ($providers as $provider) {
         foreach ($this->_devices as $device) {
             if ($device && $device->type == $provider->Type()) {
                 $provider->Device($device);
             }
         }
         $ok &= (bool) $provider->Send($this->_payload, isset($this->_options[$provider->Type()]) ? $this->_options[$provider->Type()] : array());
         $provider->Reset();
     }
     return $ok;
 }
示例#2
0
 /**
  * @param IQuarkModel $model
  * @param string $command
  * @param QuarkDTO|object|array $data
  *
  * @return bool
  */
 public function Command(IQuarkModel $model, $command, $data = [])
 {
     try {
         return $this->_api('GET', '/' . self::_class($model) . '/' . $command . '/' . $this->_identify($model), $data);
     } catch (QuarkArchException $e) {
         Quark::Log($e->message, $e->lvl);
         return false;
     }
 }
示例#3
0
 /**
  * @param string $method
  * @param string $url
  * @param array  $data
  * @param string $base = 'https://graph.facebook.com/'
  *
  * @return QuarkDTO|\StdClass
  */
 public function API($method = '', $url = '', $data = [], $base = 'https://graph.facebook.com/')
 {
     $request = new QuarkDTO(new QuarkJSONIOProcessor());
     $request->Method($method);
     $get = $method == 'GET';
     if (!$get) {
         $request->Data($data);
     }
     $response = new QuarkDTO(new QuarkJSONIOProcessor());
     $out = QuarkHTTPTransportClient::To($base . $url . '?' . http_build_query(array_merge_recursive($get ? $data : array()) + array('access_token' => $this->_session)), $request, $response);
     if (!$out->Data()) {
         $data = array();
         parse_str($out->RawData(), $data);
         $out->Data((object) $data);
     }
     if (isset($out->error)) {
         Quark::Log('Facebook.Exception: ' . (isset($out->error->type) ? $out->error->type : '') . ': ' . (isset($out->error->message) ? $out->error->message : '') . '. Code: ' . (isset($out->error->code) ? $out->error->code : ''), Quark::LOG_WARN);
         Quark::Trace($out);
         return null;
     }
     return $out;
 }
 /**
  * @param $data
  *
  * @return mixed
  */
 public function Decode($data)
 {
     if (strlen($data) == 1) {
         return '';
     }
     $first = self::_byte($data[0]);
     $second = self::_byte($data[1]);
     $op = bindec(substr($first, 4, 4));
     $masked = $second[0] == '1';
     $length = ord($data[1]) & 127;
     if (!isset(self::$IFrames[$op])) {
         Quark::Log('WebSocket error 1003. Unknown op code ' . $op);
         return '';
     }
     if ($length === 126) {
         $mask = substr($data, 4, 4);
         $payloadOffset = 8;
         $dataLength = bindec(self::_byte($data[2]) . self::_byte($data[3])) + $payloadOffset;
     } elseif ($length === 127) {
         $mask = substr($data, 10, 4);
         $payloadOffset = 14;
         $tmp = '';
         $i = 0;
         while ($i < 8) {
             $tmp .= self::_byte($data[$i + 2]);
             $i++;
         }
         $dataLength = bindec($tmp) + $payloadOffset;
         unset($tmp, $i);
     } else {
         $mask = substr($data, 2, 4);
         $payloadOffset = 6;
         $dataLength = $length + $payloadOffset;
     }
     /**
      * We have to check for large frames here. socket_recv cuts at 1024 bytes
      * so if WebSocket-frame is > 1024 bytes we have to wait until whole
      * data is transferred.
      */
     if (strlen($data) < $dataLength) {
         return false;
     }
     $payload = '';
     if ($masked) {
         $i = $payloadOffset;
         while ($i < $dataLength) {
             $j = $i - $payloadOffset;
             if (isset($data[$i])) {
                 $payload .= $data[$i] ^ $mask[$j % 4];
             }
             $i++;
         }
     } else {
         $payloadOffset = $payloadOffset - 4;
         $payload = substr($data, $payloadOffset);
     }
     return $payload;
 }
示例#5
0
 /**
  * @param string $method
  * @param string $description
  *
  * @return null
  */
 private function _log($method, $description)
 {
     Quark::Log('SocialNetwork.' . $method . ' for ' . get_class($this->_config()->SocialNetwork()) . ' failed. ' . $description, Quark::LOG_WARN);
     return null;
 }
示例#6
0
 /**
  * @param string $method
  * @param string $url
  * @param array  $data
  * @param string $base = 'https://api.vk.com/method/'
  *
  * @return QuarkDTO|\StdClass
  */
 public function API($method = '', $url = '', $data = [], $base = 'https://api.vk.com/method/')
 {
     $request = new QuarkDTO(new QuarkFormIOProcessor());
     $request->Method($method);
     $get = $method == 'GET';
     if (!$get) {
         $request->Data($data);
     }
     $response = new QuarkDTO(new QuarkJSONIOProcessor());
     $out = QuarkHTTPTransportClient::To($base . $url . '?' . http_build_query(array_merge_recursive($get ? $data : array()) + array('access_token' => $this->_session)), $request, $response);
     if (isset($out->error)) {
         Quark::Log('VKontakte.Exception: ' . (isset($out->error->error_code) ? $out->error->error_code : '') . ': ' . (isset($out->error->error_msg) ? $out->error->error_msg : ''), Quark::LOG_WARN);
         Quark::Trace($out);
         return null;
     }
     return $out;
 }
示例#7
0
文件: Mail.php 项目: saivarunk/quark
 /**
  * @param QuarkClient $client
  *
  * @return mixed
  */
 public function Client(QuarkClient $client)
 {
     $conn = $client->Connect();
     if (!$conn) {
         Quark::Log('Mail. Unable to connect to mail server. Error: ' . $client->Error(true));
         return false;
     }
     $smtp = $this->_config->SMTP();
     $this->_dto->Header(QuarkDTO::HEADER_CONTENT_TRANSFER_ENCODING, QuarkDTO::TRANSFER_ENCODING_BASE64);
     try {
         $this->_cmd($client, 220);
         $this->_cmd($client, 250, 'HELO Quark');
         $this->_cmd($client, 334, 'AUTH LOGIN');
         $this->_cmd($client, 334, base64_encode($smtp->user));
         $this->_cmd($client, 235, base64_encode($smtp->pass));
         $this->_cmd($client, 250, 'MAIL FROM: <' . $smtp->user . '>');
         foreach ($this->_receivers as $receiver) {
             $this->_cmd($client, 250, 'RCPT TO: <' . $receiver . '>');
         }
         $this->_cmd($client, 354, 'DATA');
         $this->_cmd($client, 250, $this->_dto->SerializeResponseBody() . "\r\n.");
         $this->_cmd($client, 221, 'QUIT');
     } catch (QuarkArchException $e) {
         return false;
     }
     return $client->Close();
 }