public static function getProblemInfo($problemId)
 {
     // 新建一个curl
     $ch = new Curl();
     $url = 'http://poj.org/problem?id=' . $problemId;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 获取标题
     preg_match('/<div class="ptt" lang="en-US">(.*)<\\/div>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
     }
     // 获取来源
     preg_match('/<a href="searchproblem\\?field=source.*>(.*)<\\/a>/sU', $html, $matches);
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
     }
     $problemInfo['problem_id'] = $problemId;
     $problemInfo['problem_code'] = $problemId;
     return $problemInfo;
 }
 public static function getProblemInfo($problemId)
 {
     // 新建一个curl
     $ch = new Curl();
     $url = 'http://acm.hdu.edu.cn/showproblem.php?pid=' . $problemId;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 获取标题
     preg_match('/<td align=center><h1 style=\'color:#1A5CC8\'>(.*)<\\/h1>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
         $problemInfo['title'] = iconv('GBK', 'UTF-8', $problemInfo['title']);
     }
     // 获取来源
     preg_match('/>Source.*<a.*\\/search.php.*>(.*)<\\/a>/sU', $html, $matches);
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
         $problemInfo['source'] = iconv('GBK', 'UTF-8', $problemInfo['source']);
     }
     $problemInfo['problem_id'] = $problemId;
     $problemInfo['problem_code'] = $problemId;
     return $problemInfo;
 }
Example #3
0
 /**
  * Вызов метода ApiVK
  * @param $sMethod
  * @param $mParams
  * @return bool|mixed
  */
 private function CallMethod($sMethod, $mParams)
 {
     if (is_array($mParams)) {
         if (!isset($mParams['access_token'])) {
             if (!$this->sAccessToken) {
                 return false;
             }
             $mParams['access_token'] = $this->sAccessToken;
         }
         $oCurl = new Curl();
         $oCurl->SetUrl('https://api.vk.com/method/' . $sMethod);
         $oCurl->SetPostfields($mParams);
         $sResult = $oCurl->GetResponseBody(true);
     } else {
         $sParams = $mParams;
         if (!strpos($mParams, 'access_token')) {
             if (!$this->sAccessToken) {
                 return false;
             }
             $sParams = $mParams . '&access_token=' . $this->sAccessToken;
         }
         $oCurl = new Curl();
         $oCurl->SetUrl('https://api.vk.com/method/' . $sMethod . '?' . $sParams);
         $sResult = $oCurl->GetResponseBody(true);
     }
     if ($sResult === false) {
         throw new Exception($oCurl->Error());
     }
     $oCurl->close();
     return json_decode($sResult);
 }
Example #4
0
 function testCurlWrapperCanDoHttpQueries()
 {
     $curl = new Curl(self::TEST_VALID_URL);
     $curl->setopt(CURLOPT_PROXY, $this->proxy);
     $this->assertTrue($curl->setopt(CURLOPT_RETURNTRANSFER, 1));
     $this->assertTrue($curl->setopt_array(array(CURLOPT_TIMEOUT => self::CURL_TIMEOUT, CURLOPT_FOLLOWLOCATION => true)));
     $result = $curl->exec();
     $this->assertStringStartsWith('<!doctype html>', $result);
     $curl->close();
     $this->assertFalse($curl->hasHandle());
 }
Example #5
0
 public static function ip($ip)
 {
     $url = 'http://apis.baidu.com/rtbasia/ip_type/ip_type?ip=' . $ip;
     $curl = new Curl();
     $curl->setHeader("apikey", "29ddcb64dbe2f42764115b28941d2154");
     $curl->get($url);
     $curl->close();
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         return $curl->response;
     }
 }
 public static function getProblemInfo($problemCode)
 {
     // 新建一个curl
     $ch = new Curl();
     $url = 'http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=' . $problemCode;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 获取标题
     preg_match('/<span class="bigProblemTitle">(.*)<\\/span>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
     }
     // 获取来源
     preg_match('/Source:.*<strong>(.*)<\\/strong>/sU', $html, $matches);
     if (empty($matches[1])) {
         preg_match('/Contest:.*<strong>(.*)<\\/strong>/sU', $html, $matches);
     }
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
     }
     // 获取$problemId
     preg_match('/"\\/onlinejudge\\/submit.do\\?problemId=(\\d+)"/sU', $html, $matches);
     $problemInfo['problem_id'] = 0;
     if (!empty($matches[1])) {
         $problemInfo['problem_id'] = $matches[1];
     }
     $problemInfo['problem_code'] = $problemCode;
     $problemInfo['remote'] = StatusVars::REMOTE_ZOJ;
     return $problemInfo;
 }
