예제 #1
0
 public function pingUrl()
 {
     if (!utils::keysOk($this->data, ['url', 'title'])) {
         return $this->response('ERROR', 'required keys not set');
     }
     $url = $this->data['url'];
     if (!utils::validUrl($url)) {
         return $this->response('ERROR', 'invalid url');
     }
     $title = $this->data['title'];
     main::loadLibs(['httpRequest/httpRequest.class.php']);
     $pingomaticUrl = 'http://pingomatic.com/ping/' . '?title=' . urlencode($title) . '&blogurl=' . urlencode($url) . '&rssurl=' . '&chk_weblogscom=on' . '&chk_blogs=on' . '&chk_feedburner=on' . '&chk_newsgator=on' . '&chk_myyahoo=on' . '&chk_pubsubcom=on' . '&chk_blogdigger=on' . '&chk_weblogalot=on' . '&chk_newsisfree=on' . '&chk_topicexchange=on' . '&chk_google=on' . '&chk_tailrank=on' . '&chk_skygrid=on' . '&chk_collecta=on' . '&chk_superfeedr=on' . '&chk_audioweblogs=on' . '&chk_rubhub=on' . '&chk_a2b=on' . '&chk_blogshares=on';
     $request = new httpRequest($pingomaticUrl);
     $request->setRandUserAgent();
     if (array_key_exists('proxy', $this->data)) {
         try {
             $request->setProxy($this->data['proxy']);
         } catch (Exception $e) {
             return $this->response('ERROR', $e->getMessage());
         }
     }
     $request = $request->exec();
     if (!$request['status'] == 'OK') {
         return $this->response('ERROR', $request['message']);
     }
     if (strrpos($request['data'], 'Pinging complete!') === false) {
         return $this->response('ERROR', 'pingomatic failed to ping ' . $url);
     }
     return $this->response('OK', 'successfully pinged ' . $url);
 }
