Plugin Directory

Changeset 2666322


Ignore:
Timestamp:
01/26/2022 07:57:56 PM (4 years ago)
Author:
globalprogramming
Message:

Wp remote request testing - pre-release

Location:
whmcs-bridge/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • whmcs-bridge/trunk/includes/request.class.php

    r2659751 r2666322  
    116116            }
    117117        }
    118         if ($mime) return ';type='.$mime;
     118        if ($mime) return $mime;
    119119        else return '';
    120120    }
     
    188188        $apost = [];
    189189        if (count($this->post) > 0) {
    190             $this->debug(0, "HTTP POST 2");
    191190            $post = "";
    192191            $apost = array();
     
    222221        global $wordpressPageName;
    223222
    224         $newfiles=array();
     223        $newfiles = array();
    225224
    226225        $url = str_replace('?m=DNSManagerII', '?m=DNSManager2', $url);
     
    284283        $_SESSION['cookieCach'] = $cookies;
    285284
    286         /*if (count($_FILES) > 0) {
     285        if (count($_FILES) > 0) {
    287286            foreach ($_FILES as $name => $file) {
    288287                if (is_array($file['tmp_name']) && count($file['tmp_name']) > 0) {
     
    291290                        if ($file['tmp_name'][$i]) {
    292291                            $newfile = BLOGUPLOADDIR. $file['name'][$i];
    293                             $newfiles[] = $newfile;
    294292                            copy($file['tmp_name'][$i], $newfile);
    295293                            if (!file_exists($newfile)) {
    296                                 cc_whmcs_log('Cant copy '.$file['tmp_name'][$i].' to '.$newfile);
     294                                $this->debug(0, 'Cant copy '.$file['tmp_name'][$i].' to '.$newfile);
    297295                            } else {
    298                                 if (PHP_VERSION_ID >= 50500) {
    299                                     $this->post[$name][$i] = new CurlFile($newfile, str_replace(';', '', $this->mimeType($newfile)), $newfile);
    300                                 } else {
    301                                     if ($file['tmp_name'][$i]) $this->post[$name][$i] = '@' . $newfile . $this->mimeType($newfile);
    302                                 }
     296                                $newfiles[] = [
     297                                    'file' => $newfile,
     298                                    'name' => $name.'['.$i.']'
     299                                ];
    303300                            }
    304301                        }
     
    306303                } elseif ($file['tmp_name']) {
    307304                    $newfile = BLOGUPLOADDIR. $file['name'];
    308                     $newfiles[] = $newfile;
    309305                    copy($file['tmp_name'], $newfile);
    310306                    if (!file_exists($newfile)) {
    311                         cc_whmcs_log('Cant copy '.$file['tmp_name'][$i].' to '.$newfile);
     307                        $this->debug(0, 'Cant copy '.$file['tmp_name'][$i].' to '.$newfile);
    312308                    } else {
    313                         if (PHP_VERSION_ID >= 50500 && class_exists('CurlFile')) {
    314                             $this->post[$name] = new CurlFile($newfile, str_replace(';', '', $this->mimeType($newfile)), $newfile);
    315                         } else {
    316                             if ($file['tmp_name']) $this->post[$name] = '@' . $newfile . $this->mimeType($newfile);
    317                         }
     309                        $newfiles[] = [
     310                            'file' => $newfile,
     311                            'name' => $name
     312                        ];
    318313                    }
    319314                }
    320315            }
    321             cc_whmcs_log(0, 'There are files:  '.json_encode($newfiles));
    322         }*/
     316            $this->debug(0, 'There are files:  '.json_encode($newfiles));
     317        }
    323318
    324319        $rawPost = file_get_contents('php://input');
     320
    325321        if (!empty($rawPost))
    326             $this->debug(0, "RAW data: ".$rawPost);
     322            $this->debug(0, "Raw data: ".$rawPost);
    327323
    328324        $apost = $this->generatePostArray();
    329325
    330         if (!empty($apost)) {
     326        $this->debug(0, "Post data: ".print_r($apost, true));
     327
     328        if (!empty($newfiles)) {
     329            $http_args['method'] = 'POST';
     330            $boundary = substr(md5(time()), -24);
     331            $http_args['headers']['content-type'] = 'multipart/form-data; boundary='.$boundary;
     332            $http_args['body'] = '';
     333
     334            if (!empty($apost)) {
     335                foreach ($apost as $k => $v) {
     336                    $http_args['body'] .= '--'.$boundary;
     337                    $http_args['body'] .= "\r\n";
     338                    $http_args['body'] .= 'content-disposition: form-data; name="' . $k .
     339                        '"' . "\r\n\r\n";
     340                    $http_args['body'] .= $v;
     341                    $http_args['body'] .= "\r\n";
     342                }
     343            }
     344
     345            foreach ($newfiles as $file) {
     346                $http_args['body'] .= '--' . $boundary;
     347                $http_args['body'] .= "\r\n";
     348                $http_args['body'] .= 'content-disposition: form-data; name="' . $file['name'] .
     349                    '"; filename="' . basename( $file['file'] ) . '"' . "\r\n";
     350                $http_args['body'] .= 'content-type: '. $this->mimeType($file['file']) . "\r\n";
     351                $http_args['body'] .= "\r\n";
     352                $http_args['body'] .= file_get_contents( $file['file'] );
     353                $http_args['body'] .= "\r\n";
     354            }
     355            $http_args['body'] .= '--' . $boundary . '--';
     356
     357            $this->debug(0, 'Posting with file attachment '.json_encode($newfiles));
     358
     359        } else if (!empty($apost)) {
    331360            $http_args['method'] = 'POST';
    332361
     
    336365            }
    337366
    338             if (count($newfiles) > 0) {
    339                 $this->debug(0, 'Posting as [0]:  ' . json_encode($apost));
    340 
    341                 $http_args['body'] = $apost;
    342             } else {
    343                 $pfields = $this->makeQueryString($apost);
    344                 $this->debug(0, 'Posting as [1]:  ' . json_encode($pfields));
    345 
    346                 $http_args['body'] = $pfields;
    347             }
    348 
     367            $pfields = $this->makeQueryString($apost);
     368            $this->debug(0, 'Posting as:  ' . json_encode($pfields));
     369
     370            $http_args['body'] = $pfields;
    349371        } else if (!empty($rawPost)) {
    350372            $http_args['method'] = 'POST';
     
    377399        }
    378400
    379         $this->debug(0, "Posting to {$url} with: ".json_encode($http_args));
     401        $this->debug(0, "Posting to {$url} with headers: ".json_encode($http_args['headers']));
    380402
    381403        $data = wp_remote_request($url, $http_args);
  • whmcs-bridge/trunk/readme.txt

    r2653261 r2666322  
    44Tags: WHMCS, hosting, support, billing, integration
    55Requires at least: 5.0
    6 Tested up to: 5.8.2
     6Tested up to: 5.9
    77Stable tag: 6.4
    88License: GPLv3
     
    8080= 6.4 =
    8181* Core updates
     82* Implementation of WP HTTP API
     83* Implementation of WP content wrappers
    8284
    8385= 6.3 =
Note: See TracChangeset for help on using the changeset viewer.