ソースを参照

- adding Tracking Class

pull-requests/1/from
Marcel Völkel 7年前
コミット
932f234dac
3個のファイルの変更94行の追加0行の削除
  1. 84
    0
      Application/scf/Additionals/Tracking.php
  2. 2
    0
      bootstrap.php
  3. 8
    0
      web/index.php

+ 84
- 0
Application/scf/Additionals/Tracking.php ファイルの表示

@@ -0,0 +1,84 @@
1
+<?php
2
+
3
+namespace SCF\Additionals;
4
+
5
+use SCF\Core\Database;
6
+
7
+class Tracking
8
+{
9
+
10
+    private $_db;
11
+
12
+    private $currentUserIp;
13
+
14
+    private $currentUserAgent;
15
+
16
+    private $currentUserReferer;
17
+
18
+    public function __construct(Database $db)
19
+    {
20
+        $this->_db = $db;
21
+    }
22
+
23
+    /**
24
+     * @param mixed $currentUserIp
25
+     */
26
+    public function setCurrentUserIp($currentUserIp)
27
+    {
28
+        $this->currentUserIp = $currentUserIp;
29
+    }
30
+
31
+    /**
32
+     * @param mixed $currentUserAgent
33
+     */
34
+    public function setCurrentUserAgent($currentUserAgent)
35
+    {
36
+        $this->currentUserAgent = $currentUserAgent;
37
+    }
38
+
39
+    /**
40
+     * @param mixed $currentUserReferer
41
+     */
42
+    public function setCurrentUserReferer($currentUserReferer)
43
+    {
44
+        $this->currentUserReferer = $currentUserReferer;
45
+    }
46
+
47
+    /**
48
+     * @return mixed
49
+     */
50
+    public function getCurrentUserIp()
51
+    {
52
+        return $this->currentUserIp;
53
+    }
54
+
55
+    /**
56
+     * @return mixed
57
+     */
58
+    public function getCurrentUserAgent()
59
+    {
60
+        return $this->currentUserAgent;
61
+    }
62
+
63
+    /**
64
+     * @return mixed
65
+     */
66
+    public function getCurrentUserReferer()
67
+    {
68
+        return $this->currentUserReferer;
69
+    }
70
+
71
+    public function checkUniqueUser()
72
+    {
73
+        $this->_db->query("SELECT ip_adress, `timestamp` FROM sks_unique_user WHERE ip_adress = '{$this->getCurrentUserIp()}' ORDER BY `timestamp` ASC LIMIT 1");
74
+        $result = $this->_db->single();
75
+        $trackedDate = date("Y-m-d", $result['timestamp']);
76
+        $currentDate = date("Y-m-d", time());
77
+        if ($trackedDate == $currentDate) {
78
+            echo 'same Day visit';
79
+        } else {
80
+            echo 'different Dates visit';
81
+        }
82
+
83
+    }
84
+}

+ 2
- 0
bootstrap.php ファイルの表示

@@ -16,6 +16,7 @@ use Symfony\Component\Debug\Debug;
16 16
 use SCF\Core\DI;
17 17
 use SCF\Core\Database;
18 18
 use SCF\Core\System;
19
+use SCF\Additionals\Tracking;
19 20
 use SCF\Core\Templates;
20 21
 
21 22
 /**
@@ -40,6 +41,7 @@ else {
40 41
 $di = DI::getInstance();
41 42
 $di->set('db', new Database($config['dbext'], $config['server'], $config['mysqluser'], $config['mysqlpass'], $config['mysqldbname']), true);
42 43
 $di->set('router', 'AltoRouter', true);
44
+$di->set('tracking', new Tracking(DI::getInstance()->get('db')), true);
43 45
 
44 46
 $settings = new System(DI::getInstance()->get('db'));
45 47
 

+ 8
- 0
web/index.php ファイルの表示

@@ -2,6 +2,7 @@
2 2
 require_once '../bootstrap.php';
3 3
 
4 4
 use SCF\Additionals\Carousel;
5
+use SCF\Core\DI;
5 6
 
6 7
 $c = new Carousel(ROOT . DS . 'web/Styles/sks-screens' . DS);
7 8
 
@@ -13,6 +14,13 @@ require_once ROOT.DS.APP."/Config/router.php";
13 14
 $tpl->assign('sksscreens', $c->getPicArray());
14 15
 $match = $router->match();
15 16
 
17
+
18
+$tracking = DI::getInstance()->get('tracking');
19
+$tracking->setCurrentUserIp($_SERVER['REMOTE_ADDR']);
20
+$tracking->setCurrentUserAgent($_SERVER['HTTP_USER_AGENT']);
21
+$tracking->setCurrentUserReferer($_SERVER['HTTP_REFERER']);
22
+$tracking->checkUniqueUser();
23
+
16 24
 if($match === false) {
17 25
     $tpl->display('errorpages/404.tpl');
18 26
 }

読み込み中…
キャンセル
保存