Newer
Older
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
mattab
a validé
namespace Piwik\Plugins\DevicesDetection;
use DeviceDetector\Parser\OperatingSystem AS OperatingSystemParser;
use DeviceDetector\Parser\Device\DeviceParserAbstract AS DeviceParser;
use DeviceDetector\Parser\Client\Browser AS BrowserParser;
mattab
a validé
function getBrandLogo($label)
{
$path = 'plugins/Morpheus/icons/dist/brand/%s.png';
$label = preg_replace("/[^a-z0-9_-]+/i", "_", $label);
if (!file_exists(PIWIK_INCLUDE_PATH . '/' . sprintf($path, $label))) {
$label = "unk";
}
return sprintf($path, $label);
}
{
foreach (BrowserParser::getAvailableBrowserFamilies() as $name => $family) {
if (in_array($label, $family)) {
return $name;
}
}
return Piwik::translate('General_Unknown');
}
{
$browserFamilies = BrowserParser::getAvailableBrowserFamilies();
if (!empty($label) && array_key_exists($label, $browserFamilies)) {
return getBrowserLogo($browserFamilies[$label][0]);
}
}
sgiehl
a validé
function getBrowserNameWithVersion($label)
{
$short = substr($label, 0, 2);
$ver = substr($label, 3, 10);
} else {
return Piwik::translate('General_Unknown');
}
}
sgiehl
a validé
function getBrowserName($label)
{
$short = substr($label, 0, 2);
$browsers = BrowserParser::getAvailableBrowsers();
sgiehl
a validé
return trim(ucfirst($browsers[$short]));
} else {
return Piwik::translate('General_Unknown');
}
}
/**
* Returns the path to the logo for the given browser
*
* First try to find a logo for the given short code
* If none can be found try to find a logo for the browser family
*
* @param string $short Shortcode or name of browser
*
* @return string path to image
*/
{
$path = 'plugins/Morpheus/icons/dist/browsers/%s.png';
sgiehl
a validé
// If name is given instead of short code, try to find matching shortcode
if (strlen($short) > 2) {
if (in_array($short, BrowserParser::getAvailableBrowsers())) {
$flippedBrowsers = array_flip(BrowserParser::getAvailableBrowsers());
$short = $flippedBrowsers[$short];
} else {
$short = substr($short, 0, 2);
}
sgiehl
a validé
}
$family = getBrowserFamilyFullName($short);
$browserFamilies = BrowserParser::getAvailableBrowserFamilies();
if (!empty($short) &&
array_key_exists($short, BrowserParser::getAvailableBrowsers()) &&
file_exists(PIWIK_INCLUDE_PATH.'/'.sprintf($path, $short))) {
return sprintf($path, $short);
} elseif (!empty($short) &&
array_key_exists($family, $browserFamilies) &&
file_exists(PIWIK_INCLUDE_PATH.'/'.sprintf($path, $browserFamilies[$family][0]))) {
}
return sprintf($path, 'UNK');
}
mattab
a validé
function getDeviceBrandLabel($label)
{
if (array_key_exists($label, DeviceParser::$deviceBrands)) {
return ucfirst(DeviceParser::$deviceBrands[$label]);
} else {
return Piwik::translate('General_Unknown');
}
}
mattab
a validé
function getDeviceTypeLabel($label)
{
$translations = array(
'desktop' => 'General_Desktop',
'smartphone' => 'DevicesDetection_Smartphone',
'tablet' => 'DevicesDetection_Tablet',
'phablet' => 'DevicesDetection_Phablet',
'feature phone' => 'DevicesDetection_FeaturePhone',
'console' => 'DevicesDetection_Console',
'tv' => 'DevicesDetection_TV',
'car browser' => 'DevicesDetection_CarBrowser',
'smart display' => 'DevicesDetection_SmartDisplay',
'camera' => 'DevicesDetection_Camera',
'portable media player' => 'DevicesDetection_PortableMediaPlayer',
$deviceTypes = DeviceParser::getAvailableDeviceTypes();
if (is_numeric($label) &&
in_array($label, $deviceTypes) &&
isset($translations[array_search($label, $deviceTypes)])) {
return Piwik::translate($translations[array_search($label, $deviceTypes)]);
} else if (isset($translations[$label])) {
return Piwik::translate($translations[$label]);
} else {
return Piwik::translate('General_Unknown');
}
}
mattab
a validé
function getDeviceTypeLogo($label)
{
if (is_numeric($label) && in_array($label, DeviceParser::getAvailableDeviceTypes())) {
$label = array_search($label, DeviceParser::getAvailableDeviceTypes());
$label = strtolower($label);
$label = str_replace(' ', '_', $label);
} else {
}
$path = 'plugins/Morpheus/icons/dist/devices/' . $label . ".png";
return $path;
}
mattab
a validé
function getModelName($label)
{
Matthieu Napoli
a validé
if (strpos($label, ';') !== false) {
list($brand, $model) = explode(';', $label, 2);
} else {
$brand = null;
$model = $label;
}
if (!$model) {
$model = Piwik::translate('General_Unknown');
}
if (!$brand) {
return $model;
Matthieu Napoli
a validé
return getDeviceBrandLabel($brand) . ' - ' . $model;
}
{
sgiehl
a validé
$label = OperatingSystemParser::getOsFamily(_mapLegacyOsShortCodes($label));
if ($label == 'unknown') {
$label = Piwik::translate('General_Unknown');
} else if ($label == 'Gaming Console') {
$label = Piwik::translate('DevicesDetection_Console');
Thomas Steur
a validé
if ($label !== false) {
}
return Piwik::translate('General_Unknown');
}
{
sgiehl
a validé
$label = _mapLegacyOsShortCodes($label);
$osFamilies = OperatingSystemParser::getAvailableOperatingSystemFamilies();
if (!empty($label) && array_key_exists($label, $osFamilies)) {
}
}
{
if (substr($label, 0, 3) == \Piwik\Tracker\Settings::OS_BOT) {
$os = substr($label, 0, 3);
$ver = substr($label, 4, 15);
sgiehl
a validé
$name = OperatingSystemParser::getNameFromId(_mapLegacyOsShortCodes($os), $ver);
}
}
return Piwik::translate('General_Unknown');
}
sgiehl
a validé
function _mapLegacyOsShortCodes($shortCode)
{
$legacyShortCodes = array(
'IPA' => 'IOS', // iPad => iOS
'IPH' => 'IOS', // iPhone => iOS
'IPD' => 'IOS', // iPod => iOS
'WIU' => 'WII', // WiiU => Nintendo
'3DS' => 'NDS', // Nintendo 3DS => Nintendo Mobile
'DSI' => 'NDS', // Nintendo DSi => Nintendo Mobile
'PSV' => 'PSP', // PlayStation Vita => PlayStation Portable
'MAE' => 'SMG', // Maemo => MeeGo
'W10' => 'WIN',
'W2K' => 'WIN',
'W31' => 'WIN',
'WI7' => 'WIN',
'WI8' => 'WIN',
'W81' => 'WIN',
'W95' => 'WIN',
'W98' => 'WIN',
'WME' => 'WIN',
'WNT' => 'WIN',
'WS3' => 'WIN',
'WVI' => 'WIN',
'WXP' => 'WIN',
sgiehl
a validé
//'VMS' => '', // OpenVMS => ??
);
return ($shortCode && array_key_exists($shortCode, $legacyShortCodes)) ? $legacyShortCodes[$shortCode] : $shortCode;
sgiehl
a validé
}
/**
* Returns the path to the logo for the given OS
*
* First try to find a logo for the given short code
* If none can be found try to find a logo for the os family
*
* @param string $short Shortcode or name of OS
*
* @return string path to image
*/
{
$path = 'plugins/Morpheus/icons/dist/os/%s.png';
sgiehl
a validé
$short = _mapLegacyOsShortCodes($short);
// If name is given instead of short code, try to find matching shortcode
if (strlen($short) > 3) {
if (in_array($short, OperatingSystemParser::getAvailableOperatingSystems())) {
$short = array_search($short, OperatingSystemParser::getAvailableOperatingSystems());
} else {
$short = substr($short, 0, 3);
}
}
$osFamilies = OperatingSystemParser::getAvailableOperatingSystemFamilies();
if (!empty($short) &&
array_key_exists($short, OperatingSystemParser::getAvailableOperatingSystems()) &&
file_exists(PIWIK_INCLUDE_PATH.'/'.sprintf($path, $short))) {
return sprintf($path, $short);
} elseif (!empty($family) &&
array_key_exists($family, $osFamilies) &&
file_exists(PIWIK_INCLUDE_PATH.'/'.sprintf($path, $osFamilies[$family][0]))) {
}
return sprintf($path, 'UNK');
}
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/**
* Returns the display name for a browser engine
*
* @param $engineName
*
* @return string
*/
function getBrowserEngineName($engineName) {
/*
* Map leagcy types to engines
*/
$oldTypeMapping = array(
'ie' => 'Trident',
'gecko' => 'Gecko',
'khtml' => 'KHTML',
'webkit' => 'WebKit',
'opera' => 'Presto',
'unknown' => ''
);
if (array_key_exists($engineName, $oldTypeMapping)) {
$engineName = $oldTypeMapping[$engineName];
}
$displayNames = array(
'Trident' => 'Trident (IE)',
'Gecko' => 'Gecko (Firefox)',
'Presto' => 'Presto (Opera)',
'WebKit' => 'WebKit (Safari, Chrome)',
'Blink' => 'Blink (Chrome, Opera)'
);
if (!empty($engineName)) {
if (!empty($displayNames[$engineName])) {
return $displayNames[$engineName];
}
return $engineName;
}
return Piwik::translate('General_Unknown');