Ejemplo n.º 1
0
 /**
  * @Route("/admin/plugins/getPackagesFromPackagist")
  */
 public function searchOnPackagistAction(Request $request)
 {
     $response = new JsonResponse();
     $query = $request->get('q', '');
     $client = new \Buzz\Client\Curl();
     $client->setTimeout(3600);
     $browser = new \Buzz\Browser($client);
     $packagistResponse = $browser->get('https://packagist.org/search.json?type=newscoop-plugin&q=' . $query);
     $packages = json_decode($packagistResponse->getContent(), true);
     $results = $packages['results'];
     $this->aasort($results, 'downloads');
     // hide already installed plugins
     $cleanResults = array();
     $pluginService = $this->container->get('newscoop.plugins.service');
     foreach ($results as $resultKey => $package) {
         $installed = false;
         foreach ($pluginService->getAllAvailablePlugins() as $key => $plugin) {
             if ($package['name'] == $plugin->getName()) {
                 $installed = true;
                 $packages['total'] = $packages['total'] - 1;
             }
         }
         if (!$installed) {
             $cleanResults[] = $package;
         }
     }
     $packages['results'] = $cleanResults;
     return $response->setData($packages);
 }
Ejemplo n.º 2
0
 private function addCommonServices(array &$services)
 {
     $services['browser'] = function () {
         if (function_exists('curl_version')) {
             $client = new \Buzz\Client\Curl();
             $client->setTimeout(120);
         } else {
             $client = new \Buzz\Client\FileGetContents();
         }
         $browser = new \Buzz\Browser($client);
         return $browser;
     };
     $services['request.classes.http'] = function () {
         return new \YumlPhp\Request\Http\ClassesRequest();
     };
     $services['request.classes.console'] = function () {
         return new \YumlPhp\Request\Console\ClassesRequest();
     };
     $services['request.file.http'] = function () {
         return new \YumlPhp\Request\Http\FileRequest();
     };
     $services['request.file.console'] = function () {
         return new \YumlPhp\Request\Console\FileRequest();
     };
 }
Ejemplo n.º 3
0
 /**
  * Configures the adapter for authentication against the RoboWhois API. 
  */
 protected function getDefaultAdapter()
 {
     $adapter = new Browser();
     $client = new \Buzz\Client\Curl();
     $client->setTimeout(5);
     $adapter->setClient($client);
     return $adapter;
 }
Ejemplo n.º 4
0
 /**
  * Constructor
  * @param string $sBaseUrl
  * @param \Buzz\Client\ClientInterface $oHttpClient
  */
 public function __construct($sBaseUrl = null, \Buzz\Client\ClientInterface $oHttpClient = null)
 {
     if ($sBaseUrl) {
         $this->setBaseUrl($sBaseUrl);
     }
     if (!$oHttpClient) {
         $oHttpClient = new \Buzz\Client\Curl();
     }
     $oHttpClient->setTimeout($this->getOptions('timeout'));
     $oHttpClient->setVerifyPeer(false);
     $this->setHttpClient(new \GitlabCI\HttpClient\HttpClient($this->getBaseUrl(), $this->options, $oHttpClient));
 }
Ejemplo n.º 5
0
 public function setup()
 {
     $browser = new \Buzz\Browser();
     $curl = new \Buzz\Client\Curl();
     $curl->setOption(CURLOPT_USERAGENT, "WoeidFinder/0.1");
     $browser->setClient($curl);
     $nomatimAdapter = new \Famex\WoeidFinder\Adapters\NomatimAdapter();
     $nomatimAdapter->setBrowser($browser);
     $yqlQueryAdapter = new \Famex\WoeidFinder\Adapters\YqlQueryAdapter();
     $yqlQueryAdapter->setBrowser($browser);
     $this->woeidFinder = new \Famex\WoeidFinder\WoeidFinder();
     $this->woeidFinder->setNomatimAdapter($nomatimAdapter);
     $this->woeidFinder->setYqlQueryAdapter($yqlQueryAdapter);
 }
Ejemplo n.º 6
0
 protected function getCurlClient()
 {
     $client = new \Buzz\Client\Curl();
     $client->setTimeout(5);
     $client->setVerifyPeer(false);
     $client->setMaxRedirects(0);
     $client->setOption(\CURLOPT_CONNECTTIMEOUT, 3);
     $client->setOption(\CURLOPT_USERAGENT, "baidu-apiclient-php-2.0");
     $client->setOption(\CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1);
     $client->setOption(\CURLOPT_POST, false);
     return $client;
 }
