update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -0,0 +1,172 @@
# Piwik/Cache
This is a PHP caching library based on [Doctrine cache](https://github.com/doctrine/cache) that supports different backends.
At [Piwik](http://piwik.org) we developed this library with the focus on speed as we make heavy use of caching and
sometimes fetch hundreds of entries from the cache in one request.
[![Build Status](https://travis-ci.org/piwik/component-cache.svg?branch=master)](https://travis-ci.org/piwik/component-cache)
[![Coverage Status](https://coveralls.io/repos/piwik/component-cache/badge.png?branch=master)](https://coveralls.io/r/piwik/component-cache?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/piwik/component-cache/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/piwik/component-cache/?branch=master)
## Installation
With Composer:
```json
{
"require": {
"piwik/cache": "*"
}
}
```
## Supported backends
* Array (holds cache entries only during one request but is very fast)
* Null (useful for development, won't cache anything)
* File (stores the cache entry on the file system)
* Redis (stores the cache entry on a Redis server, requires [phpredis](https://github.com/nicolasff/phpredis))
* Chained (allows to chain multiple backends to make sure it will read from a fast cache if possible)
Doctrine cache provides support for many more backends and adding one of those is easy. For example:
* APC
* Couchbase
* Memcache
* MongoDB
* Riak
* WinCache
* Xcache
* ZendData
Please send a pull request in case you have added one.
## Different caches
This library comes with three different types of caches. The naming is not optimal right now.
### Lazy
This can be considered as the default cache to use in case you don't know which one to pick. The lazy cache works with
any backend so you can decide whether you want to persist cache entries between requests or not. It does not support
the caching of any objects. Only boolean, numbers, strings and arrays are supported. Whenever you request an entry
from the cache it will fetch the entry from the defined backend again which can cause many reads depending on your
application.
### Eager
This cache stores all its cache entries under one "cache" entry in a configurable backend.
This comes handy for things that you need very often, nearly in every request. Instead of having to read eg.
a hundred cache entries from files it only loads one cache entry which contains the hundred keys. Should be used only
for things that you need very often and only for cache entries that are not too large to keep loading and parsing the
single cache entry fast. This cache is even more useful in case you are using a slow backend such as a file or a database.
Instead of having a hundred stat calls there will be only one. All cache entries it contains have the same life time.
For fast performance it won't validate any cache ids. It is not possible to cache any objects using this cache.
### Transient
This class is used to cache any data during one request. It won't be persisted.
All cache entries will be cached in a simple array meaning it is very fast to save and fetch cache entries. You can
basically achieve the same by using a lazy cache and a backend that does not persist any data such as the array cache
but this one will be a bit faster as it won't validate any cache ids and it allows you to cache any kind of objects.
Compared to the lazy cache it does not support setting any life time as it will be only valid during one request anyway.
Use this one if you read hundreds or thousands of cache entries and if performance really matters to you.
## Usage
### Creating a file backend
```php
$options = array('directory' => '/path/to/cache');
$factory = new \Piwik\Cache\Backend\Factory();
$backend = $factory->buildBackend('file', $options);
```
### Creating a Redis backend
```php
$options = array(
'host' => '127.0.0.1',
'port' => '6379',
'timeout' => 0.0,
'database' => 15, // optional
'password' => 'secret', // optional
);
$factory = new \Piwik\Cache\Backend\Factory();
$backend = $factory->buildBackend('redis', $options);
```
### Creating a chained backend
```php
$options = array(
'backends' => array('array', 'file'),
'file' => array('directory' => '/path/to/cache')
);
$factory = new \Piwik\Cache\Backend\Factory();
$backend = $factory->buildBackend('redis', $options);
```
Whenever you set a cache entry it will save it in the array and in the file cache. Whenever you are trying to read a cache
entry it will first try to get it from the fast array cache. In case it is not available there it will try to fetch
the cache entry from the file system. If the cache entry exists on the file system it will cache the entry automatically
using the array cache so the next read within this request will be fast and won't cause a stat call again. If you delete
a cache entry it will be removed from all configured backends. You can chain any backends. It is recommended to list
faster backends first.
### Creating a lazy cache
[Description lazy cache.](#lazy)
```php
$factory = new \Piwik\Cache\Backend\Factory();
$backend = $factory->buildBackend('file', array('directory' => '/path/to/cache'));
$cache = new \Piwik\Cache\Lazy($backend);
$cache->fetch('myid');
$cache->contains('myid');
$cache->delete('myid');
$cache->save('myid', 'myvalue', $lifeTimeInSeconds = 300);
$cache->flushAll();
```
### Creating an eager cache
[Description eager cache.](#eager)
```php
$cache = new \Piwik\Cache\Eager($backend, $storageId = 'eagercache');
$cache->fetch('myid');
$cache->contains('myid');
$cache->delete('myid');
$cache->save('myid', new \stdClass());
$cache->persistCacheIfNeeded($lifeTimeInSeconds = 300);
$cache->flushAll();
```
It will cache all set cache entries under the cache entry `eagercache`.
### Creating a transient cache
[Description transient cache.](#transient)
```php
$cache = new \Piwik\Cache\Transient();
$cache->fetch('myid');
$cache->contains('myid');
$cache->delete('myid');
$cache->save('myid', new \stdClass());
$cache->flushAll();
```
## License
The Cache component is released under the [LGPL v3.0](http://choosealicense.com/licenses/lgpl-3.0/).
## Changelog
* 0.2.5: updating to doctrine/cache 1.4 which contains our fix
* 0.2.4: do not throw exception when clearing a file cache if the cache dir doesn't exist
* 0.2.3: fixed another race condition in file cache
* 0.2.2: fixed a race condition in file cache
* 0.2.0: Initial release

View file

@ -0,0 +1,31 @@
{
"name": "piwik/cache",
"type": "library",
"license": "LGPL-3.0",
"description": "PHP caching library based on Doctrine cache",
"keywords": ["cache","array","file","redis"],
"authors": [
{
"name": "The Piwik Team",
"email": "hello@piwik.org",
"homepage": "http://piwik.org/the-piwik-team/"
}
],
"autoload": {
"psr-4": {
"Piwik\\Cache\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Piwik\\Cache\\": "tests/"
}
},
"require": {
"php": ">=5.3.2",
"doctrine/cache": "~1.4"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
}
}

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="Test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -0,0 +1,62 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache;
/**
* Backend interface
*/
interface Backend
{
/**
* Fetches an entry from the cache.
*
* @param string $id The id of the cache entry to fetch.
*
* @return mixed The cached data or FALSE, if no cache entry exists for the given id.
*/
public function doFetch($id);
/**
* Tests if an entry exists in the cache.
*
* @param string $id The cache id of the entry to check for.
*
* @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
*/
public function doContains($id);
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param mixed $data The cache entry/data.
* @param int $lifeTime The cache lifetime.
* If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
*
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
*/
public function doSave($id, $data, $lifeTime = 0);
/**
* Deletes a cache entry.
*
* @param string $id The cache id.
*
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
*/
public function doDelete($id);
/**
* Flushes all cache entries from the cache.
*
* @return boolean
*/
public function doFlush();
}

View file

@ -0,0 +1,46 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache\Backend;
use Piwik\Cache\Backend;
use Doctrine\Common\Cache\ArrayCache as DoctrineArrayCache;
class ArrayCache extends DoctrineArrayCache implements Backend
{
public function doFetch($id)
{
return parent::doFetch($id);
}
public function doContains($id)
{
return parent::doContains($id);
}
public function doSave($id, $data, $lifeTime = 0)
{
return parent::doSave($id, $data, $lifeTime);
}
public function doDelete($id)
{
if (!$this->doContains($id)) {
return false;
}
return parent::doDelete($id);
}
public function doFlush()
{
return parent::doFlush();
}
}

View file

@ -0,0 +1,103 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache\Backend;
use Piwik\Cache\Backend;
/**
* TODO: extend Doctrine ChainCache as soon as available
*/
class Chained implements Backend
{
/**
* @var Backend[]
*/
private $backends = array();
/**
* Initializes the chained backend.
*
* @param Backend[] $backends An array of backends to use. They should be ordered from fastest to slowest.
*/
public function __construct($backends = array())
{
$this->backends = array_values($backends);
}
public function getBackends()
{
return $this->backends;
}
public function doFetch($id)
{
foreach ($this->backends as $key => $backend) {
if ($backend->doContains($id)) {
$value = $backend->doFetch($id);
// EG If chain is ARRAY => REDIS => DB and we find result in DB we will update REDIS and ARRAY
for ($subKey = $key - 1 ; $subKey >= 0 ; $subKey--) {
$this->backends[$subKey]->doSave($id, $value, 300); // TODO we should use the actual TTL here
}
return $value;
}
}
return false;
}
public function doContains($id)
{
foreach ($this->backends as $backend) {
if ($backend->doContains($id)) {
return true;
}
}
return false;
}
public function doSave($id, $data, $lifeTime = 0)
{
$stored = true;
foreach ($this->backends as $backend) {
$stored = $backend->doSave($id, $data, $lifeTime) && $stored;
}
return $stored;
}
// returns true if was deleted from at least one backend, false if it was not present in any of those
public function doDelete($id)
{
$success = false;
foreach ($this->backends as $backend) {
if ($backend->doContains($id)) {
$success = $backend->doDelete($id) || $success;
}
}
return $success;
}
public function doFlush()
{
$flushed = true;
foreach ($this->backends as $backend) {
$flushed = $backend->doFlush() && $flushed;
}
return $flushed;
}
}

View file

@ -0,0 +1,111 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache\Backend;
use Piwik\Cache\Backend;
class Factory
{
public function buildArrayCache()
{
return new ArrayCache();
}
public function buildFileCache($options)
{
return new File($options['directory']);
}
public function buildNullCache()
{
return new NullCache();
}
public function buildChainedCache($options)
{
$backends = array();
foreach ($options['backends'] as $backendToBuild) {
$backendOptions = array();
if (array_key_exists($backendToBuild, $options)) {
$backendOptions = $options[$backendToBuild];
}
$backends[] = $this->buildBackend($backendToBuild, $backendOptions);
}
return new Chained($backends);
}
public function buildRedisCache($options)
{
if (empty($options['host']) || empty($options['port'])) {
throw new \InvalidArgumentException('RedisCache is not configured. Please provide at least a host and a port');
}
$timeout = 0.0;
if (array_key_exists('timeout', $options)) {
$timeout = $options['timeout'];
}
$redis = new \Redis();
$redis->connect($options['host'], $options['port'], $timeout);
if (!empty($options['password'])) {
$redis->auth($options['password']);
}
if (array_key_exists('database', $options)) {
$redis->select((int) $options['database']);
}
$redisCache = new Redis();
$redisCache->setRedis($redis);
return $redisCache;
}
/**
* Build a specific backend instance.
*
* @param string $type The type of backend you want to create. Eg 'array', 'file', 'chained', 'null', 'redis'.
* @param array $options An array of options for the backend you want to create.
* @return Backend
* @throws Factory\BackendNotFoundException In case the given type was not found.
*/
public function buildBackend($type, array $options)
{
switch ($type) {
case 'array':
return $this->buildArrayCache();
case 'file':
return $this->buildFileCache($options);
case 'chained':
return $this->buildChainedCache($options);
case 'null':
return $this->buildNullCache();
case 'redis':
return $this->buildRedisCache($options);
default:
throw new Factory\BackendNotFoundException("Cache backend $type not valid");
}
}
}

View file

@ -0,0 +1,15 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache\Backend\Factory;
use \Exception;
class BackendNotFoundException extends Exception {
}

View file

@ -0,0 +1,155 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache\Backend;
use Doctrine\Common\Cache\PhpFileCache;
use Piwik\Cache\Backend;
/**
* This class is used to cache data on the filesystem.
*
* This cache creates one file per id. Every time you try to read the value it will load the cache file again. It will
* try to invalidate the Opcache for a specific cache file if needed.
*/
class File extends PhpFileCache implements Backend
{
// for testing purposes since tests run on both CLI/FPM (changes in CLI can't invalidate
// opcache in FPM, so we have to invalidate before reading)
public static $invalidateOpCacheBeforeRead = false;
/**
* Constructor.
*
* @param string $directory The cache directory.
* @param string|null $extension The cache file extension.
*
* @throws \InvalidArgumentException
*/
public function __construct($directory, $extension = '.php')
{
if (!is_dir($directory)) {
$this->createDirectory($directory);
}
parent::__construct($directory, $extension);
}
public function doFetch($id)
{
if (self::$invalidateOpCacheBeforeRead) {
$this->invalidateCacheFile($id);
}
return parent::doFetch($id);
}
public function doContains($id)
{
return parent::doContains($id);
}
public function doSave($id, $data, $lifeTime = 0)
{
if (!is_dir($this->directory)) {
$this->createDirectory($this->directory);
}
$success = parent::doSave($id, $data, $lifeTime);
if ($success) {
$this->invalidateCacheFile($id);
}
return $success;
}
public function doDelete($id)
{
$this->invalidateCacheFile($id);
$success = parent::doDelete($id);
$this->invalidateCacheFile($id); // in case file was cached by another request between invalidate and doDelete()
return $success;
}
public function doFlush()
{
// if the directory does not exist, do not bother to continue clearing
if (!is_dir($this->directory)) {
return;
}
foreach ($this->getFileIterator() as $name => $file) {
$this->opCacheInvalidate($name);
}
parent::doFlush();
}
private function invalidateCacheFile($id)
{
$filename = $this->getFilename($id);
$this->opCacheInvalidate($filename);
}
/**
* @param string $id
*
* @return string
*/
protected function getFilename($id)
{
$path = $this->directory . DIRECTORY_SEPARATOR;
$id = preg_replace('@[\\\/:"*?<>|]+@', '', $id);
return $path . $id . $this->getExtension();
}
private function opCacheInvalidate($filepath)
{
if (is_file($filepath)) {
if (function_exists('opcache_invalidate')) {
@opcache_invalidate($filepath, $force = true);
}
if (function_exists('apc_delete_file')) {
@apc_delete_file($filepath);
}
}
}
/**
* @return \Iterator
*/
private function getFileIterator()
{
$pattern = '/^.+\\' . $this->getExtension() . '$/i';
$iterator = new \RecursiveDirectoryIterator($this->directory);
$iterator = new \RecursiveIteratorIterator($iterator);
return new \RegexIterator($iterator, $pattern);
}
private function createDirectory($path)
{
if (!is_dir($path)) {
// the mode in mkdir is modified by the current umask
@mkdir($path, 0750, $recursive = true);
}
// try to overcome restrictive umask (mis-)configuration
if (!is_writable($path)) {
@chmod($path, 0755);
if (!is_writable($path)) {
@chmod($path, 0775);
// enough! we're not going to make the directory world-writeable
}
}
}
}

View file

@ -0,0 +1,44 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache\Backend;
use Piwik\Cache\Backend;
/**
* Can be used in development to prevent caching. Does not cache anything.
*/
class NullCache implements Backend
{
public function doFetch($id)
{
return false;
}
public function doContains($id)
{
return false;
}
public function doSave($id, $data, $lifeTime = 0)
{
return true;
}
public function doDelete($id)
{
return true;
}
public function doFlush()
{
return true;
}
}

View file

@ -0,0 +1,41 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache\Backend;
use Doctrine\Common\Cache\RedisCache;
use Piwik\Cache\Backend;
class Redis extends RedisCache implements Backend
{
public function doFetch($id)
{
return parent::doFetch($id);
}
public function doContains($id)
{
return parent::doContains($id);
}
public function doSave($id, $data, $lifeTime = 0)
{
return parent::doSave($id, $data, $lifeTime);
}
public function doDelete($id)
{
return parent::doDelete($id);
}
public function doFlush()
{
return parent::doFlush();
}
}

View file

@ -0,0 +1,55 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache;
interface Cache
{
/**
* Fetches an entry from the cache.
*
* @param string $id The cache id.
* @return mixed The cached data or FALSE, if no cache entry exists for the given id.
*/
public function fetch($id);
/**
* Tests if an entry exists in the cache.
*
* @param string $id The cache id.
* @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
*/
public function contains($id);
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param mixed $data The cache entry/data.
* @param int $lifeTime The cache lifetime in seconds.
* If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
*
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
*/
public function save($id, $data, $lifeTime = 0);
/**
* Deletes a cache entry.
*
* @param string $id The cache id.
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
*/
public function delete($id);
/**
* Flushes all cache entries.
*
* @return boolean TRUE if the cache entries were successfully flushed, FALSE otherwise.
*/
public function flushAll();
}

View file

@ -0,0 +1,138 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache;
use Piwik\Cache\Backend;
/**
* This cache uses one "cache" entry for all cache entries it contains.
*
* This comes handy for things that you need very often, nearly in every request. Instead of having to read eg.
* a hundred caches from file we only load one file which contains the hundred cache ids. Should be used only for things
* that you need very often and only for cache entries that are not too large to keep loading and parsing the single
* cache entry fast.
*
* $cache = new Eager($backend, $storageId = 'eagercache');
* // $cache->fetch('my'id')
* // $cache->save('myid', 'test');
*
* // ... at some point or at the end of the request
* $cache->persistCacheIfNeeded($lifeTime = 43200);
*/
class Eager implements Cache
{
/**
* @var Backend
*/
private $storage;
private $storageId;
private $content = array();
private $isDirty = false;
/**
* Loads the cache entries from the given backend using the given storageId.
*
* @param Backend $storage
* @param $storageId
*/
public function __construct(Backend $storage, $storageId)
{
$this->storage = $storage;
$this->storageId = $storageId;
$content = $storage->doFetch($storageId);
if (is_array($content)) {
$this->content = $content;
}
}
/**
* Fetches an entry from the cache.
*
* Make sure to call the method {@link contains()} to verify whether there is actually any content saved under
* this cache id.
*
* @param string $id The cache id.
* @return int|float|string|boolean|array
*/
public function fetch($id)
{
return $this->content[$id];
}
/**
* {@inheritdoc}
*/
public function contains($id)
{
return array_key_exists($id, $this->content);
}
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param int|float|string|boolean|array $content
* @param int $lifeTime Setting a lifetime is not supported by this cache and the parameter will be ignored.
* @return boolean
*/
public function save($id, $content, $lifeTime = 0)
{
if (is_object($content)) {
throw new \InvalidArgumentException('You cannot use this cache to cache an object, only arrays, strings and numbers. Have a look at Transient cache.');
// for performance reasons we do currently not recursively search whether any array contains an object.
}
$this->content[$id] = $content;
$this->isDirty = true;
return true;
}
/**
* {@inheritdoc}
*/
public function delete($id)
{
if ($this->contains($id)) {
$this->isDirty = true;
unset($this->content[$id]);
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
public function flushAll()
{
$this->storage->doDelete($this->storageId);
$this->content = array();
$this->isDirty = false;
return true;
}
/**
* Will persist all previously made changes if there were any.
*
* @param int $lifeTime The cache lifetime in seconds.
* If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
*/
public function persistCacheIfNeeded($lifeTime)
{
if ($this->isDirty) {
$this->storage->doSave($this->storageId, $this->content, $lifeTime);
}
}
}

View file

@ -0,0 +1,121 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache;
use Piwik\Cache\Backend;
class Lazy implements Cache
{
private $backend;
/**
* Initializes the cache.
*
* @param Backend $backend Any backend that should be used to store / hold the cache entries.
*/
public function __construct(Backend $backend)
{
$this->backend = $backend;
}
/**
* Fetches an entry from the cache.
*
* @param string $id The cache id.
* @return mixed The cached data or FALSE, if no cache entry exists for the given id.
*/
public function fetch($id)
{
$id = $this->getCompletedCacheIdIfValid($id);
return $this->backend->doFetch($id);
}
/**
* {@inheritdoc}
*/
public function contains($id)
{
$id = $this->getCompletedCacheIdIfValid($id);
return $this->backend->doContains($id);
}
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param mixed $data The cache entry/data.
* @param int $lifeTime The cache lifetime in seconds.
* If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
*
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
*/
public function save($id, $data, $lifeTime = 0)
{
$id = $this->getCompletedCacheIdIfValid($id);
if (is_object($data)) {
throw new \InvalidArgumentException('You cannot use this cache to cache an object, only arrays, strings and numbers. Have a look at Transient cache.');
// for performance reasons we do currently not recursively search whether any array contains an object.
}
return $this->backend->doSave($id, $data, $lifeTime);
}
/**
* {@inheritdoc}
*/
public function delete($id)
{
$id = $this->getCompletedCacheIdIfValid($id);
return $this->backend->doDelete($id);
}
/**
* {@inheritdoc}
*/
public function flushAll()
{
return $this->backend->doFlush();
}
private function getCompletedCacheIdIfValid($id)
{
$this->checkId($id);
return 'piwikcache_' . $id;
}
private function checkId($id)
{
if (empty($id)) {
throw new \InvalidArgumentException('Empty cache id given');
}
if (!$this->isValidId($id)) {
throw new \InvalidArgumentException("Invalid cache id request $id");
}
}
/**
* Returns true if the string is a valid id.
*
* Id that start with a-Z or 0-9 and contain a-Z, 0-9, underscore(_), dash(-), and dot(.) will be accepted.
* Id beginning with anything but a-Z or 0-9 will be rejected (including .htaccess for example).
* Id containing anything other than above mentioned will also be rejected (file names with spaces won't be accepted).
*
* @param string $id
* @return bool
*/
private function isValidId($id)
{
return (0 !== preg_match('/(^[a-zA-Z0-9]+([a-zA-Z_0-9.-]*))$/D', $id));
}
}

View file

@ -0,0 +1,89 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Piwik\Cache;
use Piwik\Cache\Backend;
/**
* This class is used to cache data during one request.
*
* Compared to the lazy cache it does not support setting any lifetime. To be a fast cache it does
* not validate any cache id etc.
*/
class Transient implements Cache
{
/**
* @var array $data
*/
private $data = array();
/**
* Fetches an entry from the cache.
*
* Make sure to call the method {@link has()} to verify whether there is actually any content set under this
* cache id.
*
* @param string $id The cache id.
* @return mixed
*/
public function fetch($id)
{
if ($this->contains($id)) {
return $this->data[$id];
}
return false;
}
/**
* {@inheritdoc}
*/
public function contains($id)
{
return isset($this->data[$id]) || array_key_exists($id, $this->data);
}
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param mixed $content
* @param int $lifeTime Setting a lifetime is not supported by this cache and the parameter will be ignored.
* @return boolean
*/
public function save($id, $content, $lifeTime = 0)
{
$this->data[$id] = $content;
return true;
}
/**
* {@inheritdoc}
*/
public function delete($id)
{
if (!$this->contains($id)) {
return false;
}
unset($this->data[$id]);
return true;
}
/**
* {@inheritdoc}
*/
public function flushAll()
{
$this->data = array();
return true;
}
}

View file

@ -0,0 +1,50 @@
# Piwik/Decompress
Component providing several adapters to decompress files.
[![Build Status](https://travis-ci.org/piwik/component-decompress.svg?branch=master)](https://travis-ci.org/piwik/component-decompress)
[![Coverage Status](https://coveralls.io/repos/piwik/component-decompress/badge.png?branch=master)](https://coveralls.io/r/piwik/component-decompress?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/piwik/component-decompress/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/piwik/component-decompress/?branch=master)
It supports the following compression formats:
- Zip
- Gzip
- Tar (gzip or bzip)
With the following adapters:
- `PclZip`, based on the [PclZip library](http://www.phpconcept.net/pclzip/)
- `ZipArchive`, based on PHP's [Zip extension](http://fr.php.net/manual/en/book.zip.php)
- `Gzip`, based on PHP's native Gzip functions
- `Tar`, based on the [Archive_Tar library](https://github.com/pear/Archive_Tar) from PEAR
## Installation
With Composer:
```json
{
"require": {
"piwik/decompress": "*"
}
}
```
## Usage
All adapters have the same API as they implement `Piwik\Decompress\DecompressInterface`:
```php
$extractor = new \Piwik\Decompress\Gzip('file.gz');
$extractedFiles = $extractor->extract('some/directory');
if ($extractedFiles === 0) {
echo $extractor->errorInfo();
}
```
## License
The Decompress component is released under the [LGPL v3.0](http://choosealicense.com/licenses/lgpl-3.0/).

View file

@ -0,0 +1,23 @@
{
"name": "piwik/decompress",
"type": "library",
"license": "LGPL-3.0",
"autoload": {
"psr-4": {
"Piwik\\Decompress\\": "src/"
},
"classmap": ["libs/PclZip"]
},
"autoload-dev": {
"psr-4": {
"Tests\\Piwik\\Decompress\\": "tests/"
}
},
"require": {
"php": ">=5.3.2",
"pear/archive_tar": "~1.3,>=1.3.15"
},
"require-dev": {
"phpunit/phpunit": "~4.5"
}
}

View file

@ -0,0 +1,504 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,421 @@
// --------------------------------------------------------------------------------
// PclZip 2.8.2 - readme.txt
// --------------------------------------------------------------------------------
// License GNU/LGPL - August 2009
// Vincent Blavet - vincent@phpconcept.net
// http://www.phpconcept.net
// --------------------------------------------------------------------------------
// $Id: readme.txt,v 1.60 2009/09/30 20:35:21 vblavet Exp $
// --------------------------------------------------------------------------------
0 - Sommaire
============
1 - Introduction
2 - What's new
3 - Corrected bugs
4 - Known bugs or limitations
5 - License
6 - Warning
7 - Documentation
8 - Author
9 - Contribute
1 - Introduction
================
PclZip is a library that allow you to manage a Zip archive.
Full documentation about PclZip can be found here : http://www.phpconcept.net/pclzip
2 - What's new
==============
Version 2.8.2 :
- PCLZIP_CB_PRE_EXTRACT and PCLZIP_CB_POST_EXTRACT are now supported with
extraction as a string (PCLZIP_OPT_EXTRACT_AS_STRING). The string
can also be modified in the post-extract call back.
**Bugs correction :
- PCLZIP_OPT_REMOVE_ALL_PATH was not working correctly
- Remove use of eval() and do direct call to callback functions
- Correct support of 64bits systems (Thanks to WordPress team)
Version 2.8.1 :
- Move option PCLZIP_OPT_BY_EREG to PCLZIP_OPT_BY_PREG because ereg() is
deprecated in PHP 5.3. When using option PCLZIP_OPT_BY_EREG, PclZip will
automatically replace it by PCLZIP_OPT_BY_PREG.
Version 2.8 :
- Improve extraction of zip archive for large files by using temporary files
This feature is working like the one defined in r2.7.
Options are renamed : PCLZIP_OPT_TEMP_FILE_ON, PCLZIP_OPT_TEMP_FILE_OFF,
PCLZIP_OPT_TEMP_FILE_THRESHOLD
- Add a ratio constant PCLZIP_TEMPORARY_FILE_RATIO to configure the auto
sense of temporary file use.
- Bug correction : Reduce filepath in returned file list to remove ennoying
'.//' preambule in file path.
Version 2.7 :
- Improve creation of zip archive for large files :
PclZip will now autosense the configured memory and use temporary files
when large file is suspected.
This feature can also ne triggered by manual options in create() and add()
methods. 'PCLZIP_OPT_ADD_TEMP_FILE_ON' force the use of temporary files,
'PCLZIP_OPT_ADD_TEMP_FILE_OFF' disable the autosense technic,
'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD' allow for configuration of a size
threshold to use temporary files.
Using "temporary files" rather than "memory" might take more time, but
might give the ability to zip very large files :
Tested on my win laptop with a 88Mo file :
Zip "in-memory" : 18sec (max_execution_time=30, memory_limit=180Mo)
Zip "tmporary-files" : 23sec (max_execution_time=30, memory_limit=30Mo)
- Replace use of mktime() by time() to limit the E_STRICT error messages.
- Bug correction : When adding files with full windows path (drive letter)
PclZip is now working. Before, if the drive letter is not the default
path, PclZip was not able to add the file.
Version 2.6 :
- Code optimisation
- New attributes PCLZIP_ATT_FILE_COMMENT gives the ability to
add a comment for a specific file. (Don't really know if this is usefull)
- New attribute PCLZIP_ATT_FILE_CONTENT gives the ability to add a string
as a file.
- New attribute PCLZIP_ATT_FILE_MTIME modify the timestamp associated with
a file.
- Correct a bug. Files archived with a timestamp with 0h0m0s were extracted
with current time
- Add CRC value in the informations returned back for each file after an
action.
- Add missing closedir() statement.
- When adding a folder, and removing the path of this folder, files were
incorrectly added with a '/' at the beginning. Which means files are
related to root in unix systems. Corrected.
- Add conditional if before constant definition. This will allow users
to redefine constants without changing the file, and then improve
upgrade of pclzip code for new versions.
Version 2.5 :
- Introduce the ability to add file/folder with individual properties (file descriptor).
This gives for example the ability to change the filename of a zipped file.
. Able to add files individually
. Able to change full name
. Able to change short name
. Compatible with global options
- New attributes : PCLZIP_ATT_FILE_NAME, PCLZIP_ATT_FILE_NEW_SHORT_NAME, PCLZIP_ATT_FILE_NEW_FULL_NAME
- New error code : PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE
- Add a security control feature. PclZip can extract any file in any folder
of a system. People may use this to upload a zip file and try to override
a system file. The PCLZIP_OPT_EXTRACT_DIR_RESTRICTION will give the
ability to forgive any directory transversal behavior.
- New PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : check extraction path
- New error code : PCLZIP_ERR_DIRECTORY_RESTRICTION
- Modification in PclZipUtilPathInclusion() : dir and path beginning with ./ will be prepend
by current path (getcwd())
Version 2.4 :
- Code improvment : try to speed up the code by removing unusefull call to pack()
- Correct bug in delete() : delete() should be called with no argument. This was not
the case in 2.3. This is corrected in 2.4.
- Correct a bug in path_inclusion function. When the path has several '../../', the
result was bad.
- Add a check for magic_quotes_runtime configuration. If enabled, PclZip will
disable it while working and det it back to its original value.
This resolve a lots of bad formated archive errors.
- Bug correction : PclZip now correctly unzip file in some specific situation,
when compressed content has same size as uncompressed content.
- Bug correction : When selecting option 'PCLZIP_OPT_REMOVE_ALL_PATH',
directories are not any more created.
- Code improvment : correct unclosed opendir(), better handling of . and .. in
loops.
Version 2.3 :
- Correct a bug with PHP5 : affecting the value 0xFE49FFE0 to a variable does not
give the same result in PHP4 and PHP5 ....
Version 2.2 :
- Try development of PCLZIP_OPT_CRYPT .....
However this becomes to a stop. To crypt/decrypt I need to multiply 2 long integers,
the result (greater than a long) is not supported by PHP. Even the use of bcmath
functions does not help. I did not find yet a solution ...;
- Add missing '/' at end of directory entries
- Check is a file is encrypted or not. Returns status 'unsupported_encryption' and/or
error code PCLZIP_ERR_UNSUPPORTED_ENCRYPTION.
- Corrected : Bad "version need to extract" field in local file header
- Add private method privCheckFileHeaders() in order to check local and central
file headers. PclZip is now supporting purpose bit flag bit 3. Purpose bit flag bit 3 gives
the ability to have a local file header without size, compressed size and crc filled.
- Add a generic status 'error' for file status
- Add control of compression type. PclZip only support deflate compression method.
Before v2.2, PclZip does not check the compression method used in an archive while
extracting. With v2.2 PclZip returns a new error status for a file using an unsupported
compression method. New status is "unsupported_compression". New error code is
PCLZIP_ERR_UNSUPPORTED_COMPRESSION.
- Add optional attribute PCLZIP_OPT_STOP_ON_ERROR. This will stop the extract of files
when errors like 'a folder with same name exists' or 'a newer file exists' or
'a write protected file' exists, rather than set a status for the concerning file
and resume the extract of the zip.
- Add optional attribute PCLZIP_OPT_REPLACE_NEWER. This will force, during an extract' the
replacement of the file, even if a newer version of the file exists.
Note that today if a file with the same name already exists but is older it will be
replaced by the extracted one.
- Improve PclZipUtilOption()
- Support of zip archive with trailing bytes. Before 2.2, PclZip checks that the central
directory structure is the last data in the archive. Crypt encryption/decryption of
zip archive put trailing 0 bytes after decryption. PclZip is now supporting this.
Version 2.1 :
- Add the ability to abort the extraction by using a user callback function.
The user can now return the value '2' in its callback which indicates to stop the
extraction. For a pre call-back extract is stopped before the extration of the current
file. For a post call back, the extraction is stopped after.
- Add the ability to extract a file (or several files) directly in the standard output.
This is done by the new parameter PCLZIP_OPT_EXTRACT_IN_OUTPUT with method extract().
- Add support for parameters PCLZIP_OPT_COMMENT, PCLZIP_OPT_ADD_COMMENT,
PCLZIP_OPT_PREPEND_COMMENT. This will create, replace, add, or prepend comments
in the zip archive.
- When merging two archives, the comments are not any more lost, but merged, with a
blank space separator.
- Corrected bug : Files are not deleted when all files are asked to be deleted.
- Corrected bug : Folders with name '0' made PclZip to abort the create or add feature.
Version 2.0 :
***** Warning : Some new features may break the backward compatibility for your scripts.
Please carefully read the readme file.
- Add the ability to delete by Index, name and regular expression. This feature is
performed by the method delete(), which uses the optional parameters
PCLZIP_OPT_BY_INDEX, PCLZIP_OPT_BY_NAME, PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG.
- Add the ability to extract by regular expression. To extract by regexp you must use the method
extract(), with the option PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG
(depending if you want to use ereg() or preg_match() syntax) followed by the
regular expression pattern.
- Add the ability to extract by index, directly with the extract() method. This is a
code improvment of the extractByIndex() method.
- Add the ability to extract by name. To extract by name you must use the method
extract(), with the option PCLZIP_OPT_BY_NAME followed by the filename to
extract or an array of filenames to extract. To extract all a folder, use the folder
name rather than the filename with a '/' at the end.
- Add the ability to add files without compression. This is done with a new attribute
which is PCLZIP_OPT_NO_COMPRESSION.
- Add the attribute PCLZIP_OPT_EXTRACT_AS_STRING, which allow to extract a file directly
in a string without using any file (or temporary file).
- Add constant PCLZIP_SEPARATOR for static configuration of filename separators in a single string.
The default separator is now a comma (,) and not any more a blank space.
THIS BREAK THE BACKWARD COMPATIBILITY : Please check if this may have an impact with
your script.
- Improve algorythm performance by removing the use of temporary files when adding or
extracting files in an archive.
- Add (correct) detection of empty filename zipping. This can occurs when the removed
path is the same
as a zipped dir. The dir is not zipped (['status'] = filtered), only its content.
- Add better support for windows paths (thanks for help from manus@manusfreedom.com).
- Corrected bug : When the archive file already exists with size=0, the add() method
fails. Corrected in 2.0.
- Remove the use of OS_WINDOWS constant. Use php_uname() function rather.
- Control the order of index ranges in extract by index feature.
- Change the internal management of folders (better handling of internal flag).
Version 1.3 :
- Removing the double include check. This is now done by include_once() and require_once()
PHP directives.
- Changing the error handling mecanism : Remove the use of an external error library.
The former PclError...() functions are replaced by internal equivalent methods.
By changing the environment variable PCLZIP_ERROR_EXTERNAL you can still use the former library.
Introducing the use of constants for error codes rather than integer values. This will help
in futur improvment.
Introduction of error handling functions like errorCode(), errorName() and errorInfo().
- Remove the deprecated use of calling function with arguments passed by reference.
- Add the calling of extract(), extractByIndex(), create() and add() functions
with variable options rather than fixed arguments.
- Add the ability to remove all the file path while extracting or adding,
without any need to specify the path to remove.
This is available for extract(), extractByIndex(), create() and add() functionS by using
the new variable options parameters :
- PCLZIP_OPT_REMOVE_ALL_PATH : by indicating this option while calling the fct.
- Ability to change the mode of a file after the extraction (chmod()).
This is available for extract() and extractByIndex() functionS by using
the new variable options parameters.
- PCLZIP_OPT_SET_CHMOD : by setting the value of this option.
- Ability to definition call-back options. These call-back will be called during the adding,
or the extracting of file (extract(), extractByIndex(), create() and add() functions) :
- PCLZIP_CB_PRE_EXTRACT : will be called before each extraction of a file. The user
can trigerred the change the filename of the extracted file. The user can triggered the
skip of the extraction. This is adding a 'skipped' status in the file list result value.
- PCLZIP_CB_POST_EXTRACT : will be called after each extraction of a file.
Nothing can be triggered from that point.
- PCLZIP_CB_PRE_ADD : will be called before each add of a file. The user
can trigerred the change the stored filename of the added file. The user can triggered the
skip of the add. This is adding a 'skipped' status in the file list result value.
- PCLZIP_CB_POST_ADD : will be called after each add of a file.
Nothing can be triggered from that point.
- Two status are added in the file list returned as function result : skipped & filename_too_long
'skipped' is used when a call-back function ask for skipping the file.
'filename_too_long' is used while adding a file with a too long filename to archive (the file is
not added)
- Adding the function PclZipUtilPathInclusion(), that check the inclusion of a path into
a directory.
- Add a check of the presence of the archive file before some actions (like list, ...)
- Add the initialisation of field "index" in header array. This means that by
default index will be -1 when not explicitly set by the methods.
Version 1.2 :
- Adding a duplicate function.
- Adding a merge function. The merge function is a "quick merge" function,
it just append the content of an archive at the end of the first one. There
is no check for duplicate files or more recent files.
- Improve the search of the central directory end.
Version 1.1.2 :
- Changing the license of PclZip. PclZip is now released under the GNU / LGPL license
(see License section).
- Adding the optional support of a static temporary directory. You will need to configure
the constant PCLZIP_TEMPORARY_DIR if you want to use this feature.
- Improving the rename() function. In some cases rename() does not work (different
Filesystems), so it will be replaced by a copy() + unlink() functions.
Version 1.1.1 :
- Maintenance release, no new feature.
Version 1.1 :
- New method Add() : adding files in the archive
- New method ExtractByIndex() : partial extract of the archive, files are identified by
their index in the archive
- New method DeleteByIndex() : delete some files/folder entries from the archive,
files are identified by their index in the archive.
- Adding a test of the zlib extension presence. If not present abort the script.
Version 1.0.1 :
- No new feature
3 - Corrected bugs
==================
Corrected in Version 2.0 :
- Corrected : During an extraction, if a call-back fucntion is used and try to skip
a file, all the extraction process is stopped.
Corrected in Version 1.3 :
- Corrected : Support of static synopsis for method extract() is broken.
- Corrected : invalid size of archive content field (0xFF) should be (0xFFFF).
- Corrected : When an extract is done with a remove_path parameter, the entry for
the directory with exactly the same path is not skipped/filtered.
- Corrected : extractByIndex() and deleteByIndex() were not managing index in the
right way. For example indexes '1,3-5,11' will only extract files 1 and 11. This
is due to a sort of the index resulting table that puts 11 before 3-5 (sort on
string and not interger). The sort is temporarilly removed, this means that
you must provide a sorted list of index ranges.
Corrected in Version 1.2 :
- Nothing.
Corrected in Version 1.1.2 :
- Corrected : Winzip is unable to delete or add new files in a PclZip created archives.
Corrected in Version 1.1.1 :
- Corrected : When archived file is not compressed (0% compression), the
extract method fails.
Corrected in Version 1.1 :
- Corrected : Adding a complete tree of folder may result in a bad archive
creation.
Corrected in Version 1.0.1 :
- Corrected : Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
4 - Known bugs or limitations
=============================
Please publish bugs reports in SourceForge :
http://sourceforge.net/tracker/?group_id=40254&atid=427564
In Version 2.x :
- PclZip does only support file uncompressed or compressed with deflate (compression method 8)
- PclZip does not support password protected zip archive
- Some concern were seen when changing mtime of a file while archiving.
Seems to be linked to Daylight Saving Time (PclTest_changing_mtime).
In Version 1.2 :
- merge() methods does not check for duplicate files or last date of modifications.
In Version 1.1 :
- Limitation : Using 'extract' fields in the file header in the zip archive is not supported.
- WinZip is unable to delete a single file in a PclZip created archive. It is also unable to
add a file in a PclZip created archive. (Corrected in v.1.2)
In Version 1.0.1 :
- Adding a complete tree of folder may result in a bad archive
creation. (Corrected in V.1.1).
- Path given to methods must be in the unix format (/) and not the Windows format (\).
Workaround : Use only / directory separators.
- PclZip is using temporary files that are sometime the name of the file with a .tmp or .gz
added suffix. Files with these names may already exist and may be overwritten.
Workaround : none.
- PclZip does not check if the zlib extension is present. If it is absent, the zip
file is not created and the lib abort without warning.
Workaround : enable the zlib extension on the php install
In Version 1.0 :
- Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
(Corrected in v.1.0.1)
- Limitation : Multi-disk zip archive are not supported.
5 - License
===========
Since version 1.1.2, PclZip Library is released under GNU/LGPL license.
This library is free, so you can use it at no cost.
HOWEVER, if you release a script, an application, a library or any kind of
code using PclZip library (or a part of it), YOU MUST :
- Indicate in the documentation (or a readme file), that your work
uses PclZip Library, and make a reference to the author and the web site
http://www.phpconcept.net
- Gives the ability to the final user to update the PclZip libary.
I will also appreciate that you send me a mail (vincent@phpconcept.net), just to
be aware that someone is using PclZip.
For more information about GNU/LGPL license : http://www.gnu.org
6 - Warning
=================
This library and the associated files are non commercial, non professional work.
It should not have unexpected results. However if any damage is caused by this software
the author can not be responsible.
The use of this software is at the risk of the user.
7 - Documentation
=================
PclZip User Manuel is available in English on PhpConcept : http://www.phpconcept.net/pclzip/man/en/index.php
A Russian translation was done by Feskov Kuzma : http://php.russofile.ru/ru/authors/unsort/zip/
8 - Author
==========
This software was written by Vincent Blavet (vincent@phpconcept.net) on its leasure time.
9 - Contribute
==============
If you want to contribute to the development of PclZip, please contact vincent@phpconcept.net.
If you can help in financing PhpConcept hosting service, please go to
http://www.phpconcept.net/soutien.php

View file

@ -0,0 +1,10 @@
## Piwik modifications to libs/
In general, bug fixes and improvements are reported upstream. Until these are
included upstream, we maintain a list of bug fixes and local mods made to
third-party libraries:
* PclZip/
- line 1720, added possibility to define a callable for `PCLZIP_CB_PRE_EXTRACT`. Before one needed to pass a function name
- line 3676, ignore touch() - utime failed warning
- line 5401, replaced `php_uname()` by `PHP_OS` (see [#2](https://github.com/piwik/component-decompress/issues/2))

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
phpunit -c phpunit.xml
-->
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="Test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -0,0 +1,38 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*/
namespace Piwik\Decompress;
/**
* Interface of a class that can decompress files.
*/
interface DecompressInterface
{
/**
* Constructor
*
* @param string $filename Name of the archive
*/
public function __construct($filename);
/**
* Extract files from the archive to the target directory
*
* @param string $pathExtracted Absolute path of target directory
*
* @return mixed Array of file names if successful; or 0 if an error occurred
*/
public function extract($pathExtracted);
/**
* Get error description for the latest error
*
* @return string
*/
public function errorInfo();
}

View file

@ -0,0 +1,80 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*/
namespace Piwik\Decompress;
/**
* Unzip implementation for .gz files.
*/
class Gzip implements DecompressInterface
{
/**
* Name of .gz file.
*
* @var string
*/
private $filename = null;
/**
* Error string.
*
* @var string
*/
private $error = null;
/**
* Constructor.
*
* @param string $filename Name of .gz file.
*/
public function __construct($filename)
{
$this->filename = $filename;
}
/**
* Extracts the contents of the .gz file to $pathExtracted.
*
* @param string $pathExtracted Must be file, not directory.
* @return bool true if successful, false if otherwise.
*/
public function extract($pathExtracted)
{
$file = gzopen($this->filename, 'r');
if ($file === false) {
$this->error = "gzopen failed";
return false;
}
$output = fopen($pathExtracted, 'w');
while (!feof($file)) {
fwrite($output, fread($file, 1024 * 1024));
}
fclose($output);
$success = gzclose($file);
if (false === $success) {
$this->error = "gzclose failed";
return false;
}
return true;
}
/**
* Get error status string for the latest error.
*
* @return string
*/
public function errorInfo()
{
return $this->error;
}
}

View file

@ -0,0 +1,82 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*/
namespace Piwik\Decompress;
/**
* Unzip wrapper around PclZip
*/
class PclZip implements DecompressInterface
{
/**
* @var \PclZip
*/
private $pclzip;
/**
* @var string
*/
public $filename;
/**
* Constructor
*
* @param string $filename Name of the .zip archive
*/
public function __construct($filename)
{
$this->pclzip = new \PclZip($filename);
$this->filename = $filename;
}
/**
* Extract files from archive to target directory
*
* @param string $pathExtracted Absolute path of target directory
* @return mixed Array of filenames if successful; or 0 if an error occurred
*/
public function extract($pathExtracted)
{
$pathExtracted = str_replace('\\', '/', $pathExtracted);
$list = $this->pclzip->listContent();
if (empty($list)) {
return 0;
}
foreach ($list as $entry) {
$filename = str_replace('\\', '/', $entry['stored_filename']);
$parts = explode('/', $filename);
if (!strncmp($filename, '/', 1) ||
array_search('..', $parts) !== false ||
strpos($filename, ':') !== false
) {
return 0;
}
}
// PCLZIP_CB_PRE_EXTRACT callback returns 0 to skip, 1 to resume, or 2 to abort
return $this->pclzip->extract(
PCLZIP_OPT_PATH, $pathExtracted,
PCLZIP_OPT_STOP_ON_ERROR,
PCLZIP_OPT_REPLACE_NEWER,
PCLZIP_CB_PRE_EXTRACT, function ($p_event, &$p_header) use ($pathExtracted) {
return strncmp($p_header['filename'], $pathExtracted, strlen($pathExtracted)) ? 0 : 1;
}
);
}
/**
* Get error status string for the latest error
*
* @return string
*/
public function errorInfo()
{
return $this->pclzip->errorInfo(true);
}
}

View file

@ -0,0 +1,78 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*/
namespace Piwik\Decompress;
use Archive_Tar;
/**
* Unzip implementation for Archive_Tar PEAR lib.
*/
class Tar implements DecompressInterface
{
/**
* Archive_Tar instance.
*
* @var Archive_Tar
*/
private $tarArchive = null;
/**
* Constructor.
*
* @param string $filename Path to tar file.
* @param string|null $compression Either 'gz', 'bz2' or null for no compression.
*/
public function __construct($filename, $compression = null)
{
$this->tarArchive = new Archive_Tar($filename, $compression);
}
/**
* Extracts the contents of the tar file to $pathExtracted.
*
* @param string $pathExtracted Directory to extract into.
* @return bool true if successful, false if otherwise.
*/
public function extract($pathExtracted)
{
return $this->tarArchive->extract($pathExtracted);
}
/**
* Extracts one file held in a tar archive and returns the deflated file
* as a string.
*
* @param string $inArchivePath Path to file in the tar archive.
* @return bool true if successful, false if otherwise.
*/
public function extractInString($inArchivePath)
{
return $this->tarArchive->extractInString($inArchivePath);
}
/**
* Lists the files held in the tar archive.
*
* @return array List of paths describing everything held in the tar archive.
*/
public function listContent()
{
return $this->tarArchive->listContent();
}
/**
* Get error status string for the latest error.
*
* @return string
*/
public function errorInfo()
{
return $this->tarArchive->error_object->getMessage();
}
}

View file

@ -0,0 +1,137 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*/
namespace Piwik\Decompress;
use Exception;
/**
* Unzip wrapper around ZipArchive
*/
class ZipArchive implements DecompressInterface
{
/**
* @var \ZipArchive
*/
private $ziparchive;
/**
* @var string
*/
public $filename;
/**
* Constructor
*
* @param string $filename Name of the .zip archive
* @throws Exception
*/
public function __construct($filename)
{
$this->filename = $filename;
$this->ziparchive = new \ZipArchive;
if ($this->ziparchive->open($filename) !== true) {
throw new Exception('Error opening ' . $filename);
}
}
/**
* Extract files from archive to target directory
*
* @param string $pathExtracted Absolute path of target directory
* @return mixed Array of filenames if successful; or 0 if an error occurred
*/
public function extract($pathExtracted)
{
if (substr($pathExtracted, -1) !== '/') {
$pathExtracted .= '/';
}
$fileselector = array();
$list = array();
$count = $this->ziparchive->numFiles;
if ($count === 0) {
return 0;
}
for ($i = 0; $i < $count; $i++) {
$entry = $this->ziparchive->statIndex($i);
$filename = str_replace('\\', '/', $entry['name']);
$parts = explode('/', $filename);
if (!strncmp($filename, '/', 1) ||
array_search('..', $parts) !== false ||
strpos($filename, ':') !== false
) {
return 0;
}
$fileselector[] = $entry['name'];
$list[] = array(
'filename' => $pathExtracted . $entry['name'],
'stored_filename' => $entry['name'],
'size' => $entry['size'],
'compressed_size' => $entry['comp_size'],
'mtime' => $entry['mtime'],
'index' => $i,
'crc' => $entry['crc'],
);
}
$res = $this->ziparchive->extractTo($pathExtracted, $fileselector);
if ($res === false) {
return 0;
}
return $list;
}
/**
* Get error status string for the latest error
*
* @return string
*/
public function errorInfo()
{
static $statusStrings = array(
\ZipArchive::ER_OK => 'No error',
\ZipArchive::ER_MULTIDISK => 'Multi-disk zip archives not supported',
\ZipArchive::ER_RENAME => 'Renaming temporary file failed',
\ZipArchive::ER_CLOSE => 'Closing zip archive failed',
\ZipArchive::ER_SEEK => 'Seek error',
\ZipArchive::ER_READ => 'Read error',
\ZipArchive::ER_WRITE => 'Write error',
\ZipArchive::ER_CRC => 'CRC error',
\ZipArchive::ER_ZIPCLOSED => 'Containing zip archive was closed',
\ZipArchive::ER_NOENT => 'No such file',
\ZipArchive::ER_EXISTS => 'File already exists',
\ZipArchive::ER_OPEN => 'Can\'t open file',
\ZipArchive::ER_TMPOPEN => 'Failure to create temporary file',
\ZipArchive::ER_ZLIB => 'Zlib error',
\ZipArchive::ER_MEMORY => 'Malloc failure',
\ZipArchive::ER_CHANGED => 'Entry has been changed',
\ZipArchive::ER_COMPNOTSUPP => 'Compression method not supported',
\ZipArchive::ER_EOF => 'Premature EOF',
\ZipArchive::ER_INVAL => 'Invalid argument',
\ZipArchive::ER_NOZIP => 'Not a zip archive',
\ZipArchive::ER_INTERNAL => 'Internal error',
\ZipArchive::ER_INCONS => 'Zip archive inconsistent',
\ZipArchive::ER_REMOVE => 'Can\'t remove file',
\ZipArchive::ER_DELETED => 'Entry has been deleted',
);
if (isset($statusStrings[$this->ziparchive->status])) {
$statusString = $statusStrings[$this->ziparchive->status];
} else {
$statusString = 'Unknown status';
}
return $statusString . '(' . $this->ziparchive->status . ')';
}
}

View file

@ -1,3 +0,0 @@
.idea/*
vendor/*
composer.phar

View file

@ -1,13 +0,0 @@
language: php
php:
- 5.3
- 5.4
- 5.5
before_script:
- composer self-update
- composer install
script:
- phpunit tests/DeviceDetectorTest.php

View file

@ -0,0 +1,22 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Cache;
interface Cache
{
public function fetch($id);
public function contains($id);
public function save($id, $data, $lifeTime = 0);
public function delete($id);
public function flushAll();
}

View file

@ -0,0 +1,53 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Cache;
/**
* Class StaticCache
*
* Simple Cache that caches in a static property
* (Speeds up multiple detections in one request)
*
* @package DeviceDetector\Cache
*/
class StaticCache implements Cache
{
/**
* Holds the static cache data
* @var array
*/
protected static $staticCache = array();
public function fetch($id)
{
return $this->contains($id) ? self::$staticCache[$id] : false;
}
public function contains($id)
{
return isset(self::$staticCache[$id]) || array_key_exists($id, self::$staticCache);
}
public function save($id, $data, $lifeTime = 0)
{
self::$staticCache[$id] = $data;
return true;
}
public function delete($id)
{
unset(self::$staticCache[$id]);
return true;
}
public function flushAll()
{
self::$staticCache = array();
return true;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,72 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser;
/**
* Class Bot
*
* Parses a user agent for bot information
*
* Detected bots are defined in regexes/bots.yml
*
* @package DeviceDetector\Parser
*/
class Bot extends ParserAbstract
{
protected $fixtureFile = 'regexes/bots.yml';
protected $parserName = 'bot';
protected $discardDetails = false;
/**
* Enables information discarding
*/
public function discardDetails()
{
$this->discardDetails = true;
}
/**
* Parses the current UA and checks whether it contains bot information
*
* @see bots.yml for list of detected bots
*
* Step 1: Build a big regex containing all regexes and match UA against it
* -> If no matches found: return
* -> Otherwise:
* Step 2: Walk through the list of regexes in bots.yml and try to match every one
* -> Return the matched data
*
* If $discardDetails is set to TRUE, the Step 2 will be skipped
* $bot will be set to TRUE instead
*
* NOTE: Doing the big match before matching every single regex speeds up the detection
*/
public function parse()
{
$result = null;
if ($this->preMatchOverall()) {
foreach ($this->getRegexes() as $regex) {
$matches = $this->matchUserAgent($regex['regex']);
if ($matches) {
if ($this->discardDetails) {
$result = true;
break;
}
unset($regex['regex']);
$result = $regex;
break;
}
}
}
return $result;
}
}

View file

@ -0,0 +1,263 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client;
use DeviceDetector\Parser\Client\Browser\Engine;
/**
* Class Browser
*
* Client parser for browser detection
*
* @package DeviceDetector\Parser\Client
*/
class Browser extends ClientParserAbstract
{
protected $fixtureFile = 'regexes/client/browsers.yml';
protected $parserName = 'browser';
/**
* Known browsers mapped to their internal short codes
*
* @var array
*/
protected static $availableBrowsers = array(
'36' => '360 Phone Browser',
'3B' => '360 Browser',
'AA' => 'Avant Browser',
'AB' => 'ABrowse',
'AG' => 'ANTGalio',
'AM' => 'Amaya',
'AO' => 'Amigo',
'AN' => 'Android Browser',
'AR' => 'Arora',
'AV' => 'Amiga Voyager',
'AW' => 'Amiga Aweb',
'BB' => 'BlackBerry Browser',
'BD' => 'Baidu Browser',
'BS' => 'Baidu Spark',
'BE' => 'Beonex',
'BJ' => 'Bunjalloo',
'BX' => 'BrowseX',
'CA' => 'Camino',
'CC' => 'Coc Coc',
'CD' => 'Comodo Dragon',
'CX' => 'Charon',
'CF' => 'Chrome Frame',
'CH' => 'Chrome',
'CI' => 'Chrome Mobile iOS',
'CK' => 'Conkeror',
'CM' => 'Chrome Mobile',
'CN' => 'CoolNovo',
'CO' => 'CometBird',
'CP' => 'ChromePlus',
'CR' => 'Chromium',
'CS' => 'Cheshire',
'DE' => 'Deepnet Explorer',
'DF' => 'Dolphin',
'DI' => 'Dillo',
'EL' => 'Elinks',
'EP' => 'Epiphany',
'ES' => 'Espial TV Browser',
'FB' => 'Firebird',
'FD' => 'Fluid',
'FE' => 'Fennec',
'FF' => 'Firefox',
'FL' => 'Flock',
'FN' => 'Fireweb Navigator',
'GA' => 'Galeon',
'GE' => 'Google Earth',
'HJ' => 'HotJava',
'IA' => 'Iceape',
'IB' => 'IBrowse',
'IC' => 'iCab',
'ID' => 'IceDragon',
'IW' => 'Iceweasel',
'IE' => 'Internet Explorer',
'IM' => 'IE Mobile',
'IR' => 'Iron',
'JS' => 'Jasmine',
'KI' => 'Kindle Browser',
'KM' => 'K-meleon',
'KO' => 'Konqueror',
'KP' => 'Kapiko',
'KY' => 'Kylo',
'KZ' => 'Kazehakase',
'LB' => 'Liebao',
'LI' => 'Links',
'LS' => 'Lunascape',
'LX' => 'Lynx',
'MB' => 'MicroB',
'MC' => 'NCSA Mosaic',
'ME' => 'Mercury',
'MF' => 'Mobile Safari',
'MI' => 'Midori',
'MU' => 'MIUI Browser',
'MS' => 'Mobile Silk',
'MX' => 'Maxthon',
'NB' => 'Nokia Browser',
'NO' => 'Nokia OSS Browser',
'NV' => 'Nokia Ovi Browser',
'NF' => 'NetFront',
'NL' => 'NetFront Life',
'NP' => 'NetPositive',
'NS' => 'Netscape',
'OB' => 'Obigo',
'OD' => 'Odyssey Web Browser',
'OF' => 'Off By One',
'OE' => 'ONE Browser',
'OI' => 'Opera Mini',
'OM' => 'Opera Mobile',
'OP' => 'Opera',
'ON' => 'Opera Next',
'OR' => 'Oregano',
'OV' => 'Openwave Mobile Browser',
'OW' => 'OmniWeb',
'PL' => 'Palm Blazer',
'PM' => 'Pale Moon',
'PR' => 'Palm Pre',
'PU' => 'Puffin',
'PW' => 'Palm WebPro',
'PX' => 'Phoenix',
'PO' => 'Polaris',
'PS' => 'Microsoft Edge',
'QQ' => 'QQ Browser',
'RK' => 'Rekonq',
'RM' => 'RockMelt',
'SA' => 'Sailfish Browser',
'SC' => 'SEMC-Browser',
'SE' => 'Sogou Explorer',
'SF' => 'Safari',
'SH' => 'Shiira',
'SL' => 'Sleipnir',
'SM' => 'SeaMonkey',
'SN' => 'Snowshoe',
'SR' => 'Sunrise',
'SX' => 'Swiftfox',
'TZ' => 'Tizen Browser',
'UC' => 'UC Browser',
'VI' => 'Vivaldi',
'WE' => 'WebPositive',
'WO' => 'wOSBrowser',
'WT' => 'WeTab Browser',
'YA' => 'Yandex Browser',
'XI' => 'Xiino'
);
/**
* Browser families mapped to the short codes of the associated browsers
*
* @var array
*/
protected static $browserFamilies = array(
'Android Browser' => array('AN', 'MU'),
'BlackBerry Browser' => array('BB'),
'Baidu' => array('BD', 'BS'),
'Amiga' => array('AV', 'AW'),
'Chrome' => array('CH', 'CC', 'CD', 'CM', 'CI', 'CF', 'CN', 'CR', 'CP', 'IR', 'RM', 'AO', 'VI'),
'Firefox' => array('FF', 'FE', 'SX', 'FB', 'PX', 'MB'),
'Internet Explorer' => array('IE', 'IM', 'PS'),
'Konqueror' => array('KO'),
'NetFront' => array('NF'),
'Nokia Browser' => array('NB', 'NO', 'NV'),
'Opera' => array('OP', 'OM', 'OI', 'ON'),
'Safari' => array('SF', 'MF'),
'Sailfish Browser' => array('SA')
);
/**
* Returns list of all available browsers
* @return array
*/
public static function getAvailableBrowsers()
{
return self::$availableBrowsers;
}
/**
* Returns list of all available browser families
* @return array
*/
public static function getAvailableBrowserFamilies()
{
return self::$browserFamilies;
}
/**
* @param $browserLabel
* @return bool|string If false, "Unknown"
*/
public static function getBrowserFamily($browserLabel)
{
foreach (self::$browserFamilies as $browserFamily => $browserLabels) {
if (in_array($browserLabel, $browserLabels)) {
return $browserFamily;
}
}
return false;
}
public function parse()
{
foreach ($this->getRegexes() as $regex) {
$matches = $this->matchUserAgent($regex['regex']);
if ($matches) {
break;
}
}
if (!$matches) {
return null;
}
$name = $this->buildByMatch($regex['name'], $matches);
foreach (self::getAvailableBrowsers() as $browserShort => $browserName) {
if (strtolower($name) == strtolower($browserName)) {
$version = (string) $this->buildVersion($regex['version'], $matches);
$engine = $this->buildEngine(isset($regex['engine']) ? $regex['engine'] : array(), $version);
return array(
'type' => 'browser',
'name' => $browserName,
'short_name' => $browserShort,
'version' => $version,
'engine' => $engine
);
}
}
// This Exception should never be thrown. If so a defined browser name is missing in $availableBrowsers
throw new \Exception('Detected browser name was not found in $availableBrowsers'); // @codeCoverageIgnore
}
protected function buildEngine($engineData, $browserVersion)
{
$engine = '';
// if an engine is set as default
if (isset($engineData['default'])) {
$engine = $engineData['default'];
}
// check if engine is set for browser version
if (array_key_exists('versions', $engineData) && is_array($engineData['versions'])) {
foreach ($engineData['versions'] as $version => $versionEngine) {
if (version_compare($browserVersion, $version) >= 0) {
$engine = $versionEngine;
}
}
}
// try to detect the engine using the regexes
if (empty($engine)) {
$engineParser = new Engine();
$engineParser->setUserAgent($this->userAgent);
$engine = $engineParser->parse();
}
return $engine;
}
}

View file

@ -0,0 +1,76 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client\Browser;
use DeviceDetector\Parser\Client\ClientParserAbstract;
/**
* Class Engine
*
* Client parser for browser engine detection
*
* @package DeviceDetector\Parser\Client\Browser
*/
class Engine extends ClientParserAbstract
{
protected $fixtureFile = 'regexes/client/browser_engine.yml';
protected $parserName = 'browserengine';
/**
* Known browser engines mapped to their internal short codes
*
* @var array
*/
protected static $availableEngines = array(
'WebKit',
'Blink',
'Trident',
'Text-based',
'Dillo',
'iCab',
'Presto',
'Gecko',
'KHTML',
'NetFront',
'Edge'
);
/**
* Returns list of all available browser engines
* @return array
*/
public static function getAvailableEngines()
{
return self::$availableEngines;
}
public function parse()
{
foreach ($this->getRegexes() as $regex) {
$matches = $this->matchUserAgent($regex['regex']);
if ($matches) {
break;
}
}
if (!$matches) {
return '';
}
$name = $this->buildByMatch($regex['name'], $matches);
foreach (self::getAvailableEngines() as $engineName) {
if (strtolower($name) == strtolower($engineName)) {
return $engineName;
}
}
// This Exception should never be thrown. If so a defined browser name is missing in $availableEngines
throw new \Exception('Detected browser engine was not found in $availableEngines'); // @codeCoverageIgnore
}
}

View file

@ -0,0 +1,74 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client;
use DeviceDetector\Parser\ParserAbstract;
abstract class ClientParserAbstract extends ParserAbstract
{
protected $fixtureFile = '';
protected $parserName = '';
/**
* Parses the current UA and checks whether it contains any client information
*
* @see $fixtureFile for file with list of detected clients
*
* Step 1: Build a big regex containing all regexes and match UA against it
* -> If no matches found: return
* -> Otherwise:
* Step 2: Walk through the list of regexes in feed_readers.yml and try to match every one
* -> Return the matched feed reader
*
* NOTE: Doing the big match before matching every single regex speeds up the detection
*/
public function parse()
{
$result = null;
if ($this->preMatchOverall()) {
foreach ($this->getRegexes() as $regex) {
$matches = $this->matchUserAgent($regex['regex']);
if ($matches) {
$result = array(
'type' => $this->parserName,
'name' => $this->buildByMatch($regex['name'], $matches),
'version' => $this->buildVersion($regex['version'], $matches)
);
break;
}
}
}
return $result;
}
/**
* Returns all names defined in the regexes
*
* Attention: This method might not return all names of detected clients
*
* @return array
*/
public static function getAvailableClients()
{
$instance = new static();
$regexes = $instance->getRegexes();
$names = array();
foreach ($regexes as $regex) {
if ($regex['name'] != '$1') {
$names[] = $regex['name'];
}
}
natcasesort($names);
return array_unique($names);
}
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client;
/**
* Class FeedReader
*
* Client parser for feed reader detection
*
* @package DeviceDetector\Parser\Client
*/
class FeedReader extends ClientParserAbstract
{
protected $fixtureFile = 'regexes/client/feed_readers.yml';
protected $parserName = 'feed reader';
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client;
/**
* Class Library
*
* Client parser for tool & software detection
*
* @package DeviceDetector\Parser\Client
*/
class Library extends ClientParserAbstract
{
protected $fixtureFile = 'regexes/client/libraries.yml';
protected $parserName = 'library';
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client;
/**
* Class MediaPlayer
*
* Client parser for mediaplayer detection
*
* @package DeviceDetector\Parser\Client
*/
class MediaPlayer extends ClientParserAbstract
{
protected $fixtureFile = 'regexes/client/mediaplayers.yml';
protected $parserName = 'mediaplayer';
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client;
/**
* Class MobileApp
*
* Client parser for mobile app detection
*
* @package DeviceDetector\Parser\Client
*/
class MobileApp extends ClientParserAbstract
{
protected $fixtureFile = 'regexes/client/mobile_apps.yml';
protected $parserName = 'mobile app';
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Client;
/**
* Class PIM
*
* Client parser for pim (personal information manager) detection
*
* @package DeviceDetector\Parser\Client
*/
class PIM extends ClientParserAbstract
{
protected $fixtureFile = 'regexes/client/pim.yml';
protected $parserName = 'pim';
}

View file

@ -0,0 +1,30 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Device;
/**
* Class Camera
*
* Device parser for camera detection
*
* @package DeviceDetector\Parser\Device
*/
class Camera extends DeviceParserAbstract
{
protected $fixtureFile = 'regexes/device/cameras.yml';
protected $parserName = 'camera';
public function parse()
{
if (!$this->preMatchOverall()) {
return false;
}
return parent::parse();
}
}

View file

@ -0,0 +1,30 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Device;
/**
* Class CarBrowser
*
* Device parser for car browser detection
*
* @package DeviceDetector\Parser\Device
*/
class CarBrowser extends DeviceParserAbstract
{
protected $fixtureFile = 'regexes/device/car_browsers.yml';
protected $parserName = 'car browser';
public function parse()
{
if (!$this->preMatchOverall()) {
return false;
}
return parent::parse();
}
}

View file

@ -0,0 +1,30 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Device;
/**
* Class Console
*
* Device parser for console detection
*
* @package DeviceDetector\Parser\Device
*/
class Console extends DeviceParserAbstract
{
protected $fixtureFile = 'regexes/device/consoles.yml';
protected $parserName = 'console';
public function parse()
{
if (!$this->preMatchOverall()) {
return false;
}
return parent::parse();
}
}

View file

@ -0,0 +1,504 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Device;
use DeviceDetector\Parser\ParserAbstract;
/**
* Class DeviceParserAbstract
*
* Abstract class for all device parsers
*
* @package DeviceDetector\Parser\Device
*/
abstract class DeviceParserAbstract extends ParserAbstract
{
protected $deviceType = null;
protected $model = null;
protected $brand = null;
const DEVICE_TYPE_DESKTOP = 0;
const DEVICE_TYPE_SMARTPHONE = 1;
const DEVICE_TYPE_TABLET = 2;
const DEVICE_TYPE_FEATURE_PHONE = 3;
const DEVICE_TYPE_CONSOLE = 4;
const DEVICE_TYPE_TV = 5; // including set top boxes, blu-ray players,...
const DEVICE_TYPE_CAR_BROWSER = 6;
const DEVICE_TYPE_SMART_DISPLAY = 7;
const DEVICE_TYPE_CAMERA = 8;
const DEVICE_TYPE_PORTABLE_MEDIA_PAYER = 9;
const DEVICE_TYPE_PHABLET = 10;
/**
* Detectable device types
*
* @var array
*/
protected static $deviceTypes = array(
'desktop' => self::DEVICE_TYPE_DESKTOP,
'smartphone' => self::DEVICE_TYPE_SMARTPHONE,
'tablet' => self::DEVICE_TYPE_TABLET,
'feature phone' => self::DEVICE_TYPE_FEATURE_PHONE,
'console' => self::DEVICE_TYPE_CONSOLE,
'tv' => self::DEVICE_TYPE_TV,
'car browser' => self::DEVICE_TYPE_CAR_BROWSER,
'smart display' => self::DEVICE_TYPE_SMART_DISPLAY,
'camera' => self::DEVICE_TYPE_CAMERA,
'portable media player' => self::DEVICE_TYPE_PORTABLE_MEDIA_PAYER,
'phablet' => self::DEVICE_TYPE_PHABLET
);
/**
* Known device brands
*
* Note: Before using a new brand in on of the regex files, it needs to be added here
*
* @var array
*/
public static $deviceBrands = array(
'3Q' => '3Q',
'AC' => 'Acer',
'AZ' => 'Ainol',
'AI' => 'Airness',
'AL' => 'Alcatel',
'A2' => 'Allview',
'A1' => 'Altech UEC',
'AN' => 'Arnova',
'KN' => 'Amazon',
'AO' => 'Amoi',
'AP' => 'Apple',
'AR' => 'Archos',
'AS' => 'ARRIS',
'AT' => 'Airties',
'AU' => 'Asus',
'AV' => 'Avvio',
'AX' => 'Audiovox',
'AY' => 'Axxion',
'BB' => 'BBK',
'BE' => 'Becker',
'BI' => 'Bird',
'BL' => 'Beetel',
'BM' => 'Bmobile',
'BN' => 'Barnes & Noble',
'BO' => 'BangOlufsen',
'BQ' => 'BenQ',
'BS' => 'BenQ-Siemens',
'BU' => 'Blu',
'BW' => 'Boway',
'BX' => 'bq',
'BR' => 'Brondi',
'B1' => 'Bush',
'CB' => 'CUBOT',
'CF' => 'Carrefour',
'CP' => 'Captiva',
'CS' => 'Casio',
'CA' => 'Cat',
'CE' => 'Celkon',
'CC' => 'ConCorde',
'C2' => 'Changhong',
'CH' => 'Cherry Mobile',
'CK' => 'Cricket',
'C1' => 'Crosscall',
'CL' => 'Compal',
'CN' => 'CnM',
'CM' => 'Crius Mea',
'CR' => 'CreNova',
'CT' => 'Capitel',
'CQ' => 'Compaq',
'CO' => 'Coolpad',
'CW' => 'Cowon',
'CU' => 'Cube',
'CY' => 'Coby Kyros',
'DA' => 'Danew',
'DT' => 'Datang',
'DE' => 'Denver',
'DS' => 'Desay',
'DB' => 'Dbtel',
'DC' => 'DoCoMo',
'DI' => 'Dicam',
'DL' => 'Dell',
'DM' => 'DMM',
'DO' => 'Doogee',
'DV' => 'Doov',
'DP' => 'Dopod',
'DU' => 'Dune HD',
'EB' => 'E-Boda',
'EA' => 'EBEST',
'EC' => 'Ericsson',
'ES' => 'ECS',
'EI' => 'Ezio',
'EL' => 'Elephone',
'EP' => 'Easypix',
'E1' => 'Energy Sistem',
'ER' => 'Ericy',
'EN' => 'Eton',
'ET' => 'eTouch',
'EV' => 'Evertek',
'EZ' => 'Ezze',
'FL' => 'Fly',
'FO' => 'Foxconn',
'FU' => 'Fujitsu',
'GM' => 'Garmin-Asus',
'GA' => 'Gateway',
'GD' => 'Gemini',
'GI' => 'Gionee',
'GG' => 'Gigabyte',
'GS' => 'Gigaset',
'GC' => 'GOCLEVER',
'GL' => 'Goly',
'GO' => 'Google',
'GR' => 'Gradiente',
'GU' => 'Grundig',
'HA' => 'Haier',
'HS' => 'Hasee',
'HI' => 'Hisense',
'HL' => 'Hi-Level',
'HO' => 'Hosin',
'HP' => 'HP',
'HT' => 'HTC',
'HU' => 'Huawei',
'HX' => 'Humax',
'HY' => 'Hyrican',
'HN' => 'Hyundai',
'IA' => 'Ikea',
'IB' => 'iBall',
'IJ' => 'i-Joy',
'IY' => 'iBerry',
'IK' => 'iKoMo',
'IM' => 'i-mate',
'I1' => 'iOcean',
'IF' => 'Infinix',
'IN' => 'Innostream',
'II' => 'Inkti',
'IX' => 'Intex',
'IO' => 'i-mobile',
'IQ' => 'INQ',
'IT' => 'Intek',
'IV' => 'Inverto',
'IZ' => 'iTel',
'JI' => 'Jiayu',
'JO' => 'Jolla',
'KA' => 'Karbonn',
'KD' => 'KDDI',
'KI' => 'Kingsun',
'KO' => 'Konka',
'KM' => 'Komu',
'KB' => 'Koobee',
'KT' => 'K-Touch',
'KH' => 'KT-Tech',
'KP' => 'KOPO',
'KR' => 'Koridy',
'KU' => 'Kumai',
'KY' => 'Kyocera',
'KZ' => 'Kazam',
'LV' => 'Lava',
'LA' => 'Lanix',
'LC' => 'LCT',
'LE' => 'Lenovo',
'LN' => 'Lenco',
'LP' => 'Le Pan',
'LG' => 'LG',
'LI' => 'Lingwin',
'LO' => 'Loewe',
'LM' => 'Logicom',
'LX' => 'Lexibook',
'MJ' => 'Majestic',
'MA' => 'Manta Multimedia',
'MB' => 'Mobistel',
'M3' => 'Mecer',
'MD' => 'Medion',
'M2' => 'MEEG',
'M1' => 'Meizu',
'ME' => 'Metz',
'MX' => 'MEU',
'MI' => 'MicroMax',
'MC' => 'Mediacom',
'MK' => 'MediaTek',
'MO' => 'Mio',
'MM' => 'Mpman',
'MF' => 'Mofut',
'MR' => 'Motorola',
'MS' => 'Microsoft',
'MZ' => 'MSI',
'MU' => 'Memup',
'MT' => 'Mitsubishi',
'ML' => 'MLLED',
'MQ' => 'M.T.T.',
'MY' => 'MyPhone',
'NE' => 'NEC',
'NA' => 'Netgear',
'NG' => 'NGM',
'NI' => 'Nintendo',
'N1' => 'Noain',
'NK' => 'Nokia',
'NM' => 'Nomi',
'NN' => 'Nikon',
'NW' => 'Newgen',
'NX' => 'Nexian',
'NT' => 'NextBook',
'OD' => 'Onda',
'ON' => 'OnePlus',
'OP' => 'OPPO',
'OR' => 'Orange',
'OT' => 'O2',
'OK' => 'Ouki',
'OU' => 'OUYA',
'OO' => 'Opsson',
'PA' => 'Panasonic',
'PE' => 'PEAQ',
'PH' => 'Philips',
'PL' => 'Polaroid',
'PM' => 'Palm',
'PO' => 'phoneOne',
'PT' => 'Pantech',
'PV' => 'Point of View',
'PP' => 'PolyPad',
'P2' => 'Pomp',
'PS' => 'Positivo',
'PR' => 'Prestigio',
'P1' => 'ProScan',
'PU' => 'PULID',
'QI' => 'Qilive',
'QT' => 'Qtek',
'QM' => 'QMobile',
'QU' => 'Quechua',
'OV' => 'Overmax',
'OY' => 'Oysters',
'RA' => 'Ramos',
'RC' => 'RCA Tablets',
'RB' => 'Readboy',
'RI' => 'Rikomagic',
'RM' => 'RIM',
'RK' => 'Roku',
'RO' => 'Rover',
'SA' => 'Samsung',
'SD' => 'Sega',
'SE' => 'Sony Ericsson',
'S1' => 'Sencor',
'SF' => 'Softbank',
'SX' => 'SFR',
'SG' => 'Sagem',
'SH' => 'Sharp',
'SI' => 'Siemens',
'SN' => 'Sendo',
'SK' => 'Skyworth',
'SC' => 'Smartfren',
'SO' => 'Sony',
'SP' => 'Spice',
'SU' => 'SuperSonic',
'SV' => 'Selevision',
'SY' => 'Sanyo',
'SM' => 'Symphony',
'SR' => 'Smart',
'S4' => 'Star',
'ST' => 'Storex',
'S2' => 'Stonex',
'S3' => 'SunVan',
'SZ' => 'Sumvision',
'TA' => 'Tesla',
'TC' => 'TCL',
'TE' => 'Telit',
'T4' => 'ThL',
'TH' => 'TiPhone',
'TB' => 'Tecno Mobile',
'TD' => 'Tesco',
'TI' => 'TIANYU',
'TL' => 'Telefunken',
'T2' => 'Telenor',
'TM' => 'T-Mobile',
'TN' => 'Thomson',
'T1' => 'Tolino',
'TO' => 'Toplux',
'TS' => 'Toshiba',
'TT' => 'TechnoTrend',
'T3' => 'Trevi',
'TU' => 'Tunisie Telecom',
'TR' => 'Turbo-X',
'TV' => 'TVC',
'TX' => 'TechniSat',
'TZ' => 'teXet',
'UN' => 'Unowhy',
'US' => 'Uniscope',
'UT' => 'UTStarcom',
'VA' => 'Vastking',
'VD' => 'Videocon',
'VE' => 'Vertu',
'VI' => 'Vitelcom',
'VK' => 'VK Mobile',
'VS' => 'ViewSonic',
'VT' => 'Vestel',
'VV' => 'Vivo',
'V1' => 'Voto',
'VO' => 'Voxtel',
'VF' => 'Vodafone',
'VZ' => 'Vizio',
'VW' => 'Videoweb',
'WA' => 'Walton',
'WB' => 'Web TV',
'WE' => 'WellcoM',
'WY' => 'Wexler',
'WI' => 'Wiko',
'WL' => 'Wolder',
'WO' => 'Wonu',
'WX' => 'Woxter',
'XI' => 'Xiaomi',
'XO' => 'Xolo',
'XX' => 'Unknown',
'YA' => 'Yarvik',
'YU' => 'Yuandao',
'YS' => 'Yusun',
'YT' => 'Ytone',
'ZE' => 'Zeemi',
'ZO' => 'Zonda',
'ZP' => 'Zopo',
'ZT' => 'ZTE',
);
public function getDeviceType()
{
return $this->deviceType;
}
/**
* Returns available device types
*
* @see $deviceTypes
* @return array
*/
public static function getAvailableDeviceTypes()
{
return self::$deviceTypes;
}
/**
* Returns names of all available device types
*
* @return array
*/
public static function getAvailableDeviceTypeNames()
{
return array_keys(self::$deviceTypes);
}
/**
* Returns the name of the given device type
*
* @param int $deviceType one of the DEVICE_TYPE_* constants
*
* @return mixed
*/
public static function getDeviceName($deviceType)
{
return array_search($deviceType, self::$deviceTypes);
}
/**
* Returns the detected device model
*
* @return string
*/
public function getModel()
{
return $this->model;
}
/**
* Returns the detected device brand
*
* @return string
*/
public function getBrand()
{
return $this->brand;
}
/**
* Returns the full brand name for the given short name
*
* @param string $brandId short brand name
* @return string
*/
public static function getFullName($brandId)
{
if (array_key_exists($brandId, self::$deviceBrands)) {
return self::$deviceBrands[$brandId];
}
return '';
}
public function parse()
{
$regexes = $this->getRegexes();
foreach ($regexes as $brand => $regex) {
$matches = $this->matchUserAgent($regex['regex']);
if ($matches) {
break;
}
}
if (empty($matches)) {
return false;
}
$brandId = array_search($brand, self::$deviceBrands);
if ($brandId === false) {
// This Exception should never be thrown. If so a defined brand name is missing in $deviceBrands
throw new \Exception("The brand with name '$brand' should be listed in the deviceBrands array."); // @codeCoverageIgnore
}
$this->brand = $brandId;
if (isset($regex['device']) && in_array($regex['device'], self::$deviceTypes)) {
$this->deviceType = self::$deviceTypes[$regex['device']];
}
if (isset($regex['model'])) {
$this->model = $this->buildModel($regex['model'], $matches);
}
if (isset($regex['models'])) {
foreach ($regex['models'] as $modelRegex) {
$modelMatches = $this->matchUserAgent($modelRegex['regex']);
if ($modelMatches) {
break;
}
}
if (empty($modelMatches)) {
return true;
}
$this->model = trim($this->buildModel($modelRegex['model'], $modelMatches));
if (isset($modelRegex['brand']) && $brandId = array_search($modelRegex['brand'], self::$deviceBrands)) {
$this->brand = $brandId;
}
if (isset($modelRegex['device']) && in_array($modelRegex['device'], self::$deviceTypes)) {
$this->deviceType = self::$deviceTypes[$modelRegex['device']];
}
}
return true;
}
protected function buildModel($model, $matches)
{
$model = $this->buildByMatch($model, $matches);
$model = str_replace('_', ' ', $model);
$model = preg_replace('/ TD$/i', '', $model);
if ($model === 'Build') {
return null;
}
return $model;
}
}

View file

@ -0,0 +1,53 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Device;
/**
* Class HbbTv
*
* Device parser for hbbtv detection
*
* @package DeviceDetector\Parser\Device
*/
class HbbTv extends DeviceParserAbstract
{
protected $fixtureFile = 'regexes/device/televisions.yml';
protected $parserName = 'tv';
/**
* Parses the current UA and checks whether it contains HbbTv information
*
* @see televisions.yml for list of detected televisions
*/
public function parse()
{
// only parse user agents containing hbbtv fragment
if (!$this->isHbbTv()) {
return false;
}
parent::parse();
// always set device type to tv, even if no model/brand could be found
$this->deviceType = self::DEVICE_TYPE_TV;
return true;
}
/**
* Returns if the parsed UA was identified as a HbbTV device
*
* @return bool
*/
public function isHbbTv()
{
$regex = 'HbbTV/([1-9]{1}(?:\.[0-9]{1}){1,2})';
$match = $this->matchUserAgent($regex);
return $match ? $match[1] : false;
}
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Device;
/**
* Class Mobile
*
* Device parser for mobile detection
*
* @package DeviceDetector\Parser\Device
*/
class Mobile extends DeviceParserAbstract
{
protected $fixtureFile = 'regexes/device/mobiles.yml';
protected $parserName = 'mobile';
}

View file

@ -0,0 +1,30 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser\Device;
/**
* Class PortableMediaPlayer
*
* Device parser for portable media player detection
*
* @package DeviceDetector\Parser\Device
*/
class PortableMediaPlayer extends DeviceParserAbstract
{
protected $fixtureFile = 'regexes/device/portable_media_player.yml';
protected $parserName = 'portablemediaplayer';
public function parse()
{
if (!$this->preMatchOverall()) {
return false;
}
return parent::parse();
}
}

View file

@ -0,0 +1,245 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser;
/**
* Class OperatingSystem
*
* Parses the useragent for operating system information
*
* Detected operating systems can be found in self::$operatingSystems and /regexes/oss.yml
* This class also defined some operating system families and methods to get the family for a specific os
*
* @package DeviceDetector\Parser
*/
class OperatingSystem extends ParserAbstract
{
protected $fixtureFile = 'regexes/oss.yml';
protected $parserName = 'os';
/**
* Known operating systems mapped to their internal short codes
*
* @var array
*/
protected static $operatingSystems = array(
'AIX' => 'AIX',
'AND' => 'Android',
'AMG' => 'AmigaOS',
'ATV' => 'Apple TV',
'ARL' => 'Arch Linux',
'BTR' => 'BackTrack',
'SBA' => 'Bada',
'BEO' => 'BeOS',
'BLB' => 'BlackBerry OS',
'QNX' => 'BlackBerry Tablet OS',
'BMP' => 'Brew',
'CES' => 'CentOS',
'COS' => 'Chrome OS',
'CYN' => 'CyanogenMod',
'DEB' => 'Debian',
'DFB' => 'DragonFly',
'FED' => 'Fedora',
'FOS' => 'Firefox OS',
'BSD' => 'FreeBSD',
'GNT' => 'Gentoo',
'GTV' => 'Google TV',
'HPX' => 'HP-UX',
'HAI' => 'Haiku OS',
'IRI' => 'IRIX',
'INF' => 'Inferno',
'KNO' => 'Knoppix',
'KBT' => 'Kubuntu',
'LIN' => 'GNU/Linux',
'LBT' => 'Lubuntu',
'VLN' => 'VectorLinux',
'MAC' => 'Mac',
'MAE' => 'Maemo',
'MDR' => 'Mandriva',
'SMG' => 'MeeGo',
'MCD' => 'MocorDroid',
'MIN' => 'Mint',
'MLD' => 'MildWild',
'MOR' => 'MorphOS',
'NBS' => 'NetBSD',
'MTK' => 'MTK / Nucleus',
'WII' => 'Nintendo',
'NDS' => 'Nintendo Mobile',
'OS2' => 'OS/2',
'T64' => 'OSF1',
'OBS' => 'OpenBSD',
'PSP' => 'PlayStation Portable',
'PS3' => 'PlayStation',
'RHT' => 'Red Hat',
'ROS' => 'RISC OS',
'RZD' => 'RazoDroiD',
'SAB' => 'Sabayon',
'SSE' => 'SUSE',
'SAF' => 'Sailfish OS',
'SLW' => 'Slackware',
'SOS' => 'Solaris',
'SYL' => 'Syllable',
'SYM' => 'Symbian',
'SYS' => 'Symbian OS',
'S40' => 'Symbian OS Series 40',
'S60' => 'Symbian OS Series 60',
'SY3' => 'Symbian^3',
'TDX' => 'ThreadX',
'TIZ' => 'Tizen',
'UBT' => 'Ubuntu',
'WTV' => 'WebTV',
'WIN' => 'Windows',
'WCE' => 'Windows CE',
'WMO' => 'Windows Mobile',
'WPH' => 'Windows Phone',
'WRT' => 'Windows RT',
'XBX' => 'Xbox',
'XBT' => 'Xubuntu',
'YNS' => 'YunOs',
'IOS' => 'iOS',
'POS' => 'palmOS',
'WOS' => 'webOS'
);
/**
* Operating system families mapped to the short codes of the associated operating systems
*
* @var array
*/
protected static $osFamilies = array(
'Android' => array('AND', 'CYN', 'RZD', 'MLD', 'MCD'),
'AmigaOS' => array('AMG', 'MOR'),
'Apple TV' => array('ATV'),
'BlackBerry' => array('BLB', 'QNX'),
'Brew' => array('BMP'),
'BeOS' => array('BEO', 'HAI'),
'Chrome OS' => array('COS'),
'Firefox OS' => array('FOS'),
'Gaming Console' => array('WII', 'PS3'),
'Google TV' => array('GTV'),
'IBM' => array('OS2'),
'iOS' => array('IOS'),
'RISC OS' => array('ROS'),
'GNU/Linux' => array('LIN', 'ARL', 'DEB', 'KNO', 'MIN', 'UBT', 'KBT', 'XBT', 'LBT', 'FED', 'RHT', 'VLN', 'MDR', 'GNT', 'SAB', 'SLW', 'SSE', 'CES', 'BTR', 'YNS', 'SAF'),
'Mac' => array('MAC'),
'Mobile Gaming Console' => array('PSP', 'NDS', 'XBX'),
'Real-time OS' => array('MTK', 'TDX'),
'Other Mobile' => array('WOS', 'POS', 'SBA', 'TIZ', 'SMG', 'MAE'),
'Symbian' => array('SYM', 'SYS', 'SY3', 'S60', 'S40'),
'Unix' => array('SOS', 'AIX', 'HPX', 'BSD', 'NBS', 'OBS', 'DFB', 'SYL', 'IRI', 'T64', 'INF'),
'WebTV' => array('WTV'),
'Windows' => array('WIN'),
'Windows Mobile' => array('WPH', 'WMO', 'WCE', 'WRT')
);
/**
* Returns all available operating systems
*
* @return array
*/
public static function getAvailableOperatingSystems()
{
return self::$operatingSystems;
}
/**
* Returns all available operating system families
*
* @return array
*/
public static function getAvailableOperatingSystemFamilies()
{
return self::$osFamilies;
}
public function parse()
{
$return = array();
foreach ($this->getRegexes() as $osRegex) {
$matches = $this->matchUserAgent($osRegex['regex']);
if ($matches) {
break;
}
}
if (!$matches) {
return $return;
}
$name = $this->buildByMatch($osRegex['name'], $matches);
$short = 'UNK';
foreach (self::$operatingSystems as $osShort => $osName) {
if (strtolower($name) == strtolower($osName)) {
$name = $osName;
$short = $osShort;
}
}
$return = array(
'name' => $name,
'short_name' => $short,
'version' => $this->buildVersion($osRegex['version'], $matches),
'platform' => $this->parsePlatform()
);
if (in_array($return['name'], self::$operatingSystems)) {
$return['short_name'] = array_search($return['name'], self::$operatingSystems);
}
return $return;
}
protected function parsePlatform()
{
if ($this->matchUserAgent('arm')) {
return 'ARM';
} elseif ($this->matchUserAgent('WOW64|x64|win64|amd64|x86_64')) {
return 'x64';
} elseif ($this->matchUserAgent('i[0-9]86|i86pc')) {
return 'x86';
}
return '';
}
/**
* Returns the operating system family for the given operating system
*
* @param $osLabel
* @return bool|string If false, "Unknown"
*/
public static function getOsFamily($osLabel)
{
foreach (self::$osFamilies as $family => $labels) {
if (in_array($osLabel, $labels)) {
return $family;
}
}
return false;
}
/**
* Returns the full name for the given short name
*
* @param $os
* @param bool $ver
*
* @return bool|string
*/
public static function getNameFromId($os, $ver = false)
{
if (array_key_exists($os, self::$operatingSystems)) {
$osFullName = self::$operatingSystems[$os];
return trim($osFullName . " " . $ver);
}
return false;
}
}

View file

@ -0,0 +1,283 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser;
use DeviceDetector\Cache\StaticCache;
use DeviceDetector\DeviceDetector;
use DeviceDetector\Cache\Cache;
use \Spyc;
/**
* Class ParserAbstract
*
* @package DeviceDetector\Parser
*/
abstract class ParserAbstract
{
/**
* Holds the path to the yml file containing regexes
* @var string
*/
protected $fixtureFile;
/**
* Holds the internal name of the parser
* Used for caching
* @var string
*/
protected $parserName;
/**
* Holds the user agent the should be parsed
* @var string
*/
protected $userAgent;
/**
* Holds an array with method that should be available global
* @var array
*/
protected $globalMethods;
/**
* Holds an array with regexes to parse, if already loaded
* @var array
*/
protected $regexList;
/**
* Indicates how deep versioning will be detected
* if $maxMinorParts is 0 only the major version will be returned
* @var int
*/
protected static $maxMinorParts = 1;
/**
* Versioning constant used to set max versioning to major version only
* Version examples are: 3, 5, 6, 200, 123, ...
*/
const VERSION_TRUNCATION_MAJOR = 0;
/**
* Versioning constant used to set max versioning to minor version
* Version examples are: 3.4, 5.6, 6.234, 0.200, 1.23, ...
*/
const VERSION_TRUNCATION_MINOR = 1;
/**
* Versioning constant used to set max versioning to path level
* Version examples are: 3.4.0, 5.6.344, 6.234.2, 0.200.3, 1.2.3, ...
*/
const VERSION_TRUNCATION_PATCH = 2;
/**
* Versioning constant used to set versioning to build number
* Version examples are: 3.4.0.12, 5.6.334.0, 6.234.2.3, 0.200.3.1, 1.2.3.0, ...
*/
const VERSION_TRUNCATION_BUILD = 3;
/**
* Versioning constant used to set versioning to unlimited (no truncation)
*/
const VERSION_TRUNCATION_NONE = null;
/**
* @var Cache|\Doctrine\Common\Cache\Cache
*/
protected $cache;
abstract public function parse();
public function __construct($ua='')
{
$this->setUserAgent($ua);
}
/**
* Set how DeviceDetector should return versions
* @param int|null $type Any of the VERSION_TRUNCATION_* constants
*/
public static function setVersionTruncation($type)
{
if (in_array($type, array(self::VERSION_TRUNCATION_BUILD,
self::VERSION_TRUNCATION_NONE,
self::VERSION_TRUNCATION_MAJOR,
self::VERSION_TRUNCATION_MINOR,
self::VERSION_TRUNCATION_PATCH))) {
self::$maxMinorParts = $type;
}
}
/**
* Sets the user agent to parse
*
* @param string $ua user agent
*/
public function setUserAgent($ua)
{
$this->userAgent = $ua;
}
/**
* Returns the internal name of the parser
*
* @return string
*/
public function getName()
{
return $this->parserName;
}
/**
* Returns the result of the parsed yml file defined in $fixtureFile
*
* @return array
*/
protected function getRegexes()
{
if (empty($this->regexList)) {
$cacheKey = 'DeviceDetector-'.DeviceDetector::VERSION.'regexes-'.$this->getName();
$cacheKey = preg_replace('/([^a-z0-9_-]+)/i', '', $cacheKey);
$this->regexList = $this->getCache()->fetch($cacheKey);
if (empty($this->regexList)) {
$this->regexList = Spyc::YAMLLoad(dirname(__DIR__).DIRECTORY_SEPARATOR.$this->fixtureFile);
$this->getCache()->save($cacheKey, $this->regexList);
}
}
return $this->regexList;
}
/**
* Matches the useragent against the given regex
*
* @param $regex
* @return array|bool
*/
protected function matchUserAgent($regex)
{
// only match if useragent begins with given regex or there is no letter before it
$regex = '/(?:^|[^A-Z0-9\_\-]|sprd-)(?:' . str_replace('/', '\/', $regex) . ')/i';
if (preg_match($regex, $this->userAgent, $matches)) {
return $matches;
}
return false;
}
/**
* @param string $item
* @param array $matches
* @return string type
*/
protected function buildByMatch($item, $matches)
{
for ($nb=1;$nb<=3;$nb++) {
if (strpos($item, '$' . $nb) === false) {
continue;
}
$replace = isset($matches[$nb]) ? $matches[$nb] : '';
$item = trim(str_replace('$' . $nb, $replace, $item));
}
return $item;
}
/**
* Builds the version with the given $versionString and $matches
*
* Example:
* $versionString = 'v$2'
* $matches = array('version_1_0_1', '1_0_1')
* return value would be v1.0.1
*
* @param $versionString
* @param $matches
* @return mixed|string
*/
protected function buildVersion($versionString, $matches)
{
$versionString = $this->buildByMatch($versionString, $matches);
$versionString = str_replace('_', '.', $versionString);
if (null !== self::$maxMinorParts && substr_count($versionString, '.') > self::$maxMinorParts) {
$versionParts = explode('.', $versionString);
$versionParts = array_slice($versionParts, 0, 1+self::$maxMinorParts);
$versionString = implode('.', $versionParts);
}
return trim($versionString, ' .');
}
/**
* Tests the useragent against a combination of all regexes
*
* All regexes returned by getRegexes() will be reversed and concated with '|'
* Afterwards the big regex will be tested against the user agent
*
* Method can be used to speed up detections by making a big check before doing checks for every single regex
*
* @return bool
*/
protected function preMatchOverall()
{
$regexes = $this->getRegexes();
static $overAllMatch;
$cacheKey = $this->parserName.DeviceDetector::VERSION.'-all';
$cacheKey = preg_replace('/([^a-z0-9_-]+)/i', '', $cacheKey);
if (empty($overAllMatch)) {
$overAllMatch = $this->getCache()->fetch($cacheKey);
}
if (empty($overAllMatch)) {
// reverse all regexes, so we have the generic one first, which already matches most patterns
$overAllMatch = array_reduce(array_reverse($regexes), function ($val1, $val2) {
if (!empty($val1)) {
return $val1.'|'.$val2['regex'];
} else {
return $val2['regex'];
}
});
$this->getCache()->save($cacheKey, $overAllMatch);
}
return $this->matchUserAgent($overAllMatch);
}
/**
* Sets the Cache class
*
* @param Cache|\Doctrine\Common\Cache\CacheProvider $cache
* @throws \Exception
*/
public function setCache($cache)
{
if ($cache instanceof Cache ||
(class_exists('\Doctrine\Common\Cache\CacheProvider') && $cache instanceof \Doctrine\Common\Cache\CacheProvider)) {
$this->cache = $cache;
return;
}
throw new \Exception('Cache not supported');
}
/**
* Returns Cache object
*
* @return Cache|\Doctrine\Common\Cache\CacheProvider
*/
public function getCache()
{
if (!empty($this->cache)) {
return $this->cache;
}
return new StaticCache();
}
}

View file

@ -0,0 +1,44 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser;
use DeviceDetector\Parser\Device\DeviceParserAbstract;
/**
* Class VendorFragments
*
* Device parser for vendor fragment detection
*
* @package DeviceDetector\Parser\Device
*/
class VendorFragment extends ParserAbstract
{
protected $fixtureFile = 'regexes/vendorfragments.yml';
protected $parserName = 'vendorfragments';
protected $matchedRegex = null;
public function parse()
{
foreach ($this->getRegexes() as $brand => $regexes) {
foreach ($regexes as $regex) {
if ($this->matchUserAgent($regex.'[^a-z0-9]+')) {
$this->matchedRegex = $regex;
return array_search($brand, DeviceParserAbstract::$deviceBrands);
}
}
}
return '';
}
public function getMatchedRegex()
{
return $this->matchedRegex;
}
}

View file

@ -1,7 +1,148 @@
DeviceDetector
==============
The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), and detects browsers, operating systems, devices, brands and models.
[![Latest Stable Version](https://poser.pugx.org/piwik/device-detector/v/stable)](https://packagist.org/packages/piwik/device-detector)
[![Latest Unstable Version](https://poser.pugx.org/piwik/device-detector/v/unstable)](https://packagist.org/packages/piwik/device-detector)
[![Total Downloads](https://poser.pugx.org/piwik/device-detector/downloads)](https://packagist.org/packages/piwik/device-detector)
[![License](https://poser.pugx.org/piwik/device-detector/license)](https://packagist.org/packages/piwik/device-detector)
## Code Status
[![Build Status](https://travis-ci.org/piwik/device-detector.svg?branch=master)](https://travis-ci.org/piwik/device-detector)
[![Code Coverage](https://coveralls.io/repos/piwik/device-detector/badge.png)](https://coveralls.io/r/piwik/device-detector)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/piwik/device-detector.svg)](http://isitmaintained.com/project/piwik/device-detector "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/piwik/device-detector.svg)](http://isitmaintained.com/project/piwik/device-detector "Percentage of issues still open")
## Description
The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), and detects clients (browsers, feed readers, media players, PIMs, ...), operating systems, devices, brands and models.
## Usage
Using DeviceDetector with composer is quite easy. Just add piwik/device-detector to your projects requirements. And use some code like this one:
Build status (master branch) [![Build Status](https://travis-ci.org/piwik/DeviceDetector.png?branch=master)](https://travis-ci.org/piwik/DeviceDetector)
```php
require_once 'vendor/autoload.php';
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\DeviceParserAbstract;
// OPTIONAL: Set version truncation to none, so full versions will be returned
// By default only minor versions will be returned (e.g. X.Y)
// for other options see VERSION_TRUNCATION_* constants in DeviceParserAbstract class
DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE);
$dd = new DeviceDetector($userAgent);
// OPTIONAL: Set caching method
// By default static cache is used, which works best within one php process (memory array caching)
// To cache across requests use caching in files or memcache
$dd->setCache(new Doctrine\Common\Cache\PhpFileCache('./tmp/'));
// OPTIONAL: If called, getBot() will only return true if a bot was detected (speeds up detection a bit)
$dd->discardBotInformation();
// OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then)
$dd->skipBotDetection();
$dd->parse();
if ($dd->isBot()) {
// handle bots,spiders,crawlers,...
$botInfo = $dd->getBot();
} else {
$clientInfo = $dd->getClient(); // holds information about browser, feed reader, media player, ...
$osInfo = $dd->getOs();
$device = $dd->getDevice();
$brand = $dd->getBrand();
$model = $dd->getModel();
}
```
### Caching
:exclamation: Caching of DeviceDetector was completely redesigned in 3.0. You may need to reimplement it when updating from below.
In order to get results faster across requests, we recommend to use the additional caching possibility.
Currently DeviceDetector is able to use [doctrine/cache](https://github.com/doctrine/cache). You can simply require it in your composer.json and use it like in the example before.
For those who like to implement their own Caching there is a second possibility. Besides doctrine caches the ```setCache``` method also accepts classes implementing the ```DeviceDetector\Cache\Cache``` interface. That way you can do whatever you want without requiring doctrine/cache.
## Contributing
### Hacking the library
This is a free/libre library under license LGPL v3 or later.
Your pull requests and/or feedback is very welcome!
### Listing all user agents from your logs
Sometimes it may be useful to generate the list of most used user agents on your website,
extracting this list from your access logs using the following command:
```
zcat ~/path/to/access/logs* | awk -F'"' '{print $6}' | sort | uniq -c | sort -rn | head -n20000 > /home/piwik/top-user-agents.txt
```
### Contributors
Created by the [Piwik team](http://piwik.org/team/), Stefan Giehl, Matthieu Aubry, Michał Gaździk,
Tomasz Majczak, Grzegorz Kaszuba, Piotr Banaszczyk and contributors.
Together we can build the best Device Detection library.
We are looking forward to your contributions and pull requests!
## Tests
See also: [QA at Piwik](http://piwik.org/qa/)
### Running tests
```
cd /path/to/device-detector
curl -sS https://getcomposer.org/installer | php
php composer.phar install
phpunit
```
## What Device Detector is able to detect
The lists below are auto generated and updated from time to time. Some of them might not be complete.
*Last update: 2016/01/21*
### List of detected operating systems:
AIX, Android, AmigaOS, Apple TV, Arch Linux, BackTrack, Bada, BeOS, BlackBerry OS, BlackBerry Tablet OS, Brew, CentOS, Chrome OS, CyanogenMod, Debian, DragonFly, Fedora, Firefox OS, FreeBSD, Gentoo, Google TV, HP-UX, Haiku OS, IRIX, Inferno, Knoppix, Kubuntu, GNU/Linux, Lubuntu, VectorLinux, Mac, Maemo, Mandriva, MeeGo, MocorDroid, Mint, MildWild, MorphOS, NetBSD, MTK / Nucleus, Nintendo, Nintendo Mobile, OS/2, OSF1, OpenBSD, PlayStation Portable, PlayStation, Red Hat, RISC OS, RazoDroiD, Sabayon, SUSE, Sailfish OS, Slackware, Solaris, Syllable, Symbian, Symbian OS, Symbian OS Series 40, Symbian OS Series 60, Symbian^3, ThreadX, Tizen, Ubuntu, WebTV, Windows, Windows CE, Windows Mobile, Windows Phone, Windows RT, Xbox, Xubuntu, YunOs, iOS, palmOS, webOS
### List of detected browsers:
360 Phone Browser, 360 Browser, Avant Browser, ABrowse, ANTGalio, Amaya, Amigo, Android Browser, Arora, Amiga Voyager, Amiga Aweb, BlackBerry Browser, Baidu Browser, Baidu Spark, Beonex, Bunjalloo, BrowseX, Camino, Coc Coc, Comodo Dragon, Charon, Chrome Frame, Chrome, Chrome Mobile iOS, Conkeror, Chrome Mobile, CoolNovo, CometBird, ChromePlus, Chromium, Cheshire, Deepnet Explorer, Dolphin, Dillo, Elinks, Epiphany, Espial TV Browser, Firebird, Fluid, Fennec, Firefox, Flock, Fireweb Navigator, Galeon, Google Earth, HotJava, Iceape, IBrowse, iCab, IceDragon, Iceweasel, Internet Explorer, IE Mobile, Iron, Jasmine, Kindle Browser, K-meleon, Konqueror, Kapiko, Kylo, Kazehakase, Liebao, Links, Lunascape, Lynx, MicroB, NCSA Mosaic, Mercury, Mobile Safari, Midori, MIUI Browser, Mobile Silk, Maxthon, Nokia Browser, Nokia OSS Browser, Nokia Ovi Browser, NetFront, NetFront Life, NetPositive, Netscape, Obigo, Odyssey Web Browser, Off By One, ONE Browser, Opera Mini, Opera Mobile, Opera, Opera Next, Oregano, Openwave Mobile Browser, OmniWeb, Palm Blazer, Pale Moon, Palm Pre, Puffin, Palm WebPro, Phoenix, Polaris, Microsoft Edge, QQ Browser, Rekonq, RockMelt, Sailfish Browser, SEMC-Browser, Sogou Explorer, Safari, Shiira, Sleipnir, SeaMonkey, Snowshoe, Sunrise, Swiftfox, Tizen Browser, UC Browser, Vivaldi, WebPositive, wOSBrowser, WeTab Browser, Yandex Browser, Xiino
### List of detected browser engines:
WebKit, Blink, Trident, Text-based, Dillo, iCab, Presto, Gecko, KHTML, NetFront, Edge
### List of detected libraries:
curl, Guzzle (PHP HTTP Client), Java, Perl, Python Requests, Python urllib, Wget
### List of detected media players:
Banshee, Clementine, FlyCast, Instacast, iTunes, Kodi, MediaMonkey, Miro, NexPlayer, Nightingale, QuickTime, Songbird, Stagefright, SubStream, VLC, Winamp, Windows Media Player, XBMC
### List of detected mobile apps:
AndroidDownloadManager, Facebook, FeedR, Google Play Newsstand, Google Plus, Sina Weibo, WeChat, YouTube and *mobile apps using [AFNetworking](https://github.com/AFNetworking/AFNetworking)*
### List of detected PIMs (personal information manager):
Airmail, Barca, Lotus Notes, Microsoft Outlook, Outlook Express, Postbox, The Bat!, Thunderbird
### List of detected feed readers:
Akregator, Apple PubSub, FeedDemon, Feeddler RSS Reader, JetBrains Omea Reader, Liferea, NetNewsWire, Newsbeuter, NewsBlur, NewsBlur Mobile App, Pulp, ReadKit, Reeder, RSS Bandit, RSS Junkie, RSSOwl, Stringer
### List of brands with detected devices:
3Q, Acer, Ainol, Airness, Alcatel, Allview, Altech UEC, Arnova, Amazon, Amoi, Apple, Archos, ARRIS, Airties, Asus, Avvio, Audiovox, Axxion, BBK, Becker, Bird, Beetel, Bmobile, Barnes & Noble, BangOlufsen, BenQ, BenQ-Siemens, Blu, Boway, bq, Brondi, Bush, CUBOT, Carrefour, Captiva, Casio, Cat, Celkon, ConCorde, Changhong, Cherry Mobile, Cricket, Crosscall, Compal, CnM, Crius Mea, CreNova, Capitel, Compaq, Coolpad, Cowon, Cube, Coby Kyros, Danew, Datang, Denver, Desay, Dbtel, DoCoMo, Dicam, Dell, DMM, Doogee, Doov, Dopod, Dune HD, E-Boda, EBEST, Ericsson, ECS, Ezio, Elephone, Easypix, Energy Sistem, Ericy, Eton, eTouch, Evertek, Ezze, Fly, Foxconn, Fujitsu, Garmin-Asus, Gateway, Gemini, Gionee, Gigabyte, Gigaset, GOCLEVER, Goly, Google, Gradiente, Grundig, Haier, Hasee, Hisense, Hi-Level, Hosin, HP, HTC, Huawei, Humax, Hyrican, Hyundai, Ikea, iBall, i-Joy, iBerry, iKoMo, i-mate, iOcean, Infinix, Innostream, Inkti, Intex, i-mobile, INQ, Intek, Inverto, iTel, Jiayu, Jolla, Karbonn, KDDI, Kingsun, Konka, Komu, Koobee, K-Touch, KT-Tech, KOPO, Koridy, Kumai, Kyocera, Kazam, Lava, Lanix, LCT, Lenovo, Lenco, Le Pan, LG, Lingwin, Loewe, Logicom, Lexibook, Majestic, Manta Multimedia, Mobistel, Mecer, Medion, MEEG, Meizu, Metz, MEU, MicroMax, Mediacom, MediaTek, Mio, Mpman, Mofut, Motorola, Microsoft, MSI, Memup, Mitsubishi, MLLED, M.T.T., MyPhone, NEC, Netgear, NGM, Nintendo, Noain, Nokia, Nomi, Nikon, Newgen, Nexian, NextBook, Onda, OnePlus, OPPO, Orange, O2, Ouki, OUYA, Opsson, Panasonic, PEAQ, Philips, Polaroid, Palm, phoneOne, Pantech, Point of View, PolyPad, Pomp, Positivo, Prestigio, ProScan, PULID, Qilive, Qtek, QMobile, Quechua, Overmax, Oysters, Ramos, RCA Tablets, Readboy, Rikomagic, RIM, Roku, Rover, Samsung, Sega, Sony Ericsson, Sencor, Softbank, SFR, Sagem, Sharp, Siemens, Sendo, Skyworth, Smartfren, Sony, Spice, SuperSonic, Selevision, Sanyo, Symphony, Smart, Star, Storex, Stonex, SunVan, Sumvision, Tesla, TCL, Telit, ThL, TiPhone, Tecno Mobile, Tesco, TIANYU, Telefunken, Telenor, T-Mobile, Thomson, Tolino, Toplux, Toshiba, TechnoTrend, Trevi, Tunisie Telecom, Turbo-X, TVC, TechniSat, teXet, Unowhy, Uniscope, UTStarcom, Vastking, Videocon, Vertu, Vitelcom, VK Mobile, ViewSonic, Vestel, Vivo, Voto, Voxtel, Vodafone, Vizio, Videoweb, Walton, Web TV, WellcoM, Wexler, Wiko, Wolder, Wonu, Woxter, Xiaomi, Xolo, Unknown, Yarvik, Yuandao, Yusun, Ytone, Zeemi, Zonda, Zopo, ZTE

View file

@ -1,10 +1,10 @@
{
"name": "piwik/device-detector",
"type": "library",
"description": "The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), and detects browsers, operating systems, devices, brands and models.",
"description": "The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.",
"keywords": ["useragent","parser","devicedetection"],
"homepage": "http://piwik.org",
"license": "GPL-3.0+",
"license": "LGPL-3.0+",
"authors": [
{
"name": "The Piwik Team",
@ -14,15 +14,22 @@
],
"support": {
"forum": "http://forum.piwik.org/",
"issues": "http://dev.piwik.org/trac/roadmap",
"issues": "https://github.com/piwik/device-detector/issues",
"wiki": "http://dev.piwik.org/",
"source": "https://github.com/piwik/piwik"
},
"autoload": {
"files": [ "DeviceDetector.php" ]
"psr-4": { "DeviceDetector\\": "" }
},
"require": {
"php": ">=5.3.1",
"php": ">=5.3.2",
"mustangostang/spyc": "*"
},
"require-dev": {
"phpunit/phpunit": "4.1.*",
"fabpot/php-cs-fixer": "~1.7"
},
"suggest": {
"doctrine/cache": "Can directly be used for caching purpose"
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,540 +0,0 @@
###############
# Piwik - Open source web analytics
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
#
# @category UserAgentParserEnhanced
###############
#SailfishBrowser
- regex: 'SailfishBrowser(?:/(\d+\.\d+))?'
name: 'Sailfish Browser'
version: '$1'
# SeaMonkey
- regex: '(Iceape|SeaMonkey|gnuzilla)(?:/(\d+\.\d+))?'
name: '$1'
version: '$2'
# Camino
- regex: 'Camino(?:/(\d+\.\d+))?'
name: 'Camino'
version: '$1'
#Fennec (Firefox for mobile)
- regex: 'Fennec(?:/(\d+\.\d+))?'
name: 'Fennec'
version: '$1'
#MicroB
- regex: 'Firefox.*Tablet browser (\d+\.\d+)'
name: 'MicroB'
version: '$1'
#Avant Browser
- regex: 'Avant Browser'
name: 'Avant Browser'
version: ''
#Bunjalloo
- regex: 'Bunjalloo(?:/(\d+\.\d+))?'
name: 'Bunjalloo'
version: '$1'
#Iceweasel
- regex: 'Iceweasel(?:/(\d+\.\d+))?'
name: 'Iceweasel'
version: '$1'
#WebPositive
- regex: 'WebPositive'
name: 'WebPositive'
version: ''
#Pale Moon
- regex: 'PaleMoon(?:/(\d+\.\d+))?'
name: 'Pale Moon'
version: '$1'
#CometBird
- regex: 'CometBird(?:/(\d+\.\d+))?'
name: 'CometBird'
version: '$1'
#IceDragon
- regex: 'IceDragon(?:/(\d+\.\d+))?'
name: 'IceDragon'
version: '$1'
#Flock
- regex: 'Flock(?:/(\d+\.\d+))?'
name: 'Flock'
version: '$1'
#Swiftfox
- regex: 'Firefox/(\d+\.\d+).*\(Swiftfox\)'
name: 'Swiftfox'
version: '$1'
#Firefox
- regex: 'Firefox(?:/(\d+\.\d+))?'
name: 'Firefox'
version: '$1'
- regex: '(BonEcho|GranParadiso|Lorentz|Minefield|Namoroka|Shiretoko)/(\d+\.\d+)'
name: 'Firefox'
version: '$1 ($2)'
#ANTGalio
- regex: 'ANTGalio(?:/(\d+\.\d+))?'
name: 'ANTGalio'
version: '$1'
#Espial TV Browser
- regex: '(?:Espial|Escape)(?:[/ ](\d+\.\d+))?'
name: 'Espial TV Browser'
version: '$1'
#RockMelt
- regex: 'RockMelt(?:/(\d+\.\d+))?'
name: 'RockMelt'
version: '$1'
#Netscape
- regex: '(?:Navigator|Netscape6)(?:/(\d+\.\d+))?'
name: 'Netscape'
version: '$1'
#Opera
- regex: '(?:Opera Tablet.*Version|Opera/.+Opera Mobi.+Version|Mobile.+OPR)/(\d+\.\d+)'
name: 'Opera Mobile'
version: '$1'
- regex: 'Opera Mini/(?:att/)?(\d+\.\d+)'
name: 'Opera Mini'
version: '$1'
- regex: 'Opera.+Edition Next.+Version/(\d+\.\d+)'
name: 'Opera Next'
version: '$1'
- regex: '(?:Opera|OPR)[/ ](?:9.80.*Version/)?(\d+\.\d+).+Edition Next'
name: 'Opera Next'
version: '$1'
- regex: '(?:Opera|OPR)[/ ](?:9.80.*Version/)?(\d+\.\d+)'
name: 'Opera'
version: '$1'
#wOSBrowser
- regex: '(?:hpw|web)OS/(\d+\.\d+)'
name: 'wOSBrowser'
version: '$1'
#Rekonq
- regex: 'rekonq(?:/(\d+\.\d+))?'
name: 'Rekonq'
version: '$1'
#CoolNovo
- regex: 'CoolNovo(?:/(\d+\.\d+))?'
name: 'CoolNovo'
version: '$1'
#Comodo Dragon
- regex: 'Comodo[ _]Dragon(?:/(\d+\.\d+))?'
name: 'Comodo Dragon'
version: '$1'
#ChromePlus
- regex: 'ChromePlus(?:/(\d+\.\d+))?'
name: 'ChromePlus'
version: '$1'
#Conkeror
- regex: 'Conkeror(?:/(\d+\.\d+))?'
name: 'Conkeror'
version: '$1'
#Konqueror
- regex: 'Konqueror(?:/(\d+\.\d+))?'
name: 'Konqueror'
version: '$1'
#Baidu Browser
- regex: 'baidubrowser(?:[/ ](\d+(?:\.?\d+)?))?'
name: 'Baidu Browser'
version: '$1'
#Yandex Browser
- regex: 'YaBrowser(?:/(\d+(?:\.?\d+)?))?'
name: 'Yandex Browser'
version: '$1'
#Midori
- regex: 'Midori(?:/(\d+\.\d+))?'
name: 'Midori'
version: '$1'
#Mercury
- regex: 'Mercury(?:/(\d+\.\d+))?'
name: 'Mercury'
version: '$1'
#Maxthon
- regex: 'Maxthon[ /](\d+\.\d+)'
name: 'Maxthon'
version: '$1'
- regex: '(?:Maxthon|MyIE2|Uzbl|Shiira)'
name: 'Maxthon'
version: ''
#Puffin
- regex: 'Puffin(?:/(\d+\.\d+))?'
name: 'Puffin'
version: '$1'
#Iron
- regex: 'Iron(?:/(\d+\.\d+))?'
name: 'Iron'
version: '$1'
#Epiphany
- regex: 'Epiphany(?:/(\d+\.\d+))?'
name: 'Epiphany'
version: '$1'
#Chrome
- regex: 'CrMo(?:/(\d+\.\d+))?'
name: 'Chrome Mobile'
version: '$1'
- regex: 'CriOS(?:/(\d+\.\d+))?'
name: 'Chrome Mobile iOS'
version: '$1'
- regex: 'Chrome(?:/(\d+\.\d+))?.*Mobile'
name: 'Chrome Mobile'
version: '$1'
- regex: 'chromeframe(?:/(\d+\.\d+))?'
name: 'Chrome Frame'
version: '$1'
- regex: 'Chrome(?:/(\d+\.\d+))?'
name: 'Chrome'
version: '$1'
- regex: 'Chromium(?:/(\d+\.\d+))?'
name: 'Chromium'
version: '$1'
#UC Browser
- regex: 'UC[ ]?Browser(?:[ /]?(\d+\.\d+))?'
name: 'UC Browser'
version: '$1'
- regex: 'UCWEB(?:[ /]?(\d+\.\d+))?'
name: 'UC Browser'
version: '$1'
#Tizen Browser
- regex: '(?:Tizen|SLP) Browser(?:/(\d+\.\d+))?'
name: 'Tizen Browser'
version: '$1'
#Palm Blazer
- regex: 'Blazer(?:/(\d+\.\d+))?'
name: 'Palm Blazer'
version: '$1'
- regex: 'Pre/(\d+\.\d+)'
name: 'Palm Pre'
version: '$1'
#Palm WebPro
- regex: 'WebPro(?:[ /](\d+\.\d+))?'
name: 'Palm WebPro'
version: '$1'
#Fireweb Navigator
- regex: 'Fireweb Navigator(?:/(\d+\.\d+))?'
name: 'Fireweb Navigator'
version: '$1'
#Jasmine
- regex: 'Jasmine(?:[ /](\d+\.\d+))?'
name: 'Jasmine'
version: '$1'
#Lynx
- regex: 'Lynx(?:/(\d+\.\d+))?'
name: 'Lynx'
version: '$1'
#NCSA Mosaic
- regex: 'NCSA_Mosaic(?:/(\d+\.\d+))?'
name: 'NCSA Mosaic'
version: '$1'
#ABrowse
- regex: 'ABrowse(?: (\d+\.\d+))?'
name: 'ABrowse'
version: '$1'
#Amaya
- regex: 'amaya(?:/(\d+\.\d+))?'
name: 'Amaya'
version: '$1'
#Amiga Voyager
- regex: 'AmigaVoyager(?:/(\d+\.\d+))?'
name: 'Amiga Voyager'
version: '$1'
#Amiga Aweb
- regex: 'Amiga-Aweb(?:/(\d+\.\d+))?'
name: 'Amiga Aweb'
version: '$1'
#Arora
- regex: 'Arora(?:/(\d+\.\d+))?'
name: 'Arora'
version: '$1'
#Beonex
- regex: 'Beonex(?:/(\d+\.\d+))?'
name: 'Beonex'
version: '$1'
#BlackBerry Browser
- regex: 'BlackBerry|PlayBook|BB10'
name: 'BlackBerry Browser'
version: ''
#BrowseX
- regex: 'BrowseX \((\d+\.\d+)'
name: 'BrowseX'
version: '$1'
#Charon
- regex: 'Charon(?:[/ ](\d+\.\d+))?'
name: 'Charon'
version: '$1'
#Cheshire
- regex: 'Cheshire(?:/(\d+\.\d+))?'
name: 'Cheshire'
version: '$1'
#Dillo
- regex: 'Dillo(?:/(\d+\.\d+))?'
name: 'Dillo'
version: '$1'
#Dolphin
- regex: 'Dolfin(?:/(\d+\.\d+))?|dolphin'
name: 'Dolphin'
version: '$1'
#Elinks
- regex: 'Elinks(?:/(\d+\.\d+))?'
name: 'Elinks'
version: '$1'
#Firebird
- regex: 'Firebird(?:/(\d+\.\d+))?'
name: 'Firebird'
version: '$1'
#Fluid
- regex: 'Fluid(?:/(\d+\.\d+))?'
name: 'Fluid'
version: '$1'
#Galeon
- regex: 'Galeon(?:/(\d+\.\d+))?'
name: 'Galeon'
version: '$1'
#Google Earth
- regex: 'Google Earth(?:/(\d+\.\d+))?'
name: 'Google Earth'
version: '$1'
#HotJava
- regex: 'HotJava(?:/(\d+\.\d+))?'
name: 'HotJava'
version: '$1'
#IBrowse
- regex: 'IBrowse(?:[ /](\d+\.\d+))?'
name: 'IBrowse'
version: '$1'
#iCab
- regex: 'iCab(?:[ /](\d+\.\d+))?'
name: 'iCab'
version: '$1'
#Sleipnir
- regex: 'Sleipnir(?:[ /](\d+\.\d+))?'
name: 'Sleipnir'
version: '$1'
#Lunascape
- regex: 'Lunascape(?:[/ ](\d+\.\d+))?'
name: 'Lunascape'
version: '$1'
#Internet Explorer
- regex: 'IEMobile[ /](\d+\.\d+)'
name: 'IE Mobile'
version: '$1'
- regex: 'MSIE (\d+\.\d+).*XBLWP7'
name: 'IE Mobile'
version: '$1'
- regex: 'MSIE.*Trident/4.0'
name: 'Internet Explorer'
version: 8.0
- regex: 'MSIE.*Trident/5.0'
name: 'Internet Explorer'
version: 9.0
- regex: 'MSIE.*Trident/6.0'
name: 'Internet Explorer'
version: 10.0
- regex: 'Trident/7.0'
name: 'Internet Explorer'
version: 11.0
- regex: 'MSIE (\d+\.\d+)'
name: 'Internet Explorer'
version: '$1'
- regex: 'IE[ /](\d+\.\d+)'
name: 'Internet Explorer'
version: '$1'
#Kapiko
- regex: 'Kapiko(?:/(\d+\.\d+))?'
name: 'Kapiko'
version: '$1'
#Kazehakase
- regex: 'Kazehakase(?:/(\d+\.\d+))?'
name: 'Kazehakase'
version: '$1'
#Kindle Browser
- regex: 'Kindle/(\d+\.\d+)'
name: 'Kindle Browser'
version: '$1'
#K-meleon
- regex: 'K-meleon(?:/(\d+\.\d+))?'
name: 'K-meleon'
version: '$1'
#Lightning
- regex: 'Lightning(?:/(\d+\.\d+))?'
name: 'Lightning'
version: '$1'
#Links
- regex: 'Links(?: \((\d+\.\d+))?'
name: 'Links'
version: '$1'
#Openwave Mobile Browser
- regex: 'UP.Browser(?:/(\d+\.\d+))?'
name: 'Openwave Mobile Browser'
version: '$1'
#OmniWeb
- regex: 'OmniWeb(?:/[v]?(\d+\.\d+))?'
name: 'OmniWeb'
version: '$1'
#Phoenix
- regex: 'Phoenix(?:/(\d+\.\d+))?'
name: 'Phoenix'
version: '$1'
#Mobile Silk
- regex: 'Silk(?:/(\d+\.\d+))?'
name: 'Mobile Silk'
version: '$1'
#Nokia Browser
- regex: '(?:NokiaBrowser|BrowserNG)(?:/(\d+\.\d+))?'
name: 'Nokia Browser'
version: '$1'
- regex: 'Series60/5\.0'
name: 'Nokia Browser'
version: '7.0'
- regex: 'Series60/(\d+\.\d+)'
name: 'Nokia OSS Browser'
version: '$1'
- regex: 'S40OviBrowser/(\d+\.\d+)'
name: 'Nokia Ovi Browser'
version: '$1'
- regex: '^Nokia|Nokia[EN]?\d+'
name: 'Nokia Browser'
version: ''
#NetFront
- regex: 'NetFrontLifeBrowser(?:/(\d+\.\d+))?'
name: 'NetFront Life'
version: '$1'
- regex: 'NetFront(?:/(\d+\.\d+))?'
name: 'NetFront'
version: '$1'
- regex: 'PLAYSTATION|NINTENDO 3|AppleWebKit.+ NX/\d+\.\d+\.\d+'
name: 'NetFront'
version: ''
#NetPositive
- regex: 'NetPositive(?:/(\d+\.\d+))?'
name: 'NetPositive'
version: '$1'
#Obigo
- regex: 'Obigo[ ]?(?:InternetBrowser|Browser)?(?:[ /]([a-z0-9]*))?'
name: 'Obigo'
version: '$1'
- regex: 'Obigo|Teleca'
name: 'Obigo'
version: ''
#Oregano
- regex: 'Oregano(?:[ /](\d+\.\d+))?'
name: 'Oregano'
version: '$1'
#Polaris
- regex: '(?:Polaris|Embider)(?:/(\d+\.\d+))?'
name: 'Polaris'
version: '$1'
#Snowshoe
- regex: 'Snowshoe(?:/(\d+\.\d+))?'
name: 'Snowshoe'
version: '$1'
#Thunderbird
- regex: 'Thunderbird(?:/(\d+\.\d+))?'
name: 'Thunderbird'
version: '$1'
#Xiino
- regex: 'Xiino(?:/(\d+\.\d+))?'
name: 'Xiino'
version: '$1'
#Android Browser
- regex: 'Android'
name: 'Android Browser'
version: ''
#Safari
- regex: '(?:iPod|iPad|iPhone).+Version/(\d+\.\d+)'
name: 'Mobile Safari'
version: '$1'
- regex: 'Version/(\d+\.\d+).*Mobile.*Safari/'
name: 'Mobile Safari'
version: '$1'
- regex: '(?:iPod|iPhone|iPad)'
name: 'Mobile Safari'
version: ''
- regex: 'Version/(\d+\.\d+).*Safari/|Safari/\d+'
name: 'Safari'
version: '$1'

View file

@ -0,0 +1,30 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
- regex: 'NetFront'
name: 'NetFront'
- regex: 'Edge'
name: 'Edge'
- regex: 'Trident'
name: 'Trident'
- regex: 'Blink'
name: 'Blink'
- regex: '(?:Apple)?WebKit'
name: 'WebKit'
- regex: 'Presto'
name: 'Presto'
- regex: '(?<!like )Gecko'
name: 'Gecko'
- regex: 'KHTML'
name: 'KHTML'

View file

@ -0,0 +1,844 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
# Microsoft Edge (newer versions of IE)
- regex: 'Edge[ /](\d+[\.\d]+)'
name: 'Microsoft Edge'
version: '$1'
engine:
default: 'Edge'
# 360 Browser
- regex: 'QIHU 360[ES]E'
name: '360 Browser'
version: ''
# 360 Phone Browser
- regex: '360 Aphone Browser(?: \((\d+[\.\d]+)(?:beta)?\))?'
name: '360 Phone Browser'
version: '$1'
engine:
default: 'WebKit'
#SailfishBrowser
- regex: 'SailfishBrowser(?:/(\d+[\.\d]+))?'
name: 'Sailfish Browser'
version: '$1'
engine:
default: 'Gecko'
# SeaMonkey
- regex: '(Iceape|SeaMonkey|gnuzilla)(?:/(\d+[\.\d]+))?'
name: '$1'
version: '$2'
engine:
default: 'Gecko'
# Camino
- regex: 'Camino(?:/(\d+[\.\d]+))?'
name: 'Camino'
version: '$1'
engine:
default: 'Gecko'
#Fennec (Firefox for mobile)
- regex: 'Fennec(?:/(\d+[\.\d]+))?'
name: 'Fennec'
version: '$1'
engine:
default: 'Gecko'
#MicroB
- regex: 'Firefox.*Tablet browser (\d+[\.\d]+)'
name: 'MicroB'
version: '$1'
engine:
default: 'Gecko'
- regex: 'Maemo Browser(?: (\d+[\.\d]+))?'
name: 'MicroB'
version: '$1'
engine:
default: 'Gecko'
#Deepnet Explorer
- regex: 'Deepnet Explorer (\d+[\.\d]+)?'
name: 'Deepnet Explorer'
version: '$1'
#Avant Browser
- regex: 'Avant Browser'
name: 'Avant Browser'
version: ''
engine:
default: '' # multiple
#Amigo
- regex: 'Chrome/(\d+[\.\d]+).*MRCHROME'
name: 'Amigo'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
#Bunjalloo
- regex: 'Bunjalloo(?:/(\d+[\.\d]+))?'
name: 'Bunjalloo'
version: '$1'
#Iceweasel
- regex: 'Iceweasel(?:/(\d+[\.\d]+))?'
name: 'Iceweasel'
version: '$1'
engine:
default: 'Gecko'
#WebPositive
- regex: 'WebPositive'
name: 'WebPositive'
version: ''
engine:
default: 'WebKit'
#Pale Moon
- regex: 'PaleMoon(?:/(\d+[\.\d]+))?'
name: 'Pale Moon'
version: '$1'
engine:
default: 'Gecko'
#CometBird
- regex: 'CometBird(?:/(\d+[\.\d]+))?'
name: 'CometBird'
version: '$1'
engine:
default: 'Gecko'
#IceDragon
- regex: 'IceDragon(?:/(\d+[\.\d]+))?'
name: 'IceDragon'
version: '$1'
engine:
default: 'Gecko'
#Flock
- regex: 'Flock(?:/(\d+[\.\d]+))?'
name: 'Flock'
version: '$1'
engine:
default: 'Gecko'
versions:
3: 'WebKit'
#Kapiko
- regex: 'Kapiko(?:/(\d+[\.\d]+))?'
name: 'Kapiko'
version: '$1'
engine:
default: 'Gecko'
#Kylo
- regex: 'Kylo(?:/(\d+[\.\d]+))?'
name: 'Kylo'
version: '$1'
engine:
default: 'Gecko'
#Swiftfox
- regex: 'Firefox/(\d+[\.\d]+).*\(Swiftfox\)'
name: 'Swiftfox'
version: '$1'
engine:
default: 'Gecko'
#Firefox
- regex: 'Firefox(?:/(\d+[\.\d]+))?'
name: 'Firefox'
version: '$1'
engine:
default: 'Gecko'
- regex: '(BonEcho|GranParadiso|Lorentz|Minefield|Namoroka|Shiretoko)/(\d+[\.\d]+)'
name: 'Firefox'
version: '$1 ($2)'
engine:
default: 'Gecko'
- regex: 'FxiOS/(\d+[\.\d]+)'
name: 'Firefox'
version: 'iOS $1'
engine:
default: 'WebKit'
#ANTGalio
- regex: 'ANTGalio(?:/(\d+[\.\d]+))?'
name: 'ANTGalio'
version: '$1'
#Espial TV Browser
- regex: '(?:Espial|Escape)(?:[/ ](\d+[\.\d]+))?'
name: 'Espial TV Browser'
version: '$1'
#RockMelt
- regex: 'RockMelt(?:/(\d+[\.\d]+))?'
name: 'RockMelt'
version: '$1'
engine:
default: 'WebKit'
#Fireweb Navigator
- regex: 'Fireweb Navigator(?:/(\d+[\.\d]+))?'
name: 'Fireweb Navigator'
version: '$1'
#Netscape
- regex: '(?:Navigator|Netscape6)(?:/(\d+[\.\d]+))?'
name: 'Netscape'
version: '$1'
engine:
default: '' # Mosaic in the first versions, then Gecko
#Opera
- regex: '(?:Opera Tablet.*Version|Opera/.+Opera Mobi.+Version|Mobile.+OPR)/(\d+[\.\d]+)'
name: 'Opera Mobile'
version: '$1'
engine:
default: 'Presto'
versions:
15: 'Blink'
- regex: 'Opera Mini/(?:att/)?(\d+[\.\d]+)'
name: 'Opera Mini'
version: '$1'
engine:
default: 'Presto'
- regex: 'Opera.+Edition Next.+Version/(\d+[\.\d]+)'
name: 'Opera Next'
version: '$1'
engine:
default: 'Presto'
versions:
15: 'Blink'
- regex: '(?:Opera|OPR)[/ ](?:9.80.*Version/)?(\d+[\.\d]+).+Edition Next'
name: 'Opera Next'
version: '$1'
engine:
default: 'Presto'
versions:
15: 'Blink'
- regex: '(?:Opera|OPR)[/ ](?:9.80.*Version/)?(\d+[\.\d]+)'
name: 'Opera'
version: '$1'
engine:
default: 'Presto'
versions:
15: 'Blink'
#Rekonq
- regex: 'rekonq(?:/(\d+[\.\d]+))?'
name: 'Rekonq'
version: '$1'
engine:
default: 'WebKit'
#CoolNovo (former ChromePlus)
- regex: 'CoolNovo(?:/(\d+[\.\d]+))?'
name: 'CoolNovo'
version: '$1'
engine:
default: '' # multi engine
#Comodo Dragon
- regex: 'Comodo[ _]Dragon(?:/(\d+[\.\d]+))?'
name: 'Comodo Dragon'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
#ChromePlus
- regex: 'ChromePlus(?:/(\d+[\.\d]+))?'
name: 'ChromePlus'
version: '$1'
engine:
default: '' # multi engine
#Conkeror
- regex: 'Conkeror(?:/(\d+[\.\d]+))?'
name: 'Conkeror'
version: '$1'
engine:
default: 'Gecko'
#Konqueror
- regex: 'Konqueror(?:/(\d+[\.\d]+))?'
name: 'Konqueror'
version: '$1'
engine:
default: 'KHTML'
versions:
4: '' # multiple (KHTML or WebKit)
#Baidu Browser
- regex: 'baidubrowser(?:[/ ](\d+[\.\d]*))?'
name: 'Baidu Browser'
version: '$1'
#Baidu Spark
- regex: '(?:(?:BD)?Spark|BIDUBrowser)[/ ](\d+[\.\d]*)'
name: 'Baidu Spark'
version: '$1'
#Yandex Browser
- regex: 'YaBrowser(?:/(\d+[\.\d]*))?'
name: 'Yandex Browser'
version: '$1'
engine:
default: 'Blink'
#Vivaldi
- regex: 'Vivaldi(?:/(\d+[\.\d]+))?'
name: 'Vivaldi'
version: '$1'
engine:
default: 'Blink'
#Midori
- regex: 'Midori(?:/(\d+[\.\d]+))?'
name: 'Midori'
version: '$1'
engine:
default: 'WebKit'
#Mercury
- regex: 'Mercury(?:/(\d+[\.\d]+))?'
name: 'Mercury'
version: '$1'
#Maxthon
- regex: '(?:Maxthon|MxBrowser)[ /](\d+[\.\d]+)'
name: 'Maxthon'
version: '$1'
engine:
default: '' # Trident and WebKit
versions:
3: 'WebKit'
- regex: '(?:Maxthon|MyIE2|Uzbl)'
name: 'Maxthon'
version: ''
engine:
default: '' # Trident and WebKit
#Puffin
- regex: 'Puffin(?:/(\d+[\.\d]+))?'
name: 'Puffin'
version: '$1'
#Iron
- regex: 'Iron(?:/(\d+[\.\d]+))?'
name: 'Iron'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
#Epiphany
- regex: 'Epiphany(?:/(\d+[\.\d]+))?'
name: 'Epiphany'
version: '$1'
engine:
default: 'Gecko'
versions:
2.9.16: '' # multi engine
2.28: 'WebKit'
# Liebao
- regex: 'LBBrowser(?:[ /](\d+[\.\d]+))?'
name: 'Liebao'
version: '$1'
# Sogou Explorer
- regex: 'SE (\d+[\.\d]+)'
name: 'Sogou Explorer'
version: '$1'
# QQ Browser
- regex: 'M?QQBrowser/([\.\d]+)'
name: 'QQ Browser'
version: '$1'
# MIUI Browser
- regex: 'MIUIBrowser(?:/(\d+[\.\d]+))?'
name: 'MIUI Browser'
version: '$1'
# Coc Coc
# This browser (http://coccoc.vn/) is built on top of Chromium with
# additional features for Vietnamese users. Its regex has to be placed
# before generic Chrome regex, or Chrome regex will match first and
# the browser is mistaken as "Chrome".
- regex: 'coc_coc_browser(?:/(\d+[\.\d]+))?'
name: 'Coc Coc'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
#Chrome
- regex: 'CrMo(?:/(\d+[\.\d]+))?'
name: 'Chrome Mobile'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
- regex: 'CriOS(?:/(\d+[\.\d]+))?'
name: 'Chrome Mobile iOS'
version: '$1'
engine:
default: 'WebKit'
- regex: 'Chrome(?:/(\d+[\.\d]+))? Mobile'
name: 'Chrome Mobile'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
- regex: 'chromeframe(?:/(\d+[\.\d]+))?'
name: 'Chrome Frame'
version: '$1'
engine:
default: 'WebKit'
- regex: 'Chromium(?:/(\d+[\.\d]+))?'
name: 'Chromium'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
- regex: 'Chrome(?:/(\d+[\.\d]+))?'
name: 'Chrome'
version: '$1'
engine:
default: 'WebKit'
versions:
28: 'Blink'
#UC Browser
- regex: 'UC[ ]?Browser(?:[ /]?(\d+[\.\d]+))?'
name: 'UC Browser'
version: '$1'
- regex: 'UCWEB(?:[ /]?(\d+[\.\d]+))?'
name: 'UC Browser'
version: '$1'
#Tizen Browser
- regex: '(?:Tizen|SLP) Browser(?:/(\d+[\.\d]+))?'
name: 'Tizen Browser'
version: '$1'
#Palm Blazer
- regex: 'Blazer(?:/(\d+[\.\d]+))?'
name: 'Palm Blazer'
version: '$1'
- regex: 'Pre/(\d+[\.\d]+)'
name: 'Palm Pre'
version: '$1'
#wOSBrowser
- regex: '(?:hpw|web)OS/(\d+[\.\d]+)'
name: 'wOSBrowser'
version: '$1'
#Palm WebPro
- regex: 'WebPro(?:[ /](\d+[\.\d]+))?'
name: 'Palm WebPro'
version: '$1'
#Jasmine
- regex: 'Jasmine(?:[ /](\d+[\.\d]+))?'
name: 'Jasmine'
version: '$1'
#Lynx
- regex: 'Lynx(?:/(\d+[\.\d]+))?'
name: 'Lynx'
version: '$1'
engine:
default: 'Text-based'
#NCSA Mosaic
- regex: 'NCSA_Mosaic(?:/(\d+[\.\d]+))?'
name: 'NCSA Mosaic'
version: '$1'
#ABrowse
- regex: 'ABrowse(?: (\d+[\.\d]+))?'
name: 'ABrowse'
version: '$1'
#Amaya
- regex: 'amaya(?:/(\d+[\.\d]+))?'
name: 'Amaya'
version: '$1'
#Amiga Voyager
- regex: 'AmigaVoyager(?:/(\d+[\.\d]+))?'
name: 'Amiga Voyager'
version: '$1'
#Amiga Aweb
- regex: 'Amiga-Aweb(?:/(\d+[\.\d]+))?'
name: 'Amiga Aweb'
version: '$1'
#Arora
- regex: 'Arora(?:/(\d+[\.\d]+))?'
name: 'Arora'
version: '$1'
engine:
default: 'WebKit'
#Beonex
- regex: 'Beonex(?:/(\d+[\.\d]+))?'
name: 'Beonex'
version: '$1'
engine:
default: 'Gecko'
#BrowseX
- regex: 'BrowseX \((\d+[\.\d]+)'
name: 'BrowseX'
version: '$1'
#Charon
- regex: 'Charon(?:[/ ](\d+[\.\d]+))?'
name: 'Charon'
version: '$1'
#Cheshire
- regex: 'Cheshire(?:/(\d+[\.\d]+))?'
name: 'Cheshire'
version: '$1'
#Dillo
- regex: 'Dillo(?:/(\d+[\.\d]+))?'
name: 'Dillo'
version: '$1'
engine:
default: 'Dillo'
#Dolphin
- regex: 'Dolfin(?:/(\d+[\.\d]+))?|dolphin'
name: 'Dolphin'
version: '$1'
engine:
default: 'WebKit'
#Elinks
- regex: 'Elinks(?:/(\d+[\.\d]+))?'
name: 'Elinks'
version: '$1'
engine:
default: 'Text-based'
#Firebird
- regex: 'Firebird(?:/(\d+[\.\d]+))?'
name: 'Firebird'
version: '$1'
engine:
default: 'Gecko'
#Fluid
- regex: 'Fluid(?:/(\d+[\.\d]+))?'
name: 'Fluid'
version: '$1'
engine:
default: 'WebKit'
#Galeon
- regex: 'Galeon(?:/(\d+[\.\d]+))?'
name: 'Galeon'
version: '$1'
engine:
default: 'Gecko'
#Google Earth
- regex: 'Google Earth(?:/(\d+[\.\d]+))?'
name: 'Google Earth'
version: '$1'
engine:
default: 'WebKit'
#HotJava
- regex: 'HotJava(?:/(\d+[\.\d]+))?'
name: 'HotJava'
version: '$1'
#IBrowse
- regex: 'IBrowse(?:[ /](\d+[\.\d]+))?'
name: 'IBrowse'
version: '$1'
#iCab
- regex: 'iCab(?:[ /](\d+[\.\d]+))?'
name: 'iCab'
version: '$1'
engine:
default: 'iCab'
versions:
4: 'WebKit'
#Sleipnir
- regex: 'Sleipnir(?:[ /](\d+[\.\d]+))?'
name: 'Sleipnir'
version: '$1'
engine:
default: '' # multi engine
#Lunascape
- regex: 'Lunascape(?:[/ ](\d+[\.\d]+))?'
name: 'Lunascape'
version: '$1'
engine:
default: '' # multi engine
#Internet Explorer
- regex: 'IEMobile[ /](\d+[\.\d]+)'
name: 'IE Mobile'
version: '$1'
engine:
default: 'Trident'
- regex: 'MSIE (\d+[\.\d]+).*XBLWP7'
name: 'IE Mobile'
version: '$1'
engine:
default: 'Trident'
- regex: 'MSIE.*Trident/4.0'
name: 'Internet Explorer'
version: 8.0
engine:
default: 'Trident'
- regex: 'MSIE.*Trident/5.0'
name: 'Internet Explorer'
version: 9.0
engine:
default: 'Trident'
- regex: 'MSIE.*Trident/6.0'
name: 'Internet Explorer'
version: 10.0
engine:
default: 'Trident'
- regex: 'Trident/7.0'
name: 'Internet Explorer'
version: 11.0
engine:
default: 'Trident'
- regex: 'MSIE (\d+[\.\d]+)'
name: 'Internet Explorer'
version: '$1'
engine:
default: 'Trident'
- regex: 'IE[ /](\d+[\.\d]++)'
name: 'Internet Explorer'
version: '$1'
engine:
default: 'Trident'
#Kazehakase
- regex: 'Kazehakase(?:/(\d+[\.\d]+))?'
name: 'Kazehakase'
version: '$1'
engine:
default: '' # multi engine
#Kindle Browser
- regex: 'Kindle/(\d+[\.\d]+)'
name: 'Kindle Browser'
version: '$1'
#K-meleon
- regex: 'K-meleon(?:/(\d+[\.\d]+))?'
name: 'K-meleon'
version: '$1'
engine:
default: 'Gecko'
#Links
- regex: 'Links(?: \((\d+[\.\d]+))?'
name: 'Links'
version: '$1'
engine:
default: 'Text-based'
#Openwave Mobile Browser
- regex: 'UP.Browser(?:/(\d+[\.\d]+))?'
name: 'Openwave Mobile Browser'
version: '$1'
#OmniWeb
- regex: 'OmniWeb(?:/[v]?(\d+[\.\d]+))?'
name: 'OmniWeb'
version: '$1'
engine:
default: 'WebKit'
#Phoenix
- regex: 'Phoenix(?:/(\d+[\.\d]+))?'
name: 'Phoenix'
version: '$1'
#Mobile Silk
- regex: 'Silk(?:/(\d+[\.\d]+))?'
name: 'Mobile Silk'
version: '$1'
engine:
default: 'Blink'
#NetFront
- regex: 'NetFrontLifeBrowser(?:/(\d+[\.\d]+))?'
name: 'NetFront Life'
version: '$1'
engine:
default: 'NetFront'
- regex: 'NetFront(?:/(\d+[\.\d]+))?'
name: 'NetFront'
version: '$1'
engine:
default: 'NetFront'
- regex: 'PLAYSTATION|NINTENDO 3|AppleWebKit.+ NX/\d+\.\d+\.\d+'
name: 'NetFront'
version: ''
#NetPositive
- regex: 'NetPositive(?:/(\d+[\.\d]+))?'
name: 'NetPositive'
version: '$1'
#Obigo
- regex: 'Obigo[ ]?(?:InternetBrowser|Browser)?(?:[ /]([a-z0-9]*))?'
name: 'Obigo'
version: '$1'
- regex: 'Obigo|Teleca'
name: 'Obigo'
version: ''
#Odyssey Web Browser
- regex: 'Odyssey Web Browser(?:.*OWB/(\d+[\.\d]+))?'
name: 'Odyssey Web Browser'
version: '$1'
#Off By One
- regex: 'OffByOne'
name: 'Off By One'
version: ''
#ONE Browser
- regex: 'OneBrowser(?:[ /](\d+[\.\d]+))?'
name: 'ONE Browser'
version: '$1'
engine:
default: 'WebKit'
#Oregano
- regex: 'Oregano(?:[ /](\d+[\.\d]+))?'
name: 'Oregano'
version: '$1'
#Polaris
- regex: '(?:Polaris|Embider)(?:[/ ](\d+[\.\d]+))?'
name: 'Polaris'
version: '$1'
#SEMC Browser
- regex: 'SEMC-Browser(?:[/ ](\d+[\.\d]+))?'
name: 'SEMC-Browser'
version: '$1'
#Shiira
- regex: 'Shiira(?:[/ ](\d+[\.\d]+))?'
name: 'Shiira'
version: '$1'
engine:
default: 'WebKit'
#Snowshoe
- regex: 'Snowshoe(?:/(\d+[\.\d]+))?'
name: 'Snowshoe'
version: '$1'
engine:
default: 'WebKit'
#Sunrise
- regex: 'Sunrise(?:Browser)?(?:/(\d+[\.\d]+))?'
name: 'Sunrise'
version: '$1'
# WeTab Browser
- regex: 'WeTab-Browser'
name: 'WeTab Browser'
version: ''
#Xiino
- regex: 'Xiino(?:/(\d+[\.\d]+))?'
name: 'Xiino'
version: '$1'
#Nokia Browser
- regex: '(?:NokiaBrowser|BrowserNG)(?:/(\d+[\.\d]+))?'
name: 'Nokia Browser'
version: '$1'
- regex: 'Series60/5\.0'
name: 'Nokia Browser'
version: '7.0'
- regex: 'Series60/(\d+[\.\d]+)'
name: 'Nokia OSS Browser'
version: '$1'
- regex: 'S40OviBrowser/(\d+[\.\d]+)'
name: 'Nokia Ovi Browser'
version: '$1'
- regex: '^Nokia|Nokia[EN]?\d+'
name: 'Nokia Browser'
version: ''
#BlackBerry Browser
- regex: 'BlackBerry|PlayBook|BB10'
name: 'BlackBerry Browser'
version: ''
#Android Browser
- regex: 'Android'
name: 'Android Browser'
version: ''
engine:
default: 'WebKit'
#Safari
- regex: '(?:iPod|iPad|iPhone).+Version/(\d+[\.\d]+)'
name: 'Mobile Safari'
version: '$1'
engine:
default: 'WebKit'
- regex: 'Version/(\d+[\.\d]+).*Mobile.*Safari/'
name: 'Mobile Safari'
version: '$1'
engine:
default: 'WebKit'
- regex: '(?:iPod|iPhone|iPad)'
name: 'Mobile Safari'
version: ''
engine:
default: 'WebKit'
- regex: 'Version/(\d+[\.\d]+).*Safari/|Safari/\d+'
name: 'Safari'
version: '$1'
engine:
default: 'WebKit'

View file

@ -0,0 +1,108 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
- regex: 'Akregator(?:/(\d+[\.\d]+))?'
name: 'Akregator'
version: '$1'
url: 'http://userbase.kde.org/Akregator'
type: 'Feed Reader'
- regex: 'Apple-PubSub(?:/(\d+[\.\d]+))?'
name: 'Apple PubSub'
version: '$1'
url: 'https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/pubsub.1.html'
type: 'Feed Reader'
- regex: 'FeedDemon(?:/(\d+[\.\d]+))?'
name: 'FeedDemon'
version: '$1'
url: 'http://www.feeddemon.com/'
type: 'Feed Reader'
- regex: 'Feeddler(?:RSS|PRO)(?:[/ ](\d+[\.\d]+))?'
name: 'Feeddler RSS Reader'
version: '$1'
url: 'http://www.chebinliu.com/projects/iphone/feeddler-rss-reader/'
type: 'Feed Reader App'
- regex: 'JetBrains Omea Reader(?:[/ ](\d+[\.\d]+))?'
name: 'JetBrains Omea Reader'
version: '$1'
url: 'http://www.jetbrains.com/omea/reader/'
type: 'Feed Reader'
- regex: 'Liferea(?:[/ ](\d+[\.\d]+))?'
name: 'Liferea'
version: '$1'
url: 'http://liferea.sf.net/'
type: 'Feed Reader'
- regex: 'NetNewsWire(?:[/ ](\d+[\.\d]+))?'
name: 'NetNewsWire'
version: '$1'
url: 'http://netnewswireapp.com/'
type: 'Feed Reader'
- regex: 'NewsBlur (?:iPhone|iPad) App(?: v(\d+[\.\d]+))?'
name: 'NewsBlur Mobile App'
version: '$1'
url: 'http://www.newsblur.com'
type: 'Feed Reader App'
- regex: 'NewsBlur(?:/(\d+[\.\d]+))'
name: 'NewsBlur'
version: '$1'
url: 'http://www.newsblur.com'
type: 'Feed Reader'
- regex: 'newsbeuter(?:[/ ](\d+[\.\d]+))?'
name: 'Newsbeuter'
version: '$1'
url: 'http://www.newsbeuter.org/'
type: 'Feed Reader'
- regex: 'Pulp(?:[/ ](\d+[\.\d]+))?'
name: 'Pulp'
version: '$1'
url: 'http://www.acrylicapps.com/pulp/'
type: 'Feed Reader App'
- regex: 'ReadKit(?:[/ ](\d+[\.\d]+))?'
name: 'ReadKit'
version: '$1'
url: 'http://readkitapp.com/'
type: 'Feed Reader App'
- regex: 'Reeder(?:[/ ](\d+[\.\d]+))?'
name: 'Reeder'
version: '$1'
url: 'http://reederapp.com/'
type: 'Feed Reader App'
- regex: 'RSSBandit(?:[/ ](\d+[\.\d]+))?'
name: 'RSS Bandit'
version: '$1'
url: 'http://www.rssbandit.org)'
type: 'Feed Reader'
- regex: 'RSS Junkie(?:[/ ](\d+[\.\d]+))?'
name: 'RSS Junkie'
version: '$1'
url: 'https://play.google.com/store/apps/details?id=com.bitpowder.rssjunkie'
type: 'Feed Reader App'
- regex: 'RSSOwl(?:[/ ](\d+[\.\d]+))?'
name: 'RSSOwl'
version: '$1'
url: 'http://www.rssowl.org/'
type: 'Feed Reader'
- regex: 'Stringer'
name: 'Stringer'
version: ''
url: 'https://github.com/swanson/stringer'
type: 'Feed Reader'

View file

@ -0,0 +1,34 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
- regex: 'Wget(?:/(\d+[\.\d]+))?'
name: 'Wget'
version: '$1'
- regex: 'Guzzle(?:/(\d+[\.\d]+))?'
name: 'Guzzle (PHP HTTP Client)'
version: '$1'
- regex: '(?:lib)?curl(?:/(\d+[\.\d]+))?'
name: 'curl'
version: '$1'
- regex: 'python-requests(?:/(\d+[\.\d]+))?'
name: 'Python Requests'
version: '$1'
- regex: 'Python-urllib(?:/?(\d+[\.\d]+))?'
name: 'Python urllib'
version: '$1'
- regex: 'Java(?:/?(\d+[\.\d]+))?'
name: 'Java'
version: '$1'
- regex: '(?:perlclient|libwww-perl)(?:/?(\d+[\.\d]+))?'
name: 'Perl'
version: '$1'

View file

@ -0,0 +1,78 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
- regex: 'Banshee(?:[ /]([\d\.]+))?'
name: 'Banshee'
version: '$1'
- regex: 'Clementine(?:[ /]([\d\.]+))?'
name: 'Clementine'
version: '$1'
- regex: 'iTunes(?:/([\d\.]+))?'
name: 'iTunes'
version: '$1'
- regex: 'FlyCast(?:/([\d\.]+))?'
name: 'FlyCast'
version: '$1'
- regex: 'MediaMonkey(?:[ /](\d+[\.\d]+))?'
name: 'MediaMonkey'
version: '$1'
- regex: 'Miro(?:/(\d+[\.\d]+))?'
name: 'Miro'
version: '$1'
- regex: 'NexPlayer(?:/(\d+[\.\d]+))?'
name: 'NexPlayer'
version: '$1'
- regex: 'Nightingale(?:/([\d\.]+))?'
name: 'Nightingale'
version: '$1'
- regex: 'QuickTime(?:(?:(?:.+qtver=)|(?:(?: E-)?[\./]))([\d\.]+))?'
name: 'QuickTime'
version: '$1'
- regex: 'Songbird(?:/([\d\.]+))?'
name: 'Songbird'
version: '$1'
- regex: 'SubStream(?:/([\d\.]+))?'
name: 'SubStream'
version: '$1'
- regex: 'VLC(?:/([\d\.]+))?'
name: 'VLC'
version: '$1'
- regex: 'Winamp(?:MPEG)?(?:/(\d+[\.\d]+))?'
name: 'Winamp'
version: '$1'
- regex: 'Windows-Media-Player(?:/(\d+[\.\d]+))?'
name: 'Windows Media Player'
version: '$1'
- regex: 'XBMC(?:/([\d\.]+))?'
name: 'XBMC'
version: '$1'
- regex: 'Kodi(?:/([\d\.]+))?'
name: 'Kodi'
version: '$1'
- regex: 'stagefright(?:/([\d\.]+))?'
name: 'Stagefright'
version: '$1'
- regex: 'Instacast(?:/([\d\.]+))? CFNetwork/([\d\.]+)'
name: 'Instacast'
version: '$1'

View file

@ -0,0 +1,51 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
# AndroidDownloadManager
- regex: 'AndroidDownloadManager(?:[ /]([\d\.]+))?'
name: 'AndroidDownloadManager'
version: '$1'
# Facebook
- regex: 'com.facebook.katana'
name: 'Facebook'
version: ''
# FeedR
- regex: 'FeedR(?:/([\d\.]+))?'
name: 'FeedR'
version: '$1'
# Google Play Kiosk
- regex: 'com.google.android.apps.magazines'
name: 'Google Play Newsstand'
version: ''
# Google Plus
- regex: 'com.google.GooglePlus'
name: 'Google Plus'
version: ''
# WeChat
- regex: 'MicroMessenger/([^ ]+)'
name: 'WeChat'
version: '$1'
# Sina Weibo
- regex: '.*__weibo__([0-9\.]+)__'
name: 'Sina Weibo'
version: '$1'
# YouTube
- regex: 'com.google.android.youtube(?:/([\d\.]+))?'
name: 'YouTube'
version: '$1'
# AFNetworking generic
- regex: '([^/]+)/(\d+(?:\.\d+)+) \((?:iPhone|iPad); iOS [0-9\.]+; Scale/[0-9\.]+\)'
name: '$1'
version: '$2'

View file

@ -0,0 +1,38 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
- regex: 'Outlook-Express(?:/(\d+[\.\d]+))?'
name: 'Outlook Express'
version: '$1'
- regex: 'Microsoft Outlook(?:[/ ](\d+[\.\d]+))?'
name: 'Microsoft Outlook'
version: '$1'
- regex: '(?:Thunderbird|Icedove|Shredder)(?:/(\d+[\.\d]+))?'
name: 'Thunderbird'
version: '$1'
- regex: 'Airmail(?: (\d+[\.\d]+))?'
name: 'Airmail'
version: '$1'
- regex: 'Lotus-Notes(?:/(\d+[\.\d]+))?'
name: 'Lotus Notes'
version: '$1'
- regex: 'Barca(?:Pro)?(?:[/ ](\d+[\.\d]+))?'
name: 'Barca'
version: '$1'
- regex: 'Postbox(?:[/ ](\d+[\.\d]+))?'
name: 'Postbox'
version: '$1'
- regex: 'The Bat!(?: Voyager)?(?:[/ ](\d+[\.\d]+))?'
name: 'The Bat!'
version: '$1'

View file

@ -0,0 +1,28 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
#Nikon
Nikon:
regex: 'Coolpix S800c'
device: 'camera'
model: 'Coolpix S800c'
# Samsung
Samsung:
regex: 'EK-G[CN][0-9]{3}'
device: 'camera'
models:
- regex: 'EK-GN120'
model: 'GALAXY NX'
- regex: 'EK-GC100'
model: 'GALAXY Camera'
- regex: 'EK-GC110'
model: 'GALAXY Camera WiFi only'
- regex: 'EK-GC200'
model: 'GALAXY Camera 2'
- regex: 'EK-GC([0-9]{3})'
model: 'GALAXY Camera $1'

View file

@ -0,0 +1,12 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
# Tesla Model S
Tesla:
regex: 'QtCarBrowser'
device: 'car browser'
model: 'Model S'

View file

@ -0,0 +1,40 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
Archos:
regex: 'Archos.*GAMEPAD([2]?)'
device: 'console'
model: 'Gamepad $1'
Microsoft:
regex: 'Xbox'
device: 'console'
models:
- regex: 'Xbox One'
model: 'Xbox One'
- regex: 'Xbox'
model: 'Xbox 360'
Nintendo:
regex: 'Nintendo (([3]?DS[i]?)|Wii[U]?)'
device: 'console'
model: '$1'
OUYA:
regex: 'OUYA'
device: 'console'
model: 'OUYA'
Sega:
regex: 'Dreamcast'
device: 'console'
model: 'Dreamcast'
Sony:
regex: 'PlayStation (3|4|Portable|Vita)'
device: 'console'
model: 'PlayStation $1'

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,61 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
Apple:
regex: '(?:Apple-)?iPod'
device: 'portable media player'
models:
- regex: '(?:Apple-)?iPod1[C,]1'
model: 'iPod Touch 1G'
- regex: '(?:Apple-)?iPod2[C,]1'
model: 'iPod Touch 2G'
- regex: '(?:Apple-)?iPod3[C,]1'
model: 'iPod Touch 3'
- regex: '(?:Apple-)?iPod4[C,]1'
model: 'iPod Touch 4'
- regex: '(?:Apple-)?iPod5[C,]1'
model: 'iPod Touch 5'
- regex: '(?:Apple-)?iPod1[C,]1'
model: 'iPod Touch'
- regex: '(?:Apple-)?iPod1[C,]1'
model: 'iPod Touch'
- regex: '(?:Apple-)?iPod'
model: 'iPod Touch'
Cowon:
regex: 'COWON ([^;/]+) Build'
device: 'portable media player'
model: '$1'
Microsoft:
regex: 'Microsoft ZuneHD'
device: 'portable media player'
model: 'Zune HD'
Panasonic:
device: 'portable media player'
regex: '(SV-MV100)'
model: '$1'
Samsung:
regex: 'YP-(G[SIPB]?1|G[57]0|GB70D)'
device: 'portable media player'
models:
- regex: 'YP-G[B]?1'
model: 'Galaxy Player 4.0'
- regex: 'YP-G70'
model: 'Galaxy Player 5.0'
- regex: 'YP-GS1'
model: 'Galaxy Player 3.6'
- regex: 'YP-GI1'
model: 'Galaxy Player 4.2'
- regex: 'YP-GP1'
model: 'Galaxy Player 5.8 '
- regex: 'YP-G50'
model: 'Galaxy Player 50'
- regex: 'YP-GB70D'
model: 'Galaxy Player 70 Plus'

View file

@ -1,21 +1,43 @@
###############
# Piwik - Open source web analytics
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
#
# @category UserAgentParserEnhanced
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
#
# ATTENTION: This file may only include tv user agents that contain 'HbbTV/([1-9]{1}(\.[0-9]{1}){1,2})'
#
###############
# Airties
Airties:
regex: 'Airties'
device: 'tv'
models:
- regex: 'Airties; ?([^);/]+)'
model: '$1'
# Altech UEC
'Altech UEC':
regex: 'Altech UEC'
device: 'tv'
models:
- regex: 'Altech UEC; ?([^);/]+)'
model: '$1'
# BangOlufsen
BangOlufsen:
regex: 'Bangolufsen'
device: 'tv'
model: 'BeoVision'
# Changhong
Changhong:
regex: 'Changhong'
device: 'tv'
models:
- regex: 'Changhong; ?([^);/]+)'
model: '$1'
# CreNova
CreNova:
regex: 'CreNova'
@ -26,7 +48,7 @@ CreNova:
DMM:
regex: 'DMM'
device: 'tv'
models: 'Dreambox'
model: 'Dreambox'
# Grundig
Grundig:
@ -43,6 +65,8 @@ Humax:
model: '$1'
- regex: 'HMS1000S'
model: 'HMS-1000S'
- regex: 'Humax; ([^);/]+)'
model: '$1'
# IKEA
Ikea:
@ -65,6 +89,8 @@ Inverto:
regex: 'Inverto'
device: 'tv'
models:
- regex: 'inverto; ([^);/]+)'
model: '$1'
- regex: '(Volksbox Web Edition|Volksbox Essential|Volksbox II|Volksbox)'
model: '$1'
@ -126,27 +152,31 @@ PEAQ:
# Philips
Philips:
regex: 'Philips'
regex: 'Philips|NETTV/'
device: 'tv'
models:
- regex: '(NETTV/[0-9\.]{5})'
- regex: 'Philips[,;] ?((?! )[^),;/]+)'
model: '$1'
- regex: 'NETTV/[0-9\.]{5}'
model: 'NetTV Series'
# Samsung
Samsung:
regex: 'Samsung|Maple_2011'
device: 'tv'
models:
- regex: '(SmartTV2013|SmartTV2012)'
model: '$1'
- regex: 'SmartTV(2012|2013|2014|2015)'
model: 'Smart TV $1'
- regex: 'Maple_2011'
model: 'SmartTV2011'
model: 'Smart TV 2011'
# Selevision
Selevision:
regex: 'Selevision'
device: 'tv'
models:
- regex: 'Selevision; (?:Selevision )?([^);/]+)'
model: '$1'
- regex: '(EMC1000i)'
model: '$1'
@ -155,14 +185,26 @@ Sharp:
regex: 'Sharp'
device: 'tv'
models:
- regex: 'Sharp[,;] ?((?! |HbbTV)[^),;/]+)'
model: '$1'
- regex: '(LE[0-9]{3}[A-Z]{0,3})'
model: '$1'
# Skyworth
Skyworth:
regex: 'Sky_worth'
device: 'tv'
models:
- regex: 'Sky_worth;([^);/]+)'
model: '$1'
# Smart
Smart:
regex: 'Smart'
regex: 'Smart[^a-z]'
device: 'tv'
models:
- regex: 'Smart; ([^);/]+)'
model: '$1'
- regex: '([A-Z]{2}[0-9]{2}|ZAPPIX)'
model: '$1'
@ -231,12 +273,10 @@ Vestel:
# Videoweb
Videoweb:
regex: 'videoweb|compatible;'
regex: 'videoweb|tv2n'
device: 'tv'
models:
- regex: '(videowebtv)'
model: 'VideoWeb TV'
- regex: '(tv2n)'
model: '$1'
- regex: 'ANTGalio/3.0'
model: '600S'
- regex: '(videowebtv)'
model: 'VideoWeb TV'

File diff suppressed because it is too large Load diff

View file

@ -1,36 +1,16 @@
###############
# Piwik - Open source web analytics
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
#
# @category UserAgentParserEnhanced
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
##########
# Bot
##########
- regex: '(nuhk|Sosospider|CareerBot|bingbot|SputnikBot|TsolCrawler|SensikaBot|UptimeRobot|SeznamBot|AhrefsBot|Ezooms|Googlebot|Exabot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves/Teoma|ia_archiver|ScoutJet|Gulper Web Bot|EmailWolf|grub-client|Download Demon|SearchExpress|Microsoft URL Control|bot|borg|yahoo|slurp|msnbot|msrbot|openbot|archiver|netresearch|transcoder|crawler|lycos|scooter|altavista|teoma|gigabot|baiduspider|blitzbot|oegp|charlotte|furlbot|http%20client|polybot|htdig|ichiro|mogimogi|larbin|pompos|scrubby|searchsight|seekbot|semanticdiscovery|snappy|speedy|spider|voila|vortex|zao|zeal|fast-webcrawler|converacrawler|dataparksearch|findlinksYottaaMonitor|BrowserMob|HttpMonitor|YandexBot|Slurp|BingPreview|PagePeeker|ThumbShotsBot|WebThumb|URL2PNG|ZooShot|GomezA|Catchpoint bot|Willow Internet Crawler|Google SketchUp|Read%20Later|Minimo|Pingdom.com|facebookexternalhit|Twitterbot|RackspaceBot)'
name: 'Bot'
version: ''
##########
# Simulators
##########
- regex: '(Talkatone|WinWAP)'
name: '$1'
version: ''
##########
# Tizen
##########
- regex: 'Tizen'
- regex: 'Tizen[ /]?(\d+[\.\d]+)?'
name: 'Tizen'
version: ''
version: '$1'
@ -41,54 +21,17 @@
name: 'Sailfish OS'
version: ''
##########
# Android
# YunOS (Android based)
##########
- regex: '(?:Android|Adr)[ /](?:[a-z]+ )?(\d+\.\d+)'
name: 'Android'
- regex: '(?:Ali)?YunOS[ /]?(\d+[\.\d]+)?'
name: 'YunOS'
version: '$1'
- regex: 'Android|Silk-Accelerated=[a-z]{4,5}'
name: 'Android'
version: ''
##########
# AmigaOS
##########
- regex: 'AmigaOS[ ]?(\d+\.\d+)'
name: 'AmigaOS'
version: '$1'
- regex: 'AmigaOS|AmigaVoyager|Amiga-AWeb'
name: 'AmigaOS'
version: ''
##########
# Linux
##########
- regex: 'Arch ?Linux(?:[ /\-](\d+\.\d+))?'
name: 'Arch Linux'
version: '$1'
- regex: 'Linux; .*((?:Debian|Knoppix|Mint|Ubuntu|Kubuntu|Xubuntu|Lubuntu|Fedora|Red Hat|Mandriva|Gentoo|Sabayon|Slackware|SUSE|Puppy|CentOS|BackTrack|YunOs|Presto))[ /](\d+\.\d+)'
name: '$1'
version: '$2'
- regex: '(Debian|Knoppix|Mint|Ubuntu|Kubuntu|Xubuntu|Lubuntu|Fedora|Red Hat|Mandriva|Gentoo|Sabayon|Slackware|SUSE|Puppy|CentOS|BackTrack|YunOs)(?: Linux)?(?:[ /\-](\d+\.\d+))?'
name: '$1'
version: '$2'
# generic linux match -> end of file
##########
# Windows Mobile
##########
- regex: 'Windows Phone (?:OS)?[ ]?(\d+\.\d+)'
- regex: 'Windows Phone (?:OS)?[ ]?(\d+[\.\d]+)'
name: 'Windows Phone'
version: '$1'
@ -102,7 +45,7 @@
version: ''
- regex: '(?:IEMobile|Windows Mobile)(?: (\d+\.\d+))?'
- regex: '(?:IEMobile|Windows Mobile)(?: (\d+[\.\d]+))?'
name: 'Windows Mobile'
version: '$1'
@ -111,80 +54,185 @@
name: 'Windows RT'
version: ''
- regex: 'Windows NT 6.3; ARM;'
name: 'Windows RT'
version: '8.1'
##########
# Custom Android Roms
##########
- regex: 'RazoDroiD(?: v(\d+[\.\d]*))?'
name: 'RazoDroiD'
version: '$1'
- regex: 'MildWild(?: CM-(\d+[\.\d]*))?'
name: 'MildWild'
version: '$1'
- regex: 'CyanogenMod(?:[\-/](?:CM)?(\d+[\.\d]*))?'
name: 'CyanogenMod'
version: '$1'
- regex: '(?:.*_)?MocorDroid(?:(\d+[\.\d]*))?'
name: 'MocorDroid'
version: '$1'
##########
# Android
##########
- regex: '(?:Android|Adr)[ /](?:[a-z]+ )?(\d+[\.\d]+)'
name: 'Android'
version: '$1'
- regex: 'Android|Silk-Accelerated=[a-z]{4,5}'
name: 'Android'
version: ''
##########
# AmigaOS
##########
- regex: 'AmigaOS[ ]?(\d+[\.\d]+)'
name: 'AmigaOS'
version: '$1'
- regex: 'AmigaOS|AmigaVoyager|Amiga-AWeb'
name: 'AmigaOS'
version: ''
##########
# ThreadX
##########
- regex: 'ThreadX(?:/(\d+[\.\d]*))?'
name: 'ThreadX'
version: '$1'
##########
# MTK / Nucleus
##########
- regex: 'Nucleus(?:(?: |/v?)(\d+[\.\d]*))?'
name: 'MTK / Nucleus'
version: '$1'
- regex: 'MTK(?:(?: |/v?)(\d+[\.\d]*))?'
name: 'MTK / Nucleus'
version: '$1'
##########
# Linux
##########
- regex: 'Maemo'
name: 'Maemo'
version: '$1'
- regex: 'Arch ?Linux(?:[ /\-](\d+[\.\d]+))?'
name: 'Arch Linux'
version: '$1'
- regex: 'VectorLinux(?: package)?(?:[ /\-](\d+[\.\d]+))?'
name: 'VectorLinux'
version: '$1'
- regex: 'Linux; .*((?:Debian|Knoppix|Mint|Ubuntu|Kubuntu|Xubuntu|Lubuntu|Fedora|Red Hat|Mandriva|Gentoo|Sabayon|Slackware|SUSE|CentOS|BackTrack))[ /](\d+[\.\d]+)'
name: '$1'
version: '$2'
- regex: '(Debian|Knoppix|Mint|Ubuntu|Kubuntu|Xubuntu|Lubuntu|Fedora|Red Hat|Mandriva|Gentoo|Sabayon|Slackware|SUSE|CentOS|BackTrack)(?:(?: Enterprise)? Linux)?(?:[ /\-](\d+[\.\d]+))?'
name: '$1'
version: '$2'
# generic linux match -> end of file
##########
# webOS
##########
- regex: '(?:webOS|Palm webOS)(?:/(\d+\.\d+))?'
- regex: '(?:webOS|Palm webOS)(?:/(\d+[\.\d]+))?'
name: 'webOS'
version: '$1'
- regex: '(?:PalmOS|Palm OS)(?:[/ ](\d+\.\d+))?|Palm'
- regex: '(?:PalmOS|Palm OS)(?:[/ ](\d+[\.\d]+))?|Palm'
name: 'palmOS'
version: '$1'
- regex: 'Xiino(?:.*v\. (\d+\.\d+))?' # palmOS only browser
- regex: 'Xiino(?:.*v\. (\d+[\.\d]+))?' # palmOS only browser
name: 'palmOS'
version: '$1'
- regex: 'MorphOS(?:[ /](\d+[\.\d]+))?'
name: 'MorphOS'
version: '$1'
##########
# Windows
##########
- regex: 'CYGWIN_NT-6.2|Windows NT 6.2|Windows NT 6.3|Windows 8'
name: 'Windows 8'
- regex: 'CYGWIN_NT-10.0|Windows NT 10.0|Windows 10'
name: 'Windows'
version: '10'
- regex: 'CYGWIN_NT-6.4|Windows NT 6.4|Windows 10'
name: 'Windows'
version: '10'
- regex: 'CYGWIN_NT-6.3|Windows NT 6.3|Windows 8.1'
name: 'Windows'
version: '8.1'
- regex: 'CYGWIN_NT-6.2|Windows NT 6.2|Windows 8'
name: 'Windows'
version: '8'
- regex: 'CYGWIN_NT-6.1|Windows NT 6.1|Windows 7'
name: 'Windows 7'
name: 'Windows'
version: '7'
- regex: 'CYGWIN_NT-6.0|Windows NT 6.0|Windows Vista'
name: 'Windows Vista'
name: 'Windows'
version: 'Vista'
- regex: 'CYGWIN_NT-5.2|Windows NT 5.2|Windows Server 2003 / XP x64'
name: 'Windows Server 2003'
name: 'Windows'
version: 'Server 2003'
- regex: 'CYGWIN_NT-5.1|Windows NT 5.1|Windows XP'
name: 'Windows XP'
name: 'Windows'
version: 'XP'
- regex: 'CYGWIN_NT-5.0|Windows NT 5.0|Windows 2000'
name: 'Windows 2000'
name: 'Windows'
version: '2000'
- regex: 'CYGWIN_NT-4.0|Windows NT 4.0|WinNT|Windows NT'
name: 'Windows NT'
name: 'Windows'
version: 'NT'
- regex: 'CYGWIN_ME-4.90|Win 9x 4.90|Windows ME'
name: 'Windows ME'
name: 'Windows'
version: 'ME'
- regex: 'CYGWIN_98-4.10|Win98|Windows 98'
name: 'Windows 98'
name: 'Windows'
version: '98'
- regex: 'CYGWIN_95-4.0|Win32|Win95|Windows 95|Windows_95'
name: 'Windows 95'
name: 'Windows'
version: '95'
- regex: 'Windows 3.1'
name: 'Windows 3.1'
name: 'Windows'
version: '3.1'
@ -194,36 +242,158 @@
##########
# iOS
##########
- regex: 'CFNetwork/758\.1\.6'
name: 'iOS'
version: '9.1'
- regex: 'CFNetwork/758\.0\.2'
name: 'iOS'
version: '9.0'
- regex: 'CFNetwork/711\.5\.6'
name: 'iOS'
version: '8.4.1'
- regex: 'CFNetwork/711\.4\.6'
name: 'iOS'
version: '8.4'
- regex: 'CFNetwork/711\.3\.18'
name: 'iOS'
version: '8.3'
- regex: 'CFNetwork/711\.2\.23'
name: 'iOS'
version: '8.2'
- regex: 'CFNetwork/711\.1\.1[26]'
name: 'iOS'
version: '8.1'
- regex: 'CFNetwork/711\.0\.6'
name: 'iOS'
version: '8.0'
- regex: 'CFNetwork/672\.1'
name: 'iOS'
version: '7.1'
- regex: 'CFNetwork/672\.0'
name: 'iOS'
version: '7.0'
- regex: 'CFNetwork/609\.1'
name: 'iOS'
version: '6.1'
- regex: 'CFNetwork/60[29]'
name: 'iOS'
version: '6.0'
- regex: 'CFNetwork/548\.1'
name: 'iOS'
version: '5.1'
- regex: 'CFNetwork/548\.0'
name: 'iOS'
version: '5.0'
- regex: 'CFNetwork/485\.13'
name: 'iOS'
version: '4.3'
- regex: 'CFNetwork/485\.12'
name: 'iOS'
version: '4.2'
- regex: 'CFNetwork/485\.10'
name: 'iOS'
version: '4.1'
- regex: 'CFNetwork/485\.2'
name: 'iOS'
version: '4.0'
- regex: 'CFNetwork/459'
name: 'iOS'
version: '3.1'
- regex: '(?:CPU OS|iPh(?:one)? OS|iOS)[ _](\d+(?:[_\.]\d+)*)'
name: 'iOS'
version: '$1'
- regex: '(?:Apple-)?(?:iPhone|iPad|iPod)(?:.*Mac OS X.*Version/(\d+\.\d+)|; Opera)?'
name: 'iOS'
version: '$1'
##########
# Mac
##########
- regex: 'Mac OS X (\d+[_.]\d+)'
- regex: 'CFNetwork/760'
name: 'Mac'
version: '10.11'
- regex: 'CFNetwork/720'
name: 'Mac'
version: '10.10'
- regex: 'CFNetwork/673'
name: 'Mac'
version: '10.9'
- regex: 'CFNetwork/596'
name: 'Mac'
version: '10.8'
- regex: 'CFNetwork/520'
name: 'Mac'
version: '10.7'
- regex: 'CFNetwork/454'
name: 'Mac'
version: '10.6'
- regex: 'CFNetwork/(?:438|422|339|330|221|220|217)'
name: 'Mac'
version: '10.5'
- regex: 'CFNetwork/12[89]'
name: 'Mac'
version: '10.4'
- regex: 'CFNetwork/1\.2'
name: 'Mac'
version: '10.3'
- regex: 'CFNetwork/1\.1'
name: 'Mac'
version: '10.2'
- regex: 'Mac OS X(?: (?:Version )?(\d+(?:[_\.]\d+)+))?'
name: 'Mac'
version: '$1'
- regex: 'Mac (\d+(?:[_\.]\d+)+)'
name: 'Mac'
version: '$1'
- regex: 'Darwin|Macintosh|Mac_PowerPC|PPC|Mac PowerPC'
name: 'Mac'
version: ''
##########
# iOS
##########
- regex: '(?:CPU OS|iPhone OS)[ _](\d+(?:_\d+)?)'
name: 'iOS'
version: '$1'
- regex: '(?:iPhone|iPad|iPod)(?:.*Mac OS X.*Version/(\d+\.\d+)|; Opera)'
name: 'iOS'
version: '$1'
##########
# ChromeOS
##########
- regex: 'CrOS [a-z0-9_]+ (\d+\.\d+)'
- regex: 'CrOS [a-z0-9_]+ (\d+[\.\d]+)'
name: 'Chrome OS'
version: '$1'
@ -232,12 +402,12 @@
##########
# BlackBerry
##########
- regex: '(?:BB10;.+Version|Black[Bb]erry[0-9a-z]+|Black[Bb]erry.+Version)/(\d+\.\d+)'
- regex: '(?:BB10;.+Version|Black[Bb]erry[0-9a-z]+|Black[Bb]erry.+Version)/(\d+[\.\d]+)'
name: 'BlackBerry OS'
version: '$1'
- regex: 'RIM Tablet OS (\d+\.\d+)'
- regex: 'RIM Tablet OS (\d+[\.\d]+)'
name: 'BlackBerry Tablet OS'
version: '$1'
@ -273,7 +443,22 @@
##########
# Symbian
##########
- regex: '(?:Series ?60|SymbOS|S60)(?:[ /]?(\d+\.\d+|V\d+))?'
- regex: 'Symbian/3.+NokiaBrowser/7\.3'
name: 'Symbian^3'
version: 'Anna'
- regex: 'Symbian/3.+NokiaBrowser/7\.4'
name: 'Symbian^3'
version: 'Belle'
- regex: 'Symbian/3'
name: 'Symbian^3'
version: ''
- regex: '(?:Series ?60|SymbOS|S60)(?:[ /]?(\d+[\.\d]+|V\d+))?'
name: 'Symbian OS Series 60'
version: '$1'
@ -283,26 +468,11 @@
version: ''
- regex: 'SymbianOS/(\d+\.\d+)'
- regex: 'SymbianOS/(\d+[\.\d]+)'
name: 'Symbian OS'
version: '$1'
- regex: 'Symbian/3.+NokiaBrowser/7\.3'
name: 'Symbian'
version: '^3 Anna'
- regex: 'Symbian/3.+NokiaBrowser/7\.4'
name: 'Symbian'
version: '^3 Belle'
- regex: 'Symbian[/]?3'
name: 'Symbian^3'
version: '^3'
- regex: 'MeeGo|WeTab'
name: 'MeeGo'
version: ''
@ -330,7 +500,7 @@
##########
# RISC OS
##########
- regex: 'RISC OS(?:-NC)?(?:[ /](\d+\.\d+))?'
- regex: 'RISC OS(?:-NC)?(?:[ /](\d+[\.\d]+))?'
name: 'RISC OS'
version: '$1'
@ -338,7 +508,7 @@
##########
# Inferno
##########
- regex: 'Inferno(?:[ /](\d+\.\d+))?'
- regex: 'Inferno(?:[ /](\d+[\.\d]+))?'
name: 'Inferno'
version: '$1'
@ -346,7 +516,7 @@
##########
# Bada
##########
- regex: 'bada(?:[ /](\d+\.\d+))'
- regex: 'bada(?:[ /](\d+[\.\d]+))'
name: 'Bada'
version: '$1'
@ -359,7 +529,7 @@
##########
# Brew
##########
- regex: '(?:Brew MP|BREW|BMP)(?:[ /](\d+\.\d+))'
- regex: '(?:Brew MP|BREW|BMP)(?:[ /](\d+[\.\d]+))'
name: 'Brew'
version: '$1'
@ -372,17 +542,17 @@
##########
# Web TV
##########
- regex: 'GoogleTV[ /](\d+\.\d+)|GoogleTV'
- regex: 'GoogleTV(?:[ /](\d+[\.\d]+))?'
name: 'Google TV'
version: '$1'
- regex: 'AppleTV(?:/?(\d+\.\d+))?'
- regex: 'AppleTV(?:/?(\d+[\.\d]+))?'
name: 'Apple TV'
version: '$1'
- regex: 'WebTV/(\d+\.\d+)'
- regex: 'WebTV/(\d+[\.\d]+)'
name: 'WebTV'
version: '$1'
@ -391,52 +561,52 @@
##########
# Unix
##########
- regex: '(?:SunOS|Solaris)(?:[/ ](\d+\.\d+))?'
- regex: '(?:SunOS|Solaris)(?:[/ ](\d+[\.\d]+))?'
name: 'Solaris'
version: '$1'
- regex: 'AIX(?:[/ ]?(\d+\.\d+))?'
- regex: 'AIX(?:[/ ]?(\d+[\.\d]+))?'
name: 'AIX'
version: '$1'
- regex: 'HP-UX(?:[/ ]?(\d+\.\d+))?'
- regex: 'HP-UX(?:[/ ]?(\d+[\.\d]+))?'
name: 'HP-UX'
version: '$1'
- regex: 'FreeBSD(?:[/ ]?(\d+\.\d+))?'
- regex: 'FreeBSD(?:[/ ]?(\d+[\.\d]+))?'
name: 'FreeBSD'
version: '$1'
- regex: 'NetBSD(?:[/ ]?(\d+\.\d+))?'
- regex: 'NetBSD(?:[/ ]?(\d+[\.\d]+))?'
name: 'NetBSD'
version: '$1'
- regex: 'OpenBSD(?:[/ ]?(\d+\.\d+))?'
- regex: 'OpenBSD(?:[/ ]?(\d+[\.\d]+))?'
name: 'OpenBSD'
version: '$1'
- regex: 'DragonFly(?:[/ ]?(\d+\.\d+))?'
- regex: 'DragonFly(?:[/ ]?(\d+[\.\d]+))?'
name: 'DragonFly'
version: '$1'
- regex: 'Syllable(?:[/ ]?(\d+\.\d+))?'
- regex: 'Syllable(?:[/ ]?(\d+[\.\d]+))?'
name: 'Syllable'
version: '$1'
- regex: 'IRIX(?:[/ ]?(\d+\.\d+))'
- regex: 'IRIX(?:;64)?(?:[/ ]?(\d+[\.\d]+))'
name: 'IRIX'
version: '$1'
- regex: 'OSF1(?:[/ ]?v?(\d+\.\d+))?'
- regex: 'OSF1(?:[/ ]?v?(\d+[\.\d]+))?'
name: 'OSF1'
version: '$1'
@ -488,7 +658,7 @@
# Linux (Generic)
###########
- regex: 'Linux[^a-z]'
name: 'Linux'
name: 'GNU/Linux'
version: ''

View file

@ -0,0 +1,71 @@
###############
# Device Detector - The Universal Device Detection library for parsing User Agents
#
# @link http://piwik.org
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############
Dell:
- 'MDDR(JS)?'
- 'MDDC(JS)?'
- 'MDDS(JS)?'
Acer:
- 'MAAR(JS)?'
Sony:
- 'MASE(JS)?'
- 'MASP(JS)?'
- 'MASA(JS)?'
Asus:
- 'MAAU'
- 'NP0[6789]'
- 'ASJB'
- 'ASU2(JS)?'
Samsung:
- 'MASM(JS)?'
- 'SMJB'
Lenovo:
- 'MALC(JS)?'
- 'MALE(JS)?'
- 'MALN(JS)?'
- 'LCJB'
- 'LEN2'
Toshiba:
- 'MATM(JS)?'
- 'MATB(JS)?'
- 'MATP(JS)?'
- 'TNJB'
- 'TAJB'
Medion:
- 'MAMD'
MSI:
- 'MAMI(JS)?'
- 'MAM3'
Gateway:
- 'MAGW(JS)?'
Fujitsu:
- 'MAFS(JS)?'
- 'FSJB'
Compaq:
- 'CPDTDF'
- 'CPNTDF(JS?)'
- 'CMNTDF(JS)?'
- 'CMDTDF(JS)?'
HP:
- 'HPCMHP'
- 'HPNTDF(JS)?'
- 'HPDTDF(JS)?'
Hyrican:
- 'MANM(JS)?'

View file

@ -0,0 +1,74 @@
# Piwik/Ini
Read and write INI configurations.
[![Build Status](https://img.shields.io/travis/piwik/component-ini.svg?style=flat-square)](https://travis-ci.org/piwik/component-ini)
[![Coverage Status](https://img.shields.io/coveralls/piwik/component-ini/master.svg?style=flat-square)](https://coveralls.io/r/piwik/component-ini?branch=master)
[![Latest Version](https://img.shields.io/github/release/piwik/component-ini.svg?style=flat-square)](https://packagist.org/packages/piwik/component-ini)
[![](https://img.shields.io/packagist/dm/piwik/ini.svg?style=flat-square)](https://packagist.org/packages/piwik/ini)
## Installation
```json
composer require piwik/ini
```
## Why?
PHP provides a `parse_ini_file()` function to read INI files.
This component provides the following benefits over the built-in function:
- allows to write INI files
- classes can be used with dependency injection and mocked in unit tests
- throws exceptions instead of PHP errors
- better type supports:
- parses boolean values (`true`/`false`, `on`/`off`, `yes`/`no`) to real PHP booleans ([instead of strings `"1"` and `""`](http://3v4l.org/JuvOT))
- parses null to PHP `null` ([instead of an empty string](http://3v4l.org/KSoj2))
- works even if `parse_ini_file()` or `parse_ini_string()` is disabled in `php.ini` by falling back on an alternate implementation (can happen on some shared hosts)
- fixes [a PHP 5.3.3 bug](http://3v4l.org/jD1Lh)
- fixes [a parsing bug](http://3v4l.org/m24cT) present in PHP <= 5.4.4
## Usage
### Read
```php
$reader = new IniReader();
// Read a string
$array = $reader->readString($string);
// Read a file
$array = $reader->readFile('config.ini');
```
### Write
```php
$writer = new IniWriter();
// Write to a string
$string = $writer->writeToString($array);
// Write to a file
$writer->writeToFile('config.ini', $array);
```
## License
The Ini component is released under the [LGPL v3.0](http://choosealicense.com/licenses/lgpl-3.0/).
## Contributing
To run the unit tests:
```
vendor/bin/phpunit
```
To run the performance tests:
```
php -n vendor/bin/athletic -p tests/PerformanceTest
```

View file

@ -0,0 +1,22 @@
{
"name": "piwik/ini",
"type": "library",
"license": "LGPL-3.0",
"autoload": {
"psr-4": {
"Piwik\\Ini\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Piwik\\Tests\\Ini\\": "tests/"
}
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"athletic/athletic": "0.1.*"
}
}

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="Test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -0,0 +1,390 @@
<?php
/**
* 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\Ini;
/**
* Reads INI configuration.
*/
class IniReader
{
/**
* @var bool
*/
private $useNativeFunction;
public function __construct()
{
$this->useNativeFunction = function_exists('parse_ini_string');
}
/**
* Reads a INI configuration file and returns it as an array.
*
* The array returned is multidimensional, indexed by section names:
*
* ```
* array(
* 'Section 1' => array(
* 'value1' => 'hello',
* 'value2' => 'world',
* ),
* 'Section 2' => array(
* 'value3' => 'foo',
* )
* );
* ```
*
* @param string $filename The file to read.
* @throws IniReadingException
* @return array
*/
public function readFile($filename)
{
$ini = $this->getContentOfIniFile($filename);
return $this->readString($ini);
}
/**
* Reads a INI configuration string and returns it as an array.
*
* The array returned is multidimensional, indexed by section names:
*
* ```
* array(
* 'Section 1' => array(
* 'value1' => 'hello',
* 'value2' => 'world',
* ),
* 'Section 2' => array(
* 'value3' => 'foo',
* )
* );
* ```
*
* @param string $ini String containing INI configuration.
* @throws IniReadingException
* @return array
*/
public function readString($ini)
{
// On PHP 5.3.3 an empty line return is needed at the end
// See http://3v4l.org/jD1Lh
$ini .= "\n";
if ($this->useNativeFunction) {
$array = $this->readWithNativeFunction($ini);
} else {
$array = $this->readWithAlternativeImplementation($ini);
}
return $array;
}
/**
* @param string $ini
* @throws IniReadingException
* @return array
*/
private function readWithNativeFunction($ini)
{
$array = @parse_ini_string($ini, true);
if ($array === false) {
$e = error_get_last();
throw new IniReadingException('Syntax error in INI configuration: ' . $e['message']);
}
// We cannot use INI_SCANNER_RAW by default because it is buggy under PHP 5.3.14 and 5.4.4
// http://3v4l.org/m24cT
$rawValues = @parse_ini_string($ini, true, INI_SCANNER_RAW);
$array = $this->decode($array, $rawValues);
return $array;
}
private function getContentOfIniFile($filename)
{
if (!file_exists($filename) || !is_readable($filename)) {
throw new IniReadingException(sprintf("The file %s doesn't exist or is not readable", $filename));
}
$content = $this->getFileContent($filename);
if ($content === false) {
throw new IniReadingException(sprintf('Impossible to read the file %s', $filename));
}
return $content;
}
/**
* Reads ini comments for each key.
*
* The array returned is multidimensional, indexed by section names:
*
* ```
* array(
* 'Section 1' => array(
* 'key1' => 'comment 1',
* 'key2' => 'comment 2',
* ),
* 'Section 2' => array(
* 'key3' => 'comment 3',
* )
* );
* ```
*
* @param string $filename The path to a file.
* @throws IniReadingException
* @return array
*/
public function readComments($filename)
{
$ini = $this->getContentOfIniFile($filename);
$ini = $this->splitIniContentIntoLines($ini);
$descriptions = array();
$section = '';
$lastComment = '';
foreach ($ini as $line) {
$line = trim($line);
if (strpos($line, '[') === 0) {
$tmp = explode(']', $line);
$section = trim(substr($tmp[0], 1));
$descriptions[$section] = array();
$lastComment = '';
continue;
}
if (!preg_match('/^[a-zA-Z0-9[]/', $line)) {
if (strpos($line, ';') === 0) {
$line = trim(substr($line, 1));
}
// comment
$lastComment .= $line . "\n";
continue;
}
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
if (strpos($key, '[]') === strlen($key) - 2) {
$key = substr($key, 0, -2);
}
if (empty($descriptions[$section][$key])) {
$descriptions[$section][$key] = $lastComment;
}
$lastComment = '';
}
return $descriptions;
}
private function splitIniContentIntoLines($ini)
{
if (is_string($ini)) {
$ini = explode("\n", str_replace("\r", "\n", $ini));
}
return $ini;
}
/**
* Reimplementation in case `parse_ini_file()` is disabled.
*
* @author Andrew Sohn <asohn (at) aircanopy (dot) net>
* @author anthon (dot) pang (at) gmail (dot) com
*
* @param string $ini
* @return array
*/
private function readWithAlternativeImplementation($ini)
{
$ini = $this->splitIniContentIntoLines($ini);
if (count($ini) == 0) {
return array();
}
$sections = array();
$values = array();
$result = array();
$globals = array();
$i = 0;
foreach ($ini as $line) {
$line = trim($line);
$line = str_replace("\t", " ", $line);
// Comments
if (!preg_match('/^[a-zA-Z0-9[]/', $line)) {
continue;
}
// Sections
if ($line{0} == '[') {
$tmp = explode(']', $line);
$sections[] = trim(substr($tmp[0], 1));
$i++;
continue;
}
// Key-value pair
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
if (strstr($value, ";")) {
$tmp = explode(';', $value);
if (count($tmp) == 2) {
if ((($value{0} != '"') && ($value{0} != "'")) ||
preg_match('/^".*"\s*;/', $value) || preg_match('/^".*;[^"]*$/', $value) ||
preg_match("/^'.*'\s*;/", $value) || preg_match("/^'.*;[^']*$/", $value)
) {
$value = $tmp[0];
}
} else {
if ($value{0} == '"') {
$value = preg_replace('/^"(.*)".*/', '$1', $value);
} elseif ($value{0} == "'") {
$value = preg_replace("/^'(.*)'.*/", '$1', $value);
} else {
$value = $tmp[0];
}
}
}
$value = trim($value);
// Special keywords
if ($value === 'true' || $value === 'yes' || $value === 'on') {
$value = true;
} elseif ($value === 'false' || $value === 'no' || $value === 'off') {
$value = false;
} elseif ($value === '' || $value === 'null') {
$value = null;
}
if (is_string($value)) {
$value = trim($value, "'\"");
}
if ($i == 0) {
if (substr($key, -2) == '[]') {
$globals[substr($key, 0, -2)][] = $value;
} else {
$globals[$key] = $value;
}
} else {
if (substr($key, -2) == '[]') {
$values[$i - 1][substr($key, 0, -2)][] = $value;
} else {
$values[$i - 1][$key] = $value;
}
}
}
for ($j = 0; $j < $i; $j++) {
if (isset($values[$j])) {
$result[$sections[$j]] = $values[$j];
} else {
$result[$sections[$j]] = array();
}
}
$finalResult = $result + $globals;
return $this->decode($finalResult, $finalResult);
}
/**
* @param string $filename
* @return bool|string Returns false if failure.
*/
private function getFileContent($filename)
{
if (function_exists('file_get_contents')) {
return file_get_contents($filename);
} elseif (function_exists('file')) {
$ini = file($filename);
if ($ini !== false) {
return implode("\n", $ini);
}
} elseif (function_exists('fopen') && function_exists('fread')) {
$handle = fopen($filename, 'r');
if (!$handle) {
return false;
}
$ini = fread($handle, filesize($filename));
fclose($handle);
return $ini;
}
return false;
}
/**
* We have to decode values manually because parse_ini_file() has a poor implementation.
*
* @param mixed $value The array decoded by `parse_ini_file`
* @param mixed $rawValue The same array but with raw strings, so that we can re-decode manually
* and override the poor job of `parse_ini_file`
* @return mixed
*/
private function decode($value, $rawValue)
{
if (is_array($value)) {
foreach ($value as $i => &$subValue) {
$subValue = $this->decode($subValue, $rawValue[$i]);
}
return $value;
}
if (! is_string($value)) {
return $value;
}
$value = $this->decodeBoolean($value, $rawValue);
$value = $this->decodeNull($value, $rawValue);
if (is_numeric($value) && $this->noLossWhenCastToInt($value)) {
return $value + 0;
}
return $value;
}
private function decodeBoolean($value, $rawValue)
{
if ($value === '1' && ($rawValue === 'true' || $rawValue === 'yes' || $rawValue === 'on')) {
return true;
}
if ($value === '' && ($rawValue === 'false' || $rawValue === 'no' || $rawValue === 'off')) {
return false;
}
return $value;
}
private function decodeNull($value, $rawValue)
{
if ($value === '' && $rawValue === 'null') {
return null;
}
return $value;
}
private function noLossWhenCastToInt($value)
{
return (string) ($value + 0) === $value;
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* 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\Ini;
/**
* Exception when reading a INI configuration.
*/
class IniReadingException extends \Exception
{
}

View file

@ -0,0 +1,120 @@
<?php
/**
* 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\Ini;
/**
* Writes INI configuration.
*/
class IniWriter
{
/**
* Writes an array configuration to a INI file.
*
* The array provided must be multidimensional, indexed by section names:
*
* ```
* array(
* 'Section 1' => array(
* 'value1' => 'hello',
* 'value2' => 'world',
* ),
* 'Section 2' => array(
* 'value3' => 'foo',
* )
* );
* ```
*
* @param string $filename
* @param array $config
* @param string $header Optional header to insert at the top of the file.
* @throws IniWritingException
*/
public function writeToFile($filename, array $config, $header = '')
{
$ini = $this->writeToString($config, $header);
if (!file_put_contents($filename, $ini)) {
throw new IniWritingException(sprintf('Impossible to write to file %s', $filename));
}
}
/**
* Writes an array configuration to a INI string and returns it.
*
* The array provided must be multidimensional, indexed by section names:
*
* ```
* array(
* 'Section 1' => array(
* 'value1' => 'hello',
* 'value2' => 'world',
* ),
* 'Section 2' => array(
* 'value3' => 'foo',
* )
* );
* ```
*
* @param array $config
* @param string $header Optional header to insert at the top of the file.
* @return string
* @throws IniWritingException
*/
public function writeToString(array $config, $header = '')
{
$ini = $header;
$sectionNames = array_keys($config);
foreach ($sectionNames as $sectionName) {
$section = $config[$sectionName];
// no point in writing empty sections
if (empty($section)) {
continue;
}
if (! is_array($section)) {
throw new IniWritingException(sprintf("Section \"%s\" doesn't contain an array of values", $sectionName));
}
$ini .= "[$sectionName]\n";
foreach ($section as $option => $value) {
if (is_numeric($option)) {
$option = $sectionName;
$value = array($value);
}
if (is_array($value)) {
foreach ($value as $currentValue) {
$ini .= $option . '[] = ' . $this->encodeValue($currentValue) . "\n";
}
} else {
$ini .= $option . ' = ' . $this->encodeValue($value) . "\n";
}
}
$ini .= "\n";
}
return $ini;
}
private function encodeValue($value)
{
if (is_bool($value)) {
return (int) $value;
}
if (is_string($value)) {
return "\"$value\"";
}
return $value;
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* 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\Ini;
/**
* Exception when writing a INI configuration.
*/
class IniWritingException extends \Exception
{
}

View file

@ -0,0 +1,69 @@
# Piwik/Network
Component providing Network tools.
[![Build Status](https://travis-ci.org/piwik/component-network.svg?branch=master)](https://travis-ci.org/piwik/component-network)
[![Coverage Status](https://coveralls.io/repos/piwik/component-network/badge.png?branch=master)](https://coveralls.io/r/piwik/component-network?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/piwik/component-network/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/piwik/component-network/?branch=master)
## Installation
With Composer:
```json
{
"require": {
"piwik/network": "*"
}
}
```
## Usage
### IP
To manipulate an IP address, you can use the `Piwik\Network\IP` class:
```php
$ip = IP::fromStringIP('127.0.0.1');
// IPv6
$ip = IP::fromStringIP('::1');
// In binary format:
$ip = IP::fromBinaryIP("\x7F\x00\x00\x01");
echo $ip->toString(); // 127.0.0.1
echo $ip->toBinary();
// IPv4 & IPv6
if ($ip instanceof IPv4) {}
if ($ip instanceof IPv6) {}
// Hostname reverse lookup
echo $ip->getHostname();
if ($ip->isInRange('192.168.1.1/32')) {}
if ($ip->isInRange('192.168.*.*')) {}
// Anonymize an IP by setting X bytes to null bytes
$ip->anonymize(2);
```
The `Piwik\Network\IPUtils` class provides utility methods:
```php
echo IPUtils::binaryToStringIP("\x7F\x00\x00\x01");
echo IPUtils::stringToBinaryIP('127.0.0.1');
// Sanitization methods
$sanitizedIp = IPUtils::sanitizeIp($_GET['ip']);
$sanitizedIpRange = IPUtils::sanitizeIpRange($_GET['ipRange']);
// IP range
$bounds = IPUtils::getIPRangeBounds('192.168.1.*');
echo $bounds[0]; // 192.168.1.0
echo $bounds[1]; // 192.168.1.255
```
## License
The Network component is released under the [LGPL v3.0](http://choosealicense.com/licenses/lgpl-3.0/).

View file

@ -0,0 +1,21 @@
{
"name": "piwik/network",
"type": "library",
"license": "LGPL-3.0",
"autoload": {
"psr-4": {
"Piwik\\Network\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Piwik\\Network\\": "tests/"
}
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
}
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
phpunit -c phpunit.xml
-->
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="Test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -0,0 +1,216 @@
<?php
/**
* 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\Network;
/**
* IP address.
*
* This class is immutable, i.e. once created it can't be changed. Methods that modify it
* will always return a new instance.
*/
abstract class IP
{
/**
* Binary representation of the IP.
*
* @var string
*/
protected $ip;
/**
* @see fromBinaryIP
* @see fromStringIP
*
* @param string $ip Binary representation of the IP.
*/
protected function __construct($ip)
{
$this->ip = $ip;
}
/**
* Factory method to create an IP instance from an IP in binary format.
*
* @see fromStringIP
*
* @param string $ip IP address in a binary format.
* @return IP
*/
public static function fromBinaryIP($ip)
{
if ($ip === null || $ip === '') {
return new IPv4("\x00\x00\x00\x00");
}
if (self::isIPv4($ip)) {
return new IPv4($ip);
}
return new IPv6($ip);
}
/**
* Factory method to create an IP instance from an IP represented as string.
*
* @see fromBinaryIP
*
* @param string $ip IP address in a string format (X.X.X.X).
* @return IP
*/
public static function fromStringIP($ip)
{
return self::fromBinaryIP(IPUtils::stringToBinaryIP($ip));
}
/**
* Returns the IP address in a binary format.
*
* @return string
*/
public function toBinary()
{
return $this->ip;
}
/**
* Returns the IP address in a string format (X.X.X.X).
*
* @return string
*/
public function toString()
{
return IPUtils::binaryToStringIP($this->ip);
}
/**
* @return string
*/
public function __toString()
{
return $this->toString();
}
/**
* Tries to return the hostname associated to the IP.
*
* @return string|null The hostname or null if the hostname can't be resolved.
*/
public function getHostname()
{
$stringIp = $this->toString();
$host = strtolower(@gethostbyaddr($stringIp));
if ($host === '' || $host === $stringIp) {
return null;
}
return $host;
}
/**
* Determines if the IP address is in a specified IP address range.
*
* An IPv4-mapped address should be range checked with an IPv4-mapped address range.
*
* @param array|string $ipRange IP address range (string or array containing min and max IP addresses)
* @return bool
*/
public function isInRange($ipRange)
{
$ipLen = strlen($this->ip);
if (empty($this->ip) || empty($ipRange) || ($ipLen != 4 && $ipLen != 16)) {
return false;
}
if (is_array($ipRange)) {
// already split into low/high IP addresses
$ipRange[0] = IPUtils::stringToBinaryIP($ipRange[0]);
$ipRange[1] = IPUtils::stringToBinaryIP($ipRange[1]);
} else {
// expect CIDR format but handle some variations
$ipRange = IPUtils::getIPRangeBounds($ipRange);
}
if ($ipRange === null) {
return false;
}
$low = $ipRange[0];
$high = $ipRange[1];
if (strlen($low) != $ipLen) {
return false;
}
// binary-safe string comparison
if ($this->ip >= $low && $this->ip <= $high) {
return true;
}
return false;
}
/**
* Determines if the IP address is in a specified IP address range.
*
* An IPv4-mapped address should be range checked with IPv4-mapped address ranges.
*
* @param array $ipRanges List of IP address ranges (strings or arrays containing min and max IP addresses).
* @return bool True if in any of the specified IP address ranges; false otherwise.
*/
public function isInRanges(array $ipRanges)
{
$ipLen = strlen($this->ip);
if (empty($this->ip) || empty($ipRanges) || ($ipLen != 4 && $ipLen != 16)) {
return false;
}
foreach ($ipRanges as $ipRange) {
if ($this->isInRange($ipRange)) {
return true;
}
}
return false;
}
/**
* Returns the IP address as an IPv4 string when possible.
*
* Some IPv6 can be transformed to IPv4 addresses, for example
* IPv4-mapped IPv6 addresses: `::ffff:192.168.0.1` will return `192.168.0.1`.
*
* @return string|null IPv4 string address e.g. `'192.0.2.128'` or null if this is not an IPv4 address.
*/
public abstract function toIPv4String();
/**
* Anonymize X bytes of the IP address by setting them to a null byte.
*
* This method returns a new IP instance, it does not modify the current object.
*
* @param int $byteCount Number of bytes to set to "\0".
*
* @return IP Returns a new modified instance.
*/
public abstract function anonymize($byteCount);
/**
* Returns true if this is an IPv4, IPv4-compat, or IPv4-mapped address, false otherwise.
*
* @param string $binaryIp
* @return bool
*/
private static function isIPv4($binaryIp)
{
// in case mbstring overloads strlen function
$strlen = function_exists('mb_orig_strlen') ? 'mb_orig_strlen' : 'strlen';
return $strlen($binaryIp) == 4;
}
}

View file

@ -0,0 +1,178 @@
<?php
/**
* 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\Network;
/**
* IP address utilities (for both IPv4 and IPv6).
*
* As a matter of naming convention, we use `$ip` for the binary format (network address format)
* and `$ipString` for the string/presentation format (i.e., human-readable form).
*/
class IPUtils
{
/**
* Removes the port and the last portion of a CIDR IP address.
*
* @param string $ipString The IP address to sanitize.
* @return string
*/
public static function sanitizeIp($ipString)
{
$ipString = trim($ipString);
// CIDR notation, A.B.C.D/E
$posSlash = strrpos($ipString, '/');
if ($posSlash !== false) {
$ipString = substr($ipString, 0, $posSlash);
}
$posColon = strrpos($ipString, ':');
$posDot = strrpos($ipString, '.');
if ($posColon !== false) {
// IPv6 address with port, [A:B:C:D:E:F:G:H]:EEEE
$posRBrac = strrpos($ipString, ']');
if ($posRBrac !== false && $ipString[0] == '[') {
$ipString = substr($ipString, 1, $posRBrac - 1);
}
if ($posDot !== false) {
// IPv4 address with port, A.B.C.D:EEEE
if ($posColon > $posDot) {
$ipString = substr($ipString, 0, $posColon);
}
// else: Dotted quad IPv6 address, A:B:C:D:E:F:G.H.I.J
} else if (strpos($ipString, ':') === $posColon) {
$ipString = substr($ipString, 0, $posColon);
}
// else: IPv6 address, A:B:C:D:E:F:G:H
}
// else: IPv4 address, A.B.C.D
return $ipString;
}
/**
* Sanitize human-readable (user-supplied) IP address range.
*
* Accepts the following formats for $ipRange:
* - single IPv4 address, e.g., 127.0.0.1
* - single IPv6 address, e.g., ::1/128
* - IPv4 block using CIDR notation, e.g., 192.168.0.0/22 represents the IPv4 addresses from 192.168.0.0 to 192.168.3.255
* - IPv6 block using CIDR notation, e.g., 2001:DB8::/48 represents the IPv6 addresses from 2001:DB8:0:0:0:0:0:0 to 2001:DB8:0:FFFF:FFFF:FFFF:FFFF:FFFF
* - wildcards, e.g., 192.168.0.*
*
* @param string $ipRangeString IP address range
* @return string|null IP address range in CIDR notation OR null on failure
*/
public static function sanitizeIpRange($ipRangeString)
{
$ipRangeString = trim($ipRangeString);
if (empty($ipRangeString)) {
return null;
}
// IPv4 address with wildcards '*'
if (strpos($ipRangeString, '*') !== false) {
if (preg_match('~(^|\.)\*\.\d+(\.|$)~D', $ipRangeString)) {
return null;
}
$bits = 32 - 8 * substr_count($ipRangeString, '*');
$ipRangeString = str_replace('*', '0', $ipRangeString);
}
// CIDR
if (($pos = strpos($ipRangeString, '/')) !== false) {
$bits = substr($ipRangeString, $pos + 1);
$ipRangeString = substr($ipRangeString, 0, $pos);
}
// single IP
if (($ip = @inet_pton($ipRangeString)) === false)
return null;
$maxbits = strlen($ip) * 8;
if (!isset($bits))
$bits = $maxbits;
if ($bits < 0 || $bits > $maxbits) {
return null;
}
return "$ipRangeString/$bits";
}
/**
* Converts an IP address in string/presentation format to binary/network address format.
*
* @param string $ipString IP address, either IPv4 or IPv6, e.g. `'127.0.0.1'`.
* @return string Binary-safe string, e.g. `"\x7F\x00\x00\x01"`.
*/
public static function stringToBinaryIP($ipString)
{
// use @inet_pton() because it throws an exception and E_WARNING on invalid input
$ip = @inet_pton($ipString);
return $ip === false ? "\x00\x00\x00\x00" : $ip;
}
/**
* Convert binary/network address format to string/presentation format.
*
* @param string $ip IP address in binary/network address format, e.g. `"\x7F\x00\x00\x01"`.
* @return string IP address in string format, e.g. `'127.0.0.1'`.
*/
public static function binaryToStringIP($ip)
{
// use @inet_ntop() because it throws an exception and E_WARNING on invalid input
$ipStr = @inet_ntop($ip);
return $ipStr === false ? '0.0.0.0' : $ipStr;
}
/**
* Get low and high IP addresses for a specified IP range.
*
* @param string $ipRange An IP address range in string format, e.g. `'192.168.1.1/24'`.
* @return array|null Array `array($lowIp, $highIp)` in binary format, or null on failure.
*/
public static function getIPRangeBounds($ipRange)
{
if (strpos($ipRange, '/') === false) {
$ipRange = self::sanitizeIpRange($ipRange);
if ($ipRange === null) {
return null;
}
}
$pos = strpos($ipRange, '/');
$bits = substr($ipRange, $pos + 1);
$range = substr($ipRange, 0, $pos);
$high = $low = @inet_pton($range);
if ($low === false) {
return null;
}
$lowLen = strlen($low);
$i = $lowLen - 1;
$bits = $lowLen * 8 - $bits;
for ($n = (int)($bits / 8); $n > 0; $n--, $i--) {
$low[$i] = chr(0);
$high[$i] = chr(255);
}
$n = $bits % 8;
if ($n) {
$low[$i] = chr(ord($low[$i]) & ~((1 << $n) - 1));
$high[$i] = chr(ord($high[$i]) | ((1 << $n) - 1));
}
return array($low, $high);
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* 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\Network;
/**
* IP v4 address.
*
* This class is immutable, i.e. once created it can't be changed. Methods that modify it
* will always return a new instance.
*/
class IPv4 extends IP
{
/**
* {@inheritdoc}
*/
public function toIPv4String()
{
return $this->toString();
}
/**
* {@inheritdoc}
*/
public function anonymize($byteCount)
{
$newBinaryIp = $this->ip;
$i = strlen($newBinaryIp);
if ($byteCount > $i) {
$byteCount = $i;
}
while ($byteCount-- > 0) {
$newBinaryIp[--$i] = chr(0);
}
return self::fromBinaryIP($newBinaryIp);
}
}

View file

@ -0,0 +1,77 @@
<?php
/**
* 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\Network;
/**
* IP v6 address.
*
* This class is immutable, i.e. once created it can't be changed. Methods that modify it
* will always return a new instance.
*/
class IPv6 extends IP
{
const MAPPED_IPv4_START = '::ffff:';
/**
* {@inheritdoc}
*/
public function anonymize($byteCount)
{
$newBinaryIp = $this->ip;
if ($this->isMappedIPv4()) {
$i = strlen($newBinaryIp);
if ($byteCount > $i) {
$byteCount = $i;
}
while ($byteCount-- > 0) {
$newBinaryIp[--$i] = chr(0);
}
return self::fromBinaryIP($newBinaryIp);
}
$masks = array(
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
'ffff:ffff:ffff:ffff::',
'ffff:ffff:ffff:0000::',
'ffff:ff00:0000:0000::'
);
$newBinaryIp = $newBinaryIp & pack('a16', inet_pton($masks[$byteCount]));
return self::fromBinaryIP($newBinaryIp);
}
/**
* {@inheritdoc}
*/
public function toIPv4String()
{
$str = $this->toString();
if ($this->isMappedIPv4()) {
return substr($str, strlen(self::MAPPED_IPv4_START));
}
return null;
}
/**
* Returns true if this is a IPv4 mapped address, false otherwise.
*
* @return bool
*/
public function isMappedIPv4()
{
return substr_compare($this->ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff", 0, 12) === 0
|| substr_compare($this->ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0, 12) === 0;
}
}

View file

@ -0,0 +1,27 @@
Copyright (c) 2014, Piwik Open Source Analytics
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,16 @@
# PHP Client for Piwik Analytics Tracking API
The PHP Tracker Client provides all features of the [Piwik Javascript Tracker](http://developer.piwik.org/api-reference/tracking-javascript),
such as Ecommerce Tracking, Custom Variable, Event tracking and more.
## Documentation and examples
Check out our [Piwik-PHP-Tracker developer documentation](http://developer.piwik.org/api-reference/PHP-Piwik-Tracker) and
[Piwik Tracking API guide](http://piwik.org/docs/tracking-api/).
## Requirements:
* json extension (json_decode, json_encode)
* CURL or STREAM extensions (to issue the HTTP request to Piwik)
## License
Released under the [BSD License](http://www.opensource.org/licenses/bsd-license.php)

View file

@ -0,0 +1,22 @@
{
"name": "piwik/piwik-php-tracker",
"description": "PHP Client for Piwik Analytics Tracking API",
"keywords": ["piwik","tracker","analytics"],
"homepage": "http://piwik.org",
"license": "BSD-2-Clause",
"authors": [
{
"name": "The Piwik Team",
"email": "hello@piwik.org",
"homepage": "http://piwik.org/the-piwik-team/"
}
],
"support": {
"forum": "http://forum.piwik.org/",
"issues": "https://github.com/piwik/piwik-php-tracker/issues",
"source": "https://github.com/piwik/piwik-php-tracker"
},
"autoload": {
"classmap": ["."]
}
}

View file

@ -0,0 +1,13 @@
# Contributing
To add a new referrer spammer to the list, [click here to edit the spammers.txt file](https://github.com/piwik/referrer-spam-blacklist/edit/master/spammers.txt) and create a pull request. Alternatively you can create a [new issue](https://github.com/piwik/referrer-spam-blacklist/issues/new).
If you open a pull request, please:
- **add one new domain per pull request**
- explain where the referrer domain appeared and why you think it is a spammer
- name the pull request in the format `Add xxx.yyy` so that it's easy to manage duplicates (for example `Add cyber-monday.ga`)
- keep the list ordered alphabetically
- use [Linux line endings](http://en.wikipedia.org/wiki/Newline)
Please [search](https://github.com/piwik/referrer-spam-blacklist/issues?utf8=%E2%9C%93&q=is%3Aopen+) if somebody already reported the host before opening a new one.

View file

@ -0,0 +1,89 @@
This is a community-contributed list of [referrer spammers](http://en.wikipedia.org/wiki/Referer_spam) maintained by [Piwik](http://piwik.org/), the leading open source web analytics platform.
## Usage
The list is stored in this repository in `spammers.txt`. This text file contains one host per line.
You can [download this file manually](https://github.com/piwik/referrer-spam-blacklist/blob/master/spammers.txt), download the [whole folder as zip](https://github.com/piwik/referrer-spam-blacklist/archive/master.zip) or clone the repository using git:
```
git clone https://github.com/piwik/referrer-spam-blacklist.git
```
### PHP
If you are using PHP, you can also install the list through Composer:
```
composer require piwik/referrer-spam-blacklist
```
Parsing the file should be pretty easy using your favorite language. Beware that the file can contain empty lines.
Here is an example using PHP:
```php
$list = file('spammers.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
```
### Nginx
Nginx's `server` block can be configured to check the referer and return an error:
```nginx
if ($http_referer ~ '0n-line.tv') {return 403;}
if ($http_referer ~ '100dollars-seo.com') {return 403;}
...
```
When combined, list exceeds the max length for a single regex expression, so hosts must be broken up as shown above.
Here is a bash script to create an nginx conf file:
```bash
sort spammers.txt | uniq | sed 's/\./\\\\./g' | while read host;
do
echo "if (\$http_referer ~ '$host') {return 403;}" >> /etc/nginx/referer_spam.conf
done;
```
you would then `include /etc/nginx/referer_spam.conf;` inside your `server` block
Now as a daily cron job so the list stays up to date:
```bash
0 0 * * * cd /etc/nginx/referrer-spam-blacklist/ && git pull > /dev/null && echo "" > /etc/nginx/referer_spam.conf && sort spammers.txt | uniq | sed 's/\./\\\\\\\\./g' | while read host; do echo "if (\$http_referer ~ '$host') {return 403;}" >> /etc/nginx/referer_spam.conf; done; service nginx reload > /dev/null
```
### In Piwik
This list is included in each [Piwik](http://piwik.org) release so that referrer spam is filtered automatically. Piwik will also automatically update this list to its latest version every week.
## Contributing
To add a new referrer spammer to the list, [click here to edit the spammers.txt file](https://github.com/piwik/referrer-spam-blacklist/edit/master/spammers.txt) and create a pull request. Alternatively you can create a [new issue](https://github.com/piwik/referrer-spam-blacklist/issues/new). In your issue or pull request please explain where the referrer domain appeared and why you think it is a spammer. **Please open one pull request per new domain**.
If you open a pull request, it is appreciated if you keep one hostname per line, keep the list ordered alphabetically, and use [Linux line endings](http://en.wikipedia.org/wiki/Newline).
Please [search](https://github.com/piwik/referrer-spam-blacklist/issues) if somebody already reported the host before opening a new one.
### Subdomains
Piwik does sub-string matching on domain names from this list, so adding `semalt.com` is enough to block all subdomain referrers too, such as `semalt.semalt.com`.
However, there are cases where you'd only want to add a subdomain but not the root domain. For example, add `referrerspammer.tumblr.com` but not `tumblr.com`, otherwise all `*.tumblr.com` sites would be affected.
### Sorting
To keep the list sorted the same way across forks it is recommended to let the computer do the sorting. The list follows the merge sort algorithm as implemented in [sort](https://en.wikipedia.org/wiki/Sort_(Unix)). You can use sort to both sort the list and filter out doubles:
```
sort -uf -o spammers.txt spammers.txt
```
## Disclaimer
This list of Referrer spammers is contributed by the community and is provided as is. Use at your own discretion: it may be incomplete (although we aim to keep it up to date) and it may contain outdated entries (let us know if a hostname was added but is not actually a spammer).
## License
Public Domain (no copyright).

View file

@ -0,0 +1,5 @@
{
"name": "piwik/referrer-spam-blacklist",
"description": "Community-contributed list of referrer spammers",
"license": "Public Domain"
}

View file

@ -0,0 +1,329 @@
0n-line.tv
100dollars-seo.com
12masterov.com
1pamm.ru
1webmaster.ml
2your.site
4webmasters.org
5forex.ru
7makemoneyonline.com
7zap.com
acads.net
acunetix-referrer.com
adcash.com
adf.ly
adspart.com
adventureparkcostarica.com
adviceforum.info
affordablewebsitesandmobileapps.com
afora.ru
akuhni.by
alibestsale.com
allknow.info
allnews.md
allwomen.info
alpharma.net
altermix.ua
amt-k.ru
anal-acrobats.hol.es
anapa-inns.ru
android-style.com
anticrawler.org
arendakvartir.kz
arkkivoltti.net
artparquet.ru
aruplighting.com
autovideobroadcast.com
aviva-limoux.com
azartclub.org
baixar-musicas-gratis.com
baladur.ru
balitouroffice.com
bard-real.com.ua
best-seo-offer.com
best-seo-software.xyz
best-seo-solution.com
bestmobilityscooterstoday.com
bestwebsitesawards.com
bif-ru.info
biglistofwebsites.com
billiard-classic.com.ua
bizru.info
black-friday.ga
blackhatworth.com
blogtotal.de
blue-square.biz
bluerobot.info
brakehawk.com
break-the-chains.com
brk-rti.ru
brothers-smaller.ru
budmavtomatika.com.ua
burger-imperia.com
buttons-for-website.com
buttons-for-your-website.com
buy-cheap-online.info
buy-forum.ru
cardiosport.com.ua
cartechnic.ru
cenokos.ru
cenoval.ru
cezartabac.ro
chinese-amezon.com
ci.ua
cityadspix.com
civilwartheater.com
clicksor.com
coderstate.com
codysbbq.com
conciergegroup.org
connectikastudio.com
copyrightclaims.org
covadhosting.biz
cubook.supernew.org
customsua.com.ua
cyber-monday.ga
dailyrank.net
darodar.com
dbutton.net
delfin-aqua.com.ua
demenageur.com
descargar-musica-gratis.net
detskie-konstruktory.ru
dipstar.org
djekxa.ru
dktr.ru
dojki-hd.com
domination.ml
doska-vsem.ru
dostavka-v-krym.com
drupa.com
dvr.biz.ua
e-buyeasy.com
e-kwiaciarz.pl
ecomp3.ru
econom.co
edakgfvwql.ru
egovaleo.it
ekto.ee
elmifarhangi.com
erot.co
escort-russian.com
este-line.com.ua
euromasterclass.ru
europages.com.ru
eurosamodelki.ru
event-tracking.com
fast-wordpress-start.com
fbdownloader.com
floating-share-buttons.com
for-your.website
forex-procto.ru
forsex.info
forum69.info
free-floating-buttons.com
free-share-buttons.com
free-social-buttons.com
freewhatsappload.com
fsalas.com
generalporn.org
germes-trans.com
get-free-social-traffic.com
get-free-traffic-now.com
get-your-social-buttons.info
ghazel.ru
girlporn.ru
gkvector.ru
glavprofit.ru
gobongo.info
goodprotein.ru
googlemare.com
googlsucks.com
guardlink.org
handicapvantoday.com
hdmoviecamera.net
hongfanji.com
hosting-tracker.com
howopen.ru
howtostopreferralspam.eu
hulfingtonpost.com
humanorightswatch.org
hundejo.com
hvd-store.com
ico.re
igru-xbox.net
iloveitaly.ro
iloveitaly.ru
ilovevitaly.co
ilovevitaly.com
ilovevitaly.info
ilovevitaly.org
ilovevitaly.ru
iminent.com
imperiafilm.ru
investpamm.ru
iskalko.ru
ispaniya-costa-blanca.ru
it-max.com.ua
jjbabskoe.ru
justprofit.xyz
kabbalah-red-bracelets.com
kambasoft.com
kazrent.com
kino-fun.ru
kino-key.info
kinopolet.net
knigonosha.net
konkursov.net
laxdrills.com
littleberry.ru
livefixer.com
lsex.xyz
luxup.ru
makemoneyonline.com
manualterap.roleforum.ru
maridan.com.ua
masterseek.com
mebelcomplekt.ru
mebeldekor.com.ua
med-zdorovie.com.ua
minegam.com
mirobuvi.com.ua
mirtorrent.net
mobilemedia.md
moyakuhnia.ru
muscle-factory.com.ua
myftpupload.com
niki-mlt.ru
novosti-hi-tech.ru
nufaq.com
o-o-6-o-o.com
o-o-6-o-o.ru
o-o-8-o-o.com
o-o-8-o-o.ru
online-hit.info
onlinetvseries.me
onlywoman.org
ooo-olni.ru
ozas.net
palvira.com.ua
petrovka-online.com
photokitchendesign.com
pizza-imperia.com
pizza-tycoon.com
pops.foundation
pornhub-forum.ga
pornhub-forum.uni.me
pornhub-ru.com
pornoforadult.com
portnoff.od.ua
pozdravleniya-c.ru
priceg.com
pricheski-video.com
prlog.ru
producm.ru
prodvigator.ua
prointer.net.ua
promoforum.ru
psa48.ru
qualitymarketzone.com
quit-smoking.ga
qwesa.ru
rankings-analytics.com
ranksonic.info
ranksonic.net
ranksonic.org
rapidgator-porn.ga
rcb101.ru
rednise.com
research.ifmo.ru
resellerclub.com
reversing.cc
rightenergysolutions.com.au
rospromtest.ru
rusexy.xyz
sady-urala.ru
sanjosestartups.com
santasgift.ml
savetubevideo.com
screentoolkit.com
scripted.com
search-error.com
semalt.com
semaltmedia.com
seo-platform.com
seo-smm.kz
seoanalyses.com
seoexperimenty.ru
seopub.net
sexyali.com
sexyteens.hol.es
share-buttons.xyz
sharebutton.net
sharebutton.to
shop.xz618.com
sibecoprom.ru
simple-share-buttons.com
siteripz.net
sitevaluation.org
sledstvie-veli.net
slftsdybbg.ru
slkrm.ru
smailik.org
snip.to
snip.tw
soaksoak.ru
social-buttons.com
socialseet.ru
sohoindia.net
solnplast.ru
sosdepotdebilan.com
spravka130.ru
steame.ru
success-seo.com
superiends.org
taihouse.ru
tattooha.com
tedxrj.com
theguardlan.com
tomck.com
top1-seo-service.com
topseoservices.co
traffic2cash.org
traffic2cash.xyz
traffic2money.com
trafficgenius.xyz
trafficmonetize.org
trafficmonetizer.org
trion.od.ua
uasb.ru
uptimechecker.com
uzungil.com
video--production.com
video-woman.com
videos-for-your-business.com
viel.su
viktoria-center.ru
vodaodessa.com
vodkoved.ru
w3javascript.com
webmaster-traffic.com
webmonetizer.net
website-analyzer.info
websites-reviews.com
websocial.me
wmasterlead.com
wordpress-crew.net
ykecwqlixx.ru
youporn-forum.ga
youporn-forum.uni.me
youporn-ru.com
yourserverisdown.com
zastroyka.org
грузоподъемные-машины.рф
лечениенаркомании.com
непереводимая.рф
профмонтаж-врн.рф
снятьдомвсевастополе.рф
холодныйобзвон.рф
годом.рф

View file

@ -0,0 +1,145 @@
These are community-contributed definitions for search engine and social network detections list maintained and used by [Piwik](http://piwik.org/), the leading open source web analytics platform.
# Social Networks
Social networks are defined in YAML format in the file `Socials.yml`
The definitions contain the name of the social network, as well as a list of one or more urls.
```YAML
"My Social Network":
- my-social-network.com
- mysocial.org
```
# Search Engines
Search engines are defined in YAML format in the file `SearchEngines.yml`
Definitions of search engines contain several parameters that are required to be able to detect which search engine and which search keywords are included in a given url.
Those parameters are:
- name of the engine
- URLs of the engine
- request parameters (or regexes), that can be used to get the search keyword
- backlink pattern, that can be used to create a valid link back to the search engine (with the keyword)
- charsets that might be used to convert keyword to UTF-8
For each search engine (name) it is possible to define multiple configurations.
Each configuration needs to include one or more urls, one or more parameters/regexes and may include a backlink and one or more charsets.
## Configuration parameters
### urls
Each configuration needs to contain one ore more urls. Please only define the hostname.
You can use `{}` as a placeholder for country shortcodes in subdomains or tld.
- `{}.searchengine.com` would also match `de.searchengine.com` or `nl.searchengine.com`
- `searchengine.{}` would also match `searchengine.de` or `searchengine.nl`
NOTE: For tlds only `{}` would also match combined tlds like `co.uk`. (Full list `com.*, org.*, net.*, co.*, it.*, edu.*`)
### params
Each configuration needs to contain one or more params. A param is a name of a request param that might be available in the url.
As many search engines do not use query parameters to handle the keywords, but include them in the url structure, it is also possible to define a regex.
A regex need to be encapsulated by '/'
```YAML
SearchEngine:
-
urls:
- searchengine.com
params:
- q
- '/search\/[^\/]+\/(.*)/'
```
The example above would first try to get the keyword with the request param `q`. If that is not available it would use the regex `'/search\/[^\/]+\/(.*)/'` to get it.
This regex would match an url like 'http://searchengine.com/search/web/piwik'
### backlink
A backlink will be used to generate a link back to the search engine including the given keyword. backlinks may be defined per configuration and need to include `{k}` as placeholder for the keyword.
```YAML
SearchEngine:
-
urls:
- searchengine.com
params:
- q
backlink: '/search?q={k}'
```
For the configuration above the generated backlink would look like `searchengine.com/search?q=piwik` (assuming that `piwik` is the keyword).
NOTE: The backlink will always be generated using the __first__ defined url in this configuration block.
### charsets
Charsets can be defined if search engines are using charsets other than UTF-8. The provided charset will be used to convert any detected search keyword to UTF-8.
## Simple definition
A simple defintion of a search eninge might look like this:
```YAML
SearchEngine:
-
urls:
- searchengine.com
- search-engine.org
params:
- q
- as_q
```
The example above would match for the hosts `searchengine.com` and `search-engine.org` and use the request parameters `q` and `as_q` (in this order) to detect the search keyword.
## Multiple configurations
A simple definition of a search eninge with multiple configurations might look like this:
```YAML
SearchEngine:
-
urls:
- searchengine.com
params:
- as_q
-
urls:
- search-engine.org
params:
- q
```
The example above would again match for the hosts `searchengine.com` and `search-engine.org`. But differently to the first example the request parameter `q` would only be used for `search-engine.org` and `as_q` only for `searchengine.com`.
## Complete definition
A complete definition (including all optionals) of a search engine might look like this:
```YAML
SearchEngine:
-
urls:
- searchengine.com
params:
- q
backlink: '/search?q={k}'
charsets:
- windows-1250
-
urls:
- search-engine.org
params:
- as_q
```
In this case, a backlink and charset is only defined for the first configuration. Which means there is no backlink nor charset set for `search-engine.org`.
# Contribute
We welcome your contributions and Pull requests at [github.com/piwik/searchengine-and-social-list](https://github.com/piwik/searchengine-and-social-list/edit/master/README.md)!

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,217 @@
Facebook:
- facebook.com
- fb.me
Ozone:
- qzone.qq.com
Haboo:
- habbo.com
Twitter:
- twitter.com
- t.co
Renren:
- renren.com
"Windows Live Spaces":
- login.live.com
LinkedIn:
- linkedin.com
Bebo:
- bebo.com
Vkontakte:
- vk.com
- vkontakte.ru
Tagged:
- login.tagged.com
Orkut:
- orkut.com
Myspace:
- myspace.com
Frinedster:
- friendster.com
Badoo:
- badoo.com
hi5:
- hi5.com
Netlog:
- netlog.com
Flixster:
- flixster.com
MyLife:
- mylife.ru
Classmates.com:
- classmates.com
Github:
- github.com
Google%2B:
- plus.google.com
- url.google.com
douban:
- douban.com
dribbble:
- dribbble.com
Odnoklassniki:
- odnoklassniki.ru
Viadeo:
- viadeo.com
Flickr:
- flickr.com
WeeWorld:
- weeworld.com
Last.fm:
- last.fm
- lastfm.ru
- lastfm.de
- lastfm.es
- lastfm.fr
- lastfm.it
- lastfm.jp
- lastfm.pl
- lastfm.com.br
- lastfm.se
- lastfm.com.tr
MyHeritage:
- myheritage.com
Xanga:
- xanga.com
Mixi:
- mixi.jp
Cyworld:
- global.cyworld.com
Gaia Online:
- gaiaonline.com
Skyrock:
- skyrock.com
BlackPlanet:
- blackplanet.com
myYearbook:
- myyearbook.com
Fotolog:
- fotolog.com
"Friends Reunited":
- friendsreunited.com
LiveJournal:
- livejournal.ru
- livejournal.com
StudiVZ:
- studivz.net
MeinVZ:
- meinvz.net
StackOverflow:
- stackoverflow.com
Sonico.com:
- sonico.com
Pinterest:
- pinterest.com
Plaxo:
- plaxo.com
Geni.com:
- geni.com
Tuenti:
- tuenti.com
XING:
- xing.com
Taringa!:
- taringa.net
Nasza-klasa.pl:
- nk.pl
StumbleUpon:
- stumbleupon.com
Sourceforge:
- sourceforge.net
Hyves:
- hyves.nl
WAYN:
- wayn.com
Buzznet:
- buzznet.com
Multiply:
- multiply.com
Foursquare:
- foursquare.com
vkrugudruzei.ru:
- vkrugudruzei.ru
my.mail.ru:
- my.mail.ru
MoiKrug.ru:
- moikrug.ru
reddit:
- reddit.com
"Hacker News":
- news.ycombinator.com
identi.ca:
- identi.ca
Weibo:
- weibo.com
- t.cn
YouTube:
- youtube.com
- youtu.be
Vimeo:
- vimeo.com
tumblr:
- tumblr.com

View file

@ -0,0 +1,5 @@
{
"name": "piwik/searchengine-and-social-list",
"description": "Search engine and social network definitions used by Piwik",
"license": "Public Domain"
}