Пример #1
0
 /**
  * @param IQuarkRESTServiceDescriptor $descriptor
  * @param string $endpoint
  * @param string $source
  */
 public function __construct(IQuarkRESTServiceDescriptor $descriptor = null, $endpoint = '', $source = '')
 {
     if (func_num_args() == 1) {
         $endpoint = Quark::WebHost();
     }
     if (strlen(trim($source)) == 0) {
         $source = QuarkObject::ClassOf($descriptor);
     }
     $this->_descriptor = $descriptor;
     $this->_endpoint = $endpoint;
     $this->_source = $source;
 }
Пример #2
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;
 }
Пример #3
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;
     }
 }
Пример #4
0
 /**
  * @param string $config
  * @param IQuarkPaymentScenario $scenario
  */
 public function __construct($config, IQuarkPaymentScenario $scenario)
 {
     $this->_config = Quark::Config()->Extension($config);
     $this->_scenario = $scenario;
 }
Пример #5
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;
 }
Пример #6
0
 /**
  * @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;
 }
Пример #7
0
 /**
  * @param $criteria
  * @param int $lifetime (seconds)
  *
  * @return bool
  */
 public function Login($criteria, $lifetime)
 {
     $sid = (bool) $this->_sid;
     $storage = self::_storage($this->_name, $this->_sid);
     $this->_sid = Quark::GuID();
     $this->_signature = Quark::GuID();
     $this->_ttl = $lifetime;
     $old = $storage->Location();
     $storage->Location($storage->parent . '/' . $this->_name . '-' . $this->_sid . '.sid');
     $new = $storage->Location();
     if ($sid) {
         rename($old, $new);
     }
     $storage->Content(json_encode(array('user' => $this->_user->Extract(), 'signature' => $this->_signature, 'ttl' => $this->_ttl)));
     $storage->SaveContent();
     return $this->_end($lifetime);
 }
Пример #8
0
 /**
  * @return string
  */
 public function HTML()
 {
     return '<style type="text/css">@font-face {src: url(' . Quark::NormalizePath(str_replace(Quark::Host(), '', Quark::NormalizePath($this->_font, false)), false) . ');font-family: ' . $this->_family . ';}</style>';
 }
Пример #9
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;
 }
Пример #10
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;
 }
Пример #11
0
 /**
  * @param $location
  * @param $name
  * @param $extension
  * @param $isDir
  *
  * @return array
  */
 private static function _file($location, $name, $extension, $isDir)
 {
     $location = Quark::NormalizePath($location, false);
     return array(self::FIRST_LOCATION => $location, self::LOCATION => $location, self::NAME => $name, self::EXTENSION => $extension, self::IS_DIR => $isDir, self::SIZE => $isDir ? '' : filesize($location), self::PARENT => str_replace($name, '', $location));
 }
Пример #12
0
 /**
  * @param $config
  *
  * @return OpenGraphResource
  */
 public function App($config)
 {
     return $this->Property(self::PROPERTY_FB_APP_ID, Quark::Config()->Extension($config)->appId);
 }
Пример #13
0
 /**
  * @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();
 }
Пример #14
0
 /**
  * @param string $config
  * @param string $message
  * @param array $phones
  */
 public function __construct($config, $message = '', $phones = [])
 {
     $this->Message($message);
     $this->Phones($phones);
     $this->_config = Quark::Config()->Extension($config);
 }