Example #7
0
 /**
  * Sends single text message.
  *
  * @param string $number recipient's phone number
  * @param string $message the message
  * @param null $signature sender's signature
  * @param null $phoneback sender's phone number
  * @return bool
  * @throws SmsGatewayException
  */
 public function send($number, $message, $signature = null, $phoneback = null)
 {
     $curl = new Curl();
     // Step 2
     $responseStep2 = $curl->sendRequest(self::ENDPOINT . '?page=sendsms', array('phoneno' => $number, 'message' => $message, 'signature' => $signature, 'phoneback' => $phoneback, 'action' => 'verify', 'ads_check1' => 'js_off', 'ads_check2' => 'js_off'));
     $phpsessid = $curl->getHtmlProperty($responseStep2, 'PHPSESSID');
     // Step 3
     $curl->sendRequest(self::ENDPOINT, array('PHPSESSID' => $phpsessid, 'action' => 'confirmbyuser'));
     // Step 4
     $responseStep4 = $curl->sendRequest(self::ENDPOINT, array('operator' => 'donotknow', 'action' => 'confirmprovider'));
     $imagecode = $curl->getHtmlProperty($responseStep4, 'imgcode');
     // Step 5
     $curl->sendRequest(self::ENDPOINT . '?a=sent', array('imgcode' => $imagecode, 'action' => 'useraccepted'));
     $curl->close();
     return true;
 }
Example #8
0
<?php

include '../lib/Curl.php';
include '../lib/Curl/Share.php';
/**
 * curl_share_init() example
 *
 * http://php.net/manual/en/function.curl-share-init.php#refsect1-function.curl-share-init-examples
 */
// Create cURL share handle and set it to share cookie data
$sh = new Curl\Share();
$sh->setopt(CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
// Initialize the first cURL handle and assign the share handle to it
$ch1 = new Curl("http://example.com/");
$ch1->setopt(CURLOPT_SHARE, $sh);
// Execute the first cURL handle
$ch1->exec();
// Initialize the second cURL handle and assign the share handle to it
$ch2 = new Curl("http://php.net/");
$ch2->setopt(CURLOPT_SHARE, $sh);
// Execute the second cURL handle
//  all cookies from $ch1 handle are shared with $ch2 handle
$ch2->exec();
// Close the cURL share handle
$sh->close();
// Close the cURL handles
$ch1->close();
$ch2->close();
Example #9
0
 function curlNet2($method, $url, $param = array(), $ssl = FALSE)
 {
     require dirname(__FILE__) . '/ext/curl.php';
     $curl = new Curl();
     $exMethod = strtolower($method);
     if ($ssl == TRUE) {
         $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     }
     $curl->{$exMethod}($url, $param);
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
         $curl->close();
     } else {
         return $curl->response;
         $curl->close();
         unset($curl);
     }
 }
Example #10
0
 /**
  * 
  * @static
  * @param string $id
  * @return object|null
  */
 public static function item($id)
 {
     self::$_params = 'key=' . self::$_apiKey . '&id=' . $id;
     Curl::init();
     $jsonGet = Curl::get(self::$_apiUrl . '/item?' . self::$_params);
     Curl::close();
     if ($jsonGet) {
         $jsonData = json_decode($jsonGet);
         if (isset($jsonData->error)) {
             showError($jsonData->error, 'API Error', 500);
         } else {
             return $jsonData;
         }
     }
     return NULL;
 }
Example #11
0
 public function close()
 {
     $this->curl->close();
 }
Example #12
0
# limitations under the License.
*/
require_once dirname(__DIR__) . "/classes/Requires.php";
//Get settings
$result = MySQLQueries::get_settings();
$row = MySQLConnection::fetch_object($result);
$instance_key = null;
if (isset($row->data)) {
    $row->data = json_decode($row->data);
    if (isset($row->data->instance_key) && !empty($row->data->instance_key)) {
        $instance_key = $row->data->instance_key;
    } else {
        $instance_key = Functions::generate_random(9) . uniqid() . Functions::generate_random(8);
        $data = array("instance_key" => $instance_key, "default_ssh_username" => $row->data->default_ssh_username, "default_ssh_port" => $row->data->default_ssh_port, "default_interpreter" => $row->data->default_interpreter, "timezone_offset" => $row->data->timezone_offset, "timezone_daylight_savings" => $row->data->timezone_daylight_savings);
        MySQLQueries::edit_settings(json_encode((object) $data));
    }
} else {
    $instance_key = Functions::generate_random(9) . uniqid() . Functions::generate_random(8);
    $data = array("instance_key" => $instance_key);
    MySQLQueries::edit_settings(json_encode((object) $data));
}
$servers = array();
$result = MySQLQueries::get_servers();
while ($row = MySQLConnection::fetch_object($result)) {
    $servers[] = $row;
}
$payload = '{"event":"' . $instance_key . '","properties":{"token":"678f0669ff58d890eeb50633c91a633d","distinct_id":"' . $instance_key . '","ip":"' . Functions::get_remote_ip() . '","servers":"' . count($servers) . '","version":"' . Version::app . '","ip-address":"' . Functions::get_remote_ip() . '","mp_name_tag":"' . $instance_key . '","time":"' . time() . '"}}';
$curl = new Curl();
$curl->get_request("https://api.mixpanel.com/track/?data=" . base64_encode($payload));
$curl->close();
echo '{"instance_key":"' . $instance_key . '"}';
Example #13
0
 public function close()
 {
     parent::close();
     $this->unsetClassVars();
 }
Example #14
0
<?php

include '../lib/Curl.php';
/**
 * curl_init() example
 *
 * http://php.net/manual/en/function.curl-init.php#refsect1-function.curl-init-examples
 */
// create a new cURL resource
$ch = new Curl();
// set URL and other appropriate options
$ch->setopt(CURLOPT_URL, "http://www.example.com/");
$ch->setopt(CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$ch->exec();
// close cURL resource, and free up system resources
$ch->close();