Ejemplo n.º 7
0
function sendRoomNotification($room, $msg)
{
    LogMe("Sending message to room {$room}: {$msg}");
    $auth = new GorkaLaucirica\HipchatAPIv2Client\Auth\OAuth2(getAuth($room));
    $browserclient = new Buzz\Client\Curl();
    $browserclient->setVerifyPeer(false);
    $browser = new Buzz\Browser($browserclient);
    $client = new GorkaLaucirica\HipchatAPIv2Client\Client($auth, $browser);
    $message = new \GorkaLaucirica\HipchatAPIv2Client\Model\Message();
    $message->setMessage($msg['msg']);
    $message->setMessageFormat('text');
    if (isset($msg['color'])) {
        $message->setColor($msg['color']);
    }
    $x = new GorkaLaucirica\HipchatAPIv2Client\API\RoomAPI($client);
    $ret = $x->sendRoomNotification($room, $message);
    LogMe(print_r($ret, true));
}
 /**
  * Send request to refresh article cache on Facebook
  *
  * @param int $number
  * @param int $languageId
  *
  * @return mixed response from Facebook about url, or array with error message
  */
 private function clearpageCache($number, $languageId)
 {
     $article = new \Article($languageId, $number);
     if (!$article->isPublished()) {
         return array('message' => $this->get('translator')->trans('fb.label.errornot'));
     }
     $url = \ShortURL::GetURL($article->getPublicationId(), $article->getLanguageId(), $article->getIssueNumber(), $article->getSectionNumber(), $article->getArticleNumber());
     try {
         $curlClient = new \Buzz\Client\Curl();
         $curlClient->setTimeout(10000);
         $browser = new \Buzz\Browser($curlClient);
         $result = $browser->post('https://graph.facebook.com/?id=' . $url . '&scrape=true');
         $urlInfo = json_decode($result->getContent(), true);
     } catch (\Buzz\Exception\ClientException $e) {
         return array('message' => $this->get('translator')->trans('fb.label.error'));
     }
     return $urlInfo;
 }
 /**
  * Gets the 'sonata.media.buzz.connector.curl' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return Buzz\Client\Curl A Buzz\Client\Curl instance.
  */
 protected function getSonata_Media_Buzz_Connector_CurlService()
 {
     $this->services['sonata.media.buzz.connector.curl'] = $instance = new \Buzz\Client\Curl();
     $instance->setIgnoreErrors(true);
     $instance->setMaxRedirects(5);
     $instance->setTimeout(5);
     $instance->setVerifyPeer(true);
     $instance->setProxy(NULL);
     return $instance;
 }
Ejemplo n.º 10
0
 private function getDocument($uri)
 {
     // Create a CURL client
     $cURL = new \Buzz\Client\Curl();
     $cURL->setVerifyPeer(false);
     $cURL->setTimeout(30);
     // Get discovery document
     $browser = new \Buzz\Browser($cURL);
     $response = $browser->get(\URL::to($uri));
     // Document content
     return $response->getContent();
 }
 /**
  * Gets the 'hwi_oauth.http_client' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return \Buzz\Client\Curl A Buzz\Client\Curl instance.
  */
 protected function getHwiOauth_HttpClientService()
 {
     $this->services['hwi_oauth.http_client'] = $instance = new \Buzz\Client\Curl();
     $instance->setVerifyPeer(true);
     $instance->setTimeout(5);
     $instance->setMaxRedirects(5);
     $instance->setIgnoreErrors(true);
     return $instance;
 }
Ejemplo n.º 12
0
 protected function processFormRequest(\Buzz\Message\Form\FormRequest $request)
 {
     $response = new \Buzz\Message\Response();
     $client = new \Buzz\Client\Curl();
     if ('test' == $this->ogoneEnv) {
         $client->setVerifyPeer(false);
     }
     $client->setTimeout(30);
     $client->send($request, $response);
     return $response;
 }
Ejemplo n.º 13
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app['title'] = "Composer Proxy JP";
$app['base_url'] = "http://composer-proxy.jp/";
$app['repositories'] = array('packagist' => 'https://packagist.org');
$app['cache_dir'] = __DIR__ . '/web/proxy';
$app['browser'] = $app->share(function () {
    $client = new Buzz\Client\Curl();
    $client->setTimeout(20);
    return new Buzz\Browser($client);
});
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/cache/'));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
$app->get('/', function () use($app) {
    $body = $app['twig']->render('index.html.twig', array('app' => $app));
    return new Response($body, 200, array('Cache-Control' => 's-maxage=3600,public'));
});
$app->get('/proxy/{rep}/packages.json', function ($rep) use($app) {
    if (!isset($app['repositories'][$rep])) {
        $app->abort(404, "Not Found");
    }
    $url = $app['repositories'][$rep] . "/packages.json";
    $response = $app['browser']->get($url);
    if (!$response->isOk()) {
        $app->abort($response->getStatusCode(), "");
    }
    $responseJson = json_decode($response->getContent(), true);
    // convert
Ejemplo n.º 14
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/helper.php';
$app = new Silex\Application();
$app['title'] = $config['title'];
$app['base_url'] = $config['base_url'];
$app['repositories'] = $config['repositories'];
$app['cache_dir'] = __DIR__ . '/' . $config['cache_dir'] ?: 'web/proxy';
$app['browser'] = $app->share(function () {
    $client = new Buzz\Client\Curl();
    $client->setTimeout(30);
    return new Buzz\Browser($client);
});
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/cache/'));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
require_once __DIR__ . '/routes.php';
return $app;