Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #11 from peldax/master
Browse files Browse the repository at this point in the history
Tracy debug panel and replacement of MobileDetect
  • Loading branch information
akadlec authored Nov 8, 2017
2 parents f71a5e2 + c8f36eb commit f289b4e
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

"latte/latte" : "~2.3",

"mobiledetect/mobiledetectlib" : "2.8.*"
"jenssegers/agent" : "~2.5"
},

"require-dev": {
Expand Down
12 changes: 10 additions & 2 deletions src/IPub/MobileDetect/DI/MobileDetectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ final class MobileDetectExtension extends DI\CompilerExtension
'path' => '/',
'secure' => FALSE,
'httpOnly' => TRUE,
]
],
'debugger' => '%debugMode%'
];

/**
Expand All @@ -88,7 +89,7 @@ public function loadConfiguration()
$configuration = $this->getConfig($this->defaults);

// Install mobile detect service
$builder->addDefinition($this->prefix('mobileDetect'))
$mobileDetect = $builder->addDefinition($this->prefix('mobileDetect'))
->setClass(MobileDetect\MobileDetect::class);

$builder->addDefinition($this->prefix('deviceView'))
Expand All @@ -106,6 +107,13 @@ public function loadConfiguration()
'httpOnly' => $configuration['deviceViewCookie']['httpOnly'],
]);

if ($configuration['debugger'] && interface_exists('Tracy\IBarPanel')) {
$builder->addDefinition($this->prefix('panel'))
->setClass('IPub\MobileDetect\Diagnostics\Panel');

$mobileDetect->addSetup('?->register(?)', [$this->prefix('@panel'), '@self']);
}

$builder->addDefinition($this->prefix('onRequestHandler'))
->setClass(Events\OnRequestHandler::class)
->addSetup('$redirectConf', [$configuration['redirect']])
Expand Down
84 changes: 84 additions & 0 deletions src/IPub/MobileDetect/Diagnostics/Panel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* MobileDetectExtension.php
*
* @copyright More in license.md
* @license http://www.ipublikuj.eu
* @author Adam Kadlec http://www.ipublikuj.eu
* @package iPublikuj:MobileDetect!
* @subpackage DI
* @since 1.0.0
*
* @date 21.04.14
*/

declare(strict_types = 1);

namespace IPub\MobileDetect\Diagnostics;

