コード例 #1
0
ファイル: index.php プロジェクト: mimmi20/detector
<?php

chdir(dirname(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');
}
// require detector to get the family, autoloads the $ua var
use Detector\Detector;
use Detector\FeatureFamily;
$template = file_get_contents('web/demo/mustache/templates/index.mustache');
$data = array('title' => 'Hello, World!', 'description' => 'This extremely simple demo is meant to show how Detector & Mustache can be combined to create a Responsive Web Design + Server Side Component (RESS) System. By using the requesting browser\'s Detector family classification a responsive template & partials that match the browser\'s features are rendered server-side via Mustache. Choose a different layout below to see how this page & the included images change depending upon the browser family.', 'link' => 'https://github.com/dmolsen/Detector/wiki/Templating-with-Detector-&-Mustache-Tutorial', 'viewDesktop' => '/demo/mustache/?pid=13ee8513d6fb7f97aef6635309b91f40', 'viewMA' => '/demo/mustache/?pid=e1bd58cc186d3a2156b6ebddb558fd41', 'viewMB' => '/demo/mustache/?pid=658e6d9b003bb3f3a3d9ae6e5ca1a42a', 'images' => array(array('index' => '1', 'title' => 'Automobile', 'alt' => 'auto', 'img' => 'images/automobile.jpg', 'img_sml' => 'images/automobile_sml.jpg', 'src' => 'http://farm4.staticflickr.com/3347/3411775886_fcf0af1a42_z.jpg'), array('index' => '2', 'title' => 'Bus', 'alt' => 'bus', 'img' => 'images/bus.jpg', 'img_sml' => 'images/bus_sml.jpg', 'src' => 'http://www.flickr.com/photos/d0a98042/3774873571/sizes/z/in/photostream/'), array('index' => '3', 'title' => 'Train', 'alt' => 'train', 'img' => 'images/train.jpg', 'img_sml' => 'images/train_sml.jpg', 'src' => 'http://www.flickr.com/photos/30827349@N02/3965800996/sizes/z/in/photostream/')));
// if this is a request from features.js.php don't run the build function
$ua = Detector::build();
// include the browserFamily library to classify the browser by features
$ua->family = FeatureFamily::find($ua);
$options = array('partials' => array('web/demo/mustache/templates/partials/' . $ua->family, 'web/demo/mustache/templates/partials/base'));
$m = new Mustache_Engine($options);
print $m->render($template, $data);
コード例 #2
0
ファイル: _createFT.inc.php プロジェクト: mimmi20/detector
/**
 * @param \Detector\Detector $detector
 * @param \stdClass          $ua
 * @param string             $match
 * @param string             $title
 * @param string             $prefix
 * @param string             $note
 */
function createFT(Detector $detector, $ua, $match, $title, $prefix = '', $note = '')
{
    ?>
    <div class="table table-hover table-striped">
    <div class="text-center clearfix thead">
        <div class="col-xs-6 col-sm-4 col-md-4 col-lg-4 col-xl-4 th">
            <?php 
    echo htmlentities($title);
    ?>
        </div>
        <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 th">Your Browser</div>
        <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 th">Detector Profile</div>
    </div>
    <?php 
    $check = 0;
    foreach ($ua as $key => $value) {
        if (!preg_match($match, $key)) {
            continue;
        }
        $check = 1;
        if (is_object($value)) {
            foreach ($value as $vkey => $vvalue) {
                ?>
                <div class="clearfix tbody">
                    <div class="col-xs-6 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-left">
                        <?php 
                echo htmlentities($key . '->' . $vkey);
                ?>
                    </div>
                    <?php 
                if ($detector->whereFound() == 'archive') {
                    ?>
                        <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-center"><span
                                class="label label-info">N/A</span></div>
                    <?php 
                } else {
                    ?>
                        <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-center">
                            <script type="text/javascript">
                                if (typeof Modernizr === 'undefined') {
                                    document.write("<span class='label label-info'>unknown</span>");
                                } else if (Modernizr['<?php 
                    echo $prefix . $key;
                    ?>
']['<?php 
                    echo $vkey;
                    ?>
'] === true) {
                                    document.write("<span class='label label-success'>" + Modernizr['<?php 
                    echo $prefix . $key;
                    ?>
']['<?php 
                    echo $vkey;
                    ?>
'] + "</span>");
                                } else if (Modernizr['<?php 
                    echo $prefix . $key;
                    ?>
']['<?php 
                    echo $vkey;
                    ?>
'] === false) {
                                    document.write("<span class='label label-danger'>" + Modernizr['<?php 
                    echo $prefix . $key;
                    ?>
']['<?php 
                    echo $vkey;
                    ?>
'] + "</span>");
                                } else if (Modernizr['<?php 
                    echo $prefix . $key;
                    ?>
']['<?php 
                    echo $vkey;
                    ?>
']) {
                                    document.write("<span class='label label-warning'>" + Modernizr['<?php 
                    echo $prefix . $key;
                    ?>
']['<?php 
                    echo $vkey;
                    ?>
'] + "</span>");
                                } else {
                                    document.write("<span class='label label-info'>unknown</span>");
                                }
                            </script>
                        </div>
                    <?php 
                }
                ?>

                    <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-center"><?php 
                echo convertTF($vvalue);
                ?>
</div>
                </div>
            <?php 
            }
        } else {
            ?>
            <div class="clearfix tbody">
                <div class="col-xs-6 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-left">
                    <?php 
            echo htmlentities($key);
            ?>
                </div>
                <?php 
            if ($detector->whereFound() == 'archive') {
                ?>
                    <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-center"><span class="label label-info">N/A</span>
                    </div>
                <?php 
            } else {
                ?>
                    <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-center">
                        <script type="text/javascript">
                            if (typeof Modernizr === 'undefined') {
                                document.write("<span class='label label-info'>unknown</span>");
                            } else if (Modernizr['<?php 
                echo $prefix . $key;
                ?>
'] === true) {
                                document.write("<span class='label label-success'>" + Modernizr['<?php 
                echo $prefix . $key;
                ?>
'] + "</span>");
                            } else if (Modernizr['<?php 
                echo $prefix . $key;
                ?>
'] === false) {
                                document.write("<span class='label label-danger'>" + Modernizr['<?php 
                echo $prefix . $key;
                ?>
'] + "</span>");
                            } else if (Modernizr['<?php 
                echo $prefix . $key;
                ?>
']) {
                                document.write("<span class='label label-warning'>" + Modernizr['<?php 
                echo $prefix . $key;
                ?>
'] + "</span>");
                            } else {
                                document.write("<span class='label label-info'>unknown</span>");
                            }
                        </script>
                    </div>
                <?php 
            }
            ?>

                <div class="col-xs-3 col-sm-4 col-md-4 col-lg-4 col-xl-4 text-center"><?php 
            echo convertTF($value);
            ?>
</div>
            </div>
        <?php 
        }
    }
    if ($check == 0) {
        ?>
        <div class="clearfix text-left tbody">
            Detector wasn't able to capture these features because they rely on a cookie that was set after the PHP
            script ran.
        </div>
    <?php 
    }
    ?>
    </div>
    <?php 
    if ($note != '') {
        ?>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 clearfix">
            <small><em><?php 
        echo $note;
        ?>
</em></small>
        </div>
    <?php 
    }
}
コード例 #3
0
ファイル: features.js.php プロジェクト: mimmi20/detector
<?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);
コード例 #4
0
ファイル: index.php プロジェクト: mimmi20/detector
//$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);
        }
    /**/
    $response->getBody()->write('Hello, world!');
    $options = array('loader' => new Mustache_Loader_FilesystemLoader('src/templates'), 'partials_loader' => new Mustache_Loader_FilesystemLoader('src/templates/partials'), 'logger' => $errorLog);
コード例 #5
0
ファイル: contact.php プロジェクト: mimmi20/detector
$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');
}
// require Detector so we can popular identify the browser & populate $ua
use Detector\Detector;
use Monolog\ErrorHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use WurflCache\Adapter\File;
$logger = new Logger('detector');
$logger->pushHandler(new StreamHandler('log/error.log', Logger::DEBUG));
ErrorHandler::register($logger);
$cache = new File(array(File::DIR => 'cache/'));
$detector = new Detector($cache, $logger);
$cookieID = $detector->getCookieId($_SERVER);
// if this is a request from features.js.php don't run the build function
$ua = $detector->build($_SERVER);
if (!empty($_POST['post'])) {
    $message = "Here is some feedback for Detector:\n\nEmail addy: \n" . $_POST['email'] . "\n\nTheir message:\n" . $_POST['message'];
    mail('*****@*****.**', 'Detector Feedback', $message);
}
include "templates/contact.default.inc.php";