function post_data($url, $xml_string)
{
    $url = $url;
    $theData = $xml_string;
    //
    $credentials = 'user@example.com:password';
    $header_array = array('Expect' => '', 'From' => 'User A');
    $options = array(headers => $header_array, httpauthtype => HTTP_AUTH_BASIC, protocol => HTTP_VERSION_1_1);
    //create the httprequest object
    $httpRequest_OBJ = new httpRequest($url, HTTP_METH_GET, $options);
    //add the content type
    $httpRequest_OBJ->setContentType = 'Content-Type: text/xml';
    //add the raw post data
    $httpRequest_OBJ->setBody($theData);
    //
    try {
        //send the http request
        $result = $httpRequest_OBJ->send()->getBody();
        $resp_code = $httpRequest_OBJ->getResponseCode();
        //print_r($result);
        if ($resp_code == 200) {
            return $result;
        }
        //return $result;
    } catch (HttpException $ex) {
        echo $error;
    }
}
예제 #3
0
function doRequest($url)
{
    $request = new httpRequest(wm_server_address);
    $request->setUserAgent('websiteMasterClient.php');
    $request->setTimeout(wm_server_timeout);
    $postData = json_encode(['act' => 'render', 'data' => ['url' => $url]]);
    $request->setPOST($postData);
    $request = $request->exec();
    if ($request['status'] != 'OK') {
        return [false, $request['message'], true];
    }
    $reqData = json_decode($request['data'], true);
    if (!$reqData) {
        return [false, 'Invalid response data', false];
    }
    if ($reqData['status'] != 'OK') {
        return [false, $reqData['message'], false];
    }
    $contentType = $reqData['content_type'];
    $content = $reqData['data'];
    return [true, [$contentType, $content], false];
}
예제 #4
0
 /**
  * I've chosen to go with the HTTP PUT method as it is quicker, simpler
  * and more reliable than using the API or POST methods.
  * 
  * @access	public
  * @param	integer		$AlbumID The AlbumID the image is to be uploaded to
  * @param	string		$File The path to the local file that is being uploaded
  * @param	string		$FileName (Optional) The filename to give the file
  *						on upload
  * @param	mixed		$arguments (Optional) Additional arguments. See
  *						SmugMug API documentation.
  * @uses	request
  * @link	http://wiki.smugmug.net/display/API/Uploading
  * @return	array|false
  * @todo Add support for multiple asynchronous uploads
  **/
 public function images_upload()
 {
     $args = phpSmug::processArgs(func_get_args());
     if (!array_key_exists('File', $args)) {
         throw new PhpSmugException('No upload file specified.');
     }
     // Set FileName, if one isn't provided in the method call
     if (!array_key_exists('FileName', $args)) {
         $args['FileName'] = basename($args['File']);
     }
     // Ensure the FileName is phpSmug::urlencodeRFC3986 encoded - caters for stange chars and spaces
     $args['FileName'] = phpSmug::urlencodeRFC3986($args['FileName']);
     // OAuth Stuff
     if ($this->OAuthSecret) {
         $sig = $this->generate_signature('Upload', array('FileName' => $args['FileName']));
     }
     if (is_file($args['File'])) {
         $fp = fopen($args['File'], 'r');
         $data = fread($fp, filesize($args['File']));
         fclose($fp);
     } else {
         throw new PhpSmugException("File doesn't exist: {$args['File']}");
     }
     // Create a new object as we still need the other request object
     $upload_req = new httpRequest();
     $upload_req->setMethod('PUT');
     $upload_req->setConfig(array('follow_redirects' => TRUE, 'max_redirects' => 3, 'ssl_verify_peer' => FALSE, 'ssl_verify_host' => FALSE, 'connect_timeout' => 60));
     $upload_req->setAdapter($this->adapter);
     // Set the proxy if one has been set earlier
     if (isset($this->proxy) && is_array($this->proxy)) {
         $upload_req->setConfig(array('proxy_host' => $this->proxy['server'], 'proxy_port' => $this->proxy['port'], 'proxy_user' => $this->proxy['user'], 'proxy_password' => $this->proxy['password']));
     }
     $upload_req->setHeader(array('User-Agent' => "{$this->AppName} using phpSmug/" . phpSmug::$version, 'Content-MD5' => md5_file($args['File']), 'Connection' => 'keep-alive'));
     if ($this->loginType == 'authd') {
         $upload_req->setHeader('X-Smug-SessionID', $this->SessionID);
     } else {
         $upload_req->setHeader('Authorization', 'OAuth realm="http://api.smugmug.com/",' . 'oauth_consumer_key="' . $this->APIKey . '",' . 'oauth_token="' . $this->oauth_token . '",' . 'oauth_signature_method="' . $this->oauth_signature_method . '",' . 'oauth_signature="' . urlencode($sig) . '",' . 'oauth_timestamp="' . $this->oauth_timestamp . '",' . 'oauth_version="1.0",' . 'oauth_nonce="' . $this->oauth_nonce . '"');
     }
     $upload_req->setHeader(array('X-Smug-Version' => $this->APIVer, 'X-Smug-ResponseType' => 'PHP', 'X-Smug-AlbumID' => $args['AlbumID'], 'X-Smug-Filename' => basename($args['FileName'])));
     // This is actually optional, but we may as well use what we're given
     /* Optional Headers */
     foreach ($args as $arg => $value) {
         if ($arg == 'File') {
             continue;
         }
         $upload_req->setHeader('X-Smug-' . $arg, $value);
     }
     //$proto = ( $this->oauth_signature_method == 'PLAINTEXT' || $this->secure ) ? 'https' : 'http';	// No secure uploads at this time.
     //$upload_req->setURL( $proto . '://upload.smugmug.com/'.$args['FileName'] );
     $upload_req->setURL('http://upload.smugmug.com/' . $args['FileName']);
     $upload_req->setBody($data);
     //Send Requests
     $upload_req->execute();
     $this->response = $upload_req->getBody();
     // For some reason the return string is formatted with \n and extra space chars.  Remove these.
     $replace = array('\\n', '\\t', '  ');
     $this->response = str_replace($replace, '', $this->response);
     $this->parsed_response = unserialize(trim($this->response));
     if ($this->parsed_response['stat'] == 'fail') {
         $this->error_code = $this->parsed_response['code'];
         $this->error_msg = $this->parsed_response['message'];
         $this->parsed_response = FALSE;
         throw new PhpSmugException("SmugMug API Error for method image_upload: {$this->error_msg}", $this->error_code);
     } else {
         $this->error_code = FALSE;
         $this->error_msg = FALSE;
     }
     return $this->parsed_response ? $this->parsed_response['Image'] : FALSE;
 }
