Skip to content
Extraits de code Groupes Projets
Controller.php 5,63 ko
Newer Older
  • Learn to ignore specific revisions
  •  * Piwik - free/libre analytics platform
    
     *
     * @link http://piwik.org
     * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
     *
     */
    
    namespace Piwik\Plugins\DevicesDetection;
    
    
    use DeviceDetector\DeviceDetector;
    
    class Controller extends \Piwik\Plugin\Controller
    
        public function index()
    
            $view = new View('@DevicesDetection/index');
    
            $view->deviceTypes = $view->deviceModels = $view->deviceBrands = $view->osReport = $view->browserReport = "blank";
            $view->deviceTypes = $this->getType(true);
            $view->deviceBrands = $this->getBrand(true);
            $view->deviceModels = $this->getModel(true);
            $view->osReport = $this->getOsFamilies(true);
            $view->browserReport = $this->getBrowserFamilies(true);
    
            return $view->render();
    
        public function getType()
    
            return $this->renderReport(__FUNCTION__);
    
        public function getBrand()
    
            return $this->renderReport(__FUNCTION__);
    
        public function getModel()
    
            return $this->renderReport(__FUNCTION__);
    
        public function getOsFamilies()
    
            return $this->renderReport(__FUNCTION__);
    
        public function getOsVersions()
    
            return $this->renderReport(__FUNCTION__);
    
        public function getBrowserFamilies()
    
            return $this->renderReport(__FUNCTION__);
    
        public function getBrowserVersions()
    
            return $this->renderReport(__FUNCTION__);
    
        public function deviceDetection()
        {
            Piwik::checkUserHasSomeAdminAccess();
    
            $view = new View('@DevicesDetection/detection');
            $this->setBasicVariablesView($view);
            ControllerAdmin::setBasicVariablesAdminView($view);
    
            $userAgent = Common::getRequestVar('ua', $_SERVER['HTTP_USER_AGENT'], 'string');
    
    
            $uaParser = new DeviceDetector($userAgent);
            $uaParser->parse();
    
            $view->browser_name        = $uaParser->getClient('name');
            $view->browser_short_name  = $uaParser->getClient('short_name');
            $view->browser_version     = $uaParser->getClient('version');
            $view->browser_logo        = getBrowserLogoExtended($uaParser->getClient('short_name'));
            $view->browser_family      = \DeviceDetector\Parser\Client\Browser::getBrowserFamily($uaParser->getClient('short_name'));
            $view->browser_family_logo = getBrowserFamilyLogoExtended($view->browser_family);
            $view->os_name             = $uaParser->getOs('name');
            $view->os_logo             = getOsLogoExtended($uaParser->getOs('short_name'));
            $view->os_short_name       = $uaParser->getOs('short_name');
            $view->os_family           = \DeviceDetector\Parser\OperatingSystem::getOsFamily($uaParser->getOs('short_name'));
            $view->os_family_logo      = getOsFamilyLogoExtended($view->os_family);
            $view->os_version          = $uaParser->getOs('version');
            $view->device_type         = getDeviceTypeLabel($uaParser->getDeviceName());
            $view->device_type_logo    = getDeviceTypeLogo($uaParser->getDeviceName());
            $view->device_model        = $uaParser->getModel();
            $view->device_brand        = getDeviceBrandLabel($uaParser->getBrand());
            $view->device_brand_logo   = getBrandLogo($uaParser->getBrand());
    
    
        public function showList()
        {
            Piwik::checkUserHasSomeAdminAccess();
    
            $view = new View('@DevicesDetection/list');
    
            $type = Common::getRequestVar('type', 'brands', 'string');
    
            $list = array();
    
            switch ($type) {
                case 'brands':
    
                    $availableBrands = \DeviceDetector\Parser\Device\DeviceParserAbstract::$deviceBrands;
    
                        if ($name != 'Unknown') {
                            $list[$name] = getBrandLogo($name);
                        }
    
                    $availableBrowsers = \DeviceDetector\Parser\Client\Browser::getAvailableBrowsers();
    
    
                    foreach ($availableBrowsers AS $short => $name) {
                        $list[$name] = getBrowserLogoExtended($short);
                    }
                    break;
    
                case 'browserfamilies':
    
                    $availableBrowserFamilies = \DeviceDetector\Parser\Client\Browser::getAvailableBrowserFamilies();
    
    
                    foreach ($availableBrowserFamilies AS $name => $browsers) {
                        $list[$name] = getBrowserFamilyLogoExtended($name);
                    }
                    break;
    
                case 'os':
    
                    $availableOSs = \DeviceDetector\Parser\OperatingSystem::getAvailableOperatingSystems();
    
                    foreach ($availableOSs AS $short => $name) {
    
    sgiehl's avatar
    sgiehl a validé
                        $list[$name] = getOsLogoExtended($short);
    
                    $osFamilies = \DeviceDetector\Parser\OperatingSystem::getAvailableOperatingSystemFamilies();
    
    sgiehl's avatar
    sgiehl a validé
                        $list[$name] = getOsFamilyLogoExtended($name);
    
                    $deviceTypes = \DeviceDetector\Parser\Device\DeviceParserAbstract::getAvailableDeviceTypes();
    
                    foreach ($deviceTypes AS $name => $id) {
    
                        $list[$name] = getDeviceTypeLogo($name);