-
Notifications
You must be signed in to change notification settings - Fork 4
/
CrawlerDetect.php
54 lines (41 loc) · 1 KB
/
CrawlerDetect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace alikdex\crawlerdetect;
use Yii;
use Jaybizzle\CrawlerDetect\CrawlerDetect as CrawlerLib;
class CrawlerDetect extends \yii\base\Component
{
private $_crawlerDetect;
/**
* @var bool seo bot detection result.
*/
private $_isCrawler = null;
// Automatically set view parameters based on device type
public $setParams = false;
public function __call($name, $parameters) {
return call_user_func_array(
array($this->_crawlerDetect, $name),
$parameters
);
}
public function __construct($config = array()) {
parent::__construct($config);
}
public function init() {
$this->_crawlerDetect = new CrawlerLib();
parent::init();
$this->_isCrawler = $this->_crawlerDetect->isCrawler();
if ($this->setParams)
Yii::$app->params['isCrawler'] = $this->_isCrawler;
}
/**
* Check seo bot.
* @return bool
*/
public function getIsCrawler()
{
if (null === $this->_isCrawler) {
$this->_isCrawler = $this->_crawlerDetect->isCrawler();
}
return $this->_isCrawler;
}
}