Git Product home page Git Product logo

Comments (10)

serbanghita avatar serbanghita commented on July 30, 2024

@StevenMapes thank you for this valuable contribution!

For starters I will add the getUserAgent() method right away and will be available in 2.5 version.

I am preparing a similar implementation to getDetails(), check it here https://github.com/serbanghita/Mobile-Detect/wiki/Roadmap under 'What we need'. I will add some of you ideas there. I will commit it to a branch called '3.0' in the next days/weeks.

Are you interested in reviewing it together?

from mobile-detect.

StevenMapes avatar StevenMapes commented on July 30, 2024

Certainly, I saw what you were doing and it's certainly something that I'd like to help out with as I know I'll make use of it ;)

I made some further changes to my fork to help return the device names a little easier/

I added the following array keys into the phoneDevices array (really these should be somewhere else but I'll see what you do with brand 3.0). These are so I can break out Windows Phone and Android devices closer to their device names.

    // Android
    'AndroidManuf' => 'Android .*?; [a-z]{2}-[a-z]{2}; (?P<name>.+?) Build',
    'WindowsManuf' => 'Windows Phone OS .*?; .*?; .*?; (?P<name>.+?)\)',

Next I modified my getPropertyDetail method to become this

public function getPropetyDetail($method) {
    if (!method_exists($this, $method)) {
        throw new UnexpectedValueException('Method name ' . $method . ' was not expected');
    }
    foreach ($this->$method() as $name => $regex) {
        $check = $this->{'is' . $name}();
        if ($check) {
            // Match found! Check to see if the RegEx will tell us the device name
            if (! stristr($regex, '(?P<name>')) {
                return $name;
            }

            $regex = str_replace('/', '\/', $regex);
            $res = preg_match('/' . $regex . '/is', $this->userAgent, $matches);
            if ($res) {
                if (substr_count($matches['name'], ';') > 0) {
                    // The match found at least one semi colon, take the 2nd portion regardless of how many there are
                    $parts = explode(";", $matches['name']);
                    return trim($parts[1]);
                }
                return $matches['name'];
            }
            // Failover
            return $name;
        }

    }
    return '';
}

I then ran a test over around 300 Useragents from the tests/* files.

Previously it returned these unique devices

[device] => Array
    (
        [0] => AsusTablet
        [1] => AcerTablet
        [2] => Kindle
        [3] => iPhone
        [4] => iPad
        [5] => BlackBerry
        [6] => CobyTablet
        [7] => CubeTablet
        [8] => Dell
        [9] => NexusTablet
        [10] => GenericTablet
        [11] => HTC
        [12] => Motorola
        [13] => MotorolaTablet
        [14] => GenericPhone
        [15] => Samsung
        [16] => Pantech
        [17] => SamsungTablet
        [18] => Nexus
        [19] => Sony
        [20] => Palm

Now the "device" list return

[device] => Array
    (
        [0] => AsusTablet
        [1] => AcerTablet
        [2] => Allegro
        [3] => ALCATEL ONE TOUCH 918D
        [4] => Kindle
        [5] => iPhone
        [6] => iPad
        [7] => asus_laptop
        [8] => BlackBerry
        [9] => C771
        [10] => CobyTablet
        [11] => CubeTablet
        [12] => Dell
        [13] => NexusTablet
        [14] => GenericTablet
        [15] => HTC
        [16] => IncredibleS_S710e
        [17] => U8660
        [18] => HUAWEI-U8850
        [19] => VS910 4G
        [20] => LS670
        [21] => LG-P700
        [22] => LG-L160L
        [23] => LG-F160S
        [24] => LG E-900
        [25] => LG-C900
        [26] => LG-C900k
        [27] => LG-E900
        [28] => LG-E900h
        [29] => LG-Optimus 7
        [30] => Motorola
        [31] => MotorolaTablet
        [32] => GenericPhone
        [33] => Samsung
        [34] => Pantech
        [35] => A2
        [36] => SamsungTablet
        [37] => Nexus
        [38] => OMNIA 7
        [39] => Sony
        [40] => TSUNAGI
        [41] => Blade
        [42] => N880e_Dawoer_Fulllock
        [43] => V965W
        [44] => Windows Phone - Internet 7
        [45] => Palm
        [46] => XDeviceEmulator
        [47] => N880E
        [48] => sdk
    )

from mobile-detect.

Lechus avatar Lechus commented on July 30, 2024

Hi,
Is there chance to return phone/tablet model?

'isBrand' => 'Samsung',
'isModel' => 'SGH-i677',

from mobile-detect.

serbanghita avatar serbanghita commented on July 30, 2024

@Lechus yes, this is exactly what I'm working on for v.3.0

from mobile-detect.

maxxer avatar maxxer commented on July 30, 2024

Any update on this? Is it possible to get a preview of MobileDetect with these methods? thanks

from mobile-detect.

nicktacular avatar nicktacular commented on July 30, 2024

@maxxer We are presently discussing the API for this very feature. I expect to start working on it over the next 2 weeks or so.

from mobile-detect.

maxxer avatar maxxer commented on July 30, 2024

awesome!
what about the devel_3.x branch? is that usable? thanks

from mobile-detect.

nicktacular avatar nicktacular commented on July 30, 2024

No I wouldn't use devel_3.x or any other 3.x branch since there is a significant API undertaking and most things are broken at this point. Once we get to a stable point in dev with the API we'll make a post about it.

from mobile-detect.

ErikThiart avatar ErikThiart commented on July 30, 2024

How far are we with getDetails()

from mobile-detect.

serbanghita avatar serbanghita commented on July 30, 2024

I experimented with this, see https://github.com/serbanghita/Mobile-Detect/tree/devel-3-workinprogress/lib, and it's very hard to maintain. I'll keep the a tight focus to Mobile Detect, and that is to detect the mobile environment and focus on the separation of mobiles vs tablets.

from mobile-detect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.