/**
* Mobile device detect tracy panel
*
* @package iPublikuj:MobileDetect!
* @subpackage Diagnostics
*
* @author Václav Pelíšek <[email protected]>
*/
final class Panel extends \Nette\Object implements \Tracy\IBarPanel
{
/** @var \IPub\MobileDetect\MobileDetect
*/
private $mobileDetect;

public function register(\IPub\MobileDetect\MobileDetect $mobileDetect)
{
$this->mobileDetect = $mobileDetect;

\Tracy\Debugger::getBar()->addPanel($this, 'ipub.mobileDetect');

return $this;
}

/**
* Renders HTML code for custom tab.
*
* @return string
*/
public function getTab()
{
return '<span title="Mobile detect"><img width="16px" height="16px" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAACNCAYAAAAeuFBXAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9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KIc/ouEVbFCJgh7YPDQ4tz4ju0BINDg3k6tAaNPJwaIlGjERbFIJySDRyVQ6LQgTs0B59g0NLNMI7NNCtQ9vlAIeWaJTh0PKMWA4t0cjCoQURlEODRq6LQokGh5ZnRHdoiUa3ifZyEiiHBo3MlcOiEJE6tCAiSIu2Dw0OLdHI3KGdWAHlkGhkh31ocGgNGmU4tESj40RTDgRUjpndQDo0Ijk0EMqh3RjoONH2oUE5gEKUw52BbhNt2w6hEGhwaMqBMhwa6DjRnhSCQwOZO7TOij4Yh207FNmhZ8dWM8amFSECnZ69tw30yLSCQwMcGhBoxFcOE4E+KMeeF4USjRiJphzg0EDmDk050AfjoBygHEDflWO3Lv/5rxPThEyYn4VDL5pHUA6gM+VIyUxAoAGBBvYh0FuVkybDQAvgYj/LOunOVf3ZL+12UHtTzwUpaT09d9+mQJca6E+vth/+S4FKutGMQXr+/usCXdoEfHJl0Fx+D1ja6fTCA6sCXdoEfPzzpIr78Oie9OKD18pbFJYa5o9+Glaxn4Ru7ix2degiit/8sV0IHgxe5tNp7aEzAh298JM/rDWXkwWU+kczFtL6w9cFOmrRH34fbZtuGuN0eHEk0FGLPnH5VHNZKajkG9td+uWlLYGOVvDxSwvN5bcCLet0euWRVYGOVvAH302qct/xXkqvHppELrCobbv6/YvLVdkHFlqPHurQUYp970LrkAersnkmHXn0lED3vdB3z7fdaaPCrfc8Xnss5DZeEcpRv/PtoLmsyfI2cztzMdKh+1rk29+0/8WuyPLfuDu9/viWDt23ML91bijM/0j7nseyDt23At88O6n8KIZ/Yym98cREh+5LmI99vSrMU7v0gg7dh8LGX5X2vsZ/ZT1tPBnmuFbcHzST0loz5rZPtBu7jVE9+nI+ysceVzlu3mz/9DsT98agGSFOtjgki1D8KcAASOpOloXu01cAAAAASUVORK5CYII=" />'
. $this->mobileDetect->view() . ' / ' . $this->mobileDetect->platform() . '</span>';
}

/**
* Renders HTML code for custom panel.
*
* @return string
*/
public function getPanel()
{
$h = 'htmlSpecialChars';

$panel = [];

$panel[] = '<h2>Original User agent header</h2>';
$panel[] = '<p>' . $h($this->mobileDetect->getUserAgent()) . '</p>';

$properties = ['view', 'platform', 'platformVersion', 'device', 'browser', 'browserVersion'];

$panel[] = '<table style="width:100%">';
foreach ($properties as $property)
{
$panel[] = '<tr><th>' . ucfirst($property) . '</th><td>' . $h($this->mobileDetect->{$property}() ?: '') . '</td></tr>';
}
$panel[] = '</table>';

return empty($panel) ? '' :
'<h1>View: '.$this->mobileDetect->view() . ', OS: ' . $this->mobileDetect->platform().'</h1>' .
'<div class="nette-inner tracy-inner ipub-MobileDetectPanel" style="min-width:500px">' . implode($panel) . '</div>' .
'<style>
#nette-debug .ipub-MobileDetectPanel h2,
#tracy-debug .ipub-MobileDetectPanel h2 {font-size: 17px;}
</style>';
}
}
27 changes: 16 additions & 11 deletions src/IPub/MobileDetect/MobileDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @author Adam Kadlec <[email protected]>
*/
final class MobileDetect extends \Detection\MobileDetect
final class MobileDetect extends \Jenssegers\Agent\Agent
{
/**
* @var Helpers\DeviceView
Expand Down Expand Up @@ -62,16 +62,6 @@ public function __construct(
$this->deviceView = $deviceView;
}

/**
* Check if the device is mobile phone
*
* @return bool
*/
public function isPhone() : bool
{
return $this->isMobile() && !$this->isTablet();
}

/**
* Check if the device is not mobile phone
*
Expand All @@ -81,4 +71,19 @@ public function isNotPhone() : bool
{
return (($this->isMobile() && $this->isTablet()) || !$this->isMobile());
}

public function view()
{
return $this->deviceView->getViewType();
}

public function browserVersion()
{
return $this->version($this->browser());
}

public function platformVersion()
{
return $this->version($this->platform());
}
}

0 comments on commit f289b4e

Please sign in to comment.