Esempio n. 1
0
<?php

chdir(dirname(__DIR__));
$autoloadPaths = ['vendor/autoload.php', '../../autoload.php'];
$foundVendorAutoload = false;
foreach ($autoloadPaths as $path) {
    if (file_exists($path)) {
        require $path;
        $foundVendorAutoload = true;
        break;
    }
}
if (!$foundVendorAutoload) {
    throw new Exception('Could not find autoload path in any of the searched locations');
}
use ModernizrServer\Modernizr;
if (null === Modernizr::getData()) {
    echo "<html><head><script type='text/javascript'>";
    echo Modernizr::buildJsCode() . '</script></head><body></body></html>';
    exit;
}
echo 'The server knows:';
foreach (Modernizr::getData() as $feature => $value) {
    echo "<br/> {$feature}: ";
    print_r($value);
}
Esempio n. 2
0
//$app->pipe(Middleware::Expires());
//$app->pipe(Middleware::Minify());
$app->pipe(Middleware::BlockSpam());
//$app->pipe(Middleware::PhpSession()->name('DetectorSessionId'));
//$app->pipe(Middleware::Geolocate()->saveInSession(true));
//$app->pipe(Middleware::Cache($pool));
$app->pipe(Middleware::responseTime());
$app->pipeRoutingMiddleware();
$app->pipeDispatchMiddleware();
$cache = new File(array(File::DIR => 'cache/'));
$app->get('/js/features.js', function (RequestInterface $request, ResponseInterface $response, callable $next) use($errorLog, $cache) {
    $response->withAddedHeader('content-type', 'application/x-javascript');
    $response->getBody()->write(Modernizr::buildJs());
    $detector = new Detector($cache, $errorLog);
    $cookieID = $detector->getCookieId($_SERVER);
    $response->getBody()->write(Modernizr::buildConvertJs($cookieID, '', false));
    return $response;
});
$app->get('/', function (RequestInterface $request, ResponseInterface $response, callable $next) use($errorLog, $cache) {
    $detector = new Detector($cache, $errorLog);
    // if this is a request from features.js.php don't run the build function
    $ua = $detector->build($_SERVER);
    /*
        if (null === $ua) {
            $html = '<html><head><script type="text/javascript">';
    
            $html .= Modernizr::buildJs();
            $html .= Modernizr::buildConvertJs($detector->getCookieId($_SERVER), '', true);
    
            $html .= '</script></head><body></body></html>';
            return $response->getBody()->write($html);
Esempio n. 3
0
 /**
  * Tests to see if:
  *     - see if this is a debug request with appropriately formed pid, else
  *     - see if the cookie for the per user test has been set so we can record the results and add to the session
  *     - see if a session has already been opened for the request browser, if so send the info back, else
  *     - see if the cookie for the full test has been set so we can build the profile, if so build the profile &
  *     send the info back, else
  *     - see if this browser reports being a spider, doesn't support JS or doesn't support cookies
  *     - see if detector can find an already created profile for the browser, if so send the info back, else
  *     - start the process for building a profile for this unknown browser
  *
  * @param string|array|\Wurfl\Request\GenericRequest $request
  *
  * @return null|\stdClass an object that contains all the properties for this particular user agent
  */
 public function build($request = null)
 {
     $request = $this->initRequest($request);
     $sessionID = md5($request->getBrowserUserAgent() . '-session-' . $this->coreVersion . '-' . $this->extendedVersion);
     $pid = isset($_REQUEST['pid']) && preg_match('/[a-z0-9]{32}/', $_REQUEST['pid']) ? $_REQUEST['pid'] : false;
     // offer the ability to review profiles saved in the system
     if ($pid) {
         $this->foundIn = 'archive';
         // decode the core data
         $info = json_decode(@file_get_contents(__DIR__ . '/' . $this->uaDir . 'ua.' . $pid . '.json'));
         if ($info instanceof \stdClass) {
             // some general properties
             $info->nojs = false;
             $info->nocookies = false;
             // put the merged JSON info into session
             if (isset($_SESSION)) {
                 $_SESSION[$sessionID] = $info;
             }
             // return to the script
             //  return $info;
         }
     }
     $cacheId = hash('sha512', $request->getDeviceUserAgent() . '||||' . $request->getBrowserUserAgent());
     $result = null;
     $success = false;
     $info = $this->cache->getItem($cacheId, $success);
     // populate some variables specific to build()
     $uaHash = md5($request->getBrowserUserAgent());
     $uaFile = __DIR__ . '/' . $this->uaDir . $this->uaDir() . 'ua.' . $uaHash . '.json';
     if ($success && $info instanceof \stdClass) {
         $this->foundIn = 'cache';
         $this->save($request, $info, $uaFile, $cacheId);
         // send the data back to the script to be used
         //return $info;
     }
     session_id($sessionID);
     if (@session_start() && isset($_SESSION) && isset($_SESSION[$sessionID])) {
         $this->foundIn = 'session';
         $info = $_SESSION[$sessionID];
         $this->save($request, $info, $uaFile, $cacheId);
         // send the data back to the script to be used
         //return $info;
     }
     $cookieID = $this->getCookieId($request);
     $modernizrData = Modernizr::getData($cookieID);
     if ($this->checkSpider($request) || isset($_REQUEST['nojs']) && $_REQUEST['nojs'] === 'true' || isset($_REQUEST['nocookies']) && $_REQUEST['nocookies'] === 'true') {
         $this->foundIn = 'nojs';
         // use ua-parser to set-up the basic properties for this UA, populate other core properties
         // include the basic properties of the UA
         $info = $this->createUAProperties($request);
         $info->uaHash = $uaHash;
         $info->coreVersion = $this->coreVersion;
         if (null !== $modernizrData) {
             foreach ($modernizrData as $property => $value) {
                 $info->{$property} = $value;
             }
         }
         // some general properties
         $info->nojs = false;
         $info->nocookies = false;
         // add an attribute to the object in case no js or no cookies was sent
         if (isset($_REQUEST['nojs']) && $_REQUEST['nojs'] == 'true') {
             $info->nojs = true;
         } else {
             if (isset($_REQUEST['nocookies']) && $_REQUEST['nocookies'] == 'true') {
                 $info->nocookies = true;
             }
         }
         // try setting the session unless cookies are actively not supported
         if (!(isset($_REQUEST['nocookies']) && $_REQUEST['nocookies'] == 'true') && isset($_SESSION)) {
             $_SESSION[$sessionID] = $info;
         }
         $this->save($request, $info, $uaFile, $cacheId);
         // return the collected data to the script for use in this go around
         return $info;
     }
     if (null !== $modernizrData) {
         // to be clear, this section means that a UA was unknown, was profiled with modernizr
         // & now we're saving that data to build a new profile
         $this->foundIn = 'cookie';
         // use ua-parser to set-up the basic properties for this UA, populate other core properties
         $info = $this->createUAProperties($request);
         $info->uaHash = $uaHash;
         $info->coreVersion = $this->coreVersion;
         foreach ($modernizrData as $property => $value) {
             $info->{$property} = $value;
         }
         // some general properties
         $info->nojs = false;
         $info->nocookies = false;
         // unset the cookie that held the vast amount of test data
         setcookie($cookieID, '');
         // add our collected data to the session for use in future requests, also add the per request data
         if (isset($_SESSION)) {
             $_SESSION[$sessionID] = $info;
         }
         $this->save($request, $info, $uaFile, $cacheId);
         // return the collected data to the script for use in this go around
         return $info;
     }
     return null;
 }
Esempio n. 4
0
<?php

chdir(dirname(dirname(__DIR__)));
$autoloadPaths = array('vendor/autoload.php', '../../autoload.php');
$foundVendorAutoload = false;
foreach ($autoloadPaths as $path) {
    if (file_exists($path)) {
        require $path;
        $foundVendorAutoload = true;
        break;
    }
}
if (!$foundVendorAutoload) {
    throw new Exception('Could not find autoload path in any of the searched locations');
}
$p = true;
// turn off the build function
use Detector\Detector;
use ModernizrServer\Modernizr;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use WurflCache\Adapter\File;
header('content-type: application/x-javascript', true);
$logger = new Logger('detector');
$logger->pushHandler(new StreamHandler('log/error.log', Logger::NOTICE));
$cache = new File(array(File::DIR => 'cache/'));
$detector = new Detector($cache, $logger);
$cookieID = $detector->getCookieId($_SERVER);
print Modernizr::buildJs();
print Modernizr::buildConvertJs($cookieID, '', false);