Skip to content

Commit

Permalink
Added visitor details modal
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-wdmg committed Mar 15, 2019
1 parent 11d5707 commit 5b944b9
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 47 deletions.
5 changes: 5 additions & 0 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ public function bootstrap($app)
$app->getUrlManager()->addRules(
[
$prefix . '<module:stats>/' => '<module>/visitors/index',
$prefix . '<module:stats>/view' => '<module>/visitors/view',
$prefix . '<module:stats>/<controller:visitors>/' => '<module>/<controller>',
$prefix . '<module:stats>/<controller:(visitors|item)>/<action:\w+>' => '<module>/<controller>/<action>',
[
'pattern' => $prefix . '<module:stats>/',
'route' => '<module>/visitors/index',
'suffix' => '',
], [
'pattern' => $prefix . '<module:stats>/view',
'route' => '<module>/visitors/view',
'suffix' => '',
], [
'pattern' => $prefix . '<module:stats>/<controller:visitors>/',
'route' => '<module>/<controller>',
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Changelog
=========

## 1.0.4 (2019-03-15)
## 1.0.5 (2019-03-16)
* Added visitor details modal
* Added bot detection
* Added custom view options

## 1.0.4 (2019-03-15)
* Added statistics storage period
* Added clear old statistic data

Expand Down
2 changes: 1 addition & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Module extends \yii\base\Module
/**
* @var string the module version
*/
private $version = "1.0.4";
private $version = "1.0.5";

/**
* @var integer, priority of initialization
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $config['bootstrap'][] = 'wdmg\stats\Bootstrap';
`

# Status and version [in progress development]
* v.1.0.5 - Added visitor details modal
* v.1.0.4 - Added bot detection, custom view options, storage period and clear old stats
* v.1.0.3 - Fixing tables names in migrations
* v.1.0.2 - MaxMind GeoIp and Charts.js
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": ["yii2", "yii2-stats", "stats", "statistics", "wdmg"],
"type": "yii2-extension",
"license": "MIT",
"version": "1.0.4",
"version": "1.0.5",
"homepage": "https://github.com/wdmg/yii2-stats",
"support": {
"source": "https://github.com/wdmg/yii2-stats",
Expand Down
30 changes: 28 additions & 2 deletions controllers/VisitorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ public function actionIndex()
]);
}

public function actionView($id)
{
$module = Yii::$app->getModule('stats');
$clientPlatforms = $module->clientPlatforms;
$clientBrowsers = $module->clientBrowsers;

$model = self::findModel($id);

$locale = \Locale::getPrimaryLanguage(Yii::$app->language); // Get short locale string
if(!$locale)
$locale = 'en';

try {
$reader = new \GeoIp2\Database\Reader(__DIR__ .'/../database/GeoLite2-Country.mmdb', [$locale]);
} catch (Exception $e) {
$reader = null;
Yii::warning($e->getMessage());
}

return $this->renderAjax('view', [
'clientPlatforms' => $clientPlatforms,
'clientBrowsers' => $clientBrowsers,
'model' => $model,
'reader' => $reader
]);
}

public function actionClear() {
if(Visitors::clearOldStats(time())) {
Expand All @@ -216,10 +242,10 @@ public function actionClear() {
*/
protected function findModel($id)
{
if (($model = Tasks::findOne($id)) !== null) {
if (($model = Visitors::findOne($id)) !== null) {
return $model;
}

throw new NotFoundHttpException(Yii::t('app/modules/tasks', 'The requested page does not exist.'));
throw new NotFoundHttpException(Yii::t('app/modules/stats', 'The requested page does not exist.'));
}
}
5 changes: 5 additions & 0 deletions messages/ru-RU/app/modules/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
'HTTPS' => 'HTTPS',
'Session' => 'Сессия',
'DateTime' => 'Дата/время',
'Type' => 'Тип перехода',
'Unique' => 'Уникальный?',
'Params' => 'Параметры',
'Unknow IP' => 'Неизвестный IP',

'Visit Information' => 'Информация о посещении',
'View options' => 'Параметры отображения',
'Apply' => 'Применить',
'Reset' => 'Сбросить',
'Close' => 'Закрыть',


'Show chart' => 'Отображать график',
'Show robots' => 'Отображать роботов',
Expand Down
21 changes: 11 additions & 10 deletions migrations/m190209_224417_stats_robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ public function safeUp()
["Kilroy", "kilroy", "0"],
["KO_Yappo_Robot", "ko_yappo_robot", "0"],
["LabelGrabber", "labelgrabber\.txt", "0"],
["larbin", "larbin", "0"],
["legs", "legs", "0"],
["Larbin", "larbin", "0"],
["Legs", "legs", "0"],
["Link Validator", "linkidator", "0"],
["LinkScan", "linkscan", "0"],
["Lockon", "lockon", "0"],
["logo.gif Crawler", "logo_gif", "0"],
["Logo.gif Crawler", "logo_gif", "0"],
["Mac WWWWorm", "macworm", "0"],
["Magpie", "magpie", "0"],
["marvin/infoseek", "marvin", "0"],
Expand All @@ -285,7 +285,7 @@ public function safeUp()
["MerzScope", "merzscope", "0"],
["NEC-MeshExplorer", "meshexplorer", "0"],
["MindCrawler", "mindcrawler", "0"],
["mnoGoSearch search engine soft", "mnogosearch", "0"],
["mnoGoSearch", "mnogosearch", "0"],
["MOMspider", "momspider", "0"],
["Monster", "monster", "0"],
["Motor", "motor", "0"],
Expand All @@ -300,7 +300,7 @@ public function safeUp()
["newscan-online", "newscan\-online", "0"],
["NHSE Web Forager", "nhse", "0"],
["The NorthStar Robot", "northstar", "0"],
["nzexplorer", "nzexplorer", "0"],
["NZExplorer", "nzexplorer", "0"],
["ObjectsSearch", "objectssearch", "0"],
["Occam", "occam", "0"],
["HKU WWW Octopus", "octopus", "0"],
Expand Down Expand Up @@ -355,19 +355,20 @@ public function safeUp()
["Snooper", "snooper", "0"],
["Solbot", "solbot", "0"],
["Speedy Spider", "speedy", "0"],
["spider_monkey", "spider_monkey", "0"],
["Spider Monkey", "spider_monkey", "0"],
["SpiderBot", "spiderbot", "0"],
["Spiderline Crawler", "spiderline", "0"],
["SpiderMan", "spiderman", "0"],
["SpiderView(tm)", "spiderview", "0"],
["Spry Wizard Robot", "spry", "0"],
["Site Searcher", "ssearcher", "0"],
["Suke", "suke", "0"],
["suntek search engine", "suntek", "0"],
["Cliqzbot", "cliqzbot", "0"],
["Suntek Search Engine", "suntek", "0"],
["Sven", "sven", "0"],
["TACH Black Widow", "tach_bw", "0"],
["Tarantula", "tarantula", "0"],
["tarspider", "tarspider", "0"],
["Tarspider", "tarspider", "0"],
["TechBOT", "techbot", "0"],
["Templeton", "templeton", "0"],
["TITAN", "titan", "0"],
Expand All @@ -380,8 +381,8 @@ public function safeUp()
["Valkyrie", "valkyrie", "0"],
["Verticrawl", "verticrawl", "0"],
["Victoria", "victoria", "0"],
["vision-search", "visionsearch", "0"],
["void-bot", "voidbot", "0"],
["Vision-search", "visionsearch", "0"],
["Void-bot", "voidbot", "0"],
["VWbot", "vwbot", "0"],
["The NWI Robot", "w3index", "0"],
["W3M2", "w3m2", "0"],
Expand Down
2 changes: 2 additions & 0 deletions models/Visitors.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ public function attributeLabels()
'remote_host' => Yii::t('app/modules/stats', 'Remote Host'),
'user' => Yii::t('app/modules/stats', 'User'),
'user_id' => Yii::t('app/modules/stats', 'User ID'),
'robot' => Yii::t('app/modules/stats', 'Robot'),
'robot_id' => Yii::t('app/modules/stats', 'Robot ID'),
'user_agent' => Yii::t('app/modules/stats', 'User Agent'),
'referer_uri' => Yii::t('app/modules/stats', 'Referrer URL'),
'referer_host' => Yii::t('app/modules/stats', 'Referrer Host'),
'https' => Yii::t('app/modules/stats', 'HTTPS'),
'datetime' => Yii::t('app/modules/stats', 'DateTime'),
'type' => Yii::t('app/modules/stats', 'Type'),
'session' => Yii::t('app/modules/stats', 'Session'),
'unique' => Yii::t('app/modules/stats', 'Unique'),
'params' => Yii::t('app/modules/stats', 'Params'),
Expand Down
87 changes: 55 additions & 32 deletions views/visitors/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Button;
use yii\bootstrap\ButtonGroup;
use yii\bootstrap\Modal;
use wdmg\widgets\ChartJS;
use wdmg\widgets\DatePicker;
use wdmg\stats\MainAsset;
Expand Down Expand Up @@ -168,21 +169,16 @@
'filterModel' => $searchModel,
'layout' => '{summary}<br\/>{items}<br\/>{summary}<br\/><div class="text-center">{pager}</div>',
'columns' => [

'request_uri',
//'remote_addr',
//'remote_host',
/*[
'attribute' => 'user_id',
'format' => 'html',
'filter' => true,
[
'attribute' => 'request_uri',
'format' => 'raw',
'value' => function($data) {
if ($data->user_id)
return $data->user_id;
if ($data->https)
return Html::a('<span class="glyphicon glyphicon-lock text-success" data-toggle="tooltip" title="HTTPS"></span>&nbsp;' . $data->request_uri, $data->request_uri, ['target' => "_blank", 'title' => $data->request_uri, 'data-toggle' => "tooltip", 'data-pajax' => 0]);
else
return '&nbsp;';
return Html::a($data->request_uri, $data->request_uri, ['target' => "_blank", 'title' => $data->request_uri, 'data-toggle' => "tooltip", 'data-pajax' => 0]);
},
],*/
],
[
'attribute' => 'robot',
'format' => 'html',
Expand All @@ -201,7 +197,6 @@
}
},
],
//'user_agent',
[
'attribute' => 'referer_uri',
'format' => 'raw',
Expand Down Expand Up @@ -249,21 +244,6 @@
'filter' => true,
'visible' => $searchModel->viewClientIP,
'value' => function($data) use ($reader) {
/*if ($data->remote_addr && $data->remote_host && $data->remote_host !== 'localhost')
return Html::a($data->remote_addr, 'https://check-host.net/ip-info?host=' . $data->remote_addr, ['target' => "_blank", 'data-pajax' => 0]) . ' ('.$data->remote_host . ')';
else if ($data->remote_addr && $data->remote_addr !== '127.0.0.1' && $data->remote_addr !== '::1')
return Html::a($data->remote_addr, 'https://check-host.net/ip-info?host=' . $data->remote_addr, ['target' => "_blank", 'data-pajax' => 0]);
else if ($data->remote_addr)
return $data->remote_addr;
else
return 'Unknow IP';*/

/*if ($data->remote_addr && $data->remote_addr !== '127.0.0.1' && $data->remote_addr !== '::1')
return Html::a($data->remote_addr, 'https://check-host.net/ip-info?host=' . $data->remote_addr, ['target' => "_blank", 'data-pajax' => 0]);
else
return 'Unknow IP';
*/

try {
if ($reader && $data->remote_addr && $data->remote_addr !== '127.0.0.1' && $data->remote_addr !== '::1') {
$record = $reader->country($data->remote_addr);
Expand All @@ -276,8 +256,7 @@
return $data->remote_addr;
}
}
return 'Unknow IP';

return Yii::t('app/modules/stats', 'Unknow IP');
},
],
[
Expand Down Expand Up @@ -305,7 +284,6 @@
return date('d-m-Y h:i:s', $data->datetime);
},
],
//'session',
[
'attribute' => 'type',
'format' => 'html',
Expand All @@ -325,7 +303,28 @@
return $data->type;
},
],
//'params',
[
'class' => \yii\grid\ActionColumn::className(),
'buttons'=> [
'view' => function($url, $data, $key) use ($module) {
$url = Yii::$app->getUrlManager()->createUrl([$module->routePrefix . '/stats/view', 'id' => $data['id']]);
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'class' => 'visitor-details-link',
'title' => Yii::t('yii', 'View'),
'data-toggle' => 'modal',
'data-target' => '#visitorDetails',
'data-id' => $key,
'data-pjax' => '1'
]);
},
'update' => function() {
return false;
},
'delete' => function() {
return false;
},
],
],
],
]); ?>
<?php Pjax::end(); ?>
Expand All @@ -339,4 +338,28 @@
]); ?>
</div>

<?php $this->registerJs(<<< JS
$('.visitor-details-link').click(function(event) {
event.preventDefault();
$.get(
$(this).attr('href'),
function (data) {
$('#visitorDetails .modal-body').html(data);
$('#visitorDetails').modal();
}
);
});
JS
); ?>

<?php Modal::begin([
'id' => 'visitorDetails',
'header' => '<h4 class="modal-title">'.Yii::t('app/modules/stats', 'Visit Information').'</h4>',
'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">'.Yii::t('app/modules/stats', 'Close').'</a>',
'clientOptions' => [
'show' => false
]
]); ?>
<?php Modal::end(); ?>

<?php echo $this->render('../_debug'); ?>
Loading

0 comments on commit 5b944b9

Please sign in to comment.