Example #1
0
 /**
  * @return Settings
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         $settings = new Settings();
         $settings->setPlugin(self::PLUGIN_PATH);
         $settings->setSSL(false);
         $settings->setDebug(false);
         self::$instance = $settings;
     }
     return self::$instance;
 }
 /**
  * @param $url
  * @param $headers
  * @param $method
  * @param $postData
  * @return bool|mixed
  */
 private static function execute_curl($url, $headers, $method, $postData)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_FAILONERROR, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($ch, CURLOPT_URL, $url);
     if (!empty($postData)) {
         curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
     }
     $server_output = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     $response = false;
     if ($info['http_code'] == 200 || $info['http_code'] == 201) {
         $response = true;
     }
     $settings = Settings::getInstance();
     if ($settings->isDebug()) {
         $debugger = Debugger::getInstance();
         $debugger->recordRequest($url, $headers, $method, $postData, $response, $server_output);
         $debugger->recordCurlInfo($info);
     }
     return array('response' => $response, 'output' => json_decode($server_output));
 }
 /**
  * Returns always the correct jid
  * @param $jid
  */
 public function setJid($jid)
 {
     $settings = Settings::getInstance();
     $server_name = $settings->getServerName();
     if (strpos('@' . $server_name, $jid) === false) {
         $jid .= '@' . $server_name;
     }
     $this->jid = $jid;
 }