예제 #5
0
 /**
  * upload a ProfileImage
  * @param \Profile\Form\UploadForm $form
  * @param httpRequest $request
  * @param file $file file to upload
  * @return boolean
  */
 public function upload($form, $request, $file)
 {
     $filter = new UploadFilter();
     $form->setInputFilter($filter->getInputFilter());
     $nonFile = $request->getPost()->toArray();
     $data = array_merge($nonFile, array('fileupload' => $file['name']));
     $form->setData($data);
     if ($form->isValid()) {
         $options = $this->getOptions();
         $size = new Size(array('min' => '5kB', 'max' => '1.5MB'));
         $type = new Extension($options['profileImage']);
         $adapter = new \Zend\File\Transfer\Adapter\Http();
         $adapter->setValidators(array($size, $type), $file['name']);
         if (!$adapter->isValid() || file_exists('public/images/profile_uploads/' . $file['name'])) {
             return false;
         } else {
             $adapter->setDestination('public/images/profile_uploads');
             if ($adapter->receive($file['name'])) {
                 $filter->exchangeArray($form->getData());
                 $user = $this->getUserById($this->getIdentity()->getUserId());
                 $entity = $this->getUserMapper()->findUserDataById($user->getUserid());
                 if ($entity == null) {
                     $entity = new UserData();
                     $entity->setUser($user);
                 }
                 $entity->setPicture('/images/profile_uploads/' . $file['name']);
                 $this->getUserMapper()->saveData($entity);
                 return true;
             }
         }
     }
 }
 public function saveProdutoFornecedores($arr, $id_item_referencia)
 {
     $r = httpRequest::get(array('url' => $this->ps_shop_path . 'api/produto_fornecedores/' . $id_item_referencia, 'CURLOPT_USERPWD' => $this->ps_shop_path));
     if ($r->info['http_code'] != 200) {
         return false;
     }
     $suppliers = $r->response;
     foreach ($arr as $value) {
         $find = findINObj('id_supplier', $value, $suppliers);
         if ($find == false) {
             $xml = $this->webService->get(array('url' => $this->ps_shop_path . '/api/product_suppliers?schema=blank'));
             $resources = $xml->children()->children();
             $resources->id_product = $id_item_referencia;
             $resources->id_supplier = $value;
             $resources->id_product_attribute = 0;
             try {
                 $opt = array('resource' => 'product_suppliers');
                 $opt['postXml'] = $xml->asXML();
                 $xml = $this->webService->add($opt);
             } catch (PrestaShopWebserviceException $e) {
                 return json_encode(array('status' => false, 'id_fornecedor' => $value, 'errors' => $this->webService->response->errors));
             }
         }
     }
     foreach ($suppliers as $value) {
         if (!in_array($value->id_supplier, $arr)) {
             try {
                 $opt = array('resource' => 'product_suppliers');
                 $opt['id'] = $value->id_product_supplier;
                 $xml = $this->webService->delete($opt);
             } catch (PrestaShopWebserviceException $e) {
                 return json_encode(array('status' => false, 'id_fornecedor' => $value, 'errors' => $this->webService->response->errors));
             }
         }
     }
 }
예제 #7
0
<?php

$ind = 1;
foreach ($_POST as $key => $value) {
    $matrx[$key] = $value;
    $ind++;
}
$rparams = json_encode($matrx);
$url = 'http://127.0.0.1:8888';
$header_array = array('Content-Type' => 'application/json', 'Content-Length' => strlen($rparams), 'Transfer-encoding' => 'chunked');
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST);
$httpRequest_OBJ->setHeaders = $header_array;
$httpRequest_OBJ->setContentType = 'Content-Type: application/json';
$httpRequest_OBJ->setBody($rparams);
//send the http request
$result = $httpRequest_OBJ->send();
//print out the result
echo $httpRequest_OBJ->getResponseBody();