/**
  * Adds the WordPress hook during construction.
  *
  * @param \Herbert\Framework\Application $app
  * @param \Herbert\Framework\Http        $http
  */
 public function __construct(Application $app, Http $http)
 {
     $this->app = $app;
     $this->http = $http;
     if (!is_admin()) {
         return;
     }
     add_action('admin_menu', [$this, 'boot']);
     $http->setMethod($http->get('_method'), $old = $http->method());
     if (!in_array($http->method(), self::$methods)) {
         $http->setMethod($old);
     }
     if ($http->method() !== 'GET') {
         add_action('init', [$this, 'bootEarly']);
     }
 }
Exemplo n.º 2
0
<?php

// Include the Http Class
include_once 'class.http.php';
// Instantiate it
$http = new Http();
// Let's not use cURL
$http->useCurl(false);
// POST method
$http->setMethod('POST');
// POST parameters
$http->addParam('user_name', 'yourusername');
$http->addParam('password', 'yourpassword');
// Referrer
$http->setReferrer('https://yourproject.projectpath.com/login');
// Get basecamp dashboard (HTTPS)
$http->execute('https://yourproject.projectpath.com/login/authenticate');
// Show result page or error if occurred
echo $http->error ? $http->error : $http->result;
Exemplo n.º 3
0
 /**
  * @param $url              string      Url a la cual se generara la peticion
  * @param $auth             string      Cadena de autentificacion
  * @param $data             string      Parametros a enviar
  * @param array  $headers               Arreglo de headers http
  * @return mixed
  * @throws \Exception
  */
 public static function delete($url, $auth, $data = null, $headers = array())
 {
     $ch = Http::initHttp($url);
     Http::setMethod($ch, 'DELETE');
     Http::setAuth($ch, $auth);
     if (!empty($data)) {
         Http::setPostFields($ch, $data);
     }
     Http::setHeaders($ch, $headers);
     $response = Http::execHttp($ch);
     if (empty($response)) {
         throw new \Exception("Respuesta vacia");
     } else {
         return $response;
     }
 }
Exemplo n.º 4
0
 function request($url = "", $method = "GET", $params = NULL)
 {
     //#4 FIX: Don't use token on PLAINTEXT signature
     $token = $this->signature instanceof OAuthSignatureMethod_PLAINTEXT ? NULL : $this->token;
     $request = OAuthRequest::from_consumer_and_token($this->consumer, $token, $method, $url, $params);
     $request->sign_request($this->signature, $this->consumer, $token);
     $http = new Http();
     $http->setMethod($method);
     switch ($method) {
         case 'GET':
             $url = $request->to_url();
             break;
         default:
             parse_str($request->to_postdata(), $params);
             $http->setParams($params);
             $url = $request->get_normalized_http_url();
             break;
     }
     $http->execute($url);
     return $http->error ? die($http->error) : $http->result;
 }
Exemplo n.º 5
0
function api_trafficrequest_cb($id, $type)
{
    if (getconfig_var('allow_statistical_info') != 1) {
        return true;
    }
    // Include the Http Class
    require_once MAD_PATH . '/modules/http/class.http.php';
    // Instantiate it
    $http = new Http();
    $http->setMethod('GET');
    $http->addParam('install_id', getconfig_var('installation_id'));
    $http->addParam('requestid', get_actual_tr_id($id));
    $http->addParam('status', $type);
    $http->execute('http://network.madserve.org/request_accept.php');
    if ($http->error) {
        return false;
    }
    return true;
}
Exemplo n.º 6
0
 function compileJS($scripts)
 {
     // make this a config option?
     $baseUrl = "assets/js/";
     $http = new Http();
     $http->setMethod('GET');
     // sort results
     //ksort_recursive( $minify );
     // record signature
     //$md5 = "";
     $cache_path = $this->_getCacheDir() . "{$baseUrl}";
     // FIX: create the dir if not available
     if (!is_dir($cache_path)) {
         mkdir($cache_path, 0775, true);
     }
     // process each group
     foreach ($scripts as $name => $group) {
         $first = current($group);
         $result = "";
         $timestamp = 0;
         // go to next group if minify flag is not true
         if (!$first["data"]['minify']) {
             continue;
         }
         $min = new UglifyJS();
         $min->cacheDir($cache_path);
         $min->compiler($GLOBALS['config']['admin']['uglify_service']);
         // get the encoding from the first member of the group
         $encode = $first["data"]["encode"];
         // loop through the group and add the files
         foreach ($group as $script) {
             // the move the domain from the script (if available)
             // check if it's a local url
             $href = $script["src"];
             $local = substr($href, 0, 4) !== "http" || substr($href, 0, 2) !== "//";
             if ($local) {
                 $href = url($href);
             }
             $result .= $http->execute($href);
             // get modified time
             $mtime = urlmtime($href);
             // compare with newest file in the group
             if ($timestamp < $mtime) {
                 $timestamp = $mtime;
             }
             //$src = str_replace( array(url(), cdn() ),"", $script["src"] );
             // remove leading slash
             //$src = ltrim($src,'/');
             //$md5 .= md5_file($file);
         }
         // compress signatures of all files
         $md5 = md5($result);
         // set timestamp
         $min->timestamp($timestamp);
         //contents of each group are saved in a tmp file
         $tmp_file = $cache_path . "tmp.{$md5}.js";
         file_put_contents($tmp_file, $result);
         // add tmp file
         $min->add($tmp_file);
         //$min->setFile( "$name.$md5.min" );
         $min->setFile("{$name}");
         if (!DEBUG) {
             $min->quiet()->hideDebugInfo();
         }
         // condition the method of minification here...
         switch ($encode) {
             case "whitespace":
                 $min->whitespaceOnly();
                 break;
             case "simple":
                 $min->simpleMode();
                 break;
             case "advanced":
                 $min->advancedMode();
                 break;
             default:
                 $min->simpleMode();
                 break;
         }
         $min->write();
         $min->clear();
         // add the signature in the group
         //$scripts[$name][]["data"]["md5"] = $md5;
     }
     return $scripts;
 }